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


Java IdealState.getInstanceSet方法代码示例

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


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

示例1: getInstanceToTopicPartitionsMap

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
 * From IdealStates.
 *
 * @return InstanceToNumTopicPartitionMap
 */
public static Map<String, Set<TopicPartition>> getInstanceToTopicPartitionsMap(
    HelixManager helixManager) {
  Map<String, Set<TopicPartition>> instanceToNumTopicPartitionMap =
      new HashMap<String, Set<TopicPartition>>();
  HelixAdmin helixAdmin = helixManager.getClusterManagmentTool();
  String helixClusterName = helixManager.getClusterName();
  for (String topic : helixAdmin.getResourcesInCluster(helixClusterName)) {
    IdealState is = helixAdmin.getResourceIdealState(helixClusterName, topic);
    for (String partition : is.getPartitionSet()) {
      TopicPartition tpi = new TopicPartition(topic, Integer.parseInt(partition));
      for (String instance : is.getInstanceSet(partition)) {
        if (!instanceToNumTopicPartitionMap.containsKey(instance)) {
          instanceToNumTopicPartitionMap.put(instance, new HashSet<TopicPartition>());
        }
        instanceToNumTopicPartitionMap.get(instance).add(tpi);
      }
    }
  }
  return instanceToNumTopicPartitionMap;
}
 
开发者ID:uber,项目名称:uReplicator,代码行数:26,代码来源:HelixUtils.java

示例2: getInstanceToTopicPartitionsMap

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
 * From IdealStates.
 * @param helixManager
 * @return InstanceToNumTopicPartitionMap
 */
public static Map<String, Set<TopicPartition>> getInstanceToTopicPartitionsMap(
    HelixManager helixManager) {
  Map<String, Set<TopicPartition>> instanceToNumTopicPartitionMap =
      new HashMap<String, Set<TopicPartition>>();
  HelixAdmin helixAdmin = helixManager.getClusterManagmentTool();
  String helixClusterName = helixManager.getClusterName();
  for (String topic : helixAdmin.getResourcesInCluster(helixClusterName)) {
    IdealState is = helixAdmin.getResourceIdealState(helixClusterName, topic);
    for (String partition : is.getPartitionSet()) {
      TopicPartition tpi = new TopicPartition(topic, Integer.parseInt(partition));
      for (String instance : is.getInstanceSet(partition)) {
        if (!instanceToNumTopicPartitionMap.containsKey(instance)) {
          instanceToNumTopicPartitionMap.put(instance, new HashSet<TopicPartition>());
        }
        instanceToNumTopicPartitionMap.get(instance).add(tpi);
      }
    }
  }
  return instanceToNumTopicPartitionMap;
}
 
开发者ID:uber,项目名称:chaperone,代码行数:26,代码来源:HelixUtils.java

示例3: calculateDeviationForResource

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
static double calculateDeviationForResource(String resource,
                                            IdealState idealState,
                                            RoutingTableProvider routingTableProvider) {
  Set<String> partitions = idealState.getPartitionSet();
  int totalAssignments = 0, totalDeviations = 0;
  // Check if the external view has deviated from the actual view.
  for (String partition : partitions) {
    // Make a copy of the instance mapping in the ideal state.
    Set<String> idealInstances = new HashSet(idealState.getInstanceSet(partition));
    totalAssignments += idealInstances.size();
    // Now check against our real state and count the amount of deviating
    // assignments.
    List<InstanceConfig> currentInstanceConfigs = routingTableProvider.getInstances(
        resource, partition, "ONLINE");
    Set<String> currentInstances = Sets.newHashSetWithExpectedSize(
        currentInstanceConfigs.size());
    if (currentInstanceConfigs != null) {
      for (InstanceConfig instanceConfig : currentInstanceConfigs) {
        currentInstances.add(instanceConfig.getHostName());
      }
    }
    idealInstances.removeAll(currentInstances);
    totalDeviations += idealInstances.size();
  }
  return (double)totalDeviations / totalAssignments;
}
 
开发者ID:pinterest-attic,项目名称:terrapin,代码行数:27,代码来源:HdfsManager.java

