github.com/rohankumardubey/nomad@v0.11.8/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 constraints 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      enum MountConfigs {
   374          option allow_alias = true;
   375          UNKNOWN_MOUNTS = 0; // treated as ANY_MOUNTS for backwards compatibility
   376          ANY_MOUNTS = 0;
   377          NO_MOUNTS = 1;
   378      }
   379      // MountConfigs indicates whether the driver supports mount configurations.
   380      MountConfigs mount_configs = 6;
   381  }
   382  
   383  message NetworkIsolationSpec {
   384    enum NetworkIsolationMode {
   385      HOST = 0;
   386      GROUP = 1;
   387      TASK = 2;
   388      NONE = 3;
   389    }
   390    NetworkIsolationMode mode = 1;
   391  
   392    string path = 2;
   393  
   394    map<string,string> labels = 3;
   395  }
   396  
   397  message TaskConfig {
   398  
   399      // Id of the task, recommended to the globally unique, must be unique to the driver.
   400      string id = 1;
   401  
   402      // Name of the task
   403      string name = 2;
   404  
   405      // MsgpackDriverConfig is the encoded driver configuation of the task
   406      bytes msgpack_driver_config = 3;
   407  
   408      // Env is the a set of key/value pairs to be set as environment variables
   409      map<string, string> env = 4;
   410  
   411      // DeviceEnv is the set of environment variables that are defined by device
   412      // plugins. This allows the driver to differentiate environment variables
   413      // set by the device plugins and those by the user. When populating the
   414      // task's environment env should be used.
   415      map<string, string> device_env = 5;
   416  
   417      // Resources defines the resources to isolate
   418      Resources resources = 6;
   419  
   420      // Mounts is a list of targets to bind mount into the task directory
   421      repeated Mount mounts = 7;
   422  
   423      // Devices is a list of system devices to mount into the task's execution
   424      // environment.
   425      repeated Device devices = 8;
   426  
   427      // User defines the operating system user the tasks should run as
   428      string user = 9;
   429  
   430      // AllocDir is the directory on the host where the allocation directory
   431      // exists.
   432      string alloc_dir = 10;
   433  
   434      // StdoutPath is the path to the file to open and write task stdout to
   435      string stdout_path = 11;
   436  
   437      // StderrPath is the path to the file to open and write task stderr to
   438      string stderr_path = 12;
   439  
   440      // TaskGroupName is the name of the task group which this task is a member of
   441      string task_group_name = 13;
   442  
   443      // JobName is the name of the job of which this task is part of
   444      string job_name = 14;
   445  
   446      // AllocId is the ID of the associated allocation
   447      string alloc_id = 15;
   448  
   449      // NetworkIsolationSpec specifies the configuration for the network namespace
   450      // to use for the task. *Only supported on Linux
   451      NetworkIsolationSpec network_isolation_spec = 16;
   452  }
   453  
   454  message Resources {
   455  
   456      // AllocatedResources are the resources set for the task
   457      AllocatedTaskResources allocated_resources = 1;
   458  
   459      // LinuxResources are the computed values to set for specific Linux features
   460      LinuxResources linux_resources = 2;
   461  }
   462  
   463  message AllocatedTaskResources {
   464      AllocatedCpuResources cpu = 1;
   465      AllocatedMemoryResources memory = 2;
   466      repeated NetworkResource networks = 5;
   467  }
   468  
   469  message AllocatedCpuResources {
   470      int64 cpu_shares = 1;
   471  }
   472  
   473  message AllocatedMemoryResources {
   474      int64 memory_mb = 2;
   475  }
   476  
   477  message NetworkResource {
   478      string device = 1;
   479      string cidr = 2;
   480      string ip = 3;
   481      int32 mbits = 4;
   482      repeated NetworkPort reserved_ports = 5;
   483      repeated NetworkPort dynamic_ports = 6;
   484  }
   485  
   486  message NetworkPort {
   487      string label = 1;
   488      int32 value = 2;
   489  }
   490  
   491  message LinuxResources {
   492  
   493      // CPU CFS (Completely Fair Scheduler) period. Default: 0 (not specified)
   494      int64 cpu_period = 1;
   495      // CPU CFS (Completely Fair Scheduler) quota. Default: 0 (not specified)
   496      int64 cpu_quota = 2;
   497      // CPU shares (relative weight vs. other containers). Default: 0 (not specified)
   498      int64 cpu_shares = 3;
   499      // Memory limit in bytes. Default: 0 (not specified)
   500      int64 memory_limit_bytes = 4;
   501      // OOMScoreAdj adjusts the oom-killer score. Default: 0 (not specified)
   502      int64 oom_score_adj = 5;
   503      // CpusetCpus constrains the allowed set of logical CPUs. Default: "" (not specified)
   504      string cpuset_cpus = 6;
   505      // CpusetMems constrains the allowed set of memory nodes. Default: "" (not specified)
   506      string cpuset_mems = 7;
   507      // PercentTicks is a compatibility option for docker and should not be used
   508      double PercentTicks = 8;
   509  }
   510  
   511  message Mount {
   512  
   513      // TaskPath is the file path within the task directory to mount to
   514      string task_path = 1;
   515  
   516      // HostPath is the file path on the host to mount from
   517      string host_path = 2;
   518  
   519      // Readonly if set true, mounts the path in readonly mode
   520      bool readonly = 3;
   521  }
   522  
   523  message Device {
   524  
   525      // TaskPath is the file path within the task to mount the device to
   526      string task_path = 1;
   527  
   528      // HostPath is the path on the host to the source device
   529      string host_path = 2;
   530  
   531      // CgroupPermissions defines the Cgroup permissions of the device.
   532      // One or more of the following options can be set:
   533      //  * r - allows the task to read from the specified device.
   534      //  * w - allows the task to write to the specified device.
   535      //  * m - allows the task to create device files that do not yet exist.
   536      //
   537      // Example: "rw"
   538      string cgroup_permissions = 3;
   539  }
   540  
   541  enum TaskState {
   542      UNKNOWN = 0;
   543      RUNNING = 1;
   544      EXITED = 2;
   545  }
   546  
   547  // TaskHandle is created when starting a task and is used to recover task
   548  message TaskHandle {
   549  
   550      // Version is used by the driver to version the DriverState schema.
   551      // Version 0 is reserved by Nomad and should not be used.
   552      int32 version = 1;
   553  
   554      // Config is the TaskConfig for the task
   555      TaskConfig config = 2;
   556  
   557      // State is the state of the task's execution
   558      TaskState state = 3;
   559  
   560      // DriverState is the encoded state for the specific driver
   561      bytes driver_state = 4;
   562  }
   563  
   564  // NetworkOverride contains network settings which the driver may override
   565  // for the task, such as when the driver is setting up the task's network.
   566  message NetworkOverride {
   567  
   568      // PortMap can be set to replace ports with driver-specific mappings
   569      map<string,int32> port_map = 1;
   570  
   571      // Addr is the IP address for the task created by the driver
   572      string addr = 2;
   573  
   574      // AutoAdvertise indicates whether the driver thinks services that choose
   575      // to auto_advertise_addresses should use this IP instead of the host's.
   576      bool auto_advertise = 3;
   577  }
   578  
   579  // ExitResult contains information about the exit status of a task
   580  message ExitResult {
   581  
   582      // ExitCode returned from the task on exit
   583      int32 exit_code = 1;
   584  
   585      // Signal is set if a signal was sent to the task
   586      int32 signal = 2;
   587  
   588      // OomKilled is true if the task exited as a result of the OOM Killer
   589      bool oom_killed = 3;
   590  
   591  }
   592  
   593  // TaskStatus includes information of a specific task
   594  message TaskStatus {
   595      string id = 1;
   596      string name = 2;
   597  
   598      // State is the state of the task's execution
   599      TaskState state = 3;
   600  
   601      // StartedAt is the timestamp when the task was started
   602      google.protobuf.Timestamp started_at = 4;
   603  
   604      // CompletedAt is the timestamp when the task exited.
   605      // If the task is still running, CompletedAt will not be set
   606      google.protobuf.Timestamp completed_at = 5;
   607  
   608      // Result is set when CompletedAt is set.
   609      ExitResult result = 6;
   610  }
   611  
   612  message TaskDriverStatus {
   613  
   614      // Attributes is a set of string/string key value pairs specific to the
   615      // implementing driver
   616      map<string, string> attributes = 1;
   617  }
   618  
   619  message TaskStats {
   620  
   621      // Id of the task
   622      string id = 1;
   623  
   624      // Timestamp for which the stats were collected
   625      google.protobuf.Timestamp timestamp = 2;
   626  
   627      // AggResourceUsage is the aggreate usage of all processes
   628      TaskResourceUsage agg_resource_usage = 3;
   629  
   630      // ResourceUsageByPid breaks the usage stats by process
   631      map<string, TaskResourceUsage> resource_usage_by_pid = 4;
   632  }
   633  
   634  message TaskResourceUsage {
   635  
   636      // CPU usage stats
   637      CPUUsage cpu = 1;
   638  
   639      // Memory usage stats
   640      MemoryUsage memory = 2;
   641  }
   642  
   643  message CPUUsage {
   644  
   645      double system_mode = 1;
   646      double user_mode = 2;
   647      double total_ticks = 3;
   648      uint64 throttled_periods = 4;
   649      uint64 throttled_time = 5;
   650      double percent = 6;
   651  
   652      enum Fields {
   653          SYSTEM_MODE = 0;
   654          USER_MODE = 1;
   655          TOTAL_TICKS = 2;
   656          THROTTLED_PERIODS = 3;
   657          THROTTLED_TIME = 4;
   658          PERCENT = 5;
   659      }
   660      // MeasuredFields indicates which fields were actually sampled
   661      repeated Fields measured_fields = 7;
   662  }
   663  
   664  message MemoryUsage {
   665      uint64 rss = 1;
   666      uint64 cache = 2;
   667      uint64 max_usage = 3;
   668      uint64 kernel_usage = 4;
   669      uint64 kernel_max_usage = 5;
   670      uint64 usage = 7;
   671      uint64 swap = 8;
   672  
   673      enum Fields {
   674          RSS = 0;
   675          CACHE = 1;
   676          MAX_USAGE = 2;
   677          KERNEL_USAGE = 3;
   678          KERNEL_MAX_USAGE = 4;
   679          USAGE = 5;
   680          SWAP = 6;
   681      }
   682      // MeasuredFields indicates which fields were actually sampled
   683      repeated Fields measured_fields = 6;
   684  }
   685  
   686  message DriverTaskEvent {
   687  
   688      // TaskId is the id of the task for the event
   689      string task_id = 1;
   690  
   691      // AllocId of the task for the event
   692      string alloc_id = 2;
   693  
   694      // TaskName is the name of the task for the event
   695      string task_name = 3;
   696  
   697      // Timestamp when the event occurred
   698      google.protobuf.Timestamp timestamp = 4;
   699  
   700      // Message is the body of the event
   701      string message = 5;
   702  
   703      // Annotations allows for additional key/value data to be sent along with the event
   704      map<string,string> annotations = 6;
   705  }