use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class EmbeddedDatabaseService method calculateVolumeCountOnGatewayGroup.
private int calculateVolumeCountOnGatewayGroup(Stack stack) {
Optional<InstanceGroup> gatewayGroup = stack.getInstanceGroups().stream().filter(ig -> ig.getInstanceGroupType() == InstanceGroupType.GATEWAY).findFirst();
Template template = gatewayGroup.map(InstanceGroup::getTemplate).orElse(null);
return template == null ? 0 : template.getVolumeTemplates().stream().filter(volumeTemplate -> volumeTemplate.getUsageType() == VolumeUsageType.DATABASE).mapToInt(VolumeTemplate::getVolumeCount).sum();
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class StackDecorator method prepareInstanceGroups.
private void prepareInstanceGroups(Stack subject, StackV4Request request, Credential credential, User user, DetailedEnvironmentResponse environment) {
Map<String, InstanceGroupParameterResponse> instanceGroupParameterResponse = cloudParameterService.getInstanceGroupParameters(extendedCloudCredentialConverter.convert(credential), getInstanceGroupParameterRequests(subject));
CloudbreakUser cloudbreakUser = legacyRestRequestThreadLocalService.getCloudbreakUser();
subject.getInstanceGroups().parallelStream().forEach(instanceGroup -> {
subject.getCluster().getHostGroups().stream().filter(hostGroup -> hostGroup.getName().equals(instanceGroup.getGroupName())).forEach(hostGroup -> hostGroup.setInstanceGroup(instanceGroup));
legacyRestRequestThreadLocalService.setCloudbreakUser(cloudbreakUser);
updateInstanceGroupParameters(instanceGroupParameterResponse, instanceGroup);
if (instanceGroup.getTemplate() != null) {
Template template = instanceGroup.getTemplate();
if (template.getId() == null) {
template.setCloudPlatform(credential.cloudPlatform());
PlacementSettingsV4Request placement = request.getPlacement();
String availabilityZone = placement != null ? placement.getAvailabilityZone() : subject.getAvailabilityZone();
String region = placement != null ? placement.getRegion() : subject.getRegion();
CdpResourceType cdpResourceType = cdpResourceTypeProvider.fromStackType(request.getType());
template = templateDecorator.decorate(credential, template, region, availabilityZone, subject.getPlatformVariant(), cdpResourceType);
template.setWorkspace(subject.getWorkspace());
setupDatabaseAttachedVolume(subject, instanceGroup, template);
template = templateService.create(user, template);
instanceGroup.setTemplate(template);
}
}
if (instanceGroup.getSecurityGroup() != null) {
SecurityGroup securityGroup = instanceGroup.getSecurityGroup();
if (securityGroup.getId() == null) {
securityGroup.setCloudPlatform(credential.cloudPlatform());
securityGroup.setWorkspace(subject.getWorkspace());
securityGroup = securityGroupService.create(user, securityGroup);
instanceGroup.setSecurityGroup(securityGroup);
}
}
if (instanceGroup.getInstanceGroupNetwork() != null) {
InstanceGroupNetwork ign = instanceGroup.getInstanceGroupNetwork();
instanceGroup.setAvailabilityZones(getAvailabilityZoneFromEnv(instanceGroup, environment));
if (ign.getId() == null) {
ign.setCloudPlatform(credential.cloudPlatform());
ign = instanceGroupNetworkService.create(ign);
instanceGroup.setInstanceGroupNetwork(ign);
}
}
});
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class MetadataSetupService method cleanupRequestedInstancesIfNotInList.
public void cleanupRequestedInstancesIfNotInList(Long stackId, Set<String> instanceGroups, Set<Long> privateIds) {
LOGGER.info("Cleanup the requested instances if private id not in {}", privateIds);
for (String instanceGroupName : instanceGroups) {
Optional<InstanceGroup> instanceGroup = instanceGroupService.findOneByStackIdAndGroupName(stackId, instanceGroupName);
instanceGroup.ifPresent(ig -> {
List<InstanceMetaData> requestedInstanceMetaDatas = instanceMetaDataService.findAllByInstanceGroupAndInstanceStatus(ig, InstanceStatus.REQUESTED);
LOGGER.info("Instances in requested state: {}", requestedInstanceMetaDatas);
List<InstanceMetaData> removableInstanceMetaDatas = requestedInstanceMetaDatas.stream().filter(instanceMetaData -> !privateIds.contains(instanceMetaData.getPrivateId())).collect(Collectors.toList());
LOGGER.info("Cleanup the following instances: {}", requestedInstanceMetaDatas);
for (InstanceMetaData removableInstanceMetaData : removableInstanceMetaDatas) {
removableInstanceMetaData.setTerminationDate(clock.getCurrentTimeMillis());
removableInstanceMetaData.setInstanceStatus(InstanceStatus.TERMINATED);
}
instanceMetaDataService.saveAll(removableInstanceMetaDatas);
});
}
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class GatewaySecurityGroupDecorator method extendGatewaysSecurityGroupsWithRules.
private void extendGatewaysSecurityGroupsWithRules(Stack stack, Set<InstanceGroup> gateways, Set<String> defaultGatewayCidrs) {
for (InstanceGroup gateway : gateways) {
SecurityGroup securityGroup = createNewSecurityGroupIfNotPresent(gateway);
LOGGER.debug("InstanceGroupName: [{}] SecurityGoupIds: [{}]", gateway.getGroupName(), securityGroup.getSecurityGroupIds());
if (CollectionUtils.isEmpty(securityGroup.getSecurityGroupIds())) {
addSecurityRuleToSecurityGroup(stack, defaultGatewayCidrs, gateway);
}
}
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class InstanceMetaDataService method saveInstanceAndGetUpdatedStack.
public Stack saveInstanceAndGetUpdatedStack(Stack stack, Map<String, Integer> hostGroupsWithInstanceCountToCreate, Map<String, Set<String>> hostGroupWithHostnames, boolean save, boolean repair, NetworkScaleDetails networkScaleDetails) {
LOGGER.info("Get updated stack with instance count ({}) and hostnames: {} and save: ({})", hostGroupsWithInstanceCountToCreate, hostGroupWithHostnames, save);
DetailedEnvironmentResponse environment = getDetailedEnvironmentResponse(stack.getEnvironmentCrn());
Map<String, String> subnetAzPairs = multiAzCalculatorService.prepareSubnetAzMap(environment);
String stackSubnetId = getStackSubnetIdIfExists(stack);
String stackAz = stackSubnetId == null ? null : subnetAzPairs.get(stackSubnetId);
long privateId = getFirstValidPrivateId(stack.getInstanceGroupsAsList());
for (Map.Entry<String, Integer> hostGroupWithInstanceCount : hostGroupsWithInstanceCountToCreate.entrySet()) {
String hostGroup = hostGroupWithInstanceCount.getKey();
Integer instanceToCreate = hostGroupWithInstanceCount.getValue();
Iterator<String> hostNameIterator = getHostNameIterator(hostGroupWithHostnames.get(hostGroup));
for (int i = 0; i < instanceToCreate; i++) {
InstanceGroup instanceGroup = getInstanceGroup(stack.getInstanceGroups(), hostGroup);
if (instanceGroup != null) {
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setPrivateId(privateId++);
instanceMetaData.setInstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.REQUESTED);
instanceMetaData.setInstanceGroup(instanceGroup);
instanceMetaData.setVariant(stack.getPlatformVariant());
if (hostNameIterator.hasNext()) {
String hostName = hostNameIterator.next();
repository.findHostInStack(stack.getId(), hostName).ifPresent(existingHost -> {
throw new CloudbreakServiceException("There is an existing host with the same FQDN. It can happen if you retried a failed repair. " + "Please start the repairing process again instead of retry.");
});
LOGGER.info("We have hostname to be allocated: {}, set it to this instanceMetadata: {}", hostName, instanceMetaData);
instanceMetaData.setDiscoveryFQDN(hostName);
subnetAzPairs = getSubnetAzPairsFilteredByHostNameIfRepair(environment, stack, repair, instanceGroup.getGroupName(), hostName);
}
Map<String, String> filteredSubnetsByLeastUsedAz = networkScaleDetails == null ? multiAzCalculatorService.filterSubnetByLeastUsedAz(instanceGroup, subnetAzPairs) : subnetAzPairs;
prepareInstanceMetaDataSubnetAndAvailabilityZoneAndRackId(instanceGroup, instanceMetaData, filteredSubnetsByLeastUsedAz, stackSubnetId, stackAz, networkScaleDetails);
if (save) {
repository.save(instanceMetaData);
}
instanceGroup.getInstanceMetaDataSet().add(instanceMetaData);
}
}
}
return stack;
}
Aggregations