ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dillido...@apache.org
Subject git commit: ARGUS-34: change knox topology discovery logic in the light of kNOX-349
Date Fri, 05 Sep 2014 21:04:43 GMT
Repository: incubator-argus
Updated Branches:
  refs/heads/master 0c8da1adf -> da2ed83a0


ARGUS-34: change knox topology discovery logic in the light of kNOX-349


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

Branch: refs/heads/master
Commit: da2ed83a0b1def28ef7b5d9a892ae60d519cc490
Parents: 0c8da1a
Author: Dilli Dorai Arumugam <darumugam@hortonworks.com>
Authored: Thu Sep 4 18:15:04 2014 -0700
Committer: Dilli Dorai Arumugam <darumugam@hortonworks.com>
Committed: Fri Sep 5 10:54:48 2014 -0700

----------------------------------------------------------------------
 .../com/xasecure/knox/client/KnoxClient.java    | 88 ++------------------
 .../xasecure/knox/client/KnoxClientTest.java    | 36 ++++----
 2 files changed, 30 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/da2ed83a/lookup-client/src/main/java/com/xasecure/knox/client/KnoxClient.java
----------------------------------------------------------------------
diff --git a/lookup-client/src/main/java/com/xasecure/knox/client/KnoxClient.java b/lookup-client/src/main/java/com/xasecure/knox/client/KnoxClient.java
index d9dea71..4d35914 100644
--- a/lookup-client/src/main/java/com/xasecure/knox/client/KnoxClient.java
+++ b/lookup-client/src/main/java/com/xasecure/knox/client/KnoxClient.java
@@ -42,13 +42,9 @@ public class KnoxClient {
 	private String password;
 	
 	/*
+   Sample curl calls to Knox to discover topologies
 	 curl -ivk -u admin:admin-password https://localhost:8443/gateway/admin/api/v1/topologies
 	 curl -ivk -u admin:admin-password https://localhost:8443/gateway/admin/api/v1/topologies/admin
-	 curl -ivk -u admin:admin-password https://localhost:8443/gateway/admin/api/v1/topologies/sandbox
-	 curl -ivk -u admin:admin-password https://localhost:8443/gateway/admin/api/v1/topologies/hdp
-	 curl -ivk -u admin:admin-password https://localhost:8443/gateway/admin/api/v1/topologies/hdp1
-	 curl -ivk -u admin:admin-password https://localhost:8443/gateway/admin/api/v1/topologies/hdp2
-	 curl -ivk -u admin:admin-password https://localhost:8443/gateway/admin/api/v1/topologies/xa
 	*/
 	
 	public KnoxClient(String knoxUrl, String userName, String password) {
@@ -90,9 +86,11 @@ public class KnoxClient {
 						ObjectMapper objectMapper = new ObjectMapper();
 						
 						JsonNode rootNode = objectMapper.readTree(jsonString);
-						// JsonNode rootNode = objectMapper.readTree(getKnoxMockResponseTopologies());
-						
-						Iterator<JsonNode> elements = rootNode.getElements();
+						JsonNode topologyNode = rootNode.findValue("topology");
+						if (topologyNode == null) {
+							return topologyList;
+						}
+						Iterator<JsonNode> elements = topologyNode.getElements();
 						while (elements.hasNext()) {
 							JsonNode element = elements.next();
 							String topologyName = element.get("name").getValueAsText();
@@ -146,7 +144,6 @@ public class KnoxClient {
 				client.addFilter(new HTTPBasicAuthFilter(userName, password));
 				
 				WebResource webResource = client.resource(knoxUrl + "/" + topologyName);
-				// WebResource webResource = client.resource(knoxUrl);
 				
 				response = webResource.accept(EXPECTED_MIME_TYPE)
 					    .get(ClientResponse.class);
@@ -160,9 +157,8 @@ public class KnoxClient {
 						ObjectMapper objectMapper = new ObjectMapper();
 						
 						JsonNode rootNode = objectMapper.readTree(jsonString);
-						//JsonNode rootNode = objectMapper.readTree(getKnoxMockResponseTopology());
-						
-						JsonNode servicesNode = rootNode.get("services");
+						JsonNode topologyNode = rootNode.findValue("topology");
+						JsonNode servicesNode = topologyNode.get("services");
 						Iterator<JsonNode> services = servicesNode.getElements();
 						while (services.hasNext()) {
 							JsonNode service = services.next();
@@ -230,73 +226,5 @@ public class KnoxClient {
 		} finally {
 		}
 	}
-
-	String getKnoxMockResponseTopologies() {
-		
-		// See https://docs.google.com/a/hortonworks.com/document/d/1fSs1xAMP2IeE24TOtywRrFMl81BHG72LeWu-O6WTq78/edit
-		return 		
-				"[" +
-		 		    "{" +
-		 		    	"  \"name\": \"hdp1\", " +
-		 		    	"  \"timestamp\": 1405540981000, " +
-		 		    	" \"href\": \"https://hdp.example.com:8443/gateway/admin/api/v1/topologies/hdp1\",
 " +
-		 		    	" \"url\": \"https://hdp.example.com:8443/gateway/hdp1\" " +
-		 		    	"}, " +
-				    "{ " +
-				    	"  \"name\": \"hdp2\", " +
-				    	"  \"timestamp\": 1405540981000, " +
-				    	" \"href\": \"https://hdp.example.com:8443/gateway/admin/api/v1/topologies/hdp2\",
 " +
-				    	" \"url\": \"https://hdp.example.com:8443/gateway/hdp2\" " +
-				    	"}" + 
-				"]";
-	}
-	
-	String getKnoxMockResponseTopology() {
-		
-		// See https://docs.google.com/a/hortonworks.com/document/d/1fSs1xAMP2IeE24TOtywRrFMl81BHG72LeWu-O6WTq78/edit
-		return  
-		"{" +
-			"\"name\": \"hdp1\"," + 
-			"\"providers\": [" +
-				"{" + 
-					"\"enabled\": true, " +
-					"\"name\": null, " +
-					"\"params\": {" +
-						"\"main.ldapRealm\": \"org.apache.hadoop.gateway.shirorealm.KnoxLdapRealm\", " +
-						"\"main.ldapRealm.userDnTemplate\": \"uid={0},ou=people,dc=hadoop,dc=apache,dc=org\","
+
-         				"\"main.ldapRealm.contextFactory.url\": \"ldap://hdp.example.com:33389\"," +
-         				"\"main.ldapRealm.contextFactory.authenticationMechanism\": \"simple\"," +
-         				"\"urls./**\": \"authcBasic\"" +
-						"}, " +
-					"\"role\": \"authentication\"" +
-				"}, " +
-				 "{" +
-	                "\"enabled\": true," +
-	                "\"name\": \"Pseudo\"," +
-	               "\"params\": {" + "}," +
-	                "\"role\": \"identity-assertion\"" +
-	            "}, " +
-	            "{" +
-	                    "\"enabled\": false," +
-	                    "\"name\": null," +
-	                    "\"params\": {" + "}," +
-	                    "\"role\": null" +
-	              "}" +
-			"], " +
-			"\"services\": [" +
-				"{" +
-                 	"\"params\": {" + "}," +
-                 	"\"role\": \"KNOXADMIN\"," +
-                 	"\"url\": null" +
-                 	"}," +
-                 "{" +
-                 	"\"params\": {" + "}, " +
-                 	"\"role\": \"WEBHDFS\"," +
-                 	"\"url\": \"http://hdp.example.com:50070/webhdfs\"" +
-                 	"}" +
-                 	"]," +
-             "\"timestamp\": 1405541437000" +
-		"}";
-	}
 	
 }

http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/da2ed83a/lookup-client/src/main/java/com/xasecure/knox/client/KnoxClientTest.java
----------------------------------------------------------------------
diff --git a/lookup-client/src/main/java/com/xasecure/knox/client/KnoxClientTest.java b/lookup-client/src/main/java/com/xasecure/knox/client/KnoxClientTest.java
index cd13f29..3ba3e76 100644
--- a/lookup-client/src/main/java/com/xasecure/knox/client/KnoxClientTest.java
+++ b/lookup-client/src/main/java/com/xasecure/knox/client/KnoxClientTest.java
@@ -1,34 +1,42 @@
-package com.xasecure.knox.client;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
+package com.xasecure.knox.client;
 
 public class KnoxClientTest  {
 	
 	
 	/*
+   Sample curl calls to knox REST API to discover topologies
 	 curl -ivk -u admin:admin-password https://localhost:8443/gateway/admin/api/v1/topologies
 	 curl -ivk -u admin:admin-password https://localhost:8443/gateway/admin/api/v1/topologies/admin
-	 curl -ivk -u admin:admin-password https://localhost:8443/gateway/admin/api/v1/topologies/sandbox
-	 curl -ivk -u admin:admin-password https://localhost:8443/gateway/admin/api/v1/topologies/hdp
-	 curl -ivk -u admin:admin-password https://localhost:8443/gateway/admin/api/v1/topologies/hdp1
-	 curl -ivk -u admin:admin-password https://localhost:8443/gateway/admin/api/v1/topologies/hdp2
-	 curl -ivk -u admin:admin-password https://localhost:8443/gateway/admin/api/v1/topologies/xa
 	*/
 	
 	public static void main(String[] args) {
 		System.out.println(System.getProperty("java.class.path"));
+		System.setProperty("javax.net.ssl.trustStore", "/tmp/cacertswithknox)");
 		String[] testArgs = {
 				"https://localhost:8443/gateway/admin/api/v1/topologies",
-				"guest",
-				"guest-password"
+				"admin",
+				"admin-password"
 				};
 		KnoxClient.main(testArgs);
 	}
 	
 	
 }
-
-// http://hdp.example.com:6080/service/assets/hdfs/resources?dataSourceName=nn1&baseDirectory=%2F
-// http://hdp.example.com:6080/service/assets/knox/resources?dataSourceName=knox1&topology=%2F
-
-// com.xasecure.rest. AssetREST
-// com.xasecure.biz.AssetMgr
\ No newline at end of file


Mime
View raw message