@Test public void testStopWhenWebApplicationException() { SdxCluster sdxCluster = sdxCluster(); WebApplicationException clientErrorException = mock(WebApplicationException.class); when(webApplicationExceptionMessageExtractor.getErrorMessage(any())).thenReturn("error"); doThrow(clientErrorException).when(stackV4Endpoint).putStopInternal(eq(0L), eq(CLUSTER_NAME), nullable(String.class)); when(sdxService.getById(CLUSTER_ID)).thenReturn(sdxCluster); RuntimeException exception = Assertions.assertThrows(RuntimeException.class, () -> underTest.stop(CLUSTER_ID)); assertEquals("Can not stop stack, web application error happened on Cloudbreak side: error", exception.getMessage()); }
public void stop(Long sdxId) { SdxCluster sdxCluster = sdxService.getById(sdxId); try { LOGGER.info("Triggering stop flow for cluster {}", sdxCluster.getClusterName()); String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn(); FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(() -> stackV4Endpoint.putStopInternal(0L, sdxCluster.getClusterName(), initiatorUserCrn)); sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.STOP_IN_PROGRESS, "Datalake stop in progress", sdxCluster); cloudbreakFlowService.saveLastCloudbreakFlowChainId(sdxCluster, flowIdentifier); } catch (NotFoundException e) { LOGGER.error("Can not find stack on cloudbreak side {}", sdxCluster.getClusterName()); } catch (ClientErrorException e) { String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e); LOGGER.error("Can not stop stack {} from cloudbreak: {}", sdxCluster.getStackId(), errorMessage, e); throw new RuntimeException("Can not stop stack, client error happened on Cloudbreak side: " + errorMessage); } catch (WebApplicationException e) { String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e); LOGGER.error("Can not stop stack {} from cloudbreak: {}", sdxCluster.getStackId(), errorMessage, e); throw new RuntimeException("Can not stop stack, web application error happened on Cloudbreak side: " + errorMessage); } }
SdxStopService { public void stop(Long sdxId) { SdxCluster sdxCluster = sdxService.getById(sdxId); try { LOGGER.info("Triggering stop flow for cluster {}", sdxCluster.getClusterName()); String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn(); FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(() -> stackV4Endpoint.putStopInternal(0L, sdxCluster.getClusterName(), initiatorUserCrn)); sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.STOP_IN_PROGRESS, "Datalake stop in progress", sdxCluster); cloudbreakFlowService.saveLastCloudbreakFlowChainId(sdxCluster, flowIdentifier); } catch (NotFoundException e) { LOGGER.error("Can not find stack on cloudbreak side {}", sdxCluster.getClusterName()); } catch (ClientErrorException e) { String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e); LOGGER.error("Can not stop stack {} from cloudbreak: {}", sdxCluster.getStackId(), errorMessage, e); throw new RuntimeException("Can not stop stack, client error happened on Cloudbreak side: " + errorMessage); } catch (WebApplicationException e) { String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e); LOGGER.error("Can not stop stack {} from cloudbreak: {}", sdxCluster.getStackId(), errorMessage, e); throw new RuntimeException("Can not stop stack, web application error happened on Cloudbreak side: " + errorMessage); } } }
SdxStopService { public void stop(Long sdxId) { SdxCluster sdxCluster = sdxService.getById(sdxId); try { LOGGER.info("Triggering stop flow for cluster {}", sdxCluster.getClusterName()); String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn(); FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(() -> stackV4Endpoint.putStopInternal(0L, sdxCluster.getClusterName(), initiatorUserCrn)); sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.STOP_IN_PROGRESS, "Datalake stop in progress", sdxCluster); cloudbreakFlowService.saveLastCloudbreakFlowChainId(sdxCluster, flowIdentifier); } catch (NotFoundException e) { LOGGER.error("Can not find stack on cloudbreak side {}", sdxCluster.getClusterName()); } catch (ClientErrorException e) { String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e); LOGGER.error("Can not stop stack {} from cloudbreak: {}", sdxCluster.getStackId(), errorMessage, e); throw new RuntimeException("Can not stop stack, client error happened on Cloudbreak side: " + errorMessage); } catch (WebApplicationException e) { String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e); LOGGER.error("Can not stop stack {} from cloudbreak: {}", sdxCluster.getStackId(), errorMessage, e); throw new RuntimeException("Can not stop stack, web application error happened on Cloudbreak side: " + errorMessage); } }  }
SdxStopService { public void stop(Long sdxId) { SdxCluster sdxCluster = sdxService.getById(sdxId); try { LOGGER.info("Triggering stop flow for cluster {}", sdxCluster.getClusterName()); String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn(); FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(() -> stackV4Endpoint.putStopInternal(0L, sdxCluster.getClusterName(), initiatorUserCrn)); sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.STOP_IN_PROGRESS, "Datalake stop in progress", sdxCluster); cloudbreakFlowService.saveLastCloudbreakFlowChainId(sdxCluster, flowIdentifier); } catch (NotFoundException e) { LOGGER.error("Can not find stack on cloudbreak side {}", sdxCluster.getClusterName()); } catch (ClientErrorException e) { String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e); LOGGER.error("Can not stop stack {} from cloudbreak: {}", sdxCluster.getStackId(), errorMessage, e); throw new RuntimeException("Can not stop stack, client error happened on Cloudbreak side: " + errorMessage); } catch (WebApplicationException e) { String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e); LOGGER.error("Can not stop stack {} from cloudbreak: {}", sdxCluster.getStackId(), errorMessage, e); throw new RuntimeException("Can not stop stack, web application error happened on Cloudbreak side: " + errorMessage); } }  FlowIdentifier triggerStopIfClusterNotStopped(SdxCluster cluster); void stop(Long sdxId); void waitCloudbreakCluster(Long sdxId, PollingConfig pollingConfig); void stopAllDatahub(Long sdxId); }
SdxStopService { public void stop(Long sdxId) { SdxCluster sdxCluster = sdxService.getById(sdxId); try { LOGGER.info("Triggering stop flow for cluster {}", sdxCluster.getClusterName()); String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn(); FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(() -> stackV4Endpoint.putStopInternal(0L, sdxCluster.getClusterName(), initiatorUserCrn)); sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.STOP_IN_PROGRESS, "Datalake stop in progress", sdxCluster); cloudbreakFlowService.saveLastCloudbreakFlowChainId(sdxCluster, flowIdentifier); } catch (NotFoundException e) { LOGGER.error("Can not find stack on cloudbreak side {}", sdxCluster.getClusterName()); } catch (ClientErrorException e) { String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e); LOGGER.error("Can not stop stack {} from cloudbreak: {}", sdxCluster.getStackId(), errorMessage, e); throw new RuntimeException("Can not stop stack, client error happened on Cloudbreak side: " + errorMessage); } catch (WebApplicationException e) { String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e); LOGGER.error("Can not stop stack {} from cloudbreak: {}", sdxCluster.getStackId(), errorMessage, e); throw new RuntimeException("Can not stop stack, web application error happened on Cloudbreak side: " + errorMessage); } }  FlowIdentifier triggerStopIfClusterNotStopped(SdxCluster cluster); void stop(Long sdxId); void waitCloudbreakCluster(Long sdxId, PollingConfig pollingConfig); void stopAllDatahub(Long sdxId);  }