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.");
}
}
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()));
}
}
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()));
}
}
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);
}
}
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);
}
}
Aggregations