use of com.microsoft.windowsazure.management.compute.models.HostedServiceGetDetailedResponse in project elasticsearch by elastic.
the class AzureUnicastHostsProvider method buildDynamicNodes.
/**
* We build the list of Nodes from Azure Management API
* Information can be cached using `cloud.azure.refresh_interval` property if needed.
* Setting `cloud.azure.refresh_interval` to `-1` will cause infinite caching.
* Setting `cloud.azure.refresh_interval` to `0` will disable caching (default).
*/
@Override
public List<DiscoveryNode> buildDynamicNodes() {
if (refreshInterval.millis() != 0) {
if (cachedDiscoNodes != null && (refreshInterval.millis() < 0 || (System.currentTimeMillis() - lastRefresh) < refreshInterval.millis())) {
logger.trace("using cache to retrieve node list");
return cachedDiscoNodes;
}
lastRefresh = System.currentTimeMillis();
}
logger.debug("start building nodes list using Azure API");
cachedDiscoNodes = new ArrayList<>();
HostedServiceGetDetailedResponse detailed;
try {
detailed = azureComputeService.getServiceDetails();
} catch (AzureServiceDisableException e) {
logger.debug("Azure discovery service has been disabled. Returning empty list of nodes.");
return cachedDiscoNodes;
} catch (AzureServiceRemoteException e) {
// We got a remote exception
logger.warn("can not get list of azure nodes: [{}]. Returning empty list of nodes.", e.getMessage());
logger.trace("AzureServiceRemoteException caught", e);
return cachedDiscoNodes;
}
InetAddress ipAddress = null;
try {
ipAddress = networkService.resolvePublishHostAddresses(null);
logger.trace("ip of current node: [{}]", ipAddress);
} catch (IOException e) {
// We can't find the publish host address... Hmmm. Too bad :-(
logger.trace("exception while finding ip", e);
}
for (HostedServiceGetDetailedResponse.Deployment deployment : detailed.getDeployments()) {
// We check the deployment slot
if (deployment.getDeploymentSlot() != deploymentSlot) {
logger.debug("current deployment slot [{}] for [{}] is different from [{}]. skipping...", deployment.getDeploymentSlot(), deployment.getName(), deploymentSlot);
continue;
}
// If provided, we check the deployment name
if (Strings.hasLength(deploymentName) && !deploymentName.equals(deployment.getName())) {
logger.debug("current deployment name [{}] different from [{}]. skipping...", deployment.getName(), deploymentName);
continue;
}
// We check current deployment status
if (deployment.getStatus() != DeploymentStatus.Starting && deployment.getStatus() != DeploymentStatus.Deploying && deployment.getStatus() != DeploymentStatus.Running) {
logger.debug("[{}] status is [{}]. skipping...", deployment.getName(), deployment.getStatus());
continue;
}
for (RoleInstance instance : deployment.getRoleInstances()) {
String networkAddress = null;
// Let's detect if we want to use public or private IP
switch(hostType) {
case PRIVATE_IP:
InetAddress privateIp = instance.getIPAddress();
if (privateIp != null) {
if (privateIp.equals(ipAddress)) {
logger.trace("adding ourselves {}", NetworkAddress.format(ipAddress));
}
networkAddress = InetAddresses.toUriString(privateIp);
} else {
logger.trace("no private ip provided. ignoring [{}]...", instance.getInstanceName());
}
break;
case PUBLIC_IP:
for (InstanceEndpoint endpoint : instance.getInstanceEndpoints()) {
if (!publicEndpointName.equals(endpoint.getName())) {
logger.trace("ignoring endpoint [{}] as different than [{}]", endpoint.getName(), publicEndpointName);
continue;
}
networkAddress = NetworkAddress.format(new InetSocketAddress(endpoint.getVirtualIPAddress(), endpoint.getPort()));
}
if (networkAddress == null) {
logger.trace("no public ip provided. ignoring [{}]...", instance.getInstanceName());
}
break;
default:
// This could never happen!
logger.warn("undefined host_type [{}]. Please check your settings.", hostType);
return cachedDiscoNodes;
}
if (networkAddress == null) {
// We have a bad parameter here or not enough information from azure
logger.warn("no network address found. ignoring [{}]...", instance.getInstanceName());
continue;
}
try {
// we only limit to 1 port per address, makes no sense to ping 100 ports
TransportAddress[] addresses = transportService.addressesFromString(networkAddress, 1);
for (TransportAddress address : addresses) {
logger.trace("adding {}, transport_address {}", networkAddress, address);
cachedDiscoNodes.add(new DiscoveryNode("#cloud-" + instance.getInstanceName(), address, emptyMap(), emptySet(), Version.CURRENT.minimumCompatibilityVersion()));
}
} catch (Exception e) {
logger.warn("can not convert [{}] to transport address. skipping. [{}]", networkAddress, e.getMessage());
}
}
}
logger.debug("{} node(s) added", cachedDiscoNodes.size());
return cachedDiscoNodes;
}
use of com.microsoft.windowsazure.management.compute.models.HostedServiceGetDetailedResponse in project elasticsearch by elastic.
the class AzureComputeServiceSimpleMock method getServiceDetails.
@Override
public HostedServiceGetDetailedResponse getServiceDetails() {
HostedServiceGetDetailedResponse response = new HostedServiceGetDetailedResponse();
HostedServiceGetDetailedResponse.Deployment deployment = new HostedServiceGetDetailedResponse.Deployment();
// Fake the deployment
deployment.setName("dummy");
deployment.setDeploymentSlot(DeploymentSlot.Production);
deployment.setStatus(DeploymentStatus.Running);
// Fake an instance
RoleInstance instance = new RoleInstance();
instance.setInstanceName("dummy1");
// Fake the private IP
instance.setIPAddress(InetAddress.getLoopbackAddress());
// Fake the public IP
InstanceEndpoint endpoint = new InstanceEndpoint();
endpoint.setName("elasticsearch");
endpoint.setVirtualIPAddress(InetAddress.getLoopbackAddress());
endpoint.setPort(9400);
instance.setInstanceEndpoints(CollectionUtils.newSingletonArrayList(endpoint));
deployment.setRoleInstances(CollectionUtils.newSingletonArrayList(instance));
response.setDeployments(CollectionUtils.newSingletonArrayList(deployment));
return response;
}
use of com.microsoft.windowsazure.management.compute.models.HostedServiceGetDetailedResponse in project elasticsearch by elastic.
the class AzureComputeServiceTwoNodesMock method getServiceDetails.
@Override
public HostedServiceGetDetailedResponse getServiceDetails() {
HostedServiceGetDetailedResponse response = new HostedServiceGetDetailedResponse();
HostedServiceGetDetailedResponse.Deployment deployment = new HostedServiceGetDetailedResponse.Deployment();
// Fake the deployment
deployment.setName("dummy");
deployment.setDeploymentSlot(DeploymentSlot.Production);
deployment.setStatus(DeploymentStatus.Running);
// Fake a first instance
RoleInstance instance1 = new RoleInstance();
instance1.setInstanceName("dummy1");
// Fake the private IP
instance1.setIPAddress(InetAddress.getLoopbackAddress());
// Fake the public IP
InstanceEndpoint endpoint1 = new InstanceEndpoint();
endpoint1.setName("elasticsearch");
endpoint1.setVirtualIPAddress(InetAddress.getLoopbackAddress());
endpoint1.setPort(9400);
instance1.setInstanceEndpoints(newSingletonArrayList(endpoint1));
// Fake a first instance
RoleInstance instance2 = new RoleInstance();
instance2.setInstanceName("dummy1");
// Fake the private IP
instance2.setIPAddress(InetAddress.getLoopbackAddress());
// Fake the public IP
InstanceEndpoint endpoint2 = new InstanceEndpoint();
endpoint2.setName("elasticsearch");
endpoint2.setVirtualIPAddress(InetAddress.getLoopbackAddress());
endpoint2.setPort(9401);
instance2.setInstanceEndpoints(newSingletonArrayList(endpoint2));
deployment.setRoleInstances(new ArrayList<>(Arrays.asList(instance1, instance2)));
response.setDeployments(newSingletonArrayList(deployment));
return response;
}
Aggregations