Search in sources :

Example 46 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.

the class AllHostPublicDnsEntryService method getComponentLocation.

@Override
protected Map<String, List<String>> getComponentLocation(Stack stack) {
    Map<String, List<String>> result = new HashMap<>();
    Optional<InstanceMetaData> gateway = Optional.ofNullable(stack.getPrimaryGatewayInstance());
    if (gateway.isEmpty()) {
        LOGGER.info("No running gateway or all node is terminated, we skip the dns entry deletion.");
    } else {
        InstanceMetaData primaryGatewayInstance = gateway.get();
        Map<String, List<String>> hostnamesByInstanceGroupName = stack.getNotTerminatedInstanceMetaDataSet().stream().filter(im -> StringUtils.isNoneEmpty(im.getDiscoveryFQDN()) && !im.getDiscoveryFQDN().equals(primaryGatewayInstance.getDiscoveryFQDN())).collect(groupingBy(InstanceMetaData::getInstanceGroupName, mapping(InstanceMetaData::getDiscoveryFQDN, toList())));
        result.putAll(hostnamesByInstanceGroupName);
    }
    return result;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Logger(org.slf4j.Logger) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Service(org.springframework.stereotype.Service) Collectors.mapping(java.util.stream.Collectors.mapping) Map(java.util.Map) Optional(java.util.Optional) HashMap(java.util.HashMap) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List)

Example 47 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.

the class ClusterPublicEndpointManagementService method changeGatewayAddress.

private void changeGatewayAddress(Stack stack, Map<String, String> newAddressesByFqdn) {
    InstanceMetaData gatewayInstanceMetadata = stack.getPrimaryGatewayInstance();
    String ipWrapper = gatewayInstanceMetadata.getPublicIpWrapper();
    if (newAddressesByFqdn.containsValue(ipWrapper)) {
        LOGGER.info("Gateway's DNS entry needs to be updated because primary gateway IP has been updated to: '{}'", ipWrapper);
        changeGateway(stack);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)

Example 48 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.

the class MultiAzCalculatorService method calculateByRoundRobin.

public void calculateByRoundRobin(Map<String, String> subnetAzPairs, InstanceGroup instanceGroup) {
    LOGGER.debug("Calculate the subnet by round robin from {}", subnetAzPairs);
    Map<String, Integer> subnetUsage = new HashMap<>();
    Set<String> subnetIds = collectSubnetIds(instanceGroup, NetworkScaleDetails.getEmpty());
    LOGGER.debug("Collected subnetIds: {}", subnetIds);
    initializeSubnetUsage(subnetAzPairs, subnetIds, subnetUsage);
    collectCurrentSubnetUsage(instanceGroup, subnetUsage);
    if (!subnetIds.isEmpty() && multiAzValidator.supportedForInstanceMetadataGeneration(instanceGroup)) {
        checkSubnetUsageCount(subnetUsage, subnetIds);
        for (InstanceMetaData instanceMetaData : instanceGroup.getNotDeletedAndNotZombieInstanceMetaDataSet()) {
            if (isNullOrEmpty(instanceMetaData.getSubnetId())) {
                Integer numberOfInstanceInASubnet = searchTheSmallestInstanceCountForUsage(subnetUsage);
                String leastUsedSubnetId = searchTheSmallestUsedID(subnetUsage, numberOfInstanceInASubnet);
                instanceMetaData.setSubnetId(leastUsedSubnetId);
                instanceMetaData.setAvailabilityZone(subnetAzPairs.get(leastUsedSubnetId));
                subnetUsage.put(leastUsedSubnetId, numberOfInstanceInASubnet + 1);
            }
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HashMap(java.util.HashMap)

Example 49 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.

the class MultiAzCalculatorService method collectCurrentAzUsage.

private void collectCurrentAzUsage(InstanceGroup instanceGroup, Map<String, Integer> azUsage, Map<String, String> subnetAzPairs) {
    for (InstanceMetaData instanceMetaData : instanceGroup.getNotDeletedAndNotZombieInstanceMetaDataSet()) {
        String subnetId = instanceMetaData.getSubnetId();
        if (!isNullOrEmpty(subnetId)) {
            String az = subnetAzPairs.get(subnetId);
            Integer countOfInstances = azUsage.get(az);
            if (countOfInstances != null) {
                azUsage.put(az, countOfInstances + 1);
            } else {
                LOGGER.warn("AZ with subnet ID {} is not present in the environment networks. Current usage: {}", subnetId, azUsage.keySet());
            }
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)

Example 50 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.

the class HostMetadataSetup method updateWithHostData.

private void updateWithHostData(Stack stack, Collection<InstanceMetaData> metadataToUpdate) {
    try {
        LOGGER.info("Update metadatas: {}", metadataToUpdate);
        List<String> privateIps = metadataToUpdate.stream().filter(instanceMetaData -> InstanceStatus.CREATED.equals(instanceMetaData.getInstanceStatus())).map(InstanceMetaData::getPrivateIp).collect(Collectors.toList());
        if (!privateIps.isEmpty()) {
            GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
            Map<String, String> members = hostOrchestrator.getMembers(gatewayConfig, privateIps);
            LOGGER.info("Received host names from hosts: {}, original targets: {}", members.values(), privateIps);
            for (InstanceMetaData instanceMetaData : metadataToUpdate) {
                String privateIp = instanceMetaData.getPrivateIp();
                String fqdnFromTheCluster = members.get(privateIp);
                String discoveryFQDN = instanceMetaData.getDiscoveryFQDN();
                if (Strings.isNullOrEmpty(discoveryFQDN) || !discoveryFQDN.equals(fqdnFromTheCluster)) {
                    instanceMetaData.setDiscoveryFQDN(fqdnFromTheCluster);
                    LOGGER.info("Discovery FQDN has been updated for instance: {} original: {}, fqdn: {}", instanceMetaData.getInstanceId(), fqdnFromTheCluster, discoveryFQDN);
                } else {
                    LOGGER.debug("There is no need to update the FQDN for node, private ip: '{}' with FQDN: '{}'", privateIp, discoveryFQDN);
                }
            }
        } else {
            LOGGER.info("There is no hosts to update");
        }
    } catch (Exception e) {
        throw new CloudbreakRuntimeException(e);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakRuntimeException(com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException) CloudbreakRuntimeException(com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Aggregations

InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)415 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)165 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)152 Test (org.junit.jupiter.api.Test)143 Map (java.util.Map)92 HashSet (java.util.HashSet)90 Set (java.util.Set)86 List (java.util.List)84 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)77 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)73 Collectors (java.util.stream.Collectors)71 ArrayList (java.util.ArrayList)62 Test (org.junit.Test)60 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)57 Optional (java.util.Optional)52 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)48 Inject (javax.inject.Inject)47 Logger (org.slf4j.Logger)47 LoggerFactory (org.slf4j.LoggerFactory)47 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)45