org.apache.solr.common.params.CollectionParams Java Examples
The following examples show how to use
org.apache.solr.common.params.CollectionParams.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestCollectionAPIs.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override void invokeAction(SolrQueryRequest req, SolrQueryResponse rsp, CoreContainer cores, CollectionParams.CollectionAction action, CollectionOperation operation) throws Exception { Map<String, Object> result = null; if (action == CollectionParams.CollectionAction.COLLECTIONPROP) { //Fake this action, since we don't want to write to ZooKeeper in this test result = new HashMap<>(); result.put(NAME, req.getParams().required().get(NAME)); result.put(PROPERTY_NAME, req.getParams().required().get(PROPERTY_NAME)); result.put(PROPERTY_VALUE, req.getParams().required().get(PROPERTY_VALUE)); } else { result = operation.execute(req, rsp, this); } if (result != null) { result.put(QUEUE_OPERATION, operation.action.toLower()); rsp.add(ZkNodeProps.class.getName(), new ZkNodeProps(result)); } }
Example #2
Source File: CollectionAdminRequest.java From lucene-solr with Apache License 2.0 | 6 votes |
default ModifiableSolrParams mergeCollParams(Create createCollTemplate) { ModifiableSolrParams createCollParams = new ModifiableSolrParams(); // output target if (createCollTemplate == null) { return createCollParams; } final SolrParams collParams = createCollTemplate.getParams(); final Iterator<String> pIter = collParams.getParameterNamesIterator(); while (pIter.hasNext()) { String key = pIter.next(); if (key.equals(CollectionParams.ACTION) || key.equals("name")) { continue; } createCollParams.set("create-collection." + key, collParams.getParams(key)); } return createCollParams; }
Example #3
Source File: CollectionAdminRequest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public SolrParams getParams() { ModifiableSolrParams params = (ModifiableSolrParams) super.getParams(); params.set(CoreAdminParams.COLLECTION, collection); params.set(CollectionParams.TARGET_NODE, targetNode); params.set(CommonAdminParams.IN_PLACE_MOVE, inPlaceMove); if (timeout != -1) { params.set(CommonAdminParams.TIMEOUT, timeout); } if (randomlyMoveReplica) { params.set(CoreAdminParams.SHARD, shard); params.set(CollectionParams.SOURCE_NODE, sourceNode); } else { params.set(CoreAdminParams.REPLICA, replica); } return params; }
Example #4
Source File: TestRebalanceLeaders.java From lucene-solr with Apache License 2.0 | 6 votes |
void setPropWithStandardRequest(Slice slice, Replica rep, String prop) throws IOException, SolrServerException { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.ADDREPLICAPROP.toString()); params.set("collection", COLLECTION_NAME); params.set("shard", slice.getName()); params.set("replica", rep.getName()); params.set("property", prop); params.set("property.value", "true"); // Test to insure that implicit shardUnique is added for preferredLeader. if (prop.toLowerCase(Locale.ROOT).equals("preferredleader") == false) { params.set("shardUnique", "true"); } @SuppressWarnings({"rawtypes"}) SolrRequest request = new QueryRequest(params); request.setPath("/admin/collections"); cluster.getSolrClient().request(request); String propLC = prop.toLowerCase(Locale.ROOT); waitForState("Expecting property '" + prop + "'to appear on replica " + rep.getName(), COLLECTION_NAME, (n, c) -> "true".equals(c.getReplica(rep.getName()).getProperty(propLC))); }
Example #5
Source File: TestPolicy.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testComputePlanAfterNodeAdded() { String autoScalingjson = "cluster-preferences:[" + " {minimize : cores}," + " {'maximize':freedisk , precision:100}], " + " cluster-policy:[{cores:'<10',node:'#ANY'}," + " {replica:'<2', shard:'#EACH',node:'#ANY'}," + " { nodeRole:overseer,replica:0}]}"; if(useNodeset){ autoScalingjson = "cluster-preferences:[" + " {minimize : cores}," + " {'maximize':freedisk , precision:100}], " + " cluster-policy:[{cores:'<10',node:'#ANY'}," + " {replica:'<2', shard:'#EACH',node:'#ANY'}," + " {nodeset:{ nodeRole:overseer},replica:0}]}"; } @SuppressWarnings({"unchecked"}) Policy policy = new Policy((Map<String, Object>) Utils.fromJSONString(autoScalingjson)); Policy.Session session = policy.createSession(cloudManagerWithData((Map) loadFromResource("testComputePlanAfterNodeAdded.json"))); Suggester suggester = session.getSuggester(CollectionParams.CollectionAction.MOVEREPLICA) .hint(Hint.TARGET_NODE, "127.0.0.1:51147_solr"); @SuppressWarnings({"rawtypes"}) SolrRequest op = suggester.getSuggestion(); log.info("{}", op); assertNotNull("operation expected ", op); }
Example #6
Source File: MtasSolrTestDistributedSearchConsistency.java From mtas with Apache License 2.0 | 6 votes |
/** * Creates the cloud collection. * * @param collectionName * the collection name * @param numShards * the num shards * @param replicationFactor * the replication factor * @param confDir * the conf dir * @throws Exception * the exception */ private static void createCloudCollection(String collectionName, int numShards, int replicationFactor, Path confDir) throws Exception { CloudSolrClient client = cloudCluster.getSolrClient(); String confName = collectionName + "Configuration"; if (confDir != null) { SolrZkClient zkClient = client.getZkStateReader().getZkClient(); ZkConfigManager zkConfigManager = new ZkConfigManager(zkClient); zkConfigManager.uploadConfigDir(confDir, confName); } ModifiableSolrParams modParams = new ModifiableSolrParams(); modParams.set(CoreAdminParams.ACTION, CollectionParams.CollectionAction.CREATE.name()); modParams.set("name", collectionName); modParams.set("numShards", numShards); modParams.set("replicationFactor", replicationFactor); int liveNodes = client.getZkStateReader().getClusterState().getLiveNodes() .size(); int maxShardsPerNode = (int) Math .ceil(((double) numShards * replicationFactor) / liveNodes); modParams.set("maxShardsPerNode", maxShardsPerNode); modParams.set("collection.configName", confName); QueryRequest request = new QueryRequest(modParams); request.setPath("/admin/collections"); client.request(request); }
Example #7
Source File: ReplaceNodeTest.java From lucene-solr with Apache License 2.0 | 6 votes |
public static CollectionAdminRequest.AsyncCollectionAdminRequest createReplaceNodeRequest(String sourceNode, String targetNode, Boolean parallel) { if (random().nextBoolean()) { return new CollectionAdminRequest.ReplaceNode(sourceNode, targetNode).setParallel(parallel); } else { // test back compat with old param names // todo remove in solr 8.0 return new CollectionAdminRequest.AsyncCollectionAdminRequest(CollectionParams.CollectionAction.REPLACENODE) { @Override public SolrParams getParams() { ModifiableSolrParams params = (ModifiableSolrParams) super.getParams(); params.set("source", sourceNode); params.setNonNull("target", targetNode); if (parallel != null) params.set("parallel", parallel.toString()); return params; } }; } }
Example #8
Source File: TestCollectionAPI.java From lucene-solr with Apache License 2.0 | 6 votes |
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); @SuppressWarnings({"rawtypes"}) SolrRequest request = new QueryRequest(params); request.setPath("/admin/collections"); try { client.request(request); fail(); } catch (BaseHttpSolrClient.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")); } } }
Example #9
Source File: TestCollectionAPI.java From lucene-solr with Apache License 2.0 | 6 votes |
private void testCollectionCreationShardNameValidation() throws Exception { try (CloudSolrClient client = createCloudClient(null)) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CREATE.toString()); params.set("name", "valid_collection_name"); params.set("router.name", "implicit"); params.set("numShards", "1"); params.set("shards", "invalid@name#with$weird%characters"); @SuppressWarnings({"rawtypes"}) SolrRequest request = new QueryRequest(params); request.setPath("/admin/collections"); try { client.request(request); fail(); } catch (BaseHttpSolrClient.RemoteSolrException e) { final String errorMessage = e.getMessage(); assertTrue(errorMessage.contains("Invalid shard")); assertTrue(errorMessage.contains("invalid@name#with$weird%characters")); assertTrue(errorMessage.contains("shard names must consist entirely of")); } } }
Example #10
Source File: TestCollectionAPI.java From lucene-solr with Apache License 2.0 | 6 votes |
private void testCollectionCreationCollectionNameValidation() throws Exception { try (CloudSolrClient client = createCloudClient(null)) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CREATE.toString()); params.set("name", "invalid@name#with$weird%characters"); @SuppressWarnings({"rawtypes"}) SolrRequest request = new QueryRequest(params); request.setPath("/admin/collections"); try { client.request(request); fail(); } catch (BaseHttpSolrClient.RemoteSolrException e) { final String errorMessage = e.getMessage(); assertTrue(errorMessage.contains("Invalid collection")); assertTrue(errorMessage.contains("invalid@name#with$weird%characters")); assertTrue(errorMessage.contains("collection names must consist entirely of")); } } }
Example #11
Source File: NodeAddedTrigger.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void configure(SolrResourceLoader loader, SolrCloudManager cloudManager, Map<String, Object> properties) throws TriggerValidationException { super.configure(loader, cloudManager, properties); preferredOp = (String) properties.getOrDefault(PREFERRED_OP, CollectionParams.CollectionAction.MOVEREPLICA.toLower()); preferredOp = preferredOp.toLowerCase(Locale.ROOT); String replicaTypeStr = (String) properties.getOrDefault(REPLICA_TYPE, Replica.Type.NRT.name()); // verify try { replicaType = Replica.Type.valueOf(replicaTypeStr); } catch (IllegalArgumentException | NullPointerException e) { throw new TriggerValidationException("Unsupported replicaType=" + replicaTypeStr + " specified for node added trigger"); } CollectionParams.CollectionAction action = CollectionParams.CollectionAction.get(preferredOp); switch (action) { case ADDREPLICA: case MOVEREPLICA: case NONE: break; default: throw new TriggerValidationException("Unsupported preferredOperation=" + preferredOp + " specified for node added trigger"); } }
Example #12
Source File: SimClusterStateProvider.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * The instance needs to be initialized using the <code>sim*</code> methods in order * to ensure proper behavior, otherwise it will behave as a cluster with zero replicas. */ public SimClusterStateProvider(LiveNodesSet liveNodes, SimCloudManager cloudManager) throws Exception { this.liveNodes = liveNodes; for (String nodeId : liveNodes.get()) { createEphemeralLiveNode(nodeId); } this.cloudManager = cloudManager; this.stateManager = cloudManager.getSimDistribStateManager(); // names are CollectionAction operation names, delays are in ms (simulated time) defaultOpDelays.put(CollectionParams.CollectionAction.MOVEREPLICA.name(), 5000L); defaultOpDelays.put(CollectionParams.CollectionAction.DELETEREPLICA.name(), 5000L); defaultOpDelays.put(CollectionParams.CollectionAction.ADDREPLICA.name(), 500L); defaultOpDelays.put(CollectionParams.CollectionAction.SPLITSHARD.name(), 5000L); defaultOpDelays.put(CollectionParams.CollectionAction.CREATESHARD.name(), 5000L); defaultOpDelays.put(CollectionParams.CollectionAction.DELETESHARD.name(), 5000L); defaultOpDelays.put(CollectionParams.CollectionAction.CREATE.name(), 500L); defaultOpDelays.put(CollectionParams.CollectionAction.DELETE.name(), 5000L); }
Example #13
Source File: TestCollectionAPI.java From lucene-solr with Apache License 2.0 | 6 votes |
private void clusterStatusBadCollectionTest() throws Exception { try (CloudSolrClient client = createCloudClient(null)) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); params.set("collection", "bad_collection_name"); @SuppressWarnings({"rawtypes"}) SolrRequest request = new QueryRequest(params); request.setPath("/admin/collections"); try { client.request(request); fail("Collection does not exist. An exception should be thrown"); } catch (SolrException e) { //expected assertTrue(e.getMessage().contains("Collection: bad_collection_name not found")); } } }
Example #14
Source File: TestCollectionAPI.java From lucene-solr with Apache License 2.0 | 6 votes |
private void clusterStatusWithCollection() throws IOException, SolrServerException { try (CloudSolrClient client = createCloudClient(null)) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); params.set("collection", COLLECTION_NAME); @SuppressWarnings({"rawtypes"}) SolrRequest request = new QueryRequest(params); request.setPath("/admin/collections"); NamedList<Object> rsp = client.request(request); @SuppressWarnings({"unchecked"}) NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster"); assertNotNull("Cluster state should not be null", cluster); @SuppressWarnings({"unchecked"}) NamedList<Object> collections = (NamedList<Object>) cluster.get("collections"); assertNotNull("Collections should not be null in cluster state", collections); assertEquals(1, collections.size()); @SuppressWarnings({"unchecked"}) Map<String, Object> collection = (Map<String, Object>) collections.get(COLLECTION_NAME); assertNotNull(collection); assertEquals("conf1", collection.get("configName")); // assertEquals("1", collection.get("nrtReplicas")); } }
Example #15
Source File: NodeLostTrigger.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void configure(SolrResourceLoader loader, SolrCloudManager cloudManager, Map<String, Object> properties) throws TriggerValidationException { super.configure(loader, cloudManager, properties); preferredOp = (String) properties.getOrDefault(PREFERRED_OP, CollectionParams.CollectionAction.MOVEREPLICA.toLower()); preferredOp = preferredOp.toLowerCase(Locale.ROOT); // verify CollectionParams.CollectionAction action = CollectionParams.CollectionAction.get(preferredOp); switch (action) { case MOVEREPLICA: case DELETENODE: case NONE: break; default: throw new TriggerValidationException("Unsupported preferredOperation=" + preferredOp + " specified for node lost trigger"); } }
Example #16
Source File: TestCollectionAPI.java From lucene-solr with Apache License 2.0 | 6 votes |
private void clusterStatusNoCollection() throws Exception { try (CloudSolrClient client = createCloudClient(null)) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); @SuppressWarnings({"rawtypes"}) SolrRequest request = new QueryRequest(params); request.setPath("/admin/collections"); NamedList<Object> rsp = client.request(request); @SuppressWarnings({"unchecked"}) NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster"); assertNotNull("Cluster state should not be null", cluster); @SuppressWarnings({"unchecked"}) NamedList<Object> collections = (NamedList<Object>) cluster.get("collections"); assertNotNull("Collections should not be null in cluster state", collections); assertNotNull(collections.get(COLLECTION_NAME1)); assertEquals(4, collections.size()); @SuppressWarnings({"unchecked"}) List<String> liveNodes = (List<String>) cluster.get("live_nodes"); assertNotNull("Live nodes should not be null", liveNodes); assertFalse(liveNodes.isEmpty()); } }
Example #17
Source File: SimScenario.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void execute(SimScenario scenario) throws Exception { String[] collections = params.remove("collection"); if (collections == null || collections.length == 0) { throw new IOException("'collection' param is required but missing: " + params); } Map<String, Long> delays = new HashMap<>(); params.forEach(e -> { String key = e.getKey(); CollectionParams.CollectionAction a = CollectionParams.CollectionAction.get(key); if (a == null) { log.warn("Invalid collection action {}, skipping...", key); return; } String[] values = e.getValue(); if (values == null || values[0].isBlank()) { delays.put(a.name(), null); } else { Long value = Long.parseLong(values[0]); delays.put(a.name(), value); } }); for (String collection : collections) { scenario.cluster.getSimClusterStateProvider().simSetOpDelays(collection, delays); } }
Example #18
Source File: TestCollectionAPI.java From lucene-solr with Apache License 2.0 | 6 votes |
private void listCollection() throws IOException, SolrServerException { try (CloudSolrClient client = createCloudClient(null)) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.LIST.toString()); @SuppressWarnings({"rawtypes"}) SolrRequest request = new QueryRequest(params); request.setPath("/admin/collections"); NamedList<Object> rsp = client.request(request); @SuppressWarnings({"unchecked"}) List<String> collections = (List<String>) rsp.get("collections"); assertTrue("control_collection was not found in list", collections.contains("control_collection")); assertTrue(DEFAULT_COLLECTION + " was not found in list", collections.contains(DEFAULT_COLLECTION)); assertTrue(COLLECTION_NAME + " was not found in list", collections.contains(COLLECTION_NAME)); assertTrue(COLLECTION_NAME1 + " was not found in list", collections.contains(COLLECTION_NAME1)); } }
Example #19
Source File: TestCollectionAPI.java From lucene-solr with Apache License 2.0 | 6 votes |
private void assertCountsForRepFactorAndNrtReplicas(CloudSolrClient client, String collectionName) throws Exception { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); params.set("collection", collectionName); QueryRequest request = new QueryRequest(params); request.setPath("/admin/collections"); NamedList<Object> rsp = client.request(request); @SuppressWarnings({"unchecked"}) NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster"); assertNotNull("Cluster state should not be null", cluster); @SuppressWarnings({"unchecked"}) NamedList<Object> collections = (NamedList<Object>) cluster.get("collections"); assertNotNull("Collections should not be null in cluster state", collections); assertEquals(1, collections.size()); @SuppressWarnings({"unchecked"}) Map<String, Object> collection = (Map<String, Object>) collections.get(collectionName); assertNotNull(collection); assertEquals(collection.get("replicationFactor"), collection.get("nrtReplicas")); }
Example #20
Source File: TestCollectionAPI.java From lucene-solr with Apache License 2.0 | 6 votes |
private void testCollectionCreationTooManyShards() throws Exception { try (CloudSolrClient client = createCloudClient(null)) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CREATE.toString()); params.set("name", "collection_too_many"); params.set("router.name", "implicit"); params.set("numShards", "10"); params.set("maxShardsPerNode", 1); params.set("shards", "b0,b1,b2,b3,b4,b5,b6,b7,b8,b9"); @SuppressWarnings({"rawtypes"}) SolrRequest request = new QueryRequest(params); request.setPath("/admin/collections"); try { client.request(request); fail("A collection creation request with too many shards than allowed by maxShardsPerNode should not have succeeded"); } catch (BaseHttpSolrClient.RemoteSolrException e) { final String errorMessage = e.getMessage(); assertTrue(errorMessage.contains("Cannot create collection")); assertTrue(errorMessage.contains("This requires 10 shards to be created (higher than the allowed number)")); assertMissingCollection(client, "collection_too_many"); } } }
Example #21
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 6 votes |
public void checkOverseerDesignate() { try { byte[] data = zkClient.getData(ZkStateReader.ROLES, null, new Stat(), true); if (data == null) return; @SuppressWarnings({"rawtypes"}) Map roles = (Map) Utils.fromJSON(data); if (roles == null) return; @SuppressWarnings({"rawtypes"}) List nodeList = (List) roles.get("overseer"); if (nodeList == null) return; if (nodeList.contains(getNodeName())) { ZkNodeProps props = new ZkNodeProps(Overseer.QUEUE_OPERATION, CollectionParams.CollectionAction.ADDROLE.toString().toLowerCase(Locale.ROOT), "node", getNodeName(), "role", "overseer"); log.info("Going to add role {} ", props); getOverseerCollectionQueue().offer(Utils.toJSON(props)); } } catch (NoNodeException nne) { return; } catch (Exception e) { log.warn("could not read the overseer designate ", e); } }
Example #22
Source File: TestReplicaProperties.java From lucene-solr with Apache License 2.0 | 6 votes |
private void listCollection() throws IOException, SolrServerException { try (CloudSolrClient client = createCloudClient(null)) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.LIST.toString()); @SuppressWarnings({"rawtypes"}) SolrRequest request = new QueryRequest(params); request.setPath("/admin/collections"); NamedList<Object> rsp = client.request(request); @SuppressWarnings({"unchecked"}) List<String> collections = (List<String>) rsp.get("collections"); assertTrue("control_collection was not found in list", collections.contains("control_collection")); assertTrue(DEFAULT_COLLECTION + " was not found in list", collections.contains(DEFAULT_COLLECTION)); assertTrue(COLLECTION_NAME + " was not found in list", collections.contains(COLLECTION_NAME)); } }
Example #23
Source File: TriggerEvent.java From lucene-solr with Apache License 2.0 | 5 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) public static Op fromMap(Map<String, Object> map) { if (!map.containsKey("action")) { return null; } CollectionParams.CollectionAction action = CollectionParams.CollectionAction.get(String.valueOf(map.get("action"))); if (action == null) { return null; } Op op = new Op(action); Map<Object, Object> hints = (Map<Object, Object>)map.get("hints"); if (hints != null && !hints.isEmpty()) { hints.forEach((k, v) -> { Suggester.Hint h = Suggester.Hint.get(k.toString()); if (h == null) { return; } if (!(v instanceof Collection)) { v = Collections.singletonList(v); } ((Collection)v).forEach(vv -> { if (vv instanceof Map) { // maybe it's a Pair? Map<String, Object> m = (Map<String, Object>)vv; if (m.containsKey("first") && m.containsKey("second")) { Pair p = Pair.parse(m); if (p != null) { op.addHint(h, p); return; } } } op.addHint(h, vv); }); }); } return op; }
Example #24
Source File: OverseerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Create a collection. * Note there's a similar but slightly different {@link OverseerTest#createCollection(String, int)}. */ public void createCollection(String collection, int numShards) throws Exception { // Create collection znode before having ClusterStateUpdater create state.json below it or it will fail. zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection, true); ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, CollectionParams.CollectionAction.CREATE.toLower(), "name", collection, ZkStateReader.REPLICATION_FACTOR, "1", ZkStateReader.NUM_SHARDS_PROP, Integer.toString(numShards), "createNodeSet", ""); ZkDistributedQueue q = MiniSolrCloudCluster.getOpenOverseer(overseers).getStateUpdateQueue(); q.offer(Utils.toJSON(m)); }
Example #25
Source File: OverseerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * This method creates a collection. It is different from {@link MockZKController#createCollection(String, int)} in * the way the {@link ZkDistributedQueue} is obtained. */ private void createCollection(String collection, int numShards) throws Exception { // Create collection znode before having ClusterStateUpdater create state.json below it or it will fail. zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection, true); ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, CollectionParams.CollectionAction.CREATE.toLower(), "name", collection, ZkStateReader.REPLICATION_FACTOR, "1", ZkStateReader.NUM_SHARDS_PROP, Integer.toString(numShards), "createNodeSet", ""); ZkDistributedQueue q = overseers.get(0).getStateUpdateQueue(); q.offer(Utils.toJSON(m)); }
Example #26
Source File: TestCollectionAPI.java From lucene-solr with Apache License 2.0 | 5 votes |
private void clusterStatusWithCollectionAndShard() throws IOException, SolrServerException { try (CloudSolrClient client = createCloudClient(null)) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); params.set("collection", COLLECTION_NAME); params.set("shard", SHARD1); @SuppressWarnings({"rawtypes"}) SolrRequest request = new QueryRequest(params); request.setPath("/admin/collections"); NamedList<Object> rsp = client.request(request); @SuppressWarnings({"unchecked"}) NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster"); assertNotNull("Cluster state should not be null", cluster); @SuppressWarnings({"unchecked"}) NamedList<Object> collections = (NamedList<Object>) cluster.get("collections"); assertNotNull("Collections should not be null in cluster state", collections); assertNotNull(collections.get(COLLECTION_NAME)); assertEquals(1, collections.size()); @SuppressWarnings({"unchecked"}) Map<String, Object> collection = (Map<String, Object>) collections.get(COLLECTION_NAME); @SuppressWarnings({"unchecked"}) Map<String, Object> shardStatus = (Map<String, Object>) collection.get("shards"); assertEquals(1, shardStatus.size()); @SuppressWarnings({"unchecked"}) Map<String, Object> selectedShardStatus = (Map<String, Object>) shardStatus.get(SHARD1); assertNotNull(selectedShardStatus); } }
Example #27
Source File: TestCollectionAPI.java From lucene-solr with Apache License 2.0 | 5 votes |
private void testNoConfigset() throws Exception { String configSet = "delete_config"; final String collection = "deleted_collection"; try (CloudSolrClient client = createCloudClient(null)) { copyConfigUp(TEST_PATH().resolve("configsets"), "cloud-minimal", configSet, client.getZkHost()); ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CREATE.toString()); params.set("name", collection); params.set("numShards", "1"); params.set("replicationFactor", "1"); params.set("collection.configName", configSet); @SuppressWarnings({"rawtypes"}) SolrRequest request = new QueryRequest(params); request.setPath("/admin/collections"); client.request(request); waitForCollection(cloudClient.getZkStateReader(), collection, 1); waitForRecoveriesToFinish(collection, false); // Now try deleting the configset and doing a clusterstatus. String parent = ZkConfigManager.CONFIGS_ZKNODE + "/" + configSet; deleteThemAll(client.getZkStateReader().getZkClient(), parent); client.getZkStateReader().forciblyRefreshAllClusterStateSlow(); final CollectionAdminRequest.ClusterStatus req = CollectionAdminRequest.getClusterStatus(); NamedList<Object> rsp = client.request(req); @SuppressWarnings({"unchecked"}) NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster"); assertNotNull("Cluster state should not be null", cluster); @SuppressWarnings({"unchecked"}) NamedList<Object> collections = (NamedList<Object>) cluster.get("collections"); assertNotNull("Collections should not be null in cluster state", collections); assertNotNull("Testing to insure collections are returned", collections.get(COLLECTION_NAME1)); } }
Example #28
Source File: OverseerCollectionConfigSetProcessorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private void handleCreateCollMessage(byte[] bytes) { log.info("track created replicas / collections"); try { ZkNodeProps props = ZkNodeProps.load(bytes); if (CollectionParams.CollectionAction.CREATE.isEqual(props.getStr("operation"))) { String collName = props.getStr("name"); if (collName != null) collectionsSet.put(collName, new ClusterState.CollectionRef( new DocCollection(collName, new HashMap<>(), props.getProperties(), DocRouter.DEFAULT))); } if (CollectionParams.CollectionAction.ADDREPLICA.isEqual(props.getStr("operation"))) { replicas.add(props); } } catch (Exception e) {} }
Example #29
Source File: OverseerCollectionConfigSetProcessorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
protected void issueCreateJob(Integer numberOfSlices, Integer replicationFactor, Integer maxShardsPerNode, List<String> createNodeList, boolean sendCreateNodeList, boolean createNodeSetShuffle) { Map<String,Object> propMap = Utils.makeMap( Overseer.QUEUE_OPERATION, CollectionParams.CollectionAction.CREATE.toLower(), ZkStateReader.REPLICATION_FACTOR, replicationFactor.toString(), "name", COLLECTION_NAME, "collection.configName", CONFIG_NAME, OverseerCollectionMessageHandler.NUM_SLICES, numberOfSlices.toString(), ZkStateReader.MAX_SHARDS_PER_NODE, maxShardsPerNode.toString() ); if (sendCreateNodeList) { propMap.put(OverseerCollectionMessageHandler.CREATE_NODE_SET, (createNodeList != null)?StrUtils.join(createNodeList, ','):null); if (OverseerCollectionMessageHandler.CREATE_NODE_SET_SHUFFLE_DEFAULT != createNodeSetShuffle || random().nextBoolean()) { propMap.put(OverseerCollectionMessageHandler.CREATE_NODE_SET_SHUFFLE, createNodeSetShuffle); } } ZkNodeProps props = new ZkNodeProps(propMap); QueueEvent qe = new QueueEvent("id", Utils.toJSON(props), null){ @Override public void setBytes(byte[] bytes) { lastProcessMessageResult = OverseerSolrResponseSerializer.deserialize(bytes); } }; queue.add(qe); }
Example #30
Source File: TestCollectionAPI.java From lucene-solr with Apache License 2.0 | 5 votes |
private void clusterStatusWithRouteKey() throws IOException, SolrServerException { try (CloudSolrClient client = createCloudClient(DEFAULT_COLLECTION)) { SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "a!123"); // goes to shard2. see ShardRoutingTest for details client.add(doc); client.commit(); ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); params.set("collection", DEFAULT_COLLECTION); params.set(ShardParams._ROUTE_, "a!"); @SuppressWarnings({"rawtypes"}) SolrRequest request = new QueryRequest(params); request.setPath("/admin/collections"); NamedList<Object> rsp = client.request(request); @SuppressWarnings({"unchecked"}) NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster"); assertNotNull("Cluster state should not be null", cluster); @SuppressWarnings({"unchecked"}) NamedList<Object> collections = (NamedList<Object>) cluster.get("collections"); assertNotNull("Collections should not be null in cluster state", collections); assertNotNull(collections.get(DEFAULT_COLLECTION)); assertEquals(1, collections.size()); @SuppressWarnings({"unchecked"}) Map<String, Object> collection = (Map<String, Object>) collections.get(DEFAULT_COLLECTION); assertEquals("conf1", collection.get("configName")); @SuppressWarnings({"unchecked"}) Map<String, Object> shardStatus = (Map<String, Object>) collection.get("shards"); assertEquals(1, shardStatus.size()); @SuppressWarnings({"unchecked"}) Map<String, Object> selectedShardStatus = (Map<String, Object>) shardStatus.get(SHARD2); assertNotNull(selectedShardStatus); } }