Examples of BestPossibleStateOutput


Examples of com.linkedin.helix.controller.stages.BestPossibleStateOutput

          idealStates.put(resource, new IdealState(resource));
        }
      }
     
      // calculate best possible state
      BestPossibleStateOutput bestPossOutput =
          ClusterStateVerifier.calcBestPossState(cache);

      // set error states
      if (errStates != null)
      {
        for (String resourceName : errStates.keySet())
        {
          Map<String, String> partErrStates = errStates.get(resourceName);
          for (String partitionName : partErrStates.keySet())
          {
            String instanceName = partErrStates.get(partitionName);
            Map<String, String> partStateMap =
                bestPossOutput.getInstanceStateMap(resourceName,
                                                   new Partition(partitionName));
            partStateMap.put(instanceName, "ERROR");
          }
        }
      }

     
      for (String resourceName : idealStates.keySet())
      {
        ExternalView extView = extViews.get(resourceName);
        if (extView == null)
        {
          LOG.info("externalView for " + resourceName + " is not available");
          return false;
        }

        // step 0: remove empty map and DROPPED state from best possible state
        Map<Partition, Map<String, String>> bpStateMap =
            bestPossOutput.getResourceMap(resourceName);
        Iterator<Entry<Partition, Map<String, String>>> iter =
            bpStateMap.entrySet().iterator();
        while (iter.hasNext())
        {
          Map.Entry<Partition, Map<String, String>> entry = iter.next();
          Map<String, String> instanceStateMap = entry.getValue();
          if (instanceStateMap.isEmpty())
          {
            iter.remove();
          } else
          {
            // remove instances with DROPPED state
            Iterator<Map.Entry<String, String>> insIter = instanceStateMap.entrySet().iterator();
            while (insIter.hasNext())
            {
              Map.Entry<String, String> insEntry = insIter.next();
              String state = insEntry.getValue();
              if (state.equalsIgnoreCase("DROPPED"))
              {
                insIter.remove();
              }  
            }
          }
        }

        // System.err.println("resource: " + resourceName + ", bpStateMap: " + bpStateMap);

        // step 1: externalView and bestPossibleState has equal size
        int extViewSize = extView.getRecord().getMapFields().size();
        int bestPossStateSize = bestPossOutput.getResourceMap(resourceName).size();
        if (extViewSize != bestPossStateSize)
        {
          LOG.info("exterView size (" + extViewSize
              + ") is different from bestPossState size (" + bestPossStateSize
              + ") for resource: " + resourceName);
          // System.out.println("extView: " + extView.getRecord().getMapFields());
          // System.out.println("bestPossState: " +
          // bestPossOutput.getResourceMap(resourceName));
          return false;
        }

        // step 2: every entry in external view is contained in best possible state
        for (String partition : extView.getRecord().getMapFields().keySet())
        {
          Map<String, String> evInstanceStateMap =
              extView.getRecord().getMapField(partition);
          Map<String, String> bpInstanceStateMap =
              bestPossOutput.getInstanceStateMap(resourceName, new Partition(partition));

          boolean result =
              ClusterStateVerifier.<String, String> compareMap(evInstanceStateMap,
                                                               bpInstanceStateMap);
          if (result == false)
View Full Code Here

Examples of com.linkedin.helix.controller.stages.BestPossibleStateOutput

    runStage(event, rcState);
    runStage(event, csStage);
    runStage(event, bpStage);

    BestPossibleStateOutput output =
        event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.toString());

    // System.out.println("output:" + output);
    return output;
  }
View Full Code Here

Examples of com.linkedin.helix.controller.stages.BestPossibleStateOutput

    ReadClusterDataStage stage1 = new ReadClusterDataStage();
    runStage(event, stage1);
    BestPossibleStateCalcStage stage2 = new BestPossibleStateCalcStage();
    runStage(event, stage2);

    BestPossibleStateOutput output = event
        .getAttribute(AttributeName.BEST_POSSIBLE_STATE.toString());
    for (int p = 0; p < 5; p++)
    {
      Partition resource = new Partition("testResourceName_" + p);
      AssertJUnit.assertEquals(
          "MASTER",
          output.getInstanceStateMap("testResourceName", resource).get(
              "localhost_" + (p + 1) % 5));
    }
    System.out.println("END TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
  }
View Full Code Here

