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


Java IdealState.getRebalanceMode方法代码示例

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


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

示例1: matches

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Override
public boolean matches(Object o) {
  if (o == null || !(o instanceof IdealState)) {
    return false;
  }
  IdealState is = (IdealState)o;
  if (is.getRebalanceMode() != IdealState.RebalanceMode.CUSTOMIZED ||
      !is.getReplicas().equals("3") ||
      is.getNumPartitions() != this.numPartitions ||
      !is.getStateModelDefRef().equals("OnlineOffline")) {
    return false;
  }
  for (Map.Entry<Integer, List<String>> entry : partitionHostMap.entrySet()) {
    Map<String, String> stateMap = is.getInstanceStateMap(
            this.resource + "$" + entry.getKey());
    if (stateMap.size() != entry.getValue().size()) {
      return false;
    }
    for (String host : entry.getValue()) {
      if (!(stateMap.containsKey(host) && stateMap.get(host).equals("ONLINE"))) {
        return false;
      }
    }
  }
  return true;
}
 
开发者ID:pinterest-attic,项目名称:terrapin,代码行数:27,代码来源:HdfsManagerTest.java

示例2: expandResource

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public void expandResource(String clusterName, String resourceName) {
  IdealState idealState = _admin.getResourceIdealState(clusterName, resourceName);
  if (idealState.getRebalanceMode() == RebalanceMode.FULL_AUTO
      || idealState.getRebalanceMode() == RebalanceMode.CUSTOMIZED) {
    _logger.info("Skipping idealState " + idealState.getResourceName() + " "
        + idealState.getRebalanceMode());
    return;
  }
  boolean anyLiveInstance = false;
  for (List<String> list : idealState.getRecord().getListFields().values()) {
    if (list.contains(IdealState.IdealStateConstants.ANY_LIVEINSTANCE.toString())) {
      _logger.info("Skipping idealState " + idealState.getResourceName()
          + " with ANY_LIVEINSTANCE");
      anyLiveInstance = true;
      continue;
    }
  }
  if (anyLiveInstance) {
    return;
  }
  try {
    int replica = Integer.parseInt(idealState.getReplicas());
  } catch (Exception e) {
    _logger.error("", e);
    return;
  }
  if (idealState.getRecord().getListFields().size() == 0) {
    _logger.warn("Resource " + resourceName + " not balanced, skip");
    return;
  }
  balanceIdealState(clusterName, idealState);
}
 
开发者ID:apache,项目名称:helix,代码行数:33,代码来源:ClusterSetup.java

示例3: verifyExternalView

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private boolean verifyExternalView(ClusterDataCache dataCache, ExternalView externalView,
    IdealState idealState) {
  Map<String, Map<String, String>> mappingInExtview = externalView.getRecord().getMapFields();
  Map<String, Map<String, String>> idealPartitionState;

  switch (idealState.getRebalanceMode()) {
  case FULL_AUTO:
    ClusterConfig clusterConfig = new ConfigAccessor(_zkClient).getClusterConfig(dataCache.getClusterName());
    if (!clusterConfig.isPersistBestPossibleAssignment() && !clusterConfig.isPersistIntermediateAssignment()) {
      throw new HelixException(String.format("Full-Auto IdealState verifier requires "
          + "ClusterConfig.PERSIST_BEST_POSSIBLE_ASSIGNMENT or ClusterConfig.PERSIST_INTERMEDIATE_ASSIGNMENT "
          + "is enabled."));
    }
    for (String partition : idealState.getPartitionSet()) {
      if (idealState.getPreferenceList(partition) == null || idealState.getPreferenceList(partition).isEmpty()) {
        return false;
      }
    }
    idealPartitionState = computeIdealPartitionState(dataCache, idealState);
    break;
  case SEMI_AUTO:
  case USER_DEFINED:
    idealPartitionState = computeIdealPartitionState(dataCache, idealState);
    break;
  case CUSTOMIZED:
    idealPartitionState = idealState.getRecord().getMapFields();
    break;
  case TASK:
    // ignore jobs
  default:
    return true;
  }

  return mappingInExtview.equals(idealPartitionState);
}
 
开发者ID:apache,项目名称:helix,代码行数:36,代码来源:StrictMatchExternalViewVerifier.java

示例4: verifyAssignmentInIdealStateWithPersistDisabled

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private void verifyAssignmentInIdealStateWithPersistDisabled(IdealState idealState,
    Set<String> excludedInstances) {
  boolean mapFieldEmpty = true;
  boolean assignmentNotChanged = false;
  for (String partition : idealState.getPartitionSet()) {
    Map<String, String> instanceStateMap = idealState.getInstanceStateMap(partition);
    if (instanceStateMap == null || instanceStateMap.isEmpty()) {
      continue;
    }
    mapFieldEmpty = false;
    Set<String> instancesInMap = instanceStateMap.keySet();
    for (String ins : excludedInstances) {
      if(instancesInMap.contains(ins)) {
        // if at least one excluded instance is included, it means assignment was not updated.
        assignmentNotChanged = true;
      }
      if(idealState.getRebalanceMode() == RebalanceMode.FULL_AUTO) {
        List<String> instanceList = idealState.getPreferenceList(partition);
        if (instanceList.contains(ins)) {
          assignmentNotChanged = true;
        }
      }
    }
  }

  Assert.assertTrue((mapFieldEmpty || assignmentNotChanged),
      "BestPossible assignment was updated.");
}
 
