Example usage for org.apache.solr.client.solrj.response CollectionAdminResponse getErrorMessages

List of usage examples for org.apache.solr.client.solrj.response CollectionAdminResponse getErrorMessages

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.response CollectionAdminResponse getErrorMessages.

Prototype

@SuppressWarnings("unchecked")
    public NamedList<String> getErrorMessages() 

Source Link

Usage

From source file:com.hurence.logisland.service.solr.api.SolrClientService.java

License:Apache License

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");
    }//  ww w . j  ava2  s .c o m

    return ((ArrayList) response.getResponse().get("collections")).contains(name);
}

From source file:com.hurence.logisland.service.solr.Solr_6_6_2_ClientService.java

License:Apache License

protected boolean existsCloudAliasCollection(String name) throws IOException, SolrServerException {
    CollectionAdminRequest.ListAliases listAliasesRequest = new CollectionAdminRequest.ListAliases();
    CollectionAdminResponse response = listAliasesRequest.process(getClient(), name);
    if (response.getErrorMessages() != null) {
        throw new DatastoreClientServiceException("Unable to fetch collection list");
    }//from  w  w  w  .  j a  va 2  s .  c o m

    return ((ArrayList) response.getResponse().get("aliases")).contains(name);
}

From source file:com.ibm.ecod.watson.RetrieveAndRankSolrJExample.java

License:Open Source License

/**
 * Create the collection referencing the name of the configuration that was previously uploaded.
 *//*from  w  w w.  j av  a2 s  .  c o m*/
private static void createCollection() throws SolrServerException, IOException {
    final CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create();
    createCollectionRequest.setCollectionName(COLLECTION_NAME);
    createCollectionRequest.setConfigName(CONFIG_NAME);

    System.out.println("Creating collection...");
    final CollectionAdminResponse response = createCollectionRequest.process(solrClient);
    if (!response.isSuccess()) {
        System.out.println(response.getErrorMessages());
        throw new IllegalStateException(
                "Failed to create collection: " + response.getErrorMessages().toString());
    }
    System.out.println("Collection created.");
}

From source file:com.ibm.watson.apis.conversation_enhanced.listener.SetupThread.java

License:Open Source License

/**
 * Creates a SOLR collection in which documents can later be ingested
 * //from w  w w . j ava  2s  .c o  m
 * @param solrClient
 */
