Search in sources :

Example 31 with InstanceGroup

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

the class UpdateStackRequestV2ToUpdateStackRequestConverter method convert.

@Override
public UpdateStackJson convert(StackScaleRequestV2 source) {
    UpdateStackJson updateStackJson = new UpdateStackJson();
    updateStackJson.setWithClusterEvent(true);
    InstanceGroup instanceGroup = instanceGroupRepository.findOneByGroupNameInStack(source.getStackId(), source.getGroup());
    if (instanceGroup != null) {
        InstanceGroupAdjustmentJson instanceGroupAdjustmentJson = new InstanceGroupAdjustmentJson();
        instanceGroupAdjustmentJson.setInstanceGroup(source.getGroup());
        int scaleNumber = source.getDesiredCount() - instanceGroup.getNodeCount();
        instanceGroupAdjustmentJson.setScalingAdjustment(scaleNumber);
        updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
    } else {
        throw new BadRequestException(String.format("Group '%s' not available on stack", source.getGroup()));
    }
    return updateStackJson;
}
Also used : UpdateStackJson(com.sequenceiq.cloudbreak.api.model.UpdateStackJson) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 32 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup 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 33 with InstanceGroup

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

the class InstanceMetadataService method saveInstanceRequests.

public void saveInstanceRequests(Stack stack, Iterable<Group> groups) {
    Set<InstanceGroup> instanceGroups = stack.getInstanceGroups();
    for (Group group : groups) {
        InstanceGroup instanceGroup = getInstanceGroup(instanceGroups, group.getName());
        List<InstanceMetaData> existingInGroup = instanceMetaDataRepository.findAllByInstanceGroupAndInstanceStatus(instanceGroup, com.sequenceiq.cloudbreak.api.model.InstanceStatus.REQUESTED);
        for (CloudInstance cloudInstance : group.getInstances()) {
            InstanceTemplate instanceTemplate = cloudInstance.getTemplate();
            boolean exists = existingInGroup.stream().anyMatch(i -> i.getPrivateId().equals(instanceTemplate.getPrivateId()));
            if (InstanceStatus.CREATE_REQUESTED == instanceTemplate.getStatus() && !exists) {
                InstanceMetaData instanceMetaData = new InstanceMetaData();
                instanceMetaData.setPrivateId(instanceTemplate.getPrivateId());
                instanceMetaData.setInstanceStatus(com.sequenceiq.cloudbreak.api.model.InstanceStatus.REQUESTED);
                instanceMetaData.setInstanceGroup(instanceGroup);
                instanceMetaDataRepository.save(instanceMetaData);
            }
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 34 with InstanceGroup

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

the class StackService method validateScalingAdjustment.

private void validateScalingAdjustment(InstanceGroupAdjustmentJson instanceGroupAdjustmentJson, Stack stack) {
    if (0 == instanceGroupAdjustmentJson.getScalingAdjustment()) {
        throw new BadRequestException(String.format("Requested scaling adjustment on stack '%s' is 0. Nothing to do.", stack.getName()));
    }
    if (0 > instanceGroupAdjustmentJson.getScalingAdjustment()) {
        InstanceGroup instanceGroup = stack.getInstanceGroupByInstanceGroupName(instanceGroupAdjustmentJson.getInstanceGroup());
        if (-1 * instanceGroupAdjustmentJson.getScalingAdjustment() > instanceGroup.getNodeCount()) {
            throw new BadRequestException(String.format("There are %s instances in instance group '%s'. Cannot remove %s instances.", instanceGroup.getNodeCount(), instanceGroup.getGroupName(), -1 * instanceGroupAdjustmentJson.getScalingAdjustment()));
        }
        int removableHosts = instanceMetaDataRepository.findRemovableInstances(stack.getId(), instanceGroupAdjustmentJson.getInstanceGroup()).size();
        if (removableHosts < -1 * instanceGroupAdjustmentJson.getScalingAdjustment()) {
            throw new BadRequestException(String.format("There are %s unregistered instances in instance group '%s' but %s were requested. Decommission nodes from the cluster!", removableHosts, instanceGroup.getGroupName(), instanceGroupAdjustmentJson.getScalingAdjustment() * -1));
        }
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 35 with InstanceGroup

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

the class AmbariClusterCreationSuccessHandler method handleClusterCreationSuccess.

public void handleClusterCreationSuccess(Stack stack, Cluster cluster) {
    LOGGER.info("Cluster created successfully. Cluster name: {}", cluster.getName());
    Long now = new Date().getTime();
    cluster.setCreationFinished(now);
    cluster.setUpSince(now);
    cluster = clusterService.updateCluster(cluster);
    Collection<InstanceMetaData> updatedInstances = new ArrayList<>();
    for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
        Set<InstanceMetaData> instances = instanceGroup.getAllInstanceMetaData();
        for (InstanceMetaData instanceMetaData : instances) {
            if (!instanceMetaData.isTerminated()) {
                instanceMetaData.setInstanceStatus(InstanceStatus.REGISTERED);
                updatedInstances.add(instanceMetaData);
            }
        }
    }
    instanceMetadataRepository.save(updatedInstances);
    Collection<HostMetadata> hostMetadata = new ArrayList<>();
    for (HostMetadata host : hostMetadataRepository.findHostsInCluster(cluster.getId())) {
        host.setHostMetadataState(HostMetadataState.HEALTHY);
        hostMetadata.add(host);
    }
    hostMetadataRepository.save(hostMetadata);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ArrayList(java.util.ArrayList) Date(java.util.Date) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Aggregations

InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)89 Test (org.junit.Test)32 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)27 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)27 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)24 HashSet (java.util.HashSet)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Stack (com.sequenceiq.cloudbreak.domain.Stack)14 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)9 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)8 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)8 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)8 Matchers.anyString (org.mockito.Matchers.anyString)8 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)6 StackAuthentication (com.sequenceiq.cloudbreak.domain.StackAuthentication)6 Template (com.sequenceiq.cloudbreak.domain.Template)6 ArrayList (java.util.ArrayList)6 InstanceGroupRequest (com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest)5 StackAuthenticationRequest (com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest)5 FailurePolicy (com.sequenceiq.cloudbreak.domain.FailurePolicy)5