Search in sources :

Example 6 with MetricsRegistryMap

use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.

the class TestContainerProcessManager method testAppMasterWithFwk.

@Test
public void testAppMasterWithFwk() {
    ContainerProcessManager taskManager = new ContainerProcessManager(new MapConfig(config), state, new MetricsRegistryMap(), manager);
    taskManager.start();
    SamzaResource container2 = new SamzaResource(1, 1024, "", "id0");
    assertFalse(taskManager.shouldShutdown());
    taskManager.onResourceAllocated(container2);
    configVals.put(JobConfig.SAMZA_FWK_PATH(), "/export/content/whatever");
    Config config1 = new MapConfig(configVals);
    ContainerProcessManager taskManager1 = new ContainerProcessManager(new MapConfig(config), state, new MetricsRegistryMap(), manager);
    taskManager1.start();
    taskManager1.onResourceAllocated(container2);
}
Also used : JobConfig(org.apache.samza.config.JobConfig) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Test(org.junit.Test)

Example 7 with MetricsRegistryMap

use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.

the class TestContainerProcessManager method testTaskManagerShouldStopWhenContainersFinish.

/**
   * Test Task Manager should stop when all containers finish
   */
@Test
public void testTaskManagerShouldStopWhenContainersFinish() {
    Config conf = getConfig();
    ContainerProcessManager taskManager = new ContainerProcessManager(new MapConfig(conf), state, new MetricsRegistryMap(), manager);
    taskManager.start();
    assertFalse(taskManager.shouldShutdown());
    taskManager.onResourceCompleted(new SamzaResourceStatus("123", "diagnostics", SamzaResourceStatus.SUCCESS));
    assertTrue(taskManager.shouldShutdown());
}
Also used : JobConfig(org.apache.samza.config.JobConfig) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Test(org.junit.Test)

Example 8 with MetricsRegistryMap

use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.

the class TestContainerProcessManager method testContainerProcessManager.

@Test
public void testContainerProcessManager() throws Exception {
    Map<String, String> conf = new HashMap<>();
    conf.putAll(getConfig());
    conf.put("yarn.container.memory.mb", "500");
    conf.put("yarn.container.cpu.cores", "5");
    ContainerProcessManager taskManager = new ContainerProcessManager(new MapConfig(conf), state, new MetricsRegistryMap(), manager);
    AbstractContainerAllocator allocator = (AbstractContainerAllocator) getPrivateFieldFromTaskManager("containerAllocator", taskManager).get(taskManager);
    assertEquals(ContainerAllocator.class, allocator.getClass());
    // Asserts that samza exposed container configs is honored by allocator thread
    assertEquals(500, allocator.containerMemoryMb);
    assertEquals(5, allocator.containerNumCpuCores);
    conf.clear();
    conf.putAll(getConfigWithHostAffinity());
    conf.put("yarn.container.memory.mb", "500");
    conf.put("yarn.container.cpu.cores", "5");
    taskManager = new ContainerProcessManager(new MapConfig(conf), state, new MetricsRegistryMap(), manager);
    allocator = (AbstractContainerAllocator) getPrivateFieldFromTaskManager("containerAllocator", taskManager).get(taskManager);
    assertEquals(HostAwareContainerAllocator.class, allocator.getClass());
    // Asserts that samza exposed container configs is honored by allocator thread
    assertEquals(500, allocator.containerMemoryMb);
    assertEquals(5, allocator.containerNumCpuCores);
}
Also used : HashMap(java.util.HashMap) MapConfig(org.apache.samza.config.MapConfig) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Test(org.junit.Test)

Example 9 with MetricsRegistryMap

use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.

the class TestContainerProcessManager method testNewContainerRequestedOnFailureWithUnknownCode.

/**
   * Test Task Manager should request a new container when a task fails with unknown exit code
   * When host-affinity is not enabled, it will always request for ANY_HOST
   */
