Search in sources :

Example 1 with Insert

use of com.google.api.services.analytics.Analytics.Management.UnsampledReports.Insert in project incubator-gobblin by apache.

the class GoogleAnalyticsUnsampledExtractor method requestUnsampledReport.

@VisibleForTesting
UnsampledReport requestUnsampledReport(UnsampledReport request) throws IOException {
    String accountId = request.getAccountId();
    String webPropertyId = request.getWebPropertyId();
    String profileId = request.getProfileId();
    // GA somehow does not allow these values in it.
    request.setAccountId(null).setWebPropertyId(null).setProfileId(null);
    final String endDate = request.getEndDate();
    final Insert insertRequest = gaService.management().unsampledReports().insert(accountId, webPropertyId, profileId, request);
    Config config = ConfigBuilder.create().loadProps(wuState.getProperties(), REQUEST_RETRY_PREFIX).build();
    Retryer<UnsampledReport> retryer = RetryerFactory.newInstance(config);
    LOG.info("Requesting to create unsampled report " + request);
    try {
        return retryer.call(new Callable<UnsampledReport>() {

            @Override
            public UnsampledReport call() throws Exception {
                UnsampledReport response = insertRequest.execute();
                if (ReportCreationStatus.FAILED.name().equals(response.getStatus())) {
                    // No retry if it's explicitly failed from server
                    throw new NonTransientException("Failed to create unsampled report " + response);
                }
                // response does not have end date where we need it later for next watermark calculation.
                response.setEndDate(endDate);
                return response;
            }
        });
    } catch (ExecutionException e) {
        throw new IOException(e);
    } catch (RetryException e) {
        throw new RuntimeException(e);
    }
}
Also used : NonTransientException(org.apache.gobblin.exception.NonTransientException) Config(com.typesafe.config.Config) IOException(java.io.IOException) Insert(com.google.api.services.analytics.Analytics.Management.UnsampledReports.Insert) RetryException(com.github.rholder.retry.RetryException) NonTransientException(org.apache.gobblin.exception.NonTransientException) RetryException(com.github.rholder.retry.RetryException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) DataRecordException(org.apache.gobblin.source.extractor.DataRecordException) ExecutionException(java.util.concurrent.ExecutionException) UnsampledReport(com.google.api.services.analytics.model.UnsampledReport) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

RetryException (com.github.rholder.retry.RetryException)1 Insert (com.google.api.services.analytics.Analytics.Management.UnsampledReports.Insert)1 UnsampledReport (com.google.api.services.analytics.model.UnsampledReport)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Config (com.typesafe.config.Config)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 NonTransientException (org.apache.gobblin.exception.NonTransientException)1 DataRecordException (org.apache.gobblin.source.extractor.DataRecordException)1