Search in sources :

Example 61 with Stack

use of com.sequenceiq.cloudbreak.domain.Stack in project cloudbreak by hortonworks.

the class StackService method getStackRequestByName.

public StackV2Request getStackRequestByName(String name, IdentityUser identityUser) {
    Stack stack = stackRepository.findByNameInAccountWithLists(name, identityUser.getAccount());
    if (stack == null) {
        throw new NotFoundException(String.format(STACK_NOT_FOUND_EXCEPTION_FORMAT_TEXT, name));
    }
    authorizationService.hasReadPermission(stack);
    return conversionService.convert(stack, StackV2Request.class);
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 62 with Stack

use of com.sequenceiq.cloudbreak.domain.Stack in project cloudbreak by hortonworks.

the class StackService method create.

@Transactional(TxType.NEVER)
public Stack create(IdentityUser user, Stack stack, String imageCatalog, Optional<String> imageId, Optional<Blueprint> blueprint) {
    Stack savedStack;
    stack.setOwner(user.getUserId());
    stack.setAccount(user.getAccount());
    stack.setGatewayPort(nginxPort);
    setPlatformVariant(stack);
    String stackName = stack.getName();
    MDCBuilder.buildMdcContext(stack);
    try {
        if (!stack.getStackAuthentication().passwordAuthenticationRequired() && !Strings.isNullOrEmpty(stack.getStackAuthentication().getPublicKey())) {
            long start = System.currentTimeMillis();
            rsaPublicKeyValidator.validate(stack.getStackAuthentication().getPublicKey());
            LOGGER.info("RSA key has been validated in {} ms fot stack {}", System.currentTimeMillis() - start, stackName);
        }
        if (stack.getOrchestrator() != null) {
            orchestratorRepository.save(stack.getOrchestrator());
        }
        stack.getStackAuthentication().setLoginUserName(SSH_USER_CB);
        long start = System.currentTimeMillis();
        String template = connector.getTemplate(stack);
        LOGGER.info("Get cluster template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        savedStack = stackRepository.save(stack);
        LOGGER.info("Stackrepository save took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        addTemplateForStack(stack, template);
        LOGGER.info("Save cluster template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        addCloudbreakDetailsForStack(stack);
        LOGGER.info("Add Cloudbreak template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        MDCBuilder.buildMdcContext(savedStack);
        start = System.currentTimeMillis();
        instanceGroupRepository.save(savedStack.getInstanceGroups());
        LOGGER.info("Instance groups saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        SecurityConfig securityConfig = tlsSecurityService.storeSSHKeys();
        LOGGER.info("Generating SSH keys took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        securityConfig.setSaltPassword(PasswordUtil.generatePassword());
        securityConfig.setSaltBootPassword(PasswordUtil.generatePassword());
        securityConfig.setKnoxMasterSecret(PasswordUtil.generatePassword());
        LOGGER.info("Generating salt passwords took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        securityConfig.setStack(stack);
        start = System.currentTimeMillis();
        securityConfigRepository.save(securityConfig);
        LOGGER.info("Security config save took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        savedStack.setSecurityConfig(securityConfig);
        start = System.currentTimeMillis();
        imageService.create(savedStack, connector.getPlatformParameters(stack), imageCatalog, imageId, blueprint);
        LOGGER.info("Image creation took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.STACK, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.error("Cloudbreak Image not found", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    } catch (CloudbreakImageCatalogException e) {
        LOGGER.error("Cloudbreak Image Catalog error", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    }
    return savedStack;
}
Also used : SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException) Stack(com.sequenceiq.cloudbreak.domain.Stack) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Transactional(javax.transaction.Transactional)

Example 63 with Stack

use of com.sequenceiq.cloudbreak.domain.Stack in project cloudbreak by hortonworks.

the class ClusterDecorator method prepareConnectedClusterParameters.

private void prepareConnectedClusterParameters(Cluster requestedCluster, IdentityUser user, ConnectedClusterRequest connectedClusterRequest) {
    if (connectedClusterRequest != null) {
        Long stackId;
        Stack publicStack;
        if (!Strings.isNullOrEmpty(connectedClusterRequest.getSourceClusterName())) {
            publicStack = stackService.getPublicStack(connectedClusterRequest.getSourceClusterName(), user);
            stackId = publicStack.getId();
        } else {
            stackId = connectedClusterRequest.getSourceClusterId();
            publicStack = stackService.get(connectedClusterRequest.getSourceClusterId());
        }
        // We should set the ldap to the source cluster ldap
        requestedCluster.setLdapConfig(publicStack.getCluster().getLdapConfig());
        // We should set the ranger metastore to the source cluster ranger metastore if exist!
        RDSConfig rangerRds = rdsConfigService.findByClusterIdAndType(publicStack.getOwner(), publicStack.getAccount(), publicStack.getCluster().getId(), RdsType.RANGER);
        if (rangerRds != null) {
            requestedCluster.getRdsConfigs().add(rangerRds);
        }
        try {
            Set<BlueprintParameterJson> requests = new HashSet<>();
            Json blueprintAttributes = requestedCluster.getBlueprint().getInputParameters();
            if (blueprintAttributes != null && StringUtils.isNoneEmpty(blueprintAttributes.getValue())) {
                BlueprintInputParameters inputParametersObj = blueprintAttributes.get(BlueprintInputParameters.class);
                for (BlueprintParameter blueprintParameter : inputParametersObj.getParameters()) {
                    BlueprintParameterJson blueprintParameterJson = new BlueprintParameterJson();
                    blueprintParameterJson.setName(blueprintParameter.getName());
                    blueprintParameterJson.setReferenceConfiguration(blueprintParameter.getReferenceConfiguration());
                    blueprintParameterJson.setDescription(blueprintParameter.getDescription());
                    requests.add(blueprintParameterJson);
                }
            }
            ConfigsResponse configsResponse = clusterService.retrieveOutputs(stackId, requests);
            Map<String, String> newInputs = requestedCluster.getBlueprintInputs().get(Map.class);
            for (BlueprintInputJson blueprintInputJson : configsResponse.getInputs()) {
                newInputs.put(blueprintInputJson.getName(), blueprintInputJson.getPropertyValue());
            }
            requestedCluster.setBlueprintInputs(new Json(newInputs));
        } catch (IOException e) {
            LOGGER.error("Could not propagate cluster input parameters", e);
            throw new BadRequestException("Could not propagate cluster input parameters: " + e.getMessage());
        }
    }
}
Also used : RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) ConfigsResponse(com.sequenceiq.cloudbreak.api.model.ConfigsResponse) BlueprintInputJson(com.sequenceiq.cloudbreak.api.model.BlueprintInputJson) BlueprintParameter(com.sequenceiq.cloudbreak.domain.BlueprintParameter) Json(com.sequenceiq.cloudbreak.domain.json.Json) BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson) BlueprintInputJson(com.sequenceiq.cloudbreak.api.model.BlueprintInputJson) IOException(java.io.IOException) BlueprintInputParameters(com.sequenceiq.cloudbreak.domain.BlueprintInputParameters) Stack(com.sequenceiq.cloudbreak.domain.Stack) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson) HashSet(java.util.HashSet)

Example 64 with Stack

use of com.sequenceiq.cloudbreak.domain.Stack in project cloudbreak by hortonworks.

the class HostGroupDecorator method getHostGroupByInstanceGroupName.

private HostGroup getHostGroupByInstanceGroupName(Constraint constraint, HostGroup subject, Cluster cluster, String instanceGroupName) {
    HostGroup result = subject;
    Set<HostGroup> hostGroups = hostGroupService.getByCluster(cluster.getId());
    if (hostGroups.isEmpty()) {
        Stack stack = cluster.getStack();
        if (stack == null) {
            String msg = String.format("There is no stack associated to cluster (id:'%s', name: '%s')!", cluster.getId(), cluster.getName());
            throw new BadRequestException(msg);
        } else {
            subject.setConstraint(constraint);
        }
    } else {
        result = getDetailsFromExistingHostGroup(constraint, subject, instanceGroupName, hostGroups);
    }
    return result;
}
Also used : HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 65 with Stack

use of com.sequenceiq.cloudbreak.domain.Stack in project cloudbreak by hortonworks.

the class AmbariClusterModificationService method upscaleCluster.

@Override
public void upscaleCluster(Stack stack, HostGroup hostGroup, Collection<HostMetadata> hostMetadata) throws CloudbreakException {
    AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
    List<String> upscaleHostNames = hostMetadata.stream().map(HostMetadata::getHostName).collect(Collectors.toList()).stream().filter(hostName -> !ambariClient.getClusterHosts().contains(hostName)).collect(Collectors.toList());
    if (!upscaleHostNames.isEmpty()) {
        recipeEngine.executePostAmbariStartRecipes(stack, Sets.newHashSet(hostGroup));
        Pair<PollingResult, Exception> pollingResult = ambariOperationService.waitForOperations(stack, ambariClient, installServices(upscaleHostNames, stack, ambariClient, hostGroup.getName()), UPSCALE_AMBARI_PROGRESS_STATE);
        String message = pollingResult.getRight() == null ? cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_UPSCALE_FAILED.code()) : pollingResult.getRight().getMessage();
        ambariClusterConnectorPollingResultChecker.checkPollingResult(pollingResult.getLeft(), message);
    }
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) HttpResponseException(groovyx.net.http.HttpResponseException) LoggerFactory(org.slf4j.LoggerFactory) UPDATE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.model.Status.UPDATE_IN_PROGRESS) UPSCALE_AMBARI_PROGRESS_STATE(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariOperationType.UPSCALE_AMBARI_PROGRESS_STATE) CloudbreakMessagesService(com.sequenceiq.cloudbreak.service.messages.CloudbreakMessagesService) Inject(javax.inject.Inject) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) Pair(org.apache.commons.lang3.tuple.Pair) PollingResult.isTimeout(com.sequenceiq.cloudbreak.service.PollingResult.isTimeout) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) RecipeEngine(com.sequenceiq.cloudbreak.service.cluster.flow.RecipeEngine) Service(org.springframework.stereotype.Service) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) ClusterModificationService(com.sequenceiq.cloudbreak.service.cluster.api.ClusterModificationService) Stack(com.sequenceiq.cloudbreak.domain.Stack) HostMetadataRepository(com.sequenceiq.cloudbreak.repository.HostMetadataRepository) AMBARI_CLUSTER_UPSCALE_FAILED(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariMessages.AMBARI_CLUSTER_UPSCALE_FAILED) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) AMBARI_CLUSTER_SERVICES_STOPPED(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariMessages.AMBARI_CLUSTER_SERVICES_STOPPED) Logger(org.slf4j.Logger) AMBARI_CLUSTER_SERVICES_STARTING(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariMessages.AMBARI_CLUSTER_SERVICES_STARTING) Collection(java.util.Collection) Set(java.util.Set) AmbariClientExceptionUtil(com.sequenceiq.cloudbreak.util.AmbariClientExceptionUtil) Collectors(java.util.stream.Collectors) PollingResult.isExited(com.sequenceiq.cloudbreak.service.PollingResult.isExited) Sets(com.google.common.collect.Sets) AMBARI_CLUSTER_SERVICES_STOPPING(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariMessages.AMBARI_CLUSTER_SERVICES_STOPPING) List(java.util.List) AmbariOperationService(com.sequenceiq.cloudbreak.service.cluster.flow.AmbariOperationService) STOP_AMBARI_PROGRESS_STATE(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariOperationType.STOP_AMBARI_PROGRESS_STATE) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) CloudbreakEventService(com.sequenceiq.cloudbreak.service.events.CloudbreakEventService) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) HttpResponseException(groovyx.net.http.HttpResponseException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.Stack)207 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)74 Test (org.junit.Test)70 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)32 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)30 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)26 DetailedStackStatus (com.sequenceiq.cloudbreak.api.model.DetailedStackStatus)23 ArrayList (java.util.ArrayList)20 List (java.util.List)20 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)18 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)18 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)18 HashMap (java.util.HashMap)18 HashSet (java.util.HashSet)18 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)17 Map (java.util.Map)17 Matchers.anyString (org.mockito.Matchers.anyString)16 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)15 Set (java.util.Set)15 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)14