use of org.apache.solr.common.cloud.DocCollection in project lucene-solr by apache.
the class TestClusterStateMutator method testCreateCollection.
public void testCreateCollection() throws Exception {
ClusterState state = new ClusterState(-1, Collections.<String>emptySet(), Collections.<String, DocCollection>emptyMap());
MockZkStateReader zkStateReader = new MockZkStateReader(state, Collections.<String>emptySet());
ClusterState clusterState = zkStateReader.getClusterState();
ClusterStateMutator mutator = new ClusterStateMutator(zkStateReader);
ZkNodeProps message = new ZkNodeProps(Utils.makeMap("name", "xyz", "numShards", "1"));
ZkWriteCommand cmd = mutator.createCollection(clusterState, message);
DocCollection collection = cmd.collection;
assertEquals("xyz", collection.getName());
assertEquals(1, collection.getSlicesMap().size());
assertEquals(1, collection.getMaxShardsPerNode());
state = new ClusterState(-1, Collections.<String>emptySet(), Collections.singletonMap("xyz", collection));
message = new ZkNodeProps(Utils.makeMap("name", "abc", "numShards", "2", "router.name", "implicit", "shards", "x,y", "replicationFactor", "3", "maxShardsPerNode", "4"));
cmd = mutator.createCollection(state, message);
collection = cmd.collection;
assertEquals("abc", collection.getName());
assertEquals(2, collection.getSlicesMap().size());
assertNotNull(collection.getSlicesMap().get("x"));
assertNotNull(collection.getSlicesMap().get("y"));
assertNull(collection.getSlicesMap().get("x").getRange());
assertNull(collection.getSlicesMap().get("y").getRange());
assertSame(Slice.State.ACTIVE, collection.getSlicesMap().get("x").getState());
assertSame(Slice.State.ACTIVE, collection.getSlicesMap().get("y").getState());
assertEquals(4, collection.getMaxShardsPerNode());
assertEquals(ImplicitDocRouter.class, collection.getRouter().getClass());
// we still have the old collection
assertNotNull(state.getCollectionOrNull("xyz"));
}
use of org.apache.solr.common.cloud.DocCollection in project lucene-solr by apache.
the class ZkStateReaderTest method testWatchedCollectionCreation.
public void testWatchedCollectionCreation() throws Exception {
String zkDir = createTempDir("testWatchedCollectionCreation").toFile().getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
SolrZkClient zkClient = null;
ZkStateReader reader = null;
try {
server.run();
AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
ZkController.createClusterZkNodes(zkClient);
reader = new ZkStateReader(zkClient);
reader.createClusterStateWatchersAndUpdate();
reader.registerCore("c1");
// Initially there should be no c1 collection.
assertNull(reader.getClusterState().getCollectionRef("c1"));
zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true);
reader.forceUpdateCollection("c1");
// Still no c1 collection, despite a collection path.
assertNull(reader.getClusterState().getCollectionRef("c1"));
ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
// create new collection with stateFormat = 2
DocCollection state = new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE + "/c1/state.json");
ZkWriteCommand wc = new ZkWriteCommand("c1", state);
writer.enqueueUpdate(reader.getClusterState(), wc, null);
writer.writePendingUpdates();
assertTrue(zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true));
//reader.forceUpdateCollection("c1");
reader.waitForState("c1", TIMEOUT, TimeUnit.SECONDS, (n, c) -> c != null);
ClusterState.CollectionRef ref = reader.getClusterState().getCollectionRef("c1");
assertNotNull(ref);
assertFalse(ref.isLazilyLoaded());
assertEquals(2, ref.get().getStateFormat());
} finally {
IOUtils.close(reader, zkClient);
server.shutdown();
}
}
use of org.apache.solr.common.cloud.DocCollection in project lucene-solr by apache.
the class ZkStateReaderTest method testExternalCollectionWatchedNotWatched.
public void testExternalCollectionWatchedNotWatched() throws Exception {
String zkDir = createTempDir("testExternalCollectionWatchedNotWatched").toFile().getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
SolrZkClient zkClient = null;
ZkStateReader reader = null;
try {
server.run();
AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
ZkController.createClusterZkNodes(zkClient);
reader = new ZkStateReader(zkClient);
reader.createClusterStateWatchersAndUpdate();
ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true);
// create new collection with stateFormat = 2
ZkWriteCommand c1 = new ZkWriteCommand("c1", new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json"));
writer.enqueueUpdate(reader.getClusterState(), c1, null);
writer.writePendingUpdates();
reader.forceUpdateCollection("c1");
assertTrue(reader.getClusterState().getCollectionRef("c1").isLazilyLoaded());
reader.registerCore("c1");
assertFalse(reader.getClusterState().getCollectionRef("c1").isLazilyLoaded());
reader.unregisterCore("c1");
assertTrue(reader.getClusterState().getCollectionRef("c1").isLazilyLoaded());
} finally {
IOUtils.close(reader, zkClient);
server.shutdown();
}
}
use of org.apache.solr.common.cloud.DocCollection in project lucene-solr by apache.
the class RulesTest method testModifyColl.
@Test
public void testModifyColl() throws Exception {
final long minGB1 = (random().nextBoolean() ? 1 : 0);
final long minGB2 = 5;
assumeTrue("testModifyColl needs minGB1=" + minGB1 + " usable disk space", ImplicitSnitch.getUsableSpaceInGB(Paths.get("/")) > minGB1);
assumeTrue("testModifyColl needs minGB2=" + minGB2 + " usable disk space", ImplicitSnitch.getUsableSpaceInGB(Paths.get("/")) > minGB2);
String rulesColl = "modifyColl";
CollectionAdminRequest.createCollection(rulesColl, "conf", 1, 2).setRule("cores:<4", "node:*,replica:1", "freedisk:>" + minGB1).setSnitch("class:ImplicitSnitch").process(cluster.getSolrClient());
// TODO: Make a MODIFYCOLLECTION SolrJ class
ModifiableSolrParams p = new ModifiableSolrParams();
p.add("collection", rulesColl);
p.add("action", "MODIFYCOLLECTION");
p.add("rule", "cores:<5");
p.add("rule", "node:*,replica:1");
p.add("rule", "freedisk:>" + minGB2);
p.add("autoAddReplicas", "true");
cluster.getSolrClient().request(new GenericSolrRequest(POST, COLLECTIONS_HANDLER_PATH, p));
DocCollection rulesCollection = getCollectionState(rulesColl);
log.info("version_of_coll {} ", rulesCollection.getZNodeVersion());
List list = (List) rulesCollection.get("rule");
assertEquals(3, list.size());
assertEquals("<5", ((Map) list.get(0)).get("cores"));
assertEquals("1", ((Map) list.get(1)).get("replica"));
assertEquals(">" + minGB2, ((Map) list.get(2)).get("freedisk"));
assertEquals("true", String.valueOf(rulesCollection.getProperties().get("autoAddReplicas")));
list = (List) rulesCollection.get("snitch");
assertEquals(1, list.size());
assertEquals("ImplicitSnitch", ((Map) list.get(0)).get("class"));
}
use of org.apache.solr.common.cloud.DocCollection in project lucene-solr by apache.
the class RulesTest method doIntegrationTest.
@Test
public void doIntegrationTest() throws Exception {
final long minGB = (random().nextBoolean() ? 1 : 0);
assumeTrue("doIntegrationTest needs minGB=" + minGB + " usable disk space", ImplicitSnitch.getUsableSpaceInGB(Paths.get("/")) > minGB);
String rulesColl = "rulesColl";
CollectionAdminRequest.createCollectionWithImplicitRouter(rulesColl, "conf", "shard1", 2).setRule("cores:<4", "node:*,replica:<2", "freedisk:>" + minGB).setSnitch("class:ImplicitSnitch").process(cluster.getSolrClient());
DocCollection rulesCollection = getCollectionState(rulesColl);
List list = (List) rulesCollection.get("rule");
assertEquals(3, list.size());
assertEquals("<4", ((Map) list.get(0)).get("cores"));
assertEquals("<2", ((Map) list.get(1)).get("replica"));
assertEquals(">" + minGB, ((Map) list.get(2)).get("freedisk"));
list = (List) rulesCollection.get("snitch");
assertEquals(1, list.size());
assertEquals("ImplicitSnitch", ((Map) list.get(0)).get("class"));
CollectionAdminRequest.createShard(rulesColl, "shard2").process(cluster.getSolrClient());
CollectionAdminRequest.addReplicaToShard(rulesColl, "shard2").process(cluster.getSolrClient());
}
Aggregations