use of org.apache.samza.execution.LocalJobPlanner in project samza by apache.
the class TestLocalApplicationRunner method prepareTestForRunId.
private void prepareTestForRunId() throws Exception {
coordinationUtils = mock(CoordinationUtils.class);
DistributedLock lock = mock(DistributedLock.class);
when(lock.lock(anyObject())).thenReturn(true);
when(coordinationUtils.getLock(anyString())).thenReturn(lock);
clusterMembership = mock(ClusterMembership.class);
when(clusterMembership.getNumberOfProcessors()).thenReturn(1);
when(coordinationUtils.getClusterMembership()).thenReturn(clusterMembership);
metadataStore = mock(ZkMetadataStore.class);
when(metadataStore.get(any())).thenReturn(null);
PowerMockito.whenNew(ZkMetadataStore.class).withAnyArguments().thenReturn(metadataStore);
ApplicationDescriptorImpl<? extends ApplicationDescriptor> appDesc = ApplicationDescriptorUtil.getAppDescriptor(mockApp, config);
runner = spy(new LocalApplicationRunner(mockApp, config, coordinationUtils));
localPlanner = spy(new LocalJobPlanner(appDesc, coordinationUtils, "FAKE_UID", "FAKE_RUNID"));
doReturn(localPlanner).when(runner).getPlanner();
StreamProcessor sp = mock(StreamProcessor.class);
CoordinatorStreamStore coordinatorStreamStore = mock(CoordinatorStreamStore.class);
doReturn(sp).when(runner).createStreamProcessor(anyObject(), anyObject(), anyObject(), anyObject(), any(CoordinatorStreamStore.class));
doReturn(coordinatorStreamStore).when(runner).createCoordinatorStreamStore(any(Config.class));
}
use of org.apache.samza.execution.LocalJobPlanner in project samza by apache.
the class LocalApplicationRunner method getPlanner.
/**
* @return LocalJobPlanner created
*/
@VisibleForTesting
LocalJobPlanner getPlanner() {
boolean isAppModeBatch = new ApplicationConfig(appDesc.getConfig()).getAppMode() == ApplicationConfig.ApplicationMode.BATCH;
if (!isAppModeBatch) {
return new LocalJobPlanner(appDesc, PROCESSOR_ID);
}
CoordinationUtils coordinationUtils = this.coordinationUtils.orElse(null);
String runId = this.runId.orElse(null);
return new LocalJobPlanner(appDesc, coordinationUtils, PROCESSOR_ID, runId);
}
use of org.apache.samza.execution.LocalJobPlanner in project samza by apache.
the class LocalApplicationRunner method run.
@Override
public void run(ExternalContext externalContext) {
initializeRunId();
LocalJobPlanner planner = getPlanner();
try {
List<JobConfig> jobConfigs = planner.prepareJobs();
// create the StreamProcessors
if (jobConfigs.isEmpty()) {
throw new SamzaException("No jobs to run.");
}
jobConfigs.forEach(jobConfig -> {
LOG.debug("Starting job {} StreamProcessor with config {}", jobConfig.getName(), jobConfig);
MetadataStore coordinatorStreamStore = createCoordinatorStreamStore(jobConfig);
if (coordinatorStreamStore != null) {
coordinatorStreamStore.init();
}
StreamProcessor processor = createStreamProcessor(jobConfig, appDesc, sp -> new LocalStreamProcessorLifecycleListener(sp, jobConfig), Optional.ofNullable(externalContext), coordinatorStreamStore);
processors.add(Pair.of(processor, coordinatorStreamStore));
});
numProcessorsToStart.set(processors.size());
// start the StreamProcessors
processors.forEach(sp -> sp.getLeft().start());
} catch (Throwable throwable) {
cleanup();
appStatus = ApplicationStatus.unsuccessfulFinish(throwable);
shutdownLatch.countDown();
throw new SamzaException(String.format("Failed to start application: %s", new ApplicationConfig(appDesc.getConfig()).getGlobalAppId()), throwable);
}
}
use of org.apache.samza.execution.LocalJobPlanner in project samza by apache.
the class TestLocalApplicationRunner method prepareTest.
private void prepareTest() throws Exception {
CoordinationUtils coordinationUtils = mock(CoordinationUtils.class);
DistributedLock distributedLock = mock(DistributedLock.class);
when(distributedLock.lock(anyObject())).thenReturn(true);
when(coordinationUtils.getLock(anyString())).thenReturn(distributedLock);
ZkMetadataStore zkMetadataStore = mock(ZkMetadataStore.class);
when(zkMetadataStore.get(any())).thenReturn(null);
PowerMockito.whenNew(ZkMetadataStore.class).withAnyArguments().thenReturn(zkMetadataStore);
ApplicationDescriptorImpl<? extends ApplicationDescriptor> appDesc = ApplicationDescriptorUtil.getAppDescriptor(mockApp, config);
localPlanner = spy(new LocalJobPlanner(appDesc, coordinationUtils, "FAKE_UID", "FAKE_RUNID"));
runner = spy(new LocalApplicationRunner(mockApp, config, coordinationUtils));
doReturn(localPlanner).when(runner).getPlanner();
}
Aggregations