org.apache.solr.client.solrj.request.CollectionAdminRequest Java Examples

The following examples show how to use org.apache.solr.client.solrj.request.CollectionAdminRequest. 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: CreateCollectionHandler.java    From ambari-logsearch with Apache License 2.0 7 votes vote down vote up
private boolean createCollection(CloudSolrClient solrClient, SolrPropsConfig solrPropsConfig, List<String> allCollectionList)
    throws SolrServerException, IOException {

  if (allCollectionList.contains(solrPropsConfig.getCollection())) {
    logger.info("Collection " + solrPropsConfig.getCollection() + " is already there. Won't create it");
    return true;
  }

  logger.info("Creating collection " + solrPropsConfig.getCollection() + ", numberOfShards=" + solrPropsConfig.getNumberOfShards() +
    ", replicationFactor=" + solrPropsConfig.getReplicationFactor());

  CollectionAdminRequest.Create collectionCreateRequest = CollectionAdminRequest.createCollection(
      solrPropsConfig.getCollection(), solrPropsConfig.getConfigName(), solrPropsConfig.getNumberOfShards(),
      solrPropsConfig.getReplicationFactor());
  collectionCreateRequest.setMaxShardsPerNode(calculateMaxShardsPerNode(solrPropsConfig));
  CollectionAdminResponse createResponse = collectionCreateRequest.process(solrClient);
  if (createResponse.getStatus() != 0) {
    logger.error("Error creating collection. collectionName=" + solrPropsConfig.getCollection() + ", response=" + createResponse);
    return false;
  } else {
    logger.info("Created collection " + solrPropsConfig.getCollection() + ", numberOfShards=" + solrPropsConfig.getNumberOfShards() +
      ", replicationFactor=" + solrPropsConfig.getReplicationFactor());
    return true;
  }
}
 
Example #2
Source File: CloudHttp2SolrClientTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Tests if the 'shards.preference' parameter works with single-sharded collections.
 */
@Test
public void singleShardedPreferenceRules() throws Exception {
  String collectionName = "singleShardPreferenceTestColl";

  int liveNodes = cluster.getJettySolrRunners().size();

  // For testing replica.type, we want to have all replica types available for the collection
  CollectionAdminRequest.createCollection(collectionName, "conf", 1, liveNodes/3, liveNodes/3, liveNodes/3)
      .setMaxShardsPerNode(liveNodes)
      .processAndWait(cluster.getSolrClient(), TIMEOUT);
  cluster.waitForActiveCollection(collectionName, 1, liveNodes);

  // Add some new documents
  new UpdateRequest()
      .add(id, "0", "a_t", "hello1")
      .add(id, "2", "a_t", "hello2")
      .add(id, "3", "a_t", "hello2")
      .commit(getRandomClient(), collectionName);

  // Run the actual test for 'queryReplicaType'
  queryReplicaType(getRandomClient(), Replica.Type.PULL, collectionName);
  queryReplicaType(getRandomClient(), Replica.Type.TLOG, collectionName);
  queryReplicaType(getRandomClient(), Replica.Type.NRT, collectionName);
}
 
Example #3
Source File: CollectionAdminRequestRequiredParamsTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testAddReplica() {
  // with shard parameter and "client side" implicit type param
  CollectionAdminRequest.AddReplica request = CollectionAdminRequest.addReplicaToShard("collection", "shard");
  assertContainsParams(request.getParams(), ACTION, COLLECTION, SHARD, ZkStateReader.REPLICA_TYPE);
  
  // with only shard parameter and "server side" implicit type, so no param
  request = CollectionAdminRequest.addReplicaToShard("collection", "shard", null);
  assertContainsParams(request.getParams(), ACTION, COLLECTION, SHARD);
  
  // with route parameter
  request = CollectionAdminRequest.addReplicaByRouteKey("collection","route");
  assertContainsParams(request.getParams(), ACTION, COLLECTION, ShardParams._ROUTE_);
  
  // with explicit type parameter
  request = CollectionAdminRequest.addReplicaToShard("collection", "shard", Replica.Type.NRT);
  assertContainsParams(request.getParams(), ACTION, COLLECTION, SHARD, ZkStateReader.REPLICA_TYPE);
}
 
