private TitusBatchJobRequest createJobRequest()

in genie-web/src/main/java/com/netflix/genie/web/agent/launchers/impl/TitusAgentLauncherImpl.java [247:366]


    private TitusBatchJobRequest createJobRequest(final ResolvedJob resolvedJob) throws AgentLaunchException {
        final String jobId = resolvedJob.getJobSpecification().getJob().getId();

        final String jobUser = resolvedJob.getJobMetadata().getUser();

        // Map placeholders in entry point template to their values
        final Map<String, String> placeholdersMap = Map.of(
            TitusAgentLauncherProperties.JOB_ID_PLACEHOLDER,
            jobId,
            TitusAgentLauncherProperties.SERVER_HOST_PLACEHOLDER,
            this.titusAgentLauncherProperties.getGenieServerHost(),
            TitusAgentLauncherProperties.SERVER_PORT_PLACEHOLDER,
            String.valueOf(this.titusAgentLauncherProperties.getGenieServerPort())
        );

        // Substitute all placeholders with their values for the container entry point and command
        final List<String> entryPoint = REPLACE_PLACEHOLDERS.apply(
            this.titusAgentLauncherProperties.getEntryPointTemplate(),
            placeholdersMap
        );
        final List<String> command = REPLACE_PLACEHOLDERS.apply(
            this.titusAgentLauncherProperties.getCommandTemplate(),
            placeholdersMap
        );
        final Duration runtimeLimit = this.titusAgentLauncherProperties.getRuntimeLimit();

        final Map<String, String> jobAttributes = this.createJobAttributes(jobId, jobUser);

        final TitusBatchJobRequest.TitusBatchJobRequestBuilder requestBuilder = TitusBatchJobRequest.builder()
            .owner(
                TitusBatchJobRequest.Owner
                    .builder()
                    .teamEmail(this.titusAgentLauncherProperties.getOwnerEmail())
                    .build()
            )
            .applicationName(this.titusAgentLauncherProperties.getApplicationName())
            .capacityGroup(
                this.environment.getProperty(
                    TitusAgentLauncherProperties.CAPACITY_GROUP_PROPERTY,
                    String.class,
                    this.titusAgentLauncherProperties.getCapacityGroup()
                )
            )
            .attributes(jobAttributes)
            .container(
                TitusBatchJobRequest.Container
                    .builder()
                    .resources(this.getTitusResources(resolvedJob))
                    .securityProfile(
                        TitusBatchJobRequest.SecurityProfile.builder()
                            .attributes(new HashMap<>(this.titusAgentLauncherProperties.getSecurityAttributes()))
                            .securityGroups(new ArrayList<>(this.titusAgentLauncherProperties.getSecurityGroups()))
                            .iamRole(this.titusAgentLauncherProperties.getIAmRole())
                            .build()
                    )
                    .image(this.getTitusImage(resolvedJob))
                    .entryPoint(entryPoint)
                    .command(command)
                    .env(this.createJobEnvironment(jobUser))
                    .attributes(
                        this.binder
                            .bind(
                                TitusAgentLauncherProperties.CONTAINER_ATTRIBUTES_PROPERTY,
                                Bindable.mapOf(String.class, String.class)
                            )
                            .orElse(new HashMap<>())
                    )
                    .build()
            )
            .batch(
                TitusBatchJobRequest.Batch.builder()
                    .size(TITUS_JOB_BATCH_SIZE)
                    .retryPolicy(
                        TitusBatchJobRequest.RetryPolicy.builder()
                            .immediate(
                                TitusBatchJobRequest.Immediate
                                    .builder()
                                    .retries(
                                        this.environment.getProperty(
                                            TitusAgentLauncherProperties.RETRIES_PROPERTY,
                                            Integer.class,
                                            this.titusAgentLauncherProperties.getRetries()
                                        )
                                    )
                                    .build()
                            )
                            .build()
                    )
                    .runtimeLimitSec(runtimeLimit.getSeconds())
                    .build()
            )
            .disruptionBudget(
                TitusBatchJobRequest.DisruptionBudget.builder()
                    .selfManaged(
                        TitusBatchJobRequest.SelfManaged.builder()
                            .relocationTimeMs(runtimeLimit.toMillis())
                            .build()
                    )
                    .build()
            )
            .jobGroupInfo(
                TitusBatchJobRequest.JobGroupInfo.builder()
                    .stack(this.titusAgentLauncherProperties.getStack())
                    .detail(this.titusAgentLauncherProperties.getDetail())
                    .sequence(this.titusAgentLauncherProperties.getSequence())
                    .build()
            );

        final Optional<String> networkConfiguration = validateNetworkConfiguration(this.environment.getProperty(
            TitusAgentLauncherProperties.CONTAINER_NETWORK_MODE,
            String.class));
        networkConfiguration.ifPresent(config -> requestBuilder.networkConfiguration(
                TitusBatchJobRequest.NetworkConfiguration.builder().networkMode(config).build()));

        final TitusBatchJobRequest request = requestBuilder.build();

        // Run the request through the security adapter to add any necessary context
        this.jobRequestAdapter.modifyJobRequest(request, resolvedJob);
        return request;
    }