Search in sources :

Example 71 with InstanceMetaData

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);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 72 with InstanceMetaData

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;
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) StackBasedExitCriteriaModel(com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel) OrchestratorStateParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 73 with InstanceMetaData

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);
            }
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 74 with 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;
}
Also used : MultiAzCalculatorService(com.sequenceiq.freeipa.service.multiaz.MultiAzCalculatorService) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceMetadataType(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetadataType) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CachedEnvironmentClientService(com.sequenceiq.freeipa.service.client.CachedEnvironmentClientService) StackAuthenticationView(com.sequenceiq.freeipa.entity.projection.StackAuthenticationView) Service(org.springframework.stereotype.Service) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) FreeIpaService(com.sequenceiq.freeipa.service.freeipa.FreeIpaService) Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Optional(java.util.Optional) InstanceMetaDataRepository(com.sequenceiq.freeipa.repository.InstanceMetaDataRepository) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) List(java.util.List) Map(java.util.Map)

Example 75 with InstanceMetaData

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;
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Aggregations

InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)163 Stack (com.sequenceiq.freeipa.entity.Stack)104 Test (org.junit.jupiter.api.Test)77 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)30 List (java.util.List)19 Logger (org.slf4j.Logger)19 LoggerFactory (org.slf4j.LoggerFactory)19 Map (java.util.Map)18 Collectors (java.util.stream.Collectors)18 Inject (javax.inject.Inject)18 Set (java.util.Set)16 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)13 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)13 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)12 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)11 StackService (com.sequenceiq.freeipa.service.stack.StackService)10 ArrayList (java.util.ArrayList)10 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)9 HealthDetailsFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse)9 Operation (com.sequenceiq.freeipa.entity.Operation)9