Search in sources :

Example 1 with HelixManagerProperty

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();
}
Also used : StateMachineEngine(org.apache.helix.participant.StateMachineEngine) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) HashMap(java.util.HashMap) MockTask(org.apache.helix.integration.task.MockTask) HelixAdmin(org.apache.helix.HelixAdmin) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) InstanceConfig(org.apache.helix.model.InstanceConfig) TaskFactory(org.apache.helix.task.TaskFactory) HelixManagerProperty(org.apache.helix.HelixManagerProperty) TaskStateModelFactory(org.apache.helix.task.TaskStateModelFactory) RealmAwareZkClient(org.apache.helix.zookeeper.api.client.RealmAwareZkClient) Test(org.testng.annotations.Test)

Example 2 with HelixManagerProperty

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);
}
Also used : CloudConfig(org.apache.helix.model.CloudConfig) ArrayList(java.util.ArrayList) ZKHelixManager(org.apache.helix.manager.zk.ZKHelixManager) HelixCloudProperty(org.apache.helix.HelixCloudProperty) Properties(java.util.Properties) HelixManagerStateListener(org.apache.helix.manager.zk.HelixManagerStateListener) InstanceConfig(org.apache.helix.model.InstanceConfig) HelixManagerProperty(org.apache.helix.HelixManagerProperty) InstanceType(org.apache.helix.InstanceType) RealmAwareZkClient(org.apache.helix.zookeeper.api.client.RealmAwareZkClient) Test(org.testng.annotations.Test)

Example 3 with HelixManagerProperty

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);
}
Also used : CloudConfig(org.apache.helix.model.CloudConfig) HelixCloudProperty(org.apache.helix.HelixCloudProperty) HelixManagerProperty(org.apache.helix.HelixManagerProperty) ZNRecord(org.apache.helix.zookeeper.datamodel.ZNRecord) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with HelixManagerProperty

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);
}
Also used : CloudConfig(org.apache.helix.model.CloudConfig) ArrayList(java.util.ArrayList) ZKHelixManager(org.apache.helix.manager.zk.ZKHelixManager) HelixCloudProperty(org.apache.helix.HelixCloudProperty) Properties(java.util.Properties) HelixManagerStateListener(org.apache.helix.manager.zk.HelixManagerStateListener) InstanceConfig(org.apache.helix.model.InstanceConfig) HelixManagerProperty(org.apache.helix.HelixManagerProperty) InstanceType(org.apache.helix.InstanceType) RealmAwareZkClient(org.apache.helix.zookeeper.api.client.RealmAwareZkClient) Test(org.testng.annotations.Test)

Aggregations

HelixManagerProperty (org.apache.helix.HelixManagerProperty)4 HelixCloudProperty (org.apache.helix.HelixCloudProperty)3 CloudConfig (org.apache.helix.model.CloudConfig)3 InstanceConfig (org.apache.helix.model.InstanceConfig)3 RealmAwareZkClient (org.apache.helix.zookeeper.api.client.RealmAwareZkClient)3 Test (org.testng.annotations.Test)3 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 InstanceType (org.apache.helix.InstanceType)2 HelixManagerStateListener (org.apache.helix.manager.zk.HelixManagerStateListener)2 ZKHelixManager (org.apache.helix.manager.zk.ZKHelixManager)2 HashMap (java.util.HashMap)1 HelixAdmin (org.apache.helix.HelixAdmin)1 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)1 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)1 MockTask (org.apache.helix.integration.task.MockTask)1 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)1 StateMachineEngine (org.apache.helix.participant.StateMachineEngine)1 TaskFactory (org.apache.helix.task.TaskFactory)1 TaskStateModelFactory (org.apache.helix.task.TaskStateModelFactory)1