Package org.apache.helix.api.config

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


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


  private static void updateResource(ResourceConfig resource, ClusterId clusterId,
      HelixConnection connection) {
    // add some fields to the resource user config, then update it using the resource config delta
    ResourceAccessor accessor = connection.createResourceAccessor(clusterId);
    UserConfig userConfig = resource.getUserConfig();
    Map<String, String> mapField = Maps.newHashMap();
    mapField.put("k1", "v1");
    mapField.put("k2", "v2");
    userConfig.setMapField("sampleMap", mapField);
    ResourceConfig.Delta delta =
        new ResourceConfig.Delta(resource.getId()).setUserConfig(userConfig);
    accessor.updateResource(resource.getId(), delta);
  }
View Full Code Here

  private static ParticipantConfig getParticipant() {
    // identify the participant
    ParticipantId participantId = ParticipantId.from("localhost_0");

    // create (optional) participant user config properties
    UserConfig userConfig = new UserConfig(Scope.participant(participantId));
    List<String> sampleList = Lists.newArrayList("elem1", "elem2");
    userConfig.setListField("sampleList", sampleList);

    // create the configuration of a new participant
    ParticipantConfig.Builder participantBuilder =
        new ParticipantConfig.Builder(participantId).hostName("localhost").port(0)
            .userConfig(userConfig);
View Full Code Here

    FullAutoRebalancerContext.Builder rebalanceContextBuilder =
        new FullAutoRebalancerContext.Builder(resourceId).replicaCount(1).addPartition(partition1)
            .addPartition(partition2).stateModelDefId(stateModelDef.getStateModelDefId());

    // create (optional) user-defined configuration properties for the resource
    UserConfig userConfig = new UserConfig(Scope.resource(resourceId));
    userConfig.setBooleanField("sampleBoolean", true);

    // create the configuration for a new resource
    ResourceConfig.Builder resourceBuilder =
        new ResourceConfig.Builder(resourceId).rebalancerContext(rebalanceContextBuilder.build())
            .userConfig(userConfig);
View Full Code Here

        new RunningInstance(SessionId.from("session_1"), HelixVersion.from("1.2.3.4"),
            ProcId.from("1"));
    liveInstances.put(ParticipantId.from("localhost_0"),
        new Participant(ParticipantId.from("localhost_0"), "localhost", 0, true,
            disabledPartitions, tags, runningInstance0, currentStateMap, messageMap,
            new UserConfig(Scope.participant(ParticipantId.from("localhost_0")))));
    liveInstances.put(ParticipantId.from("localhost_1"),
        new Participant(ParticipantId.from("localhost_1"), "localhost", 1, true,
            disabledPartitions, tags, runningInstance1, currentStateMap, messageMap,
            new UserConfig(Scope.participant(ParticipantId.from("localhost_1")))));

    Map<ParticipantId, State> currentStates = new HashMap<ParticipantId, State>();
    currentStates.put(ParticipantId.from("localhost_0"), State.from("SLAVE"));
    currentStates.put(ParticipantId.from("localhost_1"), State.from("MASTER"));
View Full Code Here

        new RunningInstance(SessionId.from("session_1"), HelixVersion.from("1.2.3.4"),
            ProcId.from("1"));
    liveInstances.put(ParticipantId.from("localhost_0"),
        new Participant(ParticipantId.from("localhost_0"), "localhost", 0, true,
            disabledPartitions, tags, runningInstance0, currentStateMap, messageMap,
            new UserConfig(Scope.participant(ParticipantId.from("localhost_0")))));
    liveInstances.put(ParticipantId.from("localhost_1"),
        new Participant(ParticipantId.from("localhost_1"), "localhost", 1, true,
            disabledPartitions, tags, runningInstance1, currentStateMap, messageMap,
            new UserConfig(Scope.participant(ParticipantId.from("localhost_1")))));

    Map<ParticipantId, State> currentStates = new HashMap<ParticipantId, State>();
    currentStates.put(ParticipantId.from("localhost_0"), State.from("SLAVE"));
    currentStates.put(ParticipantId.from("localhost_1"), State.from("SLAVE"));
View Full Code Here

    for (IdealState idealState : idealStates) {
      ResourceId resourceId = idealState.getResourceId();
      RebalancerContext context = PartitionedRebalancerContext.from(idealState);
      Resource resource =
          new Resource(resourceId, ResourceType.DATA, idealState, null, null, context,
              new UserConfig(Scope.resource(resourceId)), idealState.getBucketSize(),
              idealState.getBatchMessageMode());
      resourceMap.put(resourceId, resource.getConfig());
    }

    return resourceMap;
View Full Code Here

  /**
   * Get a backward-compatible participant user config
   * @return UserConfig
   */
  public UserConfig getUserConfig() {
    UserConfig userConfig = UserConfig.from(this);
    for (String simpleField : _record.getSimpleFields().keySet()) {
      Optional<InstanceConfigProperty> enumField =
          Enums.getIfPresent(InstanceConfigProperty.class, simpleField);
      if (!simpleField.contains(NamespacedConfig.PREFIX_CHAR + "") && !enumField.isPresent()) {
        userConfig.setSimpleField(simpleField, _record.getSimpleField(simpleField));
      }
    }
    for (String listField : _record.getListFields().keySet()) {
      Optional<InstanceConfigProperty> enumField =
          Enums.getIfPresent(InstanceConfigProperty.class, listField);
      if (!listField.contains(NamespacedConfig.PREFIX_CHAR + "") && !enumField.isPresent()) {
        userConfig.setListField(listField, _record.getListField(listField));
      }
    }
    for (String mapField : _record.getMapFields().keySet()) {
      Optional<InstanceConfigProperty> enumField =
          Enums.getIfPresent(InstanceConfigProperty.class, mapField);
      if (!mapField.contains(NamespacedConfig.PREFIX_CHAR + "") && !enumField.isPresent()) {
        userConfig.setMapField(mapField, _record.getMapField(mapField));
      }
    }
    return userConfig;
  }
View Full Code Here

  /**
   * Get a backward-compatible resource user config
   * @return UserConfig
   */
  public UserConfig getUserConfig() {
    UserConfig userConfig = UserConfig.from(this);
    for (String simpleField : _record.getSimpleFields().keySet()) {
      Optional<Fields> enumField = Enums.getIfPresent(Fields.class, simpleField);
      if (!simpleField.contains(NamespacedConfig.PREFIX_CHAR + "") && !enumField.isPresent()) {
        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 String VALUE2 = "value2";

    // add the following: key1 straight to user config, key2 to cluster configuration,
    // allow auto join to cluster configuration
    ClusterId clusterId = ClusterId.from("clusterId");
    UserConfig userConfig = new UserConfig(Scope.cluster(clusterId));
    userConfig.setSimpleField(KEY1, VALUE1);
    ClusterConfiguration clusterConfiguration = new ClusterConfiguration(clusterId);
    clusterConfiguration.addNamespacedConfig(userConfig);
    clusterConfiguration.getRecord().setSimpleField(KEY2, VALUE2);
    clusterConfiguration.setAutoJoinAllowed(true);

    // there should be key1 and key2, but not auto join
    UserConfig result = clusterConfiguration.getUserConfig();
    Assert.assertEquals(result.getSimpleField(KEY1), VALUE1);
    Assert.assertEquals(result.getSimpleField(KEY2), VALUE2);
    Assert.assertNull(result.getSimpleField(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN));
  }
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.