use of com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent in project cloudbreak by hortonworks.
the class RdsDeletionHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<RdsDeletionWaitRequest> event) {
RdsDeletionWaitRequest rdsWaitRequest = event.getData();
Long sdxId = rdsWaitRequest.getResourceId();
String userId = rdsWaitRequest.getUserId();
Selectable response;
try {
sdxClusterRepository.findById(sdxId).ifPresent(sdxCluster -> {
if (sdxCluster.hasExternalDatabase() && StringUtils.isNotEmpty(sdxCluster.getDatabaseCrn())) {
LOGGER.debug("start polling database termination for sdx: {}", sdxId);
databaseService.terminate(sdxCluster, rdsWaitRequest.isForced());
} else {
LOGGER.debug("skipping deletion of database for sdx: {}", sdxId);
}
setDeletedStatus(sdxCluster);
});
response = new RdsDeletionSuccessEvent(sdxId, userId);
} catch (UserBreakException userBreakException) {
LOGGER.error("Database polling exited before timeout. Cause: ", userBreakException);
response = new SdxDeletionFailedEvent(sdxId, userId, userBreakException, rdsWaitRequest.isForced());
} catch (PollerStoppedException pollerStoppedException) {
LOGGER.error("Database poller stopped for sdx: {}", sdxId, pollerStoppedException);
response = new SdxDeletionFailedEvent(sdxId, userId, new PollerStoppedException("Database deletion timed out after " + durationInMinutes + " minutes"), rdsWaitRequest.isForced());
} catch (PollerException exception) {
LOGGER.error("Database polling failed for sdx: {}", sdxId, exception);
response = new SdxDeletionFailedEvent(sdxId, userId, exception, rdsWaitRequest.isForced());
} catch (Exception anotherException) {
LOGGER.error("Something wrong happened in sdx database deletion wait phase", anotherException);
response = new SdxDeletionFailedEvent(sdxId, userId, anotherException, rdsWaitRequest.isForced());
}
return response;
}
use of com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent in project cloudbreak by hortonworks.
the class StackDeletionHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<StackDeletionWaitRequest> event) {
StackDeletionWaitRequest stackDeletionWaitRequest = event.getData();
Long sdxId = stackDeletionWaitRequest.getResourceId();
String userId = stackDeletionWaitRequest.getUserId();
Selectable response;
try {
LOGGER.debug("Start polling stack deletion process for id: {}", sdxId);
PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
provisionerService.waitCloudbreakClusterDeletion(sdxId, pollingConfig);
response = new StackDeletionSuccessEvent(sdxId, userId, stackDeletionWaitRequest.isForced());
} catch (UserBreakException userBreakException) {
LOGGER.error("Deletion polling exited before timeout. Cause: ", userBreakException);
response = new SdxDeletionFailedEvent(sdxId, userId, userBreakException, stackDeletionWaitRequest.isForced());
} catch (PollerStoppedException pollerStoppedException) {
LOGGER.error("Deletion poller stopped for stack: {}", sdxId);
response = new SdxDeletionFailedEvent(sdxId, userId, new PollerStoppedException("Datalake stack deletion timed out after " + durationInMinutes + " minutes"), stackDeletionWaitRequest.isForced());
} catch (PollerException exception) {
LOGGER.error("Deletion polling failed for stack: {}", sdxId);
response = new SdxDeletionFailedEvent(sdxId, userId, exception, stackDeletionWaitRequest.isForced());
}
return response;
}
use of com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent in project cloudbreak by hortonworks.
the class SdxDeleteActions method failedAction.
@Bean(name = "SDX_DELETION_FAILED_STATE")
public Action<?, ?> failedAction() {
return new AbstractSdxAction<>(SdxDeletionFailedEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxDeletionFailedEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void doExecute(SdxContext context, SdxDeletionFailedEvent payload, Map<Object, Object> variables) throws Exception {
Exception exception = payload.getException();
String statusReason = "Datalake deletion 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.DELETE_FAILED, statusReason, payload.getResourceId());
metricService.incrementMetricCounter(MetricType.SDX_DELETION_FAILED, sdxCluster);
if (sdxCluster.isDetached()) {
eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.SDX_DETACHED_CLUSTER_DELETION_FAILED, List.of(sdxCluster.getClusterName()));
} else {
eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_DELETION_FAILED);
}
} catch (NotFoundException notFoundException) {
LOGGER.info("Can not set status to SDX_DELETION_FAILED because data lake was not found");
}
sendEvent(context, SDX_DELETE_FAILED_HANDLED_EVENT.event(), payload);
}
@Override
protected Object getFailurePayload(SdxDeletionFailedEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return null;
}
};
}
use of com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent in project cloudbreak by hortonworks.
the class StackDeletionHandlerTest method acceptTestStackDeletionFailed.
@Test
void acceptTestStackDeletionFailed() {
long id = 2L;
StackDeletionWaitRequest stackCreationWaitRequest = new StackDeletionWaitRequest(id, userId, true);
Event receivedEvent = new Event<>(stackCreationWaitRequest);
doThrow(new UserBreakException("stack deletion failed")).when(provisionerService).waitCloudbreakClusterDeletion(eq(id), any(PollingConfig.class));
stackDeletionHandler.accept(receivedEvent);
verify(provisionerService, times(1)).waitCloudbreakClusterDeletion(eq(id), 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("SdxDeletionFailedEvent", eventNotified);
Assertions.assertEquals(SdxDeletionFailedEvent.class, event.getData().getClass());
Assertions.assertEquals(id, ((SdxDeletionFailedEvent) event.getData()).getResourceId());
}
use of com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent in project cloudbreak by hortonworks.
the class StackDeletionHandlerTest method acceptTestPollerStackTimeout.
@Test
void acceptTestPollerStackTimeout() {
long id = 2L;
StackDeletionWaitRequest stackCreationWaitRequest = new StackDeletionWaitRequest(id, userId, true);
Event receivedEvent = new Event<>(stackCreationWaitRequest);
doThrow(new PollerStoppedException("stack deletion timeout")).when(provisionerService).waitCloudbreakClusterDeletion(eq(id), any(PollingConfig.class));
stackDeletionHandler.accept(receivedEvent);
verify(provisionerService, times(1)).waitCloudbreakClusterDeletion(eq(id), 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("SdxDeletionFailedEvent", eventNotified);
Assertions.assertEquals(SdxDeletionFailedEvent.class, event.getData().getClass());
Assertions.assertEquals(id, ((SdxDeletionFailedEvent) event.getData()).getResourceId());
}
Aggregations