You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by su...@apache.org on 2015/01/27 17:26:29 UTC
[03/14] knox git commit: KNOX-490: Listing and Deletion of Alias from
an invalid Cluster name, returns successful message to the user.
KNOX-490: Listing and Deletion of Alias from an invalid Cluster name, returns successful message to the user.
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/8c391335
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/8c391335
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/8c391335
Branch: refs/heads/KNOX-481
Commit: 8c39133596855641dcd992505aac8a38282998e9
Parents: f78c26e
Author: Kevin Minder <ke...@hortonworks.com>
Authored: Fri Jan 23 10:29:05 2015 -0500
Committer: Kevin Minder <ke...@hortonworks.com>
Committed: Fri Jan 23 10:29:05 2015 -0500
----------------------------------------------------------------------
.../org/apache/hadoop/gateway/util/KnoxCLI.java | 32 ++++++---
.../apache/hadoop/gateway/util/KnoxCLITest.java | 68 ++++++++++++++++++++
2 files changed, 91 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/8c391335/gateway-server/src/main/java/org/apache/hadoop/gateway/util/KnoxCLI.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/util/KnoxCLI.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/util/KnoxCLI.java
index 3840e9c..34483ab 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/util/KnoxCLI.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/util/KnoxCLI.java
@@ -301,16 +301,23 @@ public class KnoxCLI extends Configured implements Tool {
@Override
public void execute() throws Exception {
AliasService as = getAliasService();
+ KeystoreService keystoreService = getKeystoreService();
if (cluster == null) {
cluster = "__gateway";
}
- out.println("Listing aliases for: " + cluster);
- List<String> aliases = as.getAliasesForCluster(cluster);
- for (String alias : aliases) {
- out.println(alias);
- }
- out.println("\n" + aliases.size() + " items.");
+ boolean credentialStoreForClusterAvailable =
+ keystoreService.isCredentialStoreForClusterAvailable(cluster);
+ if (credentialStoreForClusterAvailable) {
+ out.println("Listing aliases for: " + cluster);
+ List<String> aliases = as.getAliasesForCluster(cluster);
+ for (String alias : aliases) {
+ out.println(alias);
+ }
+ out.println("\n" + aliases.size() + " items.");
+ } else {
+ out.println("Invalid cluster name provided: " + cluster);
+ }
}
/* (non-Javadoc)
@@ -466,12 +473,19 @@ public class KnoxCLI extends Configured implements Tool {
@Override
public void execute() throws Exception {
AliasService as = getAliasService();
+ KeystoreService keystoreService = getKeystoreService();
if (as != null) {
if (cluster == null) {
cluster = "__gateway";
}
- as.removeAliasForCluster(cluster, name);
- out.println(name + " has been successfully deleted.");
+ boolean credentialStoreForClusterAvailable =
+ keystoreService.isCredentialStoreForClusterAvailable(cluster);
+ if (credentialStoreForClusterAvailable) {
+ as.removeAliasForCluster(cluster, name);
+ out.println(name + " has been successfully deleted.");
+ } else {
+ out.println("Invalid cluster name provided: " + cluster);
+ }
}
}
@@ -605,7 +619,7 @@ public class KnoxCLI extends Configured implements Tool {
ts.redeployTopologies(cluster);
}
else {
- out.println("Invalid clusterName provided. No topologies to redeploy.");
+ out.println("Invalid cluster name provided. Nothing to redeploy.");
}
}
}
http://git-wip-us.apache.org/repos/asf/knox/blob/8c391335/gateway-server/src/test/java/org/apache/hadoop/gateway/util/KnoxCLITest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/util/KnoxCLITest.java b/gateway-server/src/test/java/org/apache/hadoop/gateway/util/KnoxCLITest.java
index fbba3a7..cfb29de 100644
--- a/gateway-server/src/test/java/org/apache/hadoop/gateway/util/KnoxCLITest.java
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/util/KnoxCLITest.java
@@ -88,6 +88,74 @@ public class KnoxCLITest {
}
@Test
+ public void testListAndDeleteOfAliasForInvalidClusterName() throws Exception {
+ outContent.reset();
+ String[] args1 =
+ { "create-alias", "alias1", "--cluster", "cluster1", "--value", "testvalue1", "--master",
+ "master" };
+ int rc = 0;
+ KnoxCLI cli = new KnoxCLI();
+ cli.setConf(new GatewayConfigImpl());
+ rc = cli.run(args1);
+ assertEquals(0, rc);
+ assertTrue(outContent.toString(), outContent.toString().contains(
+ "alias1 has been successfully " + "created."));
+
+ outContent.reset();
+ String[] args2 = { "list-alias", "--cluster", "Invalidcluster1", "--master", "master" };
+ rc = cli.run(args2);
+ assertEquals(0, rc);
+ System.out.println(outContent.toString());
+ assertTrue(outContent.toString(),
+ outContent.toString().contains("Invalid cluster name provided: Invalidcluster1"));
+
+ outContent.reset();
+ String[] args4 =
+ { "delete-alias", "alias1", "--cluster", "Invalidcluster1", "--master", "master" };
+ rc = cli.run(args4);
+ assertEquals(0, rc);
+ assertTrue(outContent.toString(),
+ outContent.toString().contains("Invalid cluster name provided: Invalidcluster1"));
+
+ }
+
+ @Test
+ public void testListAndDeleteOfAliasForValidClusterName() throws Exception {
+ outContent.reset();
+ String[] args1 =
+ { "create-alias", "alias1", "--cluster", "cluster1", "--value", "testvalue1", "--master",
+ "master" };
+ int rc = 0;
+ KnoxCLI cli = new KnoxCLI();
+ cli.setConf(new GatewayConfigImpl());
+ rc = cli.run(args1);
+ assertEquals(0, rc);
+ assertTrue(outContent.toString(), outContent.toString().contains(
+ "alias1 has been successfully " + "created."));
+
+ outContent.reset();
+ String[] args2 = { "list-alias", "--cluster", "cluster1", "--master", "master" };
+ rc = cli.run(args2);
+ assertEquals(0, rc);
+ System.out.println(outContent.toString());
+ assertTrue(outContent.toString(), outContent.toString().contains("alias1"));
+
+ outContent.reset();
+ String[] args4 =
+ { "delete-alias", "alias1", "--cluster", "cluster1", "--master", "master" };
+ rc = cli.run(args4);
+ assertEquals(0, rc);
+ assertTrue(outContent.toString(), outContent.toString().contains(
+ "alias1 has been successfully " + "deleted."));
+
+ outContent.reset();
+ rc = cli.run(args2);
+ assertEquals(0, rc);
+ assertFalse(outContent.toString(), outContent.toString().contains("alias1"));
+
+ }
+
+ @Test
public void testGatewayAndClusterStores() throws Exception {
GatewayConfigImpl config = new GatewayConfigImpl();
FileUtils.deleteQuietly( new File( config.getGatewaySecurityDir() ) );