Search in sources :

Example 86 with SolrZkClient

use of org.apache.solr.common.cloud.SolrZkClient in project lucene-solr by apache.

the class ShowFileRequestHandler method showFromZooKeeper.

// Get a list of files from ZooKeeper for from the path in the file= parameter.
private void showFromZooKeeper(SolrQueryRequest req, SolrQueryResponse rsp, CoreContainer coreContainer) throws KeeperException, InterruptedException, UnsupportedEncodingException {
    SolrZkClient zkClient = coreContainer.getZkController().getZkClient();
    String adminFile = getAdminFileFromZooKeeper(req, rsp, zkClient, hiddenFiles);
    if (adminFile == null) {
        return;
    }
    // Show a directory listing
    List<String> children = zkClient.getChildren(adminFile, null, true);
    if (children.size() > 0) {
        NamedList<SimpleOrderedMap<Object>> files = new SimpleOrderedMap<>();
        for (String f : children) {
            if (isHiddenFile(req, rsp, f, false, hiddenFiles)) {
                continue;
            }
            SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<>();
            files.add(f, fileInfo);
            List<String> fchildren = zkClient.getChildren(adminFile + "/" + f, null, true);
            if (fchildren.size() > 0) {
                fileInfo.add("directory", true);
            } else {
                // TODO? content type
                fileInfo.add("size", f.length());
            }
        // TODO: ?
        // fileInfo.add( "modified", new Date( f.lastModified() ) );
        }
        rsp.add("files", files);
    } else {
        // Include the file contents
        // The file logic depends on RawResponseWriter, so force its use.
        ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
        params.set(CommonParams.WT, "raw");
        req.setParams(params);
        ContentStreamBase content = new ContentStreamBase.ByteArrayStream(zkClient.getData(adminFile, null, null, true), adminFile);
        content.setContentType(req.getParams().get(USE_CONTENT_TYPE));
        rsp.add(RawResponseWriter.CONTENT, content);
    }
    rsp.setHttpCaching(false);
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Example 87 with SolrZkClient

use of org.apache.solr.common.cloud.SolrZkClient in project lucene-solr by apache.

the class DelegationTokenKerberosFilter method init.

@Override
public void init(FilterConfig conf) throws ServletException {
    if (conf != null && "zookeeper".equals(conf.getInitParameter("signer.secret.provider"))) {
        SolrZkClient zkClient = (SolrZkClient) conf.getServletContext().getAttribute(KerberosPlugin.DELEGATION_TOKEN_ZK_CLIENT);
        conf.getServletContext().setAttribute("signer.secret.provider.zookeeper.curator.client", getCuratorClient(zkClient));
    }
    super.init(conf);
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 88 with SolrZkClient

use of org.apache.solr.common.cloud.SolrZkClient in project lucene-solr by apache.

the class ClusterStateUpdateTest method testCoreRegistration.

@Test
public void testCoreRegistration() throws Exception {
    System.setProperty("solrcloud.update.delay", "1");
    Map<String, Object> props2 = new HashMap<>();
    props2.put("configName", "conf1");
    ZkNodeProps zkProps2 = new ZkNodeProps(props2);
    SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT);
    zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/testcore", Utils.toJSON(zkProps2), CreateMode.PERSISTENT, true);
    zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/testcore/shards", CreateMode.PERSISTENT, true);
    zkClient.close();
    container1.create("testcore", ImmutableMap.of("dataDir", dataDir4.getAbsolutePath()));
    ZkController zkController2 = container2.getZkController();
    String host = zkController2.getHostName();
    // slight pause - TODO: takes an oddly long amount of time to schedule tasks
    // with almost no delay ...
    ClusterState clusterState2 = null;
    Map<String, Slice> slices = null;
    for (int i = 75; i > 0; i--) {
        clusterState2 = zkController2.getClusterState();
        slices = clusterState2.getSlicesMap("testcore");
        if (slices != null && slices.containsKey("shard1") && slices.get("shard1").getReplicasMap().size() > 0) {
            break;
        }
        Thread.sleep(500);
    }
    assertNotNull(slices);
    assertTrue(slices.containsKey("shard1"));
    Slice slice = slices.get("shard1");
    assertEquals("shard1", slice.getName());
    Map<String, Replica> shards = slice.getReplicasMap();
    assertEquals(1, shards.size());
    Replica zkProps = shards.get(host + ":1661_solr_testcore");
    assertNotNull(zkProps);
    assertEquals(host + ":1661_solr", zkProps.getStr(ZkStateReader.NODE_NAME_PROP));
    assertEquals("http://" + host + ":1661/solr", zkProps.getStr(ZkStateReader.BASE_URL_PROP));
    Set<String> liveNodes = clusterState2.getLiveNodes();
    assertNotNull(liveNodes);
    assertEquals(3, liveNodes.size());
    container3.shutdown();
    // slight pause (15s timeout) for watch to trigger
    for (int i = 0; i < (5 * 15); i++) {
        if (zkController2.getClusterState().getLiveNodes().size() == 2) {
            break;
        }
        Thread.sleep(200);
    }
    assertEquals(2, zkController2.getClusterState().getLiveNodes().size());
    // quickly kill / start client
    container2.getZkController().getZkClient().getSolrZooKeeper().getConnection().disconnect();
    container2.shutdown();
    System.setProperty("hostPort", "1662");
    System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir2.getAbsolutePath());
    container2 = new CoreContainer(solrHomeDirectory.getAbsolutePath());
    container2.load();
    System.clearProperty("hostPort");
    // pause for watch to trigger
    for (int i = 0; i < 200; i++) {
        if (container1.getZkController().getClusterState().liveNodesContain(container2.getZkController().getNodeName())) {
            break;
        }
        Thread.sleep(100);
    }
    assertTrue(container1.getZkController().getClusterState().liveNodesContain(container2.getZkController().getNodeName()));
// core.close();  // don't close - this core is managed by container1 now
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) HashMap(java.util.HashMap) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) Replica(org.apache.solr.common.cloud.Replica) CoreContainer(org.apache.solr.core.CoreContainer) Slice(org.apache.solr.common.cloud.Slice) Test(org.junit.Test)

