Skip to content
Permalink
Browse files
AMBARI-23945. Infra Solr Client - add number of docs to collection dump
  • Loading branch information
oleewere committed Jun 20, 2018
1 parent d482acc commit 98fdcfd910c7319ee0685fb2c024d5c92542da8e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
@@ -374,6 +374,11 @@ public static void main(String[] args) {
.numberOfArgs(1)
.build();

final Option includeDocNumberOption = Option.builder("idn")
.longOpt("include-doc-number")
.desc("Include the number of docs as well in collection dump")
.build();

options.addOption(helpOption);
options.addOption(retryOption);
options.addOption(removeAdminHandlerOption);
@@ -421,6 +426,7 @@ public static void main(String[] args) {
options.addOption(setupKerberosPluginOption);
options.addOption(securityJsonLocationOption);
options.addOption(outputOption);
options.addOption(includeDocNumberOption);

AmbariSolrCloudClient solrCloudClient = null;

@@ -520,6 +526,7 @@ public static void main(String[] args) {
String copyDest = cli.hasOption("cpd") ? cli.getOptionValue("cpd") : null;
String transferMode = cli.hasOption("tm") ? cli.getOptionValue("tm") : "NONE";
String output = cli.hasOption("o") ? cli.getOptionValue("o") : null;
boolean includeDocNumber = cli.hasOption("idn");

AmbariSolrCloudClientBuilder clientBuilder = new AmbariSolrCloudClientBuilder()
.withZkConnectString(zkConnectString)
@@ -547,6 +554,7 @@ public static void main(String[] args) {
.withCopySrc(copySrc)
.withCopyDest(copyDest)
.withOutput(output)
.withIncludeDocNumber(includeDocNumber)
.withSecurityJsonLocation(securityJsonLocation)
.withZnode(znode)
.withSecure(isSecure)
@@ -79,6 +79,7 @@ public class AmbariSolrCloudClient {
private final String copySrc;
private final String copyDest;
private final String output;
private final boolean includeDocNumber;

public AmbariSolrCloudClient(AmbariSolrCloudClientBuilder builder) {
this.zkConnectString = builder.zkConnectString;
@@ -106,6 +107,7 @@ public AmbariSolrCloudClient(AmbariSolrCloudClientBuilder builder) {
this.copySrc = builder.copySrc;
this.copyDest = builder.copyDest;
this.output = builder.output;
this.includeDocNumber = builder.includeDocNumber;
}

/**
@@ -396,4 +398,8 @@ public String getCopyDest() {
public String getOutput() {
return output;
}

public boolean isIncludeDocNumber() {
return includeDocNumber;
}
}
@@ -58,6 +58,7 @@ public class AmbariSolrCloudClientBuilder {
String copySrc;
String copyDest;
String output;
public boolean includeDocNumber;

public AmbariSolrCloudClient build() {
return new AmbariSolrCloudClient(this);
@@ -221,6 +222,11 @@ public AmbariSolrCloudClientBuilder withOutput(String output) {
return this;
}

public AmbariSolrCloudClientBuilder withIncludeDocNumber(boolean includeDocNumber) {
this.includeDocNumber = includeDocNumber;
return this;
}

public AmbariSolrCloudClientBuilder withSecurityJsonLocation(String securityJson) {
this.securityJsonLocation = securityJson;
return this;
@@ -24,6 +24,7 @@
import org.apache.ambari.infra.solr.domain.json.SolrCollection;
import org.apache.ambari.infra.solr.domain.json.SolrCoreData;
import org.apache.ambari.infra.solr.domain.json.SolrShard;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.Replica;
@@ -58,7 +59,12 @@ protected String executeZkCommand(AmbariSolrCloudClient client, SolrZkClient zkC
if (!this.collections.isEmpty()) {
for (String collection : this.collections) {
SolrCollection solrCollection = new SolrCollection();
Collection<Slice> slices = getSlices(client.getSolrCloudClient(), collection);
CloudSolrClient solrClient = client.getSolrCloudClient();
if (client.isIncludeDocNumber()) {
long numberOfDocs = getNumberOfDocs(solrClient, collection);
solrCollection.setNumberOfDocs(numberOfDocs);
}
Collection<Slice> slices = getSlices(solrClient, collection);
Integer numShards = slices.size();
Map<String, SolrShard> solrShardMap = new HashMap<>();
Map<String, List<String>> leaderHostCoreMap = new HashMap<>();
@@ -141,4 +147,11 @@ private Collection<Slice> getSlices(CloudSolrClient solrClient, String collectio
DocCollection docCollection = reader.getClusterState().getCollection(collection);
return docCollection.getSlices();
}

private long getNumberOfDocs(CloudSolrClient solrClient, String collection) throws Exception {
solrClient.setDefaultCollection(collection);
SolrQuery q = new SolrQuery("*:*");
q.setRows(0);
return solrClient.query(q).getResults().getNumFound();
}
}
@@ -24,12 +24,21 @@

public class SolrCollection {
private String name;
private long numberOfDocs = -1;
private Map<String, SolrShard> shards = new HashMap<>();
private Map<String, List<String>> leaderHostCoreMap = new HashMap<>();
private Map<String, SolrCoreData> leaderSolrCoreDataMap = new HashMap<>();
private Map<String, List<String>> leaderShardsMap = new HashMap<>();
private Map<String, String> leaderCoreHostMap = new HashMap<>();

public long getNumberOfDocs() {
return numberOfDocs;
}

public void setNumberOfDocs(long numberOfDocs) {
this.numberOfDocs = numberOfDocs;
}

public Map<String, SolrShard> getShards() {
return shards;
}

0 comments on commit 98fdcfd

Please sign in to comment.