Example usage for org.apache.hadoop.yarn.api.records ContainerId toString

List of usage examples for org.apache.hadoop.yarn.api.records ContainerId toString

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.api.records ContainerId toString.

Prototype

@Override
public String toString() 

Source Link

Usage

From source file:org.apache.samza.job.yarn.YarnClusterResourceManager.java

License:Apache License

@Override
public void onContainerStatusReceived(ContainerId containerId, ContainerStatus containerStatus) {
    log.info("Got status notification for Container ID: {} for Processor ID: {}. Status: {}", containerId,
            getRunningProcessorId(containerId.toString()), containerStatus.getState());
}

From source file:org.apache.samza.job.yarn.YarnClusterResourceManager.java

License:Apache License

@Override
public void onContainerStopped(ContainerId containerId) {
    log.info("Got stop notification for Container ID: {} for Processor ID: {}", containerId,
            getRunningProcessorId(containerId.toString()));
}

From source file:org.apache.samza.job.yarn.YarnClusterResourceManager.java

License:Apache License

@Override
public void onStartContainerError(ContainerId containerId, Throwable t) {
    String processorId = getPendingProcessorId(containerId);

    if (processorId != null) {
        log.info("Got start error notification for Container ID: {} for Processor ID: {} ", containerId,
                processorId, t);//from  www.  j  a va  2s. c  o m
        YarnContainer container = state.pendingProcessors.remove(processorId);
        SamzaResource resource = new SamzaResource(container.resource().getVirtualCores(),
                container.resource().getMemory(), container.nodeId().getHost(), containerId.toString());
        clusterManagerCallback.onStreamProcessorLaunchFailure(resource, new ProcessorLaunchException(t));
    } else {
        log.warn("Did not find the pending Processor ID for the start error notification for Container ID: {}. "
                + "Ignoring notification", containerId);
    }
}

From source file:org.apache.samza.job.yarn.YarnClusterResourceManager.java

License:Apache License

@Override
public void onGetContainerStatusError(ContainerId containerId, Throwable t) {
    log.info("Got status error notification for Container ID: {} for Processor ID: {}", containerId,
            getRunningProcessorId(containerId.toString()), t);
}

From source file:org.apache.samza.job.yarn.YarnClusterResourceManager.java

License:Apache License

@Override
public void onStopContainerError(ContainerId containerId, Throwable t) {
    String processorId = getRunningProcessorId(containerId.toString());

    if (processorId != null) {
        log.info("Got stop error notification for Container ID: {} for Processor ID: {}", containerId,
                processorId, t);//from   w  ww  . j av  a  2s  .  c  om
        YarnContainer container = state.runningProcessors.get(processorId);
    } else {
        log.warn("Did not find the running Processor ID for the stop error notification for Container ID: {}. "
                + "Ignoring notification", containerId);
    }
}

From source file:org.apache.samza.webapp.TestApplicationMasterRestClient.java

License:Apache License

@Test
public void testGetTaskContextSuccess() throws IOException {
    ContainerId containerId = ConverterUtils.toContainerId(YARN_CONTAINER_ID_1);
    YarnAppState yarnAppState = createYarnAppState(containerId);

    String response = ApplicationMasterRestServlet.getTaskContext(jsonMapper, yarnAppState);
    setupMockClientResponse(HttpStatus.SC_OK, "Success", response);

    ApplicationMasterRestClient client = new ApplicationMasterRestClient(mockClient, AM_HOST_NAME, AM_RPC_PORT);
    Map<String, Object> taskContextResult = client.getTaskContext();

    assertEquals(2, taskContextResult.size());
    assertEquals(2, taskContextResult.get("task-id"));
    assertEquals(containerId.toString(), taskContextResult.get("name"));
}

From source file:org.apache.samza.webapp.TestApplicationMasterRestClient.java

License:Apache License

@Test
public void testGetAmStateSuccess() throws IOException {
    SamzaApplicationState samzaAppState = createSamzaApplicationState();

    ApplicationAttemptId attemptId = ConverterUtils.toApplicationAttemptId(APP_ATTEMPT_ID);
    ContainerId containerId = ConverterUtils.toContainerId(YARN_CONTAINER_ID_1);
    YarnAppState yarnAppState = createYarnAppState(containerId);

    String response = ApplicationMasterRestServlet.getAmState(jsonMapper, samzaAppState, yarnAppState);
    setupMockClientResponse(HttpStatus.SC_OK, "Success", response);

    ApplicationMasterRestClient client = new ApplicationMasterRestClient(mockClient, AM_HOST_NAME, AM_RPC_PORT);
    Map<String, Object> amStateResult = client.getAmState();

    assertEquals(4, amStateResult.size());
    assertEquals(String.format("%s:%s", yarnAppState.nodeHost, yarnAppState.rpcUrl.getPort()),
            amStateResult.get("host"));
    assertEquals(containerId.toString(), amStateResult.get("container-id"));
    // Can only validate the keys because up-time changes everytime it's requested
    assertEquals(buildExpectedContainerResponse(yarnAppState.runningProcessors, samzaAppState).keySet(),
            ((Map<String, Object>) amStateResult.get("containers")).keySet());
    assertEquals(attemptId.toString(), amStateResult.get("app-attempt-id"));
}

