Example usage for org.apache.solr.common.cloud SolrZkClient setData

List of usage examples for org.apache.solr.common.cloud SolrZkClient setData

Introduction

In this page you can find the example usage for org.apache.solr.common.cloud SolrZkClient setData.

Prototype

public Stat setData(String path, File file, boolean retryOnConnLoss)
        throws IOException, KeeperException, InterruptedException 

Source Link

Document

Write file to ZooKeeper - default system encoding used.

Usage

From source file:com.doculibre.constellio.services.SolrServicesImpl.java

License:Open Source License

public static void writeXMLConfigInCloud(String collectionName, String fileName, Document schemaDocument) {
    String realCollectionName;//from  ww  w  . j a  va2s.co  m
    if (SolrServicesImpl.isAliasInCloud(collectionName)) {
        realCollectionName = SolrServicesImpl.getRealCollectionInCloud(collectionName);
    } else {
        realCollectionName = collectionName;
    }
    try {
        OutputFormat format = OutputFormat.createPrettyPrint();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        XMLWriter writer = new XMLWriter(outputStream, format);
        writer.write(schemaDocument);
        writer.close();
        SolrZkClient zkClient = SolrCoreContext.getSolrZkClient();
        zkClient.setData(ZkController.CONFIGS_ZKNODE + "/" + realCollectionName + "/" + fileName,
                outputStream.toByteArray(), true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.doculibre.constellio.services.SolrServicesImpl.java

License:Open Source License

public static void writePlainConfigInCloud(String collectionName, String fileName, File file) {
    String realCollectionName;// www  .  j a v a2s .co  m
    if (SolrServicesImpl.isAliasInCloud(collectionName)) {
        realCollectionName = SolrServicesImpl.getRealCollectionInCloud(collectionName);
    } else {
        realCollectionName = collectionName;
    }
    try {
        SolrZkClient zkClient = SolrCoreContext.getSolrZkClient();
        zkClient.setData(ZkController.CONFIGS_ZKNODE + "/" + realCollectionName + "/" + fileName,
                Files.readAllBytes(file.toPath()), true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.doculibre.constellio.services.SolrServicesImpl.java

License:Open Source License

public static void writePlainConfigInCloud(String fileName, byte[] ouput) {
    try {// w  w w .j  ava2  s.  c o m
        SolrZkClient zkClient = SolrCoreContext.getSolrZkClient();
        if (!zkClient.exists(ZkController.CONFIGS_ZKNODE + "/" + fileName, true)) {
            zkClient.create(ZkController.CONFIGS_ZKNODE + "/" + fileName, ouput, CreateMode.PERSISTENT, true);
        } else {
            zkClient.setData(ZkController.CONFIGS_ZKNODE + "/" + fileName, ouput, true);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.opencommercesearch.CloudSearchServer.java

License:Apache License

/**
 * Exports the given synonym list into a configuration file in ZooKeeper
 * /*from   w  w w  . j  a v  a 2 s  .c  o m*/
 * @param synonymList
 *            the synonym list's repository item
 * @throws SearchServerException
 *             if a problem occurs while writing the file in ZooKeeper
 */
protected void exportSynonymList(RepositoryItem synonymList, Locale locale)
        throws RepositoryException, SearchServerException {
    SolrZkClient client = getZkClient(locale);

    if (client != null) {
        if (isLoggingInfo()) {
            logInfo("Exporting synoymym list '" + synonymList.getItemDisplayName() + "' to ZooKeeper");
        }

        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        PrintWriter out = new PrintWriter(byteStream);

        out.println("# This file has been auto-generated. Do not modify");

        RepositoryView view = getSearchRepository().getView(SearchRepositoryItemDescriptor.SYNONYM);
        Object params[] = { new String(synonymList.getRepositoryId()) };
        RepositoryItem[] synonymMappings = getSynonymRql().executeQuery(view, params);

        if (synonymMappings != null) {
            for (RepositoryItem synonym : synonymMappings) {
                out.println((String) synonym.getPropertyValue(SynonymProperty.MAPPING));
            }
        }

        out.close();

        String environment = "preview";

        if (getCatalogCollection().endsWith("Public")) {
            environment = "public";
        }

        for (String config : Arrays.asList(getCatalogConfig(), getRulesConfig())) {
            byte[] data = byteStream.toByteArray();
            String path = new StringBuffer("/configs/").append(config).append("/synonyms-").append(environment)
                    .append("/").append(formatSynonymListFileName(
                            (String) synonymList.getPropertyValue(SynonymListProperty.FILENAME)))
                    .toString();

            try {
                if (!client.exists(path, true)) {
                    client.makePath(path, data, CreateMode.PERSISTENT, true);
                } else {
                    client.setData(path, data, true);
                }
            } catch (KeeperException ex) {
                throw create(EXPORT_SYNONYM_EXCEPTION, ex);
            } catch (InterruptedException ex) {
                throw create(EXPORT_SYNONYM_EXCEPTION, ex);
            }
        }
    }
}