class ProvisionerService {

    public void startStackProvisioning(Long id, DetailedEnvironmentResponse environment) {
        SdxCluster sdxCluster = sdxService.getById(id);
        LOGGER.info("Call cloudbreak with stackrequest");
        try {
            stackRequestManifester.configureStackForSdxCluster(sdxCluster, environment);
            StackV4Request stackV4Request = JsonUtil.readValue(sdxCluster.getStackRequestToCloudbreak(), StackV4Request.class);
            Optional.ofNullable(sdxCluster.getDatabaseCrn()).ifPresent(crn -> {
                stackV4Request.getCluster().setDatabaseServerCrn(crn);
                sdxCluster.setStackRequestToCloudbreak(JsonUtil.writeValueAsStringSilent(stackV4Request));
            });
            StackV4Response stackV4Response;
            try {
                stackV4Response = ThreadBasedUserCrnProvider.doAsInternalActor(() ->
                        stackV4Endpoint.getByCrn(0L, sdxCluster.getCrn(), null));
            } catch (NotFoundException e) {
                LOGGER.info("Stack does not exist on cloudbreak side, POST new cluster: {}", sdxCluster.getClusterName(), e);
                String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
                stackV4Response = ThreadBasedUserCrnProvider.doAsInternalActor(() ->
                        stackV4Endpoint.postInternal(0L, stackV4Request, initiatorUserCrn));
            }
            sdxCluster.setStackId(stackV4Response.getId());
            sdxCluster.setStackCrn(stackV4Response.getCrn());
            sdxClusterRepository.save(sdxCluster);
            cloudbreakFlowService.saveLastCloudbreakFlowChainId(sdxCluster, stackV4Response.getFlowIdentifier());
            LOGGER.info("Sdx cluster updated");
        } catch (WebApplicationException e) {
            String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e);
            LOGGER.info("Cannot start provisioning: {}", errorMessage, e);
            throw new RuntimeException("Cannot start provisioning, some error happened on Cloudbreak side: " + errorMessage);
        } catch (IOException e) {
            LOGGER.info("Cannot parse stackrequest to json", e);
            throw new RuntimeException("Cannot write stackrequest to json: " + e.getMessage());
        }
    }

}