Search in sources :

Example 21 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.

the class PrimitiveFieldTypeTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    // set some system properties for use by tests
    // schema12 doesn't support _version_
    System.setProperty("enable.update.log", "false");
    System.setProperty("solr.test.sys.prop1", "propone");
    System.setProperty("solr.test.sys.prop2", "proptwo");
    System.setProperty("solr.allow.unsafe.resourceloading", "true");
    initMap = new HashMap<>();
    config = new SolrConfig(new SolrResourceLoader(TEST_PATH().resolve("collection1")), testConfHome + "solrconfig.xml", null);
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) SolrConfig(org.apache.solr.core.SolrConfig)

Example 22 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.

the class TestSystemIdResolver method testResolving.

public void testResolving() throws Exception {
    final Path testHome = SolrTestCaseJ4.getFile("solr/collection1").getParentFile().toPath();
    final ResourceLoader loader = new SolrResourceLoader(testHome.resolve("collection1"), this.getClass().getClassLoader());
    final SystemIdResolver resolver = new SystemIdResolver(loader);
    final String fileUri = new File(testHome + "/crazy-path-to-config.xml").toURI().toASCIIString();
    assertEquals("solrres:/test.xml", SystemIdResolver.createSystemIdFromResourceName("test.xml"));
    assertEquals("solrres://@/usr/local/etc/test.xml", SystemIdResolver.createSystemIdFromResourceName("/usr/local/etc/test.xml"));
    assertEquals("solrres://@/test.xml", SystemIdResolver.createSystemIdFromResourceName(File.separatorChar + "test.xml"));
    // check relative URI resolving
    assertEquals("solrres:/test.xml", resolver.resolveRelativeURI("solrres:/base.xml", "test.xml").toASCIIString());
    assertEquals("solrres://@/etc/test.xml", resolver.resolveRelativeURI("solrres://@/usr/local/etc/base.xml", "../../../etc/test.xml").toASCIIString());
    // special case: if relative URI starts with "/" convert to an absolute solrres://@/-URI
    assertEquals("solrres://@/a/test.xml", resolver.resolveRelativeURI("solrres:/base.xml", "/a/test.xml").toASCIIString());
    // test, that resolving works if somebody uses an absolute file:-URI in a href attribute, it should be preserved
    assertEquals(fileUri, resolver.resolveRelativeURI("solrres:/base.xml", fileUri).toASCIIString());
    assertEquals("solrres:/base.xml", resolver.resolveRelativeURI(fileUri, "solrres:/base.xml").toASCIIString());
    // do some real resolves to InputStreams with real existing files
    assertEntityResolving(resolver, "solrres:/schema.xml", "solrres:/solrconfig.xml", "schema.xml");
    assertEntityResolving(resolver, "solrres:/org/apache/solr/util/TestSystemIdResolver.class", "solrres:/org/apache/solr/util/RTimer.class", "TestSystemIdResolver.class");
    assertEntityResolving(resolver, SystemIdResolver.createSystemIdFromResourceName(testHome + "/collection1/conf/schema.xml"), SystemIdResolver.createSystemIdFromResourceName(testHome + "/collection1/conf/solrconfig.xml"), "schema.xml");
    assertEntityResolving(resolver, SystemIdResolver.createSystemIdFromResourceName(testHome + "/crazy-path-to-schema.xml"), SystemIdResolver.createSystemIdFromResourceName(testHome + "/crazy-path-to-config.xml"), "crazy-path-to-schema.xml");
    // test, that resolving works if somebody uses an absolute file:-URI in a href attribute, the resolver should return null (default fallback)
    assertNull(resolver.resolveEntity(null, null, "solrres:/solrconfig.xml", fileUri));
}
Also used : Path(java.nio.file.Path) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) ResourceLoader(org.apache.lucene.analysis.util.ResourceLoader) File(java.io.File)

Example 23 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.

the class SolrGraphiteReporterTest method testReporter.

@Test
public void testReporter() throws Exception {
    int jmxReporter = JmxUtil.findFirstMBeanServer() != null ? 1 : 0;
    Path home = Paths.get(TEST_HOME());
    // define these properties, they are used in solrconfig.xml
    System.setProperty("solr.test.sys.prop1", "propone");
    System.setProperty("solr.test.sys.prop2", "proptwo");
    MockGraphite mock = new MockGraphite();
    try {
        mock.start();
        Thread.sleep(1000);
        // define the port where MockGraphite is running
        System.setProperty("mock-graphite-port", String.valueOf(mock.port));
        String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-graphitereporter.xml").toFile(), "UTF-8");
        NodeConfig cfg = SolrXmlConfig.fromString(new SolrResourceLoader(home), solrXml);
        CoreContainer cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator(DEFAULT_TEST_CORENAME, initCoreDataDir.getAbsolutePath(), "solrconfig.xml", "schema.xml"));
        h.coreName = DEFAULT_TEST_CORENAME;
        SolrMetricManager metricManager = cc.getMetricManager();
        Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.node");
        assertEquals(1 + jmxReporter, reporters.size());
        SolrMetricReporter reporter = reporters.get("test");
        assertNotNull(reporter);
        assertTrue(reporter instanceof SolrGraphiteReporter);
        Thread.sleep(5000);
        assertTrue(mock.lines.size() >= 3);
        String[] frozenLines = (String[]) mock.lines.toArray(new String[mock.lines.size()]);
        for (String line : frozenLines) {
            assertTrue(line, line.startsWith("test.solr.node.CONTAINER.cores."));
        }
    } finally {
        mock.close();
    }
}
Also used : Path(java.nio.file.Path) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CoreContainer(org.apache.solr.core.CoreContainer) TestHarness(org.apache.solr.util.TestHarness) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) NodeConfig(org.apache.solr.core.NodeConfig) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) Test(org.junit.Test)

