This is an automated email from the ASF dual-hosted git repository. pradeep pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ranger.git
commit 3171f5b38908e18d7ac40d27a1737e3d41370d9a Author: Lars Francke <[email protected]> AuthorDate: Tue Jan 21 11:34:18 2020 +0100 RANGER-2707 ranger.usersync.enabled not respected on initial ugsync startup Signed-off-by: Pradeep <[email protected]> --- .../apache/ranger/usergroupsync/UserGroupSync.java | 53 +++++++++------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/ugsync/src/main/java/org/apache/ranger/usergroupsync/UserGroupSync.java b/ugsync/src/main/java/org/apache/ranger/usergroupsync/UserGroupSync.java index 2befe33..6429055 100644 --- a/ugsync/src/main/java/org/apache/ranger/usergroupsync/UserGroupSync.java +++ b/ugsync/src/main/java/org/apache/ranger/usergroupsync/UserGroupSync.java @@ -17,34 +17,31 @@ * under the License. */ - package org.apache.ranger.usergroupsync; - +package org.apache.ranger.usergroupsync; import org.apache.log4j.Logger; import org.apache.ranger.unixusersync.config.UserGroupSyncConfig; public class UserGroupSync implements Runnable { - - private static final Logger LOG = Logger.getLogger(UserGroupSync.class); - - private boolean shutdownFlag = false; - private UserGroupSink ugSink = null; - private UserGroupSource ugSource = null; + private static final Logger LOG = Logger.getLogger(UserGroupSync.class); + private UserGroupSink ugSink; + private UserGroupSource ugSource; public static void main(String[] args) { UserGroupSync userGroupSync = new UserGroupSync(); userGroupSync.run(); } + @Override public void run() { try { long sleepTimeBetweenCycleInMillis = UserGroupSyncConfig.getInstance().getSleepTimeInMillisBetweenCycle(); - boolean initDone = false; + boolean initPending = true; - while (! initDone ) { + while (initPending) { try { ugSink = UserGroupSyncConfig.getInstance().getUserGroupSink(); LOG.info("initializing sink: " + ugSink.getClass().getName()); @@ -55,14 +52,13 @@ public class UserGroupSync implements Runnable { ugSource.init(); LOG.info("Begin: initial load of user/group from source==>sink"); - ugSource.updateSink(ugSink); + syncUserGroup(); LOG.info("End: initial load of user/group from source==>sink"); - initDone = true; + initPending = false; LOG.info("Done initializing user/group source and sink"); - } - catch(Throwable t) { + } catch (Throwable t) { LOG.error("Failed to initialize UserGroup source/sink. Will retry after " + sleepTimeBetweenCycleInMillis + " milliseconds. Error details: ", t); try { LOG.debug("Sleeping for [" + sleepTimeBetweenCycleInMillis + "] milliSeconds"); @@ -73,7 +69,7 @@ public class UserGroupSync implements Runnable { } } - while (! shutdownFlag ) { + while (true) { try { LOG.debug("Sleeping for [" + sleepTimeBetweenCycleInMillis + "] milliSeconds"); Thread.sleep(sleepTimeBetweenCycleInMillis); @@ -82,35 +78,28 @@ public class UserGroupSync implements Runnable { } try { + LOG.info("Begin: update user/group from source==>sink"); syncUserGroup(); - } - catch(Throwable t) { + LOG.info("End: update user/group from source==>sink"); + } catch (Throwable t) { LOG.error("Failed to synchronize UserGroup information. Error details: ", t); } } - - } - catch(Throwable t) { + + } catch (Throwable t) { LOG.error("UserGroupSync thread got an error", t); - } - finally { + } finally { LOG.info("Shutting down the UserGroupSync thread"); } } - + private void syncUserGroup() throws Throwable { UserGroupSyncConfig config = UserGroupSyncConfig.getInstance(); - try{ - if (config.isUserSyncEnabled()) { - LOG.info("Begin: update user/group from source==>sink"); - ugSource.updateSink(ugSink); - LOG.info("End: update user/group from source==>sink"); - } - }catch(Throwable t){ - LOG.error("Failed to sync user/group : ", t); + if (config.isUserSyncEnabled()) { + ugSource.updateSink(ugSink); } - + } }
