Package org.apache.helix

Examples of org.apache.helix.HelixDataAccessor


    }

    // 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


        if (correlationId != null)
        {
          tempMessage.setCorrelationId(correlationId);
        }

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

        if (receiverType == InstanceType.CONTROLLER)
        {
          // _manager.getDataAccessor().setProperty(PropertyType.MESSAGES_CONTROLLER,
          // tempMessage,
          // tempMessage.getId());
          accessor.setProperty(keyBuilder.controllerMessage(tempMessage.getId()),
                               tempMessage);
        }

        if (receiverType == InstanceType.PARTICIPANT)
        {
          accessor.setProperty(keyBuilder.message(tempMessage.getTgtName(),
                                                  tempMessage.getId()),
                               tempMessage);
        }
      }
    }
View Full Code Here

      if (!matchedList.isEmpty())
      {
        Map<String, String> sessionIdMap = new HashMap<String, String>();
        if (recipientCriteria.isSessionSpecific())
        {
          HelixDataAccessor accessor = _manager.getHelixDataAccessor();
          Builder keyBuilder = accessor.keyBuilder();

          List<LiveInstance> liveInstances =
              accessor.getChildValues(keyBuilder.liveInstances());

          for (LiveInstance liveInstance : liveInstances)
          {
            sessionIdMap.put(liveInstance.getInstanceName(), liveInstance.getSessionId());
          }
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);
        }
      }
      catch (Exception e)
      {
View Full Code Here

    // per-instance statusUpdates
    // and errors
    logger.info("Scannning status updates ...");
    try
    {
      HelixDataAccessor accessor = _manager.getHelixDataAccessor();
      Builder keyBuilder = accessor.keyBuilder();

      List<String> instances = accessor.getChildNames(keyBuilder.instanceConfigs());
      for (String instanceName : instances)
      {
        scanPath(HelixUtil.getInstancePropertyPath(_manager.getClusterName(), instanceName,
            PropertyType.STATUSUPDATES), _thresholdNoChangeInMs);
        scanPath(HelixUtil.getInstancePropertyPath(_manager.getClusterName(), instanceName,
View Full Code Here

  }

  private void testDeactivateCluster() throws Exception,
      InterruptedException
  {
    HelixDataAccessor accessor;
    String path;
    // deactivate cluster
    String clusterUrl = getClusterUrl("clusterTest1");
    Map<String, String> paraMap = new HashMap<String, String>();
    paraMap.put(JsonParameters.ENABLED, "false");
    paraMap.put(JsonParameters.GRAND_CLUSTER, "Klazt3rz");
    paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.activateCluster);

    String response = assertSuccessPostOperation(clusterUrl, paraMap, false);
    Thread.sleep(6000);
    Assert.assertFalse(_gZkClient.exists("/Klazt3rz/IDEALSTATES/clusterTest1"));

    accessor = _startCMResultMap.get("localhost_1231")._manager.getHelixDataAccessor();
    path = accessor.keyBuilder().controllerLeader().getPath();
    Assert.assertFalse(_gZkClient.exists(path));

    deleteUrl(clusterUrl, true);

    Assert.assertTrue(_gZkClient.exists("/clusterTest1"));
View Full Code Here

  }

  private void testEnablePartitions() throws IOException,
      InterruptedException
  {
    HelixDataAccessor accessor;
    accessor = _startCMResultMap.get("localhost_1231")._manager.getHelixDataAccessor();
    // drop node should fail as not disabled
    String hostName = "localhost_1231";
    String instanceUrl = getInstanceUrl("clusterTest1", hostName);
    ExternalView ev = accessor.getProperty(accessor.keyBuilder().externalView("db_11"));

    Map<String, String> paraMap = new HashMap<String, String>();
    paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.enablePartition);
    paraMap.put(JsonParameters.ENABLED, "false");
    paraMap.put(JsonParameters.PARTITION, "db_11_0;db_11_15");
    paraMap.put(JsonParameters.RESOURCE, "db_11");

    String response = assertSuccessPostOperation(instanceUrl, paraMap, false);
    Assert.assertTrue(response.contains("DISABLED_PARTITION"));
    Assert.assertTrue(response.contains("db_11_0"));
    Assert.assertTrue(response.contains("db_11_15"));

    boolean verifyResult =
        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
                                                                                 "clusterTest1"));
    Assert.assertTrue(verifyResult);

    ev = accessor.getProperty(accessor.keyBuilder().externalView("db_11"));
    Assert.assertEquals(ev.getStateMap("db_11_0").get(hostName), "OFFLINE");
    Assert.assertEquals(ev.getStateMap("db_11_15").get(hostName), "OFFLINE");

    paraMap.put(JsonParameters.ENABLED, "true");
    response = assertSuccessPostOperation(instanceUrl, paraMap, false);
    Assert.assertFalse(response.contains("db_11_0"));
    Assert.assertFalse(response.contains("db_11_15"));

    verifyResult =
        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
                                                                                 "clusterTest1"));
    Assert.assertTrue(verifyResult);

    ev = accessor.getProperty(accessor.keyBuilder().externalView("db_11"));
    Assert.assertEquals(ev.getStateMap("db_11_0").get(hostName), "MASTER");
    Assert.assertEquals(ev.getStateMap("db_11_15").get(hostName), "SLAVE");
  }
