knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmc...@apache.org
Subject knox git commit: KNOX-617 - Add the use of CredentialCollectors to Samples
Date Fri, 30 Oct 2015 19:50:52 GMT
Repository: knox
Updated Branches:
  refs/heads/master 8005afe13 -> 1755fdfa0


KNOX-617 - Add the use of CredentialCollectors to Samples

Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/1755fdfa
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/1755fdfa
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/1755fdfa

Branch: refs/heads/master
Commit: 1755fdfa0fbdb9a016383bfd07905489c89a9319
Parents: 8005afe
Author: Larry McCay <lmccay@hortonworks.com>
Authored: Fri Oct 30 15:50:44 2015 -0400
Committer: Larry McCay <lmccay@hortonworks.com>
Committed: Fri Oct 30 15:50:44 2015 -0400

----------------------------------------------------------------------
 gateway-release/home/samples/ExampleHBase.groovy | 14 +++++++++++---
 .../home/samples/ExampleOozieWorkflow.groovy     | 19 +++++++++++++++----
 .../home/samples/ExampleWebHCatJob.groovy        | 16 ++++++++++++----
 .../home/samples/ExampleWebHCatQueue.groovy      | 13 ++++++++++---
 .../home/samples/ExampleWebHdfsLs.groovy         | 15 ++++++++++++---
 .../home/samples/ExampleWebHdfsPutGet.groovy     | 16 ++++++++++++----
 gateway-release/home/samples/SampleScript.groovy | 13 ++++++++++---
 .../HiveJDBCSample.groovy                        | 13 ++++++++++---
 .../groovy/jdbc/sandbox/HiveJDBCSample.groovy    | 16 +++++++++++++---
 .../sandbox-with-knox-inside/HiveJDBCSample.java | 12 ++++++++++--
 .../hive/java/jdbc/sandbox/HiveJDBCSample.java   | 17 ++++++++++++++---
 11 files changed, 129 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/1755fdfa/gateway-release/home/samples/ExampleHBase.groovy
----------------------------------------------------------------------
diff --git a/gateway-release/home/samples/ExampleHBase.groovy b/gateway-release/home/samples/ExampleHBase.groovy
index 0358e27..7d20aca 100644
--- a/gateway-release/home/samples/ExampleHBase.groovy
+++ b/gateway-release/home/samples/ExampleHBase.groovy
@@ -21,12 +21,20 @@ import org.apache.hadoop.gateway.shell.Hadoop
 
 import static java.util.concurrent.TimeUnit.SECONDS
 
+import org.apache.hadoop.gateway.shell.Credentials
+
 gateway = "https://localhost:8443/gateway/sandbox"
-username = "guest"
-password = "guest-password"
 tableName = "test_table"
 
-session = Hadoop.login(gateway, username, password)
+credentials = new Credentials()
+credentials.add("ClearInput", "Enter username: ", "user")
+                .add("HiddenInput", "Enter pas" + "sword: ", "pass")
+credentials.collect()
+
+username = credentials.get("user").string()
+pass = credentials.get("pass").string()
+
+session = Hadoop.login(gateway, username, pass)
 
 println "System version : " + HBase.session(session).systemVersion().now().string
 

http://git-wip-us.apache.org/repos/asf/knox/blob/1755fdfa/gateway-release/home/samples/ExampleOozieWorkflow.groovy
----------------------------------------------------------------------
diff --git a/gateway-release/home/samples/ExampleOozieWorkflow.groovy b/gateway-release/home/samples/ExampleOozieWorkflow.groovy
index 157e4ac..b6e7e72 100644
--- a/gateway-release/home/samples/ExampleOozieWorkflow.groovy
+++ b/gateway-release/home/samples/ExampleOozieWorkflow.groovy
@@ -22,14 +22,25 @@ import org.apache.hadoop.gateway.shell.hdfs.Hdfs
 import org.apache.hadoop.gateway.shell.workflow.Workflow
 
 import static java.util.concurrent.TimeUnit.SECONDS
+import org.apache.hadoop.gateway.shell.Credentials
 
 gateway = "https://localhost:8443/gateway/sandbox"
-username = "guest"
-password = username + "-password"
 inputFile = "LICENSE"
-jobDir = "/user/" + username + "/test"
 jarFile = "samples/hadoop-examples.jar"
 
