Search in sources :

Example 1 with Constraint

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

the class ContainerConstraintFactory method getAmbariAgentConstraint.

public ContainerConstraint getAmbariAgentConstraint(String ambariServerHost, String ambariAgentApp, String cloudPlatform, HostGroup hostGroup, Integer adjustment, List<String> hostBlackList, String identifier) {
    String containerInstanceName;
    containerInstanceName = YARN.equals(hostGroup.getCluster().getStack().getOrchestrator().getType()) ? createContainerInstanceNameForYarn(hostGroup, AMBARI_AGENT.getName(), identifier) : createContainerInstanceName(hostGroup, AMBARI_AGENT.getName(), identifier);
    Constraint hgConstraint = hostGroup.getConstraint();
    Builder builder = new Builder().withNamePrefix(containerInstanceName).withAppName(ambariAgentApp).networkMode(HOST_NETWORK_MODE);
    if (hgConstraint.getInstanceGroup() != null) {
        InstanceGroup instanceGroup = hgConstraint.getInstanceGroup();
        Map<String, String> dataVolumeBinds = new HashMap<>();
        dataVolumeBinds.put("/var/log/ambari-agent-container", CONTAINER_VOLUME_PATH);
        dataVolumeBinds.put(HADOOP_MOUNT_DIR, HADOOP_MOUNT_DIR);
        dataVolumeBinds.putAll(ImmutableMap.of("/data/jars", "/data/jars", HOST_VOLUME_PATH, CONTAINER_VOLUME_PATH));
        builder.addVolumeBindings(dataVolumeBinds);
        if (adjustment != null) {
            List<String> candidates = collectUpscaleCandidates(hostGroup.getCluster().getId(), hostGroup.getName(), adjustment);
            builder.addHosts(getHosts(candidates, instanceGroup));
        } else {
            builder.addHosts(getHosts(null, instanceGroup));
        }
        builder.cmd(new String[] { String.format("/usr/sbin/init systemd.setenv=AMBARI_SERVER_ADDR=%s systemd.setenv=CLOUD_PLATFORM=%s", ambariServerHost, cloudPlatform) });
    }
    if (hgConstraint.getConstraintTemplate() != null) {
        builder.cpus(hgConstraint.getConstraintTemplate().getCpu());
        builder.memory(hgConstraint.getConstraintTemplate().getMemory());
        builder.constraints(getConstraints(hostBlackList));
        if (adjustment != null) {
            builder.instances(adjustment);
        } else {
            builder.instances(hgConstraint.getHostCount());
        }
        builder.withDiskSize(hgConstraint.getConstraintTemplate().getDisk());
        Map<String, String> dataVolumeBinds = new HashMap<>();
        dataVolumeBinds.put("/var/log/ambari-agent-container", CONTAINER_VOLUME_PATH);
        builder.addVolumeBindings(dataVolumeBinds);
        builder.cmd(new String[] { String.format("/usr/sbin/init systemd.setenv=AMBARI_SERVER_ADDR=%s systemd.setenv=USE_CONSUL_DNS=false", ambariServerHost) });
    }
    return builder.build();
}
Also used : ContainerConstraint(com.sequenceiq.cloudbreak.orchestrator.model.ContainerConstraint) Constraint(com.sequenceiq.cloudbreak.domain.Constraint) HashMap(java.util.HashMap) Builder(com.sequenceiq.cloudbreak.orchestrator.model.ContainerConstraint.Builder) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 2 with Constraint

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

the class ClusterTerminationService method deleteClusterHostGroupsWithItsMetadata.

private void deleteClusterHostGroupsWithItsMetadata(Cluster cluster) {
    Set<HostGroup> hostGroups = hostGroupRepository.findHostGroupsInCluster(cluster.getId());
    Collection<Constraint> constraintsToDelete = new LinkedList<>();
    for (HostGroup hg : hostGroups) {
        hg.getRecipes().clear();
        Constraint constraint = hg.getConstraint();
        if (constraint != null) {
            constraintsToDelete.add(constraint);
        }
    }
    hostGroupRepository.delete(hostGroups);
    constraintRepository.delete(constraintsToDelete);
    cluster.getHostGroups().clear();
    cluster.getContainers().clear();
    clusterRepository.save(cluster);
}
Also used : Constraint(com.sequenceiq.cloudbreak.domain.Constraint) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) LinkedList(java.util.LinkedList)

Example 3 with Constraint

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

