Package org.apache.helix.model

Examples of org.apache.helix.model.ResourceConfiguration


    // Persist the ideal state
    _accessor.setProperty(_keyBuilder.idealStates(resourceId.stringify()), idealState);

    // Add resource user config
    boolean persistConfig = false;
    ResourceConfiguration configuration = new ResourceConfiguration(resourceId);
    if (resource.getUserConfig() != null) {
      configuration.addNamespacedConfig(resource.getUserConfig());
      persistConfig = true;
    }
    RebalancerConfig rebalancerConfig = resource.getRebalancerConfig();
    if (rebalancerConfig != null) {
      // only persist if this is not easily convertible to an ideal state
      configuration.addNamespacedConfig(new RebalancerConfigHolder(rebalancerConfig)
          .toNamespacedConfig());
      persistConfig = true;
    }
    ProvisionerConfig provisionerConfig = resource.getProvisionerConfig();
    if (provisionerConfig != null) {
      configuration.addNamespacedConfig(new ProvisionerConfigHolder(provisionerConfig)
          .toNamespacedConfig());
      persistConfig = true;
    }
    if (persistConfig) {
      _accessor.setProperty(_keyBuilder.resourceConfig(resourceId.stringify()), configuration);
View Full Code Here


   * Read a single snapshot of a resource
   * @param resourceId the resource id to read
   * @return Resource or null if not present
   */
  public Resource readResource(ResourceId resourceId) {
    ResourceConfiguration config =
        _accessor.getProperty(_keyBuilder.resourceConfig(resourceId.stringify()));
    IdealState idealState = _accessor.getProperty(_keyBuilder.idealStates(resourceId.stringify()));

    if (idealState == null) {
      LOG.error("Resource " + resourceId + " not present on the cluster");
View Full Code Here

    String eventName;
    String path = context.getPathChanged();
    if (path.contains(ConfigScopeProperty.RESOURCE.toString())) {
      List<ResourceConfiguration> resourceConfigs = Lists.newArrayList();
      for (HelixProperty property : configs) {
        resourceConfigs.add(new ResourceConfiguration(property.getRecord()));
      }
      _cache.setResourceConfigs(resourceConfigs);
      eventName = "resourceConfigChange";
    } else if (path.contains(ConfigScopeProperty.CONSTRAINT.toString())) {
      List<ClusterConstraints> constraints = Lists.newArrayList();
View Full Code Here

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

            updatedIdealState);
      }

      // Update the resource config if any of its inner configs is set
      boolean addedAnything = false;
      ResourceConfiguration updatedResourceConfig = new ResourceConfiguration(resourceId);
      ProvisionerConfig provisionerConfig = deltaConfig.getProvisionerConfig();
      if (provisionerConfig != null) {
        updatedResourceConfig.addNamespacedConfig(new ProvisionerConfigHolder(provisionerConfig)
            .toNamespacedConfig());
        addedAnything = true;
      }
      RebalancerConfig rebalancerConfig = deltaConfig.getRebalancerConfig();
      if (rebalancerConfig != null) {
        updatedResourceConfig.addNamespacedConfig(new RebalancerConfigHolder(rebalancerConfig)
            .toNamespacedConfig());
        addedAnything = true;
      }
      UserConfig userConfig = deltaConfig.getUserConfig();
      if (userConfig != null) {
        updatedResourceConfig.addNamespacedConfig(userConfig);
        addedAnything = true;
      }
      if (addedAnything) {
        accessor.updateProperty(accessor.keyBuilder().resourceConfig(resourceId.toString()),
            updatedResourceConfig);
View Full Code Here

   * Read a single snapshot of a resource
   * @param resourceId the resource id to read
   * @return Resource or null if not present
   */
  public Resource readResource(ResourceId resourceId) {
    ResourceConfiguration config =
        _accessor.getProperty(_keyBuilder.resourceConfig(resourceId.stringify()));
    IdealState idealState = _accessor.getProperty(_keyBuilder.idealStates(resourceId.stringify()));

    if (config == null && idealState == null) {
      LOG.error("Resource " + resourceId + " not present on the cluster");
View Full Code Here

   * @param context the new rebalancer context
   * @return true if the context was set, false otherwise
   */
  public boolean setRebalancerContext(ResourceId resourceId, RebalancerContext context) {
    RebalancerConfig config = new RebalancerConfig(context);
    ResourceConfiguration resourceConfig = new ResourceConfiguration(resourceId);
    resourceConfig.addNamespacedConfig(config.toNamespacedConfig());

    // update the ideal state if applicable
    IdealState oldIdealState =
        _accessor.getProperty(_keyBuilder.idealStates(resourceId.stringify()));
    if (oldIdealState != null) {
View Full Code Here

   * Read the user config of the resource
   * @param resourceId the resource to to look up
   * @return UserConfig, or null
   */
  public UserConfig readUserConfig(ResourceId resourceId) {
    ResourceConfiguration resourceConfig =
        _accessor.getProperty(_keyBuilder.resourceConfig(resourceId.stringify()));
    return resourceConfig != null ? UserConfig.from(resourceConfig) : null;
  }
View Full Code Here

   * Read the rebalancer config of the resource
   * @param resourceId the resource to to look up
   * @return RebalancerConfig, or null
   */
  public RebalancerConfig readRebalancerConfig(ResourceId resourceId) {
    ResourceConfiguration resourceConfig =
        _accessor.getProperty(_keyBuilder.resourceConfig(resourceId.stringify()));
    return resourceConfig != null ? RebalancerConfig.from(resourceConfig) : null;
  }
View Full Code Here

   * @param resourceId the resource to update
   * @param userConfig the user config key-value pairs to add
   * @return true if the user config was updated, false otherwise
   */
  public boolean updateUserConfig(ResourceId resourceId, UserConfig userConfig) {
    ResourceConfiguration resourceConfig = new ResourceConfiguration(resourceId);
    resourceConfig.addNamespacedConfig(userConfig);
    return _accessor.updateProperty(_keyBuilder.resourceConfig(resourceId.stringify()),
        resourceConfig);
  }
View Full Code Here

TOP

Related Classes of org.apache.helix.model.ResourceConfiguration

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.