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

The following examples show how to use org.elasticsearch.cluster.node.DiscoveryNode#masterNode() . These examples are extracted from open source projects. 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
@Inject
public SnapshotShardsService(Settings settings, ClusterService clusterService, SnapshotsService snapshotsService, ThreadPool threadPool,
                             TransportService transportService, IndicesService indicesService) {
    super(settings);
    this.indicesService = indicesService;
    this.snapshotsService = snapshotsService;
    this.transportService = transportService;
    this.clusterService = clusterService;
    this.threadPool = threadPool;
    if (DiscoveryNode.dataNode(settings)) {
        // this is only useful on the nodes that can hold data
        // addLast to make sure that Repository will be created before snapshot
        clusterService.addLast(this);
    }

    if (DiscoveryNode.masterNode(settings)) {
        // This needs to run only on nodes that can become masters
        transportService.registerRequestHandler(UPDATE_SNAPSHOT_ACTION_NAME, UpdateIndexShardSnapshotStatusRequest.class, ThreadPool.Names.SAME, new UpdateSnapshotStateRequestHandler());
    }

}
 
Example 2
public boolean hasEnoughMasterNodes(Iterable<DiscoveryNode> nodes) {
    if (minimumMasterNodes < 1) {
        return true;
    }
    int count = 0;
    for (DiscoveryNode node : nodes) {
        if (node.masterNode()) {
            count++;
        }
    }
    return count >= minimumMasterNodes;
}
 
Example 3
private List<DiscoveryNode> sortedMasterNodes(Iterable<DiscoveryNode> nodes) {
    List<DiscoveryNode> possibleNodes = CollectionUtils.iterableAsArrayList(nodes);
    if (possibleNodes.isEmpty()) {
        return null;
    }
    // clean non master nodes
    for (Iterator<DiscoveryNode> it = possibleNodes.iterator(); it.hasNext(); ) {
        DiscoveryNode node = it.next();
        if (!node.masterNode()) {
            it.remove();
        }
    }
    CollectionUtil.introSort(possibleNodes, nodeComparator);
    return possibleNodes;
}
 
Example 4
@Override
public int compare(DiscoveryNode o1, DiscoveryNode o2) {
    if (o1.masterNode() && !o2.masterNode()) {
        return -1;
    }
    if (!o1.masterNode() && o2.masterNode()) {
        return 1;
    }
    return o1.id().compareTo(o2.id());
}
 
Example 5
@Inject
public RepositoriesService(Settings settings, ClusterService clusterService, TransportService transportService, RepositoryTypesRegistry typesRegistry, Injector injector) {
    super(settings);
    this.typesRegistry = typesRegistry;
    this.injector = injector;
    this.clusterService = clusterService;
    // Doesn't make sense to maintain repositories on non-master and non-data nodes
    // Nothing happens there anyway
    if (DiscoveryNode.dataNode(settings) || DiscoveryNode.masterNode(settings)) {
        clusterService.add(this);
    }
    this.verifyAction = new VerifyNodeRepositoryAction(settings, transportService, clusterService, this);
}
 
Example 6
Source Project: Elasticsearch   File: GatewayMetaState.java    License: Apache License 2.0 5 votes vote down vote up
@Inject
public GatewayMetaState(Settings settings, NodeEnvironment nodeEnv, MetaStateService metaStateService,
                        DanglingIndicesState danglingIndicesState, TransportNodesListGatewayMetaState nodesListGatewayMetaState,
                        MetaDataIndexUpgradeService metaDataIndexUpgradeService) throws Exception {
    super(settings);
    this.nodeEnv = nodeEnv;
    this.metaStateService = metaStateService;
    this.danglingIndicesState = danglingIndicesState;
    this.metaDataIndexUpgradeService = metaDataIndexUpgradeService;
    nodesListGatewayMetaState.init(this);

    if (DiscoveryNode.dataNode(settings)) {
        ensureNoPre019ShardState(nodeEnv);
        MultiDataPathUpgrader.upgradeMultiDataPath(nodeEnv, logger);
    }

    if (DiscoveryNode.masterNode(settings) || DiscoveryNode.dataNode(settings)) {
        nodeEnv.ensureAtomicMoveSupported();
    }
    if (DiscoveryNode.masterNode(settings) || DiscoveryNode.dataNode(settings)) {
        try {
            ensureNoPre019State();
            pre20Upgrade();
            long startNS = System.nanoTime();
            metaStateService.loadFullState();
            logger.debug("took {} to load state", TimeValue.timeValueMillis(TimeValue.nsecToMSec(System.nanoTime() - startNS)));
        } catch (Exception e) {
            logger.error("failed to read local state, exiting...", e);
            throw e;
        }
    }
}
 
Example 7
Source Project: Elasticsearch   File: SnapshotsService.java    License: Apache License 2.0 5 votes vote down vote up
@Inject
public SnapshotsService(Settings settings, ClusterService clusterService, IndexNameExpressionResolver indexNameExpressionResolver, RepositoriesService repositoriesService, ThreadPool threadPool) {
    super(settings);
    this.clusterService = clusterService;
    this.indexNameExpressionResolver = indexNameExpressionResolver;
    this.repositoriesService = repositoriesService;
    this.threadPool = threadPool;

    if (DiscoveryNode.masterNode(settings)) {
        // addLast to make sure that Repository will be created before snapshot
        clusterService.addLast(this);
    }
}
 
Example 8
Source Project: Elasticsearch   File: ClusterStatsNodes.java    License: Apache License 2.0 5 votes vote down vote up
public void addNodeInfo(NodeInfo nodeInfo) {
    total++;
    DiscoveryNode node = nodeInfo.getNode();
    if (node.masterNode()) {
        if (node.dataNode()) {
            masterData++;
        } else {
            masterOnly++;
        }
    } else if (node.dataNode()) {
        dataOnly++;
    } else if (node.clientNode()) {
        client++;
    }
}