Search in sources :

Example 81 with HostGroup

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

the class AmbariClusterService method create.

@Override
@Transactional(TxType.NEVER)
public Cluster create(IdentityUser user, Stack stack, Cluster cluster, List<ClusterComponent> components) {
    LOGGER.info("Cluster requested [BlueprintId: {}]", cluster.getBlueprint().getId());
    String stackName = stack.getName();
    if (stack.getCluster() != null) {
        throw new BadRequestException(String.format("A cluster is already created on this stack! [cluster: '%s']", stack.getCluster().getName()));
    }
    long start = System.currentTimeMillis();
    if (clusterRepository.findByNameInAccount(cluster.getName(), user.getAccount()) != null) {
        throw new DuplicateKeyValueException(APIResourceType.CLUSTER, cluster.getName());
    }
    LOGGER.info("Cluster name collision check took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    if (Status.CREATE_FAILED.equals(stack.getStatus())) {
        throw new BadRequestException("Stack creation failed, cannot create cluster.");
    }
    start = System.currentTimeMillis();
    for (HostGroup hostGroup : cluster.getHostGroups()) {
        constraintRepository.save(hostGroup.getConstraint());
    }
    LOGGER.info("Host group constrainst saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    start = System.currentTimeMillis();
    if (cluster.getFileSystem() != null) {
        fileSystemRepository.save(cluster.getFileSystem());
    }
    LOGGER.info("Filesystem config saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    if (cluster.getKerberosConfig() != null) {
        kerberosConfigRepository.save(cluster.getKerberosConfig());
    }
    cluster.setStack(stack);
    cluster.setOwner(user.getUserId());
    cluster.setAccount(user.getAccount());
    stack.setCluster(cluster);
    start = System.currentTimeMillis();
    generateSignKeys(cluster.getGateway());
    LOGGER.info("Sign key generated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    try {
        start = System.currentTimeMillis();
        cluster = clusterRepository.save(cluster);
        LOGGER.info("Cluster object saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        clusterComponentConfigProvider.store(components, cluster);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.CLUSTER, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    }
    if (stack.isAvailable()) {
        flowManager.triggerClusterInstall(stack.getId());
        InMemoryStateStore.putCluster(cluster.getId(), statusToPollGroupConverter.convert(cluster.getStatus()));
        if (InMemoryStateStore.getStack(stack.getId()) == null) {
            InMemoryStateStore.putStack(stack.getId(), statusToPollGroupConverter.convert(stack.getStatus()));
        }
    }
    return cluster;
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) DuplicateKeyValueException(com.sequenceiq.cloudbreak.service.DuplicateKeyValueException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Transactional(javax.transaction.Transactional)

Example 82 with HostGroup

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

the class AmbariClusterService method validateRequest.

private boolean validateRequest(Stack stack, HostGroupAdjustmentJson hostGroupAdjustment) {
    HostGroup hostGroup = getHostGroup(stack, hostGroupAdjustment);
    int scalingAdjustment = hostGroupAdjustment.getScalingAdjustment();
    boolean downScale = scalingAdjustment < 0;
    if (scalingAdjustment == 0) {
        throw new BadRequestException("No scaling adjustments specified. Nothing to do.");
    }
    blueprintValidator.validateHostGroupScalingRequest(stack.getCluster().getBlueprint(), hostGroup, scalingAdjustment);
    if (!downScale && hostGroup.getConstraint().getInstanceGroup() != null) {
        validateUnusedHosts(hostGroup.getConstraint().getInstanceGroup(), scalingAdjustment);
    } else {
        validateRegisteredHosts(stack, hostGroupAdjustment);
        if (hostGroupAdjustment.getWithStackUpdate() && hostGroupAdjustment.getScalingAdjustment() > 0) {
            throw new BadRequestException("ScalingAdjustment has to be decommission if you define withStackUpdate = 'true'.");
        }
    }
    return downScale;
}
Also used : HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Constraint(com.sequenceiq.cloudbreak.domain.Constraint)

Example 83 with HostGroup

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

the class AmbariClusterService method updateHostMetadata.

@Override
public void updateHostMetadata(Long clusterId, Map<String, List<String>> hostsPerHostGroup, HostMetadataState hostMetadataState) {
    for (Entry<String, List<String>> hostGroupEntry : hostsPerHostGroup.entrySet()) {
        HostGroup hostGroup = hostGroupService.getByClusterIdAndName(clusterId, hostGroupEntry.getKey());
        if (hostGroup != null) {
            Set<String> existingHosts = hostMetadataRepository.findEmptyHostsInHostGroup(hostGroup.getId()).stream().map(HostMetadata::getHostName).collect(Collectors.toSet());
            hostGroupEntry.getValue().stream().filter(hostName -> !existingHosts.contains(hostName)).forEach(hostName -> {
                HostMetadata hostMetadataEntry = new HostMetadata();
                hostMetadataEntry.setHostName(hostName);
                hostMetadataEntry.setHostGroup(hostGroup);
                hostMetadataEntry.setHostMetadataState(hostMetadataState);
                hostGroup.getHostMetadata().add(hostMetadataEntry);
            });
            hostGroupService.save(hostGroup);
        }
    }
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) KeyPair(java.security.KeyPair) Arrays(java.util.Arrays) InstanceMetaDataRepository(com.sequenceiq.cloudbreak.repository.InstanceMetaDataRepository) HttpResponseException(groovyx.net.http.HttpResponseException) StatusToPollGroupConverter(com.sequenceiq.cloudbreak.converter.scheduler.StatusToPollGroupConverter) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) CloudbreakMessagesService(com.sequenceiq.cloudbreak.service.messages.CloudbreakMessagesService) Pair(org.apache.commons.lang3.tuple.Pair) RdsConfigService(com.sequenceiq.cloudbreak.service.rdsconfig.RdsConfigService) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) HostMetadataRepository(com.sequenceiq.cloudbreak.repository.HostMetadataRepository) TxType(javax.transaction.Transactional.TxType) Transactional(javax.transaction.Transactional) BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson) TlsSecurityService(com.sequenceiq.cloudbreak.service.TlsSecurityService) ClusterTerminationService(com.sequenceiq.cloudbreak.service.cluster.flow.ClusterTerminationService) START_REQUESTED(com.sequenceiq.cloudbreak.api.model.Status.START_REQUESTED) Set(java.util.Set) BlueprintValidator(com.sequenceiq.cloudbreak.blueprint.validation.BlueprintValidator) UserNamePasswordJson(com.sequenceiq.cloudbreak.api.model.UserNamePasswordJson) ClusterRepository(com.sequenceiq.cloudbreak.repository.ClusterRepository) Stream(java.util.stream.Stream) STOP_REQUESTED(com.sequenceiq.cloudbreak.api.model.Status.STOP_REQUESTED) InstanceStatus(com.sequenceiq.cloudbreak.api.model.InstanceStatus) PkiUtil(com.sequenceiq.cloudbreak.client.PkiUtil) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) ArrayList(java.util.ArrayList) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) Service(org.springframework.stereotype.Service) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) KerberosConfigRepository(com.sequenceiq.cloudbreak.repository.KerberosConfigRepository) ClusterComponentConfigProvider(com.sequenceiq.cloudbreak.service.ClusterComponentConfigProvider) Stack(com.sequenceiq.cloudbreak.domain.Stack) ConversionService(org.springframework.core.convert.ConversionService) ClusterResponse(com.sequenceiq.cloudbreak.api.model.ClusterResponse) DuplicateKeyValueException(com.sequenceiq.cloudbreak.service.DuplicateKeyValueException) InMemoryStateStore(com.sequenceiq.cloudbreak.cloud.store.InMemoryStateStore) IOException(java.io.IOException) ConstraintRepository(com.sequenceiq.cloudbreak.repository.ConstraintRepository) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) StatusRequest(com.sequenceiq.cloudbreak.api.model.StatusRequest) StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) X509Certificate(java.security.cert.X509Certificate) KerberosConfig(com.sequenceiq.cloudbreak.domain.KerberosConfig) ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) AmbariRepo(com.sequenceiq.cloudbreak.cloud.model.AmbariRepo) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Gateway(com.sequenceiq.cloudbreak.domain.Gateway) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) AuthorizationService(com.sequenceiq.cloudbreak.service.AuthorizationService) SqlUtil.getProperSqlErrorMessage(com.sequenceiq.cloudbreak.util.SqlUtil.getProperSqlErrorMessage) FileSystemRepository(com.sequenceiq.cloudbreak.repository.FileSystemRepository) HostMetadataState(com.sequenceiq.cloudbreak.common.type.HostMetadataState) Constraint(com.sequenceiq.cloudbreak.domain.Constraint) REQUESTED(com.sequenceiq.cloudbreak.api.model.Status.REQUESTED) StackStatus(com.sequenceiq.cloudbreak.domain.StackStatus) Collection(java.util.Collection) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) Collectors(java.util.stream.Collectors) List(java.util.List) Entry(java.util.Map.Entry) UPDATE_REQUESTED(com.sequenceiq.cloudbreak.api.model.Status.UPDATE_REQUESTED) ReactorFlowManager(com.sequenceiq.cloudbreak.core.flow2.service.ReactorFlowManager) RdsType(com.sequenceiq.cloudbreak.api.model.rds.RdsType) HashMap(java.util.HashMap) RecoveryMode(com.sequenceiq.cloudbreak.api.model.RecoveryMode) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Status(com.sequenceiq.cloudbreak.api.model.Status) JsonHelper(com.sequenceiq.cloudbreak.json.JsonHelper) OrchestratorTypeResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.OrchestratorTypeResolver) Qualifier(org.springframework.beans.factory.annotation.Qualifier) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) Json(com.sequenceiq.cloudbreak.domain.json.Json) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Logger(org.slf4j.Logger) DatabaseVendor(com.sequenceiq.cloudbreak.api.model.DatabaseVendor) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) AVAILABLE(com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AmbariClientExceptionUtil(com.sequenceiq.cloudbreak.util.AmbariClientExceptionUtil) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) BlueprintInputJson(com.sequenceiq.cloudbreak.api.model.BlueprintInputJson) APIResourceType(com.sequenceiq.cloudbreak.common.type.APIResourceType) ConfigsResponse(com.sequenceiq.cloudbreak.api.model.ConfigsResponse) Collections(java.util.Collections) JsonUtil(com.sequenceiq.cloudbreak.util.JsonUtil) CloudbreakEventService(com.sequenceiq.cloudbreak.service.events.CloudbreakEventService) StringUtils(org.springframework.util.StringUtils) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) ArrayList(java.util.ArrayList) List(java.util.List) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 84 with HostGroup

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

