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


Java HelixAdmin类代码示例

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


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

示例1: getInstanceToTopicPartitionsMap

import org.apache.helix.HelixAdmin; //导入依赖的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: getUnassignedPartitions

import org.apache.helix.HelixAdmin; //导入依赖的package包/类
public static Set<TopicPartition> getUnassignedPartitions(HelixManager helixManager) {
  Set<TopicPartition> unassignedPartitions = new HashSet<TopicPartition>();
  HelixAdmin helixAdmin = helixManager.getClusterManagmentTool();
  String helixClusterName = helixManager.getClusterName();
  for (String topic : helixAdmin.getResourcesInCluster(helixClusterName)) {
    IdealState is = helixAdmin.getResourceIdealState(helixClusterName, topic);
    int numPartitions = is.getNumPartitions();
    for (int partition = 0; partition < numPartitions; ++partition) {
      if (is.getInstanceSet(Integer.toString(partition)).isEmpty()) {
        TopicPartition tpi = new TopicPartition(topic, partition);
        unassignedPartitions.add(tpi);
      }
    }
  }
  return unassignedPartitions;
}
 
开发者ID:uber,项目名称:uReplicator,代码行数:17,代码来源:HelixUtils.java

示例3: getInstanceToTopicPartitionsMap

import org.apache.helix.HelixAdmin; //导入依赖的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

示例4: TerrapinControllerServiceImpl

import org.apache.helix.HelixAdmin; //导入依赖的package包/类
public TerrapinControllerServiceImpl(PropertiesConfiguration configuration,
                                     ZooKeeperManager zkManager,
                                     DFSClient hdfsClient,
                                     HelixAdmin helixAdmin,
                                     String clusterName) {
  this.configuration = configuration;
  this.zkManager = zkManager;
  this.hdfsClient = hdfsClient;
  this.helixAdmin = helixAdmin;
  this.clusterName = clusterName;

  ExecutorService threadPool = new ThreadPoolExecutor(100,
      100,
      0,
      TimeUnit.SECONDS,
      new LinkedBlockingDeque<Runnable>(1000),
      new ThreadFactoryBuilder().setDaemon(false)
                    .setNameFormat("controller-pool-%d")
                    .build());
 this.futurePool = new ExecutorServiceFuturePool(threadPool);
}
 
开发者ID:pinterest-attic,项目名称:terrapin,代码行数:22,代码来源:TerrapinControllerServiceImpl.java

示例5: onLiveInstanceChange

import org.apache.helix.HelixAdmin; //导入依赖的package包/类
@Override
public void onLiveInstanceChange(List<LiveInstance> list, NotificationContext notificationContext) {
  List<InetSocketAddress> addresses = new ArrayList<>();
  HelixAdmin helixAdmin = helixConnection.createClusterManagementTool();
  for (LiveInstance liveInstance : list) {
    InstanceConfig instanceConfig = helixAdmin.getInstanceConfig(
        clusterName,
        liveInstance.getInstanceName());
    InetSocketAddress address = new InetSocketAddress(
        instanceConfig.getHostName(),
        Integer.valueOf(instanceConfig.getPort()));
    addresses.add(address);
  }

  services.set(addresses);
}
 
开发者ID:brandtg,项目名称:dropwizard-helix,代码行数:17,代码来源:HelixServiceDiscoverer.java

示例6: getAssignedInstances

