swagger: "2.0"
info:
  description: "PipeDream Accounting Service"
  version: "1.0.0"
  title: "PipeDream Accounting Service"
  contact:
    email: "infrateam@zoox.com"

basePath: "/v0"

tags:
- name: "pipelines"
  description: "Querying and updating the state of pipelines."

paths:

  /metrics:
    get:
      tags:
        - "metrics"
      summary: "accounting endpoint metrics"
      description: "Return prometheus flatten metrics."
      operationId: "getMetrics"
      produces:
      - "text/plain; charset=utf-8"
      responses:
        "200":
          description: OK
          schema:
            type: string

  /pipelines:
    get:
      tags:
        - "pipelines"
      summary: "Query/filter pipelines."
      description: "Returns pipelines based on the provided filters."
      operationId: "queryPipelines"
      produces:
      - "application/json"
      parameters:
        - name: "user"
          in: "query"
          type: "string"
          description: "The user for which to return pipelines"
          required: false
        - name: "name"
          in: "query"
          type: "string"
          description: "The pipeline name to filter by"
          required: false
        - name: "stageName"
          in: "query"
          type: "string"
          description: "The stage name to filter by"
          required: false
        - name: "stageNames"
          in: "query"
          type: "array"
          items:
            type: "string"
          description: "A list of stage names to filter by"
          required: false
        - name: "partition"
          in: "query"
          type: "string"
          description: "The partition to filter by"
          required: false
        - name: "pipeId"
          in: "query"
          type: "string"
          description: "The PipeID to filter by. Can be partial. Prefix matched."
          required: false
        - name: "pipeIds"
          in: "query"
          type: "array"
          items:
            type: "string"
          description: "A list of PipeIds to filter by."
          required: false
        - name: "scheduledBefore"
          in: "query"
          type: "string"
          description: "Retrieve results scheduled on or before this date."
          required: false
        - name: "scheduledAfter"
          in: "query"
          type: "string"
          description: "Retrieve results scheduled on or after this date."
          required: false
        - name: "status"
          in: "query"
          type: "string"
          enum:
            - "PENDING"
            - "RUNNING"
            - "FINISHED"
          required: false
        - name: "includeState"
          in: "query"
          type: "boolean"
          description: "Whether to include state info."
          default: true
          required: false
        - name: "offset"
          in: "query"
          type: "integer"
          description: "The offset at which to return the results.  Use skiptoken instead if you need more precise pagination."
          required: false
        - name: "limit"
          in: "query"
          type: "integer"
          minimum: 1
          maximum: 1000
          default: 100
          description: "The max number of results to return"
          required: false
        - name: "inlinecount"
          in: "query"
          type: "string"
          enum:
            - "allpages"
            - "none"
          required: false
          default: "allpages"
        - name: "skiptoken"
          in: "query"
          type: "string"
          description: "An opaque value describing the key value to start with.  Provides more precise pagination than the offset parameter."
          required: false
        - name: "updatedBefore"
          in: "query"
          type: "string"
          description: "Retrieve results updated on or before this date."
          required: false
        - name: "updatedAfter"
          in: "query"
          type: "string"
          description: "Retrieve results updated on or after this date."
          required: false
      responses:
        "200":
          description: "successful operation"
          schema:
            $ref: "#/definitions/PaginatedPipelineList"
        "400":
          description: "invalid request"
          schema:
            $ref: "#/definitions/ErrorResponse"

  /pipelines/{pipeId}:
    get:
      tags:
        - "pipelines"
      summary: "Get information about a pipeline."
      operationId: "getPipeline"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of desired pipeline."
          required: true
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/Pipeline"
        "404":
          description: "Pipeline not found."
          schema:
            $ref: "#/definitions/ErrorResponse"
    put:
      tags:
        - "pipelines"
      summary: "Create a pipeline."
      operationId: "createPipeline"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of created pipeline."
          required: true
        - name: "pipeline"
          in: "body"
          description: "Pipeline to create."
          required: True
          schema:
            $ref: "#/definitions/Pipeline"
      responses:
        "201":
          description: "successful operation"
          schema:
            $ref: "#/definitions/Pipeline"
        "409":
          description: "PipeID already exists."
          schema:
            $ref: "#/definitions/ErrorResponse"
    patch:
      tags:
        - "pipelines"
      summary: "Update information about a pipeline."
      operationId: "patchPipeline"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of desired pipeline."
          required: true
        - name: "pipeline"
          in: "body"
          description: "Pipeline to update, fields that exist on the request will be overwrite existing fields."
          required: True
          schema:
            $ref: "#/definitions/PipelinePatch"
      responses:
        "200":
          description: "successful operation"
          schema:
            $ref: "#/definitions/Pipeline"
        "404":
          description: "Pipeline not found."
          schema:
            $ref: "#/definitions/ErrorResponse"
    delete:
      tags:
        - "pipelines"
      summary: "Delete a pipeline and associated data."
      operationId: "deletePipeline"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "The PipeId of the desired Pipeline"
          required: true
      responses:
        "204":
          description: "Pipeline deleted."
        "404":
          description: "Pipeline not found."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"

  /pipelines/{pipeId}/links:
    post:
      tags:
        - "pipelines"
      summary: "Append a link to a pipeline"
      operationId: "addPipelineLink"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of pipeline to which to add the link."
          required: true
        - name: "link"
          in: "body"
          description: "Link to append."
          required: True
          schema:
            $ref: "#/definitions/Link"
      responses:
        "201":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/Link"
        "404":
          description: "Pipeline not found."
          schema:
            $ref: "#/definitions/ErrorResponse"

    get:
      tags:
        - "pipelines"
      summary: "Get links for a pipeline."
      operationId: "getPipelineLinks"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of desired pipeline."
          required: true
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/LinkList"
        "404":
          description: "Pipeline not found."
          schema:
            $ref: "#/definitions/ErrorResponse"

  /pipelines/{pipeId}/stages:
    get:
      tags:
        - "pipelines"
      summary: "Get stages for a pipeline."
      operationId: "getPipelineStages"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of desired pipeline."
          required: true
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/StageList"
        "404":
          description: "Pipeline not found."
          schema:
            $ref: "#/definitions/ErrorResponse"
    post:
      tags:
        - "pipelines"
      summary: "Append a stage to a pipeline"
      operationId: "addPipelineStage"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of pipeline to which to add the stage."
          required: true
        - name: "stage"
          in: "body"
          description: "Stage to append."
          required: True
          schema:
            $ref: "#/definitions/Stage"
      responses:
        "201":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/Stage"
        "404":
          description: "Pipeline not found."
          schema:
            $ref: "#/definitions/ErrorResponse"

  /pipelines/{pipeId}/stages/{stageName}:
    patch:
      tags:
        - "pipelines"
      summary: "Updates information about a stage."
      operationId: "patchPipelineStage"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of pipeline for which to update the stage."
          required: true
        - name: "stageName"
          in: "path"
          type: "string"
          description: "Name of stage for which to apply the patch"
          required: true
        - name: "stage"
          in: "body"
          description: "The stage patch to apply."
          required: true
          schema:
            $ref: "#/definitions/StagePatch"
      responses:
        "201":
          description: "Stage successfully updated."
          schema:
            $ref: "#/definitions/Stage"
        "404":
          description: "Stage/Pipeline not found."
          schema:
            $ref: "#/definitions/ErrorResponse"

  /pipelines/{pipeId}/metadata:
    post:
      tags:
        - "pipelines"
      summary: "Append a link to a pipeline"
      operationId: "addPipelineMetadata"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of pipeline to which to add the link."
          required: true
        - name: "metadata"
          in: "body"
          description: "Metadata to append."
          required: True
          schema:
            $ref: "#/definitions/PipelineMetadata"
      responses:
        "201":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/PipelineMetadata"
        "404":
          description: "Pipeline not found."
          schema:
            $ref: "#/definitions/ErrorResponse"

    get:
      tags:
        - "pipelines"
      summary: "Get metadata for a pipeline."
      operationId: "getPipelineMetadata"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of desired pipeline."
          required: true
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/PipelineMetadataList"

  /pipelines/{pipeId}/parameters:
    get:
      tags:
        - "pipelines"
      summary: "Get parameters for a pipeline."
      operationId: "getPipelineParameters"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "Pipeline identifier."
          required: true
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/ParameterList"
        "404":
          description: "Pipeline not found."
          schema:
            $ref: "#/definitions/ErrorResponse"
    post:
      tags:
        - "pipelines"
      summary: "Add parameters of a pipeline."
      operationId: "batchAddPipelineParameters"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "Pipeline identifier."
          required: true
        - name: "parameters"
          in: "body"
          description: "Parameters to add."
          required: True
          schema:
            $ref: "#/definitions/ParameterList"
      responses:
        "201":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/ParameterList"
        "400":
          description: "Bad request."
          schema:
            $ref: "#/definitions/ErrorResponse"

  /pipelines/{pipeId}/parameters/{parameterName}:
    get:
      tags:
        - "pipelines"
      summary: "Get dynamic input parameters for a pipeline stage."
      operationId: "getPipelineParameter"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of desired pipeline."
          required: true
        - name: "parameterName"
          in: "path"
          type: "string"
          description: "Name of parameter to retrieve."
          required: true
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/ParameterList"
        "404":
          description: "Pipeline not found."
          schema:
            $ref: "#/definitions/ErrorResponse"
    post:
      tags:
        - "pipelines"
      summary: "Adds an input parameter value to a stage."
      operationId: "addPipelineParameter"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of desired pipeline."
          required: true
        - name: "parameterName"
          in: "path"
          type: "string"
          description: "Name of the parameter."
          required: true
        - name: "parameter"
          in: "body"
          description: "The parameter's value."
          schema:
            $ref: "#/definitions/Parameter"
          required: true
      responses:
        "201":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/Parameter"
        "400":
          description: "Invalid request."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "404":
          description: "Pipeline or stage not found."
          schema:
            $ref: "#/definitions/ErrorResponse"


  /pipelines/{pipeId}/stages/{stageName}/tasks:
    get:
      tags:
        - "pipelines"
      summary: "Get tasks for a pipeline stage."
      operationId: "getPipelineStageTasks"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of desired pipeline."
          required: true
        - name: "stageName"
          in: "path"
          type: "string"
          description: "Name of stage from whence to retrieve the tasks."
          required: true
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/TaskList"
        "404":
          description: "Pipeline not found."
          schema:
            $ref: "#/definitions/ErrorResponse"
    put:
      tags:
        - "pipelines"
      summary: "Batch append tasks to a pipeline"
      operationId: "batchAddPipelineStageTasks"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of pipeline to which to add the tasks."
          required: true
        - name: "stageName"
          in: "path"
          type: "string"
          description: "Name of stage to which to add the tasks."
          required: true
        - name: "tasks"
          in: "body"
          description: "Tasks to append."
          required: True
          schema:
            $ref: "#/definitions/TaskList"
      responses:
        "201":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/TaskList"
        "400":
          description: "Invalid request."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "404":
          description: "Pipeline or stage not found."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "409":
          description: "Task exists"
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Server error"
          schema:
            $ref: "#/definitions/ErrorResponse"
    patch:
      tags:
        - "pipelines"
      summary: "Update a batch of tasks in a pipeline."
      operationId: "batchPatchPipelineStageTasks"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of pipeline on which to patch the tasks."
          required: true
        - name: "stageName"
          in: "path"
          type: "string"
          description: "Name of stage on which to patch the tasks."
          required: true
        - name: "tasks"
          in: "body"
          description: "Tasks to update, fields that exist on the request will be overwrite existing fields."
          required: True
          schema:
            $ref: "#/definitions/TaskPatchList"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/TaskList"
        "400":
          description: "Invalid request."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "404":
          description: "Pipeline, stage, task, or task index not found."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Server error"
          schema:
            $ref: "#/definitions/ErrorResponse"

  /pipelines/{pipeId}/stages/{stageName}/tasks/{taskIndex}:
    put:
      tags:
        - "pipelines"
      summary: "Append a task to a pipeline"
      operationId: "addPipelineStageTask"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of pipeline to which to add the task."
          required: true
        - name: "stageName"
          in: "path"
          type: "string"
          description: "Name of stage to which to add the task."
          required: true
        - name: "taskIndex"
          in: "path"
          type: "integer"
          format: "int32"
          description: "Task index"
          required: True
        - name: "task"
          in: "body"
          description: "Task to append."
          required: True
          schema:
            $ref: "#/definitions/Task"
      responses:
        "201":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/Task"
        "400":
          description: "Invalid request."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "404":
          description: "Pipeline or stage not found."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "409":
          description: "Task exists"
          schema:
            $ref: "#/definitions/ErrorResponse"
    get:
      tags:
        - "pipelines"
      summary: "Get a task in a pipeline"
      operationId: "getPipelineStageTask"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of pipeline from which to retrieve the task."
          required: true
        - name: "stageName"
          in: "path"
          type: "string"
          description: "Name of stage from which to retrieve the task."
          required: true
        - name: "taskIndex"
          in: "path"
          type: "integer"
          format: "int32"
          description: "Task index"
          required: True
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/Task"
        "404":
          description: "Pipeline, stage, task, or task index not found."
          schema:
            $ref: "#/definitions/ErrorResponse"

    patch:
      tags:
        - "pipelines"
      summary: "Update a task in a pipeline"
      operationId: "patchPipelineStageTask"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of pipeline to which to add the task."
          required: true
        - name: "stageName"
          in: "path"
          type: "string"
          description: "Name of stage to which to add the task."
          required: true
        - name: "taskIndex"
          in: "path"
          type: "integer"
          format: "int32"
          description: "Task index"
          required: True
        - name: "task"
          in: "body"
          description: "Task to update, fields that exist on the request will be overwrite existing fields."
          required: True
          schema:
            $ref: "#/definitions/TaskPatch"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/Task"
        "404":
          description: "Pipeline, stage, task, or task index not found."
          schema:
            $ref: "#/definitions/ErrorResponse"

  /pipelines/{pipeId}/stages/{stageName}/tasks/{taskIndex}/concurrentUnits:
    delete:
      tags:
        - "pipelines"
      summary: "Delete all the concurrent units for a task."
      operationId: "deleteConcurrentUnits"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of pipeline to which to add the task."
          required: true
        - name: "stageName"
          in: "path"
          type: "string"
          description: "Name of stage to which to add the task."
          required: true
        - name: "taskIndex"
          in: "path"
          type: "integer"
          format: "int32"
          description: "Task index"
          required: True
      responses:
        "204":
          description: "CU deleted."
        "404":
          description: "Not found."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"


  /pipelines/{pipeId}/stages/{stageName}/tasks/{taskIndex}/concurentUnits/{concurrentUnitIndex}:
    put:
      tags:
        - "pipelines"
      summary: "Append a concurrent unit to a task"
      operationId: "addPipelineStageTaskConcurrentUnit"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of pipeline to which to add the task."
          required: true
        - name: "stageName"
          in: "path"
          type: "string"
          description: "Name of stage to which to add the task."
          required: true
        - name: "taskIndex"
          in: "path"
          type: "integer"
          format: "int32"
          description: "Task index"
          required: True
        - name: "concurrentUnitIndex"
          in: "path"
          type: "integer"
          format: "int32"
          description: "Concurrent unit index"
          required: True
        - name: "concurrentUnit"
          in: "body"
          description: "CU to append."
          required: True
          schema:
            $ref: "#/definitions/ConcurrentUnit"
      responses:
        "201":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/ConcurrentUnit"
        "400":
          description: "Invalid request."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "404":
          description: "Pipeline or stage not found."
          schema:
            $ref: "#/definitions/ErrorResponse"
    patch:
      tags:
        - "pipelines"
      summary: "Update a ConcurrentUnit in a Pipeline task"
      operationId: "patchPipelineStageTaskConcurrentUnit"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of pipeline to which to add the task."
          required: true
        - name: "stageName"
          in: "path"
          type: "string"
          description: "Name of stage to which to add the task."
          required: true
        - name: "taskIndex"
          in: "path"
          type: "integer"
          format: "int32"
          description: "Task index"
          required: True
        - name: "concurrentUnitIndex"
          in: "path"
          type: "integer"
          format: "int32"
          description: "CU index"
          required: True
        - name: "concurrentUnitPatch"
          in: "body"
          description: "Task to update, fields that exist on the request will be overwrite existing fields."
          required: True
          schema:
            $ref: "#/definitions/ConcurrentUnitPatch"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/ConcurrentUnit"
        "404":
          description: "Pipeline, stage, task, task index, or CU index not found."
          schema:
            $ref: "#/definitions/ErrorResponse"

  /schedulingStatus/{pipeId}:
    get:
      operationId: "getSchedulingStatus"
      produces:
      - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          required: true
      responses:
        "200":
          description: "successful operation"
          schema:
            $ref: "#/definitions/SchedulingStatus"
        "404":
          description: "No status found for the given Pipeline Id"
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error"
          schema:
            $ref: "#/definitions/ErrorResponse"

    put:
      operationId: "setSchedulingStatus"
      produces:
        - "application/json"
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          required: true
        - name: "status"
          in: "body"
          required: true
          schema:
            $ref: "#/definitions/SchedulingStatus"
      responses:
        "201":
          description: "Successful operation"
          schema:
            $ref: "#/definitions/SchedulingStatus"
        "404":
          description: "PipeId not found"
          schema:
            $ref: "#/definitions/ErrorResponse"





