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);
}
}
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;
}
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.");
}
}
}
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;
}
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();
}
}
Aggregations