import org.apache.helix.HelixAdmin; //导入依赖的package包/类
@Override
public List<String> getAssignedInstances(HelixAdmin helixAdmin, String helixClusterName,
    SegmentMetadata segmentMetadata, int numReplicas, String tenantName) {
  String serverTenantName = null;
  if ("realtime".equalsIgnoreCase(segmentMetadata.getIndexType())) {
    serverTenantName = ControllerTenantNameBuilder.getRealtimeTenantNameForTenant(tenantName);
  } else {
    serverTenantName = ControllerTenantNameBuilder.getOfflineTenantNameForTenant(tenantName);
  }
  final Random random = new Random(System.currentTimeMillis());

  List<String> allInstanceList = helixAdmin.getInstancesInClusterWithTag(helixClusterName, serverTenantName);
  List<String> selectedInstanceList = new ArrayList<String>();
  for (int i = 0; i < numReplicas; ++i) {
    final int idx = random.nextInt(allInstanceList.size());
    selectedInstanceList.add(allInstanceList.get(idx));
    allInstanceList.remove(idx);
  }
  LOGGER.info("Segment assignment result for : " + segmentMetadata.getName() + ", in resource : "
      + segmentMetadata.getTableName() + ", selected instances: "
      + Arrays.toString(selectedInstanceList.toArray()));

  return selectedInstanceList;
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:25,代码来源:RandomAssignmentStrategy.java

示例7: buildInitialRealtimeIdealStateFor

import org.apache.helix.HelixAdmin; //导入依赖的package包/类
public static IdealState buildInitialRealtimeIdealStateFor(String realtimeTableName,
    AbstractTableConfig realtimeTableConfig, HelixAdmin helixAdmin, String helixClusterName,
    ZkHelixPropertyStore<ZNRecord> zkHelixPropertyStore) {
  KafkaStreamMetadata kafkaStreamMetadata =
      new KafkaStreamMetadata(realtimeTableConfig.getIndexingConfig().getStreamConfigs());
  String realtimeServerTenant =
      ControllerTenantNameBuilder.getRealtimeTenantNameForTenant(realtimeTableConfig.getTenantConfig().getServer());
  switch (kafkaStreamMetadata.getConsumerType()) {
    case highLevel:
      IdealState idealState =
          buildInitialKafkaHighLevelConsumerRealtimeIdealStateFor(realtimeTableName, helixAdmin, helixClusterName,
              zkHelixPropertyStore);
      List<String> realtimeInstances = helixAdmin.getInstancesInClusterWithTag(helixClusterName, realtimeServerTenant);
      if (realtimeInstances.size() % Integer.parseInt(realtimeTableConfig.getValidationConfig().getReplication()) != 0) {
        throw new RuntimeException("Number of instance in current tenant should be an integer multiples of the number of replications");
      }
      setupInstanceConfigForKafkaHighLevelConsumer(realtimeTableName, realtimeInstances.size(),
          Integer.parseInt(realtimeTableConfig.getValidationConfig().getReplication()), realtimeTableConfig
              .getIndexingConfig().getStreamConfigs(), zkHelixPropertyStore, realtimeInstances);
      return idealState;
    case simple:
    default:
      throw new UnsupportedOperationException("Not support kafka consumer type: "
          + kafkaStreamMetadata.getConsumerType());
  }
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:27,代码来源:PinotTableIdealStateBuilder.java

示例8: main

import org.apache.helix.HelixAdmin; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  if (args.length != 3) {
    System.out.println("USAGE: MySQLAgentLauncher zkAddress clusterName instanceName");
  }
  String zkAddress = args[0];
  String clusterName = args[1];
  String instanceName = args[2];
  HelixAdmin admin = new ZKHelixAdmin(zkAddress);
  List<String> clusters = admin.getClusters();
  System.out.println(clusters);
  if (!clusters.contains(clusterName)) {
    System.err.println("Cluster is not setup. Use cluster-admin to create a  new cluster");
    System.exit(1);
  }
  InstanceConfig instanceConfig = admin.getInstanceConfig(clusterName, instanceName);
  if (instanceConfig == null) {
    String msg =
        "Agent is not yet configured in the cluster. Use cluster-admin to first configure the new Mysql Agent";
    System.err.println(msg);
    System.exit(1);
  }
  admin.close();
  MySQLAgent agent = new MySQLAgent(zkAddress, clusterName, instanceConfig);
  agent.start();
  Thread.currentThread().join();
}
 
开发者ID:kishoreg,项目名称:fullmatix,代码行数:27,代码来源:MySQLAgentLauncher.java

示例9: monitor

import org.apache.helix.HelixAdmin; //导入依赖的package包/类
private void monitor() throws Exception {
  MySQLAdmin mysqlAdmin = _context.getMysqlAdmin();
  HelixAdmin helixAdmin = _context.getHelixManager().getClusterManagmentTool();
  boolean isEnabled = _instanceConfig.getInstanceEnabled();
  int failedPingCount = 0;
  while (true) {
    Thread.sleep(1000);
    if (!mysqlAdmin.ping()) {
      LOG.info("Mysql connection check failed");

      failedPingCount = failedPingCount + 1;
    } else {
      failedPingCount = 0;
      if (!isEnabled) {
        LOG.info("Mysql connection check passed.Enabling the instance");
        helixAdmin.enableInstance(_clusterName, _instanceName, true);
        isEnabled = true;
      }
    }
    if (failedPingCount == 30) {
      LOG.info("Mysql connection check failed 30 times, disabling the instance");
      helixAdmin.enableInstance(_clusterName, _instanceName, false);
      isEnabled = false;
    }
  }
}
 
开发者ID:kishoreg,项目名称:fullmatix,代码行数:27,代码来源:MySQLAgent.java

示例10: main

import org.apache.helix.HelixAdmin; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  ConsoleAppender ca = new ConsoleAppender();
  ca.setThreshold(Level.INFO);
  ca.setWriter(new OutputStreamWriter(System.out));
  ca.setLayout(new PatternLayout("%-4r [%t] %-5p %c %x - %m%n"));
  Logger.getRootLogger().addAppender(ca);
  String clusterName = "mysql-cluster-test";
  String instanceName = "kgopalak-ld.linkedin.biz_5555";
  String zkAddress = "localhost:2181";
  // TODO:stand alone way to start the agent
  HelixAdmin admin = new ZKHelixAdmin(zkAddress);
  InstanceConfig instanceConfig = admin.getInstanceConfig(clusterName, instanceName);
  MySQLAgent agent = new MySQLAgent(zkAddress, clusterName, instanceConfig);
  agent.start();
  Thread.currentThread().join();
}
 