Example 24 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader in project SearchServices by Alfresco.

the class SolrCoreLoadRegistration method registerForCore.

/**
 * Registers with the admin handler the information server and the trackers.
 */
public static void registerForCore(AlfrescoCoreAdminHandler adminHandler, CoreContainer coreContainer, SolrCore core, String coreName) {
    TrackerRegistry trackerRegistry = adminHandler.getTrackerRegistry();
    Properties props = new CoreDescriptorDecorator(core.getCoreDescriptor()).getProperties();
    if (Boolean.parseBoolean(props.getProperty("enable.alfresco.tracking", "false"))) {
        SolrTrackerScheduler scheduler = adminHandler.getScheduler();
        SolrResourceLoader loader = core.getLatestSchema().getResourceLoader();
        SolrKeyResourceLoader keyResourceLoader = new SolrKeyResourceLoader(loader);
        if (trackerRegistry.hasTrackersForCore(coreName)) {
            log.info("Trackers for " + coreName + " is already registered, shutting them down.");
            shutdownTrackers(coreName, trackerRegistry.getTrackersForCore(coreName), scheduler);
            trackerRegistry.removeTrackersForCore(coreName);
            adminHandler.getInformationServers().remove(coreName);
        }
        SOLRAPIClientFactory clientFactory = new SOLRAPIClientFactory();
        SOLRAPIClient repositoryClient = clientFactory.getSOLRAPIClient(props, keyResourceLoader, AlfrescoSolrDataModel.getInstance().getDictionaryService(CMISStrictDictionaryService.DEFAULT), AlfrescoSolrDataModel.getInstance().getNamespaceDAO());
        // Start content store
        SolrContentStore contentStore = new SolrContentStore(coreContainer.getSolrHome());
        SolrInformationServer srv = new SolrInformationServer(adminHandler, core, repositoryClient, contentStore);
        props.putAll(srv.getProps());
        adminHandler.getInformationServers().put(coreName, srv);
        log.info("Starting to track " + coreName);
        ModelTracker mTracker = null;
        // Prevents other threads from registering the ModelTracker at the same time
        synchronized (trackerRegistry) {
            mTracker = trackerRegistry.getModelTracker();
            if (mTracker == null) {
                log.debug("Creating ModelTracker when registering trackers for core " + coreName);
                mTracker = new ModelTracker(coreContainer.getSolrHome(), props, repositoryClient, coreName, srv);
                trackerRegistry.setModelTracker(mTracker);
                log.info("Ensuring first model sync.");
                mTracker.ensureFirstModelSync();
                log.info("Done ensuring first model sync.");
                // Scheduling the ModelTracker.
                scheduler.schedule(mTracker, coreName, props);
            }
        }
        List<Tracker> trackers = createTrackers(coreName, trackerRegistry, props, scheduler, repositoryClient, srv);
        CommitTracker commitTracker = new CommitTracker(props, repositoryClient, coreName, srv, trackers);
        trackerRegistry.register(coreName, commitTracker);
        scheduler.schedule(commitTracker, coreName, props);
        log.info("The Trackers are now scheduled to run");
        // Add the commitTracker to the list of scheduled trackers that can be shutdown
        trackers.add(commitTracker);
        core.addCloseHook(new CloseHook() {

            @Override
            public void preClose(SolrCore core) {
                log.info("Shutting down " + core.getName());
                SolrCoreLoadRegistration.shutdownTrackers(core.getName(), trackers, scheduler);
            }

            @Override
            public void postClose(SolrCore core) {
            }
        });
    }
}
Also used : ContentTracker(org.alfresco.solr.tracker.ContentTracker) Tracker(org.alfresco.solr.tracker.Tracker) MetadataTracker(org.alfresco.solr.tracker.MetadataTracker) CommitTracker(org.alfresco.solr.tracker.CommitTracker) CascadeTracker(org.alfresco.solr.tracker.CascadeTracker) AclTracker(org.alfresco.solr.tracker.AclTracker) ModelTracker(org.alfresco.solr.tracker.ModelTracker) SolrContentStore(org.alfresco.solr.content.SolrContentStore) SolrCore(org.apache.solr.core.SolrCore) CommitTracker(org.alfresco.solr.tracker.CommitTracker) Properties(java.util.Properties) TrackerRegistry(org.alfresco.solr.tracker.TrackerRegistry) SolrInformationServer(org.alfresco.solr.SolrInformationServer) ModelTracker(org.alfresco.solr.tracker.ModelTracker) CoreDescriptorDecorator(org.apache.solr.core.CoreDescriptorDecorator) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CloseHook(org.apache.solr.core.CloseHook) SOLRAPIClientFactory(org.alfresco.solr.client.SOLRAPIClientFactory) SOLRAPIClient(org.alfresco.solr.client.SOLRAPIClient) SolrTrackerScheduler(org.alfresco.solr.tracker.SolrTrackerScheduler) SolrKeyResourceLoader(org.alfresco.solr.SolrKeyResourceLoader)

