dasahcc commented on a change in pull request #695: Modify participant manager
to add cluster auto registration logic
URL: https://github.com/apache/helix/pull/695#discussion_r372714094
##########
File path:
helix-core/src/main/java/org/apache/helix/manager/zk/ParticipantManager.java
##########
@@ -132,42 +139,102 @@ public void handleNewSession() throws Exception {
}
private void joinCluster() {
- // Read cluster config and see if instance can auto join the cluster
+ // Read cluster config and see if an instance can auto join or auto
register to the cluster
boolean autoJoin = false;
+ boolean autoRegistration = false;
try {
- HelixConfigScope scope =
- new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(
- _manager.getClusterName()).build();
- autoJoin =
- Boolean.parseBoolean(_configAccessor.get(scope,
- ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN));
+ 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) {
// autoJoin is false
}
+ // Read cloud config and see if an instance can auto register to the
cluster
+ try {
+ autoRegistration =
+
Boolean.valueOf(_helixManagerProperty.getHelixCloudProperty().getCloudEnabled());
+ LOG.info("instance: " + _instanceName + " auto-register " + _clusterName
+ " is "
+ + autoRegistration);
+ } catch (Exception e) {
+ // autoRegistration is false
+ }
+
if (!ZKUtil.isInstanceSetup(_zkclient, _clusterName, _instanceName,
_instanceType)) {
if (!autoJoin) {
throw new HelixException("Initial cluster structure is not set up for
instance: "
+ _instanceName + ", instanceType: " + _instanceType);
} else {
- LOG.info(_instanceName + " is auto-joining cluster: " + _clusterName);
- InstanceConfig instanceConfig = new InstanceConfig(_instanceName);
- String hostName = _instanceName;
- String port = "";
- int lastPos = _instanceName.lastIndexOf("_");
- if (lastPos > 0) {
- hostName = _instanceName.substring(0, lastPos);
- port = _instanceName.substring(lastPos + 1);
+ if (!autoRegistration) {
+ LOG.info(_instanceName + " is auto-joining cluster: " +
_clusterName);
+ addInstanceConfig(null);
+ } else {
+ 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);
+ String domain = cloudInstanceInformation
+
.get(CloudInstanceInformation.CloudInstanceField.FAULT_DOMAIN.name());
+ String cloudIdInRemote = cloudInstanceInformation
+
.get(CloudInstanceInformation.CloudInstanceField.INSTANCE_SET_NAME.name());
+ String cloudIdInConfig =
_configAccessor.getCloudConfig(_clusterName).getCloudID();
+
+ // validate that the instance is auto registering to the correct
cluster
+ if (!cloudIdInRemote.equals(cloudIdInConfig)) {
+ throw new IllegalArgumentException(String.format(
+ "cloudId in config: %s is not consistent with cloudId from
remote: %s. The instance is auto registering to a wrong cluster.",
+ cloudIdInConfig, cloudIdInRemote));
+ }
+ addInstanceConfig(domain);
+ } catch (ClassNotFoundException ex) {
+ throw new HelixException(
+ "Passed cloud instance information processor class is not
found: "
+ + cloudInstanceInformationProcessorName, ex);
+ } catch (NoSuchMethodException ex) {
+ throw new HelixException("Failed to get the constructor for the
class: "
+ + cloudInstanceInformationProcessorName, ex);
+ } catch (InstantiationException | IllegalAccessException |
InvocationTargetException ex) {
+ throw new HelixException("Failed to create a new instance for the
class: "
Review comment:
Any reason to differentiate these exceptions? They looked like instantiation
failure.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]