Search in sources :

Example 26 with CloudConfig

use of org.apache.helix.model.CloudConfig in project helix by apache.

the class HelixCloudProperty method populateFieldsWithCloudConfig.

public void populateFieldsWithCloudConfig(CloudConfig cloudConfig) {
    if (cloudConfig == null) {
        cloudConfig = new CloudConfig();
    }
    setCloudEnabled(cloudConfig.isCloudEnabled());
    setCloudId(cloudConfig.getCloudID());
    String cloudProviderStr = cloudConfig.getCloudProvider();
    setCloudProvider(cloudProviderStr);
    if (cloudProviderStr != null) {
        switch(CloudProvider.valueOf(cloudProviderStr)) {
            case AZURE:
                Properties azureProperties = new Properties();
                try {
                    InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(AZURE_CLOUD_PROPERTY_FILE);
                    azureProperties.load(stream);
                } catch (IOException e) {
                    String errMsg = "failed to open Helix Azure cloud properties file: " + AZURE_CLOUD_PROPERTY_FILE;
                    throw new IllegalArgumentException(errMsg, e);
                }
                LOG.info("Successfully loaded Helix Azure cloud properties: {}", azureProperties);
                setCloudInfoSources(Collections.singletonList(azureProperties.getProperty(CLOUD_INFO_SOURCE)));
                setCloudInfoProcessorName(azureProperties.getProperty(CLOUD_INFO_PROCESSOR_NAME));
                setCloudMaxRetry(Integer.valueOf(azureProperties.getProperty(CLOUD_MAX_RETRY)));
                setCloudConnectionTimeout(Long.valueOf(azureProperties.getProperty(CONNECTION_TIMEOUT_MS)));
                setCloudRequestTimeout(Long.valueOf(azureProperties.getProperty(REQUEST_TIMEOUT_MS)));
                break;
            case CUSTOMIZED:
                setCloudInfoSources(cloudConfig.getCloudInfoSources());
                setCloudInfoProcessorName(cloudConfig.getCloudInfoProcessorName());
                break;
            default:
                throw new HelixException(String.format("Unsupported cloud provider: %s", cloudConfig.getCloudProvider()));
        }
    }
}
Also used : InputStream(java.io.InputStream) CloudConfig(org.apache.helix.model.CloudConfig) IOException(java.io.IOException) Properties(java.util.Properties)

Example 27 with CloudConfig

use of org.apache.helix.model.CloudConfig in project helix by apache.

the class ClusterSetup method setCloudConfig.

/**
 * set cloud configs
 * @param clusterName
 * @param cloudConfigManifest
 */
public void setCloudConfig(String clusterName, String cloudConfigManifest) {
    ZNRecord record;
    try {
        record = ZNRECORD_READER.readValue(cloudConfigManifest);
    } catch (IOException e) {
        _logger.error("Failed to deserialize user's input " + cloudConfigManifest + ", Exception: " + e);
        throw new IllegalArgumentException("Failed to deserialize user's input ");
    }
    CloudConfig cloudConfig = new CloudConfig.Builder(record).build();
    _admin.addCloudConfig(clusterName, cloudConfig);
}
Also used : CloudConfig(org.apache.helix.model.CloudConfig) IOException(java.io.IOException) ZNRecord(org.apache.helix.zookeeper.datamodel.ZNRecord)

Example 28 with CloudConfig

use of org.apache.helix.model.CloudConfig in project helix by apache.

the class TestCloudConfig method testCloudConfigNonExistentCluster.

@Test(expectedExceptions = HelixException.class)
public void testCloudConfigNonExistentCluster() {
    String className = getShortClassName();
    String clusterName = "CLUSTER_" + className;
    // Read CloudConfig from Zookeeper and get exception since cluster in not setup yet
    ConfigAccessor _configAccessor = new ConfigAccessor(_gZkClient);
    CloudConfig cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName);
}
Also used : CloudConfig(org.apache.helix.model.CloudConfig) ConfigAccessor(org.apache.helix.ConfigAccessor) Test(org.testng.annotations.Test)

Example 29 with CloudConfig

use of org.apache.helix.model.CloudConfig in project helix by apache.

the class TestCloudConfig method testCloudConfigBuilder.

