Search in sources :

Example 6 with ProcessorLocality

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

the class TestJobModelHelper method testAllProcessorLocalityExists.

@Test
public void testAllProcessorLocalityExists() {
    Map<String, ContainerModel> containerModels = ImmutableMap.of("0", new ContainerModel("0", ImmutableMap.of(taskName(0), taskModel(0, 0, 0), taskName(2), taskModel(2, 2, 2))), "1", new ContainerModel("1", ImmutableMap.of(taskName(1), taskModel(1, 1, 1), taskName(3), taskModel(3, 3))));
    Map<String, ProcessorLocality> processorLocalities = ImmutableMap.of("0", processorLocality("0", HOST0), "1", processorLocality("1", HOST1));
    when(this.localityModel.getProcessorLocalities()).thenReturn(processorLocalities);
    setupOldTaskAssignments(containerModels);
    runAndCheckNewJobModel(config(), containerModels);
    verifyGrouperMetadata(processorIdToLocationId(ImmutableMap.of("0", HOST0, "1", HOST1)), ImmutableMap.of(taskName(0), new LocationId(HOST0), taskName(1), new LocationId(HOST1), taskName(2), new LocationId(HOST0), taskName(3), new LocationId(HOST1)), activeTaskToSSPs(containerModels), activeTaskToContainer(containerModels));
    verifyNewTaskAssignments(null, null, containerToTaskToMode(containerModels), sspToTasks(containerModels));
}
Also used : ProcessorLocality(org.apache.samza.job.model.ProcessorLocality) LocationId(org.apache.samza.runtime.LocationId) ContainerModel(org.apache.samza.job.model.ContainerModel) Test(org.junit.Test)

Example 7 with ProcessorLocality

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

the class TestJobModelHelper method processorLocality.

private static ProcessorLocality processorLocality(String id, String host) {
    ProcessorLocality processorLocality = mock(ProcessorLocality.class);
    when(processorLocality.id()).thenReturn(id);
    when(processorLocality.host()).thenReturn(host);
    return processorLocality;
}
Also used : ProcessorLocality(org.apache.samza.job.model.ProcessorLocality)

Example 8 with ProcessorLocality

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

the class TestJobModelHelper method testNewContainerWithProcessorLocality.

@Test
public void testNewContainerWithProcessorLocality() {
    Map<String, ContainerModel> oldContainerModels = ImmutableMap.of("0", new ContainerModel("0", ImmutableMap.of(taskName(0), taskModel(0, 0, 0))));
    Map<String, ProcessorLocality> processorLocalities = ImmutableMap.of("0", processorLocality("0", HOST0));
    when(this.localityModel.getProcessorLocalities()).thenReturn(processorLocalities);
    setupOldTaskAssignments(oldContainerModels);
    Map<String, ContainerModel> containerModels = ImmutableMap.of("0", new ContainerModel("0", ImmutableMap.of(taskName(0), taskModel(0, 0, 0), taskName(2), taskModel(2, 2, 2))), "1", new ContainerModel("1", ImmutableMap.of(taskName(1), taskModel(1, 1, 1), taskName(3), taskModel(3, 3))));
    runAndCheckNewJobModel(config(), containerModels);
    verifyGrouperMetadata(processorIdToLocationId(ImmutableMap.of("0", HOST0)), ImmutableMap.of(taskName(0), new LocationId(HOST0)), activeTaskToSSPs(oldContainerModels), activeTaskToContainer(oldContainerModels));
    verifyNewTaskAssignments(taskNameStrings(oldContainerModels, TaskMode.Active), allSSPs(containerModels), containerToTaskToMode(containerModels), sspToTasks(containerModels));
}
Also used : ProcessorLocality(org.apache.samza.job.model.ProcessorLocality) LocationId(org.apache.samza.runtime.LocationId) ContainerModel(org.apache.samza.job.model.ContainerModel) Test(org.junit.Test)

Example 9 with ProcessorLocality

use of org.apache.samza.job.model.ProcessorLocality 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 10 with ProcessorLocality

use of org.apache.samza.job.model.ProcessorLocality 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

ProcessorLocality (org.apache.samza.job.model.ProcessorLocality)18 LocalityModel (org.apache.samza.job.model.LocalityModel)12 LocalityManager (org.apache.samza.container.LocalityManager)10 HashMap (java.util.HashMap)8 ClusterManagerConfig (org.apache.samza.config.ClusterManagerConfig)6 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)6 MapConfig (org.apache.samza.config.MapConfig)5 Test (org.junit.Test)5 JobConfig (org.apache.samza.config.JobConfig)4 LocationId (org.apache.samza.runtime.LocationId)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Map (java.util.Map)3 Config (org.apache.samza.config.Config)3 CoordinatorStreamStore (org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang3.StringUtils)2 ContainerPlacementMetadataStore (org.apache.samza.clustermanager.container.placement.ContainerPlacementMetadataStore)2