Example 25 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader in project stanbol by apache.

the class EmbeddedSolrHelper method makeEmbeddedSolrServer.

/**
 * Create a single core Solr server with it's own folder hierarchy.
 */
public static EmbeddedSolrServer makeEmbeddedSolrServer(File rootFolder, String solrServerId, String coreId, String configName) throws IOException, ParserConfigurationException, SAXException {
    File solrFolder = new File(rootFolder, solrServerId);
    FileUtils.deleteQuietly(solrFolder);
    solrFolder.mkdir();
    // solr conf file
    File solrFile = new File(solrFolder, "solr.xml");
    InputStream is = EmbeddedSolrHelper.class.getResourceAsStream("/solr.xml");
    if (is == null) {
        throw new IllegalArgumentException("missing test solr.xml file");
    }
    IOUtils.copy(is, new FileOutputStream(solrFile));
    // solr conf folder with schema
    File solrCoreFolder = new File(solrFolder, coreId);
    solrCoreFolder.mkdir();
    File solrConfFolder = new File(solrCoreFolder, "conf");
    solrConfFolder.mkdir();
    File schemaFile = new File(solrConfFolder, "schema.xml");
    is = EmbeddedSolrHelper.class.getResourceAsStream("/" + configName + "/conf/schema.xml");
    if (is == null) {
        throw new IllegalArgumentException("missing test schema.xml file");
    }
    IOUtils.copy(is, new FileOutputStream(schemaFile));
    File solrConfigFile = new File(solrConfFolder, "solrconfig.xml");
    is = EmbeddedSolrHelper.class.getResourceAsStream("/" + configName + "/conf/solrconfig.xml");
    if (is == null) {
        throw new IllegalArgumentException("missing test solrconfig.xml file");
    }
    IOUtils.copy(is, new FileOutputStream(solrConfigFile));
    // create the embedded server
    SolrResourceLoader loader = new SolrResourceLoader(solrFolder.getAbsolutePath());
    CoreContainer coreContainer = new CoreContainer(loader);
    // NOTE: with Solr 4.4 we need to call coreContainer.load() otherwise we
    // would be affected by the issue stated at
    // http://mail-archives.apache.org/mod_mbox/lucene-solr-user/201301.mbox/%3CB7B8B36F1A0BE24F842758C318E56E925EB334%40EXCHDB2.na1.ad.group%3E
    // while this was introduced with 4.1 this only affects this code with 4.4
    // as with an API change the methods implicitly calling load() where
    // removed.
    coreContainer.load();
    CoreDescriptor coreDescriptor = new CoreDescriptor(coreContainer, coreId, solrCoreFolder.getAbsolutePath());
    SolrCore core = coreContainer.create(coreDescriptor);
    // coreContainer.createAndLoad(solrHome, configFile)load();
    coreContainer.register(coreId, core, true);
    return new EmbeddedSolrServer(coreContainer, coreId);
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CoreContainer(org.apache.solr.core.CoreContainer) InputStream(java.io.InputStream) CoreDescriptor(org.apache.solr.core.CoreDescriptor) SolrCore(org.apache.solr.core.SolrCore) FileOutputStream(java.io.FileOutputStream) File(java.io.File) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)

Aggregations

SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)54 Test (org.junit.Test)18 File (java.io.File)11 InputStream (java.io.InputStream)11 NamedList (org.apache.solr.common.util.NamedList)10 SolrException (org.apache.solr.common.SolrException)9 NodeConfig (org.apache.solr.core.NodeConfig)9 Path (java.nio.file.Path)8 CoreContainer (org.apache.solr.core.CoreContainer)8 InputStreamReader (java.io.InputStreamReader)7 Reader (java.io.Reader)7 Map (java.util.Map)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 XMLResponseParser (org.apache.solr.client.solrj.impl.XMLResponseParser)5 SolrCore (org.apache.solr.core.SolrCore)5 ArrayList (java.util.ArrayList)4 ZkSolrResourceLoader (org.apache.solr.cloud.ZkSolrResourceLoader)4 SolrConfig (org.apache.solr.core.SolrConfig)4