From source file:org.apache.slider.providers.agent.AgentProviderService.java

License:Apache License

@Override
public void notifyContainerCompleted(ContainerId containerId) {
    // containers get allocated and free'ed without being assigned to any
    // component - so many of the data structures may not be initialized
    if (containerId != null) {
        String containerIdStr = containerId.toString();
        if (getComponentInstanceData().containsKey(containerIdStr)) {
            getComponentInstanceData().remove(containerIdStr);
            log.info("Removing container specific data for {}", containerIdStr);
            publishComponentInstanceData();
        }//from   ww w.  jav  a2 s.c  o m

        if (this.allocatedPorts.containsKey(containerIdStr)) {
            Map<String, String> portsByContainerId = getAllocatedPorts(containerIdStr);
            this.allocatedPorts.remove(containerIdStr);
            // free up the allocations from global as well
            // if multiple containers allocate global ports then last one
            // wins and similarly first one removes it - its not supported anyway
            for (String portName : portsByContainerId.keySet()) {
                getAllocatedPorts().remove(portName);
            }

        }

        String componentName = null;
        synchronized (this.componentStatuses) {
            for (String label : getComponentStatuses().keySet()) {
                if (label.startsWith(containerIdStr)) {
                    componentName = getRoleName(label);
                    log.info("Removing component status for label {}", label);
                    getComponentStatuses().remove(label);
                }
            }
        }

        tags.releaseTag(componentName, containerIdStr);

        synchronized (this.containerExportsMap) {
            Set<String> containerExportSets = containerExportsMap.get(containerIdStr);
            if (containerExportSets != null) {
                for (String containerExportStr : containerExportSets) {
                    String[] parts = containerExportStr.split(":");
                    Map<String, List<ExportEntry>> exportGroup = getCurrentExports(parts[0]);
                    List<ExportEntry> exports = exportGroup.get(parts[1]);
                    List<ExportEntry> exportToRemove = new ArrayList<ExportEntry>();
                    for (ExportEntry export : exports) {
                        if (containerIdStr.equals(export.getContainerId())) {
                            exportToRemove.add(export);
                        }
                    }
                    exports.removeAll(exportToRemove);
                }
                log.info("Removing container exports for {}", containerIdStr);
                containerExportsMap.remove(containerIdStr);
            }
        }
    }
}

From source file:org.apache.slider.providers.agent.ComponentInstanceState.java

License:Apache License

public ComponentInstanceState(String componentName, ContainerId containerId, String applicationId) {
    this.componentName = componentName;
    this.containerId = containerId;
    this.containerIdAsString = containerId.toString();
    this.applicationId = applicationId;
    this.containerState = ContainerState.INIT;
    this.lastHeartbeat = System.currentTimeMillis();
}

From source file:org.apache.slider.providers.agent.TestAgentProviderService.java

License:Apache License

@Test
public void testNotifyContainerCompleted() throws IOException {
    AgentProviderService aps = createAgentProviderService(new Configuration());
    AgentProviderService mockAps = Mockito.spy(aps);
    doNothing().when(mockAps).publishApplicationInstanceData(anyString(), anyString(), anyCollection());

    ContainerId cid = new MockContainerId(1);
    String id = cid.toString();
    ContainerId cid2 = new MockContainerId(2);
    mockAps.getAllocatedPorts().put("a", "100");
    mockAps.getAllocatedPorts(id).put("a", "100");
    mockAps.getAllocatedPorts(id).put("b", "101");
    mockAps.getAllocatedPorts("cid2").put("c", "102");

    mockAps.getComponentInstanceData().put("cid2", new HashMap<String, String>());
    mockAps.getComponentInstanceData().put(id, new HashMap<String, String>());

    mockAps.getComponentStatuses().put("cid2_HM", new ComponentInstanceState("HM", cid2, "aid"));
    mockAps.getComponentStatuses().put(id + "_HM", new ComponentInstanceState("HM", cid, "aid"));

    Assert.assertNotNull(mockAps.getComponentInstanceData().get(id));
    Assert.assertNotNull(mockAps.getComponentInstanceData().get("cid2"));

    Assert.assertNotNull(mockAps.getComponentStatuses().get(id + "_HM"));
    Assert.assertNotNull(mockAps.getComponentStatuses().get("cid2_HM"));

    Assert.assertEquals(mockAps.getAllocatedPorts().size(), 1);
    Assert.assertEquals(mockAps.getAllocatedPorts(id).size(), 2);
    Assert.assertEquals(mockAps.getAllocatedPorts("cid2").size(), 1);

    // Make the call
    mockAps.notifyContainerCompleted(new MockContainerId(1));

    Assert.assertEquals(mockAps.getAllocatedPorts().size(), 0);
    Assert.assertEquals(mockAps.getAllocatedPorts(id).size(), 0);
    Assert.assertEquals(mockAps.getAllocatedPorts("cid2").size(), 1);

    Assert.assertNull(mockAps.getComponentInstanceData().get(id));
    Assert.assertNotNull(mockAps.getComponentInstanceData().get("cid2"));

    Assert.assertNull(mockAps.getComponentStatuses().get(id + "_HM"));
    Assert.assertNotNull(mockAps.getComponentStatuses().get("cid2_HM"));
}