use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project beam by apache.
the class DataflowRunner method getJobIdFromName.
/**
* Finds the id for the running job of the given name.
*/
private String getJobIdFromName(String jobName) {
try {
ListJobsResponse listResult;
String token = null;
do {
listResult = dataflowClient.listJobs(token);
token = listResult.getNextPageToken();
for (Job job : listResult.getJobs()) {
if (job.getName().equals(jobName) && MonitoringUtil.toState(job.getCurrentState()).equals(State.RUNNING)) {
return job.getId();
}
}
} while (token != null);
} catch (GoogleJsonResponseException e) {
throw new RuntimeException("Got error while looking up jobs: " + (e.getDetails() != null ? e.getDetails().getMessage() : e), e);
} catch (IOException e) {
throw new RuntimeException("Got error while looking up jobs: ", e);
}
throw new IllegalArgumentException("Could not find running job named " + jobName);
}
use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project beam by apache.
the class ExampleUtils method setup.
/**
* Sets up external resources that are required by the example, such as Pub/Sub topics and
* BigQuery tables.
*
* @throws IOException if there is a problem setting up the resources
*/
public void setup() throws IOException {
Sleeper sleeper = Sleeper.DEFAULT;
BackOff backOff = FluentBackoff.DEFAULT.withMaxRetries(3).withInitialBackoff(Duration.millis(200)).backoff();
Throwable lastException = null;
try {
do {
try {
setupPubsub();
setupBigQueryTable();
return;
} catch (GoogleJsonResponseException e) {
lastException = e;
}
} while (BackOffUtils.next(sleeper, backOff));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
// Ignore InterruptedException
}
throw new RuntimeException(lastException);
}
use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project druid by druid-io.
the class GoogleDataSegmentPullerTest method testDeleteOutputDirectoryWhenErrorIsRaisedPullingSegmentFiles.
@Test(expected = SegmentLoadingException.class)
public void testDeleteOutputDirectoryWhenErrorIsRaisedPullingSegmentFiles() throws IOException, SegmentLoadingException {
final File outDir = FileUtils.createTempDir();
try {
GoogleStorage storage = createMock(GoogleStorage.class);
final GoogleJsonResponseException exception = GoogleJsonResponseExceptionFactoryTesting.newMock(JacksonFactory.getDefaultInstance(), 300, "test");
EasyMock.expect(storage.get(EasyMock.eq(BUCKET), EasyMock.eq(PATH))).andThrow(exception);
replayAll();
GoogleDataSegmentPuller puller = new GoogleDataSegmentPuller(storage);
puller.getSegmentFiles(BUCKET, PATH, outDir);
Assert.assertFalse(outDir.exists());
verifyAll();
} finally {
FileUtils.deleteDirectory(outDir);
}
}
use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project druid by druid-io.
the class GoogleDataSegmentKillerTest method killWithErrorTest.
@Test(expected = SegmentLoadingException.class)
public void killWithErrorTest() throws SegmentLoadingException, IOException {
final GoogleJsonResponseException exception = GoogleJsonResponseExceptionFactoryTesting.newMock(JacksonFactory.getDefaultInstance(), 300, "test");
storage.delete(EasyMock.eq(BUCKET), EasyMock.eq(INDEX_PATH));
EasyMock.expectLastCall().andThrow(exception);
replayAll();
GoogleDataSegmentKiller killer = new GoogleDataSegmentKiller(storage, accountConfig, inputDataConfig);
killer.kill(DATA_SEGMENT);
verifyAll();
}
use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project platformlayer by platformlayer.
the class GoogleComputeClient method findInstanceByName.
public Instance findInstanceByName(String name) throws OpsException {
try {
log.debug("Retrieving instance by name: " + name);
Instance instance = compute.instances().get(projectId, name).execute();
return instance;
} catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == 404) {
return null;
}
throw new OpsException("Error getting instance", e);
} catch (IOException e) {
throw new OpsException("Error getting instance", e);
}
}
Aggregations