This is an automated email from the ASF dual-hosted git repository.

dineshkumar pushed a commit to branch ranger-2.6
in repository https://gitbox.apache.org/repos/asf/ranger.git

commit 21269596751126a7160de382642117b3b8b9eaac
Author: Rakesh Gupta <[email protected]>
AuthorDate: Mon Jan 13 19:36:55 2025 +0530

    RANGER-4879: Config Update for HA Implementation needed for 
ranger-common-ha module
    
    Signed-off-by: Dineshkumar Yadav <[email protected]>
---
 .../ranger/ha/ActiveInstanceElectorService.java    | 22 +++++++++++++++++++++-
 .../java/org/apache/ranger/ha/HAConfiguration.java |  4 ++--
 .../ranger/ha/RangerServiceServerIdSelector.java   | 12 +++++-------
 .../src/test/resources/ranger-tagsync-site.xml     |  4 ++--
 tagsync/src/main/resources/ranger-tagsync-site.xml |  4 ++--
 5 files changed, 32 insertions(+), 14 deletions(-)

diff --git 
a/ranger-common-ha/src/main/java/org/apache/ranger/ha/ActiveInstanceElectorService.java
 
b/ranger-common-ha/src/main/java/org/apache/ranger/ha/ActiveInstanceElectorService.java
index 359fcbfff..66c3f91c2 100644
--- 
a/ranger-common-ha/src/main/java/org/apache/ranger/ha/ActiveInstanceElectorService.java
+++ 
b/ranger-common-ha/src/main/java/org/apache/ranger/ha/ActiveInstanceElectorService.java
@@ -20,6 +20,7 @@
 package org.apache.ranger.ha;
 
 import java.io.IOException;
+import java.time.Instant;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
@@ -45,6 +46,9 @@ public class ActiveInstanceElectorService implements 
HARangerService, LeaderLatc
        private LeaderLatch leaderLatch;
        private String serverId;
 
