Search in sources :

Example 1 with CloudConfig

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);
}
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 2 with CloudConfig

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();
}
Also used : HelixManager(org.apache.helix.HelixManager) ZKHelixManager(org.apache.helix.manager.zk.ZKHelixManager) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) CrushEdRebalanceStrategy(org.apache.helix.controller.rebalancer.strategy.CrushEdRebalanceStrategy) ConfigScopeBuilder(org.apache.helix.model.builder.ConfigScopeBuilder) CloudConfig(org.apache.helix.model.CloudConfig) ConfigScopeBuilder(org.apache.helix.model.builder.ConfigScopeBuilder) HelixException(org.apache.helix.HelixException) HelixDataAccessor(org.apache.helix.HelixDataAccessor) ConfigScope(org.apache.helix.model.ConfigScope) PropertyKey(org.apache.helix.PropertyKey) Test(org.testng.annotations.Test)

Example 3 with CloudConfig

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);
}
Also used : HelixException(org.apache.helix.HelixException) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) CloudConfig(org.apache.helix.model.CloudConfig) ZNRecord(org.apache.helix.zookeeper.datamodel.ZNRecord) PropertyKey(org.apache.helix.PropertyKey)

Example 4 with CloudConfig

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);
}
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 5 with CloudConfig

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);
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) InstanceConfig(org.apache.helix.model.InstanceConfig) CloudConfig(org.apache.helix.model.CloudConfig) ZNRecord(org.apache.helix.zookeeper.datamodel.ZNRecord) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) HashSet(java.util.HashSet)

Aggregations

CloudConfig (org.apache.helix.model.CloudConfig)42 Test (org.testng.annotations.Test)26 ConfigAccessor (org.apache.helix.ConfigAccessor)18 ZNRecord (org.apache.helix.zookeeper.datamodel.ZNRecord)15 ArrayList (java.util.ArrayList)14 Builder (org.apache.helix.PropertyKey.Builder)10 IOException (java.io.IOException)8 PropertyPathBuilder (org.apache.helix.PropertyPathBuilder)8 HashMap (java.util.HashMap)7 HelixConfigScopeBuilder (org.apache.helix.model.builder.HelixConfigScopeBuilder)7 RealmAwareZkClient (org.apache.helix.zookeeper.api.client.RealmAwareZkClient)7 HelixException (org.apache.helix.HelixException)6 HelixAdmin (org.apache.helix.HelixAdmin)5 ResponseMetered (com.codahale.metrics.annotation.ResponseMetered)4 Timed (com.codahale.metrics.annotation.Timed)4 Properties (java.util.Properties)4 Path (javax.ws.rs.Path)4 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)4 InstanceConfig (org.apache.helix.model.InstanceConfig)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4