Package org.apache.helix.api.config

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


    if (instanceConfig == null) {
      LOG.error("Participant " + participantId + " is not present on the cluster");
      return null;
    }

    UserConfig userConfig = instanceConfig.getUserConfig();
    LiveInstance liveInstance = _accessor.getProperty(_keyBuilder.liveInstance(participantName));

    Map<String, Message> instanceMsgMap = Collections.emptyMap();
    Map<String, CurrentState> instanceCurStateMap = Collections.emptyMap();
    if (liveInstance != null) {
View Full Code Here


   * @return Resource
   */
  private static Resource createResource(ResourceId resourceId,
      ResourceConfiguration resourceConfiguration, IdealState idealState,
      ExternalView externalView, ResourceAssignment resourceAssignment) {
    UserConfig userConfig;
    ProvisionerConfig provisionerConfig = null;
    RebalancerConfig rebalancerConfig = null;
    if (resourceConfiguration != null) {
      userConfig = resourceConfiguration.getUserConfig();
      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)
View Full Code Here

  protected void init() {
    ClusterId clusterId = getClusterId();
    ClusterAccessor clusterAccessor = getConnection().createClusterAccessor(clusterId);
    ResourceId resourceId = ResourceId.from(_serviceName);
    Resource resource = clusterAccessor.readResource(resourceId);
    UserConfig userConfig = resource.getUserConfig();
    ServiceConfig serviceConfig = new ServiceConfig(Scope.resource(resourceId));
    serviceConfig.setSimpleFields(userConfig.getSimpleFields());
    serviceConfig.setListFields(userConfig.getListFields());
    serviceConfig.setMapFields(userConfig.getMapFields());
    LOG.info("Starting service:" + _serviceName + " with configuration:" + serviceConfig);
    StatelessServiceStateModelFactory stateModelFactory =
        new StatelessServiceStateModelFactory(this);
    getParticipant().getStateMachineEngine().registerStateModelFactory(
        StateModelDefId.from("StatelessService"), stateModelFactory);
View Full Code Here

  /**
   * Get a backward-compatible cluster user config
   * @return UserConfig
   */
  public UserConfig getUserConfig() {
    UserConfig userConfig = UserConfig.from(this);
    try {
      for (String simpleField : _record.getSimpleFields().keySet()) {
        Optional<HelixPropertyAttribute> superEnumField =
            Enums.getIfPresent(HelixPropertyAttribute.class, simpleField);
        if (!simpleField.contains(NamespacedConfig.PREFIX_CHAR + "")
            && !simpleField.equals(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN)
            && !superEnumField.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));
        }
      }
    } catch (NoSuchMethodError e) {
      LOG.error("Could not parse ClusterConfiguration", e);
    }
View Full Code Here

    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
    ClusterAccessor accessor = connection.createClusterAccessor(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()).addUserConfig(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);
    return participantBuilder.build();
View Full Code Here

    AutoRebalanceModeISBuilder idealStateBuilder =
        new AutoRebalanceModeISBuilder(resourceId).add(partition1).add(partition2);
    idealStateBuilder.setNumReplica(1).setStateModelDefId(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).idealState(idealStateBuilder.build()).userConfig(userConfig);
    return resourceBuilder.build();
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.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 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(IdealState.IdealStateProperty.REBALANCE_MODE.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.