the class ClusterDecorator method convertHostGroupsFromJson.

private Set<HostGroup> convertHostGroupsFromJson(Stack stack, IdentityUser user, Cluster cluster, Iterable<HostGroupRequest> hostGroupsJsons) {
    Set<HostGroup> hostGroups = new HashSet<>();
    for (HostGroupRequest json : hostGroupsJsons) {
        HostGroup hostGroup = conversionService.convert(json, HostGroup.class);
        hostGroup.setCluster(cluster);
        hostGroup = hostGroupDecorator.decorate(hostGroup, json, user, stack.getId(), true, stack.isPublicInAccount());
        hostGroups.add(hostGroup);
    }
    return hostGroups;
}
Also used : HostGroupRequest(com.sequenceiq.cloudbreak.api.model.HostGroupRequest) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) HashSet(java.util.HashSet)

Example 85 with HostGroup

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

the class HostGroupDecorator method getHostGroup.

private HostGroup getHostGroup(Long stackId, Constraint constraint, ConstraintJson constraintJson, HostGroup subject, IdentityUser user) {
    if (constraintJson == null) {
        throw new BadRequestException("The constraint field must be set in the reinstall request!");
    }
    HostGroup result = subject;
    String instanceGroupName = constraintJson.getInstanceGroupName();
    String constraintTemplateName = constraintJson.getConstraintTemplateName();
    Cluster cluster = clusterService.retrieveClusterByStackId(stackId);
    Constraint decoratedConstraint = decorateConstraint(stackId, user, constraint, instanceGroupName, constraintTemplateName);
    if (!isEmpty(instanceGroupName)) {
        result = getHostGroupByInstanceGroupName(decoratedConstraint, subject, cluster, instanceGroupName);
    } else if (!isEmpty(constraintTemplateName)) {
        subject.setConstraint(constraintRepository.save(constraint));
    } else {
        throw new BadRequestException("The constraint field must contain the 'constraintTemplateName' or 'instanceGroupName' parameter!");
    }
    return result;
}
Also used : Constraint(com.sequenceiq.cloudbreak.domain.Constraint) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Cluster(com.sequenceiq.cloudbreak.domain.Cluster)

Aggregations

HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)94 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)33 Test (org.junit.Test)33 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)31 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)29 HashSet (java.util.HashSet)22 JsonNode (com.fasterxml.jackson.databind.JsonNode)20 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)20 List (java.util.List)20 HashMap (java.util.HashMap)19 Stack (com.sequenceiq.cloudbreak.domain.Stack)18 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)16 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)15 Map (java.util.Map)14 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)13 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)12 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)11 ArrayList (java.util.ArrayList)11 Set (java.util.Set)11 Inject (javax.inject.Inject)11