Search in sources :

Example 36 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class StackRequestToStackConverter method convertInstanceGroups.

private Set<InstanceGroup> convertInstanceGroups(StackRequest source, Stack stack) {
    List<InstanceGroupRequest> instanceGroupRequests = source.getInstanceGroups();
    Set<InstanceGroup> convertedSet = new HashSet<>();
    for (InstanceGroupRequest instanceGroupRequest : instanceGroupRequests) {
        InstanceGroup instanceGroup = getConversionService().convert(instanceGroupRequest, InstanceGroup.class);
        if (instanceGroup != null) {
            convertedSet.add(getConversionService().convert(instanceGroupRequest, InstanceGroup.class));
        }
    }
    boolean gatewaySpecified = false;
    for (InstanceGroup instanceGroup : convertedSet) {
        instanceGroup.setStack(stack);
        if (!gatewaySpecified) {
            if (InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType())) {
                gatewaySpecified = true;
            }
        }
    }
    boolean containerOrchestrator;
    try {
        containerOrchestrator = orchestratorTypeResolver.resolveType(source.getOrchestrator().getType()).containerOrchestrator();
    } catch (CloudbreakException ignored) {
        throw new BadRequestException("Orchestrator not supported.");
    }
    if (!gatewaySpecified && !containerOrchestrator) {
        throw new BadRequestException("Ambari server must be specified");
    }
    return convertedSet;
}
Also used : InstanceGroupRequest(com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HashSet(java.util.HashSet)

Example 37 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class AmbariClusterService method recreate.

@Override
public Cluster recreate(Long stackId, Long blueprintId, Set<HostGroup> hostGroups, boolean validateBlueprint, StackRepoDetails stackRepoDetails, String kerberosPassword, String kerberosPrincipal) {
    if (blueprintId == null || hostGroups == null) {
        throw new BadRequestException("Blueprint id and hostGroup assignments can not be null.");
    }
    Stack stack = stackService.getByIdWithLists(stackId);
    Cluster cluster = getCluster(stack);
    if (cluster != null && stack.getCluster().isSecure()) {
        List<String> missing = Stream.of(Pair.of("password", kerberosPassword), Pair.of("principal", kerberosPrincipal)).filter(p -> !StringUtils.hasLength(p.getRight())).map(Pair::getLeft).collect(Collectors.toList());
        if (!missing.isEmpty()) {
            throw new BadRequestException(String.format("Missing Kerberos credential detail(s): %s", String.join(", ", missing)));
        }
        KerberosConfig kerberosConfig = cluster.getKerberosConfig();
        kerberosConfig.setPassword(kerberosPassword);
        kerberosConfig.setPrincipal(kerberosPrincipal);
        kerberosConfigRepository.save(kerberosConfig);
    }
    Blueprint blueprint = blueprintService.get(blueprintId);
    if (!withEmbeddedAmbariDB(cluster)) {
        throw new BadRequestException("Ambari doesn't support resetting external DB automatically. To reset Ambari Server schema you must first drop " + "and then create it using DDL scripts from /var/lib/ambari-server/resources");
    }
    if (validateBlueprint) {
        blueprintValidator.validateBlueprintForStack(cluster, blueprint, hostGroups, stack.getInstanceGroups());
    }
    Boolean containerOrchestrator;
    try {
        containerOrchestrator = orchestratorTypeResolver.resolveType(stack.getOrchestrator()).containerOrchestrator();
    } catch (CloudbreakException ignored) {
        containerOrchestrator = false;
    }
    if (containerOrchestrator) {
        clusterTerminationService.deleteClusterComponents(cluster.getId());
        cluster = clusterRepository.findById(stack.getCluster().getId());
    }
    hostGroups = hostGroupService.saveOrUpdateWithMetadata(hostGroups, cluster);
    cluster = prepareCluster(hostGroups, stackRepoDetails, blueprint, stack, cluster);
    try {
        triggerClusterInstall(stack, cluster);
    } catch (CloudbreakException e) {
        throw new CloudbreakServiceException(e);
    }
    return stack.getCluster();
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) KerberosConfig(com.sequenceiq.cloudbreak.domain.KerberosConfig) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 38 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class ClusterTerminationService method deleteClusterComponents.

public Boolean deleteClusterComponents(Long clusterId) {
    Cluster cluster = clusterRepository.findById(clusterId);
    if (cluster == null) {
        LOGGER.warn("Failed to delete containers of cluster (id:'{}'), because the cluster could not be found in the database.", clusterId);
        return Boolean.TRUE;
    }
    OrchestratorType orchestratorType;
    try {
        orchestratorType = orchestratorTypeResolver.resolveType(cluster.getStack().getOrchestrator().getType());
    } catch (CloudbreakException e) {
        throw new TerminationFailedException(String.format("Failed to delete containers of cluster (id:'%s',name:'%s').", cluster.getId(), cluster.getName()), e);
    }
    if (orchestratorType.hostOrchestrator()) {
        return Boolean.TRUE;
    }
    return deleteClusterContainers(cluster);
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) TerminationFailedException(com.sequenceiq.cloudbreak.service.stack.flow.TerminationFailedException) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType)

Example 39 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class OrchestratorRecipeExecutor method postInstall.

public void postInstall(Stack stack) throws CloudbreakException {
    HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
    GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
    try {
        hostOrchestrator.postInstallRecipes(gatewayConfig, collectNodes(stack), clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId()));
    } catch (CloudbreakOrchestratorFailedException e) {
        throw new CloudbreakException(e);
    }
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 40 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class OrchestratorRecipeExecutor method preTerminationRecipesOnNodes.

public void preTerminationRecipesOnNodes(Stack stack, Set<Node> nodes) throws CloudbreakException {
    if (stack.getCluster() == null) {
        throw new NotFoundException("Cluster does not found, pre-termination will not be run.");
    }
    HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
    GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
    try {
        hostOrchestrator.preTerminationRecipes(gatewayConfig, nodes, clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId()));
    } catch (CloudbreakOrchestratorFailedException e) {
        throw new CloudbreakException(e);
    }
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Aggregations

CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)45 Stack (com.sequenceiq.cloudbreak.domain.Stack)23 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)22 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)18 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)14 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)13 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)13 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)13 OrchestratorType (com.sequenceiq.cloudbreak.common.model.OrchestratorType)11 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)11 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)10 HashMap (java.util.HashMap)10 List (java.util.List)10 Map (java.util.Map)10 Set (java.util.Set)9 Inject (javax.inject.Inject)9 AmbariConnectionException (com.sequenceiq.ambari.client.AmbariConnectionException)8 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)8 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8