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);
}
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);
}
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
}
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();
}
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();
}
}
}
Aggregations