use of org.apache.hadoop.yarn.api.records.ContainerState in project weave by continuuity.
the class RunningContainers method handleCompleted.
/**
* Handle completion of container.
* @param status The completion status.
* @param restartRunnables Set of runnable names that requires restart.
*/
void handleCompleted(YarnContainerStatus status, Multiset<String> restartRunnables) {
containerLock.lock();
String containerId = status.getContainerId();
int exitStatus = status.getExitStatus();
ContainerState state = status.getState();
try {
Map<String, WeaveContainerController> lookup = containers.column(containerId);
if (lookup.isEmpty()) {
// It's OK because if a container is stopped through removeLast, this would be empty.
return;
}
if (lookup.size() != 1) {
LOG.warn("More than one controller found for container {}", containerId);
}
if (exitStatus != 0) {
LOG.warn("Container {} exited abnormally with state {}, exit code {}. Re-request the container.", containerId, state, exitStatus);
restartRunnables.add(lookup.keySet().iterator().next());
} else {
LOG.info("Container {} exited normally with state {}", containerId, state);
}
for (Map.Entry<String, WeaveContainerController> completedEntry : lookup.entrySet()) {
String runnableName = completedEntry.getKey();
WeaveContainerController controller = completedEntry.getValue();
controller.completed(exitStatus);
removeInstanceId(runnableName, getInstanceId(controller.getRunId()));
resourceReport.removeRunnableResources(runnableName, containerId);
}
lookup.clear();
containerChange.signalAll();
} finally {
containerLock.unlock();
}
}
use of org.apache.hadoop.yarn.api.records.ContainerState in project hadoop by apache.
the class TestDecommissioningNodesWatcher method getContainerStatuses.
// Get mocked ContainerStatus for bunch of containers,
// where numRunningContainers are RUNNING.
private List<ContainerStatus> getContainerStatuses(RMApp app, int numRunningContainers) {
// Total 12 containers
final int total = 12;
numRunningContainers = Math.min(total, numRunningContainers);
List<ContainerStatus> output = new ArrayList<ContainerStatus>();
for (int i = 0; i < total; i++) {
ContainerState cstate = (i >= numRunningContainers) ? ContainerState.COMPLETE : ContainerState.RUNNING;
output.add(ContainerStatus.newInstance(ContainerId.newContainerId(ApplicationAttemptId.newInstance(app.getApplicationId(), i), 1), cstate, "Dummy", 0));
}
return output;
}
use of org.apache.hadoop.yarn.api.records.ContainerState in project hadoop by apache.
the class ApplicationHistoryManagerOnTimelineStore method convertToContainerReport.
private static ContainerReport convertToContainerReport(TimelineEntity entity, String serverHttpAddress, String user) {
int allocatedMem = 0;
int allocatedVcore = 0;
String allocatedHost = null;
int allocatedPort = -1;
int allocatedPriority = 0;
long createdTime = 0;
long finishedTime = 0;
String diagnosticsInfo = null;
int exitStatus = ContainerExitStatus.INVALID;
ContainerState state = null;
String nodeHttpAddress = null;
Map<String, Object> entityInfo = entity.getOtherInfo();
if (entityInfo != null) {
if (entityInfo.containsKey(ContainerMetricsConstants.ALLOCATED_MEMORY_INFO)) {
allocatedMem = (Integer) entityInfo.get(ContainerMetricsConstants.ALLOCATED_MEMORY_INFO);
}
if (entityInfo.containsKey(ContainerMetricsConstants.ALLOCATED_VCORE_INFO)) {
allocatedVcore = (Integer) entityInfo.get(ContainerMetricsConstants.ALLOCATED_VCORE_INFO);
}
if (entityInfo.containsKey(ContainerMetricsConstants.ALLOCATED_HOST_INFO)) {
allocatedHost = entityInfo.get(ContainerMetricsConstants.ALLOCATED_HOST_INFO).toString();
}
if (entityInfo.containsKey(ContainerMetricsConstants.ALLOCATED_PORT_INFO)) {
allocatedPort = (Integer) entityInfo.get(ContainerMetricsConstants.ALLOCATED_PORT_INFO);
}
if (entityInfo.containsKey(ContainerMetricsConstants.ALLOCATED_PRIORITY_INFO)) {
allocatedPriority = (Integer) entityInfo.get(ContainerMetricsConstants.ALLOCATED_PRIORITY_INFO);
}
if (entityInfo.containsKey(ContainerMetricsConstants.ALLOCATED_HOST_HTTP_ADDRESS_INFO)) {
nodeHttpAddress = (String) entityInfo.get(ContainerMetricsConstants.ALLOCATED_HOST_HTTP_ADDRESS_INFO);
}
}
List<TimelineEvent> events = entity.getEvents();
if (events != null) {
for (TimelineEvent event : events) {
if (event.getEventType().equals(ContainerMetricsConstants.CREATED_EVENT_TYPE)) {
createdTime = event.getTimestamp();
} else if (event.getEventType().equals(ContainerMetricsConstants.FINISHED_EVENT_TYPE)) {
finishedTime = event.getTimestamp();
Map<String, Object> eventInfo = event.getEventInfo();
if (eventInfo == null) {
continue;
}
if (eventInfo.containsKey(ContainerMetricsConstants.DIAGNOSTICS_INFO)) {
diagnosticsInfo = eventInfo.get(ContainerMetricsConstants.DIAGNOSTICS_INFO).toString();
}
if (eventInfo.containsKey(ContainerMetricsConstants.EXIT_STATUS_INFO)) {
exitStatus = (Integer) eventInfo.get(ContainerMetricsConstants.EXIT_STATUS_INFO);
}
if (eventInfo.containsKey(ContainerMetricsConstants.STATE_INFO)) {
state = ContainerState.valueOf(eventInfo.get(ContainerMetricsConstants.STATE_INFO).toString());
}
}
}
}
ContainerId containerId = ContainerId.fromString(entity.getEntityId());
String logUrl = null;
NodeId allocatedNode = null;
if (allocatedHost != null) {
allocatedNode = NodeId.newInstance(allocatedHost, allocatedPort);
logUrl = WebAppUtils.getAggregatedLogURL(serverHttpAddress, allocatedNode.toString(), containerId.toString(), containerId.toString(), user);
}
return ContainerReport.newInstance(ContainerId.fromString(entity.getEntityId()), Resource.newInstance(allocatedMem, allocatedVcore), allocatedNode, Priority.newInstance(allocatedPriority), createdTime, finishedTime, diagnosticsInfo, logUrl, exitStatus, state, nodeHttpAddress);
}
use of org.apache.hadoop.yarn.api.records.ContainerState in project hadoop by apache.
the class BaseContainerManagerTest method waitForContainerState.
public static void waitForContainerState(ContainerManagementProtocol containerManager, ContainerId containerID, List<ContainerState> finalStates, int timeOutMax) throws InterruptedException, YarnException, IOException {
List<ContainerId> list = new ArrayList<ContainerId>();
list.add(containerID);
GetContainerStatusesRequest request = GetContainerStatusesRequest.newInstance(list);
ContainerStatus containerStatus = null;
HashSet<ContainerState> fStates = new HashSet<>(finalStates);
int timeoutSecs = 0;
do {
Thread.sleep(2000);
containerStatus = containerManager.getContainerStatuses(request).getContainerStatuses().get(0);
LOG.info("Waiting for container to get into one of states " + fStates + ". Current state is " + containerStatus.getState());
timeoutSecs += 2;
} while (!fStates.contains(containerStatus.getState()) && timeoutSecs < timeOutMax);
LOG.info("Container state is " + containerStatus.getState());
Assert.assertTrue("ContainerState is not correct (timedout)", fStates.contains(containerStatus.getState()));
}
use of org.apache.hadoop.yarn.api.records.ContainerState in project hadoop by apache.
the class LogsCLI method outputAMContainerLogs.
private void outputAMContainerLogs(ContainerLogsRequest request, Configuration conf, LogCLIHelpers logCliHelper, boolean useRegex) throws Exception {
String nodeHttpAddress = request.getNodeHttpAddress();
String containerId = request.getContainerId();
String nodeId = request.getNodeId();
if (request.isAppFinished()) {
if (containerId != null && !containerId.isEmpty()) {
if (nodeId != null && !nodeId.isEmpty()) {
printContainerLogsForFinishedApplication(request, logCliHelper, useRegex);
} else {
printContainerLogsForFinishedApplicationWithoutNodeId(request, logCliHelper, useRegex);
}
}
} else {
if (nodeHttpAddress != null && containerId != null && !nodeHttpAddress.isEmpty() && !containerId.isEmpty()) {
ContainerState containerState = getContainerReport(containerId).getContainerState();
request.setContainerState(containerState);
printContainerLogsFromRunningApplication(conf, request, logCliHelper, useRegex);
}
}
}
Aggregations