Example 89 with SolrZkClient

use of org.apache.solr.common.cloud.SolrZkClient in project lucene-solr by apache.

the class ClusterStateUpdateTest method printLayout.

static void printLayout(String zkHost) throws Exception {
    SolrZkClient zkClient = new SolrZkClient(zkHost, AbstractZkTestCase.TIMEOUT);
    zkClient.printLayoutToStdOut();
    zkClient.close();
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 90 with SolrZkClient

use of org.apache.solr.common.cloud.SolrZkClient in project lucene-solr by apache.

the class TestCloudManagedSchema method test.

@Test
public void test() throws Exception {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.STATUS.toString());
    QueryRequest request = new QueryRequest(params);
    request.setPath("/admin/cores");
    int which = r.nextInt(clients.size());
    HttpSolrClient client = (HttpSolrClient) clients.get(which);
    String previousBaseURL = client.getBaseURL();
    // Strip /collection1 step from baseURL - requests fail otherwise
    client.setBaseURL(previousBaseURL.substring(0, previousBaseURL.lastIndexOf("/")));
    NamedList namedListResponse = client.request(request);
    // Restore baseURL 
    client.setBaseURL(previousBaseURL);
    NamedList status = (NamedList) namedListResponse.get("status");
    NamedList collectionStatus = (NamedList) status.get("collection1");
    String collectionSchema = (String) collectionStatus.get(CoreAdminParams.SCHEMA);
    // Make sure the upgrade to managed schema happened
    assertEquals("Schema resource name differs from expected name", "managed-schema", collectionSchema);
    SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), 30000);
    try {
        // Make sure "DO NOT EDIT" is in the content of the managed schema
        String fileContent = getFileContentFromZooKeeper(zkClient, "/solr/configs/conf1/managed-schema");
        assertTrue("Managed schema is missing", fileContent.contains("DO NOT EDIT"));
        // Make sure the original non-managed schema is no longer in ZooKeeper
        assertFileNotInZooKeeper(zkClient, "/solr/configs/conf1", "schema.xml");
        // Make sure the renamed non-managed schema is present in ZooKeeper
        fileContent = getFileContentFromZooKeeper(zkClient, "/solr/configs/conf1/schema.xml.bak");
        assertTrue("schema file doesn't contain '<schema'", fileContent.contains("<schema"));
    } finally {
        if (zkClient != null) {
            zkClient.close();
        }
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Aggregations

SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)130 Test (org.junit.Test)46 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)34 HashMap (java.util.HashMap)21 KeeperException (org.apache.zookeeper.KeeperException)18 SolrException (org.apache.solr.common.SolrException)15 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)14 IOException (java.io.IOException)13 ClusterState (org.apache.solr.common.cloud.ClusterState)13 DocCollection (org.apache.solr.common.cloud.DocCollection)12 Map (java.util.Map)11 Slice (org.apache.solr.common.cloud.Slice)11 Replica (org.apache.solr.common.cloud.Replica)10 ArrayList (java.util.ArrayList)9 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)8 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)8 Overseer (org.apache.solr.cloud.Overseer)8 ZkTestServer (org.apache.solr.cloud.ZkTestServer)8 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)7 NamedList (org.apache.solr.common.util.NamedList)7