use of org.apache.samza.clustermanager.SamzaApplicationState in project samza by apache.
the class TestApplicationMasterRestClient method createSamzaApplicationState.
private SamzaApplicationState createSamzaApplicationState() {
HashMap<String, ContainerModel> containers = generateContainers();
JobModel mockJobModel = mock(JobModel.class);
when(mockJobModel.getContainers()).thenReturn(containers);
JobModelManager mockJobModelManager = mock(JobModelManager.class);
when(mockJobModelManager.jobModel()).thenReturn(mockJobModel);
SamzaApplicationState samzaApplicationState = new SamzaApplicationState(mockJobModelManager);
samzaApplicationState.runningProcessors.put(YARN_CONTAINER_ID_3, new SamzaResource(1, 2, "dummyNodeHost1", "dummyResourceId1"));
samzaApplicationState.runningProcessors.put(YARN_CONTAINER_ID_2, new SamzaResource(2, 4, "dummyNodeHost2", "dummyResourceId2"));
return samzaApplicationState;
}
use of org.apache.samza.clustermanager.SamzaApplicationState in project samza by apache.
the class TestApplicationMasterRestClient method testGetConfigSuccess.
@Test
public void testGetConfigSuccess() throws IOException {
SamzaApplicationState samzaAppState = createSamzaApplicationState();
Map<String, String> configMap = ImmutableMap.of("key1", "value1", "key2", "value2");
Config config = new MapConfig(configMap);
String response = ApplicationMasterRestServlet.getConfig(jsonMapper, config);
setupMockClientResponse(HttpStatus.SC_OK, "Success", response);
ApplicationMasterRestClient client = new ApplicationMasterRestClient(mockClient, AM_HOST_NAME, AM_RPC_PORT);
Map<String, Object> configResult = client.getConfig();
assertEquals(configMap, configResult);
}
use of org.apache.samza.clustermanager.SamzaApplicationState in project samza by apache.
the class TestApplicationMasterRestClient method testGetMetricsSuccess.
@Test
public void testGetMetricsSuccess() throws IOException {
SamzaApplicationState samzaAppState = createSamzaApplicationState();
MetricsRegistryMap registry = new MetricsRegistryMap();
assignMetricValues(samzaAppState, registry);
String response = ApplicationMasterRestServlet.getMetrics(jsonMapper, registry);
setupMockClientResponse(HttpStatus.SC_OK, "Success", response);
ApplicationMasterRestClient client = new ApplicationMasterRestClient(mockClient, AM_HOST_NAME, AM_RPC_PORT);
Map<String, Map<String, Object>> metricsResult = client.getMetrics();
String group = SamzaAppMasterMetrics.class.getCanonicalName();
assertEquals(1, metricsResult.size());
assertTrue(metricsResult.containsKey(group));
Map<String, Object> amMetricsGroup = metricsResult.get(group);
assertEquals(8, amMetricsGroup.size());
assertEquals(samzaAppState.runningProcessors.size(), amMetricsGroup.get("running-containers"));
assertEquals(samzaAppState.neededProcessors.get(), amMetricsGroup.get("needed-containers"));
assertEquals(samzaAppState.completedProcessors.get(), amMetricsGroup.get("completed-containers"));
assertEquals(samzaAppState.failedContainers.get(), amMetricsGroup.get("failed-containers"));
assertEquals(samzaAppState.releasedContainers.get(), amMetricsGroup.get("released-containers"));
assertEquals(samzaAppState.processorCount.get(), amMetricsGroup.get("container-count"));
assertEquals(samzaAppState.jobHealthy.get() ? 1 : 0, amMetricsGroup.get("job-healthy"));
assertEquals(0, amMetricsGroup.get("container-from-previous-attempt"));
}
use of org.apache.samza.clustermanager.SamzaApplicationState 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