github.com/manicqin/nomad@v0.9.5/plugins/drivers/proto/driver.proto (about) 1 syntax = "proto3"; 2 package hashicorp.nomad.plugins.drivers.proto; 3 option go_package = "proto"; 4 5 import "google/protobuf/duration.proto"; 6 import "google/protobuf/timestamp.proto"; 7 8 import "github.com/hashicorp/nomad/plugins/shared/hclspec/hcl_spec.proto"; 9 import "github.com/hashicorp/nomad/plugins/shared/structs/proto/attribute.proto"; 10 11 // Driver service defines RPCs used to communicate with a nomad runtime driver. 12 // Some rpcs may not be implemented by the driver based on it's capabilities. 13 service Driver { 14 15 // TaskConfigSchema returns the schema for parsing the driver 16 // configuration of a task. 17 rpc TaskConfigSchema(TaskConfigSchemaRequest) returns (TaskConfigSchemaResponse) {} 18 19 // Capabilities returns a set of features which the driver implements. Some 20 // RPCs are not possible to implement on some runtimes, this allows the 21 // driver to indicate if it doesn't support these RPCs and features. 22 rpc Capabilities(CapabilitiesRequest) returns (CapabilitiesResponse) {} 23 24 // Fingerprint starts a stream which emits information about the driver 25 // including whether the driver healthy and able to function in the 26 // existing environment. 27 // 28 // The driver should immediately stream a FingerprintResponse when the RPC 29 // is initially called, then send any additional responses if there is a 30 // change in the driver's state. 31 rpc Fingerprint(FingerprintRequest) returns (stream FingerprintResponse) {} 32 33 // RecoverTask is used when a task has been started but the driver may not 34 // know about it. Such is the case if the driver restarts or is upgraded. 35 rpc RecoverTask(RecoverTaskRequest) returns (RecoverTaskResponse) {} 36 37 // StartTask starts and tracks the task on the implemented runtime 38 rpc StartTask(StartTaskRequest) returns (StartTaskResponse) {} 39 40 // WaitTask blocks until the given task exits, returning the result of the 41 // task. It may be called after the task has exited, but before the task is 42 // destroyed. 43 rpc WaitTask(WaitTaskRequest) returns (WaitTaskResponse) {} 44 45 // StopTask stops a given task by sending the desired signal to the process. 46 // If the task does not exit on its own within the given timeout, it will be 47 // forcefully killed. 48 rpc StopTask(StopTaskRequest) returns (StopTaskResponse) {} 49 50 // DestroyTask removes the task from the driver's internal state and cleans 51 // up any additional resources created by the driver. It cannot be called 52 // on a running task, unless force is set to true. 53 rpc DestroyTask(DestroyTaskRequest) returns (DestroyTaskResponse) {} 54 55 // InspectTask returns detailed information for the given task 56 rpc InspectTask(InspectTaskRequest) returns (InspectTaskResponse) {} 57 58 // TaskStats collects and returns runtime metrics for the given task 59 rpc TaskStats(TaskStatsRequest) returns (stream TaskStatsResponse) {} 60 61 // TaskEvents starts a streaming RPC where all task events emitted by the 62 // driver are streamed to the caller. 63 rpc TaskEvents(TaskEventsRequest) returns (stream DriverTaskEvent) {} 64 65 // The following RPCs are only implemented if the driver sets the 66 // corresponding capability. 67 68 // SignalTask sends a signal to the task 69 rpc SignalTask(SignalTaskRequest) returns (SignalTaskResponse) {} 70 71 // ExecTask executes a command inside the tasks execution context 72 rpc ExecTask(ExecTaskRequest) returns (ExecTaskResponse) {} 73 74 // ExecTaskStreaming executes a command inside the tasks execution context 75 // and streams back results 76 rpc ExecTaskStreaming(stream ExecTaskStreamingRequest) returns (stream ExecTaskStreamingResponse) {} 77 78 // CreateNetwork is implemented when the driver needs to create the network 79 // namespace instead of allowing the Nomad client to do. 80 rpc CreateNetwork(CreateNetworkRequest) returns (CreateNetworkResponse) {} 81 82 // DestroyNetwork destroys a previously created network. This rpc is only 83 // implemented if the driver needs to manage network namespace creation. 84 rpc DestroyNetwork(DestroyNetworkRequest) returns (DestroyNetworkResponse) {} 85 } 86 87 message TaskConfigSchemaRequest {} 88 89 message TaskConfigSchemaResponse { 90 91 // Spec is the configuration schema for the job driver config stanza 92 hashicorp.nomad.plugins.shared.hclspec.Spec spec = 1; 93 } 94 95 message CapabilitiesRequest {} 96 97 message CapabilitiesResponse { 98 99 // Capabilities provides a way for the driver to denote if it implements 100 // non-core RPCs. Some Driver service RPCs expose additional information 101 // or functionality outside of the core task management functions. These 102 // RPCs are only implemented if the driver sets the corresponding capability. 103 DriverCapabilities capabilities = 1; 104 } 105 106 message FingerprintRequest {} 107 108 message FingerprintResponse { 109 110 111 // Attributes are key/value pairs that annotate the nomad client and can be 112 // used in scheduling contraints and affinities. 113 map<string, hashicorp.nomad.plugins.shared.structs.Attribute> attributes = 1; 114 115 enum HealthState { 116 UNDETECTED = 0; 117 UNHEALTHY = 1; 118 HEALTHY = 2; 119 120 } 121 122 // Health is used to determine the state of the health the driver is in. 123 // Health can be one of the following states: 124 // * UNDETECTED: driver dependencies are not met and the driver can not start 125 // * UNHEALTHY: driver dependencies are met but the driver is unable to 126 // perform operations due to some other problem 127 // * HEALTHY: driver is able to perform all operations 128 HealthState health = 2; 129 130 // HealthDescription is a human readable message describing the current 131 // state of driver health 132 string health_description = 3; 133 } 134 135 message RecoverTaskRequest { 136 137 // TaskId is the ID of the target task 138 string task_id = 1; 139 140 // Handle is the TaskHandle returned from StartTask 141 TaskHandle handle = 2; 142 } 143 144 message RecoverTaskResponse {} 145 146 message StartTaskRequest { 147 148 // Task configuration to launch 149 TaskConfig task = 1; 150 151 } 152 153 message StartTaskResponse { 154 155 enum Result { 156 SUCCESS = 0; 157 RETRY = 1; 158 FATAL = 2; 159 } 160 161 // Result is set depending on the type of error that occurred while starting 162 // a task: 163 // 164 // * SUCCESS: No error occurred, handle is set 165 // * RETRY: An error occurred, but is recoverable and the RPC should be retried 166 // * FATAL: A fatal error occurred and is not likely to succeed if retried 167 // 168 // If Result is not successful, the DriverErrorMsg will be set. 169 Result result = 1; 170 171 // DriverErrorMsg is set if an error occurred 172 string driver_error_msg = 2; 173 174 // Handle is opaque to the client, but must be stored in order to recover 175 // the task. 176 TaskHandle handle = 3; 177 178 // NetworkOverride is set if the driver sets network settings and the service ip/port 179 // needs to be set differently. 180 NetworkOverride network_override = 4; 181 } 182 183 message WaitTaskRequest { 184 185 // TaskId is the ID of the target task 186 string task_id = 1; 187 } 188 189 message WaitTaskResponse { 190 191 // Result is the exit status of the task 192 ExitResult result = 1; 193 // Err is set if any driver error occurred while waiting for the task 194 string err = 2; 195 } 196 197 message StopTaskRequest { 198 199 // TaskId is the ID of the target task 200 string task_id = 1; 201 202 // Timeout defines the amount of time to wait before forcefully killing 203 // the task. For example, on Unix clients, this means sending a SIGKILL to 204 // the process. 205 google.protobuf.Duration timeout = 2; 206 207 // Signal can be set to override the Task's configured shutdown signal 208 string signal = 3; 209 } 210 211 message StopTaskResponse {} 212 213 message DestroyTaskRequest { 214 215 // TaskId is the ID of the target task 216 string task_id = 1; 217 218 // Force destroys the task even if it is still in a running state 219 bool force = 2; 220 } 221 222 message DestroyTaskResponse {} 223 224 message InspectTaskRequest { 225 226 // TaskId is the ID of the target task 227 string task_id = 1; 228 } 229 230 message InspectTaskResponse { 231 232 // Task details 233 TaskStatus task = 1; 234 235 // Driver details for task 236 TaskDriverStatus driver = 2; 237 238 // NetworkOverride info if set 239 NetworkOverride network_override = 3; 240 } 241 242 message TaskStatsRequest { 243 244 // TaskId is the ID of the target task 245 string task_id = 1; 246 247 // CollectionInterval is the interval at which to stream stats to the caller 248 google.protobuf.Duration collection_interval = 2; 249 } 250 251 message TaskStatsResponse { 252 253 // Stats for the task 254 TaskStats stats = 1; 255 } 256 257 message TaskEventsRequest {} 258 259 message SignalTaskRequest { 260 261 // TaskId is the ID of the target task 262 string task_id = 1; 263 264 // Signal is the operating system signal to send to the task. Ex: SIGHUP 265 string signal = 2; 266 } 267 268 message SignalTaskResponse {} 269 270 message ExecTaskRequest { 271 272 // TaskId is the ID of the target task 273 string task_id = 1; 274 275 // Command is the command to execute in the task environment 276 repeated string command = 2; 277 278 // Timeout is the amount of time to wait for the command to stop. 279 // Defaults to 0 (run forever) 280 google.protobuf.Duration timeout = 3; 281 } 282 283 message ExecTaskResponse { 284 285 // Stdout from the exec 286 bytes stdout = 1; 287 288 // Stderr from the exec 289 bytes stderr = 2; 290 291 // Result from the exec 292 ExitResult result = 3; 293 } 294 295 message ExecTaskStreamingIOOperation { 296 bytes data = 1; 297 bool close = 2; 298 } 299 300 message ExecTaskStreamingRequest { 301 message Setup { 302 string task_id = 1; 303 repeated string command = 2; 304 bool tty = 3; 305 } 306 307 message TerminalSize { 308 int32 height = 1; 309 int32 width = 2; 310 } 311 312 Setup setup = 1; 313 TerminalSize tty_size = 2; 314 ExecTaskStreamingIOOperation stdin = 3; 315 } 316 317 message ExecTaskStreamingResponse { 318 ExecTaskStreamingIOOperation stdout = 1; 319 ExecTaskStreamingIOOperation stderr = 2; 320 321 bool exited = 3; 322 ExitResult result = 4; 323 } 324 325 message CreateNetworkRequest { 326 327 // AllocID of the allocation the network is associated with 328 string alloc_id = 1; 329 } 330 331 message CreateNetworkResponse { 332 333 NetworkIsolationSpec isolation_spec = 1; 334 335 // created indicates that the network namespace is newly created 336 // as a result of this request. if false, the NetworkIsolationSpec 337 // value returned is an existing spec. 338 bool created = 2; 339 } 340 341 message DestroyNetworkRequest { 342 343 // AllocID of the allocation the network is associated with 344 string alloc_id = 1; 345 346 NetworkIsolationSpec isolation_spec = 2; 347 } 348 349 message DestroyNetworkResponse {} 350 351 message DriverCapabilities { 352 353 // SendSignals indicates that the driver can send process signals (ex. SIGUSR1) 354 // to the task. 355 bool send_signals = 1; 356 357 // Exec indicates that the driver supports executing arbitrary commands 358 // in the task's execution environment. 359 bool exec = 2; 360 361 enum FSIsolation { 362 NONE = 0; 363 CHROOT = 1; 364 IMAGE = 2; 365 } 366 // FsIsolation indicates what kind of filesystem isolation a driver supports. 367 FSIsolation fs_isolation = 3; 368 369 repeated NetworkIsolationSpec.NetworkIsolationMode network_isolation_modes = 4; 370 371 bool must_create_network = 5; 372 } 373 374 message NetworkIsolationSpec { 375 enum NetworkIsolationMode { 376 HOST = 0; 377 GROUP = 1; 378 TASK = 2; 379 NONE = 3; 380 } 381 NetworkIsolationMode mode = 1; 382 383 string path = 2; 384 385 map<string,string> labels = 3; 386 } 387 388 message TaskConfig { 389 390 // Id of the task, recommended to the globally unique, must be unique to the driver. 391 string id = 1; 392 393 // Name of the task 394 string name = 2; 395 396 // MsgpackDriverConfig is the encoded driver configuation of the task 397 bytes msgpack_driver_config = 3; 398 399 // Env is the a set of key/value pairs to be set as environment variables 400 map<string, string> env = 4; 401 402 // DeviceEnv is the set of environment variables that are defined by device 403 // plugins. This allows the driver to differentiate environment variables 404 // set by the device plugins and those by the user. When populating the 405 // task's environment env should be used. 406 map<string, string> device_env = 5; 407 408 // Resources defines the resources to isolate 409 Resources resources = 6; 410 411 // Mounts is a list of targets to bind mount into the task directory 412 repeated Mount mounts = 7; 413 414 // Devices is a list of system devices to mount into the task's execution 415 // environment. 416 repeated Device devices = 8; 417 418 // User defines the operating system user the tasks should run as 419 string user = 9; 420 421 // AllocDir is the directory on the host where the allocation directory 422 // exists. 423 string alloc_dir = 10; 424 425 // StdoutPath is the path to the file to open and write task stdout to 426 string stdout_path = 11; 427 428 // StderrPath is the path to the file to open and write task stderr to 429 string stderr_path = 12; 430 431 // TaskGroupName is the name of the task group which this task is a member of 432 string task_group_name = 13; 433 434 // JobName is the name of the job of which this task is part of 435 string job_name = 14; 436 437 // AllocId is the ID of the associated allocation 438 string alloc_id = 15; 439 440 // NetworkIsolationSpec specifies the configuration for the network namespace 441 // to use for the task. *Only supported on Linux 442 NetworkIsolationSpec network_isolation_spec = 16; 443 } 444 445 message Resources { 446 447 // AllocatedResources are the resources set for the task 448 AllocatedTaskResources allocated_resources = 1; 449 450 // LinuxResources are the computed values to set for specific Linux features 451 LinuxResources linux_resources = 2; 452 } 453 454 message AllocatedTaskResources { 455 AllocatedCpuResources cpu = 1; 456 AllocatedMemoryResources memory = 2; 457 repeated NetworkResource networks = 5; 458 } 459 460 message AllocatedCpuResources { 461 int64 cpu_shares = 1; 462 } 463 464 message AllocatedMemoryResources { 465 int64 memory_mb = 2; 466 } 467 468 message NetworkResource { 469 string device = 1; 470 string cidr = 2; 471 string ip = 3; 472 int32 mbits = 4; 473 repeated NetworkPort reserved_ports = 5; 474 repeated NetworkPort dynamic_ports = 6; 475 } 476 477 message NetworkPort { 478 string label = 1; 479 int32 value = 2; 480 } 481 482 message LinuxResources { 483 484 // CPU CFS (Completely Fair Scheduler) period. Default: 0 (not specified) 485 int64 cpu_period = 1; 486 // CPU CFS (Completely Fair Scheduler) quota. Default: 0 (not specified) 487 int64 cpu_quota = 2; 488 // CPU shares (relative weight vs. other containers). Default: 0 (not specified) 489 int64 cpu_shares = 3; 490 // Memory limit in bytes. Default: 0 (not specified) 491 int64 memory_limit_bytes = 4; 492 // OOMScoreAdj adjusts the oom-killer score. Default: 0 (not specified) 493 int64 oom_score_adj = 5; 494 // CpusetCpus constrains the allowed set of logical CPUs. Default: "" (not specified) 495 string cpuset_cpus = 6; 496 // CpusetMems constrains the allowed set of memory nodes. Default: "" (not specified) 497 string cpuset_mems = 7; 498 // PercentTicks is a compatibility option for docker and should not be used 499 double PercentTicks = 8; 500 } 501 502 message Mount { 503 504 // TaskPath is the file path within the task directory to mount to 505 string task_path = 1; 506 507 // HostPath is the file path on the host to mount from 508 string host_path = 2; 509 510 // Readonly if set true, mounts the path in readonly mode 511 bool readonly = 3; 512 } 513 514 message Device { 515 516 // TaskPath is the file path within the task to mount the device to 517 string task_path = 1; 518 519 // HostPath is the path on the host to the source device 520 string host_path = 2; 521 522 // CgroupPermissions defines the Cgroup permissions of the device. 523 // One or more of the following options can be set: 524 // * r - allows the task to read from the specified device. 525 // * w - allows the task to write to the specified device. 526 // * m - allows the task to create device files that do not yet exist. 527 // 528 // Example: "rw" 529 string cgroup_permissions = 3; 530 } 531 532 enum TaskState { 533 UNKNOWN = 0; 534 RUNNING = 1; 535 EXITED = 2; 536 } 537 538 // TaskHandle is created when starting a task and is used to recover task 539 message TaskHandle { 540 541 // Version is used by the driver to version the DriverState schema. 542 // Version 0 is reserved by Nomad and should not be used. 543 int32 version = 1; 544 545 // Config is the TaskConfig for the task 546 TaskConfig config = 2; 547 548 // State is the state of the task's execution 549 TaskState state = 3; 550 551 // DriverState is the encoded state for the specific driver 552 bytes driver_state = 4; 553 } 554 555 // NetworkOverride contains network settings which the driver may override 556 // for the task, such as when the driver is setting up the task's network. 557 message NetworkOverride { 558 559 // PortMap can be set to replace ports with driver-specific mappings 560 map<string,int32> port_map = 1; 561 562 // Addr is the IP address for the task created by the driver 563 string addr = 2; 564 565 // AutoAdvertise indicates whether the driver thinks services that choose 566 // to auto_advertise_addresses should use this IP instead of the host's. 567 bool auto_advertise = 3; 568 } 569 570 // ExitResult contains information about the exit status of a task 571 message ExitResult { 572 573 // ExitCode returned from the task on exit 574 int32 exit_code = 1; 575 576 // Signal is set if a signal was sent to the task 577 int32 signal = 2; 578 579 // OomKilled is true if the task exited as a result of the OOM Killer 580 bool oom_killed = 3; 581 582 } 583 584 // TaskStatus includes information of a specific task 585 message TaskStatus { 586 string id = 1; 587 string name = 2; 588 589 // State is the state of the task's execution 590 TaskState state = 3; 591 592 // StartedAt is the timestamp when the task was started 593 google.protobuf.Timestamp started_at = 4; 594 595 // CompletedAt is the timestamp when the task exited. 596 // If the task is still running, CompletedAt will not be set 597 google.protobuf.Timestamp completed_at = 5; 598 599 // Result is set when CompletedAt is set. 600 ExitResult result = 6; 601 } 602 603 message TaskDriverStatus { 604 605 // Attributes is a set of string/string key value pairs specific to the 606 // implementing driver 607 map<string, string> attributes = 1; 608 } 609 610 message TaskStats { 611 612 // Id of the task 613 string id = 1; 614 615 // Timestamp for which the stats were collected 616 google.protobuf.Timestamp timestamp = 2; 617 618 // AggResourceUsage is the aggreate usage of all processes 619 TaskResourceUsage agg_resource_usage = 3; 620 621 // ResourceUsageByPid breaks the usage stats by process 622 map<string, TaskResourceUsage> resource_usage_by_pid = 4; 623 } 624 625 message TaskResourceUsage { 626 627 // CPU usage stats 628 CPUUsage cpu = 1; 629 630 // Memory usage stats 631 MemoryUsage memory = 2; 632 } 633 634 message CPUUsage { 635 636 double system_mode = 1; 637 double user_mode = 2; 638 double total_ticks = 3; 639 uint64 throttled_periods = 4; 640 uint64 throttled_time = 5; 641 double percent = 6; 642 643 enum Fields { 644 SYSTEM_MODE = 0; 645 USER_MODE = 1; 646 TOTAL_TICKS = 2; 647 THROTTLED_PERIODS = 3; 648 THROTTLED_TIME = 4; 649 PERCENT = 5; 650 } 651 // MeasuredFields indicates which fields were actually sampled 652 repeated Fields measured_fields = 7; 653 } 654 655 message MemoryUsage { 656 uint64 rss = 1; 657 uint64 cache = 2; 658 uint64 max_usage = 3; 659 uint64 kernel_usage = 4; 660 uint64 kernel_max_usage = 5; 661 uint64 usage = 7; 662 uint64 swap = 8; 663 664 enum Fields { 665 RSS = 0; 666 CACHE = 1; 667 MAX_USAGE = 2; 668 KERNEL_USAGE = 3; 669 KERNEL_MAX_USAGE = 4; 670 USAGE = 5; 671 SWAP = 6; 672 } 673 // MeasuredFields indicates which fields were actually sampled 674 repeated Fields measured_fields = 6; 675 } 676 677 message DriverTaskEvent { 678 679 // TaskId is the id of the task for the event 680 string task_id = 1; 681 682 // AllocId of the task for the event 683 string alloc_id = 2; 684 685 // TaskName is the name of the task for the event 686 string task_name = 3; 687 688 // Timestamp when the event occurred 689 google.protobuf.Timestamp timestamp = 4; 690 691 // Message is the body of the event 692 string message = 5; 693 694 // Annotations allows for additional key/value data to be sent along with the event 695 map<string,string> annotations = 6; 696 }