use of com.dyngr.core.AttemptResult in project cloudbreak by hortonworks.
the class DatabaseObtainerService method obtainAttemptResult.
AttemptResult<Object> obtainAttemptResult(Cluster cluster, DatabaseOperation databaseOperation, String databaseCrn, boolean cancellable) throws JsonProcessingException {
Optional<AttemptResult<Object>> result = Optional.ofNullable(clusterPollingCheckerService.checkClusterCancelledState(cluster, cancellable));
if (result.isEmpty()) {
checkArgument(cluster != null, "Cluster must not be null");
try {
LOGGER.info("Polling redbeams for database status: '{}'", cluster.getName());
DatabaseServerV4Response rdsStatus = redbeamsClient.getByCrn(databaseCrn);
LOGGER.info("Response from redbeams: {}", JsonUtil.writeValueAsString(rdsStatus));
result = Optional.of(databaseCriteriaResolver.resolveResultByCriteria(databaseOperation, rdsStatus, cluster));
} catch (CloudbreakServiceException e) {
if (e.getCause() instanceof NotFoundException) {
LOGGER.info("Not found returned for database crn: {}", databaseCrn);
result = Optional.of(AttemptResults.finishWith(null));
} else {
throw e;
}
} catch (NotFoundException e) {
LOGGER.info("Not found returned for database crn: {}", databaseCrn);
result = Optional.of(AttemptResults.finishWith(null));
}
}
return result.get();
}
use of com.dyngr.core.AttemptResult in project cloudbreak by hortonworks.
the class GcpImageAttemptMakerTest method testProcessWhenFinishedSuccess.
@Test
public void testProcessWhenFinishedSuccess() throws Exception {
Storage.Objects objects = mock(Storage.Objects.class);
Storage.Objects.Rewrite rewrite = mock(Storage.Objects.Rewrite.class);
RewriteResponse rewriteResponse = mock(RewriteResponse.class);
when(storage.objects()).thenReturn(objects);
when(objects.rewrite(anyString(), anyString(), anyString(), anyString(), any(StorageObject.class))).thenReturn(rewrite);
when(rewrite.execute()).thenReturn(rewriteResponse);
when(rewriteResponse.getRewriteToken()).thenReturn("token");
when(rewriteResponse.getTotalBytesRewritten()).thenReturn(1L);
when(rewriteResponse.getObjectSize()).thenReturn(1L);
when(rewriteResponse.getDone()).thenReturn(true);
AttemptResult process = underTest.process();
Assert.assertEquals("token", underTest.getRewriteToken());
Assert.assertEquals(AttemptState.FINISH, process.getState());
}
use of com.dyngr.core.AttemptResult in project cloudbreak by hortonworks.
the class GcpImageAttemptMakerTest method testProcessWhenContinue.
@Test
public void testProcessWhenContinue() throws Exception {
Storage.Objects objects = mock(Storage.Objects.class);
Storage.Objects.Rewrite rewrite = mock(Storage.Objects.Rewrite.class);
RewriteResponse rewriteResponse = mock(RewriteResponse.class);
when(storage.objects()).thenReturn(objects);
when(objects.rewrite(anyString(), anyString(), anyString(), anyString(), any(StorageObject.class))).thenReturn(rewrite);
when(rewrite.execute()).thenReturn(rewriteResponse);
when(rewriteResponse.getRewriteToken()).thenReturn("token");
when(rewriteResponse.getTotalBytesRewritten()).thenReturn(1L);
when(rewriteResponse.getObjectSize()).thenReturn(1L);
when(rewriteResponse.getDone()).thenReturn(false);
AttemptResult process = underTest.process();
Assert.assertEquals("token", underTest.getRewriteToken());
Assert.assertEquals(AttemptState.CONTINUE, process.getState());
}
use of com.dyngr.core.AttemptResult in project cloudbreak by hortonworks.
the class LoadBalancerPollerService method periodicCheckForCompletion.
private AttemptResult<List<FlowIdentifier>> periodicCheckForCompletion(List<FlowIdentifier> flowIdentifiers) {
try {
boolean anyFlowsActive = false;
for (FlowIdentifier flowIdentifier : flowIdentifiers) {
Boolean hasActiveFlow = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> flowEndpoint.hasFlowRunningByFlowId(flowIdentifier.getPollableId()).getHasActiveFlow());
if (hasActiveFlow) {
LOGGER.debug("Flow {} is still running", flowIdentifier.getPollableId());
} else {
LOGGER.debug("Flow {} is complete", flowIdentifier.getPollableId());
}
anyFlowsActive = anyFlowsActive || hasActiveFlow;
}
if (anyFlowsActive) {
return AttemptResults.justContinue();
} else {
List<FlowIdentifier> failedFlows = flowIdentifiers.stream().filter(flowId -> hasFlowFailed(ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> flowEndpoint.getFlowLogsByFlowId(flowId.getPollableId())))).collect(Collectors.toList());
return AttemptResults.finishWith(failedFlows);
}
} catch (Exception e) {
LOGGER.warn("Failure checking status of flows {}, error is: {}", flowIdentifiers, e.getMessage());
return AttemptResults.breakFor(e);
}
}
Aggregations