Example usage for org.apache.solr.client.solrj.request CollectionAdminRequest deleteCollection

List of usage examples for org.apache.solr.client.solrj.request CollectionAdminRequest deleteCollection

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.request CollectionAdminRequest deleteCollection.

Prototype

public static Delete deleteCollection(String collection) 

Source Link

Document

Returns a SolrRequest to delete a collection

Usage

From source file:com.shaie.solr.solrj.CollectionAdminHelper.java

License:Apache License

/** Deletes a collection. */
public DeleteCollectionResponse deleteCollection(String collectionName) {
    if (!collectionExists(collectionName)) {
        return null;
    }//from   ww  w .ja  v  a2 s  .  c om

    try {
        final CollectionAdminRequest.Delete deleteCollectionRequest = CollectionAdminRequest
                .deleteCollection(collectionName);

        final CollectionAdminResponse response = deleteCollectionRequest.process(solrClient);
        return new DeleteCollectionResponse(response);
    } catch (IOException | SolrServerException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.nifi.processors.solr.QuerySolrIT.java

License:Apache License

@AfterClass
public static void teardown() {
    try {//from   w ww  .j  av a2  s.co m
        CloudSolrClient solrClient = createSolrClient();
        CollectionAdminRequest.Delete deleteCollection = CollectionAdminRequest
                .deleteCollection(SOLR_COLLECTION);
        deleteCollection.process(solrClient);
        solrClient.close();
    } catch (Exception e) {
    }
}

From source file:org.apache.sentry.tests.e2e.solr.AbstractSolrSentryTestCase.java

License:Apache License

protected void deleteCollection(String userName, String collectionName)
        throws SolrServerException, IOException {
    String tmp = getAuthenticatedUser();
    try {/*from   ww w  . j  a v  a 2 s. c  om*/
        setAuthenticationUser(userName);
        // Create collection.
        CollectionAdminRequest.Delete deleteCmd = CollectionAdminRequest.deleteCollection(collectionName);
        assertEquals(0, deleteCmd.process(cluster.getSolrClient()).getStatus());
    } finally {
        setAuthenticationUser(tmp);
    }
}

From source file:org.apache.sentry.tests.e2e.solr.TestSolrAdminOperations.java

License:Apache License

protected void adminUpdateActionSuccess(String userName, String collectionName)
        throws SolrServerException, IOException {
    // Success.// w  ww . j a  v  a2s.co m
    String tmp = getAuthenticatedUser();
    try {
        // Create collection.
        setAuthenticationUser(userName);
        CollectionAdminRequest.Create createCmd = CollectionAdminRequest.createCollection(collectionName,
                "cloud-minimal", 1, NUM_SERVERS);
        assertEquals(0, createCmd.process(cluster.getSolrClient()).getStatus());

        // Delete collection.
        CollectionAdminRequest.Delete delCmd = CollectionAdminRequest.deleteCollection(collectionName);
        assertEquals(0, delCmd.process(cluster.getSolrClient()).getStatus());

    } finally {
        setAuthenticationUser(tmp);
    }
}

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 {//  w  w w . ja  v  a 2s  .  com
            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;
}

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

License:Open Source License

protected static void cleanupCollections() throws Exception {
    List<String> collections = CollectionAdminRequest.listCollections(miniSolrCloud.getSolrClient());
    for (String collection : collections) {
        CollectionAdminRequest.Delete delete = CollectionAdminRequest.deleteCollection(collection);
        delete.process(miniSolrCloud.getSolrClient());
    }/*from  w w  w . jav  a 2s.  c  om*/
}

From source file:org.opencb.commons.datastore.solr.SolrManager.java

License:Apache License

/**
 * Remove a collection.//from  ww w .  ja  v  a  2 s  .co  m
 *
 * @param collectionName Collection name
 * @throws SolrException SolrException
 */
public void removeCollection(String collectionName) throws SolrException {
    try {
        CollectionAdminRequest request = CollectionAdminRequest.deleteCollection(collectionName);
        request.process(solrClient);
    } catch (SolrServerException | IOException e) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e.getMessage(), e);
    }
}

From source file:org.wso2.extension.siddhi.store.solr.impl.SolrClientServiceImpl.java

License:Open Source License

public boolean deleteCollection(String table) throws SolrClientServiceException {
    try {/*from   w ww .  j  av a  2  s . c  o  m*/
        if (collectionExists(table)) {
            SiddhiSolrClient client = getSolrServiceClientByCollection(table);
            CollectionConfiguration configuration = tableToConfigMapping.get(table);
            if (configuration == null) {
                throw new SolrClientServiceException(
                        "Configuration is not set for table: " + table + ", call initCollection() first");
            }
            String tableNameWithDomain = SolrTableUtils
                    .getCollectionNameWithDomainName(configuration.getDomainName(), table);
            CollectionAdminRequest.Delete deleteRequest = CollectionAdminRequest
                    .deleteCollection(tableNameWithDomain);
            CollectionAdminResponse deleteRequestResponse = deleteRequest.process(client, tableNameWithDomain);
            if (deleteRequestResponse.isSuccess() && collectionConfigExists(table)) {
                ConfigSetAdminRequest.Delete configSetAdminRequest = new ConfigSetAdminRequest.Delete();
                configSetAdminRequest.setConfigSetName(tableNameWithDomain);
                ConfigSetAdminResponse configSetResponse = configSetAdminRequest.process(client);
                Object errors = configSetResponse.getErrorMessages();
                if (configSetResponse.getStatus() == 0 && errors == null) {
                    tableToConfigMapping.remove(table);
                    return tryToCloseClient(configuration);
                } else {
                    throw new SolrClientServiceException(
                            "Error in deleting index for table: " + table + ", " + ", Response code: "
                                    + configSetResponse.getStatus() + " , errors: " + errors.toString());
                }
            }
        }
    } catch (IOException | SolrServerException | SolrException e) {
        log.error("error while deleting the index for table: " + table + ": " + e.getMessage(), e);
        throw new SolrClientServiceException(
                "error while deleting the index for table: " + table + ", error: " + e.getMessage(), e);
    }
    return false;
}