org.apache.solr.client.solrj.response.CollectionAdminResponse Java Examples

The following examples show how to use org.apache.solr.client.solrj.response.CollectionAdminResponse. 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: TestSolrCloudWithSecureImpersonation.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void create1ShardCollection(String name, String config, MiniSolrCloudCluster solrCluster) throws Exception {
  CollectionAdminResponse response;
  CollectionAdminRequest.Create create = new CollectionAdminRequest.Create(name,config,1,1,0,0) {
    @Override
    public SolrParams getParams() {
      ModifiableSolrParams msp = new ModifiableSolrParams(super.getParams());
      msp.set(USER_PARAM, "user");
      return msp;
    }
  };
  create.setMaxShardsPerNode(1);
  response = create.process(solrCluster.getSolrClient());

  miniCluster.waitForActiveCollection(name, 1, 1);
  
  if (response.getStatus() != 0 || response.getErrorMessages() != null) {
    fail("Could not create collection. Response" + response.toString());
  }
}
 
Example #2
Source File: TestSolrCloudSnapshots.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked"})
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 );
  @SuppressWarnings({"rawtypes"})
  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;
}
 
Example #3
Source File: ConcurrentCreateRoutedAliasTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void createAlias() {
  try {
    CollectionAdminRequest.CreateTimeRoutedAlias rq = CollectionAdminRequest
        .createTimeRoutedAlias(
            aliasName,
            start,
            "+12HOUR",
            "routedFoo_dt",
            CollectionAdminRequest.createCollection("_ignored_", "_default", 1, 1)
        );

    final CollectionAdminResponse response = rq.process(solrClient);
    if (response.getStatus() != 0) {
      addFailure(new RuntimeException("failed to create collection " + aliasName));
    }
  } catch (Exception e) {
    addFailure(e);
  }

}
 
Example #4
Source File: TestConfigSetsAPI.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected CollectionAdminResponse createCollection(String collectionName, String confSetName, int numShards,
    int replicationFactor, SolrClient client)  throws SolrServerException, IOException {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set("action", CollectionAction.CREATE.toString());
  params.set("collection.configName", confSetName);
  params.set("name", collectionName);
  params.set("numShards", numShards);
  params.set("replicationFactor", replicationFactor);
  @SuppressWarnings({"rawtypes"})
  SolrRequest request = new QueryRequest(params);
  request.setPath("/admin/collections");

  CollectionAdminResponse res = new CollectionAdminResponse();
  res.setResponse(client.request(request));
  return res;
}
 
Example #5
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 #6
Source File: CollectionsAPISolrJTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddAndDeleteReplicaProp() throws InterruptedException, IOException, SolrServerException {

  final String collection = "replicaProperties";
  CollectionAdminRequest.createCollection(collection, "conf", 2, 2)
      .process(cluster.getSolrClient());
  
  cluster.waitForActiveCollection(collection, 2, 4);

  final Replica replica = getCollectionState(collection).getLeader("shard1");
  CollectionAdminResponse response
      = CollectionAdminRequest.addReplicaProperty(collection, "shard1", replica.getName(), "preferredleader", "true")
      .process(cluster.getSolrClient());
  assertEquals(0, response.getStatus());

  waitForState("Expecting property 'preferredleader' to appear on replica " + replica.getName(), collection,
      (n, c) -> "true".equals(c.getReplica(replica.getName()).getProperty("preferredleader")));

  response = CollectionAdminRequest.deleteReplicaProperty(collection, "shard1", replica.getName(), "property.preferredleader")
      .process(cluster.getSolrClient());
  assertEquals(0, response.getStatus());

  waitForState("Expecting property 'preferredleader' to be removed from replica " + replica.getName(), collection,
      (n, c) -> c.getReplica(replica.getName()).getProperty("preferredleader") == null);

}
 
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: SolrSnapshotsTool.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public void listSnapshots(String collectionName) {
  CollectionAdminRequest.ListSnapshots listSnaps = new CollectionAdminRequest.ListSnapshots(collectionName);
  CollectionAdminResponse resp;
  try {
    resp = listSnaps.process(solrClient);
    Preconditions.checkState(resp.getStatus() == 0, "The LISTSNAPSHOTS request failed. The status code is " + resp.getStatus());

    NamedList apiResult = (NamedList) resp.getResponse().get(SolrSnapshotManager.SNAPSHOTS_INFO);
    for (int i = 0; i < apiResult.size(); i++) {
      CLIO.out(apiResult.getName(i));
    }

  } catch (Exception e) {
    log.error("Failed to list snapshots for collection {}", collectionName, e);
    CLIO.out("Failed to list snapshots for collection " + collectionName
        +" due to following error : "+e.getLocalizedMessage());
  }
}
 
