NamedList<Object> listResponse = new CollectionAdminRequest.List().process(primary).getResponse(); List<String> collectionNames = listResponse.get("collections") == null ? collectionNames = new ArrayList<>() : (List<String>) listResponse.get("collections"); listResponse = new CollectionAdminRequest.List().process(primary).getResponse(); collectionNames = listResponse.get("collections") == null ? collectionNames = new ArrayList<>() : (List<String>) listResponse.get("collections");
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); // Ideally this property used so a new configset is not uploaded for every single // index (collection) created in solr. // if a generic configSet is not set, make the configset name the same as the collection. // This was the default behavior before a default configSet could be specified String genericConfigSet = config.has(SOLR_DEFAULT_CONFIG) ? config.get(SOLR_DEFAULT_CONFIG):collection; CollectionAdminRequest.Create createRequest = new CollectionAdminRequest.Create(); createRequest.setConfigName(genericConfigSet); 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); }
protected boolean existsCloudCollection(String name) throws IOException, SolrServerException { CollectionAdminRequest.List listRequest = new CollectionAdminRequest.List(); CollectionAdminResponse response = listRequest.process(getClient(), name); if (response.getErrorMessages() != null) { throw new DatastoreClientServiceException("Unable to fetch collection list"); } return ((ArrayList) response.getResponse().get("collections")).contains(name); }
.setStateFormat(Integer.parseInt(getStateFormat())) .setCreateNodeSet("") .process(cloudClient).getStatus()); assertTrue(response.isSuccess()); String coreName = response.getCollectionCoresStatus().keySet().iterator().next(); coreClients.add(createNewSolrClient(coreName, j.getLocalPort())); SolrClient client = createNewSolrClient(j.getLocalPort());
.createCollection("control_collection", 1, 1) .setCreateNodeSet(controlJetty.getNodeName()) .process(controlClient).isSuccess());
@Override protected CollectionAdminResponse createResponse(SolrClient client) { return new CollectionAdminResponse(); }
request.setPath("/admin/collections"); CollectionAdminResponse res = new CollectionAdminResponse(); if (client == null) { final String baseUrl = getBaseUrl((HttpSolrClient) clients.get(clientIndex)); try (SolrClient adminClient = createNewSolrClient("", baseUrl)) { res.setResponse(adminClient.request(request)); res.setResponse(client.request(request));
@SuppressWarnings("unchecked") public Map<String, NamedList<Integer>> getCollectionNodesStatus() { Map<String, NamedList<Integer>> res = new HashMap<>(); NamedList<NamedList<Object>> cols = getCollectionStatus(); if( cols != null ) { for (Map.Entry<String,NamedList<Object>> e : cols) { if (e.getKey() != null) { res.put(e.getKey(), (NamedList<Integer>) (e.getValue().get("responseHeader"))); } } } return res; } }
return response != null && response.getStatus() == SUCCESS_STATUS;
@Override public void createAlias(String collection, String alias)throws DatastoreClientServiceException { try { CollectionAdminRequest.CreateAlias createAlias = new CollectionAdminRequest.CreateAlias(); createAlias.setAliasedCollections(collection); createAlias.setAliasName(alias); CollectionAdminResponse response = createAlias.process(getClient()); response.isSuccess(); } catch (Exception e) { throw new DatastoreClientServiceException(e); } }
@Override protected CollectionAdminResponse createResponse(SolrClient client) { return new CollectionAdminResponse(); } }
@SuppressWarnings("unchecked") public Map<String, NamedList<Integer>> getCollectionNodesStatus() { Map<String, NamedList<Integer>> res = new HashMap<>(); NamedList<NamedList<Object>> cols = getCollectionStatus(); if( cols != null ) { for (Map.Entry<String,NamedList<Object>> e : cols) { if (e.getKey() != null) { res.put(e.getKey(), (NamedList<Integer>) (e.getValue().get("responseHeader"))); } } } return res; } }
.createCollection("control_collection", "conf1", 1, 1) .setCreateNodeSet(controlJetty.getNodeName()) .process(client).getStatus());
@SuppressWarnings("unchecked") public NamedList<NamedList<Object>> getCollectionStatus() { return (NamedList<NamedList<Object>>) getResponse().get( "success" ); }
private static void createCollection(CloudSolrClient cloudSolrClient, String collection, Path configPath) { try { LOGGER.info("Creating SOLR collection {}", collection); int numShards = getEnvInt("SOLR_NUM_SHARDS", 1); int numReplicas = getEnvInt("SOLR_REPLICATION_FACTOR", 1); cloudSolrClient.getZkStateReader().getZkClient().upConfig(configPath, collection); Create createCollection = CollectionAdminRequest.createCollection(collection, collection, numShards, numReplicas); createCollection.setMaxShardsPerNode(getEnvInt("SOLR_MAX_SHARDS_PER_NODE", 1)); createCollection.setAutoAddReplicas(getEnvBoolean("SOLR_AUTO_ADD_REPLICAS", false)); CollectionAdminResponse response = createCollection.process(cloudSolrClient); if (!response.isSuccess()) { LOGGER.error("Could not create collection {}: {}", collection, response.getErrorMessages()); } } catch (SolrServerException | SolrException | IOException e) { LOGGER.error("Error creating collection {}", collection, e); } }
@Override protected SolrResponse createResponse(SolrClient client) { return new CollectionAdminResponse(); } }
@SuppressWarnings("unchecked") public Map<String, NamedList<Integer>> getCollectionCoresStatus() { Map<String, NamedList<Integer>> res = new HashMap<>(); NamedList<NamedList<Object>> cols = getCollectionStatus(); if( cols != null ) { for (Map.Entry<String, NamedList<Object>> e : cols) { NamedList<Object> item = e.getValue(); String core = (String) item.get("core"); if (core != null) { res.put(core, (NamedList<Integer>)item.get("responseHeader")); } } } return res; }
@SuppressWarnings("unchecked") public NamedList<String> getErrorMessages() { return (NamedList<String>) getResponse().get( "failure" ); }
private static void createCollectionIfNotExists(CloudSolrClient client, Configuration config, String collection) throws IOException, SolrServerException, KeeperException, InterruptedException { if (!checkIfCollectionExists(client, collection)) { final Integer numShards = config.get(NUM_SHARDS); final Integer maxShardsPerNode = config.get(MAX_SHARDS_PER_NODE); final Integer replicationFactor = config.get(REPLICATION_FACTOR); // Ideally this property used so a new configset is not uploaded for every single // index (collection) created in solr. // if a generic configSet is not set, make the configset name the same as the collection. // This was the default behavior before a default configSet could be specified final String genericConfigSet = config.has(SOLR_DEFAULT_CONFIG) ? config.get(SOLR_DEFAULT_CONFIG):collection; final CollectionAdminRequest.Create createRequest = CollectionAdminRequest.createCollection(collection, genericConfigSet, numShards, replicationFactor); createRequest.setMaxShardsPerNode(maxShardsPerNode); final 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); }
@Override protected CollectionAdminResponse createResponse(SolrClient client) { return new CollectionAdminResponse(); } }