/**
 * 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.
 */

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

import "Security.proto";
import "yarn_protos.proto";
import "yarn_server_common_protos.proto";
import "yarn_service_protos.proto";

message RemoteNodeProto {
  optional NodeIdProto node_id = 1;
  optional string http_address = 2;
  optional string rack_name = 3;
  optional string node_partition = 4;
}

message RegisterDistributedSchedulingAMResponseProto {
  optional RegisterApplicationMasterResponseProto register_response = 1;
  optional ResourceProto max_container_resource = 2;
  optional ResourceProto min_container_resource = 3;
  optional ResourceProto incr_container_resource = 4;
  optional int32 container_token_expiry_interval = 5;
  optional int64 container_id_start = 6;
  repeated RemoteNodeProto nodes_for_scheduling = 7;
}

message DistributedSchedulingAllocateResponseProto {
  optional AllocateResponseProto allocate_response = 1;
  repeated RemoteNodeProto nodes_for_scheduling = 2;
}

message DistributedSchedulingAllocateRequestProto {
  optional AllocateRequestProto allocate_request = 1;
  repeated ContainerProto allocated_containers = 2;
}

message NodeLabelsProto {
  repeated NodeLabelProto nodeLabels = 1;
}

message NodeAttributesProto {
  repeated NodeAttributeProto nodeAttributes = 1;
}

message RegisterNodeManagerRequestProto {
  optional NodeIdProto node_id = 1;
  optional int32 http_port = 3;
  optional ResourceProto resource = 4;
  optional string nm_version = 5;
  repeated NMContainerStatusProto container_statuses = 6;
  repeated ApplicationIdProto runningApplications = 7;
  optional NodeLabelsProto nodeLabels = 8;
  optional ResourceProto physicalResource = 9;
  repeated LogAggregationReportProto log_aggregation_reports_for_apps = 10;
  optional NodeAttributesProto nodeAttributes = 11;
  optional NodeStatusProto nodeStatus = 12;
}

message RegisterNodeManagerResponseProto {
  optional MasterKeyProto container_token_master_key = 1;
  optional MasterKeyProto nm_token_master_key = 2;
  optional NodeActionProto nodeAction = 3;
  optional int64 rm_identifier = 4;
  optional string diagnostics_message = 5;
  optional string rm_version = 6;
  optional bool areNodeLabelsAcceptedByRM = 7 [default = false];
  optional ResourceProto resource = 8;
  optional bool areNodeAttributesAcceptedByRM = 9 [default = false];
}

message UnRegisterNodeManagerRequestProto {
  optional NodeIdProto node_id = 1;
}

message UnRegisterNodeManagerResponseProto {
}

message NodeHeartbeatRequestProto {
  optional NodeStatusProto node_status = 1;
  optional MasterKeyProto last_known_container_token_master_key = 2;
  optional MasterKeyProto last_known_nm_token_master_key = 3;
  optional NodeLabelsProto nodeLabels = 4;
  repeated LogAggregationReportProto log_aggregation_reports_for_apps = 5;
  repeated AppCollectorDataProto registering_collectors = 6;
  optional NodeAttributesProto nodeAttributes = 7;
  optional int64 tokenSequenceNo = 8;
}

message LogAggregationReportProto {
  optional ApplicationIdProto application_id = 1;
  optional LogAggregationStatusProto log_aggregation_status = 2;
  optional string diagnostics = 3 [default = "N/A"];
}

message NodeHeartbeatResponseProto {
  optional int32 response_id = 1;
  optional MasterKeyProto container_token_master_key = 2;
  optional MasterKeyProto nm_token_master_key = 3;
  optional NodeActionProto nodeAction = 4;
  repeated ContainerIdProto containers_to_cleanup = 5;
  repeated ApplicationIdProto applications_to_cleanup = 6;
  optional int64 nextHeartBeatInterval = 7;
  optional string diagnostics_message = 8;
  repeated ContainerIdProto containers_to_be_removed_from_nm = 9;
  repeated SystemCredentialsForAppsProto system_credentials_for_apps = 10;
  optional bool areNodeLabelsAcceptedByRM = 11 [default = false];
  // to be deprecated in favour of containers_to_update
  repeated ContainerProto containers_to_decrease = 12;
  repeated SignalContainerRequestProto containers_to_signal = 13;
  optional ResourceProto resource = 14;
  optional ContainerQueuingLimitProto container_queuing_limit = 15;
  repeated AppCollectorDataProto app_collectors = 16;
  // to be used in place of containers_to_decrease
  repeated ContainerProto containers_to_update = 17;
  optional bool areNodeAttributesAcceptedByRM = 18 [default = false];
  optional int64 tokenSequenceNo = 19;
}

message ContainerQueuingLimitProto {
  optional int32 max_queue_length = 1;
  optional int32 max_queue_wait_time_in_ms = 2;
}

message SystemCredentialsForAppsProto {
  optional ApplicationIdProto appId = 1;
  optional bytes credentialsForApp = 2;
}

////////////////////////////////////////////////////////////////////////
////// From collector_nodemanager_protocol ////////////////////////////
////////////////////////////////////////////////////////////////////////
message AppCollectorDataProto {
  optional ApplicationIdProto app_id = 1;
  optional string app_collector_addr = 2;
  optional int64 rm_identifier = 3 [default = -1];
  optional int64 version = 4 [default = -1];
  optional hadoop.common.TokenProto app_collector_token = 5;
}

//////////////////////////////////////////////////////
/////// collector_nodemanager_protocol //////////////
//////////////////////////////////////////////////////
message ReportNewCollectorInfoRequestProto {
  repeated AppCollectorDataProto app_collectors = 1;
}

message ReportNewCollectorInfoResponseProto {
}

message GetTimelineCollectorContextRequestProto {
  optional ApplicationIdProto appId = 1;
}

message GetTimelineCollectorContextResponseProto {
  optional string user_id = 1;
  optional string flow_name = 2;
  optional string flow_version = 3;
  optional int64 flow_run_id = 4;
}

message NMContainerStatusProto {
  optional ContainerIdProto container_id = 1;
  optional ContainerStateProto container_state = 2;
  optional ResourceProto resource = 3;
  optional PriorityProto priority = 4;
  optional string diagnostics = 5 [default = "N/A"];
  optional int32 container_exit_status = 6;
  optional int64 creation_time = 7;
  optional string nodeLabelExpression = 8;
  optional int32 version = 9;
  optional ExecutionTypeProto executionType = 10 [default = GUARANTEED];
  optional int64 allocation_request_id = 11 [default = -1];
  repeated string allocation_tags = 12;
}

message SCMUploaderNotifyRequestProto {
  optional string resource_key = 1;
  optional string filename = 2;
}

message SCMUploaderNotifyResponseProto {
  optional bool accepted = 1;
}

message SCMUploaderCanUploadRequestProto {
  optional string resource_key = 1;
}

message SCMUploaderCanUploadResponseProto {
  optional bool uploadable = 1;
}
