Skip to content
This repository has been archived by the owner on Nov 11, 2022. It is now read-only.

Forward-integrate: merge master into v2 #567

Merged
merged 30 commits into from
May 5, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
03bf9b7
Increase KafkaIO version to 0.2.0
Dec 14, 2016
8fd6661
Update version range dependency to exclude 2.0.0-betaX versions (#528)
davorbonaci Jan 9, 2017
faa4c2e
README.md for contrib/kafka
Jan 9, 2017
2829f00
README.md for contrib/kafka
Jan 9, 2017
3e61162
Fix formatting
Jan 9, 2017
40d174f
review comments
Jan 9, 2017
2e57ab1
Merge pull request #504 from rangadi/kafka_release_notes
dhalperi Jan 18, 2017
efd33cc
Fix HadoopFileSource’s split size estimate (#534)
igorbernstein2 Jan 26, 2017
dbe4644
BigQuery: fix an issue with option propagation and refactor to future…
dhalperi Jan 30, 2017
b4e391e
[BEAM-359] Treat erased type variables as non-deterministic in AvroCo…
ehlyzov Jan 30, 2017
502f99f
fixups
dhalperi Jan 30, 2017
2ea5a23
Fix InProcessPipelineRunner to handle a null subscription
sammcveety Feb 2, 2017
5625ffb
fixups
dhalperi Feb 6, 2017
9c59d78
fixups
dhalperi Feb 6, 2017
20862aa
Fixups
sammcveety Feb 11, 2017
d7a70fe
Fixups
sammcveety Feb 15, 2017
9b9ee0b
Merge pull request #547 from sammcveety/fix_pubsub_inprocess_null_topic
tgroh Feb 15, 2017
fc5fee2
Merge pull request #540 from dhalperi/bigquery-direct-standard-sql
dhalperi Feb 16, 2017
4a9f164
Small fix for BigtableIO.WriteOperation.finalize
gsgalloway Mar 1, 2017
c4bff0b
Merge pull request #555 from gsgalloway/patch-1
dhalperi Mar 2, 2017
4ede280
edited doc
anilmuppalla Apr 4, 2017
15cb364
Merge pull request #562 from anilmuppalla/master
dhalperi Apr 5, 2017
1cb04a6
DataflowPipelineJob: gracefully handle cancellatoin concurrent with t…
dhalperi Apr 7, 2017
67bfc90
Merge pull request #563 from dhalperi/cancel-double
dhalperi Apr 7, 2017
7cecf6e
Cache result of BigQuerySourceBase.split
jkff Apr 19, 2017
2a1627b
Merge pull request #564 from jkff/backport-2594
dhalperi Apr 19, 2017
52e593a
Makes cachedSplitResult transient in BigQuerySourceBase
jkff Apr 21, 2017
fed09e1
Merge pull request #565 from jkff/backport-2635
dhalperi Apr 21, 2017
f89d619
Fix a typo in Count.java
dhalperi Apr 28, 2017
56f542c
Forward-integrate: master to v2
davorbonaci May 5, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,35 @@ public void cancel() throws IOException {
content.setProjectId(projectId);
content.setId(jobId);
content.setRequestedState("JOB_STATE_CANCELLED");
dataflowClient.projects().jobs()
.update(projectId, jobId, content)
.execute();
try {
dataflowClient.projects().jobs()
.update(projectId, jobId, content)
.execute();
} catch (IOException e) {
State state = getState();
if (state.isTerminal()) {
LOG.warn("Cancel failed because job {} is already terminated in state {}.", jobId, 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.", jobId, e);
} 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(), getJobId()));
LOG.warn(errorMsg);
throw new IOException(errorMsg, e);
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -42,6 +43,7 @@
import com.google.api.services.dataflow.model.MetricUpdate;
import com.google.cloud.dataflow.sdk.PipelineResult.State;
import com.google.cloud.dataflow.sdk.runners.dataflow.DataflowAggregatorTransforms;
import com.google.cloud.dataflow.sdk.testing.ExpectedLogs;
import com.google.cloud.dataflow.sdk.testing.FastNanoClockAndSleeper;
import com.google.cloud.dataflow.sdk.transforms.Aggregator;
import com.google.cloud.dataflow.sdk.transforms.AppliedPTransform;
Expand Down Expand Up @@ -91,6 +93,9 @@ public class DataflowPipelineJobTest {
@Rule
public ExpectedException thrown = ExpectedException.none();

@Rule
public ExpectedLogs expectedLogs = ExpectedLogs.none(DataflowPipelineJob.class);

@Before
public void setup() {
MockitoAnnotations.initMocks(this);
Expand Down Expand Up @@ -193,6 +198,34 @@ public void testWaitToFinishCancelled() throws Exception {
assertEquals(State.CANCELLED, mockWaitToFinishInState(State.CANCELLED));
}

/**
* Test that {@link DataflowPipelineJob#cancel} doesn't throw if the Dataflow service returns
* non-terminal state even though the cancel API call failed, which can happen in practice.
*
* <p>TODO: delete this code if the API calls become consistent.
*/
@Test
public void testCancelTerminatedJobWithStaleState() throws IOException {
Dataflow.Projects.Jobs.Get statusRequest =
mock(Dataflow.Projects.Jobs.Get.class);

Job statusResponse = new Job();
statusResponse.setCurrentState("JOB_STATE_RUNNING");
when(mockJobs.get(PROJECT_ID, JOB_ID)).thenReturn(statusRequest);
when(statusRequest.execute()).thenReturn(statusResponse);

Dataflow.Projects.Jobs.Update update = mock(
Dataflow.Projects.Jobs.Update.class);
when(mockJobs.update(eq(PROJECT_ID), eq(JOB_ID), any(Job.class)))
.thenReturn(update);
when(update.execute()).thenThrow(new IOException("Job has terminated in state SUCCESS"));

DataflowPipelineJob job = new DataflowPipelineJob(
PROJECT_ID, JOB_ID, mockWorkflowClient, null);
job.cancel();
expectedLogs.verifyWarn("Cancel failed because job " + JOB_ID + " is already terminated.");
}

/**
* Tests that the {@link DataflowPipelineJob} understands that the {@link State#FAILED FAILED}
* state is terminal.
Expand Down