Example #9
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 #10
Source File: SolrSnapshotsTool.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private Collection<CollectionSnapshotMetaData> listCollectionSnapshots(String collectionName)
    throws SolrServerException, IOException {
  CollectionAdminRequest.ListSnapshots listSnapshots = new CollectionAdminRequest.ListSnapshots(collectionName);
  CollectionAdminResponse resp = listSnapshots.process(solrClient);

  Preconditions.checkState(resp.getStatus() == 0);

  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;
}
 
Example #11
Source File: AutoScalingHandlerTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testDiagnosticsWithPayload() throws Exception {
  CloudSolrClient solrClient = cluster.getSolrClient();
  String COLLNAME = "testDiagnosticsWithPayload.COLL";
  CollectionAdminResponse adminResponse = CollectionAdminRequest.createCollection(COLLNAME, CONFIGSET_NAME, 1, 2)
      .setMaxShardsPerNode(4)
      .process(solrClient);
  cluster.waitForActiveCollection(COLLNAME, 1, 2);
  DocCollection collection = solrClient.getClusterStateProvider().getCollection(COLLNAME);
  Replica aReplica = collection.getReplicas().get(0);

  String configPayload = "{\n" +
      "  'cluster-policy': [{'replica': 0, 'node': '_NODE'}]\n" +
      "}";
  configPayload = configPayload.replaceAll("_NODE", aReplica.getNodeName());
  @SuppressWarnings({"rawtypes"})
  SolrRequest req = AutoScalingRequest.create(SolrRequest.METHOD.POST, "/diagnostics", configPayload);
  NamedList<Object> response = solrClient.request(req);
  assertEquals(response._getStr("diagnostics/violations[0]/node",null),response._getStr("diagnostics/violations[0]/node",null));
  CollectionAdminRequest.deleteCollection(COLLNAME)
      .process(cluster.getSolrClient());
}
 
Example #12
Source File: Solr5Index.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #13
Source File: ListCollectionHandler.java    From ambari-logsearch with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public List<String> handle(CloudSolrClient solrClient, SolrPropsConfig solrPropsConfig) throws Exception {
  try {
    CollectionAdminRequest.List colListReq = new CollectionAdminRequest.List();
    CollectionAdminResponse response = colListReq.process(solrClient);
    if (response.getStatus() != 0) {
      logger.error("Error getting collection list from solr.  response=" + response);
      return null;
    }
    return (List<String>) response.getResponse().get("collections");
  } catch (SolrException e) {
    logger.error("getCollections() operation failed", e);
    return new ArrayList<>();
  }
}
 
Example #14
Source File: TestTlogReplica.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void addReplicaWithRetries() throws SolrServerException, IOException {
  int maxAttempts = 3;
  for (int i = 0; i < maxAttempts ; i++) {
    try {
      CollectionAdminResponse respone = CollectionAdminRequest.addReplicaToShard(collectionName, "shard1", Replica.Type.TLOG).process(cluster.getSolrClient());
      // This is an unfortunate hack. There are cases where the ADDREPLICA fails, will create a Jira to address that separately. for now, we'll retry
      if (respone.isSuccess()) {
        break;
      }
      log.error("Unsuccessful attempt to add replica. Attempt: {}/{}", i, maxAttempts);
    } catch (SolrException e) {
      log.error("Exception while adding replica. Attempt: {}/{}", i, maxAttempts, e);
    }
  }
}
 
