Search in sources :

Example 1 with SamzaApplicationState

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;
}
Also used : SamzaApplicationState(org.apache.samza.clustermanager.SamzaApplicationState) JobModelManager(org.apache.samza.coordinator.JobModelManager) JobModel(org.apache.samza.job.model.JobModel) SamzaResource(org.apache.samza.clustermanager.SamzaResource) ContainerModel(org.apache.samza.job.model.ContainerModel)

Example 2 with 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);
}
Also used : MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) SamzaApplicationState(org.apache.samza.clustermanager.SamzaApplicationState) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Example 3 with SamzaApplicationState

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"));
}
Also used : SamzaApplicationState(org.apache.samza.clustermanager.SamzaApplicationState) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Test(org.junit.Test)

Example 4 with SamzaApplicationState

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

SamzaApplicationState (org.apache.samza.clustermanager.SamzaApplicationState)4 Test (org.junit.Test)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)1 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)1 SamzaResource (org.apache.samza.clustermanager.SamzaResource)1 Config (org.apache.samza.config.Config)1 MapConfig (org.apache.samza.config.MapConfig)1 JobModelManager (org.apache.samza.coordinator.JobModelManager)1 ContainerModel (org.apache.samza.job.model.ContainerModel)1 JobModel (org.apache.samza.job.model.JobModel)1 YarnAppState (org.apache.samza.job.yarn.YarnAppState)1 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)1