syntax = "proto3";

package docker.cluster.api;

import "specs.proto";
import "objects.proto";
import "types.proto";
import "gogoproto/gogo.proto";

// Cluster defines the RPC methods for controlling a cluster.
//
// Other options for naming this interface:
//
// 	- "Control", since this controls a swarm cluster
// 	- "User" because it is user facing.
service Cluster {
	rpc GetNode(GetNodeRequest) returns (GetNodeResponse) {}
	rpc ListNodes(ListNodesRequest) returns (ListNodesResponse) {}
	rpc UpdateNode(UpdateNodeRequest) returns (UpdateNodeResponse) {}

	rpc GetTask(GetTaskRequest) returns (GetTaskResponse) {}
	rpc ListTasks(ListTasksRequest) returns (ListTasksResponse) {}
	rpc RemoveTask(RemoveTaskRequest) returns (RemoveTaskResponse) {}

	rpc GetService(GetServiceRequest) returns (GetServiceResponse) {}
	rpc ListServices(ListServicesRequest) returns (ListServicesResponse) {}
	rpc CreateService(CreateServiceRequest) returns (CreateServiceResponse) {}
	rpc UpdateService(UpdateServiceRequest) returns (UpdateServiceResponse) {}
	rpc RemoveService(RemoveServiceRequest) returns (RemoveServiceResponse) {}

	rpc GetNetwork(GetNetworkRequest) returns (GetNetworkResponse) {};
	rpc ListNetworks(ListNetworksRequest) returns (ListNetworksResponse) {};
	rpc CreateNetwork(CreateNetworkRequest) returns (CreateNetworkResponse) {};
	rpc RemoveNetwork(RemoveNetworkRequest) returns (RemoveNetworkResponse) {};

	rpc GetVolume(GetVolumeRequest) returns (GetVolumeResponse) {};
	rpc ListVolumes(ListVolumesRequest) returns (ListVolumesResponse) {};
	rpc CreateVolume(CreateVolumeRequest) returns (CreateVolumeResponse) {};
	rpc RemoveVolume(RemoveVolumeRequest) returns (RemoveVolumeResponse) {};

	rpc ListManagers(ListManagersRequest) returns (ListManagersResponse) {};
}

message ListOptions {
	// TODO(vieux): Replace `query` with more powerful selectors.
	string query = 1;
}

message GetNodeRequest {
	string node_id = 1 [(gogoproto.customname) = "NodeID"];
}

message GetNodeResponse {
	Node node = 1;
}

message ListNodesRequest {
	ListOptions options = 1;
}

message ListNodesResponse {
	repeated Node nodes = 1;
}

// UpdateNodeRequest requests an update to the specified node. This may be used
// to request a new availability for a node, such as PAUSE. Invalid updates
// will be denied and cause an error.
message UpdateNodeRequest {
	string node_id = 1 [(gogoproto.customname) = "NodeID"];
	Version node_version = 2;
	NodeSpec spec = 3;
}

message UpdateNodeResponse {
	Node node = 1;
}

message GetTaskRequest {
	string task_id = 1 [(gogoproto.customname) = "TaskID"];
}

message GetTaskResponse {
	Task task = 1;
}

message RemoveTaskRequest {
	string task_id = 1 [(gogoproto.customname) = "TaskID"];
}

message RemoveTaskResponse {
}

message ListTasksRequest {
}

message ListTasksResponse {
	repeated Task tasks = 1;
}

message CreateServiceRequest {
	ServiceSpec spec = 1;
}

message CreateServiceResponse {
	Service service = 1;
}

message GetServiceRequest {
	string service_id = 1 [(gogoproto.customname) = "ServiceID"];
}

message GetServiceResponse {
	Service service = 1;
}

message UpdateServiceRequest {
	string service_id = 1 [(gogoproto.customname) = "ServiceID"];
	Version service_version = 2;
	ServiceSpec spec = 3;
}

message UpdateServiceResponse {
	Service service = 1;
}

message RemoveServiceRequest {
	string service_id = 1 [(gogoproto.customname) = "ServiceID"];
}

message RemoveServiceResponse {
}

message ListServicesRequest {
	ListOptions options = 1;
}

message ListServicesResponse {
	repeated Service services = 1;
}

message CreateNetworkRequest {
	NetworkSpec spec = 1;
}

message CreateNetworkResponse {
	Network network = 1;
}

message GetNetworkRequest {
	string name = 1;
	string network_id = 2 [(gogoproto.customname) = "NetworkID"];
}

message GetNetworkResponse {
	Network network = 1;
}

message RemoveNetworkRequest {
	string name = 1;
	string network_id = 2 [(gogoproto.customname) = "NetworkID"];
}

message RemoveNetworkResponse {}

message ListNetworksRequest {
	ListOptions options = 1;
}

message ListNetworksResponse {
	repeated Network networks = 1;
}

message CreateVolumeRequest {
	VolumeSpec spec = 1;
}

message CreateVolumeResponse {
	Volume volume = 1;
}

message GetVolumeRequest {
	string volume_id = 1 [(gogoproto.customname) = "VolumeID"];
}

message GetVolumeResponse {
	Volume volume = 1;
}

message RemoveVolumeRequest {
	string volume_id = 1 [(gogoproto.customname) = "VolumeID"];
}

message RemoveVolumeResponse {}

message ListVolumesRequest {}

message ListVolumesResponse {
	repeated Volume volumes = 1;
}

message ListManagersRequest {
	ListOptions options = 1;
}

message ListManagersResponse {
	repeated Member managers = 1;
}
