use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.
the class TestSolrCloudSnapshots method listCollectionSnapshots.
private Collection<CollectionSnapshotMetaData> listCollectionSnapshots(SolrClient adminClient, String collectionName) throws Exception {
CollectionAdminRequest.ListSnapshots listSnapshots = new CollectionAdminRequest.ListSnapshots(collectionName);
CollectionAdminResponse resp = listSnapshots.process(adminClient);
assertTrue(resp.getResponse().get(SolrSnapshotManager.SNAPSHOTS_INFO) instanceof NamedList);
NamedList apiResult = (NamedList) resp.getResponse().get(SolrSnapshotManager.SNAPSHOTS_INFO);
Collection<CollectionSnapshotMetaData> result = new ArrayList<>();
for (int i = 0; i < apiResult.size(); i++) {
result.add(new CollectionSnapshotMetaData((NamedList<Object>) apiResult.getVal(i)));
}
return result;
}
use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.
the class TestManagedSchemaAPI method testReloadAndAddSimple.
private void testReloadAndAddSimple(String collection) throws IOException, SolrServerException {
CloudSolrClient cloudClient = cluster.getSolrClient();
String fieldName = "myNewField";
addStringField(fieldName, collection, cloudClient);
CollectionAdminRequest.Reload reloadRequest = CollectionAdminRequest.reloadCollection(collection);
CollectionAdminResponse response = reloadRequest.process(cloudClient);
assertEquals(0, response.getStatus());
assertTrue(response.isSuccess());
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "1");
doc.addField(fieldName, "val");
UpdateRequest ureq = new UpdateRequest().add(doc);
cloudClient.request(ureq, collection);
}
use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.
the class CollectionsAPISolrJTest method testCreateAndDeleteShard.
@Test
public void testCreateAndDeleteShard() throws IOException, SolrServerException {
// Create an implicit collection
String collectionName = "solrj_implicit";
CollectionAdminResponse response = CollectionAdminRequest.createCollectionWithImplicitRouter(collectionName, "conf", "shardA,shardB", 1, 1, 1).setMaxShardsPerNode(3).process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
assertTrue(response.isSuccess());
Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
assertEquals(6, coresStatus.size());
// Add a shard to the implicit collection
response = CollectionAdminRequest.createShard(collectionName, "shardC").process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
assertTrue(response.isSuccess());
coresStatus = response.getCollectionCoresStatus();
assertEquals(3, coresStatus.size());
assertEquals(0, (int) coresStatus.get(Assign.buildCoreName(collectionName, "shardC", Replica.Type.NRT, 1)).get("status"));
assertEquals(0, (int) coresStatus.get(Assign.buildCoreName(collectionName, "shardC", Replica.Type.TLOG, 1)).get("status"));
assertEquals(0, (int) coresStatus.get(Assign.buildCoreName(collectionName, "shardC", Replica.Type.PULL, 1)).get("status"));
response = CollectionAdminRequest.deleteShard(collectionName, "shardC").process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
assertTrue(response.isSuccess());
Map<String, NamedList<Integer>> nodesStatus = response.getCollectionNodesStatus();
assertEquals(1, nodesStatus.size());
}
use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.
the class CollectionsAPISolrJTest method testCreateAndDeleteAlias.
@Test
public void testCreateAndDeleteAlias() throws IOException, SolrServerException {
final String collection = "aliasedCollection";
CollectionAdminRequest.createCollection(collection, "conf", 1, 1).process(cluster.getSolrClient());
CollectionAdminResponse response = CollectionAdminRequest.createAlias("solrj_alias", collection).process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
response = CollectionAdminRequest.deleteAlias("solrj_alias").process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
}
use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project incubator-atlas by apache.
the class Solr5Index method createCollectionIfNotExists.
private static void createCollectionIfNotExists(CloudSolrClient client, Configuration config, String collection) throws IOException, SolrServerException, KeeperException, InterruptedException {
if (!checkIfCollectionExists(client, collection)) {
Integer numShards = config.get(NUM_SHARDS);
Integer maxShardsPerNode = config.get(MAX_SHARDS_PER_NODE);
Integer replicationFactor = config.get(REPLICATION_FACTOR);
CollectionAdminRequest.Create createRequest = new CollectionAdminRequest.Create();
createRequest.setConfigName(collection);
createRequest.setCollectionName(collection);
createRequest.setNumShards(numShards);
createRequest.setMaxShardsPerNode(maxShardsPerNode);
createRequest.setReplicationFactor(replicationFactor);
CollectionAdminResponse createResponse = createRequest.process(client);
if (createResponse.isSuccess()) {
logger.trace("Collection {} successfully created.", collection);
} else {
throw new SolrServerException(Joiner.on("\n").join(createResponse.getErrorMessages()));
}
}
waitForRecoveriesToFinish(client, collection);
}
Aggregations