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;
}
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;
}
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);
}
}
}
}
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));
}
}
}
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);
}
Aggregations