Search in sources :

Example 1 with ContainerState

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();
    }
}
Also used : WeaveContainerController(com.continuuity.weave.internal.WeaveContainerController) ContainerState(org.apache.hadoop.yarn.api.records.ContainerState) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with ContainerState

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;
}
Also used : ContainerStatus(org.apache.hadoop.yarn.api.records.ContainerStatus) ArrayList(java.util.ArrayList) ContainerState(org.apache.hadoop.yarn.api.records.ContainerState)

Example 3 with ContainerState

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);
}
Also used : TimelineEvent(org.apache.hadoop.yarn.api.records.timeline.TimelineEvent) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) NodeId(org.apache.hadoop.yarn.api.records.NodeId) ContainerState(org.apache.hadoop.yarn.api.records.ContainerState) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with ContainerState

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()));
}
Also used : ContainerStatus(org.apache.hadoop.yarn.api.records.ContainerStatus) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) GetContainerStatusesRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest) ArrayList(java.util.ArrayList) ContainerState(org.apache.hadoop.yarn.api.records.ContainerState) HashSet(java.util.HashSet)

Example 5 with ContainerState

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);
        }
    }
}
Also used : ContainerState(org.apache.hadoop.yarn.api.records.ContainerState)

Aggregations

ContainerState (org.apache.hadoop.yarn.api.records.ContainerState)5 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)2 ContainerStatus (org.apache.hadoop.yarn.api.records.ContainerStatus)2 WeaveContainerController (com.continuuity.weave.internal.WeaveContainerController)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 GetContainerStatusesRequest (org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest)1 NodeId (org.apache.hadoop.yarn.api.records.NodeId)1 TimelineEvent (org.apache.hadoop.yarn.api.records.timeline.TimelineEvent)1