YARN-6666. Fix unit test failure in TestRouterClientRMService. (Botong Huang via Subru).

This commit is contained in:
Subru Krishnan 2017-05-30 13:37:37 -07:00 committed by Carlo Curino
parent bd9c7b1bec
commit e750907d0a
1 changed files with 14 additions and 24 deletions

View File

@ -21,8 +21,8 @@ package org.apache.hadoop.yarn.server;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -118,6 +118,7 @@ import org.apache.hadoop.yarn.api.records.UpdatedContainer;
import org.apache.hadoop.yarn.api.records.YarnApplicationAttemptState; import org.apache.hadoop.yarn.api.records.YarnApplicationAttemptState;
import org.apache.hadoop.yarn.api.records.YarnApplicationState; import org.apache.hadoop.yarn.api.records.YarnApplicationState;
import org.apache.hadoop.yarn.exceptions.ApplicationMasterNotRegisteredException; import org.apache.hadoop.yarn.exceptions.ApplicationMasterNotRegisteredException;
import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException;
import org.apache.hadoop.yarn.exceptions.InvalidApplicationMasterRequestException; import org.apache.hadoop.yarn.exceptions.InvalidApplicationMasterRequestException;
import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.security.AMRMTokenIdentifier; import org.apache.hadoop.yarn.security.AMRMTokenIdentifier;
@ -167,6 +168,7 @@ public class MockResourceManagerFacade implements ApplicationClientProtocol,
private static final Logger LOG = private static final Logger LOG =
LoggerFactory.getLogger(MockResourceManagerFacade.class); LoggerFactory.getLogger(MockResourceManagerFacade.class);
private HashSet<ApplicationId> applicationMap = new HashSet<>();
private HashMap<String, List<ContainerId>> applicationContainerIdMap = private HashMap<String, List<ContainerId>> applicationContainerIdMap =
new HashMap<String, List<ContainerId>>(); new HashMap<String, List<ContainerId>>();
private HashMap<ContainerId, Container> allocatedContainerMap = private HashMap<ContainerId, Container> allocatedContainerMap =
@ -424,38 +426,26 @@ public class MockResourceManagerFacade implements ApplicationClientProtocol,
@Override @Override
public SubmitApplicationResponse submitApplication( public SubmitApplicationResponse submitApplication(
SubmitApplicationRequest request) throws YarnException, IOException { SubmitApplicationRequest request) throws YarnException, IOException {
ApplicationId appId = null;
if (request.getApplicationSubmissionContext() != null) {
appId = request.getApplicationSubmissionContext().getApplicationId();
}
LOG.info("Application submitted: " + appId);
applicationMap.add(appId);
return SubmitApplicationResponse.newInstance(); return SubmitApplicationResponse.newInstance();
} }
@Override @Override
public KillApplicationResponse forceKillApplication( public KillApplicationResponse forceKillApplication(
KillApplicationRequest request) throws YarnException, IOException { KillApplicationRequest request) throws YarnException, IOException {
String appId = ""; ApplicationId appId = null;
boolean foundApp = false;
if (request.getApplicationId() != null) { if (request.getApplicationId() != null) {
appId = request.getApplicationId().toString(); appId = request.getApplicationId();
synchronized (applicationContainerIdMap) { if (!applicationMap.remove(appId)) {
for (Entry<String, List<ContainerId>> entry : applicationContainerIdMap throw new ApplicationNotFoundException(
.entrySet()) { "Trying to kill an absent application: " + appId);
ApplicationAttemptId attemptId =
ApplicationAttemptId.fromString(entry.getKey());
if (attemptId.getApplicationId().equals(request.getApplicationId())) {
// Remove the apptempt and the containers that were being tracked
List<ContainerId> ids =
applicationContainerIdMap.remove(entry.getKey());
if (ids != null) {
for (ContainerId c : ids) {
allocatedContainerMap.remove(c);
}
}
foundApp = true;
}
}
} }
} }
if (!foundApp) {
throw new YarnException("The application id is NOT registered: " + appId);
}
LOG.info("Force killing application: " + appId); LOG.info("Force killing application: " + appId);
return KillApplicationResponse.newInstance(true); return KillApplicationResponse.newInstance(true);
} }