Search in sources :

Example 91 with CoreContainer

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

the class ZkControllerTest method testPublishAndWaitForDownStates.

@AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/SOLR-7736")
public void testPublishAndWaitForDownStates() throws Exception {
    String zkDir = createTempDir("testPublishAndWaitForDownStates").toFile().getAbsolutePath();
    CoreContainer cc = null;
    ZkTestServer server = new ZkTestServer(zkDir);
    try {
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        cc = getCoreContainer();
        ZkController zkController = null;
        try {
            CloudConfig cloudConfig = new CloudConfig.CloudConfigBuilder("127.0.0.1", 8983, "solr").build();
            zkController = new ZkController(cc, server.getZkAddress(), TIMEOUT, cloudConfig, new CurrentCoreDescriptorProvider() {

                @Override
                public List<CoreDescriptor> getCurrentDescriptors() {
                    // do nothing
                    return null;
                }
            });
            HashMap<String, DocCollection> collectionStates = new HashMap<>();
            HashMap<String, Replica> replicas = new HashMap<>();
            // than this ZkController instance
            for (int i = 1; i <= 2; i++) {
                Replica r = new Replica("core_node" + i, map(ZkStateReader.STATE_PROP, i == 1 ? "active" : "down", ZkStateReader.NODE_NAME_PROP, i == 1 ? "127.0.0.1:8983_solr" : "non_existent_host", ZkStateReader.CORE_NAME_PROP, "collection1"));
                replicas.put("core_node" + i, r);
            }
            HashMap<String, Object> sliceProps = new HashMap<>();
            sliceProps.put("state", Slice.State.ACTIVE.toString());
            Slice slice = new Slice("shard1", replicas, sliceProps);
            DocCollection c = new DocCollection("testPublishAndWaitForDownStates", map("shard1", slice), Collections.emptyMap(), DocRouter.DEFAULT);
            ClusterState state = new ClusterState(0, Collections.emptySet(), map("testPublishAndWaitForDownStates", c));
            byte[] bytes = Utils.toJSON(state);
            zkController.getZkClient().makePath(ZkStateReader.getCollectionPath("testPublishAndWaitForDownStates"), bytes, CreateMode.PERSISTENT, true);
            zkController.getZkStateReader().forceUpdateCollection("testPublishAndWaitForDownStates");
            assertTrue(zkController.getZkStateReader().getClusterState().hasCollection("testPublishAndWaitForDownStates"));
            assertNotNull(zkController.getZkStateReader().getClusterState().getCollection("testPublishAndWaitForDownStates"));
            long now = System.nanoTime();
            long timeout = now + TimeUnit.NANOSECONDS.convert(ZkController.WAIT_DOWN_STATES_TIMEOUT_SECONDS, TimeUnit.SECONDS);
            zkController.publishAndWaitForDownStates();
            assertTrue("The ZkController.publishAndWaitForDownStates should have timed out but it didn't", System.nanoTime() >= timeout);
        } finally {
            if (zkController != null)
                zkController.close();
        }
    } finally {
        if (cc != null) {
            cc.shutdown();
        }
        server.shutdown();
    }
}
Also used : HashMap(java.util.HashMap) CoreDescriptor(org.apache.solr.core.CoreDescriptor) CloudConfig(org.apache.solr.core.CloudConfig) CoreContainer(org.apache.solr.core.CoreContainer)

Example 92 with CoreContainer

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

the class ZkControllerTest method testReadConfigName.