Example #4
Source File: TestRebalanceLeaders.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupCluster() throws Exception {

  numNodes = random().nextInt(4) + 4;
  numShards = random().nextInt(3) + 3;
  numReplicas = random().nextInt(2) + 2;
  useAdminToSetProps = random().nextBoolean();

  configureCluster(numNodes)
      .addConfig(COLLECTION_NAME, configset("cloud-minimal"))
      .configure();

  CollectionAdminResponse resp = CollectionAdminRequest.createCollection(COLLECTION_NAME, COLLECTION_NAME,
      numShards, numReplicas, 0, 0)
      .setMaxShardsPerNode((numShards * numReplicas) / numNodes + 1)
      .process(cluster.getSolrClient());
  assertEquals("Admin request failed; ", 0, resp.getStatus());
  cluster.waitForActiveCollection(COLLECTION_NAME, numShards, numShards * numReplicas);

}
 
Example #5
Source File: CustomCollectionTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testRouteFieldForImplicitRouter() throws Exception {

  int numShards = 4;
  int replicationFactor = TestUtil.nextInt(random(), 0, 3) + 2;
  int maxShardsPerNode = ((numShards * replicationFactor) / NODE_COUNT) + 1;
  String shard_fld = "shard_s";

  final String collection = "withShardField";

  CollectionAdminRequest.createCollectionWithImplicitRouter(collection, "conf", "a,b,c,d", replicationFactor)
      .setMaxShardsPerNode(maxShardsPerNode)
      .setRouterField(shard_fld)
      .process(cluster.getSolrClient());

  new UpdateRequest()
      .add("id", "6", shard_fld, "a")
      .add("id", "7", shard_fld, "a")
      .add("id", "8", shard_fld, "b")
      .commit(cluster.getSolrClient(), collection);

  assertEquals(3, cluster.getSolrClient().query(collection, new SolrQuery("*:*")).getResults().getNumFound());
  assertEquals(1, cluster.getSolrClient().query(collection, new SolrQuery("*:*").setParam(_ROUTE_, "b")).getResults().getNumFound());
  assertEquals(2, cluster.getSolrClient().query(collection, new SolrQuery("*:*").setParam(_ROUTE_, "a")).getResults().getNumFound());

}
 
Example #6
Source File: TestUtilizeNode.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupCluster() throws Exception {
  configureCluster(3)
      .addConfig("conf1", TEST_PATH().resolve("configsets").resolve("cloud-dynamic").resolve("conf"))
      .configure();
  NamedList<Object> overSeerStatus = cluster.getSolrClient().request(CollectionAdminRequest.getOverseerStatus());
  JettySolrRunner overseerJetty = null;
  String overseerLeader = (String) overSeerStatus.get("leader");
  for (int i = 0; i < cluster.getJettySolrRunners().size(); i++) {
    JettySolrRunner jetty = cluster.getJettySolrRunner(i);
    if (jetty.getNodeName().equals(overseerLeader)) {
      overseerJetty = jetty;
      break;
    }
  }
  if (overseerJetty == null) {
    fail("no overseer leader!");
  }
}
 
Example #7
Source File: CollectionsAPISolrJTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testClusterProp() throws InterruptedException, IOException, SolrServerException {

  // sanity check our expected default
  final ClusterProperties props = new ClusterProperties(zkClient());
  assertEquals("Expecting prop to default to unset, test needs upated",
               props.getClusterProperty(ZkStateReader.AUTO_ADD_REPLICAS, null), null);
  
  CollectionAdminResponse response = CollectionAdminRequest.setClusterProperty(ZkStateReader.AUTO_ADD_REPLICAS, "true")
    .process(cluster.getSolrClient());
  assertEquals(0, response.getStatus());
  assertEquals("Cluster property was not set", props.getClusterProperty(ZkStateReader.AUTO_ADD_REPLICAS, null), "true");

  // Unset ClusterProp that we set.
  CollectionAdminRequest.setClusterProperty(ZkStateReader.AUTO_ADD_REPLICAS, null).process(cluster.getSolrClient());
  assertEquals("Cluster property was not unset", props.getClusterProperty(ZkStateReader.AUTO_ADD_REPLICAS, null), null);

  response = CollectionAdminRequest.setClusterProperty(ZkStateReader.AUTO_ADD_REPLICAS, "false")
      .process(cluster.getSolrClient());
  assertEquals(0, response.getStatus());
  assertEquals("Cluster property was not set", props.getClusterProperty(ZkStateReader.AUTO_ADD_REPLICAS, null), "false");
}
 
