Package org.apache.helix

Examples of org.apache.helix.ConfigScopeBuilder


    boolean enabled = true;
    if (configAccessor != null)
    {
      // zk-based cluster manager
      ConfigScope scope =
          new ConfigScopeBuilder().forCluster(_manager.getClusterName()).build();
      String isEnabled = configAccessor.get(scope, "healthChange.enabled");
      if (isEnabled != null)
      {
        enabled = new Boolean(isEnabled);
      }
View Full Code Here


          // path is "/clusters/{clusterName}/configs/cluster|particicpant|resource/
          // {clusterName}|{participantName}|{resourceName}"
          ConfigScope scope;
          if (scopeProperty == ConfigScopeProperty.CLUSTER)
          {
            scope = new ConfigScopeBuilder().build(scopeProperty, clusterName);
          }
          else
          {
            scope = new ConfigScopeBuilder().build(scopeProperty, clusterName, scopeKey1);
          }
          representation = getConfigs(scope, scopeProperty, scopeKey1);
        }
        break;
      case PARTITION:
        scopeKey1 = getValue("scopeKey1");
        String scopeKey2 = getValue("scopeKey2");
        if (scopeKey1 == null)
        {
          // path is "/clusters/{clusterName}/configs/partition"
          throw new HelixException("Missing resourceName");
        }
        else if (scopeKey2 == null)
        {
          // path is "/clusters/{clusterName}/configs/partition/resourceName"
          representation = getConfigKeys(scopeProperty, scopeKey1);
        }
        else
        {
          // path is
          // "/clusters/{clusterName}/configs/partition/resourceName/partitionName"
          ConfigScope scope =
              new ConfigScopeBuilder().build(scopeProperty,
                                             clusterName,
                                             scopeKey1,
                                             scopeKey2);
          representation = getConfigs(scope, scopeProperty, scopeKey1, scopeKey2);
        }
