Search in sources :

Example 1 with SdxCreateFailedEvent

use of com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent in project cloudbreak by hortonworks.

the class RdsWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<RdsWaitRequest> event) {
    RdsWaitRequest rdsWaitRequest = event.getData();
    Long sdxId = rdsWaitRequest.getResourceId();
    String userId = rdsWaitRequest.getUserId();
    try {
        DetailedEnvironmentResponse env = environmentService.waitNetworkAndGetEnvironment(sdxId);
        Optional<SdxCluster> sdxCluster = sdxClusterRepository.findById(sdxId);
        if (sdxCluster.isPresent()) {
            if (sdxCluster.get().hasExternalDatabase()) {
                validForDatabaseCreation(sdxId, env);
                LOGGER.debug("start polling database for sdx: {}", sdxId);
                databaseService.create(sdxCluster.get(), env);
                setRdsCreatedStatus(sdxCluster.get());
                return new RdsWaitSuccessEvent(sdxId, userId);
            } else {
                LOGGER.debug("skipping creation of database for sdx: {}", sdxId);
                return new RdsWaitSuccessEvent(sdxId, userId);
            }
        } else {
            throw notFound("SDX cluster", sdxId).get();
        }
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Database polling exited before timeout. Cause: ", userBreakException);
        return new SdxCreateFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Database poller stopped for sdx: {}", sdxId, pollerStoppedException);
        return new SdxCreateFailedEvent(sdxId, userId, new PollerStoppedException("Database creation timed out after " + durationInMinutes + " minutes"));
    } catch (PollerException exception) {
        LOGGER.error("Database polling failed for sdx: {}", sdxId, exception);
        return new SdxCreateFailedEvent(sdxId, userId, exception);
    } catch (Exception anotherException) {
        LOGGER.error("Something wrong happened in sdx database creation wait phase", anotherException);
        return new SdxCreateFailedEvent(sdxId, userId, anotherException);
    }
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) RdsWaitSuccessEvent(com.sequenceiq.datalake.flow.create.event.RdsWaitSuccessEvent) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) RdsWaitRequest(com.sequenceiq.datalake.flow.create.event.RdsWaitRequest) PollerStoppedException(com.dyngr.exception.PollerStoppedException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 2 with SdxCreateFailedEvent

use of com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent in project cloudbreak by hortonworks.

the class EnvWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<EnvWaitRequest> event) {
    EnvWaitRequest envWaitRequest = event.getData();
    Long datalakeId = envWaitRequest.getResourceId();
    String userId = envWaitRequest.getUserId();
    Selectable response;
    try {
        LOGGER.debug("start polling env for sdx: {}", datalakeId);
        DetailedEnvironmentResponse detailedEnvironmentResponse = environmentService.waitAndGetEnvironment(datalakeId);
        response = new EnvWaitSuccessEvent(datalakeId, userId, detailedEnvironmentResponse);
        setEnvCreatedStatus(datalakeId);
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Env polling exited before timeout. Cause: ", userBreakException);
        response = new SdxCreateFailedEvent(datalakeId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Env poller stopped for sdx: {}", datalakeId, pollerStoppedException);
        response = new SdxCreateFailedEvent(datalakeId, userId, new PollerStoppedException("Env wait timed out after " + durationInMinutes + " minutes"));
    } catch (PollerException exception) {
        LOGGER.error("Env polling failed for sdx: {}", datalakeId, exception);
        response = new SdxCreateFailedEvent(datalakeId, userId, exception);
    } catch (Exception anotherException) {
        LOGGER.error("Something wrong happened in sdx creation wait phase", anotherException);
        response = new SdxCreateFailedEvent(datalakeId, userId, anotherException);
    }
    return response;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) EnvWaitRequest(com.sequenceiq.datalake.flow.create.event.EnvWaitRequest) EnvWaitSuccessEvent(com.sequenceiq.datalake.flow.create.event.EnvWaitSuccessEvent) PollerStoppedException(com.dyngr.exception.PollerStoppedException) UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 3 with SdxCreateFailedEvent

use of com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent in project cloudbreak by hortonworks.

the class SdxValidationHandlerTest method acceptTestValidationFailed.

@Test
public void acceptTestValidationFailed() {
    long sdxId = 1L;
    SdxValidationRequest sdxValidationRequest = new SdxValidationRequest(sdxId, userId);
    Event receivedEvent = new Event<>(sdxValidationRequest);
    DetailedEnvironmentResponse detailedEnvironmentResponse = new DetailedEnvironmentResponse();
    when(environmentService.waitNetworkAndGetEnvironment(eq(sdxId))).thenReturn(detailedEnvironmentResponse);
    SdxCluster sdxCluster = new SdxCluster();
    sdxCluster.setId(sdxId);
    when(sdxClusterRepository.findById(eq(sdxId))).thenReturn(Optional.of(sdxCluster));
    doThrow(new BadRequestException("validation failed")).when(sdxRecommendationService).validateVmTypeOverride(any(), any());
    underTest.accept(receivedEvent);
    final ArgumentCaptor<String> eventSelector = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<Event> sentEvent = ArgumentCaptor.forClass(Event.class);
    verify(eventBus, times(1)).notify(eventSelector.capture(), sentEvent.capture());
    String eventNotified = eventSelector.getValue();
    Event event = sentEvent.getValue();
    assertEquals("SdxCreateFailedEvent", eventNotified);
    assertEquals(SdxCreateFailedEvent.class, event.getData().getClass());
    assertEquals(sdxId, ((SdxCreateFailedEvent) event.getData()).getResourceId());
    assertEquals(BadRequestException.class, ((SdxCreateFailedEvent) event.getData()).getException().getClass());
    assertEquals("validation failed", ((SdxCreateFailedEvent) event.getData()).getException().getMessage());
}
Also used : SdxValidationRequest(com.sequenceiq.datalake.flow.create.event.SdxValidationRequest) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) Event(reactor.bus.Event) SdxValidationSuccessEvent(com.sequenceiq.datalake.flow.create.event.SdxValidationSuccessEvent) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 4 with SdxCreateFailedEvent

