use of org.apache.helix.model.CloudConfig in project helix by apache.
the class TestMultiZkConectionConfig 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();
RealmAwareZkClient.RealmAwareZkConnectionConfig validZkConnectionConfig = connectionConfigBuilder.setRoutingDataSourceEndpoint(_msdsEndpoint + "," + ZK_PREFIX + ZK_START_PORT).setRoutingDataSourceType(RoutingDataReaderType.HTTP_ZK_FALLBACK.name()).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 TestInstanceAutoJoin method testAutoRegistration.
@Test(dependsOnMethods = "testInstanceAutoJoin")
public void testAutoRegistration() throws Exception {
// Create CloudConfig object and add to config
CloudConfig.Builder cloudConfigBuilder = new CloudConfig.Builder();
cloudConfigBuilder.setCloudEnabled(true);
cloudConfigBuilder.setCloudProvider(CloudProvider.AZURE);
CloudConfig cloudConfig = cloudConfigBuilder.build();
HelixManager manager = _participants[0];
HelixDataAccessor accessor = manager.getHelixDataAccessor();
_gSetupTool.addResourceToCluster(CLUSTER_NAME, db3, 60, "OnlineOffline", RebalanceMode.FULL_AUTO.name(), CrushEdRebalanceStrategy.class.getName());
_gSetupTool.rebalanceStorageCluster(CLUSTER_NAME, db3, 1);
String instance3 = "localhost_279700";
ConfigScope scope = new ConfigScopeBuilder().forCluster(CLUSTER_NAME).build();
manager.getConfigAccessor().set(scope, ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, "true");
// Write the CloudConfig to Zookeeper
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.cloudConfig(), cloudConfig);
MockParticipantManager autoParticipant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instance3);
autoParticipant.syncStart();
// populated. An exception will be thrown.
try {
manager.getConfigAccessor().getInstanceConfig(CLUSTER_NAME, instance3);
Assert.assertTrue(TestHelper.verify(() -> {
if (null == manager.getHelixDataAccessor().getProperty(accessor.keyBuilder().liveInstance(instance3))) {
return false;
}
return true;
}, 2000));
} catch (HelixException e) {
Assert.assertTrue(null == manager.getHelixDataAccessor().getProperty(accessor.keyBuilder().liveInstance(instance3)));
}
autoParticipant.syncStop();
}
use of org.apache.helix.model.CloudConfig in project helix by apache.
the class ZKHelixAdmin method addCloudConfig.
@Override
public void addCloudConfig(String clusterName, CloudConfig cloudConfig) {
logger.info("Add CloudConfig to cluster {}, CloudConfig is {}.", clusterName, cloudConfig.toString());
if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
throw new HelixException("cluster " + clusterName + " is not setup yet");
}
CloudConfig.Builder builder = new CloudConfig.Builder(cloudConfig);
CloudConfig cloudConfigBuilder = builder.build();
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.cloudConfig(), cloudConfigBuilder);
}
use of org.apache.helix.model.CloudConfig in project helix by apache.
the class TestCloudEventCallbackProperty method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
// Set up Helix manager property: Helix Cloud Property
_cloudProperty = new HelixCloudProperty(new CloudConfig(new ZNRecord(CLUSTER_NAME)));
_cloudProperty.setCloudEventCallbackEnabled(true);
HelixManagerProperty.Builder managerPropertyBuilder = new HelixManagerProperty.Builder();
managerPropertyBuilder.setHelixCloudProperty(_cloudProperty);
// Build Helix manager property
HelixManagerProperty managerProperty = managerPropertyBuilder.build();
// Create Helix Manager
_helixManager = new MockCloudEventAwareHelixManager(managerProperty);
}
use of org.apache.helix.model.CloudConfig in project helix by apache.
the class TestClusterAccessor method setupClusterForVirtualTopology.
private void setupClusterForVirtualTopology(String clusterName) {
HelixDataAccessor helixDataAccessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
ZNRecord record = new ZNRecord("testZnode");
record.setBooleanField(CloudConfig.CloudConfigProperty.CLOUD_ENABLED.name(), true);
record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_ID.name(), "TestCloudID");
record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_PROVIDER.name(), CloudProvider.AZURE.name());
CloudConfig cloudConfig = new CloudConfig.Builder(record).build();
_gSetupTool.addCluster(clusterName, true, cloudConfig);
Set<String> instances = new HashSet<>();
for (int i = 0; i < 10; i++) {
String instanceName = clusterName + "_localhost_" + (12918 + i);
_gSetupTool.addInstanceToCluster(clusterName, instanceName);
InstanceConfig instanceConfig = helixDataAccessor.getProperty(helixDataAccessor.keyBuilder().instanceConfig(instanceName));
instanceConfig.setDomain("faultDomain=" + i / 2 + ",hostname=" + instanceName);
helixDataAccessor.setProperty(helixDataAccessor.keyBuilder().instanceConfig(instanceName), instanceConfig);
instances.add(instanceName);
}
startInstances(clusterName, instances, 10);
}
Aggregations