Package com.linkedin.helix.model

Examples of com.linkedin.helix.model.Resource


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


    Iterator<Message> iter = messages.iterator();
    while (iter.hasNext())
    {
      Message message = iter.next();
      String resourceName = message.getResourceName();
      Resource resource = resourceMap.get(resourceName);
      if (resource == null || !resource.getEnableGroupMessage())
      {
        outputMessages.add(message);
        continue;
      }
View Full Code Here

    }
    MessageGenerationOutput output = new MessageGenerationOutput();

    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

    for (String resourceName : resourceMap.keySet())
    {
      logger.debug("Processing resource:" + resourceName);

      Resource resource = resourceMap.get(resourceName);
      // Ideal state may be gone. In that case we need to get the state model name
      // from the current state
      IdealState idealState = cache.getIdealState(resourceName);

      String stateModelDefName;

      if (idealState == null)
      {
        // if ideal state is deleted, use an empty one
        logger.info("resource:" + resourceName + " does not exist anymore");
        stateModelDefName = currentStateOutput.getResourceStateModelDef(resourceName);
        idealState = new IdealState(resourceName);
      }
      else
      {
        stateModelDefName = idealState.getStateModelDefRef();
      }

      StateModelDefinition stateModelDef = cache.getStateModelDef(stateModelDefName);
      if (idealState.getIdealStateMode() == IdealStateModeProperty.AUTO_REBALANCE)
      {
        calculateAutoBalancedIdealState(cache,
                                        idealState,
                                        stateModelDef,
                                        currentStateOutput);
      }

      // For idealstate that has rebalancing timer and is in AUTO mode, we will run jsql
      // queries to calculate the
      // preference list

      Map<String, List<String>> queryPartitionPriorityLists = null;
      if (idealState.getIdealStateMode() == IdealStateModeProperty.AUTO
          && idealState.getRebalanceTimerPeriod() > 0)
      {
        if (manager != null)
        {
          queryPartitionPriorityLists =
              calculatePartitionPriorityListWithQuery(manager, idealState);
        }
      }

      for (Partition partition : resource.getPartitions())
      {
        Map<String, String> currentStateMap =
            currentStateOutput.getCurrentStateMap(resourceName, partition);

        Map<String, String> bestStateForPartition;
View Full Code Here

        String resourceName = idealState.getResourceName();

        for (String partition : partitionSet)
        {
          addPartition(partition, resourceName, resourceMap);
          Resource resource = resourceMap.get(resourceName);
          resource.setStateModelDefRef(idealState.getStateModelDefRef());
          resource.setStateModelFactoryName(idealState.getStateModelFactoryName());
          resource.setBucketSize(idealState.getBucketSize());
          resource.setEnableGroupMessage(idealState.getGroupMessageMode());
        }
      }
    }

    // It's important to get partitions from CurrentState as well since the
    // idealState might be removed.
    Map<String, LiveInstance> availableInstances = cache.getLiveInstances();

    if (availableInstances != null && availableInstances.size() > 0)
    {
      for (LiveInstance instance : availableInstances.values())
      {
        String instanceName = instance.getInstanceName();
        String clientSessionId = instance.getSessionId();

        Map<String, CurrentState> currentStateMap = cache.getCurrentState(instanceName,
            clientSessionId);
        if (currentStateMap == null || currentStateMap.size() == 0)
        {
          continue;
        }
        for (CurrentState currentState : currentStateMap.values())
        {

          String resourceName = currentState.getResourceName();
          Map<String, String> resourceStateMap = currentState.getPartitionStateMap();
          addResource(resourceName, resourceMap);
          Resource resource = resourceMap.get(resourceName);
          resource.setStateModelDefRef(currentState.getStateModelDefRef());
          resource.setStateModelFactoryName(currentState.getStateModelFactoryName());
          resource.setBucketSize(currentState.getBucketSize());
          resource.setEnableGroupMessage(currentState.getGroupMessageMode());

          if (currentState.getStateModelDefRef() == null)
          {
            LOG.error("state model def is null." + "resource:" + currentState.getResourceName()
                + ", partitions: " + currentState.getPartitionStateMap().keySet() + ", states: "
View Full Code Here

    {
      return;
    }
    if (!resourceMap.containsKey(resource))
    {
      resourceMap.put(resource, new Resource(resource));
    }
  }
View Full Code Here

    {
      return;
    }
    if (!resourceMap.containsKey(resourceName))
    {
      resourceMap.put(resourceName, new Resource(resourceName));
    }
    Resource resource = resourceMap.get(resourceName);
    resource.addPartition(partition);

  }
View Full Code Here

    for (String resourceName : resourceMap.keySet())
    {
      ExternalView view = new ExternalView(resourceName);
      view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
     
      Resource resource = resourceMap.get(resourceName);
      for (Partition partition : resource.getPartitions())
      {
        Map<String, String> currentStateMap =
            currentStateOutput.getCurrentStateMap(resourceName, partition);
        if (currentStateMap != null && currentStateMap.size() > 0)
        {
View Full Code Here

TOP

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

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.