Search in sources :

Example 6 with LocalityModel

use of org.apache.samza.job.model.LocalityModel in project samza by apache.

the class TestContainerPlacementActions method setupStandby.

public void setupStandby() throws Exception {
    LocalityManager mockLocalityManager = mock(LocalityManager.class);
    when(mockLocalityManager.readLocality()).thenReturn(new LocalityModel(ImmutableMap.of("0", new ProcessorLocality("0", "host-1"), "1", new ProcessorLocality("1", "host-2"), "0-0", new ProcessorLocality("0", "host-2"), "1-0", new ProcessorLocality("0", "host-1"))));
    state = new SamzaApplicationState(getJobModelManagerWithStandby());
    callback = mock(ClusterResourceManager.Callback.class);
    MockClusterResourceManager clusterResourceManager = new MockClusterResourceManager(callback, state);
    FaultDomainManager faultDomainManager = mock(FaultDomainManager.class);
    ClusterManagerConfig clusterManagerConfig = new ClusterManagerConfig(config);
    // Enable standby
    containerManager = spy(new ContainerManager(containerPlacementMetadataStore, state, clusterResourceManager, true, true, mockLocalityManager, faultDomainManager, config));
    allocatorWithHostAffinity = new MockContainerAllocatorWithHostAffinity(clusterResourceManager, config, state, containerManager);
    cpm = new ContainerProcessManager(clusterManagerConfig, state, new MetricsRegistryMap(), clusterResourceManager, Optional.of(allocatorWithHostAffinity), containerManager, mockLocalityManager, false);
}
Also used : ProcessorLocality(org.apache.samza.job.model.ProcessorLocality) ClusterManagerConfig(org.apache.samza.config.ClusterManagerConfig) LocalityManager(org.apache.samza.container.LocalityManager) LocalityModel(org.apache.samza.job.model.LocalityModel) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap)

Example 7 with LocalityModel

use of org.apache.samza.job.model.LocalityModel in project samza by apache.

the class TestLocalityServlet method testReadContainerLocality.

@Test
public void testReadContainerLocality() throws Exception {
    URL url = new URL(webApp.getUrl().toString() + "locality");
    String response = HttpUtil.read(url, 1000, new ExponentialSleepStrategy());
    LocalityModel locality = mapper.readValue(response, LocalityModel.class);
    assertEquals("Expected locality for two containers", 2, locality.getProcessorLocalities().size());
    assertEquals("Mismatch in locality for processor " + PROCESSOR_ID1, locality.getProcessorLocality(PROCESSOR_ID1), PROCESSOR_1_LOCALITY);
    assertEquals("Mismatch in locality for processor " + PROCESSOR_ID2, locality.getProcessorLocality(PROCESSOR_ID2), PROCESSOR_2_LOCALITY);
}
Also used : ExponentialSleepStrategy(org.apache.samza.util.ExponentialSleepStrategy) LocalityModel(org.apache.samza.job.model.LocalityModel) URL(java.net.URL) Test(org.junit.Test)

Example 8 with LocalityModel

use of org.apache.samza.job.model.LocalityModel in project samza by apache.

the class TestLocalityServlet method testReadProcessorLocalityWithNoLocality.

@Test
public void testReadProcessorLocalityWithNoLocality() throws Exception {
    final ProcessorLocality expectedProcessorLocality = new ProcessorLocality(PROCESSOR_ID2, "");
    URL url = new URL(webApp.getUrl().toString() + "locality?processorId=" + PROCESSOR_ID2);
    when(localityManager.readLocality()).thenReturn(new LocalityModel(ImmutableMap.of()));
    String response = HttpUtil.read(url, 1000, new ExponentialSleepStrategy());
    ProcessorLocality processorLocality = mapper.readValue(response, ProcessorLocality.class);
    assertEquals("Expected empty response for processor locality " + PROCESSOR_ID2 + " but got " + processorLocality, processorLocality, expectedProcessorLocality);
}
Also used : ProcessorLocality(org.apache.samza.job.model.ProcessorLocality) ExponentialSleepStrategy(org.apache.samza.util.ExponentialSleepStrategy) LocalityModel(org.apache.samza.job.model.LocalityModel) URL(java.net.URL) Test(org.junit.Test)

