Package com.linkedin.helix

Examples of com.linkedin.helix.HelixDataAccessor


  }

  @Override
  public void enableCluster(String clusterName, boolean enabled)
  {
    HelixDataAccessor accessor =
        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
    Builder keyBuilder = accessor.keyBuilder();

    if (enabled)
    {
      accessor.removeProperty(keyBuilder.pause());
    }
    else
    {
      accessor.createProperty(keyBuilder.pause(), new PauseSignal("pause"));
    }
  }
View Full Code Here


      Map<String, String> summary = new TreeMap<String, String>();
      summary.put("TotalMessages:", "" + _resultSummaryMap.size());
      summary.put("Timeout", "" + timeOut);
      _resultSummaryMap.put("Summary", summary);

      HelixDataAccessor accessor = manager.getHelixDataAccessor();
      Builder keyBuilder = accessor.keyBuilder();
      ZNRecord statusUpdate = accessor.getProperty(
          keyBuilder.controllerTaskStatus(MessageType.SCHEDULER_MSG.toString(),
              originalMessage.getMsgId())).getRecord();

      statusUpdate.getMapFields().putAll(_resultSummaryMap);
      accessor.setProperty(keyBuilder.controllerTaskStatus(
          MessageType.SCHEDULER_MSG.toString(), originalMessage.getMsgId()),
          new StatusUpdate(statusUpdate));

    }
