Search in sources :

Example 36 with CoreContainer

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

the class TestRandomRequestDistribution method testRequestTracking.

/**
   * Asserts that requests aren't always sent to the same poor node. See SOLR-7493
   */
private void testRequestTracking() throws Exception {
    CollectionAdminRequest.createCollection("a1x2", 1, 2).setCreateNodeSet(nodeNames.get(0) + ',' + nodeNames.get(1)).process(cloudClient);
    CollectionAdminRequest.createCollection("b1x1", 1, 1).setCreateNodeSet(nodeNames.get(2)).process(cloudClient);
    waitForRecoveriesToFinish("a1x2", true);
    waitForRecoveriesToFinish("b1x1", true);
    cloudClient.getZkStateReader().forceUpdateCollection("b1x1");
    ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
    DocCollection b1x1 = clusterState.getCollection("b1x1");
    Collection<Replica> replicas = b1x1.getSlice("shard1").getReplicas();
    assertEquals(1, replicas.size());
    String baseUrl = replicas.iterator().next().getStr(ZkStateReader.BASE_URL_PROP);
    if (!baseUrl.endsWith("/"))
        baseUrl += "/";
    try (HttpSolrClient client = getHttpSolrClient(baseUrl + "a1x2")) {
        client.setSoTimeout(5000);
        client.setConnectionTimeout(2000);
        log.info("Making requests to " + baseUrl + "a1x2");
        for (int i = 0; i < 10; i++) {
            client.query(new SolrQuery("*:*"));
        }
    }
    Map<String, Integer> shardVsCount = new HashMap<>();
    for (JettySolrRunner runner : jettys) {
        CoreContainer container = runner.getCoreContainer();
        SolrMetricManager metricManager = container.getMetricManager();
        for (SolrCore core : container.getCores()) {
            String registry = core.getCoreMetricManager().getRegistryName();
            Counter cnt = metricManager.counter(null, registry, "requests", "QUERY.standard");
            SolrRequestHandler select = core.getRequestHandler("");
            //        long c = (long) select.getStatistics().get("requests");
            shardVsCount.put(core.getName(), (int) cnt.getCount());
        }
    }
    log.info("Shard count map = " + shardVsCount);
    for (Map.Entry<String, Integer> entry : shardVsCount.entrySet()) {
        assertTrue("Shard " + entry.getKey() + " received all 10 requests", entry.getValue() != 10);
    }
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) HashMap(java.util.HashMap) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) SolrCore(org.apache.solr.core.SolrCore) Replica(org.apache.solr.common.cloud.Replica) SolrQuery(org.apache.solr.client.solrj.SolrQuery) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Counter(com.codahale.metrics.Counter) CoreContainer(org.apache.solr.core.CoreContainer) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) DocCollection(org.apache.solr.common.cloud.DocCollection) HashMap(java.util.HashMap) Map(java.util.Map) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler)

Example 37 with CoreContainer

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

the class TestManagedSchema method assertSchemaResource.

private void assertSchemaResource(String collection, String expectedSchemaResource) throws Exception {
    final CoreContainer cores = h.getCoreContainer();
    final CoreAdminHandler admin = new CoreAdminHandler(cores);
    SolrQueryRequest request = req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.STATUS.toString());
    SolrQueryResponse response = new SolrQueryResponse();
    admin.handleRequestBody(request, response);
    assertNull("Exception on create", response.getException());
    NamedList responseValues = response.getValues();
    NamedList status = (NamedList) responseValues.get("status");
    NamedList collectionStatus = (NamedList) status.get(collection);
    String collectionSchema = (String) collectionStatus.get(CoreAdminParams.SCHEMA);
    assertEquals("Schema resource name differs from expected name", expectedSchemaResource, collectionSchema);
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) CoreContainer(org.apache.solr.core.CoreContainer) NamedList(org.apache.solr.common.util.NamedList) CoreAdminHandler(org.apache.solr.handler.admin.CoreAdminHandler)

Example 38 with CoreContainer

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

the class TestManagedSchema method testDefaultSchemaFactory.

public void testDefaultSchemaFactory() throws Exception {
    deleteCore();
    initCore("solrconfig-managed-schema-test.xml", "schema-minimal.xml", tmpSolrHome.getPath());
    final CoreContainer cores = h.getCoreContainer();
    final CoreAdminHandler admin = new CoreAdminHandler(cores);
    SolrQueryRequest request = req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.STATUS.toString());
    SolrQueryResponse response = new SolrQueryResponse();
    admin.handleRequestBody(request, response);
    assertNull("Exception on create", response.getException());
    assertSchemaResource(collection, "managed-schema");
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) CoreContainer(org.apache.solr.core.CoreContainer) CoreAdminHandler(org.apache.solr.handler.admin.CoreAdminHandler)

Example 39 with CoreContainer

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

the class MiniSolrCloudCluster method expireZkSession.

/**
   * Make the zookeeper session on a particular jetty expire
   */
public void expireZkSession(JettySolrRunner jetty) {
    CoreContainer cores = jetty.getCoreContainer();
    if (cores != null) {
        SolrZkClient zkClient = cores.getZkController().getZkClient();
        zkClient.getSolrZooKeeper().closeCnxn();
        long sessionId = zkClient.getSolrZooKeeper().getSessionId();
        zkServer.expire(sessionId);
        log.info("Expired zookeeper session {} from node {}", sessionId, jetty.getBaseUrl());
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 40 with CoreContainer

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

the class ChaosMonkey method kill.

public static void kill(JettySolrRunner jetty) throws Exception {
    CoreContainer cores = jetty.getCoreContainer();
    if (cores != null) {
        if (cores.isZooKeeperAware()) {
            int zklocalport = ((InetSocketAddress) cores.getZkController().getZkClient().getSolrZooKeeper().getSocketAddress()).getPort();
            IpTables.blockPort(zklocalport);
        }
    }
    IpTables.blockPort(jetty.getLocalPort());
    monkeyLog("kill jetty! " + jetty.getLocalPort());
    jetty.stop();
    stop(jetty);
    if (!jetty.isStopped()) {
        throw new RuntimeException("could not kill jetty");
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) InetSocketAddress(java.net.InetSocketAddress)

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