List of usage examples for org.apache.solr.common.cloud Replica getNodeName
public String getNodeName()
From source file:com.doculibre.constellio.services.StatusServicesImpl.java
License:Open Source License
@Override public String getSizeOnDisk(RecordCollection collection) { if (collection != null) { String collectionName = collection.getName(); String realCollectionName; if (SolrServicesImpl.isAliasInCloud(collectionName)) { realCollectionName = SolrServicesImpl.getRealCollectionInCloud(collectionName); } else {/*from w w w .j a v a 2 s.c o m*/ realCollectionName = collectionName; } ModifiableSolrParams params = new ModifiableSolrParams(); params.set(CommonParams.QT, "/replication"); params.set("command", "details"); try { StringBuffer formattedSize = new StringBuffer(); CloudSolrServer cloudSolrServer = (CloudSolrServer) SolrCoreContext.getMainSolrServer(); ClusterState clusterState = cloudSolrServer.getZkStateReader().getClusterState(); Collection<Slice> slices = clusterState.getActiveSlices(realCollectionName); if (slices != null) { for (Slice slice : slices) { Replica replica = clusterState.getLeader(realCollectionName, slice.getName()); HttpSolrServer solrServer = new HttpSolrServer( "http://" + StringUtils.substringBefore(replica.getNodeName(), "_") + "/solr/" + collectionName); QueryResponse response = solrServer.query(params); formattedSize .append(((NamedList) response.getResponse().get("details")).get("indexSize") + ","); } return formattedSize.toString(); } else { return FileSizeUtils.formatSize(0, 2); } } catch (SolrServerException e) { return FileSizeUtils.formatSize(0, 2); } } else { return FileSizeUtils.formatSize(0, 2); } }
From source file:com.shaie.solr.CollectionsStateHelper.java
License:Apache License
/** Returns true if the replica is on a live node and active. */ public boolean isReplicaActive(Replica replica) { return getClusterState().liveNodesContain(replica.getNodeName()) && replica.getState() == Replica.State.ACTIVE; }
From source file:com.shaie.solr.CollectionsStateHelper.java
License:Apache License
/** Returns true if the replica is in a DOWN state. */ public boolean isReplicaDown(Replica replica) { return !getClusterState().liveNodesContain(replica.getNodeName()) || replica.getState() == Replica.State.DOWN; }
From source file:com.shaie.solr.CollectionsStateHelper.java
License:Apache License
/** Returns all the replicas (of all shards and collections) that exist on the given node. */ public List<Replica> getAllNodeReplicas(String nodeName) { final List<Replica> replicas = Lists.newArrayList(); final ClusterState clusterState = getClusterState(); for (final DocCollection collection : clusterState.getCollectionsMap().values()) { for (final Slice slice : collection.getSlices()) { for (final Replica replica : slice.getReplicas()) { if (replica.getNodeName().equals(nodeName)) { replicas.add(replica); }// w w w. j a v a 2 s .c o m } } } return replicas; }
From source file:com.shaie.solr.CollectionsStateHelper.java
License:Apache License
/** Returns true if the given node holds a replica of the given shard of the given collection. */ public boolean isNodeReplicaOfShard(String collectionName, String shardName, String nodeName) { for (final Replica replica : getClusterState().getCollection(collectionName).getSlice(shardName) .getReplicas()) {//from ww w .j ava2 s .c o m if (replica.getNodeName().equals(nodeName)) { return true; } } return false; }
From source file:com.shaie.solr.CollectionsStateHelper.java
License:Apache License
/** Returns all replicas per node. */ private Map<String, List<ReplicaInfo>> getNodeReplicas() { final ClusterState clusterState = getClusterState(); final Map<String, List<ReplicaInfo>> result = Maps.newHashMap(); for (final DocCollection collection : clusterState.getCollectionsMap().values()) { for (final Slice slice : collection.getSlices()) { for (final Replica replica : slice.getReplicas()) { List<ReplicaInfo> nodeReplicas = result.get(replica.getNodeName()); if (nodeReplicas == null) { nodeReplicas = Lists.newArrayList(); result.put(replica.getNodeName(), nodeReplicas); }//from ww w .j a va2 s .co m nodeReplicas.add(new ReplicaInfo(replica, collection.getName(), slice.getName())); } } } return result; }