use of com.sequenceiq.cloudbreak.common.exception.NotFoundException 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.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class SdxServiceTest method testGetSdxClusterByAccountIdWhenNoDeployedClusterShouldThrowSdxNotFoundException.
@Test
void testGetSdxClusterByAccountIdWhenNoDeployedClusterShouldThrowSdxNotFoundException() {
when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(Optional.empty());
NotFoundException notFoundException = assertThrows(NotFoundException.class, () -> underTest.getByNameInAccount(USER_CRN, "sdxcluster"));
assertEquals("SDX cluster 'sdxcluster' not found.", notFoundException.getMessage());
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class SdxServiceTest method testDeleteSdxWhenSdxHasAttachedDataHubsAndExceptionHappensWhenGettingDatahubsAndForceDeleteShouldInitiateSdxDeletionFlow.
@Test
void testDeleteSdxWhenSdxHasAttachedDataHubsAndExceptionHappensWhenGettingDatahubsAndForceDeleteShouldInitiateSdxDeletionFlow() {
SdxCluster sdxCluster = getSdxCluster();
when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNull(anyString(), anyString())).thenReturn(Optional.of(sdxCluster));
when(sdxReactorFlowManager.triggerSdxDeletion(any(SdxCluster.class), anyBoolean())).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
doThrow(new NotFoundException("nope")).when(distroxService).getAttachedDistroXClusters(anyString());
underTest.deleteSdx(USER_CRN, "sdx-cluster-name", true);
verify(sdxReactorFlowManager, times(1)).triggerSdxDeletion(sdxCluster, true);
ArgumentCaptor<SdxCluster> captor = ArgumentCaptor.forClass(SdxCluster.class);
verify(sdxClusterRepository, times(1)).save(captor.capture());
verify(sdxStatusService, times(1)).setStatusForDatalakeAndNotify(DatalakeStatusEnum.DELETE_REQUESTED, "Datalake deletion requested", sdxCluster);
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class SdxBackupRestoreServiceTest method testWhenSuccessfulBackupDoesNotExistThenThrowError.
@Test
public void testWhenSuccessfulBackupDoesNotExistThenThrowError() {
when(datalakeDrClient.getLastSuccessfulBackup(CLUSTER_NAME, USER_CRN, Optional.empty())).thenReturn(null);
NotFoundException exception = assertThrows(NotFoundException.class, () -> sdxBackupRestoreService.getLastSuccessfulBackupInfo(CLUSTER_NAME, USER_CRN));
assertEquals("No successful backup found for data lake: " + CLUSTER_NAME, exception.getMessage());
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class ClusterProxyRegistrationHandler method accept.
@Override
public void accept(Event<ClusterProxyRegistrationRequest> event) {
ClusterProxyRegistrationRequest request = event.getData();
try {
Set<InstanceMetaData> ims = instanceMetaDataService.findNotTerminatedForStack(request.getResourceId());
if (ims.isEmpty()) {
LOGGER.error("Cluster Proxy registration has failed. No available instances found for FreeIPA");
ClusterProxyRegistrationFailed response = new ClusterProxyRegistrationFailed(request.getResourceId(), new NotFoundException("Cluster Proxy registration has failed. No available instances found for FreeIPA"));
sendEvent(response, event);
} else {
boolean allInstanceHasFqdn = ims.stream().allMatch(im -> StringUtils.isNotBlank(im.getDiscoveryFQDN()));
if (allInstanceHasFqdn) {
LOGGER.info("All instances already have FQDN set, register all to cluster proxy");
clusterProxyService.registerFreeIpa(request.getResourceId());
} else {
LOGGER.info("Instances missing FQDN, fallback to PGW registration");
clusterProxyService.registerFreeIpaForBootstrap(request.getResourceId());
}
sendEvent(new ClusterProxyRegistrationSuccess(request.getResourceId()), event);
}
} catch (Exception e) {
LOGGER.error("Cluster Proxy bootstrap registration has failed", e);
sendEvent(new ClusterProxyRegistrationFailed(request.getResourceId(), e), event);
}
}
Aggregations