summaryrefslogtreecommitdiffstats
path: root/framework/src/main/java/org/onap
diff options
context:
space:
mode:
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-09-19 23:47:08 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-11-14 14:37:26 +0530
commit4c0533c9bf8d90d191991c4f4964c79b94242c10 (patch)
tree2952928ea2cfa401f9a424948f73a0cbe16ece9f /framework/src/main/java/org/onap
parent9c2f77eed27b08e7aa3680bb9f7217dc33cab23d (diff)
Add command type to support auth and catalog
By default all commands are cmd type Issue-Id: CLI-66 Change-Id: I90567ecba00def1a1e904d2959a53c1a2cfc098b Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'framework/src/main/java/org/onap')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommand.java16
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java1
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommandSchema.java9
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/CommandType.java52
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/Constants.java1
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidCommandType.java32
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/ExternalSchema.java13
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java16
8 files changed, 138 insertions, 2 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
index 61aa2cb2..9ca43fdf 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
@@ -24,6 +24,7 @@ import java.util.Optional;
import org.onap.cli.fw.ad.OnapAuthClient;
import org.onap.cli.fw.ad.OnapCredentials;
import org.onap.cli.fw.ad.OnapService;
+import org.onap.cli.fw.cmd.CommandType;
import org.onap.cli.fw.conf.Constants;
import org.onap.cli.fw.conf.OnapCommandConfg;
import org.onap.cli.fw.error.OnapCommandException;
@@ -69,6 +70,8 @@ public abstract class OnapCommand {
protected boolean isInitialzied = false;
+ protected CommandType type = CommandType.CMD;
+
public String getSchemaVersion() {
return Constants.OPEN_CLI_SCHEMA_VERSION_VALUE;
}
@@ -148,6 +151,14 @@ public abstract class OnapCommand {
this.cmdSchemaName = schemaName;
}
+ public CommandType getType() {
+ return this.type;
+ }
+
+ public void setType(CommandType type) {
+ this.type = type;
+ }
+
/**
* Initialize this command from command schema.
*
@@ -258,8 +269,11 @@ public abstract class OnapCommand {
try {
OnapCredentials creds = OnapCommandUtils.fromParameters(this.getParameters());
+
+ // For auth type commands, login and logout logic is not required
boolean isAuthRequired = !this.onapService.isNoAuth()
- && "false".equals(paramMap.get(Constants.DEFAULT_PARAMETER_OUTPUT_NO_AUTH).getValue());
+ && "false".equals(paramMap.get(Constants.DEFAULT_PARAMETER_OUTPUT_NO_AUTH).getValue())
+ && !this.getType().equals(CommandType.AUTH);
if (!isCommandInternal()) {
this.authClient = new OnapAuthClient(
diff --git a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
index 28b2f9bf..987c3f01 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.onap.cli.fw.cmd.CommandType;
import org.onap.cli.fw.cmd.OnapHttpCommand;
import org.onap.cli.fw.conf.Constants;
import org.onap.cli.fw.conf.OnapCommandConfg;
diff --git a/framework/src/main/java/org/onap/cli/fw/OnapCommandSchema.java b/framework/src/main/java/org/onap/cli/fw/OnapCommandSchema.java
index 471ab057..2e3e0a5c 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommandSchema.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandSchema.java
@@ -20,6 +20,8 @@ import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import org.onap.cli.fw.cmd.CommandType;
+
/**
* Provide command name and schema file location, which is placed in the main resources folder (in classpath). It is
* recommended to keep the name for schema, in the form of onap-[command-name]-schema.yaml, considered this format as
@@ -52,4 +54,11 @@ public @interface OnapCommandSchema {
* @return
*/
String schema() default "";
+
+ /**
+ * Command type
+ *
+ * @return
+ */
+ String type() default "cmd";
}
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/CommandType.java b/framework/src/main/java/org/onap/cli/fw/cmd/CommandType.java
new file mode 100644
index 00000000..633a8f35
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/CommandType.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed 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.onap.cli.fw.cmd;
+
+import org.onap.cli.fw.error.OnapCommandInvalidCommandType;
+import org.onap.cli.fw.error.OnapCommandInvalidParameterType;
+
+/**
+ * Command type supported by Onap CLI.
+ *
+ */
+public enum CommandType {
+
+ AUTH,
+ CATALOG,
+ CMD;
+
+ /**
+ * Get parameter type.
+ *
+ * @param name
+ * type name
+ * @return type
+ * @throws OnapCommandInvalidParameterType
+ * exception
+ */
+ public static CommandType get(String name) throws OnapCommandInvalidCommandType {
+ if (AUTH.name().equalsIgnoreCase(name)) {
+ return AUTH;
+ } else if (CATALOG.name().equalsIgnoreCase(name)) {
+ return CATALOG;
+ } else if (CMD.name().equalsIgnoreCase(name)) {
+ return CMD;
+ } else {
+ throw new OnapCommandInvalidCommandType(name);
+ }
+ }
+}
diff --git a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
index 7dfc0d46..9fccc668 100644
--- a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
+++ b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
@@ -82,6 +82,7 @@ public class Constants {
public static final String OPEN_CLI_SCHEMA_VERSION_VALUE = "1.0";
public static final String DESCRIPTION = "description";
+ public static final String COMMAND_TYPE = "type";
public static final String SERVICE = "service";
public static final String PARAMETERS = "parameters";
public static final String DEFAULT_PARAMETERS = "default_parameters";
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidCommandType.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidCommandType.java
new file mode 100644
index 00000000..bdc2ef2b
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidCommandType.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed 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.onap.cli.fw.error;
+
+/**
+ * Command type is invalid.
+ *
+ */
+public class OnapCommandInvalidCommandType extends OnapCommandException {
+
+ private static final long serialVersionUID = 2821256032317061067L;
+
+ public OnapCommandInvalidCommandType(String cmd) {
+ super("0x3003", "Command type " + cmd + " is invalid");
+
+ }
+
+}
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/ExternalSchema.java b/framework/src/main/java/org/onap/cli/fw/utils/ExternalSchema.java
index 12f217ce..16675c26 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/ExternalSchema.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/ExternalSchema.java
@@ -16,6 +16,8 @@
package org.onap.cli.fw.utils;
+import org.onap.cli.fw.cmd.CommandType;
+
public class ExternalSchema {
private String schemaName;
@@ -23,6 +25,7 @@ public class ExternalSchema {
private String cmdName;
private String cmdVersion;
private String version;
+ private String type = CommandType.CMD.name();
private String http = "false";
public String getSchemaName() {
@@ -77,4 +80,14 @@ public class ExternalSchema {
return this.getHttp().equals("true");
}
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+
+
}
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
index 77d50171..f891fd09 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
@@ -23,6 +23,7 @@ import static org.onap.cli.fw.conf.Constants.AUTH_VALUES;
import static org.onap.cli.fw.conf.Constants.BODY;
import static org.onap.cli.fw.conf.Constants.BOOLEAN_VALUE;
import static org.onap.cli.fw.conf.Constants.CLIENT;
+import static org.onap.cli.fw.conf.Constants.COMMAND_TYPE;
import static org.onap.cli.fw.conf.Constants.DATA_DIRECTORY;
import static org.onap.cli.fw.conf.Constants.DATA_DIRECTORY_JSON_PATTERN;
import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_HOST_URL;
@@ -108,6 +109,7 @@ import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.OnapCommandRegistrar;
import org.onap.cli.fw.ad.OnapCredentials;
import org.onap.cli.fw.ad.OnapService;
+import org.onap.cli.fw.cmd.CommandType;
import org.onap.cli.fw.cmd.OnapHttpCommand;
import org.onap.cli.fw.cmd.OnapSwaggerCommand;
import org.onap.cli.fw.conf.Constants;
@@ -138,7 +140,6 @@ import org.onap.cli.fw.http.HttpResult;
import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.input.ParameterType;
import org.onap.cli.fw.input.cache.Param;
-import org.onap.cli.fw.log.OnapCommandLogger;
import org.onap.cli.fw.output.OnapCommandResult;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
import org.onap.cli.fw.output.OnapCommandResultAttributeScope;
@@ -394,6 +395,14 @@ public class OnapCommandUtils {
}
break;
+
+ case COMMAND_TYPE:
+ Object type = values.get(key);
+ if (type != null) {
+ cmd.setType(CommandType.get(type.toString()));
+ }
+ break;
+
case SERVICE:
Map<String, String> serviceMap = (Map<String, String>) values.get(key);
@@ -1537,6 +1546,11 @@ public class OnapCommandUtils {
Object obj = resourceMap.get(OPEN_CLI_SCHEMA_VERSION);
schema.setVersion(obj.toString());
schema.setCmdVersion(resourceMap.get(Constants.VERSION).toString());
+
+ if (resourceMap.get(Constants.COMMAND_TYPE) != null) {
+ schema.setType(resourceMap.get(Constants.COMMAND_TYPE).toString());
+ }
+
if (resourceMap.get(Constants.HTTP) != null) {
schema.setHttp("true");
}