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

madhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git

commit 785c56348ee63d7a5a423c3dbab371e766c8395c
Author: Anand Nadar <nadaranand...@gmail.com>
AuthorDate: Wed Apr 3 16:33:36 2024 -0700

    RANGER-4763: updated Test Connection error message when this is not 
implemented for a service-type
    
    Signed-off-by: Madhan Neethiraj <mad...@apache.org>
---
 .../ranger/plugin/service/RangerDefaultService.java       | 12 +++++++-----
 .../src/main/java/org/apache/ranger/biz/ServiceMgr.java   | 15 ++++++++++-----
 .../main/java/org/apache/ranger/common/TimedExecutor.java | 10 ++++++++--
 3 files changed, 25 insertions(+), 12 deletions(-)

diff --git 
a/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerDefaultService.java
 
b/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerDefaultService.java
old mode 100644
new mode 100755
index c89b55757..60f7a09df
--- 
a/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerDefaultService.java
+++ 
b/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerDefaultService.java
@@ -23,19 +23,21 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.collections.ListUtils;
-import org.apache.commons.collections.MapUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class RangerDefaultService extends RangerBaseService {
        private static final Logger LOG = 
LoggerFactory.getLogger(RangerDefaultService.class);
-               
+
+       public static final String ERROR_MSG_VALIDATE_CONFIG_NOT_IMPLEMENTED = 
"Configuration validation is not implemented";
+
        @Override
        public  Map<String, Object> validateConfig() throws Exception {
-               if(LOG.isDebugEnabled()) {
-                       LOG.debug("RangerDefaultService.validateConfig Service: 
(" + serviceName + " ), returning empty map");
+               if (LOG.isDebugEnabled()) {
+                       LOG.debug("RangerDefaultService.validateConfig Service: 
(" + serviceName + " ), " + ERROR_MSG_VALIDATE_CONFIG_NOT_IMPLEMENTED);
                }
-               return MapUtils.EMPTY_MAP;
+
+               throw new Exception(ERROR_MSG_VALIDATE_CONFIG_NOT_IMPLEMENTED);
        }
        
        @Override
diff --git a/security-admin/src/main/java/org/apache/ranger/biz/ServiceMgr.java 
b/security-admin/src/main/java/org/apache/ranger/biz/ServiceMgr.java
old mode 100644
new mode 100755
index 7e071ba0e..b9d51602e
--- a/security-admin/src/main/java/org/apache/ranger/biz/ServiceMgr.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/ServiceMgr.java
@@ -46,6 +46,7 @@ import org.apache.ranger.plugin.model.RangerSecurityZone;
 import org.apache.ranger.plugin.model.RangerService;
 import org.apache.ranger.plugin.model.RangerServiceDef;
 import org.apache.ranger.plugin.service.RangerBaseService;
+import org.apache.ranger.plugin.service.RangerDefaultService;
 import org.apache.ranger.plugin.service.ResourceLookupContext;
 import org.apache.ranger.plugin.store.EmbeddedServiceDefsUtil;
 import org.apache.ranger.plugin.store.ServiceStore;
@@ -199,13 +200,17 @@ public class ServiceMgr {
 
                                ret = generateResponseForTestConn(responseData, 
"");
                        } catch (Exception e) {
-                               String msg = "Unable to connect repository with 
given config for " + svc.getServiceName();
-                                               
-                               HashMap<String, Object> respData = new 
HashMap<String, Object>();
-                               if (e instanceof HadoopException) {
-                                       respData = ((HadoopException) 
e).getResponseData();
+                               Map<String, Object> respData = (e instanceof 
HadoopException) ? ((HadoopException) e).getResponseData() : new HashMap<>();
+                               String              msg;
+
+                               if (StringUtils.contains(e.getMessage(), 
RangerDefaultService.ERROR_MSG_VALIDATE_CONFIG_NOT_IMPLEMENTED)) {
+                                       msg = 
RangerDefaultService.ERROR_MSG_VALIDATE_CONFIG_NOT_IMPLEMENTED + " for " + 
svc.getServiceType();
+                               } else {
+                                       msg = "Unable to connect repository 
with given config for " + svc.getServiceName();
                                }
+
                                ret = generateResponseForTestConn(respData, 
msg);
+
                                LOG.error("==> ServiceMgr.validateConfig 
Error:" + e);
                        }
                }
diff --git 
a/security-admin/src/main/java/org/apache/ranger/common/TimedExecutor.java 
b/security-admin/src/main/java/org/apache/ranger/common/TimedExecutor.java
old mode 100644
new mode 100755
index d6fc01176..b5c47d3e9
--- a/security-admin/src/main/java/org/apache/ranger/common/TimedExecutor.java
+++ b/security-admin/src/main/java/org/apache/ranger/common/TimedExecutor.java
@@ -35,7 +35,9 @@ import java.util.concurrent.TimeoutException;
 
 import javax.annotation.PostConstruct;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.ranger.plugin.client.HadoopException;
+import org.apache.ranger.plugin.service.RangerDefaultService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -93,8 +95,12 @@ public class TimedExecutor {
                                if (LOG.isDebugEnabled()) {
                                        LOG.debug(String.format("TimedExecutor: 
Caught exception[%s] for callable[%s]: detail[%s].  Re-throwing...", 
e.getClass().getName(), callable, e.getMessage()));
                                }
-                               HadoopException he = generateHadoopException(e);
-                               throw he;
+
+                               if (StringUtils.contains(e.getMessage(), 
RangerDefaultService.ERROR_MSG_VALIDATE_CONFIG_NOT_IMPLEMENTED)) {
+                                       throw e;
+                               } else {
+                                       throw generateHadoopException(e);
+                               }
                        } catch (TimeoutException e) {
                                if (LOG.isDebugEnabled()) {
                                        LOG.debug(String.format("TimedExecutor: 
Timed out waiting for callable[%s] to finish.  Cancelling the task.", 
callable));

Reply via email to