+gateway = "https://localhost:8443/gateway/sandbox"
+tableName = "test_table"
+
+credentials = new Credentials()
+credentials.add("ClearInput", "Enter username: ", "user")
+                .add("HiddenInput", "Enter pas" + "sword: ", "pass")
+credentials.collect()
+
+username = credentials.get("user").string()
+pass = credentials.get("pass").string()
+
+jobDir = "/user/" + username + "/test"
+
 definition = """\
 <workflow-app xmlns="uri:oozie:workflow:0.2" name="wordcount-workflow">
     <start to="root-node"/>
@@ -80,7 +91,7 @@ configuration = """\
 </configuration>
 """
 
-session = Hadoop.login( gateway, username, password )
+session = Hadoop.login( gateway, username, pass )
 
 println "Delete " + jobDir + ": " + Hdfs.rm( session ).file( jobDir ).recursive().now().statusCode
 println "Mkdir " + jobDir + ": " + Hdfs.mkdir( session ).dir( jobDir ).now().statusCode

http://git-wip-us.apache.org/repos/asf/knox/blob/1755fdfa/gateway-release/home/samples/ExampleWebHCatJob.groovy
----------------------------------------------------------------------
diff --git a/gateway-release/home/samples/ExampleWebHCatJob.groovy b/gateway-release/home/samples/ExampleWebHCatJob.groovy
index 0db8497..b7477b9 100644
--- a/gateway-release/home/samples/ExampleWebHCatJob.groovy
+++ b/gateway-release/home/samples/ExampleWebHCatJob.groovy
@@ -22,15 +22,23 @@ import org.apache.hadoop.gateway.shell.hdfs.Hdfs
 import org.apache.hadoop.gateway.shell.job.Job
 
 import static java.util.concurrent.TimeUnit.SECONDS
+import org.apache.hadoop.gateway.shell.Credentials
 
 gateway = "https://localhost:8443/gateway/sandbox"
-username = "guest"
-password = username + "-password"
-jobDir = "/user/" + username + "/test"
 dataFile = "LICENSE"
 jarFile = "samples/hadoop-examples.jar"
 
-session = Hadoop.login( gateway, username, password )
+credentials = new Credentials()
+credentials.add("ClearInput", "Enter username: ", "user")
+                .add("HiddenInput", "Enter pas" + "sword: ", "pass")
+credentials.collect()
+
+username = credentials.get("user").string()
+pass = credentials.get("pass").string()
+
+jobDir = "/user/" + username + "/test"
+
+session = Hadoop.login( gateway, username, pass )
 
 println "Delete " + jobDir + ": " + Hdfs.rm( session ).file( jobDir ).recursive().now().statusCode
 println "Create " + jobDir + ": " + Hdfs.mkdir( session ).dir( jobDir ).now().statusCode

http://git-wip-us.apache.org/repos/asf/knox/blob/1755fdfa/gateway-release/home/samples/ExampleWebHCatQueue.groovy
----------------------------------------------------------------------
diff --git a/gateway-release/home/samples/ExampleWebHCatQueue.groovy b/gateway-release/home/samples/ExampleWebHCatQueue.groovy
index 7298a9b..2517db2 100644
--- a/gateway-release/home/samples/ExampleWebHCatQueue.groovy
+++ b/gateway-release/home/samples/ExampleWebHCatQueue.groovy
@@ -19,12 +19,19 @@ import org.apache.hadoop.gateway.shell.Hadoop
 import org.apache.hadoop.gateway.shell.job.Job
 
 import static java.util.concurrent.TimeUnit.SECONDS
+import org.apache.hadoop.gateway.shell.Credentials
 
 gateway = "https://localhost:8443/gateway/sandbox"
-username = "guest"
-password = username + "-password"
 
-session = Hadoop.login( gateway, username, password )
+credentials = new Credentials()
+credentials.add("ClearInput", "Enter username: ", "user")
+                .add("HiddenInput", "Enter pas" + "sword: ", "pass")
+credentials.collect()
+
+username = credentials.get("user").string()
+pass = credentials.get("pass").string()
+
+session = Hadoop.login( gateway, username, pass )
 
 println "Queue: " + Job.queryQueue( session ).now().string
 

http://git-wip-us.apache.org/repos/asf/knox/blob/1755fdfa/gateway-release/home/samples/ExampleWebHdfsLs.groovy
----------------------------------------------------------------------
diff --git a/gateway-release/home/samples/ExampleWebHdfsLs.groovy b/gateway-release/home/samples/ExampleWebHdfsLs.groovy
index 6c44db5..d631f33 100644
--- a/gateway-release/home/samples/ExampleWebHdfsLs.groovy
+++ b/gateway-release/home/samples/ExampleWebHdfsLs.groovy
@@ -20,11 +20,20 @@ import groovy.json.JsonSlurper
 import org.apache.hadoop.gateway.shell.Hadoop
 import org.apache.hadoop.gateway.shell.hdfs.Hdfs
 
+import org.apache.hadoop.gateway.shell.Credentials
+
 gateway = "https://localhost:8443/gateway/sandbox"
-username = "guest"
-password = username + "-password"
 
-session = Hadoop.login( gateway, username, password )
+credentials = new Credentials()
+credentials.add("ClearInput", "Enter username: ", "user")
+                .add("HiddenInput", "Enter pas" + "sword: ", "pass")
+credentials.collect()
+
+username = credentials.get("user").string()
+pass = credentials.get("pass").string()
+
+session = Hadoop.login( gateway, username, pass )
+
 text = Hdfs.ls( session ).dir( "/" ).now().string
 json = (new JsonSlurper()).parseText( text )
 println json.FileStatuses.FileStatus.pathSuffix

http://git-wip-us.apache.org/repos/asf/knox/blob/1755fdfa/gateway-release/home/samples/ExampleWebHdfsPutGet.groovy
----------------------------------------------------------------------
diff --git a/gateway-release/home/samples/ExampleWebHdfsPutGet.groovy b/gateway-release/home/samples/ExampleWebHdfsPutGet.groovy
index 34b6fb7..f24c0b0 100644
--- a/gateway-release/home/samples/ExampleWebHdfsPutGet.groovy
+++ b/gateway-release/home/samples/ExampleWebHdfsPutGet.groovy
@@ -17,14 +17,22 @@
  */
 import org.apache.hadoop.gateway.shell.Hadoop
 import org.apache.hadoop.gateway.shell.hdfs.Hdfs
+import org.apache.hadoop.gateway.shell.Credentials
 
 gateway = "https://localhost:8443/gateway/sandbox"
-username = "guest"
-password = username + "-password"
-dataDir = "/user/" + username + "/example"
 dataFile = "README"
 
-session = Hadoop.login( gateway, username, password )
+credentials = new Credentials()
+credentials.add("ClearInput", "Enter username: ", "user")
+                .add("HiddenInput", "Enter pas" + "sword: ", "pass")
+credentials.collect()
+
+username = credentials.get("user").string()
+pass = credentials.get("pass").string()
+
+dataDir = "/user/" + username + "/example"
+
+session = Hadoop.login( gateway, username, pass )
 
 Hdfs.rm( session ).file( dataDir ).recursive().now()
 

http://git-wip-us.apache.org/repos/asf/knox/blob/1755fdfa/gateway-release/home/samples/SampleScript.groovy
----------------------------------------------------------------------
diff --git a/gateway-release/home/samples/SampleScript.groovy b/gateway-release/home/samples/SampleScript.groovy
index 1f457a0..219ea85 100644
--- a/gateway-release/home/samples/SampleScript.groovy
+++ b/gateway-release/home/samples/SampleScript.groovy
@@ -16,12 +16,19 @@
 * limitations under the License.
 */
 import org.apache.hadoop.gateway.shell.Hadoop
+import org.apache.hadoop.gateway.shell.Credentials
 
 gateway = "https://localhost:8443/gateway/sandbox"
-username = "guest"
-password = username + "-password"
 
-session = Hadoop.login( gateway, username, password )
+credentials = new Credentials()
+credentials.add("ClearInput", "Enter username: ", "user")
+                .add("HiddenInput", "Enter pas" + "sword: ", "pass")
+credentials.collect()
+
+username = credentials.get("user").string()
+pass = credentials.get("pass").string()
+
+session = Hadoop.login( gateway, username, pass )
 
 println "JSON=" + SampleService.simple( session ).param( "/tmp" ).now().string
 

http://git-wip-us.apache.org/repos/asf/knox/blob/1755fdfa/gateway-release/home/samples/hive/groovy/jdbc/sandbox-with-knox-inside/HiveJDBCSample.groovy
----------------------------------------------------------------------
diff --git a/gateway-release/home/samples/hive/groovy/jdbc/sandbox-with-knox-inside/HiveJDBCSample.groovy
b/gateway-release/home/samples/hive/groovy/jdbc/sandbox-with-knox-inside/HiveJDBCSample.groovy
index bf3984f..0e465aa 100644
--- a/gateway-release/home/samples/hive/groovy/jdbc/sandbox-with-knox-inside/HiveJDBCSample.groovy
+++ b/gateway-release/home/samples/hive/groovy/jdbc/sandbox-with-knox-inside/HiveJDBCSample.groovy
@@ -16,9 +16,8 @@
  * limitations under the License.
  */
 import java.sql.DriverManager
+import org.apache.hadoop.gateway.shell.Credentials
 
-user = "guest";
-password = user + "-password";
 gatewayHost = "localhost";
 gatewayPort = 8443;
 trustStore = "/usr/lib/knox/data/security/keystores/gateway.jks";
@@ -26,11 +25,19 @@ trustStorePassword = "knoxsecret";
 contextPath = "gateway/sandbox-with-knox-inside/hive";
 connectionString = String.format( "jdbc:hive2://%s:%d/;ssl=true;sslTrustStore=%s;trustStorePassword=%s?hive.server2.transport.mode=http;hive.server2.thrift.http.path=/%s",
gatewayHost, gatewayPort, trustStore, trustStorePassword, contextPath );
 
+credentials = new Credentials()
+credentials.add("ClearInput", "Enter username: ", "user")
+                .add("HiddenInput", "Enter pas" + "sword: ", "pass")
+credentials.collect()
+
+user = credentials.get("user").string()
+pass = credentials.get("pass").string()
+
 // Load Hive JDBC Driver
 Class.forName( "org.apache.hive.jdbc.HiveDriver" );
 
 // Configure JDBC connection
-connection = DriverManager.getConnection( connectionString, user, password );
+connection = DriverManager.getConnection( connectionString, user, pass );
 
 statement = connection.createStatement();
 

http://git-wip-us.apache.org/repos/asf/knox/blob/1755fdfa/gateway-release/home/samples/hive/groovy/jdbc/sandbox/HiveJDBCSample.groovy
----------------------------------------------------------------------
diff --git a/gateway-release/home/samples/hive/groovy/jdbc/sandbox/HiveJDBCSample.groovy b/gateway-release/home/samples/hive/groovy/jdbc/sandbox/HiveJDBCSample.groovy
index 239fcf8..bd34edb 100644
--- a/gateway-release/home/samples/hive/groovy/jdbc/sandbox/HiveJDBCSample.groovy
+++ b/gateway-release/home/samples/hive/groovy/jdbc/sandbox/HiveJDBCSample.groovy
@@ -16,9 +16,8 @@
  * limitations under the License.
  */
 import java.sql.DriverManager
+import org.apache.hadoop.gateway.shell.Credentials
 
-user = "guest";
-password = user + "-password";
 gatewayHost = "localhost";
 gatewayPort = 8443;
 trustStore = "/usr/lib/knox/data/security/keystores/gateway.jks";
@@ -26,11 +25,22 @@ trustStorePassword = "knoxsecret";
 contextPath = "gateway/sandbox/hive";
 connectionString = String.format( "jdbc:hive2://%s:%d/;ssl=true;sslTrustStore=%s;trustStorePassword=%s?hive.server2.transport.mode=http;hive.server2.thrift.http.path=/%s",
gatewayHost, gatewayPort, trustStore, trustStorePassword, contextPath );
 
+gateway = "https://localhost:8443/gateway/sandbox"
+tableName = "test_table"
+
+credentials = new Credentials()
+credentials.add("ClearInput", "Enter username: ", "user")
+                .add("HiddenInput", "Enter pas" + "sword: ", "pass")
+credentials.collect()
+
+user = credentials.get("user").string()
+pass = credentials.get("pass").string()
+
 // Load Hive JDBC Driver
 Class.forName( "org.apache.hive.jdbc.HiveDriver" );
 
 // Configure JDBC connection
-connection = DriverManager.getConnection( connectionString, user, password );
+connection = DriverManager.getConnection( connectionString, user, pass );
 
 statement = connection.createStatement();
 

http://git-wip-us.apache.org/repos/asf/knox/blob/1755fdfa/gateway-release/home/samples/hive/java/jdbc/sandbox-with-knox-inside/HiveJDBCSample.java
----------------------------------------------------------------------
diff --git a/gateway-release/home/samples/hive/java/jdbc/sandbox-with-knox-inside/HiveJDBCSample.java
b/gateway-release/home/samples/hive/java/jdbc/sandbox-with-knox-inside/HiveJDBCSample.java
index 4b1f889..2bcf4d0 100644
--- a/gateway-release/home/samples/hive/java/jdbc/sandbox-with-knox-inside/HiveJDBCSample.java
+++ b/gateway-release/home/samples/hive/java/jdbc/sandbox-with-knox-inside/HiveJDBCSample.java
@@ -25,6 +25,8 @@ import java.sql.Statement;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.apache.hadoop.gateway.shell.Credentials;
+
 public class HiveJDBCSample {
 
   public static void main( String[] args ) {
@@ -33,8 +35,6 @@ public class HiveJDBCSample {
     ResultSet resultSet = null;
 
     try {
-      String user = "guest";
-      String password = user + "-password";
       String gatewayHost = "localhost";
       int gatewayPort = 8443;
       String trustStore = "/usr/lib/knox/data/security/keystores/gateway.jks";
@@ -42,6 +42,14 @@ public class HiveJDBCSample {
       String contextPath = "gateway/sandbox-with-knox-inside/hive";
       String connectionString = String.format( "jdbc:hive2://%s:%d/;ssl=true;sslTrustStore=%s;trustStorePassword=%s?hive.server2.transport.mode=http;hive.server2.thrift.http.path=/%s",
gatewayHost, gatewayPort, trustStore, trustStorePassword, contextPath );
 
+      Credentials credentials = new Credentials();
+      credentials.add("ClearInput", "Enter username: ", "user");
+                     .add("HiddenInput", "Enter pas" + "sword: ", "pass");
+      credentials.collect();
+
+      String username = credentials.get("user").string();
+      String pass = credentials.get("pass").string();
+
       // Load Hive JDBC Driver
       Class.forName( "org.apache.hive.jdbc.HiveDriver" );
 

http://git-wip-us.apache.org/repos/asf/knox/blob/1755fdfa/gateway-release/home/samples/hive/java/jdbc/sandbox/HiveJDBCSample.java
----------------------------------------------------------------------
diff --git a/gateway-release/home/samples/hive/java/jdbc/sandbox/HiveJDBCSample.java b/gateway-release/home/samples/hive/java/jdbc/sandbox/HiveJDBCSample.java
index 00ec5ca..ffa7e58 100644
--- a/gateway-release/home/samples/hive/java/jdbc/sandbox/HiveJDBCSample.java
+++ b/gateway-release/home/samples/hive/java/jdbc/sandbox/HiveJDBCSample.java
@@ -25,6 +25,8 @@ import java.sql.Statement;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.apache.hadoop.gateway.shell.Credentials;
+
 public class HiveJDBCSample {
 
   public static void main( String[] args ) {
@@ -33,8 +35,6 @@ public class HiveJDBCSample {
     ResultSet resultSet = null;
 
     try {
-      String user = "guest";
-      String password = user + "-password";
       String gatewayHost = "localhost";
       int gatewayPort = 8443;
       String trustStore = "/usr/lib/knox/data/security/keystores/gateway.jks";
@@ -42,11 +42,22 @@ public class HiveJDBCSample {
       String contextPath = "gateway/sandbox/hive";
       String connectionString = String.format( "jdbc:hive2://%s:%d/;ssl=true;sslTrustStore=%s;trustStorePassword=%s?hive.server2.transport.mode=http;hive.server2.thrift.http.path=/%s",
gatewayHost, gatewayPort, trustStore, trustStorePassword, contextPath );
 
+      gateway = "https://localhost:8443/gateway/sandbox"
+          tableName = "test_table"
+
+      Credentials credentials = new Credentials();
+      credentials.add("ClearInput", "Enter username: ", "user");
+                     .add("HiddenInput", "Enter pas" + "sword: ", "pass");
+      credentials.collect();
+
+      String username = credentials.get("user").string();
+      String pass = credentials.get("pass").string();
+
       // Load Hive JDBC Driver
       Class.forName( "org.apache.hive.jdbc.HiveDriver" );
 
       // Configure JDBC connection
-      connection = DriverManager.getConnection( connectionString, user, password );
+      connection = DriverManager.getConnection( connectionString, user, pass );
 
       statement = connection.createStatement();
 


Mime
View raw message