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