diff options
author | Itohan Ukponmwan <itohan.ukponmwan@intel.com> | 2019-08-05 16:30:20 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-08-05 16:30:20 +0000 |
commit | 55f55f93890a2c4745ee89505cc889f54ba3c3dd (patch) | |
tree | 5eb804de9b3907b38621a3f5d8169ae3f6a64c21 | |
parent | d53b78f51ed1a37f13163fe0ffd77ebd1c7f6f6f (diff) | |
parent | b9d85a33892c99949aff8e3471eb0fdc039d44aa (diff) |
Merge changes I816a1dbb,Ice38da57,I1217d391,I07d22e81,I0ddcdc1c, ...
* changes:
Add integration support
Update framework
Add vf model add artifact command
Add service model artifact add command
Add VF model checkout command
Add VF checkin command
Add sdc service resource property set
Add sdc consumer-show command
Add sdc consumer create command
Add ID output in service-model commands
Update open-cli.properties
Update the sample command OCS YAML
Add product into service and schema list
Update the version format
Update the README
Set SNAPSHOT versioning
clean-up stale onap profiles
Ignore python build artifacts from git
147 files changed, 2965 insertions, 579 deletions
@@ -2,6 +2,9 @@ bin/ target/ coverage-report/ data/ +build/ +dist/ +ocomp.egg-info/ .project .settings .classpath @@ -10,3 +13,5 @@ data/ *.iml *.log .idea +*.pyc + diff --git a/deployment/docker/pom.xml b/deployment/docker/pom.xml index 40240f9b..4a5837a8 100644 --- a/deployment/docker/pom.xml +++ b/deployment/docker/pom.xml @@ -23,12 +23,12 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-deployment</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-docker</artifactId> <name>cli/deployment/docker</name> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> <packaging>pom</packaging> <properties> diff --git a/deployment/pom.xml b/deployment/pom.xml index c3f70458..58793d82 100644 --- a/deployment/pom.xml +++ b/deployment/pom.xml @@ -23,7 +23,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-deployment</artifactId> diff --git a/deployment/zip/pom.xml b/deployment/zip/pom.xml index 454e259e..6af31ca3 100644 --- a/deployment/zip/pom.xml +++ b/deployment/zip/pom.xml @@ -23,7 +23,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-deployment</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-zip</artifactId> @@ -71,6 +71,12 @@ ant.delete(dir: "${deployUnzip}/data") ant.mkdir(dir: "${deployUnzip}/data") + ant.delete(dir: "${deployUnzip}/data/tmp") + ant.mkdir(dir: "${deployUnzip}/data/tmp") + + ant.delete(dir: "${deployUnzip}/script") + ant.mkdir(dir: "${deployUnzip}/script") + ant.copy(todir: "${deployUnzip}") { fileset(dir: "${basedir}/src/main/release"){ exclude(name: "**/.gitignore") @@ -96,16 +102,21 @@ fileset(dir: "${project.build.directory}/../../../grpc/target/lib/") } + ant.copy(todir: "${deployUnzip}/conf") { + fileset(dir: + "${project.build.directory}/../../../products/target/conf/") + fileset(dir: + "${project.build.directory}/../../../profiles/target/conf/") fileset(file: - "${basedir}/src/main/release/conf/open-cli.properties") + "${basedir}/src/main/release/conf/*.properties") } ant.copy(todir: - "${deployUnzip}/conf") { - fileset(file: - "${basedir}/src/main/release/conf/log4j.properties") + "${deployUnzip}/script") { + fileset(dir: + "${project.build.directory}/../../../products/target/script/") } ant.copy(todir: diff --git a/deployment/zip/src/main/release/conf/open-cli.properties b/deployment/zip/src/main/release/conf/open-cli.properties index eca284ad..65d4db7e 100644 --- a/deployment/zip/src/main/release/conf/open-cli.properties +++ b/deployment/zip/src/main/release/conf/open-cli.properties @@ -13,10 +13,13 @@ # limitations under the License. cli.product_name=open-cli -cli.version=2.0.5 +cli.version=3.0.0 cli.discover_always=false -cli.data.dir=/opt/oclip/data -cli.artifact.dir=/opt/oclip/artifacts +cli.data.dir=$s{env:OPEN_CLI_HOME}/data +cli.artifact.dir=$s{env:OPEN_CLI_HOME}/data/artifacts +cli.tmp.dir=$s{env:OPEN_CLI_HOME}/data/tmp +#timeout in seconds +cli.grpc.client.timeout=60 #schema validation cli.schema.base.sections=open_cli_schema_version,name,description,parameters,results,info @@ -31,12 +34,12 @@ cli.schema.base.parameters.sections.mandatory=name,description,type cli.schema.base.results.sections=name,description,scope,type,is_secured, default_value cli.schema.base.results.sections.mandatory=name, description, type, scope -cli.schema.boolean_values=true,false +cli.schema.boolean_values=true cli.schema.command.type=cmd,auth,catalog # moco properties cli.sample.gen.enable=false -cli.sample.gen.target=. +cli.sample.gen.target=$s{env:OPEN_CLI_HOME}/open-cli-sample # mrkanag Move this to db, once exteranl command registration is supported in place of discovery cli.schema.profile.available=http,snmp,cmd diff --git a/deployment/zip/src/main/release/data/onap-beijing-profile.json b/deployment/zip/src/main/release/data/onap-beijing-profile.json deleted file mode 100644 index 5cd58c4c..00000000 --- a/deployment/zip/src/main/release/data/onap-beijing-profile.json +++ /dev/null @@ -1,52 +0,0 @@ -[ - { - "product" : "onap-beijing", - "name" : "aai:host-url", - "value" : "https://192.168.17.35:30233" - }, - { - "product" : "onap-beijing", - "name" : "aai:host-username", - "value" : "AAI" - }, - { - "product" : "onap-beijing", - "name" : "aai:host-password", - "value" : "AAI" - }, - { - "product" : "onap-beijing", - "name" : "msb:host-url", - "value" : "http://192.168.17.35:30081" - }, - { - "product" : "onap-beijing", - "name" : "sdc:host-url", - "value" : "http://192.168.17.35:30206" - }, - { - "product" : "onap-beijing", - "name" : "sdc:host-username", - "value" : "cs_0008" - }, - { - "product" : "onap-beijing", - "name" : "sdc:host-password", - "value" : "demo123456!" - }, - { - "product" : "onap-beijing", - "name" : "so:host-url", - "value" : "http://192.168.17.35:30223" - }, - { - "product" : "onap-beijing", - "name" : "so:host-username", - "value" : "InfraPortalClien" - }, - { - "product" : "onap-beijing", - "name" : "so:host-password", - "value" : "password1$" - } -]
\ No newline at end of file diff --git a/deployment/zip/src/main/release/data/onap-casablanca-profile.json b/deployment/zip/src/main/release/data/onap-casablanca-profile.json deleted file mode 100644 index 36c4a5a9..00000000 --- a/deployment/zip/src/main/release/data/onap-casablanca-profile.json +++ /dev/null @@ -1,57 +0,0 @@ -[ - { - "product" : "onap-casablanca", - "name" : "aai:host-url", - "value" : "https://192.168.17.7:8443" - }, - { - "product" : "onap-casablanca", - "name" : "aai:host-username", - "value" : "AAI" - }, - { - "product" : "onap-casablanca", - "name" : "aai:host-password", - "value" : "AAI" - }, - { - "product" : "onap-casablanca", - "name" : "msb:host-url", - "value" : "http://192.168.17.5:80" - }, - { - "product" : "onap-casablanca", - "name" : "sdc:host-url", - "value" : "http://192.168.17.13:8080" - }, - { - "product" : "onap-casablanca", - "name" : "sdc:host-username", - "value" : "cs_0008" - }, - { - "product" : "onap-casablanca", - "name" : "sdc:host-password", - "value" : "demo123456!" - }, - { - "product" : "onap-casablanca", - "name" : "policy:host-url", - "value" : "http://192.168.17.19:8443" - }, - { - "product" : "onap-casablanca", - "name" : "so:host-url", - "value" : "http://192.168.17.3:8080" - }, - { - "product" : "onap-casablanca", - "name" : "so:host-username", - "value" : "InfraPortalClien" - }, - { - "product" : "onap-casablanca", - "name" : "so:host-password", - "value" : "password1$" - } -]
\ No newline at end of file diff --git a/framework/pom.xml b/framework/pom.xml index 60193e73..75d94ee7 100644 --- a/framework/pom.xml +++ b/framework/pom.xml @@ -24,17 +24,20 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-framework</artifactId> + <name>cli/framework</name> + <packaging>jar</packaging> + <dependencies> <dependency> <groupId>org.onap.cli</groupId> <artifactId>oclip-grpc-client</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.yaml</groupId> @@ -52,6 +55,11 @@ <version>1.3</version> </dependency> <dependency> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + <version>1.9</version> + </dependency> + <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-io</artifactId> <version>1.3.2</version> @@ -62,6 +70,21 @@ <version>3.2.9.RELEASE</version> </dependency> <dependency> + <groupId>com.jayway.jsonpath</groupId> + <artifactId>json-path</artifactId> + <version>2.2.0</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + <version>2.9.4</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.dataformat</groupId> + <artifactId>jackson-dataformat-yaml</artifactId> + <version>2.9.4</version> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> @@ -79,20 +102,5 @@ <version>1.19</version> <scope>test</scope> </dependency> - <dependency> - <groupId>com.jayway.jsonpath</groupId> - <artifactId>json-path</artifactId> - <version>2.2.0</version> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - <version>2.9.4</version> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.dataformat</groupId> - <artifactId>jackson-dataformat-yaml</artifactId> - <version>2.9.4</version> - </dependency> </dependencies> </project> 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 b814ba82..d73df4fb 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 @@ -39,6 +39,7 @@ import org.onap.cli.fw.schema.OnapCommandSchemaLoader; import org.onap.cli.fw.schema.OnapCommandSchemaMerger; import org.onap.cli.fw.store.OnapCommandArtifactStore; import org.onap.cli.fw.store.OnapCommandArtifactStore.Artifact; +import org.onap.cli.fw.store.OnapCommandExecutionStore.ExecutionStoreContext; import org.onap.cli.fw.utils.OnapCommandHelperUtils; import org.onap.cli.fw.utils.OnapCommandUtils; import org.slf4j.Logger; @@ -73,6 +74,8 @@ public abstract class OnapCommand { private boolean isRpc = false; + private ExecutionStoreContext executionStoreContext; + public boolean isRpc() { return isRpc; } @@ -234,6 +237,7 @@ public abstract class OnapCommand { protected void postRun() throws OnapCommandException { log.debug(this.getName() + " POST-RUN"); } + /** * Oclip command execute with given parameters on service. Before calling this method, its mandatory to set all * parameters value. @@ -314,6 +318,8 @@ public abstract class OnapCommand { log.info("OUTPUT: " + this.cmdResult.getRecords()); postRun(); + + return this.cmdResult; } @@ -343,4 +349,12 @@ public abstract class OnapCommand { return OnapCommandHelperUtils.help(this); } // (mrkanag) Add toString for all command, parameter, result, etc objects in JSON format + + public void setExecutionContext(ExecutionStoreContext executionStoreContext) { + this.executionStoreContext = executionStoreContext; + } + + public ExecutionStoreContext getExecutionContext() { + return this.executionStoreContext; + } } diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommandType.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommandType.java index 34ccc760..e874a14e 100644 --- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommandType.java +++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommandType.java @@ -27,8 +27,7 @@ public enum OnapCommandType { AUTH, CATALOG, - CMD, - SYSTEM; + CMD; /** * Get parameter type. @@ -46,8 +45,6 @@ public enum OnapCommandType { return CATALOG; } else if (CMD.name().equalsIgnoreCase(name)) { return CMD; - } else if (SYSTEM.name().equalsIgnoreCase(name)) { - return SYSTEM; } else { throw new OnapCommandInvalidCommandType(name); } diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowDebugCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowDebugCommand.java new file mode 100644 index 00000000..e6be04aa --- /dev/null +++ b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowDebugCommand.java @@ -0,0 +1,34 @@ +/* + * Copyright 2019 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.cmd.execution; + +import org.onap.cli.fw.cmd.OnapCommand; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.schema.OnapCommandSchema; +import org.onap.cli.fw.store.OnapCommandExecutionStore; + +@OnapCommandSchema(schema = "execution-show-debug.yaml") +public class OnapCommandExceutionShowDebugCommand extends OnapCommand { + + @Override + protected void run() throws OnapCommandException { + String executionId = getParametersMap().get("execution-id").getValue().toString(); + this.getResult().setOutput(OnapCommandExecutionStore.getStore().showExecutionDebug(executionId)); + } + + +} diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowErrCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowErrCommand.java new file mode 100644 index 00000000..bd3ff9ec --- /dev/null +++ b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowErrCommand.java @@ -0,0 +1,34 @@ +/* + * Copyright 2019 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.cmd.execution; + +import org.onap.cli.fw.cmd.OnapCommand; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.schema.OnapCommandSchema; +import org.onap.cli.fw.store.OnapCommandExecutionStore; + +@OnapCommandSchema(schema = "execution-show-err.yaml") +public class OnapCommandExceutionShowErrCommand extends OnapCommand { + + @Override + protected void run() throws OnapCommandException { + String executionId = getParametersMap().get("execution-id").getValue().toString(); + this.getResult().setOutput(OnapCommandExecutionStore.getStore().showExecutionErr(executionId)); + } + + +} diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowOutCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowOutCommand.java new file mode 100644 index 00000000..878ceb13 --- /dev/null +++ b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowOutCommand.java @@ -0,0 +1,32 @@ +/* + * Copyright 2019 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.cmd.execution; + +import org.onap.cli.fw.cmd.OnapCommand; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.schema.OnapCommandSchema; +import org.onap.cli.fw.store.OnapCommandExecutionStore; + +@OnapCommandSchema(schema = "execution-show-out.yaml") +public class OnapCommandExceutionShowOutCommand extends OnapCommand { + + @Override + protected void run() throws OnapCommandException { + String executionId = getParametersMap().get("execution-id").getValue().toString(); + this.getResult().setOutput(OnapCommandExecutionStore.getStore().showExecutionOut(executionId)); + } +} diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapServiceListCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapServiceListCommand.java index 010cdc19..fa4f60b9 100644 --- a/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapServiceListCommand.java +++ b/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapServiceListCommand.java @@ -73,6 +73,7 @@ public class OnapServiceListCommand extends OnapCommand { } for (String service : rslt.getOrDefault(product, new HashSet<String>())) { + this.getResult().getRecordsMap().get("product").getValues().add(product); this.getResult().getRecordsMap().get("service").getValues().add(service); this.getResult().getRecordsMap().get("description").getValues().add( serviceDescs.containsKey(service) ? serviceDescs.get(service) : ""); diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/schema/OnapSchemaListCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/schema/OnapSchemaListCommand.java index ef22e4af..5046f44a 100644 --- a/framework/src/main/java/org/onap/cli/fw/cmd/schema/OnapSchemaListCommand.java +++ b/framework/src/main/java/org/onap/cli/fw/cmd/schema/OnapSchemaListCommand.java @@ -47,6 +47,7 @@ public class OnapSchemaListCommand extends OnapCommand { if (service.length() > 0 && !service.equalsIgnoreCase(schema.getService())) { continue; } + this.getResult().getRecordsMap().get("product").getValues().add(schema.getProduct()); this.getResult().getRecordsMap().get("command").getValues().add(schema.getCmdName()); this.getResult().getRecordsMap().get("schema").getValues().add(schema.getSchemaName()); this.getResult().getRecordsMap().get("service").getValues().add(schema.getService()); diff --git a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfig.java b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfig.java index c59521e0..b395177f 100644 --- a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfig.java +++ b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfig.java @@ -22,6 +22,8 @@ import java.util.Map.Entry; import java.util.Properties; import java.util.stream.Collectors; +import org.onap.cli.fw.utils.OnapCommandUtils; + /** * Oclip command constants. * @@ -38,7 +40,8 @@ public final class OnapCommandConfig { } static { - loadProperties(prps, OnapCommandConstants.CONF); + addProperties(OnapCommandConstants.CONF); + for (String prpFile: getCommaSeparatedList(OnapCommandConstants.OPEN_CLI_PLUGIN_PRPS)) { addProperties(prpFile); } @@ -57,7 +60,7 @@ public final class OnapCommandConfig { loadProperties(ps, fileName); for (Entry<Object, Object> entry: ps.entrySet()) { - prps.put(entry.getKey(), entry.getValue()); + prps.put(entry.getKey(), OnapCommandUtils.replaceLineForSpecialValues(entry.getValue().toString())); } } 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 56183399..53018025 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 @@ -36,14 +36,13 @@ public class OnapCommandConstants { public static final String RESULT_PARAMS_LIST = "cli.schema.base.results.sections"; public static final String RESULT_PARAMS_MANDATORY_LIST = "cli.schema.base.results.sections.mandatory"; public static final String BOOLEAN_VALUE = "cli.schema.boolean_values"; - public static final String COMMAND_TYPE_VALUES = "cli.schema.command.type"; public static final String SCHEMA_TYPES_SUPPORTED = "cli.schema.profile.available"; public static final String OPEN_CLI_PRODUCT_NAME = "cli.product_name"; public static final String OPEN_CLI_PLUGIN_PRPS = "cli.schema.profile.confs"; public static final String OPEN_CLI_DATA_DIR = "cli.data.dir"; public static final String OPEN_CLI_ARTIFACT_DIR = "cli.artifact.dir"; - + public static final String OPEN_CLI_GRPC_CLIENT_TIMEOUT = "cli.grpc.client.timeout"; //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"; @@ -151,6 +150,7 @@ public class OnapCommandConstants { public static final String SPL_ENTRY_UUID = "uuid"; public static final String SPL_ENTRY_ENV = "env:"; public static final String SPL_ENTRY_FILE = "file:"; + public static final String SPL_ENTRY_MD5 = "md5:"; public static final String VERSION_INFO = "version.info"; public static final String VERSION_INFO_PLACE_HOLDER_VERSION = "__VERSION__"; 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 618c321c..3b13c9f8 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 @@ -288,7 +288,12 @@ public class OnapCommandParameter { public void setValue(Object value) throws OnapCommandInvalidParameterValue { this.rawValue = value; - if (OnapCommandParameterType.URL.equals(parameterType) && !value.toString().isEmpty() && !value.toString().startsWith("http") + if (OnapCommandParameterType.URL.equals(parameterType) && + !value.toString().isEmpty() && + !value.toString().startsWith("http") && + !value.toString().startsWith("ftp") && + !value.toString().startsWith("mqtt") && + !value.toString().startsWith("tcp") && !value.toString().startsWith("/")) { value = "/" + value; } else if (OnapCommandParameterType.ARRAY.equals(parameterType)) { diff --git a/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameterType.java b/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameterType.java index 391383d4..b6860b3c 100644 --- a/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameterType.java +++ b/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameterType.java @@ -23,7 +23,7 @@ import org.onap.cli.fw.error.OnapCommandInvalidParameterType; * */ public enum OnapCommandParameterType { - STRING, JSON, YAML, TEXT, URL, UUID, + STRING, BYTE, JSON, YAML, TEXT, URL, UUID, DIGIT, BOOL, ARRAY, @@ -42,6 +42,8 @@ public enum OnapCommandParameterType { public static OnapCommandParameterType get(String name) throws OnapCommandInvalidParameterType { if (JSON.name().equalsIgnoreCase(name)) { return JSON; + } else if (BYTE.name().equalsIgnoreCase(name)) { + return BYTE; } else if (YAML.name().equalsIgnoreCase(name)) { return YAML; } else if (STRING.name().equalsIgnoreCase(name)) { diff --git a/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java b/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java index d7937527..fdacbd1e 100644 --- a/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java +++ b/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java @@ -431,8 +431,8 @@ public class OnapCommandRegistrar { } } - public List<Map<String, ?>> getTestSuite(String cmd) throws OnapCommandException { - return OnapCommandDiscoveryUtils.createTestSuite(cmd, enabledProductVersion); + public List<Map<String, ?>> getTestSuite(String cmd, String product) throws OnapCommandException { + return OnapCommandDiscoveryUtils.createTestSuite(cmd, product); } public String getHost() { 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 fe191f5b..7d2cec92 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 @@ -344,7 +344,7 @@ public class OnapCommandSchemaLoader { case IS_OPTIONAL: if (validate && !OnapCommandUtils.validateBoolean(String.valueOf(parameter.get(key2)))) { exceptionList.add(OnapCommandUtils.invalidBooleanValueMessage(parameter.get(NAME), - IS_SECURED, parameter.get(key2))); + IS_OPTIONAL, parameter.get(key2))); } if (BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))) { @@ -510,6 +510,7 @@ public class OnapCommandSchemaLoader { break; } } + return exceptionList; } diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java index 4fc2508a..d09e4304 100644 --- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java +++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java @@ -19,7 +19,6 @@ package org.onap.cli.fw.store; import java.io.File; import java.io.FilenameFilter; import java.io.IOException; -import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -29,7 +28,6 @@ import java.util.Map; import java.util.TimeZone; import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; import org.onap.cli.fw.conf.OnapCommandConfig; import org.onap.cli.fw.conf.OnapCommandConstants; import org.onap.cli.fw.error.OnapCommandExecutionFailed; @@ -54,7 +52,7 @@ public class OnapCommandExecutionStore { private static SearchMode SEARCH_MODE = SearchMode.file; public static class ExecutionStoreContext { - + private String requestId; private String executionId; private String storePath; public String getExecutionId() { @@ -71,6 +69,13 @@ public class OnapCommandExecutionStore { this.storePath = storePath; return this; } + public String getRequestId() { + return requestId; + } + public ExecutionStoreContext setRequestId(String requestId) { + this.requestId = requestId; + return this; + } } public static class Execution { @@ -185,63 +190,113 @@ public class OnapCommandExecutionStore { public ExecutionStoreContext storeExectutionStart( String requestId, String product, String service, String cmd, String profile, String input) { + ExecutionStoreContext context = new ExecutionStoreContext(); + context.setRequestId(requestId); + String executionId = requestId + "-" + System.currentTimeMillis(); + context.setExecutionId(executionId); String storePath = getBasePath() + File.separator + executionId + SEPARATOR + product + SEPARATOR + service + SEPARATOR + cmd + (profile != null ? (SEPARATOR + profile) : "" ); + try { File dir = new File(storePath); FileUtils.forceMkdir(dir); + context.setStorePath(dir.getAbsolutePath()); if (product != null) - FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "product"), product); + FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "product"), product); if (service != null) - FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "service"), service); + FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "service"), service); if (cmd != null) - FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "command"), cmd); + FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "command"), cmd); - FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "requestId"), requestId); + FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "requestId"), requestId); - FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "executionId"), executionId); + FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "executionId"), executionId); if (input != null) - FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "input"), input); + FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "input"), input); if (profile != null) - FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "profile"), profile); - FileUtils.touch(new File(dir.getAbsolutePath() + File.separator + "in-progress")); + FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "profile"), profile); + + FileUtils.touch(new File(context.getStorePath() + File.separator + "stdout")); + FileUtils.touch(new File(context.getStorePath() + File.separator + "stderr")); + FileUtils.touch(new File(context.getStorePath() + File.separator + "debug")); + + FileUtils.touch(new File(context.getStorePath() + File.separator + "in-progress")); } catch (IOException e) { log.error("Failed to store the execution start details " + storePath); } - return new ExecutionStoreContext().setExecutionId(executionId).setStorePath(storePath); + return context; } public void storeExectutionEnd( - ExecutionStoreContext execContext, - String output, String error, boolean passed) { + ExecutionStoreContext context, + String output, String error, String debug, boolean passed) { try { - File dir = new File(execContext.getStorePath()); - FileUtils.forceMkdir(dir); - if (output != null) - FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "output"), output); + FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "output"), output); if (error != null) - FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "error"), error); - + FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "error"), error); + if (debug != null) + FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "debug"), debug); if (passed) - FileUtils.touch(new File(dir.getAbsolutePath() + File.separator + "completed")); + FileUtils.touch(new File(context.getStorePath() + File.separator + "completed")); else - FileUtils.touch(new File(dir.getAbsolutePath() + File.separator + "failed")); + FileUtils.touch(new File(context.getStorePath() + File.separator + "failed")); + + new File(context.getStorePath() + File.separator + "in-progress").delete(); + } catch (IOException e) { + log.error("Failed to store the execution end details " + context.storePath); + } + } + + public void storeExectutionProgress( + ExecutionStoreContext context, + String output, String error, String debug) { + + try { + if (output != null) + FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "output"), output); + if (error != null) + FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "error"), error); + if (debug != null) + FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "debug"), debug); + } catch (IOException e) { + log.error("Failed to store the execution end details " + context.storePath); + } + } + + public void storeExectutionDebug( + ExecutionStoreContext context, + String debug) { - new File(dir.getAbsolutePath() + File.separator + "in-progress").delete(); + try { + if (debug != null) { + FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "debug"), debug); + } } catch (IOException e) { - log.error("Failed to store the execution end details " + execContext.storePath); + log.error("Failed to store the execution debug details " + context.storePath); } } + public void storeExectutionOutput( + ExecutionStoreContext context, + String output) { + + try { + if (output != null) { + FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "output"), output); + } + } catch (IOException e) { + log.error("Failed to store the execution output details " + context.storePath); + } + } public List<OnapCommandExecutionStore.Execution> listExecutions(Map<String, String> search) throws OnapCommandExecutionFailed { List <OnapCommandExecutionStore.Execution> list = new ArrayList<>(); @@ -342,7 +397,8 @@ public class OnapCommandExecutionStore { return exectuion; } - public Execution getExecution(String executionId) throws OnapCommandExecutionNotFound, OnapCommandExecutionFailed { + + private File getExecutionDir(String executionId) throws OnapCommandExecutionNotFound { File []f = new File(getBasePath()).listFiles(new FilenameFilter() { @Override @@ -356,10 +412,37 @@ public class OnapCommandExecutionStore { throw new OnapCommandExecutionNotFound(executionId); } + return f[0]; + } + + public String showExecutionOut(String executionId) throws OnapCommandExecutionNotFound { + try { + return FileUtils.readFileToString(new File (this.getExecutionDir(executionId).getAbsolutePath() + File.separator + "stdout")); + } catch (IOException e) { + return ""; + } + } + + public String showExecutionErr(String executionId) throws OnapCommandExecutionNotFound { + try { + return FileUtils.readFileToString(new File (this.getExecutionDir(executionId).getAbsolutePath() + File.separator + "stderr")); + } catch (IOException e) { + return ""; + } + } + + public String showExecutionDebug(String executionId) throws OnapCommandExecutionNotFound { + try { + return FileUtils.readFileToString(new File (this.getExecutionDir(executionId).getAbsolutePath() + File.separator + "debug")); + } catch (IOException e) { + return ""; + } + } + public Execution getExecution(String executionId) throws OnapCommandExecutionNotFound, OnapCommandExecutionFailed { try { - return this.makeExecution(f[0].getAbsolutePath()); + return this.makeExecution(this.getExecutionDir(executionId).getAbsolutePath()); } catch (IOException e) { throw new OnapCommandExecutionFailed(e, "Failed to retrieve the execution"); } } -} +}
\ No newline at end of file diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java index 7c1f18f6..a94087ec 100644 --- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java +++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java @@ -508,7 +508,6 @@ public class OnapCommandDiscoveryUtils { Map<String, String> sample = samples.get(sampleId); List<String> inputArgs = new ArrayList(); - inputArgs.add(cmd); if (sample.get(OnapCommandConstants.VERIFY_INPUT) != null) { inputArgs.addAll(Arrays.asList(sample.get(OnapCommandConstants.VERIFY_INPUT).trim().split(" "))); } 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 e279fa0b..96f864e0 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 @@ -31,6 +31,8 @@ import java.util.Map.Entry; import java.util.Set; import java.util.UUID; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FileUtils; import org.onap.cli.fw.cmd.OnapCommand; import org.onap.cli.fw.conf.OnapCommandConfig; @@ -185,6 +187,49 @@ public class OnapCommandUtils { * @return */ public static String replaceLineForSpecialValues(String lineSpl) { + return replaceLineForSpecialValues(lineSpl, new HashMap<String, String>()); + } + + /** + * + * @param lineSpl + * @param values Value for the given entry already known by the caller. + * @return + */ + public static String replaceLineFromResults(String line, Map <String, String> values) { + String resultLine = ""; + + if (!line.contains("$r{")) { + return line; + } + + int currentIdx = 0; + while (currentIdx < line.length()) { + int idxS = line.indexOf("$r{", currentIdx); + if (idxS == -1) { + resultLine += line.substring(currentIdx); + break; + } + int idxE = line.indexOf("}", idxS); + String attr = line.substring(idxS + 3, idxE); + attr = attr.trim(); + + String value = ""; + + if (values.get(attr) != null) { + value = values.get(attr); + } else { + value = attr; + } + + resultLine += line.substring(currentIdx, idxS) + value; + currentIdx = idxE + 1; + } + + return resultLine; + } + + public static String replaceLineForSpecialValues(String lineSpl, Map <String, String> values) { String resultSpl = ""; if (!lineSpl.contains("$s{")) { @@ -232,8 +277,20 @@ public class OnapCommandUtils { //exist. value = ""; } + } else if (splEntry.startsWith(OnapCommandConstants.SPL_ENTRY_MD5)) { + //start to read after md5:entryname + String entryName = splEntry.substring(4); + String content = values.get(entryName); + if (content != null) + value = OnapCommandUtils.md5(content); + else + value = splEntry; } else { - value = splEntry; + if (values.get(splEntry) != null) { + value = values.get(splEntry); + } else { + value = splEntry; + } } } @@ -271,7 +328,11 @@ public class OnapCommandUtils { || OnapCommandParameterType.JSON.equals(param.getParameterType()) || OnapCommandParameterType.YAML.equals(param.getParameterType())) { // ignore the front and back double quotes in json body - result += line.substring(currentIdx, idxS - 1) + params.get(paramName).getValue().toString(); + String va_ = params.get(paramName).getValue().toString(); + if (idxS > 0) + result += line.substring(currentIdx, idxS - 1) + va_; + else + result += va_; currentIdx = idxE + 2; } else if (OnapCommandParameterType.MAP.equals(param.getParameterType())) { try { @@ -366,6 +427,12 @@ public class OnapCommandUtils { } } + public static String md5(String content) { + String md5 = DigestUtils.md5Hex(content); + + byte[] encodeBase64 = Base64.encodeBase64(md5.getBytes()); + return new String(encodeBase64); + } } diff --git a/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java b/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java index eb335837..db7245c7 100644 --- a/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java +++ b/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java @@ -17,18 +17,18 @@ package org.onap.cli.fw.utils; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStream; import java.io.StringWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.TimeUnit; import org.apache.commons.io.IOUtils; -import org.onap.cli.fw.cmd.OnapCommand; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,8 +43,9 @@ public class ProcessRunner { private int exitCode = -1; private String output; private String error; - private Map<String, Object> results; - + private long timeout = 0; + private OutputStream stdout; + private OutputStream stderr; public ProcessRunner(String []cmd, String []env, String cwd) { this.cmd = cmd; @@ -55,6 +56,14 @@ public class ProcessRunner { this.env = env; } + public void setTimeout(long timeout) { + this.timeout = timeout; + } + + public long getTimeout() { + return this.timeout; + } + public void overrideToUnix() { this.shell = UNIX_SHELL; } @@ -82,9 +91,13 @@ public class ProcessRunner { @SuppressWarnings("unchecked") public void run() throws InterruptedException, IOException { Process p = null; + final StringWriter writerOutput = new StringWriter(); final StringWriter writerError = new StringWriter(); + final OutputStream stdout = this.getStdout(); + final OutputStream stderr = this.getStderr(); + if (this.cmd.length == 1) { p = Runtime.getRuntime().exec(this.shell + this.cmd[0], this.env, null); } else { @@ -98,7 +111,10 @@ public class ProcessRunner { new Thread(new Runnable() { public void run() { try { - IOUtils.copy(p1.getInputStream(), writerOutput); + if (stdout != null) { + IOUtils.copy(p1.getInputStream(), stdout); + } + else IOUtils.copy(p1.getInputStream(), writerOutput); } catch (IOException e) { } } @@ -107,21 +123,32 @@ public class ProcessRunner { new Thread(new Runnable() { public void run() { try { - IOUtils.copy(p1.getErrorStream(), writerError); + if (stderr != null) { + IOUtils.copy(p1.getErrorStream(), stderr); + } + else IOUtils.copy(p1.getErrorStream(), writerError); } catch (IOException e) { } } }).start(); - //mrkanag: handle the case if the given cmd does not exist - p.waitFor(1, TimeUnit.MINUTES); - this.exitCode = p.exitValue(); + boolean completed = p.waitFor(this.getTimeout(), TimeUnit.MILLISECONDS); + if (completed) { + this.exitCode = p.exitValue(); + } + this.output = writerOutput.toString(); this.error = writerError.toString(); log.debug("CMD: " + Arrays.asList(this.cmd).toString() + "\nWORKING_DIR: " + this.cwd + "\nENV: " + ((this.env == null) ? this.env : Arrays.asList(this.env).toString()) + "\nOUTPUT: " + this.output + "\nERROR: " + this.error + "\nEXIT_CODE: " + this.exitCode); p.destroy(); + + if (!completed) { + throw new RuntimeException("TIMEOUT:: cmd:" + Arrays.asList(this.cmd).toString()); + } else { + + } } public String streamToString(InputStream stream) throws IOException { @@ -152,4 +179,32 @@ public class ProcessRunner { public String getError() { return this.error; } + + public OutputStream getStdout() { + return stdout; + } + + public void setStdout(OutputStream stdout) { + this.stdout = stdout; + } + + public OutputStream getStderr() { + return stderr; + } + + public void setStderr(OutputStream stderr) { + this.stderr = stderr; + } + + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("COMMAND: " + this.shell + " " + Arrays.asList(this.cmd)); + sb.append("\nCWD: " + new File(this.cwd).getAbsolutePath()); + sb.append("\nTIMEOUT: " + this.timeout); + sb.append("\nEXIT-CODE: " + this.getExitCode()); + sb.append("\nENVIRONMENTS: " + Arrays.asList(this.env)); + + return sb.toString(); + } }
\ No newline at end of file diff --git a/framework/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand b/framework/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand index 547d7872..7ca9c783 100644 --- a/framework/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand +++ b/framework/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand @@ -16,8 +16,13 @@ org.onap.cli.fw.cmd.schema.OnapSchemaValidateCommand org.onap.cli.fw.cmd.schema.OnapSchemaRefreshCommand org.onap.cli.fw.cmd.schema.OnapSchemaListCommand org.onap.cli.fw.cmd.schema.OnapSchemaShowCommand -#org.onap.cli.fw.cmd.schema.OnapSchemaSwitchCommand +org.onap.cli.fw.cmd.schema.OnapSchemaSwitchCommand + org.onap.cli.fw.cmd.product.OnapProductsListCommand org.onap.cli.fw.cmd.product.OnapServiceListCommand + org.onap.cli.fw.cmd.execution.OnapCommandExceutionListCommand org.onap.cli.fw.cmd.execution.OnapCommandExceutionShowCommand +org.onap.cli.fw.cmd.execution.OnapCommandExceutionShowDebugCommand +org.onap.cli.fw.cmd.execution.OnapCommandExceutionShowOutCommand +org.onap.cli.fw.cmd.execution.OnapCommandExceutionShowErrCommand 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 d1a074d7..f3d5e89d 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 @@ -72,4 +72,4 @@ parameters: short_option: D long_option: context is_default_param: true - is_optional: true
\ No newline at end of file + is_optional: true diff --git a/framework/src/main/resources/open-cli-schema/execution/execution-show-debug.yaml b/framework/src/main/resources/open-cli-schema/execution/execution-show-debug.yaml new file mode 100644 index 00000000..6e968747 --- /dev/null +++ b/framework/src/main/resources/open-cli-schema/execution/execution-show-debug.yaml @@ -0,0 +1,38 @@ +# Copyright 2018 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. + +open_cli_schema_version: 1.0 +name: execution-show-debug +description: Show the command execution debug information + +info: + product: open-cli + service: execution + type: cmd + author: Kanagaraj Manickam kanagaraj.manickam@huawei.com + +parameters: + - name: execution-id + type: string + description: Execution id + short_option: l + long_option: execution-id + is_optional: false + - name: format + type: string + description: Output formats, supported formats such as table, csv, json, yaml + short_option: f + long_option: format + default_value: text + is_default_param: true
\ No newline at end of file diff --git a/framework/src/main/resources/open-cli-schema/execution/execution-show-err.yaml b/framework/src/main/resources/open-cli-schema/execution/execution-show-err.yaml new file mode 100644 index 00000000..13ad274e --- /dev/null +++ b/framework/src/main/resources/open-cli-schema/execution/execution-show-err.yaml @@ -0,0 +1,38 @@ +# Copyright 2018 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. + +open_cli_schema_version: 1.0 +name: execution-show-err +description: Show the command execution console error information + +info: + product: open-cli + service: execution + type: cmd + author: Kanagaraj Manickam kanagaraj.manickam@huawei.com + +parameters: + - name: execution-id + type: string + description: Execution id + short_option: l + long_option: execution-id + is_optional: false + - name: format + type: string + description: Output formats, supported formats such as table, csv, json, yaml + short_option: f + long_option: format + default_value: text + is_default_param: true
\ No newline at end of file diff --git a/framework/src/main/resources/open-cli-schema/execution/execution-show-out.yaml b/framework/src/main/resources/open-cli-schema/execution/execution-show-out.yaml new file mode 100644 index 00000000..5b74f7aa --- /dev/null +++ b/framework/src/main/resources/open-cli-schema/execution/execution-show-out.yaml @@ -0,0 +1,38 @@ +# Copyright 2018 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. + +open_cli_schema_version: 1.0 +name: execution-show-out +description: Show the command execution console output information + +info: + product: open-cli + service: execution + type: cmd + author: Kanagaraj Manickam kanagaraj.manickam@huawei.com + +parameters: + - name: execution-id + type: string + description: Execution id + short_option: l + long_option: execution-id + is_optional: false + - name: format + type: string + description: Output formats, supported formats such as table, csv, json, yaml + short_option: f + long_option: format + default_value: text + is_default_param: true
\ No newline at end of file diff --git a/framework/src/main/resources/open-cli-schema/execution/execution-show.yaml b/framework/src/main/resources/open-cli-schema/execution/execution-show.yaml index 7b4bd599..a29775e0 100644 --- a/framework/src/main/resources/open-cli-schema/execution/execution-show.yaml +++ b/framework/src/main/resources/open-cli-schema/execution/execution-show.yaml @@ -14,7 +14,7 @@ open_cli_schema_version: 1.0 name: execution-show -description: Show the complete executions for the given request id +description: Show the complete executions for the given execution id info: product: open-cli diff --git a/framework/src/main/resources/open-cli-schema/open-cli-registry.yaml b/framework/src/main/resources/open-cli-schema/open-cli-registry.yaml index 9b988b4e..395cb01e 100644 --- a/framework/src/main/resources/open-cli-schema/open-cli-registry.yaml +++ b/framework/src/main/resources/open-cli-schema/open-cli-registry.yaml @@ -30,11 +30,5 @@ services: description: Product and service searching abilities - name: schema description: OCS schema management - - name: profile - description: Profile management - - name: artifact - description: Artifact management - name: execution description: Execution management - - name: rpc - description: RPC management across OCLIP
\ No newline at end of file diff --git a/framework/src/main/resources/open-cli-schema/product/service-list.yaml b/framework/src/main/resources/open-cli-schema/product/service-list.yaml index 8a84b257..81699309 100644 --- a/framework/src/main/resources/open-cli-schema/product/service-list.yaml +++ b/framework/src/main/resources/open-cli-schema/product/service-list.yaml @@ -33,6 +33,10 @@ parameters: results: direction: landscape attributes: + - name: product + description: Product name + scope: short + type: string - name: service description: Service name scope: short diff --git a/framework/src/main/resources/open-cli-schema/schema/schema-list.yaml b/framework/src/main/resources/open-cli-schema/schema/schema-list.yaml index 4f971ce2..72833d39 100644 --- a/framework/src/main/resources/open-cli-schema/schema/schema-list.yaml +++ b/framework/src/main/resources/open-cli-schema/schema/schema-list.yaml @@ -38,6 +38,14 @@ parameters: results: direction: landscape attributes: + - name: product + description: Product name + scope: short + type: string + - name: service + description: Service name + scope: short + type: string - name: command description: Command name scope: short @@ -46,10 +54,6 @@ results: description: Schema name scope: long type: string - - name: service - description: Service name - scope: short - type: string - name: ocs-version description: Schema version scope: short diff --git a/framework/src/main/resources/open-cli.properties b/framework/src/main/resources/open-cli.properties index e0ca44a8..259fd227 100644 --- a/framework/src/main/resources/open-cli.properties +++ b/framework/src/main/resources/open-cli.properties @@ -13,10 +13,13 @@ # limitations under the License. cli.product_name=open-cli -cli.version=2.0.5 +cli.version=3.0.0 cli.discover_always=false -cli.data.dir=data -cli.artifact.dir=d:/temp/OCLIP +cli.data.dir=./data +cli.artifact.dir=./data/artifacts +cli.tmp.dir=./data/tmp +#timeout in seconds +cli.grpc.client.timeout=60 #schema validation cli.schema.base.sections=open_cli_schema_version,name,description,parameters,results,info @@ -36,10 +39,10 @@ cli.schema.command.type=cmd,auth,catalog # moco properties cli.sample.gen.enable=false -cli.sample.gen.target=. +cli.sample.gen.target=./open-cli-sample # mrkanag Move this to db, once exteranl command registration is supported in place of discovery -cli.schema.profile.available= +cli.schema.profile.available=http,snmp,cmd #other properties to load (it should be hanled when plugins are made as externally register-able #when command plugin management support is enabled in oclip diff --git a/framework/src/main/resources/version.info b/framework/src/main/resources/version.info index edfa61d6..3b8aedf9 100644 --- a/framework/src/main/resources/version.info +++ b/framework/src/main/resources/version.info @@ -1,4 +1,4 @@ -CLI version : __VERSION__ +Version : __VERSION__ Available products: __AVAILABLE_PRODUCT_VERSIONS__ Enabled product : __ENABLED_PRODUCT_VERSIONS__ diff --git a/grpc/grpc-client/pom.xml b/grpc/grpc-client/pom.xml index 813e8e72..3b7ad6d5 100644 --- a/grpc/grpc-client/pom.xml +++ b/grpc/grpc-client/pom.xml @@ -18,7 +18,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>oclip-grpc</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>oclip-grpc-client</artifactId> <name>oclip/grpc/client</name> diff --git a/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java b/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java index 9a818d7a..e32110de 100644 --- a/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java +++ b/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java @@ -37,6 +37,9 @@ public class OpenInterfaceGrpcClient { private final ManagedChannel channel; private final OpenInterfaceGrpc.OpenInterfaceBlockingStub blockingStub; + //10 seconds + private int timeout = 60000; + public static class OpenInterfaceGrpcExecption extends Exception { private static final long serialVersionUID = -8755636432217894246L; @@ -64,6 +67,11 @@ public class OpenInterfaceGrpcClient { .build()); } + public OpenInterfaceGrpcClient(String host, int port, int timeout) { + this(host, port); + this.timeout = timeout; + + } OpenInterfaceGrpcClient(ManagedChannel channel) { this.channel = channel; blockingStub = OpenInterfaceGrpc.newBlockingStub(channel); @@ -78,7 +86,7 @@ public class OpenInterfaceGrpcClient { Output result = Output.newBuilder().build(); try { - result = blockingStub.withDeadlineAfter(10, TimeUnit.SECONDS).invoke(input); + result = blockingStub.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS).invoke(input); } catch (StatusRuntimeException e) { logger.warn("RPC failed: {0}", e.getStatus()); //Status{code=DEADLINE_EXCEEDED} @@ -93,7 +101,7 @@ public class OpenInterfaceGrpcClient { Result result = Result.newBuilder().setExitCode(1).build(); try { - result = blockingStub.withDeadlineAfter(10, TimeUnit.SECONDS).remoteCli(args); + result = blockingStub.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS).remoteCli(args); } catch (StatusRuntimeException e) { logger.warn("RPC failed: {0}", e.getStatus()); //Status{code=DEADLINE_EXCEEDED} diff --git a/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenRemoteCli.java b/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenRemoteCli.java index fc0c2aac..724267e8 100644 --- a/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenRemoteCli.java +++ b/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenRemoteCli.java @@ -26,6 +26,51 @@ import org.open.infc.grpc.Output; import org.open.infc.grpc.Result; public class OpenRemoteCli { + + private String host; + private int port; + private int timeout; + private String requestId; + + public OpenRemoteCli(String host, int port, int timeout, String requestId) { + this.host = host; + this.port = port; + this.timeout = timeout; + this.requestId = requestId; + + } + + public Result run (List <String> args) throws Exception { + OpenInterfaceGrpcClient client = new OpenInterfaceGrpcClient( + host, port, timeout); + try { + Result result = client.remoteCli(Args.newBuilder().setRequestId(this.requestId).addAllArgs(args).build()); + return result; + } finally { + client.shutdown(); + } + } + + public Output invoke (String product, String profile, String action, Map <String, String> params) throws Exception { + OpenInterfaceGrpcClient client = new OpenInterfaceGrpcClient( + host, port, timeout); + try { + + Map <String, String> options = new HashMap<>(); + options.put("product", product); + if (profile != null && !profile.isEmpty()) + options.put("profile", profile); + params.put("format", "json"); + Input input = Input.newBuilder().setAction(action).setRequestId(requestId).putAllOptions(options).putAllParams(params).build(); + + Output output = client.invoke(input); + return output; + } finally { + client.shutdown(); + } + } + + //Absolute the static methods /** * Runs CLI remotely * @param host @@ -48,7 +93,7 @@ public class OpenRemoteCli { } } - /** + /** * Runs commands as remote procedure call :) * @param host * @param port diff --git a/grpc/grpc-server/pom.xml b/grpc/grpc-server/pom.xml index be038ad5..c894e67b 100644 --- a/grpc/grpc-server/pom.xml +++ b/grpc/grpc-server/pom.xml @@ -18,7 +18,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>oclip-grpc</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>oclip-grpc-server</artifactId> <name>oclip/grpc/server</name> @@ -32,7 +32,7 @@ <dependency> <groupId>org.onap.cli</groupId> <artifactId>cli-main</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </dependency> </dependencies> <build> diff --git a/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java b/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java index 79d761d6..f34df89f 100644 --- a/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java +++ b/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java @@ -29,11 +29,13 @@ import org.onap.cli.fw.conf.OnapCommandConfig; import org.onap.cli.fw.conf.OnapCommandConstants; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.input.OnapCommandParameter; +import org.onap.cli.fw.input.OnapCommandParameterType; import org.onap.cli.fw.output.OnapCommandResultType; import org.onap.cli.fw.registrar.OnapCommandRegistrar; import org.onap.cli.fw.store.OnapCommandExecutionStore; import org.onap.cli.fw.store.OnapCommandExecutionStore.ExecutionStoreContext; import org.onap.cli.main.OnapCli; +import org.onap.cli.main.utils.OnapCliArgsParser; import org.open.infc.grpc.Args; import org.open.infc.grpc.Input; import org.open.infc.grpc.OpenInterfaceGrpc; @@ -181,6 +183,24 @@ public class OpenInterfaceGrpcServer { if (params.contains(arg.getKey())) cmd.getParametersMap().get(arg.getKey()).setValue(arg.getValue()); } + + //fill values from the file, if needed + for (OnapCommandParameter param: cmd.getParameters()) { + if (param.getParameterType().equals(OnapCommandParameterType.JSON)) { + param.setValue(OnapCliArgsParser.readJsonStringFromUrl(param.getValue().toString(), param.getName())); + + } else if (param.getParameterType().equals(OnapCommandParameterType.TEXT)) { + param.setValue(OnapCliArgsParser.readTextStringFromUrl(param.getValue().toString(), param.getName())); + + } else if (param.getParameterType().equals(OnapCommandParameterType.BYTE)) { + param.setValue(OnapCliArgsParser.readBytesFromUrl(param.getValue().toString(), param.getName())); + + } else if (param.getParameterType().equals(OnapCommandParameterType.YAML)) { + param.setValue(OnapCliArgsParser.readYamlStringFromUrl(param.getValue().toString(), param.getName())); + + } + } + } else { cmd.getParametersMap().get(OnapCommandConstants.INFO_PRODUCT).setValue(product); @@ -194,7 +214,9 @@ public class OpenInterfaceGrpcServer { if (!cmd.isRpc()) { //Start the execution - if (req.getRequestId() != null) { + if (req.getRequestId() != null && !req.getRequestId().isEmpty()) { + if (!(cmd.getInfo().getProduct().equalsIgnoreCase("open-cli") && + cmd.getName().equalsIgnoreCase("execution-list"))) { String input = cmd.getArgsJson(true); executionStoreContext = OnapCommandExecutionStore.getStore().storeExectutionStart( req.getRequestId(), @@ -203,12 +225,16 @@ public class OpenInterfaceGrpcServer { cmd.getName(), profile, input); + } } } - + cmd.setExecutionContext(executionStoreContext); cmd.execute(); if (!cmd.isRpc()) { + //Track and/or persist the execution context + new OnapCli().handleTracking(cmd); + String printOut = cmd.getResult().print(); Builder reply = Output.newBuilder(); reply.putAttrs(OnapCommandConstants.ERROR, "{}"); @@ -226,15 +252,6 @@ public class OpenInterfaceGrpcServer { } output = reply.build(); - - if (req.getRequestId() != null) { - //complete the execution recording - OnapCommandExecutionStore.getStore().storeExectutionEnd( - executionStoreContext, - printOut, - null, - cmd.getResult().isPassed()); - } logger.info(output.toString()); } else { //Rpc command will set the output. @@ -254,6 +271,7 @@ public class OpenInterfaceGrpcServer { executionStoreContext, null, e.getMessage(), + cmd.getResult().getDebugInfo(), false); reply.putAddons("execution-id", executionStoreContext.getExecutionId()); } diff --git a/grpc/grpc-stub/pom.xml b/grpc/grpc-stub/pom.xml index 0b8007d8..28703a43 100644 --- a/grpc/grpc-stub/pom.xml +++ b/grpc/grpc-stub/pom.xml @@ -18,7 +18,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>oclip-grpc</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>oclip-grpc-stub</artifactId> <name>oclip/grpc/stub</name> diff --git a/grpc/pom.xml b/grpc/pom.xml index 1023e629..75721607 100644 --- a/grpc/pom.xml +++ b/grpc/pom.xml @@ -18,9 +18,9 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> <artifactId>oclip-grpc</artifactId> <packaging>pom</packaging> <name>oclip/grpc</name> diff --git a/main/pom.xml b/main/pom.xml index 3fb4288f..9a5465c2 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-main</artifactId> @@ -37,12 +37,6 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.11</version> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.onap.cli</groupId> <artifactId>cli-framework</artifactId> <version>${project.parent.version}</version> @@ -52,12 +46,24 @@ <artifactId>jline</artifactId> <version>2.6</version> </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + </dependency> <dependency> <groupId>org.jmockit</groupId> <artifactId>jmockit</artifactId> <version>1.19</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.jmockit</groupId> + <artifactId>jmockit-coverage</artifactId> + <version>1.19</version> + <scope>test</scope> + </dependency> </dependencies> <build> <plugins> diff --git a/main/src/main/java/org/onap/cli/main/OnapCli.java b/main/src/main/java/org/onap/cli/main/OnapCli.java index 582be3c8..75bf5d18 100644 --- a/main/src/main/java/org/onap/cli/main/OnapCli.java +++ b/main/src/main/java/org/onap/cli/main/OnapCli.java @@ -43,6 +43,7 @@ import org.onap.cli.fw.registrar.OnapCommandRegistrar; import org.onap.cli.fw.store.OnapCommandExecutionStore; import org.onap.cli.fw.store.OnapCommandExecutionStore.ExecutionStoreContext; import org.onap.cli.fw.utils.OnapCommandDiscoveryUtils; +import org.onap.cli.fw.utils.OnapCommandUtils; import org.onap.cli.main.conf.OnapCliConstants; import org.onap.cli.main.interactive.StringCompleter; import org.onap.cli.main.utils.OnapCliArgsParser; @@ -162,8 +163,9 @@ public class OnapCli { } private void print(Throwable throwable) { - this.print(throwable.getMessage() != null ? throwable.getMessage() : ""); - log.error(throwable.getMessage(), throwable); + String error = throwable.getMessage() != null ? throwable.getMessage() : ""; + this.print(error); + log.error(error, throwable); } private String getShortOption(String opt) { @@ -282,7 +284,9 @@ public class OnapCli { .filter(e -> e.getName().equals(OnapCommandConstants.VERIFY_CONTEXT_PARAM)) .findFirst(); - List<Map<String, ?>> testSuite = OnapCommandRegistrar.getRegistrar().getTestSuite(cmd.getName()); + List<Map<String, ?>> testSuite = OnapCommandRegistrar.getRegistrar().getTestSuite( + cmd.getName(), + cmd.getInfo().getProduct()); OnapCommandResult testSuiteResult = new OnapCommandResult(); testSuiteResult.setType(OnapCommandResultType.TABLE); @@ -306,11 +310,10 @@ public class OnapCli { sampleFileAtt.getValues().add((String) sampleTest.get(OnapCommandConstants.VERIFY_SAMPLE_FILE_ID)); sampleIdAtt.getValues().add((String) sampleTest.get(OnapCommandConstants.VERIFY_SAMPLE_ID)); - cmd = OnapCommandRegistrar.getRegistrar().get(this.cmdName); + cmd = OnapCommandRegistrar.getRegistrar().get(cmd.getName(), + cmd.getInfo().getProduct()); List<String> arguments = (List<String>) sampleTest.get(OnapCommandConstants.VERIFY_INPUT); - if (arguments.size() > 0 && arguments.get(0).equals(this.cmdName)) { - arguments.remove(0); - } + OnapCliArgsParser.populateParams(cmd.getParameters(), arguments); this.print("\n***************Test Command: \n" + sampleTest.get(OnapCommandConstants.VERIFY_INPUT).toString()); @@ -530,38 +533,31 @@ public class OnapCli { OnapCliArgsParser.populateParams(cmd.getParameters(), this.args); //start the execution - if (this.requestId != null) { - String input = cmd.getArgsJson(true); - executionStoreContext = OnapCommandExecutionStore.getStore().storeExectutionStart( - this.requestId, - cmd.getInfo().getProduct(), - cmd.getInfo().getService(), - this.cmdName, - this.profile, - input); + if (this.requestId != null && !this.requestId.isEmpty()) { + if (!(this.product.equalsIgnoreCase("open-cli") && + this.cmdName.equalsIgnoreCase("execution-list"))) { + String input = cmd.getArgsJson(true); + executionStoreContext = OnapCommandExecutionStore.getStore().storeExectutionStart( + this.requestId, + cmd.getInfo().getProduct(), + cmd.getInfo().getService(), + this.cmdName, + this.profile, + input); + } } + cmd.setExecutionContext(executionStoreContext); OnapCommandResult result = cmd.execute(); - String printOut = result.print(); - if (this.requestId != null) { - OnapCommandExecutionStore.getStore().storeExectutionEnd( - executionStoreContext, - printOut, - null, result.isPassed()); - } - - this.print(result.getDebugInfo()); - this.print(printOut); + this.handleTracking(cmd); if (result.isPassed()) { this.exitSuccessfully(); generateSmapleYaml(cmd); + } else { + this.exitFailure(); } - - else this.exitFailure(); - - } catch (OnapCommandWarning w) { this.print(w); this.print(cmd.getResult().getDebugInfo()); @@ -572,6 +568,7 @@ public class OnapCli { executionStoreContext, null, e.getMessage(), + cmd.getResult().getDebugInfo(), false); } @@ -582,21 +579,35 @@ public class OnapCli { } } + public void handleTracking(OnapCommand cmd) throws OnapCommandException { + if (cmd.getResult().isDebug()) + this.print(cmd.getResult().getDebugInfo()); + + String printOut = cmd.getResult().print(); + this.print(printOut); + + if (cmd.getExecutionContext() != null) { + OnapCommandExecutionStore.getStore().storeExectutionEnd( + cmd.getExecutionContext(), + printOut, + null, + cmd.getResult().getDebugInfo(), + cmd.getResult().isPassed()); + } + } /** * When user invokes cli with RPC arguments... */ public void handleRpc() { - if (!this.args.isEmpty()) { + if (this.rpcHost != null && this.rpcPort != null && this.product != null) { try { - if (this.rpcHost != null && this.rpcPort != null && this.product != null) { - OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("schema-rpc", "open-cli"); - cmd.getParametersMap().get(OnapCommandConstants.RPC_HOST).setValue(this.rpcHost); - cmd.getParametersMap().get(OnapCommandConstants.RPC_PORT).setValue(this.rpcPort); - cmd.getParametersMap().get(OnapCommandConstants.RPC_PRODUCT).setValue(this.product); - cmd.getParametersMap().get(OnapCommandConstants.RPC_CMD).setValue(this.cmdName); + OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("schema-rpc", "open-cli"); + cmd.getParametersMap().get(OnapCommandConstants.RPC_HOST).setValue(this.rpcHost); + cmd.getParametersMap().get(OnapCommandConstants.RPC_PORT).setValue(this.rpcPort); + cmd.getParametersMap().get(OnapCommandConstants.RPC_PRODUCT).setValue(this.product); + cmd.getParametersMap().get(OnapCommandConstants.RPC_CMD).setValue(this.cmdName); - this.handleRpcCommand(cmd); - } + this.handleRpcCommand(cmd); } catch (Exception e) { this.print(e); this.exitFailure(); @@ -730,8 +741,8 @@ public class OnapCli { private void generateSmapleYaml(OnapCommand cmd) throws OnapCommandException { if (Boolean.parseBoolean(OnapCommandConfig.getPropertyValue(OnapCommandConstants.SAMPLE_GEN_ENABLED)) && this.getExitCode() == OnapCliConstants.EXIT_SUCCESS) { try { - SampleYamlGenerator.generateSampleYaml(args, cmd.getResult().print(), - OnapCommandRegistrar.getRegistrar().getEnabledProductVersion(), + SampleYamlGenerator.generateSampleYaml(cmd.getName(), args, cmd.getResult().print(), + cmd.getInfo().getProduct(), OnapCommandConfig.getPropertyValue(OnapCommandConstants.SAMPLE_GEN_TARGET_FOLDER) + "/" + cmd.getSchemaName().replaceAll(".yaml", "") + "-sample.yaml", cmd.getResult().isDebug()); } catch (IOException error) { diff --git a/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java index a1bde717..a07c08f2 100644 --- a/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java +++ b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandInvalidParameterValue; @@ -32,6 +33,7 @@ import org.onap.cli.fw.input.OnapCommandParameter; import org.onap.cli.fw.input.OnapCommandParameterType; import org.onap.cli.main.error.OnapCliArgumentValueMissing; import org.onap.cli.main.error.OnapCliInvalidArgument; +import org.yaml.snakeyaml.Yaml; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; @@ -116,12 +118,25 @@ public class OnapCliArgsParser { i++; continue; - } if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.TEXT)) { + } else if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.TEXT)) { paramMap.get(paramName).setValue(readTextStringFromUrl(args.get(i + 1), paramMap.get(paramName).getName())); i++; continue; + } else if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.YAML)) { + String value = readYamlStringFromUrl(args.get(i + 1), + paramMap.get(paramName).getName()); + paramMap.get(paramName).setValue(value); + i++; + continue; + + } else if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.BYTE)) { + paramMap.get(paramName).setValue(readBytesFromUrl(args.get(i + 1), + paramMap.get(paramName).getName())); + i++; + continue; + } else if (paramMap.get(paramName).getParameterType() .equals(OnapCommandParameterType.ARRAY)) { Object value = paramMap.get(paramName).getValue(); @@ -177,7 +192,7 @@ public class OnapCliArgsParser { params.addAll(paramMap.values()); } - private static String readJsonStringFromUrl(String input, String argName) throws OnapCliInvalidArgument { + public static String readJsonStringFromUrl(String input, String argName) throws OnapCliInvalidArgument { ObjectMapper mapper = new ObjectMapper(); try { File file = new File(input); @@ -194,7 +209,7 @@ public class OnapCliArgsParser { } } - private static String readTextStringFromUrl(String input, String argName) throws OnapCliInvalidArgument { + public static String readTextStringFromUrl(String input, String argName) throws OnapCliInvalidArgument { try { File file = new File(input); if (file.isFile()) { @@ -208,7 +223,38 @@ public class OnapCliArgsParser { } } - private static List<String> convertJsonToListString(String arg, String json) throws OnapCliInvalidArgument { + public static String readYamlStringFromUrl(String input, String argName) throws OnapCliInvalidArgument { + try { + File file = new File(input); + if (file.isFile()) { + String value = FileUtils.readFileToString(file); + new Yaml().load(value); + return value; + } else { + return input; + } + + } catch (IOException e) { + throw new OnapCliInvalidArgument(argName, e); + } + } + + public static String readBytesFromUrl(String input, String argName) throws OnapCliInvalidArgument { + try { + File file = new File(input); + if (file.isFile()) { + byte[] encodeBase64 = Base64.encodeBase64(FileUtils.readFileToByteArray(file)); + return new String(encodeBase64); + } else { + byte[] encodeBase64 = Base64.encodeBase64(input.getBytes()); + return new String(encodeBase64); + } + } catch (IOException e) { + throw new OnapCliInvalidArgument(argName, e); + } + } + + public static List<String> convertJsonToListString(String arg, String json) throws OnapCliInvalidArgument { TypeReference<List<String>> mapType = new TypeReference<List<String>>() { }; try { @@ -218,7 +264,7 @@ public class OnapCliArgsParser { } } - private static Map<String, String> convertJsonToMapString(String arg, String json) throws OnapCliInvalidArgument { + public static Map<String, String> convertJsonToMapString(String arg, String json) throws OnapCliInvalidArgument { TypeReference<Map<String, String>> mapType = new TypeReference<Map<String, String>>() { }; try { diff --git a/main/src/main/resources/oclip-readme.txt b/main/src/main/resources/oclip-readme.txt index bea04b79..6c929ec7 100644 --- a/main/src/main/resources/oclip-readme.txt +++ b/main/src/main/resources/oclip-readme.txt @@ -1,25 +1,10 @@ -Open Command-line interface Platform(OCLIP) -=========================================== - - _____ _____ _ _____ -| _ | / __ \| | |_ _| -| | | |_ __ ___ _ __ | / \/| | | | -| | | | '_ \ / _ \ '_ \ | | | | | | -\ \_/ / |_) | __/ | | | | \__/\| |_____| |_ - \___/| .__/ \___|_| |_| \____/\_____/\___/ - | | - |_| - -Provides unified commands to operate any cloud enabled software -products from Linux/Web console. Configure the following environment -variables, before using it: - -1. OPEN_CLI_HOST_URL - Catalog service URL or a service URL -2. OPEN_CLI_HOST_USERNAME - Service user name -3. OPEN_CLI_HOST_PASSWORD - Service password - -To know the CLI version, type oclip [-v|--version] -To know the CLI usage, type oclip [-h|--help] -To know the usage of sub commands, type oclip <command> [-h|--help] - -To know more, please refer the wiki https://wiki.onap.org + ___ ___ ___ _ __ ___ _ __ + / _ \ / __/ _ \| '_ ` _ \| '_ \ +| (_) | (_| (_) | | | | | | |_) | + \___/ \___\___/|_| |_| |_| .__/ + | | + |_| + +Open Command Platform (OCOMP) facilitates to model any cloud-enabled or monolithic software +product's functionality as command using Open Command Specification (OCS) and provides +Web and command line Shell to access and operate these commands. @@ -25,7 +25,7 @@ <groupId>org.onap.cli</groupId> <artifactId>cli</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> <packaging>pom</packaging> <name>cli</name> diff --git a/products/onap-amsterdam/auth/pom.xml b/products/onap-amsterdam/auth/pom.xml index d6b1c43e..c80fc71f 100644 --- a/products/onap-amsterdam/auth/pom.xml +++ b/products/onap-amsterdam/auth/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-amsterdam</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-amsterdam-auth</artifactId> diff --git a/products/onap-amsterdam/catalog/pom.xml b/products/onap-amsterdam/catalog/pom.xml index a7afa9bb..9fb5262f 100644 --- a/products/onap-amsterdam/catalog/pom.xml +++ b/products/onap-amsterdam/catalog/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-amsterdam</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-amsterdam-catalog</artifactId> diff --git a/products/onap-amsterdam/features/aai/pom.xml b/products/onap-amsterdam/features/aai/pom.xml index b68499e7..37f6e7df 100644 --- a/products/onap-amsterdam/features/aai/pom.xml +++ b/products/onap-amsterdam/features/aai/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-amsterdam-features</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-amsterdam-features-aai</artifactId> diff --git a/products/onap-amsterdam/features/msb/pom.xml b/products/onap-amsterdam/features/msb/pom.xml index 7e9f7ce9..f8e4d5fa 100644 --- a/products/onap-amsterdam/features/msb/pom.xml +++ b/products/onap-amsterdam/features/msb/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-amsterdam-features</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-amsterdam-features-msb</artifactId> diff --git a/products/onap-amsterdam/features/pom.xml b/products/onap-amsterdam/features/pom.xml index f2f4f6ae..b0362073 100644 --- a/products/onap-amsterdam/features/pom.xml +++ b/products/onap-amsterdam/features/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-amsterdam</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-amsterdam-features</artifactId> diff --git a/products/onap-amsterdam/features/sdc/pom.xml b/products/onap-amsterdam/features/sdc/pom.xml index ae0cab77..8fb70059 100644 --- a/products/onap-amsterdam/features/sdc/pom.xml +++ b/products/onap-amsterdam/features/sdc/pom.xml @@ -22,7 +22,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-amsterdam-features</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-amsterdam-features-sdc</artifactId> diff --git a/products/onap-amsterdam/features/so/pom.xml b/products/onap-amsterdam/features/so/pom.xml index 5beb19ec..51d572f4 100644 --- a/products/onap-amsterdam/features/so/pom.xml +++ b/products/onap-amsterdam/features/so/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-amsterdam-features</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-amsterdam-features-so</artifactId> diff --git a/products/onap-amsterdam/pom.xml b/products/onap-amsterdam/pom.xml index f30a2c4a..e4c26d99 100644 --- a/products/onap-amsterdam/pom.xml +++ b/products/onap-amsterdam/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-amsterdam</artifactId> diff --git a/products/onap-beijing/auth/pom.xml b/products/onap-beijing/auth/pom.xml index 3f7d5d63..5c6de139 100644 --- a/products/onap-beijing/auth/pom.xml +++ b/products/onap-beijing/auth/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-beijing</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-beijing-auth</artifactId> diff --git a/products/onap-beijing/catalog/pom.xml b/products/onap-beijing/catalog/pom.xml index 0215fbbe..9919ba6f 100644 --- a/products/onap-beijing/catalog/pom.xml +++ b/products/onap-beijing/catalog/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-beijing</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-beijing-catalog</artifactId> diff --git a/products/onap-beijing/features/aai/pom.xml b/products/onap-beijing/features/aai/pom.xml index 95e2aa1d..04c83f98 100644 --- a/products/onap-beijing/features/aai/pom.xml +++ b/products/onap-beijing/features/aai/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-beijing-features</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-beijing-features-aai</artifactId> diff --git a/products/onap-beijing/features/appc/pom.xml b/products/onap-beijing/features/appc/pom.xml index 6b157c29..4370a54c 100644 --- a/products/onap-beijing/features/appc/pom.xml +++ b/products/onap-beijing/features/appc/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-beijing-features</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-beijing-features-appc</artifactId> diff --git a/products/onap-beijing/features/msb/pom.xml b/products/onap-beijing/features/msb/pom.xml index 130cac07..c330f809 100644 --- a/products/onap-beijing/features/msb/pom.xml +++ b/products/onap-beijing/features/msb/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-beijing-features</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-beijing-features-msb</artifactId> diff --git a/products/onap-beijing/features/policy/pom.xml b/products/onap-beijing/features/policy/pom.xml index d6b25b1a..1c277557 100644 --- a/products/onap-beijing/features/policy/pom.xml +++ b/products/onap-beijing/features/policy/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-beijing-features</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-beijing-features-policy</artifactId> diff --git a/products/onap-beijing/features/pom.xml b/products/onap-beijing/features/pom.xml index 3c9ac625..7aee7bf6 100644 --- a/products/onap-beijing/features/pom.xml +++ b/products/onap-beijing/features/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-beijing</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-beijing-features</artifactId> diff --git a/products/onap-beijing/features/sdc/pom.xml b/products/onap-beijing/features/sdc/pom.xml index e81e4e04..36b95b56 100644 --- a/products/onap-beijing/features/sdc/pom.xml +++ b/products/onap-beijing/features/sdc/pom.xml @@ -22,7 +22,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-beijing-features</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-beijing-features-sdc</artifactId> diff --git a/products/onap-beijing/features/so/pom.xml b/products/onap-beijing/features/so/pom.xml index c2fcb77b..26240c54 100644 --- a/products/onap-beijing/features/so/pom.xml +++ b/products/onap-beijing/features/so/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-beijing-features</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-beijing-features-so</artifactId> diff --git a/products/onap-beijing/pom.xml b/products/onap-beijing/pom.xml index c0d38844..05a30b55 100644 --- a/products/onap-beijing/pom.xml +++ b/products/onap-beijing/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products</artifactId> - <version>2.0.3</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-beijing</artifactId> diff --git a/products/onap-casablanca/auth/pom.xml b/products/onap-casablanca/auth/pom.xml index c764aa93..2ac24941 100644 --- a/products/onap-casablanca/auth/pom.xml +++ b/products/onap-casablanca/auth/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-casablanca</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-casablanca-auth</artifactId> diff --git a/products/onap-casablanca/catalog/pom.xml b/products/onap-casablanca/catalog/pom.xml index a436d8b0..68e73bb7 100644 --- a/products/onap-casablanca/catalog/pom.xml +++ b/products/onap-casablanca/catalog/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-casablanca</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-casablanca-catalog</artifactId> diff --git a/products/onap-casablanca/features/aai/pom.xml b/products/onap-casablanca/features/aai/pom.xml index 19371b61..543cf177 100644 --- a/products/onap-casablanca/features/aai/pom.xml +++ b/products/onap-casablanca/features/aai/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-casablanca-features</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-casablanca-features-aai</artifactId> diff --git a/products/onap-casablanca/features/msb/pom.xml b/products/onap-casablanca/features/msb/pom.xml index 1cebb35e..047a17db 100644 --- a/products/onap-casablanca/features/msb/pom.xml +++ b/products/onap-casablanca/features/msb/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-casablanca-features</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-casablanca-features-msb</artifactId> diff --git a/products/onap-casablanca/features/pom.xml b/products/onap-casablanca/features/pom.xml index c9a77c9f..637d5fe0 100644 --- a/products/onap-casablanca/features/pom.xml +++ b/products/onap-casablanca/features/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-casablanca</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-casablanca-features</artifactId> diff --git a/products/onap-casablanca/features/sdc/pom.xml b/products/onap-casablanca/features/sdc/pom.xml index 71485a25..94c057b5 100644 --- a/products/onap-casablanca/features/sdc/pom.xml +++ b/products/onap-casablanca/features/sdc/pom.xml @@ -22,7 +22,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-casablanca-features</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-casablanca-features-sdc</artifactId> diff --git a/products/onap-casablanca/features/vnfsdk/pom.xml b/products/onap-casablanca/features/vnfsdk/pom.xml index 26563fbb..b0ea6602 100644 --- a/products/onap-casablanca/features/vnfsdk/pom.xml +++ b/products/onap-casablanca/features/vnfsdk/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-casablanca-features</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-casablanca-features-vnfsdk</artifactId> diff --git a/products/onap-casablanca/pom.xml b/products/onap-casablanca/pom.xml index 48ff1c88..d812427b 100644 --- a/products/onap-casablanca/pom.xml +++ b/products/onap-casablanca/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-casablanca</artifactId> diff --git a/products/onap-dublin/auth/pom.xml b/products/onap-dublin/auth/pom.xml index e3dd7f81..42892c9a 100644 --- a/products/onap-dublin/auth/pom.xml +++ b/products/onap-dublin/auth/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-dublin</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-dublin-auth</artifactId> diff --git a/products/onap-dublin/catalog/pom.xml b/products/onap-dublin/catalog/pom.xml index 55e35337..d5bff21d 100644 --- a/products/onap-dublin/catalog/pom.xml +++ b/products/onap-dublin/catalog/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-dublin</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-dublin-catalog</artifactId> diff --git a/products/onap-dublin/features/aai/pom.xml b/products/onap-dublin/features/aai/pom.xml index 0383c0bc..f774302c 100644 --- a/products/onap-dublin/features/aai/pom.xml +++ b/products/onap-dublin/features/aai/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-dublin-features</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-dublin-features-aai</artifactId> diff --git a/products/onap-dublin/features/integration/pom.xml b/products/onap-dublin/features/integration/pom.xml new file mode 100644 index 00000000..10ca092d --- /dev/null +++ b/products/onap-dublin/features/integration/pom.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2019 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. + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 + http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.cli</groupId> + <artifactId>cli-products-onap-dublin-features</artifactId> + <version>4.0.0-SNAPSHOT</version> + </parent> + + <artifactId>cli-products-onap-dublin-features-integration</artifactId> + <name>cli/products/onap-dublin/features/integration</name> + <packaging>jar</packaging> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/products/onap-dublin/features/integration/src/main/resources/conf/ovp-tosca-vnf-provision.json b/products/onap-dublin/features/integration/src/main/resources/conf/ovp-tosca-vnf-provision.json new file mode 100644 index 00000000..f3a5354e --- /dev/null +++ b/products/onap-dublin/features/integration/src/main/resources/conf/ovp-tosca-vnf-provision.json @@ -0,0 +1,141 @@ +{ + "open_cli_product" : "onap-dublin", + "open_cli_home" : "/opt/vtp", + "aai_url" : "https://10.12.5.224:30233", + "aai_username" : "AAI", + "aai_password" : "AAI", + + "sdc_onboarding_url" : "http://10.43.89.129:8081", + "sdc_catalog_url" : "http://10.12.5.224:30205", + "sdc_password" : "demo123456!", + "sdc_creator" : "cs0008", + "sdc_tester" : "jm0007", + "sdc_governor" : "gv0001", + "sdc_operator" : "op0001", + "sdc_consumer" : "ocomp", + + "multicloud_url" : "http://10.12.5.224:30280", + + "//" : "#Parameters required to create cloud complex", + "complex_name" : "OVP-LCM", + "street1" : "street1", + "street2" : "street2", + "physical_location" : "phy_type", + "data_center_code" : "ocomp", + "latitude" : "32.89948", + "longitude" : "97.045443", + "lata" : "example-lata-val-28399", + "elevation" : "example-elevation-val-28399", + "region" : "northwest", + "state" : "oregon", + "city" : "hillsboro", + "postal-code" : "00000", + "country" : "USA", + "identity_url" : "http://10.12.11.1:5000/v3", + "service-model-name" : "usn", + "//" : "#Dictionary containing cloud regions and their Parameters", + + "cloud_region_data":{ + "ONAP-POD-01-Rail-05":{ + "cloud-region-version" : "titanium_cloud", + "esr-system-info-id":"5c85ce1f-aa78-4ebf-8d6f-4b62784e9bc7", + "service-url": "http://10.12.11.1:5000/v3", + "user-name":"${cloud-username}", + "password":"${cloud-password}", + "system-type": "VIM", + "ssl-insecure":true, + "cloud-domain":"Default", + "default-tenant":"Integration-HPA", + "tenant-id" : "709ba629fe194f8699b12f9d6ffd86a0", + "cloud-type" : "openstack", + "identity-url": "WillBeUpdatedByMultiCloud", + "system-status":"active" + } + }, + + "//" : "#Parameters to register cloud region", + "cloud-owner" : "CloudOwner", + "owner-defined-type" : "t1", + "cloud-zone" : "CloudZone", + + "service_name" : "USN", + "customer_name" : "ocomp", + "subscriber_name" : "ocomp", + + "//" : "Onboarding parameters", + "vendor-name" : "Huawei", + "entitlement-pool-name" : "ovp-pool", + "entitlement-description" : "ovp-pool", + "start-date" : "08/01/2019", + "expiry-date" : "12/31/2019", + "key-group-name" : "ovp-key", + "key-group-type" : "Universal", + "feature-grp-name" : "ovp-feature", + "feature-grp-desc" : "ovp-feature", + "part-no" : "ovp-part", + "agreement-name" : "ovp-agreement", + "agreement-desc" : "ovp-agreement", + + "onboarding-method" : "NetworkPackage", + + "//" : "Be sure to include single quotes in parameters that have spaces", + "project-code" : "000000", + "service-model-name" : "usn", + "service-model-desc" : "'usn service'", + "icon-id" : "network_l_1-3", + "category-display" : "'Network L1-3'", + "category" : "'network l1-3'", + + "service-test-remarks" : "ovp test", + "service-accept-remarks" : "accepted", + "service-approve-remarks" : "approved", + + "//" : "#Parameters to vfc", + "vfc-url": "http://10.12.5.224:30280", + "vnfs":{ + "usn":{ + "path": "/opt/vtp/data/usn.csar", + "csar-id": "You need change it", + "vsp-name" : "ovp-usn", + "vsp-desc" : "ovp usn", + "vsp-version" : "1.0", + "vf-name" : "ovp-vf", + "vf-description" : "ovp vf", + "vf-remarks" :"ovp test", + "vf-version" : "1.0", + "key": "key2", + "value": "value2" + } + }, + "ns":{ + "csar-id": "You need change it", + "key": "key1", + "value": "value1", + "path": "/opt/vtp/data/usn_service.csar", + "name": "ovp-usn" + }, + "location": "CloudOwner_ONAP-POD-01-Rail-05", + "vnfm_params":{ + "GVNFMDRIVER":{ + "type": "gvnfmdriver", + "vendor": "vfc", + "version": "v1.0", + "url": "http://msb-iag:80/", + "vim-id": "CloudOwner_ONAP-POD-01-Rail-05", + "user-name": "admin", + "user-password": "admin", + "vnfm-version": "v1.0" + }, + "HWVNFMDRIVER":{ + "type": "hwvnfmdriver", + "vendor": "vfc", + "version": "v1.0", + "url": "http://msb-iag:80/", + "vim-id": "CloudOwner_ONAP-POD-01-Rail-05", + "user-name": "admin", + "user-password": "admin", + "vnfm-version": "v1.0" + } + }, + "sdc-controller-id": "2" +} diff --git a/products/onap-dublin/features/integration/src/main/resources/open-cli-schema/ovp-tosca-vnf-provision.yaml b/products/onap-dublin/features/integration/src/main/resources/open-cli-schema/ovp-tosca-vnf-provision.yaml new file mode 100644 index 00000000..b98bef76 --- /dev/null +++ b/products/onap-dublin/features/integration/src/main/resources/open-cli-schema/ovp-tosca-vnf-provision.yaml @@ -0,0 +1,90 @@ +# Copyright 2019 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. + +open_cli_schema_version: 1.0 +name: tosca-vnf-provision +description: | + Provision TOSCA based VNF using ONAP. + More details: https://wiki.lfnetworking.org/display/LN/TOSCA+VNF+Validation+Planning + +info: + product: onap-dublin + service: vnf-validation + author: ONAP VTP Team onap-discuss@lists.onap.org + +parameters: + - name: config-json + description: Configuration file path + type: string + short_option: x + long_option: config-json + default_value: $s{env:OPEN_CLI_HOME}/conf/ovp-tosca-vnf-provision.json + is_optional: false + - name: vsp + description: Path to the ONAP vendor service product (VSP) for the VNF to provision + type: binary + short_option: y + long_option: vsp + is_optional: false + - name: vnf-csar + description: Path to the TOSCA CSAR for the VNF to provision + type: binary + short_option: r + long_option: vnf-csar + is_optional: false + - name: ns-csar + description: Path to the TOSCA CSAR for the NS service to provision + type: binary + short_option: b + long_option: ns-csar + is_optional: true + default: false + - name: vnfm-driver + description: VNFM driver to use + type: string + short_option: c + long_option: vnfm-driver + is_optional: false + +results: + direction: portrait + attributes: + - name: vnf-id + description: ONAP VNF instance id + scope: short + type: string + - name: vnf-status + description: Onap VNF status + scope: short + type: string + - name: ns-id + description: Onap NS service instance id + scope: short + type: string + - name: ns-status + description: Onap NS status + scope: short + type: string +cmd: + command: + - python $s{env:OPEN_CLI_HOME}/script/ovp-tosca-vnf-provision.py --result-json $s{tmp:result.json} --config-json ${config-json} --vsp ${vsp} --vnf-csar ${vnf-csar} --ns-csar ${ns-csar} --vnfm-driver ${vnfm-driver} + success_codes: + - 0 + working_directory: . + output: $s{tmp:result.json} + result_map: + vnf-id: $o{$.vnf_id} + vnf-status: $o{$.vnf_status} + ns-id: $o{$.ns_id} + ns-status: $o{$.vnf_status}
\ No newline at end of file diff --git a/products/onap-dublin/features/integration/src/main/resources/script/ovp-tosca-vnf-provision.py b/products/onap-dublin/features/integration/src/main/resources/script/ovp-tosca-vnf-provision.py new file mode 100644 index 00000000..dddb0a08 --- /dev/null +++ b/products/onap-dublin/features/integration/src/main/resources/script/ovp-tosca-vnf-provision.py @@ -0,0 +1,456 @@ +#!/usr/bin/python + +import json +import os +import time +import argparse +import sys +import requests +import __main__ + +def get_parameters(file): + parameters = json.load(file) + return parameters + +def get_out_helper(in_string): + out_list = (((in_string.replace('-','')).replace('|', '')).replace('+', '')).split() + return out_list + +def get_out_helper_2(in_string): + out_list = ((in_string.replace('|', '')).replace('+', '')).split() + return out_list + +def set_open_cli_env(parameters): + os.environ["OPEN_CLI_PRODUCT_IN_USE"] = parameters["open_cli_product"] + os.environ["OPEN_CLI_HOME"] = parameters["open_cli_home"] + +def create_complex(parameters): + complex_create_string = "oclip complex-create -j {} -r {} -x {} -y {} -lt {} -l {} -i {} -lo {} \ + -S {} -la {} -g {} -w {} -z {} -k {} -o {} -q {} -m {} -u {} -p {}".format(parameters["street2"], \ + parameters["physical_location"], parameters["complex_name"], \ + parameters["data_center_code"], parameters["latitude"], parameters["region"], \ + parameters["street1"], parameters["longitude"], parameters["state"], \ + parameters["lata"], parameters["city"], parameters["postal-code"], \ + parameters["complex_name"], parameters["country"], parameters["elevation"], \ + parameters["identity_url"], parameters["aai_url"], parameters["aai_username"], \ + parameters["aai_password"]) + + os.system(complex_create_string) + +def create_vlm(parameters): + vlm_create_string = "oclip vlm-create -x {} -u {} -p {} -m {}".format(parameters["vendor-name"], \ + parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"]) + command_out = (os.popen(vlm_create_string)).read() + out_list = get_out_helper(command_out) + vlm_id = out_list[3] + vlm_version = out_list[5] + + entitlement_string = "oclip vlm-entitlement-pool-create -x {} -y {} -e {} -z {} -k {} -g {} -l {} -u {} -p {} -m {}".format( \ + parameters["entitlement-pool-name"], vlm_id, vlm_version, parameters["entitlement-description"], parameters["vendor-name"], \ + parameters["expiry-date"], parameters["start-date"], parameters["sdc_creator"], parameters["sdc_password"], \ + parameters["sdc_onboarding_url"]) + command_out = (os.popen(entitlement_string)).read() + entitlement_id = (get_out_helper(command_out))[3] + + + key_group_string = "oclip vlm-key-group-create -c {} -e {} -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, \ + parameters["key-group-name"], parameters["key-group-type"], parameters["sdc_creator"], parameters["sdc_password"], \ + parameters["sdc_onboarding_url"]) + command_out = (os.popen(key_group_string)).read() + key_group_id = (get_out_helper(command_out))[3] + + feature_group_string = "oclip vlm-feature-group-create -x {} -y {} -e {} -z {} -g {} -b {} -c {} -u {} -p {} -m {}".format( + parameters["feature-grp-name"], vlm_id, vlm_version, parameters["feature-grp-desc"], key_group_id, entitlement_id, \ + parameters["part-no"], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"]) + command_out = (os.popen(feature_group_string)).read() + feature_group_id = (get_out_helper(command_out))[3] + + agreement_string = "oclip vlm-aggreement-create -x {} -y {} -e {} -z {} -g {} -u {} -p {} -m {}".format(parameters["agreement-name"], \ + vlm_id, vlm_version, parameters["agreement-desc"], feature_group_id, parameters["sdc_creator"], parameters["sdc_password"], \ + parameters["sdc_onboarding_url"]) + command_out = (os.popen(agreement_string)).read() + agreement_id = (get_out_helper(command_out))[3] + + submit_string = "oclip vlm-submit -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, parameters["sdc_creator"], \ + parameters["sdc_password"], parameters["sdc_onboarding_url"]) + os.system(submit_string) + + output = [feature_group_id, agreement_id, vlm_version, vlm_id ] + return output + +def create_vsp(parameters, in_list): + vnfs = parameters["vnf"] + vsp_dict = {} + for name, value in vnfs.iteritems(): + create_string = "oclip vsp-create -j {} -o {} -e {} -x {} -y {} -i {} -c {} -g {} -u {} -p {} -m {}".format( in_list[0], \ + parameters["onboarding-method"], parameters["vendor-name" ], value.get("vsp-name"), value.get("vsp-desc"), in_list[1], \ + in_list[2], in_list[3], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"] ) + command_out = (os.popen(create_string)).read() + out_list = get_out_helper(command_out) + vsp_id = out_list[3] + vsp_version = out_list[5] + + os.system("oclip vsp-add-artifact -x {} -y {} -z {} -u {} -p {} -m {}".format(vsp_id, vsp_version, value.get("path"), \ + parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"])) + + os.system("oclip vsp-validate -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \ + parameters["sdc_password"], parameters["sdc_onboarding_url"])) + + os.system("oclip vsp-submit -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \ + parameters["sdc_password"], parameters["sdc_onboarding_url"])) + + os.system("oclip vsp-package -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \ + parameters["sdc_password"], parameters["sdc_onboarding_url"])) + + vsp_ids[name] = vsp_id + return vsp_ids + +def create_vf_model(parameters, vsp_dict): + vnfs = parameters["vnfs"] + vf_dict = {} + for name, value in vnfs.iteritems(): + create_string = "oclip vf-model-create -y {} -g {} -x {} -z {} -b {} -u {} -p {} -m {}".format(value.get("vf-description"), \ + value.get("vsp-version"), value.get("vf-name"), parameters["vendor-name"], vsp_dict[name], \ + parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]) + os.system(create_string) + + output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \ + parameters["sdc_creator"], parameters["sdc_password"], value.get("vf-name")))).read() + output = (get_out_helper_2(output)) + + vf_unique_id = output[1] + + # checkout + output = (os.popen("oclip vf-model-checkout --host-url {} --host-username {} --host-password {} --vf-model-uuid {} --format json".format( + parameters["sdc_catalog_url"], parameters["sdc_creator"], parameters["sdc_password"], vf_unique_id))).read() + vf_unique_id = (json.loads(output))['ID'] + + # add consumer, if already exist , just ignore, below command would fail simply !! + os.system("oclip sdc-consumer-create --consumer-name {}".format(parameters["sdc_consumer"])) + + def get_vnf_name(vnf_csar_path): + return vnf_csar_path.replace("_"," ").replace(".", " ").replace("-"," ") + + # add artifact + os.system("oclip vf-model-add-artifact --host-url {} --host-username {} --host-password {} --vf-model-uuid {} --artifact {} --artifact-name {}".format( + parameters["sdc_catalog_url"], parameters["sdc_consumer"], parameters["sdc_password"], vf_unique_id, vnf_csar, get_vnf_name(vnf_csar))) + + # check-in + os.system("oclip vf-model-checkin --host-url {} --host-username {} --host-password {} --vf-model-uuid {}".format( + parameters["sdc_catalog_url"], parameters["sdc_creator"], parameters["sdc_password"], vf_unique_id)) + + os.system("oclip vf-model-certify -b {} -r {} -u {} -p {} -m {}".format(vf_unique_id, value.get("vf-remarks"), \ + parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"])) + + #Check for new parameters after certification + output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \ + parameters["sdc_creator"], parameters["sdc_password"], value.get("vf-name")))).read() + output = (get_out_helper_2(output)) + + vf_dict[name] = output[1] + + return vf_dict + + +def create_service_model(parameters, vf_dict): + vnfs = parameters["vnfs"] + + create_string = "oclip service-model-create -z {} -y {} -e {} -x {} -c {} -b {} -u {} -p {} -m {} |grep ID".format(parameters["project-code"], \ + parameters["service-model-desc"], parameters["icon-id"], parameters["service-model-name"], parameters["category-display"], \ + parameters["category"],parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]) + + service_model_id = (get_out_helper_2((os.popen(create_string)).read()))[1] + + # checkout + output = (os.popen("oclip service-model-checkout --host-url {} --host-username {} --host-password {} --service-model-uuid {} --format json".format( + parameters["sdc_catalog_url"], parameters["sdc_creator"], parameters["sdc_password"], service_model_id))).read() + service_model_id = (json.loads(output))['ID'] + + # add consumer, if already exist , just ignore, below command would fail simply !! + os.system("oclip sdc-consumer-create --consumer-name {}".format(parameters["sdc_consumer"])) + + for name, value in vnfs.iteritems(): + output = (os.popen("oclip service-model-add-vf -x {} -b {} -y {} -z {} -u {} -p {} -m {}".format(service_model_id, \ + parameters["vf-version"], vf_dict[name], value.get("vf-name"), parameters["sdc_creator"], \ + parameters["sdc_password"], parameters["sdc_catalog_url"] ))).read() + vf_unique_id = (json.loads(output))['ID'] + vf_uuid = (json.loads(output))['UUID'] + + def get_ns_name(ns_csar_path): + return vnf_csar_path.replace("_"," ").replace(".", " ").replace("-"," ") + + # add artifact + os.system("oclip service-model-add-artifact --host-url {} --host-username {} --host-password {} --service-uniqueId {} --artifact {} --artifact-name {}".format( + parameters["sdc_catalog_url"], parameters["sdc_consumer"], parameters["sdc_password"], vf_unique_id, ns_csar, get_vnf_name(ns_csar))) + + # set properties + os.system("oclip service-model-set-property --host-url {} --host-username {} --host-password {} --service-uniqueId {} --resource-uuid {} --resource-uniqueId {} --property-name nf_type --property-value {}".format( + parameters["sdc_catalog_url"], parameters["sdc_consumer"], parameters["sdc_password"], service_model_id , vf_unique_id, vf_uuid, vnfm_driver)) + + # check-in + os.system("oclip service-model-checkin --host-url {} --host-username {} --host-password {} --service-model-uuid {}".format( + parameters["sdc_catalog_url"], parameters["sdc_creator"], parameters["sdc_password"], service_model_id)) + + + os.system("oclip service-model-test-request -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-test-remarks"], \ + parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"])) + + os.system("oclip service-model-test-start -b {} -u {} -p {} -m {}".format(service_model_id, parameters["sdc_tester"], \ + parameters["sdc_password"], parameters["sdc_catalog_url"])) + + os.system("oclip service-model-test-accept -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-accept-remarks"], \ + parameters["sdc_tester"], parameters["sdc_password"], parameters["sdc_catalog_url"])) + + #Get uniqueId for the service model + service_model_values = (os.popen("oclip service-model-list -u {} -p {} -m {} |grep {}".format(parameters["sdc_creator"], \ + parameters["sdc_password"], parameters["sdc_catalog_url"], parameters["service-model-name"]))).read() + service_model_values = get_out_helper_2(service_model_values) + service_model_uniqueId = (service_model_values)[1] + + os.system("oclip service-model-approve -b {} -r {} -u {} -p {} -m {}".format(service_model_uniqueId, parameters["service-approve-remarks"], \ + parameters["sdc_governor"], parameters["sdc_password"], parameters["sdc_catalog_url"])) + + os.system("oclip service-model-distribute -b {} -u {} -p {} -m {}".format(service_model_uniqueId, parameters["sdc_operator"], \ + parameters["sdc_password"], parameters["sdc_catalog_url"])) + + return service_model_values + +def register_cloud_helper(cloud_region, values, parameters): + #Create Cloud + cloud_create_string = 'oclip cloud-create -e {} -b {} -I {{\\\\\\"openstack-region-id\\\\\\":\\\\\\"{}\\\\\\"}} \ + -x {} -y {} -j {} -w {} -l {} -url {} -n {} -q {} -r {} -Q {} -i {} -g {} -z {} -k {} -c {} -m {} -u {} -p {}'.format( + values.get("esr-system-info-id"), values.get("user-name"), cloud_region, parameters["cloud-owner"], \ + cloud_region, values.get("password"), values.get("cloud-region-version"), values.get("default-tenant"), \ + values.get("service-url"), parameters["complex_name"], values.get("cloud-type"), parameters["owner-defined-type"], \ + values.get("system-type"), values.get("identity-url"), parameters["cloud-zone"], values.get("ssl-insecure"), \ + values.get("system-status"), values.get("cloud-domain"), parameters["aai_url"], parameters["aai_username"], \ + parameters["aai_password"]) + + + os.system(cloud_create_string) + + #Associate Cloud with complex + complex_associate_string = "oclip complex-associate -x {} -y {} -z {} -m {} -u {} -p {}".format(parameters["complex_name"], \ + cloud_region, parameters["cloud-owner"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) + os.system(complex_associate_string) + + #Register Cloud with Multicloud + multicloud_register_string = "oclip multicloud-register-cloud -y {} -x {} -m {}".format(parameters["cloud-owner"], \ + cloud_region, parameters["multicloud_url"]) + os.system(multicloud_register_string) + +def register_all_clouds(parameters): + cloud_dictionary = parameters["cloud_region_data"] + for cloud_region, cloud_region_values in cloud_dictionary.iteritems(): + register_cloud_helper(cloud_region, cloud_region_values, parameters) + +def create_service_type(parameters): + create_string = "oclip service-type-create -x {} -m {} -u {} -p {}".format( parameters["service_name"], \ + parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) + os.system(create_string) + +def create_customer(parameters): + create_string = "oclip customer-create -x {} -y {} -m {} -u {} -p {}".format( parameters["customer_name"], \ + parameters["subscriber_name"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) + os.system(create_string) + +def add_customer_subscription(parameters): + subscription_check = 0 + for cloud_region, cloud_region_values in (parameters["cloud_region_data"]).iteritems(): + if subscription_check == 0 : + subscription_string = "oclip subscription-create -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(\ + parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\ + cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] ) + else: + subscription_string = "oclip subscription-cloud-add -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(\ + parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\ + cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] ) + os.system(subscription_string) + subscription_check+=1 + +def register_vnfm_helper(vnfm_key, values, parameters): + #Create vnfm + vnfm_create_string = 'oclip vnfm-create -b {} -c {} -e {} -v {} -g {} -x {} -i {} -j {} -q {} \ + -m {} -u {} -p {}'.format(vnfm_key, values.get("type"), values.get("vendor"), \ + values.get("version"), values.get("url"), values.get("vim-id"), \ + values.get("user-name"), values.get("user-password"), values.get("vnfm-version"), \ + parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) + + os.system(vnfm_create_string) + +def register_vnfm(parameters): + vnfm_params = parameters["vnfm_params"] + for vnfm_key, vnfm_values in vnfm_params.iteritems(): + register_vnfm_helper(vnfm_key, vnfm_values, parameters) + + +def onboard_vnf(parameters): + vnfs = parameters["vnfs"] + vnf_onboard_outputs = {} + + for key, value in vnfs.items(): + vnf_onboard_string = 'oclip vfc-catalog-onboard-vnf -c {}'.format(value.get("csar-id")) + vnf_onboard_outs[key] = (os.popen(ns_onboard_string)).read() + return vnf_onboard_outputs + +def onboard_ns(parameters): + ns_onboard_string = 'oclip vfc-catalog-onboard-ns -c {}'.format(parameters["ns-csar-id"]) + ns_onboard_out = (os.popen(ns_onboard_string)).read() + return ns_onboard_out + +def create_ns(parameters, csar_id): + ns = parameters["ns"] + ns_create_string = 'oclip vfc-nslcm-create -m {} -c {} -n {} -q {} -S {}'.format(parameters["vfc-url"], \ + csar_id, ns.get("name"), parameters["customer_name"], parameters["service_name"]) + print ns_create_string + ns_create_out = (os.popen(ns_create_string)).read() + print ns_create_out + ns_instance_id = (get_out_helper_2(ns_create_out))[3] + return ns_instance_id + +def instantiate_ns(parameters, ns_instance_id): + ns_instantiate_string = 'oclip vfc-nslcm-instantiate -m {} -i {} -c {} -n {}'.format(parameters["vfc-url"], \ + ns_instance_id, parameters["location"], parameters["sdc-controller-id"]) + print ns_instantiate_string + + ns_instantiate_out = (os.popen(ns_instantiate_string)).read() + return ns_instantiate_out + +def create_ns_package(parameters): + ns = parameters["ns"] + create_ns_string = 'oclip vfc-catalog-create-ns -m {} -c {} -e {}'.format(parameters["vfc-url"], \ + ns.get("key"), ns.get("value")) + cmd_out = (os.popen(create_ns_string)).read() + out_list = get_out_helper_2(cmd_out) + return out_list[4] + +def create_vnf_package(parameters): + vnfs = parameters["vnfs"] + outputs = {} + + for vnf_key, vnf_values in vnfs.iteritems(): + create_vnf_string = 'oclip vfc-catalog-create-vnf -m {} -c {} -e {}'.format(parameters["vfc-url"], \ + vnf_values.get("key"), vnf_values.get("value")) + cmd_out = (os.popen(create_vnf_string)).read() + out_list = get_out_helper_2(cmd_out) + outputs[vnf_key] = out_list[4] + + return outputs + +def upload_ns_package(parameters, ns_package_output): + ns = parameters["ns"] + ns_upload_string = '{}/api/nsd/v1/ns_descriptors/{}/nsd_content'.format(parameters["vfc-url"], ns_package_output) + print ns_upload_string + print ns.get("path") + resp = requests.put(ns_upload_string, files={'file': open(ns.get("path"), 'rb')}) + return resp + +def upload_vnf_package(parameters, vnf_package_output): + vnfs = parameters["vnfs"] + for vnf_key, vnf_values in vnfs.iteritems(): + vnf_upload_str = '{}/api/vnfpkgm/v1/vnf_packages/{}/package_content'.format(parameters["vfc-url"], \ + vnf_package_output[vnf_key], vnf_package_output[vnf_key]) + resp = requests.put(vnf_upload_str, files={'file': open(vnf_values.get("path"), 'rb')}) + return resp + + +def provision_vnf(): + + result_json = {} + result_json['vnf_id'] = '' + result_json['vnf_status'] = '' + result_json['ns_id'] = '' + result_json['ns_status'] = '' + + # 1.Setup cloud and service + #setup cloud and region + create_complex(parameters) + register_all_clouds(parameters) + + # setup subscription and customer + create_service_type(parameters) + create_customer(parameters) + add_customer_subscription(parameters) + + # setup vnfm + register_vnfm(parameters) + + # Setup License + vlm_output = create_vlm(parameters) + print "vlm parameters={}".format(vlm_output) + + # 2. on-board VSP + vsp_id = create_vsp(parameters, vlm_output) + print "vsp id={}".format(vsp_id) + + # 3. model VF + vf_model_dict = create_vf_model(parameters, vsp_id) + print "vf model parameters={}".format(vf_model_dict) + vf_id = vf_model_dict["vf_id"] + vf_unique_id = vf_model_dict["vf_unique_id"] + + # 4. model NS and 5. Approve and distribute + service_model_list = create_service_model(parameters, vf_unique_id) + print "service model parameters={}".format(service_model_list) + + # 6. onboard VNF + vnf_onboard_output = onboard_vnf(parameters) + print vnf_onboard_output + + # 7. onboard NS + ns_onboard_out = onboard_ns(parameters) + print ns_onboard_out + + # 8. create NS + ns_instance_id = create_ns(parameters, ns_package_output) + print ns_instance_id + + instantiate_ns_output = instantiate_ns(parameters, ns_instance_id) + print instantiate_ns_output + + return result_json + +def persist_result(result_path, result): + f = open(result_json_path, "w") + + result_json = {} + result_json['vnf_id'] = result['vnf_id'] + result_json['vnf_status'] = result['vnf_status'] + result_json['ns_id'] = result['ns_id'] + result_json['ns_status'] = result['ns_status'] + + f.write(json.dumps(result_json)) + + print result_json + + f.close() + +#Main +parser = argparse.ArgumentParser() +parser.add_argument('--config-json', action='store', dest='config_file_path', help='Config file path') +parser.add_argument('--vsp', action='store', dest='vsp', help='ONAP VSP') +parser.add_argument('--vnf-csar', action='store', dest='vnf_csar', help='VNF CSAR') +parser.add_argument('--ns-csar', action='store', dest='ns_csar', help='NS CSAR') +parser.add_argument('--vnfm-driver', action='store', dest='vnfm_driver', help='gVNFM or hwVNFM') +parser.add_argument('--result-json', action='store', dest='result_json_path', help='Output result json') + +#Retrive the params +args = parser.parse_args() +print args + +config_file = open(args.config_file_path) +vsp = args.vsp +vnf_csar = args.vnf_csar +ns_csar = args.ns_csar +vnfm_driver = args.vnfm_driver +result_json_path = args.result_json_path + +# setup CLI +parameters = get_parameters(config_file) +set_open_cli_env(parameters) + +output = provision_vnf() + +persist_result(result_json_path, output) + +print "Provision is completed !"
\ No newline at end of file diff --git a/products/onap-dublin/features/msb/pom.xml b/products/onap-dublin/features/msb/pom.xml index 57f9eae2..ae8e044a 100644 --- a/products/onap-dublin/features/msb/pom.xml +++ b/products/onap-dublin/features/msb/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-dublin-features</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-dublin-features-msb</artifactId> diff --git a/products/onap-dublin/features/multicloud/pom.xml b/products/onap-dublin/features/multicloud/pom.xml index aadb0814..06d2ee91 100644 --- a/products/onap-dublin/features/multicloud/pom.xml +++ b/products/onap-dublin/features/multicloud/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-dublin-features</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-dublin-features-multicloud</artifactId> diff --git a/products/onap-dublin/features/policy/pom.xml b/products/onap-dublin/features/policy/pom.xml index aeca79ea..f7a885e8 100644 --- a/products/onap-dublin/features/policy/pom.xml +++ b/products/onap-dublin/features/policy/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-dublin-features</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-dublin-features-policy</artifactId> diff --git a/products/onap-dublin/features/pom.xml b/products/onap-dublin/features/pom.xml index 23a2d640..95b25338 100644 --- a/products/onap-dublin/features/pom.xml +++ b/products/onap-dublin/features/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-dublin</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-dublin-features</artifactId> @@ -41,12 +41,58 @@ <module>sdnc</module> <module>so</module> <module>vnfsdk</module> + <module>integration</module> </modules> <build> <pluginManagement> <plugins> <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <version>3.1.0</version> + <executions> + <execution> + <id>copy-resource-script</id> + <phase>install</phase> + <goals> + <goal>copy-resources</goal> + </goals> + + <configuration> + <outputDirectory>../../../../products/target/script</outputDirectory> + <resources> + <resource> + <directory>${project.basedir}/src/main/resources/script</directory> + <includes> + <include>*.*</include> + </includes> + </resource> + </resources> + </configuration> + </execution> + <execution> + <id>copy-resource-conf</id> + <phase>install</phase> + <goals> + <goal>copy-resources</goal> + </goals> + + <configuration> + <outputDirectory>../../../../products/target/conf</outputDirectory> + <resources> + <resource> + <directory>${project.basedir}/src/main/resources/conf</directory> + <includes> + <include>*.*</include> + </includes> + </resource> + </resources> + </configuration> + </execution> + </executions> + </plugin> + <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> diff --git a/products/onap-dublin/features/sdc/pom.xml b/products/onap-dublin/features/sdc/pom.xml index 8a91f7b4..b0cded4a 100644 --- a/products/onap-dublin/features/sdc/pom.xml +++ b/products/onap-dublin/features/sdc/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-dublin-features</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-dublin-features-sdc</artifactId> diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/consumer/sdc-consumer-create-schema-dublin-moco.json b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/consumer/sdc-consumer-create-schema-dublin-moco.json new file mode 100644 index 00000000..71bce5dd --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/consumer/sdc-consumer-create-schema-dublin-moco.json @@ -0,0 +1,31 @@ +[ { + "request" : { + "method" : "post", + "uri" : "/sdc2/rest/v1/consumers", + "headers" : { + "Accept" : "application/json", + "USER_ID" : "jh0003", + "Content-Type" : "application/json" + }, + "json" : { + "consumerName" : "mrkanag", + "consumerSalt" : "ab2987754f0c6293174865e86c47035d", + "consumerPassword" : "7fa005e6e478ee677053a2c4a5c2f11190e2aa8be227a037291ea4cbc074ecb6" + } + }, + "response" : { + "status" : 201, + "json" : { + "consumerName" : "mrkanag", + "consumerPassword" : "7fa005e6e478ee677053a2c4a5c2f11190e2aa8be227a037291ea4cbc074ecb6", + "consumerSalt" : "ab2987754f0c6293174865e86c47035d", + "consumerLastAuthenticationTime" : 0, + "consumerDetailsLastupdatedtime" : 1564379189744, + "lastModfierAtuid" : "jh0003", + "version" : null, + "ownerId" : null, + "empty" : false, + "type" : null + } + } +} ]
\ No newline at end of file diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/consumer/sdc-consumer-create-schema-dublin-sample.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/consumer/sdc-consumer-create-schema-dublin-sample.yaml new file mode 100644 index 00000000..f043ad70 --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/consumer/sdc-consumer-create-schema-dublin-sample.yaml @@ -0,0 +1,9 @@ +open_cli_sample_version: 1.0 +name: --host-url +version: open-cli +samples: + sample1: + name: --host-url + input: https://159.138.32.178:30204 --consumer-name mrkanag --debug + moco: sdc-consumer-create-schema-dublin-moco.json + output:
\ No newline at end of file diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/consumer/sdc-consumer-show-schema-dublin-moco.json b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/consumer/sdc-consumer-show-schema-dublin-moco.json new file mode 100644 index 00000000..7f025f67 --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/consumer/sdc-consumer-show-schema-dublin-moco.json @@ -0,0 +1,27 @@ +[ { + "request" : { + "method" : "get", + "uri" : "/sdc2/rest/v1/consumers/mrkanag", + "headers" : { + "Accept" : "application/json", + "USER_ID" : "jh0003", + "Content-Type" : "application/json" + }, + "json" : null + }, + "response" : { + "status" : 200, + "json" : { + "consumerName" : "mrkanag", + "consumerPassword" : "7fa005e6e478ee677053a2c4a5c2f11190e2aa8be227a037291ea4cbc074ecb6", + "consumerSalt" : "ab2987754f0c6293174865e86c47035d", + "consumerLastAuthenticationTime" : 0, + "consumerDetailsLastupdatedtime" : 1564379189744, + "lastModfierAtuid" : "jh0003", + "version" : null, + "ownerId" : null, + "empty" : false, + "type" : null + } + } +} ]
\ No newline at end of file diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/consumer/sdc-consumer-show-schema-dublin-sample.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/consumer/sdc-consumer-show-schema-dublin-sample.yaml new file mode 100644 index 00000000..4b3571d6 --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/consumer/sdc-consumer-show-schema-dublin-sample.yaml @@ -0,0 +1,9 @@ +open_cli_sample_version: 1.0 +name: --host-url +version: open-cli +samples: + sample1: + name: --host-url + input: https://159.138.32.178:30204 --consumer-name mrkanag --debug + moco: sdc-consumer-show-schema-dublin-moco.json + output: | diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/service-model/ns-model-set-property-moco.json b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/service-model/ns-model-set-property-moco.json new file mode 100644 index 00000000..2e265288 --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/service-model/ns-model-set-property-moco.json @@ -0,0 +1,154 @@ +[ { + "request" : { + "method" : "post", + "uri" : "/sdc2/rest/v1/catalog/services/66bc211e-27a1-4a1c-aee3-75952617b7fe/resourceInstance/ff654717-85e1-4458-a9ce-7dedca7be552.3694ef05-56e3-44d0-9103-7805ef8d2929.extztecp0/properties", + "headers" : { + "Authorization" : "Basic Y3MwMDA4OmRlbW8xMjM0NTYh", + "X-FromAppId" : "ONAP CLI", + "Accept" : "application/json", + "USER_ID" : "cs0008", + "X-TransactionId" : "req-a5f3d3a6-f407-4abd-81b1-b4906c039783", + "Content-Type" : "application/json" + }, + "json" : [ { + "constraints" : null, + "defaultValue" : null, + "description" : null, + "name" : "ip_address", + "parentUniqueId" : null, + "password" : false, + "required" : false, + "schema" : { + "property" : { } + }, + "schemaType" : null, + "type" : "string", + "uniqueId" : "3694ef05-56e3-44d0-9103-7805ef8d2929.ip_address", + "value" : "1.1.1.2", + "definition" : false, + "getInputValues" : null, + "parentPropertyType" : null, + "subPropertyInputPath" : null, + "toscaPresentation" : { + "ownerId" : null + }, + "getPolicyValues" : null, + "inputPath" : null + } ] + }, + "response" : { + "status" : 200, + "json" : [ { + "uniqueId" : "3694ef05-56e3-44d0-9103-7805ef8d2929.ip_address", + "type" : "string", + "required" : false, + "definition" : false, + "defaultValue" : null, + "description" : null, + "schema" : { + "derivedFrom" : null, + "constraints" : null, + "properties" : null, + "property" : { + "uniqueId" : null, + "type" : null, + "required" : false, + "definition" : true, + "defaultValue" : null, + "description" : null, + "schema" : null, + "password" : false, + "name" : null, + "value" : null, + "label" : null, + "hidden" : false, + "immutable" : false, + "inputPath" : null, + "status" : null, + "inputId" : null, + "instanceUniqueId" : null, + "propertyId" : null, + "parentPropertyType" : null, + "subPropertyInputPath" : null, + "annotations" : null, + "parentUniqueId" : null, + "getInputValues" : null, + "isDeclaredListInput" : false, + "getPolicyValues" : null, + "getInputProperty" : false, + "schemaType" : null, + "schemaProperty" : null, + "version" : null, + "ownerId" : null, + "empty" : false + }, + "version" : null, + "ownerId" : null, + "empty" : false, + "type" : null + }, + "password" : false, + "name" : "ip_address", + "value" : "1.1.1.2", + "label" : null, + "hidden" : false, + "immutable" : false, + "inputPath" : null, + "status" : null, + "inputId" : null, + "instanceUniqueId" : null, + "propertyId" : null, + "parentPropertyType" : null, + "subPropertyInputPath" : null, + "annotations" : null, + "parentUniqueId" : null, + "getInputValues" : null, + "isDeclaredListInput" : false, + "getPolicyValues" : null, + "constraints" : [ ], + "valueUniqueUid" : null, + "path" : [ "ff654717-85e1-4458-a9ce-7dedca7be552.3694ef05-56e3-44d0-9103-7805ef8d2929.extztecp0" ], + "rules" : null, + "componentInstanceName" : null, + "componentInstanceId" : null, + "getInputProperty" : false, + "schemaType" : null, + "schemaProperty" : { + "uniqueId" : null, + "type" : null, + "required" : false, + "definition" : true, + "defaultValue" : null, + "description" : null, + "schema" : null, + "password" : false, + "name" : null, + "value" : null, + "label" : null, + "hidden" : false, + "immutable" : false, + "inputPath" : null, + "status" : null, + "inputId" : null, + "instanceUniqueId" : null, + "propertyId" : null, + "parentPropertyType" : null, + "subPropertyInputPath" : null, + "annotations" : null, + "parentUniqueId" : null, + "getInputValues" : null, + "isDeclaredListInput" : false, + "getPolicyValues" : null, + "getInputProperty" : false, + "schemaType" : null, + "schemaProperty" : null, + "version" : null, + "ownerId" : null, + "empty" : false + }, + "version" : null, + "ownerId" : null, + "empty" : false + } ] + } +} ]
\ No newline at end of file diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/service-model/ns-model-set-property-sample.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/service-model/ns-model-set-property-sample.yaml new file mode 100644 index 00000000..540bb0f8 --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/service-model/ns-model-set-property-sample.yaml @@ -0,0 +1,9 @@ +open_cli_sample_version: 1.0 +name: --host-url +version: open-cli +samples: + sample1: + name: --host-url + input: https://159.138.32.178:30204 --host-username cs0008 --host-password demo123456! --service-uniqueId 66bc211e-27a1-4a1c-aee3-75952617b7fe --resource-uuid 3694ef05-56e3-44d0-9103-7805ef8d2929 --resource-uniqueId ff654717-85e1-4458-a9ce-7dedca7be552.3694ef05-56e3-44d0-9103-7805ef8d2929.extztecp0 --property-name ip_address --property-value 1.1.1.2 --debug + moco: ns-model-set-property-moco.json + output:
\ No newline at end of file diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/service-model/service-model-add-artifact-schema-dublin-sample.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/service-model/service-model-add-artifact-schema-dublin-sample.yaml new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/service-model/service-model-add-artifact-schema-dublin-sample.yaml diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/vf/vf-model-checkin-schema-dublin-moco.json b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/vf/vf-model-checkin-schema-dublin-moco.json new file mode 100644 index 00000000..e572c8ee --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/vf/vf-model-checkin-schema-dublin-moco.json @@ -0,0 +1,72 @@ +[ { + "request" : { + "method" : "post", + "uri" : "/sdc2/rest/v1/catalog/resources/c5d9a74a-c617-4542-8b83-31c4d8a7269b/lifecycleState/CHECKIN", + "headers" : { + "Authorization" : "Basic Y3MwMDA4OmRlbW8xMjM0NTYh", + "X-FromAppId" : "ONAP CLI", + "Accept" : "application/json", + "USER_ID" : "cs0008", + "X-TransactionId" : "req-26632f77-01a9-4a8a-949b-34b42544d67e", + "Content-Type" : "application/json" + }, + "json" : { + "userRemarks" : "Checked in by ONAP CLI" + } + }, + "response" : { + "status" : 200, + "json" : { + "uniqueId" : "c5d9a74a-c617-4542-8b83-31c4d8a7269b", + "name" : "ovp-test", + "version" : "1.4", + "isHighestVersion" : true, + "creationDate" : 1564379661410, + "lastUpdateDate" : 1564379845325, + "description" : "ovp-test", + "lifecycleState" : "NOT_CERTIFIED_CHECKIN", + "tags" : [ "ovp-test" ], + "icon" : "defaulticon", + "normalizedName" : "ovptest", + "systemName" : "OvpTest", + "contactId" : "cs0008", + "allVersions" : { + "1.0" : "3f0de55b-90be-459d-a30f-a24553baacaa", + "1.1" : "53235bc8-2619-4d23-b1f6-e41e64d0af47", + "1.2" : "ef2ce8c3-af1c-480a-a12f-6bd1fe0384f4", + "1.3" : "168c1a0d-82d8-4a86-a934-9e685389516f", + "1.4" : "c5d9a74a-c617-4542-8b83-31c4d8a7269b" + }, + "csarUUID" : "aa92c8177d754587b621a951a522a942", + "csarVersion" : "1.0", + "invariantUUID" : "c918f6b2-5067-4c10-91a8-672964f3fd10", + "componentType" : "RESOURCE", + "categories" : [ { + "name" : "Generic", + "normalizedName" : "generic", + "uniqueId" : "resourceNewCategory.generic", + "subcategories" : [ { + "name" : "Network Elements", + "normalizedName" : "network elements", + "uniqueId" : "resourceNewCategory.generic.network elements", + "icons" : [ "network", "connector" ], + "empty" : false + } ], + "empty" : false + } ], + "creatorUserId" : "cs0008", + "creatorFullName" : "Carlos Santana", + "lastUpdaterUserId" : "cs0008", + "lastUpdaterFullName" : "Carlos Santana", + "archiveTime" : 0, + "vendorName" : "onap", + "vendorRelease" : "1.0", + "resourceVendorModelNumber" : "", + "resourceType" : "VF", + "toscaResourceName" : "org.openecomp.resource.vf.OvpTest", + "vspArchived" : false, + "archived" : false, + "uuid" : "24d20439-1d8c-44dc-acaf-cb0929a6a5f3" + } + } +} ]
\ No newline at end of file diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/vf/vf-model-checkin-schema-dublin-sample.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/vf/vf-model-checkin-schema-dublin-sample.yaml new file mode 100644 index 00000000..940a5fb1 --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/vf/vf-model-checkin-schema-dublin-sample.yaml @@ -0,0 +1,9 @@ +open_cli_sample_version: 1.0 +name: --host-url +version: open-cli +samples: + sample1: + name: --host-url + input: https://159.138.32.178:30204 --host-username cs0008 --host-password demo123456! --vf-model-uuid c5d9a74a-c617-4542-8b83-31c4d8a7269b --debug + moco: vf-model-checkin-schema-dublin-moco.json + output:
\ No newline at end of file diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/vf/vf-model-checkout-schema-dublin-moco.json b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/vf/vf-model-checkout-schema-dublin-moco.json new file mode 100644 index 00000000..c688dcb4 --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/vf/vf-model-checkout-schema-dublin-moco.json @@ -0,0 +1,70 @@ +[ { + "request" : { + "method" : "post", + "uri" : "/sdc2/rest/v1/catalog/resources/168c1a0d-82d8-4a86-a934-9e685389516f/lifecycleState/CHECKOUT", + "headers" : { + "Authorization" : "Basic Y3MwMDA4OmRlbW8xMjM0NTYh", + "X-FromAppId" : "ONAP CLI", + "Accept" : "application/json", + "USER_ID" : "cs0008", + "X-TransactionId" : "req-4616b1ae-ca5f-4a74-97de-144647202745", + "Content-Type" : "application/json" + }, + "json" : { } + }, + "response" : { + "status" : 200, + "json" : { + "uniqueId" : "c5d9a74a-c617-4542-8b83-31c4d8a7269b", + "name" : "ovp-test", + "version" : "1.4", + "isHighestVersion" : true, + "creationDate" : 1564379661410, + "lastUpdateDate" : 1564379661410, + "description" : "ovp-test", + "lifecycleState" : "NOT_CERTIFIED_CHECKOUT", + "tags" : [ "ovp-test" ], + "icon" : "defaulticon", + "normalizedName" : "ovptest", + "systemName" : "OvpTest", + "contactId" : "cs0008", + "allVersions" : { + "1.0" : "3f0de55b-90be-459d-a30f-a24553baacaa", + "1.1" : "53235bc8-2619-4d23-b1f6-e41e64d0af47", + "1.2" : "ef2ce8c3-af1c-480a-a12f-6bd1fe0384f4", + "1.3" : "168c1a0d-82d8-4a86-a934-9e685389516f", + "1.4" : "c5d9a74a-c617-4542-8b83-31c4d8a7269b" + }, + "csarUUID" : "aa92c8177d754587b621a951a522a942", + "csarVersion" : "1.0", + "invariantUUID" : "c918f6b2-5067-4c10-91a8-672964f3fd10", + "componentType" : "RESOURCE", + "categories" : [ { + "name" : "Generic", + "normalizedName" : "generic", + "uniqueId" : "resourceNewCategory.generic", + "subcategories" : [ { + "name" : "Network Elements", + "normalizedName" : "network elements", + "uniqueId" : "resourceNewCategory.generic.network elements", + "icons" : [ "network", "connector" ], + "empty" : false + } ], + "empty" : false + } ], + "creatorUserId" : "cs0008", + "creatorFullName" : "Carlos Santana", + "lastUpdaterUserId" : "cs0008", + "lastUpdaterFullName" : "Carlos Santana", + "archiveTime" : 0, + "vendorName" : "onap", + "vendorRelease" : "1.0", + "resourceVendorModelNumber" : "", + "resourceType" : "VF", + "toscaResourceName" : "org.openecomp.resource.vf.OvpTest", + "vspArchived" : false, + "archived" : false, + "uuid" : "24d20439-1d8c-44dc-acaf-cb0929a6a5f3" + } + } +} ]
\ No newline at end of file diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/vf/vf-model-checkout-schema-dublin-sample.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/vf/vf-model-checkout-schema-dublin-sample.yaml new file mode 100644 index 00000000..39885784 --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-sample/vf/vf-model-checkout-schema-dublin-sample.yaml @@ -0,0 +1,9 @@ +open_cli_sample_version: 1.0 +name: --host-url +version: open-cli +samples: + sample1: + name: --host-url + input: https://159.138.32.178:30204 --host-username cs0008 --host-password demo123456! --vf-model-uuid 168c1a0d-82d8-4a86-a934-9e685389516f --debug + moco: vf-model-checkout-schema-dublin-moco.json + output: | diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/consumer/sdc-consumer-create-schema-dublin.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/consumer/sdc-consumer-create-schema-dublin.yaml new file mode 100644 index 00000000..20077715 --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/consumer/sdc-consumer-create-schema-dublin.yaml @@ -0,0 +1,70 @@ +# Copyright 2019 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. + +open_cli_schema_version: 1.0 +name: sdc-consumer-create +description: Create SDC consumer + +info: + product: onap-dublin + service: sdc + author: ONAP CLI Team onap-discuss@lists.onap.org + +parameters: + - name: consumer-name + description: Consumer Name + type: string + short_option: x + long_option: consumer-name + is_optional: false + - name: consumer-password + description: Consumer password + type: string + short_option: y + long_option: consumer-password + is_optional: true + default_value: 7fa005e6e478ee677053a2c4a5c2f11190e2aa8be227a037291ea4cbc074ecb6 + - name: salt + description: Salt + type: string + long_option: salt + short_option: c + is_optional: true + default_value: ab2987754f0c6293174865e86c47035d + - name: user-id + description: Designer user id + type: string + long_option: user-id + short_option: e + default_value: jh0003 + is_optional: true +http: + service: + name: sdc + version: v1.0 + auth: none + mode: direct + request: + uri: /sdc2/rest/v1/consumers + method: POST + headers: + USER_ID: ${user-id} + body: '{ + "consumerName": "${consumer-name}", + "consumerSalt": "${salt}", + "consumerPassword": "${consumer-password}" + }' + success_codes: + - 200 + - 201 diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/consumer/sdc-consumer-show-schema-dublin.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/consumer/sdc-consumer-show-schema-dublin.yaml new file mode 100644 index 00000000..5de269e4 --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/consumer/sdc-consumer-show-schema-dublin.yaml @@ -0,0 +1,66 @@ +# Copyright 2019 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. + +open_cli_schema_version: 1.0 +name: sdc-consumer-show +description: Retrieve SDC consumer + +info: + product: onap-dublin + service: sdc + author: ONAP CLI Team onap-discuss@lists.onap.org + +parameters: + - name: consumer-name + description: Consumer Name + type: string + short_option: x + long_option: consumer-name + is_optional: false + - name: user-id + description: Designer user id + type: string + long_option: user-id + short_option: e + default_value: jh0003 + is_optional: true +results: + direction: portrait + attributes: + - name: consumer-password + description: Consumer password + type: string + scope: short + - name: salt + description: Salt + type: string + scope: short + +http: + service: + name: sdc + version: v1.0 + auth: none + mode: direct + request: + uri: /sdc2/rest/v1/consumers/${consumer-name} + method: GET + headers: + USER_ID: ${user-id} + success_codes: + - 200 + - 201 + result_map: + consumer-password: $b{$.consumerPassword} + salt: $b{$.consumerSalt}
\ No newline at end of file diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service-model-add-artifact-schema-dublin.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service-model-add-artifact-schema-dublin.yaml new file mode 100644 index 00000000..dc881d90 --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service-model-add-artifact-schema-dublin.yaml @@ -0,0 +1,72 @@ +# Copyright 2019 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. + +open_cli_schema_version: 1.0 +name: service-model-add-artifact +description: Add a artifact to a Service model + +info: + product: onap-dublin + service: sdc + author: ONAP HPA Team onap-discuss@lists.onap.org + + +parameters: + - name: service-uniqueId + description: Service Unique Id + type: string + long_option: service-uniqueId + short_option: x + is_optional: false + - name: remarks + description: certification remarks + type: string + long_option: remarks + short_option: y + default_value: Uploaded from ONAP CLI + is_optional: true + - name: artifact + description: NS CSAR file + type: byte + long_option: artifact + short_option: z + is_optional: false + - name: artifact-name + description: NS CSAR name + type: string + long_option: artifact-name + short_option: b + is_optional: false + - name: user-id + description: Designer user id + type: string + long_option: user-id + short_option: e + default_value: cs0008 + is_optional: true +http: + service: + name: sdc + version: v1.0 + auth: basic + mode: direct + request: + uri: /sdc2/rest/v1/catalog/services/${service-uniqueId}/artifacts + method: POST + headers: + Content-MD5: $s{md5:__body__} + USER_ID: ${user-id} + body: '{"payloadData":"${artifact}","artifactDisplayName":"${artifact-name}","artifactType":"OTHER","description":"${remarks}","artifactName":"${artifact-name}", "artifactLabel":"${artifact-name}","artifactGroupType":"INFORMATIONAL", artifactChecksum="$s{md5:artifact}"}' + success_codes: + - 200 diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service-model-add-vf-schema-dublin.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service-model-add-vf-schema-dublin.yaml index 63454976..06b4c4fb 100644 --- a/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service-model-add-vf-schema-dublin.yaml +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service-model-add-vf-schema-dublin.yaml @@ -55,6 +55,10 @@ results: description: Service ID scope: short type: string + - name: UUID + description: Service UUID + scope: short + type: string http: service: name: sdc @@ -69,3 +73,4 @@ http: - 201 result_map: ID: $b{$.uniqueId} + UUID: $b{$.componentUid}
\ No newline at end of file diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service-model-checkout-schema-dublin.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service-model-checkout-schema-dublin.yaml index 9201e7fa..ec0ccc6d 100644 --- a/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service-model-checkout-schema-dublin.yaml +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service-model-checkout-schema-dublin.yaml @@ -30,6 +30,13 @@ parameters: short_option: b is_optional: true +results: + direction: portrait + attributes: + - name: ID + description: NS checked out version unique ID + scope: short + type: string http: service: name: sdc @@ -42,3 +49,5 @@ http: body: '{}' success_codes: - 200 + result_map: + ID: $b{$.uniqueId}
\ No newline at end of file diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service-model-set-property.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service-model-set-property.yaml new file mode 100644 index 00000000..a7ea76b7 --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service-model-set-property.yaml @@ -0,0 +1,67 @@ +# Copyright 2019 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. + +open_cli_schema_version: 1.0 +name: service-model-set-property +description: Set property to a service model + +info: + product: onap-dublin + service: sdc + author: ONAP HPA Team onap-discuss@lists.onap.org + + +parameters: + - name: service-uniqueId + description: service UniqueId + type: string + long_option: service-uniqueId + short_option: x + is_optional: false + - name: resource-uuid + description: resource uuid + type: string + long_option: resource-uuid + short_option: y + is_optional: false + - name: resource-uniqueId + description: resource UniqueId + type: string + long_option: resource-uniqueId + short_option: z + is_optional: false + - name: property-name + description: property name + type: string + long_option: property-name + short_option: b + is_optional: false + - name: property-value + description: property value + type: string + long_option: property-value + short_option: r + is_optional: false +http: + service: + name: sdc + version: v1.0 + auth: basic + mode: direct + request: + uri: /sdc2/rest/v1/catalog/services/${service-uniqueId}/resourceInstance/${resource-uniqueId}/properties + method: POST + body: '[{"constraints":null,"defaultValue":null,"description":null,"name":"${property-name}","parentUniqueId":null,"password":false,"required":false,"schema":{"property":{}},"schemaType":null,"type":"string","uniqueId":"${resource-uuid}.${property-name}","value":"${property-value}","definition":false,"getInputValues":null,"parentPropertyType":null,"subPropertyInputPath":null,"toscaPresentation":{"ownerId":null},"getPolicyValues":null,"inputPath":null}]' + success_codes: + - 200 diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service2vf-model-list-schema-dublin.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service2vf-model-list-schema-dublin.yaml index bd4c38c6..2241e05c 100644 --- a/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service2vf-model-list-schema-dublin.yaml +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/service-model/service2vf-model-list-schema-dublin.yaml @@ -49,6 +49,10 @@ results: description: version type: string scope: short + - name: vf-unique-uuid + description: customization UUID + type: string + scope: short http: service: @@ -62,6 +66,7 @@ http: success_codes: - 200 result_map: + vf-unique-uuid: $b{componentInstances.[*].uniqueId} vf-uuid: $b{componentInstances.[*].componentUid} vf-name: $b{componentInstances.[*].componentName} vf-version: $b{componentInstances.[*].componentVersion} diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/vf/vf-model-add-artifact-schema-dublin.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/vf/vf-model-add-artifact-schema-dublin.yaml new file mode 100644 index 00000000..1a6c6b7c --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/vf/vf-model-add-artifact-schema-dublin.yaml @@ -0,0 +1,72 @@ +# Copyright 2019 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. + +open_cli_schema_version: 1.0 +name: vf-model-add-artifact +description: Add a artifact to a Virtual function + +info: + product: onap-dublin + service: sdc + author: ONAP HPA Team onap-discuss@lists.onap.org + + +parameters: + - name: vf-uniqueId + description: VF UniqueId + type: string + long_option: vf-uniqueId + short_option: x + is_optional: false + - name: remarks + description: certification remarks + type: string + long_option: remarks + short_option: y + default_value: Uploaded from ONAP CLI + is_optional: true + - name: artifact + description: VNF CSAR file + type: byte + long_option: artifact + short_option: z + is_optional: false + - name: artifact-name + description: VNF CSAR name + type: string + long_option: artifact-name + short_option: b + is_optional: false + - name: user-id + description: Designer user id + type: string + long_option: user-id + short_option: e + default_value: cs0008 + is_optional: true +http: + service: + name: sdc + version: v1.0 + auth: basic + mode: direct + request: + uri: /sdc2/rest/v1/catalog/resources/${vf-uniqueId}/artifacts + method: POST + headers: + Content-MD5: $s{md5:__body__} + USER_ID: ${user-id} + body: '{"payloadData":"${artifact}","artifactDisplayName":"${artifact-name}","artifactType":"OTHER","description":"${remarks}","artifactName":"${artifact-name}", "artifactLabel":"${artifact-name}","artifactGroupType":"DEPLOYMENT", artifactChecksum="$s{md5:artifact}"}' + success_codes: + - 200 diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/vf/vf-model-checkin-schema-dublin.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/vf/vf-model-checkin-schema-dublin.yaml new file mode 100644 index 00000000..9ec09f0a --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/vf/vf-model-checkin-schema-dublin.yaml @@ -0,0 +1,50 @@ +# Copyright © Intel Corporation 2019 +# +# 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. + +open_cli_schema_version: 1.0 +name: vf-model-checkin +description: Checkin VF model in SDC + +info: + product: onap-dublin + service: sdc + author: ONAP CLI Team onap-discuss@lists.onap.org + +parameters: + - name: vf-model-uuid + description: VF model UUID (can be found by running vf-model-list) + type: string + long_option: vf-model-uuid + short_option: b + is_optional: false + - name: remarks + description: checkin remarks + type: string + long_option: remarks + short_option: r + default_value: Checked in by ONAP CLI + is_optional: false + +http: + service: + name: sdc + version: v1.0 + auth: basic + mode: direct + request: + uri: /sdc2/rest/v1/catalog/resources/${vf-model-uuid}/lifecycleState/CHECKIN + method: POST + body: '{"userRemarks": "${remarks}"}' + success_codes: + - 200 diff --git a/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/vf/vf-model-checkout-schema-dublin.yaml b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/vf/vf-model-checkout-schema-dublin.yaml new file mode 100644 index 00000000..511e29fd --- /dev/null +++ b/products/onap-dublin/features/sdc/src/main/resources/open-cli-schema/vf/vf-model-checkout-schema-dublin.yaml @@ -0,0 +1,54 @@ +# Copyright © Intel Corporation 2019 +# +# 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. + +open_cli_schema_version: 1.0 +name: vf-model-checkout +description: Checkout VF model in SDC + +info: + product: onap-dublin + service: sdc + author: ONAP CLI Team onap-discuss@lists.onap.org + + +parameters: + - name: vf-model-uuid + description: VF model UUID (can be found from vf-model-list) + type: string + long_option: vf-model-uuid + short_option: b + is_optional: false + +results: + direction: portrait + attributes: + - name: ID + description: VF checked out version unique ID + scope: short + type: string + +http: + service: + name: sdc + version: v1.0 + auth: basic + mode: direct + request: + uri: /sdc2/rest/v1/catalog/resources/${vf-model-uuid}/lifecycleState/CHECKOUT + method: POST + body: '{}' + success_codes: + - 200 + result_map: + ID: $b{$.uniqueId}
\ No newline at end of file diff --git a/products/onap-dublin/features/sdnc/pom.xml b/products/onap-dublin/features/sdnc/pom.xml index 14d30bee..48fdfcd7 100644 --- a/products/onap-dublin/features/sdnc/pom.xml +++ b/products/onap-dublin/features/sdnc/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-dublin-features</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-dublin-features-sdnc</artifactId> diff --git a/products/onap-dublin/features/so/pom.xml b/products/onap-dublin/features/so/pom.xml index d2774d60..00f99c77 100644 --- a/products/onap-dublin/features/so/pom.xml +++ b/products/onap-dublin/features/so/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-dublin-features</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-dublin-features-so</artifactId> diff --git a/products/onap-dublin/features/vfc/pom.xml b/products/onap-dublin/features/vfc/pom.xml index f7cc3c3d..28fd7fb3 100644 --- a/products/onap-dublin/features/vfc/pom.xml +++ b/products/onap-dublin/features/vfc/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-dublin-features</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-dublin-features-vfc</artifactId> diff --git a/products/onap-dublin/features/vnfsdk/pom.xml b/products/onap-dublin/features/vnfsdk/pom.xml index 0117c3f7..dd5ae244 100644 --- a/products/onap-dublin/features/vnfsdk/pom.xml +++ b/products/onap-dublin/features/vnfsdk/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-onap-dublin-features</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-dublin-features-vnfsdk</artifactId> diff --git a/products/onap-dublin/pom.xml b/products/onap-dublin/pom.xml index 25c42165..596ee9be 100644 --- a/products/onap-dublin/pom.xml +++ b/products/onap-dublin/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-onap-dublin</artifactId> diff --git a/products/openecomp/auth/pom.xml b/products/openecomp/auth/pom.xml index ae4564a1..ed2429ad 100644 --- a/products/openecomp/auth/pom.xml +++ b/products/openecomp/auth/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-openecomp</artifactId> - <version>2.0.4</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-openecomp-auth</artifactId> diff --git a/products/openecomp/catalog/pom.xml b/products/openecomp/catalog/pom.xml index 0c55a8c5..ee62cfee 100644 --- a/products/openecomp/catalog/pom.xml +++ b/products/openecomp/catalog/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-openecomp</artifactId> - <version>2.0.4</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-openecomp-catalog</artifactId> diff --git a/products/openecomp/features/aai/pom.xml b/products/openecomp/features/aai/pom.xml index 5f86fcb2..d09e24eb 100644 --- a/products/openecomp/features/aai/pom.xml +++ b/products/openecomp/features/aai/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-openecomp-features</artifactId> - <version>2.0.4</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-openecomp-features-aai</artifactId> diff --git a/products/openecomp/features/pom.xml b/products/openecomp/features/pom.xml index 9a175543..a4ebec72 100644 --- a/products/openecomp/features/pom.xml +++ b/products/openecomp/features/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-openecomp</artifactId> - <version>2.0.4</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-openecomp-features</artifactId> diff --git a/products/openecomp/features/sdc/pom.xml b/products/openecomp/features/sdc/pom.xml index 86c0b92b..769d07a0 100644 --- a/products/openecomp/features/sdc/pom.xml +++ b/products/openecomp/features/sdc/pom.xml @@ -22,7 +22,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products-openecomp-features</artifactId> - <version>2.0.4</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-openecomp-features-sdc</artifactId> diff --git a/products/openecomp/pom.xml b/products/openecomp/pom.xml index 98b725a9..96b65c3e 100644 --- a/products/openecomp/pom.xml +++ b/products/openecomp/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products</artifactId> - <version>2.0.4</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-openecomp</artifactId> diff --git a/products/pom.xml b/products/pom.xml index 4469dcb9..b7e8f651 100644 --- a/products/pom.xml +++ b/products/pom.xml @@ -19,7 +19,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products</artifactId> diff --git a/products/sample/pom.xml b/products/sample/pom.xml index 86d9f22b..831f9328 100644 --- a/products/sample/pom.xml +++ b/products/sample/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-products</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-products-sample</artifactId> diff --git a/products/sample/src/main/java/org/onap/cli/sample/OnapHelloWorldCommand.java b/products/sample/src/main/java/org/onap/cli/sample/OnapHelloWorldCommand.java index 39311998..f3df340b 100644 --- a/products/sample/src/main/java/org/onap/cli/sample/OnapHelloWorldCommand.java +++ b/products/sample/src/main/java/org/onap/cli/sample/OnapHelloWorldCommand.java @@ -26,7 +26,7 @@ import org.onap.cli.fw.schema.OnapCommandSchema; /** * Hello world. */ -@OnapCommandSchema(schema = "hello-world.yaml") +@OnapCommandSchema(schema = "hello-world-basic.yaml") public class OnapHelloWorldCommand extends OnapCommand { @Override diff --git a/products/sample/src/main/resources/open-cli-schema/hello-world.yaml b/products/sample/src/main/resources/open-cli-schema/hello-world-basic.yaml index d83a8b37..fcaaca2f 100644 --- a/products/sample/src/main/resources/open-cli-schema/hello-world.yaml +++ b/products/sample/src/main/resources/open-cli-schema/hello-world-basic.yaml @@ -14,14 +14,14 @@ open_cli_schema_version: 1.0 -name: hello-world +name: hello description: First cmd hello world info: - product: sample-helloworld - service: hello-world - author: ONAP CLI Team onap-discuss@lists.onap.org + product: tutorial + service: learning + author: Kanagaraj Manickam kanagaraj.manickam@huawei.com parameters: - name: name diff --git a/products/sample/src/main/resources/open-cli-schema/hello-world-command.yaml b/products/sample/src/main/resources/open-cli-schema/hello-world-command.yaml new file mode 100644 index 00000000..fcf44bf1 --- /dev/null +++ b/products/sample/src/main/resources/open-cli-schema/hello-world-command.yaml @@ -0,0 +1,38 @@ +# Copyright 2018 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. + +open_cli_schema_version: 1.0 +name: dir +description: Oclip sample command to do dir +info: + product: tutorial + service: learning + author: Kanagaraj Manickam kanagaraj.manickam@huawei.com + +parameters: + - name: format + type: string + description: Output formats, supported formats such as table, csv, json, yaml + short_option: f + long_option: format + default_value: text + is_default_param: true + +cmd: + command: + - dir + success_codes: + - 0 + working_directory: . + output: $stdout diff --git a/products/sample/src/main/resources/open-cli-schema/hello-world-http.yaml b/products/sample/src/main/resources/open-cli-schema/hello-world-http.yaml index 7fe12ff1..8cad8668 100644 --- a/products/sample/src/main/resources/open-cli-schema/hello-world-http.yaml +++ b/products/sample/src/main/resources/open-cli-schema/hello-world-http.yaml @@ -1,62 +1,64 @@ -# Copyright 2017-18 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. - open_cli_schema_version: 1.0 +name: weather-report +description: | + Place this OCS YAML under $OPEN_CLI_HOME/open-cli-schema folder. Then run the commands + oclip schema-refresh -name: hello-world-http + It is used to display the temparature and wind speed details from https://openweathermap.org. + Try to add new commands to display different weather details by exploring this site. -description: | - First cmd hello world using http runing under - lighttpd in cli at http://<cli-ip>:8080/version.json + Sample usage: + oclip --product tutorial weather-report --host-url http://api.openweathermap.org --zip-code 637301 --country-code in info: - product: sample-helloworld - service: hello-world - author: ONAP CLI Team onap-discuss@lists.onap.org + product: tutorial + service: learning + author: Kanagaraj Manickam kanagaraj.manickam@huawei.com parameters: - - name: name - description: name of the person - long_option: name - short_option: b - default_value: ${DEMO_NAME} - type: string - is_optional: false + - name: zip-code + description: zip-code + type: string + short_option: x + long_option: zip-code + is_optional: true + default_value: 637301 + - name: country-code + description: country-code + type: string + short_option: y + long_option: country-code + is_optional: true + default_value: in + - name: api-code + description: api-code + type: string + short_option: z + long_option: api-code + is_optional: true + default_value: 13cf06b1b379a4b7501c34c2d67a625c results: - direction: landscape - attributes: - - name: output - description: hello world output - type: string - scope: short - + direction: landscape + attributes: + - name: temperature + description: temperature at city + scope: short + type: string + - name: wind + description: wind speed + scope: short + type: string http: - service: - name: sample-service - version: 1.0.0 - auth: none - mode: direct - - request: - uri: /version.json - method: GET - success_codes: - - 200 - - 201 - result_map: - output: Hello ${name}, You are running on $b{$.name} $b{$.version} + service: + auth: none + mode: direct + request: + uri: /data/2.5/weather?zip=${zip-code},${country-code}&appid=${api-code} + method: GET + success_codes: + - 200 + result_map: + temperature: $b{$.main.temp} + wind: $b{$.wind.speed} - sample_response: - body: {"name": "oclip", "version": "1.0"}
\ No newline at end of file diff --git a/products/sample/src/main/resources/open-cli-schema/hello-world-snmp.yaml b/products/sample/src/main/resources/open-cli-schema/hello-world-snmp.yaml index d10051f7..15f3ad92 100644 --- a/products/sample/src/main/resources/open-cli-schema/hello-world-snmp.yaml +++ b/products/sample/src/main/resources/open-cli-schema/hello-world-snmp.yaml @@ -13,13 +13,13 @@ # limitations under the License. open_cli_schema_version: 1.0 -name: hello-world-snmp -description: Sample yaml usin snmp profile +name: hostname +description: Sample yaml using snmp profile for hostname info: - product: sample-helloworld - service: hello-world - author: ONAP CLI Team onap-discuss@lists.onap.org + product: tutorial + service: learning + author: Kanagaraj Manickam kanagaraj.manickam@huawei.com results: direction: portrait diff --git a/profiles/command/pom.xml b/profiles/command/pom.xml index 2379eb68..70eec137 100644 --- a/profiles/command/pom.xml +++ b/profiles/command/pom.xml @@ -22,7 +22,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-profiles</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-profiles-command</artifactId> @@ -62,6 +62,10 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + </plugin> </plugins> </build> </project> diff --git a/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java b/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java index 8e94db85..884cde12 100644 --- a/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java +++ b/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java @@ -16,9 +16,13 @@ package org.onap.cli.fw.cmd.cmd; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -27,19 +31,26 @@ import org.onap.cli.fw.cmd.OnapCommand; import org.onap.cli.fw.cmd.conf.OnapCommandCmdConstants; import org.onap.cli.fw.cmd.error.OnapCommandCmdFailure; import org.onap.cli.fw.cmd.schema.OnapCommandSchemaCmdLoader; +import org.onap.cli.fw.conf.OnapCommandConfig; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandExecutionFailed; import org.onap.cli.fw.error.OnapCommandResultEmpty; import org.onap.cli.fw.error.OnapCommandResultMapProcessingFailed; import org.onap.cli.fw.input.OnapCommandParameter; +import org.onap.cli.fw.output.OnapCommandResultAttribute; +import org.onap.cli.fw.output.OnapCommandResultType; +import org.onap.cli.fw.registrar.OnapCommandRegistrar; import org.onap.cli.fw.schema.OnapCommandSchema; +import org.onap.cli.fw.store.OnapCommandExecutionStore; import org.onap.cli.fw.utils.OnapCommandUtils; import org.onap.cli.fw.utils.ProcessRunner; +import com.google.gson.Gson; import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.PathNotFoundException; import net.minidev.json.JSONArray; +import net.minidev.json.JSONObject; /** * Hello world. @@ -108,6 +119,25 @@ public class OpenCommandShellCmd extends OnapCommand { this.resultMap = resultMap; } + private String getStdoutPath() { + String storePath = this.getExecutionContext().getStorePath(); + storePath = storePath + File.separator + "stdout"; + return storePath; + } + + private String getStderrPath() { + String storePath = this.getExecutionContext().getStorePath(); + storePath = storePath + File.separator + "stderr"; + return storePath; + } + + private String getOutputAttributeFilePath(String attrName, boolean temp) { + String storePath = (!temp) ? this.getExecutionContext().getStorePath() : OnapCommandConfig.getPropertyValue("cli.tmp.dir"); + String randomId = (this.getExecutionContext() != null) ? this.getExecutionContext().getExecutionId() : ("" + System.currentTimeMillis()); + storePath = storePath + File.separator + randomId + "_" + attrName; + return storePath; + } + @Override protected List<String> initializeProfileSchema(Map<String, ?> schemaMap, boolean validate) throws OnapCommandException { return OnapCommandSchemaCmdLoader.parseCmdSchema(this, schemaMap, validate); @@ -118,16 +148,40 @@ public class OpenCommandShellCmd extends OnapCommand { //Read the input arguments Map<String, OnapCommandParameter> paramMap = this.getParametersMap(); + //process command section + Map<String, String> tmpFiles = new HashMap<>(); List<String> commandLine = new ArrayList<>(); for (String cmdTkn: this.getCommand()) { - commandLine.add(OnapCommandUtils.replaceLineFromInputParameters(cmdTkn, paramMap)); + tmpFiles.putAll(this.formTmpFiles(cmdTkn)); + String commandLine1 = OnapCommandUtils.replaceLineForSpecialValues( + cmdTkn, tmpFiles); + commandLine1 = OnapCommandUtils.replaceLineFromInputParameters(commandLine1, paramMap); + + commandLine.add(commandLine1); } + long timeout = Long.parseLong(this.getParametersMap().get(OnapCommandCmdConstants.TIMEOUT).getValue().toString()); + //Process command String []cmd = commandLine.toArray(new String []{}); String cwd = this.getWd(); List <String> envs = new ArrayList<>(); + //add current process environments to sub process + for (Map.Entry<String, String> env: System.getenv().entrySet()) { + envs.add(env.getKey() + "=" + env.getValue()); + } + + //add oclip specific environment variables + if (this.getExecutionContext() != null) { + envs.add("OPEN_CLI_REQUEST_ID=" + this.getExecutionContext().getRequestId()); + if (OnapCommandRegistrar.getRegistrar().getHost() != null) { + envs.add("OPEN_CLI_RPC_HOST=" + OnapCommandRegistrar.getRegistrar().getHost()); + envs.add("OPEN_CLI_RPC_PORT=" + OnapCommandRegistrar.getRegistrar().getPort()); + } + //mrkanag set the profile OPEN_CLI_PROFILE + } + for (String env: this.getEnvs().keySet()) { envs.add(env + "=" + this.getEnvs().get(env)); } @@ -136,38 +190,102 @@ public class OpenCommandShellCmd extends OnapCommand { cmd, (envs.size() > 0) ? envs.toArray(new String []{}) : null, cwd); + FileOutputStream stdoutStream = null; + FileOutputStream stderrStream = null; + String outputValue = ""; + try { + pr.setTimeout(timeout); + + if (this.getExecutionContext() != null) { + + stdoutStream = new FileOutputStream(this.getStdoutPath()); + stderrStream = new FileOutputStream(this.getStderrPath()); + + pr.setStdout(stdoutStream); + pr.setStderr(stderrStream); + + OnapCommandExecutionStore.getStore().storeExectutionDebug(this.getExecutionContext(), pr.toString()); + } else { + this.getResult().setDebugInfo(pr.toString()); + } + pr.run(); } catch (Exception e) { throw new OnapCommandExecutionFailed(this.getName(), e); + } finally { + if (stdoutStream != null) { + try { + stdoutStream.close(); + } catch (IOException e) { + //never occurs // NOSONAR + } + } + if (stderrStream != null) { + try { + stderrStream.close(); + } catch (IOException e) { + //never occurs // NOSONAR + } + } } if (!this.successStatusCodes.contains(pr.getExitCode())) { throw new OnapCommandExecutionFailed(this.getName(), pr.getError(), pr.getExitCode()); } - String outputValue = ""; - if (this.output.equals("$stdout")) { - outputValue = pr.getOutput(); + if (pr.getStdout() != null) { + try (FileInputStream is = new FileInputStream(this.getStdoutPath())){ + outputValue = pr.streamToString(is); + } catch (IOException e) { + //never occurs // NOSONAR + } + } else + outputValue = pr.getOutput(); + + } else if (this.output.equals("$stderr")) { + if (pr.getStderr() != null) { + try (FileInputStream is = new FileInputStream(this.getStderrPath())) { + outputValue = pr.streamToString(is); + } catch (IOException e) { + //never occurs // NOSONAR + } + } else + outputValue = pr.getError(); + } else { - outputValue = OnapCommandUtils.replaceLineFromInputParameters(this.output, paramMap); - outputValue = OnapCommandUtils.replaceLineForSpecialValues(outputValue); + //remove ${tmp: and closing } + String tmpName = this.output.substring(7, this.output.length()-1); + String tmpFile = tmpFiles.get("tmp:" + tmpName); + if (tmpFile != null) { + try (FileInputStream is = new FileInputStream(tmpFile)) { + outputValue = pr.streamToString(is); + } catch (IOException e) { + //never occurs // NOSONAR + } + } } + this.getResult().setDebugInfo(pr.toString() + "\n" + outputValue); this.getResult().setOutput(outputValue); //populate results - for (Entry<String, String> resultMapEntry : this.getResultMap().entrySet()) { - String value = OnapCommandUtils.replaceLineFromInputParameters(resultMapEntry.getValue(), paramMap); - value = OnapCommandUtils.replaceLineForSpecialValues(value); - this.getResult().getRecordsMap().get(resultMapEntry.getKey()).setValues( - this.replaceLineFromOutputResults(value, outputValue)); - } + if (!this.getResult().getType().name().equalsIgnoreCase(OnapCommandResultType.TEXT.name())) + for (Entry<String, String> resultMapEntry : this.getResultMap().entrySet()) { + String attrName = resultMapEntry.getKey(); + OnapCommandResultAttribute attr = this.getResult().getRecordsMap().get(attrName); + + String value = OnapCommandUtils.replaceLineFromInputParameters(resultMapEntry.getValue(), paramMap); + value = OnapCommandUtils.replaceLineForSpecialValues(value); + attr.setValues(this.replaceLineFromOutputResults(value, outputValue)); + } //check for pass/failure - if (!this.passCodes.contains(pr.getExitCode())) { + if (!this.passCodes.isEmpty() && !this.passCodes.contains(pr.getExitCode())) { this.getResult().setPassed(false); + } else { + this.getResult().setPassed(true); } } @@ -179,6 +297,30 @@ public class OpenCommandShellCmd extends OnapCommand { this.output = output; } + private Map<String, String> formTmpFiles(String line){ + + Map<String, String> result = new HashMap<>(); + + if (!line.contains("$s{tmp")) { + return result; + } + + int currentIdx = 0; + while (currentIdx < line.length()) { + int idxS = line.indexOf("$s{tmp:", currentIdx); //check for output stream + if (idxS == -1) { + break; + } + + int idxE = line.indexOf("}", idxS); + String tmpName = line.substring(idxS + 7, idxE); + tmpName = tmpName.trim(); + result.put("tmp:" + tmpName, this.getOutputAttributeFilePath(tmpName, true)); + currentIdx = idxE + 1; + } + return result; + } + private ArrayList<String> replaceLineFromOutputResults(String line, String output) throws OnapCommandException { @@ -217,8 +359,11 @@ public class OpenCommandShellCmd extends OnapCommand { jsonPath = jsonPath.trim(); Object value = new Object(); try { - // JSONArray or String - value = JsonPath.read(output, jsonPath); + // Instead of parsing, just assign the json as it is + if (!jsonPath.equals("$")) + value = JsonPath.read(output, jsonPath); + else + value = output; } catch (PathNotFoundException e1) { // NOSONAR //set to blank for those entries which are missing from the output json value = ""; diff --git a/profiles/command/src/main/java/org/onap/cli/fw/cmd/conf/OnapCommandCmdConstants.java b/profiles/command/src/main/java/org/onap/cli/fw/cmd/conf/OnapCommandCmdConstants.java index 6594ef71..4f2d36b4 100644 --- a/profiles/command/src/main/java/org/onap/cli/fw/cmd/conf/OnapCommandCmdConstants.java +++ b/profiles/command/src/main/java/org/onap/cli/fw/cmd/conf/OnapCommandCmdConstants.java @@ -38,6 +38,7 @@ public class OnapCommandCmdConstants { public static final String CMD_SECTIONS = "cli.schema.cmd.sections"; public static final String DEFAULT_PARAMETER_CMD_FILE_NAME = "default_input_parameters_cmd.yaml"; + public static final String TIMEOUT = "timeout"; private OnapCommandCmdConstants() { //as per coding standard ! } diff --git a/profiles/command/src/main/resources/open-cli-schema/cmd/default_input_parameters_cmd.yaml b/profiles/command/src/main/resources/open-cli-schema/cmd/default_input_parameters_cmd.yaml index b358a0c7..b6a97b0d 100644 --- a/profiles/command/src/main/resources/open-cli-schema/cmd/default_input_parameters_cmd.yaml +++ b/profiles/command/src/main/resources/open-cli-schema/cmd/default_input_parameters_cmd.yaml @@ -13,3 +13,13 @@ # limitations under the License. open_cli_schema_version: 1.0 + +parameters: + - name: timeout + type: string + description: timeout for command to complete the given task in milliseconds + short_option: u + long_option: timeout + default_value: 60000 + is_optional: true + is_default_param: false
\ No newline at end of file diff --git a/profiles/http/pom.xml b/profiles/http/pom.xml index 1103f2f4..b8563e48 100644 --- a/profiles/http/pom.xml +++ b/profiles/http/pom.xml @@ -22,7 +22,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-profiles</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-profiles-http</artifactId> @@ -59,30 +59,12 @@ <version>2.9.4</version> </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.11</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.jmockit</groupId> - <artifactId>jmockit</artifactId> - <version>1.19</version> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.onap.cli</groupId> <artifactId>cli-main</artifactId> <version>${project.version}</version> <scope>test</scope> </dependency> <dependency> - <groupId>org.jmockit</groupId> - <artifactId>jmockit-coverage</artifactId> - <version>1.19</version> - <scope>test</scope> - </dependency> - <dependency> <groupId>com.github.dreamhead</groupId> <artifactId>moco-runner</artifactId> <version>0.12.0</version> @@ -96,14 +78,36 @@ <artifactId>logback-classic</artifactId> </exclusion> </exclusions> - </dependency> - </dependencies> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jmockit</groupId> + <artifactId>jmockit</artifactId> + <version>1.19</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jmockit</groupId> + <artifactId>jmockit-coverage</artifactId> + <version>1.19</version> + <scope>test</scope> + </dependency> + </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + </plugin> </plugins> </build> </project> 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 9b7b4039..e5f17bec 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 @@ -45,9 +45,9 @@ public class OnapCommandHttpAuthClient { private Map<String, String> loginCache = new HashMap<>(); - public OnapCommandHttpAuthClient(OnapHttpCommand cmd, boolean debug) throws OnapCommandHttpFailure { + public OnapCommandHttpAuthClient(OnapHttpCommand cmd) { this.cmd = cmd; - this.http = new OnapHttpConnection(debug); + this.http = new OnapHttpConnection(); } /** @@ -142,11 +142,6 @@ public class OnapCommandHttpAuthClient { } } - - public String getDebugInfo() { - return this.http.getDebugInfo(); - } - /** * Http call to external service. * 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 14728ad0..53a2d042 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 @@ -16,6 +16,14 @@ package org.onap.cli.fw.http.cmd; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; + import org.onap.cli.fw.cmd.OnapCommand; import org.onap.cli.fw.cmd.OnapCommandType; import org.onap.cli.fw.conf.OnapCommandConfig; @@ -34,19 +42,12 @@ import org.onap.cli.fw.http.utils.OnapCommandHttpUtils; import org.onap.cli.fw.input.OnapCommandParameter; import org.onap.cli.fw.output.OnapCommandResultAttribute; import org.onap.cli.fw.schema.OnapCommandSchema; +import org.onap.cli.fw.store.OnapCommandExecutionStore; import org.onap.cli.fw.utils.OnapCommandUtils; import org.onap.cli.http.mock.MockJsonGenerator; import org.onap.cli.http.mock.MockRequest; import org.onap.cli.http.mock.MockResponse; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; - /** * Oclip http Command. * @@ -56,6 +57,8 @@ public class OnapHttpCommand extends OnapCommand { private HttpInput input = new HttpInput(); + private HttpResult output = new HttpResult(); + private List<Integer> successStatusCodes = new ArrayList<>(); private Map<String, String> resultMap = new HashMap<>(); @@ -201,14 +204,11 @@ public class OnapHttpCommand extends OnapCommand { @Override protected void run() throws OnapCommandException { + this.authClient = new OnapCommandHttpAuthClient(this); + try { // For auth/catalog type commands, login and logout logic is not required boolean isAuthRequired = this.isAuthRequired(); - - this.authClient = new OnapCommandHttpAuthClient( - this, - this.getResult().isDebug()); - if (isAuthRequired) { this.authClient.login(); } @@ -218,24 +218,28 @@ public class OnapHttpCommand extends OnapCommand { if (isAuthRequired) { this.authClient.logout(); } - - if (this.getResult().isDebug() && authClient != null) { - this.getResult().setDebugInfo(this.authClient.getDebugInfo()); - } } catch (OnapCommandException e) { - if (this.getResult().isDebug() && authClient != null) { - this.getResult().setDebugInfo(this.authClient.getDebugInfo()); - } throw e; + } finally { + this.getResult().setDebugInfo(this.input.toString() + "\n" + this.output.toString()); } } protected void processRequest() throws OnapCommandException { HttpInput httpInput = OnapCommandHttpUtils.populateParameters(this.getParametersMap(), this.getInput()); - httpInput.setUri(this.authClient.getServiceUrl() + httpInput.getUri()); + if (!httpInput.getUri().startsWith("http")) { + httpInput.setUri(this.authClient.getServiceUrl() + httpInput.getUri()); + } - HttpResult output = this.authClient.run(httpInput); + this.setInput(httpInput); + + if (this.getExecutionContext() != null) { + OnapCommandExecutionStore.getStore().storeExectutionDebug(this.getExecutionContext(), this.getInput().toString()); + } else { + this.getResult().setDebugInfo(this.getInput().toString()); + } + this.output = this.authClient.run(this.getInput()); this.getResult().setOutput(output); if (!this.getSuccessStatusCodes().contains(output.getStatus())) { @@ -250,12 +254,17 @@ public class OnapHttpCommand extends OnapCommand { } Map<String, ArrayList<String>> results = OnapCommandHttpUtils.populateOutputs(this.getResultMap(), output); - results = OnapCommandUtils.populateOutputsFromInputParameters(results, this.getParametersMap()); + //results = OnapCommandUtils.populateOutputsFromInputParameters(results, this.getParametersMap()); for (OnapCommandResultAttribute attr : this.getResult().getRecords()) { attr.setValues(results.get(attr.getName())); } - generateJsonMock(httpInput, output, this.getSchemaName()); + + try{ + generateJsonMock(this.getInput(), output, this.getSchemaName()); + } catch (OnapCommandFailedMocoGenerate e) { + //NO SONAR ignore it + } } private void generateJsonMock(HttpInput httpInput, HttpResult httpResult, String schemaName) diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java b/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java index 2d14bb88..6a87ed13 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java @@ -94,6 +94,7 @@ public class OnapCommandHttpConstants { //context param public static final String CONTEXT = "context"; public static final String CONTEXT_REMOVE_EMPTY_JSON_NODES = "remove_empty_node"; + public static final String __BODY__ = "__body__"; // moco server const public static final String VERIFY_MOCO_HOST = "cli.verify.host"; 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 a2da0706..3f426bf3 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 @@ -27,15 +27,18 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; + import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; + import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.annotation.NotThreadSafe; import org.apache.http.client.CookieStore; import org.apache.http.client.HttpClient; +import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; import org.apache.http.client.methods.HttpGet; @@ -79,10 +82,6 @@ public class OnapHttpConnection { Map<String, String> mapCommonHeaders = new HashMap<> (); - protected boolean debug = false; - - private String debugDetails = ""; - public static class TrustAllX509TrustManager implements X509TrustManager { @Override @@ -101,18 +100,6 @@ public class OnapHttpConnection { } } - /** - * OnapHttpConnection Constructor. - * - * @param debug - * boolean - * @throws OnapCommandHttpFailure - * exception - */ - public OnapHttpConnection(boolean debug) { - this.debug = debug; - } - private void initHttpClient(boolean isSecured) throws OnapCommandHttpFailure { if (this.httpClient == null) { try { @@ -137,10 +124,6 @@ public class OnapHttpConnection { } } - public String getDebugInfo() { - return this.debugDetails; - } - private Map<String, String> getHttpHeaders(HttpResponse resp) { Map<String, String> result = new HashMap<>(); @@ -244,9 +227,12 @@ public class OnapHttpConnection { } } - private void addCommonCookies(CookieStore cookieStore) { + private void addCommonCookies(HttpInput input, CookieStore cookieStore) { for (Entry<String, String> header : this.mapCommonHeaders.entrySet()) { - Cookie cookie = new BasicClientCookie(header.getKey(), header.getValue()); + //take care of overriden headers in OCS YAML + String value = input.getReqHeaders().getOrDefault(header.getKey(), + header.getValue()); + Cookie cookie = new BasicClientCookie(header.getKey(), value); cookieStore.addCookie(cookie); } } @@ -267,7 +253,7 @@ public class OnapHttpConnection { } private void updateInputFromCookies(HttpInput input, CookieStore cookieStore) { - addCommonCookies(cookieStore); + addCommonCookies(input, cookieStore); for (String cookieName : input.getReqCookies().keySet()) { BasicClientCookie cookie = new BasicClientCookie(cookieName, input.getReqCookies().get(cookieName)); cookie.setDomain(this.getDomain(input.getUri())); @@ -320,6 +306,8 @@ public class OnapHttpConnection { } requestBase.setURI(URI.create(input.getUri())); + requestBase.setConfig(RequestConfig.custom() + .setSocketTimeout(30000).setConnectTimeout(50000).build()); for (Entry<String, String> h : input.getReqHeaders().entrySet()) { requestBase.addHeader(h.getKey(), h.getValue()); @@ -328,7 +316,6 @@ public class OnapHttpConnection { HttpResult result = new HttpResult(); try { - this.debugDetails = ""; CookieStore cookieStore = new BasicCookieStore(); updateInputFromCookies(input, cookieStore); HttpContext localContext = new BasicHttpContext(); @@ -344,12 +331,6 @@ public class OnapHttpConnection { this.updateResultFromCookies(result, cookieStore.getCookies()); } catch (Exception e) { // NOSONAR throw new OnapCommandHttpFailure(e); - } finally { - String info = input + " " + result; - log.info(info); - if (this.debug) { - this.debugDetails = info; - } } return result; 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 f4a6cee5..5cab0a68 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 @@ -76,24 +76,22 @@ public class OnapCommandHttpUtils { } } + inp.setUri(OnapCommandUtils.replaceLineForSpecialValues(input.getUri())); inp.setUri(OnapCommandUtils.replaceLineFromInputParameters(input.getUri(), params)); inp.setMethod(input.getMethod().toLowerCase()); - for (String h : input.getReqHeaders().keySet()) { - String value = input.getReqHeaders().get(h); - inp.getReqHeaders().put(h, OnapCommandUtils.replaceLineFromInputParameters(value, params)); - } + boolean isRemoveEmptyNodes = Boolean.parseBoolean(input.getContext().getOrDefault(OnapCommandHttpConstants.CONTEXT_REMOVE_EMPTY_JSON_NODES, "false")); - for (String h : input.getReqQueries().keySet()) { - String value = input.getReqQueries().get(h); - inp.getReqQueries().put(h, OnapCommandUtils.replaceLineFromInputParameters(value, params)); + //Process for md5 + Map <String, String> values = new HashMap<>(); + for (Map.Entry<String, OnapCommandParameter> param: params.entrySet()) { + values.put(param.getKey(), param.getValue().getValue().toString()); } - boolean isRemoveEmptyNodes = Boolean.parseBoolean(input.getContext().getOrDefault(OnapCommandHttpConstants.CONTEXT_REMOVE_EMPTY_JSON_NODES, "false")); - if (input.getMultiparts().size() > 0) { for (HttpInput.Part part: input.getMultiparts()) { + part.setContent(OnapCommandUtils.replaceLineForSpecialValues(part.getContent(), values)); part.setContent(OnapCommandUtils.replaceLineFromInputParameters(part.getContent(), params)); if (isRemoveEmptyNodes) { part.setContent(OnapCommandHttpUtils.normalizeJson(part.getContent())); @@ -103,11 +101,28 @@ public class OnapCommandHttpUtils { inp.setMultiparts(input.getMultiparts()); } else { inp.setMultipartEntityName(input.getMultipartEntityName()); - inp.setBody(OnapCommandUtils.replaceLineFromInputParameters(input.getBody(), params)); + inp.setBody(OnapCommandUtils.replaceLineForSpecialValues(input.getBody(), values)); + inp.setBody(OnapCommandUtils.replaceLineFromInputParameters(inp.getBody(), params)); if (isRemoveEmptyNodes) { inp.setBody(OnapCommandHttpUtils.normalizeJson(inp.getBody())); } } + + //consider __body__ spl entry + values.put(OnapCommandHttpConstants.__BODY__, inp.getBody()); + + for (String h : input.getReqHeaders().keySet()) { + String value = input.getReqHeaders().get(h); + value = OnapCommandUtils.replaceLineForSpecialValues(value, values); + inp.getReqHeaders().put(h, OnapCommandUtils.replaceLineFromInputParameters(value, params)); + } + + for (String h : input.getReqQueries().keySet()) { + String value = input.getReqQueries().get(h); + value = OnapCommandUtils.replaceLineForSpecialValues(value, values); + inp.getReqQueries().put(h, OnapCommandUtils.replaceLineFromInputParameters(value, params)); + } + return inp; } diff --git a/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java b/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java index fab02ff2..f0115580 100644 --- a/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java +++ b/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java @@ -72,8 +72,7 @@ public class OnapHttpConnectionTest { } }; inp.setMethod("get"); - con = new OnapHttpConnection(true); - con.getDebugInfo(); + con = new OnapHttpConnection(); con.get(inp); } @@ -90,7 +89,7 @@ public class OnapHttpConnectionTest { }; inp.setMethod("post"); - con = new OnapHttpConnection(true); + con = new OnapHttpConnection(); con.post(inp); } @@ -108,7 +107,7 @@ public class OnapHttpConnectionTest { inp.setMethod("post"); inp.setBinaryData(true); - con = new OnapHttpConnection(true); + con = new OnapHttpConnection(); con.post(inp); } @@ -123,7 +122,7 @@ public class OnapHttpConnectionTest { } }; inp.setMethod("put"); - con = new OnapHttpConnection(true); + con = new OnapHttpConnection(); con.put(inp); } @@ -138,7 +137,7 @@ public class OnapHttpConnectionTest { } }; inp.setMethod("delete"); - con = new OnapHttpConnection(true); + con = new OnapHttpConnection(); con.delete(inp); } @@ -153,14 +152,14 @@ public class OnapHttpConnectionTest { } }; inp.setMethod("other"); - con = new OnapHttpConnection(true); + con = new OnapHttpConnection(); con.request(inp); } @Test() public void httpUnSecuredCloseExceptionTest() throws OnapCommandHttpFailure { inp.setMethod("other"); - con = new OnapHttpConnection(true); + con = new OnapHttpConnection(); con.close(); } @@ -185,7 +184,7 @@ public class OnapHttpConnectionTest { inp.setReqHeaders(new HashMap<String, String>()); inp.setReqQueries(new HashMap<String, String>()); inp.setUri("https://192.168.99.10:80"); - OnapHttpConnection con = new OnapHttpConnection(false); + OnapHttpConnection con = new OnapHttpConnection(); con.get(inp); } catch (OnapCommandHttpFailure e) { assertEquals("0x3001::IO Exception", e.getMessage()); diff --git a/profiles/pom.xml b/profiles/pom.xml index 20abad3f..94f71c51 100644 --- a/profiles/pom.xml +++ b/profiles/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-profiles</artifactId> @@ -35,6 +35,7 @@ <module>http</module> <module>snmp</module> <module>command</module> + </modules> <dependencies> <dependency> @@ -53,6 +54,32 @@ <pluginManagement> <plugins> <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <version>3.1.0</version> + <executions> + <execution> + <id>copy-resource-conf</id> + <phase>install</phase> + <goals> + <goal>copy-resources</goal> + </goals> + + <configuration> + <outputDirectory>../../profiles/target/conf</outputDirectory> + <resources> + <resource> + <directory>${project.basedir}/src/main/resources</directory> + <includes> + <include>*.properties</include> + </includes> + </resource> + </resources> + </configuration> + </execution> + </executions> + </plugin> + <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> diff --git a/profiles/snmp/pom.xml b/profiles/snmp/pom.xml index 4b9884d6..1dcaa59a 100644 --- a/profiles/snmp/pom.xml +++ b/profiles/snmp/pom.xml @@ -22,7 +22,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-profiles</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-profiles-snmp</artifactId> @@ -62,6 +62,10 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + </plugin> </plugins> </build> </project> diff --git a/validate/pom.xml b/validate/pom.xml index 46a899cc..5c9b9ee2 100644 --- a/validate/pom.xml +++ b/validate/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-validate</artifactId> diff --git a/validate/sample-mock-generator/pom.xml b/validate/sample-mock-generator/pom.xml index 6b3eb54c..dfa5b9b7 100644 --- a/validate/sample-mock-generator/pom.xml +++ b/validate/sample-mock-generator/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-validate</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-sample-mock-generator</artifactId> @@ -39,6 +39,18 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.jmockit</groupId> + <artifactId>jmockit</artifactId> + <version>1.19</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jmockit</groupId> + <artifactId>jmockit-coverage</artifactId> + <version>1.19</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.4</version> diff --git a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java index cbb2a26a..d1d8b08d 100644 --- a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java +++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.net.URL; import java.util.Map; +import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -61,8 +62,12 @@ public class MockRequest { public void setJson(String json) throws IOException { if (!json.isEmpty()) { - ObjectMapper objectMapper = new ObjectMapper(); - this.json = objectMapper.readTree(json); + try { + ObjectMapper objectMapper = new ObjectMapper(); + this.json = objectMapper.readTree(json); + } catch (Exception e) { + this.json = new ObjectMapper().readTree("{}"); + } } } diff --git a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java index 7e8cdca8..d7999bea 100644 --- a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java +++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java @@ -38,9 +38,13 @@ public class MockResponse { } public void setJson(String json) throws IOException { - if (json != null && !json.isEmpty()) { - ObjectMapper objectMapper = new ObjectMapper(); - this.json = objectMapper.readTree(json); + if (!json.isEmpty()) { + try { + ObjectMapper objectMapper = new ObjectMapper(); + this.json = objectMapper.readTree(json); + } catch (Exception e) { + this.json = new ObjectMapper().readTree("{}"); + } } } } diff --git a/validate/sample-mock-generator/src/test/java/org/onap/cli/http/mock/MockJsonGeneratorTest.java b/validate/sample-mock-generator/src/test/java/org/onap/cli/http/mock/MockJsonGeneratorTest.java index 3b79057f..0e0c0f59 100644 --- a/validate/sample-mock-generator/src/test/java/org/onap/cli/http/mock/MockJsonGeneratorTest.java +++ b/validate/sample-mock-generator/src/test/java/org/onap/cli/http/mock/MockJsonGeneratorTest.java @@ -34,32 +34,4 @@ public class MockJsonGeneratorTest { MockJsonGenerator.generateMocking(mockRequest, mockResponse, "target/test"); } - - @Test(expected=IOException.class) - public void mocoGenerateFailedInvalidBodyTest() throws IOException { - MockRequest mockRequest = new MockRequest(); - mockRequest.setJson("{\"value\" : \"234sdf-345\""); - mockRequest.setMethod("get"); - mockRequest.setUri("http://1.1.1.1:80/getResource"); - - MockResponse mockResponse = new MockResponse(); - mockResponse.setStatus(200); - mockResponse.setJson("{\"value\" : \"234sdf-345\""); - - MockJsonGenerator.generateMocking(mockRequest, mockResponse, "target/test"); - } - - @Test(expected=IOException.class) - public void mocoGenerateFailedInvalidUrlTest() throws IOException { - MockRequest mockRequest = new MockRequest(); - mockRequest.setJson("{\"value\" : \"234sdf-345\""); - mockRequest.setMethod("get"); - mockRequest.setUri("http://1.1.1.1:80:invalid"); - - MockResponse mockResponse = new MockResponse(); - mockResponse.setStatus(200); - mockResponse.setJson("{\"value\" : \"234sdf-345\""); - - MockJsonGenerator.generateMocking(mockRequest, mockResponse, "target/test"); - } } diff --git a/validate/sample-yaml-generator/pom.xml b/validate/sample-yaml-generator/pom.xml index 400d72f1..c9503c5e 100644 --- a/validate/sample-yaml-generator/pom.xml +++ b/validate/sample-yaml-generator/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-validate</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-sample-yaml-generator</artifactId> @@ -38,6 +38,18 @@ <version>4.11</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.jmockit</groupId> + <artifactId>jmockit</artifactId> + <version>1.19</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jmockit</groupId> + <artifactId>jmockit-coverage</artifactId> + <version>1.19</version> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java b/validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java index 179eaa36..b2e2dc88 100644 --- a/validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java +++ b/validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java @@ -27,11 +27,9 @@ public class SampleYamlGenerator { static int nTab; - public static void generateSampleYaml(List<String> input, String output, String version, + public static void generateSampleYaml(String cmdName, List<String> input, String output, String version, String targetPath, boolean debug) throws IOException { - String cmdName = input.get(0); - PrintWriter writer = new PrintWriter(targetPath, "UTF-8"); writeKeyValuePair(writer, "open_cli_sample_version", "1.0"); writeKeyValuePair(writer, "name", cmdName); @@ -41,7 +39,7 @@ public class SampleYamlGenerator { writeKey(writer, "sample1"); writeKeyValuePair(writer, "name", cmdName); - writeKeyValuePair(writer, "input", input.stream().skip(1).collect(Collectors.joining(" ")).trim()); + writeKeyValuePair(writer, "input", input.stream().collect(Collectors.joining(" ")).trim()); writeKeyValuePair(writer, "moco", new File(targetPath).getName().replaceAll("-sample.yaml", "-moco.json")); writeMultilineKeyValue(writer, "output", output.trim(), debug); @@ -60,7 +58,7 @@ public class SampleYamlGenerator { writer.write(" |\n"); nTab++; String[] lines = value.split("\n"); - long skipLines = debug ? 11 : 0; + long skipLines = debug ? 0 : 0; Arrays.stream(lines).skip(skipLines ).forEach(line -> writer.write(printTabs() + line + "\n")); // NOSONAR } diff --git a/validate/sample-yaml-generator/src/test/java/org/onap/cli/sample/yaml/SampleYamlGeneratorTest.java b/validate/sample-yaml-generator/src/test/java/org/onap/cli/sample/yaml/SampleYamlGeneratorTest.java index 98c0ce9d..fba93e62 100644 --- a/validate/sample-yaml-generator/src/test/java/org/onap/cli/sample/yaml/SampleYamlGeneratorTest.java +++ b/validate/sample-yaml-generator/src/test/java/org/onap/cli/sample/yaml/SampleYamlGeneratorTest.java @@ -25,7 +25,7 @@ public class SampleYamlGeneratorTest { @Test public void testGenerateSampleYaml() throws IOException { - SampleYamlGenerator.generateSampleYaml(Arrays.asList("testcmd", "-a", "argument"), + SampleYamlGenerator.generateSampleYaml("testcmd", Arrays.asList("-a", "argument"), "+--------+\n+val +\n+argument+", "test-version-1.0", "target/test.yaml", false); } diff --git a/validate/validation/pom.xml b/validate/validation/pom.xml index 7767913c..526aa0f6 100644 --- a/validate/validation/pom.xml +++ b/validate/validation/pom.xml @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli-validate</artifactId> - <version>3.0.0</version> + <version>4.0.0-SNAPSHOT</version> </parent> <artifactId>cli-validation</artifactId> @@ -38,6 +38,18 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.jmockit</groupId> + <artifactId>jmockit</artifactId> + <version>1.19</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jmockit</groupId> + <artifactId>jmockit-coverage</artifactId> + <version>1.19</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.onap.cli</groupId> <artifactId>cli-main</artifactId> <version>${project.version}</version> |