use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.
the class TestCollectionAPI method clusterStatusZNodeVersion.
private void clusterStatusZNodeVersion() throws Exception {
String cname = "clusterStatusZNodeVersion";
try (CloudSolrClient client = createCloudClient(null)) {
CollectionAdminRequest.createCollection(cname, "conf1", 1, 1).setMaxShardsPerNode(1).process(client);
waitForRecoveriesToFinish(cname, true);
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
params.set("collection", cname);
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
NamedList<Object> rsp = client.request(request);
NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
assertNotNull("Cluster state should not be null", cluster);
NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
assertNotNull("Collections should not be null in cluster state", collections);
assertEquals(1, collections.size());
Map<String, Object> collection = (Map<String, Object>) collections.get(cname);
assertNotNull(collection);
assertEquals("conf1", collection.get("configName"));
Integer znodeVersion = (Integer) collection.get("znodeVersion");
assertNotNull(znodeVersion);
CollectionAdminRequest.AddReplica addReplica = CollectionAdminRequest.addReplicaToShard(cname, "shard1");
addReplica.process(client);
waitForRecoveriesToFinish(cname, true);
rsp = client.request(request);
cluster = (NamedList<Object>) rsp.get("cluster");
collections = (NamedList<Object>) cluster.get("collections");
collection = (Map<String, Object>) collections.get(cname);
Integer newVersion = (Integer) collection.get("znodeVersion");
assertNotNull(newVersion);
assertTrue(newVersion > znodeVersion);
}
}
use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.
the class TestCollectionAPI method testAliasCreationNameValidation.
private void testAliasCreationNameValidation() throws Exception {
try (CloudSolrClient client = createCloudClient(null)) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CREATEALIAS.toString());
params.set("name", "invalid@name#with$weird%characters");
params.set("collections", COLLECTION_NAME);
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
try {
client.request(request);
fail();
} catch (RemoteSolrException e) {
final String errorMessage = e.getMessage();
assertTrue(errorMessage.contains("Invalid alias"));
assertTrue(errorMessage.contains("invalid@name#with$weird%characters"));
assertTrue(errorMessage.contains("alias names must consist entirely of"));
}
}
}
use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.
the class TestCollectionAPI method clusterStatusAliasTest.
private void clusterStatusAliasTest() throws Exception {
try (CloudSolrClient client = createCloudClient(null)) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CREATEALIAS.toString());
params.set("name", "myalias");
params.set("collections", DEFAULT_COLLECTION + "," + COLLECTION_NAME);
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
client.request(request);
params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
params.set("collection", DEFAULT_COLLECTION);
request = new QueryRequest(params);
request.setPath("/admin/collections");
NamedList<Object> rsp = client.request(request);
NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
assertNotNull("Cluster state should not be null", cluster);
Map<String, String> aliases = (Map<String, String>) cluster.get("aliases");
assertNotNull("Aliases should not be null", aliases);
assertEquals("Alias: myalias not found in cluster status", DEFAULT_COLLECTION + "," + COLLECTION_NAME, aliases.get("myalias"));
NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
assertNotNull("Collections should not be null in cluster state", collections);
assertNotNull(collections.get(DEFAULT_COLLECTION));
Map<String, Object> collection = (Map<String, Object>) collections.get(DEFAULT_COLLECTION);
assertEquals("conf1", collection.get("configName"));
List<String> collAlias = (List<String>) collection.get("aliases");
assertEquals("Aliases not found", Lists.newArrayList("myalias"), collAlias);
}
}
use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.
the class TestCollectionAPI method clusterStatusRolesTest.
private void clusterStatusRolesTest() throws Exception {
try (CloudSolrClient client = createCloudClient(null)) {
client.connect();
Replica replica = client.getZkStateReader().getLeaderRetry(DEFAULT_COLLECTION, SHARD1);
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.ADDROLE.toString());
params.set("node", replica.getNodeName());
params.set("role", "overseer");
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
client.request(request);
params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
params.set("collection", DEFAULT_COLLECTION);
request = new QueryRequest(params);
request.setPath("/admin/collections");
NamedList<Object> rsp = client.request(request);
NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
assertNotNull("Cluster state should not be null", cluster);
Map<String, Object> roles = (Map<String, Object>) cluster.get("roles");
assertNotNull("Role information should not be null", roles);
List<String> overseer = (List<String>) roles.get("overseer");
assertNotNull(overseer);
assertEquals(1, overseer.size());
assertTrue(overseer.contains(replica.getNodeName()));
}
}
use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.
the class TestCloudJSONFacetJoinDomain method assertFacetCountsAreCorrect.
/**
* Given a set of (potentially nested) term facets, and a base query string, asserts that
* the actual counts returned when executing that query with those facets match the expected results
* of filtering on the equivilent facet terms+domain
*/
private void assertFacetCountsAreCorrect(Map<String, TermFacet> expected, final String query) throws SolrServerException, IOException {
final SolrParams baseParams = params("q", query, "rows", "0");
final SolrParams facetParams = params("json.facet", "" + TermFacet.toJSONFacetParamValue(expected));
final SolrParams initParams = SolrParams.wrapAppended(facetParams, baseParams);
log.info("Doing full run: {}", initParams);
NamedList topResponse = null;
try {
topResponse = getRandClient(random()).request(new QueryRequest(initParams));
assertNotNull(initParams + " is null response?", topResponse);
} catch (Exception e) {
throw new RuntimeException("init query failed: " + initParams + ": " + e.getMessage(), e);
}
try {
final NamedList facetResponse = (NamedList) topResponse.get("facets");
assertNotNull("null facet results?", facetResponse);
assertFacetCountsAreCorrect(expected, baseParams, facetResponse);
} catch (AssertionError e) {
throw new AssertionError(initParams + " ===> " + topResponse + " --> " + e.getMessage(), e);
} finally {
log.info("Ending full run");
}
}
Aggregations