Example #8
Source File: DeleteReplicaTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void deleteReplicaByCount() throws Exception {

  final String collectionName = "deleteByCount";

  CollectionAdminRequest.createCollection(collectionName, "conf", 1, 3).process(cluster.getSolrClient());
  waitForState("Expected a single shard with three replicas", collectionName, clusterShape(1, 3));

  CollectionAdminRequest.deleteReplicasFromShard(collectionName, "shard1", 2).process(cluster.getSolrClient());
  waitForState("Expected a single shard with a single replica", collectionName, clusterShape(1, 1));

  SolrException e = expectThrows(SolrException.class,
      "Can't delete the last replica by count",
      () -> CollectionAdminRequest.deleteReplicasFromShard(collectionName, "shard1", 1).process(cluster.getSolrClient())
  );
  assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, e.code());
  assertTrue(e.getMessage().contains("There is only one replica available"));
  DocCollection docCollection = getCollectionState(collectionName);
  // We know that since leaders are preserved, PULL replicas should not be left alone in the shard
  assertEquals(0, docCollection.getSlice("shard1").getReplicas(EnumSet.of(Replica.Type.PULL)).size());
}
 
Example #9
Source File: DirectJsonQueryRequestFacetingIntegrationTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupCluster() throws Exception {
  configureCluster(1)
      .addConfig(CONFIG_NAME, new File(ExternalPaths.TECHPRODUCTS_CONFIGSET).toPath())
      .configure();

  final List<String> solrUrls = new ArrayList<>();
  solrUrls.add(cluster.getJettySolrRunner(0).getBaseUrl().toString());

  CollectionAdminRequest.createCollection(COLLECTION_NAME, CONFIG_NAME, 1, 1).process(cluster.getSolrClient());

  ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update");
  up.setParam("collection", COLLECTION_NAME);
  up.addFile(getFile("solrj/techproducts.xml"), "application/xml");
  up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
  UpdateResponse updateResponse = up.process(cluster.getSolrClient());
  assertEquals(0, updateResponse.getStatus());
}
 
Example #10
Source File: CollectionsAPIDistributedZkTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void waitForStable(int cnt, CollectionAdminRequest.Create[] createRequests) throws InterruptedException {
  for (int i = 0; i < cnt; i++) {
    String collectionName = "awhollynewcollection_" + i;
    final int j = i;
    waitForState("Expected to see collection " + collectionName, collectionName,
        (n, c) -> {
          CollectionAdminRequest.Create req = createRequests[j];
          return DocCollection.isFullyActive(n, c, req.getNumShards(), req.getReplicationFactor());
        });
    
    ZkStateReader zkStateReader = cluster.getSolrClient().getZkStateReader();
    // make sure we have leaders for each shard
    for (int z = 1; z < createRequests[j].getNumShards(); z++) {
      zkStateReader.getLeaderRetry(collectionName, "shard" + z, 10000);
    }      // make sure we again have leaders for each shard
  }
}
 
Example #11
Source File: MultiThreadedOCPTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void testDeduplicationOfSubmittedTasks() throws IOException, SolrServerException {
  try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
    CollectionAdminRequest.createCollection("ocptest_shardsplit2","conf1",3,1).processAsync("3000",client);

    SplitShard splitShardRequest = CollectionAdminRequest.splitShard("ocptest_shardsplit2").setShardName(SHARD1);
    splitShardRequest.processAsync("3001",client);
    
    splitShardRequest = CollectionAdminRequest.splitShard("ocptest_shardsplit2").setShardName(SHARD2);
    splitShardRequest.processAsync("3002",client);

    // Now submit another task with the same id. At this time, hopefully the previous 3002 should still be in the queue.
    expectThrows(SolrServerException.class, () -> {
        CollectionAdminRequest.splitShard("ocptest_shardsplit2").setShardName(SHARD1).processAsync("3002",client);
        // more helpful assertion failure
        fail("Duplicate request was supposed to exist but wasn't found. De-duplication of submitted task failed.");
      });
    
    for (int i = 3001; i <= 3002; i++) {
      final RequestStatusState state = getRequestStateAfterCompletion(i + "", REQUEST_STATUS_TIMEOUT, client);
      assertSame("Task " + i + " did not complete, final state: " + state, RequestStatusState.COMPLETED, state);
    }
  }
}
 