Example #15
Source File: CollectionsAPISolrJTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #16
Source File: CollectionsAPISolrJTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddAndDeleteReplica() throws Exception {

  final String collectionName = "solrj_replicatests";
  CollectionAdminRequest.createCollection(collectionName, "conf", 1, 2)
      .process(cluster.getSolrClient());
  
  cluster.waitForActiveCollection(collectionName, 1, 2);

  ArrayList<String> nodeList
      = new ArrayList<>(cluster.getSolrClient().getZkStateReader().getClusterState().getLiveNodes());
  Collections.shuffle(nodeList, random());
  final String node = nodeList.get(0);

  CollectionAdminResponse response = CollectionAdminRequest.addReplicaToShard(collectionName, "shard1")
      .setNode(node)
      .process(cluster.getSolrClient());
  
  cluster.waitForActiveCollection(collectionName, 1, 3);
  
  Replica newReplica = grabNewReplica(response, getCollectionState(collectionName));
  assertEquals(0, response.getStatus());
  assertTrue(response.isSuccess());
  assertTrue(newReplica.getNodeName().equals(node));

  // Test DELETEREPLICA
  response = CollectionAdminRequest.deleteReplica(collectionName, "shard1", newReplica.getName())
      .process(cluster.getSolrClient());
  assertEquals(0, response.getStatus());

  waitForState("Expected replica " + newReplica.getName() + " to vanish from cluster state", collectionName,
      (n, c) -> c.getSlice("shard1").getReplica(newReplica.getName()) == null);

}
 
Example #17
Source File: CollectionsAPISolrJTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Replica grabNewReplica(CollectionAdminResponse response, DocCollection docCollection) {
  String replicaName = response.getCollectionCoresStatus().keySet().iterator().next();
  Optional<Replica> optional = docCollection.getReplicas().stream()
      .filter(replica -> replicaName.equals(replica.getCoreName()))
      .findAny();
  if (optional.isPresent()) {
    return optional.get();
  }
  throw new AssertionError("Can not find " + replicaName + " from " + docCollection);
}
 
Example #18
Source File: TestConfigSetsAPI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testUploadWithScriptUpdateProcessor() throws Exception {
  Assume.assumeNotNull((new ScriptEngineManager()).getEngineByExtension("js"));
  Assume.assumeNotNull((new ScriptEngineManager()).getEngineByName("JavaScript"));
  
    // Authorization off
    // unprotectConfigsHandler(); // TODO Enable this back when testUploadWithLibDirective() is re-enabled
    final String untrustedSuffix = "-untrusted";
    uploadConfigSetWithAssertions("with-script-processor", untrustedSuffix, null, null);
    // try to create a collection with the uploaded configset
    Throwable thrown = expectThrows(BaseHttpSolrClient.RemoteSolrException.class, () -> {
      createCollection("newcollection2", "with-script-processor" + untrustedSuffix,
    1, 1, solrCluster.getSolrClient());
    });

  assertThat(thrown.getMessage(), containsString("Underlying core creation failed"));

  // Authorization on
  final String trustedSuffix = "-trusted";
  protectConfigsHandler();
  uploadConfigSetWithAssertions("with-script-processor", trustedSuffix, "solr", "SolrRocks");
  // try to create a collection with the uploaded configset
  CollectionAdminResponse resp = createCollection("newcollection2", "with-script-processor" + trustedSuffix,
  1, 1, solrCluster.getSolrClient());
  scriptRequest("newcollection2");

}
 
