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

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

Introduction

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

Prototype

public void close() 

Source Link

Usage

From source file:com.cloudera.cdk.morphline.solr.AbstractSolrMorphlineZkTest.java

License:Apache License

private void uploadConfFiles() throws Exception {
    // upload our own config files
    SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), 10000);
    putConfig(zkClient, SOLR_CONF_DIR, "solrconfig.xml");
    putConfig(zkClient, SOLR_CONF_DIR, "schema.xml");
    putConfig(zkClient, SOLR_CONF_DIR, "elevate.xml");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_en.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_ar.txt");

    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_bg.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_ca.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_cz.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_da.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_el.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_es.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_eu.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_de.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_fa.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_fi.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_fr.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_ga.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_gl.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_hi.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_hu.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_hy.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_id.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_it.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_ja.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_lv.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_nl.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_no.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_pt.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_ro.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_ru.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_sv.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_th.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/stopwords_tr.txt");

    putConfig(zkClient, SOLR_CONF_DIR, "lang/contractions_ca.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/contractions_fr.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/contractions_ga.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "lang/contractions_it.txt");

    putConfig(zkClient, SOLR_CONF_DIR, "lang/stemdict_nl.txt");

    putConfig(zkClient, SOLR_CONF_DIR, "lang/hyphenations_ga.txt");

    putConfig(zkClient, SOLR_CONF_DIR, "stopwords.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "protwords.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "currency.xml");
    putConfig(zkClient, SOLR_CONF_DIR, "open-exchange-rates.json");
    putConfig(zkClient, SOLR_CONF_DIR, "mapping-ISOLatin1Accent.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "old_synonyms.txt");
    putConfig(zkClient, SOLR_CONF_DIR, "synonyms.txt");
    zkClient.close();
}

From source file:com.cloudera.cdk.morphline.solr.SolrLocator.java

License:Apache License

public IndexSchema getIndexSchema() {
    if (context instanceof SolrMorphlineContext) {
        IndexSchema schema = ((SolrMorphlineContext) context).getIndexSchema();
        if (schema != null) {
            validateSchema(schema);//www.j a v  a 2 s.  c o  m
            return schema;
        }
    }

    // If solrHomeDir isn't defined and zkHost and collectionName are defined 
    // then download schema.xml and solrconfig.xml, etc from zk and use that as solrHomeDir
    String mySolrHomeDir = solrHomeDir;
    if (solrHomeDir == null || solrHomeDir.length() == 0) {
        if (zkHost == null || zkHost.length() == 0) {
            // TODO: implement download from solrUrl if specified
            throw new MorphlineCompilationException(
                    "Downloading a Solr schema requires either parameter 'solrHomeDir' or parameters 'zkHost' and 'collection'",
                    config);
        }
        if (collectionName == null || collectionName.length() == 0) {
            throw new MorphlineCompilationException(
                    "Parameter 'zkHost' requires that you also pass parameter 'collection'", config);
        }
        ZooKeeperDownloader zki = new ZooKeeperDownloader();
        SolrZkClient zkClient = zki.getZkClient(zkHost);
        try {
            String configName = zki.readConfigName(zkClient, collectionName);
            File downloadedSolrHomeDir = zki.downloadConfigDir(zkClient, configName);
            mySolrHomeDir = downloadedSolrHomeDir.getAbsolutePath();
        } catch (KeeperException e) {
            throw new MorphlineCompilationException("Cannot download schema.xml from ZooKeeper", config, e);
        } catch (InterruptedException e) {
            throw new MorphlineCompilationException("Cannot download schema.xml from ZooKeeper", config, e);
        } catch (IOException e) {
            throw new MorphlineCompilationException("Cannot download schema.xml from ZooKeeper", config, e);
        } finally {
            zkClient.close();
        }
    }

    LOG.debug("SolrLocator loading IndexSchema from dir {}", mySolrHomeDir);
    try {
        SolrResourceLoader loader = new SolrResourceLoader(mySolrHomeDir);
        SolrConfig solrConfig = new SolrConfig(loader, "solrconfig.xml", null);
        InputSource is = new InputSource(loader.openSchema("schema.xml"));
        is.setSystemId(SystemIdResolver.createSystemIdFromResourceName("schema.xml"));

        IndexSchema schema = new IndexSchema(solrConfig, "schema.xml", is);
        validateSchema(schema);
        return schema;
    } catch (ParserConfigurationException e) {
        throw new MorphlineRuntimeException(e);
    } catch (IOException e) {
        throw new MorphlineRuntimeException(e);
    } catch (SAXException e) {
        throw new MorphlineRuntimeException(e);
    }
}

From source file:com.ngdata.hbaseindexer.util.solr.SolrTestingUtility.java

License:Apache License

/**
 * Utility method to upload a Solr config into ZooKeeper. If you don't have the config in the form of
 * a filesystem directory, you might want to use {@link #uploadConfig(String, byte[], byte[])}.
 *///from  w w  w .j av  a 2s.  c o m
public void uploadConfig(String confName, File confDir)
        throws InterruptedException, IOException, KeeperException {
    SolrZkClient zkClient = new SolrZkClient(zkConnectString, 30000, 30000, new OnReconnect() {
        @Override
        public void command() {
        }
    });
    ZkController.uploadConfigDir(zkClient, confDir, confName);
    zkClient.close();
}

From source file:org.kitesdk.morphline.solr.SolrLocator.java

License:Apache License

public IndexSchema getIndexSchema() {
    if (context instanceof SolrMorphlineContext) {
        IndexSchema schema = ((SolrMorphlineContext) context).getIndexSchema();
        if (schema != null) {
            validateSchema(schema);//  w w  w  .j  av a2 s .c om
            return schema;
        }
    }

    File downloadedSolrHomeDir = null;
    try {
        // If solrHomeDir isn't defined and zkHost and collectionName are defined 
        // then download schema.xml and solrconfig.xml, etc from zk and use that as solrHomeDir
        String mySolrHomeDir = solrHomeDir;
        if (solrHomeDir == null || solrHomeDir.length() == 0) {
            if (zkHost == null || zkHost.length() == 0) {
                // TODO: implement download from solrUrl if specified
                throw new MorphlineCompilationException(
                        "Downloading a Solr schema requires either parameter 'solrHomeDir' or parameters 'zkHost' and 'collection'",
                        config);
            }
            if (collectionName == null || collectionName.length() == 0) {
                throw new MorphlineCompilationException(
                        "Parameter 'zkHost' requires that you also pass parameter 'collection'", config);
            }
            ZooKeeperDownloader zki = new ZooKeeperDownloader();
            SolrZkClient zkClient = zki.getZkClient(zkHost);
            try {
                String configName = zki.readConfigName(zkClient, collectionName);
                downloadedSolrHomeDir = Files.createTempDir();
                downloadedSolrHomeDir = zki.downloadConfigDir(zkClient, configName, downloadedSolrHomeDir);
                mySolrHomeDir = downloadedSolrHomeDir.getAbsolutePath();
            } catch (KeeperException e) {
                throw new MorphlineCompilationException("Cannot download schema.xml from ZooKeeper", config, e);
            } catch (InterruptedException e) {
                throw new MorphlineCompilationException("Cannot download schema.xml from ZooKeeper", config, e);
            } catch (IOException e) {
                throw new MorphlineCompilationException("Cannot download schema.xml from ZooKeeper", config, e);
            } finally {
                zkClient.close();
            }
        }

        LOG.debug("SolrLocator loading IndexSchema from dir {}", mySolrHomeDir);
        try {
            SolrResourceLoader loader = new SolrResourceLoader(mySolrHomeDir);
            SolrConfig solrConfig = new SolrConfig(loader, "solrconfig.xml", null);

            IndexSchema schema = IndexSchemaFactory.buildIndexSchema("schema.xml", solrConfig);
            validateSchema(schema);
            return schema;
        } catch (ParserConfigurationException e) {
            throw new MorphlineRuntimeException(e);
        } catch (IOException e) {
            throw new MorphlineRuntimeException(e);
        } catch (SAXException e) {
            throw new MorphlineRuntimeException(e);
        }
    } finally {
        if (downloadedSolrHomeDir != null) {
            try {
                FileUtils.deleteDirectory(downloadedSolrHomeDir);
            } catch (IOException e) {
                LOG.warn("Cannot delete tmp directory", e);
            }
        }
    }
}

From source file:uk.bl.wa.apache.solr.hadoop.ZooKeeperInspector.java

License:Apache License

public DocCollection extractDocCollection(String zkHost, String collection) {
    if (collection == null) {
        throw new IllegalArgumentException("collection must not be null");
    }/*from  w  w  w. j a va 2  s . co m*/
    SolrZkClient zkClient = getZkClient(zkHost);

    try {
        ZkStateReader zkStateReader = new ZkStateReader(zkClient);
        try {
            // first check for alias
            collection = checkForAlias(zkClient, collection);
            zkStateReader.createClusterStateWatchersAndUpdate();
        } catch (Exception e) {
            throw new IllegalArgumentException(
                    "Cannot find expected information for SolrCloud in ZooKeeper: " + zkHost, e);
        }

        try {
            return zkStateReader.getClusterState().getCollection(collection);
        } catch (SolrException e) {
            throw new IllegalArgumentException(
                    "Cannot find collection '" + collection + "' in ZooKeeper: " + zkHost, e);
        }
    } finally {
        zkClient.close();
    }
}