Ejemplo n.º 1
0
 public StaticFileHelixManager(
     String clusterName, String instanceName, InstanceType instanceType, String clusterViewFile) {
   _clusterName = clusterName;
   _instanceName = instanceName;
   _instanceType = instanceType;
   _clusterView = ClusterViewSerializer.deserialize(new File(clusterViewFile));
 }
Ejemplo n.º 2
0
  public static ClusterView convertStateModelMapToClusterView(
      String outFile, String instanceName, StateModelFactory<StateModel> stateModelFactory) {
    Map<String, StateModel> currentStateMap = stateModelFactory.getStateModelMap();
    ClusterView curView = new ClusterView();

    ClusterView.MemberInstance memberInstance = curView.getMemberInstance(instanceName, true);
    List<ZNRecord> curStateList = new ArrayList<ZNRecord>();

    for (Map.Entry<String, StateModel> entry : currentStateMap.entrySet()) {
      String stateUnitKey = entry.getKey();
      String curState = entry.getValue().getCurrentState();
      ZNRecord record = new ZNRecord(stateUnitKey);
      record.setSimpleField(stateUnitKey, curState);
      curStateList.add(record);
    }

    memberInstance.setInstanceProperty(PropertyType.CURRENTSTATES, curStateList);

    // serialize to file
    // String outFile = "/tmp/curClusterView_" + instanceName +".json";
    if (outFile != null) {
      // ClusterViewSerializer serializer = new
      // ClusterViewSerializer(outFile);
      // serializer.serialize(curView);
      ClusterViewSerializer.serialize(curView, new File(outFile));
    }

    return curView;
  }
Ejemplo n.º 3
0
  public static boolean verifyFileBasedClusterStates(
      String instanceName, String expectedFile, String curFile) {
    boolean ret = true;
    ClusterView expectedView = ClusterViewSerializer.deserialize(new File(expectedFile));
    ClusterView curView = ClusterViewSerializer.deserialize(new File(curFile));

    // ideal_state for instance with the given instanceName
    Map<String, String> idealStates = new HashMap<String, String>();
    for (ZNRecord idealStateItem : expectedView.getPropertyList(PropertyType.IDEALSTATES)) {
      Map<String, Map<String, String>> allIdealStates = idealStateItem.getMapFields();

      for (Map.Entry<String, Map<String, String>> entry : allIdealStates.entrySet()) {
        if (entry.getValue().containsKey(instanceName)) {
          String state = entry.getValue().get(instanceName);
          idealStates.put(entry.getKey(), state);
        }
      }
    }

    ClusterView.MemberInstance memberInstance = curView.getMemberInstance(instanceName, false);
    List<ZNRecord> curStateList = memberInstance.getInstanceProperty(PropertyType.CURRENTSTATES);

    if (curStateList == null && idealStates.size() > 0) {
      LOG.info("current state is null");
      return false;
    } else if (curStateList == null && idealStates.size() == 0) {
      LOG.info("empty current state and ideal state");
      return true;
    } else if (curStateList.size() != idealStates.size()) {
      LOG.info(
          "Number of current states ("
              + curStateList.size()
              + ") mismatch "
              + "number of ideal states ("
              + idealStates.size()
              + ")");
      return false;
    }

    for (ZNRecord record : curStateList) {
      String stateUnitKey = record.getId();
      String curState = record.getSimpleField(stateUnitKey);

      // if (!curState.equalsIgnoreCase("offline"))
      // nonOfflineNr++;

      if (!idealStates.containsKey(stateUnitKey)) {
        LOG.error("Current state does not contain " + stateUnitKey);
        ret = false;
        continue;
      }

      String idealState = idealStates.get(stateUnitKey);
      if (!curState.equalsIgnoreCase(idealState)) {
        LOG.error(
            "State mismatch--unit_key:"
                + stateUnitKey
                + " cur:"
                + curState
                + " ideal:"
                + idealState
                + " instance_name:"
                + instanceName);
        ret = false;
        continue;
      }
    }

    return ret;
  }