Search in sources :

Example 1 with DriverState

use of org.apache.beam.runners.local.ExecutionDriver.DriverState in project beam by apache.

the class ExecutorServiceParallelExecutor method start.

@Override
// TODO: [BEAM-4563] Pass Future back to consumer to check for async errors
@SuppressWarnings("FutureReturnValueIgnored")
public void start(DirectGraph graph, RootProviderRegistry rootProviderRegistry) {
    int numTargetSplits = Math.max(3, targetParallelism);
    ImmutableMap.Builder<AppliedPTransform<?, ?, ?>, Queue<CommittedBundle<?>>> pendingRootBundles = ImmutableMap.builder();
    for (AppliedPTransform<?, ?, ?> root : graph.getRootTransforms()) {
        Queue<CommittedBundle<?>> pending = Queues.newArrayDeque();
        try {
            Collection<CommittedBundle<?>> initialInputs = rootProviderRegistry.getInitialInputs(root, numTargetSplits);
            pending.addAll(initialInputs);
        } catch (Exception e) {
            throw UserCodeException.wrap(e);
        }
        pendingRootBundles.put(root, pending);
    }
    evaluationContext.initialize(pendingRootBundles.build());
    final ExecutionDriver executionDriver = QuiescenceDriver.create(evaluationContext, graph, this, visibleUpdates, pendingRootBundles.build());
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            DriverState drive = executionDriver.drive();
            if (drive.isTermainal()) {
                State newPipelineState = State.UNKNOWN;
                switch(drive) {
                    case FAILED:
                        newPipelineState = State.FAILED;
                        break;
                    case SHUTDOWN:
                        newPipelineState = State.DONE;
                        break;
                    case CONTINUE:
                        throw new IllegalStateException(String.format("%s should not be a terminal state", DriverState.CONTINUE));
                    default:
                        throw new IllegalArgumentException(String.format("Unknown %s %s", DriverState.class.getSimpleName(), drive));
                }
                shutdownIfNecessary(newPipelineState);
            } else {
                executorService.submit(this);
            }
        }
    });
}
Also used : ImmutableMap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap) UserCodeException(org.apache.beam.sdk.util.UserCodeException) ExecutionDriver(org.apache.beam.runners.local.ExecutionDriver) AppliedPTransform(org.apache.beam.sdk.runners.AppliedPTransform) DriverState(org.apache.beam.runners.local.ExecutionDriver.DriverState) State(org.apache.beam.sdk.PipelineResult.State) DriverState(org.apache.beam.runners.local.ExecutionDriver.DriverState) BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Queue(java.util.Queue)

Aggregations

Queue (java.util.Queue)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ExecutionDriver (org.apache.beam.runners.local.ExecutionDriver)1 DriverState (org.apache.beam.runners.local.ExecutionDriver.DriverState)1 State (org.apache.beam.sdk.PipelineResult.State)1 AppliedPTransform (org.apache.beam.sdk.runners.AppliedPTransform)1 UserCodeException (org.apache.beam.sdk.util.UserCodeException)1 ImmutableMap (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap)1