RANGER-592: Troubleshoot Knox Connection issue
gson jar file was missing in the package


Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/6fc2c0ac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/6fc2c0ac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/6fc2c0ac

Branch: refs/heads/tag-policy
Commit: 6fc2c0ace63ae1a1a93d30583192ab43742b40a2
Parents: 6d79e1c
Author: Don Bosco Durai <[email protected]>
Authored: Thu Sep 10 16:07:30 2015 -0700
Committer: Don Bosco Durai <[email protected]>
Committed: Sat Sep 12 00:42:57 2015 -0700

----------------------------------------------------------------------
 .../client/RangerAdminJersey2RESTClient.java    | 66 ++++++++++----------
 src/main/assembly/knox-agent.xml                |  1 +
 2 files changed, 35 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/6fc2c0ac/knox-agent/src/main/java/org/apache/ranger/admin/client/RangerAdminJersey2RESTClient.java
----------------------------------------------------------------------
diff --git 
a/knox-agent/src/main/java/org/apache/ranger/admin/client/RangerAdminJersey2RESTClient.java
 
b/knox-agent/src/main/java/org/apache/ranger/admin/client/RangerAdminJersey2RESTClient.java
index 7fc33f9..a8020a5 100644
--- 
a/knox-agent/src/main/java/org/apache/ranger/admin/client/RangerAdminJersey2RESTClient.java
+++ 
b/knox-agent/src/main/java/org/apache/ranger/admin/client/RangerAdminJersey2RESTClient.java
@@ -73,9 +73,7 @@ public class RangerAdminJersey2RESTClient implements 
RangerAdminClient {
                _sslConfigFileName = 
_utils.getSsslConfigFileName(configPropertyPrefix);
                _isSSL = _utils.isSsl(_baseUrl);
                
-               if (LOG.isDebugEnabled()) {
-                       LOG.debug(String.format("Base URL[%s], SSL Congig 
filename[%s]", _baseUrl, _sslConfigFileName));
-               }
+               LOG.info("Init params: " + String.format("Base URL[%s], SSL 
Congig filename[%s], ServiceName=[%s]", _baseUrl, _sslConfigFileName, 
_serviceName));
                
                _client = getClient();
 
@@ -89,48 +87,52 @@ public class RangerAdminJersey2RESTClient implements 
RangerAdminClient {
                if(LOG.isDebugEnabled()) {
                        LOG.debug("==> 
RangerAdminJersey2RESTClient.getServicePoliciesIfUpdated(" + lastKnownVersion + 
")");
                }
-
                ServicePolicies servicePolicies = null;
                String url = _utils.getUrlForPolicyUpdate(_baseUrl, 
_serviceName);
-               Response response = _client.target(url)
+               try {
+                       Response response = _client.target(url)
                                
.queryParam(RangerRESTUtils.REST_PARAM_LAST_KNOWN_POLICY_VERSION, 
Long.toString(lastKnownVersion))
                                
.queryParam(RangerRESTUtils.REST_PARAM_PLUGIN_ID, _pluginId)
                                .request(MediaType.APPLICATION_JSON_TYPE)
                                .get();
-               int httpResponseCode = response == null ? -1 : 
response.getStatus();
-               String body = null;
+                       int httpResponseCode = response == null ? -1 : 
response.getStatus();
+                       String body = null;
 
-               switch (httpResponseCode) {
-               case 200:
-                       body = response.readEntity(String.class);
+                       switch (httpResponseCode) {
+                       case 200:
+                               body = response.readEntity(String.class);
                        
-                       if (LOG.isDebugEnabled()) {
-                               LOG.debug("Response from 200 server: " + body);
-                       }
+                               if (LOG.isDebugEnabled()) {
+                                       LOG.debug("Response from 200 server: " 
+ body);
+                               }
                        
-                       Gson gson = getGson();
-                       servicePolicies = gson.fromJson(body, 
ServicePolicies.class);
+                               Gson gson = getGson();
+                               servicePolicies = gson.fromJson(body, 
ServicePolicies.class);
                        
-                       if (LOG.isDebugEnabled()) {
-                               LOG.debug("Deserialized response to: " + 
servicePolicies);
+                               if (LOG.isDebugEnabled()) {
+                                       LOG.debug("Deserialized response to: " 
+ servicePolicies);
+                               }
+                               break;
+                       case 304:
+                               LOG.debug("Got response: 304. Ok. Returning 
null");
+                               break;
+                       case -1:
+                               LOG.warn("Unexpected: Null response from policy 
server while trying to get policies! Returning null!");
+                               break;
+                       default:
+                               body = response.readEntity(String.class);
+                               LOG.warn(String.format("Unexpected: Received 
status[%d] with body[%s] form url[%s]", httpResponseCode, body, url));
+                               break;
                        }
-                       break;
-               case 304:
-                       LOG.debug("Got response: 304. Ok. Returning null");
-                       break;
-               case -1:
-                       LOG.warn("Unexpected: Null response from policy server 
while trying to get policies! Returning null!");
-                       break;
-               default:
-                       body = response.readEntity(String.class);
-                       LOG.warn(String.format("Unexpected: Received status[%d] 
with body[%s] form url[%s]", httpResponseCode, body, url));
-                       break;
-               }
 
-               if(LOG.isDebugEnabled()) {
-                       LOG.debug("<== 
RangerAdminJersey2RESTClient.getServicePoliciesIfUpdated(" + lastKnownVersion + 
"): " + servicePolicies);
+                       if(LOG.isDebugEnabled()) {
+                               LOG.debug("<== 
RangerAdminJersey2RESTClient.getServicePoliciesIfUpdated(" + lastKnownVersion + 
"): " + servicePolicies);
+                       }
+                       return servicePolicies;
+               } catch (Exception ex) {
+                       LOG.error("Failed getting policies from server. url=" + 
url + ", pluginId=" + _pluginId + ", lastKnownVersion=" + lastKnownVersion );
+                       throw ex;
                }
-               return servicePolicies;
        }
 
        @Override

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/6fc2c0ac/src/main/assembly/knox-agent.xml
----------------------------------------------------------------------
diff --git a/src/main/assembly/knox-agent.xml b/src/main/assembly/knox-agent.xml
index 7c08270..4806343 100644
--- a/src/main/assembly/knox-agent.xml
+++ b/src/main/assembly/knox-agent.xml
@@ -35,6 +35,7 @@
                 <outputDirectory>/lib</outputDirectory>
                 <includes>
                     
<include>commons-configuration:commons-configuration</include>
+                   <include>com.google.code.gson:gson*</include>
                            
<include>org.apache.httpcomponents:httpmime:jar:${httpcomponent.httpmime.version}</include>
                                
<include>org.noggit:noggit:jar:${noggit.version}</include>
                                
<include>com.google.protobuf:protobuf-java:jar:${protobuf-java.version}</include>

Reply via email to