Package org.apache.helix.model

Examples of org.apache.helix.model.StateModelDefinition


      admin.addCluster(clusterName, true);

      // add state model definition
      StateModelConfigGenerator generator = new StateModelConfigGenerator();
      admin.addStateModelDef(clusterName, DEFAULT_STATE_MODEL,
          new StateModelDefinition(generator.generateConfigForOnlineOffline()));
      // addNodes
      for (int i = 0; i < numNodes; i++) {
        String port = "" + (12001 + i);
        String serverId = "localhost_" + port;
        InstanceConfig config = new InstanceConfig(serverId);
View Full Code Here


            jsonParameters.getExtraParameter(JsonParameters.NEW_STATE_MODEL_DEF);
        HelixDataAccessor accessor =
            ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);

        accessor.setProperty(accessor.keyBuilder().stateModelDef(newStateModel.getId()),
            new StateModelDefinition(newStateModel));
      } else {
        throw new HelixException("Unsupported command: " + command + ". Should be one of ["
            + ClusterSetup.addStateModelDef + "]");
      }
      getResponse().setEntity(getStateModelRepresentation(clusterName, modelName));
View Full Code Here

      admin.addInstance(CLUSTER_NAME, INSTANCE_CONFIG_LIST.get(i));
      echo("\t Added participant: " + INSTANCE_CONFIG_LIST.get(i).getInstanceName());
    }

    // Add a state model
    StateModelDefinition myStateModel = defineStateModel();
    echo("Configuring StateModel: " + "MyStateModel  with 1 Master and 1 Slave");
    admin.addStateModelDef(CLUSTER_NAME, STATE_MODEL_NAME, myStateModel);

    // Add a resource with 6 partitions and 2 replicas
    echo("Adding a resource MyResource: " + "with 6 partitions and 2 replicas");
View Full Code Here

    builder.upperBound(MASTER, 1);
    // dynamic constraint, R means it should be derived based on the replication
    // factor.
    builder.dynamicUpperBound(SLAVE, "R");

    StateModelDefinition statemodelDefinition = builder.build();
    return statemodelDefinition;
  }
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);

        // we should generate message based on the desired-state priority
        // so keep generated messages in a temp map keyed by state
        // desired-state->list of generated-messages
        Map<String, List<Message>> messageMap = new HashMap<String, List<Message>>();

        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);
            if (idealState != null
                && idealState.getStateModelDefRef().equalsIgnoreCase(
                    DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE)) {
              if (idealState.getRecord().getMapField(partition.getPartitionName()) != null) {
                message.getRecord().setMapField(Message.Attributes.INNER_MESSAGE.toString(),
                    idealState.getRecord().getMapField(partition.getPartitionName()));
              }
            }
            // Set timeout of needed
            String stateTransition =
                currentState + "-" + nextState + "_" + Message.Attributes.TIMEOUT;
            if (idealState != null) {
              String timeOutStr = idealState.getRecord().getSimpleField(stateTransition);
              if (timeOutStr == null
                  && idealState.getStateModelDefRef().equalsIgnoreCase(
                      DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE)) {
                // scheduled task queue
                if (idealState.getRecord().getMapField(partition.getPartitionName()) != null) {
                  timeOutStr =
                      idealState.getRecord().getMapField(partition.getPartitionName())
                          .get(Message.Attributes.TIMEOUT.toString());
                }
              }
              if (timeOutStr != null) {
                try {
                  int timeout = Integer.parseInt(timeOutStr);
                  if (timeout > 0) {
                    message.setExecutionTimeout(timeout);
                  }
                } catch (Exception e) {
                  logger.error("", e);
                }
              }
            }
            message.getRecord().setSimpleField("ClusterEventName", event.getName());
            // output.addMessage(resourceName, partition, message);
            if (!messageMap.containsKey(desiredState)) {
              messageMap.put(desiredState, new ArrayList<Message>());
            }
            messageMap.get(desiredState).add(message);
          }
        }

        // add generated messages to output according to state priority
        List<String> statesPriorityList = stateModelDef.getStatesPriorityList();
        for (String state : statesPriorityList) {
          if (messageMap.containsKey(state)) {
            for (Message message : messageMap.get(state)) {
              output.addMessage(resourceName, partition, message);
            }
View Full Code Here

  @Override
  public ResourceAssignment computeBestPossiblePartitionState(ClusterDataCache cache,
      IdealState idealState, Resource resource, CurrentStateOutput currentStateOutput) {
    String stateModelDefName = idealState.getStateModelDefRef();
    StateModelDefinition stateModelDef = cache.getStateModelDef(stateModelDefName);
    if (LOG.isDebugEnabled()) {
      LOG.debug("Processing resource:" + resource.getResourceName());
    }
    ResourceAssignment partitionMapping = new ResourceAssignment();
    for (Partition partition : resource.getPartitions()) {
View Full Code Here

  @Override
  public ResourceAssignment computeBestPossiblePartitionState(ClusterDataCache cache,
      IdealState idealState, Resource resource, CurrentStateOutput currentStateOutput) {
    String stateModelDefName = idealState.getStateModelDefRef();
    StateModelDefinition stateModelDef = cache.getStateModelDef(stateModelDefName);
    if (LOG.isDebugEnabled()) {
      LOG.debug("Processing resource:" + resource.getResourceName());
    }
    ResourceAssignment partitionMapping = new ResourceAssignment();
    for (Partition partition : resource.getPartitions()) {
View Full Code Here

  @Override
  public IdealState computeNewIdealState(String resourceName, IdealState currentIdealState,
      CurrentStateOutput currentStateOutput, ClusterDataCache clusterData) {
    List<String> partitions = new ArrayList<String>(currentIdealState.getPartitionSet());
    String stateModelName = currentIdealState.getStateModelDefRef();
    StateModelDefinition stateModelDef = clusterData.getStateModelDef(stateModelName);
    Map<String, LiveInstance> liveInstance = clusterData.getLiveInstances();
    String replicas = currentIdealState.getReplicas();

    LinkedHashMap<String, Integer> stateCountMap = new LinkedHashMap<String, Integer>();
    stateCountMap = stateCount(stateModelDef, liveInstance.size(), Integer.parseInt(replicas));
View Full Code Here

      IdealState idealState, Resource resource, CurrentStateOutput currentStateOutput) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Processing resource:" + resource.getResourceName());
    }
    String stateModelDefName = idealState.getStateModelDefRef();
    StateModelDefinition stateModelDef = cache.getStateModelDef(stateModelDefName);
    ResourceAssignment partitionMapping = new ResourceAssignment();
    for (Partition partition : resource.getPartitions()) {
      Map<String, String> currentStateMap =
          currentStateOutput.getCurrentStateMap(resource.getResourceName(), partition);
      Set<String> disabledInstancesForPartition =
View Full Code Here

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

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

TOP

Related Classes of org.apache.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.