use of org.apache.helix.HelixManagerProperty in project helix by apache.
the class TestMultiZkConectionConfig method testCreateParticipants.
/**
* Test Helix Participant creation and addition.
* Helix Java APIs tested in this method are:
* ZkHelixAdmin and ZKHelixManager (mock participant/controller)
*/
@Test(dependsOnMethods = "testCreateClusters")
public void testCreateParticipants() throws Exception {
// Create two ClusterSetups using two different constructors
// Note: ZK Address here could be anything because multiZk mode is on (it will be ignored)
// HelixAdmin helixAdminZkAddr = new ZKHelixAdmin(ZK_SERVER_MAP.keySet().iterator().next());
RealmAwareZkClient.RealmAwareZkConnectionConfig zkConnectionConfig = new RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder().setRoutingDataSourceEndpoint(_msdsEndpoint + "," + ZK_PREFIX + ZK_START_PORT).setRoutingDataSourceType(RoutingDataReaderType.HTTP_ZK_FALLBACK.name()).build();
HelixAdmin helixAdminBuilder = new ZKHelixAdmin.Builder().setRealmAwareZkConnectionConfig(zkConnectionConfig).build();
_zkHelixAdmin = new ZKHelixAdmin.Builder().setRealmAwareZkConnectionConfig(zkConnectionConfig).build();
String participantNamePrefix = "Node_";
int numParticipants = 5;
// createParticipantsAndVerify(helixAdminZkAddr, numParticipants, participantNamePrefix);
createParticipantsAndVerify(helixAdminBuilder, numParticipants, participantNamePrefix);
// Create mock controller and participants for next tests
for (String cluster : CLUSTER_LIST) {
// Start a controller
// Note: in multiZK mode, ZK Addr is ignored
RealmAwareZkClient.RealmAwareZkConnectionConfig zkConnectionConfigCls = new RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder().setRoutingDataSourceEndpoint(_msdsEndpoint + "," + ZK_PREFIX + ZK_START_PORT).setRoutingDataSourceType(RoutingDataReaderType.HTTP_ZK_FALLBACK.name()).setZkRealmShardingKey("/" + cluster).build();
HelixManagerProperty.Builder propertyBuilder = new HelixManagerProperty.Builder();
HelixManagerProperty helixManagerProperty = propertyBuilder.setRealmAWareZkConnectionConfig(zkConnectionConfigCls).build();
ClusterControllerManager mockController = new ClusterControllerManager(cluster, helixManagerProperty);
mockController.syncStart();
MOCK_CONTROLLERS.put(cluster, mockController);
for (int i = 0; i < numParticipants; i++) {
// Note: in multiZK mode, ZK Addr is ignored
InstanceConfig instanceConfig = new InstanceConfig(participantNamePrefix + i);
helixAdminBuilder.addInstance(cluster, instanceConfig);
MockParticipantManager mockNode = new MockParticipantManager(cluster, participantNamePrefix + i, helixManagerProperty, 10, null);
// Register task state model for task framework testing in later methods
Map<String, TaskFactory> taskFactoryReg = new HashMap<>();
taskFactoryReg.put(MockTask.TASK_COMMAND, MockTask::new);
// Register a Task state model factory.
StateMachineEngine stateMachine = mockNode.getStateMachineEngine();
stateMachine.registerStateModelFactory("Task", new TaskStateModelFactory(mockNode, taskFactoryReg));
mockNode.syncStart();
MOCK_PARTICIPANTS.add(mockNode);
}
// Check that mockNodes are up
Assert.assertTrue(TestHelper.verify(() -> helixAdminBuilder.getInstancesInCluster(cluster).size() == numParticipants, TestHelper.WAIT_DURATION));
}
// helixAdminZkAddr.close();
helixAdminBuilder.close();
}
use of org.apache.helix.HelixManagerProperty 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.HelixManagerProperty 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.HelixManagerProperty 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);
}
Aggregations