Example #12
Source File: ShardSplitTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void doSplitShardWithRule(SolrIndexSplitter.SplitMethod splitMethod) throws Exception {
  waitForThingsToLevelOut(15, TimeUnit.SECONDS);

  log.info("Starting testSplitShardWithRule");
  String collectionName = "shardSplitWithRule_" + splitMethod.toLower();
  CollectionAdminRequest.Create createRequest = CollectionAdminRequest.createCollection(collectionName, "conf1", 1, 2)
      .setRule("shard:*,replica:<2,node:*");

  CollectionAdminResponse response = createRequest.process(cloudClient);
  assertEquals(0, response.getStatus());
  
  try {
    cloudClient.waitForState(collectionName, 30, TimeUnit.SECONDS, SolrCloudTestCase.activeClusterShape(1, 2));
  } catch (TimeoutException e) {
    new RuntimeException("Timeout waiting for 1shards and 2 replicas.", e);
  }

  CollectionAdminRequest.SplitShard splitShardRequest = CollectionAdminRequest.splitShard(collectionName)
      .setShardName("shard1").setSplitMethod(splitMethod.toLower());
  response = splitShardRequest.process(cloudClient);
  assertEquals(String.valueOf(response.getErrorMessages()), 0, response.getStatus());
}
 
Example #13
Source File: AliasIntegrationTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testModifyPropertiesCAR() throws Exception {
  // note we don't use TZ in this test, thus it's UTC
  final String aliasName = getSaferTestName();
  ZkStateReader zkStateReader = createColectionsAndAlias(aliasName);
  CollectionAdminRequest.SetAliasProperty setAliasProperty = CollectionAdminRequest.setAliasProperty(aliasName);
  setAliasProperty.addProperty("foo","baz");
  setAliasProperty.addProperty("bar","bam");
  setAliasProperty.process(cluster.getSolrClient());
  checkFooAndBarMeta(aliasName, zkStateReader);

  // now verify we can delete
  setAliasProperty = CollectionAdminRequest.setAliasProperty(aliasName);
  setAliasProperty.addProperty("foo","");
  setAliasProperty.process(cluster.getSolrClient());
  setAliasProperty = CollectionAdminRequest.setAliasProperty(aliasName);
  setAliasProperty.addProperty("bar",null);
  setAliasProperty.process(cluster.getSolrClient());
  setAliasProperty = CollectionAdminRequest.setAliasProperty(aliasName);

  // whitespace value
  setAliasProperty.addProperty("foo"," ");
  setAliasProperty.process(cluster.getSolrClient());


}
 
Example #14
Source File: TestDynamicURP.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupCluster() throws Exception {
  System.setProperty("enable.runtime.lib", "true");
  configureCluster(3)
      .addConfig("conf", configset("cloud-minimal"))
      .configure();
  SolrZkClient zkClient = cluster.getSolrClient().getZkStateReader().getZkClient();
  String path = ZkStateReader.CONFIGS_ZKNODE + "/conf/solrconfig.xml";
  byte[] data = zkClient.getData(path, null, null, true);

  String solrconfigStr = new String(data, StandardCharsets.UTF_8);
  zkClient.setData(path, solrconfigStr.replace("</config>",
      "<updateRequestProcessorChain name=\"test_urp\" processor=\"testURP\" default=\"true\">\n" +
      "    <processor class=\"solr.RunUpdateProcessorFactory\"/>\n" +
      "  </updateRequestProcessorChain>\n" +
      "\n" +
      "  <updateProcessor class=\"runtimecode.TestURP\" name=\"testURP\" runtimeLib=\"true\"></updateProcessor>\n" +
      "</config>").getBytes(StandardCharsets.UTF_8), true );


  CollectionAdminRequest.createCollection(COLLECTION, "conf", 3, 1).process(cluster.getSolrClient());
  waitForState("", COLLECTION, clusterShape(3, 3));
}
 
