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;
}
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);
}
}
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);
}
}
}
}
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());
}
}
}
}
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);
}
}
Aggregations