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);
}
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);
}
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);
}
}
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();
}
}
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);
}
Aggregations