Example #15
Source File: UsingSolrJRefGuideExamplesTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void otherSolrApisExample() throws Exception {
  expectLine("Found "+NUM_LIVE_NODES+" live nodes");
  // tag::solrj-other-apis[]
  final SolrClient client = getSolrClient();

  @SuppressWarnings({"rawtypes"})
  final SolrRequest request = new CollectionAdminRequest.ClusterStatus();

  final NamedList<Object> response = client.request(request);
  @SuppressWarnings({"unchecked"})
  final NamedList<Object> cluster = (NamedList<Object>) response.get("cluster");
  @SuppressWarnings({"unchecked"})
  final List<String> liveNodes = (List<String>) cluster.get("live_nodes");

  print("Found " + liveNodes.size() + " live nodes");
  // end::solrj-other-apis[]
}
 
Example #16
Source File: TestPullReplica.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void tearDown() throws Exception {
  for (JettySolrRunner jetty:cluster.getJettySolrRunners()) {
    if (!jetty.isRunning()) {
      log.warn("Jetty {} not running, probably some bad test. Starting it", jetty.getLocalPort());
      jetty.start();
    }
  }
  if (cluster.getSolrClient().getZkStateReader().getClusterState().getCollectionOrNull(collectionName) != null) {
    log.info("tearDown deleting collection");
    CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
    log.info("Collection deleted");
    waitForDeletion(collectionName);
  }
  super.tearDown();
}
 
Example #17
Source File: CollectionManagementService.java    From vind with Apache License 2.0 6 votes vote down vote up
public CollectionManagementService(List<String> zkHost, String ... repositories) throws IOException {
    this(repositories);
    this.zkHosts = zkHost;

    try (CloudSolrClient client = new CloudSolrClient.Builder(zkHost, Optional.empty()).build()) {
        NamedList result = client.request(new CollectionAdminRequest.ClusterStatus());

        if (((NamedList) ((NamedList) result.get("cluster")).get("collections")).get(".system") == null) {
            logger.warn("Blob store '.system' for runtime libs is not yet created. Will create one");

            try {
                Create create = CollectionAdminRequest
                        .createCollection(".system", BLOB_STORE_SHARDS, BLOB_STORE_REPLICAS);
                create.process(client);
                logger.info("Blob store has been created successfully");
            } catch (SolrServerException e1) {
                throw new IOException("Blob store is not available and cannot be created");
            }
        }

    } catch (SolrServerException | IOException e) {
        logger.error("Error in collection management service: {}", e.getMessage(), e);
        throw new IOException("Error in collection management service: " + e.getMessage(), e);
    }
}
 
Example #18
Source File: CollectionManagementService.java    From vind with Apache License 2.0 6 votes vote down vote up
/**
 * 1. Check if config set is already deployed on the solr server, if not: download from repo and upload to zK
 * 2. Create collection
 * 3. Check if dependencies (runtime-libs) are installed, if not download and install (and name it with group:artifact:version)
 * 4. Add/Update collection runtime-libs
 *
 * @param collectionName {@link String} name of the collection to create.
 * @param configName should be either the name of an already defined configuration in the solr cloud or the full
 *                   name of an artifact accessible in one of the default repositories.
 * @param numOfShards integer number of shards
 * @param numOfReplicas integer number of replicas
 * @param autoAddReplicas boolean sets the Solr auto replication functionality on.
 * @throws {@link IOException} thrown if is not possible to create the collection.
 */
public void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas, Boolean autoAddReplicas) throws IOException {
    checkAndInstallConfiguration(configName);

    try (CloudSolrClient client = createCloudSolrClient()) {
        Create create = CollectionAdminRequest.
                createCollection(collectionName, configName, numOfShards, numOfReplicas);
        if(Objects.nonNull(autoAddReplicas)) {
            create.setAutoAddReplicas(autoAddReplicas);
        }
        create.process(client);
        logger.info("Collection '{}' created", collectionName);
    } catch (IOException | SolrServerException e) {
        throw new IOException("Cannot create collection", e);
    }

    Map<String,Long> runtimeDependencies = checkAndInstallRuntimeDependencies(collectionName);

    addOrUpdateRuntimeDependencies(runtimeDependencies, collectionName);
}
 
Example #19
Source File: TestSQLHandler.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupCluster() throws Exception {
  configureCluster(4)
      .addConfig("conf", configset("sql"))
      .configure();

  String collection;
  useAlias = random().nextBoolean();
  if (useAlias) {
    collection = COLLECTIONORALIAS + "_collection";
  } else {
    collection = COLLECTIONORALIAS;
  }

  CollectionAdminRequest.createCollection(collection, "conf", 2, 1).process(cluster.getSolrClient());
  cluster.waitForActiveCollection(collection, 2, 2);
  if (useAlias) {
    CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection).process(cluster.getSolrClient());
  }
}
 
