Package org.apache.helix.model

Examples of org.apache.helix.model.ClusterConstraints$ConstraintItem


    String path = keyBuilder.constraint(constraintType.toString()).getPath();

    baseAccessor.update(path, new DataUpdater<ZNRecord>() {
      @Override
      public ZNRecord update(ZNRecord currentData) {
        ClusterConstraints constraints =
            currentData == null ? new ClusterConstraints(constraintType) : new ClusterConstraints(
                currentData);

        constraints.addConstraintItem(ConstraintId.from(constraintId), constraintItem);
        return constraints.getRecord();
      }
    }, AccessOption.PERSISTENT);
  }
View Full Code Here


    baseAccessor.update(path, new DataUpdater<ZNRecord>() {
      @Override
      public ZNRecord update(ZNRecord currentData) {
        if (currentData != null) {
          ClusterConstraints constraints = new ClusterConstraints(currentData);

          constraints.removeConstraintItem(ConstraintId.from(constraintId));
          return constraints.getRecord();
        }
        return null;
      }
    }, AccessOption.PERSISTENT);
  }
View Full Code Here

    ClusterConfiguration configuration = ClusterConfiguration.from(config.getUserConfig());
    configuration.setAutoJoinAllowed(config.autoJoinAllowed());
    _accessor.setProperty(_keyBuilder.clusterConfig(), configuration);
    Map<ConstraintType, ClusterConstraints> constraints = config.getConstraintMap();
    for (ConstraintType type : constraints.keySet()) {
      ClusterConstraints constraint = constraints.get(type);
      _accessor.setProperty(_keyBuilder.constraint(type.toString()), constraint);
    }
    if (config.getStats() == null || config.getStats().getMapFields().isEmpty()) {
      _accessor.removeProperty(_keyBuilder.persistantStat());
    } else {
View Full Code Here

   * @param type the constraint type
   * @param constraintId the constraint id
   * @return true if removed, false otherwise
   */
  public boolean removeConstraint(ConstraintType type, ConstraintId constraintId) {
    ClusterConstraints constraints = _accessor.getProperty(_keyBuilder.constraint(type.toString()));
    if (constraints == null || constraints.getConstraintItem(constraintId) == null) {
      LOG.error("Constraint with id " + constraintId + " not present");
      return false;
    }
    constraints.removeConstraintItem(constraintId);
    return _accessor.setProperty(_keyBuilder.constraint(type.toString()), constraints);
  }
View Full Code Here

   *         number of replicas, or "N" for number of participants
   */
  public String getStateUpperBoundConstraint(Scope<?> scope, StateModelDefId stateModelDefId,
      State state) {
    // set up attributes to match based on the scope
    ClusterConstraints stateConstraints = getConstraintMap().get(ConstraintType.STATE_CONSTRAINT);
    Map<ConstraintAttribute, String> matchAttributes = Maps.newHashMap();
    matchAttributes.put(ConstraintAttribute.STATE, state.toString());
    matchAttributes.put(ConstraintAttribute.STATE_MODEL, stateModelDefId.toString());
    switch (scope.getType()) {
    case CLUSTER:
      // cluster is implicit
      break;
    case RESOURCE:
      matchAttributes.put(ConstraintAttribute.RESOURCE, scope.getScopedId().stringify());
      break;
    default:
      LOG.error("Unsupported scope for state constraint: " + scope);
      return "-1";
    }
    Set<ConstraintItem> matches = stateConstraints.match(matchAttributes);
    int value = -1;
    for (ConstraintItem item : matches) {
      // match: if an R or N is found, always choose that one
      // otherwise, take the minimum of the counts specified in the constraints
      String constraintValue = item.getConstraintValue();
View Full Code Here

   * @return the limit, or Integer.MAX_VALUE if there is no limit
   */
  public int getTransitionConstraint(Scope<?> scope, StateModelDefId stateModelDefId,
      Transition transition) {
    // set up attributes to match based on the scope
    ClusterConstraints transitionConstraints =
        getConstraintMap().get(ConstraintType.MESSAGE_CONSTRAINT);
    Map<ConstraintAttribute, String> matchAttributes = Maps.newHashMap();
    matchAttributes.put(ConstraintAttribute.STATE_MODEL, stateModelDefId.toString());
    matchAttributes.put(ConstraintAttribute.MESSAGE_TYPE, MessageType.STATE_TRANSITION.toString());
    matchAttributes.put(ConstraintAttribute.TRANSITION, transition.toString());
    switch (scope.getType()) {
    case CLUSTER:
      // cluster is implicit
      break;
    case RESOURCE:
      matchAttributes.put(ConstraintAttribute.RESOURCE, scope.getScopedId().stringify());
      break;
    case PARTICIPANT:
      matchAttributes.put(ConstraintAttribute.INSTANCE, scope.getScopedId().stringify());
      break;
    default:
      LOG.error("Unsupported scope for transition constraints: " + scope);
      return Integer.MAX_VALUE;
    }
    Set<ConstraintItem> matches = transitionConstraints.match(matchAttributes);
    int value = Integer.MAX_VALUE;
    for (ConstraintItem item : matches) {
      String constraintValue = item.getConstraintValue();
      if (constraintValue != null) {
        try {
View Full Code Here

          break;
        }
      }
      // add constraint deltas
      for (ConstraintType type : ConstraintType.values()) {
        ClusterConstraints constraints;
        if (orig.getConstraintMap().containsKey(type)) {
          constraints = orig.getConstraintMap().get(type);
        } else {
          constraints = new ClusterConstraints(type);
        }
        // add new constraints
        if (deltaConfig.getConstraintMap().containsKey(type)) {
          ClusterConstraints deltaConstraints = deltaConfig.getConstraintMap().get(type);
          for (ConstraintId constraintId : deltaConstraints.getConstraintItems().keySet()) {
            ConstraintItem constraintItem = deltaConstraints.getConstraintItem(constraintId);
            constraints.addConstraintItem(constraintId, constraintItem);
          }
        }
        // remove constraints
        for (ConstraintId constraintId : _removedConstraints.get(type)) {
View Full Code Here

     * Add a constraint to the cluster
     * @param constraint cluster constraint of a specific type
     * @return Builder
     */
    public Builder addConstraint(ClusterConstraints constraint) {
      ClusterConstraints existConstraints = getConstraintsInstance(constraint.getType());
      for (ConstraintId constraintId : constraint.getConstraintItems().keySet()) {
        existConstraints
            .addConstraintItem(constraintId, constraint.getConstraintItem(constraintId));
      }
      return this;
    }
View Full Code Here

     * @param constraintId unique constraint identifier
     * @param item instantiated ConstraintItem
     * @return Builder
     */
    public Builder addConstraint(ConstraintType type, ConstraintId constraintId, ConstraintItem item) {
      ClusterConstraints existConstraints = getConstraintsInstance(type);
      existConstraints.addConstraintItem(constraintId, item);
      return this;
    }
View Full Code Here

      default:
        LOG.error("Unsupported scope for adding a transition constraint: " + scope);
        return this;
      }
      ConstraintItem item = new ConstraintItemBuilder().addConstraintAttributes(attributes).build();
      ClusterConstraints constraints = getConstraintsInstance(ConstraintType.MESSAGE_CONSTRAINT);
      constraints.addConstraintItem(ConstraintId.from(scope, stateModelDefId, transition), item);
      return this;
    }
View Full Code Here

TOP

Related Classes of org.apache.helix.model.ClusterConstraints$ConstraintItem

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.