gpt4 book ai didi

org.apache.solr.common.cloud.ZkStateReader.getZkClient()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 12:22:40 28 4
gpt4 key购买 nike

本文整理了Java中org.apache.solr.common.cloud.ZkStateReader.getZkClient()方法的一些代码示例,展示了ZkStateReader.getZkClient()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkStateReader.getZkClient()方法的具体详情如下:
包路径:org.apache.solr.common.cloud.ZkStateReader
类名称:ZkStateReader
方法名:getZkClient

ZkStateReader.getZkClient介绍

暂无

代码示例

代码示例来源:origin: org.apache.solr/solr-test-framework

public SolrZkClient getZkClient() {
 return solrClient.getZkStateReader().getZkClient();
}

代码示例来源:origin: com.hynnet/solr-solrj

public Map getClusterProps(){
 Map result = null;
 try {
  if(getZkClient().exists(ZkStateReader.CLUSTER_PROPS, true)){
   result = (Map) Utils.fromJSON(getZkClient().getData(ZkStateReader.CLUSTER_PROPS, null, new Stat(), true)) ;
  } else {
   result= new LinkedHashMap();
  }
  return result;
 } catch (Exception e) {
  throw new SolrException(ErrorCode.SERVER_ERROR,"Error reading cluster properties",e) ;
 }
}

代码示例来源:origin: org.apache.solr/solr-solrj

@Override
public Map getZkJson(String path) throws KeeperException, InterruptedException {
 return Utils.getJson(zkClientClusterStateProvider.getZkStateReader().getZkClient(), path, true);
}

代码示例来源:origin: org.apache.solr/solr-solrj

public SolrClientCloudManager(DistributedQueueFactory queueFactory, CloudSolrClient solrClient) {
 this.queueFactory = queueFactory;
 this.solrClient = solrClient;
 this.zkStateReader = solrClient.getZkStateReader();
 this.zkClient = zkStateReader.getZkClient();
 this.stateManager = new ZkDistribStateManager(zkClient);
 this.isClosed = false;
 this.objectCache = new ObjectCache();
}

代码示例来源:origin: org.apache.solr/solr-solrj

@Override
public void process(WatchedEvent event) {
 // session events are not change events, and do not remove the watcher
 if (EventType.None.equals(event.getType())) {
  return;
 }
 try {
  synchronized (ZkStateReader.this.getUpdateLock()) {
   log.debug("Updating [{}] ... ", SOLR_SECURITY_CONF_PATH);
   // remake watch
   final Watcher thisWatch = this;
   final Stat stat = new Stat();
   final byte[] data = getZkClient().getData(SOLR_SECURITY_CONF_PATH, thisWatch, stat, true);
   try {
    callback.call(new Pair<>(data, stat));
   } catch (Exception e) {
    log.error("Error running collections node listener", e);
   }
  }
 } catch (KeeperException.ConnectionLossException | KeeperException.SessionExpiredException e) {
  log.warn("ZooKeeper watch triggered, but Solr cannot talk to ZK: [{}]", e.getMessage());
 } catch (KeeperException e) {
  log.error("A ZK error has occurred", e);
  throw new ZooKeeperException(ErrorCode.SERVER_ERROR, "", e);
 } catch (InterruptedException e) {
  // Restore the interrupted status
  Thread.currentThread().interrupt();
  log.warn("Interrupted", e);
 }
}

代码示例来源:origin: org.apache.solr/solr-test-framework