private static void createCollection(HttpSolrClient solrClient) {
    final CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create();
    createCollectionRequest.setCollectionName(Constants.COLLECTION_NAME);
    createCollectionRequest.setConfigName(Constants.CONFIGURATION_NAME);

    logger.info(Messages.getString("SetupThread.CREATING_COLLECTION")); //$NON-NLS-1$
    CollectionAdminResponse response = null;
    try {
        response = createCollectionRequest.process(solrClient);
    } catch (SolrServerException e) {
        logger.error(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
    }
    if (!response.isSuccess()) {
        logger.error(Messages.getString("SetupThread.CREATING_COLLECTION_FAILED") //$NON-NLS-1$
                + response.getErrorMessages().toString());
    }
    logger.info(Messages.getString("SetupThread.COLLECTION_CREATED")); //$NON-NLS-1$
}

From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.Cluster.java

License:Open Source License

/**
 * Delete a collection//  w  w  w. j  a  va 2s.c  om
 * 
 * @param collection_name - collection to be deleted if it exists
 * @param config_name - configuration to be deleted if it exists
 * @throws SolrServerException
 * @throws IOException
 */
void deleteCollection(String collection_name) throws SolrServerException, IOException {
    checkStatus();
    final CollectionAdminRequest.Delete deleteCollectionRequest = new CollectionAdminRequest.Delete();
    deleteCollectionRequest.setCollectionName(collection_name);

    // Send the deletion request and throw an exception if the response is
    // not successful
    log.info(Messages.getString("RetrieveAndRank.COLLECTION_DELETING")); //$NON-NLS-1$

    final CollectionAdminResponse response = deleteCollectionRequest.process(solrClient);
    if (!response.isSuccess()) {
        throw new IllegalStateException(
                MessageFormat.format(Messages.getString("RetrieveAndRank.COLLECTION_DELETE_FAILED"), //$NON-NLS-1$
                        response.getErrorMessages().toString()));
    }
    log.info(Messages.getString("RetrieveAndRank.COLLECTION_DELETED")); //$NON-NLS-1$
}

From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.Cluster.java

License:Open Source License

/**
 * creates a collection with the specified configuration
 * /*  w  w  w. java  2s  .  c  o  m*/
 * @param collection_name - the new collection's name
 * @param config_name - name of already uploaded configuration to use for this collection
 * @throws SolrServerException
 * @throws IOException
 */
public Collection createCollection(String collection_name, String config_name)
        throws SolrServerException, IOException {
    checkStatus();
    final CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create();
    createCollectionRequest.setCollectionName(collection_name);
    createCollectionRequest.setConfigName(config_name);

    log.info(Messages.getString("RetrieveAndRank.COLLECTION_CREATING")); //$NON-NLS-1$
    final CollectionAdminResponse response = createCollectionRequest.process(solrClient);
    if (!response.isSuccess()) {
        String errorMsg = MessageFormat.format(Messages.getString("RetrieveAndRank.COLLECTION_CREATE_FAILED"), //$NON-NLS-1$
                response.getErrorMessages().toString());
        throw new IllegalStateException(errorMsg);
    }
    log.info(Messages.getString("RetrieveAndRank.COLLECTION_CREATED")); //$NON-NLS-1$
    Collection collection = new Collection(this, collection_name);
    return collection;
}

From source file:com.ibm.watson.developer_cloud.retrieve_and_rank.v1.RetrieveAndRankSolrHttpClientExample.java

License:Open Source License

/**
 * Create the collection referencing the name of the configuration that was previously uploaded.
 */// w w  w .  j  a v a 2 s .com
private static void createCollection() throws SolrServerException, IOException {
    final CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create();
    createCollectionRequest.setCollectionName(COLLECTION_NAME);
    createCollectionRequest.setConfigName(CONFIG_NAME);

    System.out.println("Creating collection...");
    final CollectionAdminResponse response = createCollectionRequest.process(watsonSolrClient);
    if (!response.isSuccess()) {
        throw new IllegalStateException(
                "Failed to create collection: " + response.getErrorMessages().toString());
    }
    System.out.println("Collection created.");
}

From source file:com.thinkaurelius.titan.diskstorage.solr.Solr5Index.java

License:Apache License

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 {/*from   ww  w.j a v a 2  s .  c  o m*/
            throw new SolrServerException(Joiner.on("\n").join(createResponse.getErrorMessages()));
        }
    }

    waitForRecoveriesToFinish(client, collection);
}

From source file:org.codice.ddf.commands.solr.SolrCommands.java

License:Open Source License

protected void printResponseErrorMessages(CollectionAdminResponse response) {
    NamedList<String> errorMessages = response.getErrorMessages();
    if (errorMessages != null) {
        for (int i = 0; i < errorMessages.size(); i++) {
            String name = errorMessages.getName(i);
            String value = errorMessages.getVal(i);
            printErrorMessage(String.format("\t%d. Error Name: %s; Error Value: %s", i + 1, name, value));
        }//w w  w  .ja  v  a  2s  .c om
    }
}

From source file:org.codice.ddf.commands.solr.SolrCommandTest.java

License:Open Source License

protected static void createDefaultCollection() throws Exception {
    CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(DEFAULT_CORE_NAME,
            DEFAULT_CONFIGSET, 1, 1);//from  w w w.j a  v  a2  s.c  om
    CollectionAdminResponse response = create.process(miniSolrCloud.getSolrClient());
    if (response.getStatus() != 0 || response.getErrorMessages() != null) {
        fail("Could not create collection. Response: " + response.toString());
    }

    List<String> collections = CollectionAdminRequest.listCollections(miniSolrCloud.getSolrClient());
    assertThat(collections.size(), is(1));
    miniSolrCloud.getSolrClient().setDefaultCollection(DEFAULT_CORE_NAME);
}