Search in sources :

Example 6 with SdxCreateFailedEvent

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

the class SdxValidationHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<SdxValidationRequest> event) {
    SdxValidationRequest request = event.getData();
    Long sdxId = request.getResourceId();
    String userId = request.getUserId();
    try {
        DetailedEnvironmentResponse environment = environmentService.waitNetworkAndGetEnvironment(sdxId);
        Optional<SdxCluster> sdxCluster = sdxClusterRepository.findById(sdxId);
        if (sdxCluster.isPresent()) {
            sdxRecommendationService.validateVmTypeOverride(environment, sdxCluster.get());
            return new SdxValidationSuccessEvent(sdxId, userId);
        } else {
            throw notFound("SDX cluster", sdxId).get();
        }
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Env polling exited before timeout. Cause: ", userBreakException);
        return new SdxCreateFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Env poller stopped for sdx: {}", sdxId, pollerStoppedException);
        return new SdxCreateFailedEvent(sdxId, userId, new PollerStoppedException("Env wait timed out after " + durationInMinutes + " minutes in sdx validation phase"));
    } catch (PollerException exception) {
        LOGGER.error("Env polling failed for sdx: {}", sdxId, exception);
        return new SdxCreateFailedEvent(sdxId, userId, exception);
    } catch (Exception e) {
        LOGGER.error("Sdx validation failed", e);
        return new SdxCreateFailedEvent(sdxId, userId, e);
    }
}
Also used : SdxValidationSuccessEvent(com.sequenceiq.datalake.flow.create.event.SdxValidationSuccessEvent) UserBreakException(com.dyngr.exception.UserBreakException) SdxValidationRequest(com.sequenceiq.datalake.flow.create.event.SdxValidationRequest) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) PollerStoppedException(com.dyngr.exception.PollerStoppedException) UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 7 with SdxCreateFailedEvent

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

the class StackCreationHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<StackCreationWaitRequest> handlerEvent) {
    StackCreationWaitRequest stackCreationWaitRequest = handlerEvent.getData();
    Long sdxId = stackCreationWaitRequest.getResourceId();
    String userId = stackCreationWaitRequest.getUserId();
    Selectable response;
    try {
        LOGGER.debug("start polling stack creation process for id: {}", sdxId);
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
        StackV4Response stackV4Response = provisionerService.waitCloudbreakClusterCreation(sdxId, pollingConfig);
        SdxCluster sdxCluster = sdxService.getById(sdxId);
        sdxService.updateRuntimeVersionFromStackResponse(sdxCluster, stackV4Response);
        setStackCreatedStatus(sdxId);
        response = new StackCreationSuccessEvent(sdxId, userId);
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Polling exited before timeout for SDX: {}. Cause: ", sdxId, userBreakException);
        response = new SdxCreateFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Poller stopped for SDX: {}", sdxId, pollerStoppedException);
        response = new SdxCreateFailedEvent(sdxId, userId, new PollerStoppedException("Datalake stack creation timed out after " + durationInMinutes + " minutes"));
    } catch (PollerException exception) {
        LOGGER.error("Polling failed for stack: {}", sdxId, exception);
        response = new SdxCreateFailedEvent(sdxId, userId, exception);
    } catch (Exception anotherException) {
        LOGGER.error("Something wrong happened in stack creation wait phase", anotherException);
        response = new SdxCreateFailedEvent(sdxId, userId, anotherException);
    }
    return response;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) StackCreationWaitRequest(com.sequenceiq.datalake.flow.create.event.StackCreationWaitRequest) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) StackCreationSuccessEvent(com.sequenceiq.datalake.flow.create.event.StackCreationSuccessEvent) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 8 with SdxCreateFailedEvent

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

the class StorageValidationHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<StorageValidationRequest> event) {
    StorageValidationRequest storageValidationRequest = event.getData();
    Long sdxId = storageValidationRequest.getResourceId();
    String userId = storageValidationRequest.getUserId();
    try {
        Optional<SdxCluster> sdxCluster = sdxClusterRepository.findById(sdxId);
        if (sdxCluster.isPresent()) {
            DetailedEnvironmentResponse env = environmentService.getDetailedEnvironmentResponseByName(sdxCluster.get().getEnvName());
            stackRequestManifester.configureStackForSdxCluster(sdxCluster.get(), env);
            return new StorageValidationSuccessEvent(sdxId, userId);
        } else {
            throw notFound("SDX cluster", sdxId).get();
        }
    } catch (Exception anotherException) {
        LOGGER.error("Something wrong happened in sdx storage validation phase", anotherException);
        return new SdxCreateFailedEvent(sdxId, userId, anotherException);
    }
}
Also used : SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) StorageValidationSuccessEvent(com.sequenceiq.datalake.flow.create.event.StorageValidationSuccessEvent) StorageValidationRequest(com.sequenceiq.datalake.flow.create.event.StorageValidationRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)

Example 9 with SdxCreateFailedEvent

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

the class StackCreationHandlerTest method acceptTestPollerStackTimeout.

@Test
void acceptTestPollerStackTimeout() {
    long stackId = 2L;
    StackCreationWaitRequest stackCreationWaitRequest = new StackCreationWaitRequest(stackId, userId);
    Event receivedEvent = new Event<>(stackCreationWaitRequest);
    doThrow(new PollerStoppedException("stack timeout")).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(PollerStoppedException.class, ((SdxCreateFailedEvent) event.getData()).getException().getClass());
}
Also used : StackCreationWaitRequest(com.sequenceiq.datalake.flow.create.event.StackCreationWaitRequest) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) 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) PollerStoppedException(com.dyngr.exception.PollerStoppedException) Test(org.junit.jupiter.api.Test)

Example 10 with SdxCreateFailedEvent

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

the class StackCreationHandlerTest method acceptTestPollerStackFailed.

@Test
void acceptTestPollerStackFailed() {
    long stackId = 2L;
    StackCreationWaitRequest stackCreationWaitRequest = new StackCreationWaitRequest(stackId, userId);
    Event receivedEvent = new Event<>(stackCreationWaitRequest);
    doThrow(new UserBreakException("stack failed")).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(UserBreakException.class, ((SdxCreateFailedEvent) event.getData()).getException().getClass());
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) StackCreationWaitRequest(com.sequenceiq.datalake.flow.create.event.StackCreationWaitRequest) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) 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)

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