Search in sources :

Example 6 with JobModel

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

the class TestContainerAllocator method getJobModelReader.

private static JobModelManager getJobModelReader(int containerCount) {
    //Ideally, the JobModelReader should be constructed independent of HttpServer.
    //That way it becomes easier to mock objects. Save it for later.
    HttpServer server = new MockHttpServer("/", 7777, null, new ServletHolder(DefaultServlet.class));
    Map<String, ContainerModel> containers = new java.util.HashMap<>();
    for (int i = 0; i < containerCount; i++) {
        ContainerModel container = new ContainerModel(String.valueOf(i), i, new HashMap<TaskName, TaskModel>());
        containers.put(String.valueOf(i), container);
    }
    JobModel jobModel = new JobModel(getConfig(), containers);
    return new JobModelManager(jobModel, server, null);
}
Also used : HashMap(java.util.HashMap) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) JobModelManager(org.apache.samza.coordinator.JobModelManager) ContainerModel(org.apache.samza.job.model.ContainerModel) TaskName(org.apache.samza.container.TaskName) HttpServer(org.apache.samza.coordinator.server.HttpServer) JobModel(org.apache.samza.job.model.JobModel) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) TaskModel(org.apache.samza.job.model.TaskModel)

Example 7 with JobModel

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

the class TestContainerProcessManager method getCoordinator.

private JobModelManager getCoordinator(int containerCount) {
    Map<String, ContainerModel> containers = new java.util.HashMap<>();
    for (int i = 0; i < containerCount; i++) {
        ContainerModel container = new ContainerModel(String.valueOf(i), i, new HashMap<TaskName, TaskModel>());
        containers.put(String.valueOf(i), container);
    }
    Map<String, Map<String, String>> localityMap = new HashMap<>();
    localityMap.put("0", new HashMap<String, String>() {

        {
            put(SetContainerHostMapping.HOST_KEY, "abc");
        }
    });
    LocalityManager mockLocalityManager = mock(LocalityManager.class);
    when(mockLocalityManager.readContainerLocality()).thenReturn(localityMap);
    JobModel jobModel = new JobModel(getConfig(), containers, mockLocalityManager);
    JobModelManager.jobModelRef().getAndSet(jobModel);
    return new JobModelManager(jobModel, this.server, null);
}
Also used : HashMap(java.util.HashMap) JobModelManager(org.apache.samza.coordinator.JobModelManager) ContainerModel(org.apache.samza.job.model.ContainerModel) TaskName(org.apache.samza.container.TaskName) JobModel(org.apache.samza.job.model.JobModel) LocalityManager(org.apache.samza.container.LocalityManager) HashMap(java.util.HashMap) Map(java.util.Map) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) TaskModel(org.apache.samza.job.model.TaskModel)

Example 8 with JobModel

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

the class ZkJobCoordinator method onNewJobModelConfirmed.

@Override
public void onNewJobModelConfirmed(String version) {
    LOG.info("pid=" + processorId + "new version " + version + " of the job model got confirmed");
    // get the new Model
    JobModel jobModel = getJobModel();
    // start the container with the new model
    if (coordinatorListener != null) {
        coordinatorListener.onNewJobModel(processorId, jobModel);
    }
}
Also used : JobModel(org.apache.samza.job.model.JobModel)

Example 9 with JobModel

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

the class TestSamzaObjectMapper method testContainerModelCompatible.

/**
   * Critical test to guarantee compatibility between samza 0.12 container models and 0.13+
   *
   * Samza 0.12 contains only "container-id" (integer) in the ContainerModel. "processor-id" (String) is added in 0.13.
   * When serializing, we serialize both the fields in 0.13. Deserialization correctly handles the fields in 0.13.
   */
@Test
public void testContainerModelCompatible() {
    try {
        String newJobModelString = "{\"config\":{\"a\":\"b\"},\"containers\":{\"1\":{\"processor-id\":\"1\",\"container-id\":1,\"tasks\":{\"test\":{\"task-name\":\"test\",\"system-stream-partitions\":[{\"system\":\"foo\",\"partition\":1,\"stream\":\"bar\"}],\"changelog-partition\":2}}}},\"max-change-log-stream-partitions\":3,\"all-container-locality\":{\"1\":null}}";
        ObjectMapper mapper = SamzaObjectMapper.getObjectMapper();
        JobModel jobModel = mapper.readValue(newJobModelString, JobModel.class);
        String oldJobModelString = "{\"config\":{\"a\":\"b\"},\"containers\":{\"1\":{\"container-id\":1,\"tasks\":{\"test\":{\"task-name\":\"test\",\"system-stream-partitions\":[{\"system\":\"foo\",\"partition\":1,\"stream\":\"bar\"}],\"changelog-partition\":2}}}},\"max-change-log-stream-partitions\":3,\"all-container-locality\":{\"1\":null}}";
        ObjectMapper mapper1 = SamzaObjectMapper.getObjectMapper();
        JobModel jobModel1 = mapper1.readValue(oldJobModelString, JobModel.class);
        Assert.assertEquals(jobModel, jobModel1);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JobModel(org.apache.samza.job.model.JobModel) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with JobModel

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

the class TestSamzaObjectMapper method testJsonTaskModel.

@Test
public void testJsonTaskModel() throws Exception {
    ObjectMapper mapper = SamzaObjectMapper.getObjectMapper();
    String str = mapper.writeValueAsString(jobModel);
    JobModel obj = mapper.readValue(str, JobModel.class);
    assertEquals(jobModel, obj);
}
Also used : JobModel(org.apache.samza.job.model.JobModel) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Aggregations

JobModel (org.apache.samza.job.model.JobModel)16 ContainerModel (org.apache.samza.job.model.ContainerModel)8 HashMap (java.util.HashMap)6 TaskModel (org.apache.samza.job.model.TaskModel)6 TaskName (org.apache.samza.container.TaskName)5 MapConfig (org.apache.samza.config.MapConfig)4 Test (org.junit.Test)4 SamzaException (org.apache.samza.SamzaException)3 JobModelManager (org.apache.samza.coordinator.JobModelManager)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 IOException (java.io.IOException)2 Map (java.util.Map)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Config (org.apache.samza.config.Config)2 HttpServer (org.apache.samza.coordinator.server.HttpServer)2 DefaultServlet (org.eclipse.jetty.servlet.DefaultServlet)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1