Package org.apache.helix.api.config

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


    // 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 transition constraint (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.start();

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

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

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

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


  protected Map<ResourceId, ResourceConfig> getResourceMap(List<IdealState> idealStates) {
    Map<ResourceId, ResourceConfig> resourceMap = new HashMap<ResourceId, ResourceConfig>();
    for (IdealState idealState : idealStates) {
      ResourceId resourceId = idealState.getResourceId();
      ResourceConfig resourceConfig =
          new ResourceConfig.Builder(resourceId).idealState(idealState)
              .userConfig(new UserConfig(Scope.resource(resourceId))).build();
      resourceMap.put(resourceId, resourceConfig);
    }
View Full Code Here

    Map<ResourceId, ResourceConfig> resourceMap = Maps.newHashMap();
    ResourceId resourceId = ResourceId.from(testDB);
    AutoModeISBuilder idealStateBuilder = new AutoModeISBuilder(resourceId).add(testDB_0);
    idealStateBuilder.setStateModel("MasterSlave");
    IdealState idealState = idealStateBuilder.build();
    ResourceConfig resourceConfig =
        new ResourceConfig.Builder(resourceId).idealState(idealState).build();
    resourceMap.put(resourceId, resourceConfig);

    Map<String, StateModelDefinition> stateModelDefMap = Maps.newHashMap();
    StateModelDefinition msStateModelDef =
View Full Code Here

    final Map<ResourceId, ResourceConfig> resourceMap =
        event.getAttribute(AttributeName.RESOURCES.toString());
    final HelixDataAccessor accessor = helixManager.getHelixDataAccessor();
    final PropertyKey.Builder keyBuilder = accessor.keyBuilder();
    for (ResourceId resourceId : resourceMap.keySet()) {
      ResourceConfig resourceConfig = resourceMap.get(resourceId);
      ProvisionerConfig provisionerConfig = resourceConfig.getProvisionerConfig();
      if (provisionerConfig != null) {
        Provisioner provisioner;
        provisioner = _provisionerMap.get(resourceId);

        // instantiate and cache a provisioner if there isn't one already cached
View Full Code Here

    for (ResourceId resourceId : resourceMap.keySet()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Processing resource:" + resourceId);
      }
      ResourceConfig resourceConfig = resourceMap.get(resourceId);
      RebalancerConfig rebalancerConfig = resourceConfig.getRebalancerConfig();
      IdealState idealState = resourceConfig.getIdealState();
      StateModelDefinition stateModelDef = stateModelDefs.get(idealState.getStateModelDefId());
      ResourceAssignment resourceAssignment = null;
      // use a cached rebalancer if possible
      RebalancerRef ref = idealState.getRebalancerRef();
      HelixRebalancer rebalancer = null;
View Full Code Here

    ResourceConfig.Delta delta = new ResourceConfig.Delta(resourceId);
    YarnProvisionerConfig config = new YarnProvisionerConfig(resourceId);
    config.setNumContainers(numContainers);
    delta.setProvisionerConfig(config);
    delta.setIdealState(resource.getIdealState());
    ResourceConfig updatedResourceConfig = clusterAccessor.updateResource(resourceId, delta);
    LOG.info("Update provisioner config:" + updatedResourceConfig.getProvisionerConfig());

  }
View Full Code Here

    Iterator<Message> iter = messages.iterator();
    while (iter.hasNext()) {
      Message message = iter.next();
      ResourceId resourceId = message.getResourceId();
      ResourceConfig resource = resourceMap.get(resourceId);

      ParticipantId participantId = ParticipantId.from(message.getTgtName());
      Participant liveParticipant = liveParticipantMap.get(participantId);
      String participantVersion = null;
      if (liveParticipant != null) {
        participantVersion = liveParticipant.getLiveInstance().getHelixVersion();
      }

      if (resource == null || resource.getIdealState() == null
          || !resource.getIdealState().getBatchMessageMode() || participantVersion == null
          || !properties.isFeatureSupported("batch_message", participantVersion)) {
        outputMessages.add(message);
        continue;
      }
View Full Code Here

      rebalancerConfig = resourceConfiguration.getRebalancerConfig(RebalancerConfig.class);
      provisionerConfig = resourceConfiguration.getProvisionerConfig(ProvisionerConfig.class);
    } else {
      userConfig = new UserConfig(Scope.resource(resourceId));
    }
    ResourceConfig resourceConfig =
        new ResourceConfig.Builder(resourceId).idealState(idealState)
            .rebalancerConfig(rebalancerConfig).provisionerConfig(provisionerConfig)
            .schedulerTaskConfig(Resource.schedulerTaskConfig(idealState)).userConfig(userConfig)
            .build();
    return new Resource(resourceConfig, resourceAssignment, externalView);
View Full Code Here

        if (!liveParticipant.getLiveInstance().getSessionId().equals(message.getTgtSessionId())) {
          continue;
        }

        ResourceId resourceId = message.getResourceId();
        ResourceConfig resource = resourceMap.get(resourceId);
        if (resource == null) {
          continue;
        }
        IdealState idealState = resource.getIdealState();

        if (!message.getBatchMessageMode()) {
          PartitionId partitionId = message.getPartitionId();
          if (idealState.getPartitionIdSet().contains(partitionId)) {
            currentStateOutput.setPendingState(resourceId, partitionId, participantId,
                message.getTypedToState());
          } else {
            // log
          }
        } else {
          List<PartitionId> partitionNames = message.getPartitionIds();
          if (!partitionNames.isEmpty()) {
            for (PartitionId partitionId : partitionNames) {
              if (idealState.getPartitionIdSet().contains(partitionId)) {
                currentStateOutput.setPendingState(resourceId, partitionId, participantId,
                    message.getTypedToState());
              } else {
                // log
              }
            }
          }
        }
      }

      // add current state
      SessionId sessionId = SessionId.from(liveParticipant.getLiveInstance().getSessionId());
      Map<ResourceId, CurrentState> curStateMap = liveParticipant.getCurrentStateMap();
      for (CurrentState curState : curStateMap.values()) {
        if (!sessionId.equals(curState.getTypedSessionId())) {
          continue;
        }

        ResourceId resourceId = curState.getResourceId();
        StateModelDefId stateModelDefId = curState.getStateModelDefId();
        ResourceConfig resource = resourceMap.get(resourceId);
        if (resource == null) {
          continue;
        }

        if (stateModelDefId != null) {
View Full Code Here

    }

    MessageOutput output = new MessageOutput();

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

      IdealState idealState = resourceConfig.getIdealState();
      StateModelDefinition stateModelDef = stateModelDefMap.get(idealState.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 =
                SessionId.from(cluster.getLiveParticipantMap().get(participantId).getLiveInstance()
                    .getSessionId());
            Message message =
                createMessage(manager, resourceId, subUnitId, participantId, currentState,
                    nextState, sessionId, StateModelDefId.from(stateModelDef.getId()),
                    idealState.getStateModelFactoryId(), bucketSize);

            // TODO refactor get/set timeout/inner-message
            if (idealState != null
                && idealState.getStateModelDefId().equalsIgnoreCase(
                    StateModelDefId.SchedulerTaskQueue)) {
              if (resourceConfig.getSubUnitSet().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

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.