definitions:
  Pipeline:
    description: "A Pipeline object stores information about a collection of interconnected tasks."
    allOf:
      - $ref: "#/definitions/PipelinePatch"
      - type: "object"
        properties:
          name:
            type: "string"
            description: "The name of this pipeline."
          versionNum:
            type: "integer"
            format: "int32"
            description: "The configuration version number for this pipeline."
          pipeId:
            type: "string"
            description: "The PipeID for this Pipeline."
          user:
            type: "string"
            description: "The user that scheduled this pipeline."
          state:
            type: "string"
            description: "A human readable state string for the entire pipeline."
            readOnly: True
          terminated:
            type: "boolean"
            description: "A boolean representing whether the pipeline was reported as complete."
            readOnly: True
          scheduleTimestamp:
            type: "string"
            description: "The time that this pipeline was scheduled and put into pipedream queue."
          startTimestamp:
            type: "string"
            description: "The time the first task in this pipeline begins running."
          endTimestamp:
            type: "string"
            description: "The time all tasks in this pipeline completed."
          launchedTimestamp:
            type: "string"
            description: "The time at which the pipeline was launched on slurm."
          pipedreamUrl:
            type: "string"
            description: "The URL for the Piper page for this pipeline."
          subClusterName:
            type: "string"
            description: "The name of the sub-cluster that the pipeline was launched on"
            default: "default"

    required:
      - "name"
      - "versionNum"
      - "user"

  PipelinePatch:
    type: "object"
    properties:
      startTimestamp:
        type: "string"
        description: "The time the first task in this pipeline begins running."
      endTimestamp:
        type: "string"
        description: "The time all tasks in this pipeline completed."
      launchedTimestamp:
        type: "string"
        description: "The time at which the pipeline was launched on slurm."

  Stage:
    type: "object"
    properties:
      name:
        type: "string"
        description: "The name of this stage."
      stageIndex:
        type: "integer"
        format: "int32"
        description: "The position of this stage relative to others in the Pipeline."
      image:
        type: "string"
        description: "The (docker) image this stage requires."
      imageCmd:
        type: "array"
        items:
          type: "string"
          description: "The command to run inside custom images."
      branch:
        type: "string"
        description: "The git branch or (SHA) this stage requires."
      command:
        type: "string"
        description: "The command to run inside the default driving image."
      partitions:
        type: "array"
        items:
          type: "string"
          description: "The partitions to run the stage."
      args:
        type: "array"
        items:
          type: "string"
        description: "The static arguments for this stage."
      inParams:
        type: "array"
        items:
          type: "string"
        description: "The upstream parameters for this stage."
      outParams:
        type: "array"
        items:
          type: "string"
          description: "The exported parameters for this stage."
      environmentVariables:
        type: "array"
        items:
          type: "string"
        description: "The environment variables for this stage."
      autoRetryBudget:
        type: "integer"
        format: "int32"
        description: "The number of times this stage should be retried in case of failure."
      slurmId:
        type: "string"
        description: "The SLURM ID for the job."
    required:
      - "name"
      - "image"
      - "command"
      - "stageIndex"

  StagePatch:
    type: "object"
    properties:
      slurmId:
        type: "string"
        description: "The SLURM ID for the job."

  Task:
    description: "A Task contains information about one running task."
    allOf:
      - $ref: "#/definitions/TaskPatch"
      - type: "object"
        properties:
          logfile:
            type: "string"
            description: "Logfile for this task."
          state:
            type: "string"
            description: "State of the task, set by the server."
          hostname:
            type: "string"
            description: "The hostname of the machine this task ran on. DEPRECATED"
          concurrentUnitCount:
            type: "integer"
            format: "int32"
            description: "The number of hosts in this task."
          gpusPerConcurrentUnit:
            type: "integer"
            format: "int32"
            description: "The number of GPUs for this task."
          portsPerConcurrentUnit:
            type: "integer"
            format: "int32"
            description: "The number of ports per host allocated for this task."
          concurrentUnits:
            type: "array"
            description: "Information about all the concurrent units allocated in this task."
            items:
              $ref: "#/definitions/ConcurrentUnit"
          slurmId:
            type: "string"
            description: "The SLURM ID for the job."
          hostCount:
            type: "integer"
            format: "int32"
            description: "DEPRECATED"
          gpus:
            type: "integer"
            format: "int32"
            description: "DEPRECATED"
          portsPerHost:
            type: "integer"
            format: "int32"
            description: "DEPRECATED"
          progress:
            type: "object"
            description: "Progress state information"
    required:
      - "logfile"

  TaskPatch:
    type: "object"
    properties:
      taskIndex:
        type: "integer"
        format: "int32"
        description: "The index of this task, set by the server from the path parameters"
      slurmId:
        type: "string"
        description: "SLURM ID for this task"
      startTimestamp:
        type: "string"
        description: "The time the task started"
      endTimestamp:
        type: "string"
        description: "The time the task finished."
      exitCode:
        type: "integer"
        format: "int32"
        description: "The status the task exited with"
      hostname:
        type: "string"
        description: "DEPRECATED"
      progress:
        type: "object"
        allOf:
        - $ref: "#/definitions/TaskProgress"
        description: "Progress state information"

  ConcurrentUnit:
    description: "A sub-unit of work within a task. All concurrent units in a Task are run concurrently (hence the name)."
    allOf:
      - $ref: "#/definitions/ConcurrentUnitPatch"
      - type: "object"
        properties:
          concurrentUnitIndex:
            type: "integer"
            format: "int32"
            description: "The host's index inside the task. Not required when creating new records, as the parameter from the path is used."
          hostname:
            type: "string"
            description: "The host's network hostname."
          gpus:
            type: "integer"
            format: "int32"
            description: "The number of GPUs allocated on this CU."
          ports:
            type: "array"
            items:
              type: "integer"
              format: "int32"
            description: "The ports allocated for this CU."
    required:
      - "hostname"

  ConcurrentUnitPatch:
    type: "object"
    properties:
      startTimestamp:
        type: "string"
        description: "The start time for this CU."
      endTimestamp:
        type: "string"
        description: "The end time for this CU."

  PipelineMetadata:
    type: "object"
    properties:
      key:
        type: "string"
      value:
        type: "string"
    required:
      - "key"
      - "value"

  Link:
    type: "object"
    properties:
      text:
        type: "string"
        description: "A human-readable text string for this link."
      url:
        type: "string"
        description: "The link target."
    required:
      - "text"
      - "url"

  Parameter:
    type: "object"
    properties:
      name:
        type: "string"
        description: "The name of the parameter."
      values:
        type: "array"
        items:
          type: "string"
        description: "The value for ths parameter."
      parameterIndex:
        type: "integer"
        format: "int32"
        description: "Index of this particular parameter, usually matches the task index."
    required:
      - "name"
      - "values"
      - "parameterIndex"

  StageList:
    type: "object"
    properties:
      stages:
        type: "array"
        description: "A list of stages in a pipeline."
        items:
          $ref: "#/definitions/Stage"

  LinkList:
    type: "object"
    properties:
      links:
        type: "array"
        description: "A list of links in a Pipeline."
        items:
          $ref: "#/definitions/Link"

  PipelineMetadataList:
    type: "object"
    properties:
      metadata:
        type: "array"
        description: "Client provided key/value annotations."
        items:
          $ref: "#/definitions/PipelineMetadata"

  TaskList:
    type: "object"
    properties:
      tasks:
        type: "array"
        description: "A list of tasks in a pipeline stage."
        items:
          $ref: "#/definitions/Task"

  TaskPatchList:
    type: "object"
    properties:
      tasks:
        type: "array"
        description: "A list of tasks in a pipeline stage."
        items:
          $ref: "#/definitions/TaskPatch"

  TaskProgress:
    type: "object"
    properties:
      percent:
        type: "integer"
        format: "int32"
        description: "Percent completion of task"
      text:
        type: "string"
        description: "Descriptive text for completion state"
      phase:
        type: "string"
        description: "Phase of task completion"
      icon:
        type: "string"
        description: "Descriptive image for completion state"

  ParameterList:
    type: "object"
    properties:
      parameters:
        type: "array"
        description: "A list of Parameters."
        items:
          $ref: "#/definitions/Parameter"

  PaginatedPipelineList:
    type: "object"
    properties:
      pipelines:
        type: "array"
        items:
          $ref: "#/definitions/Pipeline"
      totalResults:
        type: "integer"
        format: "int32"
        description: "The total number of results this query will return.  -1 if inlinecount == none"
      nextLink:
        type: "string"
        description: "URL for next page in the query"

  SchedulingStatus:
    type:  "object"
    properties:
      pipeId:
        type: "string"
      status:
        type: "string"

  ErrorResponse:
    type: "object"
    properties:
      message:
        type: "string"
