Search in sources :

Example 1 with CloudbreakApiException

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

the class GatewayTopologyToGatewayTopologyV4RequestConverter method convert.

public GatewayTopologyV4Request convert(GatewayTopology gatewayTopology) {
    GatewayTopologyV4Request gatewayTopologyJson = new GatewayTopologyV4Request();
    gatewayTopologyJson.setTopologyName(gatewayTopology.getTopologyName());
    Json exposedJson = gatewayTopology.getExposedServices();
    if (exposedJson != null && StringUtils.isNotEmpty(exposedJson.getValue())) {
        try {
            gatewayTopologyJson.setExposedServices(exposedJson.get(ExposedServices.class).getServices());
        } catch (IOException e) {
            LOGGER.info("Failed to add exposedServices to response", e);
            throw new CloudbreakApiException("Failed to add exposedServices to response", e);
        }
    }
    return gatewayTopologyJson;
}
Also used : GatewayTopologyV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.topology.GatewayTopologyV4Request) Json(com.sequenceiq.cloudbreak.common.json.Json) IOException(java.io.IOException) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Example 2 with CloudbreakApiException

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

the class StackImageUpdateService method getNewImageIfVersionsMatch.

public StatedImage getNewImageIfVersionsMatch(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl) {
    try {
        restRequestThreadLocalService.setWorkspace(stack.getWorkspace());
        Image currentImage = stackImageService.getCurrentImage(stack);
        StatedImage newImage = getNewImage(newImageId, imageCatalogName, imageCatalogUrl, currentImage);
        if (!isCloudPlatformMatches(stack, newImage)) {
            String message = messagesService.getMessage(Msg.CLOUDPLATFORM_DIFFERENT.code(), Lists.newArrayList(String.join(",", newImage.getImage().getImageSetsByProvider().keySet()), stack.cloudPlatform()));
            LOGGER.debug(message);
            throw new OperationException(message);
        }
        if (!isOsVersionsMatch(currentImage, newImage)) {
            String message = messagesService.getMessage(Msg.OSVERSION_DIFFERENT.code(), Lists.newArrayList(newImage.getImage().getOs(), newImage.getImage().getOsType(), currentImage.getOs(), currentImage.getOsType()));
            LOGGER.debug(message);
            throw new OperationException(message);
        }
        if (!isStackMatchIfPrewarmed(newImage)) {
            String message = "Stack versions don't match on prewarmed image with cluster's";
            LOGGER.debug(message);
            throw new OperationException(message);
        }
        return newImage;
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.info("Cloudbreak Image not found", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    } catch (CloudbreakImageCatalogException e) {
        LOGGER.info("Cloudbreak Image Catalog error", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    }
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) OperationException(com.sequenceiq.cloudbreak.service.OperationException) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)

Example 3 with CloudbreakApiException

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

the class StackService method create.

@Measure(StackService.class)
public Stack create(Stack stack, String platformString, StatedImage imgFromCatalog, User user, Workspace workspace, Optional<String> externalCrn) {
    if (stack.getGatewayPort() == null) {
        stack.setGatewayPort(nginxPort);
    }
    stack.setCreator(user);
    stack.setWorkspace(workspace);
    setPlatformVariant(stack);
    String stackName = stack.getName();
    MDCBuilder.buildMdcContext(stack);
    GetPlatformTemplateRequest templateRequest = connector.triggerGetTemplate(stack);
    if (!stack.getStackAuthentication().passwordAuthenticationRequired() && !Strings.isNullOrEmpty(stack.getStackAuthentication().getPublicKey())) {
        rsaPublicKeyValidator.validate(stack.getStackAuthentication().getPublicKey());
    }
    if (stack.getOrchestrator() != null) {
        orchestratorService.save(stack.getOrchestrator());
    }
    stack.getStackAuthentication().setLoginUserName(SSH_USER_CB);
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    if (externalCrn.isPresent()) {
        // it means it is a DL cluster, double check it in sdx service
        sdxClientService.getByCrn(externalCrn.get());
        stack.setResourceCrn(externalCrn.get());
    } else {
        stack.setResourceCrn(createCRN(accountId));
    }
    setDefaultTags(stack);
    Stack savedStack = measure(() -> stackRepository.save(stack), LOGGER, "Stackrepository save took {} ms for stack {}", stackName);
    MDCBuilder.buildMdcContext(savedStack);
    measure(() -> addCloudbreakDetailsForStack(savedStack), LOGGER, "Add Cloudbreak details took {} ms for stack {}", stackName);
    measure(() -> storeTelemetryForStack(savedStack), LOGGER, "Add Telemetry settings took {} ms for stack {}", stackName);
    measure(() -> instanceGroupService.saveAll(savedStack.getInstanceGroups()), LOGGER, "Instance groups saved in {} ms for stack {}", stackName);
    measure(() -> instanceMetaDataService.saveAll(savedStack.getInstanceMetaDataAsList()), LOGGER, "Instance metadatas saved in {} ms for stack {}", stackName);
    measure(() -> loadBalancerPersistenceService.saveAll(savedStack.getLoadBalancers()), LOGGER, "Load balancers saved in {} ms for stack {}", stackName);
    measure(() -> targetGroupPersistenceService.saveAll(savedStack.getTargetGroupAsList()), LOGGER, "Target groups saved in {} ms for stack {}", stackName);
    try {
        Set<Component> components = imageService.create(stack, imgFromCatalog);
        setRuntime(stack, components);
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.info("Cloudbreak Image not found", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    } catch (CloudbreakImageCatalogException e) {
        LOGGER.info("Cloudbreak Image Catalog error", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    }
    measure(() -> addTemplateForStack(savedStack, connector.waitGetTemplate(templateRequest)), LOGGER, "Save cluster template took {} ms for stack {}", stackName);
    return savedStack;
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Component(com.sequenceiq.cloudbreak.domain.stack.Component) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) GetPlatformTemplateRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 4 with CloudbreakApiException

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

the class SdxUpgradeRecoveryServiceTest method testGetClusterRecoverableByNameInternalThrowsExceptionShouldThrowApiException.

@Test
public void testGetClusterRecoverableByNameInternalThrowsExceptionShouldThrowApiException() {
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    WebApplicationException webApplicationException = new WebApplicationException();
    doThrow(webApplicationException).when(stackV4Endpoint).getClusterRecoverableByNameInternal(WORKSPACE_ID, CLUSTER_NAME, USER_CRN);
    when(exceptionMessageExtractor.getErrorMessage(webApplicationException)).thenReturn("web-error");
    CloudbreakApiException actual = assertThrows(CloudbreakApiException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validateRecovery(cluster)));
    assertEquals("Stack recovery validation failed on cluster: [dummyCluster]. Message: [web-error]", actual.getMessage());
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) Test(org.junit.jupiter.api.Test)

Example 5 with CloudbreakApiException

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

the class DatalakeFullRestoreWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<DatalakeFullRestoreWaitRequest> event) {
    DatalakeFullRestoreWaitRequest request = event.getData();
    Long sdxId = request.getResourceId();
    String userId = request.getUserId();
    Selectable response;
    try {
        LOGGER.info("Start polling datalake full restore status for id: {}", sdxId);
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
        sdxBackupRestoreService.waitForDatalakeDrRestoreToComplete(sdxId, request.getOperationId(), request.getUserId(), pollingConfig, "Full restore");
        response = new DatalakeRestoreSuccessEvent(sdxId, userId, request.getOperationId());
    } catch (UserBreakException userBreakException) {
        LOGGER.info("Full restore polling exited before timeout. Cause: ", userBreakException);
        response = new DatalakeRestoreFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.info("Full restore poller stopped for cluster: {}", sdxId);
        response = new DatalakeRestoreFailedEvent(sdxId, userId, new PollerStoppedException("Data lake restore timed out after " + durationInMinutes + " minutes"));
    } catch (PollerException exception) {
        LOGGER.info("Full restore polling failed for cluster: {}", sdxId);
        response = new DatalakeRestoreFailedEvent(sdxId, userId, exception);
    } catch (CloudbreakApiException exception) {
        LOGGER.info("Datalake restore failed. Reason: " + exception.getMessage());
        response = new DatalakeRestoreFailedEvent(sdxId, userId, exception);
    }
    return response;
}
Also used : DatalakeRestoreSuccessEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeRestoreSuccessEvent) UserBreakException(com.dyngr.exception.UserBreakException) DatalakeRestoreFailedEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeRestoreFailedEvent) DatalakeFullRestoreWaitRequest(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeFullRestoreWaitRequest) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

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