Examples of org.apache.helix.controller.stages.BestPossibleStateOutput

          idealStates.put(resource, new IdealState(resource));
        }
      }
     
      // calculate best possible state
      BestPossibleStateOutput bestPossOutput =
          ClusterStateVerifier.calcBestPossState(cache);

      // set error states
      if (errStates != null)
      {
        for (String resourceName : errStates.keySet())
        {
          Map<String, String> partErrStates = errStates.get(resourceName);
          for (String partitionName : partErrStates.keySet())
          {
            String instanceName = partErrStates.get(partitionName);
            Map<String, String> partStateMap =
                bestPossOutput.getInstanceStateMap(resourceName,
                                                   new Partition(partitionName));
            partStateMap.put(instanceName, "ERROR");
          }
        }
      }

     
      for (String resourceName : idealStates.keySet())
      {
        ExternalView extView = extViews.get(resourceName);
        if (extView == null)
        {
          LOG.info("externalView for " + resourceName + " is not available");
          return false;
        }

        // step 0: remove empty map and DROPPED state from best possible state
        Map<Partition, Map<String, String>> bpStateMap =
            bestPossOutput.getResourceMap(resourceName);
        Iterator<Entry<Partition, Map<String, String>>> iter =
            bpStateMap.entrySet().iterator();
        while (iter.hasNext())
        {
          Map.Entry<Partition, Map<String, String>> entry = iter.next();
          Map<String, String> instanceStateMap = entry.getValue();
          if (instanceStateMap.isEmpty())
          {
            iter.remove();
          } else
          {
            // remove instances with DROPPED state
            Iterator<Map.Entry<String, String>> insIter = instanceStateMap.entrySet().iterator();
            while (insIter.hasNext())
            {
              Map.Entry<String, String> insEntry = insIter.next();
              String state = insEntry.getValue();
              if (state.equalsIgnoreCase("DROPPED"))
              {
                insIter.remove();
              }  
            }
          }
        }

        // System.err.println("resource: " + resourceName + ", bpStateMap: " + bpStateMap);

        // step 1: externalView and bestPossibleState has equal size
        int extViewSize = extView.getRecord().getMapFields().size();
        int bestPossStateSize = bestPossOutput.getResourceMap(resourceName).size();
        if (extViewSize != bestPossStateSize)
        {
          LOG.info("exterView size (" + extViewSize
              + ") is different from bestPossState size (" + bestPossStateSize
              + ") for resource: " + resourceName);
          // System.out.println("extView: " + extView.getRecord().getMapFields());
          // System.out.println("bestPossState: " +
          // bestPossOutput.getResourceMap(resourceName));
          return false;
        }

        // step 2: every entry in external view is contained in best possible state
        for (String partition : extView.getRecord().getMapFields().keySet())
        {
          Map<String, String> evInstanceStateMap =
              extView.getRecord().getMapField(partition);
          Map<String, String> bpInstanceStateMap =
              bestPossOutput.getInstanceStateMap(resourceName, new Partition(partition));

          boolean result =
              ClusterStateVerifier.<String, String> compareMap(evInstanceStateMap,
                                                               bpInstanceStateMap);
          if (result == false)
View Full Code Here

Examples of org.apache.helix.controller.stages.BestPossibleStateOutput

    runStage(event, rcState);
    runStage(event, csStage);
    runStage(event, bpStage);

    BestPossibleStateOutput output =
        event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.toString());

    // System.out.println("output:" + output);
    return output;
  }
View Full Code Here

Examples of org.apache.helix.controller.stages.BestPossibleStateOutput

    ReadClusterDataStage stage1 = new ReadClusterDataStage();
    runStage(event, stage1);
    BestPossibleStateCalcStage stage2 = new BestPossibleStateCalcStage();
    runStage(event, stage2);

    BestPossibleStateOutput output = event
        .getAttribute(AttributeName.BEST_POSSIBLE_STATE.toString());
    for (int p = 0; p < 5; p++)
    {
      Partition resource = new Partition("testResourceName_" + p);
      AssertJUnit.assertEquals(
          "MASTER",
          output.getInstanceStateMap("testResourceName", resource).get(
              "localhost_" + (p + 1) % 5));
    }
    System.out.println("END TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
  }
View Full Code Here

