use of com.sequenceiq.cloudbreak.common.network.NetworkConstants.SUBNET_ID in project cloudbreak by hortonworks.
the class AzureMetadataCollector method collect.
@Override
@Retryable(backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000), maxAttempts = 5)
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms, List<CloudInstance> knownInstances) {
LOGGER.debug("Starting to collect vm metadata.");
List<CloudVmMetaDataStatus> results = new ArrayList<>();
String resourceGroup = azureUtils.getTemplateResource(resources).getName();
AzureClient azureClient = authenticatedContext.getParameter(AzureClient.class);
Map<String, InstanceTemplate> templateMap = getTemplateMap(vms, authenticatedContext);
Map<String, VirtualMachine> virtualMachinesByName = azureVirtualMachineService.getVirtualMachinesByName(azureClient, resourceGroup, templateMap.keySet());
azureVirtualMachineService.refreshInstanceViews(virtualMachinesByName);
try {
for (Entry<String, InstanceTemplate> instance : templateMap.entrySet()) {
VirtualMachine vm = virtualMachinesByName.get(instance.getKey());
// TODO: network interface is lazy, so we will fetch it for every instances
if (vm != null) {
NetworkInterface networkInterface = vm.getPrimaryNetworkInterface();
String subnetId = networkInterface.primaryIPConfiguration().subnetName();
Integer faultDomainCount = azureClient.getFaultDomainNumber(resourceGroup, vm.name());
String publicIp = azureVmPublicIpProvider.getPublicIp(networkInterface);
String instanceId = instance.getKey();
String localityIndicator = Optional.ofNullable(faultDomainCount).map(domainCount -> getLocalityIndicator(domainCount, authenticatedContext.getCloudContext(), instance.getValue(), resourceGroup)).orElse(null);
CloudInstanceMetaData md = new CloudInstanceMetaData(networkInterface.primaryPrivateIP(), publicIp, localityIndicator);
InstanceTemplate template = templateMap.get(instanceId);
if (template != null) {
Map<String, Object> params = new HashMap<>(1);
params.put(SUBNET_ID, subnetId);
params.put(CloudInstance.INSTANCE_NAME, vm.computerName());
CloudInstance cloudInstance = new CloudInstance(instanceId, template, null, subnetId, null, params);
CloudVmInstanceStatus status = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.CREATED);
results.add(new CloudVmMetaDataStatus(status, md));
}
}
}
} catch (RuntimeException e) {
LOGGER.debug("Failed to collect vm metadata due to an exception: ", e);
throw new CloudConnectorException(e.getMessage(), e);
}
LOGGER.debug("Metadata collection finished with result {}", results);
return results;
}
Aggregations