org.apache.solr.common.cloud.SolrZkClient Java Examples
The following examples show how to use
org.apache.solr.common.cloud.SolrZkClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CdcrBufferStateManager.java From lucene-solr with Apache License 2.0 | 6 votes |
CdcrBufferStateManager(final SolrCore core, SolrParams bufferConfiguration) { this.core = core; // Ensure that the state znode exists this.createStateNode(); // set default state if (bufferConfiguration != null) { byte[] defaultState = bufferConfiguration.get( CdcrParams.DEFAULT_STATE_PARAM, DEFAULT_STATE.toLower()).getBytes(Charset.forName("UTF-8")); state = CdcrParams.BufferState.get(defaultState); } this.setState(state); // notify observers // Startup and register the watcher at startup try { SolrZkClient zkClient = core.getCoreContainer().getZkController().getZkClient(); watcher = this.initWatcher(zkClient); this.setState(CdcrParams.BufferState.get(zkClient.getData(this.getZnodePath(), watcher, null, true))); } catch (KeeperException | InterruptedException e) { log.warn("Failed fetching initial state", e); } }
Example #2
Source File: BackupManager.java From lucene-solr with Apache License 2.0 | 6 votes |
private void downloadFromZK(SolrZkClient zkClient, String zkPath, URI dir) throws IOException { try { if (!repository.exists(dir)) { repository.createDirectory(dir); } List<String> files = zkClient.getChildren(zkPath, null, true); for (String file : files) { List<String> children = zkClient.getChildren(zkPath + "/" + file, null, true); if (children.size() == 0) { log.debug("Writing file {}", file); byte[] data = zkClient.getData(zkPath + "/" + file, null, null, true); try (OutputStream os = repository.createOutput(repository.resolve(dir, file))) { os.write(data); } } else { downloadFromZK(zkClient, zkPath + "/" + file, repository.resolve(dir, file)); } } } catch (KeeperException | InterruptedException e) { throw new IOException("Error downloading files from zookeeper path " + zkPath + " to " + dir.toString(), SolrZkClient.checkInterrupted(e)); } }
Example #3
Source File: OutOfBoxZkACLAndCredentialsProvidersTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testOpenACLUnsafeAllover() throws Exception { SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT); try { List<String> verifiedList = new ArrayList<String>(); assertOpenACLUnsafeAllover(zkClient, "/", verifiedList); assertTrue(verifiedList.contains("/solr")); assertTrue(verifiedList.contains("/solr/unprotectedCreateNode")); assertTrue(verifiedList.contains("/solr/unprotectedMakePathNode")); assertTrue(verifiedList.contains("/solr/protectedMakePathNode")); assertTrue(verifiedList.contains("/solr/protectedCreateNode")); assertTrue(verifiedList.contains("/solr" + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH)); } finally { zkClient.close(); } }
Example #4
Source File: SolrCLI.java From lucene-solr with Apache License 2.0 | 6 votes |
protected void runImpl(CommandLine cli) throws Exception { raiseLogLevelUnlessVerbose(cli); String zkHost = getZkHost(cli); if (zkHost == null) { throw new IllegalStateException("Solr at " + cli.getOptionValue("zkHost") + " is running in standalone server mode, 'zk ls' can only be used when running in SolrCloud mode.\n"); } try (SolrZkClient zkClient = new SolrZkClient(zkHost, 30000)) { echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...", cli); String znode = cli.getOptionValue("path"); Boolean recurse = Boolean.parseBoolean(cli.getOptionValue("recurse")); echoIfVerbose("Getting listing for Zookeeper node " + znode + " from ZooKeeper at " + zkHost + " recurse: " + Boolean.toString(recurse), cli); stdout.print(zkClient.listZnode(znode, recurse)); } catch (Exception e) { log.error("Could not complete ls operation for reason: {}", e.getMessage()); throw (e); } }
Example #5
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Create the zknodes necessary for a cluster to operate * * @param zkClient a SolrZkClient * @throws KeeperException if there is a Zookeeper error * @throws InterruptedException on interrupt */ public static void createClusterZkNodes(SolrZkClient zkClient) throws KeeperException, InterruptedException, IOException { ZkCmdExecutor cmdExecutor = new ZkCmdExecutor(zkClient.getZkClientTimeout()); cmdExecutor.ensureExists(ZkStateReader.LIVE_NODES_ZKNODE, zkClient); cmdExecutor.ensureExists(ZkStateReader.COLLECTIONS_ZKNODE, zkClient); cmdExecutor.ensureExists(ZkStateReader.ALIASES, zkClient); cmdExecutor.ensureExists(ZkStateReader.SOLR_AUTOSCALING_EVENTS_PATH, zkClient); cmdExecutor.ensureExists(ZkStateReader.SOLR_AUTOSCALING_TRIGGER_STATE_PATH, zkClient); cmdExecutor.ensureExists(ZkStateReader.SOLR_AUTOSCALING_NODE_ADDED_PATH, zkClient); cmdExecutor.ensureExists(ZkStateReader.SOLR_AUTOSCALING_NODE_LOST_PATH, zkClient); byte[] emptyJson = "{}".getBytes(StandardCharsets.UTF_8); cmdExecutor.ensureExists(ZkStateReader.SOLR_SECURITY_CONF_PATH, emptyJson, CreateMode.PERSISTENT, zkClient); cmdExecutor.ensureExists(ZkStateReader.SOLR_AUTOSCALING_CONF_PATH, emptyJson, CreateMode.PERSISTENT, zkClient); bootstrapDefaultConfigSet(zkClient); }
Example #6
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Validates if the chroot exists in zk (or if it is successfully created). * Optionally, if create is set to true this method will create the path in * case it doesn't exist * * @return true if the path exists or is created false if the path doesn't * exist and 'create' = false */ public static boolean checkChrootPath(String zkHost, boolean create) throws KeeperException, InterruptedException { if (!SolrZkClient.containsChroot(zkHost)) { return true; } log.trace("zkHost includes chroot"); String chrootPath = zkHost.substring(zkHost.indexOf("/"), zkHost.length()); SolrZkClient tmpClient = new SolrZkClient(zkHost.substring(0, zkHost.indexOf("/")), 60000, 30000, null, null, null); boolean exists = tmpClient.exists(chrootPath, true); if (!exists && create) { tmpClient.makePath(chrootPath, false, true); exists = true; } tmpClient.close(); return exists; }
Example #7
Source File: CdcrBufferStateManager.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void process(WatchedEvent event) { if (isCancelled) return; // if the watcher is cancelled, do nothing. String collectionName = core.getCoreDescriptor().getCloudDescriptor().getCollectionName(); String shard = core.getCoreDescriptor().getCloudDescriptor().getShardId(); log.info("The CDCR buffer state has changed: {} @ {}:{}", event, collectionName, shard); // session events are not change events, and do not remove the watcher if (Event.EventType.None.equals(event.getType())) { return; } SolrZkClient zkClient = core.getCoreContainer().getZkController().getZkClient(); try { CdcrParams.BufferState state = CdcrParams.BufferState.get(zkClient.getData(CdcrBufferStateManager.this.getZnodePath(), watcher, null, true)); log.info("Received new CDCR buffer state from watcher: {} @ {}:{}", state, collectionName, shard); CdcrBufferStateManager.this.setState(state); } catch (KeeperException | InterruptedException e) { log.warn("Failed synchronising new state @ {}:{}", collectionName, shard, e); } }
Example #8
Source File: ZkConfigFilesTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testCanUploadConfigToZk() throws Exception { final String zkConnectionString = cluster.getZkClient().getZkServerAddress(); final String localConfigSetDirectory = new File(ExternalPaths.TECHPRODUCTS_CONFIGSET).getAbsolutePath(); assertConfigsContainOnly(); // tag::zk-configset-upload[] try (SolrZkClient zkClient = new SolrZkClient(zkConnectionString, ZK_TIMEOUT_MILLIS)) { ZkConfigManager manager = new ZkConfigManager(zkClient); manager.uploadConfigDir(Paths.get(localConfigSetDirectory), "nameForConfigset"); } // end::zk-configset-upload[] assertConfigsContainOnly("nameForConfigset"); }
Example #9
Source File: CdcrBufferStateManager.java From lucene-solr with Apache License 2.0 | 6 votes |
private void createStateNode() { SolrZkClient zkClient = core.getCoreContainer().getZkController().getZkClient(); try { if (!zkClient.exists(this.getZnodePath(), true)) { if (!zkClient.exists(this.getZnodeBase(), true)) { zkClient.makePath(this.getZnodeBase(), null, CreateMode.PERSISTENT, null, false, true); // Should be a no-op if node exists } zkClient.create(this.getZnodePath(), DEFAULT_STATE.getBytes(), CreateMode.PERSISTENT, true); if (log.isInfoEnabled()) { log.info("Created znode {}", this.getZnodePath()); } } } catch (KeeperException.NodeExistsException ne) { // Someone got in first and created the node. } catch (KeeperException | InterruptedException e) { log.warn("Failed to create CDCR buffer state node", e); } }
Example #10
Source File: AssignTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testAssignNode() throws Exception { assumeWorkingMockito(); SolrZkClient zkClient = mock(SolrZkClient.class); Map<String, byte[]> zkClientData = new HashMap<>(); when(zkClient.setData(anyString(), any(), anyInt(), anyBoolean())).then(invocation -> { zkClientData.put(invocation.getArgument(0), invocation.getArgument(1)); return null; } ); when(zkClient.getData(anyString(), any(), any(), anyBoolean())).then(invocation -> zkClientData.get(invocation.getArgument(0))); // TODO: fix this to be independent of ZK ZkDistribStateManager stateManager = new ZkDistribStateManager(zkClient); String nodeName = Assign.assignCoreNodeName(stateManager, new DocCollection("collection1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT)); assertEquals("core_node1", nodeName); nodeName = Assign.assignCoreNodeName(stateManager, new DocCollection("collection2", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT)); assertEquals("core_node1", nodeName); nodeName = Assign.assignCoreNodeName(stateManager, new DocCollection("collection1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT)); assertEquals("core_node2", nodeName); }
Example #11
Source File: SolrSnapshotManager.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * This method returns the {@linkplain CollectionSnapshotMetaData} for each named snapshot for the specified collection in Zookeeper. * * @param zkClient Zookeeper client * @param collectionName The name of the collection * @return the {@linkplain CollectionSnapshotMetaData} for each named snapshot * @throws InterruptedException In case of thread interruption. * @throws KeeperException In case of Zookeeper error */ public static Collection<CollectionSnapshotMetaData> listSnapshots(SolrZkClient zkClient, String collectionName) throws InterruptedException, KeeperException { Collection<CollectionSnapshotMetaData> result = new ArrayList<>(); String zkPath = getSnapshotMetaDataZkPath(collectionName, Optional.empty()); try { Collection<String> snapshots = zkClient.getChildren(zkPath, null, true); for (String snapshot : snapshots) { Optional<CollectionSnapshotMetaData> s = getCollectionLevelSnapshot(zkClient, collectionName, snapshot); if (s.isPresent()) { result.add(s.get()); } } } catch (KeeperException ex) { // Gracefully handle the case when the zk node doesn't exist (e.g. due to a concurrent delete collection operation). if ( ex.code() != KeeperException.Code.NONODE ) { throw ex; } } return result; }
Example #12
Source File: TestDynamicURP.java From lucene-solr with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupCluster() throws Exception { System.setProperty("enable.runtime.lib", "true"); configureCluster(3) .addConfig("conf", configset("cloud-minimal")) .configure(); SolrZkClient zkClient = cluster.getSolrClient().getZkStateReader().getZkClient(); String path = ZkStateReader.CONFIGS_ZKNODE + "/conf/solrconfig.xml"; byte[] data = zkClient.getData(path, null, null, true); String solrconfigStr = new String(data, StandardCharsets.UTF_8); zkClient.setData(path, solrconfigStr.replace("</config>", "<updateRequestProcessorChain name=\"test_urp\" processor=\"testURP\" default=\"true\">\n" + " <processor class=\"solr.RunUpdateProcessorFactory\"/>\n" + " </updateRequestProcessorChain>\n" + "\n" + " <updateProcessor class=\"runtimecode.TestURP\" name=\"testURP\" runtimeLib=\"true\"></updateProcessor>\n" + "</config>").getBytes(StandardCharsets.UTF_8), true ); CollectionAdminRequest.createCollection(COLLECTION, "conf", 3, 1).process(cluster.getSolrClient()); waitForState("", COLLECTION, clusterShape(3, 3)); }
Example #13
Source File: TestConfigSetsAPI.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testUploadDisabled() throws Exception { try (SolrZkClient zkClient = new SolrZkClient(solrCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, 45000, null)) { for (boolean enabled: new boolean[] {true, false}) { System.setProperty("configset.upload.enabled", String.valueOf(enabled)); try { long statusCode = uploadConfigSet("regular", "test-enabled-is-" + enabled, null, null, zkClient); assertEquals("ConfigSet upload enabling/disabling not working as expected for enabled=" + enabled + ".", enabled? 0l: 400l, statusCode); } finally { System.clearProperty("configset.upload.enabled"); } } } }
Example #14
Source File: MockSolrSource.java From lucene-solr with Apache License 2.0 | 6 votes |
public static ZkController makeSimpleMock(Overseer overseer, ZkStateReader reader, SolrZkClient zkClient) { ZkController zkControllerMock = mock(ZkController.class); if (overseer == null) overseer = mock(Overseer.class); if (reader != null && zkClient == null) { zkClient = reader.getZkClient(); } else { if (zkClient == null) { } reader = mock(ZkStateReader.class); when(reader.getZkClient()).thenReturn(zkClient); } when(zkControllerMock.getOverseer()).thenReturn(overseer); when(zkControllerMock.getZkStateReader()).thenReturn(reader); when(zkControllerMock.getZkClient()).thenReturn(zkClient); when(zkControllerMock.getOverseer()).thenReturn(overseer); return zkControllerMock; }
Example #15
Source File: BackupManager.java From lucene-solr with Apache License 2.0 | 6 votes |
public void uploadCollectionProperties(URI backupLoc, String backupId, String collectionName) throws IOException { URI sourceDir = repository.resolve(backupLoc, backupId, ZK_STATE_DIR); URI source = repository.resolve(sourceDir, ZkStateReader.COLLECTION_PROPS_ZKNODE); if (!repository.exists(source)) { // No collection properties to restore return; } String zkPath = ZkStateReader.COLLECTIONS_ZKNODE + '/' + collectionName + '/' + ZkStateReader.COLLECTION_PROPS_ZKNODE; try (IndexInput is = repository.openInput(sourceDir, ZkStateReader.COLLECTION_PROPS_ZKNODE, IOContext.DEFAULT)) { byte[] arr = new byte[(int) is.length()]; is.readBytes(arr, 0, (int) is.length()); zkStateReader.getZkClient().create(zkPath, arr, CreateMode.PERSISTENT, true); } catch (KeeperException | InterruptedException e) { throw new IOException("Error uploading file to zookeeper path " + source.toString() + " to " + zkPath, SolrZkClient.checkInterrupted(e)); } }
Example #16
Source File: TestConfigSetsAPIZkFailure.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testCreateZkFailure() throws Exception { final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); final SolrClient solrClient = getHttpSolrClient(baseUrl); final Map<String, String> oldProps = ImmutableMap.of("immutable", "true"); setupBaseConfigSet(BASE_CONFIGSET_NAME, oldProps); SolrZkClient zkClient = new SolrZkClient(solrCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null); try { ZkConfigManager configManager = new ZkConfigManager(zkClient); assertFalse(configManager.configExists(CONFIGSET_NAME)); Create create = new Create(); create.setBaseConfigSetName(BASE_CONFIGSET_NAME).setConfigSetName(CONFIGSET_NAME); RemoteSolrException se = expectThrows(RemoteSolrException.class, () -> create.process(solrClient)); // partial creation should have been cleaned up assertFalse(configManager.configExists(CONFIGSET_NAME)); assertEquals(SolrException.ErrorCode.SERVER_ERROR.code, se.code()); } finally { zkClient.close(); } solrClient.close(); }
Example #17
Source File: AssignTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testBuildCoreName() throws Exception { Path zkDir = createTempDir("zkData"); ZkTestServer server = new ZkTestServer(zkDir); server.run(); try (SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), 10000)) { // TODO: fix this to be independent of ZK ZkDistribStateManager stateManager = new ZkDistribStateManager(zkClient); Map<String, Slice> slices = new HashMap<>(); slices.put("shard1", new Slice("shard1", new HashMap<>(), null,"collection1")); slices.put("shard2", new Slice("shard2", new HashMap<>(), null,"collection1")); DocCollection docCollection = new DocCollection("collection1", slices, null, DocRouter.DEFAULT); assertEquals("Core name pattern changed", "collection1_shard1_replica_n1", Assign.buildSolrCoreName(stateManager, docCollection, "shard1", Replica.Type.NRT)); assertEquals("Core name pattern changed", "collection1_shard2_replica_p2", Assign.buildSolrCoreName(stateManager, docCollection, "shard2", Replica.Type.PULL)); } finally { server.shutdown(); } }
Example #18
Source File: OutOfBoxZkACLAndCredentialsProvidersTest.java From lucene-solr with Apache License 2.0 | 6 votes |
protected void assertOpenACLUnsafeAllover(SolrZkClient zkClient, String path, List<String> verifiedList) throws Exception { List<ACL> acls = zkClient.getSolrZooKeeper().getACL(path, new Stat()); if (log.isInfoEnabled()) { log.info("Verifying {}", path); } if (ZooDefs.CONFIG_NODE.equals(path)) { // Treat this node specially, from the ZK docs: // The dynamic configuration is stored in a special znode ZooDefs.CONFIG_NODE = /zookeeper/config. // This node by default is read only for all users, except super user and // users that's explicitly configured for write access. assertEquals("Path " + path + " does not have READ_ACL_UNSAFE", ZooDefs.Ids.READ_ACL_UNSAFE, acls); } else { assertEquals("Path " + path + " does not have OPEN_ACL_UNSAFE", ZooDefs.Ids.OPEN_ACL_UNSAFE, acls); } verifiedList.add(path); List<String> children = zkClient.getChildren(path, null, false); for (String child : children) { assertOpenACLUnsafeAllover(zkClient, path + ((path.endsWith("/")) ? "" : "/") + child, verifiedList); } }
Example #19
Source File: SaslZkACLProviderTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void setUp() throws Exception { super.setUp(); if (log.isInfoEnabled()) { log.info("####SETUP_START {}", getTestName()); } createTempDir(); Path zkDir = createTempDir().resolve("zookeeper/server1/data"); log.info("ZooKeeper dataDir:{}", zkDir); zkServer = new SaslZkTestServer(zkDir, createTempDir().resolve("miniKdc")); zkServer.run(); System.setProperty("zkHost", zkServer.getZkAddress()); try (SolrZkClient zkClient = new SolrZkClientWithACLs(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT)) { zkClient.makePath("/solr", false, true); } setupZNodes(); if (log.isInfoEnabled()) { log.info("####SETUP_END {}", getTestName()); } }
Example #20
Source File: ZookeeperInfoHandler.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Gets the requested page of collections after applying filters and offsets. */ public void fetchPage(PageOfCollections page, SolrZkClient zkClient) throws KeeperException, InterruptedException { List<String> children = getCollections(zkClient); page.selected = children; // start with the page being the full list // activate paging (if disabled) for large collection sets if (page.start == 0 && page.rows == -1 && page.filter == null && children.size() > 10) { page.rows = 20; page.start = 0; } // apply the name filter if supplied (we don't need to pull state // data from ZK to do name filtering if (page.filterType == FilterType.name && page.filter != null) children = page.applyNameFilter(children); // a little hacky ... we can't select the page when filtering by // status until reading all status objects from ZK if (page.filterType != FilterType.status) page.selectPage(children); }
Example #21
Source File: ZookeeperInfoHandler.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Create a merged view of all collections from /collections/?/state.json */ private synchronized List<String> getCollections(SolrZkClient zkClient) throws KeeperException, InterruptedException { if (cachedCollections == null) { // cache is stale, rebuild the full list ... cachedCollections = new ArrayList<String>(); List<String> fromZk = zkClient.getChildren("/collections", this, true); if (fromZk != null) cachedCollections.addAll(fromZk); // sort the final merged set of collections Collections.sort(cachedCollections, this); } return cachedCollections; }
Example #22
Source File: TestConfigSetsAPI.java From lucene-solr with Apache License 2.0 | 6 votes |
@SuppressWarnings({"rawtypes"}) private NamedList getConfigSetPropertiesFromZk( SolrZkClient zkClient, String path) throws Exception { byte [] oldPropsData = null; try { oldPropsData = zkClient.getData(path, null, null, true); } catch (KeeperException.NoNodeException e) { // okay, properties just don't exist } if (oldPropsData != null) { InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(oldPropsData), StandardCharsets.UTF_8); try { return ConfigSetProperties.readFromInputStream(reader); } finally { reader.close(); } } return null; }
Example #23
Source File: OverseerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public MockZKController(String zkAddress, String nodeName, List<Overseer> overseers) throws InterruptedException, TimeoutException, IOException, KeeperException { this.overseers = overseers; this.nodeName = nodeName; zkClient = new SolrZkClient(zkAddress, TIMEOUT); ZkController.createClusterZkNodes(zkClient); zkStateReader = new ZkStateReader(zkClient); zkStateReader.createClusterStateWatchersAndUpdate(); // live node final String nodePath = ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName; zkClient.makePath(nodePath, CreateMode.EPHEMERAL, true); }
Example #24
Source File: TestDistributedMap.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testGet() throws KeeperException, InterruptedException { try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), 10000)) { String path = getAndMakeInitialPath(zkClient); byte[] data = "data".getBytes(Charset.defaultCharset()); zkClient.makePath(path + "/" + DistributedMap.PREFIX + "foo", data, CreateMode.PERSISTENT, null, false, true); DistributedMap map = createMap(zkClient, path); assertArrayEquals(data, map.get("foo")); } }
Example #25
Source File: LeaderElectionTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void setUp() throws Exception { super.setUp(); Path zkDir = createTempDir("zkData"); server = new ZkTestServer(zkDir); server.setTheTickTime(1000); server.run(); zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT); zkStateReader = new ZkStateReader(zkClient); seqToThread = Collections.synchronizedMap(new HashMap<Integer,Thread>()); zkClient.makePath("/collections/collection1", true); zkClient.makePath("/collections/collection2", true); }
Example #26
Source File: OutOfBoxZkACLAndCredentialsProvidersTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testOutOfBoxSolrZkClient() throws Exception { SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { VMParamsZkACLAndCredentialsProvidersTest.doTest(zkClient, true, true, true, true, true, true, true, true, true, true); } finally { zkClient.close(); } }
Example #27
Source File: OverseerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private SolrCloudManager getCloudDataProvider(String zkAddress, SolrZkClient zkClient, ZkStateReader reader) { CloudSolrClient client = new CloudSolrClient.Builder(Collections.singletonList(zkAddress), Optional.empty()).withSocketTimeout(30000).withConnectionTimeout(15000).build(); solrClients.add(client); SolrClientCloudManager sccm = new SolrClientCloudManager(new ZkDistributedQueueFactory(zkClient), client); sccm.getClusterStateProvider().connect(); return sccm; }
Example #28
Source File: OverseerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private SolrZkClient electNewOverseer(String address) throws InterruptedException, TimeoutException, IOException, KeeperException, ParserConfigurationException, SAXException, NoSuchFieldException, SecurityException { SolrZkClient zkClient = new SolrZkClient(address, TIMEOUT); zkClients.add(zkClient); ZkStateReader reader = new ZkStateReader(zkClient); readers.add(reader); LeaderElector overseerElector = new LeaderElector(zkClient); if (overseers.size() > 0) { overseers.get(0).close(); overseers.get(0).getZkStateReader().getZkClient().close(); } UpdateShardHandler updateShardHandler = new UpdateShardHandler(UpdateShardHandlerConfig.DEFAULT); updateShardHandlers.add(updateShardHandler); HttpShardHandlerFactory httpShardHandlerFactory = new HttpShardHandlerFactory(); httpShardHandlerFactory.init(new PluginInfo("shardHandlerFactory", Collections.emptyMap())); httpShardHandlerFactorys.add(httpShardHandlerFactory); ZkController zkController = createMockZkController(address, null, reader); zkControllers.add(zkController); Overseer overseer = new Overseer((HttpShardHandler) httpShardHandlerFactory.getShardHandler(), updateShardHandler, "/admin/cores", reader, zkController, new CloudConfig.CloudConfigBuilder("127.0.0.1", 8983, "").build()); overseers.add(overseer); ElectionContext ec = new OverseerElectionContext(zkClient, overseer, address.replaceAll("/", "_")); overseerElector.setup(ec); overseerElector.joinElection(ec, false); return zkClient; }
Example #29
Source File: TestSolrCloudClusterSupport.java From storm-solr with Apache License 2.0 | 5 votes |
protected static void createCollection(String collectionName, int numShards, int replicationFactor, String confName, File confDir) throws Exception { if (confDir != null) { assertTrue("Specified Solr config directory '" + confDir.getAbsolutePath() + "' not found!", confDir.isDirectory()); // upload the test configs SolrZkClient zkClient = cloudSolrClient.getZkStateReader().getZkClient(); ZkConfigManager zkConfigManager = new ZkConfigManager(zkClient); zkConfigManager.uploadConfigDir(confDir.toPath(), confName); } ModifiableSolrParams modParams = new ModifiableSolrParams(); modParams.set(CoreAdminParams.ACTION, CollectionParams.CollectionAction.CREATE.name()); modParams.set("name", collectionName); modParams.set("numShards", numShards); modParams.set("replicationFactor", replicationFactor); int liveNodes = cloudSolrClient.getZkStateReader().getClusterState().getLiveNodes().size(); int maxShardsPerNode = (int) Math.ceil(((double) numShards * replicationFactor) / liveNodes); modParams.set("maxShardsPerNode", maxShardsPerNode); modParams.set("collection.configName", confName); QueryRequest request = new QueryRequest(modParams); request.setPath("/admin/collections"); cloudSolrClient.request(request); ensureAllReplicasAreActive(collectionName, numShards, replicationFactor, 20); }
Example #30
Source File: ConfigSetsHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override Map<String, Object> call(SolrQueryRequest req, SolrQueryResponse rsp, ConfigSetsHandler h) throws Exception { NamedList<Object> results = new NamedList<>(); SolrZkClient zk = h.coreContainer.getZkController().getZkStateReader().getZkClient(); ZkConfigManager zkConfigManager = new ZkConfigManager(zk); List<String> configSetsList = zkConfigManager.listConfigs(); results.add("configSets", configSetsList); SolrResponse response = new OverseerSolrResponse(results); rsp.getValues().addAll(response.getResponse()); return null; }