@Test
public void testReadConfigName() throws Exception {
    String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
    CoreContainer cc = null;
    ZkTestServer server = new ZkTestServer(zkDir);
    try {
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT);
        String actualConfigName = "firstConfig";
        zkClient.makePath(ZkConfigManager.CONFIGS_ZKNODE + "/" + actualConfigName, true);
        Map<String, Object> props = new HashMap<>();
        props.put("configName", actualConfigName);
        ZkNodeProps zkProps = new ZkNodeProps(props);
        zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION_NAME, Utils.toJSON(zkProps), CreateMode.PERSISTENT, true);
        zkClient.close();
        cc = getCoreContainer();
        CloudConfig cloudConfig = new CloudConfig.CloudConfigBuilder("127.0.0.1", 8983, "solr").build();
        ZkController zkController = new ZkController(cc, server.getZkAddress(), TIMEOUT, cloudConfig, new CurrentCoreDescriptorProvider() {

            @Override
            public List<CoreDescriptor> getCurrentDescriptors() {
                // do nothing
                return null;
            }
        });
        try {
            String configName = zkController.getZkStateReader().readConfigName(COLLECTION_NAME);
            assertEquals(configName, actualConfigName);
        } finally {
            zkController.close();
        }
    } finally {
        if (cc != null) {
            cc.shutdown();
        }
        server.shutdown();
    }
}
Also used : HashMap(java.util.HashMap) CloudConfig(org.apache.solr.core.CloudConfig) CoreContainer(org.apache.solr.core.CoreContainer) List(java.util.List) Test(org.junit.Test)

Example 93 with CoreContainer

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

the class RegisteredSolrServerTracker method addingService.

@Override
public SolrServer addingService(ServiceReference reference) {
    log.info(" ... in addingService for {} (ref: {})", this.reference, reference);
    String coreName;
    CoreContainer server;
    Object service = super.addingService(reference);
    if (service == null) {
        log.warn("addingService({}) returned null -> unable to create " + "EmbeddedSolrServer for IndexReference {}", reference, this.reference);
    }
    if (trackingSolrCore) {
        SolrCore core;
        //might not be the same as for this classloader
        if (service instanceof SolrCore) {
            core = (SolrCore) service;
        } else {
            log.warn("SolrCore fitting to IndexReference {} is incompatible to the" + "classloader of bundle [{}]{} - Service [{}] ignored!", new Object[] { reference, context.getBundle().getBundleId(), context.getBundle().getSymbolicName() }, reference.getProperty(Constants.SERVICE_ID));
            context.ungetService(reference);
            return null;
        }
        coreName = core.getName();
        CoreDescriptor descriptor = core.getCoreDescriptor();
        if (descriptor == null) {
            //core not registered with a container!
            context.ungetService(reference);
            //ignore
            return null;
        } else {
            server = descriptor.getCoreContainer();
        }
    } else {
        if (service instanceof CoreContainer) {
            server = (CoreContainer) service;
        } else {
            log.warn("Solr CoreContainer fitting to IndexReference {} is incompatible to the" + "classloader of bundle [{}]{} - Service [{}] ignored!", new Object[] { reference, context.getBundle().getBundleId(), context.getBundle().getSymbolicName() }, reference.getProperty(Constants.SERVICE_ID));
            context.ungetService(reference);
            return null;
        }
        coreName = this.coreName;
    }
    return new EmbeddedSolrServer(server, coreName);
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) SolrCore(org.apache.solr.core.SolrCore) CoreDescriptor(org.apache.solr.core.CoreDescriptor) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)

Example 94 with CoreContainer

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

the class StandaloneManagedSolrServer method initServer.

private void initServer() {
    File solrConf = new File(managedSolrDir, "solr.xml");
    if (!solrConf.exists()) {
        try {
            managedSolrDir = ConfigUtils.copyDefaultConfig((Class<?>) null, managedSolrDir, false);
        } catch (IOException e) {
            throw new IllegalStateException(String.format("Unable to copy default configuration for the manages Solr " + "Directory to the configured path '%s'!", managedSolrDir.getAbsoluteFile()), e);
        }
    }
    server = new CoreContainer(managedSolrDir.getAbsolutePath());
    //File solrXml = new File(managedSolrDir,"solr.xml");
    server.load();
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) IOException(java.io.IOException) File(java.io.File)

