diff options
13 files changed, 128 insertions, 24 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java index 09e1927a..5479b51b 100644 --- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java +++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java @@ -35,6 +35,8 @@ import org.onap.cli.fw.output.OnapCommandResultType; import org.onap.cli.fw.schema.OnapCommandSchemaLoader; import org.onap.cli.fw.utils.OnapCommandHelperUtils; import org.onap.cli.fw.utils.OnapCommandUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Oclip Command. @@ -42,6 +44,8 @@ import org.onap.cli.fw.utils.OnapCommandUtils; */ public abstract class OnapCommand { + private static Logger LOG = LoggerFactory.getLogger(OnapCommand.class); + private String cmdDescription; private String cmdName; @@ -127,7 +131,7 @@ public abstract class OnapCommand { this.setSchemaName(schema); List<String> errors = OnapCommandSchemaLoader.loadSchema(this, schema, true, validate); - errors.addAll(this.initializeProfileSchema()); + errors.addAll(this.initializeProfileSchema(validate)); this.isInitialzied = true; return errors; @@ -135,7 +139,7 @@ public abstract class OnapCommand { /** * Any additional profile based such as http schema could be initialized. */ - protected List<String> initializeProfileSchema() throws OnapCommandException { + protected List<String> initializeProfileSchema(boolean validate) throws OnapCommandException { return new ArrayList<>(); } @@ -162,8 +166,12 @@ public abstract class OnapCommand { throw new OnapCommandNotInitialized(this.getClass().getName()); } + LOG.info("CMD: " + this.getName()); + Map<String, OnapCommandParameter> paramMap = this.getParametersMap(); + LOG.info("INPUT: " + paramMap); + // -h or --help is always higher precedence !, user can set this value to get help message if (OnapCommandConstants.BOOLEAN_TRUE.equals(paramMap.get(OnapCommandConstants.DEFAULT_PARAMETER_HELP).getValue())) { this.cmdResult.setType(OnapCommandResultType.TEXT); @@ -208,6 +216,8 @@ public abstract class OnapCommand { this.run(); + LOG.info("OUTPUT: " + this.cmdResult.getRecords()); + return this.cmdResult; } diff --git a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java index 6f911c29..3b2188f3 100644 --- a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java +++ b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java @@ -67,6 +67,7 @@ public class OnapCommandConstants { public static final String DEFAULT_VALUE = "default_value"; public static final String IS_SECURED = "is_secured"; public static final String IS_INCLUDE = "is_include"; + public static final String IS_DEFAULT_PARAM = "is_default_param"; public static final String PARAMETER_TYPE_JSON = "json"; public static final String PARAMETER_TYPE_YAML = "yaml"; @@ -84,6 +85,7 @@ public class OnapCommandConstants { public static final String DEFAULT_PARAMETER_DEBUG = "debug"; public static final String DEFAULT_PARAMETER_OUTPUT_FORMAT = "format"; public static final String DEFAULT_PARAMETER_OUTPUT_ATTR_LONG = "long"; + public static final String DEFAULT_PARAMETER_OUTPUT_NO_TITLE = "no-title"; //results @@ -98,6 +100,7 @@ public class OnapCommandConstants { public static final String SCOPE = "scope"; public static final String RESULT_SCOPE_SHORT = "short"; public static final String RESULT_SCOPE_LONG = "long"; + public static final String IS_DEFAULT_ATTR = "is_default_attr"; //print public static final String PORTRAINT_COLUMN_NAME_PROPERTY = "property"; diff --git a/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java b/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java index 4b21ed4f..00a93725 100644 --- a/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java +++ b/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java @@ -98,6 +98,19 @@ public class OnapCommandParameter { */ private boolean isInclude = true; + /* + * This param is from The default input parameters file + */ + private boolean isDefaultParam = false; + + public boolean isDefaultParam() { + return isDefaultParam; + } + + public void setDefaultParam(boolean isDefaultParam) { + this.isDefaultParam = isDefaultParam; + } + public String getName() { return cmdName; } @@ -321,4 +334,9 @@ public class OnapCommandParameter { return false; return true; } + + @Override + public String toString() { + return this.getName() + ": " + this.getValue(); + } } diff --git a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultAttribute.java b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultAttribute.java index 1208a3cd..76af42d7 100644 --- a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultAttribute.java +++ b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultAttribute.java @@ -57,6 +57,19 @@ public class OnapCommandResultAttribute { private boolean isSecured = false; + /* + * This attr is from The default input parameters file + */ + private boolean isDefaultAttr = false; + + public boolean isDefaultAttr() { + return isDefaultAttr; + } + + public void setDefaultAttr(boolean isDefaultAttr) { + this.isDefaultAttr = isDefaultAttr; + } + public void setValues(List<String> values) { if (values != null) { this.values = values; @@ -86,6 +99,11 @@ public class OnapCommandResultAttribute { return values; } + public void resetValues(String value) { + this.values.clear(); + this.values.add(value); + } + public OnapCommandResultAttributeScope getScope() { return outScope; } @@ -118,4 +136,8 @@ public class OnapCommandResultAttribute { this.defaultValue = defaultValue; } + @Override + public String toString() { + return this.getName() + ": " + this.getValues(); + } } diff --git a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java index 28597443..0c4af809 100644 --- a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java +++ b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java @@ -36,6 +36,8 @@ import static org.onap.cli.fw.conf.OnapCommandConstants.INPUT_PARAMS_MANDATORY_L import static org.onap.cli.fw.conf.OnapCommandConstants.IS_INCLUDE; import static org.onap.cli.fw.conf.OnapCommandConstants.IS_OPTIONAL; import static org.onap.cli.fw.conf.OnapCommandConstants.IS_SECURED; +import static org.onap.cli.fw.conf.OnapCommandConstants.IS_DEFAULT_ATTR; +import static org.onap.cli.fw.conf.OnapCommandConstants.IS_DEFAULT_PARAM; import static org.onap.cli.fw.conf.OnapCommandConstants.LONG_OPTION; import static org.onap.cli.fw.conf.OnapCommandConstants.NAME; import static org.onap.cli.fw.conf.OnapCommandConstants.OPEN_CLI_SCHEMA_VERSION; @@ -384,6 +386,21 @@ public class OnapCommandSchemaLoader { param.setInclude(false); } break; + + case IS_DEFAULT_PARAM: + if (validate) { + if (!OnapCommandUtils.validateBoolean(String.valueOf(parameter.get(key2)))) { + exceptionList.add(OnapCommandUtils.invalidBooleanValueMessage(parameter.get(NAME), + IS_DEFAULT_PARAM, parameter.get(key2))); + } + } + + if (BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))) { + param.setDefaultParam(true); + } else { + param.setDefaultParam(false); + } + break; } } @@ -399,14 +416,13 @@ public class OnapCommandSchemaLoader { case RESULTS: Map<String, ?> valueMap = (Map<String, ?>) values.get(key); if (valueMap != null) { - OnapCommandResult result = new OnapCommandResult(); for (Map.Entry<String, ?> entry1 : valueMap.entrySet()) { String key3 = entry1.getKey(); switch (key3) { case DIRECTION: try { - result.setPrintDirection(OnapCommandPrintDirection.get((String) valueMap.get(key3))); + cmd.getResult().setPrintDirection(OnapCommandPrintDirection.get((String) valueMap.get(key3))); } catch (OnapCommandException ex) { OnapCommandUtils.throwOrCollect(ex, exceptionList, validate); } @@ -477,15 +493,28 @@ public class OnapCommandSchemaLoader { attr.setSecured(false); } break; + + case IS_DEFAULT_ATTR: + if (validate) { + if (!OnapCommandUtils.validateBoolean(String.valueOf(map.get(key4)))) { + exceptionList.add(OnapCommandUtils.invalidBooleanValueMessage(ATTRIBUTES, + IS_DEFAULT_ATTR, map.get(key4))); + } + } + if (BOOLEAN_TRUE.equals(String.valueOf(map.get(key4)))) { + attr.setDefaultAttr(true); + } else { + attr.setDefaultAttr(false); + } + break; } } - result.getRecords().add(attr); + cmd.getResult().getRecords().add(attr); } break; } } - cmd.setResult(result); } break; } diff --git a/framework/src/main/resources/log4j.properties b/framework/src/main/resources/log4j.properties index 419faf30..d27b1d60 100644 --- a/framework/src/main/resources/log4j.properties +++ b/framework/src/main/resources/log4j.properties @@ -2,7 +2,7 @@ log4j.rootLogger=ALL, file # Redirect log messages to a log file, support file rolling. log4j.appender.file=org.apache.log4j.RollingFileAppender -log4j.appender.file.File=${OPEN_CLI_HOME}/logs/oclip.log +log4j.appender.file.File=${OPEN_CLI_HOME}/logs/open-cli.log log4j.appender.file.MaxFileSize=5MB log4j.appender.file.MaxBackupIndex=10 log4j.appender.file.layout=org.apache.log4j.PatternLayout diff --git a/framework/src/main/resources/open-cli-schema/default_input_parameters.yaml b/framework/src/main/resources/open-cli-schema/default_input_parameters.yaml index 02e8a717..44c71e53 100644 --- a/framework/src/main/resources/open-cli-schema/default_input_parameters.yaml +++ b/framework/src/main/resources/open-cli-schema/default_input_parameters.yaml @@ -12,33 +12,39 @@ parameters: short_option: h long_option: help default_value: false + is_default_param: true - name: version type: bool description: print service version short_option: v long_option: version default_value: false + is_default_param: true - name: debug type: bool description: Enable debug output short_option: d long_option: debug default_value: false + is_default_param: true - name: format type: string description: Output formats, supported formats such as table, csv, json, yaml short_option: f long_option: format default_value: table + is_default_param: true - name: long type: bool description: whether to print all attributes or only short attributes short_option: s long_option: long default_value: false + is_default_param: true - name: no-title type: bool description: whether to print title or not short_option: t long_option: no-title - default_value: false
\ No newline at end of file + default_value: false + is_default_param: true
\ 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 4971269f..0e8b2af5 100644 --- a/framework/src/main/resources/open-cli.properties +++ b/framework/src/main/resources/open-cli.properties @@ -9,7 +9,7 @@ cli.schema.top_level_mandatory_list=open_cli_schema_version cli.schema.info_params_list=product,service,type,author,ignore cli.schema.info_params_mandatory_list=product,service -cli.schema.input_params_list=name,description,type,short_option,long_option, is_optional,default_value,is_secured,is_include +cli.schema.input_params_list=name,description,type,short_option,long_option, is_optional,default_value,is_secured,is_include,is_default_param cli.schema.input_params_mandatory_list=name,description,type cli.schema.result_params_list=name,description,scope,type,is_secured, default_value diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java b/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java index 4b1752af..aa1368ec 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java @@ -116,7 +116,7 @@ public class OnapCommandHttpAuthClient { if (cmd.getService().isModeDirect()){ return cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_HOST_URL).getValue().toString(); } else { //Catalog mode - OnapCommand catalog = OnapCommandRegistrar.getRegistrar().get("catalog"); + OnapCommand catalog = OnapCommandRegistrar.getRegistrar().get("catalog", cmd.getInfo().getProduct()); Map<String, String> paramsOverrides = new HashMap<>(); paramsOverrides.put(OnapCommandHttpConstants.CATALOG_SERVICE_NAME, cmd.getService().getName()); diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java index 7178be81..12309341 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java @@ -102,8 +102,8 @@ public class OnapHttpCommand extends OnapCommand { } @Override - protected List<String> initializeProfileSchema() throws OnapCommandException { - return OnapCommandSchemaHttpLoader.loadHttpSchema(this, this.getSchemaName(), true, false); + protected List<String> initializeProfileSchema(boolean validate) throws OnapCommandException { + return OnapCommandSchemaHttpLoader.loadHttpSchema(this, this.getSchemaName(), true, validate); } @Override diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java b/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java index 1ce0433c..5b6df29d 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java @@ -65,12 +65,16 @@ import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; import org.onap.cli.fw.http.conf.OnapCommandHttpConstants; import org.onap.cli.fw.http.error.OnapCommandHttpFailure; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Helps to make http connection.<br> */ public class OnapHttpConnection { + private static Logger LOG = LoggerFactory.getLogger(OnapHttpConnection.class); + private HttpClient httpClient = null; Map<String, String> mapCommonHeaders = new HashMap<String, String> (); @@ -331,8 +335,10 @@ public class OnapHttpConnection { } catch (ParseException | IOException e) { throw new OnapCommandHttpFailure(e); } finally { + String info = input + " " + result; + LOG.info(info); if (this.debug) { - this.debugDetails = input + " " + result; + this.debugDetails = info; } } diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java index e4d2cf06..cd918783 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java @@ -38,6 +38,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.jayway.jsonpath.JsonPath; +import com.jayway.jsonpath.PathNotFoundException; import net.minidev.json.JSONArray; @@ -169,21 +170,26 @@ public class OnapCommandHttpUtils { int idxE = headerProcessedLine.indexOf("}", idxS); String jsonPath = headerProcessedLine.substring(idxS + 3, idxE); jsonPath = jsonPath.trim(); + Object value = new Object(); try { // JSONArray or String - Object value = JsonPath.read(resultHttp.getBody(), jsonPath); - if (value instanceof JSONArray) { - JSONArray arr = (JSONArray) value; - if (arr.size() > maxRows) { - maxRows = arr.size(); - } - } - bodyProcessedPattern += headerProcessedLine.substring(currentIdx, idxS) + "%s"; - values.add(value); - currentIdx = idxE + 1; + value = JsonPath.read(resultHttp.getBody(), jsonPath); + } catch (PathNotFoundException e1) { + //set to blank for those entries which are missing from the output json + value = ""; } catch (Exception e) { throw new OnapCommandHttpInvalidResponseBody(jsonPath, e); } + + if (value instanceof JSONArray) { + JSONArray arr = (JSONArray) value; + if (arr.size() > maxRows) { + maxRows = arr.size(); + } + } + bodyProcessedPattern += headerProcessedLine.substring(currentIdx, idxS) + "%s"; + values.add(value); + currentIdx = idxE + 1; } if (bodyProcessedPattern.isEmpty()) { diff --git a/profiles/http/src/main/resources/open-cli-schema/http/default_input_parameters_http.yaml b/profiles/http/src/main/resources/open-cli-schema/http/default_input_parameters_http.yaml index d7fbe03c..9029e273 100644 --- a/profiles/http/src/main/resources/open-cli-schema/http/default_input_parameters_http.yaml +++ b/profiles/http/src/main/resources/open-cli-schema/http/default_input_parameters_http.yaml @@ -13,6 +13,7 @@ parameters: long_option: host-username default_value: $s{env:OPEN_CLI_HOST_USERNAME} is_optional: false + is_default_param: true - name: host-password type: string description: Host user password @@ -21,6 +22,7 @@ parameters: default_value: $s{env:OPEN_CLI_HOST_PASSWORD} is_secured: true is_optional: false + is_default_param: true - name: host-url type: url description: host url in http(s) @@ -28,9 +30,11 @@ parameters: long_option: host-url is_optional: false default_value: $s{env:OPEN_CLI_HOST_URL} + is_default_param: true - name: no-auth type: bool description: whether to authenticate user or not short_option: a long_option: no-auth - default_value: false
\ No newline at end of file + default_value: false + is_default_param: true
\ No newline at end of file |