/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
 */

/**
 * These .proto interfaces are public and stable.
 * Please see https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/Compatibility.html
 * for what changes are allowed for a *stable* .proto interface.
 */

syntax = "proto2";
option java_package = "org.apache.hadoop.yarn.proto";
option java_outer_classname = "YarnServiceProtos";
option java_generic_services = true;
option java_generate_equals_and_hash = true;
package hadoop.yarn;

import "Security.proto";
import "yarn_protos.proto";

//////////////////////////////////////////////////////
/////// AM_RM_Protocol ///////////////////////////////
//////////////////////////////////////////////////////
message RegisterApplicationMasterRequestProto {
  optional string host = 1;
  optional int32 rpc_port = 2;
  optional string tracking_url = 3;
  repeated PlacementConstraintMapEntryProto placement_constraints = 4;
}

message RegisterApplicationMasterResponseProto {
  optional ResourceProto maximumCapability = 1;
  optional bytes client_to_am_token_master_key = 2;
  repeated ApplicationACLMapProto application_ACLs = 3;
  repeated ContainerProto containers_from_previous_attempts = 4;
  optional string queue = 5;
  repeated NMTokenProto nm_tokens_from_previous_attempts = 6;
  repeated SchedulerResourceTypes scheduler_resource_types = 7;
  optional ResourceProfilesProto resource_profiles = 8;
  repeated ResourceTypeInfoProto resource_types = 9;
}

message FinishApplicationMasterRequestProto {
  optional string diagnostics = 1;
  optional string tracking_url = 2;
  optional FinalApplicationStatusProto final_application_status = 3;
}

message FinishApplicationMasterResponseProto {
  optional bool isUnregistered = 1 [default = false];
}

enum ContainerUpdateTypeProto {
  INCREASE_RESOURCE = 0;
  DECREASE_RESOURCE = 1;
  PROMOTE_EXECUTION_TYPE = 2;
  DEMOTE_EXECUTION_TYPE = 3;
}

message UpdateContainerRequestProto {
  required int32 container_version = 1;
  required ContainerIdProto container_id = 2;
  required ContainerUpdateTypeProto update_type = 3;
  optional ResourceProto capability = 4;
  optional ExecutionTypeProto execution_type = 5;
}

message UpdateContainerErrorProto {
  optional string reason = 1;
  optional UpdateContainerRequestProto update_request = 2;
  optional int32 current_container_version = 3;
}

message AllocateRequestProto {
  repeated ResourceRequestProto ask = 1;
  repeated ContainerIdProto release = 2;
  optional ResourceBlacklistRequestProto blacklist_request = 3;
  optional int32 response_id = 4;
  optional float progress = 5;
  repeated UpdateContainerRequestProto update_requests = 7;
  repeated SchedulingRequestProto scheduling_requests = 10;
  optional string tracking_url = 11;
}

message NMTokenProto {
  optional NodeIdProto nodeId = 1; 
  optional hadoop.common.TokenProto token = 2;
}

message UpdatedContainerProto {
  required ContainerUpdateTypeProto update_type = 1;
  required ContainerProto container = 2;
}

message AllocateResponseProto {
  optional AMCommandProto a_m_command = 1;
  optional int32 response_id = 2;
  repeated ContainerProto allocated_containers = 3;
  repeated ContainerStatusProto completed_container_statuses = 4;
  optional ResourceProto limit = 5;
  repeated NodeReportProto updated_nodes = 6;
  optional int32 num_cluster_nodes = 7;
  optional PreemptionMessageProto preempt = 8;
  repeated NMTokenProto nm_tokens = 9;
  optional hadoop.common.TokenProto am_rm_token = 12;
  optional PriorityProto application_priority = 13;
  optional CollectorInfoProto collector_info = 14;
  repeated UpdateContainerErrorProto update_errors = 15;
  repeated UpdatedContainerProto updated_containers = 16;
  repeated ContainerProto containers_from_previous_attempts = 17;
  repeated RejectedSchedulingRequestProto rejected_scheduling_requests = 18;
}