View Full Code Here

   * @param properitesStr
   *          : key=value, ... which represents a Map<String, String>
   */
  public void setConfig(String scopesStr, String propertiesStr)
  {
    ConfigScope scope = new ConfigScopeBuilder().build(scopesStr);

    // parse properties
    String[] properties = propertiesStr.split("[\\s,]");
    Map<String, String> propertiesMap = new TreeMap<String, String>();
    for (String property : properties)
View Full Code Here

    _admin.setConfig(scope, propertiesMap);
  }

  public void removeConfig(String scopesStr, String keysStr)
  {
    ConfigScope scope = new ConfigScopeBuilder().build(scopesStr);

    // parse keys
    String[] keys = keysStr.split("[\\s,]");
    Set<String> keysSet = new HashSet<String>(Arrays.asList(keys));
View Full Code Here

    _admin.removeConfig(scope, keysSet);
  }

  public String getConfig(String scopesStr, String keysStr)
  {
    ConfigScope scope = new ConfigScopeBuilder().build(scopesStr);

    // parse keys
    String[] keys = keysStr.split("[\\s,]");
    Set<String> keysSet = new HashSet<String>(Arrays.asList(keys));
View Full Code Here

  {
    TestHelper.setupCluster(_clusterName, ZK_ADDR, 12918, "localhost", "TestDB", 1, 10, 5, 3,
        "MasterSlave", true);

    ConfigAccessor appConfig = new ConfigAccessor(_gZkClient);
    ConfigScope clusterScope = new ConfigScopeBuilder().forCluster(_clusterName).build();

    // cluster scope config
    String clusterConfigValue = appConfig.get(clusterScope, "clusterConfigKey");
    Assert.assertNull(clusterConfigValue);

    appConfig.set(clusterScope, "clusterConfigKey", "clusterConfigValue");
    clusterConfigValue = appConfig.get(clusterScope, "clusterConfigKey");
    Assert.assertEquals(clusterConfigValue, "clusterConfigValue");

    // resource scope config
    ConfigScope resourceScope = new ConfigScopeBuilder().forCluster(_clusterName)
        .forResource("testResource").build();
    appConfig.set(resourceScope, "resourceConfigKey", "resourceConfigValue");
    String resourceConfigValue = appConfig.get(resourceScope, "resourceConfigKey");
    Assert.assertEquals(resourceConfigValue, "resourceConfigValue");

    // partition scope config
    ConfigScope partitionScope = new ConfigScopeBuilder().forCluster(_clusterName)
        .forResource("testResource").forPartition("testPartition").build();
    appConfig.set(partitionScope, "partitionConfigKey", "partitionConfigValue");
    String partitionConfigValue = appConfig.get(partitionScope, "partitionConfigKey");
    Assert.assertEquals(partitionConfigValue, "partitionConfigValue");

    // participant scope config
    ConfigScope participantScope = new ConfigScopeBuilder().forCluster(_clusterName)
        .forParticipant("localhost_12918").build();
    appConfig.set(participantScope, "participantConfigKey", "participantConfigValue");
    String participantConfigValue = appConfig.get(participantScope, "participantConfigKey");
    Assert.assertEquals(participantConfigValue, "participantConfigValue");

    List<String> keys = appConfig.getKeys(ConfigScopeProperty.RESOURCE, _clusterName);
    Assert.assertEquals(keys.size(), 1, "should be [testResource]");
    Assert.assertEquals(keys.get(0), "testResource");

    keys = appConfig.getKeys(ConfigScopeProperty.CLUSTER, _clusterName);
    Assert.assertEquals(keys.size(), 1, "should be [" + _clusterName + "]");
    Assert.assertEquals(keys.get(0), _clusterName);

    keys = appConfig.getKeys(ConfigScopeProperty.PARTICIPANT, _clusterName);
    Assert.assertEquals(keys.size(), 5, "should be [localhost_12918~22] sorted");
    Assert.assertEquals(keys.get(0), "localhost_12918");
    Assert.assertEquals(keys.get(4), "localhost_12922");

    keys = appConfig.getKeys(ConfigScopeProperty.PARTITION, _clusterName, "testResource");
    Assert.assertEquals(keys.size(), 1, "should be [testPartition]");
    Assert.assertEquals(keys.get(0), "testPartition");

    keys = appConfig.getKeys(ConfigScopeProperty.RESOURCE, _clusterName, "testResource");
    Assert.assertEquals(keys.size(), 1, "should be [resourceConfigKey]");
    Assert.assertEquals(keys.get(0), "resourceConfigKey");

    keys = appConfig.getKeys(ConfigScopeProperty.CLUSTER, _clusterName, _clusterName);
    Assert.assertEquals(keys.size(), 1, "should be [clusterConfigKey]");
    Assert.assertEquals(keys.get(0), "clusterConfigKey");

    keys = appConfig.getKeys(ConfigScopeProperty.PARTICIPANT, _clusterName, "localhost_12918");
    Assert.assertEquals(keys.size(), 4, "should be [HELIX_ENABLED, HELIX_HOST, HELIX_PORT, participantConfigKey]");
    Assert.assertEquals(keys.get(3), "participantConfigKey");

    keys = appConfig.getKeys(ConfigScopeProperty.PARTITION, _clusterName, "testResource", "testPartition");
    Assert.assertEquals(keys.size(), 1, "should be [partitionConfigKey]");
    Assert.assertEquals(keys.get(0), "partitionConfigKey");

    // test configAccessor.remove()
    appConfig.remove(clusterScope, "clusterConfigKey");
    clusterConfigValue = appConfig.get(clusterScope, "clusterConfigKey");
    Assert.assertNull(clusterConfigValue, "Should be null since it's removed");

    appConfig.remove(resourceScope, "resourceConfigKey");
    resourceConfigValue = appConfig.get(resourceScope, "resourceConfigKey");
    Assert.assertNull(resourceConfigValue, "Should be null since it's removed");

    appConfig.remove(partitionScope, "partitionConfigKey");
    partitionConfigValue = appConfig.get(partitionScope, "partitionConfigKey");
    Assert.assertNull(partitionConfigValue, "Should be null since it's removed");
   
    appConfig.remove(participantScope, "participantConfigKey");
    participantConfigValue = appConfig.get(partitionScope, "participantConfigKey");
    Assert.assertNull(participantConfigValue, "Should be null since it's removed");
   
    // negative tests
    try
    {
      new ConfigScopeBuilder().forPartition("testPartition").build();
      Assert.fail("Should fail since cluster name is not set");
    } catch (Exception e)
    {
      // OK
    }

    try
    {
      new ConfigScopeBuilder().forCluster("testCluster").forPartition("testPartition").build();
      Assert.fail("Should fail since resource name is not set");
    } catch (Exception e)
    {
      // OK
    }

    try
    {
      new ConfigScopeBuilder().forParticipant("testParticipant").build();
      Assert.fail("Should fail since cluster name is not set");
    } catch (Exception e)
    {
      // OK
    }
View Full Code Here

    ExternalView resourceExternalView = tool.getResourceExternalView(
        clusterName, "resource");
    AssertJUnit.assertNull(resourceExternalView);

    // test config support
    ConfigScope scope = new ConfigScopeBuilder().forCluster(clusterName)
        .forResource("testResource").forPartition("testPartition").build();
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("pKey1", "pValue1");
    properties.put("pKey2", "pValue2");
   
View Full Code Here

  private static void addConfiguration(ClusterSetup setup, String baseDir,
      String clusterName, String instanceName) throws IOException
  {
    Map<String, String> properties = new HashMap<String, String>();
    ConfigScopeBuilder builder = new ConfigScopeBuilder();
    ConfigScope instanceScope = builder.forCluster(clusterName)
        .forParticipant(instanceName).build();
    properties.put("change_log_dir", baseDir + instanceName + "/translog");
    properties.put("file_store_dir", baseDir + instanceName + "/filestore");
    properties.put("check_point_dir", baseDir + instanceName + "/checkpoint");
    setup.getClusterManagementTool().setConfig(instanceScope, properties);
View Full Code Here

      // Read the participant config and cluster config for the per-message type thread pool size.
      // participant config will override the cluster config.
     
      if(_manager.getInstanceType() == InstanceType.PARTICIPANT || _manager.getInstanceType() == InstanceType.CONTROLLER_PARTICIPANT)
      {
        scope = new ConfigScopeBuilder().forCluster(_manager.getClusterName()).forParticipant(_manager.getInstanceName()).build();
        threadpoolSizeStr = configAccessor.get(scope, key);
      }
     
      if(threadpoolSizeStr == null)
      {
        scope = new ConfigScopeBuilder().forCluster(_manager.getClusterName()).build();
        threadpoolSizeStr = configAccessor.get(scope, key);
      }
    }
   
    if(threadpoolSizeStr != null)
View Full Code Here

      int threadpoolSize = -1;
      ConfigAccessor configAccessor = manager.getConfigAccessor();
      if (configAccessor != null)
      {
        ConfigScope scope =
            new ConfigScopeBuilder().forCluster(manager.getClusterName())
                                    .forResource(resourceName)
                                    .build();

        String threadpoolSizeStr = configAccessor.get(scope, MAX_THREADS);
        try
View Full Code Here

TOP

Related Classes of org.apache.helix.ConfigScopeBuilder

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.