Package org.apache.helix.api.config

Examples of org.apache.helix.api.config.ParticipantConfig$Builder


    // 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
View Full Code Here


  private boolean createParticipant(ParticipantId participantId, ClusterAccessor accessor,
      String modifierName, int modifierValue) {
    // create a participant
    UserConfig userConfig = new UserConfig(Scope.participant(participantId));
    userConfig.setIntField(modifierName, modifierValue);
    ParticipantConfig participant =
        new ParticipantConfig.Builder(participantId).hostName("host").port(0)
            .userConfig(userConfig).build();
    return accessor.addParticipant(participant);
  }
View Full Code Here

        Map<ParticipantId, Participant> liveParticipantMap =
            new HashMap<ParticipantId, Participant>();
        // set up some participants
        for (String nodeName : _liveNodes) {
          ParticipantId participantId = ParticipantId.from(nodeName);
          ParticipantConfig participantConfig =
              new ParticipantConfig.Builder(participantId).hostName("hostname").port(0).build();
          Participant participant =
              new Participant(participantConfig, null, currentStateMap, messageMap, null);
          liveParticipantMap.put(participantId, participant);
        }
View Full Code Here

    if (containerSpec != null || containerState != null || containerId != null) {
      containerConfig = new ContainerConfig(containerId, containerSpec, containerState);
    }

    // Populate the logical class
    ParticipantConfig participantConfig = ParticipantConfig.from(instanceConfig);
    return new Participant(participantConfig, liveInstance, curStateMap, msgMap, containerConfig);
  }
View Full Code Here

    // 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
View Full Code Here

  private boolean createParticipant(ParticipantId participantId, ClusterAccessor accessor,
      String modifierName, int modifierValue) {
    // create a participant
    UserConfig userConfig = new UserConfig(Scope.participant(participantId));
    userConfig.setIntField(modifierName, modifierValue);
    ParticipantConfig participant =
        new ParticipantConfig.Builder(participantId).hostName("host").port(0)
            .userConfig(userConfig).build();
    return accessor.addParticipantToCluster(participant);
  }
View Full Code Here

    // start: add a user config, set host & port, add 2 tags and 2 disabled partition, start
    // disabled
    UserConfig userConfig = new UserConfig(Scope.participant(participantId));
    userConfig.setSimpleField("key1", "value1");
    ParticipantConfig config =
        new ParticipantConfig.Builder(participantId).hostName(ORIG_HOSTNAME).port(PORT)
            .enabled(false).addTag(TAG1).addTag(TAG2).addDisabledPartition(partition1)
            .addDisabledPartition(partition2).userConfig(userConfig).build();
    UserConfig newUserConfig = new UserConfig(Scope.participant(participantId));
    newUserConfig.setSimpleField("key2", "value2");

    // update: change host, remove a tag, add a tag, remove a disabled partition, add a disabled
    // partition, change user config
    ParticipantConfig updated =
        new ParticipantConfig.Delta(participantId).setHostName(NEW_HOSTNAME).removeTag(TAG1)
            .addTag(TAG3).removeDisabledPartition(partition1).addDisabledPartition(partition3)
            .setUserConfig(newUserConfig).mergeInto(config);
    Assert.assertEquals(updated.getHostName(), NEW_HOSTNAME);
    Assert.assertEquals(updated.getPort(), PORT);
    Assert.assertFalse(updated.hasTag(TAG1));
    Assert.assertTrue(updated.hasTag(TAG2));
    Assert.assertTrue(updated.hasTag(TAG3));
    Assert.assertFalse(updated.getDisabledPartitions().contains(partition1));
    Assert.assertTrue(updated.getDisabledPartitions().contains(partition2));
    Assert.assertTrue(updated.getDisabledPartitions().contains(partition3));
    Assert.assertNull(updated.getUserConfig().getSimpleField("key1"));
    Assert.assertEquals(updated.getUserConfig().getSimpleField("key2"), "value2");
    Assert.assertFalse(updated.isEnabled());
  }
View Full Code Here

  public Participant(ParticipantId id, String hostName, int port, boolean isEnabled,
      Set<PartitionId> disabledPartitionIdSet, Set<String> tags, RunningInstance runningInstance,
      Map<ResourceId, CurrentState> currentStateMap, Map<MessageId, Message> messageMap,
      UserConfig userConfig) {
    _config =
        new ParticipantConfig(id, hostName, port, isEnabled, disabledPartitionIdSet, tags,
            userConfig);
    _runningInstance = runningInstance;
    _currentStateMap = ImmutableMap.copyOf(currentStateMap);
    _messageMap = ImmutableMap.copyOf(messageMap);
  }
View Full Code Here

    Participant participant = readParticipant(participantId);
    if (participant == null) {
      LOG.error("Participant " + participantId + " does not exist, cannot be updated");
      return null;
    }
    ParticipantConfig config = participantDelta.mergeInto(participant.getConfig());
    setParticipant(config);
    return config;
  }
View Full Code Here

TOP

Related Classes of org.apache.helix.api.config.ParticipantConfig$Builder

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.