Share via


StartTask Class

  • java.lang.Object
    • com.azure.resourcemanager.batch.models.StartTask

Implements

public final class StartTask
implements JsonSerializable<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. 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.

Constructor Summary

Constructor Description
StartTask()

Creates an instance of StartTask class.

Method Summary

Modifier and Type Method and Description
String commandLine()

Get the commandLine property: The command line does not run under a shell, and therefore cannot take advantage of shell features such as environment variable expansion.

TaskContainerSettings containerSettings()

Get the containerSettings property: 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 property: A list of environment variable settings for the start task.

static StartTask fromJson(JsonReader jsonReader)

Reads an instance of StartTask from the JsonReader.

Integer maxTaskRetryCount()

Get the maxTaskRetryCount property: The Batch service retries a task if its exit code is nonzero.

List<ResourceFile> resourceFiles()

Get the resourceFiles property: A list of files that the Batch service will download to the compute node before running the command line.

JsonWriter toJson(JsonWriter jsonWriter)
UserIdentity userIdentity()

Get the userIdentity property: If omitted, the task runs as a non-administrative user unique to the task.

void validate()

Validates the instance.

Boolean waitForSuccess()

Get the waitForSuccess property: 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).

StartTask withCommandLine(String commandLine)

Set the commandLine property: The command line does not run under a shell, and therefore cannot take advantage of shell features such as environment variable expansion.

StartTask withContainerSettings(TaskContainerSettings containerSettings)

Set the containerSettings property: 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 property: A list of environment variable settings for the start task.

StartTask withMaxTaskRetryCount(Integer maxTaskRetryCount)

Set the maxTaskRetryCount property: The Batch service retries a task if its exit code is nonzero.

StartTask withResourceFiles(List<ResourceFile> resourceFiles)

Set the resourceFiles property: A list of files that the Batch service will download to the compute node before running the command line.

StartTask withUserIdentity(UserIdentity userIdentity)

Set the userIdentity property: If omitted, the task runs as a non-administrative user unique to the task.

StartTask withWaitForSuccess(Boolean waitForSuccess)

Set the waitForSuccess property: 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).

Methods inherited from java.lang.Object

Constructor Details

StartTask

public StartTask()

Creates an instance of StartTask class.

Method Details

commandLine

public String commandLine()

Get the commandLine property: 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.

Returns:

the commandLine value.

containerSettings

public TaskContainerSettings containerSettings()

Get the containerSettings property: 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<EnvironmentSetting> environmentSettings()

Get the environmentSettings property: A list of environment variable settings for the start task.

Returns:

the environmentSettings value.

fromJson

public static StartTask fromJson(JsonReader jsonReader)

Reads an instance of StartTask from the JsonReader.

Parameters:

jsonReader - The JsonReader being read.

Returns:

An instance of StartTask if the JsonReader was pointing to an instance of it, or null if it was pointing to JSON null.

Throws:

IOException

- If an error occurs while reading the StartTask.

maxTaskRetryCount

public Integer maxTaskRetryCount()

Get the maxTaskRetryCount property: 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. Default is 0.

Returns:

the maxTaskRetryCount value.

resourceFiles

public List<ResourceFile> resourceFiles()

Get the resourceFiles property: A list of files that the Batch service will download to the compute node before running the command line.

Returns:

the resourceFiles value.

toJson

public JsonWriter toJson(JsonWriter jsonWriter)

Parameters:

jsonWriter

Throws:

userIdentity

public UserIdentity userIdentity()

Get the userIdentity property: If omitted, the task runs as a non-administrative user unique to the task.

Returns:

the userIdentity value.

validate

public void validate()

Validates the instance.

waitForSuccess

public Boolean waitForSuccess()

Get the waitForSuccess property: 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.

Returns:

the waitForSuccess value.

withCommandLine

public StartTask withCommandLine(String commandLine)

Set the commandLine property: 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.

Parameters:

commandLine - the commandLine value to set.

Returns:

the StartTask object itself.

withContainerSettings

public StartTask withContainerSettings(TaskContainerSettings containerSettings)

Set the containerSettings property: 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<EnvironmentSetting> environmentSettings)

Set the environmentSettings property: A list of environment variable settings for the start task.

Parameters:

environmentSettings - the environmentSettings value to set.

Returns:

the StartTask object itself.

withMaxTaskRetryCount

public StartTask withMaxTaskRetryCount(Integer maxTaskRetryCount)

Set the maxTaskRetryCount property: 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. Default is 0.

Parameters:

maxTaskRetryCount - the maxTaskRetryCount value to set.

Returns:

the StartTask object itself.

withResourceFiles

public StartTask withResourceFiles(List<ResourceFile> resourceFiles)

Set the resourceFiles property: A list of files that the Batch service will download to the compute node before running the command line.

Parameters:

resourceFiles - the resourceFiles value to set.

Returns:

the StartTask object itself.

withUserIdentity

public StartTask withUserIdentity(UserIdentity userIdentity)

Set the userIdentity property: 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 the waitForSuccess property: 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.

Parameters:

waitForSuccess - the waitForSuccess value to set.

Returns:

the StartTask object itself.

Applies to