Java Code Examples for org.elasticsearch.cluster.node.DiscoveryNode#isMasterNode()

The following examples show how to use org.elasticsearch.cluster.node.DiscoveryNode#isMasterNode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoutingProvider.java    From crate with Apache License 2.0 6 votes vote down vote up
public Routing forRandomMasterOrDataNode(RelationName relationName, DiscoveryNodes nodes) {
    DiscoveryNode localNode = nodes.getLocalNode();
    if (localNode.isMasterNode() || localNode.isDataNode()) {
        return forTableOnSingleNode(relationName, localNode.getId());
    }
    ImmutableOpenMap<String, DiscoveryNode> masterAndDataNodes = nodes.getMasterAndDataNodes();
    int randomIdx = seed % masterAndDataNodes.size();
    Iterator<DiscoveryNode> it = masterAndDataNodes.valuesIt();
    int currIdx = 0;
    while (it.hasNext()) {
        if (currIdx == randomIdx) {
            return forTableOnSingleNode(relationName, it.next().getId());
        }
        currIdx++;
    }
    throw new AssertionError("Cannot find a master or data node with given random index " + randomIdx);
}
 
Example 2
Source File: GraphiteService.java    From elasticsearch-graphite-plugin with Do What The F*ck You Want To Public License 5 votes vote down vote up
public void run() {
    while (!closed) {
        DiscoveryNode node = clusterService.localNode();
        boolean isClusterStarted = clusterService.lifecycleState().equals(Lifecycle.State.STARTED);

        if (isClusterStarted && node != null && node.isMasterNode()) {
            NodeIndicesStats nodeIndicesStats = indicesService.stats(false);
            CommonStatsFlags commonStatsFlags = new CommonStatsFlags().clear();
            NodeStats nodeStats = nodeService.stats(commonStatsFlags, true, true, true, true, true, true, true, true, true);
            List<IndexShard> indexShards = getIndexShards(indicesService);

            GraphiteReporter graphiteReporter = new GraphiteReporter(graphiteHost, graphitePort, graphitePrefix,
                    nodeIndicesStats, indexShards, nodeStats, graphiteInclusionRegex, graphiteExclusionRegex);
            graphiteReporter.run();
        } else {
            if (node != null) {
                logger.debug("[{}]/[{}] is not master node, not triggering update", node.getId(), node.getName());
            }
        }

        try {
            Thread.sleep(graphiteRefreshInternal.millis());
        } catch (InterruptedException e1) {
            continue;
        }
    }
}
 
Example 3
Source File: IndicesClusterStateService.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected void doStart() {
    // Doesn't make sense to manage shards on non-master and non-data nodes
    if (DiscoveryNode.isDataNode(settings) || DiscoveryNode.isMasterNode(settings)) {
        clusterService.addHighPriorityApplier(this);
    }
}
 
Example 4
Source File: RepositoriesService.java    From crate with Apache License 2.0 5 votes vote down vote up
@Inject
public RepositoriesService(Settings settings, ClusterService clusterService, TransportService transportService,
                           Map<String, Repository.Factory> typesRegistry,
                           ThreadPool threadPool) {
    this.typesRegistry = typesRegistry;
    this.clusterService = clusterService;
    this.threadPool = threadPool;
    // Doesn't make sense to maintain repositories on non-master and non-data nodes
    // Nothing happens there anyway
    if (DiscoveryNode.isDataNode(settings) || DiscoveryNode.isMasterNode(settings)) {
        clusterService.addStateApplier(this);
    }
    this.verifyAction = new VerifyNodeRepositoryAction(transportService, clusterService, this);
}
 
Example 5
Source File: GatewayMetaState.java    From crate with Apache License 2.0 5 votes vote down vote up
public PersistedState getPersistedState(Settings settings, ClusterApplierService clusterApplierService) {
    applyClusterStateUpdaters();
    if (DiscoveryNode.isMasterNode(settings) == false) {
        // use Zen1 way of writing cluster state for non-master-eligible nodes
        // this avoids concurrent manipulating of IndexMetadata with IndicesStore
        clusterApplierService.addLowPriorityApplier(this);
        return new InMemoryPersistedState(getCurrentTerm(), getLastAcceptedState());
    }
    return this;
}
 
Example 6
Source File: ClusterBootstrapService.java    From crate with Apache License 2.0 5 votes vote down vote up
public ClusterBootstrapService(Settings settings, TransportService transportService,
                               Supplier<Iterable<DiscoveryNode>> discoveredNodesSupplier, BooleanSupplier isBootstrappedSupplier,
                               Consumer<VotingConfiguration> votingConfigurationConsumer) {
    if (DiscoveryModule.SINGLE_NODE_DISCOVERY_TYPE.equals(DiscoveryModule.DISCOVERY_TYPE_SETTING.get(settings))) {
        if (INITIAL_MASTER_NODES_SETTING.exists(settings)) {
            throw new IllegalArgumentException("setting [" + INITIAL_MASTER_NODES_SETTING.getKey() +
                "] is not allowed when [" + DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey() + "] is set to [" +
                DiscoveryModule.SINGLE_NODE_DISCOVERY_TYPE + "]");
        }
        if (DiscoveryNode.isMasterNode(settings) == false) {
            throw new IllegalArgumentException("node with [" + DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey() + "] set to [" +
                DiscoveryModule.SINGLE_NODE_DISCOVERY_TYPE + "] must be master-eligible");
        }
        bootstrapRequirements = Collections.singleton(Node.NODE_NAME_SETTING.get(settings));
        unconfiguredBootstrapTimeout = null;
    } else {
        final List<String> initialMasterNodes = INITIAL_MASTER_NODES_SETTING.get(settings);
        bootstrapRequirements = unmodifiableSet(new LinkedHashSet<>(initialMasterNodes));
        if (bootstrapRequirements.size() != initialMasterNodes.size()) {
            throw new IllegalArgumentException(
                "setting [" + INITIAL_MASTER_NODES_SETTING.getKey() + "] contains duplicates: " + initialMasterNodes);
        }
        unconfiguredBootstrapTimeout = discoveryIsConfigured(settings) ? null : UNCONFIGURED_BOOTSTRAP_TIMEOUT_SETTING.get(settings);
    }

    this.transportService = transportService;
    this.discoveredNodesSupplier = discoveredNodesSupplier;
    this.isBootstrappedSupplier = isBootstrappedSupplier;
    this.votingConfigurationConsumer = votingConfigurationConsumer;
}
 
Example 7
Source File: SnapshotsService.java    From crate with Apache License 2.0 5 votes vote down vote up
@Inject
public SnapshotsService(Settings settings, ClusterService clusterService, IndexNameExpressionResolver indexNameExpressionResolver,
                        RepositoriesService repositoriesService, ThreadPool threadPool) {
    this.clusterService = clusterService;
    this.indexNameExpressionResolver = indexNameExpressionResolver;
    this.repositoriesService = repositoriesService;
    this.threadPool = threadPool;

    if (DiscoveryNode.isMasterNode(settings)) {
        // addLowPriorityApplier to make sure that Repository will be created before snapshot
        clusterService.addLowPriorityApplier(this);
    }
}
 
Example 8
Source File: IndicesClusterStateService.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected void doStop() {
    if (DiscoveryNode.isDataNode(settings) || DiscoveryNode.isMasterNode(settings)) {
        clusterService.removeApplier(this);
    }
}
 
Example 9
Source File: GatewayMetaState.java    From crate with Apache License 2.0 4 votes vote down vote up
protected boolean isMasterOrDataNode() {
    return DiscoveryNode.isMasterNode(settings) || DiscoveryNode.isDataNode(settings);
}