use of org.apache.helix.model.CloudConfig in project helix by apache.
the class TestConfigAccessor method testDeleteCloudConfig.
@Test
public void testDeleteCloudConfig() throws Exception {
ClusterSetup _clusterSetup = new ClusterSetup(ZK_ADDR);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
CloudConfig.Builder cloudConfigInitBuilder = new CloudConfig.Builder();
cloudConfigInitBuilder.setCloudEnabled(true);
cloudConfigInitBuilder.setCloudID("TestCloudID");
List<String> sourceList = new ArrayList<String>();
sourceList.add("TestURL");
cloudConfigInitBuilder.setCloudInfoSources(sourceList);
cloudConfigInitBuilder.setCloudInfoProcessorName("TestProcessor");
cloudConfigInitBuilder.setCloudProvider(CloudProvider.AZURE);
CloudConfig cloudConfigInit = cloudConfigInitBuilder.build();
_clusterSetup.addCluster(clusterName, false, cloudConfigInit);
// Read CloudConfig from Zookeeper and check the content
ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR);
CloudConfig cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName);
Assert.assertTrue(cloudConfigFromZk.isCloudEnabled());
Assert.assertEquals(cloudConfigFromZk.getCloudID(), "TestCloudID");
List<String> listUrlFromZk = cloudConfigFromZk.getCloudInfoSources();
Assert.assertEquals(listUrlFromZk.get(0), "TestURL");
Assert.assertEquals(cloudConfigFromZk.getCloudInfoProcessorName(), "TestProcessor");
Assert.assertEquals(cloudConfigFromZk.getCloudProvider(), CloudProvider.AZURE.name());
// Change the processor name and check if processor name has been changed in Zookeeper.
CloudConfig.Builder cloudConfigBuilderToDelete = new CloudConfig.Builder();
cloudConfigBuilderToDelete.setCloudInfoProcessorName("TestProcessor");
cloudConfigBuilderToDelete.setCloudID("TestCloudID");
CloudConfig cloudConfigToDelete = cloudConfigBuilderToDelete.build();
_configAccessor.deleteCloudConfigFields(clusterName, cloudConfigToDelete);
cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName);
Assert.assertTrue(cloudConfigFromZk.isCloudEnabled());
Assert.assertNull(cloudConfigFromZk.getCloudID());
listUrlFromZk = cloudConfigFromZk.getCloudInfoSources();
Assert.assertEquals(listUrlFromZk.get(0), "TestURL");
Assert.assertNull(cloudConfigFromZk.getCloudInfoProcessorName());
Assert.assertEquals(cloudConfigFromZk.getCloudProvider(), CloudProvider.AZURE.name());
}
use of org.apache.helix.model.CloudConfig in project helix by apache.
the class TestMultiZkHelixJavaApis method testZKHelixManagerCloudConfig.
/**
* Test creation of HelixManager and makes sure it connects correctly.
*/
@Test(dependsOnMethods = "testZKHelixManager")
public void testZKHelixManagerCloudConfig() throws Exception {
String clusterName = "CLUSTER_1";
String participantName = "HelixManager";
InstanceConfig instanceConfig = new InstanceConfig(participantName);
_zkHelixAdmin.addInstance(clusterName, instanceConfig);
RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder connectionConfigBuilder = new RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder();
// Try with a connection config without ZK realm sharding key set (should fail)
RealmAwareZkClient.RealmAwareZkConnectionConfig invalidZkConnectionConfig = connectionConfigBuilder.build();
RealmAwareZkClient.RealmAwareZkConnectionConfig validZkConnectionConfig = connectionConfigBuilder.setZkRealmShardingKey("/" + clusterName).build();
HelixManagerProperty.Builder propertyBuilder = new HelixManagerProperty.Builder();
// create a dummy cloud config and pass to ManagerFactory. It should be overwrite by
// a default config because there is no CloudConfig ZNode in ZK.
CloudConfig.Builder cloudConfigBuilder = new CloudConfig.Builder();
cloudConfigBuilder.setCloudEnabled(true);
// Set to Customized so CloudInfoSources and CloudInfoProcessorName will be read from cloud config
// instead of properties
cloudConfigBuilder.setCloudProvider(CloudProvider.CUSTOMIZED);
cloudConfigBuilder.setCloudID("TestID");
List<String> infoURL = new ArrayList<String>();
infoURL.add("TestURL");
cloudConfigBuilder.setCloudInfoSources(infoURL);
cloudConfigBuilder.setCloudInfoProcessorName("TestProcessor");
CloudConfig cloudConfig = cloudConfigBuilder.build();
HelixCloudProperty oldCloudProperty = new HelixCloudProperty(cloudConfig);
HelixManagerProperty helixManagerProperty = propertyBuilder.setRealmAWareZkConnectionConfig(validZkConnectionConfig).setHelixCloudProperty(oldCloudProperty).build();
// Cloud property populated with fields defined in cloud config
oldCloudProperty.populateFieldsWithCloudConfig(cloudConfig);
// Add some property fields to cloud property that are not in cloud config
Properties properties = new Properties();
oldCloudProperty.setCustomizedCloudProperties(properties);
class TestZKHelixManager extends ZKHelixManager {
public TestZKHelixManager(String clusterName, String participantName, InstanceType instanceType, String zkAddress, HelixManagerStateListener stateListener, HelixManagerProperty helixManagerProperty) {
super(clusterName, participantName, instanceType, zkAddress, stateListener, helixManagerProperty);
}
public HelixManagerProperty getHelixManagerProperty() {
return _helixManagerProperty;
}
}
// Connect as a participant
TestZKHelixManager managerParticipant = new TestZKHelixManager(clusterName, participantName, InstanceType.PARTICIPANT, null, null, helixManagerProperty);
managerParticipant.connect();
HelixCloudProperty newCloudProperty = managerParticipant.getHelixManagerProperty().getHelixCloudProperty();
// Test reading from zk cloud config overwrite property fields included in cloud config
Assert.assertFalse(newCloudProperty.getCloudEnabled());
Assert.assertNull(newCloudProperty.getCloudId());
Assert.assertNull(newCloudProperty.getCloudProvider());
// Test non-cloud config fields are not overwritten after reading cloud config from zk
Assert.assertEquals(newCloudProperty.getCustomizedCloudProperties(), properties);
Assert.assertEquals(newCloudProperty.getCloudInfoSources(), infoURL);
Assert.assertEquals(newCloudProperty.getCloudInfoProcessorName(), "TestProcessor");
// Clean up
managerParticipant.disconnect();
_zkHelixAdmin.dropInstance(clusterName, instanceConfig);
}
use of org.apache.helix.model.CloudConfig in project helix by apache.
the class TestZkHelixAdmin method testAddCloudConfig.
@Test
public void testAddCloudConfig() {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
admin.addCluster(clusterName, true);
CloudConfig.Builder builder = new CloudConfig.Builder();
builder.setCloudEnabled(true);
builder.setCloudID("TestID");
builder.addCloudInfoSource("TestURL");
builder.setCloudProvider(CloudProvider.CUSTOMIZED);
builder.setCloudInfoProcessorName("TestProcessor");
CloudConfig cloudConfig = builder.build();
admin.addCloudConfig(clusterName, 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.getCloudID(), "TestID");
Assert.assertEquals(cloudConfigFromZk.getCloudProvider(), CloudProvider.CUSTOMIZED.name());
List<String> listUrlFromZk = cloudConfigFromZk.getCloudInfoSources();
Assert.assertEquals(listUrlFromZk.get(0), "TestURL");
Assert.assertEquals(cloudConfigFromZk.getCloudInfoProcessorName(), "TestProcessor");
}
use of org.apache.helix.model.CloudConfig in project helix by apache.
the class TestZkHelixAdmin method testRemoveCloudConfig.
@Test
public void testRemoveCloudConfig() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
admin.addCluster(clusterName, true);
CloudConfig.Builder builder = new CloudConfig.Builder();
builder.setCloudEnabled(true);
builder.setCloudID("TestID");
builder.addCloudInfoSource("TestURL");
builder.setCloudProvider(CloudProvider.CUSTOMIZED);
builder.setCloudInfoProcessorName("TestProcessor");
CloudConfig cloudConfig = builder.build();
admin.addCloudConfig(clusterName, 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.getCloudID(), "TestID");
Assert.assertEquals(cloudConfigFromZk.getCloudProvider(), CloudProvider.CUSTOMIZED.name());
List<String> listUrlFromZk = cloudConfigFromZk.getCloudInfoSources();
Assert.assertEquals(listUrlFromZk.get(0), "TestURL");
Assert.assertEquals(cloudConfigFromZk.getCloudInfoProcessorName(), "TestProcessor");
// Remove Cloud Config and make sure it has been removed from Zookeeper
admin.removeCloudConfig(clusterName);
cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName);
Assert.assertNull(cloudConfigFromZk);
}
use of org.apache.helix.model.CloudConfig in project helix by apache.
the class ClusterAccessor method updateCloudConfig.
@ClusterAuth
@ResponseMetered(name = HttpConstants.WRITE_REQUEST)
@Timed(name = HttpConstants.WRITE_REQUEST)
@POST
@Path("{clusterId}/cloudconfig")
public Response updateCloudConfig(@PathParam("clusterId") String clusterId, @QueryParam("command") String commandStr, String content) {
RealmAwareZkClient zkClient = getRealmAwareZkClient();
if (!ZKUtil.isClusterSetup(clusterId, zkClient)) {
return notFound();
}
ConfigAccessor configAccessor = new ConfigAccessor(zkClient);
// Here to update cloud config
Command command;
if (commandStr == null || commandStr.isEmpty()) {
// Default behavior
command = Command.update;
} else {
try {
command = getCommand(commandStr);
} catch (HelixException ex) {
return badRequest(ex.getMessage());
}
}
ZNRecord record;
CloudConfig cloudConfig;
try {
record = toZNRecord(content);
cloudConfig = new CloudConfig(record);
} catch (IOException e) {
LOG.error("Failed to deserialize user's input " + content + ", Exception: " + e);
return badRequest("Input is not a vaild ZNRecord!");
}
try {
switch(command) {
case delete:
{
configAccessor.deleteCloudConfigFields(clusterId, cloudConfig);
}
break;
case update:
{
try {
configAccessor.updateCloudConfig(clusterId, cloudConfig);
} catch (HelixException ex) {
LOG.error("Error in updating a CloudConfig to cluster: " + clusterId, ex);
return badRequest(ex.getMessage());
} catch (Exception ex) {
LOG.error("Cannot update CloudConfig for cluster: " + clusterId, ex);
return serverError(ex);
}
}
break;
default:
return badRequest("Unsupported command " + commandStr);
}
} catch (Exception ex) {
LOG.error("Failed to " + command + " cloud config, cluster " + clusterId + " new config: " + content + ", Exception: " + ex);
return serverError(ex);
}
return OK();
}
Aggregations