Java Code Examples for org.apache.solr.client.solrj.response.CollectionAdminResponse#getStatus()

The following examples show how to use org.apache.solr.client.solrj.response.CollectionAdminResponse#getStatus() . 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: 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 3
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 4
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 5
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 6
Source File: TestLTROnSolrCloud.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void createCollection(String name, String config, int numShards, int numReplicas, int maxShardsPerNode)
    throws Exception {
  CollectionAdminResponse response;
  CollectionAdminRequest.Create create =
      CollectionAdminRequest.createCollection(name, config, numShards, numReplicas);
  create.setMaxShardsPerNode(maxShardsPerNode);
  response = create.process(solrCluster.getSolrClient());

  if (response.getStatus() != 0 || response.getErrorMessages() != null) {
    fail("Could not create collection. Response" + response.toString());
  }
  ZkStateReader zkStateReader = solrCluster.getSolrClient().getZkStateReader();
  solrCluster.waitForActiveCollection(name, numShards, numShards * numReplicas);
}
 
Example 7
Source File: ConcurrentDeleteAndCreateCollectionTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void createCollection() {
  try {
    final CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName,configName,1,1)
            .process(solrClient);
    if (response.getStatus() != 0) {
      addFailure(new RuntimeException("failed to create collection " + collectionName));
    }
  } catch (Exception e) {
    addFailure(e);
  }
  
}
 
Example 8
Source File: ConcurrentDeleteAndCreateCollectionTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void deleteCollection() {
  try {
    final CollectionAdminRequest.Delete deleteCollectionRequest
      = CollectionAdminRequest.deleteCollection(collectionName);
    final CollectionAdminResponse response = deleteCollectionRequest.process(solrClient);
    if (response.getStatus() != 0) {
      addFailure(new RuntimeException("failed to delete collection " + collectionName));
    }
  } catch (Exception e) {
    addFailure(e);
  }
}
 
Example 9
Source File: TestRequestForwarding.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void createCollection(String name, String config) throws Exception {
  CollectionAdminResponse response;
  CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(name,config,2,1);
  create.setMaxShardsPerNode(1);
  response = create.process(solrCluster.getSolrClient());
  
  if (response.getStatus() != 0 || response.getErrorMessages() != null) {
    fail("Could not create collection. Response" + response.toString());
  }
  ZkStateReader zkStateReader = solrCluster.getSolrClient().getZkStateReader();
  solrCluster.waitForActiveCollection(name, 2, 2);
}