Example #19
Source File: TestRebalanceLeaders.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
void setPropWithAdminRequest(Slice slice, Replica rep, String prop) throws IOException, SolrServerException {
  boolean setUnique = (prop.toLowerCase(Locale.ROOT).equals("preferredleader") == false);
  CollectionAdminRequest.AddReplicaProp addProp =
      CollectionAdminRequest.addReplicaProperty(COLLECTION_NAME, slice.getName(), rep.getName(), prop, "true");
  if (setUnique) {
    addProp.setShardUnique(true);
  }
  CollectionAdminResponse resp = addProp.process(cluster.getSolrClient());
  assertEquals(0, resp.getStatus());
  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 #20
Source File: TestRebalanceLeaders.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void delProp(Slice slice, Replica rep, String prop) throws IOException, SolrServerException {
  String propLC = prop.toLowerCase(Locale.ROOT);
  CollectionAdminResponse resp = CollectionAdminRequest.deleteReplicaProperty(COLLECTION_NAME, slice.getName(), rep.getName(), propLC)
      .process(cluster.getSolrClient());
  assertEquals("Admin request failed; ", 0, resp.getStatus());
  waitForState("Expecting property '" + prop + "' to be removed from replica " + rep.getName(), COLLECTION_NAME,
      (n, c) -> c.getReplica(rep.getName()).getProperty(prop) == null);
}
 
Example #21
Source File: ShardSplitTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void doSplitMixedReplicaTypes(SolrIndexSplitter.SplitMethod splitMethod) throws Exception {
  waitForThingsToLevelOut(15, TimeUnit.SECONDS);
  String collectionName = "testSplitMixedReplicaTypes_" + splitMethod.toLower();
  CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName, "conf1", 1, 2, 0, 2); // TODO tlog replicas disabled right now.
  create.setMaxShardsPerNode(5); // some high number so we can create replicas without hindrance
  create.process(cloudClient);
  
  cloudClient.waitForState(collectionName, 30, TimeUnit.SECONDS, SolrCloudTestCase.activeClusterShape(1, 4));
  
  waitForRecoveriesToFinish(collectionName, false);

  for (int i = 0; i < 100; i++) {
    cloudClient.add(collectionName, getDoc("id", "id-" + i, "foo_s", "bar " + i));
  }
  cloudClient.commit(collectionName);

  CollectionAdminRequest.SplitShard splitShard = CollectionAdminRequest.splitShard(collectionName);
  splitShard.setShardName(SHARD1);
  splitShard.setSplitMethod(splitMethod.toLower());
  CollectionAdminResponse rsp = splitShard.process(cloudClient);
  waitForThingsToLevelOut(30, TimeUnit.SECONDS);
 
  cloudClient.waitForState(collectionName, 30, TimeUnit.SECONDS, SolrCloudTestCase.activeClusterShape(2, 12));

  cloudClient.getZkStateReader().forceUpdateCollection(collectionName);
  ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
  DocCollection coll = clusterState.getCollection(collectionName);
  log.info("coll: {}", coll);

  // verify the original shard
  verifyShard(coll, SHARD1, Slice.State.INACTIVE, 2, 0, 2);
  // verify new sub-shards
  verifyShard(coll, SHARD1_0, Slice.State.ACTIVE, 2, 0, 2);
  verifyShard(coll, SHARD1_1, Slice.State.ACTIVE, 2, 0, 2);
}
 
Example #22
Source File: CollectionsAPIDistributedZkTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Replica grabNewReplica(CollectionAdminResponse response, DocCollection docCollection) {
  String replicaName = response.getCollectionCoresStatus().keySet().iterator().next();
  Optional<Replica> optional = docCollection.getReplicas().stream()
      .filter(replica -> replicaName.equals(replica.getCoreName()))
      .findAny();
  if (optional.isPresent()) {
    return optional.get();
  }
  throw new AssertionError("Can not find " + replicaName + " from " + docCollection);
}
 