Example #20
Source File: DeleteLastCustomShardedReplicaTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {

  final String collectionName = "customcollreplicadeletion";

  CollectionAdminRequest.createCollectionWithImplicitRouter(collectionName, "conf", "a,b", 1)
      .setMaxShardsPerNode(5)
      .process(cluster.getSolrClient());

  DocCollection collectionState = getCollectionState(collectionName);
  Replica replica = getRandomReplica(collectionState.getSlice("a"));

  CollectionAdminRequest.deleteReplica(collectionName, "a", replica.getName())
      .process(cluster.getSolrClient());

  waitForState("Expected shard 'a' to have no replicas", collectionName, (n, c) -> {
    return c.getSlice("a") == null || c.getSlice("a").getReplicas().size() == 0;
  });

}
 
Example #21
Source File: CollectionsAPISolrJTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testCloudInfoInCoreStatus() throws IOException, SolrServerException {
  String collectionName = "corestatus_test";
  CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2)
      .process(cluster.getSolrClient());

  assertEquals(0, response.getStatus());
  assertTrue(response.isSuccess());
  
  cluster.waitForActiveCollection(collectionName, 2, 4);
  
  String nodeName = (String) response._get("success[0]/key", null);
  String corename = (String) response._get(asList("success", nodeName, "core"), null);

  try (HttpSolrClient coreclient = getHttpSolrClient(cluster.getSolrClient().getZkStateReader().getBaseUrlForNodeName(nodeName))) {
    CoreAdminResponse status = CoreAdminRequest.getStatus(corename, coreclient);
    assertEquals(collectionName, status._get(asList("status", corename, "cloud", "collection"), null));
    assertNotNull(status._get(asList("status", corename, "cloud", "shard"), null));
    assertNotNull(status._get(asList("status", corename, "cloud", "replica"), null));
  }
}
 
Example #22
Source File: CreateCollectionCleanupTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testAsyncCreateCollectionCleanup() throws Exception {
  final CloudSolrClient cloudClient = cluster.getSolrClient();
  String collectionName = "foo2";
  assertThat(CollectionAdminRequest.listCollections(cloudClient), not(hasItem(collectionName)));
  
  // Create a collection that would fail
  CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName,"conf1",1,1);

  Properties properties = new Properties();
  Path tmpDir = createTempDir();
  tmpDir = tmpDir.resolve("foo");
  Files.createFile(tmpDir);
  properties.put(CoreAdminParams.DATA_DIR, tmpDir.toString());
  create.setProperties(properties);
  create.setAsyncId("testAsyncCreateCollectionCleanup");
  create.process(cloudClient);
  RequestStatusState state = AbstractFullDistribZkTestBase.getRequestStateAfterCompletion("testAsyncCreateCollectionCleanup", 30, cloudClient);
  assertThat(state.getKey(), is("failed"));

  // Confirm using LIST that the collection does not exist
  assertThat("Failed collection is still in the clusterstate: " + cluster.getSolrClient().getClusterStateProvider().getClusterState().getCollectionOrNull(collectionName), 
      CollectionAdminRequest.listCollections(cloudClient), not(hasItem(collectionName)));

}
 
Example #23
Source File: TestHdfsCloudBackupRestore.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected void testConfigBackupOnly(String configName, String collectionName) throws Exception {
  String backupName = "configonlybackup";
  CloudSolrClient solrClient = cluster.getSolrClient();

  CollectionAdminRequest.Backup backup = CollectionAdminRequest.backupCollection(collectionName, backupName)
      .setRepositoryName(getBackupRepoName())
      .setIndexBackupStrategy(CollectionAdminParams.NO_INDEX_BACKUP_STRATEGY);
  backup.process(solrClient);

  Map<String,String> params = new HashMap<>();
  params.put("location", "/backup");
  params.put("solr.hdfs.home", hdfsUri + "/solr");

  HdfsBackupRepository repo = new HdfsBackupRepository();
  repo.init(new NamedList<>(params));
  BackupManager mgr = new BackupManager(repo, solrClient.getZkStateReader());

  URI baseLoc = repo.createURI("/backup");

  Properties props = mgr.readBackupProperties(baseLoc, backupName);
  assertNotNull(props);
  assertEquals(collectionName, props.getProperty(COLLECTION_NAME_PROP));
  assertEquals(backupName, props.getProperty(BACKUP_NAME_PROP));
  assertEquals(configName, props.getProperty(COLL_CONF));

  DocCollection collectionState = mgr.readCollectionState(baseLoc, backupName, collectionName);
  assertNotNull(collectionState);
  assertEquals(collectionName, collectionState.getName());

  URI configDirLoc = repo.resolve(baseLoc, backupName, ZK_STATE_DIR, CONFIG_STATE_DIR, configName);
  assertTrue(repo.exists(configDirLoc));

  Collection<String> expected = Arrays.asList(BACKUP_PROPS_FILE, ZK_STATE_DIR);
  URI backupLoc = repo.resolve(baseLoc, backupName);
  String[] dirs = repo.listAll(backupLoc);
  for (String d : dirs) {
    assertTrue(expected.contains(d));
  }
}
 
