diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java index cfe2897..5f90224 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java @@ -296,53 +296,60 @@ public static boolean isAclEnabled(Configuration conf) { /** ACL used in case none is found. Allows nothing. */ public static final String DEFAULT_YARN_APP_ACL = " "; - /** Is Distributed Scheduling Enabled. */ + /** Setting that controls whether distributed scheduling is enabled or not. */ public static final String DIST_SCHEDULING_ENABLED = YARN_PREFIX + "distributed-scheduling.enabled"; public static final boolean DIST_SCHEDULING_ENABLED_DEFAULT = false; - /** Mininum allocatable container memory for Distributed Scheduling. */ - public static final String DIST_SCHEDULING_MIN_MEMORY = - YARN_PREFIX + "distributed-scheduling.min-memory"; - public static final int DIST_SCHEDULING_MIN_MEMORY_DEFAULT = 512; - - /** Mininum allocatable container vcores for Distributed Scheduling. */ - public static final String DIST_SCHEDULING_MIN_VCORES = - YARN_PREFIX + "distributed-scheduling.min-vcores"; - public static final int DIST_SCHEDULING_MIN_VCORES_DEFAULT = 1; - - /** Maximum allocatable container memory for Distributed Scheduling. */ - public static final String DIST_SCHEDULING_MAX_MEMORY = - YARN_PREFIX + "distributed-scheduling.max-memory"; - public static final int DIST_SCHEDULING_MAX_MEMORY_DEFAULT = 2048; - - /** Maximum allocatable container vcores for Distributed Scheduling. */ - public static final String DIST_SCHEDULING_MAX_VCORES = - YARN_PREFIX + "distributed-scheduling.max-vcores"; - public static final int DIST_SCHEDULING_MAX_VCORES_DEFAULT = 4; - - /** Incremental allocatable container memory for Distributed Scheduling. */ - public static final String DIST_SCHEDULING_INCR_MEMORY = - YARN_PREFIX + "distributed-scheduling.incr-memory"; - public static final int DIST_SCHEDULING_INCR_MEMORY_DEFAULT = 512; - - /** Incremental allocatable container vcores for Distributed Scheduling. */ - public static final String DIST_SCHEDULING_INCR_VCORES = + /** Minimum memory (in MB) used for allocating a container through distributed + * scheduling. */ + public static final String DIST_SCHEDULING_MIN_CONTAINER_MEMORY_MB = + YARN_PREFIX + "distributed-scheduling.min-container-memory-mb"; + public static final int DIST_SCHEDULING_MIN_CONTAINER_MEMORY_MB_DEFAULT = 512; + + /** Minimum virtual CPU cores used for allocating a container through + * distributed scheduling. */ + public static final String DIST_SCHEDULING_MIN_CONTAINER_VCORES = + YARN_PREFIX + "distributed-scheduling.min-container-vcores"; + public static final int DIST_SCHEDULING_MIN_CONTAINER_VCORES_DEFAULT = 1; + + /** Maximum memory (in MB) used for allocating a container through distributed + * scheduling. */ + public static final String DIST_SCHEDULING_MAX_MEMORY_MB = + YARN_PREFIX + "distributed-scheduling.max-container-memory-mb"; + public static final int DIST_SCHEDULING_MAX_MEMORY_MB_DEFAULT = 2048; + + /** Maximum virtual CPU cores used for allocating a container through + * distributed scheduling. */ + public static final String DIST_SCHEDULING_MAX_CONTAINER_VCORES = + YARN_PREFIX + "distributed-scheduling.max-container-vcores"; + public static final int DIST_SCHEDULING_MAX_CONTAINER_VCORES_DEFAULT = 4; + + /** Incremental memory (in MB) used for allocating a container through + * distributed scheduling. */ + public static final String DIST_SCHEDULING_INCR_CONTAINER_MEMORY_MB = + YARN_PREFIX + "distributed-scheduling.incr-container-memory-mb"; + public static final int DIST_SCHEDULING_INCR_CONTAINER_MEMORY_MB_DEFAULT = + 512; + + /** Incremental virtual CPU cores used for allocating a container through + * distributed scheduling. */ + public static final String DIST_SCHEDULING_INCR_CONTAINER_VCORES = YARN_PREFIX + "distributed-scheduling.incr-vcores"; - public static final int DIST_SCHEDULING_INCR_VCORES_DEFAULT = 1; + public static final int DIST_SCHEDULING_INCR_CONTAINER_VCORES_DEFAULT = 1; - /** Container token expiry for container allocated via Distributed - * Scheduling. */ + /** Container token expiry for container allocated via distributed + * scheduling. */ public static final String DIST_SCHEDULING_CONTAINER_TOKEN_EXPIRY_MS = - YARN_PREFIX + "distributed-scheduling.container-token-expiry"; + YARN_PREFIX + "distributed-scheduling.container-token-expiry-ms"; public static final int DIST_SCHEDULING_CONTAINER_TOKEN_EXPIRY_MS_DEFAULT = 600000; - /** K least loaded nodes to be provided to the LocalScheduler of a - * NodeManager for Distributed Scheduling. */ - public static final String DIST_SCHEDULING_TOP_K = - YARN_PREFIX + "distributed-scheduling.top-k"; - public static final int DIST_SCHEDULING_TOP_K_DEFAULT = 10; + /** Number of nodes to be used by the LocalScheduler of a NodeManager for + * dispatching containers during distributed scheduling. */ + public static final String DIST_SCHEDULING_NODES_NUMBER_USED = + YARN_PREFIX + "distributed-scheduling.nodes-used"; + public static final int DIST_SCHEDULING_NODES_NUMBER_USED_DEFAULT = 10; /** Frequency for computing least loaded NMs. */ public static final String NM_CONTAINER_QUEUING_SORTING_NODES_INTERVAL_MS = @@ -373,13 +380,13 @@ public static boolean isAclEnabled(Configuration conf) { YARN_PREFIX + "nm-container-queuing.max-queue-length"; public static final int NM_CONTAINER_QUEUING_MAX_QUEUE_LENGTH_DEFAULT = 10; - /** Min wait time of container queue at NodeManager. */ + /** Min queue wait time for a container at a NodeManager. */ public static final String NM_CONTAINER_QUEUING_MIN_QUEUE_WAIT_TIME_MS = YARN_PREFIX + "nm-container-queuing.min-queue-wait-time-ms"; public static final int NM_CONTAINER_QUEUING_MIN_QUEUE_WAIT_TIME_MS_DEFAULT = 1; - /** Max wait time of container queue at NodeManager. */ + /** Max queue wait time for a container queue at a NodeManager. */ public static final String NM_CONTAINER_QUEUING_MAX_QUEUE_WAIT_TIME_MS = YARN_PREFIX + "nm-container-queuing.max-queue-wait-time-ms"; public static final int NM_CONTAINER_QUEUING_MAX_QUEUE_WAIT_TIME_MS_DEFAULT = @@ -1624,17 +1631,21 @@ public static boolean isAclEnabled(Configuration conf) { public static final String YARN_APPLICATION_CLASSPATH = YARN_PREFIX + "application.classpath"; + /** The setting that controls whether AMRMProxy is enabled or not. */ public static final String AMRM_PROXY_ENABLED = NM_PREFIX - + "amrmproxy.enable"; + + "amrmproxy.enabled"; public static final boolean DEFAULT_AMRM_PROXY_ENABLED = false; + public static final String AMRM_PROXY_ADDRESS = NM_PREFIX + "amrmproxy.address"; public static final int DEFAULT_AMRM_PROXY_PORT = 8048; public static final String DEFAULT_AMRM_PROXY_ADDRESS = "0.0.0.0:" + DEFAULT_AMRM_PROXY_PORT; + public static final String AMRM_PROXY_CLIENT_THREAD_COUNT = NM_PREFIX + "amrmproxy.client.thread-count"; public static final int DEFAULT_AMRM_PROXY_CLIENT_THREAD_COUNT = 25; + public static final String AMRM_PROXY_INTERCEPTOR_CLASS_PIPELINE = NM_PREFIX + "amrmproxy.interceptor-class.pipeline"; public static final String DEFAULT_AMRM_PROXY_INTERCEPTOR_CLASS_PIPELINE = diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/conf/TestYarnConfigurationFields.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/conf/TestYarnConfigurationFields.java index 61b698d..a2c7eeb 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/conf/TestYarnConfigurationFields.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/conf/TestYarnConfigurationFields.java @@ -119,21 +119,21 @@ public void initializeMemberVariables() { configurationPrefixToSkipCompare .add(YarnConfiguration.DIST_SCHEDULING_ENABLED); configurationPrefixToSkipCompare - .add(YarnConfiguration.DIST_SCHEDULING_INCR_MEMORY); + .add(YarnConfiguration.DIST_SCHEDULING_INCR_CONTAINER_MEMORY_MB); configurationPrefixToSkipCompare - .add(YarnConfiguration.DIST_SCHEDULING_INCR_VCORES); + .add(YarnConfiguration.DIST_SCHEDULING_INCR_CONTAINER_VCORES); configurationPrefixToSkipCompare - .add(YarnConfiguration.DIST_SCHEDULING_MAX_MEMORY); + .add(YarnConfiguration.DIST_SCHEDULING_MAX_MEMORY_MB); configurationPrefixToSkipCompare - .add(YarnConfiguration.DIST_SCHEDULING_MAX_VCORES); + .add(YarnConfiguration.DIST_SCHEDULING_MAX_CONTAINER_VCORES); configurationPrefixToSkipCompare .add(YarnConfiguration.DIST_SCHEDULING_CONTAINER_TOKEN_EXPIRY_MS); configurationPrefixToSkipCompare - .add(YarnConfiguration.DIST_SCHEDULING_MIN_MEMORY); + .add(YarnConfiguration.DIST_SCHEDULING_MIN_CONTAINER_MEMORY_MB); configurationPrefixToSkipCompare - .add(YarnConfiguration.DIST_SCHEDULING_MIN_VCORES); + .add(YarnConfiguration.DIST_SCHEDULING_MIN_CONTAINER_VCORES); configurationPrefixToSkipCompare - .add(YarnConfiguration.DIST_SCHEDULING_TOP_K); + .add(YarnConfiguration.DIST_SCHEDULING_NODES_NUMBER_USED); configurationPrefixToSkipCompare .add(YarnConfiguration.NM_CONTAINER_QUEUING_SORTING_NODES_INTERVAL_MS); configurationPrefixToSkipCompare diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml index ad9f977..039959d 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml @@ -142,7 +142,7 @@ ${basedir}/src/main/proto - distributed_scheduler_protocol.proto + distributed_scheduling_am_protocol.proto yarn_server_common_protos.proto yarn_server_common_service_protos.proto yarn_server_common_service_protos.proto diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/DistributedSchedulerProtocol.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/DistributedSchedulerProtocol.java deleted file mode 100644 index 490c25b..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/DistributedSchedulerProtocol.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * 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. - */ - -package org.apache.hadoop.yarn.server.api; - -import org.apache.hadoop.classification.InterfaceAudience.Public; -import org.apache.hadoop.classification.InterfaceStability.Unstable; -import org.apache.hadoop.io.retry.Idempotent; -import org.apache.hadoop.yarn.api.ApplicationMasterProtocol; -import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedAllocateResponse; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedRegisterResponse; -import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest; -import org.apache.hadoop.yarn.exceptions.YarnException; - -import java.io.IOException; - -/** - *

This protocol extends the ApplicationMasterProtocol. It is - * used by the LocalScheduler running on the NodeManager to wrap - * the request / response objects of the registerApplicationMaster - * and allocate methods of the protocol with addition information - * required to perform Distributed Scheduling. - *

- */ -public interface DistributedSchedulerProtocol - extends ApplicationMasterProtocol { - - /** - *

Extends the registerApplicationMaster to wrap the response - * with additional metadata.

- * - * @param request ApplicationMaster registration request - * @return A DistSchedRegisterResponse that contains a standard - * AM registration response along with additional information required - * for Distributed Scheduling - * @throws YarnException - * @throws IOException - */ - @Public - @Unstable - @Idempotent - DistSchedRegisterResponse registerApplicationMasterForDistributedScheduling( - RegisterApplicationMasterRequest request) - throws YarnException, IOException; - - /** - *

Extends the allocate to wrap the response with additional - * metadata.

- * - * @param request ApplicationMaster allocate request - * @return A DistSchedAllocateResponse that contains a standard - * AM allocate response along with additional information required - * for Distributed Scheduling - * @throws YarnException - * @throws IOException - */ - @Public - @Unstable - @Idempotent - DistSchedAllocateResponse allocateForDistributedScheduling( - AllocateRequest request) throws YarnException, IOException; -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/DistributedSchedulerProtocolPB.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/DistributedSchedulerProtocolPB.java deleted file mode 100644 index 413b9c9..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/DistributedSchedulerProtocolPB.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * 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. - */ - -package org.apache.hadoop.yarn.server.api; - -import org.apache.hadoop.classification.InterfaceAudience.Private; -import org.apache.hadoop.classification.InterfaceStability.Unstable; -import org.apache.hadoop.ipc.ProtocolInfo; -import org.apache.hadoop.yarn.proto.ApplicationMasterProtocol.ApplicationMasterProtocolService; - - -import org.apache.hadoop.yarn.proto.DistributedSchedulerProtocol; - -@Private -@Unstable -@ProtocolInfo(protocolName = "org.apache.hadoop.yarn.server.api.DistributedSchedulerProtocolPB", - protocolVersion = 1) -public interface DistributedSchedulerProtocolPB extends - DistributedSchedulerProtocol.DistributedSchedulerProtocolService.BlockingInterface, - ApplicationMasterProtocolService.BlockingInterface { -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/DistributedSchedulingAMProtocol.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/DistributedSchedulingAMProtocol.java new file mode 100644 index 0000000..c90c7fa --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/DistributedSchedulingAMProtocol.java @@ -0,0 +1,86 @@ +/** + * 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. + */ + +package org.apache.hadoop.yarn.server.api; + +import org.apache.hadoop.classification.InterfaceAudience.Public; +import org.apache.hadoop.classification.InterfaceStability.Unstable; +import org.apache.hadoop.io.retry.Idempotent; +import org.apache.hadoop.yarn.api.ApplicationMasterProtocol; +import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest; +import org.apache.hadoop.yarn.server.api.protocolrecords.DistributedSchedulingAllocateResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.RegisterDistributedSchedulingAMResponse; +import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest; +import org.apache.hadoop.yarn.exceptions.YarnException; + +import java.io.IOException; + +/** + *

+ * This protocol extends the ApplicationMasterProtocol. It is used + * by the DistributedScheduler running on the NodeManager to wrap + * the request / response objects of the registerApplicationMaster + * and allocate methods of the protocol with addition information + * required to perform Distributed Scheduling. + *

+ */ +public interface DistributedSchedulingAMProtocol + extends ApplicationMasterProtocol { + + /** + *

+ * Extends the registerApplicationMaster to wrap the response + * with additional metadata. + *

+ * + * @param request + * ApplicationMaster registration request + * @return A RegisterDistributedSchedulingAMResponse that + * contains a standard AM registration response along with additional + * information required for distributed scheduling + * @throws YarnException + * @throws IOException + */ + @Public + @Unstable + @Idempotent + RegisterDistributedSchedulingAMResponse + registerApplicationMasterForDistributedScheduling( + RegisterApplicationMasterRequest request) + throws YarnException, IOException; + + /** + *

+ * Extends the allocate to wrap the response with additional + * metadata. + *

+ * + * @param request + * ApplicationMaster allocate request + * @return A DistributedSchedulingAllocateResponse that contains + * a standard AM allocate response along with additional information + * required for distributed scheduling + * @throws YarnException + * @throws IOException + */ + @Public + @Unstable + @Idempotent + DistributedSchedulingAllocateResponse allocateForDistributedScheduling( + AllocateRequest request) throws YarnException, IOException; +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/DistributedSchedulingAMProtocolPB.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/DistributedSchedulingAMProtocolPB.java new file mode 100644 index 0000000..6cbd166 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/DistributedSchedulingAMProtocolPB.java @@ -0,0 +1,36 @@ +/** + * 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. + */ + +package org.apache.hadoop.yarn.server.api; + +import org.apache.hadoop.classification.InterfaceAudience.Private; +import org.apache.hadoop.classification.InterfaceStability.Unstable; +import org.apache.hadoop.ipc.ProtocolInfo; +import org.apache.hadoop.yarn.proto.ApplicationMasterProtocol.ApplicationMasterProtocolService; + +import org.apache.hadoop.yarn.proto.DistributedSchedulingAMProtocol; + +@Private +@Unstable +@ProtocolInfo(protocolName = + "org.apache.hadoop.yarn.server.api.DistributedSchedulingAMProtocolPB", + protocolVersion = 1) +public interface DistributedSchedulingAMProtocolPB extends + DistributedSchedulingAMProtocol.DistributedSchedulingAMProtocolService. + BlockingInterface, ApplicationMasterProtocolService.BlockingInterface { +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/ServerRMProxy.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/ServerRMProxy.java index c23e27c..8555fc3 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/ServerRMProxy.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/ServerRMProxy.java @@ -78,7 +78,7 @@ protected InetSocketAddress getRMAddress(YarnConfiguration conf, YarnConfiguration.RM_RESOURCE_TRACKER_ADDRESS, YarnConfiguration.DEFAULT_RM_RESOURCE_TRACKER_ADDRESS, YarnConfiguration.DEFAULT_RM_RESOURCE_TRACKER_PORT); - } else if (protocol == DistributedSchedulerProtocol.class) { + } else if (protocol == DistributedSchedulingAMProtocol.class) { return conf.getSocketAddr(YarnConfiguration.RM_SCHEDULER_ADDRESS, YarnConfiguration.DEFAULT_RM_SCHEDULER_ADDRESS, YarnConfiguration.DEFAULT_RM_SCHEDULER_PORT); diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/client/DistributedSchedulerProtocolPBClientImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/client/DistributedSchedulerProtocolPBClientImpl.java deleted file mode 100644 index c1dd9e5..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/client/DistributedSchedulerProtocolPBClientImpl.java +++ /dev/null @@ -1,151 +0,0 @@ -/** - * 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. - */ - -package org.apache.hadoop.yarn.server.api.impl.pb.client; - -import com.google.protobuf.ServiceException; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.ipc.ProtobufRpcEngine; -import org.apache.hadoop.ipc.RPC; -import org.apache.hadoop.yarn.server.api.DistributedSchedulerProtocol; -import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest; -import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedAllocateResponse; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedRegisterResponse; -import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest; -import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterResponse; -import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest; -import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.AllocateRequestPBImpl; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.AllocateResponsePBImpl; - - -import org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.DistSchedAllocateResponsePBImpl; -import org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.DistSchedRegisterResponsePBImpl; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb - .FinishApplicationMasterRequestPBImpl; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb - .FinishApplicationMasterResponsePBImpl; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb - .RegisterApplicationMasterRequestPBImpl; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb - .RegisterApplicationMasterResponsePBImpl; -import org.apache.hadoop.yarn.exceptions.YarnException; -import org.apache.hadoop.yarn.ipc.RPCUtil; -import org.apache.hadoop.yarn.proto.YarnServiceProtos; -import org.apache.hadoop.yarn.server.api.DistributedSchedulerProtocolPB; - -import java.io.Closeable; -import java.io.IOException; -import java.net.InetSocketAddress; - -public class DistributedSchedulerProtocolPBClientImpl implements - DistributedSchedulerProtocol, Closeable { - - private DistributedSchedulerProtocolPB proxy; - - public DistributedSchedulerProtocolPBClientImpl(long clientVersion, - InetSocketAddress addr, - Configuration conf) throws IOException { - RPC.setProtocolEngine(conf, DistributedSchedulerProtocolPB.class, - ProtobufRpcEngine.class); - proxy = RPC.getProxy(DistributedSchedulerProtocolPB.class, clientVersion, - addr, conf); - } - - @Override - public void close() { - if (this.proxy != null) { - RPC.stopProxy(this.proxy); - } - } - - @Override - public DistSchedRegisterResponse - registerApplicationMasterForDistributedScheduling - (RegisterApplicationMasterRequest request) throws YarnException, - IOException { - YarnServiceProtos.RegisterApplicationMasterRequestProto requestProto = - ((RegisterApplicationMasterRequestPBImpl) request).getProto(); - try { - return new DistSchedRegisterResponsePBImpl( - proxy.registerApplicationMasterForDistributedScheduling( - null, requestProto)); - } catch (ServiceException e) { - RPCUtil.unwrapAndThrowException(e); - return null; - } - } - - @Override - public DistSchedAllocateResponse allocateForDistributedScheduling - (AllocateRequest request) throws YarnException, IOException { - YarnServiceProtos.AllocateRequestProto requestProto = - ((AllocateRequestPBImpl) request).getProto(); - try { - return new DistSchedAllocateResponsePBImpl( - proxy.allocateForDistributedScheduling(null, requestProto)); - } catch (ServiceException e) { - RPCUtil.unwrapAndThrowException(e); - return null; - } - } - - @Override - public RegisterApplicationMasterResponse registerApplicationMaster - (RegisterApplicationMasterRequest request) throws YarnException, - IOException { - YarnServiceProtos.RegisterApplicationMasterRequestProto requestProto = - ((RegisterApplicationMasterRequestPBImpl) request).getProto(); - try { - return new RegisterApplicationMasterResponsePBImpl( - proxy.registerApplicationMaster(null, requestProto)); - } catch (ServiceException e) { - RPCUtil.unwrapAndThrowException(e); - return null; - } - } - - @Override - public FinishApplicationMasterResponse finishApplicationMaster - (FinishApplicationMasterRequest request) throws YarnException, - IOException { - YarnServiceProtos.FinishApplicationMasterRequestProto requestProto = - ((FinishApplicationMasterRequestPBImpl) request).getProto(); - try { - return new FinishApplicationMasterResponsePBImpl( - proxy.finishApplicationMaster(null, requestProto)); - } catch (ServiceException e) { - RPCUtil.unwrapAndThrowException(e); - return null; - } - } - - @Override - public AllocateResponse allocate(AllocateRequest request) throws - YarnException, IOException { - YarnServiceProtos.AllocateRequestProto requestProto = - ((AllocateRequestPBImpl) request).getProto(); - try { - return new AllocateResponsePBImpl(proxy.allocate(null, requestProto)); - } catch (ServiceException e) { - RPCUtil.unwrapAndThrowException(e); - return null; - } - } -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/client/DistributedSchedulingAMProtocolPBClientImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/client/DistributedSchedulingAMProtocolPBClientImpl.java new file mode 100644 index 0000000..41bc38c --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/client/DistributedSchedulingAMProtocolPBClientImpl.java @@ -0,0 +1,145 @@ +/** + * 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. + */ + +package org.apache.hadoop.yarn.server.api.impl.pb.client; + +import com.google.protobuf.ServiceException; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.ipc.ProtobufRpcEngine; +import org.apache.hadoop.ipc.RPC; +import org.apache.hadoop.yarn.server.api.DistributedSchedulingAMProtocol; +import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest; +import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.DistributedSchedulingAllocateResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.RegisterDistributedSchedulingAMResponse; +import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest; +import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterResponse; +import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest; +import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.AllocateRequestPBImpl; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.AllocateResponsePBImpl; +import org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.DistributedSchedulingAllocateResponsePBImpl; +import org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.RegisterDistributedSchedulingAMResponsePBImpl; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.FinishApplicationMasterRequestPBImpl; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.FinishApplicationMasterResponsePBImpl; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RegisterApplicationMasterRequestPBImpl; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RegisterApplicationMasterResponsePBImpl; +import org.apache.hadoop.yarn.exceptions.YarnException; +import org.apache.hadoop.yarn.ipc.RPCUtil; +import org.apache.hadoop.yarn.proto.YarnServiceProtos; +import org.apache.hadoop.yarn.server.api.DistributedSchedulingAMProtocolPB; + +import java.io.Closeable; +import java.io.IOException; +import java.net.InetSocketAddress; + +public class DistributedSchedulingAMProtocolPBClientImpl implements + DistributedSchedulingAMProtocol, Closeable { + + private DistributedSchedulingAMProtocolPB proxy; + + public DistributedSchedulingAMProtocolPBClientImpl(long clientVersion, + InetSocketAddress addr, + Configuration conf) throws IOException { + RPC.setProtocolEngine(conf, DistributedSchedulingAMProtocolPB.class, + ProtobufRpcEngine.class); + proxy = RPC.getProxy(DistributedSchedulingAMProtocolPB.class, clientVersion, + addr, conf); + } + + @Override + public void close() { + if (this.proxy != null) { + RPC.stopProxy(this.proxy); + } + } + + @Override + public RegisterDistributedSchedulingAMResponse + registerApplicationMasterForDistributedScheduling + (RegisterApplicationMasterRequest request) throws YarnException, + IOException { + YarnServiceProtos.RegisterApplicationMasterRequestProto requestProto = + ((RegisterApplicationMasterRequestPBImpl) request).getProto(); + try { + return new RegisterDistributedSchedulingAMResponsePBImpl( + proxy.registerApplicationMasterForDistributedScheduling( + null, requestProto)); + } catch (ServiceException e) { + RPCUtil.unwrapAndThrowException(e); + return null; + } + } + + @Override + public DistributedSchedulingAllocateResponse allocateForDistributedScheduling + (AllocateRequest request) throws YarnException, IOException { + YarnServiceProtos.AllocateRequestProto requestProto = + ((AllocateRequestPBImpl) request).getProto(); + try { + return new DistributedSchedulingAllocateResponsePBImpl( + proxy.allocateForDistributedScheduling(null, requestProto)); + } catch (ServiceException e) { + RPCUtil.unwrapAndThrowException(e); + return null; + } + } + + @Override + public RegisterApplicationMasterResponse registerApplicationMaster + (RegisterApplicationMasterRequest request) throws YarnException, + IOException { + YarnServiceProtos.RegisterApplicationMasterRequestProto requestProto = + ((RegisterApplicationMasterRequestPBImpl) request).getProto(); + try { + return new RegisterApplicationMasterResponsePBImpl( + proxy.registerApplicationMaster(null, requestProto)); + } catch (ServiceException e) { + RPCUtil.unwrapAndThrowException(e); + return null; + } + } + + @Override + public FinishApplicationMasterResponse finishApplicationMaster + (FinishApplicationMasterRequest request) throws YarnException, + IOException { + YarnServiceProtos.FinishApplicationMasterRequestProto requestProto = + ((FinishApplicationMasterRequestPBImpl) request).getProto(); + try { + return new FinishApplicationMasterResponsePBImpl( + proxy.finishApplicationMaster(null, requestProto)); + } catch (ServiceException e) { + RPCUtil.unwrapAndThrowException(e); + return null; + } + } + + @Override + public AllocateResponse allocate(AllocateRequest request) throws + YarnException, IOException { + YarnServiceProtos.AllocateRequestProto requestProto = + ((AllocateRequestPBImpl) request).getProto(); + try { + return new AllocateResponsePBImpl(proxy.allocate(null, requestProto)); + } catch (ServiceException e) { + RPCUtil.unwrapAndThrowException(e); + return null; + } + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/service/DistributedSchedulerProtocolPBServiceImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/service/DistributedSchedulerProtocolPBServiceImpl.java deleted file mode 100644 index 8be2893..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/service/DistributedSchedulerProtocolPBServiceImpl.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * 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. - */ - -package org.apache.hadoop.yarn.server.api.impl.pb.service; - -import com.google.protobuf.RpcController; -import com.google.protobuf.ServiceException; -import org.apache.hadoop.yarn.server.api.DistributedSchedulerProtocol; -import org.apache.hadoop.yarn.proto.YarnServerCommonServiceProtos; -import org.apache.hadoop.yarn.server.api.DistributedSchedulerProtocolPB; -import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedAllocateResponse; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedRegisterResponse; -import org.apache.hadoop.yarn.api.protocolrecords - .FinishApplicationMasterResponse; -import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.AllocateRequestPBImpl; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.AllocateResponsePBImpl; -import org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.DistSchedAllocateResponsePBImpl; -import org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.DistSchedRegisterResponsePBImpl; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb - .FinishApplicationMasterRequestPBImpl; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb - .FinishApplicationMasterResponsePBImpl; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RegisterApplicationMasterRequestPBImpl; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RegisterApplicationMasterResponsePBImpl; -import org.apache.hadoop.yarn.exceptions.YarnException; -import org.apache.hadoop.yarn.proto.YarnServiceProtos; -import org.apache.hadoop.yarn.proto.YarnServiceProtos.AllocateRequestProto; -import org.apache.hadoop.yarn.proto.YarnServiceProtos.RegisterApplicationMasterRequestProto; - -import java.io.IOException; - -public class DistributedSchedulerProtocolPBServiceImpl implements - DistributedSchedulerProtocolPB { - - private DistributedSchedulerProtocol real; - - public DistributedSchedulerProtocolPBServiceImpl( - DistributedSchedulerProtocol impl) { - this.real = impl; - } - - @Override - public YarnServerCommonServiceProtos.DistSchedRegisterResponseProto - registerApplicationMasterForDistributedScheduling(RpcController controller, - RegisterApplicationMasterRequestProto proto) throws - ServiceException { - RegisterApplicationMasterRequestPBImpl request = new - RegisterApplicationMasterRequestPBImpl(proto); - try { - DistSchedRegisterResponse response = - real.registerApplicationMasterForDistributedScheduling(request); - return ((DistSchedRegisterResponsePBImpl) response).getProto(); - } catch (YarnException e) { - throw new ServiceException(e); - } catch (IOException e) { - throw new ServiceException(e); - } - } - - @Override - public YarnServerCommonServiceProtos.DistSchedAllocateResponseProto - allocateForDistributedScheduling(RpcController controller, - AllocateRequestProto proto) throws ServiceException { - AllocateRequestPBImpl request = new AllocateRequestPBImpl(proto); - try { - DistSchedAllocateResponse response = real - .allocateForDistributedScheduling(request); - return ((DistSchedAllocateResponsePBImpl) response).getProto(); - } catch (YarnException e) { - throw new ServiceException(e); - } catch (IOException e) { - throw new ServiceException(e); - } - } - - @Override - public YarnServiceProtos.AllocateResponseProto allocate(RpcController arg0, - AllocateRequestProto proto) throws ServiceException { - AllocateRequestPBImpl request = new AllocateRequestPBImpl(proto); - try { - AllocateResponse response = real.allocate(request); - return ((AllocateResponsePBImpl) response).getProto(); - } catch (YarnException e) { - throw new ServiceException(e); - } catch (IOException e) { - throw new ServiceException(e); - } - } - - @Override - public YarnServiceProtos.FinishApplicationMasterResponseProto - finishApplicationMaster( - RpcController arg0, YarnServiceProtos - .FinishApplicationMasterRequestProto proto) - throws ServiceException { - FinishApplicationMasterRequestPBImpl request = new - FinishApplicationMasterRequestPBImpl(proto); - try { - FinishApplicationMasterResponse response = real.finishApplicationMaster - (request); - return ((FinishApplicationMasterResponsePBImpl) response).getProto(); - } catch (YarnException e) { - throw new ServiceException(e); - } catch (IOException e) { - throw new ServiceException(e); - } - } - - @Override - public YarnServiceProtos.RegisterApplicationMasterResponseProto - registerApplicationMaster( - RpcController arg0, RegisterApplicationMasterRequestProto proto) - throws ServiceException { - RegisterApplicationMasterRequestPBImpl request = new - RegisterApplicationMasterRequestPBImpl(proto); - try { - RegisterApplicationMasterResponse response = real - .registerApplicationMaster(request); - return ((RegisterApplicationMasterResponsePBImpl) response).getProto(); - } catch (YarnException e) { - throw new ServiceException(e); - } catch (IOException e) { - throw new ServiceException(e); - } - } -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/service/DistributedSchedulingAMProtocolPBServiceImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/service/DistributedSchedulingAMProtocolPBServiceImpl.java new file mode 100644 index 0000000..2c1838b --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/service/DistributedSchedulingAMProtocolPBServiceImpl.java @@ -0,0 +1,144 @@ +/** + * 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. + */ + +package org.apache.hadoop.yarn.server.api.impl.pb.service; + +import com.google.protobuf.RpcController; +import com.google.protobuf.ServiceException; +import org.apache.hadoop.yarn.server.api.DistributedSchedulingAMProtocol; +import org.apache.hadoop.yarn.proto.YarnServerCommonServiceProtos; +import org.apache.hadoop.yarn.server.api.DistributedSchedulingAMProtocolPB; +import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.DistributedSchedulingAllocateResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.RegisterDistributedSchedulingAMResponse; +import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterResponse; +import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.AllocateRequestPBImpl; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.AllocateResponsePBImpl; +import org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.DistributedSchedulingAllocateResponsePBImpl; +import org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.RegisterDistributedSchedulingAMResponsePBImpl; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.FinishApplicationMasterRequestPBImpl; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.FinishApplicationMasterResponsePBImpl; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RegisterApplicationMasterRequestPBImpl; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RegisterApplicationMasterResponsePBImpl; +import org.apache.hadoop.yarn.exceptions.YarnException; +import org.apache.hadoop.yarn.proto.YarnServiceProtos; +import org.apache.hadoop.yarn.proto.YarnServiceProtos.AllocateRequestProto; +import org.apache.hadoop.yarn.proto.YarnServiceProtos.RegisterApplicationMasterRequestProto; + +import java.io.IOException; + +public class DistributedSchedulingAMProtocolPBServiceImpl implements + DistributedSchedulingAMProtocolPB { + + private DistributedSchedulingAMProtocol real; + + public DistributedSchedulingAMProtocolPBServiceImpl( + DistributedSchedulingAMProtocol impl) { + this.real = impl; + } + + @Override + public YarnServerCommonServiceProtos. + RegisterDistributedSchedulingAMResponseProto + registerApplicationMasterForDistributedScheduling( + RpcController controller, RegisterApplicationMasterRequestProto proto) + throws ServiceException { + RegisterApplicationMasterRequestPBImpl request = new + RegisterApplicationMasterRequestPBImpl(proto); + try { + RegisterDistributedSchedulingAMResponse response = + real.registerApplicationMasterForDistributedScheduling(request); + return ((RegisterDistributedSchedulingAMResponsePBImpl) response) + .getProto(); + } catch (YarnException e) { + throw new ServiceException(e); + } catch (IOException e) { + throw new ServiceException(e); + } + } + + @Override + public YarnServerCommonServiceProtos. + DistributedSchedulingAllocateResponseProto + allocateForDistributedScheduling(RpcController controller, + AllocateRequestProto proto) throws ServiceException { + AllocateRequestPBImpl request = new AllocateRequestPBImpl(proto); + try { + DistributedSchedulingAllocateResponse response = real + .allocateForDistributedScheduling(request); + return ((DistributedSchedulingAllocateResponsePBImpl) response) + .getProto(); + } catch (YarnException e) { + throw new ServiceException(e); + } catch (IOException e) { + throw new ServiceException(e); + } + } + + @Override + public YarnServiceProtos.AllocateResponseProto allocate(RpcController arg0, + AllocateRequestProto proto) throws ServiceException { + AllocateRequestPBImpl request = new AllocateRequestPBImpl(proto); + try { + AllocateResponse response = real.allocate(request); + return ((AllocateResponsePBImpl) response).getProto(); + } catch (YarnException e) { + throw new ServiceException(e); + } catch (IOException e) { + throw new ServiceException(e); + } + } + + @Override + public YarnServiceProtos.FinishApplicationMasterResponseProto + finishApplicationMaster( + RpcController arg0, YarnServiceProtos + .FinishApplicationMasterRequestProto proto) + throws ServiceException { + FinishApplicationMasterRequestPBImpl request = new + FinishApplicationMasterRequestPBImpl(proto); + try { + FinishApplicationMasterResponse response = real.finishApplicationMaster + (request); + return ((FinishApplicationMasterResponsePBImpl) response).getProto(); + } catch (YarnException e) { + throw new ServiceException(e); + } catch (IOException e) { + throw new ServiceException(e); + } + } + + @Override + public YarnServiceProtos.RegisterApplicationMasterResponseProto + registerApplicationMaster( + RpcController arg0, RegisterApplicationMasterRequestProto proto) + throws ServiceException { + RegisterApplicationMasterRequestPBImpl request = new + RegisterApplicationMasterRequestPBImpl(proto); + try { + RegisterApplicationMasterResponse response = real + .registerApplicationMaster(request); + return ((RegisterApplicationMasterResponsePBImpl) response).getProto(); + } catch (YarnException e) { + throw new ServiceException(e); + } catch (IOException e) { + throw new ServiceException(e); + } + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/DistSchedAllocateResponse.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/DistSchedAllocateResponse.java deleted file mode 100644 index 5f6e069..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/DistSchedAllocateResponse.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * 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. - */ - -package org.apache.hadoop.yarn.server.api.protocolrecords; - -import org.apache.hadoop.classification.InterfaceAudience.Public; -import org.apache.hadoop.classification.InterfaceStability.Unstable; -import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse; -import org.apache.hadoop.yarn.api.records.NodeId; -import org.apache.hadoop.yarn.util.Records; - -import java.util.List; - -@Public -@Unstable -public abstract class DistSchedAllocateResponse { - - @Public - @Unstable - public static DistSchedAllocateResponse newInstance(AllocateResponse - allResp) { - DistSchedAllocateResponse response = - Records.newRecord(DistSchedAllocateResponse.class); - response.setAllocateResponse(allResp); - return response; - } - - @Public - @Unstable - public abstract void setAllocateResponse(AllocateResponse response); - - @Public - @Unstable - public abstract AllocateResponse getAllocateResponse(); - - @Public - @Unstable - public abstract void setNodesForScheduling(List nodesForScheduling); - - @Public - @Unstable - public abstract List getNodesForScheduling(); -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/DistSchedRegisterResponse.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/DistSchedRegisterResponse.java deleted file mode 100644 index e4e5138..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/DistSchedRegisterResponse.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * 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. - */ - -package org.apache.hadoop.yarn.server.api.protocolrecords; - -import org.apache.hadoop.classification.InterfaceAudience.Public; -import org.apache.hadoop.classification.InterfaceStability.Unstable; -import org.apache.hadoop.yarn.api.protocolrecords - .RegisterApplicationMasterResponse; -import org.apache.hadoop.yarn.api.records.NodeId; -import org.apache.hadoop.yarn.api.records.Resource; -import org.apache.hadoop.yarn.util.Records; - -import java.util.List; - -@Public -@Unstable -public abstract class DistSchedRegisterResponse { - - @Public - @Unstable - public static DistSchedRegisterResponse newInstance - (RegisterApplicationMasterResponse regAMResp) { - DistSchedRegisterResponse response = - Records.newRecord(DistSchedRegisterResponse.class); - response.setRegisterResponse(regAMResp); - return response; - } - - @Public - @Unstable - public abstract void setRegisterResponse( - RegisterApplicationMasterResponse resp); - - @Public - @Unstable - public abstract RegisterApplicationMasterResponse getRegisterResponse(); - - @Public - @Unstable - public abstract void setMinAllocatableCapabilty(Resource minResource); - - @Public - @Unstable - public abstract Resource getMinAllocatableCapabilty(); - - @Public - @Unstable - public abstract void setMaxAllocatableCapabilty(Resource maxResource); - - @Public - @Unstable - public abstract Resource getMaxAllocatableCapabilty(); - - @Public - @Unstable - public abstract void setIncrAllocatableCapabilty(Resource maxResource); - - @Public - @Unstable - public abstract Resource getIncrAllocatableCapabilty(); - - @Public - @Unstable - public abstract void setContainerTokenExpiryInterval(int interval); - - @Public - @Unstable - public abstract int getContainerTokenExpiryInterval(); - - @Public - @Unstable - public abstract void setContainerIdStart(long containerIdStart); - - @Public - @Unstable - public abstract long getContainerIdStart(); - - @Public - @Unstable - public abstract void setNodesForScheduling(List nodesForScheduling); - - @Public - @Unstable - public abstract List getNodesForScheduling(); - -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/DistSchedAllocateResponsePBImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/DistSchedAllocateResponsePBImpl.java deleted file mode 100644 index 3ea4965..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/DistSchedAllocateResponsePBImpl.java +++ /dev/null @@ -1,180 +0,0 @@ -/** - * 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. - */ - -package org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb; - -import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse; - -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb - .AllocateResponsePBImpl; -import org.apache.hadoop.yarn.api.records.NodeId; -import org.apache.hadoop.yarn.api.records.impl.pb.ProtoUtils; -import org.apache.hadoop.yarn.proto.YarnProtos; -import org.apache.hadoop.yarn.proto.YarnServerCommonServiceProtos; -import org.apache.hadoop.yarn.proto.YarnServiceProtos; -import org.apache.hadoop.yarn.server.api.protocolrecords - .DistSchedAllocateResponse; - - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class DistSchedAllocateResponsePBImpl extends DistSchedAllocateResponse { - - YarnServerCommonServiceProtos.DistSchedAllocateResponseProto proto = - YarnServerCommonServiceProtos.DistSchedAllocateResponseProto.getDefaultInstance(); - YarnServerCommonServiceProtos.DistSchedAllocateResponseProto.Builder builder = null; - boolean viaProto = false; - - private AllocateResponse allocateResponse; - private List nodesForScheduling; - - public DistSchedAllocateResponsePBImpl() { - builder = YarnServerCommonServiceProtos.DistSchedAllocateResponseProto.newBuilder(); - } - - public DistSchedAllocateResponsePBImpl(YarnServerCommonServiceProtos.DistSchedAllocateResponseProto proto) { - this.proto = proto; - viaProto = true; - } - - public YarnServerCommonServiceProtos.DistSchedAllocateResponseProto getProto() { - mergeLocalToProto(); - proto = viaProto ? proto : builder.build(); - viaProto = true; - return proto; - } - - private void maybeInitBuilder() { - if (viaProto || builder == null) { - builder = YarnServerCommonServiceProtos.DistSchedAllocateResponseProto.newBuilder(proto); - } - viaProto = false; - } - - private synchronized void mergeLocalToProto() { - if (viaProto) - maybeInitBuilder(); - mergeLocalToBuilder(); - proto = builder.build(); - viaProto = true; - } - - private synchronized void mergeLocalToBuilder() { - if (this.nodesForScheduling != null) { - builder.clearNodesForScheduling(); - Iterable iterable = - getNodeIdProtoIterable(this.nodesForScheduling); - builder.addAllNodesForScheduling(iterable); - } - if (this.allocateResponse != null) { - builder.setAllocateResponse( - ((AllocateResponsePBImpl)this.allocateResponse).getProto()); - } - } - @Override - public void setAllocateResponse(AllocateResponse response) { - maybeInitBuilder(); - if(allocateResponse == null) { - builder.clearAllocateResponse(); - } - this.allocateResponse = response; - } - - @Override - public AllocateResponse getAllocateResponse() { - if (this.allocateResponse != null) { - return this.allocateResponse; - } - - YarnServerCommonServiceProtos.DistSchedAllocateResponseProtoOrBuilder p = - viaProto ? proto : builder; - if (!p.hasAllocateResponse()) { - return null; - } - - this.allocateResponse = - new AllocateResponsePBImpl(p.getAllocateResponse()); - return this.allocateResponse; - } - - @Override - public void setNodesForScheduling(List nodesForScheduling) { - maybeInitBuilder(); - if (nodesForScheduling == null || nodesForScheduling.isEmpty()) { - if (this.nodesForScheduling != null) { - this.nodesForScheduling.clear(); - } - builder.clearNodesForScheduling(); - return; - } - this.nodesForScheduling = new ArrayList<>(); - this.nodesForScheduling.addAll(nodesForScheduling); - } - - @Override - public List getNodesForScheduling() { - if (nodesForScheduling != null) { - return nodesForScheduling; - } - initLocalNodesForSchedulingList(); - return nodesForScheduling; - } - - private synchronized void initLocalNodesForSchedulingList() { - YarnServerCommonServiceProtos.DistSchedAllocateResponseProtoOrBuilder p = - viaProto ? proto : builder; - List list = p.getNodesForSchedulingList(); - nodesForScheduling = new ArrayList<>(); - if (list != null) { - for (YarnProtos.NodeIdProto t : list) { - nodesForScheduling.add(ProtoUtils.convertFromProtoFormat(t)); - } - } - } - private synchronized Iterable getNodeIdProtoIterable( - final List nodeList) { - maybeInitBuilder(); - return new Iterable() { - @Override - public synchronized Iterator iterator() { - return new Iterator() { - - Iterator iter = nodeList.iterator(); - - @Override - public boolean hasNext() { - return iter.hasNext(); - } - - @Override - public YarnProtos.NodeIdProto next() { - return ProtoUtils.convertToProtoFormat(iter.next()); - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; - } - }; - } - -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/DistSchedRegisterResponsePBImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/DistSchedRegisterResponsePBImpl.java deleted file mode 100644 index 0322c70..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/DistSchedRegisterResponsePBImpl.java +++ /dev/null @@ -1,304 +0,0 @@ -/** - * 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. - */ - -package org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb; - -import com.google.protobuf.TextFormat; - -import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse; - - -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb - .RegisterApplicationMasterResponsePBImpl; -import org.apache.hadoop.yarn.api.records.NodeId; -import org.apache.hadoop.yarn.api.records.Resource; -import org.apache.hadoop.yarn.api.records.impl.pb.ProtoUtils; -import org.apache.hadoop.yarn.proto.YarnProtos; -import org.apache.hadoop.yarn.proto.YarnServerCommonServiceProtos; -import org.apache.hadoop.yarn.server.api.protocolrecords - .DistSchedRegisterResponse; - - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class DistSchedRegisterResponsePBImpl extends DistSchedRegisterResponse { - - YarnServerCommonServiceProtos.DistSchedRegisterResponseProto proto = - YarnServerCommonServiceProtos.DistSchedRegisterResponseProto.getDefaultInstance(); - YarnServerCommonServiceProtos.DistSchedRegisterResponseProto.Builder builder = null; - boolean viaProto = false; - - private Resource maxAllocatableCapability; - private Resource minAllocatableCapability; - private Resource incrAllocatableCapability; - private List nodesForScheduling; - private RegisterApplicationMasterResponse registerApplicationMasterResponse; - - public DistSchedRegisterResponsePBImpl() { - builder = YarnServerCommonServiceProtos.DistSchedRegisterResponseProto.newBuilder(); - } - - public DistSchedRegisterResponsePBImpl(YarnServerCommonServiceProtos.DistSchedRegisterResponseProto proto) { - this.proto = proto; - viaProto = true; - } - - public YarnServerCommonServiceProtos.DistSchedRegisterResponseProto getProto() { - mergeLocalToProto(); - proto = viaProto ? proto : builder.build(); - viaProto = true; - return proto; - } - - private void maybeInitBuilder() { - if (viaProto || builder == null) { - builder = YarnServerCommonServiceProtos.DistSchedRegisterResponseProto.newBuilder(proto); - } - viaProto = false; - } - - private synchronized void mergeLocalToProto() { - if (viaProto) - maybeInitBuilder(); - mergeLocalToBuilder(); - proto = builder.build(); - viaProto = true; - } - - private synchronized void mergeLocalToBuilder() { - if (this.nodesForScheduling != null) { - builder.clearNodesForScheduling(); - Iterable iterable = - getNodeIdProtoIterable(this.nodesForScheduling); - builder.addAllNodesForScheduling(iterable); - } - if (this.maxAllocatableCapability != null) { - builder.setMaxAllocCapability( - ProtoUtils.convertToProtoFormat(this.maxAllocatableCapability)); - } - if (this.minAllocatableCapability != null) { - builder.setMaxAllocCapability( - ProtoUtils.convertToProtoFormat(this.minAllocatableCapability)); - } - if (this.registerApplicationMasterResponse != null) { - builder.setRegisterResponse( - ((RegisterApplicationMasterResponsePBImpl) - this.registerApplicationMasterResponse).getProto()); - } - } - - @Override - public void setRegisterResponse(RegisterApplicationMasterResponse resp) { - maybeInitBuilder(); - if(registerApplicationMasterResponse == null) { - builder.clearRegisterResponse(); - } - this.registerApplicationMasterResponse = resp; - } - - @Override - public RegisterApplicationMasterResponse getRegisterResponse() { - if (this.registerApplicationMasterResponse != null) { - return this.registerApplicationMasterResponse; - } - - YarnServerCommonServiceProtos.DistSchedRegisterResponseProtoOrBuilder p = viaProto ? proto : builder; - if (!p.hasRegisterResponse()) { - return null; - } - - this.registerApplicationMasterResponse = - new RegisterApplicationMasterResponsePBImpl(p.getRegisterResponse()); - return this.registerApplicationMasterResponse; - } - - @Override - public void setMaxAllocatableCapabilty(Resource maxResource) { - maybeInitBuilder(); - if(maxAllocatableCapability == null) { - builder.clearMaxAllocCapability(); - } - this.maxAllocatableCapability = maxResource; - } - - @Override - public Resource getMaxAllocatableCapabilty() { - if (this.maxAllocatableCapability != null) { - return this.maxAllocatableCapability; - } - - YarnServerCommonServiceProtos.DistSchedRegisterResponseProtoOrBuilder p = viaProto ? proto : builder; - if (!p.hasMaxAllocCapability()) { - return null; - } - - this.maxAllocatableCapability = - ProtoUtils.convertFromProtoFormat(p.getMaxAllocCapability()); - return this.maxAllocatableCapability; - } - - @Override - public void setMinAllocatableCapabilty(Resource minResource) { - maybeInitBuilder(); - if(minAllocatableCapability == null) { - builder.clearMinAllocCapability(); - } - this.minAllocatableCapability = minResource; - } - - @Override - public Resource getMinAllocatableCapabilty() { - if (this.minAllocatableCapability != null) { - return this.minAllocatableCapability; - } - - YarnServerCommonServiceProtos.DistSchedRegisterResponseProtoOrBuilder p = viaProto ? proto : builder; - if (!p.hasMinAllocCapability()) { - return null; - } - - this.minAllocatableCapability = - ProtoUtils.convertFromProtoFormat(p.getMinAllocCapability()); - return this.minAllocatableCapability; - } - - @Override - public void setIncrAllocatableCapabilty(Resource incrResource) { - maybeInitBuilder(); - if(incrAllocatableCapability == null) { - builder.clearIncrAllocCapability(); - } - this.incrAllocatableCapability = incrResource; - } - - @Override - public Resource getIncrAllocatableCapabilty() { - if (this.incrAllocatableCapability != null) { - return this.incrAllocatableCapability; - } - - YarnServerCommonServiceProtos.DistSchedRegisterResponseProtoOrBuilder p = viaProto ? proto : builder; - if (!p.hasIncrAllocCapability()) { - return null; - } - - this.incrAllocatableCapability = - ProtoUtils.convertFromProtoFormat(p.getIncrAllocCapability()); - return this.incrAllocatableCapability; - } - - @Override - public void setContainerTokenExpiryInterval(int interval) { - maybeInitBuilder(); - builder.setContainerTokenExpiryInterval(interval); - } - - @Override - public int getContainerTokenExpiryInterval() { - YarnServerCommonServiceProtos.DistSchedRegisterResponseProtoOrBuilder p = viaProto ? proto : builder; - if (!p.hasContainerTokenExpiryInterval()) { - return 0; - } - return p.getContainerTokenExpiryInterval(); - } - - @Override - public void setContainerIdStart(long containerIdStart) { - maybeInitBuilder(); - builder.setContainerIdStart(containerIdStart); - } - - @Override - public long getContainerIdStart() { - YarnServerCommonServiceProtos.DistSchedRegisterResponseProtoOrBuilder p = viaProto ? proto : builder; - if (!p.hasContainerIdStart()) { - return 0; - } - return p.getContainerIdStart(); - } - - - @Override - public void setNodesForScheduling(List nodesForScheduling) { - maybeInitBuilder(); - if (nodesForScheduling == null || nodesForScheduling.isEmpty()) { - if (this.nodesForScheduling != null) { - this.nodesForScheduling.clear(); - } - builder.clearNodesForScheduling(); - return; - } - this.nodesForScheduling = new ArrayList<>(); - this.nodesForScheduling.addAll(nodesForScheduling); - } - - @Override - public List getNodesForScheduling() { - if (nodesForScheduling != null) { - return nodesForScheduling; - } - initLocalNodesForSchedulingList(); - return nodesForScheduling; - } - - private synchronized void initLocalNodesForSchedulingList() { - YarnServerCommonServiceProtos.DistSchedRegisterResponseProtoOrBuilder p = viaProto ? proto : builder; - List list = p.getNodesForSchedulingList(); - nodesForScheduling = new ArrayList<>(); - if (list != null) { - for (YarnProtos.NodeIdProto t : list) { - nodesForScheduling.add(ProtoUtils.convertFromProtoFormat(t)); - } - } - } - private synchronized Iterable getNodeIdProtoIterable( - final List nodeList) { - maybeInitBuilder(); - return new Iterable() { - @Override - public synchronized Iterator iterator() { - return new Iterator() { - - Iterator iter = nodeList.iterator(); - - @Override - public boolean hasNext() { - return iter.hasNext(); - } - - @Override - public YarnProtos.NodeIdProto next() { - return ProtoUtils.convertToProtoFormat(iter.next()); - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; - } - }; - } - - @Override - public String toString() { - return TextFormat.shortDebugString(getProto()); - } -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/records/QueuedContainersStatus.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/records/QueuedContainersStatus.java index fb567d5..a7f0ece 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/records/QueuedContainersStatus.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/records/QueuedContainersStatus.java @@ -41,5 +41,5 @@ public static QueuedContainersStatus newInstance() { public abstract int getWaitQueueLength(); - public abstract void setWaitQueueLength(int waitQueueLength); + public abstract void setWaitQueueLength(int queueWaitTime); } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/proto/distributed_scheduler_protocol.proto hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/proto/distributed_scheduler_protocol.proto deleted file mode 100644 index 7e3a77f..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/proto/distributed_scheduler_protocol.proto +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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 http://wiki.apache.org/hadoop/Compatibility - * for what changes are allowed for a *stable* .proto interface. - */ - -option java_package = "org.apache.hadoop.yarn.proto"; -option java_outer_classname = "DistributedSchedulerProtocol"; -option java_generic_services = true; -option java_generate_equals_and_hash = true; -package hadoop.yarn; - -import "yarn_service_protos.proto"; -import "yarn_server_common_service_protos.proto"; - - -service DistributedSchedulerProtocolService { - rpc registerApplicationMasterForDistributedScheduling (RegisterApplicationMasterRequestProto) returns (DistSchedRegisterResponseProto); - rpc allocateForDistributedScheduling (AllocateRequestProto) returns (DistSchedAllocateResponseProto); -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/proto/distributed_scheduling_am_protocol.proto hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/proto/distributed_scheduling_am_protocol.proto new file mode 100644 index 0000000..d628f47 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/proto/distributed_scheduling_am_protocol.proto @@ -0,0 +1,38 @@ +/** + * 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 http://wiki.apache.org/hadoop/Compatibility + * for what changes are allowed for a *stable* .proto interface. + */ + +option java_package = "org.apache.hadoop.yarn.proto"; +option java_outer_classname = "DistributedSchedulingAMProtocol"; +option java_generic_services = true; +option java_generate_equals_and_hash = true; +package hadoop.yarn; + +import "yarn_service_protos.proto"; +import "yarn_server_common_service_protos.proto"; + + +service DistributedSchedulingAMProtocolService { + rpc registerApplicationMasterForDistributedScheduling (RegisterApplicationMasterRequestProto) returns (RegisterDistributedSchedulingAMResponseProto); + rpc allocateForDistributedScheduling (AllocateRequestProto) returns (DistributedSchedulingAllocateResponseProto); +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/proto/yarn_server_common_service_protos.proto hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/proto/yarn_server_common_service_protos.proto index a7e5a86..b19bce7 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/proto/yarn_server_common_service_protos.proto +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/proto/yarn_server_common_service_protos.proto @@ -26,17 +26,17 @@ import "yarn_protos.proto"; import "yarn_server_common_protos.proto"; import "yarn_service_protos.proto"; -message DistSchedRegisterResponseProto { +message RegisterDistributedSchedulingAMResponseProto { optional RegisterApplicationMasterResponseProto register_response = 1; - optional ResourceProto max_alloc_capability = 2; - optional ResourceProto min_alloc_capability = 3; - optional ResourceProto incr_alloc_capability = 4; + 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 NodeIdProto nodes_for_scheduling = 7; } -message DistSchedAllocateResponseProto { +message DistributedSchedulingAllocateResponseProto { optional AllocateResponseProto allocate_response = 1; repeated NodeIdProto nodes_for_scheduling = 2; } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/AMRMProxyService.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/AMRMProxyService.java index ac360f4..084057e 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/AMRMProxyService.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/AMRMProxyService.java @@ -65,7 +65,7 @@ import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationEvent; import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationEventType; -import org.apache.hadoop.yarn.server.nodemanager.scheduler.LocalScheduler; +import org.apache.hadoop.yarn.server.nodemanager.scheduler.DistributedScheduler; import org.apache.hadoop.yarn.server.security.MasterKeyData; import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.server.utils.YarnServerSecurityUtils; @@ -467,10 +467,9 @@ protected RequestInterceptor createRequestInterceptorChain() { interceptorClassNames.add(item.trim()); } - // Make sure LocalScheduler is present at the beginning - // of the chain.. + // Make sure LocalScheduler is present at the beginning of the chain. if (this.nmContext.isDistributedSchedulingEnabled()) { - interceptorClassNames.add(0, LocalScheduler.class.getName()); + interceptorClassNames.add(0, DistributedScheduler.class.getName()); } return interceptorClassNames; diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/AbstractRequestInterceptor.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/AbstractRequestInterceptor.java index 2b2a2f6..4e7ee48 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/AbstractRequestInterceptor.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/AbstractRequestInterceptor.java @@ -22,11 +22,10 @@ import com.google.common.base.Preconditions; import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest; -import org.apache.hadoop.yarn.api.protocolrecords - .RegisterApplicationMasterRequest; +import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest; import org.apache.hadoop.yarn.exceptions.YarnException; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedAllocateResponse; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedRegisterResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.DistributedSchedulingAllocateResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.RegisterDistributedSchedulingAMResponse; import java.io.IOException; @@ -118,7 +117,7 @@ public AMRMProxyApplicationContext getApplicationContext() { * @throws IOException */ @Override - public DistSchedAllocateResponse allocateForDistributedScheduling + public DistributedSchedulingAllocateResponse allocateForDistributedScheduling (AllocateRequest request) throws YarnException, IOException { return (this.nextInterceptor != null) ? this.nextInterceptor.allocateForDistributedScheduling(request) : null; @@ -134,7 +133,7 @@ public AMRMProxyApplicationContext getApplicationContext() { * @throws IOException */ @Override - public DistSchedRegisterResponse + public RegisterDistributedSchedulingAMResponse registerApplicationMasterForDistributedScheduling (RegisterApplicationMasterRequest request) throws YarnException, IOException { diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/DefaultRequestInterceptor.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/DefaultRequestInterceptor.java index 1637682..35d6004 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/DefaultRequestInterceptor.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/DefaultRequestInterceptor.java @@ -43,11 +43,10 @@ import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.apache.hadoop.yarn.security.AMRMTokenIdentifier; -import org.apache.hadoop.yarn.server.api.DistributedSchedulerProtocol; +import org.apache.hadoop.yarn.server.api.DistributedSchedulingAMProtocol; import org.apache.hadoop.yarn.server.api.ServerRMProxy; -import org.apache.hadoop.yarn.server.api.protocolrecords - .DistSchedAllocateResponse; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedRegisterResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.DistributedSchedulingAllocateResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.RegisterDistributedSchedulingAMResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,7 +61,7 @@ AbstractRequestInterceptor { private static final Logger LOG = LoggerFactory .getLogger(DefaultRequestInterceptor.class); - private DistributedSchedulerProtocol rmClient; + private DistributedSchedulingAMProtocol rmClient; private UserGroupInformation user = null; @Override @@ -77,12 +76,12 @@ public void init(AMRMProxyApplicationContext appContext) { final Configuration conf = this.getConf(); rmClient = - user.doAs(new PrivilegedExceptionAction() { + user.doAs(new PrivilegedExceptionAction() { @Override - public DistributedSchedulerProtocol run() throws Exception { + public DistributedSchedulingAMProtocol run() throws Exception { setAMRMTokenService(conf); return ServerRMProxy.createRMProxy(conf, - DistributedSchedulerProtocol.class); + DistributedSchedulingAMProtocol.class); } }); } catch (IOException e) { @@ -123,7 +122,7 @@ public AllocateResponse allocate(final AllocateRequest request) } @Override - public DistSchedRegisterResponse + public RegisterDistributedSchedulingAMResponse registerApplicationMasterForDistributedScheduling (RegisterApplicationMasterRequest request) throws YarnException, IOException { @@ -133,13 +132,13 @@ public AllocateResponse allocate(final AllocateRequest request) } @Override - public DistSchedAllocateResponse allocateForDistributedScheduling + public DistributedSchedulingAllocateResponse allocateForDistributedScheduling (AllocateRequest request) throws YarnException, IOException { if (LOG.isDebugEnabled()) { LOG.debug("Forwarding allocateForDistributedScheduling request" + "to the real YARN RM"); } - DistSchedAllocateResponse allocateResponse = + DistributedSchedulingAllocateResponse allocateResponse = rmClient.allocateForDistributedScheduling(request); if (allocateResponse.getAllocateResponse().getAMRMToken() != null) { updateAMRMToken(allocateResponse.getAllocateResponse().getAMRMToken()); @@ -179,10 +178,10 @@ private void updateAMRMToken(Token token) throws IOException { @VisibleForTesting public void setRMClient(final ApplicationMasterProtocol rmClient) { - if (rmClient instanceof DistributedSchedulerProtocol) { - this.rmClient = (DistributedSchedulerProtocol)rmClient; + if (rmClient instanceof DistributedSchedulingAMProtocol) { + this.rmClient = (DistributedSchedulingAMProtocol)rmClient; } else { - this.rmClient = new DistributedSchedulerProtocol() { + this.rmClient = new DistributedSchedulingAMProtocol() { @Override public RegisterApplicationMasterResponse registerApplicationMaster (RegisterApplicationMasterRequest request) throws YarnException, @@ -204,7 +203,7 @@ public AllocateResponse allocate(AllocateRequest request) throws } @Override - public DistSchedRegisterResponse + public RegisterDistributedSchedulingAMResponse registerApplicationMasterForDistributedScheduling (RegisterApplicationMasterRequest request) throws YarnException, IOException { @@ -212,7 +211,7 @@ public AllocateResponse allocate(AllocateRequest request) throws } @Override - public DistSchedAllocateResponse + public DistributedSchedulingAllocateResponse allocateForDistributedScheduling(AllocateRequest request) throws YarnException, IOException { throw new IOException("Not Supported !!"); diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/RequestInterceptor.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/RequestInterceptor.java index 7a73563..5995af1 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/RequestInterceptor.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/RequestInterceptor.java @@ -19,14 +19,14 @@ package org.apache.hadoop.yarn.server.nodemanager.amrmproxy; import org.apache.hadoop.conf.Configurable; -import org.apache.hadoop.yarn.server.api.DistributedSchedulerProtocol; +import org.apache.hadoop.yarn.server.api.DistributedSchedulingAMProtocol; /** * Defines the contract to be implemented by the request intercepter classes, * that can be used to intercept and inspect messages sent from the application * master to the resource manager. */ -public interface RequestInterceptor extends DistributedSchedulerProtocol, +public interface RequestInterceptor extends DistributedSchedulingAMProtocol, Configurable { /** * This method is called for initializing the intercepter. This is guaranteed diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/queuing/QueuingContainerManagerImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/queuing/QueuingContainerManagerImpl.java index 707051f..4f9d5a3 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/queuing/QueuingContainerManagerImpl.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/queuing/QueuingContainerManagerImpl.java @@ -200,7 +200,6 @@ private void startAllocatedContainer( .getContainerTokenIdentifier().getContainerID(); this.context.getQueuingContext().getQueuedContainers().remove(containerId); try { - LOG.info("Starting container [" + containerId + "]"); super.startContainerInternal( allocatedContainerInfo.getContainerTokenIdentifier(), allocatedContainerInfo.getStartRequest()); diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/scheduler/DistributedScheduler.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/scheduler/DistributedScheduler.java new file mode 100644 index 0000000..1a137df --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/scheduler/DistributedScheduler.java @@ -0,0 +1,408 @@ +/** + * 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. + */ + +package org.apache.hadoop.yarn.server.nodemanager.scheduler; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest; +import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.DistributedSchedulingAllocateResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.RegisterDistributedSchedulingAMResponse; +import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest; +import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterResponse; +import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest; +import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse; +import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; +import org.apache.hadoop.yarn.api.records.Container; +import org.apache.hadoop.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.api.records.ContainerStatus; +import org.apache.hadoop.yarn.api.records.ExecutionType; +import org.apache.hadoop.yarn.api.records.NMToken; +import org.apache.hadoop.yarn.api.records.NodeId; +import org.apache.hadoop.yarn.api.records.Priority; +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.api.records.ResourceBlacklistRequest; +import org.apache.hadoop.yarn.api.records.ResourceRequest; +import org.apache.hadoop.yarn.exceptions.YarnException; +import org.apache.hadoop.yarn.server.nodemanager.amrmproxy.AMRMProxyApplicationContext; +import org.apache.hadoop.yarn.server.nodemanager.amrmproxy.AbstractRequestInterceptor; + + + +import org.apache.hadoop.yarn.server.nodemanager.security.NMTokenSecretManagerInNM; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +/** + *

The DistributedScheduler runs on the NodeManager and is modeled as an + * AMRMProxy request interceptor. It is responsible for the + * following:

+ *
    + *
  • Intercept ApplicationMasterProtocol calls and unwrap the + * response objects to extract instructions from the + * ClusterMonitor running on the ResourceManager to aid in making + * distributed scheduling decisions.
  • + *
  • Call the OpportunisticContainerAllocator to allocate + * containers for the outstanding OPPORTUNISTIC container requests.
  • + *
+ */ +public final class DistributedScheduler extends AbstractRequestInterceptor { + + static class PartitionedResourceRequests { + private List guaranteed = new ArrayList<>(); + private List opportunistic = new ArrayList<>(); + public List getGuaranteed() { + return guaranteed; + } + public List getOpportunistic() { + return opportunistic; + } + } + + static class DistributedSchedulerParams { + Resource maxResource; + Resource minResource; + Resource incrementResource; + int containerTokenExpiryInterval; + } + + private static final Logger LOG = LoggerFactory + .getLogger(DistributedScheduler.class); + + // Currently just used to keep track of allocated containers. + // Can be used for reporting stats later. + private Set containersAllocated = new HashSet<>(); + + private DistributedSchedulerParams appParams = + new DistributedSchedulerParams(); + private final OpportunisticContainerAllocator.ContainerIdCounter + containerIdCounter = + new OpportunisticContainerAllocator.ContainerIdCounter(); + private Map nodeList = new HashMap<>(); + + // Mapping of NodeId to NodeTokens. Populated either from RM response or + // generated locally if required. + private Map nodeTokens = new HashMap<>(); + final Set blacklist = new HashSet<>(); + + // This maintains a map of outstanding OPPORTUNISTIC Reqs. Key-ed by Priority, + // Resource Name (Host/rack/any) and capability. This mapping is required + // to match a received Container to an outstanding OPPORTUNISTIC + // ResourceRequest (ask). + final TreeMap> + outstandingOpReqs = new TreeMap<>(); + + private ApplicationAttemptId applicationAttemptId; + private OpportunisticContainerAllocator containerAllocator; + private NMTokenSecretManagerInNM nmSecretManager; + private String appSubmitter; + + public void init(AMRMProxyApplicationContext appContext) { + super.init(appContext); + initLocal(appContext.getApplicationAttemptId(), + appContext.getNMCotext().getContainerAllocator(), + appContext.getNMCotext().getNMTokenSecretManager(), + appContext.getUser()); + } + + @VisibleForTesting + void initLocal(ApplicationAttemptId applicationAttemptId, + OpportunisticContainerAllocator containerAllocator, + NMTokenSecretManagerInNM nmSecretManager, String appSubmitter) { + this.applicationAttemptId = applicationAttemptId; + this.containerAllocator = containerAllocator; + this.nmSecretManager = nmSecretManager; + this.appSubmitter = appSubmitter; + } + + /** + * Route register call to the corresponding distributed scheduling method viz. + * registerApplicationMasterForDistributedScheduling, and return response to + * the caller after stripping away Distributed Scheduling information. + * + * @param request + * registration request + * @return Allocate Response + * @throws YarnException + * @throws IOException + */ + @Override + public RegisterApplicationMasterResponse registerApplicationMaster + (RegisterApplicationMasterRequest request) throws YarnException, + IOException { + return registerApplicationMasterForDistributedScheduling(request) + .getRegisterResponse(); + } + + /** + * Route allocate call to the allocateForDistributedScheduling method and + * return response to the caller after stripping away Distributed Scheduling + * information. + * + * @param request + * allocation request + * @return Allocate Response + * @throws YarnException + * @throws IOException + */ + @Override + public AllocateResponse allocate(AllocateRequest request) throws + YarnException, IOException { + return allocateForDistributedScheduling(request).getAllocateResponse(); + } + + @Override + public FinishApplicationMasterResponse finishApplicationMaster + (FinishApplicationMasterRequest request) throws YarnException, + IOException { + return getNextInterceptor().finishApplicationMaster(request); + } + + /** + * Check if we already have a NMToken. if Not, generate the Token and + * add it to the response + */ + private void updateResponseWithNMTokens(AllocateResponse response, + List nmTokens, List allocatedContainers) { + List newTokens = new ArrayList<>(); + if (allocatedContainers.size() > 0) { + response.getAllocatedContainers().addAll(allocatedContainers); + for (Container alloc : allocatedContainers) { + if (!nodeTokens.containsKey(alloc.getNodeId())) { + newTokens.add(nmSecretManager.generateNMToken(appSubmitter, alloc)); + } + } + List retTokens = new ArrayList<>(nmTokens); + retTokens.addAll(newTokens); + response.setNMTokens(retTokens); + } + } + + private PartitionedResourceRequests partitionAskList(List + askList) { + PartitionedResourceRequests partitionedRequests = + new PartitionedResourceRequests(); + for (ResourceRequest rr : askList) { + if (rr.getExecutionType() == ExecutionType.OPPORTUNISTIC) { + partitionedRequests.getOpportunistic().add(rr); + } else { + partitionedRequests.getGuaranteed().add(rr); + } + } + return partitionedRequests; + } + + private void updateParameters( + RegisterDistributedSchedulingAMResponse registerResponse) { + appParams.minResource = registerResponse.getMinContainerResource(); + appParams.maxResource = registerResponse.getMaxContainerResource(); + appParams.incrementResource = + registerResponse.getIncrContainerResource(); + if (appParams.incrementResource == null) { + appParams.incrementResource = appParams.minResource; + } + appParams.containerTokenExpiryInterval = registerResponse + .getContainerTokenExpiryInterval(); + + containerIdCounter + .resetContainerIdCounter(registerResponse.getContainerIdStart()); + setNodeList(registerResponse.getNodesForScheduling()); + } + + /** + * Takes a list of ResourceRequests (asks), extracts the key information viz. + * (Priority, ResourceName, Capability) and adds to the outstanding + * OPPORTUNISTIC outstandingOpReqs map. The nested map is required to enforce + * the current YARN constraint that only a single ResourceRequest can exist at + * a give Priority and Capability. + */ + public void addToOutstandingReqs(List resourceAsks) { + for (ResourceRequest request : resourceAsks) { + Priority priority = request.getPriority(); + + // TODO: Extend for Node/Rack locality. We only handle ANY requests now + if (!ResourceRequest.isAnyLocation(request.getResourceName())) { + continue; + } + + if (request.getNumContainers() == 0) { + continue; + } + + Map reqMap = + this.outstandingOpReqs.get(priority); + if (reqMap == null) { + reqMap = new HashMap<>(); + this.outstandingOpReqs.put(priority, reqMap); + } + + ResourceRequest resourceRequest = reqMap.get(request.getCapability()); + if (resourceRequest == null) { + resourceRequest = request; + reqMap.put(request.getCapability(), request); + } else { + resourceRequest.setNumContainers( + resourceRequest.getNumContainers() + request.getNumContainers()); + } + if (ResourceRequest.isAnyLocation(request.getResourceName())) { + LOG.info("# of outstandingOpReqs in ANY (at priority = " + priority + + ", with capability = " + request.getCapability() + " ) : " + + resourceRequest.getNumContainers()); + } + } + } + + /** + * This method matches a returned list of Container Allocations to any + * outstanding OPPORTUNISTIC ResourceRequest. + */ + public void matchAllocationToOutstandingRequest(Resource capability, + List allocatedContainers) { + for (Container c : allocatedContainers) { + containersAllocated.add(c.getId()); + Map asks = + outstandingOpReqs.get(c.getPriority()); + + if (asks == null) + continue; + + ResourceRequest rr = asks.get(capability); + if (rr != null) { + rr.setNumContainers(rr.getNumContainers() - 1); + if (rr.getNumContainers() == 0) { + asks.remove(capability); + } + } + } + } + + private void setNodeList(List nodeList) { + this.nodeList.clear(); + addToNodeList(nodeList); + } + + private void addToNodeList(List nodes) { + for (NodeId n : nodes) { + this.nodeList.put(n.getHost(), n); + } + } + + @Override + public RegisterDistributedSchedulingAMResponse + registerApplicationMasterForDistributedScheduling + (RegisterApplicationMasterRequest request) throws YarnException, + IOException { + LOG.info("Forwarding registration request to the" + + "Distributed Scheduler Service on YARN RM"); + RegisterDistributedSchedulingAMResponse dsResp = getNextInterceptor() + .registerApplicationMasterForDistributedScheduling(request); + updateParameters(dsResp); + return dsResp; + } + + @Override + public DistributedSchedulingAllocateResponse allocateForDistributedScheduling + (AllocateRequest request) throws YarnException, IOException { + if (LOG.isDebugEnabled()) { + LOG.debug("Forwarding allocate request to the" + + "Distributed Scheduler Service on YARN RM"); + } + // Partition requests into GUARANTEED and OPPORTUNISTIC reqs + PartitionedResourceRequests partitionedAsks = partitionAskList(request + .getAskList()); + + List releasedContainers = request.getReleaseList(); + int numReleasedContainers = releasedContainers.size(); + if (numReleasedContainers > 0) { + LOG.info("AttemptID: " + applicationAttemptId + " released: " + + numReleasedContainers); + containersAllocated.removeAll(releasedContainers); + } + + // Also, update black list + ResourceBlacklistRequest rbr = request.getResourceBlacklistRequest(); + if (rbr != null) { + blacklist.removeAll(rbr.getBlacklistRemovals()); + blacklist.addAll(rbr.getBlacklistAdditions()); + } + + // Add OPPORTUNISTIC reqs to the outstanding reqs + addToOutstandingReqs(partitionedAsks.getOpportunistic()); + + List allocatedContainers = new ArrayList<>(); + for (Priority priority : outstandingOpReqs.descendingKeySet()) { + // Allocated containers : + // Key = Requested Capability, + // Value = List of Containers of given Cap (The actual container size + // might be different than what is requested.. which is why + // we need the requested capability (key) to match against + // the outstanding reqs) + Map> allocated = + containerAllocator.allocate(this.appParams, containerIdCounter, + outstandingOpReqs.get(priority).values(), blacklist, + applicationAttemptId, nodeList, appSubmitter); + for (Map.Entry> e : allocated.entrySet()) { + matchAllocationToOutstandingRequest(e.getKey(), e.getValue()); + allocatedContainers.addAll(e.getValue()); + } + } + + // Send all the GUARANTEED Reqs to RM + request.setAskList(partitionedAsks.getGuaranteed()); + DistributedSchedulingAllocateResponse dsResp = + getNextInterceptor().allocateForDistributedScheduling(request); + + // Update host to nodeId mapping + setNodeList(dsResp.getNodesForScheduling()); + List nmTokens = dsResp.getAllocateResponse().getNMTokens(); + for (NMToken nmToken : nmTokens) { + nodeTokens.put(nmToken.getNodeId(), nmToken); + } + + List completedContainers = + dsResp.getAllocateResponse().getCompletedContainersStatuses(); + + // Only account for opportunistic containers + for (ContainerStatus cs : completedContainers) { + if (cs.getExecutionType() == ExecutionType.OPPORTUNISTIC) { + containersAllocated.remove(cs.getContainerId()); + } + } + + // Check if we have NM tokens for all the allocated containers. If not + // generate one and update the response. + updateResponseWithNMTokens( + dsResp.getAllocateResponse(), nmTokens, allocatedContainers); + + if (LOG.isDebugEnabled()) { + LOG.debug( + "Number of opportunistic containers currently allocated by" + + "application: " + containersAllocated.size()); + } + return dsResp; + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/scheduler/LocalScheduler.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/scheduler/LocalScheduler.java deleted file mode 100644 index fca814b..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/scheduler/LocalScheduler.java +++ /dev/null @@ -1,418 +0,0 @@ -/** - * 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. - */ - -package org.apache.hadoop.yarn.server.nodemanager.scheduler; - -import com.google.common.annotations.VisibleForTesting; -import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest; -import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedAllocateResponse; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedRegisterResponse; -import org.apache.hadoop.yarn.api.protocolrecords - .FinishApplicationMasterRequest; -import org.apache.hadoop.yarn.api.protocolrecords - .FinishApplicationMasterResponse; -import org.apache.hadoop.yarn.api.protocolrecords - .RegisterApplicationMasterRequest; -import org.apache.hadoop.yarn.api.protocolrecords - .RegisterApplicationMasterResponse; -import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; -import org.apache.hadoop.yarn.api.records.Container; -import org.apache.hadoop.yarn.api.records.ContainerId; -import org.apache.hadoop.yarn.api.records.ContainerStatus; -import org.apache.hadoop.yarn.api.records.ExecutionType; -import org.apache.hadoop.yarn.api.records.NMToken; -import org.apache.hadoop.yarn.api.records.NodeId; -import org.apache.hadoop.yarn.api.records.Priority; -import org.apache.hadoop.yarn.api.records.Resource; -import org.apache.hadoop.yarn.api.records.ResourceBlacklistRequest; -import org.apache.hadoop.yarn.api.records.ResourceRequest; -import org.apache.hadoop.yarn.exceptions.YarnException; -import org.apache.hadoop.yarn.server.nodemanager.amrmproxy - .AMRMProxyApplicationContext; -import org.apache.hadoop.yarn.server.nodemanager.amrmproxy.AbstractRequestInterceptor; - - - -import org.apache.hadoop.yarn.server.nodemanager.security - .NMTokenSecretManagerInNM; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - -/** - *

The LocalScheduler runs on the NodeManager and is modelled as an - * AMRMProxy request interceptor. It is responsible for the - * following :

- *
    - *
  • Intercept ApplicationMasterProtocol calls and unwrap the - * response objects to extract instructions from the - * ClusterManager running on the ResourceManager to aid in making - * Scheduling scheduling decisions
  • - *
  • Call the OpportunisticContainerAllocator to allocate - * containers for the opportunistic resource outstandingOpReqs
  • - *
- */ -public final class LocalScheduler extends AbstractRequestInterceptor { - - static class PartitionedResourceRequests { - private List guaranteed = new ArrayList<>(); - private List opportunistic = new ArrayList<>(); - public List getGuaranteed() { - return guaranteed; - } - public List getOpportunistic() { - return opportunistic; - } - } - - static class DistSchedulerParams { - Resource maxResource; - Resource minResource; - Resource incrementResource; - int containerTokenExpiryInterval; - } - - private static final Logger LOG = LoggerFactory - .getLogger(LocalScheduler.class); - - // Currently just used to keep track of allocated Containers - // Can be used for reporting stats later - private Set containersAllocated = new HashSet<>(); - - private DistSchedulerParams appParams = new DistSchedulerParams(); - private final OpportunisticContainerAllocator.ContainerIdCounter containerIdCounter = - new OpportunisticContainerAllocator.ContainerIdCounter(); - private Map nodeList = new HashMap<>(); - - // Mapping of NodeId to NodeTokens. Populated either from RM response or - // generated locally if required. - private Map nodeTokens = new HashMap<>(); - final Set blacklist = new HashSet<>(); - - // This maintains a map of outstanding OPPORTUNISTIC Reqs. Key-ed by Priority, - // Resource Name (Host/rack/any) and capability. This mapping is required - // to match a received Container to an outstanding OPPORTUNISTIC - // ResourceRequests (ask) - final TreeMap> - outstandingOpReqs = new TreeMap<>(); - - private ApplicationAttemptId applicationAttemptId; - private OpportunisticContainerAllocator containerAllocator; - private NMTokenSecretManagerInNM nmSecretManager; - private String appSubmitter; - - public void init(AMRMProxyApplicationContext appContext) { - super.init(appContext); - initLocal(appContext.getApplicationAttemptId(), - appContext.getNMCotext().getContainerAllocator(), - appContext.getNMCotext().getNMTokenSecretManager(), - appContext.getUser()); - } - - @VisibleForTesting - void initLocal(ApplicationAttemptId applicationAttemptId, - OpportunisticContainerAllocator containerAllocator, - NMTokenSecretManagerInNM nmSecretManager, String appSubmitter) { - this.applicationAttemptId = applicationAttemptId; - this.containerAllocator = containerAllocator; - this.nmSecretManager = nmSecretManager; - this.appSubmitter = appSubmitter; - } - - /** - * Route register call to the corresponding distributed scheduling method viz. - * registerApplicationMasterForDistributedScheduling, and return response to - * the caller after stripping away Distributed Scheduling information. - * - * @param request - * registration request - * @return Allocate Response - * @throws YarnException - * @throws IOException - */ - @Override - public RegisterApplicationMasterResponse registerApplicationMaster - (RegisterApplicationMasterRequest request) throws YarnException, - IOException { - return registerApplicationMasterForDistributedScheduling(request) - .getRegisterResponse(); - } - - /** - * Route allocate call to the allocateForDistributedScheduling method and - * return response to the caller after stripping away Distributed Scheduling - * information. - * - * @param request - * allocation request - * @return Allocate Response - * @throws YarnException - * @throws IOException - */ - @Override - public AllocateResponse allocate(AllocateRequest request) throws - YarnException, IOException { - return allocateForDistributedScheduling(request).getAllocateResponse(); - } - - @Override - public FinishApplicationMasterResponse finishApplicationMaster - (FinishApplicationMasterRequest request) throws YarnException, - IOException { - return getNextInterceptor().finishApplicationMaster(request); - } - - /** - * Check if we already have a NMToken. if Not, generate the Token and - * add it to the response - * @param response - * @param nmTokens - * @param allocatedContainers - */ - private void updateResponseWithNMTokens(AllocateResponse response, - List nmTokens, List allocatedContainers) { - List newTokens = new ArrayList<>(); - if (allocatedContainers.size() > 0) { - response.getAllocatedContainers().addAll(allocatedContainers); - for (Container alloc : allocatedContainers) { - if (!nodeTokens.containsKey(alloc.getNodeId())) { - newTokens.add(nmSecretManager.generateNMToken(appSubmitter, alloc)); - } - } - List retTokens = new ArrayList<>(nmTokens); - retTokens.addAll(newTokens); - response.setNMTokens(retTokens); - } - } - - private PartitionedResourceRequests partitionAskList(List - askList) { - PartitionedResourceRequests partitionedRequests = - new PartitionedResourceRequests(); - for (ResourceRequest rr : askList) { - if (rr.getExecutionType() == ExecutionType.OPPORTUNISTIC) { - partitionedRequests.getOpportunistic().add(rr); - } else { - partitionedRequests.getGuaranteed().add(rr); - } - } - return partitionedRequests; - } - - private void updateParameters( - DistSchedRegisterResponse registerResponse) { - appParams.minResource = registerResponse.getMinAllocatableCapabilty(); - appParams.maxResource = registerResponse.getMaxAllocatableCapabilty(); - appParams.incrementResource = - registerResponse.getIncrAllocatableCapabilty(); - if (appParams.incrementResource == null) { - appParams.incrementResource = appParams.minResource; - } - appParams.containerTokenExpiryInterval = registerResponse - .getContainerTokenExpiryInterval(); - - containerIdCounter - .resetContainerIdCounter(registerResponse.getContainerIdStart()); - setNodeList(registerResponse.getNodesForScheduling()); - } - - /** - * Takes a list of ResourceRequests (asks), extracts the key information viz. - * (Priority, ResourceName, Capability) and adds it the outstanding - * OPPORTUNISTIC outstandingOpReqs map. The nested map is required to enforce - * the current YARN constraint that only a single ResourceRequest can exist at - * a give Priority and Capability - * @param resourceAsks - */ - public void addToOutstandingReqs(List resourceAsks) { - for (ResourceRequest request : resourceAsks) { - Priority priority = request.getPriority(); - - // TODO: Extend for Node/Rack locality. We only handle ANY requests now - if (!ResourceRequest.isAnyLocation(request.getResourceName())) { - continue; - } - - if (request.getNumContainers() == 0) { - continue; - } - - Map reqMap = - this.outstandingOpReqs.get(priority); - if (reqMap == null) { - reqMap = new HashMap<>(); - this.outstandingOpReqs.put(priority, reqMap); - } - - ResourceRequest resourceRequest = reqMap.get(request.getCapability()); - if (resourceRequest == null) { - resourceRequest = request; - reqMap.put(request.getCapability(), request); - } else { - resourceRequest.setNumContainers( - resourceRequest.getNumContainers() + request.getNumContainers()); - } - if (ResourceRequest.isAnyLocation(request.getResourceName())) { - LOG.info("# of outstandingOpReqs in ANY (at priority = " + priority - + ", with capability = " + request.getCapability() + " ) : " - + resourceRequest.getNumContainers()); - } - } - } - - /** - * This method matches a returned list of Container Allocations to any - * outstanding OPPORTUNISTIC ResourceRequest - * @param capability - * @param allocatedContainers - */ - public void matchAllocationToOutstandingRequest(Resource capability, - List allocatedContainers) { - for (Container c : allocatedContainers) { - containersAllocated.add(c.getId()); - Map asks = - outstandingOpReqs.get(c.getPriority()); - - if (asks == null) - continue; - - ResourceRequest rr = asks.get(capability); - if (rr != null) { - rr.setNumContainers(rr.getNumContainers() - 1); - if (rr.getNumContainers() == 0) { - asks.remove(capability); - } - } - } - } - - private void setNodeList(List nodeList) { - this.nodeList.clear(); - addToNodeList(nodeList); - } - - private void addToNodeList(List nodes) { - for (NodeId n : nodes) { - this.nodeList.put(n.getHost(), n); - } - } - - @Override - public DistSchedRegisterResponse - registerApplicationMasterForDistributedScheduling - (RegisterApplicationMasterRequest request) throws YarnException, - IOException { - LOG.info("Forwarding registration request to the" + - "Distributed Scheduler Service on YARN RM"); - DistSchedRegisterResponse dsResp = getNextInterceptor() - .registerApplicationMasterForDistributedScheduling(request); - updateParameters(dsResp); - return dsResp; - } - - @Override - public DistSchedAllocateResponse allocateForDistributedScheduling - (AllocateRequest request) throws YarnException, IOException { - if (LOG.isDebugEnabled()) { - LOG.debug("Forwarding allocate request to the" + - "Distributed Scheduler Service on YARN RM"); - } - // Partition requests into GUARANTEED and OPPORTUNISTIC reqs - PartitionedResourceRequests partitionedAsks = partitionAskList(request - .getAskList()); - - List releasedContainers = request.getReleaseList(); - int numReleasedContainers = releasedContainers.size(); - if (numReleasedContainers > 0) { - LOG.info("AttemptID: " + applicationAttemptId + " released: " - + numReleasedContainers); - containersAllocated.removeAll(releasedContainers); - } - - // Also, update black list - ResourceBlacklistRequest rbr = request.getResourceBlacklistRequest(); - if (rbr != null) { - blacklist.removeAll(rbr.getBlacklistRemovals()); - blacklist.addAll(rbr.getBlacklistAdditions()); - } - - // Add OPPORTUNISTIC reqs to the outstanding reqs - addToOutstandingReqs(partitionedAsks.getOpportunistic()); - - List allocatedContainers = new ArrayList<>(); - for (Priority priority : outstandingOpReqs.descendingKeySet()) { - // Allocated containers : - // Key = Requested Capability, - // Value = List of Containers of given Cap (The actual container size - // might be different than what is requested.. which is why - // we need the requested capability (key) to match against - // the outstanding reqs) - Map> allocated = - containerAllocator.allocate(this.appParams, containerIdCounter, - outstandingOpReqs.get(priority).values(), blacklist, - applicationAttemptId, nodeList, appSubmitter); - for (Map.Entry> e : allocated.entrySet()) { - matchAllocationToOutstandingRequest(e.getKey(), e.getValue()); - allocatedContainers.addAll(e.getValue()); - } - } - - // Send all the GUARANTEED Reqs to RM - request.setAskList(partitionedAsks.getGuaranteed()); - DistSchedAllocateResponse dsResp = - getNextInterceptor().allocateForDistributedScheduling(request); - - // Update host to nodeId mapping - setNodeList(dsResp.getNodesForScheduling()); - List nmTokens = dsResp.getAllocateResponse().getNMTokens(); - for (NMToken nmToken : nmTokens) { - nodeTokens.put(nmToken.getNodeId(), nmToken); - } - - List completedContainers = - dsResp.getAllocateResponse().getCompletedContainersStatuses(); - - // Only account for opportunistic containers - for (ContainerStatus cs : completedContainers) { - if (cs.getExecutionType() == ExecutionType.OPPORTUNISTIC) { - containersAllocated.remove(cs.getContainerId()); - } - } - - // Check if we have NM tokens for all the allocated containers. If not - // generate one and update the response. - updateResponseWithNMTokens( - dsResp.getAllocateResponse(), nmTokens, allocatedContainers); - - if (LOG.isDebugEnabled()) { - LOG.debug( - "Number of opportunistic containers currently allocated by" + - "application: " + containersAllocated.size()); - } - return dsResp; - } -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/scheduler/OpportunisticContainerAllocator.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/scheduler/OpportunisticContainerAllocator.java index e33c389..2e748a3 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/scheduler/OpportunisticContainerAllocator.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/scheduler/OpportunisticContainerAllocator.java @@ -29,7 +29,7 @@ import org.apache.hadoop.yarn.server.api.ContainerType; import org.apache.hadoop.yarn.server.nodemanager.Context; import org.apache.hadoop.yarn.server.nodemanager.NodeStatusUpdater; -import org.apache.hadoop.yarn.server.nodemanager.scheduler.LocalScheduler.DistSchedulerParams; +import org.apache.hadoop.yarn.server.nodemanager.scheduler.DistributedScheduler.DistributedSchedulerParams; import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; @@ -37,15 +37,17 @@ import java.net.InetSocketAddress; import java.util.*; +import java.util.Map.Entry; import java.util.concurrent.atomic.AtomicLong; /** - *

The OpportunisticContainerAllocator allocates containers on a given list - * of Nodes after it modifies the container sizes to within allowable limits - * specified by the ClusterManager running on the RM. It tries to - * distribute the containers as evenly as possible. It also uses the - * NMTokenSecretManagerInNM to generate the required NM tokens for - * the allocated containers

+ *

+ * The OpportunisticContainerAllocator allocates containers on a given list of + * nodes, after modifying the container sizes to respect the limits set by the + * ResourceManager. It tries to distribute the containers as evenly as possible. + * It also uses the NMTokenSecretManagerInNM to generate the + * required NM tokens for the allocated containers. + *

*/ public class OpportunisticContainerAllocator { @@ -78,15 +80,15 @@ public OpportunisticContainerAllocator(NodeStatusUpdater nodeStatusUpdater, this.webpagePort = webpagePort; } - public Map> allocate(DistSchedulerParams appParams, - ContainerIdCounter idCounter, Collection resourceAsks, - Set blacklist, ApplicationAttemptId appAttId, - Map allNodes, String userName) throws YarnException { + public Map> allocate( + DistributedSchedulerParams appParams, ContainerIdCounter idCounter, + Collection resourceAsks, Set blacklist, + ApplicationAttemptId appAttId, Map allNodes, + String userName) throws YarnException { Map> containers = new HashMap<>(); - Set nodesAllocated = new HashSet<>(); for (ResourceRequest anyAsk : resourceAsks) { allocateOpportunisticContainers(appParams, idCounter, blacklist, appAttId, - allNodes, userName, containers, nodesAllocated, anyAsk); + allNodes, userName, containers, anyAsk); LOG.info("Opportunistic allocation requested for [" + "priority=" + anyAsk.getPriority() + ", num_containers=" + anyAsk.getNumContainers() @@ -96,30 +98,30 @@ public OpportunisticContainerAllocator(NodeStatusUpdater nodeStatusUpdater, return containers; } - private void allocateOpportunisticContainers(DistSchedulerParams appParams, - ContainerIdCounter idCounter, Set blacklist, - ApplicationAttemptId id, Map allNodes, String userName, - Map> containers, Set nodesAllocated, - ResourceRequest anyAsk) throws YarnException { + private void allocateOpportunisticContainers( + DistributedSchedulerParams appParams, ContainerIdCounter idCounter, + Set blacklist, ApplicationAttemptId id, + Map allNodes, String userName, + Map> containers, ResourceRequest anyAsk) + throws YarnException { int toAllocate = anyAsk.getNumContainers() - - (containers.isEmpty() ? - 0 : containers.get(anyAsk.getCapability()).size()); + - (containers.isEmpty() ? 0 : + containers.get(anyAsk.getCapability()).size()); - List topKNodesLeft = new ArrayList<>(); - for (String s : allNodes.keySet()) { - // Bias away from whatever we have already allocated and respect blacklist - if (nodesAllocated.contains(s) || blacklist.contains(s)) { + List nodesForScheduling = new ArrayList<>(); + for (Entry nodeEntry : allNodes.entrySet()) { + // Do not use blacklisted nodes for scheduling. + if (blacklist.contains(nodeEntry.getKey())) { continue; } - topKNodesLeft.add(s); + nodesForScheduling.add(nodeEntry.getValue()); } int numAllocated = 0; - int nextNodeToAllocate = 0; + int nextNodeToSchedule = 0; for (int numCont = 0; numCont < toAllocate; numCont++) { - String topNode = topKNodesLeft.get(nextNodeToAllocate); - nextNodeToAllocate++; - nextNodeToAllocate %= topKNodesLeft.size(); - NodeId nodeId = allNodes.get(topNode); + nextNodeToSchedule++; + nextNodeToSchedule %= nodesForScheduling.size(); + NodeId nodeId = nodesForScheduling.get(nextNodeToSchedule); Container container = buildContainer(appParams, idCounter, anyAsk, id, userName, nodeId); List cList = containers.get(anyAsk.getCapability()); @@ -134,7 +136,7 @@ private void allocateOpportunisticContainers(DistSchedulerParams appParams, LOG.info("Allocated " + numAllocated + " opportunistic containers."); } - private Container buildContainer(DistSchedulerParams appParams, + private Container buildContainer(DistributedSchedulerParams appParams, ContainerIdCounter idCounter, ResourceRequest rr, ApplicationAttemptId id, String userName, NodeId nodeId) throws YarnException { ContainerId cId = @@ -164,7 +166,7 @@ private Container buildContainer(DistSchedulerParams appParams, return container; } - private Resource normalizeCapability(DistSchedulerParams appParams, + private Resource normalizeCapability(DistributedSchedulerParams appParams, ResourceRequest ask) { return Resources.normalize(RESOURCE_CALCULATOR, ask.getCapability(), appParams.minResource, appParams.maxResource, diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/scheduler/TestLocalScheduler.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/scheduler/TestLocalScheduler.java index e987e79..6a2c5fc 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/scheduler/TestLocalScheduler.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/scheduler/TestLocalScheduler.java @@ -20,15 +20,12 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.yarn.security.ContainerTokenIdentifier; -import org.apache.hadoop.yarn.server.api.DistributedSchedulerProtocol; import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest; import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedAllocateResponse; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedRegisterResponse; -import org.apache.hadoop.yarn.api.protocolrecords - .RegisterApplicationMasterRequest; -import org.apache.hadoop.yarn.api.protocolrecords - .RegisterApplicationMasterResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.DistributedSchedulingAllocateResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.RegisterDistributedSchedulingAMResponse; +import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest; +import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse; import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.Container; @@ -42,10 +39,8 @@ import org.apache.hadoop.yarn.server.nodemanager.Context; import org.apache.hadoop.yarn.server.nodemanager.NodeStatusUpdater; import org.apache.hadoop.yarn.server.nodemanager.amrmproxy.RequestInterceptor; -import org.apache.hadoop.yarn.server.nodemanager.security - .NMContainerTokenSecretManager; -import org.apache.hadoop.yarn.server.nodemanager.security - .NMTokenSecretManagerInNM; +import org.apache.hadoop.yarn.server.nodemanager.security.NMContainerTokenSecretManager; +import org.apache.hadoop.yarn.server.nodemanager.security.NMTokenSecretManagerInNM; import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.Records; import org.junit.Assert; @@ -67,7 +62,7 @@ public void testLocalScheduler() throws Exception { Configuration conf = new Configuration(); - LocalScheduler localScheduler = new LocalScheduler(); + DistributedScheduler localScheduler = new DistributedScheduler(); NodeStatusUpdater nodeStatusUpdater = Mockito.mock(NodeStatusUpdater.class); Mockito.when(nodeStatusUpdater.getRMIdentifier()).thenReturn(12345l); @@ -104,15 +99,15 @@ public void setBytes(ByteBuffer bytes) {} RequestInterceptor finalReqIntcptr = Mockito.mock(RequestInterceptor.class); localScheduler.setNextInterceptor(finalReqIntcptr); - DistSchedRegisterResponse distSchedRegisterResponse = - Records.newRecord(DistSchedRegisterResponse.class); + RegisterDistributedSchedulingAMResponse distSchedRegisterResponse = + Records.newRecord(RegisterDistributedSchedulingAMResponse.class); distSchedRegisterResponse.setRegisterResponse( Records.newRecord(RegisterApplicationMasterResponse.class)); distSchedRegisterResponse.setContainerTokenExpiryInterval(12345); distSchedRegisterResponse.setContainerIdStart(0); - distSchedRegisterResponse.setMaxAllocatableCapabilty( + distSchedRegisterResponse.setMaxContainerResource( Resource.newInstance(1024, 4)); - distSchedRegisterResponse.setMinAllocatableCapabilty( + distSchedRegisterResponse.setMinContainerResource( Resource.newInstance(512, 2)); distSchedRegisterResponse.setNodesForScheduling(Arrays.asList( NodeId.newInstance("a", 1), NodeId.newInstance("b", 2))); @@ -127,9 +122,9 @@ public void setBytes(ByteBuffer bytes) {} Mockito.when( finalReqIntcptr.allocateForDistributedScheduling( Mockito.any(AllocateRequest.class))) - .thenAnswer(new Answer() { + .thenAnswer(new Answer() { @Override - public DistSchedAllocateResponse answer(InvocationOnMock + public DistributedSchedulingAllocateResponse answer(InvocationOnMock invocationOnMock) throws Throwable { return createAllocateResponse(Arrays.asList( NodeId.newInstance("c", 3), NodeId.newInstance("d", 4))); @@ -153,7 +148,8 @@ public DistSchedAllocateResponse answer(InvocationOnMock allocateRequest.setAskList(Arrays.asList(guaranteedReq, opportunisticReq)); // Verify 4 containers were allocated - AllocateResponse allocateResponse = localScheduler.allocate(allocateRequest); + AllocateResponse allocateResponse = localScheduler.allocate( + allocateRequest); Assert.assertEquals(4, allocateResponse.getAllocatedContainers().size()); // Verify equal distribution on hosts a and b @@ -188,11 +184,12 @@ public DistSchedAllocateResponse answer(InvocationOnMock Assert.assertNull(allocs.get(NodeId.newInstance("b", 2))); } - private DistSchedAllocateResponse createAllocateResponse(List nodes) { - DistSchedAllocateResponse distSchedAllocateResponse = Records.newRecord - (DistSchedAllocateResponse.class); - distSchedAllocateResponse.setAllocateResponse( - Records.newRecord(AllocateResponse.class)); + private DistributedSchedulingAllocateResponse createAllocateResponse( + List nodes) { + DistributedSchedulingAllocateResponse distSchedAllocateResponse = Records + .newRecord(DistributedSchedulingAllocateResponse.class); + distSchedAllocateResponse.setAllocateResponse(Records.newRecord( + AllocateResponse.class)); distSchedAllocateResponse.setNodesForScheduling(nodes); return distSchedAllocateResponse; } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ApplicationMasterService.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ApplicationMasterService.java index 4f90fa0..ac98c57 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ApplicationMasterService.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ApplicationMasterService.java @@ -91,8 +91,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerNodeReport; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler; -import org.apache.hadoop.yarn.server.resourcemanager.security - .AMRMTokenSecretManager; +import org.apache.hadoop.yarn.server.resourcemanager.security.AMRMTokenSecretManager; import org.apache.hadoop.yarn.server.resourcemanager.security.authorize.RMPolicyProvider; import org.apache.hadoop.yarn.server.security.MasterKeyData; import org.apache.hadoop.yarn.server.utils.BuilderUtils; diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/DistributedSchedulingAMService.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/DistributedSchedulingAMService.java new file mode 100644 index 0000000..55e6863 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/DistributedSchedulingAMService.java @@ -0,0 +1,338 @@ +/** + * 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. + */ + +package org.apache.hadoop.yarn.server.resourcemanager; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.ipc.RPC; +import org.apache.hadoop.ipc.Server; +import org.apache.hadoop.yarn.api.ApplicationMasterProtocolPB; +import org.apache.hadoop.yarn.api.records.NodeId; +import org.apache.hadoop.yarn.event.EventHandler; +import org.apache.hadoop.yarn.server.api.DistributedSchedulingAMProtocol; +import org.apache.hadoop.yarn.api.impl.pb.service.ApplicationMasterProtocolPBServiceImpl; + + +import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest; +import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.DistributedSchedulingAllocateResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.RegisterDistributedSchedulingAMResponse; +import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest; +import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterResponse; +import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest; +import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse; + +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.exceptions.YarnException; +import org.apache.hadoop.yarn.ipc.YarnRPC; +import org.apache.hadoop.yarn.proto.ApplicationMasterProtocol.ApplicationMasterProtocolService; + +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.distributed.NodeQueueLoadMonitor; + + +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.distributed.QueueLimitCalculator; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeAddedSchedulerEvent; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeRemovedSchedulerEvent; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeResourceUpdateSchedulerEvent; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeUpdateSchedulerEvent; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent; +import org.apache.hadoop.yarn.server.resourcemanager.security.AMRMTokenSecretManager; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** + * The DistributedSchedulingAMService is started instead of the + * ApplicationMasterService if distributed scheduling is enabled for the YARN + * cluster. + * It extends the functionality of the ApplicationMasterService by servicing + * clients (AMs and AMRMProxy request interceptors) that understand the + * DistributedSchedulingProtocol. + */ +public class DistributedSchedulingAMService extends ApplicationMasterService + implements DistributedSchedulingAMProtocol, EventHandler { + + private static final Log LOG = + LogFactory.getLog(DistributedSchedulingAMService.class); + + private final NodeQueueLoadMonitor nodeQueueLoadMonitor; + + private final ConcurrentHashMap> rackToNode = + new ConcurrentHashMap<>(); + private final ConcurrentHashMap> hostToNode = + new ConcurrentHashMap<>(); + private final int nodesNo; + + public DistributedSchedulingAMService(RMContext rmContext, + YarnScheduler scheduler) { + super(DistributedSchedulingAMService.class.getName(), rmContext, scheduler); + this.nodesNo = rmContext.getYarnConfiguration().getInt( + YarnConfiguration.DIST_SCHEDULING_NODES_NUMBER_USED, + YarnConfiguration.DIST_SCHEDULING_NODES_NUMBER_USED_DEFAULT); + long nodeSortInterval = rmContext.getYarnConfiguration().getLong( + YarnConfiguration.NM_CONTAINER_QUEUING_SORTING_NODES_INTERVAL_MS, + YarnConfiguration. + NM_CONTAINER_QUEUING_SORTING_NODES_INTERVAL_MS_DEFAULT); + NodeQueueLoadMonitor.LoadComparator comparator = + NodeQueueLoadMonitor.LoadComparator.valueOf( + rmContext.getYarnConfiguration().get( + YarnConfiguration.NM_CONTAINER_QUEUING_LOAD_COMPARATOR, + YarnConfiguration. + NM_CONTAINER_QUEUING_LOAD_COMPARATOR_DEFAULT)); + + NodeQueueLoadMonitor topKSelector = + new NodeQueueLoadMonitor(nodeSortInterval, comparator); + + float sigma = rmContext.getYarnConfiguration() + .getFloat(YarnConfiguration.NM_CONTAINER_QUEUING_LIMIT_STDEV, + YarnConfiguration.NM_CONTAINER_QUEUING_LIMIT_STDEV_DEFAULT); + + int limitMin, limitMax; + + if (comparator == NodeQueueLoadMonitor.LoadComparator.QUEUE_LENGTH) { + limitMin = rmContext.getYarnConfiguration() + .getInt(YarnConfiguration.NM_CONTAINER_QUEUING_MIN_QUEUE_LENGTH, + YarnConfiguration. + NM_CONTAINER_QUEUING_MIN_QUEUE_LENGTH_DEFAULT); + limitMax = rmContext.getYarnConfiguration() + .getInt(YarnConfiguration.NM_CONTAINER_QUEUING_MAX_QUEUE_LENGTH, + YarnConfiguration. + NM_CONTAINER_QUEUING_MAX_QUEUE_LENGTH_DEFAULT); + } else { + limitMin = rmContext.getYarnConfiguration() + .getInt( + YarnConfiguration.NM_CONTAINER_QUEUING_MIN_QUEUE_WAIT_TIME_MS, + YarnConfiguration. + NM_CONTAINER_QUEUING_MIN_QUEUE_WAIT_TIME_MS_DEFAULT); + limitMax = rmContext.getYarnConfiguration() + .getInt( + YarnConfiguration.NM_CONTAINER_QUEUING_MAX_QUEUE_WAIT_TIME_MS, + YarnConfiguration. + NM_CONTAINER_QUEUING_MAX_QUEUE_WAIT_TIME_MS_DEFAULT); + } + + topKSelector.initThresholdCalculator(sigma, limitMin, limitMax); + this.nodeQueueLoadMonitor = topKSelector; + } + + @Override + public Server getServer(YarnRPC rpc, Configuration serverConf, + InetSocketAddress addr, AMRMTokenSecretManager secretManager) { + Server server = rpc.getServer(DistributedSchedulingAMProtocol.class, this, + addr, serverConf, secretManager, + serverConf.getInt(YarnConfiguration.RM_SCHEDULER_CLIENT_THREAD_COUNT, + YarnConfiguration.DEFAULT_RM_SCHEDULER_CLIENT_THREAD_COUNT)); + // To support applications running on NMs that DO NOT support + // Distributed Scheduling... The server multiplexes both the + // ApplicationMasterProtocol as well as the DistributedSchedulingProtocol + ((RPC.Server) server).addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER, + ApplicationMasterProtocolPB.class, + ApplicationMasterProtocolService.newReflectiveBlockingService( + new ApplicationMasterProtocolPBServiceImpl(this))); + return server; + } + + @Override + public RegisterApplicationMasterResponse registerApplicationMaster + (RegisterApplicationMasterRequest request) throws YarnException, + IOException { + return super.registerApplicationMaster(request); + } + + @Override + public FinishApplicationMasterResponse finishApplicationMaster + (FinishApplicationMasterRequest request) throws YarnException, + IOException { + return super.finishApplicationMaster(request); + } + + @Override + public AllocateResponse allocate(AllocateRequest request) throws + YarnException, IOException { + return super.allocate(request); + } + + @Override + public RegisterDistributedSchedulingAMResponse + registerApplicationMasterForDistributedScheduling( + RegisterApplicationMasterRequest request) throws YarnException, + IOException { + RegisterApplicationMasterResponse response = + registerApplicationMaster(request); + RegisterDistributedSchedulingAMResponse dsResp = recordFactory + .newRecordInstance(RegisterDistributedSchedulingAMResponse.class); + dsResp.setRegisterResponse(response); + dsResp.setMinContainerResource( + Resource.newInstance( + getConfig().getInt( + YarnConfiguration.DIST_SCHEDULING_MIN_CONTAINER_MEMORY_MB, + YarnConfiguration. + DIST_SCHEDULING_MIN_CONTAINER_MEMORY_MB_DEFAULT), + getConfig().getInt( + YarnConfiguration.DIST_SCHEDULING_MIN_CONTAINER_VCORES, + YarnConfiguration.DIST_SCHEDULING_MIN_CONTAINER_VCORES_DEFAULT) + ) + ); + dsResp.setMaxContainerResource( + Resource.newInstance( + getConfig().getInt( + YarnConfiguration.DIST_SCHEDULING_MAX_MEMORY_MB, + YarnConfiguration.DIST_SCHEDULING_MAX_MEMORY_MB_DEFAULT), + getConfig().getInt( + YarnConfiguration.DIST_SCHEDULING_MAX_CONTAINER_VCORES, + YarnConfiguration.DIST_SCHEDULING_MAX_CONTAINER_VCORES_DEFAULT) + ) + ); + dsResp.setIncrContainerResource( + Resource.newInstance( + getConfig().getInt( + YarnConfiguration.DIST_SCHEDULING_INCR_CONTAINER_MEMORY_MB, + YarnConfiguration. + DIST_SCHEDULING_INCR_CONTAINER_MEMORY_MB_DEFAULT), + getConfig().getInt( + YarnConfiguration.DIST_SCHEDULING_INCR_CONTAINER_VCORES, + YarnConfiguration.DIST_SCHEDULING_INCR_CONTAINER_VCORES_DEFAULT) + ) + ); + dsResp.setContainerTokenExpiryInterval( + getConfig().getInt( + YarnConfiguration.DIST_SCHEDULING_CONTAINER_TOKEN_EXPIRY_MS, + YarnConfiguration. + DIST_SCHEDULING_CONTAINER_TOKEN_EXPIRY_MS_DEFAULT)); + dsResp.setContainerIdStart( + this.rmContext.getEpoch() << ResourceManager.EPOCH_BIT_SHIFT); + + // Set nodes to be used for scheduling + dsResp.setNodesForScheduling( + this.nodeQueueLoadMonitor.selectLeastLoadedNodes(this.nodesNo)); + return dsResp; + } + + @Override + public DistributedSchedulingAllocateResponse allocateForDistributedScheduling + (AllocateRequest request) throws YarnException, IOException { + AllocateResponse response = allocate(request); + DistributedSchedulingAllocateResponse dsResp = recordFactory.newRecordInstance + (DistributedSchedulingAllocateResponse.class); + dsResp.setAllocateResponse(response); + dsResp.setNodesForScheduling( + this.nodeQueueLoadMonitor.selectLeastLoadedNodes(this.nodesNo)); + return dsResp; + } + + private void addToMapping(ConcurrentHashMap> mapping, + String rackName, NodeId nodeId) { + if (rackName != null) { + mapping.putIfAbsent(rackName, new HashSet()); + Set nodeIds = mapping.get(rackName); + synchronized (nodeIds) { + nodeIds.add(nodeId); + } + } + } + + private void removeFromMapping(ConcurrentHashMap> mapping, + String rackName, NodeId nodeId) { + if (rackName != null) { + Set nodeIds = mapping.get(rackName); + synchronized (nodeIds) { + nodeIds.remove(nodeId); + } + } + } + + @Override + public void handle(SchedulerEvent event) { + switch (event.getType()) { + case NODE_ADDED: + if (!(event instanceof NodeAddedSchedulerEvent)) { + throw new RuntimeException("Unexpected event type: " + event); + } + NodeAddedSchedulerEvent nodeAddedEvent = (NodeAddedSchedulerEvent) event; + nodeQueueLoadMonitor.addNode(nodeAddedEvent.getContainerReports(), + nodeAddedEvent.getAddedRMNode()); + addToMapping(rackToNode, nodeAddedEvent.getAddedRMNode().getRackName(), + nodeAddedEvent.getAddedRMNode().getNodeID()); + addToMapping(hostToNode, nodeAddedEvent.getAddedRMNode().getHostName(), + nodeAddedEvent.getAddedRMNode().getNodeID()); + break; + case NODE_REMOVED: + if (!(event instanceof NodeRemovedSchedulerEvent)) { + throw new RuntimeException("Unexpected event type: " + event); + } + NodeRemovedSchedulerEvent nodeRemovedEvent = + (NodeRemovedSchedulerEvent) event; + nodeQueueLoadMonitor.removeNode(nodeRemovedEvent.getRemovedRMNode()); + removeFromMapping(rackToNode, + nodeRemovedEvent.getRemovedRMNode().getRackName(), + nodeRemovedEvent.getRemovedRMNode().getNodeID()); + removeFromMapping(hostToNode, + nodeRemovedEvent.getRemovedRMNode().getHostName(), + nodeRemovedEvent.getRemovedRMNode().getNodeID()); + break; + case NODE_UPDATE: + if (!(event instanceof NodeUpdateSchedulerEvent)) { + throw new RuntimeException("Unexpected event type: " + event); + } + NodeUpdateSchedulerEvent nodeUpdatedEvent = (NodeUpdateSchedulerEvent) + event; + nodeQueueLoadMonitor.updateNode(nodeUpdatedEvent.getRMNode()); + break; + case NODE_RESOURCE_UPDATE: + if (!(event instanceof NodeResourceUpdateSchedulerEvent)) { + throw new RuntimeException("Unexpected event type: " + event); + } + NodeResourceUpdateSchedulerEvent nodeResourceUpdatedEvent = + (NodeResourceUpdateSchedulerEvent) event; + nodeQueueLoadMonitor.updateNodeResource( + nodeResourceUpdatedEvent.getRMNode(), + nodeResourceUpdatedEvent.getResourceOption()); + break; + + // <-- IGNORED EVENTS : START --> + case APP_ADDED: + break; + case APP_REMOVED: + break; + case APP_ATTEMPT_ADDED: + break; + case APP_ATTEMPT_REMOVED: + break; + case CONTAINER_EXPIRED: + break; + case NODE_LABELS_UPDATE: + break; + // <-- IGNORED EVENTS : END --> + default: + LOG.error("Unknown event arrived at DistributedSchedulingService: " + + event.toString()); + } + + } + + public QueueLimitCalculator getNodeManagerQueueLimitCalculator() { + return nodeQueueLoadMonitor.getThresholdCalculator(); + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/DistributedSchedulingService.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/DistributedSchedulingService.java deleted file mode 100644 index a93f683..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/DistributedSchedulingService.java +++ /dev/null @@ -1,335 +0,0 @@ -/** - * 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. - */ - -package org.apache.hadoop.yarn.server.resourcemanager; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.ipc.RPC; -import org.apache.hadoop.ipc.Server; -import org.apache.hadoop.yarn.api.ApplicationMasterProtocolPB; -import org.apache.hadoop.yarn.api.records.NodeId; -import org.apache.hadoop.yarn.event.EventHandler; -import org.apache.hadoop.yarn.server.api.DistributedSchedulerProtocol; -import org.apache.hadoop.yarn.api.impl.pb.service.ApplicationMasterProtocolPBServiceImpl; - - -import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest; -import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedAllocateResponse; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedRegisterResponse; -import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest; -import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterResponse; -import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest; -import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse; - -import org.apache.hadoop.yarn.api.records.Resource; -import org.apache.hadoop.yarn.conf.YarnConfiguration; -import org.apache.hadoop.yarn.exceptions.YarnException; -import org.apache.hadoop.yarn.ipc.YarnRPC; -import org.apache.hadoop.yarn.proto.ApplicationMasterProtocol.ApplicationMasterProtocolService; - -import org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler; -import org.apache.hadoop.yarn.server.resourcemanager.scheduler.distributed.NodeQueueLoadMonitor; - - -import org.apache.hadoop.yarn.server.resourcemanager.scheduler.distributed.QueueLimitCalculator; -import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeAddedSchedulerEvent; -import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeRemovedSchedulerEvent; -import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeResourceUpdateSchedulerEvent; -import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeUpdateSchedulerEvent; -import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent; -import org.apache.hadoop.yarn.server.resourcemanager.security.AMRMTokenSecretManager; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -/** - * The DistributedSchedulingService is started instead of the - * ApplicationMasterService if DistributedScheduling is enabled for the YARN - * cluster. - * It extends the functionality of the ApplicationMasterService by servicing - * clients (AMs and AMRMProxy request interceptors) that understand the - * DistributedSchedulingProtocol. - */ -public class DistributedSchedulingService extends ApplicationMasterService - implements DistributedSchedulerProtocol, EventHandler { - - private static final Log LOG = - LogFactory.getLog(DistributedSchedulingService.class); - - private final NodeQueueLoadMonitor nodeMonitor; - - private final ConcurrentHashMap> rackToNode = - new ConcurrentHashMap<>(); - private final ConcurrentHashMap> hostToNode = - new ConcurrentHashMap<>(); - private final int k; - - public DistributedSchedulingService(RMContext rmContext, - YarnScheduler scheduler) { - super(DistributedSchedulingService.class.getName(), rmContext, scheduler); - this.k = rmContext.getYarnConfiguration().getInt( - YarnConfiguration.DIST_SCHEDULING_TOP_K, - YarnConfiguration.DIST_SCHEDULING_TOP_K_DEFAULT); - long nodeSortInterval = rmContext.getYarnConfiguration().getLong( - YarnConfiguration.NM_CONTAINER_QUEUING_SORTING_NODES_INTERVAL_MS, - YarnConfiguration. - NM_CONTAINER_QUEUING_SORTING_NODES_INTERVAL_MS_DEFAULT); - NodeQueueLoadMonitor.LoadComparator comparator = - NodeQueueLoadMonitor.LoadComparator.valueOf( - rmContext.getYarnConfiguration().get( - YarnConfiguration.NM_CONTAINER_QUEUING_LOAD_COMPARATOR, - YarnConfiguration. - NM_CONTAINER_QUEUING_LOAD_COMPARATOR_DEFAULT)); - - NodeQueueLoadMonitor topKSelector = - new NodeQueueLoadMonitor(nodeSortInterval, comparator); - - float sigma = rmContext.getYarnConfiguration() - .getFloat(YarnConfiguration.NM_CONTAINER_QUEUING_LIMIT_STDEV, - YarnConfiguration.NM_CONTAINER_QUEUING_LIMIT_STDEV_DEFAULT); - - int limitMin, limitMax; - - if (comparator == NodeQueueLoadMonitor.LoadComparator.QUEUE_LENGTH) { - limitMin = rmContext.getYarnConfiguration() - .getInt(YarnConfiguration.NM_CONTAINER_QUEUING_MIN_QUEUE_LENGTH, - YarnConfiguration. - NM_CONTAINER_QUEUING_MIN_QUEUE_LENGTH_DEFAULT); - limitMax = rmContext.getYarnConfiguration() - .getInt(YarnConfiguration.NM_CONTAINER_QUEUING_MAX_QUEUE_LENGTH, - YarnConfiguration. - NM_CONTAINER_QUEUING_MAX_QUEUE_LENGTH_DEFAULT); - } else { - limitMin = rmContext.getYarnConfiguration() - .getInt( - YarnConfiguration.NM_CONTAINER_QUEUING_MIN_QUEUE_WAIT_TIME_MS, - YarnConfiguration. - NM_CONTAINER_QUEUING_MIN_QUEUE_WAIT_TIME_MS_DEFAULT); - limitMax = rmContext.getYarnConfiguration() - .getInt( - YarnConfiguration.NM_CONTAINER_QUEUING_MAX_QUEUE_WAIT_TIME_MS, - YarnConfiguration. - NM_CONTAINER_QUEUING_MAX_QUEUE_WAIT_TIME_MS_DEFAULT); - } - - topKSelector.initThresholdCalculator(sigma, limitMin, limitMax); - this.nodeMonitor = topKSelector; - } - - @Override - public Server getServer(YarnRPC rpc, Configuration serverConf, - InetSocketAddress addr, AMRMTokenSecretManager secretManager) { - Server server = rpc.getServer(DistributedSchedulerProtocol.class, this, - addr, serverConf, secretManager, - serverConf.getInt(YarnConfiguration.RM_SCHEDULER_CLIENT_THREAD_COUNT, - YarnConfiguration.DEFAULT_RM_SCHEDULER_CLIENT_THREAD_COUNT)); - // To support application running on NMs that DO NOT support - // Dist Scheduling... The server multiplexes both the - // ApplicationMasterProtocol as well as the DistributedSchedulingProtocol - ((RPC.Server) server).addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER, - ApplicationMasterProtocolPB.class, - ApplicationMasterProtocolService.newReflectiveBlockingService( - new ApplicationMasterProtocolPBServiceImpl(this))); - return server; - } - - @Override - public RegisterApplicationMasterResponse registerApplicationMaster - (RegisterApplicationMasterRequest request) throws YarnException, - IOException { - return super.registerApplicationMaster(request); - } - - @Override - public FinishApplicationMasterResponse finishApplicationMaster - (FinishApplicationMasterRequest request) throws YarnException, - IOException { - return super.finishApplicationMaster(request); - } - - @Override - public AllocateResponse allocate(AllocateRequest request) throws - YarnException, IOException { - return super.allocate(request); - } - - @Override - public DistSchedRegisterResponse - registerApplicationMasterForDistributedScheduling( - RegisterApplicationMasterRequest request) throws YarnException, - IOException { - RegisterApplicationMasterResponse response = - registerApplicationMaster(request); - DistSchedRegisterResponse dsResp = recordFactory - .newRecordInstance(DistSchedRegisterResponse.class); - dsResp.setRegisterResponse(response); - dsResp.setMinAllocatableCapabilty( - Resource.newInstance( - getConfig().getInt( - YarnConfiguration.DIST_SCHEDULING_MIN_MEMORY, - YarnConfiguration.DIST_SCHEDULING_MIN_MEMORY_DEFAULT), - getConfig().getInt( - YarnConfiguration.DIST_SCHEDULING_MIN_VCORES, - YarnConfiguration.DIST_SCHEDULING_MIN_VCORES_DEFAULT) - ) - ); - dsResp.setMaxAllocatableCapabilty( - Resource.newInstance( - getConfig().getInt( - YarnConfiguration.DIST_SCHEDULING_MAX_MEMORY, - YarnConfiguration.DIST_SCHEDULING_MAX_MEMORY_DEFAULT), - getConfig().getInt( - YarnConfiguration.DIST_SCHEDULING_MAX_VCORES, - YarnConfiguration.DIST_SCHEDULING_MAX_VCORES_DEFAULT) - ) - ); - dsResp.setIncrAllocatableCapabilty( - Resource.newInstance( - getConfig().getInt( - YarnConfiguration.DIST_SCHEDULING_INCR_MEMORY, - YarnConfiguration.DIST_SCHEDULING_INCR_MEMORY_DEFAULT), - getConfig().getInt( - YarnConfiguration.DIST_SCHEDULING_INCR_VCORES, - YarnConfiguration.DIST_SCHEDULING_INCR_VCORES_DEFAULT) - ) - ); - dsResp.setContainerTokenExpiryInterval( - getConfig().getInt( - YarnConfiguration.DIST_SCHEDULING_CONTAINER_TOKEN_EXPIRY_MS, - YarnConfiguration. - DIST_SCHEDULING_CONTAINER_TOKEN_EXPIRY_MS_DEFAULT)); - dsResp.setContainerIdStart( - this.rmContext.getEpoch() << ResourceManager.EPOCH_BIT_SHIFT); - - // Set nodes to be used for scheduling - dsResp.setNodesForScheduling( - this.nodeMonitor.selectLeastLoadedNodes(this.k)); - return dsResp; - } - - @Override - public DistSchedAllocateResponse allocateForDistributedScheduling - (AllocateRequest request) throws YarnException, IOException { - AllocateResponse response = allocate(request); - DistSchedAllocateResponse dsResp = recordFactory.newRecordInstance - (DistSchedAllocateResponse.class); - dsResp.setAllocateResponse(response); - dsResp.setNodesForScheduling( - this.nodeMonitor.selectLeastLoadedNodes(this.k)); - return dsResp; - } - - private void addToMapping(ConcurrentHashMap> mapping, - String rackName, NodeId nodeId) { - if (rackName != null) { - mapping.putIfAbsent(rackName, new HashSet()); - Set nodeIds = mapping.get(rackName); - synchronized (nodeIds) { - nodeIds.add(nodeId); - } - } - } - - private void removeFromMapping(ConcurrentHashMap> mapping, - String rackName, NodeId nodeId) { - if (rackName != null) { - Set nodeIds = mapping.get(rackName); - synchronized (nodeIds) { - nodeIds.remove(nodeId); - } - } - } - - @Override - public void handle(SchedulerEvent event) { - switch (event.getType()) { - case NODE_ADDED: - if (!(event instanceof NodeAddedSchedulerEvent)) { - throw new RuntimeException("Unexpected event type: " + event); - } - NodeAddedSchedulerEvent nodeAddedEvent = (NodeAddedSchedulerEvent) event; - nodeMonitor.addNode(nodeAddedEvent.getContainerReports(), - nodeAddedEvent.getAddedRMNode()); - addToMapping(rackToNode, nodeAddedEvent.getAddedRMNode().getRackName(), - nodeAddedEvent.getAddedRMNode().getNodeID()); - addToMapping(hostToNode, nodeAddedEvent.getAddedRMNode().getHostName(), - nodeAddedEvent.getAddedRMNode().getNodeID()); - break; - case NODE_REMOVED: - if (!(event instanceof NodeRemovedSchedulerEvent)) { - throw new RuntimeException("Unexpected event type: " + event); - } - NodeRemovedSchedulerEvent nodeRemovedEvent = - (NodeRemovedSchedulerEvent) event; - nodeMonitor.removeNode(nodeRemovedEvent.getRemovedRMNode()); - removeFromMapping(rackToNode, - nodeRemovedEvent.getRemovedRMNode().getRackName(), - nodeRemovedEvent.getRemovedRMNode().getNodeID()); - removeFromMapping(hostToNode, - nodeRemovedEvent.getRemovedRMNode().getHostName(), - nodeRemovedEvent.getRemovedRMNode().getNodeID()); - break; - case NODE_UPDATE: - if (!(event instanceof NodeUpdateSchedulerEvent)) { - throw new RuntimeException("Unexpected event type: " + event); - } - NodeUpdateSchedulerEvent nodeUpdatedEvent = (NodeUpdateSchedulerEvent) - event; - nodeMonitor.updateNode(nodeUpdatedEvent.getRMNode()); - break; - case NODE_RESOURCE_UPDATE: - if (!(event instanceof NodeResourceUpdateSchedulerEvent)) { - throw new RuntimeException("Unexpected event type: " + event); - } - NodeResourceUpdateSchedulerEvent nodeResourceUpdatedEvent = - (NodeResourceUpdateSchedulerEvent) event; - nodeMonitor.updateNodeResource(nodeResourceUpdatedEvent.getRMNode(), - nodeResourceUpdatedEvent.getResourceOption()); - break; - - // <-- IGNORED EVENTS : START --> - case APP_ADDED: - break; - case APP_REMOVED: - break; - case APP_ATTEMPT_ADDED: - break; - case APP_ATTEMPT_REMOVED: - break; - case CONTAINER_EXPIRED: - break; - case NODE_LABELS_UPDATE: - break; - // <-- IGNORED EVENTS : END --> - default: - LOG.error("Unknown event arrived at DistributedSchedulingService: " - + event.toString()); - } - - } - - public QueueLimitCalculator getNodeManagerQueueLimitCalculator() { - return nodeMonitor.getThresholdCalculator(); - } -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java index f9d3325..e578392 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java @@ -1142,12 +1142,12 @@ protected ApplicationMasterService createApplicationMasterService() { if (this.rmContext.getYarnConfiguration().getBoolean( YarnConfiguration.DIST_SCHEDULING_ENABLED, YarnConfiguration.DIST_SCHEDULING_ENABLED_DEFAULT)) { - DistributedSchedulingService distributedSchedulingService = new - DistributedSchedulingService(this.rmContext, scheduler); + DistributedSchedulingAMService distributedSchedulingService = new + DistributedSchedulingAMService(this.rmContext, scheduler); EventDispatcher distSchedulerEventDispatcher = new EventDispatcher(distributedSchedulingService, - DistributedSchedulingService.class.getName()); - // Add an event dispoatcher for the DistributedSchedulingService + DistributedSchedulingAMService.class.getName()); + // Add an event dispatcher for the DistributedSchedulingService // to handle node updates/additions and removals. // Since the SchedulerEvent is currently a super set of theses, // we register interest for it.. diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AppSchedulingInfo.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AppSchedulingInfo.java index 463bebd..c2452ee 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AppSchedulingInfo.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AppSchedulingInfo.java @@ -46,6 +46,7 @@ import org.apache.hadoop.yarn.api.records.ResourceRequest; import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.server.resourcemanager.RMServerUtils; +import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager; import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer; import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainerState; @@ -62,7 +63,6 @@ private static final Log LOG = LogFactory.getLog(AppSchedulingInfo.class); private static final Comparator COMPARATOR = new org.apache.hadoop.yarn.server.resourcemanager.resource.Priority.Comparator(); - private static final int EPOCH_BIT_SHIFT = 40; private final ApplicationId applicationId; private final ApplicationAttemptId applicationAttemptId; @@ -93,8 +93,8 @@ public AppSchedulingInfo(ApplicationAttemptId appAttemptId, this.queue = queue; this.user = user; this.activeUsersManager = activeUsersManager; - this.containerIdCounter = - new AtomicLong(epoch << EPOCH_BIT_SHIFT); + this.containerIdCounter = new AtomicLong( + epoch << ResourceManager.EPOCH_BIT_SHIFT); this.appResourceUsage = appResourceUsage; } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/distributed/NodeQueueLoadMonitor.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/distributed/NodeQueueLoadMonitor.java index 017a256..21f4f6e 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/distributed/NodeQueueLoadMonitor.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/distributed/NodeQueueLoadMonitor.java @@ -195,11 +195,11 @@ public void updateNode(RMNode rmNode) { new ClusterNode(rmNode.getNodeID()) .setQueueWaitTime(estimatedQueueWaitTime) .setQueueLength(waitQueueLength)); - LOG.info("Inserting ClusterNode [" + rmNode.getNodeID() + "] " + + LOG.info("Inserting ClusterNode [" + rmNode.getNodeID() + "]" + "with queue wait time [" + estimatedQueueWaitTime + "] and " + "wait queue length [" + waitQueueLength + "]"); } else { - LOG.warn("IGNORING ClusterNode [" + rmNode.getNodeID() + "] " + + LOG.warn("IGNORING ClusterNode [" + rmNode.getNodeID() + "]" + "with queue wait time [" + estimatedQueueWaitTime + "] and " + "wait queue length [" + waitQueueLength + "]"); } @@ -210,14 +210,12 @@ public void updateNode(RMNode rmNode) { .setQueueWaitTime(estimatedQueueWaitTime) .setQueueLength(waitQueueLength) .updateTimestamp(); - if (LOG.isDebugEnabled()) { - LOG.debug("Updating ClusterNode [" + rmNode.getNodeID() + "] " + - "with queue wait time [" + estimatedQueueWaitTime + "] and " + - "wait queue length [" + waitQueueLength + "]"); - } + LOG.info("Updating ClusterNode [" + rmNode.getNodeID() + "]" + + "with queue wait time [" + estimatedQueueWaitTime + "] and " + + "wait queue length [" + waitQueueLength + "]"); } else { this.clusterNodes.remove(rmNode.getNodeID()); - LOG.info("Deleting ClusterNode [" + rmNode.getNodeID() + "] " + + LOG.info("Deleting ClusterNode [" + rmNode.getNodeID() + "]" + "with queue wait time [" + currentNode.queueWaitTime + "] and " + "wait queue length [" + currentNode.queueLength + "]"); } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/MockRM.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/MockRM.java index 982724e..f957b33 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/MockRM.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/MockRM.java @@ -815,7 +815,7 @@ protected ApplicationMasterService createApplicationMasterService() { if (this.rmContext.getYarnConfiguration().getBoolean( YarnConfiguration.DIST_SCHEDULING_ENABLED, YarnConfiguration.DIST_SCHEDULING_ENABLED_DEFAULT)) { - return new DistributedSchedulingService(getRMContext(), scheduler) { + return new DistributedSchedulingAMService(getRMContext(), scheduler) { @Override protected void serviceStart() { // override to not start rpc handler diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestDistributedSchedulingAMService.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestDistributedSchedulingAMService.java new file mode 100644 index 0000000..238a534 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestDistributedSchedulingAMService.java @@ -0,0 +1,197 @@ +/** + * 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. + */ + +package org.apache.hadoop.yarn.server.resourcemanager; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.ipc.ProtobufRpcEngine; +import org.apache.hadoop.ipc.RPC; +import org.apache.hadoop.ipc.Server; +import org.apache.hadoop.net.NetUtils; +import org.apache.hadoop.yarn.api.ApplicationMasterProtocolPB; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.AllocateRequestPBImpl; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.AllocateResponsePBImpl; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.FinishApplicationMasterRequestPBImpl; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.FinishApplicationMasterResponsePBImpl; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RegisterApplicationMasterRequestPBImpl; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RegisterApplicationMasterResponsePBImpl; +import org.apache.hadoop.yarn.server.api.DistributedSchedulingAMProtocolPB; +import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest; +import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.DistributedSchedulingAllocateResponse; +import org.apache.hadoop.yarn.server.api.protocolrecords.RegisterDistributedSchedulingAMResponse; +import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest; +import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterResponse; +import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest; +import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse; + +import org.apache.hadoop.yarn.api.records.NodeId; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.exceptions.YarnException; +import org.apache.hadoop.yarn.factories.RecordFactory; +import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider; +import org.apache.hadoop.yarn.ipc.HadoopYarnProtoRPC; +import org.apache.hadoop.yarn.ipc.YarnRPC; +import org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.DistributedSchedulingAllocateResponsePBImpl; +import org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.RegisterDistributedSchedulingAMResponsePBImpl; +import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.AMLivelinessMonitor; + +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.Arrays; + +public class TestDistributedSchedulingAMService { + + // Test if the DistributedSchedulingAMService can handle both DSProtocol as + // well as AMProtocol clients + @Test + public void testRPCWrapping() throws Exception { + Configuration conf = new Configuration(); + conf.set(YarnConfiguration.IPC_RPC_IMPL, HadoopYarnProtoRPC.class + .getName()); + YarnRPC rpc = YarnRPC.create(conf); + String bindAddr = "localhost:0"; + InetSocketAddress addr = NetUtils.createSocketAddr(bindAddr); + conf.setSocketAddr(YarnConfiguration.RM_SCHEDULER_ADDRESS, addr); + final RecordFactory factory = RecordFactoryProvider.getRecordFactory(null); + final RMContext rmContext = new RMContextImpl() { + @Override + public AMLivelinessMonitor getAMLivelinessMonitor() { + return null; + } + + @Override + public Configuration getYarnConfiguration() { + return new YarnConfiguration(); + } + }; + DistributedSchedulingAMService service = + new DistributedSchedulingAMService(rmContext, null) { + @Override + public RegisterApplicationMasterResponse registerApplicationMaster + (RegisterApplicationMasterRequest request) throws + YarnException, IOException { + RegisterApplicationMasterResponse resp = factory.newRecordInstance( + RegisterApplicationMasterResponse.class); + // Dummy Entry to Assert that we get this object back + resp.setQueue("dummyQueue"); + return resp; + } + + @Override + public FinishApplicationMasterResponse finishApplicationMaster + (FinishApplicationMasterRequest request) throws YarnException, + IOException { + FinishApplicationMasterResponse resp = factory.newRecordInstance( + FinishApplicationMasterResponse.class); + // Dummy Entry to Assert that we get this object back + resp.setIsUnregistered(false); + return resp; + } + + @Override + public AllocateResponse allocate(AllocateRequest request) throws + YarnException, IOException { + AllocateResponse response = factory.newRecordInstance + (AllocateResponse.class); + response.setNumClusterNodes(12345); + return response; + } + + @Override + public RegisterDistributedSchedulingAMResponse + registerApplicationMasterForDistributedScheduling + (RegisterApplicationMasterRequest request) throws + YarnException, IOException { + RegisterDistributedSchedulingAMResponse resp = factory.newRecordInstance( + RegisterDistributedSchedulingAMResponse.class); + resp.setContainerIdStart(54321l); + return resp; + } + + @Override + public DistributedSchedulingAllocateResponse allocateForDistributedScheduling + (AllocateRequest request) throws YarnException, IOException { + DistributedSchedulingAllocateResponse resp = + factory.newRecordInstance(DistributedSchedulingAllocateResponse.class); + resp.setNodesForScheduling( + Arrays.asList(NodeId.newInstance("h1", 1234))); + return resp; + } + }; + Server server = service.getServer(rpc, conf, addr, null); + server.start(); + + // Verify that the DistrubutedSchedulingService can handle vanilla + // ApplicationMasterProtocol clients + RPC.setProtocolEngine(conf, ApplicationMasterProtocolPB.class, + ProtobufRpcEngine.class); + ApplicationMasterProtocolPB ampProxy = + RPC.getProxy(ApplicationMasterProtocolPB + .class, 1, NetUtils.getConnectAddress(server), conf); + RegisterApplicationMasterResponse regResp = + new RegisterApplicationMasterResponsePBImpl( + ampProxy.registerApplicationMaster(null, + ((RegisterApplicationMasterRequestPBImpl)factory + .newRecordInstance( + RegisterApplicationMasterRequest.class)).getProto())); + Assert.assertEquals("dummyQueue", regResp.getQueue()); + FinishApplicationMasterResponse finishResp = + new FinishApplicationMasterResponsePBImpl( + ampProxy.finishApplicationMaster(null, + ((FinishApplicationMasterRequestPBImpl)factory + .newRecordInstance( + FinishApplicationMasterRequest.class)).getProto() + )); + Assert.assertEquals(false, finishResp.getIsUnregistered()); + AllocateResponse allocResp = + new AllocateResponsePBImpl( + ampProxy.allocate(null, + ((AllocateRequestPBImpl)factory + .newRecordInstance(AllocateRequest.class)).getProto()) + ); + Assert.assertEquals(12345, allocResp.getNumClusterNodes()); + + + // Verify that the DistrubutedSchedulingService can handle the + // DistributedSchedulerProtocol clients as well + RPC.setProtocolEngine(conf, DistributedSchedulingAMProtocolPB.class, + ProtobufRpcEngine.class); + DistributedSchedulingAMProtocolPB dsProxy = + RPC.getProxy(DistributedSchedulingAMProtocolPB + .class, 1, NetUtils.getConnectAddress(server), conf); + + RegisterDistributedSchedulingAMResponse dsRegResp = + new RegisterDistributedSchedulingAMResponsePBImpl( + dsProxy.registerApplicationMasterForDistributedScheduling(null, + ((RegisterApplicationMasterRequestPBImpl)factory + .newRecordInstance(RegisterApplicationMasterRequest.class)) + .getProto())); + Assert.assertEquals(54321l, dsRegResp.getContainerIdStart()); + DistributedSchedulingAllocateResponse dsAllocResp = + new DistributedSchedulingAllocateResponsePBImpl( + dsProxy.allocateForDistributedScheduling(null, + ((AllocateRequestPBImpl)factory + .newRecordInstance(AllocateRequest.class)).getProto())); + Assert.assertEquals( + "h1", dsAllocResp.getNodesForScheduling().get(0).getHost()); + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestDistributedSchedulingService.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestDistributedSchedulingService.java deleted file mode 100644 index 49bf4d0..0000000 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestDistributedSchedulingService.java +++ /dev/null @@ -1,205 +0,0 @@ -/** - * 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. - */ - -package org.apache.hadoop.yarn.server.resourcemanager; - -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.ipc.ProtobufRpcEngine; -import org.apache.hadoop.ipc.RPC; -import org.apache.hadoop.ipc.Server; -import org.apache.hadoop.net.NetUtils; -import org.apache.hadoop.yarn.api.ApplicationMasterProtocolPB; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.AllocateRequestPBImpl; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb - .AllocateResponsePBImpl; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb - .FinishApplicationMasterRequestPBImpl; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb - .FinishApplicationMasterResponsePBImpl; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb - .RegisterApplicationMasterRequestPBImpl; -import org.apache.hadoop.yarn.api.protocolrecords.impl.pb - .RegisterApplicationMasterResponsePBImpl; -import org.apache.hadoop.yarn.server.api.DistributedSchedulerProtocolPB; -import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest; -import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedAllocateResponse; -import org.apache.hadoop.yarn.server.api.protocolrecords.DistSchedRegisterResponse; -import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest; -import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterResponse; -import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest; -import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse; - -import org.apache.hadoop.yarn.api.records.NodeId; -import org.apache.hadoop.yarn.conf.YarnConfiguration; -import org.apache.hadoop.yarn.exceptions.YarnException; -import org.apache.hadoop.yarn.factories.RecordFactory; -import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider; -import org.apache.hadoop.yarn.ipc.HadoopYarnProtoRPC; -import org.apache.hadoop.yarn.ipc.YarnRPC; -import org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb - .DistSchedAllocateResponsePBImpl; -import org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb - .DistSchedRegisterResponsePBImpl; -import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt - .AMLivelinessMonitor; - -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.Arrays; - -public class TestDistributedSchedulingService { - - // Test if the DistributedSchedulingService can handle both DSProtocol as - // well as AMProtocol clients - @Test - public void testRPCWrapping() throws Exception { - Configuration conf = new Configuration(); - conf.set(YarnConfiguration.IPC_RPC_IMPL, HadoopYarnProtoRPC.class - .getName()); - YarnRPC rpc = YarnRPC.create(conf); - String bindAddr = "localhost:0"; - InetSocketAddress addr = NetUtils.createSocketAddr(bindAddr); - conf.setSocketAddr(YarnConfiguration.RM_SCHEDULER_ADDRESS, addr); - final RecordFactory factory = RecordFactoryProvider.getRecordFactory(null); - final RMContext rmContext = new RMContextImpl() { - @Override - public AMLivelinessMonitor getAMLivelinessMonitor() { - return null; - } - - @Override - public Configuration getYarnConfiguration() { - return new YarnConfiguration(); - } - }; - DistributedSchedulingService service = - new DistributedSchedulingService(rmContext, null) { - @Override - public RegisterApplicationMasterResponse registerApplicationMaster - (RegisterApplicationMasterRequest request) throws - YarnException, IOException { - RegisterApplicationMasterResponse resp = factory.newRecordInstance( - RegisterApplicationMasterResponse.class); - // Dummy Entry to Assert that we get this object back - resp.setQueue("dummyQueue"); - return resp; - } - - @Override - public FinishApplicationMasterResponse finishApplicationMaster - (FinishApplicationMasterRequest request) throws YarnException, - IOException { - FinishApplicationMasterResponse resp = factory.newRecordInstance( - FinishApplicationMasterResponse.class); - // Dummy Entry to Assert that we get this object back - resp.setIsUnregistered(false); - return resp; - } - - @Override - public AllocateResponse allocate(AllocateRequest request) throws - YarnException, IOException { - AllocateResponse response = factory.newRecordInstance - (AllocateResponse.class); - response.setNumClusterNodes(12345); - return response; - } - - @Override - public DistSchedRegisterResponse - registerApplicationMasterForDistributedScheduling - (RegisterApplicationMasterRequest request) throws - YarnException, IOException { - DistSchedRegisterResponse resp = factory.newRecordInstance( - DistSchedRegisterResponse.class); - resp.setContainerIdStart(54321l); - return resp; - } - - @Override - public DistSchedAllocateResponse allocateForDistributedScheduling - (AllocateRequest request) throws YarnException, IOException { - DistSchedAllocateResponse resp = - factory.newRecordInstance(DistSchedAllocateResponse.class); - resp.setNodesForScheduling( - Arrays.asList(NodeId.newInstance("h1", 1234))); - return resp; - } - }; - Server server = service.getServer(rpc, conf, addr, null); - server.start(); - - // Verify that the DistrubutedSchedulingService can handle vanilla - // ApplicationMasterProtocol clients - RPC.setProtocolEngine(conf, ApplicationMasterProtocolPB.class, - ProtobufRpcEngine.class); - ApplicationMasterProtocolPB ampProxy = - RPC.getProxy(ApplicationMasterProtocolPB - .class, 1, NetUtils.getConnectAddress(server), conf); - RegisterApplicationMasterResponse regResp = - new RegisterApplicationMasterResponsePBImpl( - ampProxy.registerApplicationMaster(null, - ((RegisterApplicationMasterRequestPBImpl)factory - .newRecordInstance( - RegisterApplicationMasterRequest.class)).getProto())); - Assert.assertEquals("dummyQueue", regResp.getQueue()); - FinishApplicationMasterResponse finishResp = - new FinishApplicationMasterResponsePBImpl( - ampProxy.finishApplicationMaster(null, - ((FinishApplicationMasterRequestPBImpl)factory - .newRecordInstance( - FinishApplicationMasterRequest.class)).getProto() - )); - Assert.assertEquals(false, finishResp.getIsUnregistered()); - AllocateResponse allocResp = - new AllocateResponsePBImpl( - ampProxy.allocate(null, - ((AllocateRequestPBImpl)factory - .newRecordInstance(AllocateRequest.class)).getProto()) - ); - Assert.assertEquals(12345, allocResp.getNumClusterNodes()); - - - // Verify that the DistrubutedSchedulingService can handle the - // DistributedSchedulerProtocol clients as well - RPC.setProtocolEngine(conf, DistributedSchedulerProtocolPB.class, - ProtobufRpcEngine.class); - DistributedSchedulerProtocolPB dsProxy = - RPC.getProxy(DistributedSchedulerProtocolPB - .class, 1, NetUtils.getConnectAddress(server), conf); - - DistSchedRegisterResponse dsRegResp = - new DistSchedRegisterResponsePBImpl( - dsProxy.registerApplicationMasterForDistributedScheduling(null, - ((RegisterApplicationMasterRequestPBImpl)factory - .newRecordInstance(RegisterApplicationMasterRequest.class)) - .getProto())); - Assert.assertEquals(54321l, dsRegResp.getContainerIdStart()); - DistSchedAllocateResponse dsAllocResp = - new DistSchedAllocateResponsePBImpl( - dsProxy.allocateForDistributedScheduling(null, - ((AllocateRequestPBImpl)factory - .newRecordInstance(AllocateRequest.class)).getProto())); - Assert.assertEquals( - "h1", dsAllocResp.getNodesForScheduling().get(0).getHost()); - } -} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/MiniYARNCluster.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/MiniYARNCluster.java index de4e22d..2372ea2 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/MiniYARNCluster.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/MiniYARNCluster.java @@ -75,9 +75,6 @@ import org.apache.hadoop.yarn.server.nodemanager.amrmproxy.DefaultRequestInterceptor; import org.apache.hadoop.yarn.server.nodemanager.amrmproxy.RequestInterceptor; import org.apache.hadoop.yarn.server.nodemanager.containermanager.ContainerManagerImpl; -import org.apache.hadoop.yarn.server.nodemanager.containermanager.monitor.ContainersMonitor; -import org.apache.hadoop.yarn.server.nodemanager.containermanager.monitor.ContainersMonitorImpl; -import org.apache.hadoop.yarn.server.nodemanager.containermanager.queuing.QueuingContainerManagerImpl; import org.apache.hadoop.yarn.server.nodemanager.metrics.NodeManagerMetrics; import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager; import org.apache.hadoop.yarn.server.resourcemanager.ResourceTrackerService; @@ -716,14 +713,8 @@ protected ContainerManagerImpl createContainerManager(Context context, ContainerExecutor exec, DeletionService del, NodeStatusUpdater nodeStatusUpdater, ApplicationACLsManager aclsManager, LocalDirsHandlerService dirsHandler) { - if (getConfig().getBoolean(YarnConfiguration.NM_CONTAINER_QUEUING_ENABLED, - YarnConfiguration.NM_CONTAINER_QUEUING_ENABLED_DEFAULT)) { - return new CustomQueueingContainerManagerImpl(context, exec, del, - nodeStatusUpdater, metrics, dirsHandler); - } else { - return new CustomContainerManagerImpl(context, exec, del, - nodeStatusUpdater, metrics, dirsHandler); - } + return new CustomContainerManagerImpl(context, exec, del, + nodeStatusUpdater, metrics, dirsHandler); } } @@ -855,55 +846,6 @@ protected void createAMRMProxyService(Configuration conf) { } } - private class CustomQueueingContainerManagerImpl extends - QueuingContainerManagerImpl { - - public CustomQueueingContainerManagerImpl(Context context, - ContainerExecutor exec, DeletionService del, NodeStatusUpdater - nodeStatusUpdater, NodeManagerMetrics metrics, - LocalDirsHandlerService dirsHandler) { - super(context, exec, del, nodeStatusUpdater, metrics, dirsHandler); - } - - @Override - protected ContainersMonitor createContainersMonitor(ContainerExecutor - exec) { - return new ContainersMonitorImpl(exec, dispatcher, this.context) { - - @Override - public void increaseContainersAllocation(ProcessTreeInfo pti) { } - - @Override - public void decreaseContainersAllocation(ProcessTreeInfo pti) { } - - @Override - public boolean hasResourcesAvailable( - ContainersMonitorImpl.ProcessTreeInfo pti) { - return true; - } - }; - } - - @Override - protected void createAMRMProxyService(Configuration conf) { - this.amrmProxyEnabled = - conf.getBoolean(YarnConfiguration.AMRM_PROXY_ENABLED, - YarnConfiguration.DEFAULT_AMRM_PROXY_ENABLED); - - if (this.amrmProxyEnabled) { - LOG.info("CustomAMRMProxyService is enabled. " - + "All the AM->RM requests will be intercepted by the proxy"); - AMRMProxyService amrmProxyService = - useRpc ? new AMRMProxyService(getContext(), dispatcher) - : new ShortCircuitedAMRMProxy(getContext(), dispatcher); - this.setAMRMProxyService(amrmProxyService); - addService(this.getAMRMProxyService()); - } else { - LOG.info("CustomAMRMProxyService is disabled"); - } - } - } - private class ShortCircuitedAMRMProxy extends AMRMProxyService { public ShortCircuitedAMRMProxy(Context context,