StartTask Class

  • java.lang.Object
    • com.microsoft.azure.batch.protocol.models.StartTask

public class StartTask

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. Batch will retry tasks when a recovery operation is triggered on a compute node. Examples of recovery operations include (but are not limited to) when an unhealthy compute node is rebooted or a compute node disappeared due to host failure. Retries due to recovery operations are independent of and are not counted against the maxTaskRetryCount. Even if the maxTaskRetryCount is 0, an internal retry due to a recovery operation may occur. Because of this, all tasks should be idempotent. This means tasks need to tolerate being interrupted and restarted without causing any corruption or duplicate data. The best practice for long running tasks is to use some form of checkpointing.

Method Summary

Modifier and Type Method and Description
String commandLine()

Get 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. If the command line refers to file paths, it should use a relative path (relative to the task working directory), or use the Batch provided environment variable (https://docs.microsoft.com/en-us/azure/batch/batch-compute-node-environment-variables).

TaskContainerSettings containerSettings()

Get 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.

List<EnvironmentSetting> environmentSettings()

Get the environmentSettings value.

Integer maxTaskRetryCount()

Get 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.

List<ResourceFile> resourceFiles()

Get files listed under this element are located in the task's working directory.

UserIdentity userIdentity()

Get if omitted, the task runs as a non-administrative user unique to the task.

Boolean waitForSuccess()

Get 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 failure info details. 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 false.

StartTask withCommandLine(String commandLine)

Set 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. If the command line refers to file paths, it should use a relative path (relative to the task working directory), or use the Batch provided environment variable (https://docs.microsoft.com/en-us/azure/batch/batch-compute-node-environment-variables).

StartTask withContainerSettings(TaskContainerSettings containerSettings)

Set 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.

StartTask withEnvironmentSettings(List<EnvironmentSetting> environmentSettings)

Set the environmentSettings value.

StartTask withMaxTaskRetryCount(Integer maxTaskRetryCount)

Set 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.

StartTask withResourceFiles(List<ResourceFile> resourceFiles)

Set files listed under this element are located in the task's working directory.

StartTask withUserIdentity(UserIdentity userIdentity)

Set if omitted, the task runs as a non-administrative user unique to the task.

StartTask withWaitForSuccess(Boolean waitForSuccess)

Set 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 failure info details. 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 false.

Method Details

commandLine

public String commandLine()

Get 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. If the command line refers to file paths, it should use a relative path (relative to the task working directory), or use the Batch provided environment variable (https://docs.microsoft.com/en-us/azure/batch/batch-compute-node-environment-variables).

Returns:

the commandLine value

containerSettings

public TaskContainerSettings containerSettings()

Get 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.

Returns:

the containerSettings value

environmentSettings

public List environmentSettings()

Get the environmentSettings value.

Returns:

the environmentSettings value

maxTaskRetryCount

public Integer maxTaskRetryCount()

Get 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.

Returns:

the maxTaskRetryCount value

resourceFiles

public List resourceFiles()

Get files listed under this element are located in the task's working directory.

Returns:

the resourceFiles value

userIdentity

public UserIdentity userIdentity()

Get if omitted, the task runs as a non-administrative user unique to the task.

Returns:

the userIdentity value

waitForSuccess

public Boolean waitForSuccess()

Get 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 failure info details. 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 false.

Returns:

the waitForSuccess value

withCommandLine

public StartTask withCommandLine(String commandLine)

Set 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. If the command line refers to file paths, it should use a relative path (relative to the task working directory), or use the Batch provided environment variable (https://docs.microsoft.com/en-us/azure/batch/batch-compute-node-environment-variables).

Parameters:

commandLine - the commandLine value to set

Returns:

the StartTask object itself.

withContainerSettings

public StartTask withContainerSettings(TaskContainerSettings containerSettings)

Set 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.

Parameters:

containerSettings - the containerSettings value to set

Returns:

the StartTask object itself.

withEnvironmentSettings

public StartTask withEnvironmentSettings(List environmentSettings)

Set the environmentSettings value.

Parameters:

environmentSettings - the environmentSettings value to set

Returns:

the StartTask object itself.

withMaxTaskRetryCount

public StartTask withMaxTaskRetryCount(Integer maxTaskRetryCount)

Set 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.

Parameters:

maxTaskRetryCount - the maxTaskRetryCount value to set

Returns:

the StartTask object itself.

withResourceFiles

public StartTask withResourceFiles(List resourceFiles)

Set files listed under this element are located in the task's working directory.

Parameters:

resourceFiles - the resourceFiles value to set

Returns:

the StartTask object itself.

withUserIdentity

public StartTask withUserIdentity(UserIdentity userIdentity)

Set if omitted, the task runs as a non-administrative user unique to the task.

Parameters:

userIdentity - the userIdentity value to set

Returns:

the StartTask object itself.

withWaitForSuccess

public StartTask withWaitForSuccess(Boolean waitForSuccess)

Set 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 failure info details. 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 false.

Parameters:

waitForSuccess - the waitForSuccess value to set

Returns:

the StartTask object itself.

Applies to