Example #24
Source File: CollectionsAPIDistributedZkTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testTooManyReplicas() {
  @SuppressWarnings({"rawtypes"})
  CollectionAdminRequest req = CollectionAdminRequest.createCollection("collection", "conf", 2, 10);

  expectThrows(Exception.class, () -> {
    cluster.getSolrClient().request(req);
  });
}
 
Example #25
Source File: TestWithCollection.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddReplicaSimple() throws Exception {
  String prefix = "testAddReplica";
  String xyz = prefix + "_xyz";
  String abc = prefix + "_abc";

  CloudSolrClient solrClient = cluster.getSolrClient();
  String chosenNode = cluster.getRandomJetty(random()).getNodeName();
  log.info("Chosen node {} for collection {}", chosenNode, abc);
  CollectionAdminRequest.createCollection(abc, 1, 1)
      .setCreateNodeSet(chosenNode) // randomize to avoid choosing the first node always
      .process(solrClient);
  CollectionAdminRequest.createCollection(xyz, 1, 1)
      .setWithCollection(abc)
      .process(solrClient);

  String otherNode = null;
  for (JettySolrRunner jettySolrRunner : cluster.getJettySolrRunners()) {
    if (!chosenNode.equals(jettySolrRunner.getNodeName())) {
      otherNode = jettySolrRunner.getNodeName();
    }
  }
  CollectionAdminRequest.addReplicaToShard(xyz, "shard1")
      .setNode(otherNode)
      .process(solrClient);
  DocCollection collection = solrClient.getZkStateReader().getClusterState().getCollection(xyz);
  DocCollection withCollection = solrClient.getZkStateReader().getClusterState().getCollection(abc);

  assertTrue(collection.getReplicas().stream().noneMatch(replica -> withCollection.getReplicas(replica.getNodeName()).isEmpty()));
}
 
Example #26
Source File: CloudHttp2SolrClientTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testParallelUpdateQTime() throws Exception {
  CollectionAdminRequest.createCollection(COLLECTION, "conf", 2, 1).process(cluster.getSolrClient());
  cluster.waitForActiveCollection(COLLECTION, 2, 2);
  UpdateRequest req = new UpdateRequest();
  for (int i=0; i<10; i++)  {
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", String.valueOf(TestUtil.nextInt(random(), 1000, 1100)));
    req.add(doc);
  }
  UpdateResponse response = req.process(getRandomClient(), COLLECTION);
  // See SOLR-6547, we just need to ensure that no exception is thrown here
  assertTrue(response.getQTime() >= 0);
}
 
Example #27
Source File: CloudSolrClientTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testInitializationWithSolrUrls() throws Exception {
  CollectionAdminRequest.createCollection(COLLECTION, "conf", 2, 1).process(cluster.getSolrClient());
  cluster.waitForActiveCollection(COLLECTION, 2, 2);
  CloudSolrClient client = httpBasedCloudSolrClient;
  SolrInputDocument doc = new SolrInputDocument("id", "1", "title_s", "my doc");
  client.add(COLLECTION, doc);
  client.commit(COLLECTION);
  assertEquals(1, client.query(COLLECTION, params("q", "*:*")).getResults().getNumFound());
}
 
