Examples of HelixManager


Examples of org.apache.helix.HelixManager

  @BeforeClass()
  public synchronized void setup()
  {

    final String[] array = new String[] { "localhost_8900", "localhost_8901" };
    HelixManager manager = new Mocks.MockManager() {
      private MockAccessor _mockAccessor;

      @Override
//      public DataAccessor getDataAccessor()
      public HelixDataAccessor getHelixDataAccessor()
View Full Code Here

Examples of org.apache.helix.HelixManager

  {
    long startTime = System.currentTimeMillis();
    logger.info("START ReadClusterDataStage.process()");

   
    HelixManager manager = event.getAttribute("helixmanager");
    if (manager == null)
    {
      throw new StageException("HelixManager attribute value is null");
    }
    HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
    _cache.refresh(dataAccessor);
   
    ClusterStatusMonitor clusterStatusMonitor = (ClusterStatusMonitor) event.getAttribute("clusterStatusMonitor");
    if(clusterStatusMonitor != null)
    {
View Full Code Here

Examples of org.apache.helix.HelixManager

    long startTime = System.currentTimeMillis();
    // String aggTypeName =
    // DEFAULT_AGG_TYPE+AggregationType.DELIM+DEFAULT_DECAY_PARAM;
    // _defaultAggType = AggregationTypeFactory.getAggregationType(aggTypeName);

    HelixManager manager = event.getAttribute("helixmanager");
    HealthDataCache cache = event.getAttribute("HealthDataCache");

    if (manager == null || cache == null)
    {
      throw new StageException("helixmanager|HealthDataCache attribute value is null");
    }
    if(_alertsHolder == null)
    {
      _statsHolder = new StatsHolder(manager, cache);
      _alertsHolder = new AlertsHolder(manager, cache, _statsHolder);
    }
    else
    {
      _statsHolder.updateCache(cache);
      _alertsHolder.updateCache(cache);
    }
    if (_statsHolder.getStatsList().size() == 0)
    {
      if(logger.isTraceEnabled()){
        logger.trace("stat holder is empty");
      }
      return;
    }

    // init agg stats from cache
    // initAggStats(cache);

    Map<String, LiveInstance> liveInstances = cache.getLiveInstances();

    long currTime = System.currentTimeMillis();
    // for each live node, read node's stats
    long readInstancesStart = System.currentTimeMillis();
    for (LiveInstance instance : liveInstances.values())
    {
      String instanceName = instance.getInstanceName();
      logger.debug("instanceName: " + instanceName);
      // XXX: now have map of HealthStats, so no need to traverse them...verify
      // correctness
      Map<String, HealthStat> stats;
      stats = cache.getHealthStats(instanceName);
      // find participants stats
      long modTime = -1;
      // TODO: get healthreport child node modified time and reportAgeStat based on that
      boolean reportedAge = false;
      for (HealthStat participantStat : stats.values())
      {
        if (participantStat != null && !reportedAge)
        {
          // generate and report stats for how old this node's report is
          modTime = participantStat.getLastModifiedTimeStamp();
          reportAgeStat(instance, modTime, currTime);
          reportedAge = true;
        }
        // System.out.println(modTime);
        // XXX: need to convert participantStat to a better format
        // need to get instanceName in here

        if (participantStat != null)
        {
          // String timestamp = String.valueOf(instance.getModifiedTime()); WANT
          // REPORT LEVEL TS
          Map<String, Map<String, String>> statMap =
              participantStat.getHealthFields(instanceName);
          for (String key : statMap.keySet())
          {
            _statsHolder.applyStat(key, statMap.get(key));
          }
        }
      }
    }
    // Call _statsHolder.persistStats() once per pipeline. This will
    // write the updated persisted stats into zookeeper
    _statsHolder.persistStats();
    logger.info("Done processing stats: "
        + (System.currentTimeMillis() - readInstancesStart));
    // populate _statStatus
    _statStatus = _statsHolder.getStatsMap();

    for (String statKey : _statStatus.keySet())
    {
      logger.debug("Stat key, value: " + statKey + ": " + _statStatus.get(statKey));
    }

    long alertExecuteStartTime = System.currentTimeMillis();
    // execute alerts, populate _alertStatus
    _alertStatus =
        AlertProcessor.executeAllAlerts(_alertsHolder.getAlertList(),
                                        _statsHolder.getStatsList());
    logger.info("done executing alerts: "
        + (System.currentTimeMillis() - alertExecuteStartTime));
    for (String originAlertName : _alertStatus.keySet())
    {
      _alertBeanCollection.setAlerts(originAlertName,
                                     _alertStatus.get(originAlertName),
                                     manager.getClusterName());
    }

    executeAlertActions(manager);
    // Write alert fire history to zookeeper
    updateAlertHistory(manager);
View Full Code Here

Examples of org.apache.helix.HelixManager

     * ZkHelixManager.disconnect()->reset() TODO: Refactor accessing
     * HelixMaangerMain class statically
     */
    @Override
    public synchronized void onControllerChange(NotificationContext changeContext) {
  HelixManager manager = changeContext.getManager();
  if (manager == null) {
      LOG.error("missing attributes in changeContext. requires HelixManager");
      return;
  }

  InstanceType type = manager.getInstanceType();
  if (type != InstanceType.CONTROLLER && type != InstanceType.CONTROLLER_PARTICIPANT) {
      LOG.error("fail to become controller because incorrect instanceType (was "
        + type.toString() + ", requires CONTROLLER | CONTROLLER_PARTICIPANT)");
      return;
  }

  try {
      if (changeContext.getType().equals(NotificationContext.Type.INIT)
        || changeContext.getType().equals(NotificationContext.Type.CALLBACK)) {
    // DataAccessor dataAccessor = manager.getDataAccessor();
    HelixDataAccessor accessor = manager.getHelixDataAccessor();
    Builder keyBuilder = accessor.keyBuilder();

    while (accessor.getProperty(keyBuilder.controllerLeader()) == null) {
        boolean success = tryUpdateController(manager);
        if (success) {
      updateHistory(manager);
      if (type == InstanceType.CONTROLLER) {
          HelixControllerMain.addListenersToController(manager, _controller);
          manager.startTimerTasks();
      } else if (type == InstanceType.CONTROLLER_PARTICIPANT) {
          String clusterName = manager.getClusterName();
          String controllerName = manager.getInstanceName();
          _leader = HelixManagerFactory.getZKHelixManager(clusterName,
            controllerName, InstanceType.CONTROLLER, _zkAddr);

          _leader.connect();
          _leader.startTimerTasks();
View Full Code Here

Examples of org.apache.helix.HelixManager

      // since ZkClient.unsubscribe() does not immediately remove listeners
      // from zk, it is possible that two listeners exist when leadership transfers
      // therefore, double check to make sure only one participant invokes the code
      if (context.getType() == Type.CALLBACK)
      {
        HelixManager manager = context.getManager();
        // DataAccessor accessor = manager.getDataAccessor();
        HelixDataAccessor accessor = manager.getHelixDataAccessor();
        Builder keyBuilder = accessor.keyBuilder();

        String instance = manager.getInstanceName();
        String sessionId = manager.getSessionId();

        // get resource name from partition key: "PARTICIPANT_LEADER_XXX_0"
        String resourceName = _partitionKey.substring(0, _partitionKey.lastIndexOf('_'));

        CurrentState curState =
View Full Code Here

Examples of org.apache.helix.HelixManager

  @Test
  public void testDataChange() throws Exception
  {
    // Create an admin and add LiveInstanceChange listener to it
    HelixManager adminManager =
        HelixManagerFactory.getZKHelixManager(clusterName,
                                              null,
                                              InstanceType.ADMINISTRATOR,
                                              ZK_ADDR);
    adminManager.connect();
    final BlockingQueue<List<LiveInstance>> changeList =
        new LinkedBlockingQueue<List<LiveInstance>>();

    adminManager.addLiveInstanceChangeListener(new LiveInstanceChangeListener()
    {
      @Override
      public void onLiveInstanceChange(List<LiveInstance> liveInstances,
                                       NotificationContext changeContext)
      {
        // The queue is basically unbounded, so shouldn't throw exception when calling
        // "add".
        changeList.add(deepCopy(liveInstances));
      }
    });
   
    // Check the initial condition
    List<LiveInstance> instances = changeList.poll(1, TimeUnit.SECONDS);
    Assert.assertNotNull(instances, "Expecting a list of live instance");
    Assert.assertTrue(instances.isEmpty(), "Expecting an empty list of live instance");
    // Join as participant, should trigger a live instance change event
    HelixManager manager =
        HelixManagerFactory.getZKHelixManager(clusterName,
                                              "localhost_54321",
                                              InstanceType.PARTICIPANT,
                                              ZK_ADDR);
    manager.connect();
    instances = changeList.poll(1, TimeUnit.SECONDS);
    Assert.assertNotNull(instances, "Expecting a list of live instance");
    Assert.assertEquals(instances.size(), 1, "Expecting one live instance");
    Assert.assertEquals(instances.get(0).getInstanceName(), manager.getInstanceName());
    // Update data in the live instance node, should trigger another live instance change
    // event
    HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
    PropertyKey propertyKey =
        helixDataAccessor.keyBuilder().liveInstance(manager.getInstanceName());
    LiveInstance instance = helixDataAccessor.getProperty(propertyKey);

    Map<String, String> map = new TreeMap<String, String>();
    map.put("k1", "v1");
    instance.getRecord().setMapField("test", map);
    Assert.assertTrue(helixDataAccessor.updateProperty(propertyKey, instance),
                      "Failed to update live instance node");

    instances = changeList.poll(1, TimeUnit.SECONDS);
    Assert.assertNotNull(instances, "Expecting a list of live instance");
    Assert.assertEquals(instances.get(0).getRecord().getMapField("test"),
                        map,
                        "Wrong map data.");
    manager.disconnect();
    Thread.sleep(1000); // wait for callback finish

    instances = changeList.poll(1, TimeUnit.SECONDS);
    Assert.assertNotNull(instances, "Expecting a list of live instance");
    Assert.assertTrue(instances.isEmpty(), "Expecting an empty list of live instance");
View Full Code Here

Examples of org.apache.helix.HelixManager

    String leader = getCurrentLeader(zkClient, clusterName);
    Assert.assertTrue(leader != null);
    System.out.println("stop leader:" + leader + " in " + clusterName);
    Assert.assertTrue(leader != null);

    HelixManager manager = managerMap.remove(leader);
    Assert.assertTrue(manager != null);
    manager.disconnect();

    Thread thread = threadMap.remove(leader);
    Assert.assertTrue(thread != null);
    thread.interrupt();
View Full Code Here

Examples of org.apache.helix.HelixManager

      thread1.start();
      thread2.start();
      thread3.start();

      // Start Controller
      final HelixManager manager = HelixControllerMain.startHelixController(
          zkAddress, clusterName, "controller", HelixControllerMain.STANDALONE);
      Thread.sleep(5000);
      printStatus(manager);
      listFiles(baseDir);
      System.out.println("Writing files a.txt and b.txt to current master "
View Full Code Here

Examples of org.apache.helix.HelixManager

  }

  public static HelixManager startHelixController(final String zkConnectString,
      final String clusterName, final String controllerName, final String controllerMode)
  {
    HelixManager manager = null;
    try
    {
      if (controllerMode.equalsIgnoreCase(STANDALONE))
      {
        manager = HelixManagerFactory.getZKHelixManager(clusterName, controllerName,
            InstanceType.CONTROLLER, zkConnectString);
        manager.connect();
      } else if (controllerMode.equalsIgnoreCase(DISTRIBUTED))
      {
        manager = HelixManagerFactory.getZKHelixManager(clusterName, controllerName,
            InstanceType.CONTROLLER_PARTICIPANT, zkConnectString);

        DistClusterControllerStateModelFactory stateModelFactory = new DistClusterControllerStateModelFactory(
            zkConnectString);

        // StateMachineEngine genericStateMachineHandler = new
        // StateMachineEngine();
        StateMachineEngine stateMach = manager.getStateMachineEngine();
        stateMach.registerStateModelFactory("LeaderStandby", stateModelFactory);
        // manager.getMessagingService().registerMessageHandlerFactory(MessageType.STATE_TRANSITION.toString(),
        // genericStateMachineHandler);
        manager.connect();
      } else
      {
        logger.error("cluster controller mode:" + controllerMode + " NOT supported");
        // throw new
        // IllegalArgumentException("Unsupported cluster controller mode:" +
View Full Code Here

Examples of org.apache.helix.HelixManager

    if (propertyTransServicePort > 0)
    {
      ZKPropertyTransferServer.getInstance().init(propertyTransServicePort, zkConnectString);
    }
   
    HelixManager manager = startHelixController(zkConnectString, clusterName, controllerName,
        controllerMode);
    try
    {
      Thread.currentThread().join();
    }
    catch (InterruptedException e)
    {
      logger.info("controller:" + controllerName + ", " + Thread.currentThread().getName()
          + " interrupted");
    }
    finally
    {
      manager.disconnect();
      ZKPropertyTransferServer.getInstance().shutdown();
    }

  }
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.