use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent in project hadoop by apache.
the class ContainerManagerImpl method rollbackLastReInitialization.
/**
* Rollback the last reInitialization, if possible.
* @param containerId Container ID.
* @return Rollback Response.
* @throws YarnException Yarn Exception.
*/
@Override
public RollbackResponse rollbackLastReInitialization(ContainerId containerId) throws YarnException {
Container container = preReInitializeOrLocalizeCheck(containerId, ReInitOp.ROLLBACK);
if (container.canRollback()) {
dispatcher.getEventHandler().handle(new ContainerEvent(containerId, ContainerEventType.ROLLBACK_REINIT));
container.setIsReInitializing(true);
} else {
throw new YarnException("Nothing to rollback to !!");
}
return RollbackResponse.newInstance();
}
use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent in project hadoop by apache.
the class RecoveredContainerLaunch method call.
/**
* Wait on the process specified in pid file and return its exit code
*/
@SuppressWarnings("unchecked")
@Override
public Integer call() {
int retCode = ExitCode.LOST.getExitCode();
ContainerId containerId = container.getContainerId();
String appIdStr = containerId.getApplicationAttemptId().getApplicationId().toString();
String containerIdStr = containerId.toString();
dispatcher.getEventHandler().handle(new ContainerEvent(containerId, ContainerEventType.CONTAINER_LAUNCHED));
boolean notInterrupted = true;
try {
File pidFile = locatePidFile(appIdStr, containerIdStr);
if (pidFile != null) {
String pidPathStr = pidFile.getPath();
pidFilePath = new Path(pidPathStr);
exec.activateContainer(containerId, pidFilePath);
retCode = exec.reacquireContainer(new ContainerReacquisitionContext.Builder().setContainer(container).setUser(container.getUser()).setContainerId(containerId).build());
} else {
LOG.warn("Unable to locate pid file for container " + containerIdStr);
}
} catch (InterruptedException | InterruptedIOException e) {
LOG.warn("Interrupted while waiting for exit code from " + containerId);
notInterrupted = false;
} catch (IOException e) {
LOG.error("Unable to recover container " + containerIdStr, e);
} finally {
if (notInterrupted) {
this.completed.set(true);
exec.deactivateContainer(containerId);
try {
getContext().getNMStateStore().storeContainerCompleted(containerId, retCode);
} catch (IOException e) {
LOG.error("Unable to set exit code for container " + containerId);
}
}
}
if (retCode != 0) {
LOG.warn("Recovered container exited with a non-zero exit code " + retCode);
this.dispatcher.getEventHandler().handle(new ContainerExitEvent(containerId, ContainerEventType.CONTAINER_EXITED_WITH_FAILURE, retCode, "Container exited with a non-zero exit code " + retCode));
return retCode;
}
LOG.info("Recovered container " + containerId + " succeeded");
dispatcher.getEventHandler().handle(new ContainerEvent(containerId, ContainerEventType.CONTAINER_EXITED_WITH_SUCCESS));
return 0;
}
use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent in project hadoop by apache.
the class ContainerLaunch method launchContainer.
@SuppressWarnings("unchecked")
protected int launchContainer(ContainerStartContext ctx) throws IOException {
ContainerId containerId = container.getContainerId();
if (container.isMarkedForKilling()) {
LOG.info("Container " + containerId + " not launched as it has already " + "been marked for Killing");
this.killedBeforeStart = true;
return ExitCode.TERMINATED.getExitCode();
}
// LaunchContainer is a blocking call. We are here almost means the
// container is launched, so send out the event.
dispatcher.getEventHandler().handle(new ContainerEvent(containerId, ContainerEventType.CONTAINER_LAUNCHED));
context.getNMStateStore().storeContainerLaunched(containerId);
// Check if the container is signalled to be killed.
if (!containerAlreadyLaunched.compareAndSet(false, true)) {
LOG.info("Container " + containerId + " not launched as " + "cleanup already called");
return ExitCode.TERMINATED.getExitCode();
} else {
exec.activateContainer(containerId, pidFilePath);
return exec.launchContainer(ctx);
}
}
use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent in project hadoop by apache.
the class ContainerLaunch method handleContainerExitCode.
@SuppressWarnings("unchecked")
protected void handleContainerExitCode(int exitCode, Path containerLogDir) {
ContainerId containerId = container.getContainerId();
if (LOG.isDebugEnabled()) {
LOG.debug("Container " + containerId + " completed with exit code " + exitCode);
}
StringBuilder diagnosticInfo = new StringBuilder("Container exited with a non-zero exit code ");
diagnosticInfo.append(exitCode);
diagnosticInfo.append(". ");
if (exitCode == ExitCode.FORCE_KILLED.getExitCode() || exitCode == ExitCode.TERMINATED.getExitCode()) {
// If Container was killed before starting... NO need to do this.
if (!killedBeforeStart) {
dispatcher.getEventHandler().handle(new ContainerExitEvent(containerId, ContainerEventType.CONTAINER_KILLED_ON_REQUEST, exitCode, diagnosticInfo.toString()));
}
} else if (exitCode != 0) {
handleContainerExitWithFailure(containerId, exitCode, containerLogDir, diagnosticInfo);
} else {
LOG.info("Container " + containerId + " succeeded ");
dispatcher.getEventHandler().handle(new ContainerEvent(containerId, ContainerEventType.CONTAINER_EXITED_WITH_SUCCESS));
}
}
use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent in project hadoop by apache.
the class DummyContainerManager method createResourceLocalizationService.
@Override
@SuppressWarnings("unchecked")
protected ResourceLocalizationService createResourceLocalizationService(ContainerExecutor exec, DeletionService deletionContext, Context context) {
return new ResourceLocalizationService(super.dispatcher, exec, deletionContext, super.dirsHandler, context) {
@Override
public void handle(LocalizationEvent event) {
switch(event.getType()) {
case INIT_APPLICATION_RESOURCES:
Application app = ((ApplicationLocalizationEvent) event).getApplication();
// Simulate event from ApplicationLocalization.
dispatcher.getEventHandler().handle(new ApplicationInitedEvent(app.getAppId()));
break;
case LOCALIZE_CONTAINER_RESOURCES:
ContainerLocalizationRequestEvent rsrcReqs = (ContainerLocalizationRequestEvent) event;
// simulate localization of all requested resources
for (Collection<LocalResourceRequest> rc : rsrcReqs.getRequestedResources().values()) {
for (LocalResourceRequest req : rc) {
LOG.info("DEBUG: " + req + ":" + rsrcReqs.getContainer().getContainerId());
dispatcher.getEventHandler().handle(new ContainerResourceLocalizedEvent(rsrcReqs.getContainer().getContainerId(), req, new Path("file:///local" + req.getPath().toUri().getPath())));
}
}
break;
case CLEANUP_CONTAINER_RESOURCES:
Container container = ((ContainerLocalizationEvent) event).getContainer();
// TODO: delete the container dir
this.dispatcher.getEventHandler().handle(new ContainerEvent(container.getContainerId(), ContainerEventType.CONTAINER_RESOURCES_CLEANEDUP));
break;
case DESTROY_APPLICATION_RESOURCES:
Application application = ((ApplicationLocalizationEvent) event).getApplication();
// decrement reference counts of all resources associated with this
// app
this.dispatcher.getEventHandler().handle(new ApplicationEvent(application.getAppId(), ApplicationEventType.APPLICATION_RESOURCES_CLEANEDUP));
break;
default:
fail("Unexpected event: " + event.getType());
}
}
};
}
Aggregations