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);
}
}
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);
}
}
Aggregations