public static void waitForCollectionToDisappear(String collection,
  ZkStateReader zkStateReader, boolean verbose, boolean failOnTimeout, int timeoutSeconds)
  throws Exception {
 log.info("Wait for collection to disappear - collection: " + collection + " failOnTimeout:" + failOnTimeout + " timeout (sec):" + timeoutSeconds);
 boolean cont = true;
 int cnt = 0;
 
 while (cont) {
  if (verbose) System.out.println("-");
  ClusterState clusterState = zkStateReader.getClusterState();
  if (!clusterState.hasCollection(collection)) break;
  if (cnt == timeoutSeconds) {
   if (verbose) System.out.println("Gave up waiting for "+collection+" to disappear..");
   if (failOnTimeout) {
    Diagnostics.logThreadDumps("Gave up waiting for "+collection+" to disappear.  THREAD DUMP:");
    zkStateReader.getZkClient().printLayoutToStdOut();
    fail("The collection ("+collection+") is still present - waited for " + timeoutSeconds + " seconds");
    // won't get here
    return;
   }
   cont = false;
  } else {
   Thread.sleep(1000);
  }
  cnt++;
 }
 log.info("Collection has disappeared - collection: " + collection);
}

代码示例来源:origin: com.hynnet/solr-solrj

public static DocCollection getCollectionLive(ZkStateReader zkStateReader,
  String coll) {
 String collectionPath = getCollectionPath(coll);
 try {
  Stat stat = new Stat();
  byte[] data = zkStateReader.getZkClient().getData(collectionPath, null, stat, true);
  ClusterState state = ClusterState.load(stat.getVersion(), data,
    Collections.<String> emptySet(), collectionPath);
  ClusterState.CollectionRef collectionRef = state.getCollectionStates().get(coll);
  return collectionRef == null ? null : collectionRef.get();
 } catch (KeeperException.NoNodeException e) {
  log.warn("No node available : " + collectionPath, e);
  return null;
 } catch (KeeperException e) {
  throw new SolrException(ErrorCode.BAD_REQUEST,
    "Could not load collection from ZK:" + coll, e);
 } catch (InterruptedException e) {
  Thread.currentThread().interrupt();
  throw new SolrException(ErrorCode.BAD_REQUEST,
    "Could not load collection from ZK:" + coll, e);
 }
}

代码示例来源:origin: org.apache.solr/solr-test-framework

@Override
public void distribSetUp() throws Exception {
 super.distribSetUp();
 // ignoreException(".*");
 if (sliceCount > 0) {
  System.setProperty("numShards", Integer.toString(sliceCount));
 } else {
  System.clearProperty("numShards");
 }
 if (isSSLMode()) {
  System.clearProperty("urlScheme");
  try (ZkStateReader zkStateReader = new ZkStateReader(zkServer.getZkAddress(),
    AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT)) {
   try {
    zkStateReader.getZkClient().create(ZkStateReader.CLUSTER_PROPS,
      Utils.toJSON(Collections.singletonMap("urlScheme", "https")),
      CreateMode.PERSISTENT, true);
   } catch (KeeperException.NodeExistsException e) {
    ZkNodeProps props = ZkNodeProps.load(zkStateReader.getZkClient().getData(ZkStateReader.CLUSTER_PROPS,
      null, null, true));
    zkStateReader.getZkClient().setData(ZkStateReader.CLUSTER_PROPS, Utils.toJSON(props.plus("urlScheme", "https")), true);
   }
  }
 }
 if (useTlogReplicas()) {
  log.info("Will use {} replicas unless explicitly asked otherwise", Replica.Type.TLOG);
 } else {
  log.info("Will use {} replicas unless explicitly asked otherwise", Replica.Type.NRT);
 }
}

代码示例来源:origin: org.apache.solr/solr-solrj

/**
 * Returns the content of /security.json from ZooKeeper as a Map
 * If the files doesn't exist, it returns null.
 */
public ConfigData getSecurityProps(boolean getFresh) {
 if (!getFresh) {
  if (securityData == null) return new ConfigData(EMPTY_MAP,-1);
  return new ConfigData(securityData.data, securityData.version);
 }
 try {
  Stat stat = new Stat();
  if(getZkClient().exists(SOLR_SECURITY_CONF_PATH, true)) {
   final byte[] data = getZkClient().getData(ZkStateReader.SOLR_SECURITY_CONF_PATH, null, stat, true);
   return data != null && data.length > 0 ?
     new ConfigData((Map<String, Object>) Utils.fromJSON(data), stat.getVersion()) :
     null;
  }
 } catch (InterruptedException e) {
  Thread.currentThread().interrupt();
  throw new SolrException(ErrorCode.SERVER_ERROR,"Error reading security properties", e) ;
 } catch (KeeperException e) {
  throw new SolrException(ErrorCode.SERVER_ERROR,"Error reading security properties", e) ;
 }
 return null;
}

