use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.
the class UpgradeService method upgradeFreeIpa.
@SuppressWarnings("IllegalType")
public FreeIpaUpgradeResponse upgradeFreeIpa(String accountId, FreeIpaUpgradeRequest request) {
validationService.validateEntitlement(accountId);
Stack stack = stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(request.getEnvironmentCrn(), accountId);
Set<InstanceMetaData> allInstances = stack.getNotDeletedInstanceMetaDataSet();
validationService.validateStackForUpgrade(allInstances, stack);
String pgwInstanceId = instanceMetaDataService.getPrimaryGwInstance(allInstances).getInstanceId();
HashSet<String> nonPgwInstanceIds = selectNonPgwInstanceIds(allInstances);
ImageInfoResponse currentImage = imageService.fetchCurrentImage(stack);
ImageSettingsRequest imageSettingsRequest = assembleImageSettingsRequest(request, currentImage);
ImageInfoResponse selectedImage = imageService.selectImage(stack, imageSettingsRequest);
validationService.validateSelectedImageDifferentFromCurrent(currentImage, selectedImage);
return triggerUpgrade(request, stack, pgwInstanceId, nonPgwInstanceIds, imageSettingsRequest, selectedImage, currentImage);
}
use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.
the class UpgradeCcmOrchestratorService method createStateParams.
private OrchestratorStateParams createStateParams(Long stackId, String saltState) {
Stack stack = stackService.getByIdWithListsInTransaction(stackId);
Set<InstanceMetaData> instanceMetaDatas = stack.getNotDeletedInstanceMetaDataSet();
Set<Node> allNodes = freeIpaNodeUtilService.mapInstancesToNodes(instanceMetaDatas);
OrchestratorStateParams stateParams = new OrchestratorStateParams();
stateParams.setState(saltState);
stateParams.setPrimaryGatewayConfig(gatewayConfigService.getPrimaryGatewayConfig(stack));
stateParams.setTargetHostNames(allNodes.stream().map(Node::getHostname).collect(Collectors.toSet()));
stateParams.setAllNodes(allNodes);
stateParams.setExitCriteriaModel(new StackBasedExitCriteriaModel(stack.getId()));
return stateParams;
}
use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.
the class InstanceMetaDataService method saveInstanceRequests.
public void saveInstanceRequests(Stack stack, List<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.freeipa.api.v1.freeipa.stack.model.common.instance.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.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus.REQUESTED);
instanceMetaData.setInstanceGroup(instanceGroup);
instanceMetaData.setVariant(stack.getPlatformvariant());
instanceMetaDataRepository.save(instanceMetaData);
}
}
}
}
use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.
the class InstanceMetaDataService method saveInstanceAndGetUpdatedStack.
public Stack saveInstanceAndGetUpdatedStack(Stack stack, List<CloudInstance> cloudInstances) {
FreeIpa freeIpa = freeIpaService.findByStack(stack);
DetailedEnvironmentResponse environment = measure(() -> cachedEnvironmentClientService.getByCrn(stack.getEnvironmentCrn()), LOGGER, "Environment properties were queried under {} ms for environment {}", stack.getEnvironmentCrn());
Map<String, List<CloudInstance>> instancesPerGroup = cloudInstances.stream().collect(Collectors.groupingBy(cloudInstance -> cloudInstance.getTemplate().getGroupName()));
for (Map.Entry<String, List<CloudInstance>> instancesPerGroupEntry : instancesPerGroup.entrySet()) {
InstanceGroup instanceGroup = getInstanceGroup(stack.getInstanceGroups(), instancesPerGroupEntry.getKey());
if (instanceGroup != null) {
Map<String, String> subnetAzMap = multiAzCalculatorService.prepareSubnetAzMap(environment);
Map<String, Integer> currentSubnetUsage = multiAzCalculatorService.calculateCurrentSubnetUsage(subnetAzMap, instanceGroup);
for (CloudInstance cloudInstance : instancesPerGroupEntry.getValue()) {
InstanceMetaData instanceMetaData = new InstanceMetaData();
Long privateId = cloudInstance.getTemplate().getPrivateId();
instanceMetaData.setPrivateId(privateId);
instanceMetaData.setInstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus.REQUESTED);
instanceMetaData.setInstanceGroup(instanceGroup);
instanceMetaData.setDiscoveryFQDN(freeIpa.getHostname() + String.format("%d.", privateId) + freeIpa.getDomain());
if (!subnetAzMap.isEmpty()) {
Map<String, String> filteredSubnetsByLeastUsedAz = multiAzCalculatorService.filterSubnetByLeastUsedAz(instanceGroup, subnetAzMap);
multiAzCalculatorService.updateSubnetIdForSingleInstanceIfEligible(filteredSubnetsByLeastUsedAz, currentSubnetUsage, instanceMetaData, instanceGroup);
}
instanceMetaDataRepository.save(instanceMetaData);
LOGGER.debug("Saved InstanceMetaData: {}", instanceMetaData);
instanceGroup.getInstanceMetaDataSet().add(instanceMetaData);
}
}
}
return stack;
}
use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.
the class InstanceMetaDataService method getPrimaryGwInstance.
public InstanceMetaData getPrimaryGwInstance(Set<InstanceMetaData> allInstances) {
InstanceMetaData primaryGateway = allInstances.stream().filter(instanceMetaData -> InstanceMetadataType.GATEWAY_PRIMARY == instanceMetaData.getInstanceMetadataType()).findFirst().orElseThrow(() -> new BadRequestException("No primary Gateway found"));
LOGGER.debug("Found primary gateway with instance id: [{}]", primaryGateway.getInstanceId());
return primaryGateway;
}
Aggregations