Package org.apache.helix

Examples of org.apache.helix.HelixDataAccessor


      // 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 =
            accessor.getProperty(keyBuilder.currentState(instance,
                                                         sessionId,
                                                         resourceName));
        if (curState == null)
        {
          return;
View Full Code Here


    message.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY);
    MockStateModel stateModel = new MockStateModel();
    NotificationContext context;
    MockManager manager = new MockManager("clusterName");
//    DataAccessor accessor = manager.getDataAccessor();
    HelixDataAccessor accessor = manager.getHelixDataAccessor();
    StateModelConfigGenerator generator = new StateModelConfigGenerator();
    StateModelDefinition stateModelDef = new StateModelDefinition(
        generator.generateConfigForMasterSlave());
    Builder keyBuilder = accessor.keyBuilder();
    accessor.setProperty(keyBuilder.stateModelDef("MasterSlave"), stateModelDef);

    context = new NotificationContext(manager);
    CurrentState currentStateDelta = new CurrentState("TestDB");
    currentStateDelta.setState("TestDB_0", "OFFLINE");
View Full Code Here

    MockStateModelAnnotated stateModel = new MockStateModelAnnotated();
    NotificationContext context;

    MockManager manager = new MockManager("clusterName");
//    DataAccessor accessor = manager.getDataAccessor();
    HelixDataAccessor accessor = manager.getHelixDataAccessor();

    StateModelConfigGenerator generator = new StateModelConfigGenerator();
    StateModelDefinition stateModelDef = new StateModelDefinition(
        generator.generateConfigForMasterSlave());
//    accessor.setProperty(PropertyType.STATEMODELDEFS, stateModelDef, "MasterSlave");
    Builder keyBuilder = accessor.keyBuilder();
    accessor.setProperty(keyBuilder.stateModelDef("MasterSlave"), stateModelDef);


    context = new NotificationContext(manager);
   
    CurrentState currentStateDelta = new CurrentState("TestDB");
View Full Code Here

    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"),
View Full Code Here

  }

  private static void printStatus(final HelixManager manager)
  {
    System.out.println("CLUSTER STATUS");
    HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
    Builder keyBuilder = helixDataAccessor.keyBuilder();
    System.out.println("External View \n"
        + helixDataAccessor.getProperty(keyBuilder.externalView("repository")));
  }
View Full Code Here

        nMsgsSent = _manager.getMessagingService().send(recipientCriteria,
            messageTemplate,
            callback,
            timeOut);
      }
      HelixDataAccessor accessor = _manager.getHelixDataAccessor();
      Builder keyBuilder = accessor.keyBuilder();

      // Record the number of messages sent into status updates
      Map<String, String> sendSummary = new HashMap<String, String>();
      sendSummary.put("MessageCount", "" + nMsgsSent);
     
      ZNRecord statusUpdate = accessor.getProperty(
          keyBuilder.controllerTaskStatus(MessageType.SCHEDULER_MSG.toString(),
              _message.getMsgId())).getRecord();

      statusUpdate.getMapFields().put("SentMessageCount", sendSummary);

      accessor.setProperty(keyBuilder.controllerTaskStatus(
          MessageType.SCHEDULER_MSG.toString(), _message.getMsgId()),
          new StatusUpdate(statusUpdate));

      result.getTaskResultMap().put(
          "ControllerResult",
View Full Code Here

      RoutingTable newRoutingTable = new RoutingTable();
      _routingTableRef.set(newRoutingTable);
      return;
    }
   
    HelixDataAccessor accessor = changeContext.getManager().getHelixDataAccessor();
    Builder keyBuilder = accessor.keyBuilder();
    List<ExternalView> externalViewList = accessor.getChildValues(keyBuilder.externalViews());
    refresh(externalViewList, changeContext);   
  }
