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