use of com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent in project cloudbreak by hortonworks.

the class StackCreationHandlerTest method acceptTestPollerStackOtherError.

@Test
void acceptTestPollerStackOtherError() {
    long stackId = 2L;
    StackCreationWaitRequest stackCreationWaitRequest = new StackCreationWaitRequest(stackId, userId);
    Event receivedEvent = new Event<>(stackCreationWaitRequest);
    doThrow(new PollerException("stack error")).when(provisionerService).waitCloudbreakClusterCreation(eq(stackId), any(PollingConfig.class));
    stackCreationHandler.accept(receivedEvent);
    verify(provisionerService, times(1)).waitCloudbreakClusterCreation(eq(stackId), any(PollingConfig.class));
    final ArgumentCaptor<String> eventSelector = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<Event> sentEvent = ArgumentCaptor.forClass(Event.class);
    verify(eventBus, times(1)).notify(eventSelector.capture(), sentEvent.capture());
    String eventNotified = eventSelector.getValue();
    Event event = sentEvent.getValue();
    Assertions.assertEquals("SdxCreateFailedEvent", eventNotified);
    Assertions.assertEquals(SdxCreateFailedEvent.class, event.getData().getClass());
    Assertions.assertEquals(stackId, ((SdxCreateFailedEvent) event.getData()).getResourceId());
    Assertions.assertEquals(PollerException.class, ((SdxCreateFailedEvent) event.getData()).getException().getClass());
}
Also used : StackCreationWaitRequest(com.sequenceiq.datalake.flow.create.event.StackCreationWaitRequest) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) PollerException(com.dyngr.exception.PollerException) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) Event(reactor.bus.Event) StackCreationSuccessEvent(com.sequenceiq.datalake.flow.create.event.StackCreationSuccessEvent) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) Test(org.junit.jupiter.api.Test)

Example 5 with SdxCreateFailedEvent

use of com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent in project cloudbreak by hortonworks.

the class SdxCreateActions method failedAction.

@Bean(name = "SDX_CREATION_FAILED_STATE")
public Action<?, ?> failedAction() {
    return new AbstractSdxAction<>(SdxCreateFailedEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxCreateFailedEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, SdxCreateFailedEvent payload, Map<Object, Object> variables) throws Exception {
            Exception exception = payload.getException();
            String statusReason = "Datalake creation failed";
            String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(exception);
            if (StringUtils.hasText(errorMessage)) {
                statusReason = statusReason + ". " + errorMessage;
            } else if (exception.getMessage() != null) {
                statusReason = statusReason + ". " + exception.getMessage();
            }
            LOGGER.error(statusReason, exception);
            try {
                SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.PROVISIONING_FAILED, statusReason, payload.getResourceId());
                metricService.incrementMetricCounter(MetricType.SDX_CREATION_FAILED, sdxCluster);
                eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_CREATION_FAILED);
            } catch (NotFoundException notFoundException) {
                LOGGER.info("Can not set status to SDX_CREATION_FAILED because data lake was not found");
            } catch (DatalakeStatusUpdateException datalakeStatusUpdateException) {
                LOGGER.info("Status update for data lake failed (possible reason: ongoing parallel deletion flow): {}", exception.getMessage());
            }
            Flow flow = getFlow(context.getFlowParameters().getFlowId());
            flow.setFlowFailed(payload.getException());
            sendEvent(context, SDX_CREATE_FAILED_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxCreateFailedEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Flow(com.sequenceiq.flow.core.Flow) FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

SdxCreateFailedEvent (com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent)10 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)6 PollerException (com.dyngr.exception.PollerException)5 PollerStoppedException (com.dyngr.exception.PollerStoppedException)5 UserBreakException (com.dyngr.exception.UserBreakException)5 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)5 StackCreationSuccessEvent (com.sequenceiq.datalake.flow.create.event.StackCreationSuccessEvent)4 StackCreationWaitRequest (com.sequenceiq.datalake.flow.create.event.StackCreationWaitRequest)4 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)4 Test (org.junit.jupiter.api.Test)4 Event (reactor.bus.Event)4 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 SdxValidationRequest (com.sequenceiq.datalake.flow.create.event.SdxValidationRequest)2 SdxValidationSuccessEvent (com.sequenceiq.datalake.flow.create.event.SdxValidationSuccessEvent)2 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 EnvWaitRequest (com.sequenceiq.datalake.flow.create.event.EnvWaitRequest)1 EnvWaitSuccessEvent (com.sequenceiq.datalake.flow.create.event.EnvWaitSuccessEvent)1