Search in sources :

Example 1 with AttemptResult

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();
}
Also used : AttemptResult(com.dyngr.core.AttemptResult) DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) NotFoundException(javax.ws.rs.NotFoundException)

Example 2 with AttemptResult

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());
}
Also used : AttemptResult(com.dyngr.core.AttemptResult) Storage(com.google.api.services.storage.Storage) StorageObject(com.google.api.services.storage.model.StorageObject) RewriteResponse(com.google.api.services.storage.model.RewriteResponse) Test(org.junit.jupiter.api.Test)

Example 3 with AttemptResult

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());
}
Also used : AttemptResult(com.dyngr.core.AttemptResult) Storage(com.google.api.services.storage.Storage) StorageObject(com.google.api.services.storage.model.StorageObject) RewriteResponse(com.google.api.services.storage.model.RewriteResponse) Test(org.junit.jupiter.api.Test)

Example 4 with AttemptResult

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);
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) UpdateFailedException(com.sequenceiq.environment.exception.UpdateFailedException) Value(org.springframework.beans.factory.annotation.Value) AttemptResults(com.dyngr.core.AttemptResults) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) Service(org.springframework.stereotype.Service) PublicEndpointAccessGateway(com.sequenceiq.common.api.type.PublicEndpointAccessGateway) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) AttemptResult(com.dyngr.core.AttemptResult) FlowLogResponse(com.sequenceiq.flow.api.model.FlowLogResponse) SdxService(com.sequenceiq.environment.environment.service.sdx.SdxService) DatahubService(com.sequenceiq.environment.environment.service.datahub.DatahubService) PollingConfig(com.sequenceiq.environment.util.PollingConfig) Logger(org.slf4j.Logger) FlowEndpoint(com.sequenceiq.flow.api.FlowEndpoint) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Polling(com.dyngr.Polling) Stream(java.util.stream.Stream) StackService(com.sequenceiq.environment.environment.service.stack.StackService) PollerStoppedException(com.dyngr.exception.PollerStoppedException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) UpdateFailedException(com.sequenceiq.environment.exception.UpdateFailedException) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Aggregations

AttemptResult (com.dyngr.core.AttemptResult)4 Storage (com.google.api.services.storage.Storage)2 RewriteResponse (com.google.api.services.storage.model.RewriteResponse)2 StorageObject (com.google.api.services.storage.model.StorageObject)2 Test (org.junit.jupiter.api.Test)2 Polling (com.dyngr.Polling)1 AttemptResults (com.dyngr.core.AttemptResults)1 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)1 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)1 RegionAwareInternalCrnGeneratorFactory (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 PublicEndpointAccessGateway (com.sequenceiq.common.api.type.PublicEndpointAccessGateway)1 DatahubService (com.sequenceiq.environment.environment.service.datahub.DatahubService)1 SdxService (com.sequenceiq.environment.environment.service.sdx.SdxService)1 StackService (com.sequenceiq.environment.environment.service.stack.StackService)1 UpdateFailedException (com.sequenceiq.environment.exception.UpdateFailedException)1 PollingConfig (com.sequenceiq.environment.util.PollingConfig)1 FlowEndpoint (com.sequenceiq.flow.api.FlowEndpoint)1 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)1