开发者ID:kishoreg,项目名称:fullmatix,代码行数:17,代码来源:MySQLAgent.java

示例11: testDisableResource

import org.apache.helix.HelixAdmin; //导入依赖的package包/类
@Test
public void testDisableResource() {
  String className = TestHelper.getTestClassName();
  String methodName = TestHelper.getTestMethodName();
  String clusterName = className + "_" + methodName;
  System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
  HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
  admin.addCluster(clusterName, true);
  Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _gZkClient), "Cluster should be setup");
  String resourceName = "TestDB";
  admin.addStateModelDef(clusterName, "MasterSlave", new StateModelDefinition(
      StateModelConfigGenerator.generateConfigForMasterSlave()));
  admin.addResource(clusterName, resourceName, 4, "MasterSlave");
  admin.enableResource(clusterName, resourceName, false);
  BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
  HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
  PropertyKey.Builder keyBuilder = accessor.keyBuilder();
  IdealState idealState = accessor.getProperty(keyBuilder.idealStates(resourceName));
  Assert.assertFalse(idealState.isEnabled());
  admin.enableResource(clusterName, resourceName, true);
  idealState = accessor.getProperty(keyBuilder.idealStates(resourceName));
  Assert.assertTrue(idealState.isEnabled());
  System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
 
开发者ID:apache,项目名称:helix,代码行数:25,代码来源:TestZkHelixAdmin.java

示例12: printStatus

