Search in sources :

Example 1 with SdxValidationSuccessEvent

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

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

SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)2 SdxCreateFailedEvent (com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent)2 SdxValidationRequest (com.sequenceiq.datalake.flow.create.event.SdxValidationRequest)2 SdxValidationSuccessEvent (com.sequenceiq.datalake.flow.create.event.SdxValidationSuccessEvent)2 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)2 PollerException (com.dyngr.exception.PollerException)1 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 UserBreakException (com.dyngr.exception.UserBreakException)1 Test (org.junit.jupiter.api.Test)1 Event (reactor.bus.Event)1