Search in sources :

Example 41 with GoogleJsonResponseException

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);
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) ListJobsResponse(com.google.api.services.dataflow.model.ListJobsResponse) StringUtils.byteArrayToJsonString(org.apache.beam.sdk.util.StringUtils.byteArrayToJsonString) IOException(java.io.IOException) DataflowTemplateJob(org.apache.beam.runners.dataflow.util.DataflowTemplateJob) Job(com.google.api.services.dataflow.model.Job)

Example 42 with GoogleJsonResponseException

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);
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Sleeper(org.apache.beam.sdk.util.Sleeper) BackOff(org.apache.beam.sdk.util.BackOff)

Example 43 with GoogleJsonResponseException

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);
    }
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) File(java.io.File) Test(org.junit.Test)

Example 44 with GoogleJsonResponseException

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();
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Test(org.junit.Test)

Example 45 with GoogleJsonResponseException

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);
    }
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) OpsException(org.platformlayer.ops.OpsException) Instance(com.google.api.services.compute.model.Instance) IOException(java.io.IOException)

Aggregations

GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)90 IOException (java.io.IOException)45 YouTube (com.google.api.services.youtube.YouTube)26 Credential (com.google.api.client.auth.oauth2.Credential)25 Operation (com.google.api.services.compute.model.Operation)12 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 Compute (com.google.api.services.compute.Compute)11 Storage (com.google.api.services.storage.Storage)10 GcpResourceException (com.sequenceiq.cloudbreak.cloud.gcp.GcpResourceException)8 GcsOptions (org.apache.beam.sdk.extensions.gcp.options.GcsOptions)7 GoogleJsonError (com.google.api.client.googleapis.json.GoogleJsonError)5 InputStreamContent (com.google.api.client.http.InputStreamContent)5 BackOff (com.google.api.client.util.BackOff)5 HashMap (java.util.HashMap)5 Objects (com.google.api.services.storage.model.Objects)4 GoogleCloudStorage (com.google.cloud.hadoop.gcsio.GoogleCloudStorage)4 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)4 MediaHttpUploader (com.google.api.client.googleapis.media.MediaHttpUploader)3 MediaHttpUploaderProgressListener (com.google.api.client.googleapis.media.MediaHttpUploaderProgressListener)3