Skip to content

Commit

Permalink
Add support for providing default Instance Config to be used with aut…
Browse files Browse the repository at this point in the history
…o-join and auto-reg (apache#2609)

Add support for setting a default InstanceConfig through HelixManagerProperty. This will allow InstanceConfig fields be able to have defaults while also allowing users to leverage autoJoin and autoRegistration.
  • Loading branch information
zpinto authored Sep 20, 2023
1 parent 96cd0d0 commit 0922e1f
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Properties;

import org.apache.helix.model.CloudConfig;
import org.apache.helix.model.InstanceConfig;
import org.apache.helix.zookeeper.api.client.RealmAwareZkClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -35,6 +36,7 @@ public class HelixManagerProperty {
private String _version;
private long _healthReportLatency;
private HelixCloudProperty _helixCloudProperty;
private InstanceConfig.Builder _defaultInstanceConfigBuilder;
private RealmAwareZkClient.RealmAwareZkConnectionConfig _zkConnectionConfig;
private RealmAwareZkClient.RealmAwareZkClientConfig _zkClientConfig;

Expand All @@ -55,12 +57,13 @@ public HelixManagerProperty(Properties helixManagerProperties, CloudConfig cloud
}

private HelixManagerProperty(String version, long healthReportLatency,
HelixCloudProperty helixCloudProperty,
HelixCloudProperty helixCloudProperty, InstanceConfig.Builder defaultInstanceConfig,
RealmAwareZkClient.RealmAwareZkConnectionConfig zkConnectionConfig,
RealmAwareZkClient.RealmAwareZkClientConfig zkClientConfig) {
_version = version;
_healthReportLatency = healthReportLatency;
_helixCloudProperty = helixCloudProperty;
_defaultInstanceConfigBuilder = defaultInstanceConfig;
_zkConnectionConfig = zkConnectionConfig;
_zkClientConfig = zkClientConfig;
}
Expand All @@ -72,6 +75,13 @@ public HelixCloudProperty getHelixCloudProperty() {
return _helixCloudProperty;
}

public InstanceConfig.Builder getDefaultInstanceConfigBuilder() {
if (_defaultInstanceConfigBuilder == null) {
_defaultInstanceConfigBuilder = new InstanceConfig.Builder();
}
return _defaultInstanceConfigBuilder;
}

public String getVersion() {
return _version;
}
Expand All @@ -92,6 +102,7 @@ public static class Builder {
private String _version;
private long _healthReportLatency;
private HelixCloudProperty _helixCloudProperty;
private InstanceConfig.Builder _defaultInstanceConfigBuilder;
private RealmAwareZkClient.RealmAwareZkConnectionConfig _zkConnectionConfig;
private RealmAwareZkClient.RealmAwareZkClientConfig _zkClientConfig;

Expand All @@ -100,7 +111,7 @@ public Builder() {

public HelixManagerProperty build() {
return new HelixManagerProperty(_version, _healthReportLatency, _helixCloudProperty,
_zkConnectionConfig, _zkClientConfig);
_defaultInstanceConfigBuilder, _zkConnectionConfig, _zkClientConfig);
}

public Builder setVersion(String version) {
Expand All @@ -118,6 +129,12 @@ public Builder setHelixCloudProperty(HelixCloudProperty helixCloudProperty) {
return this;
}

public Builder setDefaultInstanceConfigBuilder(
InstanceConfig.Builder defaultInstanceConfigBuilder) {
_defaultInstanceConfigBuilder = defaultInstanceConfigBuilder;
return this;
}

public Builder setRealmAWareZkConnectionConfig(
RealmAwareZkClient.RealmAwareZkConnectionConfig zkConnectionConfig) {
_zkConnectionConfig = zkConnectionConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import org.apache.helix.participant.statemachine.StateModelFactory;
import org.apache.helix.task.TaskConstants;
import org.apache.helix.task.TaskUtil;
import org.apache.helix.util.HelixUtil;
import org.apache.helix.zookeeper.api.client.RealmAwareZkClient;
import org.apache.helix.zookeeper.datamodel.ZNRecord;
import org.apache.helix.zookeeper.datamodel.ZNRecordBucketizer;
Expand Down Expand Up @@ -199,8 +198,7 @@ private void joinCluster() {
// Difference between auto join and auto registration is that the latter will also populate the
// domain information in instance config
try {
autoRegistration =
Boolean.valueOf(_helixManagerProperty.getHelixCloudProperty().getCloudEnabled());
autoRegistration = _helixManagerProperty.getHelixCloudProperty().getCloudEnabled();
LOG.info("instance: " + _instanceName + " auto-registering " + _clusterName + " is "
+ autoRegistration);
} catch (Exception e) {
Expand All @@ -215,13 +213,15 @@ private void joinCluster() {
}
if (!autoRegistration) {
LOG.info(_instanceName + " is auto-joining cluster: " + _clusterName);
instanceConfig = HelixUtil.composeInstanceConfig(_instanceName);
instanceConfig =
_helixManagerProperty.getDefaultInstanceConfigBuilder().build(_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);
String domain = cloudInstanceInformation.get(
CloudInstanceInformation.CloudInstanceField.FAULT_DOMAIN.name()) + _instanceName;
instanceConfig =
_helixManagerProperty.getDefaultInstanceConfigBuilder().build(_instanceName);
instanceConfig.setDomain(domain);
}
instanceConfig
Expand Down
Loading

0 comments on commit 0922e1f

Please sign in to comment.