Search in sources :

Example 1 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.

the class GrpcUmsClient method makeCheckRightCall.

private boolean makeCheckRightCall(String userCrn, String right, String resource, Optional<String> requestId) {
    checkArgument(VALID_AUTHZ_RESOURCE.test(resource), String.format("Provided resource [%s] is not in CRN format", resource));
    try {
        AuthorizationClient client = makeAuthorizationClient();
        LOGGER.info("Checking right {} for user {} on resource {}!", right, userCrn, resource != null ? resource : "account");
        client.checkRight(RequestIdUtil.getOrGenerate(requestId), userCrn, right, resource);
        LOGGER.info("User {} has right {} on resource {}!", userCrn, right, resource != null ? resource : "account");
        return true;
    } catch (StatusRuntimeException statusRuntimeException) {
        if (Status.Code.PERMISSION_DENIED.equals(statusRuntimeException.getStatus().getCode())) {
            LOGGER.error("Checking right {} failed for user {}, thus access is denied! Cause: {}", right, userCrn, statusRuntimeException.getMessage());
            return false;
        } else if (Status.Code.DEADLINE_EXCEEDED.equals(statusRuntimeException.getStatus().getCode())) {
            LOGGER.error("Deadline exceeded for check right {} for user {} on resource {}", right, userCrn, resource != null ? resource : "account", statusRuntimeException);
            throw new CloudbreakServiceException("Authorization failed due to user management service call timed out.");
        } else {
            LOGGER.error("Status runtime exception while checking right {} for user {} on resource {}", right, userCrn, resource != null ? resource : "account", statusRuntimeException);
            throw new CloudbreakServiceException("Authorization failed due to user management service call failed.");
        }
    } catch (Exception e) {
        LOGGER.error("Unkown error while checking right {} for user {} on resource {}", right, userCrn, resource != null ? resource : "account", e);
        throw new CloudbreakServiceException("Authorization failed due to user management service call failed with error.");
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StatusRuntimeException(io.grpc.StatusRuntimeException) StatusRuntimeException(io.grpc.StatusRuntimeException) UmsOperationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 2 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.

the class ContainerConfigService method create.

private Component create(Stack stack, DockerContainer dc) throws CloudbreakException {
    try {
        ContainerConfig config;
        ContainerOrchestrator orchestrator = containerOrchestratorResolver.get(stack.getOrchestrator().getType());
        Map<String, String> customContainerConfig = getCustomContainerConfig(stack);
        Optional<String> customContainerName = Optional.ofNullable(customContainerConfig.get(dc.name()));
        Optional<String> customQueue = getCustomQueue(stack);
        switch(dc) {
            case AMBARI_SERVER:
                config = new Builder(orchestrator.ambariServerContainer(customContainerName), customQueue).build();
                break;
            case AMBARI_AGENT:
                config = new Builder(orchestrator.ambariClientContainer(customContainerName), customQueue).build();
                break;
            case AMBARI_DB:
                config = new Builder(orchestrator.ambariDbContainer(customContainerName), customQueue).build();
                break;
            default:
                throw new CloudbreakServiceException(String.format("No configuration exist for %s", dc));
        }
        Component component = new Component(ComponentType.CONTAINER, dc.name(), new Json(config), stack);
        return componentConfigProviderService.store(component);
    } catch (IllegalArgumentException ignored) {
        throw new CloudbreakServiceException(String.format("Failed to parse component ContainerConfig for stack: %d, container: %s", stack.getId(), dc.getName()));
    }
}
Also used : ContainerConfig(com.sequenceiq.cloudbreak.orchestrator.model.ContainerConfig) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Builder(com.sequenceiq.cloudbreak.core.bootstrap.config.ContainerConfigBuilder.Builder) Json(com.sequenceiq.cloudbreak.common.json.Json) Component(com.sequenceiq.cloudbreak.domain.stack.Component)

Example 3 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.

the class ContainerConfigService method get.

public ContainerConfig get(Stack stack, DockerContainer dc) {
    try {
        Component component = componentConfigProviderService.getComponent(stack.getId(), ComponentType.CONTAINER, dc.name());
        if (component == null) {
            component = create(stack, dc);
            LOGGER.debug("Container component definition created: {}", component);
        } else {
            LOGGER.debug("Container component definition found in database: {}", component);
        }
        return component.getAttributes().get(ContainerConfig.class);
    } catch (CloudbreakException | IOException ignored) {
        throw new CloudbreakServiceException(String.format("Failed to parse component ContainerConfig for stack: %d, container: %s", stack.getId(), dc.getName()));
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) IOException(java.io.IOException) Component(com.sequenceiq.cloudbreak.domain.stack.Component)

Example 4 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.

the class ClusterHostServiceRunner method redeployGatewayPillarOnly.

public void redeployGatewayPillarOnly(Stack stack, Cluster cluster) {
    throwIfNull(stack, () -> new IllegalArgumentException("Stack should not be null"));
    throwIfNull(cluster, () -> new IllegalArgumentException("Cluster should not be null"));
    try {
        Set<Node> allNodes = stackUtil.collectNodes(stack);
        Set<Node> reachableNodes = stackUtil.collectReachableNodes(stack);
        List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
        List<GrainProperties> grainsProperties = grainPropertiesService.createGrainProperties(gatewayConfigs, cluster, reachableNodes);
        SaltConfig saltConfig = createSaltConfigWithGatewayPillarOnly(stack, cluster, grainsProperties);
        ExitCriteriaModel exitCriteriaModel = clusterDeletionBasedModel(stack.getId(), cluster.getId());
        LOGGER.debug("Calling orchestrator to upload gateway pillar");
        hostOrchestrator.uploadGatewayPillar(gatewayConfigs, allNodes, exitCriteriaModel, saltConfig);
    } catch (CloudbreakOrchestratorCancelledException e) {
        LOGGER.debug("Orchestration cancelled during redeploying gateway pillar", e);
        throw new CancellationException(e.getMessage());
    } catch (CloudbreakOrchestratorException | IOException e) {
        LOGGER.debug("Orchestration exception during redeploying gateway pillar", e);
        throw new CloudbreakServiceException(e.getMessage(), e);
    }
}
Also used : ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) ClusterDeletionBasedExitCriteriaModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) GrainProperties(com.sequenceiq.cloudbreak.orchestrator.model.GrainProperties) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) IOException(java.io.IOException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 5 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.

the class ClusterHostServiceRunner method redeployGatewayCertificate.

public void redeployGatewayCertificate(Stack stack, Cluster cluster) {
    throwIfNull(stack, () -> new IllegalArgumentException("Stack should not be null"));
    throwIfNull(cluster, () -> new IllegalArgumentException("Cluster should not be null"));
    try {
        Set<Node> allNodes = stackUtil.collectNodes(stack);
        Set<Node> reachableNodes = stackUtil.collectReachableNodes(stack);
        List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
        List<GrainProperties> grainsProperties = grainPropertiesService.createGrainProperties(gatewayConfigs, cluster, reachableNodes);
        SaltConfig saltConfig = createSaltConfig(stack, cluster, grainsProperties);
        ExitCriteriaModel exitCriteriaModel = clusterDeletionBasedModel(stack.getId(), cluster.getId());
        hostOrchestrator.uploadGatewayPillar(gatewayConfigs, allNodes, exitCriteriaModel, saltConfig);
        hostOrchestrator.runService(gatewayConfigs, reachableNodes, saltConfig, exitCriteriaModel);
    } catch (CloudbreakOrchestratorCancelledException e) {
        throw new CancellationException(e.getMessage());
    } catch (CloudbreakOrchestratorException | IOException e) {
        throw new CloudbreakServiceException(e.getMessage(), e);
    }
}
Also used : ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) ClusterDeletionBasedExitCriteriaModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) GrainProperties(com.sequenceiq.cloudbreak.orchestrator.model.GrainProperties) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) IOException(java.io.IOException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Aggregations

CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)142 Test (org.junit.jupiter.api.Test)25 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)24 List (java.util.List)20 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)18 IOException (java.io.IOException)18 Map (java.util.Map)18 ApiException (com.cloudera.api.swagger.client.ApiException)17 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)16 Collectors (java.util.stream.Collectors)15 Inject (javax.inject.Inject)15 Logger (org.slf4j.Logger)15 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)14 LoggerFactory (org.slf4j.LoggerFactory)14 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)13 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)12 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)12 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)12 Optional (java.util.Optional)12 Set (java.util.Set)12