Example usage for org.apache.solr.client.solrj.response CoreAdminResponse getCoreStatus

List of usage examples for org.apache.solr.client.solrj.response CoreAdminResponse getCoreStatus

Introduction

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

Prototype

@SuppressWarnings("unchecked")
    public NamedList<NamedList<Object>> getCoreStatus() 

Source Link

Usage

From source file:com.github.fengtan.sophie.beans.SolrUtils.java

License:Open Source License

/**
 * Get list of cores from the remote Solr server.
 * //from  w  w  w .j  ava  2s .co  m
 * @return Map of cores attributes keyed by core name.
 * @throws SophieException
 *             If the list of cores cannot be fetched.
 */
@SuppressWarnings("unchecked")
public static Map<String, NamedList<Object>> getCores() throws SophieException {
    CoreAdminRequest request = new CoreAdminRequest();
    request.setAction(CoreAdminAction.STATUS);
    try {
        CoreAdminResponse response = request.process(Sophie.client);
        return response.getCoreStatus().asMap(-1);
    } catch (SolrServerException | IOException | SolrException e) {
        throw new SophieException("Unable to fetch list of Solr cores", e);
    }
}

From source file:com.k_joseph.apps.multisearch.solr.AddCustomFieldsToSchema.java

License:Mozilla Public License

/**
 * Used to Reload the SolrServer after changes are made to the schema.xml among other
 * configuration files//from   w w w  . ja  v a2s  . c  o m
 * 
 * @param solrServer
 * @param adminRequest
 */
public static void reloadSolrServer(SolrServer solrServer, CoreAdminRequest adminRequest) {
    adminRequest.setAction(CoreAdminAction.RELOAD);
    CoreAdminResponse adminResponse;
    try {
        adminResponse = adminRequest.process(solrServer);
        @SuppressWarnings("unused")
        NamedList<NamedList<Object>> coreStatus = adminResponse.getCoreStatus();
    } catch (SolrServerException e) {
        System.out.println("Error generated" + e);
    } catch (IOException e) {
        System.out.println("Error generated" + e);
    }
}

From source file:com.stratio.decision.service.SolrOperationsService.java

License:Apache License

public List<String> getCoreList() throws IOException, SolrServerException {
    SolrClient solrClient = getSolrclient(null);
    CoreAdminRequest coreAdminRequest = new CoreAdminRequest();
    coreAdminRequest.setAction(CoreAdminParams.CoreAdminAction.STATUS);
    CoreAdminResponse cores = coreAdminRequest.process(solrClient);

    List<String> coreList = new ArrayList<String>();
    for (int i = 0; i < cores.getCoreStatus().size(); i++) {
        coreList.add(cores.getCoreStatus().getName(i));
    }/*w ww .  ja va2 s .c om*/
    return coreList;
}

From source file:org.apache.drill.exec.store.solr.SolrClientAPIExec.java

License:Apache License

public Set<String> getSolrCoreList() {
    // Request core list
    SolrClientAPIExec.logger.debug("Getting cores from solr..");
    CoreAdminRequest request = new CoreAdminRequest();
    request.setAction(CoreAdminAction.STATUS);
    Set<String> coreList = null;
    try {/* w  w  w .  jav a2  s  . com*/
        CoreAdminResponse cores = request.process(solrClient);
        coreList = new HashSet<String>(cores.getCoreStatus().size());
        for (int i = 0; i < cores.getCoreStatus().size(); i++) {
            String coreName = cores.getCoreStatus().getName(i);
            coreList.add(coreName);
        }
    } catch (SolrServerException | IOException e) {
        SolrClientAPIExec.logger.info("Error getting core info from solr server...");
    }
    return coreList;
}

From source file:org.apache.ranger.services.solr.client.ServiceSolrClient.java

License:Apache License

public List<String> getCoresList(List<String> ignoreCollectionList) throws Exception {
    CoreAdminRequest request = new CoreAdminRequest();
    request.setAction(CoreAdminAction.STATUS);
    CoreAdminResponse cores = request.process(solrClient);
    // List of the cores
    List<String> coreList = new ArrayList<String>();
    for (int i = 0; i < cores.getCoreStatus().size(); i++) {
        if (ignoreCollectionList == null || !ignoreCollectionList.contains(cores.getCoreStatus().getName(i))) {
            coreList.add(cores.getCoreStatus().getName(i));
        }//  w  w  w  . j a v a  2  s.com
    }
    return coreList;
}

From source file:org.opencommercesearch.CloudSearchServer.java

License:Apache License

/**
 * Reloads the core/*from ww  w  .j a va  2 s .co m*/
 *
 * @param collectionName
 *            the cored to be reloaded
 *
 * @throws SearchServerException
 *          if an error occurs while reloading the core
 *
 */
public void reloadCollection(String collectionName, Locale locale) throws SearchServerException {
    CoreAdminRequest adminRequest = new CoreAdminRequest();
    adminRequest.setCoreName(collectionName);
    adminRequest.setAction(CoreAdminAction.RELOAD);

    CloudSolrServer server = getSolrServer(collectionName, locale);
    ZkStateReader zkStateReader = server.getZkStateReader();
    if (zkStateReader == null) {
        //if the zkStateReader is null it means we haven't connect to this collection
        server.connect();
        zkStateReader = server.getZkStateReader();
    }

    ClusterState clusterState = zkStateReader.getClusterState();
    Set<String> liveNodes = clusterState.getLiveNodes();

    if (liveNodes == null || liveNodes.size() == 0) {
        if (isLoggingInfo()) {
            logInfo("No live nodes found, 0 cores were reloaded");
        }
        return;
    }

    Map<String, Slice> slices = clusterState.getSlicesMap(collectionName);
    if (slices.size() == 0) {
        if (isLoggingInfo()) {
            logInfo("No slices found, 0 cores were reloaded");
        }
    }

    for (Slice slice : slices.values()) {
        for (ZkNodeProps nodeProps : slice.getReplicas()) {
            ZkCoreNodeProps coreNodeProps = new ZkCoreNodeProps(nodeProps);
            String node = coreNodeProps.getNodeName();
            if (!liveNodes.contains(coreNodeProps.getNodeName())
                    || !coreNodeProps.getState().equals(ZkStateReader.ACTIVE)) {
                if (isLoggingInfo()) {
                    logInfo("Node " + node + " is not live, unable to reload core " + collectionName);
                }
                continue;
            }

            if (isLoggingInfo()) {
                logInfo("Reloading core " + collectionName + " on " + node);
            }
            HttpClient httpClient = server.getLbServer().getHttpClient();
            HttpSolrServer nodeServer = new HttpSolrServer(coreNodeProps.getBaseUrl(), httpClient,
                    getResponseParser());
            try {
                CoreAdminResponse adminResponse = adminRequest.process(nodeServer);
                if (isLoggingInfo()) {
                    logInfo("Reladed core " + collectionName + ", current status is "
                            + adminResponse.getCoreStatus());
                }
            } catch (SolrServerException ex) {
                if (ex.getCause() instanceof SocketTimeoutException) {
                    //if we experience a socket timeout out don't kill the entire process. Try to reload the other nodes
                    if (isLoggingError()) {
                        logError("Reloading core failed due to socket timeout for node [" + node
                                + "] and collection [" + collectionName + "]");
                    }
                } else {
                    throw create(CORE_RELOAD_EXCEPTION, ex);
                }
            } catch (IOException ex) {
                throw create(CORE_RELOAD_EXCEPTION, ex);
            }
        }
    }
}