Package org.apache.helix.api.config

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


  }

  private boolean createCluster(ClusterId clusterId, ClusterAccessor accessor, String modifierName,
      int modifierValue) {
    // create a cluster
    UserConfig userConfig = new UserConfig(Scope.cluster(clusterId));
    userConfig.setIntField(modifierName, modifierValue);
    ClusterConfig cluster = new ClusterConfig.Builder(clusterId).userConfig(userConfig).build();
    return accessor.createCluster(cluster);
  }
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

    // thread that will update the cluster in one way
    Thread t1 = new Thread() {
      @Override
      public void run() {
        UserConfig userConfig = new UserConfig(Scope.cluster(clusterId));
        userConfig.setBooleanField(key1, true);
        ClusterConfig.Delta delta =
            new ClusterConfig.Delta(clusterId).addStateUpperBoundConstraint(
                Scope.cluster(clusterId), stateModelDefId, state, constraint1).setUserConfig(
                userConfig);
        ClusterAccessor accessor =
            new AtomicClusterAccessor(clusterId, helixAccessor, lockProvider);
        accessor.updateCluster(delta);
      }
    };

    // thread that will update the cluster in another way
    Thread t2 = new Thread() {
      @Override
      public void run() {
        UserConfig userConfig = new UserConfig(Scope.cluster(clusterId));
        userConfig.setBooleanField(key2, true);
        ClusterConfig.Delta delta =
            new ClusterConfig.Delta(clusterId).addStateUpperBoundConstraint(
                Scope.cluster(clusterId), stateModelDefId, state, constraint2).setUserConfig(
                userConfig);
        ClusterAccessor accessor =
View Full Code Here

  /**
   * Get a backward-compatible cluster user config
   * @return UserConfig
   */
  public UserConfig getUserConfig() {
    UserConfig userConfig = UserConfig.from(this);
    for (String simpleField : _record.getSimpleFields().keySet()) {
      if (!simpleField.contains(NamespacedConfig.PREFIX_CHAR + "")
          && !simpleField.equals(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN)) {
        userConfig.setSimpleField(simpleField, _record.getSimpleField(simpleField));
      }
    }
    for (String listField : _record.getListFields().keySet()) {
      if (!listField.contains(NamespacedConfig.PREFIX_CHAR + "")) {
        userConfig.setListField(listField, _record.getListField(listField));
      }
    }
    for (String mapField : _record.getMapFields().keySet()) {
      if (!mapField.contains(NamespacedConfig.PREFIX_CHAR + "")) {
        userConfig.setMapField(mapField, _record.getMapField(mapField));
      }
    }
    return userConfig;
  }
View Full Code Here

    final PartitionId partition3 = PartitionId.from("resource_3");
    final ParticipantId participantId = ParticipantId.from("participant");

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

    final int NEW_BUCKET_SIZE = 1;
    final ResourceId resourceId = ResourceId.from("resource");

    // start: add a user config, a semi auto rebalancer context, and set bucket size and batch
    // 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)
View Full Code Here

    final State master = State.from("MASTER");
    final State slave = State.from("SLAVE");
    final State offline = State.from("OFFLINE");

    // start: add a user config, add master and slave constraints
    UserConfig userConfig = new UserConfig(Scope.cluster(clusterId));
    userConfig.setSimpleField("key1", "value1");
    ClusterConfig config =
        new ClusterConfig.Builder(clusterId)
            .addStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, master, 2)
            .addStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, slave, 3)
            .userConfig(userConfig).autoJoin(true).build();

    // update: overwrite user config, change master constraint, remove slave constraint, add offline
    // constraint, change auto join
    UserConfig newUserConfig = new UserConfig(Scope.cluster(clusterId));
    newUserConfig.setSimpleField("key2", "value2");
    ClusterConfig updated =
        new ClusterConfig.Delta(clusterId)
            .addStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, master, 1)
            .removeStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, slave)
            .addStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, offline, "R")
