Example usage for com.google.api.client.googleapis.services AbstractGoogleClientRequest execute

List of usage examples for com.google.api.client.googleapis.services AbstractGoogleClientRequest execute

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.services AbstractGoogleClientRequest execute.

Prototype

public T execute() throws IOException 

Source Link

Document

Sends the metadata request to the server and returns the parsed metadata response.

Usage

From source file:ExampleUtils.java

License:Apache License

private static <T> T executeNullIfNotFound(AbstractGoogleClientRequest<T> request) throws IOException {
    try {//  w  w  w  .j  av a 2 s .  c o  m
        return request.execute();
    } catch (GoogleJsonResponseException e) {
        if (e.getStatusCode() == SC_NOT_FOUND) {
            return null;
        } else {
            throw e;
        }
    }
}

From source file:$.DataflowExampleUtils.java

License:Apache License

private static <T> T executeNullIfNotFound(AbstractGoogleClientRequest<T> request) throws IOException {
        try {//from  www.  jav  a2  s . c o m
            return request.execute();
        } catch (GoogleJsonResponseException e) {
            if (e.getStatusCode() == HttpServletResponse.SC_NOT_FOUND) {
                return null;
            } else {
                throw e;
            }
        }
    }

From source file:$.ExampleUtils.java

License:Apache License

private static <T> T executeNullIfNotFound(AbstractGoogleClientRequest<T> request) throws IOException {
        try {//from ww w.jav  a2  s .c o m
            return request.execute();
        } catch (GoogleJsonResponseException e) {
            if (e.getStatusCode() == SC_NOT_FOUND) {
                return null;
            } else {
                throw e;
            }
        }
    }

From source file:com.acacia.angleddream.common.DataflowUtils.java

License:Apache License

private static <T> T executeNullIfNotFound(AbstractGoogleClientRequest<T> request) throws IOException {
    try {/*from  w w  w.jav  a2  s  .c om*/
        return request.execute();
    } catch (GoogleJsonResponseException e) {
        if (e.getStatusCode() == HttpServletResponse.SC_NOT_FOUND) {
            return null;
        } else {
            throw e;
        }
    }
}

From source file:com.google.cloud.dataflow.sdk.util.BigQueryServicesImpl.java

License:Apache License

@VisibleForTesting
static <T> T executeWithRetries(AbstractGoogleClientRequest<T> request, String errorMessage, Sleeper sleeper,
        BackOff backoff) throws IOException, InterruptedException {
    Exception lastException = null;
    do {/* w  w  w  .  j  a  v a  2 s.  c  om*/
        try {
            return request.execute();
        } catch (IOException e) {
            LOG.warn("Ignore the error and retry the request.", e);
            lastException = e;
        }
    } while (nextBackOff(sleeper, backoff));
    throw new IOException(errorMessage, lastException);
}

From source file:com.google.cloud.dataflow.sdk.util.BigQueryTableRowIterator.java

License:Apache License

public static <T> T executeWithBackOff(AbstractGoogleClientRequest<T> client, String error, Object... errorArgs)
        throws IOException, InterruptedException {
    Sleeper sleeper = Sleeper.DEFAULT;/*from www  .j  a va  2  s  . c  o  m*/
    BackOff backOff = new AttemptBoundedExponentialBackOff(MAX_RETRIES, INITIAL_BACKOFF_TIME.getMillis());

    T result = null;
    while (true) {
        try {
            result = client.execute();
            break;
        } catch (IOException e) {
            LOG.error(String.format(error, errorArgs), e.getMessage());
            if (!BackOffUtils.next(sleeper, backOff)) {
                LOG.error(String.format(error, errorArgs), "Failing after retrying " + MAX_RETRIES + " times.");
                throw e;
            }
        }
    }

    return result;
}

From source file:org.apache.beam.sdk.io.gcp.bigquery.BigQueryServicesImpl.java

License:Apache License

@VisibleForTesting
static <T> T executeWithRetries(AbstractGoogleClientRequest<T> request, String errorMessage, Sleeper sleeper,
        BackOff backoff, SerializableFunction<IOException, Boolean> shouldRetry)
        throws IOException, InterruptedException {
    Exception lastException = null;
    do {/*from   w ww .j a  v  a 2  s  .co m*/
        try {
            return request.execute();
        } catch (IOException e) {
            lastException = e;
            if (!shouldRetry.apply(e)) {
                break;
            }
            LOG.info("Ignore the error and retry the request.", e);
        }
    } while (nextBackOff(sleeper, backoff));
    throw new IOException(errorMessage, lastException);
}

From source file:org.apache.beam.sdk.io.gcp.bigquery.BigQueryTableRowIterator.java

License:Apache License

private static <T> T executeWithBackOff(AbstractGoogleClientRequest<T> client, String error)
        throws IOException, InterruptedException {
    Sleeper sleeper = Sleeper.DEFAULT;/*from   w w w .  jav  a2s.c o  m*/
    BackOff backOff = FluentBackoff.DEFAULT.withMaxRetries(MAX_RETRIES).withInitialBackoff(INITIAL_BACKOFF_TIME)
            .backoff();

    T result = null;
    while (true) {
        try {
            result = client.execute();
            break;
        } catch (IOException e) {
            LOG.error("{}", error, e);
            if (!BackOffUtils.next(sleeper, backOff)) {
                String errorMessage = String.format("%s Failing to execute job after %d attempts.", error,
                        MAX_RETRIES + 1);
                LOG.error("{}", errorMessage, e);
                throw new IOException(errorMessage, e);
            }
        }
    }
    return result;
}

From source file:org.apache.beam.sdk.io.gcp.bigquery.PatchedBigQueryTableRowIterator.java

License:Apache License

public static <T> T executeWithBackOff(AbstractGoogleClientRequest<T> client, String error)
        throws IOException, InterruptedException {
    Sleeper sleeper = Sleeper.DEFAULT;/*from w w w .  j  a v  a2s.c om*/
    BackOff backOff = BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.withMaxRetries(MAX_RETRIES)
            .withInitialBackoff(INITIAL_BACKOFF_TIME).backoff());

    T result = null;
    while (true) {
        try {
            result = client.execute();
            break;
        } catch (IOException e) {
            LOG.error("{}", error, e);
            if (!BackOffUtils.next(sleeper, backOff)) {
                String errorMessage = String.format("%s Failing to execute job after %d attempts.", error,
                        MAX_RETRIES + 1);
                LOG.error("{}", errorMessage, e);
                throw new IOException(errorMessage, e);
            }
        }
    }
    return result;
}

From source file:org.apache.camel.component.google.calendar.GoogleCalendarConsumer.java

License:Apache License

@Override
protected Object doInvokeMethod(Map<String, Object> properties) throws RuntimeCamelException {
    AbstractGoogleClientRequest request = (AbstractGoogleClientRequest) super.doInvokeMethod(properties);
    try {//  ww  w.  j  a  v  a2s.c  o  m
        TypeConverter typeConverter = getEndpoint().getCamelContext().getTypeConverter();
        for (Entry<String, Object> p : properties.entrySet()) {
            IntrospectionSupport.setProperty(typeConverter, request, p.getKey(), p.getValue());
        }
        return request.execute();
    } catch (Exception e) {
        throw new RuntimeCamelException(e);
    }
}