KNOX-1541 - Rename Hadoop class in KnoxShell to KnoxSession Project: http://git-wip-us.apache.org/repos/asf/knox/repo Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/381eef37 Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/381eef37 Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/381eef37
Branch: refs/heads/master Commit: 381eef37a43054279b89344ab55086e5c5adb47f Parents: e08d545 Author: Larry McCay <[email protected]> Authored: Sat Oct 27 13:41:00 2018 -0400 Committer: Larry McCay <[email protected]> Committed: Sat Oct 27 13:41:00 2018 -0400 ---------------------------------------------------------------------- .../main/resources/samples/ExampleHBase.groovy | 4 +- .../samples/ExampleManagerListResources.groovy | 4 +- .../ExampleManagerResourceDeployment.groovy | 4 +- .../samples/ExampleOozieWorkflow.groovy | 4 +- .../resources/samples/ExampleWebHCatJob.groovy | 4 +- .../samples/ExampleWebHCatJobTeragen.groovy | 4 +- .../resources/samples/ExampleWebHCatPig.groovy | 4 +- .../samples/ExampleWebHCatQueue.groovy | 4 +- .../samples/ExampleWebHCatSqoop.groovy | 4 +- .../resources/samples/ExampleWebHdfsLs.groovy | 4 +- .../samples/ExampleWebHdfsPutGet.groovy | 4 +- .../samples/SampleComplexCommand.groovy | 4 +- .../main/resources/samples/SampleScript.groovy | 4 +- .../main/resources/samples/SampleService.groovy | 6 +- .../samples/SampleSimpleCommand.groovy | 4 +- .../knox/gateway/shell/AbstractRequest.java | 10 +- .../org/apache/knox/gateway/shell/Hadoop.java | 289 +---------------- .../knox/gateway/shell/HadoopException.java | 7 +- .../apache/knox/gateway/shell/KnoxSession.java | 319 +++++++++++++++++++ .../org/apache/knox/gateway/shell/KnoxSh.java | 6 +- .../knox/gateway/shell/KnoxShellException.java | 34 ++ .../org/apache/knox/gateway/shell/Shell.java | 2 +- .../gateway/shell/hbase/ClusterVersion.java | 4 +- .../apache/knox/gateway/shell/hbase/HBase.java | 8 +- .../apache/knox/gateway/shell/hbase/Status.java | 4 +- .../knox/gateway/shell/hbase/SystemVersion.java | 4 +- .../gateway/shell/hbase/table/CreateTable.java | 4 +- .../gateway/shell/hbase/table/DeleteTable.java | 4 +- .../knox/gateway/shell/hbase/table/Table.java | 8 +- .../gateway/shell/hbase/table/TableList.java | 4 +- .../gateway/shell/hbase/table/TableRegions.java | 4 +- .../gateway/shell/hbase/table/TableSchema.java | 4 +- .../shell/hbase/table/TruncateTable.java | 4 +- .../gateway/shell/hbase/table/UpdateTable.java | 4 +- .../shell/hbase/table/row/DeleteRows.java | 4 +- .../shell/hbase/table/row/QueryRows.java | 4 +- .../gateway/shell/hbase/table/row/StoreRow.java | 4 +- .../hbase/table/scanner/CreateScanner.java | 4 +- .../hbase/table/scanner/DeleteScanner.java | 4 +- .../hbase/table/scanner/ScannerGetNext.java | 4 +- .../org/apache/knox/gateway/shell/hdfs/Get.java | 4 +- .../apache/knox/gateway/shell/hdfs/Hdfs.java | 16 +- .../org/apache/knox/gateway/shell/hdfs/Ls.java | 4 +- .../apache/knox/gateway/shell/hdfs/Mkdir.java | 4 +- .../org/apache/knox/gateway/shell/hdfs/Put.java | 10 +- .../apache/knox/gateway/shell/hdfs/Rename.java | 4 +- .../org/apache/knox/gateway/shell/hdfs/Rm.java | 4 +- .../apache/knox/gateway/shell/hdfs/Status.java | 4 +- .../org/apache/knox/gateway/shell/job/Hive.java | 4 +- .../org/apache/knox/gateway/shell/job/Java.java | 4 +- .../org/apache/knox/gateway/shell/job/Job.java | 14 +- .../org/apache/knox/gateway/shell/job/Pig.java | 4 +- .../apache/knox/gateway/shell/job/Queue.java | 4 +- .../apache/knox/gateway/shell/job/Sqoop.java | 4 +- .../apache/knox/gateway/shell/job/Status.java | 4 +- .../knox/gateway/shell/knox/token/Get.java | 4 +- .../knox/gateway/shell/knox/token/Token.java | 4 +- .../shell/manager/DeployResourceRequest.java | 4 +- .../shell/manager/ListDescriptorsRequest.java | 4 +- .../ListProviderConfigurationsRequest.java | 4 +- .../shell/manager/ListResourcesRequest.java | 4 +- .../shell/manager/ListTopologiesRequest.java | 4 +- .../knox/gateway/shell/manager/Manager.java | 16 +- .../shell/manager/UndeployResourceRequest.java | 4 +- .../knox/gateway/shell/workflow/Status.java | 4 +- .../knox/gateway/shell/workflow/Submit.java | 4 +- .../knox/gateway/shell/workflow/Workflow.java | 6 +- .../knox/gateway/shell/yarn/AppState.java | 4 +- .../apache/knox/gateway/shell/yarn/KillApp.java | 4 +- .../apache/knox/gateway/shell/yarn/NewApp.java | 4 +- .../knox/gateway/shell/yarn/SubmitApp.java | 4 +- .../apache/knox/gateway/shell/yarn/Yarn.java | 10 +- 72 files changed, 536 insertions(+), 449 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell-samples/src/main/resources/samples/ExampleHBase.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/ExampleHBase.groovy b/gateway-shell-samples/src/main/resources/samples/ExampleHBase.groovy index 87f362d..180017a 100644 --- a/gateway-shell-samples/src/main/resources/samples/ExampleHBase.groovy +++ b/gateway-shell-samples/src/main/resources/samples/ExampleHBase.groovy @@ -17,7 +17,7 @@ */ package org.apache.knox.gateway.shell.hbase -import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.KnoxSession import static java.util.concurrent.TimeUnit.SECONDS @@ -34,7 +34,7 @@ credentials.collect() username = credentials.get("user").string() pass = credentials.get("pass").string() -session = Hadoop.login(gateway, username, pass) +session = KnoxSession.login(gateway, username, pass) println "System version : " + HBase.session(session).systemVersion().now().string http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell-samples/src/main/resources/samples/ExampleManagerListResources.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/ExampleManagerListResources.groovy b/gateway-shell-samples/src/main/resources/samples/ExampleManagerListResources.groovy index b995ef3..bdcb094 100644 --- a/gateway-shell-samples/src/main/resources/samples/ExampleManagerListResources.groovy +++ b/gateway-shell-samples/src/main/resources/samples/ExampleManagerListResources.groovy @@ -16,7 +16,7 @@ * limitations under the License. */ -import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.KnoxSession import org.apache.knox.gateway.shell.manager.Manager import org.apache.knox.gateway.shell.Credentials @@ -30,7 +30,7 @@ credentials.collect() username = credentials.get("user").string() pass = credentials.get("pass").string() -session = Hadoop.login( gateway, username, pass ) +session = KnoxSession.login( gateway, username, pass ) List<String> pcs = Manager.listProviderConfigurations(session); System.out.println("Provider Configurations") http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell-samples/src/main/resources/samples/ExampleManagerResourceDeployment.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/ExampleManagerResourceDeployment.groovy b/gateway-shell-samples/src/main/resources/samples/ExampleManagerResourceDeployment.groovy index db7d86d..1a1ab89 100644 --- a/gateway-shell-samples/src/main/resources/samples/ExampleManagerResourceDeployment.groovy +++ b/gateway-shell-samples/src/main/resources/samples/ExampleManagerResourceDeployment.groovy @@ -16,7 +16,7 @@ * limitations under the License. */ -import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.KnoxSession import org.apache.knox.gateway.shell.manager.Manager import org.apache.knox.gateway.shell.Credentials @@ -33,7 +33,7 @@ credentials.collect() username = credentials.get("user").string() pass = credentials.get("pass").string() -session = Hadoop.login( GATEWAY, username, pass ) +session = KnoxSession.login( GATEWAY, username, pass ) // Present the existing provider configurations List<String> pcs = Manager.listProviderConfigurations(session); http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell-samples/src/main/resources/samples/ExampleOozieWorkflow.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/ExampleOozieWorkflow.groovy b/gateway-shell-samples/src/main/resources/samples/ExampleOozieWorkflow.groovy index f459ddd..3b4e048 100644 --- a/gateway-shell-samples/src/main/resources/samples/ExampleOozieWorkflow.groovy +++ b/gateway-shell-samples/src/main/resources/samples/ExampleOozieWorkflow.groovy @@ -17,7 +17,7 @@ */ import com.jayway.jsonpath.JsonPath import groovy.json.JsonSlurper -import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.KnoxSession import org.apache.knox.gateway.shell.hdfs.Hdfs import org.apache.knox.gateway.shell.workflow.Workflow @@ -91,7 +91,7 @@ configuration = """\ </configuration> """ -session = Hadoop.login( gateway, username, pass ) +session = KnoxSession.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/381eef37/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatJob.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatJob.groovy b/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatJob.groovy index b0d593f..c87890c 100644 --- a/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatJob.groovy +++ b/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatJob.groovy @@ -17,7 +17,7 @@ */ import com.jayway.jsonpath.JsonPath import groovy.json.JsonSlurper -import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.KnoxSession import org.apache.knox.gateway.shell.hdfs.Hdfs import org.apache.knox.gateway.shell.job.Job @@ -38,7 +38,7 @@ pass = credentials.get("pass").string() jobDir = "/user/" + username + "/test" -session = Hadoop.login( gateway, username, pass ) +session = KnoxSession.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/381eef37/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatJobTeragen.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatJobTeragen.groovy b/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatJobTeragen.groovy index a6b88da..83cdd87 100644 --- a/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatJobTeragen.groovy +++ b/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatJobTeragen.groovy @@ -17,7 +17,7 @@ */ import com.jayway.jsonpath.JsonPath import groovy.json.JsonSlurper -import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.KnoxSession import org.apache.knox.gateway.shell.hdfs.Hdfs import org.apache.knox.gateway.shell.job.Job @@ -41,7 +41,7 @@ pass = credentials.get("pass").string() jobDir = "/user/" + username + "/test" -session = Hadoop.login( gateway, username, pass ) +session = KnoxSession.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/381eef37/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatPig.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatPig.groovy b/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatPig.groovy index be00d9c..47be110 100644 --- a/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatPig.groovy +++ b/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatPig.groovy @@ -17,7 +17,7 @@ */ import com.jayway.jsonpath.JsonPath import groovy.json.JsonSlurper -import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.KnoxSession import org.apache.knox.gateway.shell.hdfs.Hdfs import org.apache.knox.gateway.shell.job.Job @@ -36,7 +36,7 @@ pass = credentials.get("pass").string() jobDir = "/user/" + username + "/test" -session = Hadoop.login( gateway, username, pass ) +session = KnoxSession.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/381eef37/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatQueue.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatQueue.groovy b/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatQueue.groovy index c180e5f..6e13a17 100644 --- a/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatQueue.groovy +++ b/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatQueue.groovy @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.KnoxSession import org.apache.knox.gateway.shell.job.Job import static java.util.concurrent.TimeUnit.SECONDS @@ -31,7 +31,7 @@ credentials.collect() username = credentials.get("user").string() pass = credentials.get("pass").string() -session = Hadoop.login( gateway, username, pass ) +session = KnoxSession.login( gateway, username, pass ) println "Queue: " + Job.queryQueue( session ).now().string http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatSqoop.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatSqoop.groovy b/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatSqoop.groovy index b89736f..05609a9 100644 --- a/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatSqoop.groovy +++ b/gateway-shell-samples/src/main/resources/samples/ExampleWebHCatSqoop.groovy @@ -17,7 +17,7 @@ */ import com.jayway.jsonpath.JsonPath import groovy.json.JsonSlurper -import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.KnoxSession import org.apache.knox.gateway.shell.hdfs.Hdfs import org.apache.knox.gateway.shell.job.Job @@ -36,7 +36,7 @@ pass = credentials.get("pass").string() jobDir = "/user/" + username + "/test" -session = Hadoop.login( gateway, username, pass ) +session = KnoxSession.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/381eef37/gateway-shell-samples/src/main/resources/samples/ExampleWebHdfsLs.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/ExampleWebHdfsLs.groovy b/gateway-shell-samples/src/main/resources/samples/ExampleWebHdfsLs.groovy index a142917..73b7007 100644 --- a/gateway-shell-samples/src/main/resources/samples/ExampleWebHdfsLs.groovy +++ b/gateway-shell-samples/src/main/resources/samples/ExampleWebHdfsLs.groovy @@ -17,7 +17,7 @@ */ import groovy.json.JsonSlurper -import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.KnoxSession import org.apache.knox.gateway.shell.hdfs.Hdfs import org.apache.knox.gateway.shell.Credentials @@ -32,7 +32,7 @@ credentials.collect() username = credentials.get("user").string() pass = credentials.get("pass").string() -session = Hadoop.login( gateway, username, pass ) +session = KnoxSession.login( gateway, username, pass ) text = Hdfs.ls( session ).dir( "/" ).now().string json = (new JsonSlurper()).parseText( text ) http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell-samples/src/main/resources/samples/ExampleWebHdfsPutGet.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/ExampleWebHdfsPutGet.groovy b/gateway-shell-samples/src/main/resources/samples/ExampleWebHdfsPutGet.groovy index 297481f..f8d9ebc 100644 --- a/gateway-shell-samples/src/main/resources/samples/ExampleWebHdfsPutGet.groovy +++ b/gateway-shell-samples/src/main/resources/samples/ExampleWebHdfsPutGet.groovy @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.KnoxSession import org.apache.knox.gateway.shell.hdfs.Hdfs import org.apache.knox.gateway.shell.Credentials @@ -32,7 +32,7 @@ pass = credentials.get("pass").string() dataDir = "/user/" + username + "/example" -session = Hadoop.login( gateway, username, pass ) +session = KnoxSession.login( gateway, username, pass ) Hdfs.rm( session ).file( dataDir ).recursive().now() http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell-samples/src/main/resources/samples/SampleComplexCommand.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/SampleComplexCommand.groovy b/gateway-shell-samples/src/main/resources/samples/SampleComplexCommand.groovy index a80663d..5886d91 100644 --- a/gateway-shell-samples/src/main/resources/samples/SampleComplexCommand.groovy +++ b/gateway-shell-samples/src/main/resources/samples/SampleComplexCommand.groovy @@ -18,7 +18,7 @@ import com.jayway.jsonpath.JsonPath import org.apache.knox.gateway.shell.AbstractRequest import org.apache.knox.gateway.shell.BasicResponse -import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.KnoxSession import org.apache.http.HttpResponse import org.apache.http.client.methods.HttpGet import org.apache.http.client.utils.URIBuilder @@ -29,7 +29,7 @@ class SampleComplexCommand { static class Request extends AbstractRequest<Response> { - Request( Hadoop hadoop ) { + Request( KnoxSession hadoop ) { super( hadoop ) } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell-samples/src/main/resources/samples/SampleScript.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/SampleScript.groovy b/gateway-shell-samples/src/main/resources/samples/SampleScript.groovy index 56a87ad..3196cbc 100644 --- a/gateway-shell-samples/src/main/resources/samples/SampleScript.groovy +++ b/gateway-shell-samples/src/main/resources/samples/SampleScript.groovy @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.KnoxSession import org.apache.knox.gateway.shell.Credentials gateway = "https://localhost:8443/gateway/sandbox" @@ -28,7 +28,7 @@ credentials.collect() username = credentials.get("user").string() pass = credentials.get("pass").string() -session = Hadoop.login( gateway, username, pass ) +session = KnoxSession.login( gateway, username, pass ) println "JSON=" + SampleService.simple( session ).param( "/tmp" ).now().string http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell-samples/src/main/resources/samples/SampleService.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/SampleService.groovy b/gateway-shell-samples/src/main/resources/samples/SampleService.groovy index e87834e..283f6c6 100644 --- a/gateway-shell-samples/src/main/resources/samples/SampleService.groovy +++ b/gateway-shell-samples/src/main/resources/samples/SampleService.groovy @@ -15,17 +15,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.KnoxSession class SampleService { static String PATH = "/webhdfs/v1" - static SampleSimpleCommand simple( Hadoop hadoop ) { + static SampleSimpleCommand simple( KnoxSession hadoop ) { return new SampleSimpleCommand( hadoop ) } - static SampleComplexCommand.Request complex( Hadoop hadoop ) { + static SampleComplexCommand.Request complex( KnoxSession hadoop ) { return new SampleComplexCommand.Request( hadoop ) } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell-samples/src/main/resources/samples/SampleSimpleCommand.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/SampleSimpleCommand.groovy b/gateway-shell-samples/src/main/resources/samples/SampleSimpleCommand.groovy index 1e178c6..9f14015 100644 --- a/gateway-shell-samples/src/main/resources/samples/SampleSimpleCommand.groovy +++ b/gateway-shell-samples/src/main/resources/samples/SampleSimpleCommand.groovy @@ -17,7 +17,7 @@ */ import org.apache.knox.gateway.shell.AbstractRequest import org.apache.knox.gateway.shell.BasicResponse -import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.KnoxSession import org.apache.http.client.methods.HttpGet import org.apache.http.client.utils.URIBuilder @@ -25,7 +25,7 @@ import java.util.concurrent.Callable class SampleSimpleCommand extends AbstractRequest<BasicResponse> { - SampleSimpleCommand( Hadoop hadoop ) { + SampleSimpleCommand( KnoxSession hadoop ) { super( hadoop ) } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/AbstractRequest.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/AbstractRequest.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/AbstractRequest.java index 21bb120..c95c3f0 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/AbstractRequest.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/AbstractRequest.java @@ -35,13 +35,13 @@ import java.util.concurrent.Future; public abstract class AbstractRequest<T> { - private Hadoop session; + private KnoxSession session; - protected AbstractRequest( Hadoop session ) { + protected AbstractRequest( KnoxSession session ) { this.session = session; } - protected Hadoop hadoop() { + protected KnoxSession hadoop() { return session; } @@ -78,11 +78,11 @@ public abstract class AbstractRequest<T> { abstract protected Callable<T> callable(); - public T now() throws HadoopException { + public T now() throws KnoxShellException { try { return callable().call(); } catch( Exception e ) { - throw new HadoopException( e ); + throw new KnoxShellException( e ); } } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Hadoop.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Hadoop.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Hadoop.java index c5d4380..a1f89f5 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Hadoop.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Hadoop.java @@ -17,79 +17,24 @@ */ package org.apache.knox.gateway.shell; -import org.apache.commons.io.IOUtils; -import org.apache.http.HttpHost; -import org.apache.http.HttpRequest; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.AuthCache; -import org.apache.http.client.CredentialsProvider; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.config.ConnectionConfig; -import org.apache.http.config.Registry; -import org.apache.http.config.RegistryBuilder; -import org.apache.http.config.SocketConfig; -import org.apache.http.conn.socket.ConnectionSocketFactory; -import org.apache.http.conn.socket.PlainConnectionSocketFactory; -import org.apache.http.conn.ssl.NoopHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.TrustSelfSignedStrategy; -import org.apache.http.conn.ssl.TrustStrategy; -import org.apache.http.impl.auth.BasicScheme; -import org.apache.http.impl.client.BasicAuthCache; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.protocol.BasicHttpContext; -import org.apache.http.ssl.SSLContexts; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLContext; -import java.io.Closeable; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; import java.net.URISyntaxException; import java.security.GeneralSecurityException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; -import java.util.HashMap; import java.util.Map; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -public class Hadoop implements Closeable { - - private static final String GATEWAY_CLIENT_TRUST_DEFAULT_PASS = "changeit"; - private static final String KNOX_CLIENT_TRUSTSTORE_PASS = "KNOX_CLIENT_TRUSTSTORE_PASS"; - private static final String GATEWAY_CLIENT_TRUST = "gateway-client-trust.jks"; - private static final String KNOX_CLIENT_TRUSTSTORE_FILENAME = "KNOX_CLIENT_TRUSTSTORE_FILENAME"; - private static final String KNOX_CLIENT_TRUSTSTORE_DIR = "KNOX_CLIENT_TRUSTSTORE_DIR"; - String base; - HttpHost host; - CloseableHttpClient client; - BasicHttpContext context; - ExecutorService executor; - Map<String, String> headers = new HashMap<>(); +@Deprecated +public class Hadoop extends KnoxSession { - public Map<String, String> getHeaders() { - return headers; - } + public Hadoop(ClientContext clientContext) throws KnoxShellException, URISyntaxException { + super(clientContext); + this.executor = Executors.newCachedThreadPool(); + this.base = clientContext.url(); - public void setHeaders(Map<String, String> headers) { - this.headers = headers; + try { + client = createClient(clientContext); + } catch (KnoxShellException | GeneralSecurityException e) { + throw new HadoopException("Failed to create HTTP client.", e); + } } public static Hadoop login( String url, Map<String,String> headers ) throws URISyntaxException { @@ -103,217 +48,7 @@ public class Hadoop implements Closeable { } public static Hadoop loginInsecure(String url, String username, String password) throws URISyntaxException { - return new Hadoop(ClientContext.with(username, password, url) + return new Hadoop(ClientContext.with(username, password, url) .connection().secure(false).end()); } - - public Hadoop( ClientContext clientContext) throws HadoopException, URISyntaxException { - this.executor = Executors.newCachedThreadPool(); - this.base = clientContext.url(); - - try { - client = createClient(clientContext); - } catch (GeneralSecurityException e) { - throw new HadoopException("Failed to create HTTP client.", e); - } - } - - private CloseableHttpClient createClient(ClientContext clientContext) throws GeneralSecurityException { - - // SSL - HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE; - TrustStrategy trustStrategy = null; - if (clientContext.connection().secure()) { - hostnameVerifier = SSLConnectionSocketFactory.getDefaultHostnameVerifier(); - } else { - trustStrategy = TrustSelfSignedStrategy.INSTANCE; - System.out.println("**************** WARNING ******************\n" - + "This is an insecure client instance and may\n" - + "leave the interactions subject to a man in\n" - + "the middle attack. Please use the login()\n" - + "method instead of loginInsecure() for any\n" - + "sensitive or production usecases.\n" - + "*******************************************"); - } - - KeyStore trustStore = getTrustStore(); - SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(trustStore, trustStrategy).build(); - Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() - .register("http", PlainConnectionSocketFactory.getSocketFactory()) - .register("https", new SSLConnectionSocketFactory(sslContext, hostnameVerifier)).build(); - - // Pool - PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry); - connectionManager.setMaxTotal(clientContext.pool().maxTotal()); - connectionManager.setDefaultMaxPerRoute(clientContext.pool().defaultMaxPerRoute()); - - ConnectionConfig connectionConfig = ConnectionConfig.custom() - .setBufferSize(clientContext.connection().bufferSize()) - .build(); - connectionManager.setDefaultConnectionConfig(connectionConfig); - - SocketConfig socketConfig = SocketConfig.custom() - .setSoKeepAlive(clientContext.socket().keepalive()) - .setSoLinger(clientContext.socket().linger()) - .setSoReuseAddress(clientContext.socket().reuseAddress()) - .setSoTimeout(clientContext.socket().timeout()) - .setTcpNoDelay(clientContext.socket().tcpNoDelay()) - .build(); - connectionManager.setDefaultSocketConfig(socketConfig); - - // Auth - URI uri = URI.create(clientContext.url()); - host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); - - CredentialsProvider credentialsProvider = null; - if (clientContext.username() != null && clientContext.password() != null) { - credentialsProvider = new BasicCredentialsProvider(); - credentialsProvider.setCredentials( - new AuthScope(host.getHostName(), host.getPort()), - new UsernamePasswordCredentials(clientContext.username(), clientContext.password())); - - AuthCache authCache = new BasicAuthCache(); - BasicScheme authScheme = new BasicScheme(); - authCache.put(host, authScheme); - context = new BasicHttpContext(); - context.setAttribute(org.apache.http.client.protocol.HttpClientContext.AUTH_CACHE, authCache); - } - return HttpClients.custom() - .setConnectionManager(connectionManager) - .setDefaultCredentialsProvider(credentialsProvider) - .build(); - - } - - private static KeyStore getTrustStore() throws GeneralSecurityException { - KeyStore ks = null; - String truststoreDir = System.getenv(KNOX_CLIENT_TRUSTSTORE_DIR); - if (truststoreDir == null) { - truststoreDir = System.getProperty("user.home"); - } - String truststoreFileName = System.getenv(KNOX_CLIENT_TRUSTSTORE_FILENAME); - if (truststoreFileName == null) { - truststoreFileName = GATEWAY_CLIENT_TRUST; - } - String truststorePass = System.getenv(KNOX_CLIENT_TRUSTSTORE_PASS); - if (truststorePass == null) { - truststorePass = GATEWAY_CLIENT_TRUST_DEFAULT_PASS; - } - - InputStream is = null; - try { - ks = KeyStore.getInstance("JKS"); - File file = new File(truststoreDir, truststoreFileName); - if (!file.exists()) { - String truststore = System.getProperty("javax.net.ssl.trustStore"); - if (truststore == null) { - truststoreDir = System.getProperty("java.home"); - truststore = truststoreDir + File.separator + "lib" + File.separator - + "security" + File.separator + "cacerts"; - truststorePass = System.getProperty("javax.net.ssl.trustStorePassword", "changeit"); - } - file = new File(truststore); - } - - if (file.exists()) { - is = new FileInputStream(file); - ks.load(is, truststorePass.toCharArray()); - } - else { - throw new HadoopException("Unable to find a truststore for secure login." - + "Please import the gateway-identity certificate into the JVM" - + " truststore or set the truststore location ENV variables."); - } - } catch (KeyStoreException e) { - throw new HadoopException("Unable to create keystore of expected type.", e); - } catch (FileNotFoundException e) { - throw new HadoopException("Unable to read truststore." - + " Please import the gateway-identity certificate into the JVM" - + " truststore or set the truststore location ENV variables.", e); - } catch (NoSuchAlgorithmException e) { - throw new HadoopException("Unable to load the truststore." - + " Please import the gateway-identity certificate into the JVM" - + " truststore or set the truststore location ENV variables.", e); - } catch (CertificateException e) { - throw new HadoopException("Certificate cannot be found in the truststore." - + " Please import the gateway-identity certificate into the JVM" - + " truststore or set the truststore location ENV variables.", e); - } catch (IOException e) { - throw new HadoopException("Unable to load truststore." - + " May be related to password setting or truststore format.", e); - } finally { - IOUtils.closeQuietly(is); - } - - return ks; - } - - public String base() { - return base; - } - - public CloseableHttpResponse executeNow(HttpRequest request ) throws IOException { - CloseableHttpResponse response = client.execute( host, request, context ); - if( response.getStatusLine().getStatusCode() < 400 ) { - return response; - } else { - throw new ErrorResponse( response ); - } - } - - public <T> Future<T> executeLater( Callable<T> callable ) { - return executor.submit( callable ); - } - - public void waitFor( Future<?>... futures ) throws ExecutionException, InterruptedException { - if( futures != null ) { - for( Future future : futures ) { - future.get(); - } - } - } - - public void waitFor( long timeout, TimeUnit units, Future<?>... futures ) throws ExecutionException, TimeoutException, InterruptedException { - if( futures != null ) { - timeout = TimeUnit.MILLISECONDS.convert( timeout, units ); - long start; - for( Future future : futures ) { - start = System.currentTimeMillis(); - future.get( timeout, TimeUnit.MILLISECONDS ); - timeout -= ( System.currentTimeMillis() - start ); - } - } - } - - private void closeClient() throws IOException { - if(client != null) { - client.close(); - } - } - - public void shutdown() throws InterruptedException, IOException { - try { - executor.shutdownNow(); - } finally { - closeClient(); - } - } - - public boolean shutdown( long timeout, TimeUnit unit ) throws InterruptedException, IOException { - try{ - executor.shutdown(); - return executor.awaitTermination( timeout, unit ); - } finally { - closeClient(); - } - } - - @Override - public void close() throws IOException { - try { - shutdown(); - } catch (InterruptedException e) { - throw new HadoopException("Can not shutdown underlying resources", e); - } - } } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/HadoopException.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/HadoopException.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/HadoopException.java index a4c29b0..b6ed2da 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/HadoopException.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/HadoopException.java @@ -17,10 +17,10 @@ */ package org.apache.knox.gateway.shell; -public class HadoopException extends RuntimeException { +public class HadoopException extends KnoxShellException { - public HadoopException( String message ) { - super( message ); + public HadoopException(String message) { + super(message); } public HadoopException( Throwable throwable ) { @@ -30,5 +30,4 @@ public class HadoopException extends RuntimeException { public HadoopException( String message, Throwable throwable ) { super( message, throwable ); } - } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java new file mode 100644 index 0000000..eb30a4f --- /dev/null +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java @@ -0,0 +1,319 @@ +/* + * 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 org.apache.knox.gateway.shell; + +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.AuthCache; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.config.ConnectionConfig; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.config.SocketConfig; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.conn.ssl.TrustStrategy; +import org.apache.http.impl.auth.BasicScheme; +import org.apache.http.impl.client.BasicAuthCache; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.protocol.BasicHttpContext; +import org.apache.http.ssl.SSLContexts; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLContext; +import java.io.Closeable; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.security.GeneralSecurityException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class KnoxSession implements Closeable { + + private static final String GATEWAY_CLIENT_TRUST_DEFAULT_PASS = "changeit"; + private static final String KNOX_CLIENT_TRUSTSTORE_PASS = "KNOX_CLIENT_TRUSTSTORE_PASS"; + private static final String GATEWAY_CLIENT_TRUST = "gateway-client-trust.jks"; + private static final String KNOX_CLIENT_TRUSTSTORE_FILENAME = "KNOX_CLIENT_TRUSTSTORE_FILENAME"; + private static final String KNOX_CLIENT_TRUSTSTORE_DIR = "KNOX_CLIENT_TRUSTSTORE_DIR"; + + String base; + HttpHost host; + CloseableHttpClient client; + BasicHttpContext context; + ExecutorService executor; + Map<String, String> headers = new HashMap<>(); + + public Map<String, String> getHeaders() { + return headers; + } + + public void setHeaders(Map<String, String> headers) { + this.headers = headers; + } + + public static KnoxSession login( String url, Map<String,String> headers ) throws URISyntaxException { + KnoxSession instance = new KnoxSession(ClientContext.with(url)); + instance.setHeaders(headers); + return instance; + } + + public static KnoxSession login( String url, String username, String password ) throws URISyntaxException { + return new KnoxSession(ClientContext.with(username, password, url)); + } + + public static KnoxSession loginInsecure(String url, String username, String password) throws URISyntaxException { + return new KnoxSession(ClientContext.with(username, password, url) + .connection().secure(false).end()); + } + + public KnoxSession( ClientContext clientContext) throws KnoxShellException, URISyntaxException { + this.executor = Executors.newCachedThreadPool(); + this.base = clientContext.url(); + + try { + client = createClient(clientContext); + } catch (GeneralSecurityException e) { + throw new KnoxShellException("Failed to create HTTP client.", e); + } + } + + protected CloseableHttpClient createClient(ClientContext clientContext) throws GeneralSecurityException { + + // SSL + HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE; + TrustStrategy trustStrategy = null; + if (clientContext.connection().secure()) { + hostnameVerifier = SSLConnectionSocketFactory.getDefaultHostnameVerifier(); + } else { + trustStrategy = TrustSelfSignedStrategy.INSTANCE; + System.out.println("**************** WARNING ******************\n" + + "This is an insecure client instance and may\n" + + "leave the interactions subject to a man in\n" + + "the middle attack. Please use the login()\n" + + "method instead of loginInsecure() for any\n" + + "sensitive or production usecases.\n" + + "*******************************************"); + } + + KeyStore trustStore = getTrustStore(); + SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(trustStore, trustStrategy).build(); + Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() + .register("http", PlainConnectionSocketFactory.getSocketFactory()) + .register("https", new SSLConnectionSocketFactory(sslContext, hostnameVerifier)).build(); + + // Pool + PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry); + connectionManager.setMaxTotal(clientContext.pool().maxTotal()); + connectionManager.setDefaultMaxPerRoute(clientContext.pool().defaultMaxPerRoute()); + + ConnectionConfig connectionConfig = ConnectionConfig.custom() + .setBufferSize(clientContext.connection().bufferSize()) + .build(); + connectionManager.setDefaultConnectionConfig(connectionConfig); + + SocketConfig socketConfig = SocketConfig.custom() + .setSoKeepAlive(clientContext.socket().keepalive()) + .setSoLinger(clientContext.socket().linger()) + .setSoReuseAddress(clientContext.socket().reuseAddress()) + .setSoTimeout(clientContext.socket().timeout()) + .setTcpNoDelay(clientContext.socket().tcpNoDelay()) + .build(); + connectionManager.setDefaultSocketConfig(socketConfig); + + // Auth + URI uri = URI.create(clientContext.url()); + host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); + + CredentialsProvider credentialsProvider = null; + if (clientContext.username() != null && clientContext.password() != null) { + credentialsProvider = new BasicCredentialsProvider(); + credentialsProvider.setCredentials( + new AuthScope(host.getHostName(), host.getPort()), + new UsernamePasswordCredentials(clientContext.username(), clientContext.password())); + + AuthCache authCache = new BasicAuthCache(); + BasicScheme authScheme = new BasicScheme(); + authCache.put(host, authScheme); + context = new BasicHttpContext(); + context.setAttribute(org.apache.http.client.protocol.HttpClientContext.AUTH_CACHE, authCache); + } + return HttpClients.custom() + .setConnectionManager(connectionManager) + .setDefaultCredentialsProvider(credentialsProvider) + .build(); + + } + + private static KeyStore getTrustStore() throws GeneralSecurityException { + KeyStore ks = null; + String truststoreDir = System.getenv(KNOX_CLIENT_TRUSTSTORE_DIR); + if (truststoreDir == null) { + truststoreDir = System.getProperty("user.home"); + } + String truststoreFileName = System.getenv(KNOX_CLIENT_TRUSTSTORE_FILENAME); + if (truststoreFileName == null) { + truststoreFileName = GATEWAY_CLIENT_TRUST; + } + String truststorePass = System.getenv(KNOX_CLIENT_TRUSTSTORE_PASS); + if (truststorePass == null) { + truststorePass = GATEWAY_CLIENT_TRUST_DEFAULT_PASS; + } + + InputStream is = null; + try { + ks = KeyStore.getInstance("JKS"); + File file = new File(truststoreDir, truststoreFileName); + if (!file.exists()) { + String truststore = System.getProperty("javax.net.ssl.trustStore"); + if (truststore == null) { + truststoreDir = System.getProperty("java.home"); + truststore = truststoreDir + File.separator + "lib" + File.separator + + "security" + File.separator + "cacerts"; + truststorePass = System.getProperty("javax.net.ssl.trustStorePassword", "changeit"); + } + file = new File(truststore); + } + + if (file.exists()) { + is = new FileInputStream(file); + ks.load(is, truststorePass.toCharArray()); + } + else { + throw new KnoxShellException("Unable to find a truststore for secure login." + + "Please import the gateway-identity certificate into the JVM" + + " truststore or set the truststore location ENV variables."); + } + } catch (KeyStoreException e) { + throw new KnoxShellException("Unable to create keystore of expected type.", e); + } catch (FileNotFoundException e) { + throw new KnoxShellException("Unable to read truststore." + + " Please import the gateway-identity certificate into the JVM" + + " truststore or set the truststore location ENV variables.", e); + } catch (NoSuchAlgorithmException e) { + throw new KnoxShellException("Unable to load the truststore." + + " Please import the gateway-identity certificate into the JVM" + + " truststore or set the truststore location ENV variables.", e); + } catch (CertificateException e) { + throw new KnoxShellException("Certificate cannot be found in the truststore." + + " Please import the gateway-identity certificate into the JVM" + + " truststore or set the truststore location ENV variables.", e); + } catch (IOException e) { + throw new KnoxShellException("Unable to load truststore." + + " May be related to password setting or truststore format.", e); + } finally { + IOUtils.closeQuietly(is); + } + + return ks; + } + + public String base() { + return base; + } + + public CloseableHttpResponse executeNow(HttpRequest request ) throws IOException { + CloseableHttpResponse response = client.execute( host, request, context ); + if( response.getStatusLine().getStatusCode() < 400 ) { + return response; + } else { + throw new ErrorResponse( response ); + } + } + + public <T> Future<T> executeLater( Callable<T> callable ) { + return executor.submit( callable ); + } + + public void waitFor( Future<?>... futures ) throws ExecutionException, InterruptedException { + if( futures != null ) { + for( Future future : futures ) { + future.get(); + } + } + } + + public void waitFor( long timeout, TimeUnit units, Future<?>... futures ) throws ExecutionException, TimeoutException, InterruptedException { + if( futures != null ) { + timeout = TimeUnit.MILLISECONDS.convert( timeout, units ); + long start; + for( Future future : futures ) { + start = System.currentTimeMillis(); + future.get( timeout, TimeUnit.MILLISECONDS ); + timeout -= ( System.currentTimeMillis() - start ); + } + } + } + + private void closeClient() throws IOException { + if(client != null) { + client.close(); + } + } + + public void shutdown() throws InterruptedException, IOException { + try { + executor.shutdownNow(); + } finally { + closeClient(); + } + } + + public boolean shutdown( long timeout, TimeUnit unit ) throws InterruptedException, IOException { + try{ + executor.shutdown(); + return executor.awaitTermination( timeout, unit ); + } finally { + closeClient(); + } + } + + @Override + public void close() throws IOException { + try { + shutdown(); + } catch (InterruptedException e) { + throw new KnoxShellException("Can not shutdown underlying resources", e); + } + } +} http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSh.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSh.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSh.java index 9f44412..34914f5 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSh.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSh.java @@ -175,10 +175,10 @@ public class KnoxSh { String username = credentials.get("user").string(); String pass = credentials.get("pass").string(); - Hadoop session = null; + KnoxSession session = null; Get.Response response = null; try { - session = Hadoop.login(gateway, username, pass); + session = KnoxSession.login(gateway, username, pass); response = Token.get( session ).now(); String text = response.getString(); @@ -197,7 +197,7 @@ public class KnoxSh { perms.add(PosixFilePermission.OWNER_WRITE); Files.setPosixFilePermissions(Paths.get(System.getProperty("user.home") + "/.knoxtokencache"), perms); } - } catch(HadoopException he) { + } catch(KnoxShellException he) { System.out.println("Failure to acquire token. Please verify your credentials and Knox URL and try again."); } if ( session != null ) { http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxShellException.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxShellException.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxShellException.java new file mode 100644 index 0000000..296cf7f --- /dev/null +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxShellException.java @@ -0,0 +1,34 @@ +/* + * 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 org.apache.knox.gateway.shell; + +public class KnoxShellException extends RuntimeException { + + public KnoxShellException( String message ) { + super( message ); + } + + public KnoxShellException( Throwable throwable ) { + super( throwable ); + } + + public KnoxShellException( String message, Throwable throwable ) { + super( message, throwable ); + } + +} http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Shell.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Shell.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Shell.java index 22cd107..fa95af7 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Shell.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Shell.java @@ -36,7 +36,7 @@ import java.util.concurrent.TimeUnit; public class Shell { private static final String[] IMPORTS = new String[] { - Hadoop.class.getName(), + KnoxSession.class.getName(), HBase.class.getName(), Hdfs.class.getName(), Job.class.getName(), http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/ClusterVersion.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/ClusterVersion.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/ClusterVersion.java index 78af40d..6a472ac 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/ClusterVersion.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/ClusterVersion.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway.shell.hbase; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.BasicResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.URIBuilder; @@ -29,7 +29,7 @@ public class ClusterVersion { public static class Request extends AbstractRequest<Response> { - public Request( Hadoop session ) { + public Request( KnoxSession session ) { super( session ); } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/HBase.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/HBase.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/HBase.java index 6061830..c1fd8dc 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/HBase.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/HBase.java @@ -16,20 +16,20 @@ */ package org.apache.knox.gateway.shell.hbase; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.knox.gateway.shell.hbase.table.Table; public class HBase { public static final String SERVICE_PATH = "/hbase"; - private Hadoop session; + private KnoxSession session; - public HBase( Hadoop session ) { + public HBase( KnoxSession session ) { this.session = session; } - public static HBase session( Hadoop session ) { + public static HBase session( KnoxSession session ) { HBase hbase = new HBase( session ); return hbase; } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/Status.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/Status.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/Status.java index dfec1e8..1cc7953 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/Status.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/Status.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway.shell.hbase; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.BasicResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.URIBuilder; @@ -29,7 +29,7 @@ public class Status { public static class Request extends AbstractRequest<Response> { - public Request( Hadoop session ) { + public Request( KnoxSession session ) { super( session ); } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/SystemVersion.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/SystemVersion.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/SystemVersion.java index a487589..c2505d4 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/SystemVersion.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/SystemVersion.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway.shell.hbase; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.BasicResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.URIBuilder; @@ -29,7 +29,7 @@ public class SystemVersion { public static class Request extends AbstractRequest<Response> { - public Request( Hadoop session ) { + public Request( KnoxSession session ) { super( session ); } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/CreateTable.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/CreateTable.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/CreateTable.java index 8be5bd6..dc54037 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/CreateTable.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/CreateTable.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway.shell.hbase.table; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.EmptyResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.knox.gateway.shell.hbase.HBase; import org.apache.knox.gateway.util.XmlUtils; import org.apache.http.HttpEntity; @@ -50,7 +50,7 @@ public class CreateTable { private List<Attribute> attributes = new ArrayList<>(); private List<Family<Request>> families = new ArrayList<>(); - public Request( Hadoop session, String tableName ) { + public Request( KnoxSession session, String tableName ) { super( session ); this.tableName = tableName; } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/DeleteTable.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/DeleteTable.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/DeleteTable.java index b16931a..5389eea 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/DeleteTable.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/DeleteTable.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway.shell.hbase.table; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.EmptyResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.knox.gateway.shell.hbase.HBase; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpDelete; @@ -32,7 +32,7 @@ public class DeleteTable { private String tableName; - public Request( Hadoop session, String tableName ) { + public Request( KnoxSession session, String tableName ) { super( session ); this.tableName = tableName; } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/Table.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/Table.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/Table.java index c8304e2..e2e4094 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/Table.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/Table.java @@ -16,14 +16,14 @@ */ package org.apache.knox.gateway.shell.hbase.table; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.knox.gateway.shell.hbase.table.row.Row; import org.apache.knox.gateway.shell.hbase.table.scanner.Scanner; public class Table { private String name; - private Hadoop session; + private KnoxSession session; public Table( String name ) { this.name = name; @@ -33,12 +33,12 @@ public class Table { return name; } - public Table session( Hadoop session ) { + public Table session( KnoxSession session ) { this.session = session; return this; } - public Hadoop session() { + public KnoxSession session() { return session; } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TableList.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TableList.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TableList.java index 2cb4686..cdc022b 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TableList.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TableList.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway.shell.hbase.table; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.BasicResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.knox.gateway.shell.hbase.HBase; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; @@ -30,7 +30,7 @@ public class TableList { public static class Request extends AbstractRequest<Response> { - public Request( Hadoop session ) { + public Request( KnoxSession session ) { super( session ); } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TableRegions.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TableRegions.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TableRegions.java index da43c13..7455d56 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TableRegions.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TableRegions.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway.shell.hbase.table; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.BasicResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.knox.gateway.shell.hbase.HBase; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; @@ -32,7 +32,7 @@ public class TableRegions { private String tableName; - public Request( Hadoop session, String tableName ) { + public Request( KnoxSession session, String tableName ) { super( session ); this.tableName = tableName; } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TableSchema.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TableSchema.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TableSchema.java index 3666aa0..97956bd 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TableSchema.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TableSchema.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway.shell.hbase.table; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.BasicResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.knox.gateway.shell.hbase.HBase; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; @@ -32,7 +32,7 @@ public class TableSchema { private String tableName; - public Request( Hadoop session, String tableName ) { + public Request( KnoxSession session, String tableName ) { super( session ); this.tableName = tableName; } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TruncateTable.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TruncateTable.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TruncateTable.java index 8e8c948..c67e9bd 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TruncateTable.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TruncateTable.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway.shell.hbase.table; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.EmptyResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.knox.gateway.shell.hbase.HBase; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -39,7 +39,7 @@ public class TruncateTable { private String tableName; - public Request(Hadoop session, String tableName) { + public Request(KnoxSession session, String tableName) { super(session); this.tableName = tableName; } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/UpdateTable.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/UpdateTable.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/UpdateTable.java index 1498b02..eb6d879 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/UpdateTable.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/UpdateTable.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway.shell.hbase.table; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.EmptyResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.knox.gateway.shell.hbase.HBase; import org.apache.knox.gateway.util.XmlUtils; import org.apache.http.HttpEntity; @@ -49,7 +49,7 @@ public class UpdateTable { private String tableName; private List<Family<Request>> families = new ArrayList<>(); - public Request( Hadoop session, String tableName ) { + public Request( KnoxSession session, String tableName ) { super( session ); this.tableName = tableName; } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/DeleteRows.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/DeleteRows.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/DeleteRows.java index 4d027f0..8671b7f 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/DeleteRows.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/DeleteRows.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway.shell.hbase.table.row; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.EmptyResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.knox.gateway.shell.hbase.HBase; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpDelete; @@ -35,7 +35,7 @@ public class DeleteRows { private Column column; private Long time; - public Request( Hadoop session, String rowsId, String tableName ) { + public Request( KnoxSession session, String rowsId, String tableName ) { super( session ); this.rowsId = rowsId; this.tableName = tableName; http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/QueryRows.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/QueryRows.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/QueryRows.java index b0445d6..a30b3af 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/QueryRows.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/QueryRows.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway.shell.hbase.table.row; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.BasicResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.knox.gateway.shell.hbase.HBase; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; @@ -39,7 +39,7 @@ public class QueryRows { private Long endTime; private Long numVersions; - public Request( Hadoop session, String rowsId, String tableName ) { + public Request( KnoxSession session, String rowsId, String tableName ) { super( session ); this.rowsId = rowsId; this.tableName = tableName; http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/StoreRow.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/StoreRow.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/StoreRow.java index caa222c..77ba041 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/StoreRow.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/StoreRow.java @@ -19,7 +19,7 @@ package org.apache.knox.gateway.shell.hbase.table.row; import org.apache.commons.codec.binary.Base64; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.EmptyResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.knox.gateway.shell.hbase.HBase; import org.apache.knox.gateway.util.XmlUtils; import org.apache.http.HttpEntity; @@ -54,7 +54,7 @@ public class StoreRow { private String tableName; private List<InsertableColumn> columns = new ArrayList<>(); - public Request( Hadoop session, String rowId, String tableName ) { + public Request( KnoxSession session, String rowId, String tableName ) { super( session ); this.rowId = rowId; this.tableName = tableName; http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/CreateScanner.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/CreateScanner.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/CreateScanner.java index acb424d..26816ee 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/CreateScanner.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/CreateScanner.java @@ -19,7 +19,7 @@ package org.apache.knox.gateway.shell.hbase.table.scanner; import org.apache.commons.codec.binary.Base64; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.EmptyResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.knox.gateway.shell.hbase.HBase; import org.apache.knox.gateway.shell.hbase.table.row.Column; import org.apache.knox.gateway.util.XmlUtils; @@ -65,7 +65,7 @@ public class CreateScanner { private String filter; private Integer maxVersions; - public Request( Hadoop session, String tableName ) { + public Request( KnoxSession session, String tableName ) { super( session ); this.tableName = tableName; } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/DeleteScanner.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/DeleteScanner.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/DeleteScanner.java index 403ffe1..a25acf6 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/DeleteScanner.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/DeleteScanner.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway.shell.hbase.table.scanner; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.EmptyResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.knox.gateway.shell.hbase.HBase; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpDelete; @@ -33,7 +33,7 @@ public class DeleteScanner { private String scannerId; private String tableName; - public Request( Hadoop session, String scannerId, String tableName ) { + public Request( KnoxSession session, String scannerId, String tableName ) { super( session ); this.scannerId = scannerId; this.tableName = tableName; http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/ScannerGetNext.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/ScannerGetNext.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/ScannerGetNext.java index 76c123f..28f26b2 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/ScannerGetNext.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/ScannerGetNext.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway.shell.hbase.table.scanner; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.BasicResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.knox.gateway.shell.hbase.HBase; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; @@ -33,7 +33,7 @@ public class ScannerGetNext { private String scannerId; private String tableName; - public Request( Hadoop session, String scannerId, String tableName ) { + public Request( KnoxSession session, String scannerId, String tableName ) { super( session ); this.scannerId = scannerId; this.tableName = tableName; http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Get.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Get.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Get.java index 188ac2d..202e735 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Get.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Get.java @@ -20,7 +20,7 @@ package org.apache.knox.gateway.shell.hdfs; import org.apache.commons.io.FileUtils; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.BasicResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.URIBuilder; @@ -36,7 +36,7 @@ public class Get { private String from; private String to; - Request( Hadoop session ) { + Request( KnoxSession session ) { super( session ); } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Hdfs.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Hdfs.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Hdfs.java index c2fe1da..68424ad 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Hdfs.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Hdfs.java @@ -17,37 +17,37 @@ */ package org.apache.knox.gateway.shell.hdfs; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; public class Hdfs { static final String SERVICE_PATH = "/webhdfs/v1"; - public static Rename.Request rename( Hadoop session ) { + public static Rename.Request rename( KnoxSession session ) { return new Rename.Request( session ); } - public static Status.Request status(Hadoop session ) { + public static Status.Request status(KnoxSession session ) { return new Status.Request( session ); } - public static Ls.Request ls( Hadoop session ) { + public static Ls.Request ls( KnoxSession session ) { return new Ls.Request( session ); } - public static Rm.Request rm( Hadoop session ) { + public static Rm.Request rm( KnoxSession session ) { return new Rm.Request( session ); } - public static Put.Request put( Hadoop session ) { + public static Put.Request put( KnoxSession session ) { return new Put.Request( session ); } - public static Get.Request get( Hadoop session ) { + public static Get.Request get( KnoxSession session ) { return new Get.Request( session ); } - public static Mkdir.Request mkdir( Hadoop session ) { + public static Mkdir.Request mkdir( KnoxSession session ) { return new Mkdir.Request( session ); } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Ls.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Ls.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Ls.java index b394d46..04c0a06 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Ls.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Ls.java @@ -19,7 +19,7 @@ package org.apache.knox.gateway.shell.hdfs; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.BasicResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.URIBuilder; @@ -32,7 +32,7 @@ class Ls { String dir; - Request( Hadoop session ) { + Request( KnoxSession session ) { super( session ); } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Mkdir.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Mkdir.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Mkdir.java index 69a3066..3dd5d82 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Mkdir.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Mkdir.java @@ -19,7 +19,7 @@ package org.apache.knox.gateway.shell.hdfs; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.EmptyResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.utils.URIBuilder; @@ -33,7 +33,7 @@ class Mkdir { String dir = null; String perm = null; - Request( Hadoop session ) { + Request( KnoxSession session ) { super( session ); } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Put.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Put.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Put.java index 03486b5..733185a 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Put.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Put.java @@ -19,8 +19,8 @@ package org.apache.knox.gateway.shell.hdfs; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.EmptyResponse; -import org.apache.knox.gateway.shell.Hadoop; -import org.apache.knox.gateway.shell.HadoopException; +import org.apache.knox.gateway.shell.KnoxSession; +import org.apache.knox.gateway.shell.KnoxShellException; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -47,7 +47,7 @@ class Put { private Integer buffersize; private Short replication; - Request( Hadoop session ) { + Request( KnoxSession session ) { super( session ); } @@ -105,12 +105,12 @@ class Put { HttpPut nn = new HttpPut( uri.build() ); HttpResponse r = execute( nn ); if( r.getStatusLine().getStatusCode() != HttpStatus.SC_TEMPORARY_REDIRECT ) { - throw new HadoopException( r.getStatusLine().toString() ); + throw new KnoxShellException( r.getStatusLine().toString() ); } EntityUtils.consumeQuietly( r.getEntity() ); Header[] h = r.getHeaders( "Location" ); if( h == null || h.length != 1 ) { - throw new HadoopException( "Invalid Location header." ); + throw new KnoxShellException( "Invalid Location header." ); } String loc = h[0].getValue(); HttpPut dn = new HttpPut( loc ); http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Rename.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Rename.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Rename.java index 1afa670..af85643 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Rename.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Rename.java @@ -19,7 +19,7 @@ package org.apache.knox.gateway.shell.hdfs; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.EmptyResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.utils.URIBuilder; @@ -33,7 +33,7 @@ public class Rename { private String file; private String to; - Request(Hadoop session) { + Request(KnoxSession session) { super(session); } http://git-wip-us.apache.org/repos/asf/knox/blob/381eef37/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Rm.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Rm.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Rm.java index e0ff52d..4076da3 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Rm.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hdfs/Rm.java @@ -19,7 +19,7 @@ package org.apache.knox.gateway.shell.hdfs; import org.apache.knox.gateway.shell.AbstractRequest; import org.apache.knox.gateway.shell.EmptyResponse; -import org.apache.knox.gateway.shell.Hadoop; +import org.apache.knox.gateway.shell.KnoxSession; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.utils.URIBuilder; @@ -34,7 +34,7 @@ class Rm { String file; Boolean recursive; - Request( Hadoop session ) { + Request( KnoxSession session ) { super( session ); }
