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"));
}
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;
}
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();
}
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"));
}
Aggregations