Search in sources :

Example 1 with YarnAppState

use of org.apache.samza.job.yarn.YarnAppState in project samza by apache.

the class TestApplicationMasterRestClient method testGetTaskContextSuccess.

@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"));
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) YarnAppState(org.apache.samza.job.yarn.YarnAppState) Test(org.junit.Test)

Example 2 with YarnAppState

use of org.apache.samza.job.yarn.YarnAppState in project samza by apache.

the class TestApplicationMasterRestClient method createYarnAppState.

private YarnAppState createYarnAppState(ContainerId containerId) throws MalformedURLException {
    YarnAppState yarnAppState = new YarnAppState(2, containerId, AM_HOST_NAME, AM_RPC_PORT, AM_HTTP_PORT);
    yarnAppState.rpcUrl = new URL(new HttpHost(AM_HOST_NAME, AM_RPC_PORT).toURI());
    yarnAppState.runningProcessors.put("0", new YarnContainer(Container.newInstance(ConverterUtils.toContainerId(YARN_CONTAINER_ID_2), ConverterUtils.toNodeIdWithDefaultPort("dummyNodeHost1"), "dummyNodeHttpHost1", null, null, null)));
    yarnAppState.runningProcessors.put("1", new YarnContainer(Container.newInstance(ConverterUtils.toContainerId(YARN_CONTAINER_ID_3), ConverterUtils.toNodeIdWithDefaultPort("dummyNodeHost2"), "dummyNodeHttpHost2", null, null, null)));
    return yarnAppState;
}
Also used : HttpHost(org.apache.http.HttpHost) YarnAppState(org.apache.samza.job.yarn.YarnAppState) YarnContainer(org.apache.samza.job.yarn.YarnContainer) URL(java.net.URL)

Example 3 with YarnAppState

use of org.apache.samza.job.yarn.YarnAppState in project samza by apache.

the class TestYarnContainerHeartbeatServlet method setup.

@Before
public void setup() throws Exception {
    container = mock(YarnContainer.class);
    ReadableMetricsRegistry registry = new MetricsRegistryMap();
    yarnAppState = new YarnAppState(-1, ConverterUtils.toContainerId("container_1350670447861_0003_01_000001"), "testHost", 1, 1);
    webApp = new HttpServer("/", 0, "", new ServletHolder(new DefaultServlet()));
    webApp.addServlet("/", new YarnContainerHeartbeatServlet(yarnAppState, registry));
    webApp.start();
    mapper = new ObjectMapper();
}
Also used : ReadableMetricsRegistry(org.apache.samza.metrics.ReadableMetricsRegistry) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) YarnAppState(org.apache.samza.job.yarn.YarnAppState) HttpServer(org.apache.samza.coordinator.server.HttpServer) YarnContainer(org.apache.samza.job.yarn.YarnContainer) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 4 with YarnAppState

use of org.apache.samza.job.yarn.YarnAppState in project samza by apache.

the class TestApplicationMasterRestClient method testGetAmStateSuccess.

@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"));
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) YarnAppState(org.apache.samza.job.yarn.YarnAppState) SamzaApplicationState(org.apache.samza.clustermanager.SamzaApplicationState) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) Test(org.junit.Test)

Aggregations

YarnAppState (org.apache.samza.job.yarn.YarnAppState)4 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)2 YarnContainer (org.apache.samza.job.yarn.YarnContainer)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 URL (java.net.URL)1 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)1 HttpHost (org.apache.http.HttpHost)1 SamzaApplicationState (org.apache.samza.clustermanager.SamzaApplicationState)1 HttpServer (org.apache.samza.coordinator.server.HttpServer)1 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)1 ReadableMetricsRegistry (org.apache.samza.metrics.ReadableMetricsRegistry)1 DefaultServlet (org.eclipse.jetty.servlet.DefaultServlet)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 Before (org.junit.Before)1