All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.genie.common.internal.dtos.ApiJobRequest Maven / Gradle / Ivy

There is a newer version: 4.3.20
Show newest version
/*
 *
 *  Copyright 2018 Netflix, Inc.
 *
 *     Licensed under the Apache License, Version 2.0 (the "License");
 *     you may not use this file except in compliance with the License.
 *     You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *     Unless required by applicable law or agreed to in writing, software
 *     distributed under the License is distributed on an "AS IS" BASIS,
 *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *     See the License for the specific language governing permissions and
 *     limitations under the License.
 *
 */
package com.netflix.genie.common.internal.dtos;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.collect.Lists;
import lombok.AccessLevel;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.Nullable;
import java.util.List;

/**
 * The builder and methods available for a request generated by a REST API request.
 *
 * @author tgianos
 * @since 4.0.0
 */
@JsonDeserialize(builder = ApiJobRequest.Builder.class)
public interface ApiJobRequest extends CommonRequest {

    /**
     * Get the command arguments a user has requested be appended to a command executable for their job.
     *
     * @return The command arguments as an immutable list. Any attempt to modify will throw exception
     */
    List getCommandArgs();

    /**
     * Get the metadata a user has supplied for the job including things like name, tags, etc.
     *
     * @return The metadata
     */
    JobMetadata getMetadata();

    /**
     * The resource criteria that was supplied for the job.
     *
     * @return The criteria used to select the cluster, command and optionally applications for the job
     */
    ExecutionResourceCriteria getCriteria();

    /**
     * Get the environment parameters the user requested to be associated with the Agent.
     *
     * @return The requested agent environment
     */
    JobEnvironmentRequest getRequestedJobEnvironment();

    /**
     * Get the requested agent configuration.
     *
     * @return The requested agent configuration parameters
     */
    AgentConfigRequest getRequestedAgentConfig();

    /**
     * Builder for a V4 Job Request.
     *
     * @author tgianos
     * @since 4.0.0
     */
    @Getter(AccessLevel.PACKAGE)
    class Builder extends CommonRequestImpl.Builder {

        private final JobMetadata bMetadata;
        private final ExecutionResourceCriteria bCriteria;
        private final List bCommandArgs = Lists.newArrayList();
        private JobEnvironmentRequest bRequestedJobEnvironment;
        private AgentConfigRequest bRequestedAgentConfig;

        /**
         * Constructor with required parameters.
         *
         * @param metadata All user supplied metadata
         * @param criteria All user supplied execution criteria
         */
        @JsonCreator
        public Builder(
            @JsonProperty(value = "metadata", required = true) final JobMetadata metadata,
            @JsonProperty(value = "criteria", required = true) final ExecutionResourceCriteria criteria
        ) {
            super();
            this.bMetadata = metadata;
            this.bCriteria = criteria;
        }

        /**
         * Set the ordered list of command line arguments to append to the command executable at runtime.
         *
         * @param commandArgs The arguments in the order they should be placed on the command line. Maximum of 10,000
         *                    characters per argument. Any blanks will be removed
         * @return The builder
         */
        public Builder withCommandArgs(@Nullable final List commandArgs) {
            this.bCommandArgs.clear();
            if (commandArgs != null) {
                commandArgs.stream().filter(StringUtils::isNotBlank).forEach(this.bCommandArgs::add);
            }
            return this;
        }

        /**
         * Set the information provided by a user for the Agent execution environment.
         *
         * @param requestedJobEnvironment the requested Genie job environment parameters
         * @return The builder
         */
        public Builder withRequestedAgentEnvironment(
            @Nullable final JobEnvironmentRequest requestedJobEnvironment
        ) {
            this.bRequestedJobEnvironment = requestedJobEnvironment;
            return this;
        }

        /**
         * Set the configuration requested for the agent when this job is executed.
         *
         * @param requestedAgentConfig The requested configuration
         * @return The builder
         */
        public Builder withRequestedAgentConfig(@Nullable final AgentConfigRequest requestedAgentConfig) {
            this.bRequestedAgentConfig = requestedAgentConfig;
            return this;
        }

        /**
         * Build an immutable job request instance.
         *
         * @return An immutable representation of the user supplied information for a job request
         */
        public ApiJobRequest build() {
            return new JobRequest(this);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy