use of org.apache.gobblin.exception.NonTransientException in project incubator-gobblin by apache.
the class RetryWriterTest method retryTestNonTransientException.
public void retryTestNonTransientException() throws IOException {
DataWriter<Void> writer = mock(DataWriter.class);
doThrow(new NonTransientException()).when(writer).writeEnvelope(any(RecordEnvelope.class));
DataWriterWrapperBuilder<Void> builder = new DataWriterWrapperBuilder<>(writer, new State());
DataWriter<Void> retryWriter = builder.build();
try {
retryWriter.writeEnvelope(new RecordEnvelope<>(null));
Assert.fail("Should have failed.");
} catch (Exception e) {
}
verify(writer, atMost(1)).writeEnvelope(any(RecordEnvelope.class));
}
use of org.apache.gobblin.exception.NonTransientException 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 org.apache.gobblin.exception.NonTransientException in project incubator-gobblin by apache.
the class SalesforceRestWriter method onConnect.
/**
* Retrieve access token, if needed, retrieve instance url, and set server host URL
* {@inheritDoc}
* @see org.apache.gobblin.writer.http.HttpWriter#onConnect(org.apache.http.HttpHost)
*/
@Override
public void onConnect(URI serverHost) throws IOException {
if (!StringUtils.isEmpty(accessToken)) {
// No need to be called if accessToken is active.
return;
}
try {
getLog().info("Getting Oauth2 access token.");
OAuthClientRequest request = OAuthClientRequest.tokenLocation(serverHost.toString()).setGrantType(GrantType.PASSWORD).setClientId(clientId).setClientSecret(clientSecret).setUsername(userId).setPassword(password + securityToken).buildQueryMessage();
OAuthClient client = new OAuthClient(new URLConnectionClient());
OAuthJSONAccessTokenResponse response = client.accessToken(request, OAuth.HttpMethod.POST);
accessToken = response.getAccessToken();
setCurServerHost(new URI(response.getParam("instance_url")));
} catch (OAuthProblemException e) {
throw new NonTransientException("Error while authenticating with Oauth2", e);
} catch (OAuthSystemException e) {
throw new RuntimeException("Failed getting access token", e);
} catch (URISyntaxException e) {
throw new RuntimeException("Failed due to invalid instance url", e);
}
}
use of org.apache.gobblin.exception.NonTransientException 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 org.apache.gobblin.exception.NonTransientException 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