syntax = "proto2";

option java_multiple_files = true;
option java_package = "alluxio.grpc";
option java_outer_classname = "CommonProto";

package alluxio.grpc;

enum Bits {
  NONE = 1;
  EXECUTE = 2;
  WRITE = 3;
  WRITE_EXECUTE = 4;
  READ = 5;
  READ_EXECUTE = 6;
  READ_WRITE = 7;
  ALL = 8;
}

message PMode {
  required Bits ownerBits = 1;
  required Bits groupBits = 2;
  required Bits otherBits = 3;
}

/**
 * Contains the information of a block in Alluxio. It maintains the worker nodes where the replicas
 * of the blocks are stored.
 */
message BlockInfo {
  optional int64 blockId = 1;
  optional int64 length = 2;
  repeated BlockLocation locations = 3;
}

/**
 * Information about blocks.
 */
message BlockLocation {
  optional int64 workerId = 1;
  optional WorkerNetAddress workerAddress = 2;
  optional string tierAlias = 3;
  optional string mediumType = 4;
}

/**
 * Information about metrics.
 */
message Metric {
  optional string instance = 1;
  optional string source = 2;
  optional string name = 3;
  optional double value = 4;
  required MetricType metricType = 5;
  map<string,string> tags = 6;
}

enum MetricType {
  // GAUGE is the simplest type of metric. If you're not sure which to use, gauge is a safe choice. It is represents a
  // general K-V pair.
  GAUGE = 0;
  // COUNTER represents values which can be incremented or decremented over time by certain operations. It does not rely
  // on timing to determine the value.
  COUNTER = 1;
  // METER represents a metric value at a _rate_. The value of the metric varies with the time over which events are
  // recorded
  METER = 2;
  // TIMER represents a histogram of the rate of the specified events.
  TIMER = 3;
}

enum CommandType {
  Unknown = 0;
  Nothing = 1;
  Register = 2; // Ask the worker to re-register.
  Free = 3;     // Ask the worker to free files.
  Delete = 4;   // Ask the worker to delete files.
  Persist = 5;  // Ask the worker to persist a file for lineage
}

message ConfigProperty {
  optional string name = 1;
  optional string source = 2;
  optional string value = 3;
}

enum TtlAction {
  DELETE = 0; // Delete the file after TTL expires.
  FREE = 1;   // Free the file after TTL expires.
}

message Command {
  optional CommandType commandType = 1;
  repeated int64 data = 2;
}

message LocalityTier {
  optional string tierName = 1;
  optional string value = 2;
}

message TieredIdentity {
  repeated LocalityTier tiers = 1;
}

/**
 * Address information about masters.
 */
message NetAddress {
  optional string host = 1;
  optional int32 rpcPort = 2;
}

/**
 * Address information about workers.
 */
message WorkerNetAddress {
  optional string host = 1;
  optional int32 rpcPort = 2;
  optional int32 dataPort = 3;
  optional int32 webPort = 4;
  optional string domainSocketPath = 5;
  optional TieredIdentity tieredIdentity = 6;
  optional string containerHost = 7;
}

message BlockStoreLocationProto {
  optional string tierAlias = 1;
  optional string mediumType = 2;
}
