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;
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;
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());
}
// -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());
// -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);
}
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;
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;
* 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);
}
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
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());
+ }
}
}
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 {
}
}
- 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.
*
* 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)
*
* @return
*/
- String schema();
+ String schema() default "";
+
+ /**
+ * Schema type
+ */
+ String type() default "";
}
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;
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;
* Oclip Command.
*
*/
+@OnapCommandSchema(type = Constants.HTTP_SCHEMA_PROFILE)
public class OnapHttpCommand extends OnapCommand {
private HttpInput input = new HttpInput();
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";
}
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;
*/
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;
}
/**
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() {
this.schemaProfile = internal;
}
- @JsonIgnore
- public boolean isHttp() {
- return this.getSchemaProfile().equals(Constants.HTTP_SCHEMA_PROFILE);
- }
-
public String getType() {
return type;
}
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
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
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
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>'
import java.net.URL;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandHelpFailed;
}
}
- @Test
- public void registerTest() throws OnapCommandException {
- OnapCommand test = new OnapCommandTest();
- Class<OnapCommand> cmd = (Class<OnapCommand>) test.getClass();
- registerar.register("Test", "open-cli", cmd);
- OnapCommand cc = registerar.get("Test");
- assertTrue(cmd == cc.getClass());
-
- }
-
- @Test
- public void cmdTestSchema() throws OnapCommandException {
- OnapCommand test = new OnapCommandTest();
- Class<OnapCommand> cmd = (Class<OnapCommand>) test.getClass();
- registerar.register("Test", "open-cli", cmd);
- OnapCommand cc = registerar.get("Test");
- }
-
@Test
public void oclipCommandNotFoundTest() throws OnapCommandException {
try {
}
}
- @Test
- public void oclipCommandRegistrationFailedTest() throws OnapCommandException {
-
- @OnapCommandSchema(schema = "sample-test-schema.yaml")
- class Test extends OnapCommand {
-
- @Override
- protected void run() throws OnapCommandException {
-
- }
-
- }
-
- OnapCommand com = new Test();
- Class<OnapCommand> cmd = (Class<OnapCommand>) com.getClass();
- try {
- registerar.register("Test2", "open-cli", cmd);
- registerar.get("Test2");
- fail("This should have thrown an exception");
- } catch (OnapCommandRegistrationFailed e) {
- assertEquals("0x2002", e.getErrorCode());
- }
- }
-
- @Test(expected = OnapCommandHelpFailed.class)
- public void helpTestException() throws OnapCommandException {
- OnapCommand test = new OnapCommandTest1();
- Class<OnapCommand> cmd = (Class<OnapCommand>) test.getClass();
- registerar = new OnapCommandRegistrar();
- registerar.register("test1", "open-cli", cmd);
- String help = registerar.getHelp();
- assertNotNull(help);
- }
-
@Test
public void helpTest() throws OnapCommandException {
String help = registerar.getHelp();
import static org.junit.Assert.fail;
+import org.junit.Before;
import org.junit.Test;
import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.OnapCommandRegistrar;
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.OnapCommandProductVersionInvalid;
public class OnapAuthClientCommandBasedTest {
+ @Before
+ public void setup() throws OnapCommandProductVersionInvalid, OnapCommandException {
+ OnapCommandRegistrar.getRegistrar().setEnabledProductVersion(OnapCommandConfg.getProductName());
+ }
+
@Test
public void internalCommandTest() {
try {
cmd.execute();
} catch (OnapCommandException e) {
fail("Internal command failed to run");
- e.printStackTrace();
+ e.printStackTrace(System.out);
}
}
cmd.execute();
} catch (OnapCommandException e) {
fail("External command Yes Auth Yes Catalog failed to run");
- e.printStackTrace();
+ e.printStackTrace(System.out);
}
}
cmd.execute();
} catch (OnapCommandException e) {
- fail("External command Yes Auth No Catalog failed to run");
- e.printStackTrace();
+ fail("External command Yes Auth No Catalog failed to run " + e.getMessage());
+ e.printStackTrace(System.out);
}
}
cmd.execute();
} catch (OnapCommandException e) {
fail("External command Yes Auth No Catalog failed to run");
- e.printStackTrace();
+ e.printStackTrace(System.out);
}
}
cmd.execute();
} catch (OnapCommandException e) {
fail("External command No Auth No Catalog failed to run");
- e.printStackTrace();
+ e.printStackTrace(System.out);
}
}
@Test
public void findOnapCommandsTest() {
List<Class<OnapCommand>> cmds = OnapCommandUtils.discoverCommandPlugins();
- assertTrue(cmds.size() == 6);
+ assertTrue(cmds.size() == 7);
}
@Test
try {
if ((args.size() == 1) && (this.getLongOption(OnapCliConstants.PARAM_HELP_LOGN).equals(args.get(0))
|| this.getShortOption(OnapCliConstants.PARAM_HELP_SHORT).equals(args.get(0)))) {
- this.print(IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("onap-readme.txt")));
+ this.print(IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("oclip-readme.txt")));
String help = OnapCommandRegistrar.getRegistrar().getHelp();
this.print(help);
this.exitSuccessfully();
private static final long serialVersionUID = -6362824415803063442L;
public OnapCliArgumentValueMissing(String arg) {
- super("0x7001", "Value for argument " + arg + " is missing");
+ super("0x7101", "Value for argument " + arg + " is missing");
}
}
public class OnapCliInvalidArgument extends OnapCommandException {
private static final long serialVersionUID = -1438492553530993246L;
- private static final String ERROR_CODE = "0x7000";
+ private static final String ERROR_CODE = "0x7102";
private static final String ERROR_MESSAGE1 = "Invalid argument ";
public OnapCliInvalidArgument(String arg) {
@Test
public void onapCliArgumentValueMissingTest() {
OnapCliArgumentValueMissing failed = new OnapCliArgumentValueMissing("Argument value missing");
- assertEquals("0x7001::Value for argument Argument value missing is missing", failed.getMessage());
+ assertEquals("0x7101::Value for argument Argument value missing is missing", failed.getMessage());
}
@Test
public void onapCliInvalidArgumentTest() {
OnapCliInvalidArgument failed = new OnapCliInvalidArgument("Invalid Argument");
- assertEquals("0x7000::Invalid argument Invalid Argument", failed.getMessage());
+ assertEquals("0x7102::Invalid argument Invalid Argument", failed.getMessage());
failed = new OnapCliInvalidArgument("Invalid Argument", new Exception(""));
- assertEquals("0x7000::Invalid argument Invalid Argument , ", failed.getMessage());
+ assertEquals("0x7102::Invalid argument Invalid Argument , ", failed.getMessage());
}
}