Examples of org.apache.helix.controller.stages.BestPossibleStateOutput

          idealStates.put(resource, new IdealState(resource));
        }
      }

      // calculate best possible state
      BestPossibleStateOutput bestPossOutput = ClusterStateVerifier.calcBestPossState(cache);
      Map<String, Map<Partition, Map<String, String>>> bestPossStateMap =
          bestPossOutput.getStateMap();

      // set error states
      if (errStates != null) {
        for (String resourceName : errStates.keySet()) {
          Map<String, String> partErrStates = errStates.get(resourceName);
          for (String partitionName : partErrStates.keySet()) {
            String instanceName = partErrStates.get(partitionName);

            if (!bestPossStateMap.containsKey(resourceName)) {
              bestPossStateMap.put(resourceName, new HashMap<Partition, Map<String, String>>());
            }
            Partition partition = new Partition(partitionName);
            if (!bestPossStateMap.get(resourceName).containsKey(partition)) {
              bestPossStateMap.get(resourceName).put(partition, new HashMap<String, String>());
            }
            bestPossStateMap.get(resourceName).get(partition)
                .put(instanceName, HelixDefinedState.ERROR.toString());
          }
        }
      }

      // System.out.println("stateMap: " + bestPossStateMap);

      for (String resourceName : idealStates.keySet()) {
        ExternalView extView = extViews.get(resourceName);
        if (extView == null) {
          LOG.info("externalView for " + resourceName + " is not available");
          return false;
        }

        // step 0: remove empty map and DROPPED state from best possible state
        Map<Partition, Map<String, String>> bpStateMap =
            bestPossOutput.getResourceMap(resourceName);
        Iterator<Entry<Partition, Map<String, String>>> iter = bpStateMap.entrySet().iterator();
        while (iter.hasNext()) {
          Map.Entry<Partition, Map<String, String>> entry = iter.next();
          Map<String, String> instanceStateMap = entry.getValue();
          if (instanceStateMap.isEmpty()) {
            iter.remove();
          } else {
            // remove instances with DROPPED state
            Iterator<Map.Entry<String, String>> insIter = instanceStateMap.entrySet().iterator();
            while (insIter.hasNext()) {
              Map.Entry<String, String> insEntry = insIter.next();
              String state = insEntry.getValue();
              if (state.equalsIgnoreCase(HelixDefinedState.DROPPED.toString())) {
                insIter.remove();
              }
            }
          }
        }

        // System.err.println("resource: " + resourceName + ", bpStateMap: " + bpStateMap);

        // step 1: externalView and bestPossibleState has equal size
        int extViewSize = extView.getRecord().getMapFields().size();
        int bestPossStateSize = bestPossOutput.getResourceMap(resourceName).size();
        if (extViewSize != bestPossStateSize) {
          LOG.info("exterView size (" + extViewSize + ") is different from bestPossState size ("
              + bestPossStateSize + ") for resource: " + resourceName);

          // System.err.println("exterView size (" + extViewSize
          // + ") is different from bestPossState size (" + bestPossStateSize
          // + ") for resource: " + resourceName);
          // System.out.println("extView: " + extView.getRecord().getMapFields());
          // System.out.println("bestPossState: " +
          // bestPossOutput.getResourceMap(resourceName));
          return false;
        }

        // step 2: every entry in external view is contained in best possible state
        for (String partition : extView.getRecord().getMapFields().keySet()) {
          Map<String, String> evInstanceStateMap = extView.getRecord().getMapField(partition);
          Map<String, String> bpInstanceStateMap =
              bestPossOutput.getInstanceStateMap(resourceName, new Partition(partition));

          boolean result =
              ClusterStateVerifier.<String, String> compareMap(evInstanceStateMap,
                  bpInstanceStateMap);
          if (result == false) {
View Full Code Here

Examples of org.apache.helix.controller.stages.BestPossibleStateOutput

    runStage(event, rcState);
    runStage(event, csStage);
    runStage(event, bpStage);

    BestPossibleStateOutput output =
        event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.toString());

    // System.out.println("output:" + output);
    return output;
  }
View Full Code Here

Examples of org.apache.helix.controller.stages.BestPossibleStateOutput

    ReadClusterDataStage stage1 = new ReadClusterDataStage();
    runStage(event, stage1);
    BestPossibleStateCalcStage stage2 = new BestPossibleStateCalcStage();
    runStage(event, stage2);

    BestPossibleStateOutput output =
        event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.toString());
    for (int p = 0; p < 5; p++) {
      Partition resource = new Partition("testResourceName_" + p);
      AssertJUnit.assertEquals("MASTER", output.getInstanceStateMap("testResourceName", resource)
          .get("localhost_" + (p + 1) % 5));
    }
    System.out.println("END TestBestPossibleStateCalcStage at "
        + new Date(System.currentTimeMillis()));
  }
View Full Code Here

Examples of org.apache.helix.controller.stages.BestPossibleStateOutput

      LOG.info("liveNodes not match, expect: " + _expectSortedLiveNodes + ", actual: "
          + liveInstances);
      return false;
    }

    BestPossibleStateOutput bestPossbileStates = calculateBestPossibleState(cache);
    Map<String, ExternalView> externalViews =
        _accessor.getChildValuesMap(_keyBuilder.externalViews());

    // TODO all ideal-states should be included in external-views

    for (String resourceName : externalViews.keySet()) {
      ExternalView externalView = externalViews.get(resourceName);
      Map<Partition, Map<String, String>> bestPossbileState =
          bestPossbileStates.getResourceMap(resourceName);
      success = verifyExternalView(externalView, bestPossbileState);
      if (!success) {
        LOG.info("external-view for resource: " + resourceName + " not match");
        return false;
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.