use of com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent in project cloudbreak by hortonworks.
the class RdsWaitHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<RdsWaitRequest> event) {
RdsWaitRequest rdsWaitRequest = event.getData();
Long sdxId = rdsWaitRequest.getResourceId();
String userId = rdsWaitRequest.getUserId();
try {
DetailedEnvironmentResponse env = environmentService.waitNetworkAndGetEnvironment(sdxId);
Optional<SdxCluster> sdxCluster = sdxClusterRepository.findById(sdxId);
if (sdxCluster.isPresent()) {
if (sdxCluster.get().hasExternalDatabase()) {
validForDatabaseCreation(sdxId, env);
LOGGER.debug("start polling database for sdx: {}", sdxId);
databaseService.create(sdxCluster.get(), env);
setRdsCreatedStatus(sdxCluster.get());
return new RdsWaitSuccessEvent(sdxId, userId);
} else {
LOGGER.debug("skipping creation of database for sdx: {}", sdxId);
return new RdsWaitSuccessEvent(sdxId, userId);
}
} else {
throw notFound("SDX cluster", sdxId).get();
}
} catch (UserBreakException userBreakException) {
LOGGER.error("Database polling exited before timeout. Cause: ", userBreakException);
return new SdxCreateFailedEvent(sdxId, userId, userBreakException);
} catch (PollerStoppedException pollerStoppedException) {
LOGGER.error("Database poller stopped for sdx: {}", sdxId, pollerStoppedException);
return new SdxCreateFailedEvent(sdxId, userId, new PollerStoppedException("Database creation timed out after " + durationInMinutes + " minutes"));
} catch (PollerException exception) {
LOGGER.error("Database polling failed for sdx: {}", sdxId, exception);
return new SdxCreateFailedEvent(sdxId, userId, exception);
} catch (Exception anotherException) {
LOGGER.error("Something wrong happened in sdx database creation wait phase", anotherException);
return new SdxCreateFailedEvent(sdxId, userId, anotherException);
}
}
use of com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent in project cloudbreak by hortonworks.
the class EnvWaitHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<EnvWaitRequest> event) {
EnvWaitRequest envWaitRequest = event.getData();
Long datalakeId = envWaitRequest.getResourceId();
String userId = envWaitRequest.getUserId();
Selectable response;
try {
LOGGER.debug("start polling env for sdx: {}", datalakeId);
DetailedEnvironmentResponse detailedEnvironmentResponse = environmentService.waitAndGetEnvironment(datalakeId);
response = new EnvWaitSuccessEvent(datalakeId, userId, detailedEnvironmentResponse);
setEnvCreatedStatus(datalakeId);
} catch (UserBreakException userBreakException) {
LOGGER.error("Env polling exited before timeout. Cause: ", userBreakException);
response = new SdxCreateFailedEvent(datalakeId, userId, userBreakException);
} catch (PollerStoppedException pollerStoppedException) {
LOGGER.error("Env poller stopped for sdx: {}", datalakeId, pollerStoppedException);
response = new SdxCreateFailedEvent(datalakeId, userId, new PollerStoppedException("Env wait timed out after " + durationInMinutes + " minutes"));
} catch (PollerException exception) {
LOGGER.error("Env polling failed for sdx: {}", datalakeId, exception);
response = new SdxCreateFailedEvent(datalakeId, userId, exception);
} catch (Exception anotherException) {
LOGGER.error("Something wrong happened in sdx creation wait phase", anotherException);
response = new SdxCreateFailedEvent(datalakeId, userId, anotherException);
}
return response;
}
use of com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent 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.SdxCreateFailedEvent in project cloudbreak by hortonworks.
the class StackCreationHandlerTest method acceptTestPollerStackOtherError.
@Test
void acceptTestPollerStackOtherError() {
long stackId = 2L;
StackCreationWaitRequest stackCreationWaitRequest = new StackCreationWaitRequest(stackId, userId);
Event receivedEvent = new Event<>(stackCreationWaitRequest);
doThrow(new PollerException("stack error")).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(PollerException.class, ((SdxCreateFailedEvent) event.getData()).getException().getClass());
}
use of com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent in project cloudbreak by hortonworks.
the class SdxCreateActions method failedAction.
@Bean(name = "SDX_CREATION_FAILED_STATE")
public Action<?, ?> failedAction() {
return new AbstractSdxAction<>(SdxCreateFailedEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxCreateFailedEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void doExecute(SdxContext context, SdxCreateFailedEvent payload, Map<Object, Object> variables) throws Exception {
Exception exception = payload.getException();
String statusReason = "Datalake creation failed";
String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(exception);
if (StringUtils.hasText(errorMessage)) {
statusReason = statusReason + ". " + errorMessage;
} else if (exception.getMessage() != null) {
statusReason = statusReason + ". " + exception.getMessage();
}
LOGGER.error(statusReason, exception);
try {
SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.PROVISIONING_FAILED, statusReason, payload.getResourceId());
metricService.incrementMetricCounter(MetricType.SDX_CREATION_FAILED, sdxCluster);
eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_CREATION_FAILED);
} catch (NotFoundException notFoundException) {
LOGGER.info("Can not set status to SDX_CREATION_FAILED because data lake was not found");
} catch (DatalakeStatusUpdateException datalakeStatusUpdateException) {
LOGGER.info("Status update for data lake failed (possible reason: ongoing parallel deletion flow): {}", exception.getMessage());
}
Flow flow = getFlow(context.getFlowParameters().getFlowId());
flow.setFlowFailed(payload.getException());
sendEvent(context, SDX_CREATE_FAILED_HANDLED_EVENT.event(), payload);
}
@Override
protected Object getFailurePayload(SdxCreateFailedEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return null;
}
};
}
Aggregations