View Full Code Here

    ParticipantId participantId = ParticipantId.from("testParticipant");
    InstanceConfig instanceConfig = new InstanceConfig(participantId);
    instanceConfig.setHostName("localhost");

    // now, add user configuration
    UserConfig userConfig = new UserConfig(Scope.participant(participantId));
    userConfig.setSimpleField(testKey, testSimpleValue);
    userConfig.setListField(testKey, testListValue);
    userConfig.setMapField(testKey, testMapValue);

    // add the user configuration to the Helix configuration
    instanceConfig.addNamespacedConfig(userConfig);

    // get the user configuration back from the property
    UserConfig retrievedConfig = UserConfig.from(instanceConfig);

    // check that the property still has the host name
    Assert.assertTrue(instanceConfig.getHostName().equals("localhost"));

    // check that the retrieved config does not contain the host name
    Assert.assertEquals(retrievedConfig.getStringField(
        InstanceConfigProperty.HELIX_HOST.toString(), "not localhost"), "not localhost");

    // check that both the retrieved config and the original config have the added properties
    Assert.assertEquals(userConfig.getSimpleField(testKey), testSimpleValue);
    Assert.assertEquals(userConfig.getListField(testKey), testListValue);
    Assert.assertEquals(userConfig.getMapField(testKey), testMapValue);
    Assert.assertEquals(retrievedConfig.getSimpleField(testKey), testSimpleValue);
    Assert.assertEquals(retrievedConfig.getListField(testKey), testListValue);
    Assert.assertEquals(retrievedConfig.getMapField(testKey), testMapValue);

    // test that the property has the user config, but prefixed
    Assert.assertEquals(instanceConfig.getRecord().getSimpleField(prefixedKey), testSimpleValue);
    Assert.assertEquals(instanceConfig.getRecord().getListField(prefixedKey), testListValue);
    Assert.assertEquals(instanceConfig.getRecord().getMapField(prefixedKey), testMapValue);
View Full Code Here

    final String VALUE3 = "value3";

    // add key1 through user config, key2 through resource config, key3 through ideal state,
    // resource type through resource config, rebalance mode through ideal state
    ResourceId resourceId = ResourceId.from("resourceId");
    UserConfig userConfig = new UserConfig(Scope.resource(resourceId));
    userConfig.setSimpleField(KEY1, VALUE1);
    ResourceConfiguration resourceConfig = new ResourceConfiguration(resourceId);
    resourceConfig.setType(ResourceType.DATA);
    resourceConfig.addNamespacedConfig(userConfig);
    resourceConfig.getRecord().setSimpleField(KEY2, VALUE2);
    IdealState idealState = new IdealState(resourceId);
    idealState.setRebalanceMode(RebalanceMode.USER_DEFINED);
    idealState.getRecord().setSimpleField(KEY3, VALUE3);

    // should have key1, key2, and key3, not type or rebalance mode
    UserConfig result = resourceConfig.getUserConfig();
    idealState.updateUserConfig(result);
    Assert.assertEquals(result.getSimpleField(KEY1), VALUE1);
    Assert.assertEquals(result.getSimpleField(KEY2), VALUE2);
    Assert.assertEquals(result.getSimpleField(KEY3), VALUE3);
    Assert.assertNull(result.getSimpleField(ResourceConfiguration.Fields.TYPE.toString()));
    Assert
        .assertNull(result.getSimpleField(IdealState.IdealStateProperty.REBALANCE_MODE.toString()));
  }
View Full Code Here

    final String KEY2 = "key2";
    final String VALUE2 = "value2";

    // add key1 through user config, key2 through instance config, hostname through user config
    ParticipantId participantId = ParticipantId.from("participantId");
    UserConfig userConfig = new UserConfig(Scope.participant(participantId));
    userConfig.setSimpleField(KEY1, VALUE1);
    InstanceConfig instanceConfig = new InstanceConfig(participantId);
    instanceConfig.setHostName("localhost");
    instanceConfig.addNamespacedConfig(userConfig);
    instanceConfig.getRecord().setSimpleField(KEY2, VALUE2);

    // should have key1 and key2, not hostname
    UserConfig result = instanceConfig.getUserConfig();
    Assert.assertEquals(result.getSimpleField(KEY1), VALUE1);
    Assert.assertEquals(result.getSimpleField(KEY2), VALUE2);
    Assert.assertNull(result.getSimpleField(InstanceConfig.InstanceConfigProperty.HELIX_HOST
        .toString()));
  }
View Full Code Here

TOP

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

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.