Skip to content

Commit

Permalink
RANGER-4307: Allow users customize the time interval (#269)
Browse files Browse the repository at this point in the history
Modified the UserGroupSyncConfig.java file and added the configuration of user forced custom time synchronization. If enabled, LDAP users can be synchronized according to the user defined time.
  • Loading branch information
zhutong6688 committed Sep 13, 2024
1 parent e671f86 commit 854a113
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public class UserGroupSyncConfig {

private static final String UGSYNC_SLEEP_TIME_IN_MILLIS_BETWEEN_CYCLE_PARAM = "ranger.usersync.sleeptimeinmillisbetweensynccycle";

private static final String UGSYNC_SLEEP_LDAP_FORCE_TIME_IN_MILLIS_BETWEEN_CYCLE_PARAM_ENABLED = "ranger.usersync.ldap.force.sleeptimeinmillisbetweensynccycle.enabled";

private static final long UGSYNC_SLEEP_TIME_IN_MILLIS_BETWEEN_CYCLE_MIN_VALUE = 60000L;

private static final long UGSYNC_SLEEP_TIME_IN_MILLIS_BETWEEN_CYCLE_UNIX_DEFAULT_VALUE = 60000L;
Expand Down Expand Up @@ -517,6 +519,7 @@ public long getInitSleepTimeInMillisBetweenCycle() throws Throwable{
}
public long getSleepTimeInMillisBetweenCycle() throws Throwable {
String val = prop.getProperty(UGSYNC_SLEEP_TIME_IN_MILLIS_BETWEEN_CYCLE_PARAM);
boolean is_ldap_force = Boolean.parseBoolean(prop.getProperty(UGSYNC_SLEEP_LDAP_FORCE_TIME_IN_MILLIS_BETWEEN_CYCLE_PARAM_ENABLED));
String className = getUserGroupSource().getClass().getName();
if (val == null) {
if (LGSYNC_SOURCE_CLASS.equals(className)) {
Expand All @@ -529,7 +532,12 @@ public long getSleepTimeInMillisBetweenCycle() throws Throwable {
long ret = Long.parseLong(val);
long min_interval;
if (LGSYNC_SOURCE_CLASS.equals(className)) {
min_interval = UGSYNC_SLEEP_TIME_IN_MILLIS_BETWEEN_CYCLE_LDAP_DEFAULT_VALUE;
if (is_ldap_force && ret < UGSYNC_SLEEP_TIME_IN_MILLIS_BETWEEN_CYCLE_LDAP_DEFAULT_VALUE) {
min_interval = ret;
LOG.info("If you force the synchronization time of ldap users to be less than the default of 3600s, this setting [" + min_interval + "] millisec will take effect.");
} else {
min_interval = UGSYNC_SLEEP_TIME_IN_MILLIS_BETWEEN_CYCLE_LDAP_DEFAULT_VALUE;
}
}else if(UGSYNC_SOURCE_CLASS.equals(className)){
min_interval = UGSYNC_SLEEP_TIME_IN_MILLIS_BETWEEN_CYCLE_UNIX_DEFAULT_VALUE;
} else {
Expand Down

0 comments on commit 854a113

Please sign in to comment.