Example 95 with CoreContainer

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

the class SolrYardIndexingDestination method initialise.

@Override
public void initialise() {
    log.info("initialise {}", getClass().getSimpleName());
    //The constructors and the setConfiguration(..) only validate the parsed
    //parameters and initialise the member variables. This method performs 
    //the the actual initialisation of the SolrYard!
    //copy a custom configuration (if present)
    EmbeddedSolrServer server;
    IndexReference solrServerRef = IndexReference.parse(solrYardConfig.getSolrServerLocation());
    if (solrIndexConfig != null) {
        //copy the configuration
        try {
            log.info(" ... copy Solr Configuration form {} to {}", solrIndexConfig, solrIndexLocation);
            FileUtils.copyDirectory(solrIndexConfig, solrIndexLocation);
        } catch (IOException e) {
            throw new IllegalStateException(String.format("Unable to copy the Solr index configuration from %s to %s!", solrIndexConfig, solrIndexLocation), e);
        }
        solrYardConfig.setAllowInitialisation(Boolean.FALSE);
        server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(solrServerRef, solrServerRef.getIndex());
        this.core = server.getCoreContainer().getCore(solrServerRef.getIndex());
    } else {
        //allow the default initialisation
        solrYardConfig.setAllowInitialisation(Boolean.TRUE);
        StandaloneEmbeddedSolrServerProvider.getInstance();
        server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(solrServerRef, solrYardConfig.getIndexConfigurationName());
        if (server != null) {
            log.info("   ... initialised SolrCore with default configuration");
            this.core = server.getCoreContainer().getCore(solrServerRef.getIndex());
        } else if (solrServerRef.isPath() && new File(solrServerRef.getIndex()).isAbsolute()) {
            //the parsed absolute path is not within the managed SolrServer
            //so we need to create some CoreContainer and init/register
            //the core at the parsed location
            StandaloneManagedSolrServer s;
            if (solrServerRef.getServer() == null) {
                s = StandaloneManagedSolrServer.getManagedServer();
            } else {
                s = StandaloneManagedSolrServer.getManagedServer(solrServerRef.getServer());
            }
            CoreContainer cc = s.getCoreContainer();
            CoreDescriptor cd = new CoreDescriptor(cc, "dummy", solrServerRef.getIndex());
            this.core = cc.create(cd);
            cc.register(core, false);
            server = new EmbeddedSolrServer(cc, "dummy");
            log.info("   ... initialised existing SolrCore at {}", solrServerRef.getIndex());
        } else {
            throw new IllegalStateException("Unable to initialise SolrCore " + solrServerRef);
        }
    }
    log.info("   ... create SolrYard");
    this.solrYard = new SolrYard(server, solrYardConfig, namespacePrefixService);
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) CoreDescriptor(org.apache.solr.core.CoreDescriptor) StandaloneManagedSolrServer(org.apache.stanbol.commons.solr.managed.standalone.StandaloneManagedSolrServer) IOException(java.io.IOException) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer) IndexReference(org.apache.stanbol.commons.solr.IndexReference) File(java.io.File) SolrYard(org.apache.stanbol.entityhub.yard.solr.impl.SolrYard)

Aggregations

CoreContainer (org.apache.solr.core.CoreContainer)95 SolrCore (org.apache.solr.core.SolrCore)30 Test (org.junit.Test)23 SolrException (org.apache.solr.common.SolrException)16 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)14 File (java.io.File)13 HashMap (java.util.HashMap)11 Replica (org.apache.solr.common.cloud.Replica)11 CoreDescriptor (org.apache.solr.core.CoreDescriptor)11 Path (java.nio.file.Path)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)8 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)8 Map (java.util.Map)7 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)7 Properties (java.util.Properties)6 DocCollection (org.apache.solr.common.cloud.DocCollection)6 Slice (org.apache.solr.common.cloud.Slice)6 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)6