Example #23
Source File: CollectionsAPIDistributedZkTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateShouldFailOnExistingCore() throws Exception {
  assertEquals(0, CollectionAdminRequest.createCollection("halfcollectionblocker", "conf", 1, 1)
      .setCreateNodeSet("")
      .process(cluster.getSolrClient()).getStatus());
  assertTrue(CollectionAdminRequest.addReplicaToShard("halfcollectionblocker", "shard1")
      .setNode(cluster.getJettySolrRunner(0).getNodeName())
      .setCoreName("halfcollection_shard1_replica_n1")
      .process(cluster.getSolrClient()).isSuccess());

  assertEquals(0, CollectionAdminRequest.createCollection("halfcollectionblocker2", "conf",1, 1)
      .setCreateNodeSet("")
      .process(cluster.getSolrClient()).getStatus());
  assertTrue(CollectionAdminRequest.addReplicaToShard("halfcollectionblocker2", "shard1")
      .setNode(cluster.getJettySolrRunner(1).getNodeName())
      .setCoreName("halfcollection_shard1_replica_n1")
      .process(cluster.getSolrClient()).isSuccess());

  String nn1 = cluster.getJettySolrRunner(0).getNodeName();
  String nn2 = cluster.getJettySolrRunner(1).getNodeName();

  expectThrows(BaseHttpSolrClient.RemoteSolrException.class, () -> {
    CollectionAdminResponse resp = CollectionAdminRequest.createCollection("halfcollection", "conf", 2, 1)
        .setCreateNodeSet(nn1 + "," + nn2)
        .process(cluster.getSolrClient());
  });
}
 
Example #24
Source File: ZkCollectionPropsCachingTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Before
@Override
public void setUp() throws Exception {
  super.setUp();

  collectionName = "CollectionPropsTest" + System.nanoTime();

  CollectionAdminRequest.Create request = CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2);
  CollectionAdminResponse response = request.process(cluster.getSolrClient());
  assertTrue("Unable to create collection: " + response.toString(), response.isSuccess());
}
 
Example #25
Source File: ReindexCollectionTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicReindexing() throws Exception {
  final String sourceCollection = "basicReindexing";

  createCollection(sourceCollection, "conf1", 2, 2);

  indexDocs(sourceCollection, NUM_DOCS,
      i -> new SolrInputDocument("id", String.valueOf(i), "string_s", String.valueOf(i)));

  final String targetCollection = "basicReindexingTarget";

  CollectionAdminRequest.ReindexCollection req = CollectionAdminRequest.reindexCollection(sourceCollection)
      .setTarget(targetCollection);
  CollectionAdminResponse rsp = req.process(solrClient);
  assertNotNull(rsp.toString(), rsp.getResponse().get(ReindexCollectionCmd.REINDEX_STATUS));
  @SuppressWarnings({"unchecked"})
  Map<String, Object> status = (Map<String, Object>)rsp.getResponse().get(ReindexCollectionCmd.REINDEX_STATUS);
  assertEquals(status.toString(), (long)NUM_DOCS, ((Number)status.get("inputDocs")).longValue());
  assertEquals(status.toString(), (long)NUM_DOCS, ((Number)status.get("processedDocs")).longValue());

  CloudUtil.waitForState(cloudManager, "did not finish copying in time", targetCollection, (liveNodes, coll) -> {
    ReindexCollectionCmd.State state = ReindexCollectionCmd.State.get(coll.getStr(ReindexCollectionCmd.REINDEXING_STATE));
    return ReindexCollectionCmd.State.FINISHED == state;
  });

  // verify the target docs exist
  QueryResponse queryResponse = solrClient.query(targetCollection, params(CommonParams.Q, "*:*"));
  assertEquals("copied num docs", NUM_DOCS, queryResponse.getResults().getNumFound());
}
 
Example #26
Source File: SolrIndex.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #27
Source File: ReplicationFactorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
void createCollectionWithRetry(String testCollectionName, String config, int numShards, int replicationFactor, int maxShardsPerNode) throws IOException, SolrServerException, InterruptedException, TimeoutException {
  CollectionAdminResponse resp = createCollection(testCollectionName, "conf1", numShards, replicationFactor, maxShardsPerNode);

  if (resp.getResponse().get("failure") != null) {
    Thread.sleep(5000); // let system settle down. This should be very rare.

    CollectionAdminRequest.deleteCollection(testCollectionName).process(cloudClient);

    resp = createCollection(testCollectionName, "conf1", numShards, replicationFactor, maxShardsPerNode);

    if (resp.getResponse().get("failure") != null) {
      fail("Could not create " + testCollectionName);
    }
  }
}
 
