Search in sources :

Example 1 with ZkSolrResourceLoader

use of org.apache.solr.cloud.ZkSolrResourceLoader in project lucene-solr by apache.

the class ConfigSetService method getConfig.

/**
   * Load the ConfigSet for a core
   * @param dcore the core's CoreDescriptor
   * @return a ConfigSet
   */
public final ConfigSet getConfig(CoreDescriptor dcore) {
    SolrResourceLoader coreLoader = createCoreResourceLoader(dcore);
    try {
        // ConfigSet properties are loaded from ConfigSetProperties.DEFAULT_FILENAME file.
        // ConfigSet flags are loaded from the metadata of the ZK node of the configset.
        NamedList properties = createConfigSetProperties(dcore, coreLoader);
        NamedList flags = getConfigSetFlags(dcore, coreLoader);
        boolean trusted = (coreLoader instanceof ZkSolrResourceLoader && flags != null && flags.get("trusted") != null && !flags.getBooleanArg("trusted")) ? false : true;
        SolrConfig solrConfig = createSolrConfig(dcore, coreLoader);
        IndexSchema schema = createIndexSchema(dcore, solrConfig);
        return new ConfigSet(configName(dcore), solrConfig, schema, properties, trusted);
    } catch (Exception e) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not load conf for core " + dcore.getName() + ": " + e.getMessage(), e);
    }
}
Also used : ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) NamedList(org.apache.solr.common.util.NamedList) IndexSchema(org.apache.solr.schema.IndexSchema) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SolrException(org.apache.solr.common.SolrException) SolrException(org.apache.solr.common.SolrException)

Example 2 with ZkSolrResourceLoader

use of org.apache.solr.cloud.ZkSolrResourceLoader in project lucene-solr by apache.

the class ShowFileRequestHandler method getAdminFileFromZooKeeper.

// Refactored to be usable from multiple methods. Gets the path of the requested file from ZK.
// Returns null if the file is not found.
//
// Assumes that the file is in a parameter called "file".
public static String getAdminFileFromZooKeeper(SolrQueryRequest req, SolrQueryResponse rsp, SolrZkClient zkClient, Set<String> hiddenFiles) throws KeeperException, InterruptedException {
    String adminFile = null;
    SolrCore core = req.getCore();
    final ZkSolrResourceLoader loader = (ZkSolrResourceLoader) core.getResourceLoader();
    String confPath = loader.getConfigSetZkPath();
    String fname = req.getParams().get("file", null);
    if (fname == null) {
        adminFile = confPath;
    } else {
        // normalize slashes
        fname = fname.replace('\\', '/');
        if (isHiddenFile(req, rsp, fname, true, hiddenFiles)) {
            return null;
        }
        if (fname.startsWith("/")) {
            // Only files relative to conf are valid
            fname = fname.substring(1);
        }
        adminFile = confPath + "/" + fname;
    }
    // Make sure the file exists, is readable and is not a hidden file
    if (!zkClient.exists(adminFile, true)) {
        log.error("Can not find: " + adminFile);
        rsp.setException(new SolrException(SolrException.ErrorCode.NOT_FOUND, "Can not find: " + adminFile));
        return null;
    }
    return adminFile;
}
Also used : SolrCore(org.apache.solr.core.SolrCore) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) SolrException(org.apache.solr.common.SolrException)

Example 3 with ZkSolrResourceLoader

use of org.apache.solr.cloud.ZkSolrResourceLoader in project lucene-solr by apache.

the class ManagedIndexSchemaFactory method warnIfNonManagedSchemaExists.

/**
   * Return whether a non-managed schema exists, either in local storage or on ZooKeeper. 
   */
private void warnIfNonManagedSchemaExists() {
    if (!resourceName.equals(managedSchemaResourceName)) {
        boolean exists = false;
        SolrResourceLoader loader = config.getResourceLoader();
        if (loader instanceof ZkSolrResourceLoader) {
            ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader) loader;
            String nonManagedSchemaPath = zkLoader.getConfigSetZkPath() + "/" + resourceName;
            try {
                exists = zkLoader.getZkController().pathExists(nonManagedSchemaPath);
            } catch (InterruptedException e) {
                // Restore the interrupted status
                Thread.currentThread().interrupt();
                // Log as warning and suppress the exception 
                log.warn("", e);
            } catch (KeeperException e) {
                // log as warning and suppress the exception
                log.warn("Error checking for the existence of the non-managed schema " + resourceName, e);
            }
        } else {
            // Config is not in ZooKeeper
            InputStream nonManagedSchemaInputStream = null;
            try {
                nonManagedSchemaInputStream = loader.openSchema(resourceName);
                if (null != nonManagedSchemaInputStream) {
                    exists = true;
                }
            } catch (IOException e) {
            // This is expected when the non-managed schema does not exist
            } finally {
                IOUtils.closeQuietly(nonManagedSchemaInputStream);
            }
        }
        if (exists) {
            log.warn("The schema has been upgraded to managed, but the non-managed schema " + resourceName + " is still loadable.  PLEASE REMOVE THIS FILE.");
        }
    }
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 4 with ZkSolrResourceLoader

