use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class TestEmbeddedSolrServerConstructors method testNodeConfigConstructor.
@Test
public void testNodeConfigConstructor() throws Exception {
Path path = createTempDir();
SolrResourceLoader loader = new SolrResourceLoader(path);
NodeConfig config = new NodeConfig.NodeConfigBuilder("testnode", loader).setConfigSetBaseDirectory(Paths.get(TEST_HOME()).resolve("configsets").toString()).build();
try (EmbeddedSolrServer server = new EmbeddedSolrServer(config, "newcore")) {
CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create();
createRequest.setCoreName("newcore");
createRequest.setConfigSet("minimal");
server.request(createRequest);
SolrInputDocument doc = new SolrInputDocument();
doc.addField("articleid", "test");
server.add("newcore", doc);
server.commit();
assertEquals(1, server.query(new SolrQuery("*:*")).getResults().getNumFound());
assertEquals(1, server.query("newcore", new SolrQuery("*:*")).getResults().getNumFound());
}
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class DataImportHandler method handleRequestBody.
@Override
@SuppressWarnings("unchecked")
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
rsp.setHttpCaching(false);
//TODO: figure out why just the first one is OK...
ContentStream contentStream = null;
Iterable<ContentStream> streams = req.getContentStreams();
if (streams != null) {
for (ContentStream stream : streams) {
contentStream = stream;
break;
}
}
SolrParams params = req.getParams();
NamedList defaultParams = (NamedList) initArgs.get("defaults");
RequestInfo requestParams = new RequestInfo(req, getParamsMap(params), contentStream);
String command = requestParams.getCommand();
if (DataImporter.SHOW_CONF_CMD.equals(command)) {
String dataConfigFile = params.get("config");
String dataConfig = params.get("dataConfig");
if (dataConfigFile != null) {
dataConfig = SolrWriter.getResourceAsString(req.getCore().getResourceLoader().openResource(dataConfigFile));
}
if (dataConfig == null) {
rsp.add("status", DataImporter.MSG.NO_CONFIG_FOUND);
} else {
// Modify incoming request params to add wt=raw
ModifiableSolrParams rawParams = new ModifiableSolrParams(req.getParams());
rawParams.set(CommonParams.WT, "raw");
req.setParams(rawParams);
ContentStreamBase content = new ContentStreamBase.StringStream(dataConfig);
rsp.add(RawResponseWriter.CONTENT, content);
}
return;
}
rsp.add("initArgs", initArgs);
String message = "";
if (command != null) {
rsp.add("command", command);
}
// If importer is still null
if (importer == null) {
rsp.add("status", DataImporter.MSG.NO_INIT);
return;
}
if (command != null && DataImporter.ABORT_CMD.equals(command)) {
importer.runCmd(requestParams, null);
} else if (importer.isBusy()) {
message = DataImporter.MSG.CMD_RUNNING;
} else if (command != null) {
if (DataImporter.FULL_IMPORT_CMD.equals(command) || DataImporter.DELTA_IMPORT_CMD.equals(command) || IMPORT_CMD.equals(command)) {
importer.maybeReloadConfiguration(requestParams, defaultParams);
UpdateRequestProcessorChain processorChain = req.getCore().getUpdateProcessorChain(params);
UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp);
SolrResourceLoader loader = req.getCore().getResourceLoader();
DIHWriter sw = getSolrWriter(processor, loader, requestParams, req);
if (requestParams.isDebug()) {
if (debugEnabled) {
// Synchronous request for the debug mode
importer.runCmd(requestParams, sw);
rsp.add("mode", "debug");
rsp.add("documents", requestParams.getDebugInfo().debugDocuments);
if (requestParams.getDebugInfo().debugVerboseOutput != null) {
rsp.add("verbose-output", requestParams.getDebugInfo().debugVerboseOutput);
}
} else {
message = DataImporter.MSG.DEBUG_NOT_ENABLED;
}
} else {
// Asynchronous request for normal mode
if (requestParams.getContentStream() == null && !requestParams.isSyncMode()) {
importer.runAsync(requestParams, sw);
} else {
importer.runCmd(requestParams, sw);
}
}
} else if (DataImporter.RELOAD_CONF_CMD.equals(command)) {
if (importer.maybeReloadConfiguration(requestParams, defaultParams)) {
message = DataImporter.MSG.CONFIG_RELOADED;
} else {
message = DataImporter.MSG.CONFIG_NOT_RELOADED;
}
}
}
rsp.add("status", importer.isBusy() ? "busy" : "idle");
rsp.add("importResponse", message);
rsp.add("statusMessages", importer.getStatusMessages());
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class BaseManagedTokenFilterFactory method inform.
/**
* Registers an endpoint with the RestManager so that this component can be
* managed using the REST API. This method can be invoked before all the
* resources the {@link org.apache.solr.rest.RestManager} needs to initialize
* a {@link ManagedResource} are available, so this simply registers the need
* to be managed at a specific endpoint and lets the RestManager deal with
* initialization when ready.
*/
@Override
public void inform(ResourceLoader loader) throws IOException {
SolrResourceLoader solrResourceLoader = (SolrResourceLoader) loader;
// here we want to register that we need to be managed
// at a specified path and the ManagedResource impl class
// that should be used to manage this component
solrResourceLoader.getManagedResourceRegistry().registerManagedResource(getResourceId(), getManagedResourceImplClass(), this);
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class ParseContextConfigTest method testAll.
public void testAll() throws Exception {
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element entries = document.createElement("entries");
Element entry = document.createElement("entry");
entry.setAttribute("class", "org.apache.tika.parser.pdf.PDFParserConfig");
entry.setAttribute("impl", "org.apache.tika.parser.pdf.PDFParserConfig");
Element property = document.createElement("property");
property.setAttribute("name", "extractInlineImages");
property.setAttribute("value", "true");
entry.appendChild(property);
entries.appendChild(entry);
ParseContext parseContext = new ParseContextConfig(new SolrResourceLoader(Paths.get(".")), entries).create();
PDFParserConfig pdfParserConfig = parseContext.get(PDFParserConfig.class);
assertEquals(true, pdfParserConfig.getExtractInlineImages());
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class ShowFileRequestHandler method getAdminFileFromFileSystem.
// Find the file indicated by the "file=XXX" parameter or the root of the conf directory on the local
// file system. Respects all the "interesting" stuff around what the resource loader does to find files.
public static File getAdminFileFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp, Set<String> hiddenFiles) {
File adminFile = null;
final SolrResourceLoader loader = req.getCore().getResourceLoader();
File configdir = new File(loader.getConfigDir());
if (!configdir.exists()) {
// TODO: maybe we should just open it this way to start with?
try {
configdir = new File(loader.getClassLoader().getResource(loader.getConfigDir()).toURI());
} catch (URISyntaxException e) {
log.error("Can not access configuration directory!");
rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN, "Can not access configuration directory!", e));
return null;
}
}
String fname = req.getParams().get("file", null);
if (fname == null) {
adminFile = configdir;
} else {
// normalize slashes
fname = fname.replace('\\', '/');
if (hiddenFiles.contains(fname.toUpperCase(Locale.ROOT))) {
log.error("Can not access: " + fname);
rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN, "Can not access: " + fname));
return null;
}
if (fname.indexOf("..") >= 0) {
log.error("Invalid path: " + fname);
rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN, "Invalid path: " + fname));
return null;
}
adminFile = new File(configdir, fname);
}
return adminFile;
}
Aggregations