+       private static Long transitionCount   = 0L;
+       private static Long lastTranstionTime = 0L;
+
        /**
         * Create a new instance of {@link ActiveInstanceElectorService}
         *
@@ -139,9 +143,11 @@ public class ActiveInstanceElectorService implements 
HARangerService, LeaderLatc
                        }
                        activeInstanceState.update(serverId);
                        serviceState.setActive();
+                       transitionCount++;
+                       setLastTranstionTime(Instant.now().toEpochMilli());
                } catch (Exception e) {
                        LOG.error("Got exception while activating", e);
-                       notLeader();
+                       serviceState.setPassive();
                        rejoinElection();
                }
        }
@@ -182,6 +188,20 @@ public class ActiveInstanceElectorService implements 
HARangerService, LeaderLatc
                }
 
                serviceState.setPassive();
+               transitionCount++;
+               setLastTranstionTime(Instant.now().toEpochMilli());
+       }
+
+       public static Long getTransitionCount() {
+               return transitionCount;
+       }
+
+       public static Long getLastTranstionTime() {
+               return lastTranstionTime;
+       }
+
+       public static void setLastTranstionTime(Long lastTranstionTime) {
+               ActiveInstanceElectorService.lastTranstionTime = 
lastTranstionTime;
        }
 
 }
diff --git 
a/ranger-common-ha/src/main/java/org/apache/ranger/ha/HAConfiguration.java 
b/ranger-common-ha/src/main/java/org/apache/ranger/ha/HAConfiguration.java
index ded5a2ded..4a099de7e 100644
--- a/ranger-common-ha/src/main/java/org/apache/ranger/ha/HAConfiguration.java
+++ b/ranger-common-ha/src/main/java/org/apache/ranger/ha/HAConfiguration.java
@@ -53,8 +53,8 @@ public class HAConfiguration {
        private static final int DEFAULT_ZOOKEEPER_SESSION_TIMEOUT_MILLIS = 
20000;
        private static final String HA_ZOOKEEPER_ACL                            
        = RANGER_SERVER_HA_PREFIX + ZOOKEEPER_PREFIX + "acl";
        private static final String HA_ZOOKEEPER_AUTH                           
        = RANGER_SERVER_HA_PREFIX + ZOOKEEPER_PREFIX + "auth";
-       public static final String RANGER_HA_SERVICE_HTTPS_PORT                 
= RANGER_SERVER_HA_PREFIX + "https.port";
-       public static final String RANGER_HA_SERVICE_HTTP_PORT                  
= RANGER_SERVER_HA_PREFIX + "http.port";
+       public static final String RANGER_HA_SERVICE_HTTPS_PORT                 
= ".service.https.port";
+       public static final String RANGER_HA_SERVICE_HTTP_PORT                  
= ".service.http.port";
        public static final String RANGER_SERVICE_SSL_ENABLED                   
= RANGER_SERVER_HA_PREFIX + "ssl.enabled";
 
        /**
diff --git 
a/ranger-common-ha/src/main/java/org/apache/ranger/ha/RangerServiceServerIdSelector.java
 
b/ranger-common-ha/src/main/java/org/apache/ranger/ha/RangerServiceServerIdSelector.java
index 5be954e0e..da6147da9 100644
--- 
a/ranger-common-ha/src/main/java/org/apache/ranger/ha/RangerServiceServerIdSelector.java
+++ 
b/ranger-common-ha/src/main/java/org/apache/ranger/ha/RangerServiceServerIdSelector.java
@@ -48,16 +48,14 @@ public class RangerServiceServerIdSelector {
                // ids are already trimmed by this method
                String[] ids              = 
HAConfiguration.getStringsConfig(configuration,HAConfiguration.RANGER_SERVER_HA_IDS,
 null);
                String   matchingServerId = null;
-               String   appPortStr       = null;
-               int      appPort          = 1; // keeping this as default > 0 
for tagSync
                boolean  isSecure         = 
HAConfiguration.getBooleanConfig(configuration, 
HAConfiguration.RANGER_SERVICE_SSL_ENABLED, false);
 
-               appPortStr = isSecure ? 
HAConfiguration.getStringConfig(configuration, 
HAConfiguration.RANGER_HA_SERVICE_HTTPS_PORT, null) :
-                       HAConfiguration.getStringConfig(configuration, 
HAConfiguration.RANGER_HA_SERVICE_HTTP_PORT, null);
+               int appPort = isSecure ? 
HAConfiguration.getIntConfig(configuration, 
HAConfiguration.RANGER_HA_SERVICE_HTTPS_PORT, -1) : 
HAConfiguration.getIntConfig(configuration, 
HAConfiguration.RANGER_HA_SERVICE_HTTP_PORT, -1);
 
-               if (StringUtils.isNotBlank(appPortStr)) {
-                       appPort = Integer.parseInt(appPortStr);
+               if (appPort < 1) {
+                       LOG.warn("Service HTTP/HTTPS port is not configured 
correctly. Please configure properties {}{} and {}{}", 
HAConfiguration.getPrefix(configuration), 
HAConfiguration.RANGER_HA_SERVICE_HTTPS_PORT, 
HAConfiguration.getPrefix(configuration), 
HAConfiguration.RANGER_HA_SERVICE_HTTP_PORT);
                }
+
                for (String id : ids) {
                        String hostPort = 
HAConfiguration.getStringConfig(configuration, 
HAConfiguration.RANGER_SERVER_HA_ADDRESS_PREFIX + id, null);
                        LOG.info("==> 
RangerServiceServerIdSelector.selectServerId() id["+id + "] 
hostPort["+hostPort+"]");
@@ -70,7 +68,7 @@ public class RangerServiceServerIdSelector {
                                        LOG.error("Exception while trying to 
get socket address for {}"+ hostPort, e);
                                        continue;
                                }
-                               //LOG.info("==> 
RangerServiceServerIdSelector.selectServerId() 
socketAddress.isUnresolved["+socketAddress.isUnresolved() + "] 
socketAddress.getPort["+socketAddress.getPort()+"] 
isLocalAddress["+NetUtils.isLocalAddress(socketAddress.getAddress())+"]");
+
                                if (!socketAddress.isUnresolved() && 
NetUtils.isLocalAddress(socketAddress.getAddress())
                                                && appPort == 
socketAddress.getPort()) {
                                        LOG.info("Found matched server id {} 
with host port: {}",id , hostPort);
diff --git a/ranger-common-ha/src/test/resources/ranger-tagsync-site.xml 
b/ranger-common-ha/src/test/resources/ranger-tagsync-site.xml
index d37d7e43f..5404b9ceb 100644
--- a/ranger-common-ha/src/test/resources/ranger-tagsync-site.xml
+++ b/ranger-common-ha/src/test/resources/ranger-tagsync-site.xml
@@ -189,11 +189,11 @@
                <value></value>
        </property>
        <property>
-               <name>ranger-tagsync.server.ha.http.port</name>
+               <name>ranger-tagsync.service.http.port</name>
                <value></value>
        </property>
        <property>
-               <name>ranger-tagsync.server.ha.https.port</name>
+               <name>ranger-tagsync.service.https.port</name>
                <value></value>
        </property>
 </configuration>
diff --git a/tagsync/src/main/resources/ranger-tagsync-site.xml 
b/tagsync/src/main/resources/ranger-tagsync-site.xml
index 6bda5f4ab..30666f396 100644
--- a/tagsync/src/main/resources/ranger-tagsync-site.xml
+++ b/tagsync/src/main/resources/ranger-tagsync-site.xml
@@ -185,11 +185,11 @@
                <value></value>
        </property>
        <property>
-               <name>ranger-tagsync.server.ha.http.port</name>
+               <name>ranger-tagsync.service.http.port</name>
                <value></value>
        </property>
        <property>
-               <name>ranger-tagsync.server.ha.https.port</name>
+               <name>ranger-tagsync.service.https.port</name>
                <value></value>
        </property>
 </configuration>

Reply via email to