knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmc...@apache.org
Subject knox git commit: KNOX-507 - Deletion of Non existing Alias from a cluster should not be successful (J.Andreina via lmccay)
Date Tue, 26 Jan 2016 21:15:32 GMT
Repository: knox
Updated Branches:
  refs/heads/master 62c759678 -> 94ec60ca5


KNOX-507 - Deletion of Non existing Alias from a cluster should not be successful (J.Andreina
via lmccay)

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

Branch: refs/heads/master
Commit: 94ec60ca5b8db35c038abf06f2a6e78b4a3cb7c2
Parents: 62c7596
Author: Larry McCay <lmccay@hortonworks.com>
Authored: Tue Jan 26 16:15:09 2016 -0500
Committer: Larry McCay <lmccay@hortonworks.com>
Committed: Tue Jan 26 16:15:09 2016 -0500

----------------------------------------------------------------------
 .../org/apache/hadoop/gateway/util/KnoxCLI.java | 10 +++-
 .../apache/hadoop/gateway/util/KnoxCLITest.java | 48 ++++++++++++++++++++
 2 files changed, 56 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/94ec60ca/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 82618be..037d3df 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
@@ -623,8 +623,14 @@ public class KnoxCLI extends Configured implements Tool {
         boolean credentialStoreForClusterAvailable =
             keystoreService.isCredentialStoreForClusterAvailable(cluster);
         if (credentialStoreForClusterAvailable) {
-          as.removeAliasForCluster(cluster, name);
-          out.println(name + " has been successfully deleted.");
+          List<String> aliasesForCluster = as.getAliasesForCluster(cluster);
+          if (null == aliasesForCluster || !aliasesForCluster.contains(name)) {
+            out.println("Deletion of Alias: " + name + " from cluster: " + cluster + " Failed.
"
+                + "\n" + "No such alias exists in the cluster.");
+          } else {
+            as.removeAliasForCluster(cluster, name);
+            out.println(name + " has been successfully deleted.");
+          }
         } else {
           out.println("Invalid cluster name provided: " + cluster);
         }

http://git-wip-us.apache.org/repos/asf/knox/blob/94ec60ca/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 1d87375..4e8c08e 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
@@ -125,6 +125,54 @@ public class KnoxCLITest {
   }
 
   @Test
+  public void testDeleteOfNonExistAliasFromUserDefinedCluster() throws Exception {
+    KnoxCLI cli = new KnoxCLI();
+    cli.setConf(new GatewayConfigImpl());
+    try {
+      int rc = 0;
+      outContent.reset();
+      String[] args1 =
+          { "create-alias", "alias1", "--cluster", "cluster1", "--value", "testvalue1", "--master",
+              "master" };
+      cli.run(args1);
+
+      // Delete invalid alias from the cluster
+      outContent.reset();
+      String[] args2 = { "delete-alias", "alias2", "--cluster", "cluster1", "--master", "master"
};
+      rc = cli.run(args2);
+      assertEquals(0, rc);
+      assertTrue(outContent.toString().contains("No such alias exists in the cluster."));
+    } finally {
+      outContent.reset();
+      String[] args1 = { "delete-alias", "alias1", "--cluster", "cluster1", "--master", "master"
};
+      cli.run(args1);
+    }
+  }
+
+  @Test
+  public void testDeleteOfNonExistAliasFromDefaultCluster() throws Exception {
+    KnoxCLI cli = new KnoxCLI();
+    cli.setConf(new GatewayConfigImpl());
+    try {
+      int rc = 0;
+      outContent.reset();
+      String[] args1 = { "create-alias", "alias1", "--value", "testvalue1", "--master", "master"
};
+      cli.run(args1);
+
+      // Delete invalid alias from the cluster
+      outContent.reset();
+      String[] args2 = { "delete-alias", "alias2", "--master", "master" };
+      rc = cli.run(args2);
+      assertEquals(0, rc);
+      assertTrue(outContent.toString().contains("No such alias exists in the cluster."));
+    } finally {
+      outContent.reset();
+      String[] args1 = { "delete-alias", "alias1", "--master", "master" };
+      cli.run(args1);
+    }
+  }
+
+  @Test
   public void testForInvalidArgument() throws Exception {
     outContent.reset();
     String[] args1 = { "--value", "testvalue1", "--master", "master" };


Mime
View raw message