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());
}
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());
}
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);
}
};
}
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);
}
}
Aggregations