Example #28
Source File: SplitShardTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void multipleOptionsSplitTest() throws IOException, SolrServerException {
  CollectionAdminRequest.SplitShard splitShard = CollectionAdminRequest.splitShard(COLLECTION_NAME)
      .setNumSubShards(5)
      .setRanges("0-c,d-7fffffff")
      .setShardName("shard1");
  boolean expectedException = false;
  try {
    splitShard.process(cluster.getSolrClient());
    fail("An exception should have been thrown");
  } catch (SolrException ex) {
    expectedException = true;
  }
  assertTrue("Expected SolrException but it didn't happen", expectedException);
}
 
Example #29
Source File: DistributedQueryComponentOptimizationTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setupCluster() throws Exception {
  configureCluster(3)
      .withSolrXml(TEST_PATH().resolve("solr-trackingshardhandler.xml"))
      .addConfig("conf", configset("cloud-dynamic"))
      .configure();

  CollectionAdminRequest.createCollection(COLLECTION, "conf", 3, 1)
      .setMaxShardsPerNode(1)
      .processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT);
  cluster.getSolrClient().waitForState(COLLECTION, DEFAULT_TIMEOUT, TimeUnit.SECONDS,
      (n, c) -> DocCollection.isFullyActive(n, c, sliceCount, 1));

  new UpdateRequest()
      .add(sdoc(id, "1", "text", "a", "test_sS", "21", "payload", ByteBuffer.wrap(new byte[]{0x12, 0x62, 0x15})))
      .add(sdoc(id, "2", "text", "b", "test_sS", "22", "payload", ByteBuffer.wrap(new byte[]{0x25, 0x21, 0x16})))                  //  5
      .add(sdoc(id, "3", "text", "a", "test_sS", "23", "payload", ByteBuffer.wrap(new byte[]{0x35, 0x32, 0x58})))                  //  8
      .add(sdoc(id, "4", "text", "b", "test_sS", "24", "payload", ByteBuffer.wrap(new byte[]{0x25, 0x21, 0x15})))                    //  4
      .add(sdoc(id, "5", "text", "a", "test_sS", "25", "payload", ByteBuffer.wrap(new byte[]{0x35, 0x35, 0x10, 0x00})))              //  9
      .add(sdoc(id, "6", "text", "c", "test_sS", "26", "payload", ByteBuffer.wrap(new byte[]{0x1a, 0x2b, 0x3c, 0x00, 0x00, 0x03})))  //  3
      .add(sdoc(id, "7", "text", "c", "test_sS", "27", "payload", ByteBuffer.wrap(new byte[]{0x00, 0x3c, 0x73})))                    //  1
      .add(sdoc(id, "8", "text", "c", "test_sS", "28", "payload", ByteBuffer.wrap(new byte[]{0x59, 0x2d, 0x4d})))                    // 11
      .add(sdoc(id, "9", "text", "a", "test_sS", "29", "payload", ByteBuffer.wrap(new byte[]{0x39, 0x79, 0x7a})))                    // 10
      .add(sdoc(id, "10", "text", "b", "test_sS", "30", "payload", ByteBuffer.wrap(new byte[]{0x31, 0x39, 0x7c})))                   //  6
      .add(sdoc(id, "11", "text", "d", "test_sS", "31", "payload", ByteBuffer.wrap(new byte[]{(byte) 0xff, (byte) 0xaf, (byte) 0x9c}))) // 13
      .add(sdoc(id, "12", "text", "d", "test_sS", "32", "payload", ByteBuffer.wrap(new byte[]{0x34, (byte) 0xdd, 0x4d})))             //  7
      .add(sdoc(id, "13", "text", "d", "test_sS", "33", "payload", ByteBuffer.wrap(new byte[]{(byte) 0x80, 0x11, 0x33})))             // 12
      // SOLR-6545, wild card field list
      .add(sdoc(id, "19", "text", "d", "cat_a_sS", "1", "dynamic_s", "2", "payload", ByteBuffer.wrap(new byte[]{(byte) 0x80, 0x11, 0x34})))
      .commit(cluster.getSolrClient(), COLLECTION);

}
 
Example #30
Source File: TestPullReplicaErrorHandling.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void tearDown() throws Exception {
  if (cluster.getSolrClient().getZkStateReader().getClusterState().getCollectionOrNull(collectionName) != null) {
    log.info("tearDown deleting collection");
    CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
    log.info("Collection deleted");
    waitForDeletion(collectionName);
  }
  collectionName = null;
  super.tearDown();
}