the class ConstraintRequestToConstraintConverter method convert.

@Override
public Constraint convert(ConstraintJson source) {
    Constraint constraint = new Constraint();
    constraint.setHostCount(source.getHostCount());
    return constraint;
}
Also used : Constraint(com.sequenceiq.cloudbreak.domain.Constraint)

Example 4 with Constraint

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

the class StackValidationRequestToStackValidationConverter method convertHostGroupsFromJson.

private Set<HostGroup> convertHostGroupsFromJson(Collection<InstanceGroup> instanceGroups, Iterable<HostGroupRequest> hostGroupsJsons) {
    Set<HostGroup> hostGroups = new HashSet<>();
    for (HostGroupRequest json : hostGroupsJsons) {
        HostGroup hostGroup = new HostGroup();
        hostGroup.setName(json.getName());
        Constraint constraint = getConversionService().convert(json.getConstraint(), Constraint.class);
        String instanceGroupName = json.getConstraint().getInstanceGroupName();
        if (instanceGroupName != null) {
            InstanceGroup instanceGroup = instanceGroups.stream().filter(instanceGroup1 -> instanceGroup1.getGroupName().equals(instanceGroupName)).findFirst().get();
            if (instanceGroup == null) {
                throw new BadRequestException(String.format("Cannot find instance group named '%s' in instance group list", instanceGroupName));
            }
            constraint.setInstanceGroup(instanceGroup);
        }
        hostGroup.setConstraint(constraint);
        hostGroups.add(hostGroup);
    }
    return hostGroups;
}
Also used : Constraint(com.sequenceiq.cloudbreak.domain.Constraint) HostGroupRequest(com.sequenceiq.cloudbreak.api.model.HostGroupRequest) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HashSet(java.util.HashSet) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 5 with Constraint

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

the class HostGroupDecorator method getDetailsFromExistingHostGroup.

private HostGroup getDetailsFromExistingHostGroup(Constraint constraint, HostGroup subject, String instanceGroupName, Collection<HostGroup> hostGroups) {
    Optional<HostGroup> hostGroupOptional = hostGroups.stream().filter(input -> input.getConstraint().getInstanceGroup().getGroupName().equals(instanceGroupName)).findFirst();
    if (hostGroupOptional.isPresent()) {
        HostGroup hostGroup = hostGroupOptional.get();
        Integer instanceGroupNodeCount = hostGroup.getConstraint().getInstanceGroup().getNodeCount();
        if (constraint.getHostCount() > instanceGroupNodeCount) {
            throw new BadRequestException(String.format("The 'hostCount' of host group '%s' constraint could not be more than '%s'!", subject.getName(), instanceGroupNodeCount));
        }
        hostGroup.getConstraint().setHostCount(constraint.getHostCount());
        hostGroup.setName(subject.getName());
        return hostGroup;
    } else {
        throw new BadRequestException(String.format("Invalid 'instanceGroupName'! Could not find instance group with name: '%s'", instanceGroupName));
    }
}
Also used : RecipeService(com.sequenceiq.cloudbreak.service.recipe.RecipeService) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) LoggerFactory(org.slf4j.LoggerFactory) RecipeRequest(com.sequenceiq.cloudbreak.api.model.RecipeRequest) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) ConstraintTemplateRepository(com.sequenceiq.cloudbreak.repository.ConstraintTemplateRepository) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Inject(javax.inject.Inject) ConstraintTemplate(com.sequenceiq.cloudbreak.domain.ConstraintTemplate) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) ConstraintJson(com.sequenceiq.cloudbreak.api.model.ConstraintJson) Stack(com.sequenceiq.cloudbreak.domain.Stack) ConversionService(org.springframework.core.convert.ConversionService) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Constraint(com.sequenceiq.cloudbreak.domain.Constraint) Logger(org.slf4j.Logger) Collection(java.util.Collection) InstanceGroupRepository(com.sequenceiq.cloudbreak.repository.InstanceGroupRepository) Set(java.util.Set) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Recipe(com.sequenceiq.cloudbreak.domain.Recipe) Component(org.springframework.stereotype.Component) HostGroupRequest(com.sequenceiq.cloudbreak.api.model.HostGroupRequest) ConstraintRepository(com.sequenceiq.cloudbreak.repository.ConstraintRepository) StringUtils.isEmpty(org.springframework.util.StringUtils.isEmpty) Optional(java.util.Optional) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

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