use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method getFirstValidPrivateId.
private Long getFirstValidPrivateId(Iterable<InstanceGroup> instanceGroups) {
LOGGER.info("Get first valid PrivateId of instanceGroups");
long highest = 0;
for (InstanceGroup instanceGroup : instanceGroups) {
LOGGER.info("Checking of instanceGroup: {}", instanceGroup.getGroupName());
for (InstanceMetaData metaData : instanceGroup.getAllInstanceMetaData()) {
Long privateId = metaData.getPrivateId();
LOGGER.info("InstanceMetaData metaData: privateId: {}, instanceGroupName: {}, instanceId: {}, status: {}", privateId, metaData.getInstanceGroupName(), metaData.getInstanceId(), metaData.getInstanceStatus());
if (privateId == null) {
continue;
}
if (privateId > highest) {
highest = privateId;
}
}
}
LOGGER.info("highest privateId: {}", highest);
return highest == 0 ? 0 : highest + 1;
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class InstanceMetadataService method updateInstanceStatus.
public void updateInstanceStatus(Iterable<InstanceGroup> instanceGroup, com.sequenceiq.cloudbreak.api.model.InstanceStatus newStatus, Collection<String> candidateAddresses) {
for (InstanceGroup group : instanceGroup) {
for (InstanceMetaData instanceMetaData : group.getInstanceMetaData()) {
if (candidateAddresses.contains(instanceMetaData.getDiscoveryFQDN())) {
instanceMetaData.setInstanceStatus(newStatus);
instanceMetaDataRepository.save(instanceMetaData);
}
}
}
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class InstanceMetadataService method updateInstanceStatus.
public void updateInstanceStatus(Iterable<InstanceGroup> instanceGroup, Map<InstanceGroupType, com.sequenceiq.cloudbreak.api.model.InstanceStatus> newStatusByGroupType) {
for (InstanceGroup group : instanceGroup) {
com.sequenceiq.cloudbreak.api.model.InstanceStatus newStatus = newStatusByGroupType.get(group.getInstanceGroupType());
if (newStatus != null) {
for (InstanceMetaData instanceMetaData : group.getInstanceMetaData()) {
instanceMetaData.setInstanceStatus(newStatus);
instanceMetaDataRepository.save(instanceMetaData);
}
}
}
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class StackService method validateHostGroupAdjustment.
private void validateHostGroupAdjustment(InstanceGroupAdjustmentJson instanceGroupAdjustmentJson, Stack stack, Integer adjustment) {
Blueprint blueprint = stack.getCluster().getBlueprint();
Optional<HostGroup> hostGroup = stack.getCluster().getHostGroups().stream().filter(input -> input.getConstraint().getInstanceGroup().getGroupName().equals(instanceGroupAdjustmentJson.getInstanceGroup())).findFirst();
if (!hostGroup.isPresent()) {
throw new BadRequestException(String.format("Instancegroup '%s' not found or not part of stack '%s'", instanceGroupAdjustmentJson.getInstanceGroup(), stack.getName()));
}
blueprintValidator.validateHostGroupScalingRequest(blueprint, hostGroup.get(), adjustment);
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class ServiceProviderConnectorAdapter method removeInstances.
public Set<String> removeInstances(Stack stack, Set<String> instanceIds, String instanceGroup) {
LOGGER.debug("Assembling downscale stack event for stack: {}", stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
List<CloudInstance> instances = new ArrayList<>();
InstanceGroup group = stack.getInstanceGroupByInstanceGroupName(instanceGroup);
for (InstanceMetaData metaData : group.getAllInstanceMetaData()) {
if (instanceIds.contains(metaData.getInstanceId())) {
CloudInstance cloudInstance = metadataConverter.convert(metaData);
instances.add(cloudInstance);
}
}
CloudStack cloudStack = cloudStackConverter.convertForDownscale(stack, instanceIds);
DownscaleStackRequest downscaleRequest = new DownscaleStackRequest(cloudContext, cloudCredential, cloudStack, resources, instances);
LOGGER.info("Triggering downscale stack event: {}", downscaleRequest);
eventBus.notify(downscaleRequest.selector(), eventFactory.createEvent(downscaleRequest));
try {
DownscaleStackResult res = downscaleRequest.await();
LOGGER.info("Downscale stack result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
LOGGER.error("Failed to downscale the stack", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
return instanceIds;
} catch (InterruptedException e) {
LOGGER.error("Error while downscaling the stack", e);
throw new OperationException(e);
}
}
Aggregations