task.proto 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. // Copyright 2022 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. syntax = "proto3";
  15. package google.cloud.batch.v1;
  16. import "google/api/resource.proto";
  17. import "google/cloud/batch/v1/volume.proto";
  18. import "google/protobuf/duration.proto";
  19. import "google/protobuf/timestamp.proto";
  20. option csharp_namespace = "Google.Cloud.Batch.V1";
  21. option go_package = "google.golang.org/genproto/googleapis/cloud/batch/v1;batch";
  22. option java_multiple_files = true;
  23. option java_outer_classname = "TaskProto";
  24. option java_package = "com.google.cloud.batch.v1";
  25. option objc_class_prefix = "GCB";
  26. option php_namespace = "Google\\Cloud\\Batch\\V1";
  27. option ruby_package = "Google::Cloud::Batch::V1";
  28. // Compute resource requirements
  29. message ComputeResource {
  30. // The milliCPU count.
  31. int64 cpu_milli = 1;
  32. // Memory in MiB.
  33. int64 memory_mib = 2;
  34. // Extra boot disk size in MiB for each task.
  35. int64 boot_disk_mib = 4;
  36. }
  37. // Status event
  38. message StatusEvent {
  39. // Type of the event.
  40. string type = 3;
  41. // Description of the event.
  42. string description = 1;
  43. // The time this event occurred.
  44. google.protobuf.Timestamp event_time = 2;
  45. // Task Execution
  46. TaskExecution task_execution = 4;
  47. }
  48. // This Task Execution field includes detail information for
  49. // task execution procedures, based on StatusEvent types.
  50. message TaskExecution {
  51. // When task is completed as the status of FAILED or SUCCEEDED,
  52. // exit code is for one task execution result, default is 0 as success.
  53. int32 exit_code = 1;
  54. }
  55. // Status of a task
  56. message TaskStatus {
  57. // Task states.
  58. enum State {
  59. // unknown state
  60. STATE_UNSPECIFIED = 0;
  61. // The Task is created and waiting for resources.
  62. PENDING = 1;
  63. // The Task is assigned to at least one VM.
  64. ASSIGNED = 2;
  65. // The Task is running.
  66. RUNNING = 3;
  67. // The Task has failed.
  68. FAILED = 4;
  69. // The Task has succeeded.
  70. SUCCEEDED = 5;
  71. }
  72. // Task state
  73. State state = 1;
  74. // Detailed info about why the state is reached.
  75. repeated StatusEvent status_events = 2;
  76. }
  77. // Runnable describes instructions for executing a specific script or container
  78. // as part of a Task.
  79. message Runnable {
  80. // Container runnable.
  81. message Container {
  82. // The URI to pull the container image from.
  83. string image_uri = 1;
  84. // Overrides the `CMD` specified in the container. If there is an ENTRYPOINT
  85. // (either in the container image or with the entrypoint field below) then
  86. // commands are appended as arguments to the ENTRYPOINT.
  87. repeated string commands = 2;
  88. // Overrides the `ENTRYPOINT` specified in the container.
  89. string entrypoint = 3;
  90. // Volumes to mount (bind mount) from the host machine files or directories
  91. // into the container, formatted to match docker run's --volume option,
  92. // e.g. /foo:/bar, or /foo:/bar:ro
  93. repeated string volumes = 7;
  94. // Arbitrary additional options to include in the "docker run" command when
  95. // running this container, e.g. "--network host".
  96. string options = 8;
  97. // If set to true, external network access to and from container will be
  98. // blocked. The container will use the default internal network
  99. // 'goog-internal'.
  100. bool block_external_network = 9;
  101. // Optional username for logging in to a docker registry. If username
  102. // matches `projects/*/secrets/*/versions/*` then Batch will read the
  103. // username from the Secret Manager.
  104. string username = 10;
  105. // Optional password for logging in to a docker registry. If password
  106. // matches `projects/*/secrets/*/versions/*` then Batch will read the
  107. // password from the Secret Manager;
  108. string password = 11;
  109. }
  110. // Script runnable.
  111. message Script {
  112. oneof command {
  113. // Script file path on the host VM.
  114. string path = 1;
  115. // Shell script text.
  116. string text = 2;
  117. }
  118. }
  119. // Barrier runnable blocks until all tasks in a taskgroup reach it.
  120. message Barrier {
  121. // Barriers are identified by their index in runnable list.
  122. // Names are not required, but if present should be an identifier.
  123. string name = 1;
  124. }
  125. // The script or container to run.
  126. oneof executable {
  127. // Container runnable.
  128. Container container = 1;
  129. // Script runnable.
  130. Script script = 2;
  131. // Barrier runnable.
  132. Barrier barrier = 6;
  133. }
  134. // Normally, a non-zero exit status causes the Task to fail. This flag allows
  135. // execution of other Runnables to continue instead.
  136. bool ignore_exit_status = 3;
  137. // This flag allows a Runnable to continue running in the background while the
  138. // Task executes subsequent Runnables. This is useful to provide services to
  139. // other Runnables (or to provide debugging support tools like SSH servers).
  140. bool background = 4;
  141. // By default, after a Runnable fails, no further Runnable are executed. This
  142. // flag indicates that this Runnable must be run even if the Task has already
  143. // failed. This is useful for Runnables that copy output files off of the VM
  144. // or for debugging.
  145. //
  146. // The always_run flag does not override the Task's overall max_run_duration.
  147. // If the max_run_duration has expired then no further Runnables will execute,
  148. // not even always_run Runnables.
  149. bool always_run = 5;
  150. // Environment variables for this Runnable (overrides variables set for the
  151. // whole Task or TaskGroup).
  152. Environment environment = 7;
  153. // Timeout for this Runnable.
  154. google.protobuf.Duration timeout = 8;
  155. }
  156. // Spec of a task
  157. message TaskSpec {
  158. // The sequence of scripts or containers to run for this Task. Each Task using
  159. // this TaskSpec executes its list of runnables in order. The Task succeeds if
  160. // all of its runnables either exit with a zero status or any that exit with a
  161. // non-zero status have the ignore_exit_status flag.
  162. //
  163. // Background runnables are killed automatically (if they have not already
  164. // exited) a short time after all foreground runnables have completed. Even
  165. // though this is likely to result in a non-zero exit status for the
  166. // background runnable, these automatic kills are not treated as Task
  167. // failures.
  168. repeated Runnable runnables = 8;
  169. // ComputeResource requirements.
  170. ComputeResource compute_resource = 3;
  171. // Maximum duration the task should run.
  172. // The task will be killed and marked as FAILED if over this limit.
  173. google.protobuf.Duration max_run_duration = 4;
  174. // Maximum number of retries on failures.
  175. // The default, 0, which means never retry.
  176. // The valid value range is [0, 10].
  177. int32 max_retry_count = 5;
  178. // Lifecycle management schema when any task in a task group is failed.
  179. // The valid size of lifecycle policies are [0, 10].
  180. // For each lifecycle policy, when the condition is met,
  181. // the action in that policy will execute.
  182. // If there are multiple policies that the task execution result matches,
  183. // we use the action from the first matched policy. If task execution result
  184. // does not meet with any of the defined lifecycle policy, we consider it as
  185. // the default policy. Default policy means if the exit code is 0, exit task.
  186. // If task ends with non-zero exit code, retry the task with max_retry_count.
  187. repeated LifecyclePolicy lifecycle_policies = 9;
  188. // Environment variables to set before running the Task.
  189. // You can set up to 100 environments.
  190. map<string, string> environments = 6 [deprecated = true];
  191. // Volumes to mount before running Tasks using this TaskSpec.
  192. repeated Volume volumes = 7;
  193. // Environment variables to set before running the Task.
  194. Environment environment = 10;
  195. }
  196. // LifecyclePolicy describes how to deal with task failures
  197. // based on different conditions.
  198. message LifecyclePolicy {
  199. // Conditions for actions to deal with task failures.
  200. message ActionCondition {
  201. // Exit codes of a task execution.
  202. // If there are more than 1 exit codes,
  203. // when task executes with any of the exit code in the list,
  204. // the condition is met and the action will be executed.
  205. repeated int32 exit_codes = 1;
  206. }
  207. // Action on task failures based on different conditions.
  208. enum Action {
  209. // Action unspecified.
  210. ACTION_UNSPECIFIED = 0;
  211. // Action that tasks in the group will be scheduled to re-execute.
  212. RETRY_TASK = 1;
  213. // Action that tasks in the group will be stopped immediately.
  214. FAIL_TASK = 2;
  215. }
  216. // Action to execute when ActionCondition is true.
  217. Action action = 1;
  218. // Conditions that decide why a task failure is dealt with a specific action.
  219. ActionCondition action_condition = 2;
  220. }
  221. // A Cloud Batch task.
  222. message Task {
  223. option (google.api.resource) = {
  224. type: "batch.googleapis.com/Task"
  225. pattern: "projects/{project}/locations/{location}/jobs/{job}/taskGroups/{task_group}/tasks/{task}"
  226. };
  227. // Task name.
  228. // The name is generated from the parent TaskGroup name and 'id' field.
  229. // For example:
  230. // "projects/123456/locations/us-west1/jobs/job01/taskGroups/group01/tasks/task01".
  231. string name = 1;
  232. // Task Status.
  233. TaskStatus status = 2;
  234. }
  235. // An Environment describes a collection of environment variables to set when
  236. // executing Tasks.
  237. message Environment {
  238. // A map of environment variable names to values.
  239. map<string, string> variables = 1;
  240. }