Search in sources :

Example 1 with LocalJobPlanner

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));
}
Also used : DistributedLock(org.apache.samza.coordinator.DistributedLock) StreamProcessor(org.apache.samza.processor.StreamProcessor) CoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore) ClusterMembership(org.apache.samza.coordinator.ClusterMembership) MapConfig(org.apache.samza.config.MapConfig) JobCoordinatorConfig(org.apache.samza.config.JobCoordinatorConfig) Config(org.apache.samza.config.Config) JobConfig(org.apache.samza.config.JobConfig) ApplicationConfig(org.apache.samza.config.ApplicationConfig) LocalJobPlanner(org.apache.samza.execution.LocalJobPlanner) ZkMetadataStore(org.apache.samza.zk.ZkMetadataStore) CoordinationUtils(org.apache.samza.coordinator.CoordinationUtils)

Example 2 with LocalJobPlanner

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);
}
Also used : ApplicationConfig(org.apache.samza.config.ApplicationConfig) LocalJobPlanner(org.apache.samza.execution.LocalJobPlanner) CoordinationUtils(org.apache.samza.coordinator.CoordinationUtils) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with LocalJobPlanner

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);
    }
}
Also used : MetadataStore(org.apache.samza.metadatastore.MetadataStore) StreamProcessor(org.apache.samza.processor.StreamProcessor) ApplicationConfig(org.apache.samza.config.ApplicationConfig) LocalJobPlanner(org.apache.samza.execution.LocalJobPlanner) SamzaException(org.apache.samza.SamzaException) JobConfig(org.apache.samza.config.JobConfig)

Example 4 with LocalJobPlanner

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();
}
Also used : DistributedLock(org.apache.samza.coordinator.DistributedLock) LocalJobPlanner(org.apache.samza.execution.LocalJobPlanner) ZkMetadataStore(org.apache.samza.zk.ZkMetadataStore) CoordinationUtils(org.apache.samza.coordinator.CoordinationUtils)

Aggregations

LocalJobPlanner (org.apache.samza.execution.LocalJobPlanner)4 ApplicationConfig (org.apache.samza.config.ApplicationConfig)3 CoordinationUtils (org.apache.samza.coordinator.CoordinationUtils)3 JobConfig (org.apache.samza.config.JobConfig)2 DistributedLock (org.apache.samza.coordinator.DistributedLock)2 StreamProcessor (org.apache.samza.processor.StreamProcessor)2 ZkMetadataStore (org.apache.samza.zk.ZkMetadataStore)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 SamzaException (org.apache.samza.SamzaException)1 Config (org.apache.samza.config.Config)1 JobCoordinatorConfig (org.apache.samza.config.JobCoordinatorConfig)1 MapConfig (org.apache.samza.config.MapConfig)1 ClusterMembership (org.apache.samza.coordinator.ClusterMembership)1 CoordinatorStreamStore (org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore)1 MetadataStore (org.apache.samza.metadatastore.MetadataStore)1