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