Package com.linkedin.helix.model

Examples of com.linkedin.helix.model.StateModelDefinition


      if(command.equalsIgnoreCase(ClusterSetup.addStateModelDef))
      {
        ZNRecord newStateModel = jsonParameters.getExtraParameter(JsonParameters.NEW_STATE_MODEL_DEF);
        HelixDataAccessor accessor = ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
        
        accessor.setProperty(accessor.keyBuilder().stateModelDef(newStateModel.getId()), new StateModelDefinition(newStateModel) );
        getResponse().setEntity(getStateModelsRepresentation());
      }
      else
      {
          throw new HelixException("Unsupported command: " + command
View Full Code Here


    MessageSelectionStageOutput output = new MessageSelectionStageOutput();

    for (String resourceName : resourceMap.keySet())
    {
      Resource resource = resourceMap.get(resourceName);
      StateModelDefinition stateModelDef =
          cache.getStateModelDef(resource.getStateModelDefRef());

      Map<String, Integer> stateTransitionPriorities =
          getStateTransitionPriorityMap(stateModelDef);
      IdealState idealState = cache.getIdealState(resourceName);
      Map<String, Bounds> stateConstraints =
          computeStateConstraints(stateModelDef, idealState, cache);

      for (Partition partition : resource.getPartitions())
      {
        List<Message> messages = messageGenOutput.getMessages(resourceName, partition);
        List<Message> selectedMessages =
            selectMessages(cache.getLiveInstances(),
                           currentStateOutput.getCurrentStateMap(resourceName, partition),
                           currentStateOutput.getPendingStateMap(resourceName, partition),
                           messages,
                           stateConstraints,
                           stateTransitionPriorities,
                           stateModelDef.getInitialState());
        output.addMessages(resourceName, partition, selectedMessages);
      }
    }
    event.addAttribute(AttributeName.MESSAGES_SELECTED.toString(), output);
  }
View Full Code Here

    // add MasterSlave state mode definition
    StateModelConfigGenerator generator = new StateModelConfigGenerator();
    admin.addStateModelDef(clusterName,
                           "MasterSlave",
                           new StateModelDefinition(generator.generateConfigForMasterSlave()));

    // add 3 participants: "localhost:{12918, 12919, 12920}"
    for (int i = 0; i < 3; i++)
    {
      int port = 12918 + i;
View Full Code Here

    // add MasterSlave state mode definition
    StateModelConfigGenerator generator = new StateModelConfigGenerator();
    admin.addStateModelDef(clusterName,
                           "MasterSlave",
                           new StateModelDefinition(generator.generateConfigForMasterSlave()));

    // add 3 participants: "localhost:{12918, 12919, 12920}"
    for (int i = 0; i < 3; i++)
    {
      int port = 12918 + i;
View Full Code Here

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

    paraMap.put(JsonParameters.MANAGEMENT_COMMAND,
                ClusterSetup.addStateModelDef);

    ZNRecord r = new ZNRecord("Test");
    r.merge(zn);
    StateModelDefinition newStateModel = new StateModelDefinition(r);

    httpUrlBase =
        "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/StateModelDefs";
    resourceRef = new Reference(httpUrlBase);
    request = new Request(Method.POST, resourceRef);
View Full Code Here

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

    for (String resourceName : resourceMap.keySet())
    {
      Resource resource = resourceMap.get(resourceName);
      int bucketSize = resource.getBucketSize();

      StateModelDefinition stateModelDef = cache.getStateModelDef(resource.getStateModelDefRef());

      for (Partition partition : resource.getPartitions())
      {
        Map<String, String> instanceStateMap = bestPossibleStateOutput.getInstanceStateMap(
            resourceName, partition);

        for (String instanceName : instanceStateMap.keySet())
        {
          String desiredState = instanceStateMap.get(instanceName);

          String currentState = currentStateOutput.getCurrentState(resourceName, partition,
              instanceName);
          if (currentState == null)
          {
            currentState = stateModelDef.getInitialState();
          }

          if (desiredState.equalsIgnoreCase(currentState))
          {
            continue;
          }

          String pendingState = currentStateOutput.getPendingState(resourceName, partition,
              instanceName);

          String nextState = stateModelDef.getNextStateForTransition(currentState, desiredState);
          if (nextState == null)
          {
            logger.error("Unable to find a next state for partition: "
                + partition.getPartitionName() + " from stateModelDefinition"
                + stateModelDef.getClass() + " from:" + currentState + " to:" + desiredState);
            continue;
          }

          if (pendingState != null)
          {
            if (nextState.equalsIgnoreCase(pendingState))
            {
              logger.debug("Message already exists for " + instanceName + " to transit "
                  + partition.getPartitionName() + " from " + currentState + " to " + nextState);
            } else if (currentState.equalsIgnoreCase(pendingState))
            {
              logger.info("Message hasn't been removed for " + instanceName + " to transit"
                  + partition.getPartitionName() + " to " + pendingState + ", desiredState: "
                  + desiredState);
            } else
            {
              logger.info("IdealState changed before state transition completes for "
                  + partition.getPartitionName() + " on " + instanceName + ", pendingState: "
                  + pendingState + ", currentState: " + currentState + ", nextState: " + nextState);
            }
          } else
          {
            Message message = createMessage(manager, resourceName, partition.getPartitionName(),
                instanceName, currentState, nextState, sessionIdMap.get(instanceName),
                stateModelDef.getId(), resource.getStateModelFactoryname(), bucketSize);
            IdealState idealState = cache.getIdealState(resourceName);
            // Set timeout of needed
            String stateTransition = currentState + "-" + nextState + "_"
                + Message.Attributes.TIMEOUT;
            if (idealState != null
View Full Code Here

      else
      {
        stateModelDefName = idealState.getStateModelDefRef();
      }

      StateModelDefinition stateModelDef = cache.getStateModelDef(stateModelDefName);
      if (idealState.getIdealStateMode() == IdealStateModeProperty.AUTO_REBALANCE)
      {
        calculateAutoBalancedIdealState(cache,
                                        idealState,
                                        stateModelDef,
View Full Code Here

    stateTransitionPriorityList.add("IDLE-OFFLINE");
    stateTransitionPriorityList.add("IDLE-DROPPED");
    stateTransitionPriorityList.add("ERROR-IDLED");
    record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
                        stateTransitionPriorityList);
    return new StateModelDefinition(record);
  }
View Full Code Here

TOP

Related Classes of com.linkedin.helix.model.StateModelDefinition

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.