@Test(dependsOnMethods = "testCloudConfig")
public void testCloudConfigBuilder() {
    String className = getShortClassName();
    String clusterName = "CLUSTER_" + className;
    TestHelper.setupEmptyCluster(_gZkClient, clusterName);
    CloudConfig.Builder builder = new CloudConfig.Builder();
    builder.setCloudEnabled(true);
    builder.setCloudProvider(CloudProvider.CUSTOMIZED);
    builder.setCloudID("TestID");
    builder.addCloudInfoSource("TestURL0");
    builder.addCloudInfoSource("TestURL1");
    builder.setCloudInfoProcessorName("TestProcessor");
    // Check builder getter methods
    Assert.assertTrue(builder.getCloudEnabled());
    Assert.assertEquals(builder.getCloudProvider(), CloudProvider.CUSTOMIZED.name());
    Assert.assertEquals(builder.getCloudID(), "TestID");
    List<String> listUrlFromBuilder = builder.getCloudInfoSources();
    Assert.assertEquals(listUrlFromBuilder.size(), 2);
    Assert.assertEquals(listUrlFromBuilder.get(0), "TestURL0");
    Assert.assertEquals(listUrlFromBuilder.get(1), "TestURL1");
    Assert.assertEquals(builder.getCloudInfoProcessorName(), "TestProcessor");
    CloudConfig cloudConfig = builder.build();
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
    Builder keyBuilder = accessor.keyBuilder();
    accessor.setProperty(keyBuilder.cloudConfig(), cloudConfig);
    // Read CloudConfig from Zookeeper and check the content
    ConfigAccessor _configAccessor = new ConfigAccessor(_gZkClient);
    CloudConfig cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName);
    Assert.assertTrue(cloudConfigFromZk.isCloudEnabled());
    Assert.assertEquals(cloudConfigFromZk.getCloudProvider(), CloudProvider.CUSTOMIZED.name());
    Assert.assertEquals(cloudConfigFromZk.getCloudID(), "TestID");
    List<String> listUrlFromZk = cloudConfigFromZk.getCloudInfoSources();
    Assert.assertEquals(listUrlFromZk.get(0), "TestURL0");
    Assert.assertEquals(listUrlFromZk.get(1), "TestURL1");
    Assert.assertEquals(cloudConfigFromZk.getCloudInfoProcessorName(), "TestProcessor");
}
Also used : ZkBaseDataAccessor(org.apache.helix.manager.zk.ZkBaseDataAccessor) Builder(org.apache.helix.PropertyKey.Builder) CloudConfig(org.apache.helix.model.CloudConfig) ConfigAccessor(org.apache.helix.ConfigAccessor) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 30 with CloudConfig

use of org.apache.helix.model.CloudConfig in project helix by apache.

the class TestCloudConfig method testCloudConfigNull.

@Test(dependsOnMethods = "testCloudConfigNonExistentCluster")
public void testCloudConfigNull() {
    String className = getShortClassName();
    String clusterName = "CLUSTER_" + className;
    TestHelper.setupEmptyCluster(_gZkClient, clusterName);
    // Read CloudConfig from Zookeeper
    ConfigAccessor _configAccessor = new ConfigAccessor(_gZkClient);
    CloudConfig cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName);
    // since CloudConfig is not written to ZooKeeper, the output should be null
    Assert.assertNull(cloudConfigFromZk);
}
Also used : CloudConfig(org.apache.helix.model.CloudConfig) ConfigAccessor(org.apache.helix.ConfigAccessor) Test(org.testng.annotations.Test)

Aggregations

CloudConfig (org.apache.helix.model.CloudConfig)42 Test (org.testng.annotations.Test)26 ConfigAccessor (org.apache.helix.ConfigAccessor)18 ZNRecord (org.apache.helix.zookeeper.datamodel.ZNRecord)15 ArrayList (java.util.ArrayList)14 Builder (org.apache.helix.PropertyKey.Builder)10 IOException (java.io.IOException)8 PropertyPathBuilder (org.apache.helix.PropertyPathBuilder)8 HashMap (java.util.HashMap)7 HelixConfigScopeBuilder (org.apache.helix.model.builder.HelixConfigScopeBuilder)7 RealmAwareZkClient (org.apache.helix.zookeeper.api.client.RealmAwareZkClient)7 HelixException (org.apache.helix.HelixException)6 HelixAdmin (org.apache.helix.HelixAdmin)5 ResponseMetered (com.codahale.metrics.annotation.ResponseMetered)4 Timed (com.codahale.metrics.annotation.Timed)4 Properties (java.util.Properties)4 Path (javax.ws.rs.Path)4 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)4 InstanceConfig (org.apache.helix.model.InstanceConfig)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4