示例4: isServerTenantDeletable

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public boolean isServerTenantDeletable(String tenantName) {
  Set<String> taggedInstances =
      new HashSet<String>(_helixAdmin.getInstancesInClusterWithTag(_helixClusterName,
          ControllerTenantNameBuilder.getOfflineTenantNameForTenant(tenantName)));
  taggedInstances.addAll(_helixAdmin.getInstancesInClusterWithTag(_helixClusterName,
      ControllerTenantNameBuilder.getRealtimeTenantNameForTenant(tenantName)));
  for (String tableName : getAllTableNames()) {
    if (tableName.equals(CommonConstants.Helix.BROKER_RESOURCE_INSTANCE)) {
      continue;
    }
    IdealState tableIdealState = _helixAdmin.getResourceIdealState(_helixClusterName, tableName);
    for (String partition : tableIdealState.getPartitionSet()) {
      for (String instance : tableIdealState.getInstanceSet(partition)) {
        if (taggedInstances.contains(instance)) {
          return false;
        }
      }
    }
  }
  return true;
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:22,代码来源:PinotHelixResourceManager.java

示例5: getInstanceToSegmentsInATableMap

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public Map<String, List<String>> getInstanceToSegmentsInATableMap(String tableName) {
  Map<String, List<String>> instancesToSegmentsMap = new HashMap<String, List<String>>();
  IdealState is = _helixAdmin.getResourceIdealState(_helixClusterName, tableName);
  Set<String> segments = is.getPartitionSet();

  for (String segment : segments) {
    Set<String> instances = is.getInstanceSet(segment);
    for (String instance : instances) {
      if (instancesToSegmentsMap.containsKey(instance)) {
        instancesToSegmentsMap.get(instance).add(segment);
      } else {
        List<String> a = new ArrayList<String>();
        a.add(segment);
        instancesToSegmentsMap.put(instance, a);
      }
    }
  }

  return instancesToSegmentsMap;
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:21,代码来源:PinotHelixResourceManager.java

示例6: removeSegmentFromIdealState

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
 * Remove the segment from the cluster.
 *
 * @param helixManager The HelixManager object to access the helix cluster.
 * @param tableName Name of the table to which the new segment is to be added.
 * @param segmentName Name of the new segment to be added
 */
public static void removeSegmentFromIdealState(HelixManager helixManager, String tableName, final String segmentName) {
  Function<IdealState, IdealState> updater = new Function<IdealState, IdealState>() {
    @Override
    public IdealState apply(IdealState idealState) {
      final Set<String> currentInstanceSet = idealState.getInstanceSet(segmentName);

      if (!currentInstanceSet.isEmpty() && idealState.getPartitionSet().contains(segmentName)) {
        idealState.getPartitionSet().remove(segmentName);
        return idealState;
      } else {
        return null;
      }
    }
  };

  updateIdealState(helixManager, tableName, updater, DEFAULT_RETRY_POLICY);
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:25,代码来源:HelixHelper.java

示例7: isServerTenantDeletable

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public boolean isServerTenantDeletable(String tenantName) {
  Set<String> taggedInstances =
      new HashSet<String>(_helixAdmin.getInstancesInClusterWithTag(_helixClusterName,
          ControllerTenantNameBuilder.getOfflineTenantNameForTenant(tenantName)));
  taggedInstances.addAll(_helixAdmin.getInstancesInClusterWithTag(_helixClusterName,
      ControllerTenantNameBuilder.getRealtimeTenantNameForTenant(tenantName)));
  for (String resourceName : getAllResources()) {
    if (!TableNameBuilder.isTableResource(resourceName)) {
      continue;
    }
    IdealState tableIdealState = _helixAdmin.getResourceIdealState(_helixClusterName, resourceName);
    for (String partition : tableIdealState.getPartitionSet()) {
      for (String instance : tableIdealState.getInstanceSet(partition)) {
        if (taggedInstances.contains(instance)) {
          return false;
        }
      }
    }
  }
  return true;
}
 
开发者ID:linkedin,项目名称:pinot,代码行数:22,代码来源:PinotHelixResourceManager.java

示例8: isInstanceDroppable

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
 * Check if an instance can safely dropped from helix cluster. Instance should not be dropped if:
 * - It is a live instance.
 * - Any idealstate includes the instance.
 *
 * @param instanceName: Name of the instance to be dropped.
 * @return
 */
public boolean isInstanceDroppable(String instanceName) {
  // Check if this instance is live
  HelixDataAccessor helixDataAccessor = _helixZkManager.getHelixDataAccessor();
  LiveInstance liveInstance = helixDataAccessor.getProperty(_keyBuilder.liveInstance(instanceName));
  if (liveInstance != null) {
    return false;
  }

  // Check if any idealstate contains information on this instance
  for (String resourceName : getAllResources()) {
    IdealState resourceIdealState = _helixAdmin.getResourceIdealState(_helixClusterName, resourceName);
    for (String partition : resourceIdealState.getPartitionSet()) {
      for (String instance : resourceIdealState.getInstanceSet(partition)) {
        if (instance.equals(instanceName)) {
          return false;
        }
      }
    }
  }
  return true;
}
 
开发者ID:linkedin,项目名称:pinot,代码行数:30,代码来源:PinotHelixResourceManager.java

示例9: isBrokerTenantDeletable

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public boolean isBrokerTenantDeletable(String tenantName) {
  String brokerTag = ControllerTenantNameBuilder.getBrokerTenantNameForTenant(tenantName);
  Set<String> taggedInstances =
      new HashSet<String>(_helixAdmin.getInstancesInClusterWithTag(_helixClusterName, brokerTag));
  String brokerName = CommonConstants.Helix.BROKER_RESOURCE_INSTANCE;
  IdealState brokerIdealState = _helixAdmin.getResourceIdealState(_helixClusterName, brokerName);
  for (String partition : brokerIdealState.getPartitionSet()) {
    for (String instance : brokerIdealState.getInstanceSet(partition)) {
      if (taggedInstances.contains(instance)) {
        return false;
      }
    }
  }
  return true;
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:16,代码来源:PinotHelixResourceManager.java

示例10: addNewOfflineSegment

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
 * Helper method to add the passed in offline segment to the helix cluster.
 * - Gets the segment name and the table name from the passed in segment meta-data.
 * - Identifies the instance set onto which the segment needs to be added, based on
 *   segment assignment strategy and replicas in the table config in the property-store.
 * - Updates ideal state such that the new segment is assigned to required set of instances as per
 *    the segment assignment strategy and replicas.
 *
 * @param segmentMetadata Meta-data for the segment, used to access segmentName and tableName.
 * @throws JsonParseException
 * @throws JsonMappingException
 * @throws JsonProcessingException
 * @throws JSONException
 * @throws IOException
 */
private void addNewOfflineSegment(final SegmentMetadata segmentMetadata) throws JsonParseException,
    JsonMappingException, JsonProcessingException, JSONException, IOException {
  final AbstractTableConfig offlineTableConfig =
      ZKMetadataProvider.getOfflineTableConfig(_propertyStore, segmentMetadata.getTableName());

  final String segmentName = segmentMetadata.getName();
  final String offlineTableName =
      TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(segmentMetadata.getTableName());

  if (!SEGMENT_ASSIGNMENT_STRATEGY_MAP.containsKey(offlineTableName)) {
    SEGMENT_ASSIGNMENT_STRATEGY_MAP.put(offlineTableName, SegmentAssignmentStrategyFactory
        .getSegmentAssignmentStrategy(offlineTableConfig.getValidationConfig().getSegmentAssignmentStrategy()));
  }
  final SegmentAssignmentStrategy segmentAssignmentStrategy = SEGMENT_ASSIGNMENT_STRATEGY_MAP.get(offlineTableName);

  // Passing a callable to this api to avoid helixHelper having which is in pinot-common having to
  // depend upon pinot-controller.
  Callable<List<String>> getInstancesForSegment = new Callable<List<String>>() {
    @Override
    public List<String> call() throws Exception {
      final IdealState currentIdealState = _helixAdmin.getResourceIdealState(_helixClusterName, offlineTableName);
      final Set<String> currentInstanceSet = currentIdealState.getInstanceSet(segmentName);

      if (currentInstanceSet.isEmpty()) {
        final String serverTenant =
            ControllerTenantNameBuilder.getOfflineTenantNameForTenant(offlineTableConfig.getTenantConfig()
                .getServer());
        final int replicas = Integer.parseInt(offlineTableConfig.getValidationConfig().getReplication());
        return segmentAssignmentStrategy.getAssignedInstances(_helixAdmin, _helixClusterName, segmentMetadata,
            replicas, serverTenant);
      } else {
        return new ArrayList<String>(currentIdealState.getInstanceSet(segmentName));
      }
    }
  };

  HelixHelper.addSegmentToIdealState(_helixZkManager, offlineTableName, segmentName, getInstancesForSegment);
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:54,代码来源:PinotHelixResourceManager.java

示例11: dropSegmentFromIdealStateFor

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
 * Remove a segment is also required to recompute the ideal state.
 *
 * @param tableName
 * @param segmentId
 * @param helixAdmin
 * @param helixClusterName
 * @return
 */
public synchronized static IdealState dropSegmentFromIdealStateFor(String tableName, String segmentId,
    HelixAdmin helixAdmin, String helixClusterName) {

  final IdealState currentIdealState = helixAdmin.getResourceIdealState(helixClusterName, tableName);
  final Set<String> currentInstanceSet = currentIdealState.getInstanceSet(segmentId);
  if (!currentInstanceSet.isEmpty() && currentIdealState.getPartitionSet().contains(segmentId)) {
    for (String instanceName : currentIdealState.getInstanceSet(segmentId)) {
      currentIdealState.setPartitionState(segmentId, instanceName, "DROPPED");
    }
  } else {
    throw new RuntimeException("Cannot found segmentId - " + segmentId + " in table - " + tableName);
  }
  return currentIdealState;
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:24,代码来源:PinotTableIdealStateBuilder.java

示例12: removeBrokerResourceFromIdealStateFor

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
 *
 * @param brokerResourceName
 * @param helixAdmin
 * @param helixClusterName
 * @return
 */
public static IdealState removeBrokerResourceFromIdealStateFor(String brokerResourceName, HelixAdmin helixAdmin,
    String helixClusterName) {
  final IdealState currentIdealState =
      helixAdmin.getResourceIdealState(helixClusterName, CommonConstants.Helix.BROKER_RESOURCE_INSTANCE);
  final Set<String> currentInstanceSet = currentIdealState.getInstanceSet(brokerResourceName);
  if (!currentInstanceSet.isEmpty() && currentIdealState.getPartitionSet().contains(brokerResourceName)) {
    currentIdealState.getPartitionSet().remove(brokerResourceName);
  } else {
    throw new RuntimeException("Cannot found broker resource - " + brokerResourceName + " in broker resource ");
  }
  return currentIdealState;
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:20,代码来源:PinotTableIdealStateBuilder.java

示例13: getAllInstancesForResource

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
 * Returns all instances for the given resource.
 *
 * @param idealState IdealState of the resource for which to return the instances of.
 * @return Returns a Set of strings containing the instance names for the given cluster.
 */
public static Set<String> getAllInstancesForResource(IdealState idealState) {
  final Set<String> instances = new HashSet<String>();

  for (final String partition : idealState.getPartitionSet()) {
    for (final String instance : idealState.getInstanceSet(partition)) {
      instances.add(instance);
    }
  }
  return instances;
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:17,代码来源:HelixHelper.java

示例14: createTable

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public void createTable(String clusterName, String dbName, String table, String tableSpec) {
  LOG.info("Creating table:" + table + " with table_spec: " + tableSpec + " in dbName:" + dbName);
  IdealState dbIdealState = _helixAdmin.getResourceIdealState(clusterName, dbName);
  int numPartitions = dbIdealState.getNumPartitions();
  String dbTableName = dbName + "." + table;
  AutoModeISBuilder builder = new AutoModeISBuilder(dbTableName);
  builder.setRebalancerMode(RebalanceMode.SEMI_AUTO);
  builder.setNumPartitions(numPartitions);
  builder.setNumReplica(Integer.parseInt(dbIdealState.getReplicas()));
  builder.setStateModel("OnlineOffline");
  builder.setStateModelFactoryName("TableTransitionHandlerFactory");
  for (String dbPartitionName : dbIdealState.getPartitionSet()) {
    String tablePartitionName = dbPartitionName + "." + table;
    Set<String> instanceSet = dbIdealState.getInstanceSet(dbPartitionName);
    builder.add(tablePartitionName);
    String[] instanceNames = new String[instanceSet.size()];
    instanceSet.toArray(instanceNames);
    builder.assignPreferenceList(tablePartitionName, instanceNames);
  }
  IdealState idealState = builder.build();

  // before setting the idealstate, set the configuration
  Map<String, String> properties = new HashMap<String, String>();
  properties.put("table_spec", tableSpec);
  properties.put("type", "TABLE");

  HelixConfigScope scope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName)
          .forResource(dbTableName).build();
  _helixAdmin.setConfig(scope, properties);
  _helixAdmin.setResourceIdealState(clusterName, dbTableName, idealState);
}
 
开发者ID:kishoreg,项目名称:fullmatix,代码行数:33,代码来源:ClusterAdmin.java

示例15: getSegmentsPerInstance

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private Map<String, Integer> getSegmentsPerInstance(String tableName) {
  Map<String, Integer> segmentsPerInstance = new HashMap<String, Integer>();
  IdealState idealState = _helixAdmin.getResourceIdealState(getHelixClusterName(), tableName + "_OFFLINE");
  for (String partitionName : idealState.getPartitionSet()) {
    for (String instanceName : idealState.getInstanceSet(partitionName)) {
      if (!segmentsPerInstance.containsKey(instanceName)) {
        segmentsPerInstance.put(instanceName, 1);
      } else {
        segmentsPerInstance.put(instanceName, segmentsPerInstance.get(instanceName) + 1);
      }
    }
  }
  return segmentsPerInstance;
}
 
开发者ID:linkedin,项目名称:pinot,代码行数:15,代码来源:BalanceNumSegmentAssignmentStrategyIntegrationTest.java


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