enum SchedulerResourceTypes {
  MEMORY = 0;
  CPU = 1;
}

//////////////////////////////////////////////////////
/////// client_RM_Protocol ///////////////////////////
//////////////////////////////////////////////////////

message GetNewApplicationRequestProto {
}

message GetNewApplicationResponseProto {
  optional ApplicationIdProto application_id = 1;
  optional ResourceProto maximumCapability = 2;
}

message GetApplicationReportRequestProto {
  optional ApplicationIdProto application_id = 1;
}

message GetApplicationReportResponseProto {
  optional ApplicationReportProto application_report = 1;
}

message SubmitApplicationRequestProto {
  optional ApplicationSubmissionContextProto application_submission_context= 1;
}

message SubmitApplicationResponseProto {
}

message FailApplicationAttemptRequestProto {
  optional ApplicationAttemptIdProto application_attempt_id = 1;
}

message FailApplicationAttemptResponseProto {
}

message KillApplicationRequestProto {
  optional ApplicationIdProto application_id = 1;
  optional string diagnostics = 2;
}

message KillApplicationResponseProto {
  optional bool is_kill_completed = 1 [default = false];
}

message GetClusterMetricsRequestProto {
}

message GetClusterMetricsResponseProto {
  optional YarnClusterMetricsProto cluster_metrics = 1;
}

message MoveApplicationAcrossQueuesRequestProto {
  required ApplicationIdProto application_id = 1;
  required string target_queue = 2;
}

message MoveApplicationAcrossQueuesResponseProto {
}

enum ApplicationsRequestScopeProto {
  ALL = 0;
  VIEWABLE = 1;
  OWN = 2;
}

message GetApplicationsRequestProto {
  repeated string application_types = 1;
  repeated YarnApplicationStateProto application_states = 2;
  repeated string users = 3;
  repeated string queues = 4;
  optional int64 limit = 5;
  optional int64 start_begin = 6;
  optional int64 start_end = 7;
  optional int64 finish_begin = 8;
  optional int64 finish_end = 9;
  repeated string applicationTags = 10;
  optional ApplicationsRequestScopeProto scope = 11 [default = ALL];
  optional string name = 12;
}

message GetApplicationsResponseProto {
  repeated ApplicationReportProto applications = 1;
}

message GetClusterNodesRequestProto {
  repeated NodeStateProto nodeStates = 1;
}

message GetClusterNodesResponseProto {
  repeated NodeReportProto nodeReports = 1;
}

message GetQueueInfoRequestProto {
  optional string queueName = 1;
  optional bool includeApplications = 2;
  optional bool includeChildQueues = 3;
  optional bool recursive = 4;
}

message GetQueueInfoResponseProto {
  optional QueueInfoProto queueInfo = 1;
}

message GetQueueUserAclsInfoRequestProto {
}

message GetQueueUserAclsInfoResponseProto {
  repeated QueueUserACLInfoProto queueUserAcls = 1;
}

message GetNodesToLabelsRequestProto {
}

message GetNodesToLabelsResponseProto {
  repeated NodeIdToLabelsProto nodeToLabels = 1;
}

message GetLabelsToNodesRequestProto {
  repeated string nodeLabels = 1;
}

message GetLabelsToNodesResponseProto {
  repeated LabelsToNodeIdsProto labelsToNodes = 1;
}

message GetClusterNodeLabelsRequestProto {
}

message GetClusterNodeLabelsResponseProto {
  repeated string deprecatedNodeLabels = 1;
  repeated NodeLabelProto nodeLabels = 2;
}

message GetClusterNodeAttributesRequestProto {
}

message GetClusterNodeAttributesResponseProto {
  repeated NodeAttributeInfoProto nodeAttributes = 1;
}

message GetAttributesToNodesRequestProto {
  repeated NodeAttributeKeyProto nodeAttributes = 1;
}

