diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AMRMClient.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AMRMClient.java index bd0f16b..38058e4 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AMRMClient.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AMRMClient.java @@ -36,6 +36,7 @@ import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.client.api.impl.AMRMClientImpl; import org.apache.hadoop.yarn.exceptions.YarnException; +import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import com.google.common.collect.ImmutableList; @@ -57,6 +58,10 @@ @Public public static AMRMClient createAMRMClient( ApplicationAttemptId appAttemptId) { + if (appAttemptId == null) { + throw new YarnRuntimeException( + "Invalid AppAttemptId. The AppAttemptId can not be null"); + } AMRMClient client = new AMRMClientImpl(appAttemptId); return client; } @@ -95,6 +100,19 @@ protected AMRMClient(String name) { public ContainerRequest(Resource capability, String[] nodes, String[] racks, Priority priority, int containerCount) { + if (capability == null) { + throw new YarnRuntimeException( + "The Resource to be requested for each container " + + "should not be null "); + } + if (priority == null) { + throw new YarnRuntimeException( + "The priority at which to request containers should not be null "); + } + if (containerCount <= 0) { + throw new YarnRuntimeException( + "The number of containers to request should larger than 0"); + } this.capability = capability; this.nodes = (nodes != null ? ImmutableList.copyOf(nodes) : null); this.racks = (racks != null ? ImmutableList.copyOf(racks) : null); diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/AMRMClientImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/AMRMClientImpl.java index 68cc287..b8ff26c 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/AMRMClientImpl.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/AMRMClientImpl.java @@ -69,8 +69,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; -// TODO check inputs for null etc. YARN-654 - @Private @Unstable public class AMRMClientImpl extends AMRMClient { @@ -204,6 +202,13 @@ protected void serviceStop() throws Exception { public RegisterApplicationMasterResponse registerApplicationMaster( String appHostName, int appHostPort, String appTrackingUrl) throws YarnException, IOException { + if (appHostName == null) { + throw new YarnRuntimeException("The host name should not be null"); + } + if (appHostPort < 0) { + throw new YarnRuntimeException( + "Port number of the host should not be negative"); + } // do this only once ??? RegisterApplicationMasterRequest request = recordFactory .newRecordInstance(RegisterApplicationMasterRequest.class); @@ -223,6 +228,9 @@ public RegisterApplicationMasterResponse registerApplicationMaster( @Override public AllocateResponse allocate(float progressIndicator) throws YarnException, IOException { + if (progressIndicator < 0) { + throw new YarnRuntimeException ("Process Indicator can not be negative"); + } AllocateResponse allocateResponse = null; ArrayList askList = null; ArrayList releaseList = null; @@ -295,6 +303,9 @@ protected void populateNMTokens(AllocateResponse allocateResponse) { public void unregisterApplicationMaster(FinalApplicationStatus appStatus, String appMessage, String appTrackingUrl) throws YarnException, IOException { + if (appStatus == null) { + throw new YarnRuntimeException("AppStatus should not be null."); + } FinishApplicationMasterRequest request = recordFactory .newRecordInstance(FinishApplicationMasterRequest.class); request.setAppAttemptId(appAttemptId); @@ -310,6 +321,9 @@ public void unregisterApplicationMaster(FinalApplicationStatus appStatus, @Override public synchronized void addContainerRequest(T req) { + if (req == null) { + throw new YarnRuntimeException("Resource request can not be null."); + } Set allRacks = new HashSet(); if (req.getRacks() != null) { allRacks.addAll(req.getRacks()); @@ -348,6 +362,9 @@ public synchronized void addContainerRequest(T req) { @Override public synchronized void removeContainerRequest(T req) { + if (req == null) { + throw new YarnRuntimeException("Resource request can not be null."); + } Set allRacks = new HashSet(); if (req.getRacks() != null) { allRacks.addAll(req.getRacks()); @@ -373,6 +390,9 @@ public synchronized void removeContainerRequest(T req) { @Override public synchronized void releaseAssignedContainer(ContainerId containerId) { + if (containerId == null) { + throw new YarnRuntimeException("ContainerId can not be null."); + } release.add(containerId); } @@ -391,6 +411,14 @@ public synchronized int getClusterNodeCount() { Priority priority, String resourceName, Resource capability) { + if (capability == null) { + throw new YarnRuntimeException( + "The Resource to be requested should not be null "); + } + if (priority == null) { + throw new YarnRuntimeException( + "The priority at which to request containers should not be null "); + } List> list = new LinkedList>(); Map> remoteRequests = this.remoteRequestsTable.get(priority);