当前位置: 首页>>代码示例>>Java>>正文


Java ZkStateReader.fromJSON方法代码示例

本文整理汇总了Java中org.apache.solr.common.cloud.ZkStateReader.fromJSON方法的典型用法代码示例。如果您正苦于以下问题:Java ZkStateReader.fromJSON方法的具体用法?Java ZkStateReader.fromJSON怎么用?Java ZkStateReader.fromJSON使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.common.cloud.ZkStateReader的用法示例。


在下文中一共展示了ZkStateReader.fromJSON方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkOverseerDesignate

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
public void checkOverseerDesignate() {
  try {
    byte[] data = zkClient.getData(ZkStateReader.ROLES, null, new Stat(), true);
    if(data ==null) return;
    Map roles = (Map) ZkStateReader.fromJSON(data);
    if(roles ==null) return;
    List nodeList= (List) roles.get("overseer");
    if(nodeList == null) return;
    if(nodeList.contains(getNodeName())){
      ZkNodeProps props = new ZkNodeProps(Overseer.QUEUE_OPERATION, CollectionParams.CollectionAction.ADDROLE.toString().toLowerCase(Locale.ROOT),
          "node", getNodeName(),
          "role", "overseer");
      log.info("Going to add role {} ",props);
      getOverseerCollectionQueue().offer(ZkStateReader.toJSON(props));
    }
  } catch (NoNodeException nne){
    return;
  } catch (Exception e) {
    log.warn("could not readd the overseer designate ",e);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:ZkController.java

示例2: prioritizeOverseerNodes

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
private synchronized void prioritizeOverseerNodes() throws KeeperException, InterruptedException {
  SolrZkClient zk = zkStateReader.getZkClient();
  if(!zk.exists(ZkStateReader.ROLES,true))return;
  Map m = (Map) ZkStateReader.fromJSON(zk.getData(ZkStateReader.ROLES, null, new Stat(), true));

  List overseerDesignates = (List) m.get("overseer");
  if(overseerDesignates==null || overseerDesignates.isEmpty()) return;
  String ldr = getLeaderNode(zk);
  if(overseerDesignates.contains(ldr)) return;
  log.info("prioritizing overseer nodes at {} overseer designates are {}", myId, overseerDesignates);
  List<String> electionNodes = getSortedElectionNodes(zk);
  if(electionNodes.size()<2) return;
  log.info("sorted nodes {}", electionNodes);

  String designateNodeId = null;
  for (String electionNode : electionNodes) {
    if(overseerDesignates.contains( LeaderElector.getNodeName(electionNode))){
      designateNodeId = electionNode;
      break;
    }
  }

  if(designateNodeId == null){
    log.warn("No live overseer designate ");
    return;
  }
  if(!designateNodeId.equals( electionNodes.get(1))) { //checking if it is already at no:1
    log.info("asking node {} to come join election at head", designateNodeId);
    invokeOverseerOp(designateNodeId, "rejoinAtHead"); //ask designate to come first
    log.info("asking the old first in line {} to rejoin election  ",electionNodes.get(1) );
    invokeOverseerOp(electionNodes.get(1), "rejoin");//ask second inline to go behind
  }
  //now ask the current leader to QUIT , so that the designate can takeover
  Overseer.getInQueue(zkStateReader.getZkClient()).offer(
      ZkStateReader.toJSON(new ZkNodeProps(Overseer.QUEUE_OPERATION, Overseer.QUIT,
          "id",getLeaderId(zkStateReader.getZkClient()))));

}
 
开发者ID:europeana,项目名称:search,代码行数:39,代码来源:OverseerCollectionProcessor.java

示例3: getLeaderId

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
public static String getLeaderId(SolrZkClient zkClient) throws KeeperException,InterruptedException{
  byte[] data = null;
  try {
    data = zkClient.getData("/overseer_elect/leader", null, new Stat(), true);
  } catch (KeeperException.NoNodeException e) {
    return null;
  }
  Map m = (Map) ZkStateReader.fromJSON(data);
  return  (String) m.get("id");
}
 
开发者ID:europeana,项目名称:search,代码行数:11,代码来源:OverseerCollectionProcessor.java

示例4: testQuitCommand

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
private void testQuitCommand() throws Exception{
  String collectionName = "testOverseerQuit";

  createCollection(collectionName, client);

  waitForRecoveriesToFinish(collectionName, false);

  SolrZkClient zk = client.getZkStateReader().getZkClient();
  byte[] data = new byte[0];
  data = zk.getData("/overseer_elect/leader", null, new Stat(), true);
  Map m = (Map) ZkStateReader.fromJSON(data);
  String s = (String) m.get("id");
  String leader = LeaderElector.getNodeName(s);
  Overseer.getInQueue(zk).offer(ZkStateReader.toJSON(new ZkNodeProps(Overseer.QUEUE_OPERATION, Overseer.QUIT)));
  long timeout = System.currentTimeMillis()+10000;
  String newLeader=null;
  for(;System.currentTimeMillis() < timeout;){
    newLeader = OverseerCollectionProcessor.getLeaderNode(zk);
    if(newLeader!=null && !newLeader.equals(leader)) break;
    Thread.sleep(100);
  }
  assertNotSame( "Leader not changed yet",newLeader,leader);



  assertTrue("The old leader should have rejoined election ", OverseerCollectionProcessor.getSortedOverseerNodeNames(zk).contains(leader));
}
 
开发者ID:europeana,项目名称:search,代码行数:28,代码来源:OverseerRolesTest.java

示例5: getLeaderInitiatedRecoveryStateObject

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
public Map<String,Object> getLeaderInitiatedRecoveryStateObject(String collection, String shardId, String coreNodeName) {

    if (collection == null || shardId == null || coreNodeName == null)
      return null; // if we don't have complete data about a core in cloud mode, return null
    
    String znodePath = getLeaderInitiatedRecoveryZnodePath(collection, shardId, coreNodeName);
    byte[] stateData = null;
    try {
      stateData = zkClient.getData(znodePath, null, new Stat(), false);
    } catch (NoNodeException ignoreMe) {
      // safe to ignore as this znode will only exist if the leader initiated recovery
    } catch (ConnectionLossException cle) {
      // sort of safe to ignore ??? Usually these are seen when the core is going down
      // or there are bigger issues to deal with than reading this znode
      log.warn("Unable to read "+znodePath+" due to: "+cle);
    } catch (SessionExpiredException see) {
      // sort of safe to ignore ??? Usually these are seen when the core is going down
      // or there are bigger issues to deal with than reading this znode
      log.warn("Unable to read "+znodePath+" due to: "+see);
    } catch (Exception exc) {
      log.error("Failed to read data from znode "+znodePath+" due to: "+exc);
      if (exc instanceof SolrException) {
        throw (SolrException)exc;
      } else {
        throw new SolrException(ErrorCode.SERVER_ERROR, 
            "Failed to read data from znodePath: "+znodePath, exc);
      }
    }

    Map<String,Object> stateObj = null;
    if (stateData != null && stateData.length > 0) {
      // TODO: Remove later ... this is for upgrading from 4.8.x to 4.10.3 (see: SOLR-6732)
      if (stateData[0] == (byte)'{') {
        Object parsedJson = ZkStateReader.fromJSON(stateData);
        if (parsedJson instanceof Map) {
          stateObj = (Map<String,Object>)parsedJson;
        } else {
          throw new SolrException(ErrorCode.SERVER_ERROR, "Leader-initiated recovery state data is invalid! "+parsedJson);
        }
      } else {
        // old format still in ZK
        stateObj = ZkNodeProps.makeMap("state", new String(stateData, StandardCharsets.UTF_8));
      }
    }

    return stateObj;
  }
 
开发者ID:europeana,项目名称:search,代码行数:48,代码来源:ZkController.java

示例6: processRoleCommand

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
private void processRoleCommand(ZkNodeProps message, String operation) throws KeeperException, InterruptedException {
  SolrZkClient zkClient = zkStateReader.getZkClient();
  Map roles = null;
  String node = message.getStr("node");

  String roleName = message.getStr("role");
  boolean nodeExists = false;
  if(nodeExists = zkClient.exists(ZkStateReader.ROLES, true)){
    roles = (Map) ZkStateReader.fromJSON(zkClient.getData(ZkStateReader.ROLES, null, new Stat(), true));
  } else {
    roles = new LinkedHashMap(1);
  }

  List nodeList= (List) roles.get(roleName);
  if(nodeList == null) roles.put(roleName, nodeList = new ArrayList());
  if(ADDROLE.toString().toLowerCase(Locale.ROOT).equals(operation) ){
    log.info("Overseer role added to {}", node);
    if(!nodeList.contains(node)) nodeList.add(node);
  } else if(REMOVEROLE.toString().toLowerCase(Locale.ROOT).equals(operation)) {
    log.info("Overseer role removed from {}", node);
    nodeList.remove(node);
  }

  if(nodeExists){
    zkClient.setData(ZkStateReader.ROLES, ZkStateReader.toJSON(roles),true);
  } else {
    zkClient.create(ZkStateReader.ROLES, ZkStateReader.toJSON(roles), CreateMode.PERSISTENT,true);
  }
  //if there are too many nodes this command may time out. And most likely dedicated
  // overseers are created when there are too many nodes  . So , do this operation in a separate thread
  new Thread(){
    @Override
    public void run() {
      try {
        prioritizeOverseerNodes();
      } catch (Exception e) {
        log.error("Error in prioritizing Overseer",e);
      }

    }
  }.start();
}
 
开发者ID:europeana,项目名称:search,代码行数:43,代码来源:OverseerCollectionProcessor.java


注:本文中的org.apache.solr.common.cloud.ZkStateReader.fromJSON方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。