github.com/zhizhiboom/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/plugins/drivers/base/proto/driver.proto (about)

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