Search in sources :

Example 1 with CloudInstanceInformation

use of org.apache.helix.api.cloud.CloudInstanceInformation in project helix by apache.

the class ParticipantManager method joinCluster.

private void joinCluster() {
    // Read cluster config and see if an instance can auto join or auto register to the cluster
    boolean autoJoin = false;
    boolean autoRegistration = false;
    // Read "allowParticipantAutoJoin" field to see if an instance can auto join to the cluster
    try {
        HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(_manager.getClusterName()).build();
        autoJoin = Boolean.parseBoolean(_configAccessor.get(scope, ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN));
        LOG.info("instance: " + _instanceName + " auto-joining " + _clusterName + " is " + autoJoin);
    } catch (Exception e) {
        LOG.info("auto join is false for cluster" + _clusterName);
    }
    // domain information in instance config
    try {
        autoRegistration = Boolean.valueOf(_helixManagerProperty.getHelixCloudProperty().getCloudEnabled());
        LOG.info("instance: " + _instanceName + " auto-registering " + _clusterName + " is " + autoRegistration);
    } catch (Exception e) {
        LOG.info("auto registration is false for cluster" + _clusterName);
    }
    InstanceConfig instanceConfig;
    if (!ZKUtil.isInstanceSetup(_zkclient, _clusterName, _instanceName, _instanceType)) {
        if (!autoJoin) {
            throw new HelixException("Initial cluster structure is not set up for instance: " + _instanceName + ", instanceType: " + _instanceType);
        }
        if (!autoRegistration) {
            LOG.info(_instanceName + " is auto-joining cluster: " + _clusterName);
            instanceConfig = HelixUtil.composeInstanceConfig(_instanceName);
        } else {
            LOG.info(_instanceName + " is auto-registering cluster: " + _clusterName);
            CloudInstanceInformation cloudInstanceInformation = getCloudInstanceInformation();
            String domain = cloudInstanceInformation.get(CloudInstanceInformation.CloudInstanceField.FAULT_DOMAIN.name()) + _instanceName;
            instanceConfig = HelixUtil.composeInstanceConfig(_instanceName);
            instanceConfig.setDomain(domain);
        }
        instanceConfig.validateTopologySettingInInstanceConfig(_configAccessor.getClusterConfig(_clusterName), _instanceName);
        _helixAdmin.addInstance(_clusterName, instanceConfig);
    } else {
        _configAccessor.getInstanceConfig(_clusterName, _instanceName).validateTopologySettingInInstanceConfig(_configAccessor.getClusterConfig(_clusterName), _instanceName);
    }
}
Also used : HelixException(org.apache.helix.HelixException) InstanceConfig(org.apache.helix.model.InstanceConfig) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) HelixConfigScope(org.apache.helix.model.HelixConfigScope) CloudInstanceInformation(org.apache.helix.api.cloud.CloudInstanceInformation) HelixException(org.apache.helix.HelixException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ZkClientException(org.apache.helix.zookeeper.exception.ZkClientException) ZkSessionMismatchedException(org.apache.helix.zookeeper.zkclient.exception.ZkSessionMismatchedException) ZkNodeExistsException(org.apache.helix.zookeeper.zkclient.exception.ZkNodeExistsException)

Example 2 with CloudInstanceInformation

use of org.apache.helix.api.cloud.CloudInstanceInformation in project helix by apache.

the class ParticipantManager method getCloudInstanceInformation.

private CloudInstanceInformation getCloudInstanceInformation() {
    String cloudInstanceInformationProcessorName = _helixManagerProperty.getHelixCloudProperty().getCloudInfoProcessorName();
    try {
        // fetch cloud instance information for the instance
        String cloudInstanceInformationProcessorClassName = CLOUD_PROCESSOR_PATH_PREFIX + _helixManagerProperty.getHelixCloudProperty().getCloudProvider().toLowerCase() + "." + cloudInstanceInformationProcessorName;
        Class processorClass = Class.forName(cloudInstanceInformationProcessorClassName);
        Constructor constructor = processorClass.getConstructor(HelixCloudProperty.class);
        CloudInstanceInformationProcessor processor = (CloudInstanceInformationProcessor) constructor.newInstance(_helixManagerProperty.getHelixCloudProperty());
        List<String> responses = processor.fetchCloudInstanceInformation();
        // parse cloud instance information for the participant
        CloudInstanceInformation cloudInstanceInformation = processor.parseCloudInstanceInformation(responses);
        return cloudInstanceInformation;
    } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) {
        throw new HelixException("Failed to create a new instance for the class: " + cloudInstanceInformationProcessorName, ex);
    }
}
Also used : Constructor(java.lang.reflect.Constructor) CloudInstanceInformation(org.apache.helix.api.cloud.CloudInstanceInformation) CloudInstanceInformationProcessor(org.apache.helix.api.cloud.CloudInstanceInformationProcessor) InvocationTargetException(java.lang.reflect.InvocationTargetException) HelixException(org.apache.helix.HelixException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HelixException (org.apache.helix.HelixException)2 CloudInstanceInformation (org.apache.helix.api.cloud.CloudInstanceInformation)2 Constructor (java.lang.reflect.Constructor)1 CloudInstanceInformationProcessor (org.apache.helix.api.cloud.CloudInstanceInformationProcessor)1 HelixConfigScope (org.apache.helix.model.HelixConfigScope)1 InstanceConfig (org.apache.helix.model.InstanceConfig)1 HelixConfigScopeBuilder (org.apache.helix.model.builder.HelixConfigScopeBuilder)1 ZkClientException (org.apache.helix.zookeeper.exception.ZkClientException)1 ZkNodeExistsException (org.apache.helix.zookeeper.zkclient.exception.ZkNodeExistsException)1 ZkSessionMismatchedException (org.apache.helix.zookeeper.zkclient.exception.ZkSessionMismatchedException)1