List of usage examples for org.apache.solr.client.solrj.response CollectionAdminResponse isSuccess
public boolean isSuccess()
From source file:com.hurence.logisland.service.solr.api.SolrClientService.java
License:Apache License
@Override public void createAlias(String collection, String alias) throws DatastoreClientServiceException { try {/* w w w . jav a 2 s. co m*/ 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); } }
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 . java2 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 a v a 2 s.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/*from www. j a va 2 s . c o m*/ * * @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
/** * list all collection names on the cluster * //from w ww .ja va 2 s .c o m * @return List<String> - a list of the names of the collections * @throws SolrServerException * @throws IOException */ @SuppressWarnings("unchecked") public List<String> listCollections() throws SolrServerException, IOException { checkStatus(); final CollectionAdminRequest.List listCollectionRequest = new CollectionAdminRequest.List(); final CollectionAdminResponse listResponse = listCollectionRequest.process(solrClient); final List<String> collections = (List<String>) listResponse.getResponse().get("collections"); // check that the response is successful and return the list if (!listResponse.isSuccess()) { return collections; } else { String errorMsg = MessageFormat.format(Messages.getString("RetrieveAndRank.COLLECTION_LIST"), //$NON-NLS-1$ listResponse); throw new SolrServerException(errorMsg); } }
From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.Cluster.java
License:Open Source License
/** * creates a collection with the specified configuration * //from w w w.j ava 2 s . 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. *///from w w w .jav a2 s.c om 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 va2 s.co m throw new SolrServerException(Joiner.on("\n").join(createResponse.getErrorMessages())); } } waitForRecoveriesToFinish(client, collection); }
From source file:org.codice.ddf.commands.solr.BackupCommand.java
License:Open Source License
private boolean backup(SolrClient client, String collection, String backupLocation, String backupName) throws IOException, SolrServerException { CollectionAdminRequest.Backup backup = CollectionAdminRequest.backupCollection(collection, backupName) .setLocation(backupLocation); CollectionAdminResponse response = backup.process(client, collection); LOGGER.debug("Backup status: {}", response.getStatus()); if (response.getStatus() != 0) { printErrorMessage("Backup failed."); printResponseErrorMessages(response); }//w w w . j a va 2 s .co m return response.isSuccess(); }
From source file:org.codice.ddf.commands.solr.RestoreCommand.java
License:Open Source License
private boolean canRestore(SolrClient client, String collection) throws IOException, SolrServerException { LOGGER.trace("Checking restoration capability of collection {}", collection); if (collectionExists(client, collection)) { LOGGER.trace("Collection {} already exists", collection); if (force) { LOGGER.trace("Force option set, deleting existing {} collection", collection); CollectionAdminRequest.Delete delete = CollectionAdminRequest.deleteCollection(collection); CollectionAdminResponse response = delete.process(client); return response.isSuccess(); } else {//from www . j a v a2 s . c o m printErrorMessage(String.format( "Force option not set, cannot restore %s collection. Use --force to restore when the collection exists.", collection)); LOGGER.trace("Force option not set, cannot restore {} collection", collection); return false; } } return true; }