message GetAttributesToNodesResponseProto {
  repeated AttributeToNodesProto attributesToNodes = 1;
}

message GetNodesToAttributesRequestProto {
  repeated string hostnames = 1;
}

message GetNodesToAttributesResponseProto {
  repeated NodeToAttributesProto nodesToAttributes = 1;
}

message UpdateApplicationPriorityRequestProto {
  required ApplicationIdProto applicationId = 1;
  required PriorityProto applicationPriority = 2;
}

message UpdateApplicationPriorityResponseProto {
   optional PriorityProto applicationPriority = 1;
}

message SignalContainerRequestProto {
    required ContainerIdProto container_id = 1;
    required SignalContainerCommandProto command = 2;
}

message SignalContainerResponseProto {
}

message UpdateApplicationTimeoutsRequestProto {
    required ApplicationIdProto applicationId = 1;
    repeated ApplicationUpdateTimeoutMapProto application_timeouts = 2;
}

message UpdateApplicationTimeoutsResponseProto {
    repeated ApplicationUpdateTimeoutMapProto application_timeouts = 1;
}

message GetAllResourceProfilesRequestProto {
}

message GetAllResourceProfilesResponseProto {
  required ResourceProfilesProto resource_profiles = 1;
}

message GetResourceProfileRequestProto {
  required string profile = 1;
}

message GetResourceProfileResponseProto {
  required ResourceProto resources = 1;
}

message GetAllResourceTypeInfoRequestProto {
}

message GetAllResourceTypeInfoResponseProto {
  repeated ResourceTypeInfoProto resource_type_info = 1;
}

//////////////////////////////////////////////////////
/////// client_NM_Protocol ///////////////////////////
//////////////////////////////////////////////////////

message StartContainerRequestProto {
  optional ContainerLaunchContextProto container_launch_context = 1;
  optional hadoop.common.TokenProto container_token = 2;
}

message StartContainerResponseProto {
  repeated StringBytesMapProto services_meta_data = 1;
}

message StopContainerRequestProto {
  optional ContainerIdProto container_id = 1;
}

message StopContainerResponseProto {
}

message ResourceLocalizationRequestProto {
  optional ContainerIdProto container_id = 1;
  repeated StringLocalResourceMapProto local_resources = 2;
}

message ResourceLocalizationResponseProto {
}

message ReInitializeContainerRequestProto {
  optional ContainerIdProto container_id = 1;
  optional ContainerLaunchContextProto container_launch_context = 2;
  optional bool auto_commit = 3 [default = true];
}

message ReInitializeContainerResponseProto {
}

message RestartContainerResponseProto {
}

message RollbackResponseProto {
}

message CommitResponseProto {
}

//// bulk API records
message StartContainersRequestProto {
  repeated StartContainerRequestProto start_container_request = 1;
}

message ContainerExceptionMapProto {
  optional ContainerIdProto container_id = 1;
  optional SerializedExceptionProto exception = 2;
}

message StartContainersResponseProto {
  repeated StringBytesMapProto services_meta_data = 1;
  repeated ContainerIdProto succeeded_requests = 2;
  repeated ContainerExceptionMapProto failed_requests = 3;
}

message StopContainersRequestProto {
  repeated ContainerIdProto container_id = 1;
}

message StopContainersResponseProto {
  repeated ContainerIdProto succeeded_requests = 1;
  repeated ContainerExceptionMapProto failed_requests = 2;
}

message GetContainerStatusesRequestProto {
  repeated ContainerIdProto container_id = 1;
}

message GetContainerStatusesResponseProto {
  repeated ContainerStatusProto status = 1;
  repeated ContainerExceptionMapProto failed_requests = 2;
}

message IncreaseContainersResourceRequestProto {
  repeated hadoop.common.TokenProto increase_containers = 1;
}

message IncreaseContainersResourceResponseProto {
  repeated ContainerIdProto succeeded_requests = 1;
  repeated ContainerExceptionMapProto failed_requests = 2;
}