import org.apache.helix.HelixAdmin; //导入依赖的package包/类
private static void printStatus(HelixAdmin admin, String cluster, String resource) {
  ExternalView externalView = admin.getResourceExternalView(cluster, resource);
  // System.out.println(externalView);
  TreeSet<String> treeSet = new TreeSet<String>(externalView.getPartitionSet());
  System.out.println("lockName" + "\t" + "acquired By");
  System.out.println("======================================");
  for (String lockName : treeSet) {
    Map<String, String> stateMap = externalView.getStateMap(lockName);
    String acquiredBy = null;
    if (stateMap != null) {
      for (String instanceName : stateMap.keySet()) {
        if ("ONLINE".equals(stateMap.get(instanceName))) {
          acquiredBy = instanceName;
          break;
        }
      }
    }
    System.out.println(lockName + "\t" + ((acquiredBy != null) ? acquiredBy : "NONE"));
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:21,代码来源:LockManagerDemo.java

示例13: addInstance

import org.apache.helix.HelixAdmin; //导入依赖的package包/类
@PUT
@Path("{instanceName}")
public Response addInstance(@PathParam("clusterId") String clusterId,
    @PathParam("instanceName") String instanceName, String content) {
  HelixAdmin admin = getHelixAdmin();
  ZNRecord record;
  try {
    record = toZNRecord(content);
  } catch (IOException e) {
    _logger.error("Failed to deserialize user's input " + content + ", Exception: " + e);
    return badRequest("Input is not a vaild ZNRecord!");
  }

  try {
    admin.addInstance(clusterId, new InstanceConfig(record));
  } catch (Exception ex) {
    _logger.error("Error in adding an instance: " + instanceName, ex);
    return serverError(ex);
  }

  return OK();
}
 
开发者ID:apache,项目名称:helix,代码行数:23,代码来源:InstanceAccessor.java

示例14: updateInstanceConfig

import org.apache.helix.HelixAdmin; //导入依赖的package包/类
@PUT
@Path("{instanceName}/configs")
public Response updateInstanceConfig(@PathParam("clusterId") String clusterId,
    @PathParam("instanceName") String instanceName, String content) throws IOException {
  HelixAdmin admin = getHelixAdmin();
  ZNRecord record;
  try {
    record = toZNRecord(content);
  } catch (IOException e) {
    _logger.error("Failed to deserialize user's input " + content + ", Exception: " + e);
    return badRequest("Input is not a vaild ZNRecord!");
  }

  try {
    admin.setInstanceConfig(clusterId, instanceName, new InstanceConfig(record));
  } catch (Exception ex) {
    _logger.error("Error in update instance config: " + instanceName, ex);
    return serverError(ex);
  }

  return OK();
}
 
开发者ID:apache,项目名称:helix,代码行数:23,代码来源:InstanceAccessor.java

示例15: getAssignedInstances

import org.apache.helix.HelixAdmin; //导入依赖的package包/类
@Override
public List<String> getAssignedInstances(HelixAdmin helixAdmin, ZkHelixPropertyStore<ZNRecord> propertyStore,
    String helixClusterName, SegmentMetadata segmentMetadata, int numReplicas, String tenantName) {
  String serverTenantName = ControllerTenantNameBuilder.getOfflineTenantNameForTenant(tenantName);

  List<String> allInstances = HelixHelper.getEnabledInstancesWithTag(helixAdmin, helixClusterName, serverTenantName);
  List<String> selectedInstanceList = new ArrayList<>();
  if (segmentMetadata.getShardingKey() != null) {
    for (String instance : allInstances) {
      if (HelixHelper.getInstanceConfigsMapFor(instance, helixClusterName, helixAdmin)
          .get("shardingKey")
          .equalsIgnoreCase(segmentMetadata.getShardingKey())) {
        selectedInstanceList.add(instance);
      }
    }
    LOGGER.info("Segment assignment result for : " + segmentMetadata.getName() + ", in resource : "
        + segmentMetadata.getTableName() + ", selected instances: " + Arrays.toString(
        selectedInstanceList.toArray()));
    return selectedInstanceList;
  } else {
    throw new RuntimeException("Segment missing sharding key!");
  }
}
 
开发者ID:linkedin,项目名称:pinot,代码行数:24,代码来源:BucketizedSegmentStrategy.java


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