@Test
public void testNewContainerRequestedOnFailureWithUnknownCode() throws Exception {
    Config conf = getConfig();
    ContainerProcessManager taskManager = new ContainerProcessManager(new MapConfig(conf), state, new MetricsRegistryMap(), manager);
    MockContainerAllocator allocator = new MockContainerAllocator(manager, conf, state);
    getPrivateFieldFromTaskManager("containerAllocator", taskManager).set(taskManager, allocator);
    Thread thread = new Thread(allocator);
    getPrivateFieldFromTaskManager("allocatorThread", taskManager).set(taskManager, thread);
    // start triggers a request
    taskManager.start();
    assertFalse(taskManager.shouldShutdown());
    assertEquals(1, allocator.getContainerRequestState().numPendingRequests());
    SamzaResource container = new SamzaResource(1, 1024, "abc", "id0");
    taskManager.onResourceAllocated(container);
    // Allow container to run and update state
    Thread.sleep(300);
    // Create first container failure
    taskManager.onResourceCompleted(new SamzaResourceStatus(container.getResourceID(), "diagnostics", 1));
    // The above failure should trigger a container request
    assertEquals(1, allocator.getContainerRequestState().numPendingRequests());
    assertEquals(ResourceRequestState.ANY_HOST, allocator.getContainerRequestState().peekPendingRequest().getPreferredHost());
    assertFalse(taskManager.shouldShutdown());
    assertFalse(state.jobHealthy.get());
    assertEquals(2, manager.resourceRequests.size());
    assertEquals(0, manager.releasedResources.size());
    taskManager.onResourceAllocated(container);
    // Allow container to run and update state
    Thread.sleep(1000);
    assertTrue(state.jobHealthy.get());
    // Create a second failure
    taskManager.onResourceCompleted(new SamzaResourceStatus(container.getResourceID(), "diagnostics", 1));
    // The above failure should trigger a job shutdown because our retry count is set to 1
    assertEquals(0, allocator.getContainerRequestState().numPendingRequests());
    assertEquals(2, manager.resourceRequests.size());
    assertEquals(0, manager.releasedResources.size());
    assertFalse(state.jobHealthy.get());
    assertTrue(taskManager.shouldShutdown());
    assertEquals(SamzaApplicationState.SamzaAppStatus.FAILED, state.status);
    taskManager.stop();
}
Also used : JobConfig(org.apache.samza.config.JobConfig) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Test(org.junit.Test)

Example 10 with MetricsRegistryMap

use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.

the class TestContainerProcessManager method testOnShutdown.

@Test
public void testOnShutdown() throws Exception {
    Config conf = getConfig();
    ContainerProcessManager taskManager = new ContainerProcessManager(new MapConfig(conf), state, new MetricsRegistryMap(), manager);
    taskManager.start();
    Thread.sleep(100);
    Thread allocatorThread = (Thread) getPrivateFieldFromTaskManager("allocatorThread", taskManager).get(taskManager);
    assertTrue(allocatorThread.isAlive());
    taskManager.stop();
    Thread.sleep(100);
    assertFalse(allocatorThread.isAlive());
}
Also used : JobConfig(org.apache.samza.config.JobConfig) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Test(org.junit.Test)

Aggregations

MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)23 Config (org.apache.samza.config.Config)16 Test (org.junit.Test)15 TaskContext (org.apache.samza.task.TaskContext)9 MapConfig (org.apache.samza.config.MapConfig)6 JobConfig (org.apache.samza.config.JobConfig)5 Before (org.junit.Before)5 HashMap (java.util.HashMap)4 TestMessageEnvelope (org.apache.samza.operators.data.TestMessageEnvelope)4 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)4 Set (java.util.Set)3 StreamGraphImpl (org.apache.samza.operators.StreamGraphImpl)3 TestOutputMessageEnvelope (org.apache.samza.operators.data.TestOutputMessageEnvelope)3 JoinFunction (org.apache.samza.operators.functions.JoinFunction)3 Matchers.anyObject (org.mockito.Matchers.anyObject)3 Field (java.lang.reflect.Field)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2