R/JobRequest.r

# Agave Platform Science API
#
# Power your digital lab and reduce the time from theory to discovery using the Agave Science-as-a-Service API Platform. Agave provides hosted services that allow researchers to manage data, conduct experiments, and publish and share results from anywhere at any time.
#
# Agave Platform version: 2.2.14
# 
# Generated by: https://github.com/swagger-api/swagger-codegen.git


#' JobRequest Class
#'
#' A request to run a registered app.
#'
#' @field appId The unique name of the application being run by this job. This must be a valid application that the calling user has permission to run.
#' @field archive Whether the output from this job should be archived. If true, all new files created by this application's execution will be archived to the archivePath in the user's default storage system.
#' @field archivePath The path of the archive folder for this job on default storage sytem of the user
#' @field archiveSystem The unique id of the storage system on which this job output will be staged.
#' @field batchQueue The queue to which this job should be submitted. This is optional and only applies when the execution system has a batch scheduler.
#' @field inputs The application specific input files needed for this job. These vary from application to application and should be entered as multiple individual parameters in the form. Inputs may be given as relative paths in the user's default storage system or as URI. If a URI is given, the data will be staged in by the IO service and made avaialble to the application at run time.
#' @field memoryPerNode The requested memory for this application to run given in GB.
#' @field name The name of the job.
#' @field nodeCount The number of processors this application should utilize while running. If the application is not of executionType PARALLEL, this should be 1.
#' @field notifications An array of notifications you wish to receive.
#' @field parameters The application specific parameters needed for this job. These vary from application to application and should be entered as multiple individual parameters in the form. The actual dataType will be determined by the application description.
#' @field processorsPerNode The number of processors this application should utilize while running. If the application is not of executionType PARALLEL, this should be 1.
#' @field maxRunTime The requested compute time needed for this application to complete given in HH:mm:ss format.
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
JobRequest <- R6::R6Class(
  'JobRequest',
  public = list(
    `appId` = NULL,
    `archive` = NULL,
    `archivePath` = NULL,
    `archiveSystem` = NULL,
    `batchQueue` = NULL,
    `inputs` = NULL,
    `memoryPerNode` = NULL,
    `name` = NULL,
    `nodeCount` = NULL,
    `notifications` = NULL,
    `parameters` = NULL,
    `processorsPerNode` = NULL,
    `maxRunTime` = NULL,
    initialize = function(`appId`, `archive`, `archivePath`, `archiveSystem`, `batchQueue`, `inputs`, `memoryPerNode`, `name`, `nodeCount`, `notifications`, `parameters`, `processorsPerNode`, `maxRunTime`){
      if (!missing(`appId`)) {
        stopifnot(is.character(`appId`), length(`appId`) == 1)
        self$`appId` <- `appId`
      }
      if (!missing(`archive`)) {
        self$`archive` <- `archive`
      }
      if (!missing(`archivePath`)) {
        stopifnot(is.character(`archivePath`), length(`archivePath`) == 1)
        self$`archivePath` <- `archivePath`
      }
      if (!missing(`archiveSystem`)) {
        stopifnot(is.character(`archiveSystem`), length(`archiveSystem`) == 1)
        self$`archiveSystem` <- `archiveSystem`
      }
      if (!missing(`batchQueue`)) {
        stopifnot(is.character(`batchQueue`), length(`batchQueue`) == 1)
        self$`batchQueue` <- `batchQueue`
      }
      if (!missing(`inputs`)) {
        stopifnot(R6::is.R6(`inputs`))
        self$`inputs` <- `inputs`
      }
      if (!missing(`memoryPerNode`)) {
        stopifnot(is.numeric(`memoryPerNode`), length(`memoryPerNode`) == 1)
        self$`memoryPerNode` <- `memoryPerNode`
      }
      if (!missing(`name`)) {
        stopifnot(is.character(`name`), length(`name`) == 1)
        self$`name` <- `name`
      }
      if (!missing(`nodeCount`)) {
        stopifnot(is.numeric(`nodeCount`), length(`nodeCount`) == 1)
        self$`nodeCount` <- `nodeCount`
      }
      if (!missing(`notifications`)) {
        stopifnot(is.list(`notifications`), length(`notifications`) != 0)
        lapply(`notifications`, function(x) stopifnot(R6::is.R6(x)))
        self$`notifications` <- `notifications`
      }
      if (!missing(`parameters`)) {
        stopifnot(R6::is.R6(`parameters`))
        self$`parameters` <- `parameters`
      }
      if (!missing(`processorsPerNode`)) {
        stopifnot(is.numeric(`processorsPerNode`), length(`processorsPerNode`) == 1)
        self$`processorsPerNode` <- `processorsPerNode`
      }
      if (!missing(`maxRunTime`)) {
        stopifnot(is.character(`maxRunTime`), length(`maxRunTime`) == 1)
        self$`maxRunTime` <- `maxRunTime`
      }
    },
    asJSON = function() {
      self$toJSON()
    },
    toJSON = function() {
      JobRequestObject <- list()
      if (!is.null(self$`appId`)) {
        JobRequestObject[['appId']] <- self$`appId`
      }
      else {
        JobRequestObject[['appId']] <- NULL
      }
      if (!is.null(self$`archive`)) {
        JobRequestObject[['archive']] <- self$`archive`
      }
      else {
        JobRequestObject[['archive']] <- NULL
      }
      if (!is.null(self$`archivePath`)) {
        JobRequestObject[['archivePath']] <- self$`archivePath`
      }
      else {
        JobRequestObject[['archivePath']] <- NULL
      }
      if (!is.null(self$`archiveSystem`)) {
        JobRequestObject[['archiveSystem']] <- self$`archiveSystem`
      }
      else {
        JobRequestObject[['archiveSystem']] <- NULL
      }
      if (!is.null(self$`batchQueue`)) {
        JobRequestObject[['batchQueue']] <- self$`batchQueue`
      }
      else {
        JobRequestObject[['batchQueue']] <- NULL
      }
      if (!is.null(self$`inputs`)) {
        JobRequestObject[['inputs']] <- self$`inputs`$toJSON()
      }
      else {
        JobRequestObject[['inputs']] <- NULL
      }
      if (!is.null(self$`memoryPerNode`)) {
        JobRequestObject[['memoryPerNode']] <- self$`memoryPerNode`
      }
      else {
        JobRequestObject[['memoryPerNode']] <- NULL
      }
      if (!is.null(self$`name`)) {
        JobRequestObject[['name']] <- self$`name`
      }
      else {
        JobRequestObject[['name']] <- NULL
      }
      if (!is.null(self$`nodeCount`)) {
        JobRequestObject[['nodeCount']] <- self$`nodeCount`
      }
      else {
        JobRequestObject[['nodeCount']] <- NULL
      }
      if (!is.null(self$`notifications`)) {
        JobRequestObject[['notifications']] <- lapply(self$`notifications`, function(x) x$toJSON())
      }
      else {
        JobRequestObject[['notifications']] <- NULL
      }
      if (!is.null(self$`parameters`)) {
        JobRequestObject[['parameters']] <- self$`parameters`$toJSON()
      }
      else {
        JobRequestObject[['parameters']] <- NULL
      }
      if (!is.null(self$`processorsPerNode`)) {
        JobRequestObject[['processorsPerNode']] <- self$`processorsPerNode`
      }
      else {
        JobRequestObject[['processorsPerNode']] <- NULL
      }
      if (!is.null(self$`maxRunTime`)) {
        JobRequestObject[['maxRunTime']] <- self$`maxRunTime`
      }
      else {
        JobRequestObject[['maxRunTime']] <- NULL
      }

      JobRequestObject
    },
    fromJSON = function(JobRequestObject) {
      if (is.character(JobRequestObject)) {
        JobRequestObject <- jsonlite::fromJSON(JobRequestJson)
      }

      if ("result" %in% names(JobRequestObject)) {
        JobRequestObject <- JobRequestObject$result
      }

      if (!is.null(JobRequestObject$`appId`)) {
        self$`appId` <- JobRequestObject$`appId`
      }
      if (!is.null(JobRequestObject$`archive`)) {
        self$`archive` <- JobRequestObject$`archive`
      }
      if (!is.null(JobRequestObject$`archivePath`)) {
        self$`archivePath` <- JobRequestObject$`archivePath`
      }
      if (!is.null(JobRequestObject$`archiveSystem`)) {
        self$`archiveSystem` <- JobRequestObject$`archiveSystem`
      }
      if (!is.null(JobRequestObject$`batchQueue`)) {
        self$`batchQueue` <- JobRequestObject$`batchQueue`
      }
      if (!is.null(JobRequestObject$`inputs`)) {
        inputsObject <- TODO_OBJECT_MAPPING$new()
        inputsObject$fromJSON(jsonlite::toJSON(JobRequestObject$inputs, auto_unbox = TRUE))
        self$`inputs` <- inputsObject
      }
      if (!is.null(JobRequestObject$`memoryPerNode`)) {
        self$`memoryPerNode` <- JobRequestObject$`memoryPerNode`
      }
      if (!is.null(JobRequestObject$`name`)) {
        self$`name` <- JobRequestObject$`name`
      }
      if (!is.null(JobRequestObject$`nodeCount`)) {
        self$`nodeCount` <- JobRequestObject$`nodeCount`
      }
      if (!is.null(JobRequestObject$`notifications`)) {
        self$`notifications` <- lapply(JobRequestObject$`notifications`, function(x) {
          notificationsObject <- Notification$new()
          notificationsObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
          notificationsObject
        })
      }
      if (!is.null(JobRequestObject$`parameters`)) {
        parametersObject <- TODO_OBJECT_MAPPING$new()
        parametersObject$fromJSON(jsonlite::toJSON(JobRequestObject$parameters, auto_unbox = TRUE))
        self$`parameters` <- parametersObject
      }
      if (!is.null(JobRequestObject$`processorsPerNode`)) {
        self$`processorsPerNode` <- JobRequestObject$`processorsPerNode`
      }
      if (!is.null(JobRequestObject$`maxRunTime`)) {
        self$`maxRunTime` <- JobRequestObject$`maxRunTime`
      }
    },
    toJSONString = function() {
       sprintf(
        '{
           "appId": %s,
           "archive": %s,
           "archivePath": %s,
           "archiveSystem": %s,
           "batchQueue": %s,
           "inputs": %s,
           "memoryPerNode": %d,
           "name": %s,
           "nodeCount": %d,
           "notifications": [%s],
           "parameters": %s,
           "processorsPerNode": %d,
           "maxRunTime": %s
        }',
        ifelse( is.null(self$`appId`),"null",paste0(c('"', self$`appId`, '"'))),
        ifelse( is.null(self$`archive`),"null",paste0(c('"', self$`archive`, '"'))),
        ifelse( is.null(self$`archivePath`),"null",paste0(c('"', self$`archivePath`, '"'))),
        ifelse( is.null(self$`archiveSystem`),"null",paste0(c('"', self$`archiveSystem`, '"'))),
        ifelse( is.null(self$`batchQueue`),"null",paste0(c('"', self$`batchQueue`, '"'))),
        self$`inputs`$toJSON(),
        ifelse( is.null(self$`memoryPerNode`),"null",paste0(c('"', self$`memoryPerNode`, '"'))),
        ifelse( is.null(self$`name`),"null",paste0(c('"', self$`name`, '"'))),
        ifelse( is.null(self$`nodeCount`),"null",paste0(c('"', self$`nodeCount`, '"'))),
        lapply(self$`notifications`, function(x) paste(x$toJSON(), sep=",")),
        self$`parameters`$toJSON(),
        ifelse( is.null(self$`processorsPerNode`),"null",paste0(c('"', self$`processorsPerNode`, '"'))),
        ifelse( is.null(self$`maxRunTime`),"null",paste0(c('"', self$`maxRunTime`, '"')))
      )
    },
    fromJSONString = function(JobRequestJson) {
      JobRequestObject <- jsonlite::fromJSON(JobRequestJson)
      self::fromJSON(JobRequestObject)

    }
  )
)
agaveplatform/r-sdk documentation built on May 13, 2019, 8:20 a.m.