task.proto 10 KB

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