Example 9 with LocalityModel

use of org.apache.samza.job.model.LocalityModel in project samza by apache.

the class TestLocalityServlet method setup.

@Before
public void setup() throws Exception {
    localityManager = mock(LocalityManager.class);
    when(localityManager.readLocality()).thenReturn(new LocalityModel(ImmutableMap.of(PROCESSOR_ID1, PROCESSOR_1_LOCALITY, PROCESSOR_ID2, PROCESSOR_2_LOCALITY)));
    webApp = new HttpServer("/", 0, "", new ServletHolder(new DefaultServlet()));
    webApp.addServlet("/locality", new LocalityServlet(localityManager));
    webApp.start();
}
Also used : LocalityServlet(org.apache.samza.coordinator.server.LocalityServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpServer(org.apache.samza.coordinator.server.HttpServer) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) LocalityManager(org.apache.samza.container.LocalityManager) LocalityModel(org.apache.samza.job.model.LocalityModel) Before(org.junit.Before)

Example 10 with LocalityModel

use of org.apache.samza.job.model.LocalityModel in project samza by apache.

the class TestContainerAllocatorWithHostAffinity method setup.

@Before
public void setup() throws Exception {
    LocalityManager mockLocalityManager = mock(LocalityManager.class);
    when(mockLocalityManager.readLocality()).thenReturn(new LocalityModel(ImmutableMap.of("0", new ProcessorLocality("0", "abc"))));
    CoordinatorStreamStoreTestUtil coordinatorStreamStoreTestUtil = new CoordinatorStreamStoreTestUtil(config);
    CoordinatorStreamStore coordinatorStreamStore = coordinatorStreamStoreTestUtil.getCoordinatorStreamStore();
    coordinatorStreamStore.init();
    containerPlacementMetadataStore = new ContainerPlacementMetadataStore(coordinatorStreamStore);
    containerPlacementMetadataStore.start();
    containerManager = new ContainerManager(containerPlacementMetadataStore, state, clusterResourceManager, true, false, mockLocalityManager, faultDomainManager, config);
    containerAllocator = new ContainerAllocator(clusterResourceManager, config, state, true, containerManager);
    requestState = new MockContainerRequestState(clusterResourceManager, true);
    Field requestStateField = containerAllocator.getClass().getDeclaredField("resourceRequestState");
    requestStateField.setAccessible(true);
    requestStateField.set(containerAllocator, requestState);
    allocatorThread = new Thread(containerAllocator);
}
Also used : ProcessorLocality(org.apache.samza.job.model.ProcessorLocality) Field(java.lang.reflect.Field) CoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore) ContainerPlacementMetadataStore(org.apache.samza.clustermanager.container.placement.ContainerPlacementMetadataStore) LocalityManager(org.apache.samza.container.LocalityManager) LocalityModel(org.apache.samza.job.model.LocalityModel) CoordinatorStreamStoreTestUtil(org.apache.samza.coordinator.metadatastore.CoordinatorStreamStoreTestUtil) Before(org.junit.Before)

Aggregations

LocalityModel (org.apache.samza.job.model.LocalityModel)19 LocalityManager (org.apache.samza.container.LocalityManager)13 ProcessorLocality (org.apache.samza.job.model.ProcessorLocality)12 HashMap (java.util.HashMap)10 Test (org.junit.Test)7 ClusterManagerConfig (org.apache.samza.config.ClusterManagerConfig)6 MapConfig (org.apache.samza.config.MapConfig)5 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)5 Before (org.junit.Before)4 Matchers.anyString (org.mockito.Matchers.anyString)4 URL (java.net.URL)3 ContainerPlacementMetadataStore (org.apache.samza.clustermanager.container.placement.ContainerPlacementMetadataStore)3 CoordinatorStreamStore (org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore)3 CoordinatorStreamStoreTestUtil (org.apache.samza.coordinator.metadatastore.CoordinatorStreamStoreTestUtil)3 ExponentialSleepStrategy (org.apache.samza.util.ExponentialSleepStrategy)3 Field (java.lang.reflect.Field)2 Config (org.apache.samza.config.Config)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 Map (java.util.Map)1 JobConfig (org.apache.samza.config.JobConfig)1