diff options
Diffstat (limited to 'framework/src/main')
10 files changed, 66 insertions, 75 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 89c62207..87c1ba74 100644 --- a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java +++ b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java @@ -19,12 +19,8 @@ package org.onap.cli.fw; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Optional; -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; import org.onap.cli.fw.error.OnapCommandHelpFailed; import org.onap.cli.fw.error.OnapCommandInvalidParameterType; @@ -33,7 +29,6 @@ import org.onap.cli.fw.error.OnapCommandInvalidResultAttributeScope; import org.onap.cli.fw.error.OnapCommandInvalidSchema; import org.onap.cli.fw.error.OnapCommandInvalidSchemaVersion; import org.onap.cli.fw.error.OnapCommandNotInitialized; -import org.onap.cli.fw.error.OnapCommandParameterMissing; import org.onap.cli.fw.error.OnapCommandParameterNameConflict; import org.onap.cli.fw.error.OnapCommandParameterOptionConflict; import org.onap.cli.fw.error.OnapCommandRegistrationFailed; @@ -198,7 +193,7 @@ public abstract class OnapCommand { Map<String, OnapCommandParameter> paramMap = this.getParametersMap(); // -h or --help is always higher precedence !, user can set this value to get help message - if ("true".equals(paramMap.get(Constants.DEFAULT_PARAMETER_HELP).getValue())) { + if (Constants.BOOLEAN_TRUE.equals(paramMap.get(Constants.DEFAULT_PARAMETER_HELP).getValue())) { OnapCommandResult result = new OnapCommandResult(); result.setType(ResultType.TEXT); result.setOutput(this.printHelp()); @@ -206,7 +201,7 @@ public abstract class OnapCommand { } // -v or --version is next higher precedence !, user can set this value to get help message - if ("true".equals(paramMap.get(Constants.DEFAULT_PARAMETER_VERSION).getValue())) { + if (Constants.BOOLEAN_TRUE.equals(paramMap.get(Constants.DEFAULT_PARAMETER_VERSION).getValue())) { OnapCommandResult result = new OnapCommandResult(); result.setType(ResultType.TEXT); result.setOutput(this.printVersion()); @@ -219,16 +214,16 @@ public abstract class OnapCommand { // -f or --format this.cmdResult.setType( ResultType.get(paramMap.get(Constants.DEFAULT_PARAMETER_OUTPUT_FORMAT).getValue().toString())); - if ("true".equals(paramMap.get(Constants.DEFAULT_PARAMETER_OUTPUT_ATTR_LONG).getValue())) { + if (Constants.BOOLEAN_TRUE.equals(paramMap.get(Constants.DEFAULT_PARAMETER_OUTPUT_ATTR_LONG).getValue())) { this.cmdResult.setScope(OnapCommandResultAttributeScope.LONG); } // --no-title - if ("true".equals(paramMap.get(Constants.DEFAULT_PARAMETER_OUTPUT_NO_TITLE).getValue())) { + if (Constants.BOOLEAN_TRUE.equals(paramMap.get(Constants.DEFAULT_PARAMETER_OUTPUT_NO_TITLE).getValue())) { this.cmdResult.setIncludeTitle(false); } // --debug - if ("true".equals(paramMap.get(Constants.DEFAULT_PARAMETER_DEBUG).getValue())) { + if (Constants.BOOLEAN_TRUE.equals(paramMap.get(Constants.DEFAULT_PARAMETER_DEBUG).getValue())) { this.cmdResult.setDebug(true); } 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 1d2c5166..f42f68f9 100644 --- a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java +++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java @@ -19,7 +19,6 @@ package org.onap.cli.fw; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.net.URISyntaxException; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -27,7 +26,6 @@ import java.util.Map; import java.util.Set; import org.apache.commons.io.IOUtils; -import org.onap.cli.fw.cmd.OnapHttpCommand; import org.onap.cli.fw.conf.Constants; import org.onap.cli.fw.conf.OnapCommandConfg; import org.onap.cli.fw.error.OnapCommandException; @@ -101,7 +99,7 @@ public class OnapCommandRegistrar { * Invalid registration exception * @throws OnapCommandRegistrationProductInfoMissing */ - public void register(String name, String version, Class<? extends OnapCommand> cmd) throws OnapCommandInvalidRegistration, OnapCommandRegistrationProductInfoMissing { + private void register(String name, String version, Class<? extends OnapCommand> cmd) throws OnapCommandInvalidRegistration, OnapCommandRegistrationProductInfoMissing { if (version == null || version.isEmpty()) { throw new OnapCommandRegistrationProductInfoMissing(name); } @@ -210,12 +208,7 @@ public class OnapCommandRegistrar { Constructor<?> constr = cls.getConstructor(); cmd = (OnapCommand) constr.newInstance(); - String schemaName; - if (cmd.getClass().equals(OnapHttpCommand.class)) { // NOSONAR - schemaName = OnapCommandUtils.getSchemaInfo(cmdName, version).getSchemaName(); - } else { - schemaName = this.getSchemaFileName(cls); - } + String schemaName = OnapCommandUtils.getSchemaInfo(cmdName, version).getSchemaName(); cmd.initializeSchema(schemaName); } catch (OnapCommandException | NoSuchMethodException | SecurityException | InstantiationException @@ -233,7 +226,13 @@ public class OnapCommandRegistrar { for (Class<OnapCommand> cmd : cmds) { if (cmd.isAnnotationPresent(OnapCommandSchema.class)) { OnapCommandSchema ano = cmd.getAnnotation(OnapCommandSchema.class); - map.put(ano.schema(), cmd); + if (ano.schema() != null && !ano.schema().isEmpty()) { + map.put(ano.schema(), cmd); + } else if (ano.type() != null && !ano.type().isEmpty()) { + map.put(ano.type(), cmd); + } else { + throw new OnapUnsupportedSchemaProfile(ano.schema()); + } } } @@ -246,8 +245,8 @@ public class OnapCommandRegistrar { Map<String, Class<OnapCommand>> plugins = this.autoDiscoverCommandPlugins(); for (SchemaInfo schema : schemas) { - if (schema.isHttp()) { - this.register(schema.getCmdName(), schema.getProduct(), OnapHttpCommand.class); + if (plugins.containsKey(schema.getSchemaProfile())) { + this.register(schema.getCmdName(), schema.getProduct(), plugins.get(schema.getSchemaProfile())); } else if (plugins.containsKey(schema.getSchemaName())) { this.register(schema.getCmdName(), schema.getProduct(), plugins.get(schema.getSchemaName())); } else { @@ -256,11 +255,6 @@ public class OnapCommandRegistrar { } } - private String getSchemaFileName(Class<? extends OnapCommand> cmd) { - OnapCommandSchema ano = (OnapCommandSchema) cmd.getAnnotation(OnapCommandSchema.class); - return ano.schema(); - } - /** * Helps to find the Oclip CLI version, could be used with --version or -v option. * 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 16b53ea6..d5f71044 100644 --- a/framework/src/main/java/org/onap/cli/fw/OnapCommandSchema.java +++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandSchema.java @@ -26,7 +26,7 @@ import java.lang.annotation.RetentionPolicy; * default if the schema declaration is missing for a command abc-create, schema file name could be * abc-create-schema.yaml, corresponding command would like as below * - * @OnapCommandSchema(name="abc-create", schema="onap-abc-create-schema.yaml") public class AbcCreate extends + * @OnapCommandSchema(type="http", schema="onap-abc-create-schema.yaml") public class AbcCreate extends * OnapCommand { ... } */ @Retention(RetentionPolicy.RUNTIME) @@ -37,5 +37,10 @@ public @interface OnapCommandSchema { * * @return */ - String schema(); + String schema() default ""; + + /** + * Schema type + */ + String type() default ""; } 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 198affbc..7ff38b64 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 @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; import org.onap.cli.fw.OnapCommand; +import org.onap.cli.fw.OnapCommandSchema; import org.onap.cli.fw.ad.OnapAuthClient; import org.onap.cli.fw.ad.OnapService; import org.onap.cli.fw.conf.Constants; @@ -32,7 +33,6 @@ import org.onap.cli.fw.error.OnapCommandExecutionFailed; import org.onap.cli.fw.error.OnapCommandFailedMocoGenerate; import org.onap.cli.fw.http.HttpInput; import org.onap.cli.fw.http.HttpResult; -import org.onap.cli.fw.input.OnapCommandParameter; import org.onap.cli.fw.output.OnapCommandResultAttribute; import org.onap.cli.fw.utils.OnapCommandUtils; import org.onap.cli.http.mock.MockJsonGenerator; @@ -43,6 +43,7 @@ import org.onap.cli.http.mock.MockResponse; * Oclip Command. * */ +@OnapCommandSchema(type = Constants.HTTP_SCHEMA_PROFILE) public class OnapHttpCommand extends OnapCommand { private HttpInput input = new HttpInput(); 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 bd416446..248ea068 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 @@ -28,26 +28,26 @@ public class Constants { 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"; - public static final String SERVICE_PARAMS_MANDATORY_LIST ="cli.schema.service_params_mandatory_list"; - public static final String INFO_PARAMS_LIST ="cli.schema.info_params_list"; - public static final String INFO_PARAMS_MANDATORY_LIST ="cli.schema.info_params_mandatory_list"; - public static final String INPUT_PARAMS_LIST ="cli.schema.input_params_list"; - public static final String INPUT_PARAMS_MANDATORY_LIST ="cli.schema.input_params_mandatory_list"; - public static final String RESULT_PARAMS_LIST ="cli.schema.result_params_list"; - public static final String RESULT_PARAMS_MANDATORY_LIST ="cli.schema.result_params_mandatory_list"; - public static final String HTTP_SECTIONS ="cli.schema.http_sections"; - public static final String HTTP_MANDATORY_SECTIONS ="cli.schema.http_mandatory_sections"; - public static final String HTTP_REQUEST_PARAMS ="cli.schema.http_request_params"; - public static final String HTTP_REQUEST_MANDATORY_PARAMS ="cli.schema.http_request_mandatory_params"; - public static final String HTTP_METHODS ="cli.schema.http_methods"; - public static final String BOOLEAN_VALUE ="cli.schema.boolean_values"; - public static final String AUTH_VALUES="cli.schema.auth_values"; - public static final String MODE_VALUES="cli.schema.mode_values"; - public static final String COMMAND_TYPE_VALUES="cli.command.type"; - + 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"; + public static final String SERVICE_PARAMS_MANDATORY_LIST = "cli.schema.service_params_mandatory_list"; + public static final String INFO_PARAMS_LIST = "cli.schema.info_params_list"; + public static final String INFO_PARAMS_MANDATORY_LIST = "cli.schema.info_params_mandatory_list"; + public static final String INPUT_PARAMS_LIST = "cli.schema.input_params_list"; + public static final String INPUT_PARAMS_MANDATORY_LIST = "cli.schema.input_params_mandatory_list"; + public static final String RESULT_PARAMS_LIST = "cli.schema.result_params_list"; + public static final String RESULT_PARAMS_MANDATORY_LIST = "cli.schema.result_params_mandatory_list"; + public static final String HTTP_SECTIONS = "cli.schema.http_sections"; + public static final String HTTP_MANDATORY_SECTIONS = "cli.schema.http_mandatory_sections"; + public static final String HTTP_REQUEST_PARAMS = "cli.schema.http_request_params"; + public static final String HTTP_REQUEST_MANDATORY_PARAMS = "cli.schema.http_request_mandatory_params"; + public static final String HTTP_METHODS = "cli.schema.http_methods"; + public static final String BOOLEAN_VALUE = "cli.schema.boolean_values"; + public static final String AUTH_VALUES = "cli.schema.auth_values"; + public static final String MODE_VALUES = "cli.schema.mode_values"; + public static final String COMMAND_TYPE_VALUES = "cli.command.type"; + public static final String SCHEMA_TYPES_SUPPORTED = "cli.schema.type.supported"; //http connection public static final String SSLCONTEST_TLS = "TLSV1.2"; public static final String APPLICATION_JSON = "application/json"; 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 ca708274..0f64ed3a 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 @@ -1658,8 +1658,11 @@ public class OnapCommandUtils { } private static String identitySchemaProfileType(Map<String, ?> schemaYamlMap) { - if (schemaYamlMap.get(Constants.HTTP) != null) { - return Constants.HTTP_SCHEMA_PROFILE; + + for (String schemeType : OnapCommandConfg.getSchemaAttrInfo(Constants.SCHEMA_TYPES_SUPPORTED)) { + if (schemaYamlMap.get(schemeType) != null) { + return schemeType; + } } return Constants.BASIC_SCHEMA_PROFILE; @@ -1852,16 +1855,16 @@ public class OnapCommandUtils { */ public static SchemaInfo getSchemaInfo(String cmd, String version) throws OnapCommandException { List<SchemaInfo> list = discoverOrLoadSchemas(); - SchemaInfo schemaStr = null; + SchemaInfo schemaInfo = null; if (list != null) { for (SchemaInfo schema : list) { if (cmd.equals(schema.getCmdName()) && version.equals(schema.getProduct())) { - schemaStr = schema; + schemaInfo = schema; break; } } } - return schemaStr; + return schemaInfo; } /** diff --git a/framework/src/main/java/org/onap/cli/fw/utils/SchemaInfo.java b/framework/src/main/java/org/onap/cli/fw/utils/SchemaInfo.java index 462fcceb..85d6b1f8 100644 --- a/framework/src/main/java/org/onap/cli/fw/utils/SchemaInfo.java +++ b/framework/src/main/java/org/onap/cli/fw/utils/SchemaInfo.java @@ -19,35 +19,33 @@ package org.onap.cli.fw.utils; import org.onap.cli.fw.cmd.CommandType; import org.onap.cli.fw.conf.Constants; -import com.fasterxml.jackson.annotation.JsonIgnore; - /** * SchemaInfo is used in discovery caching. * */ public class SchemaInfo { - /** - * Name of the schema file name - */ + /** + * Name of the schema file name + */ private String schemaName; - + /** * Schema location in complete path */ private String schemaURI; - + private String cmdName; - + private String product; - + /** * OCS version */ private String version; - + private String type = CommandType.CMD.name(); - + private String schemaProfile = Constants.BASIC_SCHEMA_PROFILE; public String getSchemaName() { @@ -98,11 +96,6 @@ public class SchemaInfo { this.schemaProfile = internal; } - @JsonIgnore - public boolean isHttp() { - return this.getSchemaProfile().equals(Constants.HTTP_SCHEMA_PROFILE); - } - public String getType() { return type; } diff --git a/framework/src/main/resources/META-INF/services/org.onap.cli.fw.OnapCommand b/framework/src/main/resources/META-INF/services/org.onap.cli.fw.OnapCommand index e29c2c28..1993bcb6 100644 --- a/framework/src/main/resources/META-INF/services/org.onap.cli.fw.OnapCommand +++ b/framework/src/main/resources/META-INF/services/org.onap.cli.fw.OnapCommand @@ -3,3 +3,4 @@ org.onap.cli.fw.cmd.OnapSchemaRefreshCommand org.onap.cli.fw.cmd.BasicAuthLoginCommand org.onap.cli.fw.cmd.BasicAuthLogoutCommand org.onap.cli.fw.cmd.CatalogCommand +org.onap.cli.fw.cmd.OnapHttpCommand
\ No newline at end of file diff --git a/framework/src/main/resources/open-cli.properties b/framework/src/main/resources/open-cli.properties index 84a4736e..757b0259 100644 --- a/framework/src/main/resources/open-cli.properties +++ b/framework/src/main/resources/open-cli.properties @@ -34,7 +34,6 @@ cli.schema.auth_values=none,basic cli.schema.mode_values=direct,catalog cli.command.type=cmd,auth,catalog -<<<<<<< 5301969fc26714a8494882027116282898278f32:framework/src/main/resources/onap.properties #product version cli.product.version=cli-1.0 @@ -42,5 +41,5 @@ cli.product.version=cli-1.0 cli.sample.gen.enable=false cli.sample.gen.target=. -======= ->>>>>>> Migrate onap-cli-schema into open-cli-schema:framework/src/main/resources/open-cli.properties +# mrkanag Move this to db, once exteranl command registration is supported in place of discovery +cli.schema.type.supported=http diff --git a/framework/src/main/resources/version.info b/framework/src/main/resources/version.info index 34f4d969..fc959d19 100644 --- a/framework/src/main/resources/version.info +++ b/framework/src/main/resources/version.info @@ -2,6 +2,6 @@ CLI version : __VERSION__ Available products: __AVAILABLE_PRODUCT_VERSIONS__ Enabled product : __ENABLED_PRODUCT_VERSIONS__ -To enable a product , use one of following methods: +To enable a product, use one of following methods: 1. In scripting mode, Set environment variable OPEN_CLI_PRODUCT_IN_USE 2. In interactive mode, set the directive 'use <product>' |