View Full Code Here

  {
    @Override
    public void doTransition(Message message, NotificationContext context)
    {
      HelixManager manager = context.getManager();
      HelixDataAccessor accessor = manager.getHelixDataAccessor();
      String fromState = message.getFromState();
      String toState = message.getToState();
      String instance = message.getTgtName();
      String partition = message.getPartitionName();
View Full Code Here

  //@Test
  public void testWildcardExpansion() throws Exception
  {
    HelixManager manager = ((TestHelper.StartCMResult) (_startCMResultMap.values().toArray()[0]))._manager;
    HelixDataAccessor accessor = manager.getHelixDataAccessor();

    List<String> instancesInCluster = manager.getClusterManagmentTool().getInstancesInCluster(manager.getClusterName());
    for(String instance : instancesInCluster)
    {
      ZNRecord record = new ZNRecord("scnTable");
      record.setSimpleField("k1", "v1");
      Builder kb = accessor.keyBuilder();
      accessor.setProperty(kb.healthReport(instance, "scnTable"), new HealthStat(record));
    }

    String path = "INSTANCES/*/HEALTHREPORT/scnTable";
    DataAccessorBasedTupleReader tupleReader = new DataAccessorBasedTupleReader(accessor, manager.getClusterName());
    List<ZNRecord> tuples = tupleReader.get(path);
View Full Code Here

  @Test
  public void testNewMasterSelection() throws Exception
  {
    HelixManager manager = ((TestHelper.StartCMResult) (_startCMResultMap.values().toArray()[0]))._manager;
    HelixDataAccessor accessor = manager.getHelixDataAccessor();

    IdealState resourceIdealState = manager.getClusterManagmentTool().getResourceIdealState(manager.getClusterName(), TEST_DB);
    Map<String, Map<String, Integer>> scnMap = new HashMap<String, Map<String, Integer>>();

    List<String> instancesInCluster = manager.getClusterManagmentTool().getInstancesInCluster(manager.getClusterName());
    List<String> instances = new ArrayList<String>();
    instances.addAll(instancesInCluster);
    //instances.add(instancesInCluster.get(0));
    instances.add("deadInstance");
    System.out.println(instances.size());

    int seq = 50;
    for(String instance : instances)
    {
      ZNRecord scnRecord = new ZNRecord("scnTable");
      scnRecord.setSimpleField("instance", instance);
      for(int i = 0; i < _PARTITIONS; i++)
      {
        Map<String, String> scnDetails = new HashMap<String, String>();

        String partition = TEST_DB + "_" + i;
        List<String> idealStatePrefList =
            resourceIdealState.getPreferenceList(partition);
        String idealStateMaster = idealStatePrefList.get(0);

        scnDetails.put("gen", "4");

        if (instance.equals(idealStateMaster))
        {
          scnDetails.put("seq", "" + (seq - 25));
        }
        else
        {
          scnDetails.put("seq", "" + seq++);
        }
        scnRecord.setMapField(partition, scnDetails);
      }

      Builder kb = accessor.keyBuilder();
      accessor.setProperty(kb.healthReport(instance, "scnTable"), new HealthStat(scnRecord));
    }

    ZNRecordQueryProcessor processor = new ZNRecordQueryProcessor();
    DataAccessorBasedTupleReader tupleReader = new DataAccessorBasedTupleReader(accessor, manager.getClusterName());
View Full Code Here

  public void testStateMismatch() throws InterruptedException
  {
    String controllerName = CONTROLLER_PREFIX + "_0";
   
    HelixManager manager = _startCMResultMap.get(controllerName)._manager;
    HelixDataAccessor accessor = manager.getHelixDataAccessor();
    Builder kb = accessor.keyBuilder();
    ExternalView ev = accessor.getProperty(kb.externalView(TEST_DB));
    Map<String, LiveInstance> liveinstanceMap = accessor.getChildValuesMap(accessor.keyBuilder().liveInstances());
   
    for(String instanceName : liveinstanceMap.keySet())
    {
      String sessionid = liveinstanceMap.get(instanceName).getSessionId();
      for(String partition : ev.getPartitionSet())
      {
        if(ev.getStateMap(partition).containsKey(instanceName))
        {
          String uuid = UUID.randomUUID().toString();
          Message message = new Message(MessageType.STATE_TRANSITION, uuid);
          boolean rand = new Random().nextInt(10) > 5;
          if(ev.getStateMap(partition).get(instanceName).equals("MASTER"))
          {
            message.setSrcName(manager.getInstanceName());
            message.setTgtName(instanceName);
            message.setMsgState(MessageState.NEW);
            message.setPartitionName(partition);
            message.setResourceName(TEST_DB);
            message.setFromState(rand ? "SLAVE" : "OFFLINE");
            message.setToState(rand ? "MASTER" : "SLAVE");
            message.setTgtSessionId(sessionid);
            message.setSrcSessionId(manager.getSessionId());
            message.setStateModelDef("MasterSlave");
            message.setStateModelFactoryName("DEFAULT");
          }
          else if (ev.getStateMap(partition).get(instanceName).equals("SLAVE"))
          {
            message.setSrcName(manager.getInstanceName());
            message.setTgtName(instanceName);
            message.setMsgState(MessageState.NEW);
            message.setPartitionName(partition);
            message.setResourceName(TEST_DB);
            message.setFromState(rand ? "MASTER" : "OFFLINE");
            message.setToState(rand ? "SLAVE" : "SLAVE");
            message.setTgtSessionId(sessionid);
            message.setSrcSessionId(manager.getSessionId());
            message.setStateModelDef("MasterSlave");
            message.setStateModelFactoryName("DEFAULT");
          }
          accessor.setProperty(accessor.keyBuilder().message(instanceName, message.getMsgId()), message);
        }
      }
    }
    Thread.sleep(3000);
    ExternalView ev2 = accessor.getProperty(kb.externalView(TEST_DB));
    Assert.assertTrue(ev.equals(ev2));
  }
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

      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

    }

    // check if the state model definition exists and cache it
    if (!_stateModelDefs.containsKey(stateModelName))
    {
      HelixDataAccessor accessor = _manager.getHelixDataAccessor();
      Builder keyBuilder = accessor.keyBuilder();
      StateModelDefinition stateModelDef =
          accessor.getProperty(keyBuilder.stateModelDef(stateModelName));
      if (stateModelDef == null)
      {
        throw new HelixException("stateModelDef for " + stateModelName
            + " does NOT exists");
      }
View Full Code Here

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

    HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
    List<Message> messagesToSend = new ArrayList<Message>();
    for (String resourceName : resourceMap.keySet())
    {
      Resource resource = resourceMap.get(resourceName);
      for (Partition partition : resource.getPartitions())
      {
        List<Message> messages = messageOutput.getMessages(resourceName, partition);
        messagesToSend.addAll(messages);
      }
    }

    List<Message> outputMessages =
        groupMessage(dataAccessor.keyBuilder(), messagesToSend, resourceMap);
    sendMessages(dataAccessor, outputMessages);

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

TOP

Related Classes of com.linkedin.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.