/*
	Copyright The containerd Authors.

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

		http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/

syntax = "proto3";

package containerd.services.tasks.v1;

import "google/protobuf/empty.proto";
import "google/protobuf/any.proto";
import weak "gogoproto/gogo.proto";
import "github.com/containerd/containerd/api/types/mount.proto";
import "github.com/containerd/containerd/api/types/metrics.proto";
import "github.com/containerd/containerd/api/types/descriptor.proto";
import "github.com/containerd/containerd/api/types/task/task.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/containerd/containerd/api/services/tasks/v1;tasks";

service Tasks {
	// Create a task.
	rpc Create(CreateTaskRequest) returns (CreateTaskResponse);

	// Start a process.
	rpc Start(StartRequest) returns (StartResponse);

	// Delete a task and on disk state.
	rpc Delete(DeleteTaskRequest) returns (DeleteResponse);

	rpc DeleteProcess(DeleteProcessRequest) returns (DeleteResponse);

	rpc Get(GetRequest) returns (GetResponse);

	rpc List(ListTasksRequest) returns (ListTasksResponse);

	// Kill a task or process.
	rpc Kill(KillRequest) returns (google.protobuf.Empty);

	rpc Exec(ExecProcessRequest) returns (google.protobuf.Empty);

	rpc ResizePty(ResizePtyRequest) returns (google.protobuf.Empty);

	rpc CloseIO(CloseIORequest) returns (google.protobuf.Empty);

	rpc Pause(PauseTaskRequest) returns (google.protobuf.Empty);

	rpc Resume(ResumeTaskRequest) returns (google.protobuf.Empty);

	rpc ListPids(ListPidsRequest) returns (ListPidsResponse);

	rpc Checkpoint(CheckpointTaskRequest) returns (CheckpointTaskResponse);

	rpc Update(UpdateTaskRequest) returns (google.protobuf.Empty);

	rpc Metrics(MetricsRequest) returns (MetricsResponse);

	rpc Wait(WaitRequest) returns (WaitResponse);
}

message CreateTaskRequest {
	string container_id = 1;

	// RootFS provides the pre-chroot mounts to perform in the shim before
	// executing the container task.
	//
	// These are for mounts that cannot be performed in the user namespace.
	// Typically, these mounts should be resolved from snapshots specified on
	// the container object.
	repeated containerd.types.Mount rootfs = 3;

	string stdin = 4;
	string stdout = 5;
	string stderr = 6;
	bool terminal = 7;

	containerd.types.Descriptor checkpoint = 8;

	google.protobuf.Any options = 9;
}

message CreateTaskResponse {
	string container_id = 1;
	uint32 pid = 2;
}

message StartRequest {
	string container_id = 1;
	string exec_id = 2;
}

message StartResponse {
	uint32 pid = 1;
}

message DeleteTaskRequest {
	string container_id = 1;
}

message DeleteResponse {
	string id = 1;
	uint32 pid = 2;
	uint32 exit_status = 3;
	google.protobuf.Timestamp exited_at = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
}

message DeleteProcessRequest {
	string container_id = 1;
	string exec_id = 2;
}

message GetRequest {
	string container_id = 1;
	string exec_id = 2;
}

message GetResponse {
	containerd.v1.types.Process process = 1;
}

message ListTasksRequest {
	string filter = 1;
}

message ListTasksResponse {
	repeated containerd.v1.types.Process tasks = 1;
}

message KillRequest {
	string container_id = 1;
	string exec_id = 2;
	uint32 signal = 3;
	bool all = 4;
}

message ExecProcessRequest {
	string container_id = 1;
	string stdin = 2;
	string stdout = 3;
	string stderr = 4;
	bool terminal = 5;
	// Spec for starting a process in the target container.
	//
	// For runc, this is a process spec, for example.
	google.protobuf.Any spec = 6;
	// id of the exec process
	string exec_id = 7;
}

message ExecProcessResponse {
}

message ResizePtyRequest {
	string container_id = 1;
	string exec_id = 2;
	uint32 width = 3;
	uint32 height = 4;
}

message CloseIORequest {
	string container_id = 1;
	string exec_id = 2;
	bool stdin = 3;
}

message PauseTaskRequest {
	string container_id = 1;
}

message ResumeTaskRequest {
	string container_id = 1;
}

message ListPidsRequest {
	string container_id = 1;
}

message ListPidsResponse {
	// Processes includes the process ID and additional process information
	repeated containerd.v1.types.ProcessInfo processes = 1;
}

message CheckpointTaskRequest {
	string container_id = 1;
	string parent_checkpoint = 2 [(gogoproto.customtype) = "github.com/opencontainers/go-digest.Digest", (gogoproto.nullable) = false];
	google.protobuf.Any options = 3;
}

message CheckpointTaskResponse {
	repeated containerd.types.Descriptor descriptors = 1;
}

message UpdateTaskRequest {
	string container_id = 1;
	google.protobuf.Any resources = 2;
	map<string, string> annotations = 3;
}

message MetricsRequest {
	repeated string filters = 1;
}

message MetricsResponse {
	repeated types.Metric metrics = 1;
}

message WaitRequest {
	string container_id = 1;
	string exec_id = 2;
}

message WaitResponse {
	uint32 exit_status = 1;
	google.protobuf.Timestamp exited_at = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
}