message ContainerUpdateRequestProto {
  repeated hadoop.common.TokenProto update_container_token = 1;
}

message ContainerUpdateResponseProto {
  repeated ContainerIdProto succeeded_requests = 1;
  repeated ContainerExceptionMapProto failed_requests = 2;
}

//////////////////////////////////////////////////////
/////// Application_History_Protocol /////////////////
//////////////////////////////////////////////////////

message GetApplicationAttemptReportRequestProto {
  optional ApplicationAttemptIdProto application_attempt_id = 1;
}

message GetApplicationAttemptReportResponseProto {
  optional ApplicationAttemptReportProto application_attempt_report = 1;
}

message GetApplicationAttemptsRequestProto {
  optional ApplicationIdProto application_id = 1;
}

message GetApplicationAttemptsResponseProto {
  repeated ApplicationAttemptReportProto application_attempts = 1;
}

message GetContainerReportRequestProto {
  optional ContainerIdProto container_id = 1;
}

message GetContainerReportResponseProto {
  optional ContainerReportProto container_report = 1;
}

message GetContainersRequestProto {
  optional ApplicationAttemptIdProto application_attempt_id = 1;
}

message GetContainersResponseProto {
  repeated ContainerReportProto containers = 1;
}

//////////////////////////////////////////////////////
/////// client_SCM_Protocol //////////////////////////
//////////////////////////////////////////////////////

message UseSharedCacheResourceRequestProto {
  optional ApplicationIdProto applicationId = 1;
  optional string resourceKey = 2;
}

message UseSharedCacheResourceResponseProto {
  optional string path = 1;
}

message ReleaseSharedCacheResourceRequestProto {
  optional ApplicationIdProto applicationId = 1;
  optional string resourceKey = 2;
}

message ReleaseSharedCacheResourceResponseProto {
}

//////////////////////////////////////////////////////
//  reservation_protocol
//////////////////////////////////////////////////////

message GetNewReservationRequestProto {
}

message GetNewReservationResponseProto {
  optional ReservationIdProto reservation_id = 1;
}

message ReservationSubmissionRequestProto {
  optional string queue = 1;
  optional ReservationDefinitionProto reservation_definition = 2;
  optional ReservationIdProto reservation_id = 3;
}

message ReservationSubmissionResponseProto {
}

message ReservationUpdateRequestProto {
  optional ReservationDefinitionProto reservation_definition = 1;
  optional ReservationIdProto reservation_id = 2;
}

message ReservationUpdateResponseProto {   
}

message ReservationDeleteRequestProto {
  optional ReservationIdProto reservation_id = 1;
}

message ReservationDeleteResponseProto {
}

message ReservationListRequestProto {
  optional string queue = 1;
  optional string reservation_id = 3;
  optional int64 start_time = 4;
  optional int64 end_time = 5;
  optional bool include_resource_allocations = 6;
}

message ReservationListResponseProto {
  repeated ReservationAllocationStateProto reservations = 1;
}

//////////////////////////////////////////////////////
/////// SCM_Admin_Protocol //////////////////////////
//////////////////////////////////////////////////////

message RunSharedCacheCleanerTaskRequestProto {
}

message RunSharedCacheCleanerTaskResponseProto {
  optional bool accepted = 1;
}

// Localization
message GetLocalizationStatusesRequestProto {
  repeated ContainerIdProto container_id = 1;
}

message GetLocalizationStatusesResponseProto {
  repeated ContainerLocalizationStatusesProto cntn_localization_statuses = 1;
  repeated ContainerExceptionMapProto failed_requests = 2;
}

enum LocalizationStateProto {
  L_PENDING = 1;
  L_COMPLETED = 2;
  L_FAILED = 3;
}


message LocalizationStatusProto {
  optional string resource_key = 1;
  optional LocalizationStateProto localization_state= 2;
  optional string diagnostics = 3;
}

message ContainerLocalizationStatusesProto {
  optional ContainerIdProto container_id = 1;
  repeated LocalizationStatusProto localization_statuses = 2;
}
