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.
*/
public abstract class OnapCommand {
+ private static Logger LOG = LoggerFactory.getLogger(OnapCommand.class);
+
private String cmdDescription;
private String cmdName;
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;
/**
* 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<>();
}
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);
this.run();
+ LOG.info("OUTPUT: " + this.cmdResult.getRecords());
+
return this.cmdResult;
}
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";
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
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";
*/
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;
}
return false;
return true;
}
+
+ @Override
+ public String toString() {
+ return this.getName() + ": " + this.getValue();
+ }
}
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;
return values;
}
+ public void resetValues(String value) {
+ this.values.clear();
+ this.values.add(value);
+ }
+
public OnapCommandResultAttributeScope getScope() {
return outScope;
}
this.defaultValue = defaultValue;
}
+ @Override
+ public String toString() {
+ return this.getName() + ": " + this.getValues();
+ }
}
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;
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;
}
}
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);
}
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;
}
# 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
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
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
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());
}
@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
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> ();
} 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;
}
}
import org.slf4j.LoggerFactory;
import com.jayway.jsonpath.JsonPath;
+import com.jayway.jsonpath.PathNotFoundException;
import net.minidev.json.JSONArray;
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()) {
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
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)
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