use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container in project hadoop by apache.
the class ContainerManagerImpl method recoverActiveContainer.
/**
* Recover a running container.
*/
@SuppressWarnings("unchecked")
protected void recoverActiveContainer(Application app, ContainerLaunchContext launchContext, ContainerTokenIdentifier token, RecoveredContainerState rcs) throws IOException {
Credentials credentials = YarnServerSecurityUtils.parseCredentials(launchContext);
Container container = new ContainerImpl(getConfig(), dispatcher, launchContext, credentials, metrics, token, context, rcs);
context.getContainers().put(token.getContainerID(), container);
app.handle(new ApplicationContainerInitEvent(container));
}
use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container in project hadoop by apache.
the class ContainerManagerImpl method changeContainerResourceInternal.
@SuppressWarnings("unchecked")
private void changeContainerResourceInternal(ContainerId containerId, int containerVersion, Resource targetResource, boolean increase) throws YarnException, IOException {
Container container = context.getContainers().get(containerId);
// Check container existence
if (container == null) {
if (nodeStatusUpdater.isContainerRecentlyStopped(containerId)) {
throw RPCUtil.getRemoteException("Container " + containerId.toString() + " was recently stopped on node manager.");
} else {
throw RPCUtil.getRemoteException("Container " + containerId.toString() + " is not handled by this NodeManager");
}
}
// Check container state
org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerState currentState = container.getContainerState();
if (currentState != org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerState.RUNNING) {
throw RPCUtil.getRemoteException("Container " + containerId.toString() + " is in " + currentState.name() + " state." + " Resource can only be changed when a container is in" + " RUNNING state");
}
// Check validity of the target resource.
Resource currentResource = container.getResource();
if (currentResource.equals(targetResource)) {
LOG.warn("Unable to change resource for container " + containerId.toString() + ". The target resource " + targetResource.toString() + " is the same as the current resource");
return;
}
if (increase && !Resources.fitsIn(currentResource, targetResource)) {
throw RPCUtil.getRemoteException("Unable to increase resource for " + "container " + containerId.toString() + ". The target resource " + targetResource.toString() + " is smaller than the current resource " + currentResource.toString());
}
if (!increase && (!Resources.fitsIn(Resources.none(), targetResource) || !Resources.fitsIn(targetResource, currentResource))) {
throw RPCUtil.getRemoteException("Unable to decrease resource for " + "container " + containerId.toString() + ". The target resource " + targetResource.toString() + " is not smaller than the current resource " + currentResource.toString());
}
if (increase) {
org.apache.hadoop.yarn.api.records.Container increasedContainer = org.apache.hadoop.yarn.api.records.Container.newInstance(containerId, null, null, targetResource, null, null);
if (context.getIncreasedContainers().putIfAbsent(containerId, increasedContainer) != null) {
throw RPCUtil.getRemoteException("Container " + containerId.toString() + " resource is being increased.");
}
}
this.readLock.lock();
try {
if (!serviceStopped) {
// Persist container resource change for recovery
this.context.getNMStateStore().storeContainerResourceChanged(containerId, containerVersion, targetResource);
getContainersMonitor().handle(new ChangeMonitoringContainerResourceEvent(containerId, targetResource));
} else {
throw new YarnException("Unable to change container resource as the NodeManager is " + "in the process of shutting down");
}
} finally {
this.readLock.unlock();
}
}
use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container in project hadoop by apache.
the class ContainerManagerImpl method stopContainerInternal.
@SuppressWarnings("unchecked")
protected void stopContainerInternal(ContainerId containerID) throws YarnException, IOException {
String containerIDStr = containerID.toString();
Container container = this.context.getContainers().get(containerID);
LOG.info("Stopping container with container Id: " + containerIDStr);
if (container == null) {
if (!nodeStatusUpdater.isContainerRecentlyStopped(containerID)) {
throw RPCUtil.getRemoteException("Container " + containerIDStr + " is not handled by this NodeManager");
}
} else {
if (container.isRecovering()) {
throw new NMNotYetReadyException("Container " + containerIDStr + " is recovering, try later");
}
context.getNMStateStore().storeContainerKilled(containerID);
container.sendKillEvent(ContainerExitStatus.KILLED_BY_APPMASTER, "Container killed by the ApplicationMaster.");
NMAuditLogger.logSuccess(container.getUser(), AuditConstants.STOP_CONTAINER, "ContainerManageImpl", containerID.getApplicationAttemptId().getApplicationId(), containerID);
}
}
use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container in project hadoop by apache.
the class ResourceLocalizationService method handleCleanupContainerResources.
@SuppressWarnings("unchecked")
private void handleCleanupContainerResources(ContainerLocalizationCleanupEvent rsrcCleanup) {
Container c = rsrcCleanup.getContainer();
Map<LocalResourceVisibility, Collection<LocalResourceRequest>> rsrcs = rsrcCleanup.getResources();
for (Map.Entry<LocalResourceVisibility, Collection<LocalResourceRequest>> e : rsrcs.entrySet()) {
LocalResourcesTracker tracker = getLocalResourcesTracker(e.getKey(), c.getUser(), c.getContainerId().getApplicationAttemptId().getApplicationId());
for (LocalResourceRequest req : e.getValue()) {
tracker.handle(new ResourceReleaseEvent(req, c.getContainerId()));
}
}
String locId = c.getContainerId().toString();
localizerTracker.cleanupPrivLocalizers(locId);
// Delete the container directories
String userName = c.getUser();
String containerIDStr = c.toString();
String appIDStr = c.getContainerId().getApplicationAttemptId().getApplicationId().toString();
for (String localDir : dirsHandler.getLocalDirsForCleanup()) {
// Delete the user-owned container-dir
Path usersdir = new Path(localDir, ContainerLocalizer.USERCACHE);
Path userdir = new Path(usersdir, userName);
Path allAppsdir = new Path(userdir, ContainerLocalizer.APPCACHE);
Path appDir = new Path(allAppsdir, appIDStr);
Path containerDir = new Path(appDir, containerIDStr);
submitDirForDeletion(userName, containerDir);
// Delete the nmPrivate container-dir
Path sysDir = new Path(localDir, NM_PRIVATE_DIR);
Path appSysDir = new Path(sysDir, appIDStr);
Path containerSysDir = new Path(appSysDir, containerIDStr);
submitDirForDeletion(null, containerSysDir);
}
dispatcher.getEventHandler().handle(new ContainerEvent(c.getContainerId(), ContainerEventType.CONTAINER_RESOURCES_CLEANEDUP));
}
use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container in project hadoop by apache.
the class ResourceLocalizationService method handleContainerResourcesLocalized.
/**
* Once a container's resources are localized, kill the corresponding
* {@link ContainerLocalizer}
*/
private void handleContainerResourcesLocalized(ContainerLocalizationEvent event) {
Container c = event.getContainer();
String locId = c.getContainerId().toString();
localizerTracker.endContainerLocalization(locId);
}
Aggregations