代码示例来源:origin: org.apache.solr/solr-test-framework

/**
 * Configure, run and return the {@link MiniSolrCloudCluster}
 * @throws Exception if an error occurs on startup
 */
public MiniSolrCloudCluster build() throws Exception {
 MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(nodeCount, baseDir, solrxml, jettyConfig, null, securityJson);
 CloudSolrClient client = cluster.getSolrClient();
 for (Config config : configs) {
  ((ZkClientClusterStateProvider)client.getClusterStateProvider()).uploadConfig(config.path, config.name);
 }
 if (clusterProperties.size() > 0) {
  ClusterProperties props = new ClusterProperties(cluster.getSolrClient().getZkStateReader().getZkClient());
  for (Map.Entry<String, String> entry : clusterProperties.entrySet()) {
   props.setClusterProperty(entry.getKey(), entry.getValue());
  }
 }
 return cluster;
}

代码示例来源:origin: com.hynnet/solr-solrj

/**
 * Returns the content of /security.json from ZooKeeper as a Map
 * If the files doesn't exist, it returns null.
 */
public ConfigData getSecurityProps(boolean getFresh) {
 if (!getFresh) {
  if (securityData == null) return new ConfigData(EMPTY_MAP, -1);
  return new ConfigData(securityData.data, securityData.version);
 }
 try {
  Stat stat = new Stat();
  if(getZkClient().exists(SOLR_SECURITY_CONF_PATH, true)) {
   byte[] data = getZkClient()
     .getData(ZkStateReader.SOLR_SECURITY_CONF_PATH, null, stat, true);
   return data != null && data.length > 0 ?
     new ConfigData((Map<String, Object>) Utils.fromJSON(data), stat.getVersion()) :
     null;
  }
 } catch (KeeperException | InterruptedException e) {
  throw new SolrException(ErrorCode.SERVER_ERROR,"Error reading security properties",e) ;
 }
 return null;
}
/**

代码示例来源:origin: org.apache.solr/solr-test-framework

if (failOnTimeout) {
 Diagnostics.logThreadDumps("Gave up waiting for recovery to finish.  THREAD DUMP:");
 zkStateReader.getZkClient().printLayoutToStdOut();
 fail("There are still nodes recoverying - waited for " + timeoutSeconds + " seconds");

代码示例来源:origin: org.apache.solr/solr-test-framework

/** Delete all collections (and aliases) */
public void deleteAllCollections() throws Exception {
 try (ZkStateReader reader = new ZkStateReader(solrClient.getZkStateReader().getZkClient())) {
  reader.createClusterStateWatchersAndUpdate(); // up to date aliases & collections
  reader.aliasesManager.applyModificationAndExportToZk(aliases -> Aliases.EMPTY);
  for (String collection : reader.getClusterState().getCollectionStates().keySet()) {
   CollectionAdminRequest.deleteCollection(collection).process(solrClient);
  }
 }
}

代码示例来源:origin: org.apache.solr/solr-test-framework

protected static SolrZkClient zkClient() {
 ZkStateReader reader = cluster.getSolrClient().getZkStateReader();
 if (reader == null)
  cluster.getSolrClient().connect();
 return cluster.getSolrClient().getZkStateReader().getZkClient();
}

代码示例来源:origin: keeps/roda

