Package org.apache.helix.api.config

Examples of org.apache.helix.api.config.ResourceConfig


    for (ResourceId resourceId : resourceMap.keySet()) {
      ExternalView view = new ExternalView(resourceId.stringify());
      // view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
      // if resource ideal state has bucket size, set it
      // otherwise resource has been dropped, use bucket size from current state instead
      ResourceConfig resource = resourceMap.get(resourceId);
      SchedulerTaskConfig schedulerTaskConfig = resource.getSchedulerTaskConfig();

      if (resource.getIdealState().getBucketSize() > 0) {
        view.setBucketSize(resource.getIdealState().getBucketSize());
      } else {
        view.setBucketSize(currentStateOutput.getBucketSize(resourceId));
      }
      for (PartitionId partitionId : resource.getSubUnitSet()) {
        Map<ParticipantId, State> currentStateMap =
            currentStateOutput.getCurrentStateMap(resourceId, partitionId);
        if (currentStateMap != null && currentStateMap.size() > 0) {
          // Set<String> disabledInstances
          // = cache.getDisabledInstancesForResource(resource.toString());
View Full Code Here


      idealStateBuilder.setStateModelDefId(statelessService.getStateModelDefId());
      idealStateBuilder.add(PartitionId.from(resourceId, "0"));
      idealStateBuilder.setNumReplica(1);
      ResourceConfig.Builder resourceConfigBuilder =
          new ResourceConfig.Builder(ResourceId.from(resourceName));
      ResourceConfig resourceConfig =
          resourceConfigBuilder.provisionerConfig(provisionerConfig)
              .idealState(idealStateBuilder.build()) //
              .build();
      clusterAccessor.addResource(resourceConfig);
    }
View Full Code Here

    }

    MessageOutput output = new MessageOutput();

    for (ResourceId resourceId : resourceMap.keySet()) {
      ResourceConfig resource = resourceMap.get(resourceId);
      StateModelDefinition stateModelDef =
          stateModelDefMap.get(resource.getIdealState().getStateModelDefId());

      if (stateModelDef == null) {
        LOG.info("resource: "
            + resourceId
            + " doesn't have state-model-def; e.g. we add a resource config but not add the resource in ideal-states");
View Full Code Here

    // get a state model definition
    StateModelDefinition lockUnlock = getLockUnlockModel();

    // set up a resource with the state model definition
    ResourceConfig resource = getResource(lockUnlock);

    // set up a participant
    ParticipantConfig participant = getParticipant();

    // cluster id should be unique
    ClusterId clusterId = ClusterId.from("exampleCluster");

    // a user config is an object that stores arbitrary keys and values for a scope
    // in this case, the scope is the cluster with id clusterId
    // this is optional
    UserConfig userConfig = new UserConfig(Scope.cluster(clusterId));
    userConfig.setIntField("sampleInt", 1);

    // fully specify the cluster with a ClusterConfig
    ClusterConfig.Builder clusterBuilder =
        new ClusterConfig.Builder(clusterId).addResource(resource).addParticipant(participant)
            .addStateModelDefinition(lockUnlock).userConfig(userConfig).autoJoin(true);

    // add a state constraint that is more restrictive than what is in the state model
    clusterBuilder.addStateUpperBoundConstraint(Scope.cluster(clusterId),
        lockUnlock.getStateModelDefId(), State.from("LOCKED"), 1);

    // add a transition constraint (this time with a resource scope)
    clusterBuilder.addTransitionConstraint(Scope.resource(resource.getId()),
        lockUnlock.getStateModelDefId(),
        Transition.from(State.from("RELEASED"), State.from("LOCKED")), 1);

    ClusterConfig cluster = clusterBuilder.build();

    // set up a connection to work with ZooKeeper-persisted data
    HelixConnection connection = new ZkHelixConnection(args[0]);
    connection.connect();

    // create the cluster
    createCluster(cluster, connection);

    // update the resource
    updateResource(resource, clusterId, connection);

    // update the participant
    updateParticipant(participant, clusterId, connection);

    // start the controller
    ControllerId controllerId = ControllerId.from("exampleController");
    HelixController helixController = connection.createController(clusterId, controllerId);
    helixController.startAsync();

    // start the specified participant
    HelixParticipant helixParticipant =
        connection.createParticipant(clusterId, participant.getId());
    helixParticipant.getStateMachineEngine().registerStateModelFactory(
        lockUnlock.getStateModelDefId(), new LockUnlockFactory());
    helixParticipant.startAsync();

    // start another participant via auto join
    HelixParticipant autoJoinParticipant =
        connection.createParticipant(clusterId, ParticipantId.from("localhost_12120"));
    autoJoinParticipant.getStateMachineEngine().registerStateModelFactory(
        lockUnlock.getStateModelDefId(), new LockUnlockFactory());
    autoJoinParticipant.startAsync();

    Thread.sleep(5000);
    printExternalView(connection, clusterId, resource.getId());

    // stop the participants
    helixParticipant.stopAsync();
    autoJoinParticipant.stopAsync();
View Full Code Here

    // message mode
    UserConfig userConfig = new UserConfig(Scope.resource(resourceId));
    userConfig.setSimpleField("key1", "value1");
    SemiAutoRebalancerContext rebalancerContext =
        new SemiAutoRebalancerContext.Builder(resourceId).build();
    ResourceConfig config =
        new ResourceConfig.Builder(resourceId).userConfig(userConfig)
            .rebalancerContext(rebalancerContext).bucketSize(OLD_BUCKET_SIZE)
            .batchMessageMode(true).build();

    // update: overwrite user config, change to full auto rebalancer context, and change the bucket
    // size
    UserConfig newUserConfig = new UserConfig(Scope.resource(resourceId));
    newUserConfig.setSimpleField("key2", "value2");
    FullAutoRebalancerContext newRebalancerContext =
        new FullAutoRebalancerContext.Builder(resourceId).build();
    ResourceConfig updated =
        new ResourceConfig.Delta(resourceId).setBucketSize(NEW_BUCKET_SIZE)
            .setUserConfig(newUserConfig).setRebalancerContext(newRebalancerContext)
            .mergeInto(config);
    Assert.assertEquals(updated.getBucketSize(), NEW_BUCKET_SIZE);
    Assert.assertTrue(updated.getBatchMessageMode());
    Assert.assertNull(updated.getRebalancerConfig().getRebalancerContext(
        SemiAutoRebalancerContext.class));
    Assert.assertNotNull(updated.getRebalancerConfig().getRebalancerContext(
        FullAutoRebalancerContext.class));
    Assert.assertNull(updated.getUserConfig().getSimpleField("key1"));
    Assert.assertEquals(updated.getUserConfig().getSimpleField("key2"), "value2");
  }
View Full Code Here

      boolean batchMessageMode) {
    SchedulerTaskConfig schedulerTaskConfig = schedulerTaskConfig(idealState);
    RebalancerConfig rebalancerConfig = new RebalancerConfig(rebalancerContext);

    _config =
        new ResourceConfig(id, type, schedulerTaskConfig, rebalancerConfig, userConfig, bucketSize,
            batchMessageMode);
    _externalView = externalView;
    _resourceAssignment = resourceAssignment;
  }
View Full Code Here

    }

    MessageOutput output = new MessageOutput();

    for (ResourceId resourceId : resourceMap.keySet()) {
      ResourceConfig resourceConfig = resourceMap.get(resourceId);
      int bucketSize = resourceConfig.getBucketSize();

      RebalancerContext rebalancerCtx =
          resourceConfig.getRebalancerConfig().getRebalancerContext(RebalancerContext.class);
      StateModelDefinition stateModelDef = stateModelDefMap.get(rebalancerCtx.getStateModelDefId());

      ResourceAssignment resourceAssignment =
          bestPossibleStateOutput.getResourceAssignment(resourceId);
      for (PartitionId subUnitId : resourceAssignment.getMappedPartitionIds()) {
        Map<ParticipantId, State> instanceStateMap = resourceAssignment.getReplicaMap(subUnitId);

        // 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<State, List<Message>> messageMap = new HashMap<State, List<Message>>();

        for (ParticipantId participantId : instanceStateMap.keySet()) {
          State desiredState = instanceStateMap.get(participantId);

          State currentState =
              currentStateOutput.getCurrentState(resourceId, subUnitId, participantId);
          if (currentState == null) {
            currentState = stateModelDef.getTypedInitialState();
          }

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

          State pendingState =
              currentStateOutput.getPendingState(resourceId, subUnitId, participantId);

          // TODO fix it
          State nextState = stateModelDef.getNextStateForTransition(currentState, desiredState);
          if (nextState == null) {
            LOG.error("Unable to find a next state for partition: " + subUnitId
                + " from stateModelDefinition" + stateModelDef.getClass() + " from:" + currentState
                + " to:" + desiredState);
            continue;
          }

          if (pendingState != null) {
            if (nextState.equals(pendingState)) {
              LOG.debug("Message already exists for " + participantId + " to transit " + subUnitId
                  + " from " + currentState + " to " + nextState);
            } else if (currentState.equals(pendingState)) {
              LOG.info("Message hasn't been removed for " + participantId + " to transit"
                  + subUnitId + " to " + pendingState + ", desiredState: " + desiredState);
            } else {
              LOG.info("IdealState changed before state transition completes for " + subUnitId
                  + " on " + participantId + ", pendingState: " + pendingState + ", currentState: "
                  + currentState + ", nextState: " + nextState);
            }
          } else {
            // TODO check if instance is alive
            SessionId sessionId =
                cluster.getLiveParticipantMap().get(participantId).getRunningInstance()
                    .getSessionId();
            RebalancerContext rebalancerContext =
                resourceConfig.getRebalancerConfig().getRebalancerContext(RebalancerContext.class);
            Message message =
                createMessage(manager, resourceId, subUnitId, participantId, currentState,
                    nextState, sessionId, StateModelDefId.from(stateModelDef.getId()),
                    rebalancerContext.getStateModelFactoryId(), bucketSize);

            // TODO refactor get/set timeout/inner-message
            if (rebalancerContext != null
                && rebalancerContext.getStateModelDefId().equalsIgnoreCase(
                    StateModelDefId.SchedulerTaskQueue)) {
              if (resourceConfig.getSubUnitMap().size() > 0) {
                // TODO refactor it -- we need a way to read in scheduler tasks a priori
                Message innerMsg =
                    resourceConfig.getSchedulerTaskConfig().getInnerMessage(subUnitId);
                if (innerMsg != null) {
                  message.setInnerMessage(innerMsg);
                }
              }
            }

            // Set timeout if needed
            String stateTransition =
                String.format("%s-%s_%s", currentState, nextState,
                    Message.Attributes.TIMEOUT.name());
            SchedulerTaskConfig schedulerTaskConfig = resourceConfig.getSchedulerTaskConfig();
            if (schedulerTaskConfig != null) {
              int timeout = schedulerTaskConfig.getTimeout(stateTransition, subUnitId);
              if (timeout > 0) {
                message.setExecutionTimeout(timeout);
              }
View Full Code Here

    for (ResourceId resourceId : resourceMap.keySet()) {
      ExternalView view = new ExternalView(resourceId.stringify());
      // view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
      // if resource ideal state has bucket size, set it
      // otherwise resource has been dropped, use bucket size from current state instead
      ResourceConfig resource = resourceMap.get(resourceId);
      RebalancerConfig rebalancerConfig = resource.getRebalancerConfig();
      SchedulerTaskConfig schedulerTaskConfig = resource.getSchedulerTaskConfig();

      if (resource.getBucketSize() > 0) {
        view.setBucketSize(resource.getBucketSize());
      } else {
        view.setBucketSize(currentStateOutput.getBucketSize(resourceId));
      }
      for (PartitionId partitionId : resource.getSubUnitMap().keySet()) {
        Map<ParticipantId, State> currentStateMap =
            currentStateOutput.getCurrentStateMap(resourceId, partitionId);
        if (currentStateMap != null && currentStateMap.size() > 0) {
          // Set<String> disabledInstances
          // = cache.getDisabledInstancesForResource(resource.toString());
View Full Code Here

    Resource resource = readResource(resourceId);
    if (resource == null) {
      LOG.error("Resource " + resourceId + " does not exist, cannot be updated");
      return null;
    }
    ResourceConfig config = resourceDelta.mergeInto(resource.getConfig());
    setResource(config);
    return config;
  }
View Full Code Here

    }

    MessageOutput output = new MessageOutput();

    for (ResourceId resourceId : resourceMap.keySet()) {
      ResourceConfig resource = resourceMap.get(resourceId);
      StateModelDefinition stateModelDef =
          stateModelDefMap.get(resource.getRebalancerConfig()
              .getRebalancerContext(RebalancerContext.class).getStateModelDefId());

      // TODO have a logical model for transition
      Map<String, Integer> stateTransitionPriorities = getStateTransitionPriorityMap(stateModelDef);
      Resource configResource = cluster.getResource(resourceId);
View Full Code Here

TOP

Related Classes of org.apache.helix.api.config.ResourceConfig

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.