xref: /aosp_15_r20/external/googleapis/google/cloud/batch/v1/task.proto (revision d5c09012810ac0c9f33fe448fb6da8260d444cc9)
1// Copyright 2023 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15syntax = "proto3";
16
17package google.cloud.batch.v1;
18
19import "google/api/field_behavior.proto";
20import "google/api/resource.proto";
21import "google/cloud/batch/v1/volume.proto";
22import "google/protobuf/duration.proto";
23import "google/protobuf/timestamp.proto";
24
25option csharp_namespace = "Google.Cloud.Batch.V1";
26option go_package = "cloud.google.com/go/batch/apiv1/batchpb;batchpb";
27option java_multiple_files = true;
28option java_outer_classname = "TaskProto";
29option java_package = "com.google.cloud.batch.v1";
30option objc_class_prefix = "GCB";
31option php_namespace = "Google\\Cloud\\Batch\\V1";
32option ruby_package = "Google::Cloud::Batch::V1";
33
34// Compute resource requirements.
35//
36// ComputeResource defines the amount of resources required for each task.
37// Make sure your tasks have enough resources to successfully run.
38// If you also define the types of resources for a job to use with the
39// [InstancePolicyOrTemplate](https://cloud.google.com/batch/docs/reference/rest/v1/projects.locations.jobs#instancepolicyortemplate)
40// field, make sure both fields are compatible with each other.
41message ComputeResource {
42  // The milliCPU count.
43  //
44  // `cpuMilli` defines the amount of CPU resources per task in milliCPU units.
45  // For example, `1000` corresponds to 1 vCPU per task. If undefined, the
46  // default value is `2000`.
47  //
48  // If you also define the VM's machine type using the `machineType` in
49  // [InstancePolicy](https://cloud.google.com/batch/docs/reference/rest/v1/projects.locations.jobs#instancepolicy)
50  // field or inside the `instanceTemplate` in the
51  // [InstancePolicyOrTemplate](https://cloud.google.com/batch/docs/reference/rest/v1/projects.locations.jobs#instancepolicyortemplate)
52  // field, make sure the CPU resources for both fields are compatible with each
53  // other and with how many tasks you want to allow to run on the same VM at
54  // the same time.
55  //
56  // For example, if you specify the `n2-standard-2` machine type, which has 2
57  // vCPUs each, you are recommended to set `cpuMilli` no more than `2000`, or
58  // you are recommended to run two tasks on the same VM if you set `cpuMilli`
59  // to `1000` or less.
60  int64 cpu_milli = 1;
61
62  // Memory in MiB.
63  //
64  // `memoryMib` defines the amount of memory per task in MiB units.
65  // If undefined, the default value is `2000`.
66  // If you also define the VM's machine type using the `machineType` in
67  // [InstancePolicy](https://cloud.google.com/batch/docs/reference/rest/v1/projects.locations.jobs#instancepolicy)
68  // field or inside the `instanceTemplate` in the
69  // [InstancePolicyOrTemplate](https://cloud.google.com/batch/docs/reference/rest/v1/projects.locations.jobs#instancepolicyortemplate)
70  // field, make sure the memory resources for both fields are compatible with
71  // each other and with how many tasks you want to allow to run on the same VM
72  // at the same time.
73  //
74  // For example, if you specify the `n2-standard-2` machine type, which has 8
75  // GiB each, you are recommended to set `memoryMib` to no more than `8192`,
76  // or you are recommended to run two tasks on the same VM if you set
77  // `memoryMib` to `4096` or less.
78  int64 memory_mib = 2;
79
80  // Extra boot disk size in MiB for each task.
81  int64 boot_disk_mib = 4;
82}
83
84// Status event
85message StatusEvent {
86  // Type of the event.
87  string type = 3;
88
89  // Description of the event.
90  string description = 1;
91
92  // The time this event occurred.
93  google.protobuf.Timestamp event_time = 2;
94
95  // Task Execution
96  TaskExecution task_execution = 4;
97
98  // Task State
99  TaskStatus.State task_state = 5;
100}
101
102// This Task Execution field includes detail information for
103// task execution procedures, based on StatusEvent types.
104message TaskExecution {
105  // When task is completed as the status of FAILED or SUCCEEDED,
106  // exit code is for one task execution result, default is 0 as success.
107  int32 exit_code = 1;
108}
109
110// Status of a task
111message TaskStatus {
112  // Task states.
113  enum State {
114    // Unknown state.
115    STATE_UNSPECIFIED = 0;
116
117    // The Task is created and waiting for resources.
118    PENDING = 1;
119
120    // The Task is assigned to at least one VM.
121    ASSIGNED = 2;
122
123    // The Task is running.
124    RUNNING = 3;
125
126    // The Task has failed.
127    FAILED = 4;
128
129    // The Task has succeeded.
130    SUCCEEDED = 5;
131
132    // The Task has not been executed when the Job finishes.
133    UNEXECUTED = 6;
134  }
135
136  // Task state
137  State state = 1;
138
139  // Detailed info about why the state is reached.
140  repeated StatusEvent status_events = 2;
141}
142
143// Runnable describes instructions for executing a specific script or container
144// as part of a Task.
145message Runnable {
146  // Container runnable.
147  message Container {
148    // The URI to pull the container image from.
149    string image_uri = 1;
150
151    // Overrides the `CMD` specified in the container. If there is an ENTRYPOINT
152    // (either in the container image or with the entrypoint field below) then
153    // commands are appended as arguments to the ENTRYPOINT.
154    repeated string commands = 2;
155
156    // Overrides the `ENTRYPOINT` specified in the container.
157    string entrypoint = 3;
158
159    // Volumes to mount (bind mount) from the host machine files or directories
160    // into the container, formatted to match docker run's --volume option,
161    // e.g. /foo:/bar, or /foo:/bar:ro
162    //
163    // If the `TaskSpec.Volumes` field is specified but this field is not, Batch
164    // will mount each volume from the host machine to the container with the
165    // same mount path by default. In this case, the default mount option for
166    // containers will be read-only (ro) for existing persistent disks and
167    // read-write (rw) for other volume types, regardless of the original mount
168    // options specified in `TaskSpec.Volumes`. If you need different mount
169    // settings, you can explicitly configure them in this field.
170    repeated string volumes = 7;
171
172    // Arbitrary additional options to include in the "docker run" command when
173    // running this container, e.g. "--network host".
174    string options = 8;
175
176    // If set to true, external network access to and from container will be
177    // blocked, containers that are with block_external_network as true can
178    // still communicate with each other, network cannot be specified in the
179    // `container.options` field.
180    bool block_external_network = 9;
181
182    // Required if the container image is from a private Docker registry. The
183    // username to login to the Docker registry that contains the image.
184    //
185    // You can either specify the username directly by using plain text or
186    // specify an encrypted username by using a Secret Manager secret:
187    // `projects/*/secrets/*/versions/*`. However, using a secret is
188    // recommended for enhanced security.
189    //
190    // Caution: If you specify the username using plain text, you risk the
191    // username being exposed to any users who can view the job or its logs.
192    // To avoid this risk, specify a secret that contains the username instead.
193    //
194    // Learn more about [Secret
195    // Manager](https://cloud.google.com/secret-manager/docs/) and [using
196    // Secret Manager with
197    // Batch](https://cloud.google.com/batch/docs/create-run-job-secret-manager).
198    string username = 10;
199
200    // Required if the container image is from a private Docker registry. The
201    // password to login to the Docker registry that contains the image.
202    //
203    // For security, it is strongly recommended to specify an
204    // encrypted password by using a Secret Manager secret:
205    // `projects/*/secrets/*/versions/*`.
206    //
207    // Warning: If you specify the password using plain text, you risk the
208    // password being exposed to any users who can view the job or its logs.
209    // To avoid this risk, specify a secret that contains the password instead.
210    //
211    // Learn more about [Secret
212    // Manager](https://cloud.google.com/secret-manager/docs/) and [using
213    // Secret Manager with
214    // Batch](https://cloud.google.com/batch/docs/create-run-job-secret-manager).
215    string password = 11;
216
217    // Optional. If set to true, this container runnable uses Image streaming.
218    //
219    // Use Image streaming to allow the runnable to initialize without
220    // waiting for the entire container image to download, which can
221    // significantly reduce startup time for large container images.
222    //
223    // When `enableImageStreaming` is set to true, the container
224    // runtime is [containerd](https://containerd.io/) instead of Docker.
225    // Additionally, this container runnable only supports the following
226    // `container` subfields: `imageUri`,
227    // `commands[]`, `entrypoint`, and
228    // `volumes[]`; any other `container` subfields are ignored.
229    //
230    // For more information about the requirements and limitations for using
231    // Image streaming with Batch, see the [`image-streaming`
232    // sample on
233    // GitHub](https://github.com/GoogleCloudPlatform/batch-samples/tree/main/api-samples/image-streaming).
234    bool enable_image_streaming = 12 [(google.api.field_behavior) = OPTIONAL];
235  }
236
237  // Script runnable.
238  message Script {
239    oneof command {
240      // Script file path on the host VM.
241      //
242      // To specify an interpreter, please add a `#!<interpreter>`(also known as
243      // [shebang line](https://en.wikipedia.org/wiki/Shebang_(Unix))) as the
244      // first line of the file.(For example, to execute the script using bash,
245      // `#!/bin/bash` should be the first line of the file. To execute the
246      // script using`Python3`, `#!/usr/bin/env python3` should be the first
247      // line of the file.) Otherwise, the file will by default be executed by
248      // `/bin/sh`.
249      string path = 1;
250
251      // Shell script text.
252      //
253      // To specify an interpreter, please add a `#!<interpreter>\n` at the
254      // beginning of the text.(For example, to execute the script using bash,
255      // `#!/bin/bash\n` should be added. To execute the script using`Python3`,
256      // `#!/usr/bin/env python3\n` should be added.) Otherwise, the script will
257      // by default be executed by `/bin/sh`.
258      string text = 2;
259    }
260  }
261
262  // Barrier runnable blocks until all tasks in a taskgroup reach it.
263  message Barrier {
264    // Barriers are identified by their index in runnable list.
265    // Names are not required, but if present should be an identifier.
266    string name = 1;
267  }
268
269  // The script or container to run.
270  oneof executable {
271    // Container runnable.
272    Container container = 1;
273
274    // Script runnable.
275    Script script = 2;
276
277    // Barrier runnable.
278    Barrier barrier = 6;
279  }
280
281  // Optional. DisplayName is an optional field that can be provided by the
282  // caller. If provided, it will be used in logs and other outputs to identify
283  // the script, making it easier for users to understand the logs. If not
284  // provided the index of the runnable will be used for outputs.
285  string display_name = 10 [(google.api.field_behavior) = OPTIONAL];
286
287  // Normally, a non-zero exit status causes the Task to fail. This flag allows
288  // execution of other Runnables to continue instead.
289  bool ignore_exit_status = 3;
290
291  // This flag allows a Runnable to continue running in the background while the
292  // Task executes subsequent Runnables. This is useful to provide services to
293  // other Runnables (or to provide debugging support tools like SSH servers).
294  bool background = 4;
295
296  // By default, after a Runnable fails, no further Runnable are executed. This
297  // flag indicates that this Runnable must be run even if the Task has already
298  // failed. This is useful for Runnables that copy output files off of the VM
299  // or for debugging.
300  //
301  // The always_run flag does not override the Task's overall max_run_duration.
302  // If the max_run_duration has expired then no further Runnables will execute,
303  // not even always_run Runnables.
304  bool always_run = 5;
305
306  // Environment variables for this Runnable (overrides variables set for the
307  // whole Task or TaskGroup).
308  Environment environment = 7;
309
310  // Timeout for this Runnable.
311  google.protobuf.Duration timeout = 8;
312
313  // Labels for this Runnable.
314  map<string, string> labels = 9;
315}
316
317// Spec of a task
318message TaskSpec {
319  // The sequence of scripts or containers to run for this Task. Each Task using
320  // this TaskSpec executes its list of runnables in order. The Task succeeds if
321  // all of its runnables either exit with a zero status or any that exit with a
322  // non-zero status have the ignore_exit_status flag.
323  //
324  // Background runnables are killed automatically (if they have not already
325  // exited) a short time after all foreground runnables have completed. Even
326  // though this is likely to result in a non-zero exit status for the
327  // background runnable, these automatic kills are not treated as Task
328  // failures.
329  repeated Runnable runnables = 8;
330
331  // ComputeResource requirements.
332  ComputeResource compute_resource = 3;
333
334  // Maximum duration the task should run.
335  // The task will be killed and marked as FAILED if over this limit.
336  // The valid value range for max_run_duration in seconds is [0,
337  // 315576000000.999999999],
338  google.protobuf.Duration max_run_duration = 4;
339
340  // Maximum number of retries on failures.
341  // The default, 0, which means never retry.
342  // The valid value range is [0, 10].
343  int32 max_retry_count = 5;
344
345  // Lifecycle management schema when any task in a task group is failed.
346  // Currently we only support one lifecycle policy.
347  // When the lifecycle policy condition is met,
348  // the action in the policy will execute.
349  // If task execution result does not meet with the defined lifecycle
350  // policy, we consider it as the default policy.
351  // Default policy means if the exit code is 0, exit task.
352  // If task ends with non-zero exit code, retry the task with max_retry_count.
353  repeated LifecyclePolicy lifecycle_policies = 9;
354
355  // Deprecated: please use environment(non-plural) instead.
356  map<string, string> environments = 6 [deprecated = true];
357
358  // Volumes to mount before running Tasks using this TaskSpec.
359  repeated Volume volumes = 7;
360
361  // Environment variables to set before running the Task.
362  Environment environment = 10;
363}
364
365// LifecyclePolicy describes how to deal with task failures
366// based on different conditions.
367message LifecyclePolicy {
368  // Conditions for actions to deal with task failures.
369  message ActionCondition {
370    // Exit codes of a task execution.
371    // If there are more than 1 exit codes,
372    // when task executes with any of the exit code in the list,
373    // the condition is met and the action will be executed.
374    repeated int32 exit_codes = 1;
375  }
376
377  // Action on task failures based on different conditions.
378  enum Action {
379    // Action unspecified.
380    ACTION_UNSPECIFIED = 0;
381
382    // Action that tasks in the group will be scheduled to re-execute.
383    RETRY_TASK = 1;
384
385    // Action that tasks in the group will be stopped immediately.
386    FAIL_TASK = 2;
387  }
388
389  // Action to execute when ActionCondition is true.
390  // When RETRY_TASK is specified, we will retry failed tasks
391  // if we notice any exit code match and fail tasks if no match is found.
392  // Likewise, when FAIL_TASK is specified, we will fail tasks
393  // if we notice any exit code match and retry tasks if no match is found.
394  Action action = 1;
395
396  // Conditions that decide why a task failure is dealt with a specific action.
397  ActionCondition action_condition = 2;
398}
399
400// A Cloud Batch task.
401message Task {
402  option (google.api.resource) = {
403    type: "batch.googleapis.com/Task"
404    pattern: "projects/{project}/locations/{location}/jobs/{job}/taskGroups/{task_group}/tasks/{task}"
405  };
406
407  // Task name.
408  // The name is generated from the parent TaskGroup name and 'id' field.
409  // For example:
410  // "projects/123456/locations/us-west1/jobs/job01/taskGroups/group01/tasks/task01".
411  string name = 1;
412
413  // Task Status.
414  TaskStatus status = 2;
415}
416
417// An Environment describes a collection of environment variables to set when
418// executing Tasks.
419message Environment {
420  message KMSEnvMap {
421    // The name of the KMS key that will be used to decrypt the cipher text.
422    string key_name = 1;
423
424    // The value of the cipherText response from the `encrypt` method.
425    string cipher_text = 2;
426  }
427
428  // A map of environment variable names to values.
429  map<string, string> variables = 1;
430
431  // A map of environment variable names to Secret Manager secret names.
432  // The VM will access the named secrets to set the value of each environment
433  // variable.
434  map<string, string> secret_variables = 2;
435
436  // An encrypted JSON dictionary where the key/value pairs correspond to
437  // environment variable names and their values.
438  KMSEnvMap encrypted_variables = 3;
439}
440