开发者ID:apache,项目名称:helix,代码行数:29,代码来源:TestRebalancerPersistAssignments.java

示例5: verifyReplication

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public void verifyReplication(ZkClient zkClient, String clusterName, String resource, int repl) {
  ZKHelixDataAccessor accessor =
      new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
  Builder keyBuilder = accessor.keyBuilder();

  IdealState idealState = accessor.getProperty(keyBuilder.idealStates(resource));
  for (String partitionName : idealState.getPartitionSet()) {
    if (idealState.getRebalanceMode() == RebalanceMode.SEMI_AUTO) {
      AssertJUnit.assertEquals(repl, idealState.getPreferenceList(partitionName).size());
    } else if (idealState.getRebalanceMode() == RebalanceMode.CUSTOMIZED) {
      AssertJUnit.assertEquals(repl, idealState.getInstanceStateMap(partitionName).size());
    }
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:15,代码来源:ZkUnitTestBase.java

示例6: rebalance

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
void rebalance(String clusterName, String resourceName, int replica, String keyPrefix,
    List<String> instanceNames, String groupId) {
  // ensure we get the same idealState with the same set of instances
  Collections.sort(instanceNames);

  IdealState idealState = getResourceIdealState(clusterName, resourceName);
  if (idealState == null) {
    throw new HelixException("Resource: " + resourceName + " has NOT been added yet");
  }

  if (groupId != null && groupId.length() > 0) {
    idealState.setInstanceGroupTag(groupId);
  }
  idealState.setReplicas(Integer.toString(replica));
  int partitions = idealState.getNumPartitions();
  String stateModelName = idealState.getStateModelDefRef();
  StateModelDefinition stateModDef = getStateModelDef(clusterName, stateModelName);

  if (stateModDef == null) {
    throw new HelixException("cannot find state model: " + stateModelName);
  }
  // StateModelDefinition def = new StateModelDefinition(stateModDef);

  List<String> statePriorityList = stateModDef.getStatesPriorityList();

  String masterStateValue = null;
  String slaveStateValue = null;
  replica--;

  for (String state : statePriorityList) {
    String count = stateModDef.getNumInstancesPerState(state);
    if (count.equals("1")) {
      if (masterStateValue != null) {
        throw new HelixException("Invalid or unsupported state model definition");
      }
      masterStateValue = state;
    } else if (count.equalsIgnoreCase("R")) {
      if (slaveStateValue != null) {
        throw new HelixException("Invalid or unsupported state model definition");
      }
      slaveStateValue = state;
    } else if (count.equalsIgnoreCase("N")) {
      if (!(masterStateValue == null && slaveStateValue == null)) {
        throw new HelixException("Invalid or unsupported state model definition");
      }
      replica = instanceNames.size() - 1;
      masterStateValue = slaveStateValue = state;
    }
  }
  if (masterStateValue == null && slaveStateValue == null) {
    throw new HelixException("Invalid or unsupported state model definition");
  }

  if (masterStateValue == null) {
    masterStateValue = slaveStateValue;
  }
  if (idealState.getRebalanceMode() != RebalanceMode.FULL_AUTO
      && idealState.getRebalanceMode() != RebalanceMode.USER_DEFINED) {
    ZNRecord newIdealState = DefaultIdealStateCalculator
        .calculateIdealState(instanceNames, partitions, replica, keyPrefix, masterStateValue,
            slaveStateValue);

    // for now keep mapField in SEMI_AUTO mode and remove listField in CUSTOMIZED mode
    if (idealState.getRebalanceMode() == RebalanceMode.SEMI_AUTO) {
      idealState.getRecord().setListFields(newIdealState.getListFields());
      // TODO: need consider to remove this.
      idealState.getRecord().setMapFields(newIdealState.getMapFields());
    }
    if (idealState.getRebalanceMode() == RebalanceMode.CUSTOMIZED) {
      idealState.getRecord().setMapFields(newIdealState.getMapFields());
    }
  } else {
    for (int i = 0; i < partitions; i++) {
      String partitionName = keyPrefix + "_" + i;
      idealState.getRecord().setMapField(partitionName, new HashMap<String, String>());
      idealState.getRecord().setListField(partitionName, new ArrayList<String>());
    }
  }
  setResourceIdealState(clusterName, resourceName, idealState);
}
 
开发者ID:apache,项目名称:helix,代码行数:81,代码来源:ZKHelixAdmin.java


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