/*
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 *
 * Code generated by Microsoft (R) AutoRest Code Generator.
 * Changes may cause incorrect behavior and will be lost if the code is
 * regenerated.
 */

'use strict';

/**
 * @summary A task which is run when a compute node joins a pool in the Azure
 * Batch service, or when the compute node is rebooted or reimaged.
  *
 * In some cases the start task may be re-run even though the node was not
 * rebooted. Due to this, start tasks should be idempotent and exit gracefully
 * if the setup they're performing has already been done. Special care should
 * be taken to avoid start tasks which create breakaway process or
 * install/launch services from the start task working directory, as this will
 * block Batch from being able to re-run the start task.
 *
 */
class StartTask {
  /**
   * Create a StartTask.
   * @property {string} [commandLine] The command line of the start task. The
   * command line does not run under a shell, and therefore cannot take
   * advantage of shell features such as environment variable expansion. If you
   * want to take advantage of such features, you should invoke the shell in
   * the command line, for example using "cmd /c MyCommand" in Windows or
   * "/bin/sh -c MyCommand" in Linux. Required if any other properties of the
   * startTask are specified.
   * @property {array} [resourceFiles] A list of files that the Batch service
   * will download to the compute node before running the command line.
   * @property {array} [environmentSettings] A list of environment variable
   * settings for the start task.
   * @property {object} [userIdentity] The user identity under which the start
   * task runs. If omitted, the task runs as a non-administrative user unique
   * to the task.
   * @property {string} [userIdentity.userName] The userName and autoUser
   * properties are mutually exclusive; you must specify one but not both.
   * @property {object} [userIdentity.autoUser] The userName and autoUser
   * properties are mutually exclusive; you must specify one but not both.
   * @property {string} [userIdentity.autoUser.scope] The default value is
   * Pool. If the pool is running Windows a value of Task should be specified
   * if stricter isolation between tasks is required. For example, if the task
   * mutates the registry in a way which could impact other tasks, or if
   * certificates have been specified on the pool which should not be
   * accessible by normal tasks but should be accessible by start tasks.
   * Possible values include: 'Task', 'Pool'
   * @property {string} [userIdentity.autoUser.elevationLevel] The default
   * value is nonAdmin. Possible values include: 'NonAdmin', 'Admin'
   * @property {number} [maxTaskRetryCount] The maximum number of times the
   * task may be retried. The Batch service retries a task if its exit code is
   * nonzero. Note that this value specifically controls the number of retries.
   * The Batch service will try the task once, and may then retry up to this
   * limit. For example, if the maximum retry count is 3, Batch tries the task
   * up to 4 times (one initial try and 3 retries). If the maximum retry count
   * is 0, the Batch service does not retry the task. If the maximum retry
   * count is -1, the Batch service retries the task without limit.
   * @property {boolean} [waitForSuccess] Whether the Batch service should wait
   * for the start task to complete successfully (that is, to exit with exit
   * code 0) before scheduling any tasks on the compute node. If true and the
   * start task fails on a compute node, the Batch service retries the start
   * task up to its maximum retry count (maxTaskRetryCount). If the task has
   * still not completed successfully after all retries, then the Batch service
   * marks the compute node unusable, and will not schedule tasks to it. This
   * condition can be detected via the node state and scheduling error detail.
   * If false, the Batch service will not wait for the start task to complete.
   * In this case, other tasks can start executing on the compute node while
   * the start task is still running; and even if the start task fails, new
   * tasks will continue to be scheduled on the node. The default is true.
   * @property {object} [containerSettings] The settings for the container
   * under which the start task runs. When this is specified, all directories
   * recursively below the AZ_BATCH_NODE_ROOT_DIR (the root of Azure Batch
   * directories on the node) are mapped into the container, all task
   * environment variables are mapped into the container, and the task command
   * line is executed in the container.
   * @property {string} [containerSettings.containerRunOptions] These
   * additional options are supplied as arguments to the "docker create"
   * command, in addition to those controlled by the Batch Service.
   * @property {string} [containerSettings.imageName] This is the full image
   * reference, as would be specified to "docker pull". If no tag is provided
   * as part of the image name, the tag ":latest" is used as a default.
   * @property {object} [containerSettings.registry] This setting can be
   * omitted if was already provided at pool creation.
   * @property {string} [containerSettings.registry.registryServer] If omitted,
   * the default is "docker.io".
   * @property {string} [containerSettings.registry.userName]
   * @property {string} [containerSettings.registry.password]
   * @property {string} [containerSettings.workingDirectory] Possible values
   * include: 'TaskWorkingDirectory', 'ContainerImageDefault'
   */
  constructor() {
  }

  /**
   * Defines the metadata of StartTask
   *
   * @returns {object} metadata of StartTask
   *
   */
  mapper() {
    return {
      required: false,
      serializedName: 'StartTask',
      type: {
        name: 'Composite',
        className: 'StartTask',
        modelProperties: {
          commandLine: {
            required: false,
            serializedName: 'commandLine',
            type: {
              name: 'String'
            }
          },
          resourceFiles: {
            required: false,
            serializedName: 'resourceFiles',
            type: {
              name: 'Sequence',
              element: {
                  required: false,
                  serializedName: 'ResourceFileElementType',
                  type: {
                    name: 'Composite',
                    className: 'ResourceFile'
                  }
              }
            }
          },
          environmentSettings: {
            required: false,
            serializedName: 'environmentSettings',
            type: {
              name: 'Sequence',
              element: {
                  required: false,
                  serializedName: 'EnvironmentSettingElementType',
                  type: {
                    name: 'Composite',
                    className: 'EnvironmentSetting'
                  }
              }
            }
          },
          userIdentity: {
            required: false,
            serializedName: 'userIdentity',
            type: {
              name: 'Composite',
              className: 'UserIdentity'
            }
          },
          maxTaskRetryCount: {
            required: false,
            serializedName: 'maxTaskRetryCount',
            type: {
              name: 'Number'
            }
          },
          waitForSuccess: {
            required: false,
            serializedName: 'waitForSuccess',
            type: {
              name: 'Boolean'
            }
          },
          containerSettings: {
            required: false,
            serializedName: 'containerSettings',
            type: {
              name: 'Composite',
              className: 'TaskContainerSettings'
            }
          }
        }
      }
    };
  }
}

module.exports = StartTask;