use of org.apache.solr.cloud.ZkSolrResourceLoader in project lucene-solr by apache.

the class RequestParams method getFreshRequestParams.

public static RequestParams getFreshRequestParams(SolrResourceLoader loader, RequestParams requestParams) {
    if (loader instanceof ZkSolrResourceLoader) {
        ZkSolrResourceLoader resourceLoader = (ZkSolrResourceLoader) loader;
        try {
            Stat stat = resourceLoader.getZkController().getZkClient().exists(resourceLoader.getConfigSetZkPath() + "/" + RequestParams.RESOURCE, null, true);
            log.debug("latest version of {} in ZK  is : {}", resourceLoader.getConfigSetZkPath() + "/" + RequestParams.RESOURCE, stat == null ? "" : stat.getVersion());
            if (stat == null) {
                requestParams = new RequestParams(Collections.EMPTY_MAP, -1);
            } else if (requestParams == null || stat.getVersion() > requestParams.getZnodeVersion()) {
                Object[] o = getMapAndVersion(loader, RequestParams.RESOURCE);
                requestParams = new RequestParams((Map) o[0], (Integer) o[1]);
                log.info("request params refreshed to version {}", requestParams.getZnodeVersion());
            }
        } catch (KeeperException | InterruptedException e) {
            SolrZkClient.checkInterrupted(e);
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
        }
    } else {
        Object[] o = getMapAndVersion(loader, RequestParams.RESOURCE);
        requestParams = new RequestParams((Map) o[0], (Integer) o[1]);
    }
    return requestParams;
}
Also used : Stat(org.apache.zookeeper.data.Stat) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) KeeperException(org.apache.zookeeper.KeeperException) SolrException(org.apache.solr.common.SolrException)

Example 5 with ZkSolrResourceLoader

use of org.apache.solr.cloud.ZkSolrResourceLoader in project lucene-solr by apache.

the class SchemaManager method getFreshManagedSchema.

public static ManagedIndexSchema getFreshManagedSchema(SolrCore core) throws IOException, KeeperException, InterruptedException {
    SolrResourceLoader resourceLoader = core.getResourceLoader();
    String name = core.getLatestSchema().getResourceName();
    if (resourceLoader instanceof ZkSolrResourceLoader) {
        InputStream in = resourceLoader.openResource(name);
        if (in instanceof ZkSolrResourceLoader.ZkByteArrayInputStream) {
            int version = ((ZkSolrResourceLoader.ZkByteArrayInputStream) in).getStat().getVersion();
            log.info("managed schema loaded . version : {} ", version);
            return new ManagedIndexSchema(core.getSolrConfig(), name, new InputSource(in), true, name, version, core.getLatestSchema().getSchemaUpdateLock());
        } else {
            return (ManagedIndexSchema) core.getLatestSchema();
        }
    } else {
        return (ManagedIndexSchema) core.getLatestSchema();
    }
}
Also used : ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader)

Aggregations

ZkSolrResourceLoader (org.apache.solr.cloud.ZkSolrResourceLoader)14 SolrException (org.apache.solr.common.SolrException)11 IOException (java.io.IOException)8 KeeperException (org.apache.zookeeper.KeeperException)6 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)4 File (java.io.File)3 InputStream (java.io.InputStream)3 ZkController (org.apache.solr.cloud.ZkController)3 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)3 Stat (org.apache.zookeeper.data.Stat)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StringWriter (java.io.StringWriter)2 ExecutionException (java.util.concurrent.ExecutionException)2 SolrCore (org.apache.solr.core.SolrCore)2 InputSource (org.xml.sax.InputSource)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Collections.singletonList (java.util.Collections.singletonList)1