Search in sources :

Example 6 with HttpSolrClient

use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.

the class TestCryptoKeys method test.

@Test
public void test() throws Exception {
    System.setProperty("enable.runtime.lib", "true");
    setupHarnesses();
    String pk1sig = "G8LEW7uJ1is81Aqqfl3Sld3qDtOxPuVFeTLJHFJWecgDvUkmJNFXmf7nkHOVlXnDWahp1vqZf0W02VHXg37lBw==";
    String pk2sig = "pCyBQycB/0YvLVZfKLDIIqG1tFwM/awqzkp2QNpO7R3ThTqmmrj11wEJFDRLkY79efuFuQPHt40EE7jrOKoj9jLNELsfEqvU3jw9sZKiDONY+rV9Bj9QPeW8Pgt+F9Y1";
    String wrongKeySig = "xTk2hTipfpb+J5s4x3YZGOXkmHWtnJz05Vvd8RTm/Q1fbQVszR7vMk6dQ1URxX08fcg4HvxOo8g9bG2TSMOGjg==";
    String result = null;
    CryptoKeys cryptoKeys = null;
    SolrZkClient zk = getCommonCloudSolrClient().getZkStateReader().getZkClient();
    cryptoKeys = new CryptoKeys(CloudUtil.getTrustedKeys(zk, "exe"));
    ByteBuffer samplefile = ByteBuffer.wrap(readFile("cryptokeys/samplefile.bin"));
    //there are no keys yet created in ZK
    result = cryptoKeys.verify(pk1sig, samplefile);
    assertNull(result);
    zk.makePath("/keys/exe", true);
    zk.create("/keys/exe/pubk1.der", readFile("cryptokeys/pubk1.der"), CreateMode.PERSISTENT, true);
    zk.create("/keys/exe/pubk2.der", readFile("cryptokeys/pubk2.der"), CreateMode.PERSISTENT, true);
    Map<String, byte[]> trustedKeys = CloudUtil.getTrustedKeys(zk, "exe");
    cryptoKeys = new CryptoKeys(trustedKeys);
    result = cryptoKeys.verify(pk2sig, samplefile);
    assertEquals("pubk2.der", result);
    result = cryptoKeys.verify(pk1sig, samplefile);
    assertEquals("pubk1.der", result);
    try {
        result = cryptoKeys.verify(wrongKeySig, samplefile);
        assertNull(result);
    } catch (Exception e) {
    //pass
    }
    try {
        result = cryptoKeys.verify("SGVsbG8gV29ybGQhCg==", samplefile);
        assertNull(result);
    } catch (Exception e) {
    //pass
    }
    HttpSolrClient randomClient = (HttpSolrClient) clients.get(random().nextInt(clients.size()));
    String baseURL = randomClient.getBaseURL();
    baseURL = baseURL.substring(0, baseURL.lastIndexOf('/'));
    TestBlobHandler.createSystemCollection(getHttpSolrClient(baseURL, randomClient.getHttpClient()));
    waitForRecoveriesToFinish(".system", true);
    ByteBuffer jar = TestDynamicLoading.getFileContent("runtimecode/runtimelibs.jar.bin");
    String blobName = "signedjar";
    TestBlobHandler.postAndCheck(cloudClient, baseURL, blobName, jar, 1);
    String payload = "{\n" + "'create-requesthandler' : { 'name' : '/runtime', 'class': 'org.apache.solr.core.RuntimeLibReqHandler' , 'runtimeLib':true }" + "}";
    RestTestHarness client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "requestHandler", "/runtime", "class"), "org.apache.solr.core.RuntimeLibReqHandler", 10);
    payload = "{\n" + "'add-runtimelib' : { 'name' : 'signedjar' ,'version':1}\n" + "}";
    client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "runtimeLib", blobName, "version"), 1l, 10);
    Map map = TestSolrConfigHandler.getRespMap("/runtime?wt=json", client);
    String s = (String) Utils.getObjectByPath(map, false, Arrays.asList("error", "msg"));
    assertNotNull(TestBlobHandler.getAsString(map), s);
    assertTrue(TestBlobHandler.getAsString(map), s.contains("should be signed with one of the keys in ZK /keys/exe"));
    String wrongSig = "QKqHtd37QN02iMW9UEgvAO9g9qOOuG5vEBNkbUsN7noc2hhXKic/ABFIOYJA9PKw61mNX2EmNFXOcO3WClYdSw==";
    payload = "{\n" + "'update-runtimelib' : { 'name' : 'signedjar' ,'version':1, 'sig': 'QKqHtd37QN02iMW9UEgvAO9g9qOOuG5vEBNkbUsN7noc2hhXKic/ABFIOYJA9PKw61mNX2EmNFXOcO3WClYdSw=='}\n" + "}";
    client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "runtimeLib", blobName, "sig"), wrongSig, 10);
    map = TestSolrConfigHandler.getRespMap("/runtime?wt=json", client);
    s = (String) Utils.getObjectByPath(map, false, Arrays.asList("error", "msg"));
    //No key matched signature for jar
    assertNotNull(TestBlobHandler.getAsString(map), s);
    assertTrue(TestBlobHandler.getAsString(map), s.contains("No key matched signature for jar"));
    String rightSig = "YkTQgOtvcM/H/5EQdABGl3wjjrPhonAGlouIx59vppBy2cZEofX3qX1yZu5sPNRmJisNXEuhHN2149dxeUmk2Q==";
    payload = "{\n" + "'update-runtimelib' : { 'name' : 'signedjar' ,'version':1, 'sig': 'YkTQgOtvcM/H/5EQdABGl3wjjrPhonAGlouIx59vppBy2cZEofX3qX1yZu5sPNRmJisNXEuhHN2149dxeUmk2Q=='}\n" + "}";
    client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "runtimeLib", blobName, "sig"), rightSig, 10);
    map = TestSolrConfigHandler.testForResponseElement(client, null, "/runtime?wt=json", null, Arrays.asList("class"), "org.apache.solr.core.RuntimeLibReqHandler", 10);
    compareValues(map, MemClassLoader.class.getName(), asList("loader"));
    rightSig = "VJPMTxDf8Km3IBj2B5HWkIOqeM/o+HHNobOYCNA3WjrEVfOMZbMMqS1Lo7uLUUp//RZwOGkOhrUhuPNY1z2CGEIKX2/m8VGH64L14d52oSvFiwhoTDDuuyjW1TFGu35D";
    payload = "{\n" + "'update-runtimelib' : { 'name' : 'signedjar' ,'version':1, 'sig': 'VJPMTxDf8Km3IBj2B5HWkIOqeM/o+HHNobOYCNA3WjrEVfOMZbMMqS1Lo7uLUUp//RZwOGkOhrUhuPNY1z2CGEIKX2/m8VGH64L14d52oSvFiwhoTDDuuyjW1TFGu35D'}\n" + "}";
    client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "runtimeLib", blobName, "sig"), rightSig, 10);
    map = TestSolrConfigHandler.testForResponseElement(client, null, "/runtime?wt=json", null, Arrays.asList("class"), "org.apache.solr.core.RuntimeLibReqHandler", 10);
    compareValues(map, MemClassLoader.class.getName(), asList("loader"));
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) RestTestHarness(org.apache.solr.util.RestTestHarness) CryptoKeys(org.apache.solr.util.CryptoKeys) MemClassLoader(org.apache.solr.core.MemClassLoader) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) ByteBuffer(java.nio.ByteBuffer) Map(java.util.Map) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with HttpSolrClient