private static void createCollection(CloudSolrClient cloudSolrClient, String collection, Path configPath) {
 try {
  LOGGER.info("Creating SOLR collection {}", collection);
  int numShards = getEnvInt("SOLR_NUM_SHARDS", 1);
  int numReplicas = getEnvInt("SOLR_REPLICATION_FACTOR", 1);
  cloudSolrClient.getZkStateReader().getZkClient().upConfig(configPath, collection);
  Create createCollection = CollectionAdminRequest.createCollection(collection, collection, numShards, numReplicas);
  createCollection.setMaxShardsPerNode(getEnvInt("SOLR_MAX_SHARDS_PER_NODE", 1));
  createCollection.setAutoAddReplicas(getEnvBoolean("SOLR_AUTO_ADD_REPLICAS", false));
  CollectionAdminResponse response = createCollection.process(cloudSolrClient);
  if (!response.isSuccess()) {
   LOGGER.error("Could not create collection {}: {}", collection, response.getErrorMessages());
  }
 } catch (SolrServerException | SolrException | IOException e) {
  LOGGER.error("Error creating collection {}", collection, e);
 }
}

代码示例来源:origin: org.apache.solr/solr-test-framework

protected void assertCollectionNotExists(String collectionName, int timeoutSeconds) throws Exception {
 waitForCollectionToDisappear(collectionName, getCommonCloudSolrClient().getZkStateReader(), false, true, timeoutSeconds);
 assertFalse(cloudClient.getZkStateReader().getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true));
}

代码示例来源:origin: org.apache.jackrabbit/oak-solr-core

private void createCollectionIfNeeded(CloudSolrClient cloudSolrServer) throws SolrServerException {
  String solrCollection = remoteSolrServerConfiguration.getSolrCollection();
  ZkStateReader zkStateReader = cloudSolrServer.getZkStateReader();
  SolrZkClient zkClient = zkStateReader.getZkClient();
  log.debug("creating {} collection if needed", solrCollection);
  try {

代码示例来源:origin: apache/jackrabbit-oak

private void createCollectionIfNeeded(CloudSolrClient cloudSolrServer) throws SolrServerException {
  String solrCollection = remoteSolrServerConfiguration.getSolrCollection();
  ZkStateReader zkStateReader = cloudSolrServer.getZkStateReader();
  SolrZkClient zkClient = zkStateReader.getZkClient();
  log.debug("creating {} collection if needed", solrCollection);
  try {

代码示例来源:origin: org.apache.solr/solr-test-framework

static void waitForNewLeader(CloudSolrClient cloudClient, String shardName, Replica oldLeader, TimeOut timeOut)
  throws Exception {
 log.info("Will wait for a node to become leader for {} secs", timeOut.timeLeft(SECONDS));
 ZkStateReader zkStateReader = cloudClient.getZkStateReader();
 zkStateReader.forceUpdateCollection(DEFAULT_COLLECTION);
 for (; ; ) {
  ClusterState clusterState = zkStateReader.getClusterState();
  DocCollection coll = clusterState.getCollection("collection1");
  Slice slice = coll.getSlice(shardName);
  if (slice.getLeader() != null && !slice.getLeader().equals(oldLeader) && slice.getLeader().getState() == Replica.State.ACTIVE) {
   log.info("Old leader {}, new leader {}. New leader got elected in {} ms", oldLeader, slice.getLeader(),timeOut.timeElapsed(MILLISECONDS) );
   break;
  }
  if (timeOut.hasTimedOut()) {
   Diagnostics.logThreadDumps("Could not find new leader in specified timeout");
   zkStateReader.getZkClient().printLayoutToStdOut();
   fail("Could not find new leader even after waiting for " + timeOut.timeElapsed(MILLISECONDS) + "ms");
  }
  Thread.sleep(100);
 }
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-io-solr

ZkStateReader zkStateReader = cluster.getSolrClient().getZkStateReader();
zkStateReader
  .getZkClient()
  .setData("/security.json", securityJson.getBytes(Charset.defaultCharset()), true);
String zkAddress = cluster.getZkServer().getZkAddress();

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com