Search in sources :

Example 66 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class SdxRecoveryService method recoverCluster.

public void recoverCluster(Long clusterId) {
    SdxCluster sdxCluster = sdxService.getById(clusterId);
    sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.RECOVERY_IN_PROGRESS, DATALAKE_RECOVERY_REQUESTED, "Recovering datalake stack", sdxCluster);
    try {
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.recoverClusterByNameInternal(0L, sdxCluster.getClusterName(), initiatorUserCrn)).getFlowIdentifier();
        cloudbreakFlowService.saveLastCloudbreakFlowChainId(sdxCluster, flowIdentifier);
    } catch (WebApplicationException e) {
        String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Stack recovery failed on cluster: [%s]. Message: [%s]", sdxCluster.getClusterName(), exceptionMessage);
        throw new CloudbreakApiException(message, e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Example 67 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class SdxRepairService method startRepairInCb.

protected void startRepairInCb(SdxCluster sdxCluster, SdxRepairSettings repairRequest) {
    try {
        LOGGER.info("Triggering repair flow for cluster {} with hostgroups {}", sdxCluster.getClusterName(), repairRequest.getHostGroupNames());
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.repairClusterInternal(0L, sdxCluster.getClusterName(), createRepairRequest(repairRequest), initiatorUserCrn));
        cloudbreakFlowService.saveLastCloudbreakFlowChainId(sdxCluster, flowIdentifier);
        sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.REPAIR_IN_PROGRESS, "Datalake repair in progress", sdxCluster);
    } catch (NotFoundException e) {
        LOGGER.info("Can not find stack on cloudbreak side {}", sdxCluster.getClusterName());
    } catch (ClientErrorException e) {
        String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e);
        LOGGER.info("Can not repair stack {} from cloudbreak: {}", sdxCluster.getStackId(), errorMessage, e);
        throw new RuntimeException("Cannot repair cluster, error happened during operation: " + errorMessage);
    } catch (WebApplicationException e) {
        LOGGER.info("Can not repair stack {} from cloudbreak: {}", sdxCluster.getStackId(), e.getMessage(), e);
        throw new RuntimeException("Cannot repair cluster, error happened during the operation: " + e.getMessage());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) NotFoundException(javax.ws.rs.NotFoundException) ClientErrorException(javax.ws.rs.ClientErrorException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Example 68 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class SdxService method deleteSdxCluster.

private FlowIdentifier deleteSdxCluster(SdxCluster sdxCluster, boolean forced) {
    checkIfSdxIsDeletable(sdxCluster, forced);
    MDCBuilder.buildMdcContext(sdxCluster);
    sdxClusterRepository.save(sdxCluster);
    sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.DELETE_REQUESTED, "Datalake deletion requested", sdxCluster);
    FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerSdxDeletion(sdxCluster, forced);
    flowCancelService.cancelRunningFlows(sdxCluster.getId());
    return flowIdentifier;
}
Also used : FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Example 69 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class SdxUpgradeService method changeImage.

public void changeImage(Long id, UpgradeOptionV4Response upgradeOption) {
    SdxCluster cluster = sdxService.getById(id);
    String targetImageId = upgradeOption.getUpgrade().getImageId();
    StackImageChangeV4Request stackImageChangeRequest = new StackImageChangeV4Request();
    stackImageChangeRequest.setImageId(targetImageId);
    stackImageChangeRequest.setImageCatalogName(upgradeOption.getUpgrade().getImageCatalogName());
    sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.CHANGE_IMAGE_IN_PROGRESS, "Changing image", cluster);
    try {
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.changeImageInternal(0L, cluster.getClusterName(), stackImageChangeRequest, initiatorUserCrn));
        cloudbreakFlowService.saveLastCloudbreakFlowChainId(cluster, flowIdentifier);
    } catch (WebApplicationException e) {
        String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Stack change image failed on cluster: [%s]. Message: [%s]", cluster.getClusterName(), exceptionMessage);
        throw new CloudbreakApiException(message, e);
    }
}
Also used : StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) WebApplicationException(javax.ws.rs.WebApplicationException) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Example 70 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class SdxUpgradeService method upgradeRuntime.

public void upgradeRuntime(Long id, String imageId) {
    SdxCluster sdxCluster = sdxService.getById(id);
    sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.DATALAKE_UPGRADE_IN_PROGRESS, "Upgrading datalake stack", sdxCluster);
    try {
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.upgradeClusterByNameInternal(0L, sdxCluster.getClusterName(), imageId, initiatorUserCrn));
        cloudbreakFlowService.saveLastCloudbreakFlowChainId(sdxCluster, flowIdentifier);
    } catch (WebApplicationException e) {
        String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Stack upgrade failed on cluster: [%s]. Message: [%s]", sdxCluster.getClusterName(), exceptionMessage);
        throw new CloudbreakApiException(message, e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Aggregations

FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)150 Test (org.junit.jupiter.api.Test)55 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)15 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)14 SdxClusterDetailResponse (com.sequenceiq.sdx.api.model.SdxClusterDetailResponse)14 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)13 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)10 Supplier (java.util.function.Supplier)10 ImageChangeDto (com.sequenceiq.cloudbreak.service.image.ImageChangeDto)9 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)7 StackImageChangeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request)7 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)7 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)7 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)7 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)7 CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)7