View Full Code Here

    refresh(externalViewList, changeContext);   
  }
 
  private void refresh(List<ExternalView> externalViewList, NotificationContext changeContext)
  {
    HelixDataAccessor accessor = changeContext.getManager().getHelixDataAccessor();
    Builder keyBuilder = accessor.keyBuilder();
   
    List<InstanceConfig> configList = accessor.getChildValues(keyBuilder.instanceConfigs());
    Map<String, InstanceConfig> instanceConfigMap = new HashMap<String, InstanceConfig>();
    for (InstanceConfig config : configList)
    {
      instanceConfigMap.put(config.getId(), config);
    }
View Full Code Here

    {
      throw new StageException("Missing attributes in event:" + event
          + ". Requires ClusterManager|RESOURCES|DataCache");
    }

    HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();

    CurrentStateOutput currentStateOutput =
        event.getAttribute(AttributeName.CURRENT_STATE.toString());

    List<ExternalView> newExtViews = new ArrayList<ExternalView>();
    List<PropertyKey> keys = new ArrayList<PropertyKey>();

    for (String resourceName : resourceMap.keySet())
    {
      ExternalView view = new ExternalView(resourceName);
      // view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
      // if resource ideal state has bucket size, set it
      // otherwise resource has been dropped, use bucket size from current state instead
      Resource resource = resourceMap.get(resourceName);
      if (resource.getBucketSize() > 0)
      {
        view.setBucketSize(resource.getBucketSize());
      }
      else
      {
        view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
      }

      for (Partition partition : resource.getPartitions())
      {
        Map<String, String> currentStateMap =
            currentStateOutput.getCurrentStateMap(resourceName, partition);
        if (currentStateMap != null && currentStateMap.size() > 0)
        {
          // Set<String> disabledInstances
          // = cache.getDisabledInstancesForResource(resource.toString());
          for (String instance : currentStateMap.keySet())
          {
            // if (!disabledInstances.contains(instance))
            // {
            view.setState(partition.getPartitionName(),
                          instance,
                          currentStateMap.get(instance));
            // }
          }
        }
      }
      // Update cluster status monitor mbean
      ClusterStatusMonitor clusterStatusMonitor =
          (ClusterStatusMonitor) event.getAttribute("clusterStatusMonitor");
      if (clusterStatusMonitor != null)
      {
        clusterStatusMonitor.onExternalViewChange(view,
                                                  cache._idealStateMap.get(view.getResourceName()));
      }

      // compare the new external view with current one, set only on different
      Map<String, ExternalView> curExtViews =
          dataAccessor.getChildValuesMap(manager.getHelixDataAccessor()
                                                .keyBuilder()
                                                .externalViews());

      ExternalView curExtView = curExtViews.get(resourceName);
      if (curExtView == null || !curExtView.getRecord().equals(view.getRecord()))
      {
        keys.add(manager.getHelixDataAccessor().keyBuilder().externalView(resourceName));
        newExtViews.add(view);
        // dataAccessor.setProperty(PropertyType.EXTERNALVIEW, view,
        // resourceName);
      }
    }

    if (newExtViews.size() > 0)
    {
      dataAccessor.setChildren(keys, newExtViews);
    }

    long endTime = System.currentTimeMillis();
    log.info("END ExternalViewComputeStage.process(). took: " + (endTime - startTime)
        + " ms");
View Full Code Here

      try
      {
        Message nopMsg = new Message(MessageType.NO_OP, UUID.randomUUID().toString());
        nopMsg.setSrcName(_manager.getInstanceName());

        HelixDataAccessor accessor = _manager.getHelixDataAccessor();
        Builder keyBuilder = accessor.keyBuilder();

        if (_manager.getInstanceType() == InstanceType.CONTROLLER
            || _manager.getInstanceType() == InstanceType.CONTROLLER_PARTICIPANT)
        {
          nopMsg.setTgtName("Controller");
          accessor.setProperty(keyBuilder.controllerMessage(nopMsg.getId()), nopMsg);
        }

        if (_manager.getInstanceType() == InstanceType.PARTICIPANT
            || _manager.getInstanceType() == InstanceType.CONTROLLER_PARTICIPANT)
        {
          nopMsg.setTgtName(_manager.getInstanceName());
          accessor.setProperty(keyBuilder.message(nopMsg.getTgtName(), nopMsg.getId()),
                               nopMsg);
        }
        logger.info("Send NO_OP message to " + nopMsg.getTgtName() + ", msgId: "
            + nopMsg.getId());
      }
View Full Code Here

TOP

Related Classes of org.apache.helix.HelixDataAccessor

Copyright © 2018 www.massapicom. 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.