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()));
}
}
}
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);
}
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);
}
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");
}
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);
}
Aggregations