Search in sources :

Example 61 with Job

use of com.google.api.services.dataflow.model.Job in project beam by apache.

the class DataflowPipelineTranslator method translate.

/**
 * Translates a {@link Pipeline} into a {@code JobSpecification}.
 */
public JobSpecification translate(Pipeline pipeline, RunnerApi.Pipeline pipelineProto, SdkComponents sdkComponents, DataflowRunner runner, List<DataflowPackage> packages) {
    Translator translator = new Translator(pipeline, runner, sdkComponents);
    Job result = translator.translate(packages);
    return new JobSpecification(result, pipelineProto, Collections.unmodifiableMap(translator.stepNames));
}
Also used : Job(com.google.api.services.dataflow.model.Job)

Example 62 with Job

use of com.google.api.services.dataflow.model.Job in project beam by apache.

the class DataflowPipelineJob method cancel.

@Override
public State cancel() throws IOException {
    // Enforce that a cancel() call on the job is done at most once - as
    // a workaround for Dataflow service's current bugs with multiple
    // cancellation, where it may sometimes return an error when cancelling
    // a job that was already cancelled, but still report the job state as
    // RUNNING.
    // To partially work around these issues, we absorb duplicate cancel()
    // calls. This, of course, doesn't address the case when the job terminates
    // externally almost concurrently to calling cancel(), but at least it
    // makes it possible to safely call cancel() multiple times and from
    // multiple threads in one program.
    FutureTask<State> tentativeCancelTask = new FutureTask<>(() -> {
        Job content = new Job();
        content.setProjectId(getProjectId());
        String currentJobId = getJobId();
        content.setId(currentJobId);
        content.setRequestedState("JOB_STATE_CANCELLED");
        try {
            Job job = dataflowClient.updateJob(currentJobId, content);
            return MonitoringUtil.toState(job.getCurrentState());
        } catch (IOException e) {
            State state = getState();
            if (state.isTerminal()) {
                LOG.warn("Cancel failed because job is already terminated. State is {}", state);
                return state;
            } else if (e.getMessage().contains("has terminated")) {
                // This handles the case where the getState() call above returns RUNNING but the
                // cancel was rejected because the job is in fact done. Hopefully, someday we can
                // delete this code if there is better consistency between the State and whether
                // Cancel succeeds.
                // 
                // Example message:
                // Workflow modification failed. Causes: (7603adc9e9bff51e): Cannot perform
                // operation 'cancel' on Job: 2017-04-01_22_50_59-9269855660514862348. Job has
                // terminated in state SUCCESS: Workflow job:
                // 2017-04-01_22_50_59-9269855660514862348 succeeded.
                LOG.warn("Cancel failed because job is already terminated.", e);
                return state;
            } else {
                String errorMsg = String.format("Failed to cancel job in state %s, " + "please go to the Developers Console to cancel it manually: %s", state, MonitoringUtil.getJobMonitoringPageURL(getProjectId(), getRegion(), getJobId()));
                LOG.warn(errorMsg);
                throw new IOException(errorMsg, e);
            }
        }
    });
    if (cancelState.compareAndSet(null, tentativeCancelTask)) {
        // This thread should perform cancellation, while others will
        // only wait for the result.
        cancelState.get().run();
    }
    try {
        return cancelState.get().get();
    } catch (InterruptedException | ExecutionException e) {
        throw new IOException(e);
    }
}
Also used : FutureTask(java.util.concurrent.FutureTask) IOException(java.io.IOException) Job(com.google.api.services.dataflow.model.Job) ExecutionException(java.util.concurrent.ExecutionException)

Example 63 with Job

use of com.google.api.services.dataflow.model.Job in project beam by apache.

the class DataflowPipelineJob method getStateWithRetries.

State getStateWithRetries(BackOff attempts, Sleeper sleeper) throws IOException {
    if (terminalState != null) {
        return terminalState;
    }
    Job job = getJobWithRetries(attempts, sleeper);
    latestStateString = job.getCurrentState();
    return MonitoringUtil.toState(latestStateString);
}
Also used : Job(com.google.api.services.dataflow.model.Job)

Aggregations

Job (com.google.api.services.dataflow.model.Job)63 Test (org.junit.Test)50 DataflowPipelineOptions (org.apache.beam.runners.dataflow.options.DataflowPipelineOptions)44 Pipeline (org.apache.beam.sdk.Pipeline)39 RunnerApi (org.apache.beam.model.pipeline.v1.RunnerApi)25 SdkComponents (org.apache.beam.runners.core.construction.SdkComponents)25 DataflowRunner.getContainerImageForJob (org.apache.beam.runners.dataflow.DataflowRunner.getContainerImageForJob)17 Structs.getString (org.apache.beam.runners.dataflow.util.Structs.getString)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 Step (com.google.api.services.dataflow.model.Step)13 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)12 Map (java.util.Map)11 TestPipeline (org.apache.beam.sdk.testing.TestPipeline)11 IOException (java.io.IOException)8 Dataflow (com.google.api.services.dataflow.Dataflow)7 DataflowPackage (com.google.api.services.dataflow.model.DataflowPackage)7 ArrayList (java.util.ArrayList)6 ListJobsResponse (com.google.api.services.dataflow.model.ListJobsResponse)5 List (java.util.List)5 ImmutableList (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList)5