Example usage for org.apache.solr.util SystemIdResolver createSystemIdFromResourceName

List of usage examples for org.apache.solr.util SystemIdResolver createSystemIdFromResourceName

Introduction

In this page you can find the example usage for org.apache.solr.util SystemIdResolver createSystemIdFromResourceName.

Prototype

public static String createSystemIdFromResourceName(String name) 

Source Link

Usage

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);//from  w  w w  .  j a  va  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.sindicetech.siren.solr.schema.SirenDatatypeAnalyzerConfig.java

License:Open Source License

/**
 * Constructs a config using the specified resource name and stream.
 * If the is stream is null, the resource loader will load the resource
 * by name.//from  ww w.j  av a2 s . c o m
 * @see SolrResourceLoader#openConfig
 * By default, this follows the normal config path directory searching rules.
 * @see SolrResourceLoader#openResource
 */
public SirenDatatypeAnalyzerConfig(final SolrResourceLoader loader, final String name, InputSource is,
        final Version luceneMatchVersion) {
    this.luceneMatchVersion = luceneMatchVersion;
    this.resourceName = name;
    this.loader = loader;

    try {
        if (is == null) {
            is = new InputSource(loader.openResource(name));
            is.setSystemId(SystemIdResolver.createSystemIdFromResourceName(name));
        }
        this.readConfig(is);
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}