Search in sources :

Example 6 with Constraint

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

the class HostGroupDecorator method decorate.

public HostGroup decorate(HostGroup subject, HostGroupRequest hostGroupRequest, IdentityUser user, Long stackId, boolean postRequest, Boolean publicInAccount) {
    ConstraintJson constraintJson = hostGroupRequest.getConstraint();
    Set<Long> recipeIds = hostGroupRequest.getRecipeIds();
    Set<RecipeRequest> recipes = hostGroupRequest.getRecipes();
    Set<String> recipeNames = hostGroupRequest.getRecipeNames();
    LOGGER.debug("Decorating hostgroup on [{}] request.", postRequest ? "POST" : "PUT");
    Constraint constraint = conversionService.convert(constraintJson, Constraint.class);
    if (postRequest) {
        constraint = decorateConstraint(stackId, user, constraint, constraintJson.getInstanceGroupName(), constraintJson.getConstraintTemplateName());
        subject.setConstraint(constraint);
    } else {
        subject = getHostGroup(stackId, constraint, constraintJson, subject, user);
    }
    subject.getRecipes().clear();
    if (recipeIds != null) {
        prepareRecipesByIds(subject, recipeIds);
    }
    if (recipeNames != null && !recipeNames.isEmpty()) {
        prepareRecipesByName(subject, user, recipeNames);
    }
    if (recipes != null && !recipes.isEmpty()) {
        prepareRecipesByRequests(subject, user, recipes, publicInAccount);
    }
    return subject;
}
Also used : Constraint(com.sequenceiq.cloudbreak.domain.Constraint) ConstraintJson(com.sequenceiq.cloudbreak.api.model.ConstraintJson) RecipeRequest(com.sequenceiq.cloudbreak.api.model.RecipeRequest)

Example 7 with Constraint

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

the class BlueprintValidatorTest method createHostGroup.

private HostGroup createHostGroup(String groupName, InstanceGroup instanceGroup) {
    HostGroup group = new HostGroup();
    group.setName(groupName);
    Constraint constraint = new Constraint();
    constraint.setHostCount(instanceGroup.getNodeCount());
    constraint.setInstanceGroup(instanceGroup);
    group.setConstraint(constraint);
    return group;
}
Also used : Constraint(com.sequenceiq.cloudbreak.domain.Constraint) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup)

Example 8 with Constraint

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

the class ComponentLocatorServiceTest method createHostGroup.

private HostGroup createHostGroup(String name, String hostname) {
    HostGroup hg = new HostGroup();
    hg.setName(name);
    Constraint constraint = new Constraint();
    hg.setConstraint(constraint);
    InstanceGroup ig = new InstanceGroup();
    constraint.setInstanceGroup(ig);
    InstanceMetaData im = new InstanceMetaData();
    im.setDiscoveryFQDN(hostname);
    ig.setInstanceMetaData(ImmutableSet.of(im));
    return hg;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Constraint(com.sequenceiq.cloudbreak.domain.Constraint) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 9 with Constraint

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

the class AmbariClusterService method updateHostCountWithAdjustment.

@Override
public void updateHostCountWithAdjustment(Long clusterId, String hostGroupName, Integer adjustment) {
    HostGroup hostGroup = hostGroupService.getByClusterIdAndName(clusterId, hostGroupName);
    Constraint constraint = hostGroup.getConstraint();
    constraint.setHostCount(constraint.getHostCount() + adjustment);
    constraintRepository.save(constraint);
}
Also used : Constraint(com.sequenceiq.cloudbreak.domain.Constraint) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup)

Example 10 with Constraint

use of com.sequenceiq.cloudbreak.domain.Constraint 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

Constraint (com.sequenceiq.cloudbreak.domain.Constraint)12 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)9 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)5 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)3 ConstraintJson (com.sequenceiq.cloudbreak.api.model.ConstraintJson)2 HostGroupRequest (com.sequenceiq.cloudbreak.api.model.HostGroupRequest)2 RecipeRequest (com.sequenceiq.cloudbreak.api.model.RecipeRequest)2 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)2 Selectable (com.sequenceiq.cloudbreak.cloud.event.Selectable)1 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)1 ClusterAndStackDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent)1 ClusterDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleTriggerEvent)1 ClusterScaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterScaleTriggerEvent)1 StackDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent)1 StackScaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent)1 ConstraintTemplate (com.sequenceiq.cloudbreak.domain.ConstraintTemplate)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)1 Recipe (com.sequenceiq.cloudbreak.domain.Recipe)1 Stack (com.sequenceiq.cloudbreak.domain.Stack)1 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)1