Search in sources :

Example 81 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class GceDiscoveryTests method testNodesWithDifferentTagsAndNoTagSet.

public void testNodesWithDifferentTagsAndNoTagSet() {
    Settings nodeSettings = Settings.builder().put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName).put(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "europe-west1-b").build();
    mock = new GceInstancesServiceMock(nodeSettings);
    List<TransportAddress> dynamicHosts = buildDynamicNodes(mock, nodeSettings);
    assertThat(dynamicHosts, hasSize(2));
}
Also used : TransportAddress(org.opensearch.common.transport.TransportAddress) Settings(org.opensearch.common.settings.Settings)

Example 82 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class GceDiscoveryTests method testNodesWithDifferentTagsAndTwoTagSet.

public void testNodesWithDifferentTagsAndTwoTagSet() {
    Settings nodeSettings = Settings.builder().put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName).put(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "europe-west1-b").putList(GceSeedHostsProvider.TAGS_SETTING.getKey(), "opensearch", "dev").build();
    mock = new GceInstancesServiceMock(nodeSettings);
    List<TransportAddress> dynamicHosts = buildDynamicNodes(mock, nodeSettings);
    assertThat(dynamicHosts, hasSize(1));
}
Also used : TransportAddress(org.opensearch.common.transport.TransportAddress) Settings(org.opensearch.common.settings.Settings)

Example 83 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class GceDiscoveryTests method testMetadataServerValues.

public void testMetadataServerValues() {
    Settings nodeSettings = Settings.EMPTY;
    mock = new GceInstancesServiceMock(nodeSettings);
    assertThat(mock.projectId(), not(projectName));
    List<TransportAddress> dynamicHosts = buildDynamicNodes(mock, nodeSettings);
    assertThat(dynamicHosts, hasSize(1));
}
Also used : TransportAddress(org.opensearch.common.transport.TransportAddress) Settings(org.opensearch.common.settings.Settings)

Example 84 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class GceDiscoveryTests method testNodesWithSameTagsAndTwoTagsSet.

public void testNodesWithSameTagsAndTwoTagsSet() {
    Settings nodeSettings = Settings.builder().put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName).put(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "europe-west1-b").putList(GceSeedHostsProvider.TAGS_SETTING.getKey(), "opensearch", "dev").build();
    mock = new GceInstancesServiceMock(nodeSettings);
    List<TransportAddress> dynamicHosts = buildDynamicNodes(mock, nodeSettings);
    assertThat(dynamicHosts, hasSize(2));
}
Also used : TransportAddress(org.opensearch.common.transport.TransportAddress) Settings(org.opensearch.common.settings.Settings)

Example 85 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class AzureSeedHostsProvider method getSeedAddresses.

/**
 * 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<TransportAddress> getSeedAddresses(HostsResolver hostsResolver) {
    if (refreshInterval.millis() != 0) {
        if (dynamicHosts != null && (refreshInterval.millis() < 0 || (System.currentTimeMillis() - lastRefresh) < refreshInterval.millis())) {
            logger.trace("using cache to retrieve node list");
            return dynamicHosts;
        }
        lastRefresh = System.currentTimeMillis();
    }
    logger.debug("start building nodes list using Azure API");
    dynamicHosts = 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 dynamicHosts;
    } 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 dynamicHosts;
    }
    InetAddress ipAddress = null;
    try {
        ipAddress = networkService.resolvePublishHostAddresses(NetworkService.GLOBAL_NETWORK_PUBLISH_HOST_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY));
        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()) {
            final String networkAddress = resolveInstanceAddress(hostType, instance);
            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 {
                TransportAddress[] addresses = transportService.addressesFromString(networkAddress);
                for (TransportAddress address : addresses) {
                    logger.trace("adding {}, transport_address {}", networkAddress, address);
                    dynamicHosts.add(address);
                }
            } catch (Exception e) {
                logger.warn("can not convert [{}] to transport address. skipping. [{}]", networkAddress, e.getMessage());
            }
        }
    }
    logger.debug("{} addresses added", dynamicHosts.size());
    return dynamicHosts;
}
Also used : HostedServiceGetDetailedResponse(com.microsoft.windowsazure.management.compute.models.HostedServiceGetDetailedResponse) TransportAddress(org.opensearch.common.transport.TransportAddress) AzureServiceRemoteException(org.opensearch.cloud.azure.classic.AzureServiceRemoteException) RoleInstance(com.microsoft.windowsazure.management.compute.models.RoleInstance) IOException(java.io.IOException) InetAddress(java.net.InetAddress) AzureServiceRemoteException(org.opensearch.cloud.azure.classic.AzureServiceRemoteException) AzureServiceDisableException(org.opensearch.cloud.azure.classic.AzureServiceDisableException) IOException(java.io.IOException) AzureServiceDisableException(org.opensearch.cloud.azure.classic.AzureServiceDisableException)

Aggregations

TransportAddress (org.opensearch.common.transport.TransportAddress)129 Settings (org.opensearch.common.settings.Settings)51 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)43 BoundTransportAddress (org.opensearch.common.transport.BoundTransportAddress)31 Version (org.opensearch.Version)26 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)22 List (java.util.List)21 InetAddress (java.net.InetAddress)20 HashSet (java.util.HashSet)20 CountDownLatch (java.util.concurrent.CountDownLatch)20 ClusterSettings (org.opensearch.common.settings.ClusterSettings)20 ThreadPool (org.opensearch.threadpool.ThreadPool)17 Matchers.containsString (org.hamcrest.Matchers.containsString)16 HttpServerTransport (org.opensearch.http.HttpServerTransport)16 Set (java.util.Set)15 TimeUnit (java.util.concurrent.TimeUnit)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)15 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)15 MockTransportService (org.opensearch.test.transport.MockTransportService)15