Search in sources :

Example 1 with SdxValidationRequest

use of com.sequenceiq.datalake.flow.create.event.SdxValidationRequest 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 2 with SdxValidationRequest

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

the class SdxValidationHandlerTest method acceptTestValidationSucceeded.

@Test
public void acceptTestValidationSucceeded() {
    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));
    underTest.accept(receivedEvent);
    verify(sdxRecommendationService, times(1)).validateVmTypeOverride(eq(detailedEnvironmentResponse), eq(sdxCluster));
    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("SdxValidationSuccessEvent", eventNotified);
    assertEquals(SdxValidationSuccessEvent.class, event.getData().getClass());
    assertEquals(sdxId, ((SdxValidationSuccessEvent) event.getData()).getResourceId());
}
Also used : SdxValidationRequest(com.sequenceiq.datalake.flow.create.event.SdxValidationRequest) 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) Test(org.junit.jupiter.api.Test)

Example 3 with SdxValidationRequest

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

the class SdxCreateActions method sdxValidation.

@Bean(name = "SDX_CREATION_VALIDATION_STATE")
public Action<?, ?> sdxValidation() {
    return new AbstractSdxAction<>(SdxEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) throws Exception {
            setCorrectSdxIdIfNecessary(context, payload);
            eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_PROVISION_STARTED);
            SdxValidationRequest req = new SdxValidationRequest(context);
            sendEvent(context, req.selector(), req);
        }

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

Example 4 with SdxValidationRequest

use of com.sequenceiq.datalake.flow.create.event.SdxValidationRequest 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)

Aggregations

SdxValidationRequest (com.sequenceiq.datalake.flow.create.event.SdxValidationRequest)4 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)3 SdxCreateFailedEvent (com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent)3 SdxValidationSuccessEvent (com.sequenceiq.datalake.flow.create.event.SdxValidationSuccessEvent)3 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)3 Test (org.junit.jupiter.api.Test)2 Event (reactor.bus.Event)2 PollerException (com.dyngr.exception.PollerException)1 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 UserBreakException (com.dyngr.exception.UserBreakException)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)1 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)1 DatalakeStatusUpdateException (com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Bean (org.springframework.context.annotation.Bean)1