View Full Code Here

    Assert.assertEquals(ev.getStateMap("db_11_15").get(hostName), "SLAVE");
  }

  private void testInstanceOperations() throws Exception
  {
    HelixDataAccessor accessor;
    // drop node should fail as not disabled
    String instanceUrl = getInstanceUrl("clusterTest1", "localhost_1232");
    deleteUrl(instanceUrl, true);

    // disabled node
    Map<String, String> paraMap = new HashMap<String, String>();
    paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.enableInstance);
    paraMap.put(JsonParameters.ENABLED, "false");
    String response = assertSuccessPostOperation(instanceUrl, paraMap, false);
    Assert.assertTrue(response.contains("false"));

    // Cannot drop / swap
    deleteUrl(instanceUrl, true);

    String instancesUrl = getClusterUrl("clusterTest1") + "/instances";
    paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.swapInstance);
    paraMap.put(JsonParameters.OLD_INSTANCE, "localhost_1232");
    paraMap.put(JsonParameters.NEW_INSTANCE, "localhost_12320");
    response = assertSuccessPostOperation(instancesUrl, paraMap, true);

    // disconnect the node
    _startCMResultMap.get("localhost_1232")._manager.disconnect();
    _startCMResultMap.get("localhost_1232")._thread.interrupt();

    // add new node then swap instance
    paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstance);
    paraMap.put(JsonParameters.INSTANCE_NAME, "localhost_12320");
    response = assertSuccessPostOperation(instancesUrl, paraMap, false);
    Assert.assertTrue(response.contains("localhost_12320"));

    // swap instance. The instance get swapped out should not exist anymore
    paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.swapInstance);
    paraMap.put(JsonParameters.OLD_INSTANCE, "localhost_1232");
    paraMap.put(JsonParameters.NEW_INSTANCE, "localhost_12320");
    response = assertSuccessPostOperation(instancesUrl, paraMap, false);
    Assert.assertTrue(response.contains("localhost_12320"));
    Assert.assertFalse(response.contains("localhost_1232\""));

    accessor = _startCMResultMap.get("localhost_1231")._manager.getHelixDataAccessor();
    String path = accessor.keyBuilder().instanceConfig("localhost_1232").getPath();
    Assert.assertFalse(_gZkClient.exists(path));

    _startCMResultMap.put("localhost_12320",
                          TestHelper.startDummyProcess(ZK_ADDR,
                                                       "clusterTest1",
View Full Code Here

    Thread.sleep(500);

    deleteUrl(clusterUrl, true);

    // verify leader node
    HelixDataAccessor accessor =
        _startCMResultMap.get("controller_9001")._manager.getHelixDataAccessor();
    LiveInstance controllerLeader =
        accessor.getProperty(accessor.keyBuilder().controllerLeader());
    Assert.assertTrue(controllerLeader.getInstanceName().startsWith("controller_900"));

    accessor = _startCMResultMap.get("localhost_1232")._manager.getHelixDataAccessor();
    LiveInstance leader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
    for(int i = 0; i < 5; i++)
    {
      if(leader != null)
      {
        break;
      }
      Thread.sleep(1000);
      leader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
    }
    Assert.assertTrue(leader.getInstanceName().startsWith("controller_900"));

    boolean verifyResult =
        ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR,
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 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.