use of com.google.api.services.analytics.model.UnsampledReport in project incubator-gobblin by apache.
the class GoogleAnalyticsUnsampledExtractorTest method testPollForCompletionWithException.
public void testPollForCompletionWithException() 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, true);
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 GoogleAnalyticsUnsampledExtractorTest method testPollForCompletionFailure.
public void testPollForCompletionFailure() 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.FAILED, wuState, false);
UnsampledReport requestedReport = new UnsampledReport().setAccountId("testAccountId").setWebPropertyId("testWebPropertyId").setProfileId("testProfileId").setId("testId");
try {
extractor.pollForCompletion(wuState, gaService, requestedReport);
Assert.fail("Should have failed with failed status");
} catch (Exception e) {
Assert.assertTrue(e.getCause().getCause() instanceof NonTransientException);
}
verify(getReq, atLeast(5)).execute();
}
use of com.google.api.services.analytics.model.UnsampledReport 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);
}
}
use of com.google.api.services.analytics.model.UnsampledReport in project incubator-gobblin by apache.
the class GoogleAnalyticsUnsampledExtractor method createUnsampledReports.
@VisibleForTesting
UnsampledReport createUnsampledReports(UnsampledReport request) throws IOException {
long startTimeInMillis = System.currentTimeMillis();
try {
UnsampledReport requestedReport = requestUnsampledReport(request);
UnsampledReport createdReport = pollForCompletion(wuState, gaService, requestedReport);
createdReport.setEndDate(requestedReport.getEndDate());
return createdReport;
} finally {
long delta = System.currentTimeMillis() - startTimeInMillis;
if (GobblinMetrics.isEnabled(wuState)) {
Timer timer = Instrumented.getMetricContext(wuState, getClass()).timer(GA_UNSAMPLED_REPORT_CREATION_TIMER);
Instrumented.updateTimer(Optional.of(timer), delta, TimeUnit.MILLISECONDS);
}
}
}
use of com.google.api.services.analytics.model.UnsampledReport in project incubator-gobblin by apache.
the class GoogleAnalyticsUnsampledExtractorTest method setup.
private GoogleAnalyticsUnsampledExtractor setup(final ReportCreationStatus status, WorkUnitState wuState, final boolean throwException) throws IOException {
Extractor actualExtractor = mock(Extractor.class);
gaService = mock(Analytics.class);
Management mgmt = mock(Management.class);
when(gaService.management()).thenReturn(mgmt);
UnsampledReports req = mock(UnsampledReports.class);
when(mgmt.unsampledReports()).thenReturn(req);
getReq = mock(Get.class);
when(req.get(anyString(), anyString(), anyString(), anyString())).thenReturn(getReq);
int pollCount = 10;
final MutableInt countDown = new MutableInt(pollCount);
when(getReq.execute()).then(new Answer<UnsampledReport>() {
@Override
public UnsampledReport answer(InvocationOnMock invocation) throws Throwable {
countDown.decrement();
if (countDown.intValue() == 0) {
UnsampledReport response = new UnsampledReport();
DriveDownloadDetails details = new DriveDownloadDetails();
details.setDocumentId(EXPECTED_FILE_ID);
response.setStatus(status.name()).setDownloadType(DOWNLOAD_TYPE_GOOGLE_DRIVE).setDriveDownloadDetails(details);
return response;
} else if (throwException) {
throw new RuntimeException("Dummy exception.");
}
return new UnsampledReport();
}
});
return new GoogleAnalyticsUnsampledExtractor<>(wuState, actualExtractor, gaService);
}
Aggregations