Search in sources :

Example 16 with CloudbreakApiException

use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.

the class SdxBackupRestoreServiceTest method testgetDatabaseBackupStatus.

@Test
public void testgetDatabaseBackupStatus() {
    when(sdxOperationRepository.findSdxOperationByOperationId(Mockito.anyString())).thenReturn(null);
    try {
        sdxBackupRestoreService.getDatabaseBackupStatus(sdxCluster, BACKUP_ID);
        fail("Exception should have been thrown");
    } catch (NotFoundException notFoundException) {
        String exceptedMessage = String.format("Status with id: [%s] not found", BACKUP_ID);
        assertEquals(exceptedMessage, notFoundException.getLocalizedMessage());
    }
    reset(sdxOperationRepository);
    SdxOperation sdxOperation = new SdxOperation();
    sdxOperation.setOperationType(SdxOperationType.RESTORE);
    sdxOperation.setSdxClusterId(sdxCluster.getId());
    sdxOperation.setOperationId(BACKUP_ID);
    when(sdxOperationRepository.findSdxOperationByOperationId(Mockito.anyString())).thenReturn(sdxOperation);
    try {
        sdxBackupRestoreService.getDatabaseBackupStatus(sdxCluster, BACKUP_ID);
        fail("Exception should have been thrown");
    } catch (CloudbreakApiException cloudbreakApiException) {
        String exceptedMessage = String.format("Invalid operation-id: [%s]. provided", BACKUP_ID);
        assertEquals(exceptedMessage, cloudbreakApiException.getLocalizedMessage());
    }
}
Also used : SdxOperation(com.sequenceiq.datalake.entity.operation.SdxOperation) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) Test(org.junit.jupiter.api.Test)

Example 17 with CloudbreakApiException

use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.

the class SdxUpgradeService method upgradeOs.

public void upgradeOs(Long id) {
    SdxCluster cluster = sdxService.getById(id);
    sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.DATALAKE_UPGRADE_IN_PROGRESS, "OS upgrade started", cluster);
    try {
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.upgradeOsInternal(0L, cluster.getClusterName(), initiatorUserCrn));
        cloudbreakFlowService.saveLastCloudbreakFlowChainId(cluster, flowIdentifier);
    } catch (WebApplicationException e) {
        String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Stack upgrade failed on cluster: [%s]. Message: [%s]", cluster.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 18 with CloudbreakApiException

use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.

the class ClusterToClusterV4ResponseConverter method convertContainerConfig.

private void convertContainerConfig(Cluster source, ClusterV4Response clusterResponse) {
    Json customContainerDefinition = source.getCustomContainerDefinition();
    if (customContainerDefinition != null && StringUtils.isNotEmpty(customContainerDefinition.getValue())) {
        try {
            Map<String, String> map = customContainerDefinition.get(Map.class);
            Map<String, String> result = new HashMap<>();
            for (Entry<String, String> stringStringEntry : map.entrySet()) {
                result.put(stringStringEntry.getKey(), stringStringEntry.getValue());
            }
            CustomContainerV4Response customContainers = new CustomContainerV4Response();
            customContainers.setDefinitions(result);
            clusterResponse.setCustomContainers(customContainers);
        } catch (IOException e) {
            LOGGER.info("Failed to add customContainerDefinition to response", e);
            throw new CloudbreakApiException("Failed to add customContainerDefinition to response", e);
        }
    }
}
Also used : CustomContainerV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.customcontainer.CustomContainerV4Response) HashMap(java.util.HashMap) Json(com.sequenceiq.cloudbreak.common.json.Json) IOException(java.io.IOException) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Example 19 with CloudbreakApiException

use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.

the class SdxImageCatalogService method changeImageCatalog.

public void changeImageCatalog(SdxCluster sdxCluster, String imageCatalog) {
    if (flowLogService.isOtherFlowRunning(sdxCluster.getId())) {
        throw new CloudbreakApiException(String.format("Operation is running for cluster '%s'. Please try again later.", sdxCluster.getName()));
    }
    try {
        ChangeImageCatalogV4Request changeImageCatalogRequest = new ChangeImageCatalogV4Request();
        changeImageCatalogRequest.setImageCatalog(imageCatalog);
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.changeImageCatalogInternal(WORKSPACE_ID_DEFAULT, sdxCluster.getClusterName(), initiatorUserCrn, changeImageCatalogRequest));
    } catch (CloudbreakServiceException e) {
        throw new CloudbreakApiException(e.getMessage(), e);
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ChangeImageCatalogV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.ChangeImageCatalogV4Request) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Example 20 with CloudbreakApiException

use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.

the class SdxUpgradeRecoveryService method validateRecovery.

public SdxRecoverableResponse validateRecovery(SdxCluster sdxCluster) {
    MDCBuilder.buildMdcContext(sdxCluster);
    try {
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        RecoveryValidationV4Response response = ThreadBasedUserCrnProvider.doAsInternalActor(() -> stackV4Endpoint.getClusterRecoverableByNameInternal(0L, sdxCluster.getClusterName(), initiatorUserCrn));
        return new SdxRecoverableResponse(response.getReason(), response.getStatus());
    } catch (WebApplicationException e) {
        String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Stack recovery validation failed on cluster: [%s]. Message: [%s]", sdxCluster.getClusterName(), exceptionMessage);
        throw new CloudbreakApiException(message, e);
    }
}
Also used : RecoveryValidationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryValidationV4Response) WebApplicationException(javax.ws.rs.WebApplicationException) SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Aggregations

CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)20 WebApplicationException (javax.ws.rs.WebApplicationException)10 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)7 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)5 PollerException (com.dyngr.exception.PollerException)2 PollerStoppedException (com.dyngr.exception.PollerStoppedException)2 UserBreakException (com.dyngr.exception.UserBreakException)2 RecoveryValidationV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryValidationV4Response)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)2 Json (com.sequenceiq.cloudbreak.common.json.Json)2 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)2 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)2 FlowNotAcceptedException (com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)2 FlowsAlreadyRunningException (com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException)2 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)2 FlowAcceptResult (com.sequenceiq.flow.core.model.FlowAcceptResult)2 SdxRecoverableResponse (com.sequenceiq.sdx.api.model.SdxRecoverableResponse)2 IOException (java.io.IOException)2 Test (org.junit.jupiter.api.Test)2 com.cloudera.thunderhead.service.datalakedr.datalakeDRProto (com.cloudera.thunderhead.service.datalakedr.datalakeDRProto)1