Example #28
Source File: SolrAuditAliasConfigurer.java    From ambari-logsearch with Apache License 2.0 5 votes vote down vote up
private int createAlias(final CloudSolrClient solrClient, String aliasNameIn, Collection<String> collectionListIn)
  throws SolrServerException, IOException {
  List<String> collectionToAdd = new ArrayList<>();
  try {
    collectionToAdd = new ListCollectionHandler().handle(solrClient, null);
  } catch (Exception e) {
    logger.error("Invalid state during getting collections for creating alias");
  }
  collectionToAdd.retainAll(collectionListIn);

  String collectionsCSV = null;
  if (!collectionToAdd.isEmpty()) {
    collectionsCSV = StringUtils.join(collectionToAdd, ',');
    CollectionAdminRequest.CreateAlias aliasCreateRequest = CollectionAdminRequest.createAlias(aliasNameIn, collectionsCSV);
    CollectionAdminResponse createResponse = aliasCreateRequest.process(solrClient);
    if (createResponse.getStatus() != 0) {
      logger.error("Error creating alias. alias=" + aliasNameIn + ", collectionList=" + collectionsCSV
        + ", response=" + createResponse);
      return 0;
    }
  }
  if (collectionToAdd.size() == collectionListIn.size()) {
    logger.info("Created alias for all collections. alias=" + aliasNameIn + ", collectionsCSV=" + collectionsCSV);
  } else {
    logger.info("Created alias for " + collectionToAdd.size() + " out of " + collectionListIn.size() + " collections. " +
      "alias=" + aliasNameIn + ", collectionsCSV=" + collectionsCSV);
  }
  return collectionToAdd.size();
}
 
Example #29
Source File: TestRebalanceLeaders.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void rebalanceLeaderUsingSolrJAPI() throws IOException, SolrServerException, InterruptedException {
  CollectionAdminResponse resp = CollectionAdminRequest
      .rebalanceLeaders(COLLECTION_NAME)
      .process(cluster.getSolrClient());
  assertTrue("All leaders should have been verified", resp.getResponse().get("Summary").toString().contains("Success"));
  assertEquals("Admin request failed; ", 0, resp.getStatus());
}
 
Example #30
Source File: TestConfigSetsAPI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore // enable this back when the sleep is removed from protectConfigsHandler() call
public void testUploadWithLibDirective() throws Exception {
  // Authorization off
  unprotectConfigsHandler();
  final String untrustedSuffix = "-untrusted";
  uploadConfigSetWithAssertions("with-lib-directive", untrustedSuffix, null, null);
  // try to create a collection with the uploaded configset
  Throwable thrown = expectThrows(BaseHttpSolrClient.RemoteSolrException.class, () -> {
    createCollection("newcollection3", "with-lib-directive" + untrustedSuffix,
        1, 1, solrCluster.getSolrClient());
  });

  assertThat(thrown.getMessage(), containsString("Underlying core creation failed"));

  // Authorization on
  final String trustedSuffix = "-trusted";
  protectConfigsHandler();
  uploadConfigSetWithAssertions("with-lib-directive", trustedSuffix, "solr", "SolrRocks");
  // try to create a collection with the uploaded configset
  CollectionAdminResponse resp = createCollection("newcollection3", "with-lib-directive" + trustedSuffix,
      1, 1, solrCluster.getSolrClient());
  
  SolrInputDocument doc = sdoc("id", "4055", "subject", "Solr");
  solrCluster.getSolrClient().add("newcollection3", doc);
  solrCluster.getSolrClient().commit("newcollection3");
  assertEquals("4055", solrCluster.getSolrClient().query("newcollection3",
      params("q", "*:*")).getResults().get(0).get("id"));
}