Search in sources :

Example 21 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class SimpleNetty4TransportTests method nettyFromThreadPool.

public static MockTransportService nettyFromThreadPool(Settings settings, ThreadPool threadPool, final Version version, ClusterSettings clusterSettings, boolean doHandshake) {
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
    Transport transport = new Netty4Transport(settings, threadPool, new NetworkService(settings, Collections.emptyList()), BigArrays.NON_RECYCLING_INSTANCE, namedWriteableRegistry, new NoneCircuitBreakerService()) {

        @Override
        protected Version executeHandshake(DiscoveryNode node, Channel channel, TimeValue timeout) throws IOException, InterruptedException {
            if (doHandshake) {
                return super.executeHandshake(node, channel, timeout);
            } else {
                return version.minimumCompatibilityVersion();
            }
        }

        @Override
        protected Version getCurrentVersion() {
            return version;
        }
    };
    MockTransportService mockTransportService = MockTransportService.createNewService(Settings.EMPTY, transport, version, threadPool, clusterSettings);
    mockTransportService.start();
    return mockTransportService;
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportService(org.elasticsearch.test.transport.MockTransportService) Channel(io.netty.channel.Channel) NetworkService(org.elasticsearch.common.network.NetworkService) Transport(org.elasticsearch.transport.Transport) TimeValue(org.elasticsearch.common.unit.TimeValue) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Example 22 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode 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;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) InetSocketAddress(java.net.InetSocketAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) IOException(java.io.IOException) AzureServiceRemoteException(org.elasticsearch.cloud.azure.classic.AzureServiceRemoteException) IOException(java.io.IOException) AzureServiceDisableException(org.elasticsearch.cloud.azure.classic.AzureServiceDisableException) AzureServiceDisableException(org.elasticsearch.cloud.azure.classic.AzureServiceDisableException) HostedServiceGetDetailedResponse(com.microsoft.windowsazure.management.compute.models.HostedServiceGetDetailedResponse) InstanceEndpoint(com.microsoft.windowsazure.management.compute.models.InstanceEndpoint) AzureServiceRemoteException(org.elasticsearch.cloud.azure.classic.AzureServiceRemoteException) RoleInstance(com.microsoft.windowsazure.management.compute.models.RoleInstance) InetAddress(java.net.InetAddress)

Example 23 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class GceDiscoveryTests method testNoRegionReturnsEmptyList.

/**
     * For issue https://github.com/elastic/elasticsearch/issues/16967:
     * When using multiple regions and one of them has no instance at all, this
     * was producing a NPE as a result.
     */
public void testNoRegionReturnsEmptyList() {
    Settings nodeSettings = Settings.builder().put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName).putArray(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "europe-west1-b", "us-central1-a").build();
    mock = new GceInstancesServiceMock(nodeSettings);
    List<DiscoveryNode> discoveryNodes = buildDynamicNodes(mock, nodeSettings);
    assertThat(discoveryNodes, hasSize(1));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings)

Example 24 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

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").putArray(GceUnicastHostsProvider.TAGS_SETTING.getKey(), "elasticsearch", "dev").build();
    mock = new GceInstancesServiceMock(nodeSettings);
    List<DiscoveryNode> discoveryNodes = buildDynamicNodes(mock, nodeSettings);
    assertThat(discoveryNodes, hasSize(1));
    assertThat(discoveryNodes.get(0).getId(), is("#cloud-test2-0"));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings)

Example 25 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class GceDiscoveryTests method testNodesWithSameTagsAndOneTagSet.

public void testNodesWithSameTagsAndOneTagSet() {
    Settings nodeSettings = Settings.builder().put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName).put(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "europe-west1-b").putArray(GceUnicastHostsProvider.TAGS_SETTING.getKey(), "elasticsearch").build();
    mock = new GceInstancesServiceMock(nodeSettings);
    List<DiscoveryNode> discoveryNodes = buildDynamicNodes(mock, nodeSettings);
    assertThat(discoveryNodes, hasSize(2));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)352 ClusterState (org.elasticsearch.cluster.ClusterState)83 ArrayList (java.util.ArrayList)82 Settings (org.elasticsearch.common.settings.Settings)79 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)74 IOException (java.io.IOException)69 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)52 HashMap (java.util.HashMap)45 ShardId (org.elasticsearch.index.shard.ShardId)45 HashSet (java.util.HashSet)43 List (java.util.List)41 TransportAddress (org.elasticsearch.common.transport.TransportAddress)41 CountDownLatch (java.util.concurrent.CountDownLatch)39 MockTransportService (org.elasticsearch.test.transport.MockTransportService)39 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)37 Map (java.util.Map)35 ExecutionException (java.util.concurrent.ExecutionException)35 Version (org.elasticsearch.Version)35 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)31 ClusterName (org.elasticsearch.cluster.ClusterName)30