use of com.google.api.services.analytics.model.UnsampledReport in project incubator-gobblin by apache.
the class GoogleAnalyticsUnsampledExtractorTest method testPollForCompletion.
public void testPollForCompletion() throws IOException {
wuState = new WorkUnitState();
wuState.setProp(POLL_RETRY_PREFIX + RETRY_TIME_OUT_MS, TimeUnit.SECONDS.toMillis(30L));
wuState.setProp(POLL_RETRY_PREFIX + RETRY_INTERVAL_MS, 1L);
GoogleAnalyticsUnsampledExtractor extractor = setup(ReportCreationStatus.COMPLETED, wuState, false);
UnsampledReport requestedReport = new UnsampledReport().setAccountId("testAccountId").setWebPropertyId("testWebPropertyId").setProfileId("testProfileId").setId("testId");
String actualFileId = extractor.pollForCompletion(wuState, gaService, requestedReport).getDriveDownloadDetails().getDocumentId();
Assert.assertEquals(actualFileId, EXPECTED_FILE_ID);
verify(getReq, atLeast(5)).execute();
}
use of com.google.api.services.analytics.model.UnsampledReport in project incubator-gobblin by apache.
the class GoogleAnalyticsUnsampledExtractor method prepareUnsampledReport.
/**
* Create unsampled report in Google drive and add google drive file id into state so that Google drive extractor
* can extract record from it. Also, update the state to use CsvFileDownloader unless other downloader is defined.
*
* It also register closer to delete the file from Google Drive unless explicitly requested to not deleting it.
* @return documentID of unsampled report in Google drive
* @throws IOException
*/
@VisibleForTesting
UnsampledReport prepareUnsampledReport(UnsampledReport request, final GoogleDriveFsHelper fsHelper, boolean isDeleteTempReport) throws IOException {
UnsampledReport createdReport = createUnsampledReports(request);
final String fileId = createdReport.getDriveDownloadDetails().getDocumentId();
LOG.info("Temporary unsampled report created in Google Drive: " + fileId);
if (isDeleteTempReport) {
closer.register(new Closeable() {
@Override
public void close() throws IOException {
LOG.info("Deleting created temporary unsampled report from Google drive " + fileId);
fsHelper.deleteFile(fileId);
}
});
} else {
LOG.warn("Temporary unsampled report will not be deleted as requested. File ID: " + fileId);
}
wuState.setProp(SOURCE_FILEBASED_FILES_TO_PULL, fileId);
if (!wuState.contains(SOURCE_FILEBASED_OPTIONAL_DOWNLOADER_CLASS)) {
wuState.setProp(SOURCE_FILEBASED_OPTIONAL_DOWNLOADER_CLASS, CsvFileDownloader.class.getName());
}
return createdReport;
}
use of com.google.api.services.analytics.model.UnsampledReport in project incubator-gobblin by apache.
the class GoogleAnalyticsUnsampledExtractor method pollForCompletion.
@VisibleForTesting
UnsampledReport pollForCompletion(State state, final Analytics gaService, final UnsampledReport requestedReport) throws IOException {
Config config = ConfigBuilder.create().loadProps(state.getProperties(), POLL_RETRY_PREFIX).build().withFallback(POLL_RETRY_DEFAULTS);
Retryer<UnsampledReport> retryer = RetryerFactory.newInstance(config);
LOG.info("Will poll for completion on unsampled report with retry config: " + config);
final Stopwatch stopwatch = Stopwatch.createStarted();
UnsampledReport result = null;
try {
result = retryer.call(new Callable<UnsampledReport>() {
@Override
public UnsampledReport call() throws Exception {
UnsampledReport response = null;
try {
response = gaService.management().unsampledReports().get(requestedReport.getAccountId(), requestedReport.getWebPropertyId(), requestedReport.getProfileId(), requestedReport.getId()).execute();
} catch (Exception e) {
LOG.warn("Encountered exception while polling for unsampled report. Will keep polling. " + "Elasped so far: " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds", e);
throw e;
}
ReportCreationStatus status = ReportCreationStatus.valueOf(response.getStatus());
switch(status) {
case FAILED:
// Stop retrying if it explicitly failed from server.
throw new NonTransientException("Unsampled report has failed to be generated. " + response);
case PENDING:
LOG.info("Waiting for report completion. Elasped so far: " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds for unsampled report: " + response);
// Throw so that Retryer will retry
throw new RuntimeException("Not completed yet. This will be retried. " + response);
case COMPLETED:
return response;
default:
throw new NonTransientException(status + " is not supported. " + response);
}
}
});
} catch (ExecutionException e) {
throw new IOException(e);
} catch (RetryException e) {
throw new RuntimeException(e);
}
LOG.info("Unsampled report creation has been completed. " + result);
Preconditions.checkArgument(DOWNLOAD_TYPE_GOOGLE_DRIVE.equals(result.getDownloadType()), result.getDownloadType() + " DownloadType is not supported.");
return result;
}
Aggregations