Package org.apache.helix.model

Examples of org.apache.helix.model.CurrentState


    Map<ResourceId, PartitionedRebalancerContext.Builder> rebCtxBuilderMap =
        new HashMap<ResourceId, PartitionedRebalancerContext.Builder>();

    for (Participant liveParticipant : cluster.getLiveParticipantMap().values()) {
      for (ResourceId resourceId : liveParticipant.getCurrentStateMap().keySet()) {
        CurrentState currentState = liveParticipant.getCurrentStateMap().get(resourceId);

        if (currentState.getStateModelDefRef() == null) {
          LOG.error("state model def is null." + "resource:" + currentState.getResourceId()
              + ", partitions: " + currentState.getPartitionStateMap().keySet()
              + ", states: " + currentState.getPartitionStateMap().values());
          throw new StageException("State model def is null for resource:"
              + currentState.getResourceId());
        }

        if (!resCfgBuilderMap.containsKey(resourceId)) {
          PartitionedRebalancerContext.Builder rebCtxBuilder =
              new PartitionedRebalancerContext.Builder(resourceId);
          rebCtxBuilder.stateModelDefId(currentState.getStateModelDefId());
          rebCtxBuilder.stateModelFactoryId(StateModelFactoryId.from(currentState
              .getStateModelFactoryName()));
          rebCtxBuilderMap.put(resourceId, rebCtxBuilder);

          ResourceConfig.Builder resCfgBuilder = new ResourceConfig.Builder(resourceId);
          resCfgBuilder.bucketSize(currentState.getBucketSize());
          resCfgBuilder.batchMessageMode(currentState.getBatchMessageMode());
          resCfgBuilderMap.put(resourceId, resCfgBuilder);
        }

        PartitionedRebalancerContext.Builder rebCtxBuilder = rebCtxBuilderMap.get(resourceId);
        for (PartitionId partitionId : currentState.getTypedPartitionStateMap().keySet()) {
          rebCtxBuilder.addPartition(new Partition(partitionId));
        }
      }
    }
View Full Code Here


      LOG.error("Not all of the specified partitions to reset exist for the resource");
      return false;
    }

    // check for a valid current state that has all specified partitions in ERROR state
    CurrentState currentState = participant.getCurrentStateMap().get(resourceId);
    if (currentState == null) {
      LOG.error("The participant does not have a current state for the resource");
      return false;
    }
    for (PartitionId partitionId : resetPartitionIdSet) {
      if (!currentState.getState(partitionId).equals(State.from(HelixDefinedState.ERROR))) {
        LOG.error("Partition " + partitionId + " is not in error state, aborting reset");
        return false;
      }
    }
View Full Code Here

  /**
   * @param resourceId
   * @param bucketSize
   */
  public void setBucketSize(ResourceId resourceId, int bucketSize) {
    CurrentState curStateMeta = _curStateMetaMap.get(resourceId);
    if (curStateMeta == null) {
      curStateMeta = new CurrentState(resourceId);
      _curStateMetaMap.put(resourceId, curStateMeta);
    }
    curStateMeta.setBucketSize(bucketSize);
  }
View Full Code Here

   * @param resourceId
   * @return
   */
  public int getBucketSize(ResourceId resourceId) {
    int bucketSize = 0;
    CurrentState curStateMeta = _curStateMetaMap.get(resourceId);
    if (curStateMeta != null) {
      bucketSize = curStateMeta.getBucketSize();
    }

    return bucketSize;
  }
View Full Code Here

      // verify current state empty
      List<String> liveParticipants = accessor.getChildNames(keyBuilder.liveInstances());
      for (String participant : liveParticipants) {
        List<String> sessionIds = accessor.getChildNames(keyBuilder.sessions(participant));
        for (String sessionId : sessionIds) {
          CurrentState currentState =
              accessor.getProperty(keyBuilder.currentState(participant, sessionId, _resourceName));
          Map<String, String> partitionStateMap = currentState.getPartitionStateMap();
          if (partitionStateMap != null && !partitionStateMap.isEmpty()) {
            LOG.error("Current state not empty for " + participant);
            return false;
          }
        }
View Full Code Here

  public String getResourceStateModelDef(String resourceName) {
    return _resourceStateModelMap.get(resourceName);
  }

  public void setBucketSize(String resource, int bucketSize) {
    CurrentState curStateMeta = _curStateMetaMap.get(resource);
    if (curStateMeta == null) {
      curStateMeta = new CurrentState(resource);
      _curStateMetaMap.put(resource, curStateMeta);
    }
    curStateMeta.setBucketSize(bucketSize);
  }
View Full Code Here

    curStateMeta.setBucketSize(bucketSize);
  }

  public int getBucketSize(String resource) {
    int bucketSize = 0;
    CurrentState curStateMeta = _curStateMetaMap.get(resource);
    if (curStateMeta != null) {
      bucketSize = curStateMeta.getBucketSize();
    }

    return bucketSize;
  }
View Full Code Here

        String resourceName = message.getResourceName();
        if (!curResourceNames.contains(resourceName) && !createCurStateNames.contains(resourceName)) {
          createCurStateNames.add(resourceName);
          createCurStateKeys.add(keyBuilder.currentState(instanceName, sessionId, resourceName));

          CurrentState metaCurState = new CurrentState(resourceName);
          metaCurState.setBucketSize(message.getBucketSize());
          metaCurState.setStateModelDefRef(message.getStateModelDef());
          metaCurState.setSessionId(sessionId);
          metaCurState.setBatchMessageMode(message.getBatchMessageMode());
          String ftyName = message.getStateModelFactoryName();
          if (ftyName != null) {
            metaCurState.setStateModelFactoryName(ftyName);
          } else {
            metaCurState.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY);
          }

          metaCurStates.add(metaCurState);
        }
      }
View Full Code Here

      }
    }

    // check partition is in ERROR state
    String sessionId = liveInstance.getSessionId();
    CurrentState curState =
        accessor.getProperty(keyBuilder.currentState(instanceName, sessionId, resourceName));
    for (String partitionName : resetPartitionNames) {
      if (!curState.getState(partitionName).equals(HelixDefinedState.ERROR.toString())) {
        throw new HelixException("Can't reset state for " + resourceName + "/" + partitionNames
            + " on " + instanceName + ", because not all " + partitionNames + " are in ERROR state");
      }
    }
View Full Code Here

    Assert.assertEquals(stateMap.size(), 1);
    Assert.assertEquals(stateMap.keySet().iterator().next(), "localhost_12918");
    Assert.assertEquals(stateMap.get("localhost_12918"), HelixDefinedState.ERROR.name());

    // localhost_12918 should have TestDB0_4 in ERROR state
    CurrentState cs = accessor.getProperty(keyBuilder.currentState(participants[0].getInstanceName(),
        participants[0].getSessionId(), "TestDB0"));
    Map<String, String> partitionStateMap = cs.getPartitionStateMap();
    Assert.assertEquals(partitionStateMap.size(), 1);
    Assert.assertEquals(partitionStateMap.keySet().iterator().next(), "TestDB0_4");
    Assert.assertEquals(partitionStateMap.get("TestDB0_4"), HelixDefinedState.ERROR.name());

    // all other participants should have cleaned up empty current state
View Full Code Here

TOP

Related Classes of org.apache.helix.model.CurrentState

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.