use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.

the class TestConfigSetsAPI method xsltRequest.

private void xsltRequest(String collection) throws SolrServerException, IOException {
    String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();
    try (HttpSolrClient client = getHttpSolrClient(baseUrl + "/" + collection)) {
        String xml = "<random>" + " <document>" + "  <node name=\"id\" value=\"12345\"/>" + "  <node name=\"name\" value=\"kitten\"/>" + "  <node name=\"text\" enhance=\"3\" value=\"some other day\"/>" + "  <node name=\"title\" enhance=\"4\" value=\"A story\"/>" + "  <node name=\"timestamp\" enhance=\"5\" value=\"2011-07-01T10:31:57.140Z\"/>" + " </document>" + "</random>";
        SolrQuery query = new SolrQuery();
        //for anything
        query.setQuery("*:*");
        query.add("qt", "/update");
        query.add(CommonParams.TR, "xsl-update-handler-test.xsl");
        query.add("stream.body", xml);
        query.add("commit", "true");
        try {
            client.query(query);
            fail("This should've returned a 401.");
        } catch (SolrException ex) {
            assertEquals(ErrorCode.UNAUTHORIZED.code, ex.code());
        }
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrException(org.apache.solr.common.SolrException)

Example 8 with HttpSolrClient

use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.

the class TestPullReplica method testRealTimeGet.

public void testRealTimeGet() throws SolrServerException, IOException, KeeperException, InterruptedException {
    // should be redirected to Replica.Type.NRT
    int numReplicas = random().nextBoolean() ? 1 : 2;
    CollectionAdminRequest.createCollection(collectionName, "conf", 1, numReplicas, 0, numReplicas).setMaxShardsPerNode(100).process(cluster.getSolrClient());
    waitForState("Unexpected replica count", collectionName, activeReplicaCount(numReplicas, 0, numReplicas));
    DocCollection docCollection = assertNumberOfReplicas(numReplicas, 0, numReplicas, false, true);
    HttpClient httpClient = cluster.getSolrClient().getHttpClient();
    int id = 0;
    Slice slice = docCollection.getSlice("shard1");
    List<String> ids = new ArrayList<>(slice.getReplicas().size());
    for (Replica rAdd : slice.getReplicas()) {
        try (HttpSolrClient client = getHttpSolrClient(rAdd.getCoreUrl(), httpClient)) {
            client.add(new SolrInputDocument("id", String.valueOf(id), "foo_s", "bar"));
        }
        SolrDocument docCloudClient = cluster.getSolrClient().getById(collectionName, String.valueOf(id));
        assertEquals("bar", docCloudClient.getFieldValue("foo_s"));
        for (Replica rGet : slice.getReplicas()) {
            try (HttpSolrClient client = getHttpSolrClient(rGet.getCoreUrl(), httpClient)) {
                SolrDocument doc = client.getById(String.valueOf(id));
                assertEquals("bar", doc.getFieldValue("foo_s"));
            }
        }
        ids.add(String.valueOf(id));
        id++;
    }
    SolrDocumentList previousAllIdsResult = null;
    for (Replica rAdd : slice.getReplicas()) {
        try (HttpSolrClient client = getHttpSolrClient(rAdd.getCoreUrl(), httpClient)) {
            SolrDocumentList allIdsResult = client.getById(ids);
            if (previousAllIdsResult != null) {
                assertTrue(compareSolrDocumentList(previousAllIdsResult, allIdsResult));
            } else {
                // set the first response here
                previousAllIdsResult = allIdsResult;
                assertEquals("Unexpected number of documents", ids.size(), allIdsResult.getNumFound());
            }
        }
        id++;
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrDocument(org.apache.solr.common.SolrDocument) Slice(org.apache.solr.common.cloud.Slice) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) DocCollection(org.apache.solr.common.cloud.DocCollection) SolrDocumentList(org.apache.solr.common.SolrDocumentList) Replica(org.apache.solr.common.cloud.Replica)

Example 9 with HttpSolrClient

use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.

the class TestCustomStream method testDynamicLoadingCustomStream.

@Test
public void testDynamicLoadingCustomStream() throws Exception {
    System.setProperty("enable.runtime.lib", "true");
    setupHarnesses();
    String blobName = "colltest";
    HttpSolrClient randomClient = (HttpSolrClient) clients.get(random().nextInt(clients.size()));
    String baseURL = randomClient.getBaseURL();
    baseURL = baseURL.substring(0, baseURL.lastIndexOf('/'));
    TestBlobHandler.createSystemCollection(getHttpSolrClient(baseURL, randomClient.getHttpClient()));
    waitForRecoveriesToFinish(".system", true);
    String payload = "{\n" + "'create-expressible' : { 'name' : 'hello', 'class': 'org.apache.solr.core.HelloStream' }\n" + "}";
    RestTestHarness client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "expressible", "hello", "class"), "org.apache.solr.core.HelloStream", 10);
    TestSolrConfigHandler.testForResponseElement(client, null, "/stream?expr=hello()", null, Arrays.asList("result-set", "docs[0]", "msg"), "Hello World!", 10);
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) RestTestHarness(org.apache.solr.util.RestTestHarness) Test(org.junit.Test)

Example 10 with HttpSolrClient

use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.

the class TestDynamicLoading method testDynamicLoading.

@Test
public void testDynamicLoading() throws Exception {
    System.setProperty("enable.runtime.lib", "true");
    setupHarnesses();
    String blobName = "colltest";
    boolean success = false;
    HttpSolrClient randomClient = (HttpSolrClient) clients.get(random().nextInt(clients.size()));
    String baseURL = randomClient.getBaseURL();
    baseURL = baseURL.substring(0, baseURL.lastIndexOf('/'));
    String payload = "{\n" + "'add-runtimelib' : { 'name' : 'colltest' ,'version':1}\n" + "}";
    RestTestHarness client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "runtimeLib", blobName, "version"), 1l, 10);
    payload = "{\n" + "'create-requesthandler' : { 'name' : '/test1', 'class': 'org.apache.solr.core.BlobStoreTestRequestHandler' ,registerPath: '/solr,/v2',  'runtimeLib' : true }\n" + "}";
    client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "requestHandler", "/test1", "class"), "org.apache.solr.core.BlobStoreTestRequestHandler", 10);
    Map map = TestSolrConfigHandler.getRespMap("/test1?wt=json", client);
    assertNotNull(TestBlobHandler.getAsString(map), map = (Map) map.get("error"));
    assertTrue(TestBlobHandler.getAsString(map), map.get("msg").toString().contains(".system collection not available"));
    TestBlobHandler.createSystemCollection(getHttpSolrClient(baseURL, randomClient.getHttpClient()));
    waitForRecoveriesToFinish(".system", true);
    map = TestSolrConfigHandler.getRespMap("/test1?wt=json", client);
    assertNotNull(map = (Map) map.get("error"));
    assertTrue("full output " + TestBlobHandler.getAsString(map), map.get("msg").toString().contains("no such blob or version available: colltest/1"));
    payload = " {\n" + "  'set' : {'watched': {" + "                    'x':'X val',\n" + "                    'y': 'Y val'}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(client, "/config/params?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/params?wt=json", cloudClient, Arrays.asList("response", "params", "watched", "x"), "X val", 10);
    for (int i = 0; i < 100; i++) {
        map = TestSolrConfigHandler.getRespMap("/test1?wt=json", client);
        if ("X val".equals(map.get("x"))) {
            success = true;
            break;
        }
        Thread.sleep(100);
    }
    ByteBuffer jar = null;
    //     jar = persistZip("/tmp/runtimelibs.jar.bin", TestDynamicLoading.class, RuntimeLibReqHandler.class, RuntimeLibResponseWriter.class, RuntimeLibSearchComponent.class);
    //    if(true) return;
    jar = getFileContent("runtimecode/runtimelibs.jar.bin");
    TestBlobHandler.postAndCheck(cloudClient, baseURL, blobName, jar, 1);
    payload = "{\n" + "'create-requesthandler' : { 'name' : '/runtime', 'class': 'org.apache.solr.core.RuntimeLibReqHandler' , 'runtimeLib':true }," + "'create-searchcomponent' : { 'name' : 'get', 'class': 'org.apache.solr.core.RuntimeLibSearchComponent' , 'runtimeLib':true }," + "'create-queryResponseWriter' : { 'name' : 'json1', 'class': 'org.apache.solr.core.RuntimeLibResponseWriter' , 'runtimeLib':true }" + "}";
    client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    Map result = TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "requestHandler", "/runtime", "class"), "org.apache.solr.core.RuntimeLibReqHandler", 10);
    compareValues(result, "org.apache.solr.core.RuntimeLibResponseWriter", asList("overlay", "queryResponseWriter", "json1", "class"));
    compareValues(result, "org.apache.solr.core.RuntimeLibSearchComponent", asList("overlay", "searchComponent", "get", "class"));
    result = TestSolrConfigHandler.testForResponseElement(client, null, "/runtime?wt=json", null, Arrays.asList("class"), "org.apache.solr.core.RuntimeLibReqHandler", 10);
    compareValues(result, MemClassLoader.class.getName(), asList("loader"));
    result = TestSolrConfigHandler.testForResponseElement(client, null, "/runtime?wt=json1", null, Arrays.asList("wt"), "org.apache.solr.core.RuntimeLibResponseWriter", 10);
    compareValues(result, MemClassLoader.class.getName(), asList("loader"));
    result = TestSolrConfigHandler.testForResponseElement(client, null, "/get?abc=xyz", null, Arrays.asList("get"), "org.apache.solr.core.RuntimeLibSearchComponent", 10);
    compareValues(result, MemClassLoader.class.getName(), asList("loader"));
    jar = getFileContent("runtimecode/runtimelibs_v2.jar.bin");
    TestBlobHandler.postAndCheck(cloudClient, baseURL, blobName, jar, 2);
    payload = "{\n" + "'update-runtimelib' : { 'name' : 'colltest' ,'version':2}\n" + "}";
    client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "runtimeLib", blobName, "version"), 2l, 10);
    result = TestSolrConfigHandler.testForResponseElement(client, null, "/get?abc=xyz", null, Arrays.asList("Version"), "2", 10);
    payload = " {\n" + "  'set' : {'watched': {" + "                    'x':'X val',\n" + "                    'y': 'Y val'}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(client, "/config/params?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/params?wt=json", cloudClient, Arrays.asList("response", "params", "watched", "x"), "X val", 10);
    result = TestSolrConfigHandler.testForResponseElement(client, null, "/test1?wt=json", cloudClient, Arrays.asList("x"), "X val", 10);
    payload = " {\n" + "  'set' : {'watched': {" + "                    'x':'X val changed',\n" + "                    'y': 'Y val'}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(client, "/config/params?wt=json", payload);
    result = TestSolrConfigHandler.testForResponseElement(client, null, "/test1?wt=json", cloudClient, Arrays.asList("x"), "X val changed", 10);
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) RestTestHarness(org.apache.solr.util.RestTestHarness) Map(java.util.Map) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)187 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)48 SolrClient (org.apache.solr.client.solrj.SolrClient)46 Test (org.junit.Test)46 SolrQuery (org.apache.solr.client.solrj.SolrQuery)38 ArrayList (java.util.ArrayList)35 Replica (org.apache.solr.common.cloud.Replica)34 SolrInputDocument (org.apache.solr.common.SolrInputDocument)31 IOException (java.io.IOException)26 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)25 Slice (org.apache.solr.common.cloud.Slice)25 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)24 SolrException (org.apache.solr.common.SolrException)23 SolrServerException (org.apache.solr.client.solrj.SolrServerException)21 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)20 NamedList (org.apache.solr.common.util.NamedList)19 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)18 DocCollection (org.apache.solr.common.cloud.DocCollection)18 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)15 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)15