aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/main/java
diff options
context:
space:
mode:
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-10-06 22:30:23 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-11-20 12:41:19 +0530
commit20dc78d226aca6cb390586a9e19e522d68d0821b (patch)
treecb302def17571f8f53d08073cbf83a89082fbcdc /framework/src/main/java
parent51a60f14821cb3ca54848e94694b3dda045fe666 (diff)
Normalize OnapCommandSchema
discovery is optimized to register the plugins and http commands from one function Issue-Id: CLI-66 Change-Id: I3b813862ffd5640c5218c4cced7d10f914dce4ad Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'framework/src/main/java')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommand.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java40
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommandSchema.java23
-rw-r--r--framework/src/main/java/org/onap/cli/fw/ad/OnapService.java5
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLoginCommand.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLogoutCommand.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/CatalogCommand.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommand.java12
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/Constants.java171
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java13
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapUnsupportedSchemaProfile.java35
-rw-r--r--framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java429
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/SchemaInfo.java (renamed from framework/src/main/java/org/onap/cli/fw/utils/ExternalSchema.java)47
16 files changed, 411 insertions, 378 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 ec7e1338..bc9effba 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
@@ -67,7 +67,7 @@ public abstract class OnapCommand {
protected boolean isInitialzied = false;
public String getSchemaVersion() {
- return Constants.OPEN_CLI_SCHEMA_VERSION_VALUE;
+ return Constants.OPEN_CLI_SCHEMA_VERSION_VALUE_1_0;
}
/**
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 090fae47..1a0514ef 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
@@ -24,7 +24,6 @@ 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;
@@ -35,14 +34,16 @@ import org.onap.cli.fw.error.OnapCommandNotFound;
import org.onap.cli.fw.error.OnapCommandProductVersionInvalid;
import org.onap.cli.fw.error.OnapCommandRegistrationFailed;
import org.onap.cli.fw.error.OnapCommandRegistrationProductInfoMissing;
+import org.onap.cli.fw.error.OnapUnsupportedSchemaProfile;
import org.onap.cli.fw.input.cache.OnapCommandParameterCache;
import org.onap.cli.fw.output.OnapCommandResult;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
import org.onap.cli.fw.output.OnapCommandResultAttributeScope;
import org.onap.cli.fw.output.PrintDirection;
import org.onap.cli.fw.output.ResultType;
-import org.onap.cli.fw.utils.ExternalSchema;
import org.onap.cli.fw.utils.OnapCommandUtils;
+import org.onap.cli.fw.utils.SchemaInfo;
+
/**
* Onap Command registrar provides a common place, where every command would get registered automatically when its
@@ -116,8 +117,7 @@ public class OnapCommandRegistrar {
public static OnapCommandRegistrar getRegistrar() throws OnapCommandException {
if (registrar == null) {
registrar = new OnapCommandRegistrar();
- registrar.autoDiscover();
- registrar.autoDiscoverHttpSchemas();
+ registrar.autoDiscoverSchemas();
}
return registrar;
@@ -176,8 +176,8 @@ public class OnapCommandRegistrar {
* @throws OnapCommandException
* exception
*/
- public List<ExternalSchema> listCommandInfo() throws OnapCommandException {
- return OnapCommandUtils.findAllExternalSchemas();
+ public List<SchemaInfo> listCommandInfo() throws OnapCommandException {
+ return OnapCommandUtils.discoverSchemas();
}
/**
@@ -209,7 +209,7 @@ public class OnapCommandRegistrar {
String schemaName;
if (cmd.getClass().equals(OnapHttpCommand.class)) { // NOSONAR
- schemaName = OnapCommandUtils.loadExternalSchemaFromJson(cmdName, version).getSchemaName();
+ schemaName = OnapCommandUtils.getSchemaInfo(cmdName, version).getSchemaName();
} else {
schemaName = this.getSchemaFileName(cls);
}
@@ -222,22 +222,32 @@ public class OnapCommandRegistrar {
return cmd;
}
- private void autoDiscover() throws OnapCommandInvalidRegistration, OnapCommandRegistrationProductInfoMissing {
- List<Class<OnapCommand>> cmds = OnapCommandUtils.findOnapCommands();
+ private Map<String, Class<OnapCommand>> autoDiscoverCommandPlugins() throws OnapCommandException {
+ List<Class<OnapCommand>> cmds = OnapCommandUtils.discoverCommandPlugins();
+ Map<String, Class<OnapCommand>> map = new HashMap<>();
for (Class<OnapCommand> cmd : cmds) {
if (cmd.isAnnotationPresent(OnapCommandSchema.class)) {
OnapCommandSchema ano = cmd.getAnnotation(OnapCommandSchema.class);
- this.register(ano.name(), ano.version(), cmd);
+ map.put(ano.schema(), cmd);
}
}
+
+ return map;
}
- private void autoDiscoverHttpSchemas() throws OnapCommandException {
- List<ExternalSchema> schemas = OnapCommandUtils.loadExternalSchemasFromJson();
- for (ExternalSchema schema : schemas) {
+ private void autoDiscoverSchemas() throws OnapCommandException {
+ List<SchemaInfo> schemas = OnapCommandUtils.discoverOrLoadSchemas();
+
+ Map<String, Class<OnapCommand>> plugins = this.autoDiscoverCommandPlugins();
+
+ for (SchemaInfo schema : schemas) {
if (schema.isHttp()) {
- this.register(schema.getCmdName(), schema.getCmdVersion(), OnapHttpCommand.class);
+ this.register(schema.getCmdName(), schema.getProduct(), OnapHttpCommand.class);
+ } else if (plugins.containsKey(schema.getSchemaName())) {
+ this.register(schema.getCmdName(), schema.getProduct(), plugins.get(schema.getSchemaName()));
+ } else {
+ throw new OnapUnsupportedSchemaProfile(schema.getSchemaURI());
}
}
}
@@ -304,7 +314,7 @@ public class OnapCommandRegistrar {
OnapCommandResultAttribute attrVer = new OnapCommandResultAttribute();
if (!isEnabledProductVersionOnly) {
- attrVer.setName(Constants.PRODUCT_VERSION.toUpperCase());
+ attrVer.setName(Constants.INFO_PRODUCT.toUpperCase());
attrVer.setDescription(Constants.DESCRIPTION);
attrVer.setScope(OnapCommandResultAttributeScope.SHORT);
help.getRecords().add(attrVer);
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 2e3e0a5c..47a84955 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommandSchema.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandSchema.java
@@ -35,30 +35,9 @@ import org.onap.cli.fw.cmd.CommandType;
@Documented
public @interface OnapCommandSchema {
/**
- * Command name
- *
- * @return
- */
- String name();
-
- /**
- * Command version
- *
- * @return
- */
- String version();
-
- /**
* Schema file name placed under class path
*
* @return
*/
- String schema() default "";
-
- /**
- * Command type
- *
- * @return
- */
- String type() default "cmd";
+ String schema();
}
diff --git a/framework/src/main/java/org/onap/cli/fw/ad/OnapService.java b/framework/src/main/java/org/onap/cli/fw/ad/OnapService.java
index 44b79078..7462bb18 100644
--- a/framework/src/main/java/org/onap/cli/fw/ad/OnapService.java
+++ b/framework/src/main/java/org/onap/cli/fw/ad/OnapService.java
@@ -17,7 +17,6 @@
package org.onap.cli.fw.ad;
import org.onap.cli.fw.conf.Constants;
-import org.onap.cli.fw.conf.OnapCommandConfg;
/**
* Onap Service as reported in api catalog.
@@ -42,9 +41,9 @@ public class OnapService {
* Another mode is 'direct', in which bastPath will be
* same as OnapCredentails.ServiceUrl.
*/
- private String mode = Constants.MODE_CATALOG;
+ private String mode = Constants.MODE_DIRECT;
- private String authType = OnapCommandConfg.getAuthType();;
+ private String authType = Constants.AUTH_NONE;
public String getMode() {
return mode;
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLoginCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLoginCommand.java
index e4c89a7a..28a86a9b 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLoginCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLoginCommand.java
@@ -25,7 +25,7 @@ import org.onap.cli.fw.conf.Constants;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.input.OnapCommandParameter;
-@OnapCommandSchema(name = "basic-login", version = "open-cli", type = "auth", schema = "basic-login.yaml")
+@OnapCommandSchema(schema = "basic-login.yaml")
public class BasicAuthLoginCommand extends OnapHttpCommand {
@Override
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLogoutCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLogoutCommand.java
index 085f93c8..553b28f8 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLogoutCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLogoutCommand.java
@@ -19,7 +19,7 @@ package org.onap.cli.fw.cmd;
import org.onap.cli.fw.OnapCommandSchema;
import org.onap.cli.fw.error.OnapCommandException;
-@OnapCommandSchema(name = "basic-logout", version = "open-cli", type = "auth", schema = "basic-logout.yaml")
+@OnapCommandSchema(schema = "basic-logout.yaml")
public class BasicAuthLogoutCommand extends OnapHttpCommand {
@Override
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/CatalogCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/CatalogCommand.java
index d377b78d..34bf90c2 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/CatalogCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/CatalogCommand.java
@@ -19,7 +19,7 @@ package org.onap.cli.fw.cmd;
import org.onap.cli.fw.OnapCommandSchema;
import org.onap.cli.fw.error.OnapCommandException;
-@OnapCommandSchema(name = "catalog", version = "open-cli", type = "catalog", schema = "catalog.yaml")
+@OnapCommandSchema(schema = "catalog.yaml")
public class CatalogCommand extends OnapHttpCommand {
@Override
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java
index 3edcee40..860adce6 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java
@@ -61,7 +61,7 @@ public class OnapHttpCommand extends OnapCommand {
@Override
public String getSchemaVersion() {
- return Constants.OPEN_CLI_SCHEMA_VERSION_VALUE;
+ return Constants.OPEN_CLI_SCHEMA_VERSION_VALUE_1_0;
}
public void setSuccessStatusCodes(List<Integer> successStatusCodes) {
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommand.java
index a6e2e2b0..0ea4ef08 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommand.java
@@ -20,7 +20,7 @@ import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.OnapCommandSchema;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
-import org.onap.cli.fw.utils.ExternalSchema;
+import org.onap.cli.fw.utils.SchemaInfo;
import org.onap.cli.fw.utils.OnapCommandUtils;
import java.util.ArrayList;
@@ -30,15 +30,15 @@ import java.util.List;
* Refresh external schema.
*
*/
-@OnapCommandSchema(name = "schema-refresh", version = "open-cli", schema = "schema-refresh.yaml")
+@OnapCommandSchema(schema = "schema-refresh.yaml")
public class OnapSchemaRefreshCommand extends OnapCommand {
@Override
protected void run() throws OnapCommandException {
- List<ExternalSchema> schemas = OnapCommandUtils.findAllExternalSchemas();
+ List<SchemaInfo> schemas = OnapCommandUtils.discoverSchemas();
// Will override the existing json file
- OnapCommandUtils.persist(schemas);
+ OnapCommandUtils.persistSchemaInfo(schemas);
List<String> slNumbers = new ArrayList<>();
List<String> cmdNames = new ArrayList<>();
@@ -47,12 +47,12 @@ public class OnapSchemaRefreshCommand extends OnapCommand {
List<String> cmdVersions = new ArrayList<>();
for (int i = 0; i < schemas.size(); i++) {
- ExternalSchema schema = schemas.get(i);
+ SchemaInfo schema = schemas.get(i);
slNumbers.add(String.valueOf(i + 1));
cmdNames.add(schema.getCmdName());
cmdFiles.add(schema.getSchemaName());
versions.add(schema.getVersion());
- cmdVersions.add(schema.getCmdVersion());
+ cmdVersions.add(schema.getProduct());
}
for (OnapCommandResultAttribute attribute : this.getResult().getRecords()) {
if ("sl-no".equals(attribute.getName())) {
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java
index 3366cf65..b3b9f357 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java
@@ -29,7 +29,7 @@ import java.util.Map;
/**
* Validate schema command.
*/
-@OnapCommandSchema(name = "schema-validate", version = "open-cli", schema = "schema-validate.yaml")
+@OnapCommandSchema(schema = "schema-validate.yaml")
public class OnapSchemaValidateCommand extends OnapCommand {
@Override
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 eefe7273..a0133404 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
@@ -22,7 +22,12 @@ package org.onap.cli.fw.conf;
*/
public class Constants {
- // schema validation
+ //config
+ public static final String CONF = "open-cli.properties";
+ public static final String OPEN_IGNORE_AUTH = "cli.ignore_auth";
+ public static final String OPEN_CLI_VERSION = "cli.version";
+ public static final String HTTP_API_KEY_USE_COOKIES = "cli.http.api_key_use_cookies";
+
public static final String TOP_LEVEL_PARAMS_LIST ="cli.schema.top_level_params_list";
public static final String TOP_LEVEL_MANDATORY_LIST ="cli.schema.top_level_mandatory_list";
public static final String SERVICE_PARAMS_LIST ="cli.schema.service_params_list";
@@ -43,64 +48,32 @@ public class Constants {
public static final String MODE_VALUES="cli.schema.mode_values";
public static final String COMMAND_TYPE_VALUES="cli.command.type";
+ //http connection
public static final String SSLCONTEST_TLS = "TLSV1.2";
public static final String APPLICATION_JSON = "application/json";
public static final String OPEN_CLI_PRODUCT_NAME = "cli.product_name";
+ //schema
+ public static final String OPEN_CLI_SCHEMA_VERSION = "open_cli_schema_version";
+ public static final String OPEN_CLI_SCHEMA_VERSION_VALUE_1_0 = "1.0";
- //http
- public static final String URI = "uri";
- public static final String BODY = "body";
- public static final String METHOD_TYPE = "method";
- public static final String HEADERS = "headers";
- public static final String QUERIES = "queries";
- public static final String COOKIES = "cookies";
+ public static final String NAME = "name";
- public static final String HTTP = "http";
- public static final String REQUEST = "request";
- public static final String SAMPLE_RESPONSE = "sample_response";
- public static final String SUCCESS_CODES = "success_codes";
- public static final String RESULT_MAP = "result_map";
+ public static final String DESCRIPTION = "description";
//Info
public static final String INFO = "info";
+
public static final String INFO_PRODUCT = "product";
+ public static final String OPEN_OPEN_CLI_PRODUCT_IN_USE_ENV_NAME = "OPEN_CLI_PRODUCT_IN_USE";
+
public static final String INFO_SERVICE = "service";
public static final String INFO_TYPE = "type";
public static final String INFO_AUTHOR = "author";
- //swagger
- public static final String EXECUTOR = "exec";
-
- public static final String API = "api";
- public static final String CLIENT = "client";
- public static final String ENTITY = "entity";
- public static final String METHOD = "method";
- public static final String MULTIPART_ENTITY_NAME = "multipart_entity_name";
- public static final String EXCEPTION = "exception";
-
- public static final String SCOPE = "scope";
-
- 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";
+ //parameters
public static final String PARAMETERS = "parameters";
-
- public static final String RESULTS = "results";
-
- public static final String OPEN_CLI_SCHEMA_VERSION = "open_cli_schema_version";
- public static final String NAME = "name";
- public static final String VERSION = "version";
- public static final String BASE_PATH = "base_path";
- public static final String AUTH = "auth";
- public static final String AUTH_NONE = "none";
- public static final String AUTH_BASIC = "basic";
- public static final String MODE = "mode";
- public static final String MODE_DIRECT = "direct";
- public static final String MODE_CATALOG = "catalog";
-
public static final String SHORT_OPTION = "short_option";
public static final String LONG_OPTION = "long_option";
public static final String TYPE = "type";
@@ -109,13 +82,19 @@ public class Constants {
public static final String IS_SECURED = "is_secured";
public static final String IS_INCLUDE = "is_include";
- public static final String DIRECTION = "direction";
- public static final String ATTRIBUTES = "attributes";
+ public static final String PARAMETER_TYPE_JSON = "json";
+ public static final String PARAMETER_TYPE_YAML = "yaml";
+ public static final String PARAMETER_TYPE_STRING = "string";
+ public static final String PARAMETER_TYPE_LONG = "long";
+ public static final String PARAMETER_TYPE_URL = "url";
+ public static final String PARAMETER_TYPE_BOOL = "bool";
+ public static final String PARAMETER_TYPE_ARRAY = "array";
+ public static final String PARAMETER_TYPE_BINARY = "binary";
+ public static final String PARAMETER_TYPE_MAP = "map";
public static final String DEFAULT_PARAMETER_FILE_NAME = "default_input_parameters.yaml";
public static final String DEFAULT_PARAMETER_HTTP_FILE_NAME = "default_input_parameters_http.yaml";
- // Common parameters used across all commands.
public static final String DEAFULT_PARAMETER_USERNAME = "host-username";
public static final String DEAFULT_PARAMETER_PASSWORD = "host-password";
public static final String DEAFULT_PARAMETER_HOST_URL = "host-url";
@@ -127,57 +106,83 @@ public class Constants {
public static final String DEFAULT_PARAMETER_OUTPUT_NO_TITLE = "no-title";
public static final String DEFAULT_PARAMETER_NO_AUTH = "no-auth";
- // Configuration properties
- public static final String CONF = "open-cli.properties";
- public static final String OPEN_IGNORE_AUTH = "cli.ignore_auth";
- public static final String OPEN_CLI_VERSION = "cli.version";
- public static final String OPEN_OPEN_CLI_PRODUCT_IN_USE_ENV_NAME = "OPEN_CLI_PRODUCT_IN_USE";
- public static final String HTTP_API_KEY_USE_COOKIES = "cli.http.api_key_use_cookies";
+ //results
+ public static final String RESULTS = "results";
- public static final String SERVICE_AUTH = "cli.service.auth";
- public static final String SERVICE_AUTH_BASIC_HTTP_HEADERS = "cli.http.basic.common_headers";
+ public static final String DIRECTION = "direction";
+ public static final String DIRECTION_PORTRAIT = "portrait";
+ public static final String DIRECTION_LANDSCAPE = "landscape";
+
+ public static final String ATTRIBUTES = "attributes";
+
+ public static final String SCOPE = "scope";
+ public static final String RESULT_SCOPE_SHORT = "short";
+ public static final String RESULT_SCOPE_LONG = "long";
- // Used while printing the column name during PORTRAIT mode print
+ //print
public static final String PORTRAINT_COLUMN_NAME_PROPERTY = "property";
public static final String PORTRAINT_COLUMN_NAME_VALUE = "value";
- public static final String EXTERNAL_SCHEMA_DIRECTORY = "open-cli-schema";
- public static final String EXTERNAL_YAML_PATTERN = "/**/*.yaml";
- public static final String EXTERNAL_JSON_PATTERN = "/**/*.json";
- public static final String EXTERNAL_SCHEMA_PATH_PATERN = EXTERNAL_SCHEMA_DIRECTORY + EXTERNAL_YAML_PATTERN;
+ public static final String SCHEMA_DIRECTORY = "open-cli-schema";
+ public static final String YAML_PATTERN = "/**/*.yaml";
+ public static final String JSON_PATTERN = "/**/*.json";
+ public static final String SCHEMA_PATH_PATERN = SCHEMA_DIRECTORY + YAML_PATTERN;
public static final String DATA_DIRECTORY = "data";
- public static final String EXTERNAL_DISCOVERY_FILE = "cli-schema.json";
- public static final String DATA_DIRECTORY_JSON_PATTERN = DATA_DIRECTORY
- + EXTERNAL_JSON_PATTERN;
+ public static final String DISCOVERY_FILE = "cli-schema.json";
+ public static final String DATA_PATH_JSON_PATTERN = DATA_DIRECTORY + JSON_PATTERN;
+ public static final String DISCOVER_ALWAYS = "discover_always";
+ public static final String PARAM_CACHE_FILE_NAME = "global-profile";
- public static final String PARAMETER_TYPE_JSON = "json";
- public static final String PARAMETER_TYPE_YAML = "yaml";
- public static final String PARAMETER_TYPE_STRING = "string";
- public static final String PARAMETER_TYPE_LONG = "long";
- public static final String PARAMETER_TYPE_URL = "url";
- public static final String PARAMETER_TYPE_BOOL = "bool";
- public static final String PARAMETER_TYPE_ARRAY = "array";
- public static final String PARAMETER_TYPE_BINARY = "binary";
- public static final String PARAMETER_TYPE_MAP = "map";
+ //normal
+ public static final String BASIC_SCHEMA_PROFILE = "basic-schema";
+ public static final String HTTP_SCHEMA_PROFILE = "http-schema";
- public static final String BOOLEAN_TRUE = "true";
- public static final String BOOLEAN_FALSE = "false";
+ //http
+ public static final String HTTP = "http";
- public static final String DIRECTION_PORTRAIT = "portrait";
- public static final String DIRECTION_LANDSCAPE = "landscape";
+ public static final String SERVICE = "service";
+ public static final String VERSION = "version";
+ public static final String BASE_PATH = "base_path";
+ public static final String AUTH = "auth";
+ public static final String AUTH_NONE = "none";
+ public static final String AUTH_BASIC = "basic";
+ public static final String MODE = "mode";
+ public static final String MODE_DIRECT = "direct";
+ public static final String MODE_CATALOG = "catalog";
- public static final String RESULT_SCOPE_SHORT = "short";
- public static final String RESULT_SCOPE_LONG = "long";
+ public static final String REQUEST = "request";
+ public static final String URI = "uri";
+ public static final String BODY = "body";
+ public static final String METHOD_TYPE = "method";
public static final String POST = "post";
public static final String GET = "get";
public static final String DELETE = "delete";
public static final String PUT = "put";
public static final String HEAD = "delete";
- public static final String DEFAULT_SCHEMA_FILE_NAME = "default_input_parameters.yaml";
+ public static final String HEADERS = "headers";
+ public static final String QUERIES = "queries";
+ public static final String COOKIES = "cookies";
+
+ public static final String SUCCESS_CODES = "success_codes";
+
+ public static final String RESULT_MAP = "result_map";
+
+ public static final String SAMPLE_RESPONSE = "sample_response";
+
+ //swagger
+ public static final String EXECUTOR = "exec";
+
+ public static final String API = "api";
+ public static final String CLIENT = "client";
+ public static final String ENTITY = "entity";
+ public static final String METHOD = "method";
+ public static final String MULTIPART_ENTITY_NAME = "multipart_entity_name";
+ public static final String EXCEPTION = "exception";
+ public static final String BOOLEAN_TRUE = "true";
+ public static final String BOOLEAN_FALSE = "false";
- public static final String PRODUCT_VERSION = "product version";
// Error message
public static final String SCHEMA_INVALID_DEFAULT_PARAMS_SECTION = "Invalid default_parameter section";
public static final String SCHEMA_FILE_EMPTY = "The schema file cann't be null or empty";
@@ -192,9 +197,6 @@ public class Constants {
public static final String HTTP_SAMPLE_RESPONSE_FAILED_PARSING = "The http Sample response json is failed to parse.";
public static final String USE_DIRECTIVE = "use";
- public static final String PARAM_CACHE_FILE_NAME = "global-profile";
-
- public static final String DISCOVER_ALWAYS = "discover_always";
public static final String SAMPLE_GEN_ENABLED = "cli.sample.gen.enable";
public static final String SAMPLE_GEN_TARGET_FOLDER = "cli.sample.gen.target";
@@ -202,14 +204,13 @@ public class Constants {
public static final String SPL_ENTRY_UUID = "uuid";
public static final String SPL_ENTRY_ENV = "env:";
+ //auth plugin
public static final String AUTH_SERVICE_AUTHORIZATION = "Authorization";
+ //catalog plugin
public static final String CATALOG_SERVICE_NAME = "catalog-service-name";
-
public static final String CATALOG_SERVICE_VERSION = "catalog-service-version";
-
public static final String CATALOG_SERVICE_BASE_PATH = "catalog-service-base-path";
-
public static final String CATALOG_SERVICE_HOST_URL = "catalog-service-host-url";
private Constants() {
diff --git a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java
index 7dc9d5a1..60929358 100644
--- a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java
+++ b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java
@@ -104,10 +104,6 @@ public final class OnapCommandConfg {
return prps.getProperty(Constants.OPEN_CLI_PRODUCT_NAME);
}
- public static String getAuthType() {
- return prps.getProperty(Constants.SERVICE_AUTH, Constants.AUTH_BASIC);
- }
-
private static Map<String, String> getHeaderValues(String headerKey, Map<String, String> paramMap) {
Map<String, String> mapHeaders = new HashMap<String, String> ();
if (prps.containsKey(headerKey)) {
@@ -129,15 +125,6 @@ public final class OnapCommandConfg {
return mapHeaders;
}
- public static Map<String, String> getBasicCommonHeaders(Map<String, String> paramMap) {
- return getHeaderValues(Constants.SERVICE_AUTH_BASIC_HTTP_HEADERS, paramMap);
- }
-
- public static Map<String, String> getServiceHeaders(String serviceName, Map<String, String> paramMap) {
- String serviceHeader = Constants.SERVICE_AUTH_BASIC_HTTP_HEADERS+ "." + serviceName;
- return getHeaderValues(serviceHeader, paramMap);
- }
-
//mrkanag move this utils class
public static List<String> getSchemaAttrInfo(String key) {
return Arrays.stream(prps.getProperty(key).split(",")).map(String::trim).collect(Collectors.toList()); // NOSONAR
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapUnsupportedSchemaProfile.java b/framework/src/main/java/org/onap/cli/fw/error/OnapUnsupportedSchemaProfile.java
new file mode 100644
index 00000000..098f04df
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/error/OnapUnsupportedSchemaProfile.java
@@ -0,0 +1,35 @@
+/*
+ * 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 schema not found.
+ *
+ */
+public class OnapUnsupportedSchemaProfile extends OnapCommandException {
+
+ private static final long serialVersionUID = -3919580583845280200L;
+
+ private static final String ERROR_CODE = "0xb004";
+
+ private static final String ERROR_MSG = "Unsupported schema profile";
+
+ public OnapUnsupportedSchemaProfile(String schema) {
+ super(ERROR_CODE, ERROR_MSG + schema);
+ }
+
+}
diff --git a/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java b/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java
index 1d9cb549..32035737 100644
--- a/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java
+++ b/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java
@@ -93,7 +93,7 @@ public class OnapCommandParameterCache {
}
try {
- OnapCommandUtils.persistParams(params, this.profileName);
+ OnapCommandUtils.persistProfile(params, this.profileName);
} catch (OnapCommandPersistProfileFailed e) {
throw new RuntimeException(e); // NOSONAR
}
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 e056456a..7baae094 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
@@ -25,7 +25,7 @@ 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_VALUES;
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.DATA_PATH_JSON_PATTERN;
import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_PASSWORD;
import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_USERNAME;
import static org.onap.cli.fw.conf.Constants.DEFAULT_PARAMETER_FILE_NAME;
@@ -34,12 +34,10 @@ import static org.onap.cli.fw.conf.Constants.DEFAULT_PARAMETER_NO_AUTH;
import static org.onap.cli.fw.conf.Constants.DEFAULT_VALUE;
import static org.onap.cli.fw.conf.Constants.DESCRIPTION;
import static org.onap.cli.fw.conf.Constants.DIRECTION;
+import static org.onap.cli.fw.conf.Constants.DISCOVERY_FILE;
import static org.onap.cli.fw.conf.Constants.ENTITY;
import static org.onap.cli.fw.conf.Constants.EXCEPTION;
import static org.onap.cli.fw.conf.Constants.EXECUTOR;
-import static org.onap.cli.fw.conf.Constants.EXTERNAL_DISCOVERY_FILE;
-import static org.onap.cli.fw.conf.Constants.EXTERNAL_SCHEMA_DIRECTORY;
-import static org.onap.cli.fw.conf.Constants.EXTERNAL_SCHEMA_PATH_PATERN;
import static org.onap.cli.fw.conf.Constants.HEADERS;
import static org.onap.cli.fw.conf.Constants.HTTP;
import static org.onap.cli.fw.conf.Constants.HTTP_BODY_FAILED_PARSING;
@@ -78,8 +76,10 @@ import static org.onap.cli.fw.conf.Constants.RESULT_MAP;
import static org.onap.cli.fw.conf.Constants.RESULT_PARAMS_LIST;
import static org.onap.cli.fw.conf.Constants.RESULT_PARAMS_MANDATORY_LIST;
import static org.onap.cli.fw.conf.Constants.SAMPLE_RESPONSE;
+import static org.onap.cli.fw.conf.Constants.SCHEMA_DIRECTORY;
import static org.onap.cli.fw.conf.Constants.SCHEMA_FILE_NOT_EXIST;
import static org.onap.cli.fw.conf.Constants.SCHEMA_FILE_WRONG_EXTN;
+import static org.onap.cli.fw.conf.Constants.SCHEMA_PATH_PATERN;
import static org.onap.cli.fw.conf.Constants.SCOPE;
import static org.onap.cli.fw.conf.Constants.SERVICE;
import static org.onap.cli.fw.conf.Constants.SERVICE_PARAMS_LIST;
@@ -149,6 +149,8 @@ import org.onap.cli.fw.output.OnapCommandResultAttributeScope;
import org.onap.cli.fw.output.PrintDirection;
import org.onap.cli.fw.output.ResultType;
import org.onap.cli.fw.run.OnapCommandExecutor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
@@ -166,6 +168,7 @@ import net.minidev.json.JSONObject;
*/
public class OnapCommandUtils {
+ private static Logger LOG = LoggerFactory.getLogger(OnapCommandUtils.class);
/**
* Private constructor.
*/
@@ -187,7 +190,7 @@ public class OnapCommandUtils {
InputStream inputStream = OnapCommandUtils.class.getClassLoader().getResourceAsStream(schemaName);
try {
- Resource resource = getExternalResource(schemaName, EXTERNAL_SCHEMA_PATH_PATERN);
+ Resource resource = getExternalResource(schemaName, SCHEMA_PATH_PATERN);
if (resource != null) {
inputStream = resource.getInputStream();
@@ -243,14 +246,7 @@ public class OnapCommandUtils {
* @param schemaName schema name
* @param includeDefault include if default
* @param validateSchema flag to represent validation
- * @throws OnapCommandParameterNameConflict param name conflict exception
- * @throws OnapCommandParameterOptionConflict param option conflict exception
- * @throws OnapCommandInvalidParameterType invalid param type exception
- * @throws OnapCommandInvalidPrintDirection invalid print direction exception
- * @throws OnapCommandInvalidResultAttributeScope invalid scope exception
- * @throws OnapCommandSchemaNotFound schema not found
- * @throws OnapCommandInvalidSchema invalid schema
- * @throws OnapCommandInvalidSchemaVersion invalid schema version
+ * @throws OnapCommandException on error
*/
public static List<String> loadSchema(OnapCommand cmd, String schemaName, boolean includeDefault,
boolean validateSchema) throws OnapCommandException {
@@ -300,47 +296,6 @@ public class OnapCommandUtils {
}
}
- private static void throwOrCollect(OnapCommandException ex, List<String> list,
- boolean shouldCollectException) throws OnapCommandException {
- if (shouldCollectException) {
- list.add(ex.getMessage());
- } else {
- throw ex;
- }
- }
-
- private static void validateTags(List<String> schemaErrors, Map<String, ?> yamlMap,
- List<String> totalParams, List<String> mandatoryParams,
- String section) {
- //mrkanag capture invalid entries as well
- for (String param : totalParams) {
- boolean isMandatory = mandatoryParams.contains(param);
- boolean isYamlContains = yamlMap.containsKey(param);
- if (isMandatory) {
- if (!isYamlContains) {
- schemaErrors.add("Mandatory attribute '" + param + "' is missing under '" + section + "'");
- } else {
- String value = String.valueOf(yamlMap.get(param));
- if (value == null || value.isEmpty()) {
- schemaErrors.add("Mandatory attribute '" + param + "' under '" + section
- + "' shouldn't be null or empty");
- }
- }
- }
- }
- }
-
- /**
- * Validate Boolean.
- *
- * @param toValidate
- * string
- * @return boolean
- */
- protected static boolean validateBoolean(String toValidate) {
- return OnapCommandConfg.getSchemaAttrInfo(BOOLEAN_VALUE).contains(toValidate.toLowerCase());
- }
-
private static List<String> parseSchema(OnapCommand cmd,
final Map<String, ?> values,
boolean validate) throws OnapCommandException {
@@ -658,111 +613,6 @@ public class OnapCommandUtils {
return exceptionList;
}
- private static String emptySection(String section) {
- return "The section '" + section + ":' cann't be null or empty";
- }
-
- private static String invalidBooleanValueMessage(String section, String attribute, String value) {
- return "The value '" + value + "' of '" + attribute + "' present under '" + section + "' should be boolean";
- }
-
- private static Set<String> validateHttpQueries(Map<String, Object> requestMap) {
- Map<String, Object> queries = (Map<String, Object>) requestMap.get(QUERIES);
- Set<String> queryParamNames = new HashSet<>();
- if (queries != null) {
- for (Entry<String, Object> entry : queries.entrySet()) {
- parseParameters(String.valueOf(entry.getValue()), queryParamNames);
- }
- }
- return queryParamNames;
- }
-
-
- private static Set<String> validateHttpHeaders(Map<String, Object> requestMap) {
-
- Map<String, Object> headers = (Map<String, Object>) requestMap.get(HEADERS);
- Set<String> headerParamNames = new HashSet<>();
- if (headers != null) {
- for (Entry<String, Object> entry : headers.entrySet()) {
- parseParameters(String.valueOf(entry.getValue()), headerParamNames);
- }
- }
- return headerParamNames;
- }
-
- private static Set<String> validateHttpBody(List<String> errorList, Map<String, Object> requestMap) {
- Set<String> bodyParamNames = new HashSet<>();
- Object bodyString = requestMap.get(BODY);
- if (bodyString == null) {
- return bodyParamNames;
- }
-
- String body = String.valueOf(bodyString);
- JSONObject obj = null;
- try {
- obj = new ObjectMapper().readValue(body, JSONObject.class);
- } catch (IOException e1) { // NOSONAR
- errorList.add(HTTP_BODY_FAILED_PARSING);
- }
- if (obj == null || "".equals(obj.toString())) {
- errorList.add(HTTP_BODY_JSON_EMPTY);
- }
- parseParameters(body, bodyParamNames);
-
- return bodyParamNames;
- }
-
- private static Set<String> validateHttpUri(List<String> errorList, Map<String, Object> requestMap) {
- Set<String> uriParamNames = new HashSet<>();
- String uri = (String) requestMap.get(URI);
- if (uri == null || uri.isEmpty()) {
- errorList.add(emptySection(URI));
- return uriParamNames;
- }
- parseParameters(uri, uriParamNames);
- return uriParamNames;
- }
-
- private static void parseParameters(String line, Set<String> paramNames) {
-
- int currentIdx = 0;
- while (currentIdx < line.length()) {
- int idxS = line.indexOf("${", currentIdx);
- if (idxS == -1) {
- break;
- }
- int idxE = line.indexOf("}", idxS);
- String paramName = line.substring(idxS + 2, idxE);
- paramNames.add(paramName.trim());
-
- currentIdx = idxE + 1;
- }
-
- }
-
- private static Set<String> getRequestParams(Map<String, ?> yamlMap) {
-
- Set<String> set = new HashSet<>();
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> inputParams = (List<Map<String, Object>>) yamlMap.get(PARAMETERS);
-
- if (inputParams != null) {
- for (Map<String, Object> map : inputParams) {
- for (Entry<String, Object> entry : map.entrySet()) {
- Object key = entry.getKey();
-
- if (NAME.equals(key)) {
- set.add(String.valueOf(entry.getValue()));
- break;
- }
- }
- }
- }
-
- return set;
- }
-
/**
* Load the schema.
*
@@ -824,22 +674,8 @@ public class OnapCommandUtils {
* OnapHttpCommand
* @param schemaName
* schema name
- * @throws OnapCommandParameterNameConflict
- * param name conflict exception
- * @throws OnapCommandParameterOptionConflict
- * param option conflict exception
- * @throws OnapCommandInvalidParameterType
- * invalid param type exception
- * @throws OnapCommandInvalidPrintDirection
- * invalid print direction exception
- * @throws OnapCommandInvalidResultAttributeScope
- * invalid scope exception
- * @throws OnapCommandSchemaNotFound
- * schema not found
- * @throws OnapCommandInvalidSchema
- * invalid schema
- * @throws OnapCommandInvalidSchemaVersion
- * invalid schema version
+ * @throws OnapCommandException
+ * on error
*/
private static ArrayList<String> parseHttpSchema(OnapHttpCommand cmd,
final Map<String, ?> values,
@@ -989,6 +825,152 @@ public class OnapCommandUtils {
return errorList;
}
+
+ private static void throwOrCollect(OnapCommandException ex, List<String> list, boolean shouldCollectException)
+ throws OnapCommandException {
+ if (shouldCollectException) {
+ list.add(ex.getMessage());
+ } else {
+ throw ex;
+ }
+ }
+
+ private static void validateTags(List<String> schemaErrors, Map<String, ?> yamlMap, List<String> totalParams,
+ List<String> mandatoryParams, String section) {
+ // mrkanag capture invalid entries as well
+ for (String param : totalParams) {
+ boolean isMandatory = mandatoryParams.contains(param);
+ boolean isYamlContains = yamlMap.containsKey(param);
+ if (isMandatory) {
+ if (!isYamlContains) {
+ schemaErrors.add("Mandatory attribute '" + param + "' is missing under '" + section + "'");
+ } else {
+ String value = String.valueOf(yamlMap.get(param));
+ if (value == null || value.isEmpty()) {
+ schemaErrors.add("Mandatory attribute '" + param + "' under '" + section
+ + "' shouldn't be null or empty");
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Validate Boolean.
+ *
+ * @param toValidate
+ * string
+ * @return boolean
+ */
+ protected static boolean validateBoolean(String toValidate) {
+ return OnapCommandConfg.getSchemaAttrInfo(BOOLEAN_VALUE).contains(toValidate.toLowerCase());
+ }
+
+ private static String emptySection(String section) {
+ return "The section '" + section + ":' cann't be null or empty";
+ }
+
+ private static String invalidBooleanValueMessage(String section, String attribute, String value) {
+ return "The value '" + value + "' of '" + attribute + "' present under '" + section + "' should be boolean";
+ }
+
+ private static Set<String> validateHttpQueries(Map<String, Object> requestMap) {
+ Map<String, Object> queries = (Map<String, Object>) requestMap.get(QUERIES);
+ Set<String> queryParamNames = new HashSet<>();
+ if (queries != null) {
+ for (Entry<String, Object> entry : queries.entrySet()) {
+ parseParameters(String.valueOf(entry.getValue()), queryParamNames);
+ }
+ }
+ return queryParamNames;
+ }
+
+
+ private static Set<String> validateHttpHeaders(Map<String, Object> requestMap) {
+
+ Map<String, Object> headers = (Map<String, Object>) requestMap.get(HEADERS);
+ Set<String> headerParamNames = new HashSet<>();
+ if (headers != null) {
+ for (Entry<String, Object> entry : headers.entrySet()) {
+ parseParameters(String.valueOf(entry.getValue()), headerParamNames);
+ }
+ }
+ return headerParamNames;
+ }
+
+ private static Set<String> validateHttpBody(List<String> errorList, Map<String, Object> requestMap) {
+ Set<String> bodyParamNames = new HashSet<>();
+ Object bodyString = requestMap.get(BODY);
+ if (bodyString == null) {
+ return bodyParamNames;
+ }
+
+ String body = String.valueOf(bodyString);
+ JSONObject obj = null;
+ try {
+ obj = new ObjectMapper().readValue(body, JSONObject.class);
+ } catch (IOException e1) { // NOSONAR
+ errorList.add(HTTP_BODY_FAILED_PARSING);
+ }
+ if (obj == null || "".equals(obj.toString())) {
+ errorList.add(HTTP_BODY_JSON_EMPTY);
+ }
+ parseParameters(body, bodyParamNames);
+
+ return bodyParamNames;
+ }
+
+ private static Set<String> validateHttpUri(List<String> errorList, Map<String, Object> requestMap) {
+ Set<String> uriParamNames = new HashSet<>();
+ String uri = (String) requestMap.get(URI);
+ if (uri == null || uri.isEmpty()) {
+ errorList.add(emptySection(URI));
+ return uriParamNames;
+ }
+ parseParameters(uri, uriParamNames);
+ return uriParamNames;
+ }
+
+ private static void parseParameters(String line, Set<String> paramNames) {
+
+ int currentIdx = 0;
+ while (currentIdx < line.length()) {
+ int idxS = line.indexOf("${", currentIdx);
+ if (idxS == -1) {
+ break;
+ }
+ int idxE = line.indexOf("}", idxS);
+ String paramName = line.substring(idxS + 2, idxE);
+ paramNames.add(paramName.trim());
+
+ currentIdx = idxE + 1;
+ }
+
+ }
+
+ private static Set<String> getRequestParams(Map<String, ?> yamlMap) {
+
+ Set<String> set = new HashSet<>();
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> inputParams = (List<Map<String, Object>>) yamlMap.get(PARAMETERS);
+
+ if (inputParams != null) {
+ for (Map<String, Object> map : inputParams) {
+ for (Entry<String, Object> entry : map.entrySet()) {
+ Object key = entry.getKey();
+
+ if (NAME.equals(key)) {
+ set.add(String.valueOf(entry.getValue()));
+ break;
+ }
+ }
+ }
+ }
+
+ return set;
+ }
+
private static void validateHttpResultMap(List<String> errorList, Map<String, ?> values) throws OnapCommandException {
Map<String, ?> valMap = (Map<String, ?>) values.get(HTTP);
List<Map<String, String>> attributes = (List<Map<String, String>>) ((Map<String, ?>)values.get(RESULTS)).get(ATTRIBUTES);
@@ -1226,7 +1208,7 @@ public class OnapCommandUtils {
*
* @return list
*/
- public static List<Class<OnapCommand>> findOnapCommands() {
+ public static List<Class<OnapCommand>> discoverCommandPlugins() {
ServiceLoader<OnapCommand> loader = ServiceLoader.load(OnapCommand.class);
List<Class<OnapCommand>> clss = new ArrayList<>();
for (OnapCommand implClass : loader) {
@@ -1539,7 +1521,6 @@ public class OnapCommandUtils {
inp.getReqQueries().put(h, replaceLineFromInputParameters(value, params));
}
- //mrkanag replaceLineFromInputParameters for result_map, to support input param in result output
return inp;
}
@@ -1620,44 +1601,62 @@ public class OnapCommandUtils {
* @throws OnapCommandInvalidSchema
* exception
*/
- public static List<ExternalSchema> findAllExternalSchemas() throws OnapCommandException {
- List<ExternalSchema> extSchemas = new ArrayList<>();
+ public static List<SchemaInfo> discoverSchemas() throws OnapCommandException {
+ List<SchemaInfo> extSchemas = new ArrayList<>();
try {
- Resource[] res = getExternalResources(EXTERNAL_SCHEMA_PATH_PATERN);
+ Resource[] res = getExternalResources(SCHEMA_PATH_PATERN);
if (res != null && res.length > 0) {
Map<String, ?> resourceMap;
+
for (Resource resource : res) {
- resourceMap = getExternalSchemaMap(resource);
+ resourceMap = loadSchema(resource);
+
if (resourceMap != null && resourceMap.size() > 0) {
- ExternalSchema schema = new ExternalSchema();
- schema.setSchemaName(resource.getFilename());
+ SchemaInfo schema = new SchemaInfo();
+
schema.setSchemaURI(resource.getURI().toString());
- schema.setCmdName((String) resourceMap.get(NAME));
+
Object obj = resourceMap.get(OPEN_CLI_SCHEMA_VERSION);
schema.setVersion(obj.toString());
+ if (!schema.getVersion().equalsIgnoreCase(Constants.OPEN_CLI_SCHEMA_VERSION_VALUE_1_0)) {
+ LOG.info("Unsupported Schema version found " + schema.getSchemaURI());
+ continue;
+ }
+
+ schema.setSchemaName(resource.getFilename());
+ schema.setCmdName((String) resourceMap.get(NAME));
+
Map<String, ?> infoMap = (Map<String, ?>) resourceMap.get(Constants.INFO);
- if (infoMap != null && infoMap.get(Constants.COMMAND_TYPE) != null) {
- schema.setType(infoMap.get(Constants.COMMAND_TYPE).toString());
+ if (infoMap != null && infoMap.get(Constants.INFO_TYPE) != null) {
+ schema.setType(infoMap.get(Constants.INFO_TYPE).toString());
}
+
if (infoMap != null && infoMap.get(Constants.INFO_PRODUCT) != null) {
- schema.setCmdVersion(infoMap.get(Constants.INFO_PRODUCT).toString());
+ schema.setProduct(infoMap.get(Constants.INFO_PRODUCT).toString());
}
- if (resourceMap.get(Constants.HTTP) != null) {
- schema.setHttp("true");
- }
+ schema.setSchemaProfile(identitySchemaProfileType(resourceMap));
+
extSchemas.add(schema);
}
}
}
} catch (IOException e) {
- throw new OnapCommandDiscoveryFailed(EXTERNAL_SCHEMA_DIRECTORY, e);
+ throw new OnapCommandDiscoveryFailed(SCHEMA_DIRECTORY, e);
}
return extSchemas;
}
+ private static String identitySchemaProfileType(Map<String, ?> schemaYamlMap) {
+ if (schemaYamlMap.get(Constants.HTTP) != null) {
+ return Constants.HTTP_SCHEMA_PROFILE;
+ }
+
+ return Constants.BASIC_SCHEMA_PROFILE;
+ }
+
/**
* Returns all resources available under certain directory in class-path.
*
@@ -1704,7 +1703,7 @@ public class OnapCommandUtils {
* @throws OnapCommandInvalidSchema
* exception
*/
- public static Map<String, ?> getExternalSchemaMap(Resource resource) throws OnapCommandInvalidSchema {
+ public static Map<String, ?> loadSchema(Resource resource) throws OnapCommandInvalidSchema {
Map<String, ?> values = null;
try {
values = (Map<String, ?>) new Yaml().load(resource.getInputStream());
@@ -1722,24 +1721,24 @@ public class OnapCommandUtils {
* @throws OnapCommandDiscoveryFailed
* exception
*/
- public static void persist(List<ExternalSchema> schemas) throws OnapCommandDiscoveryFailed {
+ public static void persistSchemaInfo(List<SchemaInfo> schemas) throws OnapCommandDiscoveryFailed {
if (schemas != null) {
try {
Resource[] resources = getExternalResources(DATA_DIRECTORY);
if (resources != null && resources.length == 1) {
String path = resources[0].getURI().getPath();
- File file = new File(path + File.separator + EXTERNAL_DISCOVERY_FILE);
+ File file = new File(path + File.separator + DISCOVERY_FILE);
ObjectMapper mapper = new ObjectMapper();
mapper.writerWithDefaultPrettyPrinter().writeValue(file, schemas);
}
} catch (IOException e1) {
throw new OnapCommandDiscoveryFailed(DATA_DIRECTORY,
- EXTERNAL_DISCOVERY_FILE, e1);
+ DISCOVERY_FILE, e1);
}
}
}
- public static void persistParams(List<Param> params, String profileName) throws OnapCommandPersistProfileFailed {
+ public static void persistProfile(List<Param> params, String profileName) throws OnapCommandPersistProfileFailed {
if (params != null) {
try {
Resource[] resources = getExternalResources(DATA_DIRECTORY);
@@ -1762,17 +1761,17 @@ public class OnapCommandUtils {
* @throws OnapCommandDiscoveryFailed
* exception
*/
- public static boolean isJsonFileDiscovered() throws OnapCommandDiscoveryFailed {
+ public static boolean isAlreadyDiscovered() throws OnapCommandDiscoveryFailed {
Resource resource = null;
try {
- resource = getExternalResource(EXTERNAL_DISCOVERY_FILE,
- DATA_DIRECTORY_JSON_PATTERN);
+ resource = getExternalResource(DISCOVERY_FILE,
+ DATA_PATH_JSON_PATTERN);
if (resource != null) {
return true;
}
} catch (IOException e) {
throw new OnapCommandDiscoveryFailed(DATA_DIRECTORY,
- EXTERNAL_DISCOVERY_FILE, e);
+ DISCOVERY_FILE, e);
}
return false;
@@ -1787,26 +1786,26 @@ public class OnapCommandUtils {
* @throws OnapCommandDiscoveryFailed
* exception
*/
- public static List<ExternalSchema> loadExternalSchemasFromJson() throws OnapCommandException {
- List<ExternalSchema> schemas = new ArrayList<>();
- if (OnapCommandConfg.isDiscoverAlways() || !isJsonFileDiscovered()) {
- schemas = findAllExternalSchemas();
+ public static List<SchemaInfo> discoverOrLoadSchemas() throws OnapCommandException {
+ List<SchemaInfo> schemas = new ArrayList<>();
+ if (OnapCommandConfg.isDiscoverAlways() || !isAlreadyDiscovered()) {
+ schemas = discoverSchemas();
if (!schemas.isEmpty()) {
- persist(schemas);
+ persistSchemaInfo(schemas);
}
} else {
try {
- Resource resource = getExternalResource(EXTERNAL_DISCOVERY_FILE,
- DATA_DIRECTORY_JSON_PATTERN);
+ Resource resource = getExternalResource(DISCOVERY_FILE,
+ DATA_PATH_JSON_PATTERN);
if (resource != null) {
File file = new File(resource.getURI().getPath());
ObjectMapper mapper = new ObjectMapper();
- ExternalSchema[] list = mapper.readValue(file, ExternalSchema[].class);
+ SchemaInfo[] list = mapper.readValue(file, SchemaInfo[].class);
schemas.addAll(Arrays.asList(list));
}
} catch (IOException e) {
throw new OnapCommandDiscoveryFailed(DATA_DIRECTORY,
- EXTERNAL_DISCOVERY_FILE, e);
+ DISCOVERY_FILE, e);
}
}
@@ -1818,7 +1817,7 @@ public class OnapCommandUtils {
try {
Resource resource = getExternalResource(profileName + ".json",
- DATA_DIRECTORY_JSON_PATTERN);
+ DATA_PATH_JSON_PATTERN);
if (resource != null) {
File file = new File(resource.getURI().getPath());
ObjectMapper mapper = new ObjectMapper();
@@ -1843,12 +1842,12 @@ public class OnapCommandUtils {
* @throws OnapCommandDiscoveryFailed
* exception
*/
- public static ExternalSchema loadExternalSchemaFromJson(String cmd, String version) throws OnapCommandException {
- List<ExternalSchema> list = loadExternalSchemasFromJson();
- ExternalSchema schemaStr = null;
+ public static SchemaInfo getSchemaInfo(String cmd, String version) throws OnapCommandException {
+ List<SchemaInfo> list = discoverOrLoadSchemas();
+ SchemaInfo schemaStr = null;
if (list != null) {
- for (ExternalSchema schema : list) {
- if (cmd.equals(schema.getCmdName()) && version.equals(schema.getCmdVersion())) {
+ for (SchemaInfo schema : list) {
+ if (cmd.equals(schema.getCmdName()) && version.equals(schema.getProduct())) {
schemaStr = schema;
break;
}
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/ExternalSchema.java b/framework/src/main/java/org/onap/cli/fw/utils/SchemaInfo.java
index 16675c26..462fcceb 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/ExternalSchema.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/SchemaInfo.java
@@ -17,16 +17,38 @@
package org.onap.cli.fw.utils;
import org.onap.cli.fw.cmd.CommandType;
+import org.onap.cli.fw.conf.Constants;
-public class ExternalSchema {
+import com.fasterxml.jackson.annotation.JsonIgnore;
+/**
+ * SchemaInfo is used in discovery caching.
+ *
+ */
+public class SchemaInfo {
+
+ /**
+ * Name of the schema file name
+ */
private String schemaName;
+
+ /**
+ * Schema location in complete path
+ */
private String schemaURI;
+
private String cmdName;
- private String cmdVersion;
+
+ private String product;
+
+ /**
+ * OCS version
+ */
private String version;
+
private String type = CommandType.CMD.name();
- private String http = "false";
+
+ private String schemaProfile = Constants.BASIC_SCHEMA_PROFILE;
public String getSchemaName() {
return schemaName;
@@ -52,12 +74,12 @@ public class ExternalSchema {
this.version = version;
}
- public String getCmdVersion() {
- return cmdVersion;
+ public String getProduct() {
+ return product;
}
- public void setCmdVersion(String cmdVersion) {
- this.cmdVersion = cmdVersion;
+ public void setProduct(String cmdVersion) {
+ this.product = cmdVersion;
}
public String getSchemaURI() {
@@ -68,16 +90,17 @@ public class ExternalSchema {
this.schemaURI = schemaURI;
}
- public String getHttp() {
- return http;
+ public String getSchemaProfile() {
+ return schemaProfile;
}
- public void setHttp(String internal) {
- this.http = internal;
+ public void setSchemaProfile(String internal) {
+ this.schemaProfile = internal;
}
+ @JsonIgnore
public boolean isHttp() {
- return this.getHttp().equals("true");
+ return this.getSchemaProfile().equals(Constants.HTTP_SCHEMA_PROFILE);
}
public String getType() {