From cb07500090e0c50929e7543a63b42ff5b8dc12e3 Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Tue, 16 Mar 2021 00:30:22 -0400 Subject: Renaming ansible and saltstanck adapter to adaptor Issue-ID: CCSDK-3212 Signed-off-by: Singal, Kapil (ks220y) Change-Id: Ibf0366b31a37173050602bd692627647f4f29bb7 --- adaptors/ansible-adapter/.pydevproject | 5 - .../ansible-adapter-bundle/.gitignore | 25 - .../ansible-adapter/ansible-adapter-bundle/pom.xml | 123 --- .../ccsdk/sli/adaptors/ansible/AnsibleAdapter.java | 53 - .../adaptors/ansible/AnsibleAdapterConstants.java | 50 - .../ansible/AnsibleAdapterPropertiesProvider.java | 31 - .../adaptors/ansible/impl/AnsibleAdapterImpl.java | 620 ------------ .../impl/AnsibleAdapterPropertiesProviderImpl.java | 208 ---- .../adaptors/ansible/impl/ConnectionBuilder.java | 235 ----- .../ansible/model/AnsibleMessageParser.java | 367 ------- .../sli/adaptors/ansible/model/AnsibleResult.java | 115 --- .../adaptors/ansible/model/AnsibleResultCodes.java | 91 -- .../ansible/model/AnsibleServerEmulator.java | 126 --- .../blueprint/ansible-adapter-blueprint.xml | 40 - .../src/main/resources/ansible-adapter.properties | 42 - .../blueprint/ansible-adapter-blueprint.xml | 40 - .../ansible/impl/TestAnsibleAdapterImpl.java | 239 ----- .../TestAnsibleAdapterPropertiesProviderImpl.java | 64 -- .../ansible/impl/TestConnectionBuilder.java | 236 ----- .../adapter/ansible/model/TestAnsibleAdapter.java | 100 -- .../ansible/model/TestAnsibleMessageParser.java | 249 ----- .../adapter/ansible/model/TestAnsibleResult.java | 45 - .../java/org/onap/ccsdk/test/ExecutorHarness.java | 166 ---- .../java/org/onap/ccsdk/test/InterceptLogger.java | 447 --------- .../ansible-adapter-bundle/src/test/resources/cert | 125 --- .../resources/org/onap/appc/asdc-client-cert.crt | 10 - .../test/resources/org/onap/appc/asdc-client.jks | Bin 1177 -> 0 bytes .../properties/ansible-adapter-test.properties | 109 -- .../ansible-adapter-installer/pom.xml | 150 --- .../src/assembly/assemble_installer_zip.xml | 62 -- .../src/assembly/assemble_mvnrepo_zip.xml | 50 - .../src/main/resources/scripts/install-feature.sh | 42 - adaptors/ansible-adapter/pom.xml | 181 ---- adaptors/ansible-adaptor/.pydevproject | 5 + .../ansible-adaptor-bundle/.gitignore | 25 + .../ansible-adaptor/ansible-adaptor-bundle/pom.xml | 123 +++ .../ccsdk/sli/adaptors/ansible/AnsibleAdaptor.java | 53 + .../adaptors/ansible/AnsibleAdaptorConstants.java | 50 + .../ansible/AnsibleAdaptorPropertiesProvider.java | 31 + .../adaptors/ansible/impl/AnsibleAdaptorImpl.java | 620 ++++++++++++ .../impl/AnsibleAdaptorPropertiesProviderImpl.java | 208 ++++ .../adaptors/ansible/impl/ConnectionBuilder.java | 235 +++++ .../ansible/model/AnsibleMessageParser.java | 367 +++++++ .../sli/adaptors/ansible/model/AnsibleResult.java | 115 +++ .../adaptors/ansible/model/AnsibleResultCodes.java | 91 ++ .../ansible/model/AnsibleServerEmulator.java | 126 +++ .../blueprint/ansible-adaptor-blueprint.xml | 40 + .../src/main/resources/ansible-adaptor.properties | 42 + .../blueprint/ansible-adaptor-blueprint.xml | 40 + .../ansible/impl/TestAnsibleAdaptorImpl.java | 239 +++++ .../TestAnsibleAdaptorPropertiesProviderImpl.java | 64 ++ .../ansible/impl/TestConnectionBuilder.java | 236 +++++ .../adaptors/ansible/model/TestAnsibleAdaptor.java | 100 ++ .../ansible/model/TestAnsibleMessageParser.java | 249 +++++ .../adaptors/ansible/model/TestAnsibleResult.java | 45 + .../java/org/onap/ccsdk/test/ExecutorHarness.java | 166 ++++ .../java/org/onap/ccsdk/test/InterceptLogger.java | 447 +++++++++ .../ansible-adaptor-bundle/src/test/resources/cert | 125 +++ .../resources/org/onap/appc/asdc-client-cert.crt | 10 + .../test/resources/org/onap/appc/asdc-client.jks | Bin 0 -> 1177 bytes .../properties/ansible-adaptor-test.properties | 109 ++ .../ansible-adaptor-installer/pom.xml | 150 +++ .../src/assembly/assemble_installer_zip.xml | 62 ++ .../src/assembly/assemble_mvnrepo_zip.xml | 50 + .../src/main/resources/scripts/install-feature.sh | 42 + adaptors/ansible-adaptor/pom.xml | 181 ++++ adaptors/artifacts/pom.xml | 12 +- adaptors/features/ccsdk-ansible-adapter/pom.xml | 43 - adaptors/features/ccsdk-ansible-adaptor/pom.xml | 43 + adaptors/features/ccsdk-saltstack-adapter/pom.xml | 39 - adaptors/features/ccsdk-saltstack-adaptor/pom.xml | 39 + adaptors/features/ccsdk-sli-adaptors-all/pom.xml | 6 +- adaptors/features/installer/pom.xml | 4 +- adaptors/features/pom.xml | 4 +- adaptors/message-router/consumer/pom.xml | 2 +- adaptors/message-router/pom.xml | 2 +- adaptors/message-router/publisher/pom.xml | 2 +- adaptors/pom.xml | 4 +- adaptors/saltstack-adapter/.pydevproject | 5 - adaptors/saltstack-adapter/README.md | 137 --- adaptors/saltstack-adapter/pom.xml | 197 ---- .../saltstack-adapter-installer/pom.xml | 164 --- .../src/assembly/assemble_installer_zip.xml | 61 -- .../src/assembly/assemble_mvnrepo_zip.xml | 50 - .../src/main/resources/scripts/install-feature.sh | 42 - .../saltstack-adapter-provider/.gitignore | 25 - .../saltstack-adapter-provider/pom.xml | 115 --- .../sli/adaptors/saltstack/SaltstackAdapter.java | 59 -- .../SaltstackAdapterPropertiesProvider.java | 32 - .../adaptors/saltstack/impl/ConnectionBuilder.java | 172 ---- .../saltstack/impl/SaltstackAdapterImpl.java | 446 --------- .../SaltstackAdapterPropertiesProviderImpl.java | 192 ---- .../sli/adaptors/saltstack/impl/SshConnection.java | 217 ---- .../sli/adaptors/saltstack/model/Constants.java | 93 -- .../sli/adaptors/saltstack/model/JsonParser.java | 89 -- .../saltstack/model/SaltstackMessageParser.java | 412 -------- .../adaptors/saltstack/model/SaltstackResult.java | 102 -- .../saltstack/model/SaltstackResultCodes.java | 100 -- .../saltstack/model/SaltstackServerEmulator.java | 93 -- .../sli/adaptors/saltstack/model/SshException.java | 37 - .../blueprint/saltstack-adapter-blueprint.xml | 42 - .../main/resources/saltstack-adapter.properties | 43 - .../ccsdk/adapter/impl/TestConnectionBuilder.java | 184 ---- .../adapter/impl/TestSaltstackAdapterImpl.java | 1051 -------------------- ...TestSaltstackAdapterPropertiesProviderImpl.java | 310 ------ .../onap/ccsdk/adapter/model/TestJsonParser.java | 76 -- .../src/test/resources/config.sls | 2 - .../resources/org/onap/ccsdk/default.properties | 102 -- .../src/test/resources/test | 30 - .../src/test/resources/test-invalid.json | 29 - .../src/test/resources/test-sls.json | 35 - .../src/test/resources/test.json | 30 - .../src/test/resources/test.sls | 30 - .../src/test/resources/test.txt | 30 - .../APPC_saltstack-adapter-1.0-exe-nonSLS.json | 203 ---- .../APPC_saltstack-adapter-1.0-exe-nonSLS.xml | 50 - .../APPC_saltstack-adapter-1.0-exec-SLSFile.json | 350 ------- .../APPC_saltstack-adapter-1.0-exec-SLSFile.xml | 112 --- .../APPC_saltstack-adapter-1.0-exec-multi-sls.json | 399 -------- .../APPC_saltstack-adapter-1.0-exec-multi-sls.xml | 129 --- ..._saltstack-adapter-1.0-exec-single-SLSComm.json | 203 ---- ...C_saltstack-adapter-1.0-exec-single-SLSComm.xml | 51 - .../APPC_saltstack-adapter-1.0 IDEAL.json | 214 ---- .../APPC_saltstack-adapter-1.0 IDEAL.xml | 52 - ...PPC_saltstack-adapter-1.0-exec-SLS-applyTo.json | 372 ------- ...APPC_saltstack-adapter-1.0-exec-SLS-applyTo.xml | 112 --- .../APPC_saltstack-adapter-1.0-SLSFILE.json | 214 ---- .../APPC_saltstack-adapter-1.0-SLSFILE.xml | 48 - ...saltstack-adapter-1.0-exec-SLSFile-applyTo.json | 372 ------- ..._saltstack-adapter-1.0-exec-SLSFile-applyTo.xml | 112 --- adaptors/saltstack-adaptor/.pydevproject | 5 + adaptors/saltstack-adaptor/README.md | 137 +++ adaptors/saltstack-adaptor/pom.xml | 197 ++++ .../saltstack-adaptor-installer/pom.xml | 164 +++ .../src/assembly/assemble_installer_zip.xml | 61 ++ .../src/assembly/assemble_mvnrepo_zip.xml | 50 + .../src/main/resources/scripts/install-feature.sh | 42 + .../saltstack-adaptor-provider/.gitignore | 25 + .../saltstack-adaptor-provider/pom.xml | 115 +++ .../sli/adaptors/saltstack/SaltstackAdaptor.java | 59 ++ .../SaltstackAdaptorPropertiesProvider.java | 32 + .../adaptors/saltstack/impl/ConnectionBuilder.java | 172 ++++ .../saltstack/impl/SaltstackAdaptorImpl.java | 446 +++++++++ .../SaltstackAdaptorPropertiesProviderImpl.java | 192 ++++ .../sli/adaptors/saltstack/impl/SshConnection.java | 217 ++++ .../sli/adaptors/saltstack/model/Constants.java | 93 ++ .../sli/adaptors/saltstack/model/JsonParser.java | 89 ++ .../saltstack/model/SaltstackMessageParser.java | 412 ++++++++ .../adaptors/saltstack/model/SaltstackResult.java | 102 ++ .../saltstack/model/SaltstackResultCodes.java | 100 ++ .../saltstack/model/SaltstackServerEmulator.java | 93 ++ .../sli/adaptors/saltstack/model/SshException.java | 37 + .../blueprint/saltstack-adaptor-blueprint.xml | 42 + .../main/resources/saltstack-adaptor.properties | 43 + .../saltstack/impl/TestConnectionBuilder.java | 184 ++++ .../saltstack/impl/TestSaltstackAdaptorImpl.java | 1051 ++++++++++++++++++++ ...TestSaltstackAdaptorPropertiesProviderImpl.java | 310 ++++++ .../adaptors/saltstack/model/TestJsonParser.java | 76 ++ .../src/test/resources/config.sls | 2 + .../resources/org/onap/ccsdk/default.properties | 102 ++ .../src/test/resources/test | 30 + .../src/test/resources/test-invalid.json | 29 + .../src/test/resources/test-sls.json | 35 + .../src/test/resources/test.json | 30 + .../src/test/resources/test.sls | 30 + .../src/test/resources/test.txt | 30 + .../APPC_saltstack-adaptor-1.0-exe-nonSLS.json | 203 ++++ .../APPC_saltstack-adaptor-1.0-exe-nonSLS.xml | 50 + .../APPC_saltstack-adaptor-1.0-exec-SLSFile.json | 350 +++++++ .../APPC_saltstack-adaptor-1.0-exec-SLSFile.xml | 112 +++ .../APPC_saltstack-adaptor-1.0-exec-multi-sls.json | 399 ++++++++ .../APPC_saltstack-adaptor-1.0-exec-multi-sls.xml | 129 +++ ..._saltstack-adaptor-1.0-exec-single-SLSComm.json | 203 ++++ ...C_saltstack-adaptor-1.0-exec-single-SLSComm.xml | 51 + .../APPC_saltstack-adaptor-1.0 IDEAL.json | 214 ++++ .../APPC_saltstack-adaptor-1.0 IDEAL.xml | 52 + ...PPC_saltstack-adaptor-1.0-exec-SLS-applyTo.json | 372 +++++++ ...APPC_saltstack-adaptor-1.0-exec-SLS-applyTo.xml | 112 +++ .../APPC_saltstack-adaptor-1.0-SLSFILE.json | 214 ++++ .../APPC_saltstack-adaptor-1.0-SLSFILE.xml | 48 + ...saltstack-adaptor-1.0-exec-SLSFile-applyTo.json | 372 +++++++ ..._saltstack-adaptor-1.0-exec-SLSFile-applyTo.xml | 112 +++ 182 files changed, 12373 insertions(+), 12373 deletions(-) delete mode 100644 adaptors/ansible-adapter/.pydevproject delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/.gitignore delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/pom.xml delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapter.java delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapterConstants.java delete mode 100755 adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapterPropertiesProvider.java delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdapterImpl.java delete mode 100755 adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdapterPropertiesProviderImpl.java delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/ConnectionBuilder.java delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleMessageParser.java delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResult.java delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResultCodes.java delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleServerEmulator.java delete mode 100755 adaptors/ansible-adapter/ansible-adapter-bundle/src/main/resources/OSGI-INF/blueprint/ansible-adapter-blueprint.xml delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/main/resources/ansible-adapter.properties delete mode 100755 adaptors/ansible-adapter/ansible-adapter-bundle/src/main/resources/org/opendaylight/blueprint/ansible-adapter-blueprint.xml delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestAnsibleAdapterImpl.java delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestAnsibleAdapterPropertiesProviderImpl.java delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestConnectionBuilder.java delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/model/TestAnsibleAdapter.java delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/model/TestAnsibleMessageParser.java delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/model/TestAnsibleResult.java delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/test/ExecutorHarness.java delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/test/InterceptLogger.java delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/cert delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/org/onap/appc/asdc-client-cert.crt delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/org/onap/appc/asdc-client.jks delete mode 100644 adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/properties/ansible-adapter-test.properties delete mode 100644 adaptors/ansible-adapter/ansible-adapter-installer/pom.xml delete mode 100644 adaptors/ansible-adapter/ansible-adapter-installer/src/assembly/assemble_installer_zip.xml delete mode 100644 adaptors/ansible-adapter/ansible-adapter-installer/src/assembly/assemble_mvnrepo_zip.xml delete mode 100644 adaptors/ansible-adapter/ansible-adapter-installer/src/main/resources/scripts/install-feature.sh delete mode 100644 adaptors/ansible-adapter/pom.xml create mode 100644 adaptors/ansible-adaptor/.pydevproject create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/.gitignore create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/pom.xml create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdaptor.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdaptorConstants.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdaptorPropertiesProvider.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdaptorImpl.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdaptorPropertiesProviderImpl.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/ConnectionBuilder.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleMessageParser.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResult.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResultCodes.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleServerEmulator.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/resources/OSGI-INF/blueprint/ansible-adaptor-blueprint.xml create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/resources/ansible-adaptor.properties create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/resources/org/opendaylight/blueprint/ansible-adaptor-blueprint.xml create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/impl/TestAnsibleAdaptorImpl.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/impl/TestAnsibleAdaptorPropertiesProviderImpl.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/impl/TestConnectionBuilder.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/model/TestAnsibleAdaptor.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/model/TestAnsibleMessageParser.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/model/TestAnsibleResult.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/test/ExecutorHarness.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/test/InterceptLogger.java create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/cert create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/org/onap/appc/asdc-client-cert.crt create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/org/onap/appc/asdc-client.jks create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/properties/ansible-adaptor-test.properties create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-installer/pom.xml create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-installer/src/assembly/assemble_installer_zip.xml create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-installer/src/assembly/assemble_mvnrepo_zip.xml create mode 100644 adaptors/ansible-adaptor/ansible-adaptor-installer/src/main/resources/scripts/install-feature.sh create mode 100644 adaptors/ansible-adaptor/pom.xml delete mode 100644 adaptors/features/ccsdk-ansible-adapter/pom.xml create mode 100644 adaptors/features/ccsdk-ansible-adaptor/pom.xml delete mode 100644 adaptors/features/ccsdk-saltstack-adapter/pom.xml create mode 100644 adaptors/features/ccsdk-saltstack-adaptor/pom.xml delete mode 100644 adaptors/saltstack-adapter/.pydevproject delete mode 100644 adaptors/saltstack-adapter/README.md delete mode 100644 adaptors/saltstack-adapter/pom.xml delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-installer/pom.xml delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-installer/src/assembly/assemble_installer_zip.xml delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-installer/src/assembly/assemble_mvnrepo_zip.xml delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-installer/src/main/resources/scripts/install-feature.sh delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/.gitignore delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/pom.xml delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdapter.java delete mode 100755 adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdapterPropertiesProvider.java delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/ConnectionBuilder.java delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterImpl.java delete mode 100755 adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterPropertiesProviderImpl.java delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/Constants.java delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/JsonParser.java delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackMessageParser.java delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResult.java delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResultCodes.java delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackServerEmulator.java delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SshException.java delete mode 100755 adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/resources/org/opendaylight/blueprint/saltstack-adapter-blueprint.xml delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/resources/saltstack-adapter.properties delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestConnectionBuilder.java delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestSaltstackAdapterImpl.java delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestSaltstackAdapterPropertiesProviderImpl.java delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/model/TestJsonParser.java delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/config.sls delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/org/onap/ccsdk/default.properties delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test-invalid.json delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test-sls.json delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test.json delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test.sls delete mode 100644 adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test.txt delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exe-nonSLS.json delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exe-nonSLS.xml delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-SLSFile.json delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-SLSFile.xml delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-multi-sls.json delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-multi-sls.xml delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-single-SLSComm.json delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-single-SLSComm.xml delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0 IDEAL.json delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0 IDEAL.xml delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0-exec-SLS-applyTo.json delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0-exec-SLS-applyTo.xml delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-SLSFILE.json delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-SLSFILE.xml delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-exec-SLSFile-applyTo.json delete mode 100644 adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-exec-SLSFile-applyTo.xml create mode 100644 adaptors/saltstack-adaptor/.pydevproject create mode 100644 adaptors/saltstack-adaptor/README.md create mode 100644 adaptors/saltstack-adaptor/pom.xml create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-installer/pom.xml create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-installer/src/assembly/assemble_installer_zip.xml create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-installer/src/assembly/assemble_mvnrepo_zip.xml create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-installer/src/main/resources/scripts/install-feature.sh create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/.gitignore create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/pom.xml create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdaptor.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdaptorPropertiesProvider.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/ConnectionBuilder.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdaptorImpl.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdaptorPropertiesProviderImpl.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/Constants.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/JsonParser.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackMessageParser.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResult.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResultCodes.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackServerEmulator.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SshException.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/resources/org/opendaylight/blueprint/saltstack-adaptor-blueprint.xml create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/resources/saltstack-adaptor.properties create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestConnectionBuilder.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSaltstackAdaptorImpl.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSaltstackAdaptorPropertiesProviderImpl.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/model/TestJsonParser.java create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/config.sls create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/org/onap/ccsdk/default.properties create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test-invalid.json create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test-sls.json create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test.json create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test.sls create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test.txt create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exe-nonSLS.json create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exe-nonSLS.xml create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-SLSFile.json create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-SLSFile.xml create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-multi-sls.json create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-multi-sls.xml create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-single-SLSComm.json create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-single-SLSComm.xml create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0 IDEAL.json create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0 IDEAL.xml create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0-exec-SLS-applyTo.json create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0-exec-SLS-applyTo.xml create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-SLSFILE.json create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-SLSFILE.xml create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-exec-SLSFile-applyTo.json create mode 100644 adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-exec-SLSFile-applyTo.xml (limited to 'adaptors') diff --git a/adaptors/ansible-adapter/.pydevproject b/adaptors/ansible-adapter/.pydevproject deleted file mode 100644 index d001f0aea..000000000 --- a/adaptors/ansible-adapter/.pydevproject +++ /dev/null @@ -1,5 +0,0 @@ - - -Default -python interpreter - diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/.gitignore b/adaptors/ansible-adapter/ansible-adapter-bundle/.gitignore deleted file mode 100644 index 255b54097..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -# ============LICENSE_START========================================== -# ONAP : APPC -# =================================================================== -# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. -# =================================================================== -# -# Unless otherwise specified, all software contained herein is licensed -# under the Apache License, Version 2.0 (the License); -# you may not use this software 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. -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. -# ============LICENSE_END============================================ -/bin/ -/target/ -/target-ide/ -/.settings/ diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/pom.xml b/adaptors/ansible-adapter/ansible-adapter-bundle/pom.xml deleted file mode 100644 index 192bcec05..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/pom.xml +++ /dev/null @@ -1,123 +0,0 @@ - - - - - 4.0.0 - - - org.onap.ccsdk.parent - binding-parent - 2.2.0-SNAPSHOT - - - - org.onap.ccsdk.sli.adaptors - ansible-adapter-bundle - 1.3.0-SNAPSHOT - bundle - - ccsdk-sli-adaptors :: ${project.artifactId} - - - - - org.onap.ccsdk.sli.core - sli-core-artifacts - ${project.version} - pom - import - - - - - - com.att.eelf - eelf-core - - - commons-codec - commons-codec - - - commons-logging - commons-logging - - - org.apache.httpcomponents - httpclient - - - org.onap.ccsdk.sli.core - sli-common - - - org.onap.ccsdk.sli.core - sli-provider - - - org.osgi - org.osgi.core - - - org.slf4j - slf4j-api - - - org.slf4j - jcl-over-slf4j - - - org.json - json - - - com.google.guava - guava - - - - org.glassfish.jersey.core - jersey-common - test - - - org.codehaus.jackson - jackson-jaxrs - test - - - junit - junit - test - - - - org.mockito - mockito-core - 1.10.19 - test - - - org.powermock - powermock-reflect - test - - - org.powermock - powermock-api-mockito2 - test - - - diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapter.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapter.java deleted file mode 100644 index 65f80a1c2..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapter.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.ansible; - -import java.util.Map; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -/** - * This interface defines the operations that the Ansible adapter exposes. - */ -public interface AnsibleAdapter extends SvcLogicJavaPlugin { - /** - * Returns the symbolic name of the adapter - * - * @return The adapter name - */ - String getAdapterName(); - - /* Method to post request for execution of Playbook */ - void reqExec(Map params, SvcLogicContext ctx) throws SvcLogicException; - - /* Method to get result of a playbook execution request */ - void reqExecResult(Map params, SvcLogicContext ctx) throws SvcLogicException; - - /* Method to get log of a playbook execution request */ - void reqExecLog(Map params, SvcLogicContext ctx) throws SvcLogicException; - - /* Method to get output of a playbook execution request */ - void reqExecOutput(Map params, SvcLogicContext ctx) throws SvcLogicException; - -} diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapterConstants.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapterConstants.java deleted file mode 100644 index 20a8400bb..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapterConstants.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.onap.ccsdk.sli.adaptors.ansible; - -public class AnsibleAdapterConstants { - - public static final String ID = "Id"; - public static final String USER = "User"; - public static final String PSWD = "Password"; - public static final String SERVERIP = "ServerIP"; - public static final String AGENT_URL = "AgentUrl"; - public static final String NODE_LIST = "NodeList"; - public static final String ANSIBLE_SERVER = "AnsibleServer"; - - public static final String APPC_PROPS = "/appc.properties"; - public static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; - public static final String PROPDIR = System.getenv(SDNC_CONFIG_DIR); - - public static final String ACTION = "Action"; - public static final String OUTPUT = "Output"; - public static final String TIMEOUT = "Timeout"; - public static final String VERSION = "Version"; - - public static final String FAILURE = "failure"; - public static final String SUCCESS = "success"; - public static final String STATUS_CODE = "StatusCode"; - public static final String STATUS_MESSAGE = "StatusMessage"; - - public static final String EXTRA_VARS = "ExtraVars"; - public static final String PLAYBOOK_NAME = "PlaybookName"; - public static final String AUTO_NODE_LIST = "AutoNodeList"; - public static final String ENV_PARAMETERS = "EnvParameters"; - public static final String FILE_PARAMETERS = "FileParameters"; - public static final String INVENTORY_NAMES = "InventoryNames"; - public static final String LOCAL_PARAMETERS = "LocalParameters"; - - public static final String ID_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.Id"; - public static final String LOG_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.log"; - public static final String OUTPUT_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.output"; - public static final String TIMEOUT_PROPERTY_NAME = "org.onap.appc.adapter.ansible.timeout"; - public static final String MESSAGE_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.message"; - public static final String RESULTS_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.results"; - public static final String RESULT_CODE_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.result.code"; - - public static final String TRUSTSTORE_PROPERTY_NAME = "org.onap.appc.adapter.ansible.trustStore"; - public static final String CLIENT_TYPE_PROPERTY_NAME = "org.onap.appc.adapter.ansible.clientType"; - public static final String POLL_INTERVAL_PROPERTY_NAME = "org.onap.appc.adapter.ansible.pollInterval"; - public static final String SOCKET_TIMEOUT_PROPERTY_NAME = "org.onap.appc.adapter.ansible.socketTimeout"; - public static final String TRUSTSTORE_PASS_PROPERTY_NAME = "org.onap.appc.adapter.ansible.trustStore.trustPasswd"; - - -} diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapterPropertiesProvider.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapterPropertiesProvider.java deleted file mode 100755 index 671b1e488..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapterPropertiesProvider.java +++ /dev/null @@ -1,31 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.ansible; - -import java.util.Properties; - -public interface AnsibleAdapterPropertiesProvider { - - Properties getProperties(); - -} diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdapterImpl.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdapterImpl.java deleted file mode 100644 index bc0af2782..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdapterImpl.java +++ /dev/null @@ -1,620 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.ansible.impl; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import org.apache.commons.lang.StringUtils; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdapter; -import org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdapterPropertiesProvider; -import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleMessageParser; -import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResult; -import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResultCodes; -import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleServerEmulator; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.utils.encryption.EncryptionTool; - -import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdapterConstants.*; - -/** - * This class implements the {@link AnsibleAdapter} interface. This interface defines the behaviors - * that our service provides. - */ -public class AnsibleAdapterImpl implements AnsibleAdapter { - - /** - * Adapter Name - */ - private static final String ADAPTER_NAME = "Ansible Adapter"; - private static final String APPC_EXCEPTION_CAUGHT = "APPCException caught"; - - /** - * The logger to be used - */ - private static final EELFLogger logger = EELFManager.getInstance().getLogger(AnsibleAdapterImpl.class); - private int defaultTimeout = 600 * 1000; - private int defaultSocketTimeout = 60 * 1000; - private int defaultPollInterval = 60 * 1000; - /** - * Ansible API Message Handlers - **/ - private AnsibleMessageParser messageProcessor; - - /** - * indicator whether in test mode - **/ - private boolean testMode = false; - - /** - * server emulator object to be used if in test mode - **/ - private AnsibleServerEmulator testServer; - - /** - * This default constructor is used as a work around because the activator wasn't getting called - */ - public AnsibleAdapterImpl() { - initialize(new AnsibleAdapterPropertiesProviderImpl()); - } - - /** - * Instantiates a new Ansible adapter. - * - * @param propProvider the prop provider - */ - public AnsibleAdapterImpl(AnsibleAdapterPropertiesProvider propProvider) { - initialize(propProvider); - } - - /** - * Used for jUnit test and testing interface - * - * @param mode the mode - */ - public AnsibleAdapterImpl(boolean mode) { - testMode = mode; - testServer = new AnsibleServerEmulator(); - messageProcessor = new AnsibleMessageParser(); - } - - /** - * Returns the symbolic name of the adapter - * - * @return The adapter name - */ - @Override - public String getAdapterName() { - return ADAPTER_NAME; - } - - @SuppressWarnings("static-method") - private void doFailure(SvcLogicContext svcLogic, int code, String message) throws SvcLogicException { - svcLogic.markFailed(); - svcLogic.setAttribute(RESULT_CODE_ATTRIBUTE_NAME, Integer.toString(code)); - svcLogic.setAttribute(MESSAGE_ATTRIBUTE_NAME, message); - throw new SvcLogicException("Ansible Adapter Error = " + message); - } - - /** - * initialize the Ansible adapter based on default and over-ride configuration data - */ - private void initialize(AnsibleAdapterPropertiesProvider propProvider) { - Properties props = propProvider.getProperties(); - // Create the message processor instance - messageProcessor = new AnsibleMessageParser(); - - //continuing for checking defaultTimeout - try { - String timeoutStr = props.getProperty(TIMEOUT_PROPERTY_NAME); - defaultTimeout = Integer.parseInt(timeoutStr) * 1000; - } catch (Exception e) { - defaultTimeout = 600 * 1000; - logger.error("Error while reading time out property", e); - } - //continuing for checking defaultSocketTimeout - try { - String timeoutStr = props.getProperty(SOCKET_TIMEOUT_PROPERTY_NAME); - defaultSocketTimeout = Integer.parseInt(timeoutStr) * 1000; - } catch (Exception e) { - defaultSocketTimeout = 60 * 1000; - logger.error("Error while reading socket time out property", e); - } - //continuing for checking defaultPollInterval - try { - String timeoutStr = props.getProperty(POLL_INTERVAL_PROPERTY_NAME); - defaultPollInterval = Integer.parseInt(timeoutStr) * 1000; - } catch (Exception e) { - defaultPollInterval = 60 * 1000; - logger.error("Error while reading poll interval property", e); - } - logger.info("Initialized Ansible Adapter"); - } - - private ConnectionBuilder getHttpConn(int timeout, String serverIP) { - String path = PROPDIR + APPC_PROPS; - File propFile = new File(path); - Properties props = new Properties(); - InputStream input; - try { - input = new FileInputStream(propFile); - props.load(input); - } catch (Exception ex) { - logger.error("Error while reading appc.properties file {}", ex.getMessage()); - } - // Create the http client instance - // type of client is extracted from the property file parameter - // org.onap.appc.adapter.ansible.clientType - // It can be : - // 1. TRUST_ALL (trust all SSL certs). To be used ONLY in dev - // 2. TRUST_CERT (trust only those whose certificates have been stored in the trustStore file) - // 3. DEFAULT (trust only well known certificates). This is standard behavior to which it will - // revert. To be used in PROD - ConnectionBuilder httpClientLocal = null; - try { - String clientType = props.getProperty(CLIENT_TYPE_PROPERTY_NAME); - logger.info("Ansible http client type set to {}", clientType); - if ("TRUST_ALL".equals(clientType)) { - logger.info("Creating http client to trust ALL ssl certificates. WARNING. This should be done only in dev environments"); - httpClientLocal = new ConnectionBuilder(1, timeout); - } else if ("TRUST_CERT".equals(clientType)) { - // set path to keystore file - String trustStoreFile = props.getProperty(TRUSTSTORE_PROPERTY_NAME); - String key = props.getProperty(TRUSTSTORE_PASS_PROPERTY_NAME); - char[] trustStorePasswd = EncryptionTool.getInstance().decrypt(key).toCharArray(); - logger.info("Creating http client with trust manager from {}", trustStoreFile); - httpClientLocal = new ConnectionBuilder(trustStoreFile, trustStorePasswd, timeout, serverIP); - } else { - logger.info("Creating http client with default behaviour"); - httpClientLocal = new ConnectionBuilder(0, timeout); - } - } catch (Exception e) { - logger.error("Error Getting HTTP Connection Builder due to Unknown Exception", e); - } - - logger.info("Got HTTP Connection Builder"); - return httpClientLocal; - } - - // Public Method to post request to execute playbook. Posts the following back - // to Svc context memory - // org.onap.appc.adapter.ansible.req.code : 100 if successful - // org.onap.appc.adapter.ansible.req.messge : any message - // org.onap.appc.adapter.ansible.req.Id : a unique uuid to reference the request - @Override - public void reqExec(Map params, SvcLogicContext ctx) throws SvcLogicException { - String playbookName = StringUtils.EMPTY; - String payload = StringUtils.EMPTY; - String agentUrl = StringUtils.EMPTY; - String user = StringUtils.EMPTY; - String pswd = StringUtils.EMPTY; - String id = StringUtils.EMPTY; - - try { - // create json object to send request - JSONObject jsonPayload = messageProcessor.reqMessage(params); - logger.info("Initial Payload = {}", jsonPayload.toString()); - - agentUrl = (String) jsonPayload.remove("AgentUrl"); - id = jsonPayload.getString("Id"); - user = (String) jsonPayload.remove(USER); - pswd = (String) jsonPayload.remove(PSWD); - if (StringUtils.isNotBlank(pswd)) { - pswd = EncryptionTool.getInstance().decrypt(pswd); - } - String timeout = jsonPayload.getString("Timeout"); - if (StringUtils.isBlank(timeout)) { - timeout = "600"; - } - - String autoNodeList = (String) jsonPayload.remove("AutoNodeList"); - if (Boolean.parseBoolean(autoNodeList)) { - JSONArray generatedNodeList = generateNodeList(params, ctx); - if (generatedNodeList.length() > 0) { - jsonPayload.put("NodeList", generatedNodeList); - jsonPayload.put("InventoryNames", "VM"); - } else { - doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), - "Auto generation of Node List Failed - no elements on the list"); - } - } else { - logger.debug("Auto Node List is DISABLED"); - } - - payload = jsonPayload.toString(); - ctx.setAttribute("AnsibleTimeout", timeout); - logger.info("Updated Payload = {} timeout = {}", payload, timeout); - } catch (SvcLogicException e) { - logger.error(APPC_EXCEPTION_CAUGHT, e); - doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), - "Error constructing request for execution of playbook due to missing mandatory parameters. Reason = " - + e.getMessage()); - } catch (JSONException e) { - logger.error("JSONException caught", e); - doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), - "Error constructing request for execution of playbook due to invalid JSON block. Reason = " - + e.getMessage()); - } catch (NumberFormatException e) { - logger.error("NumberFormatException caught", e); - doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), - "Error constructing request for execution of playbook due to invalid parameter values. Reason = " - + e.getMessage()); - } - - int code = -1; - String message = StringUtils.EMPTY; - - try { - // post the test request - logger.info("Posting ansible request = {} to url = {}", payload, agentUrl); - AnsibleResult testResult = postExecRequest(agentUrl, payload, user, pswd); - if (testResult != null) { - logger.info("Received response on ansible post request {}", testResult.getStatusMessage()); - // Process if HTTP was successful - if (testResult.getStatusCode() == 200) { - testResult = messageProcessor.parsePostResponse(testResult.getStatusMessage()); - } else { - doFailure(ctx, testResult.getStatusCode(), - "Error posting request. Reason = " + testResult.getStatusMessage()); - } - - code = testResult.getStatusCode(); - message = testResult.getStatusMessage(); - ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, testResult.getOutput()); - ctx.setAttribute(SERVERIP, StringUtils.defaultIfBlank(testResult.getServerIp(), "")); - // Check status of test request returned by Agent - if (code == AnsibleResultCodes.PENDING.getValue()) { - logger.info("Submission of Test {} successful.", playbookName); - // test request accepted. We are in asynchronous case - } else { - doFailure(ctx, code, "Request for execution of playbook rejected. Reason = " + message); - } - } else { - doFailure(ctx, code, "Ansible Test result is null"); - } - } catch (SvcLogicException e) { - logger.error(APPC_EXCEPTION_CAUGHT, e); - doFailure(ctx, AnsibleResultCodes.UNKNOWN_EXCEPTION.getValue(), - "Exception encountered when posting request for execution of playbook. Reason = " + e.getMessage()); - } - - ctx.setAttribute(RESULT_CODE_ATTRIBUTE_NAME, Integer.toString(code)); - ctx.setAttribute(MESSAGE_ATTRIBUTE_NAME, message); - ctx.setAttribute(ID_ATTRIBUTE_NAME, id); - } - - /** - * Method is used to automatically generate NodeList section base on the svc context - */ - private JSONArray generateNodeList(Map params, SvcLogicContext ctx) throws SvcLogicException { - String vfModuleId = StringUtils.trimToNull(params.get("vf-module-id")); - String vnfcName = StringUtils.trimToNull(params.get("vnfc-name")); - String vServerId = StringUtils.trimToNull(params.get("vserver-id")); - String vnfcType = StringUtils.trimToNull(params.get("vnfc-type")); - - JSONArray result = new JSONArray(); - logger.info("GENERATING NODE LIST"); - logger.debug("Auto Node List filtering parameter vserver-id {} | vnfc-name {} | vnfc-type {} | vf-module-id {}", - vServerId, vnfcName, vnfcType, vfModuleId); - - Map candidates = new HashMap<>(); - for (int i = 0; ; i++) { - String vmKey = "tmp.vnfInfo.vm[" + i + "]"; - logger.info("Looking for attributes of: {}", vmKey); - if (ctx.getAttribute(vmKey + ".vnfc-name") != null) { - String debugText = "Auto Node List candidate "; - String vmVnfcName = ctx.getAttribute(vmKey + ".vnfc-name"); - String vmVnfcIpv4Address = ctx.getAttribute(vmKey + ".vnfc-ipaddress-v4-oam-vip"); - String vmVnfcType = ctx.getAttribute(vmKey + ".vnfc-type"); - - if (vmVnfcName != null && vmVnfcIpv4Address != null && vmVnfcType != null - && !vmVnfcName.equals("") && !vmVnfcIpv4Address.equals("") && !vmVnfcType.equals("")) { - if (vServerId != null) { - String vmVserverId = ctx.getAttribute(vmKey + ".vserver-id"); - if (!vServerId.equals(vmVserverId)) { - logger.debug("{}{} dropped. vserver-id mismatch", debugText, vmVnfcName); - continue; - } - } - if (vfModuleId != null) { - String vmVfModuleId = ctx.getAttribute(vmKey + ".vf-module-id"); - if (!vfModuleId.equals(vmVfModuleId)) { - logger.debug("{}{} dropped. vf-module-id mismatch", debugText, vmVnfcName); - continue; - } - } - if (vnfcName != null && !vmVnfcName.equals(vnfcName)) { - logger.debug("{}{} dropped. vnfc-name mismatch", debugText, vmVnfcName); - continue; - } - if (vnfcType != null && !vmVnfcType.equals(vnfcType)) { - logger.debug("{}{} dropped. vnfc-type mismatch", debugText, vmVnfcType); - continue; - } - - logger.info("{}{} [{},{}]", debugText, vmVnfcName, vmVnfcIpv4Address, vmVnfcType); - - JSONObject vnfTypeCandidates; - JSONArray vmList; - if (!candidates.containsKey(vmVnfcType)) { - vnfTypeCandidates = new JSONObject(); - vmList = new JSONArray(); - vnfTypeCandidates.put("site", "site"); - vnfTypeCandidates.put("vnfc-type", vmVnfcType); - vnfTypeCandidates.put("vm-info", vmList); - candidates.put(vmVnfcType, vnfTypeCandidates); - } else { - vnfTypeCandidates = candidates.get(vmVnfcType); - vmList = (JSONArray) vnfTypeCandidates.get("vm-info"); - } - - JSONObject candidate = new JSONObject(); - candidate.put("ne_id", vmVnfcName); - candidate.put("fixed_ip_address", vmVnfcIpv4Address); - vmList.put(candidate); - } else { - logger.warn("Incomplete information for Auto Node List candidate {}", vmKey); - } - } else { - break; - } - } - - for (JSONObject vnfcCandidates : candidates.values()) { - result.put(vnfcCandidates); - } - - logger.info("GENERATING NODE LIST COMPLETED"); - return result; - } - - /** - * Public method to query status of a specific request It blocks till the Ansible Server - * responds or the session times out (non-Javadoc) - * - * @see org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdapter#reqExecResult(java.util.Map, - * org.onap.ccsdk.sli.core.sli.SvcLogicContext) - */ - @Override - public void reqExecResult(Map params, SvcLogicContext ctx) throws SvcLogicException { - // Get URI - String reqUri; - - try { - String serverIp = ctx.getAttribute(SERVERIP); - if (StringUtils.isNotBlank(serverIp)) { - reqUri = messageProcessor.reqUriResultWithIP(params, serverIp); - } else { - reqUri = messageProcessor.reqUriResult(params); - } - logger.info("Got uri {}", reqUri); - } catch (SvcLogicException e) { - logger.error(APPC_EXCEPTION_CAUGHT, e); - doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), - "Error constructing request to retrieve result due to missing parameters. Reason = " - + e.getMessage()); - return; - } catch (NumberFormatException e) { - logger.error("NumberFormatException caught", e); - doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), - "Error constructing request to retrieve result due to invalid parameters value. Reason = " - + e.getMessage()); - return; - } - - int code; - String message; - String output; - String configData; - String results = StringUtils.EMPTY; - String finalResponse = StringUtils.EMPTY; - try { - // Try to retrieve the test results (modify the URL for that) - AnsibleResult testResult = queryServer(reqUri, params.get(USER), - EncryptionTool.getInstance().decrypt(params.get(PSWD)), ctx); - code = testResult.getStatusCode(); - message = testResult.getStatusMessage(); - - if (code == 200 || code == 400 || "FINISHED".equalsIgnoreCase(message)) { - logger.info("Parsing response from ansible Server = {}", message); - // Valid HTTP. process the Ansible message - testResult = messageProcessor.parseGetResponse(message); - code = testResult.getStatusCode(); - message = testResult.getStatusMessage(); - results = testResult.getResults(); - output = testResult.getOutput(); - configData = testResult.getConfigData(); - if ((StringUtils.isBlank(output)) || (output.trim().equalsIgnoreCase("{}"))) { - finalResponse = results; - } else { - finalResponse = output; - } - logger.info("configData from ansible's response = {}", configData); - ctx.setAttribute("device-running-config", configData); - } - logger.info("Request response = " + message); - } catch (SvcLogicException e) { - logger.error(APPC_EXCEPTION_CAUGHT, e); - ctx.setAttribute(RESULTS_ATTRIBUTE_NAME, results); - ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, finalResponse); - doFailure(ctx, AnsibleResultCodes.UNKNOWN_EXCEPTION.getValue(), - "Exception encountered retrieving result : " + e.getMessage()); - return; - } - - // We were able to get and process the results. Determine if playbook succeeded - - if (code == AnsibleResultCodes.FINAL_SUCCESS.getValue()) { - message = String.format("Ansible Request %s finished with Result = %s, Message = %s", params.get("Id"), - SUCCESS, message); - logger.info(message); - } else { - logger.info(String.format("Ansible Request %s finished with Result %s, Message = %s", params.get("Id"), - FAILURE, message)); - ctx.setAttribute(RESULTS_ATTRIBUTE_NAME, results); - ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, finalResponse); - doFailure(ctx, code, message); - return; - } - - // In case of 200, 400, FINISHED return 400 - ctx.setAttribute(RESULT_CODE_ATTRIBUTE_NAME, Integer.toString(400)); - ctx.setAttribute(MESSAGE_ATTRIBUTE_NAME, message); - ctx.setAttribute(RESULTS_ATTRIBUTE_NAME, results); - ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, finalResponse); - ctx.markSuccess(); - } - - /** - * Public method to get logs from playbook execution for a specific request - *

- * It blocks till the Ansible Server responds or the session times out very similar to - * reqExecResult logs are returned in the DG context variable org.onap.appc.adapter.ansible.log - */ - @Override - public void reqExecLog(Map params, SvcLogicContext ctx) throws SvcLogicException { - String reqUri = StringUtils.EMPTY; - try { - reqUri = messageProcessor.reqUriLog(params); - logger.info("Retrieving results from {}", reqUri); - } catch (Exception e) { - logger.error("Exception caught", e); - doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), e.getMessage()); - } - - queryServerAndProcessResult(params, ctx, reqUri, LOG_ATTRIBUTE_NAME); - } - - /** - * Public method to get output from playbook execution for a specific request - *

- * It blocks till the Ansible Server responds or the session times out very similar to - * reqExecResult and output is returned in the DG context variable org.onap.appc.adapter.ansible.output - */ - @Override - public void reqExecOutput(Map params, SvcLogicContext ctx) throws SvcLogicException { - String reqUri = StringUtils.EMPTY; - try { - reqUri = messageProcessor.reqUriOutput(params); - logger.info("Retrieving results from {}", reqUri); - } catch (Exception e) { - logger.error("Exception caught", e); - doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), e.getMessage()); - } - - queryServerAndProcessResult(params, ctx, reqUri, OUTPUT_ATTRIBUTE_NAME); - } - - /** - * Method that posts the request - */ - private AnsibleResult postExecRequest(String agentUrl, String payload, String user, String pswd) { - AnsibleResult testResult = null; - ConnectionBuilder httpClientLocal = getHttpConn(defaultSocketTimeout, ""); - if (!testMode) { - if (httpClientLocal != null) { - httpClientLocal.setHttpContext(user, pswd); - testResult = httpClientLocal.post(agentUrl, payload); - httpClientLocal.close(); - } - } else { - testResult = testServer.post(payload); - } - return testResult; - } - - private void queryServerAndProcessResult(Map params, SvcLogicContext ctx, String reqUri, String attributeName) - throws SvcLogicException { - try { - // Try to retrieve the test results (modify the url for that) - AnsibleResult testResult = queryServer(reqUri, params.get(USER), - EncryptionTool.getInstance().decrypt(params.get(PSWD)), ctx); - String message = testResult.getStatusMessage(); - logger.info("Request output = {}", message); - ctx.setAttribute(attributeName, message); - ctx.markSuccess(); - } catch (Exception e) { - logger.error("Exception caught: {}", e.getMessage(), e); - doFailure(ctx, AnsibleResultCodes.UNKNOWN_EXCEPTION.getValue(), - String.format("Exception encountered retrieving output: %s", e.getMessage())); - } - } - - /** - * Method to query Ansible server - */ - private AnsibleResult queryServer(String agentUrl, String user, String pswd, SvcLogicContext ctx) { - AnsibleResult testResult = new AnsibleResult(); - int timeout; - try { - timeout = Integer.parseInt(ctx.getAttribute("AnsibleTimeout")) * 1000; - } catch (Exception e) { - timeout = defaultTimeout; - } - long endTime = System.currentTimeMillis() + timeout; - - while (System.currentTimeMillis() < endTime) { - String serverIP = ctx.getAttribute(SERVERIP); - ConnectionBuilder httpClientLocal = getHttpConn(defaultSocketTimeout, serverIP); - logger.info("Querying ansible GetResult URL = {}", agentUrl); - - if (!testMode) { - if (httpClientLocal != null) { - httpClientLocal.setHttpContext(user, pswd); - testResult = httpClientLocal.get(agentUrl); - httpClientLocal.close(); - } - } else { - testResult = testServer.get(agentUrl); - } - if (testResult.getStatusCode() != AnsibleResultCodes.IO_EXCEPTION.getValue() - && testResult.getStatusCode() != AnsibleResultCodes.PENDING.getValue()) { - break; - } - - try { - Thread.sleep(defaultPollInterval); - } catch (InterruptedException ex) { - logger.error("Thread Interrupted Exception", ex); - Thread.currentThread().interrupt(); - } - - } - if (testResult.getStatusCode() == AnsibleResultCodes.PENDING.getValue()) { - testResult.setStatusCode(AnsibleResultCodes.IO_EXCEPTION.getValue()); - testResult.setStatusMessage("Request timed out"); - } - - return testResult; - } - -} diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdapterPropertiesProviderImpl.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdapterPropertiesProviderImpl.java deleted file mode 100755 index e465e1378..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdapterPropertiesProviderImpl.java +++ /dev/null @@ -1,208 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.ansible.impl; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Properties; -import org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdapterPropertiesProvider; -import org.onap.ccsdk.sli.core.sli.ConfigurationException; -import org.onap.ccsdk.sli.core.utils.JREFileResolver; -import org.onap.ccsdk.sli.core.utils.KarafRootFileResolver; -import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver; -import org.onap.ccsdk.sli.core.utils.common.CoreDefaultFileResolver; -import org.onap.ccsdk.sli.core.utils.common.EnvProperties; -import org.onap.ccsdk.sli.core.utils.common.SdncConfigEnvVarFileResolver; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Responsible for determining the properties file to use and instantiating the - * SqlResource Service. The priority for properties file - * resolution is as follows: - * - *

    - *
  1. A directory identified by the system environment variable - * SDNC_CONFIG_DIR
  2. - *
  3. The default directory DEFAULT_DBLIB_PROP_DIR
  4. - *
  5. A directory identified by the JRE argument - * sql-resource.properties
  6. - *
  7. A sql-resource.properties file located in the karaf root - * directory
  8. - *
- */ -public class AnsibleAdapterPropertiesProviderImpl implements AnsibleAdapterPropertiesProvider { - - private static final Logger LOG = LoggerFactory.getLogger(AnsibleAdapterPropertiesProviderImpl.class); - - /** - * The name of the properties file for database configuration - */ - private static final String ANSIBLE_ADAPTER_PROPERTIES = "ansible-adapter.properties"; - - /** - * A prioritized list of strategies for resolving sql-resource properties files. - */ - private final List ansibleAdapterPropertiesFileResolvers = new ArrayList<>(); - - /** - * The configuration properties for the db connection. - */ - private Properties properties; - - /** - * Set up the prioritized list of strategies for resolving dblib properties - * files. - */ - public AnsibleAdapterPropertiesProviderImpl() { - ansibleAdapterPropertiesFileResolvers - .add(new SdncConfigEnvVarFileResolver("Using property file (1) from environment variable")); - ansibleAdapterPropertiesFileResolvers - .add(new CoreDefaultFileResolver("Using property file (2) from default directory")); - ansibleAdapterPropertiesFileResolvers - .add(new JREFileResolver("Using property file (3) from JRE argument", AnsibleAdapterPropertiesProviderImpl.class)); - ansibleAdapterPropertiesFileResolvers - .add(new KarafRootFileResolver("Using property file (4) from karaf root", this)); - - // determines properties file as according to the priority described in the - // class header comment - final File propertiesFile = determinePropertiesFile(); - if (propertiesFile != null) { - try (FileInputStream fileInputStream = new FileInputStream(propertiesFile)) { - properties = new EnvProperties(); - properties.load(fileInputStream); - } catch (final IOException e) { - LOG.error("Failed to load properties for file: {}", propertiesFile, - new ConfigurationException("Failed to load properties for file: " + propertiesFile, e)); - } - } else { - // Try to read properties as resource - InputStream propStr = getClass().getResourceAsStream("/" + ANSIBLE_ADAPTER_PROPERTIES); - if (propStr != null) { - properties = new EnvProperties(); - try { - properties.load(propStr); - propStr.close(); - } catch (IOException e) { - properties = null; - } - } - } - if (properties == null) { - reportFailure(new ConfigurationException( - "Missing configuration properties resource(3): " + ANSIBLE_ADAPTER_PROPERTIES)); - LOG.info("Defaulting org.onap.appc.adapter.ansible.clientType to TRUST_ALL"); - properties = new Properties(); - properties.setProperty("org.onap.appc.adapter.ansible.clientType", "TRUST_ALL"); - } - - } - - /** - * Instantiates a new Ansible adapter properties provider. - * - * @param configFilePath the config file path - */ - public AnsibleAdapterPropertiesProviderImpl(String configFilePath) { - properties = new EnvProperties(); - try { - properties.load(new FileInputStream(configFilePath)); - } catch (IOException e) { - properties = null; - } - if (properties == null) { - reportFailure(new ConfigurationException( - "Missing configuration properties resource(3): " + ANSIBLE_ADAPTER_PROPERTIES)); - LOG.info("Defaulting org.onap.appc.adapter.ansible.clientType to TRUST_ALL"); - properties = new Properties(); - properties.setProperty("org.onap.appc.adapter.ansible.clientType", "TRUST_ALL"); - } - - } - - /** - * Reports the method chosen for properties resolution to the - * Logger. - * - * @param message Some user friendly message - * @param fileOptional The file location of the chosen properties file - * - * @return the file location of the chosen properties file - */ - private static File reportSuccess(final String message, final Optional fileOptional) { - if (fileOptional.isPresent()) { - final File file = fileOptional.get(); - LOG.info("{} {}", message, file.getPath()); - return file; - } - return null; - } - - /** - * Reports fatal errors. This is the case in which no properties file could be - * found. - * - * @param configurationException An exception describing what went wrong during resolution - */ - private static void reportFailure(final ConfigurationException configurationException) { - LOG.error("{}", "Missing configuration properties resource(3)", configurationException); - } - - /** - * Extract svclogic config properties. - * - * @return the svclogic config properties - */ - public Properties getProperties() { - return properties; - } - - /** - * Determines the sql-resource properties file to use based on the following priority: - *
    - *
  1. A directory identified by the system environment variable - * SDNC_CONFIG_DIR
  2. - *
  3. The default directory DEFAULT_DBLIB_PROP_DIR
  4. - *
  5. A directory identified by the JRE argument - * sql-resource.properties
  6. - *
  7. A sql-resource.properties file located in the karaf root - * directory
  8. - *
- */ - File determinePropertiesFile() { - for (final PropertiesFileResolver propertiesFileResolver : ansibleAdapterPropertiesFileResolvers) { - final Optional fileOptional = propertiesFileResolver.resolveFile(ANSIBLE_ADAPTER_PROPERTIES); - if (fileOptional.isPresent()) { - return reportSuccess(propertiesFileResolver.getSuccessfulResolutionMessage(), fileOptional); - } - } - - return null; - } - -} diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/ConnectionBuilder.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/ConnectionBuilder.java deleted file mode 100644 index 1fbf20633..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/ConnectionBuilder.java +++ /dev/null @@ -1,235 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.ansible.impl; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import java.io.Closeable; -import java.io.FileInputStream; -import java.io.IOException; -import java.security.KeyManagementException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import javax.net.ssl.SSLContext; -import org.apache.commons.lang.StringUtils; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.conn.ssl.NoopHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLContexts; -import org.apache.http.conn.ssl.TrustSelfSignedStrategy; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; -import org.json.JSONObject; -import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResult; -import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResultCodes; -import org.onap.ccsdk.sli.core.utils.PathValidator; - -/** - * Returns a custom http client - * - based on options - * - can create one with ssl using an X509 certificate that does NOT have a known CA - * - create one which trusts ALL SSL certificates - * - return default httpclient (which only trusts known CAs from default cacerts file for process) this is the default - * option - **/ - -public class ConnectionBuilder implements Closeable { - private static final String STATUS_CODE_KEY = "StatusCode"; - private static final EELFLogger logger = EELFManager.getInstance().getLogger(ConnectionBuilder.class); - - private final CloseableHttpClient httpClient; - private final HttpClientContext httpContext = new HttpClientContext(); - - /** - * Constructor that initializes an http client based on certificate - **/ - public ConnectionBuilder(String certFile, int timeout) throws KeyStoreException, CertificateException, IOException, - KeyManagementException, NoSuchAlgorithmException { - - /* Point to the certificate */ - try (FileInputStream fs = new FileInputStream(certFile)) { - /* Generate a certificate from the X509 */ - CertificateFactory cf = CertificateFactory.getInstance("X.509"); - X509Certificate cert = (X509Certificate) cf.generateCertificate(fs); - - /* Create a keystore object and load the certificate there */ - KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); - keystore.load(null, null); - keystore.setCertificateEntry("cacert", cert); - - SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(keystore).build(); - SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext, - SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); - - RequestConfig config = RequestConfig.custom().setSocketTimeout(timeout).build(); - httpClient = HttpClients.custom().setDefaultRequestConfig(config).setSSLSocketFactory(factory).build(); - } - } - - /** - * Constructor which trusts all certificates in a specific java keystore file (assumes a JKS - * file) - **/ - public ConnectionBuilder(String trustStoreFile, char[] trustStorePasswd, int timeout, String serverIP) - throws KeyStoreException, IOException, KeyManagementException, NoSuchAlgorithmException, - CertificateException { - if (!PathValidator.isValidFilePath(trustStoreFile)) { - throw new IOException("Invalid trust store file path"); - } - - /* Load the specified trustStore */ - KeyStore keystore = KeyStore.getInstance("JKS"); - FileInputStream readStream = new FileInputStream(trustStoreFile); - keystore.load(readStream, trustStorePasswd); - if (StringUtils.isNotBlank(serverIP)) { - SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(); - SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext, new NoopHostnameVerifier()); - - RequestConfig config = RequestConfig.custom().setSocketTimeout(timeout).build(); - httpClient = HttpClients.custom().setDefaultRequestConfig(config).setSSLSocketFactory(factory).build(); - } else { - SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(keystore).build(); - SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext, - SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); - RequestConfig config = RequestConfig.custom().setSocketTimeout(timeout).build(); - httpClient = HttpClients.custom().setDefaultRequestConfig(config).setSSLSocketFactory(factory).build(); - } - } - - /** - * Constructor that trusts ALL SSl certificates (NOTE : ONLY FOR DEV TESTING) if Mode == 1 or - * Default if Mode == 0 - */ - public ConnectionBuilder(int mode, int timeout) - throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { - RequestConfig config = RequestConfig.custom().setSocketTimeout(timeout).build(); - if (mode == 1) { - SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(); - SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext, - SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); - - httpClient = HttpClients.custom().setDefaultRequestConfig(config).setSSLSocketFactory(factory).build(); - } else { - httpClient = HttpClients.custom().setDefaultRequestConfig(config).build(); - } - } - - // Use to create an http context with auth headers - public void setHttpContext(String user, String pswd) { - - // Are credential provided ? If so, set the context to be used - if (user != null && !user.isEmpty() && pswd != null && !pswd.isEmpty()) { - UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, pswd); - AuthScope authscope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT); - BasicCredentialsProvider credsprovider = new BasicCredentialsProvider(); - credsprovider.setCredentials(authscope, credentials); - httpContext.setCredentialsProvider(credsprovider); - } - } - - // Method posts to the ansible server and writes out response to - // Ansible result object - public AnsibleResult post(String agentUrl, String payload) { - - AnsibleResult result = new AnsibleResult(); - try { - - HttpPost postObj = new HttpPost(agentUrl); - StringEntity bodyParams = new StringEntity(payload, "UTF-8"); - postObj.setEntity(bodyParams); - postObj.addHeader("Content-type", "application/json"); - - HttpResponse response = httpClient.execute(postObj, httpContext); - HttpEntity entity = response.getEntity(); - String responseOutput = entity != null ? EntityUtils.toString(entity) : null; - int responseCode = response.getStatusLine().getStatusCode(); - result.setStatusCode(responseCode); - result.setStatusMessage(responseOutput); - } catch (IOException io) { - logger.error("Caught IOException", io); - result.setStatusCode(AnsibleResultCodes.IO_EXCEPTION.getValue()); - result.setStatusMessage(io.getMessage()); - } - return result; - } - - // Method gets information from an Ansible server and writes out response to - // Ansible result object - - public AnsibleResult get(String agentUrl) { - - AnsibleResult result = new AnsibleResult(); - - try { - HttpGet getObj = new HttpGet(agentUrl); - HttpResponse response = httpClient.execute(getObj, httpContext); - HttpEntity entity = response.getEntity(); - String responseOutput = entity != null ? EntityUtils.toString(entity) : null; - int responseCode = response.getStatusLine().getStatusCode(); - logger.info("GetResult response for ansible GET URL" + agentUrl + " returned " + responseOutput); - JSONObject postResponse = new JSONObject(responseOutput); - if (postResponse.has(STATUS_CODE_KEY)) { - int codeStatus = postResponse.getInt(STATUS_CODE_KEY); - if (codeStatus == AnsibleResultCodes.PENDING.getValue()) { - result.setStatusCode(codeStatus); - } else { - result.setStatusCode(responseCode); - } - } else { - result.setStatusCode(responseCode); - } - result.setStatusMessage(responseOutput); - } catch (IOException io) { - result.setStatusCode(AnsibleResultCodes.IO_EXCEPTION.getValue()); - result.setStatusMessage(io.getMessage()); - logger.error("Caught IOException", io); - } - return result; - } - - @Override - public void close() { - try { - if (httpClient != null) { - httpClient.close(); - } - } catch (IOException e) { - logger.error("Caught IOException during httpClient close", e); - } - } - -} diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleMessageParser.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleMessageParser.java deleted file mode 100644 index e448f1c47..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleMessageParser.java +++ /dev/null @@ -1,367 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.ansible.model; - -import com.google.common.base.Strings; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import org.apache.commons.lang.StringUtils; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdapterConstants; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdapterConstants.*; - -/** - * Class that validates and constructs requests sent/received from - * Ansible Server - */ -public class AnsibleMessageParser { - - - private static final String JSON_ERROR_MESSAGE = "JSONException: Error parsing response"; - - private static final Logger LOGGER = LoggerFactory.getLogger(AnsibleMessageParser.class); - - /** - * Accepts a map of strings and - * a) validates if all parameters are appropriate (else, throws an exception) and - * b) if correct returns a JSON object with appropriate key-value pairs to send to the server. - *

- * Mandatory parameters, that must be in the supplied information to the Ansible Adapter - * 1. URL to connect to - * 2. credentials for URL (assume user pswd for now) - * 3. Playbook name - */ - public JSONObject reqMessage(Map params) throws SvcLogicException { - final String[] mandatoryTestParams = {AGENT_URL, PLAYBOOK_NAME, USER, PSWD}; - final String[] optionalTestParams = {ENV_PARAMETERS, NODE_LIST, LOCAL_PARAMETERS, TIMEOUT, VERSION, FILE_PARAMETERS, - ACTION, INVENTORY_NAMES, AUTO_NODE_LIST}; - JSONObject jsonPayload = new JSONObject(); - - for (String key : mandatoryTestParams) { - throwIfMissingMandatoryParam(params, key); - jsonPayload.put(key, params.get(key)); - } - - parseOptionalParams(params, optionalTestParams, jsonPayload); - - // Generate a unique uuid for the test - String reqId = UUID.randomUUID().toString(); - jsonPayload.put(ID, reqId); - return jsonPayload; - } - - /** - * Method that validates that the Map has enough information - * to query Ansible server for a result. If so, it returns - * the appropriate url, else an empty string. - */ - public String reqUriResult(Map params) throws SvcLogicException { - final String[] mandatoryTestParams = {AGENT_URL, ID, USER, PSWD}; - for (String key : mandatoryTestParams) { - throwIfMissingMandatoryParam(params, key); - } - return params.get(AGENT_URL) + "?Id=" + params.get(ID) + "&Type=GetResult"; - } - - /** - * Method that validates that the Map has enough information to query Ansible - * server for a result. If so, it returns the appropriate url, else an empty - * string. - */ - public String reqUriResultWithIP(Map params, String serverIP) throws SvcLogicException { - final String[] mandatoryTestParams = {AGENT_URL, ID, USER, PSWD}; - for (String key : mandatoryTestParams) { - throwIfMissingMandatoryParam(params, key); - } - String[] arr1 = params.get(AGENT_URL).split("//", 2); - String[] arr2 = arr1[1].split(":", 2); - return arr1[0] + "//" + serverIP + ":" + arr2[1] + "?Id=" + params.get(ID) + "&Type=GetResult"; - } - - /** - * Method that validates that the Map has enough information to query Ansible - * server for logs. If so, it populates the appropriate returns the appropriate - * url, else an empty string. - */ - public String reqUriLog(Map params) throws SvcLogicException { - final String[] mandatoryTestParams = {AGENT_URL, ID, USER, PSWD}; - for (String mandatoryParam : mandatoryTestParams) { - throwIfMissingMandatoryParam(params, mandatoryParam); - } - return params.get(AGENT_URL) + "?Id=" + params.get(ID) + "&Type=GetLog"; - } - - /** - * Method that validates that the Map has enough information - * to query Ansible server for an output. If so, it returns - * the appropriate url, else an empty string. - */ - public String reqUriOutput(Map params) throws SvcLogicException { - final String[] mandatoryTestParams = {AGENT_URL, ID, USER, PSWD}; - for (String mandatoryParam : mandatoryTestParams) { - throwIfMissingMandatoryParam(params, mandatoryParam); - } - return params.get(AGENT_URL) + "?Id=" + params.get(ID) + "&Type=GetOutput"; - } - - /** - * This method parses response from the Ansible Server when we do a post - * and returns an AnsibleResult object. - */ - public AnsibleResult parsePostResponse(String input) throws SvcLogicException { - AnsibleResult ansibleResult; - try { - JSONObject postResponse = new JSONObject(input); - int code = postResponse.getInt(STATUS_CODE); - int initResponseValue = AnsibleResultCodes.INITRESPONSE.getValue(); - boolean validCode = AnsibleResultCodes.CODE.checkValidCode(initResponseValue, code); - if (!validCode) { - throw new SvcLogicException(String.format("Invalid InitResponse code = %s received. MUST be one of %s", - code, AnsibleResultCodes.CODE.getValidCodes(initResponseValue))); - } - - ansibleResult = new AnsibleResult(code, postResponse.getString(STATUS_MESSAGE)); - if (postResponse.has(ANSIBLE_SERVER) && StringUtils.isNotBlank(postResponse.getString(ANSIBLE_SERVER))) { - ansibleResult.setServerIp(postResponse.getString(ANSIBLE_SERVER)); - } - if (!postResponse.isNull(OUTPUT)) { - LOGGER.info("Processing results-output in post response"); - JSONObject output = postResponse.getJSONObject(OUTPUT); - ansibleResult.setOutput(output.toString()); - } - } catch (JSONException e) { - LOGGER.error(JSON_ERROR_MESSAGE, e); - ansibleResult = new AnsibleResult(600, "Error parsing response = " + input + ". Error = " + e.getMessage()); - } - return ansibleResult; - } - - /** - * This method parses response from an Ansible server when we do a GET for a result - * and returns an AnsibleResult object. - **/ - public AnsibleResult parseGetResponse(String input) throws SvcLogicException { - AnsibleResult ansibleResult = new AnsibleResult(); - try { - JSONObject postResponse = new JSONObject(input); - parseGetResponseNested(ansibleResult, postResponse); - } catch (JSONException e) { - LOGGER.error(JSON_ERROR_MESSAGE, e); - ansibleResult = new AnsibleResult(AnsibleResultCodes.INVALID_PAYLOAD.getValue(), - "Error parsing response = " + input + ". Error = " + e.getMessage(), ""); - } - return ansibleResult; - } - - private void parseGetResponseNested(AnsibleResult ansibleResult, JSONObject postRsp) throws SvcLogicException { - String messageStatus = postRsp.getString(STATUS_MESSAGE); - int codeStatus = postRsp.getInt(STATUS_CODE); - int finalCode = AnsibleResultCodes.FINAL_SUCCESS.getValue(); - boolean valCode = AnsibleResultCodes.CODE.checkValidCode(AnsibleResultCodes.FINALRESPONSE.getValue(), codeStatus); - if (!valCode) { - throw new SvcLogicException(String.format("Invalid InitResponse code = %s received. MUST be one of %s", - codeStatus, AnsibleResultCodes.CODE.getValidCodes(AnsibleResultCodes.FINALRESPONSE.getValue()))); - } - - ansibleResult.setStatusCode(codeStatus); - ansibleResult.setStatusMessage(messageStatus); - ansibleResult.setConfigData("UNKNOWN"); - LOGGER.info("Received response with code = {}, Message = {}", codeStatus, messageStatus); - - if (!postRsp.isNull("Results")) { - - // Results are available. process them - // Results is a dictionary of the form - - LOGGER.info("Processing results in response"); - JSONObject results = postRsp.getJSONObject("Results"); - - LOGGER.info("Get JSON dictionary from Results by Iterating through hosts"); - Iterator hosts = results.keys(); - while (hosts.hasNext()) { - String host = hosts.next(); - LOGGER.info("Processing host = {}", - (host.matches("^[\\w\\-.]+$")) ? host : "[unexpected value, logging suppressed]"); - try { - JSONObject hostResponse = results.getJSONObject(host); - int subCode = hostResponse.getInt(STATUS_CODE); - String message = hostResponse.getString(STATUS_MESSAGE); - - LOGGER.info("Code = {}, Message = {}", subCode, message); - - if (subCode != 200 || !"SUCCESS".equals(message)) { - finalCode = AnsibleResultCodes.REQ_FAILURE.getValue(); - } - if ((hostResponse.optJSONObject(OUTPUT)) != null) { - JSONObject hostResponseObjectInfo = hostResponse.optJSONObject(OUTPUT).optJSONObject("info"); - JSONObject hostResponseConfigData = hostResponseObjectInfo.optJSONObject("configData"); - if (hostResponseConfigData != null) { - ansibleResult.setConfigData(hostResponseConfigData.toString()); - } - } - } catch (JSONException e) { - LOGGER.error(JSON_ERROR_MESSAGE, e); - ansibleResult.setStatusCode(AnsibleResultCodes.INVALID_RESPONSE.getValue()); - ansibleResult.setStatusMessage(String.format("Error processing response message = %s from host %s", - results.getString(host), host)); - break; - } - } - ansibleResult.setStatusCode(finalCode); - - // We return entire Results object as message - ansibleResult.setResults(results.toString()); - } else { - ansibleResult.setStatusCode(AnsibleResultCodes.INVALID_RESPONSE.getValue()); - ansibleResult.setStatusMessage("Results not found in GET for response"); - } - if (!postRsp.isNull(OUTPUT)) { - LOGGER.info("Processing results-output in response"); - JSONObject output = postRsp.getJSONObject(OUTPUT); - ansibleResult.setOutput(output.toString()); - } - } - - private void parseOptionalParams(Map params, String[] optionalTestParams, JSONObject jsonPayload) { - - Set optionalParamsSet = new HashSet<>(); - Collections.addAll(optionalParamsSet, optionalTestParams); - - //@formatter:off - params.entrySet().stream().filter(entry -> optionalParamsSet.contains(entry.getKey())) - .filter(entry -> !Strings.isNullOrEmpty(entry.getValue())) - .forEach(entry -> parseOptionalParam(entry, jsonPayload)); - //@formatter:on - } - - private void parseOptionalParam(Map.Entry params, JSONObject jsonPayload) { - String key = params.getKey(); - String payload = params.getValue(); - - switch (key) { - case TIMEOUT: - if (dataIsVariable(payload)) { - break; - } - int timeout = Integer.parseInt(payload); - if (timeout < 0) { - throw new NumberFormatException(" : specified negative integer for timeout = " + payload); - } - jsonPayload.put(key, payload); - break; - case AUTO_NODE_LIST: - if (payload.equalsIgnoreCase("true") || payload.equalsIgnoreCase("false")) { - jsonPayload.put(key, payload); - } else { - throw new IllegalArgumentException(" : specified invalid boolean value of AutoNodeList = " + payload); - } - break; - case VERSION: - if (dataIsVariable(payload)) { - break; - } - case INVENTORY_NAMES: - jsonPayload.put(key, payload); - break; - - case LOCAL_PARAMETERS: - case ENV_PARAMETERS: - case EXTRA_VARS: - JSONObject paramsJson = new JSONObject(payload); - jsonDataIsVariable(paramsJson); - jsonPayload.put(key, paramsJson); - break; - - case NODE_LIST: - if (payload.startsWith("$")) { - break; - } - JSONArray paramsArray = new JSONArray(payload); - jsonPayload.put(key, paramsArray); - break; - - case FILE_PARAMETERS: - if (dataIsVariable(payload)) { - break; - } - jsonPayload.put(key, getFilePayload(payload)); - break; - - default: - break; - } - } - - /** - * Return payload with escaped newlines - */ - private JSONObject getFilePayload(String payload) { - String formattedPayload = payload.replace("\n", "\\n").replace("\r", "\\r"); - return new JSONObject(formattedPayload); - } - - private void throwIfMissingMandatoryParam(Map params, String key) throws SvcLogicException { - if (!params.containsKey(key)) { - throw new SvcLogicException(String.format( - "Ansible: Mandatory AnsibleAdapter key %s not found in parameters provided by calling agent !", key)); - } - if (Strings.isNullOrEmpty(params.get(key))) { - throw new SvcLogicException(String.format( - "Ansible: Mandatory AnsibleAdapter key %s not found in parameters provided by calling agent !", key)); - } - if (StringUtils.startsWith(params.get(key), "$")) { - throw new SvcLogicException(String.format( - "Ansible: Mandatory AnsibleAdapter key %s is a variable", key)); - } - } - - private boolean dataIsVariable(String payload) { - return StringUtils.startsWith(payload, "$") || StringUtils.isEmpty(payload); - } - - private void jsonDataIsVariable(JSONObject paramsJson) { - LOGGER.info("input json is " + paramsJson); - String[] keys = JSONObject.getNames(paramsJson); - for (String k : keys) { - Object a = paramsJson.get(k); - if (a instanceof String) { - if (StringUtils.startsWith(a.toString(), "$") || StringUtils.isEmpty(a.toString())) { - LOGGER.info("removing key " + k); - paramsJson.remove(k); - } - } - } - LOGGER.info("returning json as {}", paramsJson); - } - -} diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResult.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResult.java deleted file mode 100644 index bad0f5e20..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResult.java +++ /dev/null @@ -1,115 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.ansible.model; - -/** - * Simple class to store code and message returned by POST/GET to an Ansible Server - */ -public class AnsibleResult { - - private static final String EMPTY_VALUE = "UNKNOWN"; - - private int statusCode; - private String statusMessage; - private String results; - private String output; - private String serverIp; - private String configData; - - public AnsibleResult() { - this(-1, EMPTY_VALUE, EMPTY_VALUE); - } - - public AnsibleResult(int code, String message) { - this(code, message, EMPTY_VALUE); - } - - public AnsibleResult(int code, String message, String result) { - statusCode = code; - statusMessage = message; - results = result; - } - - public AnsibleResult(int code, String message, String result, String outputData) { - statusCode = code; - statusMessage = message; - results = result; - output = outputData; - } - - public String getOutput() { - return output; - } - - public void setOutput(String output) { - this.output = output; - } - - void set(int code, String message, String results, String output) { - this.statusCode = code; - this.statusMessage = message; - this.results = results; - this.output = output; - } - - public int getStatusCode() { - return this.statusCode; - } - - public void setStatusCode(int code) { - this.statusCode = code; - } - - public String getStatusMessage() { - return this.statusMessage; - } - - public void setStatusMessage(String message) { - this.statusMessage = message; - } - - public String getResults() { - return this.results; - } - - public void setResults(String results) { - this.results = results; - } - - public String getServerIp() { - return this.serverIp; - } - - public void setServerIp(String serverIp) { - this.serverIp = serverIp; - } - - public String getConfigData() { - return this.configData; - } - - public void setConfigData(String configData) { - this.configData = configData; - } - -} diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResultCodes.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResultCodes.java deleted file mode 100644 index 55a1e7086..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResultCodes.java +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.ansible.model; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -/** - * enum of the various codes that APP-C uses to resolve different - * status of response from Ansible Server - **/ - -public enum AnsibleResultCodes { - - // @formatter:off - SUCCESS(400), - KEYSTORE_EXCEPTION(622), - CERTIFICATE_ERROR(610), - IO_EXCEPTION(611), - HOST_UNKNOWN(625), - USER_UNAUTHORIZED(613), - UNKNOWN_EXCEPTION(699), - SSL_EXCEPTION(697), - INVALID_PAYLOAD(698), - INVALID_RESPONSE(601), - PENDING(100), - REJECTED(101), - FINAL_SUCCESS(200), - REQ_FAILURE(401), - MESSAGE(1), - CODE(0), - INITRESPONSE(0), - FINALRESPONSE(1); - // @formatter:on - - private final Set initCodes = new HashSet<>(Arrays.asList(100, 101)); - private final Set finalCodes = new HashSet<>(Arrays.asList(200, 500)); - private final ArrayList> codeSets = new ArrayList<>(Arrays.asList(initCodes, finalCodes)); - private final Set messageSet = new HashSet<>(Arrays.asList("PENDING", "FINISHED", "TERMINATED")); - private final int value; - - AnsibleResultCodes(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - - public boolean checkValidCode(int type, int code) { - return codeSets.get(type).contains(code); - } - - public String getValidCodes(int type) { - StringBuilder sb = new StringBuilder("[ "); - codeSets.get(type).forEach(s -> sb.append(s).append(",")); - return sb.append("]").toString(); - } - - public boolean checkValidMessage(String message) { - return messageSet.contains(message); - } - - public String getValidMessages() { - StringBuilder sb = new StringBuilder("[ "); - messageSet.forEach(s -> sb.append(s).append(",")); - return sb.append("]").toString(); - } -} diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleServerEmulator.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleServerEmulator.java deleted file mode 100644 index a10a0aeb2..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleServerEmulator.java +++ /dev/null @@ -1,126 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.ansible.model; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.apache.commons.lang.StringUtils; -import org.json.JSONException; -import org.json.JSONObject; - -import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdapterConstants.PLAYBOOK_NAME; -import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdapterConstants.STATUS_CODE; -import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdapterConstants.STATUS_MESSAGE; - -public class AnsibleServerEmulator { - - private final EELFLogger logger = EELFManager.getInstance().getLogger(AnsibleServerEmulator.class); - - /** - * Method that emulates the response from an Ansible Server - * when presented with a request to execute a playbook - * Returns an ansible object result. The response code is always the http code 200 (i.e connection successful) - * payload is json string as would be sent back by Ansible Server - **/ - public AnsibleResult post(String payload) { - AnsibleResult result = new AnsibleResult(); - - try { - // Request must be a JSON object - - JSONObject message = new JSONObject(payload); - String playbookName = "test_playbook.yaml"; - if (message.isNull("Id")) { - rejectRequest(result, "Must provide a valid Id"); - } else if (message.isNull(PLAYBOOK_NAME)) { - rejectRequest(result, "Must provide a playbook Name"); - } else if (!message.getString(PLAYBOOK_NAME).equals(playbookName)) { - rejectRequest(result, "Playbook " + message.getString(PLAYBOOK_NAME) + " not found in catalog"); - } else { - acceptRequest(result); - } - } catch (JSONException e) { - logger.error("JSONException caught", e); - rejectRequest(result, e.getMessage()); - } - return result; - } - - /** - * Method to emulate response from an Ansible - * Server when presented with a GET request - * Returns an ansibl object result. The response code is always the http code 200 (i.e connection successful) - * payload is json string as would be sent back by Ansible Server - **/ - public AnsibleResult get(String agentUrl) { - - Pattern pattern = Pattern.compile(".*?\\?Id=(.*?)&Type.*"); - Matcher matcher = pattern.matcher(agentUrl); - String id = StringUtils.EMPTY; - String vmAddress = "192.168.1.10"; - - if (matcher.find()) { - id = matcher.group(1); - } - - AnsibleResult getResult = new AnsibleResult(); - - JSONObject response = new JSONObject(); - response.put(STATUS_CODE, 200); - response.put(STATUS_MESSAGE, "FINISHED"); - - JSONObject results = new JSONObject(); - - JSONObject vmResults = new JSONObject(); - vmResults.put(STATUS_CODE, 200); - vmResults.put(STATUS_MESSAGE, "SUCCESS"); - vmResults.put("Id", id); - results.put(vmAddress, vmResults); - - response.put("Results", results); - - getResult.setStatusCode(200); - getResult.setStatusMessage(response.toString()); - - return getResult; - } - - private void rejectRequest(AnsibleResult result, String Message) { - result.setStatusCode(200); - JSONObject response = new JSONObject(); - response.put(STATUS_CODE, AnsibleResultCodes.REJECTED.getValue()); - response.put(STATUS_MESSAGE, Message); - result.setStatusMessage(response.toString()); - } - - private void acceptRequest(AnsibleResult result) { - result.setStatusCode(200); - JSONObject response = new JSONObject(); - response.put(STATUS_CODE, AnsibleResultCodes.PENDING.getValue()); - response.put(STATUS_MESSAGE, "PENDING"); - result.setStatusMessage(response.toString()); - } - -} \ No newline at end of file diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/resources/OSGI-INF/blueprint/ansible-adapter-blueprint.xml b/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/resources/OSGI-INF/blueprint/ansible-adapter-blueprint.xml deleted file mode 100755 index 76abc8276..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/resources/OSGI-INF/blueprint/ansible-adapter-blueprint.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdapter - - - - diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/resources/ansible-adapter.properties b/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/resources/ansible-adapter.properties deleted file mode 100644 index 8def3da30..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/resources/ansible-adapter.properties +++ /dev/null @@ -1,42 +0,0 @@ -### -# ============LICENSE_START======================================================= -# ONAP : SLI -# ================================================================================ -# Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# 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. -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. -# ============LICENSE_END========================================================= - -### -# -# Default properties for the APP-C Provider Adapter -# -# ------------------------------------------------------------------------------------------------- -# -# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded -# to supply configuration options -org.onap.appc.bootstrap.file=appc.properties -org.onap.appc.bootstrap.path=${user.home},/opt/opendaylight/current/properties,. -appc.application.name=APPC -# -# Define the message resource bundle name to be loaded -org.onap.appc.resources=org/onap/appc/i18n/MessageResources -# -# The name of the adapter. -org.onap.appc.provider.adaptor.name=org.onap.appc.appc_ansible_adapter -# Default truststore path and password -org.onap.appc.adapter.ansible.trustStore=/opt/opendaylight/tls-client/mykeystore.js -org.onap.appc.adapter.ansible.trustStore.trustPasswd=changeit -org.onap.appc.adapter.ansible.clientType=TRUST_ALL diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/resources/org/opendaylight/blueprint/ansible-adapter-blueprint.xml b/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/resources/org/opendaylight/blueprint/ansible-adapter-blueprint.xml deleted file mode 100755 index 76abc8276..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/main/resources/org/opendaylight/blueprint/ansible-adapter-blueprint.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdapter - - - - diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestAnsibleAdapterImpl.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestAnsibleAdapterImpl.java deleted file mode 100644 index be4bfd8f2..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestAnsibleAdapterImpl.java +++ /dev/null @@ -1,239 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.adapter.ansible.impl; - -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.ccsdk.sli.adaptors.ansible.impl.AnsibleAdapterImpl; -import org.onap.ccsdk.sli.adaptors.ansible.impl.AnsibleAdapterPropertiesProviderImpl; -import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleMessageParser; -import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResult; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.powermock.reflect.Whitebox; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.when; -import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdapterConstants.*; -@RunWith(MockitoJUnitRunner.class) -public class TestAnsibleAdapterImpl { - - private static final String PENDING = "100"; - private static final String AGENT_URL = "https://192.168.1.1"; - - private static String KEYSTORE_PSWD; - private static Properties properties; - private boolean testMode = true; - - private AnsibleAdapterImpl adapter; - private AnsibleResult result; - private AnsibleAdapterImpl spyAdapter; - private Map params; - private SvcLogicContext svcContext; - private JSONObject jsonPayload; - - @Mock - private AnsibleMessageParser messageProcessor; - - @BeforeClass - public static void once() { - properties = new AnsibleAdapterPropertiesProviderImpl().getProperties(); - KEYSTORE_PSWD = properties.getProperty("org.onap.appc.adapter.ansible.trustStore.trustPasswd"); - } - - /** - * Use reflection to locate fields and methods so that they can be manipulated - * during the test to change the internal state accordingly. - */ - @Before - public void setup() { - testMode = true; - svcContext = new SvcLogicContext(); - adapter = new AnsibleAdapterImpl(testMode); - params = new HashMap<>(); - params.put("AgentUrl", AGENT_URL); - jsonPayload = new JSONObject(); - jsonPayload.put("Id", "100"); - jsonPayload.put("User", "test"); - jsonPayload.put("Password", "test"); - jsonPayload.put("PlaybookName", "test_playbook.yaml"); - jsonPayload.put("Timeout", "60000"); - jsonPayload.put("AgentUrl", AGENT_URL); - result = new AnsibleResult(); - result.setStatusMessage("Success"); - result.setResults("Success"); - result.setOutput("{}"); - Whitebox.setInternalState(adapter, "messageProcessor", messageProcessor); - spyAdapter = Mockito.spy(adapter); - } - - @After - public void tearDown() { - testMode = false; - adapter = null; - params = null; - svcContext = null; - } - - @Test - public void reqExec_shouldSetPending() throws SvcLogicException { - result.setStatusCode(Integer.parseInt(PENDING)); - when(messageProcessor.reqMessage(params)).thenReturn(jsonPayload); - when(messageProcessor.parsePostResponse(anyString())).thenReturn(result); - spyAdapter.reqExec(params, svcContext); - assertEquals(PENDING, svcContext.getAttribute(RESULT_CODE_ATTRIBUTE_NAME)); - } - - @Test(expected = SvcLogicException.class) - public void reqExecResult_shouldSetSuccess() throws SvcLogicException { - params.put("Id", "100"); - result.setStatusMessage(SUCCESS); - when(messageProcessor.reqUriResult(params)).thenReturn(AGENT_URL); - when(messageProcessor.parseGetResponse(anyString())).thenReturn(result); - spyAdapter.reqExecResult(params, svcContext); - assertEquals(SUCCESS, svcContext.getAttribute(SUCCESS)); - } - @Test(expected = SvcLogicException.class) - public void reqExecResult_Failure() throws SvcLogicException { - params.put("Id", "100"); - result.setStatusCode(100); - result.setStatusMessage("Failed"); - JSONObject cData = new JSONObject(); - cData.put("GatewayInfo", "Radius"); - result.setConfigData(cData.toString()); - result.setOutput(cData.toString()); - when(messageProcessor.reqUriResult(params)).thenReturn(AGENT_URL); - when(messageProcessor.parseGetResponse(anyString())).thenReturn(result); - adapter.reqExecResult(params, svcContext); - } - - @Test(expected = SvcLogicException.class) - public void reqExecResult_SvcLogicException() throws SvcLogicException { - when(messageProcessor.reqUriResult(params)).thenThrow(new SvcLogicException()); - adapter.reqExecResult(params, svcContext); - } - - @Test(expected = SvcLogicException.class) - public void reqExecResult_numberFormatException() - throws IllegalStateException, IllegalArgumentException, SvcLogicException { - when(messageProcessor.reqUriResult(params)).thenThrow(new NumberFormatException()); - adapter.reqExecResult(params, svcContext); - } - - @Test - public void reqExecLog_shouldSetMessage() throws SvcLogicException { - params.put("Id", "101"); - when(messageProcessor.reqUriLog(params)).thenReturn(AGENT_URL); - adapter.reqExecLog(params, svcContext); - String message = getResponseMessage(); - assertEquals(message, svcContext.getAttribute(LOG_ATTRIBUTE_NAME)); - } - - private String getResponseMessage() { - JSONObject response = new JSONObject(); - response.put(STATUS_CODE, 200); - response.put(STATUS_MESSAGE, "FINISHED"); - JSONObject results = new JSONObject(); - - JSONObject vmResults = new JSONObject(); - vmResults.put(STATUS_CODE, 200); - vmResults.put(STATUS_MESSAGE, "SUCCESS"); - vmResults.put("Id", ""); - results.put("192.168.1.10", vmResults); - - response.put("Results", results); - return response.toString(); - } - - @Test(expected = SvcLogicException.class) - public void reqExecException() - throws IllegalStateException, IllegalArgumentException, SvcLogicException { - when(messageProcessor.reqUriLog(params)).thenThrow(new SvcLogicException("Appc Exception")); - adapter.reqExecLog(params, svcContext); - } - - @Test(expected = SvcLogicException.class) - public void reqExec_SvcLogicException() - throws IllegalStateException, IllegalArgumentException, SvcLogicException { - when(messageProcessor.reqMessage(params)).thenThrow(new SvcLogicException()); - adapter.reqExec(params, svcContext); - } - - @Test(expected = SvcLogicException.class) - public void reqExec_JsonException() - throws IllegalStateException, IllegalArgumentException, SvcLogicException { - when(messageProcessor.reqMessage(params)).thenThrow(new JSONException("Json Exception")); - adapter.reqExec(params, svcContext); - } - - @Test(expected = SvcLogicException.class) - public void reqExec_NumberFormatException() - throws IllegalStateException, IllegalArgumentException, SvcLogicException { - when(messageProcessor.reqMessage(params)).thenThrow(new NumberFormatException("Numbre Format Exception")); - adapter.reqExec(params, svcContext); - } - - @Test - public void testInitializeWithDefault() { - properties.setProperty("org.onap.appc.adapter.ansible.clientType", ""); - adapter = new AnsibleAdapterImpl(); - assertNotNull(adapter); - } - - @Test - public void testInitializeWithTrustAll() { - properties.setProperty("org.onap.appc.adapter.ansible.clientType", "TRUST_ALL"); - adapter = new AnsibleAdapterImpl(); - assertNotNull(adapter); - } - - @Test - public void testInitializeWithTrustCert() { - properties.setProperty("org.onap.appc.adapter.ansible.clientType", "TRUST_CERT"); - properties.setProperty("org.onap.appc.adapter.ansible.trustStore.trustPasswd", KEYSTORE_PSWD); - adapter = new AnsibleAdapterImpl(); - assertNotNull(adapter); - } - - @Test - public void testInitializeWithException() { - properties.setProperty("org.onap.appc.adapter.ansible.clientType", "TRUST_CERT"); - properties.setProperty("org.onap.appc.adapter.ansible.trustStore.trustPasswd", "appc"); - adapter = new AnsibleAdapterImpl(); - assertNotNull(adapter); - } - -} \ No newline at end of file diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestAnsibleAdapterPropertiesProviderImpl.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestAnsibleAdapterPropertiesProviderImpl.java deleted file mode 100644 index 5ce1712d3..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestAnsibleAdapterPropertiesProviderImpl.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.adapter.ansible.impl; - -import java.io.File; -import java.util.Properties; -import org.junit.Test; -import org.onap.ccsdk.sli.adaptors.ansible.impl.AnsibleAdapterPropertiesProviderImpl; - -import static org.junit.Assert.assertEquals; -import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdapterConstants.*; - -public class TestAnsibleAdapterPropertiesProviderImpl { - - @Test - public void testGetProperties() throws IllegalStateException, IllegalArgumentException { - Properties prop = new AnsibleAdapterPropertiesProviderImpl().getProperties(); - - assertEquals("TRUST_ALL", prop.getProperty(CLIENT_TYPE_PROPERTY_NAME)); - assertEquals("org.onap.appc.appc_ansible_adapter", prop.getProperty("org.onap.appc.provider.adaptor.name")); - assertEquals("changeit", prop.getProperty(TRUSTSTORE_PASS_PROPERTY_NAME)); - assertEquals("${user.home},/opt/opendaylight/current/properties,.", prop.getProperty("org.onap.appc.bootstrap.path")); - assertEquals("APPC", prop.getProperty("appc.application.name")); - assertEquals("appc.properties", prop.getProperty("org.onap.appc.bootstrap.file")); - assertEquals("org/onap/appc/i18n/MessageResources", prop.getProperty("org.onap.appc.resources")); - assertEquals("/opt/opendaylight/tls-client/mykeystore.js", prop.getProperty(TRUSTSTORE_PROPERTY_NAME)); - } - - @Test - public void testGetTestProperties() throws IllegalStateException, IllegalArgumentException { - final String configFilePath = "src/test/resources/properties/ansible-adapter-test.properties".replace("/", File.separator); - Properties prop = new AnsibleAdapterPropertiesProviderImpl(configFilePath).getProperties(); - - assertEquals("appc", prop.getProperty(CLIENT_TYPE_PROPERTY_NAME)); - assertEquals("org.onap.appc.appc_ansible_adapter", prop.getProperty("org.onap.appc.provider.adaptor.name")); - assertEquals("Aa123456", prop.getProperty(TRUSTSTORE_PASS_PROPERTY_NAME)); - assertEquals("${user.home},/opt/opendaylight/current/properties,.", prop.getProperty("org.onap.appc.bootstrap.path")); - assertEquals("APPC", prop.getProperty("appc.application.name")); - assertEquals("appc.properties", prop.getProperty("org.onap.appc.bootstrap.file")); - assertEquals("org/onap/appc/i18n/MessageResources", prop.getProperty("org.onap.appc.resources")); - assertEquals("src/test/resources/org/onap/appc/asdc-client.jks", prop.getProperty(TRUSTSTORE_PROPERTY_NAME)); - } - -} diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestConnectionBuilder.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestConnectionBuilder.java deleted file mode 100644 index 25f89863d..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestConnectionBuilder.java +++ /dev/null @@ -1,236 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.adapter.ansible.impl; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; -import java.util.Properties; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.StatusLine; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.impl.client.CloseableHttpClient; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.ccsdk.sli.adaptors.ansible.impl.AnsibleAdapterPropertiesProviderImpl; -import org.onap.ccsdk.sli.adaptors.ansible.impl.ConnectionBuilder; -import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResult; -import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResultCodes; -import org.powermock.reflect.Whitebox; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdapterConstants.*; - -@RunWith(MockitoJUnitRunner.class) -public class TestConnectionBuilder { - - private static String KEYSTORE_FILE; - private static String KEYSTORE_PSWD; - private static String KEYSTORE_CERTIFICATE; - private static String USER; - private static String PSWD; - private static String URL; - - private final int SUCCESS_STATUS = 200; - private ConnectionBuilder connectionBuilder; - - @Mock - private CloseableHttpClient httpClient; - - @Mock - private HttpClientContext httpClientContext; - - @Mock - private CloseableHttpResponse response; - - @Mock - private HttpEntity entity; - - @Mock - private StatusLine statusLine; - - /** - * Load the configuration properties - */ - @BeforeClass - public static void once() { - final String configFilePath = "src/test/resources/properties/ansible-adapter-test.properties".replace("/", File.separator); - Properties properties = new AnsibleAdapterPropertiesProviderImpl(configFilePath).getProperties(); - - KEYSTORE_FILE = properties.getProperty(TRUSTSTORE_PROPERTY_NAME); - KEYSTORE_PSWD = properties.getProperty(TRUSTSTORE_PASS_PROPERTY_NAME); - KEYSTORE_CERTIFICATE = properties.getProperty("org.onap.appc.adapter.ansible.cert"); - USER = properties.getProperty("org.onap.appc.adapter.ansible.username"); - PSWD = properties.getProperty("org.onap.appc.adapter.ansible.password"); - URL = properties.getProperty("org.onap.appc.adapter.ansible.identity"); - } - - @Before - public void setup() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException { - connectionBuilder = new ConnectionBuilder(1, 2000); - Whitebox.setInternalState(connectionBuilder, "httpClient", httpClient); - Whitebox.setInternalState(connectionBuilder, "httpContext", httpClientContext); - HttpResponse httpResponse = response; - when(httpResponse.getEntity()).thenReturn(entity); - when(httpResponse.getStatusLine()).thenReturn(statusLine); - when(statusLine.getStatusCode()).thenReturn(SUCCESS_STATUS); - } - - @After - public void tearDown() { - connectionBuilder = null; - } - - @Test - public void testConnectionBuilder() throws KeyManagementException, KeyStoreException, CertificateException, - NoSuchAlgorithmException, IOException { - char[] trustStorePassword = KEYSTORE_PSWD.toCharArray(); - ConnectionBuilder connectionBuilder = new ConnectionBuilder(KEYSTORE_FILE, trustStorePassword, 600000, ""); - assertNotNull(connectionBuilder); - } - - @Test - public void testConnectionBuilderWithFilePath() throws KeyManagementException, KeyStoreException, - CertificateException, NoSuchAlgorithmException, IOException { - new ConnectionBuilder(KEYSTORE_CERTIFICATE, 600000); - } - - @Test - public void testSetHttpContext() { - ConnectionBuilder spyConnectionBuilder = Mockito.spy(connectionBuilder); - spyConnectionBuilder.setHttpContext(USER, PSWD); - verify(spyConnectionBuilder, times(1)).setHttpContext(USER, PSWD); - } - - @Test - public void testPost() throws IOException { - when(httpClient.execute(anyObject(), eq(httpClientContext))).thenReturn(response); - AnsibleResult result = connectionBuilder.post(URL, "appc"); - assertNull(result.getStatusMessage()); - assertEquals(SUCCESS_STATUS, result.getStatusCode()); - assertEquals("UNKNOWN", result.getResults()); - } - - @Test - public void testPostWithException() throws IOException { - when(httpClient.execute(anyObject(), eq(httpClientContext))).thenThrow(new IOException()); - AnsibleResult result = connectionBuilder.post(URL, "appc"); - assertEquals(AnsibleResultCodes.IO_EXCEPTION.getValue(), result.getStatusCode()); - } - - @Ignore - @Test - public void testGet() throws IOException { - when(httpClient.execute(anyObject(), eq(httpClientContext))).thenReturn(response); - AnsibleResult result = connectionBuilder.get(URL); - assertNull(result.getStatusMessage()); - assertEquals(SUCCESS_STATUS, result.getStatusCode()); - assertEquals("UNKNOWN", result.getResults()); - } - - @Test - public void testGetWithException() throws IOException { - when(httpClient.execute(anyObject(), eq(httpClientContext))).thenThrow(new IOException()); - AnsibleResult result = connectionBuilder.get(URL); - assertEquals(AnsibleResultCodes.IO_EXCEPTION.getValue(), result.getStatusCode()); - } - - @Test - public void testClose() { - connectionBuilder.close(); - } - - @Test - public void testGetMode() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { - connectionBuilder = new ConnectionBuilder(2, 2000); - connectionBuilder.setHttpContext(USER, PSWD); - AnsibleResult result = connectionBuilder.get("test.server.com"); - - assertEquals(611, result.getStatusCode()); - assertNull(result.getStatusMessage()); - assertEquals("UNKNOWN", result.getResults()); - } - - @Test (expected = FileNotFoundException.class) - public void testGetModeNoCert() throws KeyStoreException, CertificateException, IOException, - KeyManagementException, NoSuchAlgorithmException { - String certFile = "testCert"; - - connectionBuilder = new ConnectionBuilder(certFile, 2000); - connectionBuilder.setHttpContext(USER, PSWD); - AnsibleResult result = connectionBuilder.get(URL); - - assertEquals(611, result.getStatusCode()); - assertNull(result.getStatusMessage()); - assertEquals("UNKNOWN", result.getResults()); - } - - @Test - public void testGetModeCert() throws KeyStoreException, CertificateException, IOException, - KeyManagementException, NoSuchAlgorithmException { - String certFile = "src/test/resources/cert"; - - connectionBuilder = new ConnectionBuilder(certFile, 2000); - connectionBuilder.setHttpContext(USER, PSWD); - AnsibleResult result = connectionBuilder.get("test.server.com"); - - assertEquals(611, result.getStatusCode()); - assertNull(result.getStatusMessage()); - assertEquals("UNKNOWN", result.getResults()); - } - - @Test (expected = IOException.class) - public void testGetModeStore() throws KeyStoreException, CertificateException, IOException, - KeyManagementException, NoSuchAlgorithmException { - String store = "src/test/resources/cert"; - - connectionBuilder = new ConnectionBuilder(store, new char['t'], 2000, "1.1.1.1" ); - connectionBuilder.setHttpContext(USER, PSWD); - AnsibleResult result = connectionBuilder.get(URL); - - assertEquals(611, result.getStatusCode()); - assertNull(result.getStatusMessage()); - assertEquals("UNKNOWN", result.getResults()); - } - -} diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/model/TestAnsibleAdapter.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/model/TestAnsibleAdapter.java deleted file mode 100644 index 3e1929bf5..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/model/TestAnsibleAdapter.java +++ /dev/null @@ -1,100 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.adapter.ansible.model; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import org.json.JSONObject; -import org.junit.Test; -import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleMessageParser; -import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResult; -import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleServerEmulator; - -import static org.junit.Assert.assertNotNull; - -public class TestAnsibleAdapter { - - @Test - public void callPrivateConstructorsMethodsForCodeCoverage() - throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, - InvocationTargetException { - - /* test constructors */ - Class[] classesOne = {AnsibleMessageParser.class}; - for (Class clazz : classesOne) { - Constructor constructor = clazz.getDeclaredConstructor(); - constructor.setAccessible(true); - assertNotNull(constructor.newInstance()); - } - Class[] classesTwo = {AnsibleServerEmulator.class}; - for (Class clazz : classesTwo) { - Constructor constructor = clazz.getDeclaredConstructor(); - constructor.setAccessible(true); - assertNotNull(constructor.newInstance()); - } - Class[] classesThree = {AnsibleResult.class}; - for (Class clazz : classesThree) { - Constructor constructor = clazz.getDeclaredConstructor(); - constructor.setAccessible(true); - assertNotNull(constructor.newInstance()); - } - - /* test methods */ - AnsibleMessageParser ansibleMessageParser = new AnsibleMessageParser(); - Class[] parameterTypes = new Class[1]; - parameterTypes[0] = java.lang.String.class; - - Method m = ansibleMessageParser.getClass().getDeclaredMethod("getFilePayload", parameterTypes); - m.setAccessible(true); - assertNotNull(m.invoke(ansibleMessageParser, "{\"test\": test}")); - - // test logging-suppression for an invalid host value (Fortify Log Forging fix) - String input = "{" - + " \"Results\": {" - + " \"192.168.1.10\": {" - + " \"Id\": \"101\"," - + " \"StatusCode\": 200," - + " \"StatusMessage\": \"SUCCESS\"" - + " }," - + " \"192%168%1%10\": {" - + " \"Id\": \"102\"," - + " \"StatusCode\": 200," - + " \"StatusMessage\": \"SUCCESS\"" - + " }," - + " \"server-dev.att.com\": {" - + " \"Id\": \"103\"," - + " \"StatusCode\": 200," - + " \"StatusMessage\": \"SUCCESS\"" - + " }" - + " }," - + " \"StatusCode\": 200," - + " \"StatusMessage\": \"FINISHED\"" - + "}"; - Method m2 = ansibleMessageParser.getClass().getDeclaredMethod("parseGetResponseNested", AnsibleResult.class, JSONObject.class); - m2.setAccessible(true); - m2.invoke(ansibleMessageParser, new AnsibleResult(), new JSONObject(input)); - } - -} - diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/model/TestAnsibleMessageParser.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/model/TestAnsibleMessageParser.java deleted file mode 100644 index bcf18e3b2..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/model/TestAnsibleMessageParser.java +++ /dev/null @@ -1,249 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.adapter.ansible.model; - -import java.util.HashMap; -import java.util.Map; -import org.json.JSONObject; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleMessageParser; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public class TestAnsibleMessageParser { - private AnsibleMessageParser msgParser; - - @Before - public void setup() { - msgParser = new AnsibleMessageParser(); - } - - @Test - public void testReqMessage() throws Exception { - // String result = "{"\AgentUrl : TestAgentUrl}"; - Map params = new HashMap<>(); - params.put("AgentUrl", "TestAgentUrl"); - params.put("PlaybookName", "TestPlaybookName"); - params.put("User", "TestUser"); - params.put("Password", "TestPass"); - - assertEquals("TestAgentUrl", msgParser.reqMessage(params).get("AgentUrl")); - } - - @Test - public void testReqUriResult() throws Exception { - Map params = new HashMap<>(); - params.put("AgentUrl", "TestAgentUrl"); - params.put("Id", "TestId"); - params.put("User", "TestUser"); - params.put("Password", "TestPass"); - - assertTrue(msgParser.reqUriResult(params).contains("TestId")); - } - - @Test - public void testReqUriLog() throws Exception { - Map params = new HashMap<>(); - params.put("AgentUrl", "TestAgent-Url"); - params.put("Id", "TestId"); - params.put("User", "TestUser"); - params.put("Password", "TestPass"); - - assertTrue(msgParser.reqUriLog(params).contains("TestAgent-Url")); - } - - @Test - public void TestParsePostResponse() throws Exception { - String input = "{\"StatusCode\":\"100\",\"StatusMessage\":\"TestMessage\"}"; - assertEquals("TestMessage", msgParser.parsePostResponse(input).getStatusMessage()); - - } - - @Test(expected = SvcLogicException.class) - public void TestParsePostResponseException() throws Exception { - String input = "{\"StatusCode\":\"600\",\"StatusMessage\":\"TestMessage\"}"; - assertTrue(msgParser.parsePostResponse(input).getStatusMessage().contains("Error parsing response")); - } - - @Test(expected = SvcLogicException.class) - public void TestParsePostResponseException2() throws Exception { - String input = "{\"StatusCode\":\"600\"}"; - assertTrue(msgParser.parsePostResponse(input).getStatusMessage().contains("Error parsing response")); - } - - @Test(expected = SvcLogicException.class) - public void TestParseGetResponseException() throws Exception { - String input = "{\"StatusCode\":\"100\",\"StatusMessage\":\"TestMessage\"}"; - assertTrue(msgParser.parseGetResponse(input).getStatusMessage().contains("Invalid FinalResponse code")); - } - - @Test - public void TestParseGetResponseExec() throws Exception { - String input = "{\"StatusCode\":\"200\",\"StatusMessage\":\"TestMessage\"}"; - assertTrue(msgParser.parseGetResponse(input).getStatusMessage().contains("Results not found in GET for response")); - } - - @Test - public void TestParseGetResponse() throws Exception { - String input = "{" - + " \"StatusCode\": \"200\"," - + " \"StatusMessage\": \"TestMessage\"," - + " \"Results\": {" - + " \"host\": {" - + " \"StatusCode\": \"200\"," - + " \"StatusMessage\": \"SUCCESS\"" - + " }" - + " }," - + " \"Output\": {" - + " \"results-output\": {" - + " \"OutputResult\": \"TestOutPutResult\"" - + " }" - + " }" - + "}"; - assertTrue(msgParser.parseGetResponse(input).getOutput().contains("TestOutPutResult")); - } - - @Test - public void TestParseGetResponseEx() throws Exception { - String input = "{\"StatusCode\":\"200\",\"StatusMessage\":\"TestMessage\",\"Results\":{\"host\":\"TestHost\"}}"; - assertTrue(msgParser.parseGetResponse(input).getStatusMessage().contains("Error processing response message")); - } - - @Test - public void TestParseGetResponseJsonEx() throws Exception { - String input = "{\"StatusCode\":\"200\",\"StatusMessage\":\"TestMessage\",\"Results\":\"host\":\"TestHost\"}"; - assertTrue(msgParser.parseGetResponse(input).getStatusMessage().contains("Error parsing response")); - } - - @Test - public void TestParseGetResponseResultEx() throws Exception { - String input = "{" - + " \"StatusCode\": \"200\"," - + " \"StatusMessage\": \"TestMessage\"," - + " \"Results\": {" - + " \"host\": {" - + " \"StatusCode\": \"100\"," - + " \"StatusMessage\": \"Failure\"" - + " }" - + " }," - + " \"Output\": {" - + " \"results-output\": {" - + " \"OutputResult\": \"TestOutPutResult\"" - + " }" - + " }" - + "}"; - assertTrue(msgParser.parseGetResponse(input).getOutput().contains("TestOutPutResult")); - } - - @Test - public void testParseOptionalParam() throws Exception { - Map params = new HashMap<>(); - params.put("AgentUrl", "TestAgentUrl"); - params.put("PlaybookName", "TestPlaybookName"); - params.put("User", "TestUser"); - params.put("Password", "TestPass"); - params.put("Timeout", "3"); - params.put("Version", "1"); - params.put("InventoryNames", "VNFC"); - - JSONObject jObject = msgParser.reqMessage(params); - assertEquals("1", jObject.get("Version")); - assertEquals("VNFC", jObject.get("InventoryNames")); - } - - @Test - public void testParseOptionalParamForEnvParameters() throws Exception { - Map params = new HashMap<>(); - params.put("AgentUrl", "TestAgentUrl"); - params.put("PlaybookName", "TestPlaybookName"); - params.put("User", "TestUser"); - params.put("Password", "TestPass"); - params.put("EnvParameters", "{name:value}"); - - JSONObject result = msgParser.reqMessage(params); - assertEquals("TestAgentUrl", result.get("AgentUrl")); - assertEquals("TestPlaybookName", result.get("PlaybookName")); - assertEquals("TestUser", result.get("User")); - assertEquals("TestPass", result.get("Password")); - } - - @Test - public void TestParseGetConfigResponseResult() throws Exception { - String input = "{" - + " \"StatusCode\": \"200\"," - + " \"StatusMessage\": \"TestMessage\"," - + " \"Results\": {" - + " \"host\": {" - + " \"StatusCode\": \"200\"," - + " \"StatusMessage\": \"SUCCESS\"," - + " \"Output\": {" - + " \"info\": {" - + " \"configData\": {" - + " \"abc\": \"TestOutPutResult\"," - + " \"rtr\": \"vfc\"" - + " }" - + " }" - + " }" - + " }" - + " }" - + "}"; - assertTrue(msgParser.parseGetResponse(input).getConfigData().contains("abc")); - } - - @Test - public void testParseOptionalParamTest2() throws Exception { - - Map params = new HashMap<>(); - params.put("AgentUrl", "TestAgentUrl"); - params.put("PlaybookName", "TestPlaybookName"); - params.put("User", "TestUser"); - params.put("Password", "TestPass"); - //params.put("Timeout", "3"); - params.put("Version", "1"); - params.put("InventoryNames", "VNFC"); - params.put("Timeout", "4"); - params.put("EnvParameters", "{ \"userID\": \"$0002\", \"vnf-type\" : \"\", \"vnf\" : \"abc\" }"); - params.put("NodeList", "${Nodelist}"); - - JSONObject jObject = msgParser.reqMessage(params); - assertEquals("1", jObject.get("Version")); - assertEquals("4", jObject.get("Timeout")); - } - - @Test - public void testReqUriResultWithIPs() throws Exception { - Map params = new HashMap<>(); - params.put("AgentUrl", "http://xx:yy:zz"); - params.put("Id", "TestId"); - params.put("User", "TestUser"); - params.put("Password", "TestPass"); - String serverIp = "10.0.2.3"; - String actual = msgParser.reqUriResultWithIP(params, serverIp); - String expected = "http://10.0.2.3:yy:zz?Id=TestId&Type=GetResult"; - assertEquals(expected, actual); - } - -} diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/model/TestAnsibleResult.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/model/TestAnsibleResult.java deleted file mode 100644 index 301cce135..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/model/TestAnsibleResult.java +++ /dev/null @@ -1,45 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.adapter.ansible.model; - -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResult; - -import static org.junit.Assert.assertEquals; - -public class TestAnsibleResult { - private AnsibleResult ansibleResult; - - @Before - public void setUp() { - ansibleResult = new AnsibleResult(10, "message", "result", "outputData"); - } - - @Test - public void testServerIp() { - ansibleResult.setServerIp("10.0.9.87"); - assertEquals("10.0.9.87", ansibleResult.getServerIp()); - } - -} diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/test/ExecutorHarness.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/test/ExecutorHarness.java deleted file mode 100644 index b6476d9dc..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/test/ExecutorHarness.java +++ /dev/null @@ -1,166 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - - -package org.onap.ccsdk.test; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -/** - * This class is used as a test harness to wrap the call to an executor node. - */ - -public class ExecutorHarness { - - /** - * The executor to be tested - */ - private SvcLogicJavaPlugin executor; - - /** - * The collection of all exec methods found on the class - */ - private final Map methods; - - /** - * Create the harness and initialize it - * - * @throws SecurityException If a security manager, s, is present and any of the following conditions is met: - *

    - *
  • invocation of s.checkMemberAccess(this, Member.DECLARED) denies access to the declared field
  • - *
  • the caller's class loader is not the same as or an ancestor of the class loader for the current - * class and invocation of s.checkPackageAccess() denies access to the package of this class
  • - *
- * @throws NoSuchFieldException if a field with the specified name is not found. - * @throws IllegalAccessException if this Field object is enforcing Java language access control and the underlying field is either - * inaccessible or final. - * @throws IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field - * (or a subclass or implementor thereof), or if an unwrapping conversion fails. - */ - @SuppressWarnings("nls") - public ExecutorHarness() throws NoSuchFieldException, SecurityException, IllegalArgumentException, - IllegalAccessException { - methods = new HashMap<>(); - new SvcLogicContext(); - - Class contextClass = SvcLogicContext.class; - /** - * The field of the class being tested that contains the reference to the logger to be used. This is modified to - * point to our interception logger for the test. - */ - Field contextLogger = contextClass.getDeclaredField("LOG"); - contextLogger.setAccessible(true); - /** - * The interception logger that buffers all messages logged and allows us to look at them as part of the test case. - */ - InterceptLogger logger = new InterceptLogger(); - contextLogger.set(null, logger); - } - - /** - * Convenience constructor - * - * @param executor The executor to be tested by the harness - * - * @throws SecurityException If a security manager, s, is present and any of the following conditions is met: - *
    - *
  • invocation of s.checkMemberAccess(this, Member.DECLARED) denies access to the declared field
  • - *
  • the caller's class loader is not the same as or an ancestor of the class loader for the current - * class and invocation of s.checkPackageAccess() denies access to the package of this class
  • - *
- * @throws NoSuchFieldException if a field with the specified name is not found. - * @throws IllegalAccessException if this Field object is enforcing Java language access control and the underlying field is either - * inaccessible or final. - * @throws IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field - * (or a subclass or implementor thereof), or if an unwrapping conversion fails. - */ - public ExecutorHarness(SvcLogicJavaPlugin executor) throws NoSuchFieldException, SecurityException, - IllegalArgumentException, IllegalAccessException { - this(); - setExecutor(executor); - } - - /** - * @return The java plugin class to be executed - */ - public SvcLogicJavaPlugin getExecutor() { - return executor; - } - - /** - * @param executor The java plugin class to be executed - */ - public void setExecutor(SvcLogicJavaPlugin executor) { - this.executor = executor; - scanExecutor(); - } - - /** - * @return The set of all methods that meet the signature requirements - */ - public List getExecMethodNames() { - List names = new ArrayList<>(); - names.addAll(methods.keySet()); - return names; - } - - /** - * Returns an indication if the named method is a valid executor method that could be called from a DG execute node - * - * @param methodName The method name to be validated - * - * @return True if the method name meets the signature requirements, false if the method either does not exist or - * does not meet the requirements. - */ - public boolean isExecMethod(String methodName) { - return methods.containsKey(methodName); - } - - /** - * This method scans the executor class hierarchy to locate all methods that match the required signature of the - * executor and records these methods in a map. - */ - private void scanExecutor() { - methods.clear(); - Class executorClass = executor.getClass(); - Method[] publicMethods = executorClass.getMethods(); - for (Method method : publicMethods) { - if (method.getReturnType().equals(Void.class)) { - Class[] paramTypes = method.getParameterTypes(); - if (paramTypes.length == 2) { - if (Map.class.isAssignableFrom(paramTypes[0]) - && SvcLogicContext.class.isAssignableFrom(paramTypes[1])) { - methods.put(method.getName(), method); - } - } - } - } - } - -} diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/test/InterceptLogger.java b/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/test/InterceptLogger.java deleted file mode 100644 index 3ed32376a..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/test/InterceptLogger.java +++ /dev/null @@ -1,447 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SLI - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - - -package org.onap.ccsdk.test; - -import ch.qos.logback.classic.Level; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.List; -import org.slf4j.Marker; - -/** - * This class is used as an intercept logger that can be used in testing to intercept and record all messages that are - * logged, thus allowing a junit test case to examine the log output and make assertions. - */ -public class InterceptLogger implements org.slf4j.Logger { - - /** - * The list of all intercepted log events - */ - private final List events; - - /** - * Create the intercept logger - */ - public InterceptLogger() { - events = new ArrayList<>(1000); - } - - /** - * @return Returns all intercepted log events - */ - public List getLogRecords() { - return events; - } - - /** - * Clears all log events - */ - public void clear() { - events.clear(); - } - - @Override - public void debug(Marker marker, String msg) { - debug(msg); - } - - @Override - public void debug(Marker marker, String format, Object arg) { - debug(MessageFormat.format(format, arg)); - } - - @Override - public void debug(Marker marker, String format, Object... arguments) { - debug(MessageFormat.format(format, arguments)); - } - - @Override - public void debug(Marker marker, String format, Object arg1, Object arg2) { - debug(MessageFormat.format(format, arg1, arg2)); - } - - @Override - public void debug(Marker marker, String msg, Throwable t) { - debug(msg, t); - } - - @Override - public void debug(String msg) { - events.add(new LogRecord(Level.DEBUG, msg)); - } - - @Override - public void debug(String format, Object arg) { - events.add(new LogRecord(Level.DEBUG, MessageFormat.format(format, arg))); - } - - @Override - public void debug(String format, Object... arguments) { - events.add(new LogRecord(Level.DEBUG, MessageFormat.format(format, arguments))); - } - - @Override - public void debug(String format, Object arg1, Object arg2) { - events.add(new LogRecord(Level.DEBUG, MessageFormat.format(format, arg1, arg2))); - } - - @Override - public void debug(String msg, Throwable t) { - events.add(new LogRecord(Level.DEBUG, msg, t)); - } - - @Override - public void error(Marker marker, String msg) { - error(msg); - } - - @Override - public void error(Marker marker, String format, Object arg) { - error(format, arg); - } - - @Override - public void error(Marker marker, String format, Object... arguments) { - error(format, arguments); - } - - @Override - public void error(Marker marker, String format, Object arg1, Object arg2) { - error(format, arg1, arg2); - } - - @Override - public void error(Marker marker, String msg, Throwable t) { - events.add(new LogRecord(Level.ERROR, msg, t)); - } - - @Override - public void error(String msg) { - events.add(new LogRecord(Level.ERROR, msg)); - } - - @Override - public void error(String format, Object arg) { - events.add(new LogRecord(Level.ERROR, MessageFormat.format(format, arg))); - } - - @Override - public void error(String format, Object... arguments) { - events.add(new LogRecord(Level.ERROR, MessageFormat.format(format, arguments))); - } - - @Override - public void error(String format, Object arg1, Object arg2) { - events.add(new LogRecord(Level.ERROR, MessageFormat.format(format, arg1, arg2))); - } - - @Override - public void error(String msg, Throwable t) { - events.add(new LogRecord(Level.ERROR, msg, t)); - } - - @Override - public String getName() { - return null; - } - - @Override - public void info(Marker marker, String msg) { - info(msg); - } - - @Override - public void info(Marker marker, String format, Object arg) { - info(format, arg); - } - - @Override - public void info(Marker marker, String format, Object... arguments) { - info(format, arguments); - } - - @Override - public void info(Marker marker, String format, Object arg1, Object arg2) { - info(format, arg1, arg2); - } - - @Override - public void info(Marker marker, String msg, Throwable t) { - events.add(new LogRecord(Level.INFO, msg, t)); - } - - @Override - public void info(String msg) { - events.add(new LogRecord(Level.INFO, msg)); - } - - @Override - public void info(String format, Object arg) { - events.add(new LogRecord(Level.INFO, MessageFormat.format(format, arg))); - } - - @Override - public void info(String format, Object... arguments) { - events.add(new LogRecord(Level.INFO, MessageFormat.format(format, arguments))); - } - - @Override - public void info(String format, Object arg1, Object arg2) { - events.add(new LogRecord(Level.INFO, MessageFormat.format(format, arg1, arg2))); - } - - @Override - public void info(String msg, Throwable t) { - events.add(new LogRecord(Level.INFO, msg, t)); - } - - @Override - public boolean isDebugEnabled() { - return true; - } - - @Override - public boolean isDebugEnabled(Marker marker) { - return true; - } - - @Override - public boolean isErrorEnabled() { - return true; - } - - @Override - public boolean isErrorEnabled(Marker marker) { - return true; - } - - @Override - public boolean isInfoEnabled() { - return true; - } - - @Override - public boolean isInfoEnabled(Marker marker) { - return true; - } - - @Override - public boolean isTraceEnabled() { - return true; - } - - @Override - public boolean isTraceEnabled(Marker marker) { - return true; - } - - @Override - public boolean isWarnEnabled() { - return true; - } - - @Override - public boolean isWarnEnabled(Marker marker) { - return true; - } - - @Override - public void trace(Marker marker, String msg) { - trace(msg); - } - - @Override - public void trace(Marker marker, String format, Object arg) { - trace(format, arg); - } - - @Override - public void trace(Marker marker, String format, Object... argArray) { - trace(format, argArray); - } - - @Override - public void trace(Marker marker, String format, Object arg1, Object arg2) { - trace(format, arg1, arg2); - } - - @Override - public void trace(Marker marker, String msg, Throwable t) { - trace(msg, t); - } - - @Override - public void trace(String msg) { - events.add(new LogRecord(Level.TRACE, msg)); - } - - @Override - public void trace(String format, Object arg) { - events.add(new LogRecord(Level.TRACE, MessageFormat.format(format, arg))); - } - - @Override - public void trace(String format, Object... arguments) { - events.add(new LogRecord(Level.TRACE, MessageFormat.format(format, arguments))); - } - - @Override - public void trace(String format, Object arg1, Object arg2) { - events.add(new LogRecord(Level.TRACE, MessageFormat.format(format, arg1, arg2))); - } - - @Override - public void trace(String msg, Throwable t) { - events.add(new LogRecord(Level.TRACE, msg, t)); - } - - @Override - public void warn(Marker marker, String msg) { - warn(msg); - } - - @Override - public void warn(Marker marker, String format, Object arg) { - warn(format, arg); - } - - @Override - public void warn(Marker marker, String format, Object... arguments) { - warn(format, arguments); - } - - @Override - public void warn(Marker marker, String format, Object arg1, Object arg2) { - warn(format, arg1, arg2); - } - - @Override - public void warn(Marker marker, String msg, Throwable t) { - events.add(new LogRecord(Level.WARN, msg, t)); - } - - @Override - public void warn(String msg) { - events.add(new LogRecord(Level.WARN, msg)); - } - - @Override - public void warn(String format, Object arg) { - events.add(new LogRecord(Level.WARN, MessageFormat.format(format, arg))); - } - - @Override - public void warn(String format, Object... arguments) { - events.add(new LogRecord(Level.WARN, MessageFormat.format(format, arguments))); - } - - @Override - public void warn(String format, Object arg1, Object arg2) { - events.add(new LogRecord(Level.WARN, MessageFormat.format(format, arg1, arg2))); - } - - @Override - public void warn(String msg, Throwable t) { - events.add(new LogRecord(Level.WARN, msg, t)); - } - - /** - * This inner class represents an intercepted log event - */ - public class LogRecord { - private Level level; - private String message; - private long timestamp; - private Throwable t; - - public LogRecord(Level level, String message) { - setLevel(level); - setTimestamp(System.currentTimeMillis()); - setMessage(message); - } - - public LogRecord(Level level, String message, Throwable t) { - this(level, message); - setThrowable(t); - } - - /** - * @return the value of level - */ - public Level getLevel() { - return level; - } - - /** - * @param level the value for level - */ - public void setLevel(Level level) { - this.level = level; - } - - /** - * @return the value of message - */ - public String getMessage() { - return message; - } - - /** - * @param message the value for message - */ - public void setMessage(String message) { - this.message = message; - } - - /** - * @return the value of timestamp - */ - public long getTimestamp() { - return timestamp; - } - - /** - * @param timestamp the value for timestamp - */ - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - - /** - * @return the value of t - */ - public Throwable getThrowable() { - return t; - } - - /** - * @param t the value for t - */ - public void setThrowable(Throwable t) { - this.t = t; - } - - } - -} diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/cert b/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/cert deleted file mode 100644 index cc2921c4b..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/cert +++ /dev/null @@ -1,125 +0,0 @@ -Certificate: - Data: - Version: 3 (0x2) - Serial Number: 1 (0x1) - Signature Algorithm: sha1WithRSAEncryption - Issuer: C=FR, ST=Alsace, L=Strasbourg, O=www.freelan.org, OU=freelan, CN=Freelan Sample Certificate Authority/emailAddress=contact@freelan.org - Validity - Not Before: Apr 27 10:31:18 2012 GMT - Not After : Apr 25 10:31:18 2022 GMT - Subject: C=FR, ST=Alsace, O=www.freelan.org, OU=freelan, CN=alice/emailAddress=contact@freelan.org - Subject Public Key Info: - Public Key Algorithm: rsaEncryption - Public-Key: (4096 bit) - Modulus: - 00:dd:6d:bd:f8:80:fa:d7:de:1b:1f:a7:a3:2e:b2: - 02:e2:16:f6:52:0a:3c:bf:a6:42:f8:ca:dc:93:67: - 4d:60:c3:4f:8d:c3:8a:00:1b:f1:c4:4b:41:6a:69: - d2:69:e5:3f:21:8e:c5:0b:f8:22:37:ad:b6:2c:4b: - 55:ff:7a:03:72:bb:9a:d3:ec:96:b9:56:9f:cb:19: - 99:c9:32:94:6f:8f:c6:52:06:9f:45:03:df:fd:e8: - 97:f6:ea:d6:ba:bb:48:2b:b5:e0:34:61:4d:52:36: - 0f:ab:87:52:25:03:cf:87:00:87:13:f2:ca:03:29: - 16:9d:90:57:46:b5:f4:0e:ae:17:c8:0a:4d:92:ed: - 08:a6:32:23:11:71:fe:f2:2c:44:d7:6c:07:f3:0b: - 7b:0c:4b:dd:3b:b4:f7:37:70:9f:51:b6:88:4e:5d: - 6a:05:7f:8d:9b:66:7a:ab:80:20:fe:ee:6b:97:c3: - 49:7d:78:3b:d5:99:97:03:75:ce:8f:bc:c5:be:9c: - 9a:a5:12:19:70:f9:a4:bd:96:27:ed:23:02:a7:c7: - 57:c9:71:cf:76:94:a2:21:62:f6:b8:1d:ca:88:ee: - 09:ad:46:2f:b7:61:b3:2c:15:13:86:9f:a5:35:26: - 5a:67:f4:37:c8:e6:80:01:49:0e:c7:ed:61:d3:cd: - bc:e4:f8:be:3f:c9:4e:f8:7d:97:89:ce:12:bc:ca: - b5:c6:d2:e0:d9:b3:68:3c:2e:4a:9d:b4:5f:b8:53: - ee:50:3d:bf:dd:d4:a2:8a:b6:a0:27:ab:98:0c:b3: - b2:58:90:e2:bc:a1:ad:ff:bd:8e:55:31:0f:00:bf: - 68:e9:3d:a9:19:9a:f0:6d:0b:a2:14:6a:c6:4c:c6: - 4e:bd:63:12:a5:0b:4d:97:eb:42:09:79:53:e2:65: - aa:24:34:70:b8:c1:ab:23:80:e7:9c:6c:ed:dc:82: - aa:37:04:b8:43:2a:3d:2a:a8:cc:20:fc:27:5d:90: - 26:58:f9:b7:14:e2:9e:e2:c1:70:73:97:e9:6b:02: - 8e:d3:52:59:7b:00:ec:61:30:f1:56:3f:9c:c1:7c: - 05:c5:b1:36:c8:18:85:cf:61:40:1f:07:e8:a7:06: - 87:df:9a:77:0b:a9:64:72:03:f6:93:fc:e0:02:59: - c1:96:ec:c0:09:42:3e:30:a2:7f:1b:48:2f:fe:e0: - 21:8f:53:87:25:0d:cb:ea:49:f5:4a:9b:d0:e3:5f: - ee:78:18:e5:ba:71:31:a9:04:98:0f:b1:ad:67:52: - a0:f2:e3:9c:ab:6a:fe:58:84:84:dd:07:3d:32:94: - 05:16:45:15:96:59:a0:58:6c:18:0e:e3:77:66:c7: - b3:f7:99 - Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - Netscape Comment: - OpenSSL Generated Certificate - X509v3 Subject Key Identifier: - 59:5F:C9:13:BA:1B:CC:B9:A8:41:4A:8A:49:79:6A:36:F6:7D:3E:D7 - X509v3 Authority Key Identifier: - keyid:23:6C:2D:3D:3E:29:5D:78:B8:6C:3E:AA:E2:BB:2E:1E:6C:87:F2:53 - - Signature Algorithm: sha1WithRSAEncryption - 13:e7:02:45:3e:a7:ab:bd:b8:da:e7:ef:74:88:ac:62:d5:dd: - 10:56:d5:46:07:ec:fa:6a:80:0c:b9:62:be:aa:08:b4:be:0b: - eb:9a:ef:68:b7:69:6f:4d:20:92:9d:18:63:7a:23:f4:48:87: - 6a:14:c3:91:98:1b:4e:08:59:3f:91:80:e9:f4:cf:fd:d5:bf: - af:4b:e4:bd:78:09:71:ac:d0:81:e5:53:9f:3e:ac:44:3e:9f: - f0:bf:5a:c1:70:4e:06:04:ef:dc:e8:77:05:a2:7d:c5:fa:80: - 58:0a:c5:10:6d:90:ca:49:26:71:84:39:b7:9a:3e:e9:6f:ae: - c5:35:b6:5b:24:8c:c9:ef:41:c3:b1:17:b6:3b:4e:28:89:3c: - 7e:87:a8:3a:a5:6d:dc:39:03:20:20:0b:c5:80:a3:79:13:1e: - f6:ec:ae:36:df:40:74:34:87:46:93:3b:a3:e0:a4:8c:2f:43: - 4c:b2:54:80:71:76:78:d4:ea:12:28:d8:f2:e3:80:55:11:9b: - f4:65:dc:53:0e:b4:4c:e0:4c:09:b4:dc:a0:80:5c:e6:b5:3b: - 95:d3:69:e4:52:3d:5b:61:86:02:e5:fd:0b:00:3a:fa:b3:45: - cc:c9:a3:64:f2:dc:25:59:89:58:0d:9e:6e:28:3a:55:45:50: - 5f:88:67:2a:d2:e2:48:cc:8b:de:9a:1b:93:ae:87:e1:f2:90: - 50:40:d9:0f:44:31:53:46:ad:62:4e:8d:48:86:19:77:fc:59: - 75:91:79:35:59:1d:e3:4e:33:5b:e2:31:d7:ee:52:28:5f:0a: - 70:a7:be:bb:1c:03:ca:1a:18:d0:f5:c1:5b:9c:73:04:b6:4a: - e8:46:52:58:76:d4:6a:e6:67:1c:0e:dc:13:d0:61:72:a0:92: - cb:05:97:47:1c:c1:c9:cf:41:7d:1f:b1:4d:93:6b:53:41:03: - 21:2b:93:15:63:08:3e:2c:86:9e:7b:9f:3a:09:05:6a:7d:bb: - 1c:a7:b7:af:96:08:cb:5b:df:07:fb:9c:f2:95:11:c0:82:81: - f6:1b:bf:5a:1e:58:cd:28:ca:7d:04:eb:aa:e9:29:c4:82:51: - 2c:89:61:95:b6:ed:a5:86:7c:7c:48:1d:ec:54:96:47:79:ea: - fc:7f:f5:10:43:0a:9b:00:ef:8a:77:2e:f4:36:66:d2:6a:a6: - 95:b6:9f:23:3b:12:e2:89:d5:a4:c1:2c:91:4e:cb:94:e8:3f: - 22:0e:21:f9:b8:4a:81:5c:4c:63:ae:3d:05:b2:5c:5c:54:a7: - 55:8f:98:25:55:c4:a6:90:bc:19:29:b1:14:d4:e2:b0:95:e4: - ff:89:71:61:be:8a:16:85 ------BEGIN CERTIFICATE----- -MIIGJzCCBA+gAwIBAgIBATANBgkqhkiG9w0BAQUFADCBsjELMAkGA1UEBhMCRlIx -DzANBgNVBAgMBkFsc2FjZTETMBEGA1UEBwwKU3RyYXNib3VyZzEYMBYGA1UECgwP -d3d3LmZyZWVsYW4ub3JnMRAwDgYDVQQLDAdmcmVlbGFuMS0wKwYDVQQDDCRGcmVl -bGFuIFNhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxIjAgBgkqhkiG9w0BCQEW -E2NvbnRhY3RAZnJlZWxhbi5vcmcwHhcNMTIwNDI3MTAzMTE4WhcNMjIwNDI1MTAz -MTE4WjB+MQswCQYDVQQGEwJGUjEPMA0GA1UECAwGQWxzYWNlMRgwFgYDVQQKDA93 -d3cuZnJlZWxhbi5vcmcxEDAOBgNVBAsMB2ZyZWVsYW4xDjAMBgNVBAMMBWFsaWNl -MSIwIAYJKoZIhvcNAQkBFhNjb250YWN0QGZyZWVsYW4ub3JnMIICIjANBgkqhkiG -9w0BAQEFAAOCAg8AMIICCgKCAgEA3W29+ID6194bH6ejLrIC4hb2Ugo8v6ZC+Mrc -k2dNYMNPjcOKABvxxEtBamnSaeU/IY7FC/giN622LEtV/3oDcrua0+yWuVafyxmZ -yTKUb4/GUgafRQPf/eiX9urWurtIK7XgNGFNUjYPq4dSJQPPhwCHE/LKAykWnZBX -RrX0Dq4XyApNku0IpjIjEXH+8ixE12wH8wt7DEvdO7T3N3CfUbaITl1qBX+Nm2Z6 -q4Ag/u5rl8NJfXg71ZmXA3XOj7zFvpyapRIZcPmkvZYn7SMCp8dXyXHPdpSiIWL2 -uB3KiO4JrUYvt2GzLBUThp+lNSZaZ/Q3yOaAAUkOx+1h08285Pi+P8lO+H2Xic4S -vMq1xtLg2bNoPC5KnbRfuFPuUD2/3dSiiragJ6uYDLOyWJDivKGt/72OVTEPAL9o -6T2pGZrwbQuiFGrGTMZOvWMSpQtNl+tCCXlT4mWqJDRwuMGrI4DnnGzt3IKqNwS4 -Qyo9KqjMIPwnXZAmWPm3FOKe4sFwc5fpawKO01JZewDsYTDxVj+cwXwFxbE2yBiF -z2FAHwfopwaH35p3C6lkcgP2k/zgAlnBluzACUI+MKJ/G0gv/uAhj1OHJQ3L6kn1 -SpvQ41/ueBjlunExqQSYD7GtZ1Kg8uOcq2r+WISE3Qc9MpQFFkUVllmgWGwYDuN3 -Zsez95kCAwEAAaN7MHkwCQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3BlblNT -TCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFFlfyRO6G8y5qEFKikl5 -ajb2fT7XMB8GA1UdIwQYMBaAFCNsLT0+KV14uGw+quK7Lh5sh/JTMA0GCSqGSIb3 -DQEBBQUAA4ICAQAT5wJFPqervbja5+90iKxi1d0QVtVGB+z6aoAMuWK+qgi0vgvr -mu9ot2lvTSCSnRhjeiP0SIdqFMORmBtOCFk/kYDp9M/91b+vS+S9eAlxrNCB5VOf -PqxEPp/wv1rBcE4GBO/c6HcFon3F+oBYCsUQbZDKSSZxhDm3mj7pb67FNbZbJIzJ -70HDsRe2O04oiTx+h6g6pW3cOQMgIAvFgKN5Ex727K4230B0NIdGkzuj4KSML0NM -slSAcXZ41OoSKNjy44BVEZv0ZdxTDrRM4EwJtNyggFzmtTuV02nkUj1bYYYC5f0L -ADr6s0XMyaNk8twlWYlYDZ5uKDpVRVBfiGcq0uJIzIvemhuTrofh8pBQQNkPRDFT -Rq1iTo1Ihhl3/Fl1kXk1WR3jTjNb4jHX7lIoXwpwp767HAPKGhjQ9cFbnHMEtkro -RlJYdtRq5mccDtwT0GFyoJLLBZdHHMHJz0F9H7FNk2tTQQMhK5MVYwg+LIaee586 -CQVqfbscp7evlgjLW98H+5zylRHAgoH2G79aHljNKMp9BOuq6SnEglEsiWGVtu2l -hnx8SB3sVJZHeer8f/UQQwqbAO+Kdy70NmbSaqaVtp8jOxLiidWkwSyRTsuU6D8i -DiH5uEqBXExjrj0FslxcVKdVj5glVcSmkLwZKbEU1OKwleT/iXFhvooWhQ== ------END CERTIFICATE----- diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/org/onap/appc/asdc-client-cert.crt b/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/org/onap/appc/asdc-client-cert.crt deleted file mode 100644 index 941c1d8f4..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/org/onap/appc/asdc-client-cert.crt +++ /dev/null @@ -1,10 +0,0 @@ ------BEGIN CERTIFICATE----- - MIIBezCCASWgAwIBAgIQyWD8dLUoqpJFyDxrfRlrsTANBgkqhkiG9w0BAQQFADAW - MRQwEgYDVQQDEwtSb290IEFnZW5jeTAeFw0wMTEwMTkxMjU5MjZaFw0zOTEyMzEy - MzU5NTlaMBoxGDAWBgNVBAMTD1Jvb3RDZXJ0aWZpY2F0ZTBcMA0GCSqGSIb3DQEB - AQUAA0sAMEgCQQC+NFKszPjatUZKWmyWaFjir1wB93FX2u5SL+GMjgUsMs1JcTKQ - Kh0cnnQKknNkV4cTW4NPn31YCoB1+0KA3mknAgMBAAGjSzBJMEcGA1UdAQRAMD6A - EBLkCS0GHR1PAI1hIdwWZGOhGDAWMRQwEgYDVQQDEwtSb290IEFnZW5jeYIQBjds - AKoAZIoRz7jUqlw19DANBgkqhkiG9w0BAQQFAANBACJxAfP57yqaT9N+nRgAOugM - JG0aN3/peCIvL3p29epRL2xoWFvxpUUlsH2I39OZ6b8+twWCebhkv1I62segXAk= - -----END CERTIFICATE----- \ No newline at end of file diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/org/onap/appc/asdc-client.jks b/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/org/onap/appc/asdc-client.jks deleted file mode 100644 index eb0a0d35a..000000000 Binary files a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/org/onap/appc/asdc-client.jks and /dev/null differ diff --git a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/properties/ansible-adapter-test.properties b/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/properties/ansible-adapter-test.properties deleted file mode 100644 index ef4bfb2e9..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-bundle/src/test/resources/properties/ansible-adapter-test.properties +++ /dev/null @@ -1,109 +0,0 @@ -### -# ============LICENSE_START======================================================= -# ONAP : SLI -# ================================================================================ -# Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# 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. -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. -# ============LICENSE_END========================================================= - -### -# -# Default properties for the APP-C Provider Adapter -# -# ------------------------------------------------------------------------------------------------- -# -# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded -# to supply configuration options -org.onap.appc.bootstrap.file=appc.properties -org.onap.appc.bootstrap.path=${user.home},/opt/opendaylight/current/properties,. -appc.application.name=APPC -#Define ansible property -org.onap.appc.adapter.ansible.clientType=appc -org.onap.appc.adapter.ansible.trustStore=src/test/resources/org/onap/appc/asdc-client.jks -org.onap.appc.adapter.ansible.trustStore.trustPasswd=Aa123456 -org.onap.appc.adapter.ansible.cert=src/test/resources/org/onap/appc/asdc-client-cert.crt -org.onap.appc.adapter.ansible.identity=http://localhost:9081/v2.0 -org.onap.appc.adapter.ansible.username=appc -org.onap.appc.adapter.ansible.password=appc -# -# Define the message resource bundle name to be loaded -org.onap.appc.resources=org/onap/appc/i18n/MessageResources -# -# The name of the adapter. -org.onap.appc.provider.adaptor.name=org.onap.appc.appc_ansible_adapter -# -# Set up the logging environment -# -org.onap.appc.logging.file=org/onap/appc/logback.xml -org.onap.appc.logging.path=${user.home};etc;../etc -org.onap.appc.logger=org.onap.appc -org.onap.appc.security.logger=org.onap.appc.security -# -# The minimum and maximum provider/tenant context pool sizes. Min=1 means that as soon -# as the provider/tenant is referenced a Context is opened and added to the pool. Max=0 -# means that the upper bound on the pool is unbounded. -org.onap.appc.provider.min.pool=1 -org.onap.appc.provider.max.pool=0 -# -# The following properties are used to configure the retry logic for connection to the -# IaaS provider(s). The retry delay property is the amount of time, in seconds, the -# application waits between retry attempts. The retry limit is the number of retries -# that are allowed before the request is failed. -org.onap.appc.provider.retry.delay=30 -org.onap.appc.provider.retry.limit=10 -# -# The trusted hosts list for SSL access when a certificate is not provided. -# -provider.trusted.hosts=* -# -# The amount of time, in seconds, to wait for a server state change (start->stop, stop->start, etc). -# If the server does not change state to a valid state within the alloted time, the operation -# fails. -org.onap.appc.server.state.change.timeout=300 -# -# The amount of time to wait, in seconds, between subsequent polls to the OpenStack provider -# to refresh the status of a resource we are waiting on. -# -org.onap.appc.openstack.poll.interval=20 -# -# The connection information to connect to the provider we are using. These properties -# are "structured" properties, in that the name is a compound name, where the nodes -# of the name can be ordered (1, 2, 3, ...). All of the properties with the same ordinal -# position are defining the same entity. For example, provider1.type and provider1.name -# are defining the same provider, whereas provider2.name and provider2.type are defining -# the values for a different provider. Any number of providers can be defined in this -# way. -# -# Don't change these 2 right now since they are hard coded in the DG -#provider1.type=appc -#provider1.name=appc -#These you can change -#provider1.identity=appc -#provider1.tenant1.name=appc -#provider1.tenant1.userid=appc -#provider1.tenant1.password=appc -# After a change to the provider make sure to recheck these values with an api call to provider1.identity/tokens -test.expected-regions=1 -test.expected-endpoints=1 -#Your OpenStack IP -#test.ip=192.168.1.2 -# Your OpenStack Platform's Keystone Port (default is 5000) -#test.port=5000 -#test.tenantid=abcde12345fghijk6789lmnopq123rst -#test.vmid=abc12345-1234-5678-890a-abcdefg12345 -# Port 8774 below is default port for OpenStack's Nova API Service -#test.url=http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345 - diff --git a/adaptors/ansible-adapter/ansible-adapter-installer/pom.xml b/adaptors/ansible-adapter/ansible-adapter-installer/pom.xml deleted file mode 100644 index ae9365882..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-installer/pom.xml +++ /dev/null @@ -1,150 +0,0 @@ - - - - - 4.0.0 - - - org.onap.ccsdk.parent - odlparent-lite - 2.2.0-SNAPSHOT - - - - org.onap.ccsdk.sli.adaptors - ansible-adapter-installer - 1.3.0-SNAPSHOT - pom - - ccsdk-sli-adaptors :: ${project.artifactId} - - - ccsdk-ansible-adapter - ${application.name} - mvn:org.onap.ccsdk.sli.adaptors/${features.boot}/${project.version}/xml/features - false - - - - - - org.onap.ccsdk.sli.adaptors - ansible-adapter-bundle - ${project.version} - - - - - - - - maven-assembly-plugin - - - maven-repo-zip - - single - - package - - true - true - stage/${application.name}-${project.version} - - src/assembly/assemble_mvnrepo_zip.xml - - - - - installer-zip - - single - - package - - false - true - ${application.name}-${project.version} - - src/assembly/assemble_installer_zip.xml - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-dependencies - - copy-dependencies - - prepare-package - - false - ${project.build.directory}/assembly/system - false - true - true - true - false - false - org.onap.ccsdk.sli.adaptors - - provided - - - - - - maven-resources-plugin - - - copy-version - - copy-resources - - - validate - - ${basedir}/target/stage - - - src/main/resources/scripts - - install-feature.sh - - true - - - - - - - - - diff --git a/adaptors/ansible-adapter/ansible-adapter-installer/src/assembly/assemble_installer_zip.xml b/adaptors/ansible-adapter/ansible-adapter-installer/src/assembly/assemble_installer_zip.xml deleted file mode 100644 index 322fa76eb..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-installer/src/assembly/assemble_installer_zip.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - adapter - - zip - - - - false - - - - target/stage/ - ${application.name} - 755 - - *.sh - - - - target/stage/ - ${application.name} - 644 - - *.sh - - - - - - - diff --git a/adaptors/ansible-adapter/ansible-adapter-installer/src/assembly/assemble_mvnrepo_zip.xml b/adaptors/ansible-adapter/ansible-adapter-installer/src/assembly/assemble_mvnrepo_zip.xml deleted file mode 100644 index ec65e79e1..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-installer/src/assembly/assemble_mvnrepo_zip.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - repo - - zip - - - - false - - - - target/assembly/ - . - - - - - - diff --git a/adaptors/ansible-adapter/ansible-adapter-installer/src/main/resources/scripts/install-feature.sh b/adaptors/ansible-adapter/ansible-adapter-installer/src/main/resources/scripts/install-feature.sh deleted file mode 100644 index c8214c520..000000000 --- a/adaptors/ansible-adapter/ansible-adapter-installer/src/main/resources/scripts/install-feature.sh +++ /dev/null @@ -1,42 +0,0 @@ -### -# ============LICENSE_START======================================================= -# ONAP : APPC -# ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# Copyright (C) 2017 Amdocs -# ============================================================================= -# 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. -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. -# ============LICENSE_END========================================================= -### - -#!/bin/bash - -ODL_HOME=${ODL_HOME:-/opt/opendaylight/current} -ODL_KARAF_CLIENT=${ODL_KARAF_CLIENT:-${ODL_HOME}/bin/client} -INSTALLERDIR=$(dirname $0) - -REPOZIP=${INSTALLERDIR}/${features.boot}-${project.version}.zip - -if [ -f ${REPOZIP} ] -then - unzip -n -d ${ODL_HOME} ${REPOZIP} -else - echo "ERROR : repo zip ($REPOZIP) not found" - exit 1 -fi - -${ODL_KARAF_CLIENT} feature:repo-add ${features.repositories} -${ODL_KARAF_CLIENT} feature:install ${features.boot} diff --git a/adaptors/ansible-adapter/pom.xml b/adaptors/ansible-adapter/pom.xml deleted file mode 100644 index 5fd02ba09..000000000 --- a/adaptors/ansible-adapter/pom.xml +++ /dev/null @@ -1,181 +0,0 @@ - - - - - 4.0.0 - - - org.onap.ccsdk.parent - odlparent-lite - 2.2.0-SNAPSHOT - - - - org.onap.ccsdk.sli.adaptors - ansible-adaptor - 1.3.0-SNAPSHOT - pom - - ccsdk-sli-adaptors :: ${project.artifactId} - Abstractions to interact with Ansible server via REST - - - ansible-adapter-bundle - ansible-adapter-installer - - - - - - org.onap.appc - ansible-adapter-features - ${project.version} - xml - features - - - org.onap.appc - ansible-adapter-provider - ${project.version} - - - - - - - - JCenter - JCenter Repository - http://jcenter.bintray.com - - - - - - - - - - - - - maven-javadoc-plugin - - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.antlr - antlr4 - ${antlr.version} - - - org.antlr - antlr4-runtime - 4.3 - - - - - - - javadoc-no-fork - test-javadoc-no-fork - - - - aggregate - - aggregate - test-aggregate - - - - - - org.apache.maven.plugins - maven-jxr-plugin - 2.3 - - - aggregate - - aggregate - test-aggregate - - - - - - - maven-surefire-plugin - - - - org.apache.maven.plugins - maven-changelog-plugin - 2.3 - - - dual-report - - range - 30 - - - changelog - file-activity - - - - - - - org.codehaus.mojo - taglist-maven-plugin - 2.4 - - - - - diff --git a/adaptors/ansible-adaptor/.pydevproject b/adaptors/ansible-adaptor/.pydevproject new file mode 100644 index 000000000..d001f0aea --- /dev/null +++ b/adaptors/ansible-adaptor/.pydevproject @@ -0,0 +1,5 @@ + + +Default +python interpreter + diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/.gitignore b/adaptors/ansible-adaptor/ansible-adaptor-bundle/.gitignore new file mode 100644 index 000000000..255b54097 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/.gitignore @@ -0,0 +1,25 @@ +# ============LICENSE_START========================================== +# ONAP : APPC +# =================================================================== +# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the License); +# you may not use this software 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. +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# ============LICENSE_END============================================ +/bin/ +/target/ +/target-ide/ +/.settings/ diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/pom.xml b/adaptors/ansible-adaptor/ansible-adaptor-bundle/pom.xml new file mode 100644 index 000000000..be24ed12d --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/pom.xml @@ -0,0 +1,123 @@ + + + + + 4.0.0 + + + org.onap.ccsdk.parent + binding-parent + 2.2.0-SNAPSHOT + + + + org.onap.ccsdk.sli.adaptors + ansible-adaptor-bundle + 1.3.0-SNAPSHOT + bundle + + ccsdk-sli-adaptors :: ${project.artifactId} + + + + + org.onap.ccsdk.sli.core + sli-core-artifacts + ${project.version} + pom + import + + + + + + com.att.eelf + eelf-core + + + commons-codec + commons-codec + + + commons-logging + commons-logging + + + org.apache.httpcomponents + httpclient + + + org.onap.ccsdk.sli.core + sli-common + + + org.onap.ccsdk.sli.core + sli-provider + + + org.osgi + org.osgi.core + + + org.slf4j + slf4j-api + + + org.slf4j + jcl-over-slf4j + + + org.json + json + + + com.google.guava + guava + + + + org.glassfish.jersey.core + jersey-common + test + + + org.codehaus.jackson + jackson-jaxrs + test + + + junit + junit + test + + + + org.mockito + mockito-core + 1.10.19 + test + + + org.powermock + powermock-reflect + test + + + org.powermock + powermock-api-mockito2 + test + + + diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdaptor.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdaptor.java new file mode 100644 index 000000000..55dbc4257 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdaptor.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.ansible; + +import java.util.Map; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +/** + * This interface defines the operations that the Ansible adaptor exposes. + */ +public interface AnsibleAdaptor extends SvcLogicJavaPlugin { + /** + * Returns the symbolic name of the adaptor + * + * @return The adaptor name + */ + String getAdaptorName(); + + /* Method to post request for execution of Playbook */ + void reqExec(Map params, SvcLogicContext ctx) throws SvcLogicException; + + /* Method to get result of a playbook execution request */ + void reqExecResult(Map params, SvcLogicContext ctx) throws SvcLogicException; + + /* Method to get log of a playbook execution request */ + void reqExecLog(Map params, SvcLogicContext ctx) throws SvcLogicException; + + /* Method to get output of a playbook execution request */ + void reqExecOutput(Map params, SvcLogicContext ctx) throws SvcLogicException; + +} diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdaptorConstants.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdaptorConstants.java new file mode 100644 index 000000000..e10e35a04 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdaptorConstants.java @@ -0,0 +1,50 @@ +package org.onap.ccsdk.sli.adaptors.ansible; + +public class AnsibleAdaptorConstants { + + public static final String ID = "Id"; + public static final String USER = "User"; + public static final String PSWD = "Password"; + public static final String SERVERIP = "ServerIP"; + public static final String AGENT_URL = "AgentUrl"; + public static final String NODE_LIST = "NodeList"; + public static final String ANSIBLE_SERVER = "AnsibleServer"; + + public static final String APPC_PROPS = "/appc.properties"; + public static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; + public static final String PROPDIR = System.getenv(SDNC_CONFIG_DIR); + + public static final String ACTION = "Action"; + public static final String OUTPUT = "Output"; + public static final String TIMEOUT = "Timeout"; + public static final String VERSION = "Version"; + + public static final String FAILURE = "failure"; + public static final String SUCCESS = "success"; + public static final String STATUS_CODE = "StatusCode"; + public static final String STATUS_MESSAGE = "StatusMessage"; + + public static final String EXTRA_VARS = "ExtraVars"; + public static final String PLAYBOOK_NAME = "PlaybookName"; + public static final String AUTO_NODE_LIST = "AutoNodeList"; + public static final String ENV_PARAMETERS = "EnvParameters"; + public static final String FILE_PARAMETERS = "FileParameters"; + public static final String INVENTORY_NAMES = "InventoryNames"; + public static final String LOCAL_PARAMETERS = "LocalParameters"; + + public static final String ID_ATTRIBUTE_NAME = "org.onap.appc.adaptor.ansible.Id"; + public static final String LOG_ATTRIBUTE_NAME = "org.onap.appc.adaptor.ansible.log"; + public static final String OUTPUT_ATTRIBUTE_NAME = "org.onap.appc.adaptor.ansible.output"; + public static final String TIMEOUT_PROPERTY_NAME = "org.onap.appc.adaptor.ansible.timeout"; + public static final String MESSAGE_ATTRIBUTE_NAME = "org.onap.appc.adaptor.ansible.message"; + public static final String RESULTS_ATTRIBUTE_NAME = "org.onap.appc.adaptor.ansible.results"; + public static final String RESULT_CODE_ATTRIBUTE_NAME = "org.onap.appc.adaptor.ansible.result.code"; + + public static final String TRUSTSTORE_PROPERTY_NAME = "org.onap.appc.adaptor.ansible.trustStore"; + public static final String CLIENT_TYPE_PROPERTY_NAME = "org.onap.appc.adaptor.ansible.clientType"; + public static final String POLL_INTERVAL_PROPERTY_NAME = "org.onap.appc.adaptor.ansible.pollInterval"; + public static final String SOCKET_TIMEOUT_PROPERTY_NAME = "org.onap.appc.adaptor.ansible.socketTimeout"; + public static final String TRUSTSTORE_PASS_PROPERTY_NAME = "org.onap.appc.adaptor.ansible.trustStore.trustPasswd"; + + +} diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdaptorPropertiesProvider.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdaptorPropertiesProvider.java new file mode 100644 index 000000000..024215ae3 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdaptorPropertiesProvider.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.ansible; + +import java.util.Properties; + +public interface AnsibleAdaptorPropertiesProvider { + + Properties getProperties(); + +} diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdaptorImpl.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdaptorImpl.java new file mode 100644 index 000000000..790b10f92 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdaptorImpl.java @@ -0,0 +1,620 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.ansible.impl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import org.apache.commons.lang.StringUtils; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdaptor; +import org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdaptorPropertiesProvider; +import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleMessageParser; +import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResult; +import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResultCodes; +import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleServerEmulator; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.utils.encryption.EncryptionTool; + +import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdaptorConstants.*; + +/** + * This class implements the {@link AnsibleAdaptor} interface. This interface defines the behaviors + * that our service provides. + */ +public class AnsibleAdaptorImpl implements AnsibleAdaptor { + + /** + * Adaptor Name + */ + private static final String Adaptor_NAME = "Ansible Adaptor"; + private static final String APPC_EXCEPTION_CAUGHT = "APPCException caught"; + + /** + * The logger to be used + */ + private static final EELFLogger logger = EELFManager.getInstance().getLogger(AnsibleAdaptorImpl.class); + private int defaultTimeout = 600 * 1000; + private int defaultSocketTimeout = 60 * 1000; + private int defaultPollInterval = 60 * 1000; + /** + * Ansible API Message Handlers + **/ + private AnsibleMessageParser messageProcessor; + + /** + * indicator whether in test mode + **/ + private boolean testMode = false; + + /** + * server emulator object to be used if in test mode + **/ + private AnsibleServerEmulator testServer; + + /** + * This default constructor is used as a work around because the activator wasn't getting called + */ + public AnsibleAdaptorImpl() { + initialize(new AnsibleAdaptorPropertiesProviderImpl()); + } + + /** + * Instantiates a new Ansible adaptor. + * + * @param propProvider the prop provider + */ + public AnsibleAdaptorImpl(AnsibleAdaptorPropertiesProvider propProvider) { + initialize(propProvider); + } + + /** + * Used for jUnit test and testing interface + * + * @param mode the mode + */ + public AnsibleAdaptorImpl(boolean mode) { + testMode = mode; + testServer = new AnsibleServerEmulator(); + messageProcessor = new AnsibleMessageParser(); + } + + /** + * Returns the symbolic name of the adaptor + * + * @return The adaptor name + */ + @Override + public String getAdaptorName() { + return Adaptor_NAME; + } + + @SuppressWarnings("static-method") + private void doFailure(SvcLogicContext svcLogic, int code, String message) throws SvcLogicException { + svcLogic.markFailed(); + svcLogic.setAttribute(RESULT_CODE_ATTRIBUTE_NAME, Integer.toString(code)); + svcLogic.setAttribute(MESSAGE_ATTRIBUTE_NAME, message); + throw new SvcLogicException("Ansible Adaptor Error = " + message); + } + + /** + * initialize the Ansible adaptor based on default and over-ride configuration data + */ + private void initialize(AnsibleAdaptorPropertiesProvider propProvider) { + Properties props = propProvider.getProperties(); + // Create the message processor instance + messageProcessor = new AnsibleMessageParser(); + + //continuing for checking defaultTimeout + try { + String timeoutStr = props.getProperty(TIMEOUT_PROPERTY_NAME); + defaultTimeout = Integer.parseInt(timeoutStr) * 1000; + } catch (Exception e) { + defaultTimeout = 600 * 1000; + logger.error("Error while reading time out property", e); + } + //continuing for checking defaultSocketTimeout + try { + String timeoutStr = props.getProperty(SOCKET_TIMEOUT_PROPERTY_NAME); + defaultSocketTimeout = Integer.parseInt(timeoutStr) * 1000; + } catch (Exception e) { + defaultSocketTimeout = 60 * 1000; + logger.error("Error while reading socket time out property", e); + } + //continuing for checking defaultPollInterval + try { + String timeoutStr = props.getProperty(POLL_INTERVAL_PROPERTY_NAME); + defaultPollInterval = Integer.parseInt(timeoutStr) * 1000; + } catch (Exception e) { + defaultPollInterval = 60 * 1000; + logger.error("Error while reading poll interval property", e); + } + logger.info("Initialized Ansible Adaptor"); + } + + private ConnectionBuilder getHttpConn(int timeout, String serverIP) { + String path = PROPDIR + APPC_PROPS; + File propFile = new File(path); + Properties props = new Properties(); + InputStream input; + try { + input = new FileInputStream(propFile); + props.load(input); + } catch (Exception ex) { + logger.error("Error while reading appc.properties file {}", ex.getMessage()); + } + // Create the http client instance + // type of client is extracted from the property file parameter + // org.onap.appc.adaptor.ansible.clientType + // It can be : + // 1. TRUST_ALL (trust all SSL certs). To be used ONLY in dev + // 2. TRUST_CERT (trust only those whose certificates have been stored in the trustStore file) + // 3. DEFAULT (trust only well known certificates). This is standard behavior to which it will + // revert. To be used in PROD + ConnectionBuilder httpClientLocal = null; + try { + String clientType = props.getProperty(CLIENT_TYPE_PROPERTY_NAME); + logger.info("Ansible http client type set to {}", clientType); + if ("TRUST_ALL".equals(clientType)) { + logger.info("Creating http client to trust ALL ssl certificates. WARNING. This should be done only in dev environments"); + httpClientLocal = new ConnectionBuilder(1, timeout); + } else if ("TRUST_CERT".equals(clientType)) { + // set path to keystore file + String trustStoreFile = props.getProperty(TRUSTSTORE_PROPERTY_NAME); + String key = props.getProperty(TRUSTSTORE_PASS_PROPERTY_NAME); + char[] trustStorePasswd = EncryptionTool.getInstance().decrypt(key).toCharArray(); + logger.info("Creating http client with trust manager from {}", trustStoreFile); + httpClientLocal = new ConnectionBuilder(trustStoreFile, trustStorePasswd, timeout, serverIP); + } else { + logger.info("Creating http client with default behaviour"); + httpClientLocal = new ConnectionBuilder(0, timeout); + } + } catch (Exception e) { + logger.error("Error Getting HTTP Connection Builder due to Unknown Exception", e); + } + + logger.info("Got HTTP Connection Builder"); + return httpClientLocal; + } + + // Public Method to post request to execute playbook. Posts the following back + // to Svc context memory + // org.onap.appc.adaptor.ansible.req.code : 100 if successful + // org.onap.appc.adaptor.ansible.req.messge : any message + // org.onap.appc.adaptor.ansible.req.Id : a unique uuid to reference the request + @Override + public void reqExec(Map params, SvcLogicContext ctx) throws SvcLogicException { + String playbookName = StringUtils.EMPTY; + String payload = StringUtils.EMPTY; + String agentUrl = StringUtils.EMPTY; + String user = StringUtils.EMPTY; + String pswd = StringUtils.EMPTY; + String id = StringUtils.EMPTY; + + try { + // create json object to send request + JSONObject jsonPayload = messageProcessor.reqMessage(params); + logger.info("Initial Payload = {}", jsonPayload.toString()); + + agentUrl = (String) jsonPayload.remove("AgentUrl"); + id = jsonPayload.getString("Id"); + user = (String) jsonPayload.remove(USER); + pswd = (String) jsonPayload.remove(PSWD); + if (StringUtils.isNotBlank(pswd)) { + pswd = EncryptionTool.getInstance().decrypt(pswd); + } + String timeout = jsonPayload.getString("Timeout"); + if (StringUtils.isBlank(timeout)) { + timeout = "600"; + } + + String autoNodeList = (String) jsonPayload.remove("AutoNodeList"); + if (Boolean.parseBoolean(autoNodeList)) { + JSONArray generatedNodeList = generateNodeList(params, ctx); + if (generatedNodeList.length() > 0) { + jsonPayload.put("NodeList", generatedNodeList); + jsonPayload.put("InventoryNames", "VM"); + } else { + doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), + "Auto generation of Node List Failed - no elements on the list"); + } + } else { + logger.debug("Auto Node List is DISABLED"); + } + + payload = jsonPayload.toString(); + ctx.setAttribute("AnsibleTimeout", timeout); + logger.info("Updated Payload = {} timeout = {}", payload, timeout); + } catch (SvcLogicException e) { + logger.error(APPC_EXCEPTION_CAUGHT, e); + doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), + "Error constructing request for execution of playbook due to missing mandatory parameters. Reason = " + + e.getMessage()); + } catch (JSONException e) { + logger.error("JSONException caught", e); + doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), + "Error constructing request for execution of playbook due to invalid JSON block. Reason = " + + e.getMessage()); + } catch (NumberFormatException e) { + logger.error("NumberFormatException caught", e); + doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), + "Error constructing request for execution of playbook due to invalid parameter values. Reason = " + + e.getMessage()); + } + + int code = -1; + String message = StringUtils.EMPTY; + + try { + // post the test request + logger.info("Posting ansible request = {} to url = {}", payload, agentUrl); + AnsibleResult testResult = postExecRequest(agentUrl, payload, user, pswd); + if (testResult != null) { + logger.info("Received response on ansible post request {}", testResult.getStatusMessage()); + // Process if HTTP was successful + if (testResult.getStatusCode() == 200) { + testResult = messageProcessor.parsePostResponse(testResult.getStatusMessage()); + } else { + doFailure(ctx, testResult.getStatusCode(), + "Error posting request. Reason = " + testResult.getStatusMessage()); + } + + code = testResult.getStatusCode(); + message = testResult.getStatusMessage(); + ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, testResult.getOutput()); + ctx.setAttribute(SERVERIP, StringUtils.defaultIfBlank(testResult.getServerIp(), "")); + // Check status of test request returned by Agent + if (code == AnsibleResultCodes.PENDING.getValue()) { + logger.info("Submission of Test {} successful.", playbookName); + // test request accepted. We are in asynchronous case + } else { + doFailure(ctx, code, "Request for execution of playbook rejected. Reason = " + message); + } + } else { + doFailure(ctx, code, "Ansible Test result is null"); + } + } catch (SvcLogicException e) { + logger.error(APPC_EXCEPTION_CAUGHT, e); + doFailure(ctx, AnsibleResultCodes.UNKNOWN_EXCEPTION.getValue(), + "Exception encountered when posting request for execution of playbook. Reason = " + e.getMessage()); + } + + ctx.setAttribute(RESULT_CODE_ATTRIBUTE_NAME, Integer.toString(code)); + ctx.setAttribute(MESSAGE_ATTRIBUTE_NAME, message); + ctx.setAttribute(ID_ATTRIBUTE_NAME, id); + } + + /** + * Method is used to automatically generate NodeList section base on the svc context + */ + private JSONArray generateNodeList(Map params, SvcLogicContext ctx) throws SvcLogicException { + String vfModuleId = StringUtils.trimToNull(params.get("vf-module-id")); + String vnfcName = StringUtils.trimToNull(params.get("vnfc-name")); + String vServerId = StringUtils.trimToNull(params.get("vserver-id")); + String vnfcType = StringUtils.trimToNull(params.get("vnfc-type")); + + JSONArray result = new JSONArray(); + logger.info("GENERATING NODE LIST"); + logger.debug("Auto Node List filtering parameter vserver-id {} | vnfc-name {} | vnfc-type {} | vf-module-id {}", + vServerId, vnfcName, vnfcType, vfModuleId); + + Map candidates = new HashMap<>(); + for (int i = 0; ; i++) { + String vmKey = "tmp.vnfInfo.vm[" + i + "]"; + logger.info("Looking for attributes of: {}", vmKey); + if (ctx.getAttribute(vmKey + ".vnfc-name") != null) { + String debugText = "Auto Node List candidate "; + String vmVnfcName = ctx.getAttribute(vmKey + ".vnfc-name"); + String vmVnfcIpv4Address = ctx.getAttribute(vmKey + ".vnfc-ipaddress-v4-oam-vip"); + String vmVnfcType = ctx.getAttribute(vmKey + ".vnfc-type"); + + if (vmVnfcName != null && vmVnfcIpv4Address != null && vmVnfcType != null + && !vmVnfcName.equals("") && !vmVnfcIpv4Address.equals("") && !vmVnfcType.equals("")) { + if (vServerId != null) { + String vmVserverId = ctx.getAttribute(vmKey + ".vserver-id"); + if (!vServerId.equals(vmVserverId)) { + logger.debug("{}{} dropped. vserver-id mismatch", debugText, vmVnfcName); + continue; + } + } + if (vfModuleId != null) { + String vmVfModuleId = ctx.getAttribute(vmKey + ".vf-module-id"); + if (!vfModuleId.equals(vmVfModuleId)) { + logger.debug("{}{} dropped. vf-module-id mismatch", debugText, vmVnfcName); + continue; + } + } + if (vnfcName != null && !vmVnfcName.equals(vnfcName)) { + logger.debug("{}{} dropped. vnfc-name mismatch", debugText, vmVnfcName); + continue; + } + if (vnfcType != null && !vmVnfcType.equals(vnfcType)) { + logger.debug("{}{} dropped. vnfc-type mismatch", debugText, vmVnfcType); + continue; + } + + logger.info("{}{} [{},{}]", debugText, vmVnfcName, vmVnfcIpv4Address, vmVnfcType); + + JSONObject vnfTypeCandidates; + JSONArray vmList; + if (!candidates.containsKey(vmVnfcType)) { + vnfTypeCandidates = new JSONObject(); + vmList = new JSONArray(); + vnfTypeCandidates.put("site", "site"); + vnfTypeCandidates.put("vnfc-type", vmVnfcType); + vnfTypeCandidates.put("vm-info", vmList); + candidates.put(vmVnfcType, vnfTypeCandidates); + } else { + vnfTypeCandidates = candidates.get(vmVnfcType); + vmList = (JSONArray) vnfTypeCandidates.get("vm-info"); + } + + JSONObject candidate = new JSONObject(); + candidate.put("ne_id", vmVnfcName); + candidate.put("fixed_ip_address", vmVnfcIpv4Address); + vmList.put(candidate); + } else { + logger.warn("Incomplete information for Auto Node List candidate {}", vmKey); + } + } else { + break; + } + } + + for (JSONObject vnfcCandidates : candidates.values()) { + result.put(vnfcCandidates); + } + + logger.info("GENERATING NODE LIST COMPLETED"); + return result; + } + + /** + * Public method to query status of a specific request It blocks till the Ansible Server + * responds or the session times out (non-Javadoc) + * + * @see org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdaptor#reqExecResult(java.util.Map, + * org.onap.ccsdk.sli.core.sli.SvcLogicContext) + */ + @Override + public void reqExecResult(Map params, SvcLogicContext ctx) throws SvcLogicException { + // Get URI + String reqUri; + + try { + String serverIp = ctx.getAttribute(SERVERIP); + if (StringUtils.isNotBlank(serverIp)) { + reqUri = messageProcessor.reqUriResultWithIP(params, serverIp); + } else { + reqUri = messageProcessor.reqUriResult(params); + } + logger.info("Got uri {}", reqUri); + } catch (SvcLogicException e) { + logger.error(APPC_EXCEPTION_CAUGHT, e); + doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), + "Error constructing request to retrieve result due to missing parameters. Reason = " + + e.getMessage()); + return; + } catch (NumberFormatException e) { + logger.error("NumberFormatException caught", e); + doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), + "Error constructing request to retrieve result due to invalid parameters value. Reason = " + + e.getMessage()); + return; + } + + int code; + String message; + String output; + String configData; + String results = StringUtils.EMPTY; + String finalResponse = StringUtils.EMPTY; + try { + // Try to retrieve the test results (modify the URL for that) + AnsibleResult testResult = queryServer(reqUri, params.get(USER), + EncryptionTool.getInstance().decrypt(params.get(PSWD)), ctx); + code = testResult.getStatusCode(); + message = testResult.getStatusMessage(); + + if (code == 200 || code == 400 || "FINISHED".equalsIgnoreCase(message)) { + logger.info("Parsing response from ansible Server = {}", message); + // Valid HTTP. process the Ansible message + testResult = messageProcessor.parseGetResponse(message); + code = testResult.getStatusCode(); + message = testResult.getStatusMessage(); + results = testResult.getResults(); + output = testResult.getOutput(); + configData = testResult.getConfigData(); + if ((StringUtils.isBlank(output)) || (output.trim().equalsIgnoreCase("{}"))) { + finalResponse = results; + } else { + finalResponse = output; + } + logger.info("configData from ansible's response = {}", configData); + ctx.setAttribute("device-running-config", configData); + } + logger.info("Request response = " + message); + } catch (SvcLogicException e) { + logger.error(APPC_EXCEPTION_CAUGHT, e); + ctx.setAttribute(RESULTS_ATTRIBUTE_NAME, results); + ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, finalResponse); + doFailure(ctx, AnsibleResultCodes.UNKNOWN_EXCEPTION.getValue(), + "Exception encountered retrieving result : " + e.getMessage()); + return; + } + + // We were able to get and process the results. Determine if playbook succeeded + + if (code == AnsibleResultCodes.FINAL_SUCCESS.getValue()) { + message = String.format("Ansible Request %s finished with Result = %s, Message = %s", params.get("Id"), + SUCCESS, message); + logger.info(message); + } else { + logger.info(String.format("Ansible Request %s finished with Result %s, Message = %s", params.get("Id"), + FAILURE, message)); + ctx.setAttribute(RESULTS_ATTRIBUTE_NAME, results); + ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, finalResponse); + doFailure(ctx, code, message); + return; + } + + // In case of 200, 400, FINISHED return 400 + ctx.setAttribute(RESULT_CODE_ATTRIBUTE_NAME, Integer.toString(400)); + ctx.setAttribute(MESSAGE_ATTRIBUTE_NAME, message); + ctx.setAttribute(RESULTS_ATTRIBUTE_NAME, results); + ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, finalResponse); + ctx.markSuccess(); + } + + /** + * Public method to get logs from playbook execution for a specific request + *

+ * It blocks till the Ansible Server responds or the session times out very similar to + * reqExecResult logs are returned in the DG context variable org.onap.appc.adaptor.ansible.log + */ + @Override + public void reqExecLog(Map params, SvcLogicContext ctx) throws SvcLogicException { + String reqUri = StringUtils.EMPTY; + try { + reqUri = messageProcessor.reqUriLog(params); + logger.info("Retrieving results from {}", reqUri); + } catch (Exception e) { + logger.error("Exception caught", e); + doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), e.getMessage()); + } + + queryServerAndProcessResult(params, ctx, reqUri, LOG_ATTRIBUTE_NAME); + } + + /** + * Public method to get output from playbook execution for a specific request + *

+ * It blocks till the Ansible Server responds or the session times out very similar to + * reqExecResult and output is returned in the DG context variable org.onap.appc.adaptor.ansible.output + */ + @Override + public void reqExecOutput(Map params, SvcLogicContext ctx) throws SvcLogicException { + String reqUri = StringUtils.EMPTY; + try { + reqUri = messageProcessor.reqUriOutput(params); + logger.info("Retrieving results from {}", reqUri); + } catch (Exception e) { + logger.error("Exception caught", e); + doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), e.getMessage()); + } + + queryServerAndProcessResult(params, ctx, reqUri, OUTPUT_ATTRIBUTE_NAME); + } + + /** + * Method that posts the request + */ + private AnsibleResult postExecRequest(String agentUrl, String payload, String user, String pswd) { + AnsibleResult testResult = null; + ConnectionBuilder httpClientLocal = getHttpConn(defaultSocketTimeout, ""); + if (!testMode) { + if (httpClientLocal != null) { + httpClientLocal.setHttpContext(user, pswd); + testResult = httpClientLocal.post(agentUrl, payload); + httpClientLocal.close(); + } + } else { + testResult = testServer.post(payload); + } + return testResult; + } + + private void queryServerAndProcessResult(Map params, SvcLogicContext ctx, String reqUri, String attributeName) + throws SvcLogicException { + try { + // Try to retrieve the test results (modify the url for that) + AnsibleResult testResult = queryServer(reqUri, params.get(USER), + EncryptionTool.getInstance().decrypt(params.get(PSWD)), ctx); + String message = testResult.getStatusMessage(); + logger.info("Request output = {}", message); + ctx.setAttribute(attributeName, message); + ctx.markSuccess(); + } catch (Exception e) { + logger.error("Exception caught: {}", e.getMessage(), e); + doFailure(ctx, AnsibleResultCodes.UNKNOWN_EXCEPTION.getValue(), + String.format("Exception encountered retrieving output: %s", e.getMessage())); + } + } + + /** + * Method to query Ansible server + */ + private AnsibleResult queryServer(String agentUrl, String user, String pswd, SvcLogicContext ctx) { + AnsibleResult testResult = new AnsibleResult(); + int timeout; + try { + timeout = Integer.parseInt(ctx.getAttribute("AnsibleTimeout")) * 1000; + } catch (Exception e) { + timeout = defaultTimeout; + } + long endTime = System.currentTimeMillis() + timeout; + + while (System.currentTimeMillis() < endTime) { + String serverIP = ctx.getAttribute(SERVERIP); + ConnectionBuilder httpClientLocal = getHttpConn(defaultSocketTimeout, serverIP); + logger.info("Querying ansible GetResult URL = {}", agentUrl); + + if (!testMode) { + if (httpClientLocal != null) { + httpClientLocal.setHttpContext(user, pswd); + testResult = httpClientLocal.get(agentUrl); + httpClientLocal.close(); + } + } else { + testResult = testServer.get(agentUrl); + } + if (testResult.getStatusCode() != AnsibleResultCodes.IO_EXCEPTION.getValue() + && testResult.getStatusCode() != AnsibleResultCodes.PENDING.getValue()) { + break; + } + + try { + Thread.sleep(defaultPollInterval); + } catch (InterruptedException ex) { + logger.error("Thread Interrupted Exception", ex); + Thread.currentThread().interrupt(); + } + + } + if (testResult.getStatusCode() == AnsibleResultCodes.PENDING.getValue()) { + testResult.setStatusCode(AnsibleResultCodes.IO_EXCEPTION.getValue()); + testResult.setStatusMessage("Request timed out"); + } + + return testResult; + } + +} diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdaptorPropertiesProviderImpl.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdaptorPropertiesProviderImpl.java new file mode 100644 index 000000000..d33fdd855 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdaptorPropertiesProviderImpl.java @@ -0,0 +1,208 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.ansible.impl; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Properties; +import org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdaptorPropertiesProvider; +import org.onap.ccsdk.sli.core.sli.ConfigurationException; +import org.onap.ccsdk.sli.core.utils.JREFileResolver; +import org.onap.ccsdk.sli.core.utils.KarafRootFileResolver; +import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver; +import org.onap.ccsdk.sli.core.utils.common.CoreDefaultFileResolver; +import org.onap.ccsdk.sli.core.utils.common.EnvProperties; +import org.onap.ccsdk.sli.core.utils.common.SdncConfigEnvVarFileResolver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Responsible for determining the properties file to use and instantiating the + * SqlResource Service. The priority for properties file + * resolution is as follows: + * + *

    + *
  1. A directory identified by the system environment variable + * SDNC_CONFIG_DIR
  2. + *
  3. The default directory DEFAULT_DBLIB_PROP_DIR
  4. + *
  5. A directory identified by the JRE argument + * sql-resource.properties
  6. + *
  7. A sql-resource.properties file located in the karaf root + * directory
  8. + *
+ */ +public class AnsibleAdaptorPropertiesProviderImpl implements AnsibleAdaptorPropertiesProvider { + + private static final Logger LOG = LoggerFactory.getLogger(AnsibleAdaptorPropertiesProviderImpl.class); + + /** + * The name of the properties file for database configuration + */ + private static final String ANSIBLE_Adaptor_PROPERTIES = "ansible-adaptor.properties"; + + /** + * A prioritized list of strategies for resolving sql-resource properties files. + */ + private final List ansibleAdaptorPropertiesFileResolvers = new ArrayList<>(); + + /** + * The configuration properties for the db connection. + */ + private Properties properties; + + /** + * Set up the prioritized list of strategies for resolving dblib properties + * files. + */ + public AnsibleAdaptorPropertiesProviderImpl() { + ansibleAdaptorPropertiesFileResolvers + .add(new SdncConfigEnvVarFileResolver("Using property file (1) from environment variable")); + ansibleAdaptorPropertiesFileResolvers + .add(new CoreDefaultFileResolver("Using property file (2) from default directory")); + ansibleAdaptorPropertiesFileResolvers + .add(new JREFileResolver("Using property file (3) from JRE argument", AnsibleAdaptorPropertiesProviderImpl.class)); + ansibleAdaptorPropertiesFileResolvers + .add(new KarafRootFileResolver("Using property file (4) from karaf root", this)); + + // determines properties file as according to the priority described in the + // class header comment + final File propertiesFile = determinePropertiesFile(); + if (propertiesFile != null) { + try (FileInputStream fileInputStream = new FileInputStream(propertiesFile)) { + properties = new EnvProperties(); + properties.load(fileInputStream); + } catch (final IOException e) { + LOG.error("Failed to load properties for file: {}", propertiesFile, + new ConfigurationException("Failed to load properties for file: " + propertiesFile, e)); + } + } else { + // Try to read properties as resource + InputStream propStr = getClass().getResourceAsStream("/" + ANSIBLE_Adaptor_PROPERTIES); + if (propStr != null) { + properties = new EnvProperties(); + try { + properties.load(propStr); + propStr.close(); + } catch (IOException e) { + properties = null; + } + } + } + if (properties == null) { + reportFailure(new ConfigurationException( + "Missing configuration properties resource(3): " + ANSIBLE_Adaptor_PROPERTIES)); + LOG.info("Defaulting org.onap.appc.adaptor.ansible.clientType to TRUST_ALL"); + properties = new Properties(); + properties.setProperty("org.onap.appc.adaptor.ansible.clientType", "TRUST_ALL"); + } + + } + + /** + * Instantiates a new Ansible adaptor properties provider. + * + * @param configFilePath the config file path + */ + public AnsibleAdaptorPropertiesProviderImpl(String configFilePath) { + properties = new EnvProperties(); + try { + properties.load(new FileInputStream(configFilePath)); + } catch (IOException e) { + properties = null; + } + if (properties == null) { + reportFailure(new ConfigurationException( + "Missing configuration properties resource(3): " + ANSIBLE_Adaptor_PROPERTIES)); + LOG.info("Defaulting org.onap.appc.adaptor.ansible.clientType to TRUST_ALL"); + properties = new Properties(); + properties.setProperty("org.onap.appc.adaptor.ansible.clientType", "TRUST_ALL"); + } + + } + + /** + * Reports the method chosen for properties resolution to the + * Logger. + * + * @param message Some user friendly message + * @param fileOptional The file location of the chosen properties file + * + * @return the file location of the chosen properties file + */ + private static File reportSuccess(final String message, final Optional fileOptional) { + if (fileOptional.isPresent()) { + final File file = fileOptional.get(); + LOG.info("{} {}", message, file.getPath()); + return file; + } + return null; + } + + /** + * Reports fatal errors. This is the case in which no properties file could be + * found. + * + * @param configurationException An exception describing what went wrong during resolution + */ + private static void reportFailure(final ConfigurationException configurationException) { + LOG.error("{}", "Missing configuration properties resource(3)", configurationException); + } + + /** + * Extract svclogic config properties. + * + * @return the svclogic config properties + */ + public Properties getProperties() { + return properties; + } + + /** + * Determines the sql-resource properties file to use based on the following priority: + *
    + *
  1. A directory identified by the system environment variable + * SDNC_CONFIG_DIR
  2. + *
  3. The default directory DEFAULT_DBLIB_PROP_DIR
  4. + *
  5. A directory identified by the JRE argument + * sql-resource.properties
  6. + *
  7. A sql-resource.properties file located in the karaf root + * directory
  8. + *
+ */ + File determinePropertiesFile() { + for (final PropertiesFileResolver propertiesFileResolver : ansibleAdaptorPropertiesFileResolvers) { + final Optional fileOptional = propertiesFileResolver.resolveFile(ANSIBLE_Adaptor_PROPERTIES); + if (fileOptional.isPresent()) { + return reportSuccess(propertiesFileResolver.getSuccessfulResolutionMessage(), fileOptional); + } + } + + return null; + } + +} diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/ConnectionBuilder.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/ConnectionBuilder.java new file mode 100644 index 000000000..1fbf20633 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/ConnectionBuilder.java @@ -0,0 +1,235 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.ansible.impl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import java.io.Closeable; +import java.io.FileInputStream; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import javax.net.ssl.SSLContext; +import org.apache.commons.lang.StringUtils; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContexts; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.json.JSONObject; +import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResult; +import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResultCodes; +import org.onap.ccsdk.sli.core.utils.PathValidator; + +/** + * Returns a custom http client + * - based on options + * - can create one with ssl using an X509 certificate that does NOT have a known CA + * - create one which trusts ALL SSL certificates + * - return default httpclient (which only trusts known CAs from default cacerts file for process) this is the default + * option + **/ + +public class ConnectionBuilder implements Closeable { + private static final String STATUS_CODE_KEY = "StatusCode"; + private static final EELFLogger logger = EELFManager.getInstance().getLogger(ConnectionBuilder.class); + + private final CloseableHttpClient httpClient; + private final HttpClientContext httpContext = new HttpClientContext(); + + /** + * Constructor that initializes an http client based on certificate + **/ + public ConnectionBuilder(String certFile, int timeout) throws KeyStoreException, CertificateException, IOException, + KeyManagementException, NoSuchAlgorithmException { + + /* Point to the certificate */ + try (FileInputStream fs = new FileInputStream(certFile)) { + /* Generate a certificate from the X509 */ + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + X509Certificate cert = (X509Certificate) cf.generateCertificate(fs); + + /* Create a keystore object and load the certificate there */ + KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); + keystore.load(null, null); + keystore.setCertificateEntry("cacert", cert); + + SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(keystore).build(); + SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext, + SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); + + RequestConfig config = RequestConfig.custom().setSocketTimeout(timeout).build(); + httpClient = HttpClients.custom().setDefaultRequestConfig(config).setSSLSocketFactory(factory).build(); + } + } + + /** + * Constructor which trusts all certificates in a specific java keystore file (assumes a JKS + * file) + **/ + public ConnectionBuilder(String trustStoreFile, char[] trustStorePasswd, int timeout, String serverIP) + throws KeyStoreException, IOException, KeyManagementException, NoSuchAlgorithmException, + CertificateException { + if (!PathValidator.isValidFilePath(trustStoreFile)) { + throw new IOException("Invalid trust store file path"); + } + + /* Load the specified trustStore */ + KeyStore keystore = KeyStore.getInstance("JKS"); + FileInputStream readStream = new FileInputStream(trustStoreFile); + keystore.load(readStream, trustStorePasswd); + if (StringUtils.isNotBlank(serverIP)) { + SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(); + SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext, new NoopHostnameVerifier()); + + RequestConfig config = RequestConfig.custom().setSocketTimeout(timeout).build(); + httpClient = HttpClients.custom().setDefaultRequestConfig(config).setSSLSocketFactory(factory).build(); + } else { + SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(keystore).build(); + SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext, + SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); + RequestConfig config = RequestConfig.custom().setSocketTimeout(timeout).build(); + httpClient = HttpClients.custom().setDefaultRequestConfig(config).setSSLSocketFactory(factory).build(); + } + } + + /** + * Constructor that trusts ALL SSl certificates (NOTE : ONLY FOR DEV TESTING) if Mode == 1 or + * Default if Mode == 0 + */ + public ConnectionBuilder(int mode, int timeout) + throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + RequestConfig config = RequestConfig.custom().setSocketTimeout(timeout).build(); + if (mode == 1) { + SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(); + SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext, + SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); + + httpClient = HttpClients.custom().setDefaultRequestConfig(config).setSSLSocketFactory(factory).build(); + } else { + httpClient = HttpClients.custom().setDefaultRequestConfig(config).build(); + } + } + + // Use to create an http context with auth headers + public void setHttpContext(String user, String pswd) { + + // Are credential provided ? If so, set the context to be used + if (user != null && !user.isEmpty() && pswd != null && !pswd.isEmpty()) { + UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, pswd); + AuthScope authscope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT); + BasicCredentialsProvider credsprovider = new BasicCredentialsProvider(); + credsprovider.setCredentials(authscope, credentials); + httpContext.setCredentialsProvider(credsprovider); + } + } + + // Method posts to the ansible server and writes out response to + // Ansible result object + public AnsibleResult post(String agentUrl, String payload) { + + AnsibleResult result = new AnsibleResult(); + try { + + HttpPost postObj = new HttpPost(agentUrl); + StringEntity bodyParams = new StringEntity(payload, "UTF-8"); + postObj.setEntity(bodyParams); + postObj.addHeader("Content-type", "application/json"); + + HttpResponse response = httpClient.execute(postObj, httpContext); + HttpEntity entity = response.getEntity(); + String responseOutput = entity != null ? EntityUtils.toString(entity) : null; + int responseCode = response.getStatusLine().getStatusCode(); + result.setStatusCode(responseCode); + result.setStatusMessage(responseOutput); + } catch (IOException io) { + logger.error("Caught IOException", io); + result.setStatusCode(AnsibleResultCodes.IO_EXCEPTION.getValue()); + result.setStatusMessage(io.getMessage()); + } + return result; + } + + // Method gets information from an Ansible server and writes out response to + // Ansible result object + + public AnsibleResult get(String agentUrl) { + + AnsibleResult result = new AnsibleResult(); + + try { + HttpGet getObj = new HttpGet(agentUrl); + HttpResponse response = httpClient.execute(getObj, httpContext); + HttpEntity entity = response.getEntity(); + String responseOutput = entity != null ? EntityUtils.toString(entity) : null; + int responseCode = response.getStatusLine().getStatusCode(); + logger.info("GetResult response for ansible GET URL" + agentUrl + " returned " + responseOutput); + JSONObject postResponse = new JSONObject(responseOutput); + if (postResponse.has(STATUS_CODE_KEY)) { + int codeStatus = postResponse.getInt(STATUS_CODE_KEY); + if (codeStatus == AnsibleResultCodes.PENDING.getValue()) { + result.setStatusCode(codeStatus); + } else { + result.setStatusCode(responseCode); + } + } else { + result.setStatusCode(responseCode); + } + result.setStatusMessage(responseOutput); + } catch (IOException io) { + result.setStatusCode(AnsibleResultCodes.IO_EXCEPTION.getValue()); + result.setStatusMessage(io.getMessage()); + logger.error("Caught IOException", io); + } + return result; + } + + @Override + public void close() { + try { + if (httpClient != null) { + httpClient.close(); + } + } catch (IOException e) { + logger.error("Caught IOException during httpClient close", e); + } + } + +} diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleMessageParser.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleMessageParser.java new file mode 100644 index 000000000..3294fabad --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleMessageParser.java @@ -0,0 +1,367 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.ansible.model; + +import com.google.common.base.Strings; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import org.apache.commons.lang.StringUtils; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdaptorConstants; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdaptorConstants.*; + +/** + * Class that validates and constructs requests sent/received from + * Ansible Server + */ +public class AnsibleMessageParser { + + + private static final String JSON_ERROR_MESSAGE = "JSONException: Error parsing response"; + + private static final Logger LOGGER = LoggerFactory.getLogger(AnsibleMessageParser.class); + + /** + * Accepts a map of strings and + * a) validates if all parameters are appropriate (else, throws an exception) and + * b) if correct returns a JSON object with appropriate key-value pairs to send to the server. + *

+ * Mandatory parameters, that must be in the supplied information to the Ansible Adaptor + * 1. URL to connect to + * 2. credentials for URL (assume user pswd for now) + * 3. Playbook name + */ + public JSONObject reqMessage(Map params) throws SvcLogicException { + final String[] mandatoryTestParams = {AGENT_URL, PLAYBOOK_NAME, USER, PSWD}; + final String[] optionalTestParams = {ENV_PARAMETERS, NODE_LIST, LOCAL_PARAMETERS, TIMEOUT, VERSION, FILE_PARAMETERS, + ACTION, INVENTORY_NAMES, AUTO_NODE_LIST}; + JSONObject jsonPayload = new JSONObject(); + + for (String key : mandatoryTestParams) { + throwIfMissingMandatoryParam(params, key); + jsonPayload.put(key, params.get(key)); + } + + parseOptionalParams(params, optionalTestParams, jsonPayload); + + // Generate a unique uuid for the test + String reqId = UUID.randomUUID().toString(); + jsonPayload.put(ID, reqId); + return jsonPayload; + } + + /** + * Method that validates that the Map has enough information + * to query Ansible server for a result. If so, it returns + * the appropriate url, else an empty string. + */ + public String reqUriResult(Map params) throws SvcLogicException { + final String[] mandatoryTestParams = {AGENT_URL, ID, USER, PSWD}; + for (String key : mandatoryTestParams) { + throwIfMissingMandatoryParam(params, key); + } + return params.get(AGENT_URL) + "?Id=" + params.get(ID) + "&Type=GetResult"; + } + + /** + * Method that validates that the Map has enough information to query Ansible + * server for a result. If so, it returns the appropriate url, else an empty + * string. + */ + public String reqUriResultWithIP(Map params, String serverIP) throws SvcLogicException { + final String[] mandatoryTestParams = {AGENT_URL, ID, USER, PSWD}; + for (String key : mandatoryTestParams) { + throwIfMissingMandatoryParam(params, key); + } + String[] arr1 = params.get(AGENT_URL).split("//", 2); + String[] arr2 = arr1[1].split(":", 2); + return arr1[0] + "//" + serverIP + ":" + arr2[1] + "?Id=" + params.get(ID) + "&Type=GetResult"; + } + + /** + * Method that validates that the Map has enough information to query Ansible + * server for logs. If so, it populates the appropriate returns the appropriate + * url, else an empty string. + */ + public String reqUriLog(Map params) throws SvcLogicException { + final String[] mandatoryTestParams = {AGENT_URL, ID, USER, PSWD}; + for (String mandatoryParam : mandatoryTestParams) { + throwIfMissingMandatoryParam(params, mandatoryParam); + } + return params.get(AGENT_URL) + "?Id=" + params.get(ID) + "&Type=GetLog"; + } + + /** + * Method that validates that the Map has enough information + * to query Ansible server for an output. If so, it returns + * the appropriate url, else an empty string. + */ + public String reqUriOutput(Map params) throws SvcLogicException { + final String[] mandatoryTestParams = {AGENT_URL, ID, USER, PSWD}; + for (String mandatoryParam : mandatoryTestParams) { + throwIfMissingMandatoryParam(params, mandatoryParam); + } + return params.get(AGENT_URL) + "?Id=" + params.get(ID) + "&Type=GetOutput"; + } + + /** + * This method parses response from the Ansible Server when we do a post + * and returns an AnsibleResult object. + */ + public AnsibleResult parsePostResponse(String input) throws SvcLogicException { + AnsibleResult ansibleResult; + try { + JSONObject postResponse = new JSONObject(input); + int code = postResponse.getInt(STATUS_CODE); + int initResponseValue = AnsibleResultCodes.INITRESPONSE.getValue(); + boolean validCode = AnsibleResultCodes.CODE.checkValidCode(initResponseValue, code); + if (!validCode) { + throw new SvcLogicException(String.format("Invalid InitResponse code = %s received. MUST be one of %s", + code, AnsibleResultCodes.CODE.getValidCodes(initResponseValue))); + } + + ansibleResult = new AnsibleResult(code, postResponse.getString(STATUS_MESSAGE)); + if (postResponse.has(ANSIBLE_SERVER) && StringUtils.isNotBlank(postResponse.getString(ANSIBLE_SERVER))) { + ansibleResult.setServerIp(postResponse.getString(ANSIBLE_SERVER)); + } + if (!postResponse.isNull(OUTPUT)) { + LOGGER.info("Processing results-output in post response"); + JSONObject output = postResponse.getJSONObject(OUTPUT); + ansibleResult.setOutput(output.toString()); + } + } catch (JSONException e) { + LOGGER.error(JSON_ERROR_MESSAGE, e); + ansibleResult = new AnsibleResult(600, "Error parsing response = " + input + ". Error = " + e.getMessage()); + } + return ansibleResult; + } + + /** + * This method parses response from an Ansible server when we do a GET for a result + * and returns an AnsibleResult object. + **/ + public AnsibleResult parseGetResponse(String input) throws SvcLogicException { + AnsibleResult ansibleResult = new AnsibleResult(); + try { + JSONObject postResponse = new JSONObject(input); + parseGetResponseNested(ansibleResult, postResponse); + } catch (JSONException e) { + LOGGER.error(JSON_ERROR_MESSAGE, e); + ansibleResult = new AnsibleResult(AnsibleResultCodes.INVALID_PAYLOAD.getValue(), + "Error parsing response = " + input + ". Error = " + e.getMessage(), ""); + } + return ansibleResult; + } + + private void parseGetResponseNested(AnsibleResult ansibleResult, JSONObject postRsp) throws SvcLogicException { + String messageStatus = postRsp.getString(STATUS_MESSAGE); + int codeStatus = postRsp.getInt(STATUS_CODE); + int finalCode = AnsibleResultCodes.FINAL_SUCCESS.getValue(); + boolean valCode = AnsibleResultCodes.CODE.checkValidCode(AnsibleResultCodes.FINALRESPONSE.getValue(), codeStatus); + if (!valCode) { + throw new SvcLogicException(String.format("Invalid InitResponse code = %s received. MUST be one of %s", + codeStatus, AnsibleResultCodes.CODE.getValidCodes(AnsibleResultCodes.FINALRESPONSE.getValue()))); + } + + ansibleResult.setStatusCode(codeStatus); + ansibleResult.setStatusMessage(messageStatus); + ansibleResult.setConfigData("UNKNOWN"); + LOGGER.info("Received response with code = {}, Message = {}", codeStatus, messageStatus); + + if (!postRsp.isNull("Results")) { + + // Results are available. process them + // Results is a dictionary of the form + + LOGGER.info("Processing results in response"); + JSONObject results = postRsp.getJSONObject("Results"); + + LOGGER.info("Get JSON dictionary from Results by Iterating through hosts"); + Iterator hosts = results.keys(); + while (hosts.hasNext()) { + String host = hosts.next(); + LOGGER.info("Processing host = {}", + (host.matches("^[\\w\\-.]+$")) ? host : "[unexpected value, logging suppressed]"); + try { + JSONObject hostResponse = results.getJSONObject(host); + int subCode = hostResponse.getInt(STATUS_CODE); + String message = hostResponse.getString(STATUS_MESSAGE); + + LOGGER.info("Code = {}, Message = {}", subCode, message); + + if (subCode != 200 || !"SUCCESS".equals(message)) { + finalCode = AnsibleResultCodes.REQ_FAILURE.getValue(); + } + if ((hostResponse.optJSONObject(OUTPUT)) != null) { + JSONObject hostResponseObjectInfo = hostResponse.optJSONObject(OUTPUT).optJSONObject("info"); + JSONObject hostResponseConfigData = hostResponseObjectInfo.optJSONObject("configData"); + if (hostResponseConfigData != null) { + ansibleResult.setConfigData(hostResponseConfigData.toString()); + } + } + } catch (JSONException e) { + LOGGER.error(JSON_ERROR_MESSAGE, e); + ansibleResult.setStatusCode(AnsibleResultCodes.INVALID_RESPONSE.getValue()); + ansibleResult.setStatusMessage(String.format("Error processing response message = %s from host %s", + results.getString(host), host)); + break; + } + } + ansibleResult.setStatusCode(finalCode); + + // We return entire Results object as message + ansibleResult.setResults(results.toString()); + } else { + ansibleResult.setStatusCode(AnsibleResultCodes.INVALID_RESPONSE.getValue()); + ansibleResult.setStatusMessage("Results not found in GET for response"); + } + if (!postRsp.isNull(OUTPUT)) { + LOGGER.info("Processing results-output in response"); + JSONObject output = postRsp.getJSONObject(OUTPUT); + ansibleResult.setOutput(output.toString()); + } + } + + private void parseOptionalParams(Map params, String[] optionalTestParams, JSONObject jsonPayload) { + + Set optionalParamsSet = new HashSet<>(); + Collections.addAll(optionalParamsSet, optionalTestParams); + + //@formatter:off + params.entrySet().stream().filter(entry -> optionalParamsSet.contains(entry.getKey())) + .filter(entry -> !Strings.isNullOrEmpty(entry.getValue())) + .forEach(entry -> parseOptionalParam(entry, jsonPayload)); + //@formatter:on + } + + private void parseOptionalParam(Map.Entry params, JSONObject jsonPayload) { + String key = params.getKey(); + String payload = params.getValue(); + + switch (key) { + case TIMEOUT: + if (dataIsVariable(payload)) { + break; + } + int timeout = Integer.parseInt(payload); + if (timeout < 0) { + throw new NumberFormatException(" : specified negative integer for timeout = " + payload); + } + jsonPayload.put(key, payload); + break; + case AUTO_NODE_LIST: + if (payload.equalsIgnoreCase("true") || payload.equalsIgnoreCase("false")) { + jsonPayload.put(key, payload); + } else { + throw new IllegalArgumentException(" : specified invalid boolean value of AutoNodeList = " + payload); + } + break; + case VERSION: + if (dataIsVariable(payload)) { + break; + } + case INVENTORY_NAMES: + jsonPayload.put(key, payload); + break; + + case LOCAL_PARAMETERS: + case ENV_PARAMETERS: + case EXTRA_VARS: + JSONObject paramsJson = new JSONObject(payload); + jsonDataIsVariable(paramsJson); + jsonPayload.put(key, paramsJson); + break; + + case NODE_LIST: + if (payload.startsWith("$")) { + break; + } + JSONArray paramsArray = new JSONArray(payload); + jsonPayload.put(key, paramsArray); + break; + + case FILE_PARAMETERS: + if (dataIsVariable(payload)) { + break; + } + jsonPayload.put(key, getFilePayload(payload)); + break; + + default: + break; + } + } + + /** + * Return payload with escaped newlines + */ + private JSONObject getFilePayload(String payload) { + String formattedPayload = payload.replace("\n", "\\n").replace("\r", "\\r"); + return new JSONObject(formattedPayload); + } + + private void throwIfMissingMandatoryParam(Map params, String key) throws SvcLogicException { + if (!params.containsKey(key)) { + throw new SvcLogicException(String.format( + "Ansible: Mandatory AnsibleAdaptor key %s not found in parameters provided by calling agent !", key)); + } + if (Strings.isNullOrEmpty(params.get(key))) { + throw new SvcLogicException(String.format( + "Ansible: Mandatory AnsibleAdaptor key %s not found in parameters provided by calling agent !", key)); + } + if (StringUtils.startsWith(params.get(key), "$")) { + throw new SvcLogicException(String.format( + "Ansible: Mandatory AnsibleAdaptor key %s is a variable", key)); + } + } + + private boolean dataIsVariable(String payload) { + return StringUtils.startsWith(payload, "$") || StringUtils.isEmpty(payload); + } + + private void jsonDataIsVariable(JSONObject paramsJson) { + LOGGER.info("input json is " + paramsJson); + String[] keys = JSONObject.getNames(paramsJson); + for (String k : keys) { + Object a = paramsJson.get(k); + if (a instanceof String) { + if (StringUtils.startsWith(a.toString(), "$") || StringUtils.isEmpty(a.toString())) { + LOGGER.info("removing key " + k); + paramsJson.remove(k); + } + } + } + LOGGER.info("returning json as {}", paramsJson); + } + +} diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResult.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResult.java new file mode 100644 index 000000000..bad0f5e20 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResult.java @@ -0,0 +1,115 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.ansible.model; + +/** + * Simple class to store code and message returned by POST/GET to an Ansible Server + */ +public class AnsibleResult { + + private static final String EMPTY_VALUE = "UNKNOWN"; + + private int statusCode; + private String statusMessage; + private String results; + private String output; + private String serverIp; + private String configData; + + public AnsibleResult() { + this(-1, EMPTY_VALUE, EMPTY_VALUE); + } + + public AnsibleResult(int code, String message) { + this(code, message, EMPTY_VALUE); + } + + public AnsibleResult(int code, String message, String result) { + statusCode = code; + statusMessage = message; + results = result; + } + + public AnsibleResult(int code, String message, String result, String outputData) { + statusCode = code; + statusMessage = message; + results = result; + output = outputData; + } + + public String getOutput() { + return output; + } + + public void setOutput(String output) { + this.output = output; + } + + void set(int code, String message, String results, String output) { + this.statusCode = code; + this.statusMessage = message; + this.results = results; + this.output = output; + } + + public int getStatusCode() { + return this.statusCode; + } + + public void setStatusCode(int code) { + this.statusCode = code; + } + + public String getStatusMessage() { + return this.statusMessage; + } + + public void setStatusMessage(String message) { + this.statusMessage = message; + } + + public String getResults() { + return this.results; + } + + public void setResults(String results) { + this.results = results; + } + + public String getServerIp() { + return this.serverIp; + } + + public void setServerIp(String serverIp) { + this.serverIp = serverIp; + } + + public String getConfigData() { + return this.configData; + } + + public void setConfigData(String configData) { + this.configData = configData; + } + +} diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResultCodes.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResultCodes.java new file mode 100644 index 000000000..55a1e7086 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleResultCodes.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.ansible.model; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** + * enum of the various codes that APP-C uses to resolve different + * status of response from Ansible Server + **/ + +public enum AnsibleResultCodes { + + // @formatter:off + SUCCESS(400), + KEYSTORE_EXCEPTION(622), + CERTIFICATE_ERROR(610), + IO_EXCEPTION(611), + HOST_UNKNOWN(625), + USER_UNAUTHORIZED(613), + UNKNOWN_EXCEPTION(699), + SSL_EXCEPTION(697), + INVALID_PAYLOAD(698), + INVALID_RESPONSE(601), + PENDING(100), + REJECTED(101), + FINAL_SUCCESS(200), + REQ_FAILURE(401), + MESSAGE(1), + CODE(0), + INITRESPONSE(0), + FINALRESPONSE(1); + // @formatter:on + + private final Set initCodes = new HashSet<>(Arrays.asList(100, 101)); + private final Set finalCodes = new HashSet<>(Arrays.asList(200, 500)); + private final ArrayList> codeSets = new ArrayList<>(Arrays.asList(initCodes, finalCodes)); + private final Set messageSet = new HashSet<>(Arrays.asList("PENDING", "FINISHED", "TERMINATED")); + private final int value; + + AnsibleResultCodes(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + public boolean checkValidCode(int type, int code) { + return codeSets.get(type).contains(code); + } + + public String getValidCodes(int type) { + StringBuilder sb = new StringBuilder("[ "); + codeSets.get(type).forEach(s -> sb.append(s).append(",")); + return sb.append("]").toString(); + } + + public boolean checkValidMessage(String message) { + return messageSet.contains(message); + } + + public String getValidMessages() { + StringBuilder sb = new StringBuilder("[ "); + messageSet.forEach(s -> sb.append(s).append(",")); + return sb.append("]").toString(); + } +} diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleServerEmulator.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleServerEmulator.java new file mode 100644 index 000000000..b850f3f65 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleServerEmulator.java @@ -0,0 +1,126 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.ansible.model; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.apache.commons.lang.StringUtils; +import org.json.JSONException; +import org.json.JSONObject; + +import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdaptorConstants.PLAYBOOK_NAME; +import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdaptorConstants.STATUS_CODE; +import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdaptorConstants.STATUS_MESSAGE; + +public class AnsibleServerEmulator { + + private final EELFLogger logger = EELFManager.getInstance().getLogger(AnsibleServerEmulator.class); + + /** + * Method that emulates the response from an Ansible Server + * when presented with a request to execute a playbook + * Returns an ansible object result. The response code is always the http code 200 (i.e connection successful) + * payload is json string as would be sent back by Ansible Server + **/ + public AnsibleResult post(String payload) { + AnsibleResult result = new AnsibleResult(); + + try { + // Request must be a JSON object + + JSONObject message = new JSONObject(payload); + String playbookName = "test_playbook.yaml"; + if (message.isNull("Id")) { + rejectRequest(result, "Must provide a valid Id"); + } else if (message.isNull(PLAYBOOK_NAME)) { + rejectRequest(result, "Must provide a playbook Name"); + } else if (!message.getString(PLAYBOOK_NAME).equals(playbookName)) { + rejectRequest(result, "Playbook " + message.getString(PLAYBOOK_NAME) + " not found in catalog"); + } else { + acceptRequest(result); + } + } catch (JSONException e) { + logger.error("JSONException caught", e); + rejectRequest(result, e.getMessage()); + } + return result; + } + + /** + * Method to emulate response from an Ansible + * Server when presented with a GET request + * Returns an ansibl object result. The response code is always the http code 200 (i.e connection successful) + * payload is json string as would be sent back by Ansible Server + **/ + public AnsibleResult get(String agentUrl) { + + Pattern pattern = Pattern.compile(".*?\\?Id=(.*?)&Type.*"); + Matcher matcher = pattern.matcher(agentUrl); + String id = StringUtils.EMPTY; + String vmAddress = "192.168.1.10"; + + if (matcher.find()) { + id = matcher.group(1); + } + + AnsibleResult getResult = new AnsibleResult(); + + JSONObject response = new JSONObject(); + response.put(STATUS_CODE, 200); + response.put(STATUS_MESSAGE, "FINISHED"); + + JSONObject results = new JSONObject(); + + JSONObject vmResults = new JSONObject(); + vmResults.put(STATUS_CODE, 200); + vmResults.put(STATUS_MESSAGE, "SUCCESS"); + vmResults.put("Id", id); + results.put(vmAddress, vmResults); + + response.put("Results", results); + + getResult.setStatusCode(200); + getResult.setStatusMessage(response.toString()); + + return getResult; + } + + private void rejectRequest(AnsibleResult result, String Message) { + result.setStatusCode(200); + JSONObject response = new JSONObject(); + response.put(STATUS_CODE, AnsibleResultCodes.REJECTED.getValue()); + response.put(STATUS_MESSAGE, Message); + result.setStatusMessage(response.toString()); + } + + private void acceptRequest(AnsibleResult result) { + result.setStatusCode(200); + JSONObject response = new JSONObject(); + response.put(STATUS_CODE, AnsibleResultCodes.PENDING.getValue()); + response.put(STATUS_MESSAGE, "PENDING"); + result.setStatusMessage(response.toString()); + } + +} \ No newline at end of file diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/resources/OSGI-INF/blueprint/ansible-adaptor-blueprint.xml b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/resources/OSGI-INF/blueprint/ansible-adaptor-blueprint.xml new file mode 100644 index 000000000..45e5ba48f --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/resources/OSGI-INF/blueprint/ansible-adaptor-blueprint.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdaptor + + + + diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/resources/ansible-adaptor.properties b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/resources/ansible-adaptor.properties new file mode 100644 index 000000000..ace7e8556 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/resources/ansible-adaptor.properties @@ -0,0 +1,42 @@ +### +# ============LICENSE_START======================================================= +# ONAP : SLI +# ================================================================================ +# Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# ============LICENSE_END========================================================= + +### +# +# Default properties for the APP-C Provider Adaptor +# +# ------------------------------------------------------------------------------------------------- +# +# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded +# to supply configuration options +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=${user.home},/opt/opendaylight/current/properties,. +appc.application.name=APPC +# +# Define the message resource bundle name to be loaded +org.onap.appc.resources=org/onap/appc/i18n/MessageResources +# +# The name of the adaptor. +org.onap.appc.provider.adaptor.name=org.onap.appc.appc_ansible_adaptor +# Default truststore path and password +org.onap.appc.adaptor.ansible.trustStore=/opt/opendaylight/tls-client/mykeystore.js +org.onap.appc.adaptor.ansible.trustStore.trustPasswd=changeit +org.onap.appc.adaptor.ansible.clientType=TRUST_ALL diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/resources/org/opendaylight/blueprint/ansible-adaptor-blueprint.xml b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/resources/org/opendaylight/blueprint/ansible-adaptor-blueprint.xml new file mode 100644 index 000000000..45e5ba48f --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/main/resources/org/opendaylight/blueprint/ansible-adaptor-blueprint.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdaptor + + + + diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/impl/TestAnsibleAdaptorImpl.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/impl/TestAnsibleAdaptorImpl.java new file mode 100644 index 000000000..ee79f9eed --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/impl/TestAnsibleAdaptorImpl.java @@ -0,0 +1,239 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.ali.adaptors.ansible.impl; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.ccsdk.sli.adaptors.ansible.impl.AnsibleAdaptorImpl; +import org.onap.ccsdk.sli.adaptors.ansible.impl.AnsibleAdaptorPropertiesProviderImpl; +import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleMessageParser; +import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResult; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.powermock.reflect.Whitebox; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.when; +import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdaptorConstants.*; +@RunWith(MockitoJUnitRunner.class) +public class TestAnsibleAdaptorImpl { + + private static final String PENDING = "100"; + private static final String AGENT_URL = "https://192.168.1.1"; + + private static String KEYSTORE_PSWD; + private static Properties properties; + private boolean testMode = true; + + private AnsibleAdaptorImpl adaptor; + private AnsibleResult result; + private AnsibleAdaptorImpl spyAdaptor; + private Map params; + private SvcLogicContext svcContext; + private JSONObject jsonPayload; + + @Mock + private AnsibleMessageParser messageProcessor; + + @BeforeClass + public static void once() { + properties = new AnsibleAdaptorPropertiesProviderImpl().getProperties(); + KEYSTORE_PSWD = properties.getProperty("org.onap.appc.adaptor.ansible.trustStore.trustPasswd"); + } + + /** + * Use reflection to locate fields and methods so that they can be manipulated + * during the test to change the internal state accordingly. + */ + @Before + public void setup() { + testMode = true; + svcContext = new SvcLogicContext(); + adaptor = new AnsibleAdaptorImpl(testMode); + params = new HashMap<>(); + params.put("AgentUrl", AGENT_URL); + jsonPayload = new JSONObject(); + jsonPayload.put("Id", "100"); + jsonPayload.put("User", "test"); + jsonPayload.put("Password", "test"); + jsonPayload.put("PlaybookName", "test_playbook.yaml"); + jsonPayload.put("Timeout", "60000"); + jsonPayload.put("AgentUrl", AGENT_URL); + result = new AnsibleResult(); + result.setStatusMessage("Success"); + result.setResults("Success"); + result.setOutput("{}"); + Whitebox.setInternalState(adaptor, "messageProcessor", messageProcessor); + spyAdaptor = Mockito.spy(adaptor); + } + + @After + public void tearDown() { + testMode = false; + adaptor = null; + params = null; + svcContext = null; + } + + @Test + public void reqExec_shouldSetPending() throws SvcLogicException { + result.setStatusCode(Integer.parseInt(PENDING)); + when(messageProcessor.reqMessage(params)).thenReturn(jsonPayload); + when(messageProcessor.parsePostResponse(anyString())).thenReturn(result); + spyAdaptor.reqExec(params, svcContext); + assertEquals(PENDING, svcContext.getAttribute(RESULT_CODE_ATTRIBUTE_NAME)); + } + + @Test(expected = SvcLogicException.class) + public void reqExecResult_shouldSetSuccess() throws SvcLogicException { + params.put("Id", "100"); + result.setStatusMessage(SUCCESS); + when(messageProcessor.reqUriResult(params)).thenReturn(AGENT_URL); + when(messageProcessor.parseGetResponse(anyString())).thenReturn(result); + spyAdaptor.reqExecResult(params, svcContext); + assertEquals(SUCCESS, svcContext.getAttribute(SUCCESS)); + } + @Test(expected = SvcLogicException.class) + public void reqExecResult_Failure() throws SvcLogicException { + params.put("Id", "100"); + result.setStatusCode(100); + result.setStatusMessage("Failed"); + JSONObject cData = new JSONObject(); + cData.put("GatewayInfo", "Radius"); + result.setConfigData(cData.toString()); + result.setOutput(cData.toString()); + when(messageProcessor.reqUriResult(params)).thenReturn(AGENT_URL); + when(messageProcessor.parseGetResponse(anyString())).thenReturn(result); + adaptor.reqExecResult(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void reqExecResult_SvcLogicException() throws SvcLogicException { + when(messageProcessor.reqUriResult(params)).thenThrow(new SvcLogicException()); + adaptor.reqExecResult(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void reqExecResult_numberFormatException() + throws IllegalStateException, IllegalArgumentException, SvcLogicException { + when(messageProcessor.reqUriResult(params)).thenThrow(new NumberFormatException()); + adaptor.reqExecResult(params, svcContext); + } + + @Test + public void reqExecLog_shouldSetMessage() throws SvcLogicException { + params.put("Id", "101"); + when(messageProcessor.reqUriLog(params)).thenReturn(AGENT_URL); + adaptor.reqExecLog(params, svcContext); + String message = getResponseMessage(); + assertEquals(message, svcContext.getAttribute(LOG_ATTRIBUTE_NAME)); + } + + private String getResponseMessage() { + JSONObject response = new JSONObject(); + response.put(STATUS_CODE, 200); + response.put(STATUS_MESSAGE, "FINISHED"); + JSONObject results = new JSONObject(); + + JSONObject vmResults = new JSONObject(); + vmResults.put(STATUS_CODE, 200); + vmResults.put(STATUS_MESSAGE, "SUCCESS"); + vmResults.put("Id", ""); + results.put("192.168.1.10", vmResults); + + response.put("Results", results); + return response.toString(); + } + + @Test(expected = SvcLogicException.class) + public void reqExecException() + throws IllegalStateException, IllegalArgumentException, SvcLogicException { + when(messageProcessor.reqUriLog(params)).thenThrow(new SvcLogicException("Appc Exception")); + adaptor.reqExecLog(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void reqExec_SvcLogicException() + throws IllegalStateException, IllegalArgumentException, SvcLogicException { + when(messageProcessor.reqMessage(params)).thenThrow(new SvcLogicException()); + adaptor.reqExec(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void reqExec_JsonException() + throws IllegalStateException, IllegalArgumentException, SvcLogicException { + when(messageProcessor.reqMessage(params)).thenThrow(new JSONException("Json Exception")); + adaptor.reqExec(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void reqExec_NumberFormatException() + throws IllegalStateException, IllegalArgumentException, SvcLogicException { + when(messageProcessor.reqMessage(params)).thenThrow(new NumberFormatException("Numbre Format Exception")); + adaptor.reqExec(params, svcContext); + } + + @Test + public void testInitializeWithDefault() { + properties.setProperty("org.onap.appc.adaptor.ansible.clientType", ""); + adaptor = new AnsibleAdaptorImpl(); + assertNotNull(adaptor); + } + + @Test + public void testInitializeWithTrustAll() { + properties.setProperty("org.onap.appc.adaptor.ansible.clientType", "TRUST_ALL"); + adaptor = new AnsibleAdaptorImpl(); + assertNotNull(adaptor); + } + + @Test + public void testInitializeWithTrustCert() { + properties.setProperty("org.onap.appc.adaptor.ansible.clientType", "TRUST_CERT"); + properties.setProperty("org.onap.appc.adaptor.ansible.trustStore.trustPasswd", KEYSTORE_PSWD); + adaptor = new AnsibleAdaptorImpl(); + assertNotNull(adaptor); + } + + @Test + public void testInitializeWithException() { + properties.setProperty("org.onap.appc.adaptor.ansible.clientType", "TRUST_CERT"); + properties.setProperty("org.onap.appc.adaptor.ansible.trustStore.trustPasswd", "appc"); + adaptor = new AnsibleAdaptorImpl(); + assertNotNull(adaptor); + } + +} \ No newline at end of file diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/impl/TestAnsibleAdaptorPropertiesProviderImpl.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/impl/TestAnsibleAdaptorPropertiesProviderImpl.java new file mode 100644 index 000000000..7fba32eb6 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/impl/TestAnsibleAdaptorPropertiesProviderImpl.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.ali.adaptors.ansible.impl; + +import java.io.File; +import java.util.Properties; +import org.junit.Test; +import org.onap.ccsdk.sli.adaptors.ansible.impl.AnsibleAdaptorPropertiesProviderImpl; + +import static org.junit.Assert.assertEquals; +import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdaptorConstants.*; + +public class TestAnsibleAdaptorPropertiesProviderImpl { + + @Test + public void testGetProperties() throws IllegalStateException, IllegalArgumentException { + Properties prop = new AnsibleAdaptorPropertiesProviderImpl().getProperties(); + + assertEquals("TRUST_ALL", prop.getProperty(CLIENT_TYPE_PROPERTY_NAME)); + assertEquals("org.onap.appc.appc_ansible_adaptor", prop.getProperty("org.onap.appc.provider.adaptor.name")); + assertEquals("changeit", prop.getProperty(TRUSTSTORE_PASS_PROPERTY_NAME)); + assertEquals("${user.home},/opt/opendaylight/current/properties,.", prop.getProperty("org.onap.appc.bootstrap.path")); + assertEquals("APPC", prop.getProperty("appc.application.name")); + assertEquals("appc.properties", prop.getProperty("org.onap.appc.bootstrap.file")); + assertEquals("org/onap/appc/i18n/MessageResources", prop.getProperty("org.onap.appc.resources")); + assertEquals("/opt/opendaylight/tls-client/mykeystore.js", prop.getProperty(TRUSTSTORE_PROPERTY_NAME)); + } + + @Test + public void testGetTestProperties() throws IllegalStateException, IllegalArgumentException { + final String configFilePath = "src/test/resources/properties/ansible-adaptor-test.properties".replace("/", File.separator); + Properties prop = new AnsibleAdaptorPropertiesProviderImpl(configFilePath).getProperties(); + + assertEquals("appc", prop.getProperty(CLIENT_TYPE_PROPERTY_NAME)); + assertEquals("org.onap.appc.appc_ansible_adaptor", prop.getProperty("org.onap.appc.provider.adaptor.name")); + assertEquals("Aa123456", prop.getProperty(TRUSTSTORE_PASS_PROPERTY_NAME)); + assertEquals("${user.home},/opt/opendaylight/current/properties,.", prop.getProperty("org.onap.appc.bootstrap.path")); + assertEquals("APPC", prop.getProperty("appc.application.name")); + assertEquals("appc.properties", prop.getProperty("org.onap.appc.bootstrap.file")); + assertEquals("org/onap/appc/i18n/MessageResources", prop.getProperty("org.onap.appc.resources")); + assertEquals("src/test/resources/org/onap/appc/asdc-client.jks", prop.getProperty(TRUSTSTORE_PROPERTY_NAME)); + } + +} diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/impl/TestConnectionBuilder.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/impl/TestConnectionBuilder.java new file mode 100644 index 000000000..ae50c01f1 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/impl/TestConnectionBuilder.java @@ -0,0 +1,236 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.ali.adaptors.ansible.impl; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.util.Properties; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.StatusLine; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.impl.client.CloseableHttpClient; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.ccsdk.sli.adaptors.ansible.impl.AnsibleAdaptorPropertiesProviderImpl; +import org.onap.ccsdk.sli.adaptors.ansible.impl.ConnectionBuilder; +import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResult; +import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResultCodes; +import org.powermock.reflect.Whitebox; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.onap.ccsdk.sli.adaptors.ansible.AnsibleAdaptorConstants.*; + +@RunWith(MockitoJUnitRunner.class) +public class TestConnectionBuilder { + + private static String KEYSTORE_FILE; + private static String KEYSTORE_PSWD; + private static String KEYSTORE_CERTIFICATE; + private static String USER; + private static String PSWD; + private static String URL; + + private final int SUCCESS_STATUS = 200; + private ConnectionBuilder connectionBuilder; + + @Mock + private CloseableHttpClient httpClient; + + @Mock + private HttpClientContext httpClientContext; + + @Mock + private CloseableHttpResponse response; + + @Mock + private HttpEntity entity; + + @Mock + private StatusLine statusLine; + + /** + * Load the configuration properties + */ + @BeforeClass + public static void once() { + final String configFilePath = "src/test/resources/properties/ansible-adaptor-test.properties".replace("/", File.separator); + Properties properties = new AnsibleAdaptorPropertiesProviderImpl(configFilePath).getProperties(); + + KEYSTORE_FILE = properties.getProperty(TRUSTSTORE_PROPERTY_NAME); + KEYSTORE_PSWD = properties.getProperty(TRUSTSTORE_PASS_PROPERTY_NAME); + KEYSTORE_CERTIFICATE = properties.getProperty("org.onap.appc.adaptor.ansible.cert"); + USER = properties.getProperty("org.onap.appc.adaptor.ansible.username"); + PSWD = properties.getProperty("org.onap.appc.adaptor.ansible.password"); + URL = properties.getProperty("org.onap.appc.adaptor.ansible.identity"); + } + + @Before + public void setup() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException { + connectionBuilder = new ConnectionBuilder(1, 2000); + Whitebox.setInternalState(connectionBuilder, "httpClient", httpClient); + Whitebox.setInternalState(connectionBuilder, "httpContext", httpClientContext); + HttpResponse httpResponse = response; + when(httpResponse.getEntity()).thenReturn(entity); + when(httpResponse.getStatusLine()).thenReturn(statusLine); + when(statusLine.getStatusCode()).thenReturn(SUCCESS_STATUS); + } + + @After + public void tearDown() { + connectionBuilder = null; + } + + @Test + public void testConnectionBuilder() throws KeyManagementException, KeyStoreException, CertificateException, + NoSuchAlgorithmException, IOException { + char[] trustStorePassword = KEYSTORE_PSWD.toCharArray(); + ConnectionBuilder connectionBuilder = new ConnectionBuilder(KEYSTORE_FILE, trustStorePassword, 600000, ""); + assertNotNull(connectionBuilder); + } + + @Test + public void testConnectionBuilderWithFilePath() throws KeyManagementException, KeyStoreException, + CertificateException, NoSuchAlgorithmException, IOException { + new ConnectionBuilder(KEYSTORE_CERTIFICATE, 600000); + } + + @Test + public void testSetHttpContext() { + ConnectionBuilder spyConnectionBuilder = Mockito.spy(connectionBuilder); + spyConnectionBuilder.setHttpContext(USER, PSWD); + verify(spyConnectionBuilder, times(1)).setHttpContext(USER, PSWD); + } + + @Test + public void testPost() throws IOException { + when(httpClient.execute(anyObject(), eq(httpClientContext))).thenReturn(response); + AnsibleResult result = connectionBuilder.post(URL, "appc"); + assertNull(result.getStatusMessage()); + assertEquals(SUCCESS_STATUS, result.getStatusCode()); + assertEquals("UNKNOWN", result.getResults()); + } + + @Test + public void testPostWithException() throws IOException { + when(httpClient.execute(anyObject(), eq(httpClientContext))).thenThrow(new IOException()); + AnsibleResult result = connectionBuilder.post(URL, "appc"); + assertEquals(AnsibleResultCodes.IO_EXCEPTION.getValue(), result.getStatusCode()); + } + + @Ignore + @Test + public void testGet() throws IOException { + when(httpClient.execute(anyObject(), eq(httpClientContext))).thenReturn(response); + AnsibleResult result = connectionBuilder.get(URL); + assertNull(result.getStatusMessage()); + assertEquals(SUCCESS_STATUS, result.getStatusCode()); + assertEquals("UNKNOWN", result.getResults()); + } + + @Test + public void testGetWithException() throws IOException { + when(httpClient.execute(anyObject(), eq(httpClientContext))).thenThrow(new IOException()); + AnsibleResult result = connectionBuilder.get(URL); + assertEquals(AnsibleResultCodes.IO_EXCEPTION.getValue(), result.getStatusCode()); + } + + @Test + public void testClose() { + connectionBuilder.close(); + } + + @Test + public void testGetMode() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + connectionBuilder = new ConnectionBuilder(2, 2000); + connectionBuilder.setHttpContext(USER, PSWD); + AnsibleResult result = connectionBuilder.get("test.server.com"); + + assertEquals(611, result.getStatusCode()); + assertNull(result.getStatusMessage()); + assertEquals("UNKNOWN", result.getResults()); + } + + @Test (expected = FileNotFoundException.class) + public void testGetModeNoCert() throws KeyStoreException, CertificateException, IOException, + KeyManagementException, NoSuchAlgorithmException { + String certFile = "testCert"; + + connectionBuilder = new ConnectionBuilder(certFile, 2000); + connectionBuilder.setHttpContext(USER, PSWD); + AnsibleResult result = connectionBuilder.get(URL); + + assertEquals(611, result.getStatusCode()); + assertNull(result.getStatusMessage()); + assertEquals("UNKNOWN", result.getResults()); + } + + @Test + public void testGetModeCert() throws KeyStoreException, CertificateException, IOException, + KeyManagementException, NoSuchAlgorithmException { + String certFile = "src/test/resources/cert"; + + connectionBuilder = new ConnectionBuilder(certFile, 2000); + connectionBuilder.setHttpContext(USER, PSWD); + AnsibleResult result = connectionBuilder.get("test.server.com"); + + assertEquals(611, result.getStatusCode()); + assertNull(result.getStatusMessage()); + assertEquals("UNKNOWN", result.getResults()); + } + + @Test (expected = IOException.class) + public void testGetModeStore() throws KeyStoreException, CertificateException, IOException, + KeyManagementException, NoSuchAlgorithmException { + String store = "src/test/resources/cert"; + + connectionBuilder = new ConnectionBuilder(store, new char['t'], 2000, "1.1.1.1" ); + connectionBuilder.setHttpContext(USER, PSWD); + AnsibleResult result = connectionBuilder.get(URL); + + assertEquals(611, result.getStatusCode()); + assertNull(result.getStatusMessage()); + assertEquals("UNKNOWN", result.getResults()); + } + +} diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/model/TestAnsibleAdaptor.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/model/TestAnsibleAdaptor.java new file mode 100644 index 000000000..a4dc7d490 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/model/TestAnsibleAdaptor.java @@ -0,0 +1,100 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.ali.adaptors.ansible.model; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import org.json.JSONObject; +import org.junit.Test; +import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleMessageParser; +import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResult; +import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleServerEmulator; + +import static org.junit.Assert.assertNotNull; + +public class TestAnsibleAdaptor { + + @Test + public void callPrivateConstructorsMethodsForCodeCoverage() + throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, + InvocationTargetException { + + /* test constructors */ + Class[] classesOne = {AnsibleMessageParser.class}; + for (Class clazz : classesOne) { + Constructor constructor = clazz.getDeclaredConstructor(); + constructor.setAccessible(true); + assertNotNull(constructor.newInstance()); + } + Class[] classesTwo = {AnsibleServerEmulator.class}; + for (Class clazz : classesTwo) { + Constructor constructor = clazz.getDeclaredConstructor(); + constructor.setAccessible(true); + assertNotNull(constructor.newInstance()); + } + Class[] classesThree = {AnsibleResult.class}; + for (Class clazz : classesThree) { + Constructor constructor = clazz.getDeclaredConstructor(); + constructor.setAccessible(true); + assertNotNull(constructor.newInstance()); + } + + /* test methods */ + AnsibleMessageParser ansibleMessageParser = new AnsibleMessageParser(); + Class[] parameterTypes = new Class[1]; + parameterTypes[0] = java.lang.String.class; + + Method m = ansibleMessageParser.getClass().getDeclaredMethod("getFilePayload", parameterTypes); + m.setAccessible(true); + assertNotNull(m.invoke(ansibleMessageParser, "{\"test\": test}")); + + // test logging-suppression for an invalid host value (Fortify Log Forging fix) + String input = "{" + + " \"Results\": {" + + " \"192.168.1.10\": {" + + " \"Id\": \"101\"," + + " \"StatusCode\": 200," + + " \"StatusMessage\": \"SUCCESS\"" + + " }," + + " \"192%168%1%10\": {" + + " \"Id\": \"102\"," + + " \"StatusCode\": 200," + + " \"StatusMessage\": \"SUCCESS\"" + + " }," + + " \"server-dev.att.com\": {" + + " \"Id\": \"103\"," + + " \"StatusCode\": 200," + + " \"StatusMessage\": \"SUCCESS\"" + + " }" + + " }," + + " \"StatusCode\": 200," + + " \"StatusMessage\": \"FINISHED\"" + + "}"; + Method m2 = ansibleMessageParser.getClass().getDeclaredMethod("parseGetResponseNested", AnsibleResult.class, JSONObject.class); + m2.setAccessible(true); + m2.invoke(ansibleMessageParser, new AnsibleResult(), new JSONObject(input)); + } + +} + diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/model/TestAnsibleMessageParser.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/model/TestAnsibleMessageParser.java new file mode 100644 index 000000000..9cf941dfd --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/model/TestAnsibleMessageParser.java @@ -0,0 +1,249 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.ali.adaptors.ansible.model; + +import java.util.HashMap; +import java.util.Map; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleMessageParser; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class TestAnsibleMessageParser { + private AnsibleMessageParser msgParser; + + @Before + public void setup() { + msgParser = new AnsibleMessageParser(); + } + + @Test + public void testReqMessage() throws Exception { + // String result = "{"\AgentUrl : TestAgentUrl}"; + Map params = new HashMap<>(); + params.put("AgentUrl", "TestAgentUrl"); + params.put("PlaybookName", "TestPlaybookName"); + params.put("User", "TestUser"); + params.put("Password", "TestPass"); + + assertEquals("TestAgentUrl", msgParser.reqMessage(params).get("AgentUrl")); + } + + @Test + public void testReqUriResult() throws Exception { + Map params = new HashMap<>(); + params.put("AgentUrl", "TestAgentUrl"); + params.put("Id", "TestId"); + params.put("User", "TestUser"); + params.put("Password", "TestPass"); + + assertTrue(msgParser.reqUriResult(params).contains("TestId")); + } + + @Test + public void testReqUriLog() throws Exception { + Map params = new HashMap<>(); + params.put("AgentUrl", "TestAgent-Url"); + params.put("Id", "TestId"); + params.put("User", "TestUser"); + params.put("Password", "TestPass"); + + assertTrue(msgParser.reqUriLog(params).contains("TestAgent-Url")); + } + + @Test + public void TestParsePostResponse() throws Exception { + String input = "{\"StatusCode\":\"100\",\"StatusMessage\":\"TestMessage\"}"; + assertEquals("TestMessage", msgParser.parsePostResponse(input).getStatusMessage()); + + } + + @Test(expected = SvcLogicException.class) + public void TestParsePostResponseException() throws Exception { + String input = "{\"StatusCode\":\"600\",\"StatusMessage\":\"TestMessage\"}"; + assertTrue(msgParser.parsePostResponse(input).getStatusMessage().contains("Error parsing response")); + } + + @Test(expected = SvcLogicException.class) + public void TestParsePostResponseException2() throws Exception { + String input = "{\"StatusCode\":\"600\"}"; + assertTrue(msgParser.parsePostResponse(input).getStatusMessage().contains("Error parsing response")); + } + + @Test(expected = SvcLogicException.class) + public void TestParseGetResponseException() throws Exception { + String input = "{\"StatusCode\":\"100\",\"StatusMessage\":\"TestMessage\"}"; + assertTrue(msgParser.parseGetResponse(input).getStatusMessage().contains("Invalid FinalResponse code")); + } + + @Test + public void TestParseGetResponseExec() throws Exception { + String input = "{\"StatusCode\":\"200\",\"StatusMessage\":\"TestMessage\"}"; + assertTrue(msgParser.parseGetResponse(input).getStatusMessage().contains("Results not found in GET for response")); + } + + @Test + public void TestParseGetResponse() throws Exception { + String input = "{" + + " \"StatusCode\": \"200\"," + + " \"StatusMessage\": \"TestMessage\"," + + " \"Results\": {" + + " \"host\": {" + + " \"StatusCode\": \"200\"," + + " \"StatusMessage\": \"SUCCESS\"" + + " }" + + " }," + + " \"Output\": {" + + " \"results-output\": {" + + " \"OutputResult\": \"TestOutPutResult\"" + + " }" + + " }" + + "}"; + assertTrue(msgParser.parseGetResponse(input).getOutput().contains("TestOutPutResult")); + } + + @Test + public void TestParseGetResponseEx() throws Exception { + String input = "{\"StatusCode\":\"200\",\"StatusMessage\":\"TestMessage\",\"Results\":{\"host\":\"TestHost\"}}"; + assertTrue(msgParser.parseGetResponse(input).getStatusMessage().contains("Error processing response message")); + } + + @Test + public void TestParseGetResponseJsonEx() throws Exception { + String input = "{\"StatusCode\":\"200\",\"StatusMessage\":\"TestMessage\",\"Results\":\"host\":\"TestHost\"}"; + assertTrue(msgParser.parseGetResponse(input).getStatusMessage().contains("Error parsing response")); + } + + @Test + public void TestParseGetResponseResultEx() throws Exception { + String input = "{" + + " \"StatusCode\": \"200\"," + + " \"StatusMessage\": \"TestMessage\"," + + " \"Results\": {" + + " \"host\": {" + + " \"StatusCode\": \"100\"," + + " \"StatusMessage\": \"Failure\"" + + " }" + + " }," + + " \"Output\": {" + + " \"results-output\": {" + + " \"OutputResult\": \"TestOutPutResult\"" + + " }" + + " }" + + "}"; + assertTrue(msgParser.parseGetResponse(input).getOutput().contains("TestOutPutResult")); + } + + @Test + public void testParseOptionalParam() throws Exception { + Map params = new HashMap<>(); + params.put("AgentUrl", "TestAgentUrl"); + params.put("PlaybookName", "TestPlaybookName"); + params.put("User", "TestUser"); + params.put("Password", "TestPass"); + params.put("Timeout", "3"); + params.put("Version", "1"); + params.put("InventoryNames", "VNFC"); + + JSONObject jObject = msgParser.reqMessage(params); + assertEquals("1", jObject.get("Version")); + assertEquals("VNFC", jObject.get("InventoryNames")); + } + + @Test + public void testParseOptionalParamForEnvParameters() throws Exception { + Map params = new HashMap<>(); + params.put("AgentUrl", "TestAgentUrl"); + params.put("PlaybookName", "TestPlaybookName"); + params.put("User", "TestUser"); + params.put("Password", "TestPass"); + params.put("EnvParameters", "{name:value}"); + + JSONObject result = msgParser.reqMessage(params); + assertEquals("TestAgentUrl", result.get("AgentUrl")); + assertEquals("TestPlaybookName", result.get("PlaybookName")); + assertEquals("TestUser", result.get("User")); + assertEquals("TestPass", result.get("Password")); + } + + @Test + public void TestParseGetConfigResponseResult() throws Exception { + String input = "{" + + " \"StatusCode\": \"200\"," + + " \"StatusMessage\": \"TestMessage\"," + + " \"Results\": {" + + " \"host\": {" + + " \"StatusCode\": \"200\"," + + " \"StatusMessage\": \"SUCCESS\"," + + " \"Output\": {" + + " \"info\": {" + + " \"configData\": {" + + " \"abc\": \"TestOutPutResult\"," + + " \"rtr\": \"vfc\"" + + " }" + + " }" + + " }" + + " }" + + " }" + + "}"; + assertTrue(msgParser.parseGetResponse(input).getConfigData().contains("abc")); + } + + @Test + public void testParseOptionalParamTest2() throws Exception { + + Map params = new HashMap<>(); + params.put("AgentUrl", "TestAgentUrl"); + params.put("PlaybookName", "TestPlaybookName"); + params.put("User", "TestUser"); + params.put("Password", "TestPass"); + //params.put("Timeout", "3"); + params.put("Version", "1"); + params.put("InventoryNames", "VNFC"); + params.put("Timeout", "4"); + params.put("EnvParameters", "{ \"userID\": \"$0002\", \"vnf-type\" : \"\", \"vnf\" : \"abc\" }"); + params.put("NodeList", "${Nodelist}"); + + JSONObject jObject = msgParser.reqMessage(params); + assertEquals("1", jObject.get("Version")); + assertEquals("4", jObject.get("Timeout")); + } + + @Test + public void testReqUriResultWithIPs() throws Exception { + Map params = new HashMap<>(); + params.put("AgentUrl", "http://xx:yy:zz"); + params.put("Id", "TestId"); + params.put("User", "TestUser"); + params.put("Password", "TestPass"); + String serverIp = "10.0.2.3"; + String actual = msgParser.reqUriResultWithIP(params, serverIp); + String expected = "http://10.0.2.3:yy:zz?Id=TestId&Type=GetResult"; + assertEquals(expected, actual); + } + +} diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/model/TestAnsibleResult.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/model/TestAnsibleResult.java new file mode 100644 index 000000000..8069da0a3 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ansible/model/TestAnsibleResult.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.ali.adaptors.ansible.model; + +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResult; + +import static org.junit.Assert.assertEquals; + +public class TestAnsibleResult { + private AnsibleResult ansibleResult; + + @Before + public void setUp() { + ansibleResult = new AnsibleResult(10, "message", "result", "outputData"); + } + + @Test + public void testServerIp() { + ansibleResult.setServerIp("10.0.9.87"); + assertEquals("10.0.9.87", ansibleResult.getServerIp()); + } + +} diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/test/ExecutorHarness.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/test/ExecutorHarness.java new file mode 100644 index 000000000..b6476d9dc --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/test/ExecutorHarness.java @@ -0,0 +1,166 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + + +package org.onap.ccsdk.test; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +/** + * This class is used as a test harness to wrap the call to an executor node. + */ + +public class ExecutorHarness { + + /** + * The executor to be tested + */ + private SvcLogicJavaPlugin executor; + + /** + * The collection of all exec methods found on the class + */ + private final Map methods; + + /** + * Create the harness and initialize it + * + * @throws SecurityException If a security manager, s, is present and any of the following conditions is met: + *

    + *
  • invocation of s.checkMemberAccess(this, Member.DECLARED) denies access to the declared field
  • + *
  • the caller's class loader is not the same as or an ancestor of the class loader for the current + * class and invocation of s.checkPackageAccess() denies access to the package of this class
  • + *
+ * @throws NoSuchFieldException if a field with the specified name is not found. + * @throws IllegalAccessException if this Field object is enforcing Java language access control and the underlying field is either + * inaccessible or final. + * @throws IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field + * (or a subclass or implementor thereof), or if an unwrapping conversion fails. + */ + @SuppressWarnings("nls") + public ExecutorHarness() throws NoSuchFieldException, SecurityException, IllegalArgumentException, + IllegalAccessException { + methods = new HashMap<>(); + new SvcLogicContext(); + + Class contextClass = SvcLogicContext.class; + /** + * The field of the class being tested that contains the reference to the logger to be used. This is modified to + * point to our interception logger for the test. + */ + Field contextLogger = contextClass.getDeclaredField("LOG"); + contextLogger.setAccessible(true); + /** + * The interception logger that buffers all messages logged and allows us to look at them as part of the test case. + */ + InterceptLogger logger = new InterceptLogger(); + contextLogger.set(null, logger); + } + + /** + * Convenience constructor + * + * @param executor The executor to be tested by the harness + * + * @throws SecurityException If a security manager, s, is present and any of the following conditions is met: + *
    + *
  • invocation of s.checkMemberAccess(this, Member.DECLARED) denies access to the declared field
  • + *
  • the caller's class loader is not the same as or an ancestor of the class loader for the current + * class and invocation of s.checkPackageAccess() denies access to the package of this class
  • + *
+ * @throws NoSuchFieldException if a field with the specified name is not found. + * @throws IllegalAccessException if this Field object is enforcing Java language access control and the underlying field is either + * inaccessible or final. + * @throws IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field + * (or a subclass or implementor thereof), or if an unwrapping conversion fails. + */ + public ExecutorHarness(SvcLogicJavaPlugin executor) throws NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException { + this(); + setExecutor(executor); + } + + /** + * @return The java plugin class to be executed + */ + public SvcLogicJavaPlugin getExecutor() { + return executor; + } + + /** + * @param executor The java plugin class to be executed + */ + public void setExecutor(SvcLogicJavaPlugin executor) { + this.executor = executor; + scanExecutor(); + } + + /** + * @return The set of all methods that meet the signature requirements + */ + public List getExecMethodNames() { + List names = new ArrayList<>(); + names.addAll(methods.keySet()); + return names; + } + + /** + * Returns an indication if the named method is a valid executor method that could be called from a DG execute node + * + * @param methodName The method name to be validated + * + * @return True if the method name meets the signature requirements, false if the method either does not exist or + * does not meet the requirements. + */ + public boolean isExecMethod(String methodName) { + return methods.containsKey(methodName); + } + + /** + * This method scans the executor class hierarchy to locate all methods that match the required signature of the + * executor and records these methods in a map. + */ + private void scanExecutor() { + methods.clear(); + Class executorClass = executor.getClass(); + Method[] publicMethods = executorClass.getMethods(); + for (Method method : publicMethods) { + if (method.getReturnType().equals(Void.class)) { + Class[] paramTypes = method.getParameterTypes(); + if (paramTypes.length == 2) { + if (Map.class.isAssignableFrom(paramTypes[0]) + && SvcLogicContext.class.isAssignableFrom(paramTypes[1])) { + methods.put(method.getName(), method); + } + } + } + } + } + +} diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/test/InterceptLogger.java b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/test/InterceptLogger.java new file mode 100644 index 000000000..3ed32376a --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/java/org/onap/ccsdk/test/InterceptLogger.java @@ -0,0 +1,447 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SLI + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + + +package org.onap.ccsdk.test; + +import ch.qos.logback.classic.Level; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import org.slf4j.Marker; + +/** + * This class is used as an intercept logger that can be used in testing to intercept and record all messages that are + * logged, thus allowing a junit test case to examine the log output and make assertions. + */ +public class InterceptLogger implements org.slf4j.Logger { + + /** + * The list of all intercepted log events + */ + private final List events; + + /** + * Create the intercept logger + */ + public InterceptLogger() { + events = new ArrayList<>(1000); + } + + /** + * @return Returns all intercepted log events + */ + public List getLogRecords() { + return events; + } + + /** + * Clears all log events + */ + public void clear() { + events.clear(); + } + + @Override + public void debug(Marker marker, String msg) { + debug(msg); + } + + @Override + public void debug(Marker marker, String format, Object arg) { + debug(MessageFormat.format(format, arg)); + } + + @Override + public void debug(Marker marker, String format, Object... arguments) { + debug(MessageFormat.format(format, arguments)); + } + + @Override + public void debug(Marker marker, String format, Object arg1, Object arg2) { + debug(MessageFormat.format(format, arg1, arg2)); + } + + @Override + public void debug(Marker marker, String msg, Throwable t) { + debug(msg, t); + } + + @Override + public void debug(String msg) { + events.add(new LogRecord(Level.DEBUG, msg)); + } + + @Override + public void debug(String format, Object arg) { + events.add(new LogRecord(Level.DEBUG, MessageFormat.format(format, arg))); + } + + @Override + public void debug(String format, Object... arguments) { + events.add(new LogRecord(Level.DEBUG, MessageFormat.format(format, arguments))); + } + + @Override + public void debug(String format, Object arg1, Object arg2) { + events.add(new LogRecord(Level.DEBUG, MessageFormat.format(format, arg1, arg2))); + } + + @Override + public void debug(String msg, Throwable t) { + events.add(new LogRecord(Level.DEBUG, msg, t)); + } + + @Override + public void error(Marker marker, String msg) { + error(msg); + } + + @Override + public void error(Marker marker, String format, Object arg) { + error(format, arg); + } + + @Override + public void error(Marker marker, String format, Object... arguments) { + error(format, arguments); + } + + @Override + public void error(Marker marker, String format, Object arg1, Object arg2) { + error(format, arg1, arg2); + } + + @Override + public void error(Marker marker, String msg, Throwable t) { + events.add(new LogRecord(Level.ERROR, msg, t)); + } + + @Override + public void error(String msg) { + events.add(new LogRecord(Level.ERROR, msg)); + } + + @Override + public void error(String format, Object arg) { + events.add(new LogRecord(Level.ERROR, MessageFormat.format(format, arg))); + } + + @Override + public void error(String format, Object... arguments) { + events.add(new LogRecord(Level.ERROR, MessageFormat.format(format, arguments))); + } + + @Override + public void error(String format, Object arg1, Object arg2) { + events.add(new LogRecord(Level.ERROR, MessageFormat.format(format, arg1, arg2))); + } + + @Override + public void error(String msg, Throwable t) { + events.add(new LogRecord(Level.ERROR, msg, t)); + } + + @Override + public String getName() { + return null; + } + + @Override + public void info(Marker marker, String msg) { + info(msg); + } + + @Override + public void info(Marker marker, String format, Object arg) { + info(format, arg); + } + + @Override + public void info(Marker marker, String format, Object... arguments) { + info(format, arguments); + } + + @Override + public void info(Marker marker, String format, Object arg1, Object arg2) { + info(format, arg1, arg2); + } + + @Override + public void info(Marker marker, String msg, Throwable t) { + events.add(new LogRecord(Level.INFO, msg, t)); + } + + @Override + public void info(String msg) { + events.add(new LogRecord(Level.INFO, msg)); + } + + @Override + public void info(String format, Object arg) { + events.add(new LogRecord(Level.INFO, MessageFormat.format(format, arg))); + } + + @Override + public void info(String format, Object... arguments) { + events.add(new LogRecord(Level.INFO, MessageFormat.format(format, arguments))); + } + + @Override + public void info(String format, Object arg1, Object arg2) { + events.add(new LogRecord(Level.INFO, MessageFormat.format(format, arg1, arg2))); + } + + @Override + public void info(String msg, Throwable t) { + events.add(new LogRecord(Level.INFO, msg, t)); + } + + @Override + public boolean isDebugEnabled() { + return true; + } + + @Override + public boolean isDebugEnabled(Marker marker) { + return true; + } + + @Override + public boolean isErrorEnabled() { + return true; + } + + @Override + public boolean isErrorEnabled(Marker marker) { + return true; + } + + @Override + public boolean isInfoEnabled() { + return true; + } + + @Override + public boolean isInfoEnabled(Marker marker) { + return true; + } + + @Override + public boolean isTraceEnabled() { + return true; + } + + @Override + public boolean isTraceEnabled(Marker marker) { + return true; + } + + @Override + public boolean isWarnEnabled() { + return true; + } + + @Override + public boolean isWarnEnabled(Marker marker) { + return true; + } + + @Override + public void trace(Marker marker, String msg) { + trace(msg); + } + + @Override + public void trace(Marker marker, String format, Object arg) { + trace(format, arg); + } + + @Override + public void trace(Marker marker, String format, Object... argArray) { + trace(format, argArray); + } + + @Override + public void trace(Marker marker, String format, Object arg1, Object arg2) { + trace(format, arg1, arg2); + } + + @Override + public void trace(Marker marker, String msg, Throwable t) { + trace(msg, t); + } + + @Override + public void trace(String msg) { + events.add(new LogRecord(Level.TRACE, msg)); + } + + @Override + public void trace(String format, Object arg) { + events.add(new LogRecord(Level.TRACE, MessageFormat.format(format, arg))); + } + + @Override + public void trace(String format, Object... arguments) { + events.add(new LogRecord(Level.TRACE, MessageFormat.format(format, arguments))); + } + + @Override + public void trace(String format, Object arg1, Object arg2) { + events.add(new LogRecord(Level.TRACE, MessageFormat.format(format, arg1, arg2))); + } + + @Override + public void trace(String msg, Throwable t) { + events.add(new LogRecord(Level.TRACE, msg, t)); + } + + @Override + public void warn(Marker marker, String msg) { + warn(msg); + } + + @Override + public void warn(Marker marker, String format, Object arg) { + warn(format, arg); + } + + @Override + public void warn(Marker marker, String format, Object... arguments) { + warn(format, arguments); + } + + @Override + public void warn(Marker marker, String format, Object arg1, Object arg2) { + warn(format, arg1, arg2); + } + + @Override + public void warn(Marker marker, String msg, Throwable t) { + events.add(new LogRecord(Level.WARN, msg, t)); + } + + @Override + public void warn(String msg) { + events.add(new LogRecord(Level.WARN, msg)); + } + + @Override + public void warn(String format, Object arg) { + events.add(new LogRecord(Level.WARN, MessageFormat.format(format, arg))); + } + + @Override + public void warn(String format, Object... arguments) { + events.add(new LogRecord(Level.WARN, MessageFormat.format(format, arguments))); + } + + @Override + public void warn(String format, Object arg1, Object arg2) { + events.add(new LogRecord(Level.WARN, MessageFormat.format(format, arg1, arg2))); + } + + @Override + public void warn(String msg, Throwable t) { + events.add(new LogRecord(Level.WARN, msg, t)); + } + + /** + * This inner class represents an intercepted log event + */ + public class LogRecord { + private Level level; + private String message; + private long timestamp; + private Throwable t; + + public LogRecord(Level level, String message) { + setLevel(level); + setTimestamp(System.currentTimeMillis()); + setMessage(message); + } + + public LogRecord(Level level, String message, Throwable t) { + this(level, message); + setThrowable(t); + } + + /** + * @return the value of level + */ + public Level getLevel() { + return level; + } + + /** + * @param level the value for level + */ + public void setLevel(Level level) { + this.level = level; + } + + /** + * @return the value of message + */ + public String getMessage() { + return message; + } + + /** + * @param message the value for message + */ + public void setMessage(String message) { + this.message = message; + } + + /** + * @return the value of timestamp + */ + public long getTimestamp() { + return timestamp; + } + + /** + * @param timestamp the value for timestamp + */ + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + /** + * @return the value of t + */ + public Throwable getThrowable() { + return t; + } + + /** + * @param t the value for t + */ + public void setThrowable(Throwable t) { + this.t = t; + } + + } + +} diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/cert b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/cert new file mode 100644 index 000000000..cc2921c4b --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/cert @@ -0,0 +1,125 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: 1 (0x1) + Signature Algorithm: sha1WithRSAEncryption + Issuer: C=FR, ST=Alsace, L=Strasbourg, O=www.freelan.org, OU=freelan, CN=Freelan Sample Certificate Authority/emailAddress=contact@freelan.org + Validity + Not Before: Apr 27 10:31:18 2012 GMT + Not After : Apr 25 10:31:18 2022 GMT + Subject: C=FR, ST=Alsace, O=www.freelan.org, OU=freelan, CN=alice/emailAddress=contact@freelan.org + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + Public-Key: (4096 bit) + Modulus: + 00:dd:6d:bd:f8:80:fa:d7:de:1b:1f:a7:a3:2e:b2: + 02:e2:16:f6:52:0a:3c:bf:a6:42:f8:ca:dc:93:67: + 4d:60:c3:4f:8d:c3:8a:00:1b:f1:c4:4b:41:6a:69: + d2:69:e5:3f:21:8e:c5:0b:f8:22:37:ad:b6:2c:4b: + 55:ff:7a:03:72:bb:9a:d3:ec:96:b9:56:9f:cb:19: + 99:c9:32:94:6f:8f:c6:52:06:9f:45:03:df:fd:e8: + 97:f6:ea:d6:ba:bb:48:2b:b5:e0:34:61:4d:52:36: + 0f:ab:87:52:25:03:cf:87:00:87:13:f2:ca:03:29: + 16:9d:90:57:46:b5:f4:0e:ae:17:c8:0a:4d:92:ed: + 08:a6:32:23:11:71:fe:f2:2c:44:d7:6c:07:f3:0b: + 7b:0c:4b:dd:3b:b4:f7:37:70:9f:51:b6:88:4e:5d: + 6a:05:7f:8d:9b:66:7a:ab:80:20:fe:ee:6b:97:c3: + 49:7d:78:3b:d5:99:97:03:75:ce:8f:bc:c5:be:9c: + 9a:a5:12:19:70:f9:a4:bd:96:27:ed:23:02:a7:c7: + 57:c9:71:cf:76:94:a2:21:62:f6:b8:1d:ca:88:ee: + 09:ad:46:2f:b7:61:b3:2c:15:13:86:9f:a5:35:26: + 5a:67:f4:37:c8:e6:80:01:49:0e:c7:ed:61:d3:cd: + bc:e4:f8:be:3f:c9:4e:f8:7d:97:89:ce:12:bc:ca: + b5:c6:d2:e0:d9:b3:68:3c:2e:4a:9d:b4:5f:b8:53: + ee:50:3d:bf:dd:d4:a2:8a:b6:a0:27:ab:98:0c:b3: + b2:58:90:e2:bc:a1:ad:ff:bd:8e:55:31:0f:00:bf: + 68:e9:3d:a9:19:9a:f0:6d:0b:a2:14:6a:c6:4c:c6: + 4e:bd:63:12:a5:0b:4d:97:eb:42:09:79:53:e2:65: + aa:24:34:70:b8:c1:ab:23:80:e7:9c:6c:ed:dc:82: + aa:37:04:b8:43:2a:3d:2a:a8:cc:20:fc:27:5d:90: + 26:58:f9:b7:14:e2:9e:e2:c1:70:73:97:e9:6b:02: + 8e:d3:52:59:7b:00:ec:61:30:f1:56:3f:9c:c1:7c: + 05:c5:b1:36:c8:18:85:cf:61:40:1f:07:e8:a7:06: + 87:df:9a:77:0b:a9:64:72:03:f6:93:fc:e0:02:59: + c1:96:ec:c0:09:42:3e:30:a2:7f:1b:48:2f:fe:e0: + 21:8f:53:87:25:0d:cb:ea:49:f5:4a:9b:d0:e3:5f: + ee:78:18:e5:ba:71:31:a9:04:98:0f:b1:ad:67:52: + a0:f2:e3:9c:ab:6a:fe:58:84:84:dd:07:3d:32:94: + 05:16:45:15:96:59:a0:58:6c:18:0e:e3:77:66:c7: + b3:f7:99 + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Basic Constraints: + CA:FALSE + Netscape Comment: + OpenSSL Generated Certificate + X509v3 Subject Key Identifier: + 59:5F:C9:13:BA:1B:CC:B9:A8:41:4A:8A:49:79:6A:36:F6:7D:3E:D7 + X509v3 Authority Key Identifier: + keyid:23:6C:2D:3D:3E:29:5D:78:B8:6C:3E:AA:E2:BB:2E:1E:6C:87:F2:53 + + Signature Algorithm: sha1WithRSAEncryption + 13:e7:02:45:3e:a7:ab:bd:b8:da:e7:ef:74:88:ac:62:d5:dd: + 10:56:d5:46:07:ec:fa:6a:80:0c:b9:62:be:aa:08:b4:be:0b: + eb:9a:ef:68:b7:69:6f:4d:20:92:9d:18:63:7a:23:f4:48:87: + 6a:14:c3:91:98:1b:4e:08:59:3f:91:80:e9:f4:cf:fd:d5:bf: + af:4b:e4:bd:78:09:71:ac:d0:81:e5:53:9f:3e:ac:44:3e:9f: + f0:bf:5a:c1:70:4e:06:04:ef:dc:e8:77:05:a2:7d:c5:fa:80: + 58:0a:c5:10:6d:90:ca:49:26:71:84:39:b7:9a:3e:e9:6f:ae: + c5:35:b6:5b:24:8c:c9:ef:41:c3:b1:17:b6:3b:4e:28:89:3c: + 7e:87:a8:3a:a5:6d:dc:39:03:20:20:0b:c5:80:a3:79:13:1e: + f6:ec:ae:36:df:40:74:34:87:46:93:3b:a3:e0:a4:8c:2f:43: + 4c:b2:54:80:71:76:78:d4:ea:12:28:d8:f2:e3:80:55:11:9b: + f4:65:dc:53:0e:b4:4c:e0:4c:09:b4:dc:a0:80:5c:e6:b5:3b: + 95:d3:69:e4:52:3d:5b:61:86:02:e5:fd:0b:00:3a:fa:b3:45: + cc:c9:a3:64:f2:dc:25:59:89:58:0d:9e:6e:28:3a:55:45:50: + 5f:88:67:2a:d2:e2:48:cc:8b:de:9a:1b:93:ae:87:e1:f2:90: + 50:40:d9:0f:44:31:53:46:ad:62:4e:8d:48:86:19:77:fc:59: + 75:91:79:35:59:1d:e3:4e:33:5b:e2:31:d7:ee:52:28:5f:0a: + 70:a7:be:bb:1c:03:ca:1a:18:d0:f5:c1:5b:9c:73:04:b6:4a: + e8:46:52:58:76:d4:6a:e6:67:1c:0e:dc:13:d0:61:72:a0:92: + cb:05:97:47:1c:c1:c9:cf:41:7d:1f:b1:4d:93:6b:53:41:03: + 21:2b:93:15:63:08:3e:2c:86:9e:7b:9f:3a:09:05:6a:7d:bb: + 1c:a7:b7:af:96:08:cb:5b:df:07:fb:9c:f2:95:11:c0:82:81: + f6:1b:bf:5a:1e:58:cd:28:ca:7d:04:eb:aa:e9:29:c4:82:51: + 2c:89:61:95:b6:ed:a5:86:7c:7c:48:1d:ec:54:96:47:79:ea: + fc:7f:f5:10:43:0a:9b:00:ef:8a:77:2e:f4:36:66:d2:6a:a6: + 95:b6:9f:23:3b:12:e2:89:d5:a4:c1:2c:91:4e:cb:94:e8:3f: + 22:0e:21:f9:b8:4a:81:5c:4c:63:ae:3d:05:b2:5c:5c:54:a7: + 55:8f:98:25:55:c4:a6:90:bc:19:29:b1:14:d4:e2:b0:95:e4: + ff:89:71:61:be:8a:16:85 +-----BEGIN CERTIFICATE----- +MIIGJzCCBA+gAwIBAgIBATANBgkqhkiG9w0BAQUFADCBsjELMAkGA1UEBhMCRlIx +DzANBgNVBAgMBkFsc2FjZTETMBEGA1UEBwwKU3RyYXNib3VyZzEYMBYGA1UECgwP +d3d3LmZyZWVsYW4ub3JnMRAwDgYDVQQLDAdmcmVlbGFuMS0wKwYDVQQDDCRGcmVl +bGFuIFNhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxIjAgBgkqhkiG9w0BCQEW +E2NvbnRhY3RAZnJlZWxhbi5vcmcwHhcNMTIwNDI3MTAzMTE4WhcNMjIwNDI1MTAz +MTE4WjB+MQswCQYDVQQGEwJGUjEPMA0GA1UECAwGQWxzYWNlMRgwFgYDVQQKDA93 +d3cuZnJlZWxhbi5vcmcxEDAOBgNVBAsMB2ZyZWVsYW4xDjAMBgNVBAMMBWFsaWNl +MSIwIAYJKoZIhvcNAQkBFhNjb250YWN0QGZyZWVsYW4ub3JnMIICIjANBgkqhkiG +9w0BAQEFAAOCAg8AMIICCgKCAgEA3W29+ID6194bH6ejLrIC4hb2Ugo8v6ZC+Mrc +k2dNYMNPjcOKABvxxEtBamnSaeU/IY7FC/giN622LEtV/3oDcrua0+yWuVafyxmZ +yTKUb4/GUgafRQPf/eiX9urWurtIK7XgNGFNUjYPq4dSJQPPhwCHE/LKAykWnZBX +RrX0Dq4XyApNku0IpjIjEXH+8ixE12wH8wt7DEvdO7T3N3CfUbaITl1qBX+Nm2Z6 +q4Ag/u5rl8NJfXg71ZmXA3XOj7zFvpyapRIZcPmkvZYn7SMCp8dXyXHPdpSiIWL2 +uB3KiO4JrUYvt2GzLBUThp+lNSZaZ/Q3yOaAAUkOx+1h08285Pi+P8lO+H2Xic4S +vMq1xtLg2bNoPC5KnbRfuFPuUD2/3dSiiragJ6uYDLOyWJDivKGt/72OVTEPAL9o +6T2pGZrwbQuiFGrGTMZOvWMSpQtNl+tCCXlT4mWqJDRwuMGrI4DnnGzt3IKqNwS4 +Qyo9KqjMIPwnXZAmWPm3FOKe4sFwc5fpawKO01JZewDsYTDxVj+cwXwFxbE2yBiF +z2FAHwfopwaH35p3C6lkcgP2k/zgAlnBluzACUI+MKJ/G0gv/uAhj1OHJQ3L6kn1 +SpvQ41/ueBjlunExqQSYD7GtZ1Kg8uOcq2r+WISE3Qc9MpQFFkUVllmgWGwYDuN3 +Zsez95kCAwEAAaN7MHkwCQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3BlblNT +TCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFFlfyRO6G8y5qEFKikl5 +ajb2fT7XMB8GA1UdIwQYMBaAFCNsLT0+KV14uGw+quK7Lh5sh/JTMA0GCSqGSIb3 +DQEBBQUAA4ICAQAT5wJFPqervbja5+90iKxi1d0QVtVGB+z6aoAMuWK+qgi0vgvr +mu9ot2lvTSCSnRhjeiP0SIdqFMORmBtOCFk/kYDp9M/91b+vS+S9eAlxrNCB5VOf +PqxEPp/wv1rBcE4GBO/c6HcFon3F+oBYCsUQbZDKSSZxhDm3mj7pb67FNbZbJIzJ +70HDsRe2O04oiTx+h6g6pW3cOQMgIAvFgKN5Ex727K4230B0NIdGkzuj4KSML0NM +slSAcXZ41OoSKNjy44BVEZv0ZdxTDrRM4EwJtNyggFzmtTuV02nkUj1bYYYC5f0L +ADr6s0XMyaNk8twlWYlYDZ5uKDpVRVBfiGcq0uJIzIvemhuTrofh8pBQQNkPRDFT +Rq1iTo1Ihhl3/Fl1kXk1WR3jTjNb4jHX7lIoXwpwp767HAPKGhjQ9cFbnHMEtkro +RlJYdtRq5mccDtwT0GFyoJLLBZdHHMHJz0F9H7FNk2tTQQMhK5MVYwg+LIaee586 +CQVqfbscp7evlgjLW98H+5zylRHAgoH2G79aHljNKMp9BOuq6SnEglEsiWGVtu2l +hnx8SB3sVJZHeer8f/UQQwqbAO+Kdy70NmbSaqaVtp8jOxLiidWkwSyRTsuU6D8i +DiH5uEqBXExjrj0FslxcVKdVj5glVcSmkLwZKbEU1OKwleT/iXFhvooWhQ== +-----END CERTIFICATE----- diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/org/onap/appc/asdc-client-cert.crt b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/org/onap/appc/asdc-client-cert.crt new file mode 100644 index 000000000..941c1d8f4 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/org/onap/appc/asdc-client-cert.crt @@ -0,0 +1,10 @@ +-----BEGIN CERTIFICATE----- + MIIBezCCASWgAwIBAgIQyWD8dLUoqpJFyDxrfRlrsTANBgkqhkiG9w0BAQQFADAW + MRQwEgYDVQQDEwtSb290IEFnZW5jeTAeFw0wMTEwMTkxMjU5MjZaFw0zOTEyMzEy + MzU5NTlaMBoxGDAWBgNVBAMTD1Jvb3RDZXJ0aWZpY2F0ZTBcMA0GCSqGSIb3DQEB + AQUAA0sAMEgCQQC+NFKszPjatUZKWmyWaFjir1wB93FX2u5SL+GMjgUsMs1JcTKQ + Kh0cnnQKknNkV4cTW4NPn31YCoB1+0KA3mknAgMBAAGjSzBJMEcGA1UdAQRAMD6A + EBLkCS0GHR1PAI1hIdwWZGOhGDAWMRQwEgYDVQQDEwtSb290IEFnZW5jeYIQBjds + AKoAZIoRz7jUqlw19DANBgkqhkiG9w0BAQQFAANBACJxAfP57yqaT9N+nRgAOugM + JG0aN3/peCIvL3p29epRL2xoWFvxpUUlsH2I39OZ6b8+twWCebhkv1I62segXAk= + -----END CERTIFICATE----- \ No newline at end of file diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/org/onap/appc/asdc-client.jks b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/org/onap/appc/asdc-client.jks new file mode 100644 index 000000000..eb0a0d35a Binary files /dev/null and b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/org/onap/appc/asdc-client.jks differ diff --git a/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/properties/ansible-adaptor-test.properties b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/properties/ansible-adaptor-test.properties new file mode 100644 index 000000000..1e406b6c9 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-bundle/src/test/resources/properties/ansible-adaptor-test.properties @@ -0,0 +1,109 @@ +### +# ============LICENSE_START======================================================= +# ONAP : SLI +# ================================================================================ +# Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# ============LICENSE_END========================================================= + +### +# +# Default properties for the APP-C Provider Adaptor +# +# ------------------------------------------------------------------------------------------------- +# +# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded +# to supply configuration options +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=${user.home},/opt/opendaylight/current/properties,. +appc.application.name=APPC +#Define ansible property +org.onap.appc.adaptor.ansible.clientType=appc +org.onap.appc.adaptor.ansible.trustStore=src/test/resources/org/onap/appc/asdc-client.jks +org.onap.appc.adaptor.ansible.trustStore.trustPasswd=Aa123456 +org.onap.appc.adaptor.ansible.cert=src/test/resources/org/onap/appc/asdc-client-cert.crt +org.onap.appc.adaptor.ansible.identity=http://localhost:9081/v2.0 +org.onap.appc.adaptor.ansible.username=appc +org.onap.appc.adaptor.ansible.password=appc +# +# Define the message resource bundle name to be loaded +org.onap.appc.resources=org/onap/appc/i18n/MessageResources +# +# The name of the adaptor. +org.onap.appc.provider.adaptor.name=org.onap.appc.appc_ansible_adaptor +# +# Set up the logging environment +# +org.onap.appc.logging.file=org/onap/appc/logback.xml +org.onap.appc.logging.path=${user.home};etc;../etc +org.onap.appc.logger=org.onap.appc +org.onap.appc.security.logger=org.onap.appc.security +# +# The minimum and maximum provider/tenant context pool sizes. Min=1 means that as soon +# as the provider/tenant is referenced a Context is opened and added to the pool. Max=0 +# means that the upper bound on the pool is unbounded. +org.onap.appc.provider.min.pool=1 +org.onap.appc.provider.max.pool=0 +# +# The following properties are used to configure the retry logic for connection to the +# IaaS provider(s). The retry delay property is the amount of time, in seconds, the +# application waits between retry attempts. The retry limit is the number of retries +# that are allowed before the request is failed. +org.onap.appc.provider.retry.delay=30 +org.onap.appc.provider.retry.limit=10 +# +# The trusted hosts list for SSL access when a certificate is not provided. +# +provider.trusted.hosts=* +# +# The amount of time, in seconds, to wait for a server state change (start->stop, stop->start, etc). +# If the server does not change state to a valid state within the alloted time, the operation +# fails. +org.onap.appc.server.state.change.timeout=300 +# +# The amount of time to wait, in seconds, between subsequent polls to the OpenStack provider +# to refresh the status of a resource we are waiting on. +# +org.onap.appc.openstack.poll.interval=20 +# +# The connection information to connect to the provider we are using. These properties +# are "structured" properties, in that the name is a compound name, where the nodes +# of the name can be ordered (1, 2, 3, ...). All of the properties with the same ordinal +# position are defining the same entity. For example, provider1.type and provider1.name +# are defining the same provider, whereas provider2.name and provider2.type are defining +# the values for a different provider. Any number of providers can be defined in this +# way. +# +# Don't change these 2 right now since they are hard coded in the DG +#provider1.type=appc +#provider1.name=appc +#These you can change +#provider1.identity=appc +#provider1.tenant1.name=appc +#provider1.tenant1.userid=appc +#provider1.tenant1.password=appc +# After a change to the provider make sure to recheck these values with an api call to provider1.identity/tokens +test.expected-regions=1 +test.expected-endpoints=1 +#Your OpenStack IP +#test.ip=192.168.1.2 +# Your OpenStack Platform's Keystone Port (default is 5000) +#test.port=5000 +#test.tenantid=abcde12345fghijk6789lmnopq123rst +#test.vmid=abc12345-1234-5678-890a-abcdefg12345 +# Port 8774 below is default port for OpenStack's Nova API Service +#test.url=http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345 + diff --git a/adaptors/ansible-adaptor/ansible-adaptor-installer/pom.xml b/adaptors/ansible-adaptor/ansible-adaptor-installer/pom.xml new file mode 100644 index 000000000..075db793b --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-installer/pom.xml @@ -0,0 +1,150 @@ + + + + + 4.0.0 + + + org.onap.ccsdk.parent + odlparent-lite + 2.2.0-SNAPSHOT + + + + org.onap.ccsdk.sli.adaptors + ansible-adaptor-installer + 1.3.0-SNAPSHOT + pom + + ccsdk-sli-adaptors :: ${project.artifactId} + + + ccsdk-ansible-adaptor + ${application.name} + mvn:org.onap.ccsdk.sli.adaptors/${features.boot}/${project.version}/xml/features + false + + + + + + org.onap.ccsdk.sli.adaptors + ansible-adaptor-bundle + ${project.version} + + + + + + + + maven-assembly-plugin + + + maven-repo-zip + + single + + package + + true + true + stage/${application.name}-${project.version} + + src/assembly/assemble_mvnrepo_zip.xml + + + + + installer-zip + + single + + package + + false + true + ${application.name}-${project.version} + + src/assembly/assemble_installer_zip.xml + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + + copy-dependencies + + prepare-package + + false + ${project.build.directory}/assembly/system + false + true + true + true + false + false + org.onap.ccsdk.sli.adaptors + + provided + + + + + + maven-resources-plugin + + + copy-version + + copy-resources + + + validate + + ${basedir}/target/stage + + + src/main/resources/scripts + + install-feature.sh + + true + + + + + + + + + diff --git a/adaptors/ansible-adaptor/ansible-adaptor-installer/src/assembly/assemble_installer_zip.xml b/adaptors/ansible-adaptor/ansible-adaptor-installer/src/assembly/assemble_installer_zip.xml new file mode 100644 index 000000000..cc4aa8830 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-installer/src/assembly/assemble_installer_zip.xml @@ -0,0 +1,62 @@ + + + + + + adaptor + + zip + + + + false + + + + target/stage/ + ${application.name} + 755 + + *.sh + + + + target/stage/ + ${application.name} + 644 + + *.sh + + + + + + + diff --git a/adaptors/ansible-adaptor/ansible-adaptor-installer/src/assembly/assemble_mvnrepo_zip.xml b/adaptors/ansible-adaptor/ansible-adaptor-installer/src/assembly/assemble_mvnrepo_zip.xml new file mode 100644 index 000000000..ec65e79e1 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-installer/src/assembly/assemble_mvnrepo_zip.xml @@ -0,0 +1,50 @@ + + + + + + repo + + zip + + + + false + + + + target/assembly/ + . + + + + + + diff --git a/adaptors/ansible-adaptor/ansible-adaptor-installer/src/main/resources/scripts/install-feature.sh b/adaptors/ansible-adaptor/ansible-adaptor-installer/src/main/resources/scripts/install-feature.sh new file mode 100644 index 000000000..c8214c520 --- /dev/null +++ b/adaptors/ansible-adaptor/ansible-adaptor-installer/src/main/resources/scripts/install-feature.sh @@ -0,0 +1,42 @@ +### +# ============LICENSE_START======================================================= +# ONAP : APPC +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Copyright (C) 2017 Amdocs +# ============================================================================= +# 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. +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# ============LICENSE_END========================================================= +### + +#!/bin/bash + +ODL_HOME=${ODL_HOME:-/opt/opendaylight/current} +ODL_KARAF_CLIENT=${ODL_KARAF_CLIENT:-${ODL_HOME}/bin/client} +INSTALLERDIR=$(dirname $0) + +REPOZIP=${INSTALLERDIR}/${features.boot}-${project.version}.zip + +if [ -f ${REPOZIP} ] +then + unzip -n -d ${ODL_HOME} ${REPOZIP} +else + echo "ERROR : repo zip ($REPOZIP) not found" + exit 1 +fi + +${ODL_KARAF_CLIENT} feature:repo-add ${features.repositories} +${ODL_KARAF_CLIENT} feature:install ${features.boot} diff --git a/adaptors/ansible-adaptor/pom.xml b/adaptors/ansible-adaptor/pom.xml new file mode 100644 index 000000000..65624ed6d --- /dev/null +++ b/adaptors/ansible-adaptor/pom.xml @@ -0,0 +1,181 @@ + + + + + 4.0.0 + + + org.onap.ccsdk.parent + odlparent-lite + 2.2.0-SNAPSHOT + + + + org.onap.ccsdk.sli.adaptors + ansible-adaptor + 1.3.0-SNAPSHOT + pom + + ccsdk-sli-adaptors :: ${project.artifactId} + Abstractions to interact with Ansible server via REST + + + ansible-adaptor-bundle + ansible-adaptor-installer + + + + + + org.onap.appc + ansible-adaptor-features + ${project.version} + xml + features + + + org.onap.appc + ansible-adaptor-provider + ${project.version} + + + + + + + + JCenter + JCenter Repository + http://jcenter.bintray.com + + + + + + + + + + + + + maven-javadoc-plugin + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.antlr + antlr4 + ${antlr.version} + + + org.antlr + antlr4-runtime + 4.3 + + + + + + + javadoc-no-fork + test-javadoc-no-fork + + + + aggregate + + aggregate + test-aggregate + + + + + + org.apache.maven.plugins + maven-jxr-plugin + 2.3 + + + aggregate + + aggregate + test-aggregate + + + + + + + maven-surefire-plugin + + + + org.apache.maven.plugins + maven-changelog-plugin + 2.3 + + + dual-report + + range + 30 + + + changelog + file-activity + + + + + + + org.codehaus.mojo + taglist-maven-plugin + 2.4 + + + + + diff --git a/adaptors/artifacts/pom.xml b/adaptors/artifacts/pom.xml index 58700e0ef..99dba8dda 100755 --- a/adaptors/artifacts/pom.xml +++ b/adaptors/artifacts/pom.xml @@ -32,7 +32,7 @@ org.onap.ccsdk.sli.adaptors - ccsdk-ansible-adapter + ccsdk-ansible-adaptor ${project.version} xml feature @@ -60,7 +60,7 @@ org.onap.ccsdk.sli.adaptors - ccsdk-saltstack-adapter + ccsdk-saltstack-adaptor ${project.version} xml feature @@ -84,12 +84,12 @@ org.onap.ccsdk.sli.adaptors - ansible-adapter-provider + ansible-adaptor-provider ${project.version} org.onap.ccsdk.sli.adaptors - ansible-adapter-installer + ansible-adaptor-installer ${project.version} @@ -124,12 +124,12 @@ org.onap.ccsdk.sli.adaptors - saltstack-adapter-provider + saltstack-adaptor-provider ${project.version} org.onap.ccsdk.sli.adaptors - saltstack-adapter-installer + saltstack-adaptor-installer ${project.version} diff --git a/adaptors/features/ccsdk-ansible-adapter/pom.xml b/adaptors/features/ccsdk-ansible-adapter/pom.xml deleted file mode 100644 index 7b47125e1..000000000 --- a/adaptors/features/ccsdk-ansible-adapter/pom.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - 4.0.0 - - - org.onap.ccsdk.parent - single-feature-parent - 2.2.0-SNAPSHOT - - - - org.onap.ccsdk.sli.adaptors - ccsdk-ansible-adapter - 1.3.0-SNAPSHOT - feature - - ccsdk-sli-adaptors :: features :: ${project.artifactId} - - - - - org.onap.ccsdk.sli.core - ccsdk-sli - ${project.version} - xml - features - provided - - - - ${project.groupId} - ansible-adapter-bundle - ${project.version} - - - org.powermock - powermock-api-mockito - - - - - - diff --git a/adaptors/features/ccsdk-ansible-adaptor/pom.xml b/adaptors/features/ccsdk-ansible-adaptor/pom.xml new file mode 100644 index 000000000..ebe4bdcf5 --- /dev/null +++ b/adaptors/features/ccsdk-ansible-adaptor/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + + org.onap.ccsdk.parent + single-feature-parent + 2.2.0-SNAPSHOT + + + + org.onap.ccsdk.sli.adaptors + ccsdk-ansible-adaptor + 1.3.0-SNAPSHOT + feature + + ccsdk-sli-adaptors :: features :: ${project.artifactId} + + + + + org.onap.ccsdk.sli.core + ccsdk-sli + ${project.version} + xml + features + provided + + + + ${project.groupId} + ansible-adaptor-bundle + ${project.version} + + + org.powermock + powermock-api-mockito + + + + + + diff --git a/adaptors/features/ccsdk-saltstack-adapter/pom.xml b/adaptors/features/ccsdk-saltstack-adapter/pom.xml deleted file mode 100644 index 73836112d..000000000 --- a/adaptors/features/ccsdk-saltstack-adapter/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - 4.0.0 - - - org.onap.ccsdk.parent - single-feature-parent - 2.2.0-SNAPSHOT - - - - org.onap.ccsdk.sli.adaptors - ccsdk-saltstack-adapter - 1.3.0-SNAPSHOT - feature - - ccsdk-sli-adaptors :: features :: ${project.artifactId} - - - - org.onap.ccsdk.sli.core - ccsdk-sli - ${project.version} - xml - features - - - ${project.groupId} - saltstack-adapter-provider - ${project.version} - - - org.powermock - powermock-api-mockito - - - - - diff --git a/adaptors/features/ccsdk-saltstack-adaptor/pom.xml b/adaptors/features/ccsdk-saltstack-adaptor/pom.xml new file mode 100644 index 000000000..c9846c8cc --- /dev/null +++ b/adaptors/features/ccsdk-saltstack-adaptor/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + + + org.onap.ccsdk.parent + single-feature-parent + 2.2.0-SNAPSHOT + + + + org.onap.ccsdk.sli.adaptors + ccsdk-saltstack-adaptor + 1.3.0-SNAPSHOT + feature + + ccsdk-sli-adaptors :: features :: ${project.artifactId} + + + + org.onap.ccsdk.sli.core + ccsdk-sli + ${project.version} + xml + features + + + ${project.groupId} + saltstack-adaptor-provider + ${project.version} + + + org.powermock + powermock-api-mockito + + + + + diff --git a/adaptors/features/ccsdk-sli-adaptors-all/pom.xml b/adaptors/features/ccsdk-sli-adaptors-all/pom.xml index b4c7a21ba..e23f8cb48 100644 --- a/adaptors/features/ccsdk-sli-adaptors-all/pom.xml +++ b/adaptors/features/ccsdk-sli-adaptors-all/pom.xml @@ -26,15 +26,15 @@ ${project.groupId} - ccsdk-ansible-adapter + ccsdk-ansible-adaptor ${project.version} xml features - - - - 4.0.0 - - - org.onap.ccsdk.parent - odlparent-lite - 2.2.0-SNAPSHOT - - - - org.onap.ccsdk.sli.adaptors - saltstack-adaptor - 1.3.0-SNAPSHOT - pom - - ccsdk-sli-adaptors :: ${project.artifactId} - Abstractions to interact with Saltstack server via REST - - - - saltstack-adapter-provider - saltstack-adapter-installer - - - - - - - org.onap.appc - saltstack-adapter-features - ${project.version} - xml - features - - - - org.onap.appc - saltstack-adapter-provider - ${project.version} - - - - junit - junit - 4.11 - test - - - - - - - - - - JCenter - JCenter Repository - http://jcenter.bintray.com - - - - - - - - - - - - - - - - maven-javadoc-plugin - - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.antlr - antlr4 - ${antlr.version} - - - org.antlr - antlr4-runtime - 4.3 - - - - - - - javadoc-no-fork - test-javadoc-no-fork - - - - aggregate - - aggregate - test-aggregate - - - - - - org.apache.maven.plugins - maven-jxr-plugin - 2.3 - - - aggregate - - aggregate - test-aggregate - - - - - - - maven-surefire-plugin - - - - org.apache.maven.plugins - maven-changelog-plugin - 2.3 - - - dual-report - - range - 30 - - - changelog - file-activity - - - - - - - org.codehaus.mojo - taglist-maven-plugin - 2.4 - - - - - diff --git a/adaptors/saltstack-adapter/saltstack-adapter-installer/pom.xml b/adaptors/saltstack-adapter/saltstack-adapter-installer/pom.xml deleted file mode 100644 index 9e05aeb1f..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-installer/pom.xml +++ /dev/null @@ -1,164 +0,0 @@ - - - - - 4.0.0 - - - org.onap.ccsdk.parent - odlparent-lite - 2.2.0-SNAPSHOT - - - - org.onap.ccsdk.sli.adaptors - saltstack-adapter-installer - 1.3.0-SNAPSHOT - pom - - ccsdk-sli-adaptors :: ${project.artifactId} - - - ccsdk-saltstack-adapter - ${application.name} - - mvn:org.onap.ccsdk.sli.adaptors/${features.boot}/${project.version}/xml/features - - false - - - - - - org.onap.ccsdk.sli.adaptors - saltstack-adapter-provider - ${project.version} - - - - - - - - maven-assembly-plugin - - - maven-repo-zip - - single - - package - - true - true - - stage/${application.name}-${project.version} - - - - src/assembly/assemble_mvnrepo_zip.xml - - - true - - - - installer-zip - - single - - package - - false - true - ${application.name}-${project.version} - - - - src/assembly/assemble_installer_zip.xml - - - false - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-dependencies - - copy-dependencies - - prepare-package - - false - - ${project.build.directory}/assembly/system - - false - true - true - true - false - false - org.onap.ccsdk.sli.adaptors - provided - - - - - - maven-resources-plugin - - - copy-version - - copy-resources - - - validate - - ${basedir}/target/stage - - - - src/main/resources/scripts - - - install-feature.sh - - true - - - - - - - - - diff --git a/adaptors/saltstack-adapter/saltstack-adapter-installer/src/assembly/assemble_installer_zip.xml b/adaptors/saltstack-adapter/saltstack-adapter-installer/src/assembly/assemble_installer_zip.xml deleted file mode 100644 index d307e4f30..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-installer/src/assembly/assemble_installer_zip.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - adapter - - zip - - - - false - - - - target/stage/ - ${application.name} - 755 - - *.sh - - - - target/stage/ - ${application.name} - 644 - - *.sh - - - - - - diff --git a/adaptors/saltstack-adapter/saltstack-adapter-installer/src/assembly/assemble_mvnrepo_zip.xml b/adaptors/saltstack-adapter/saltstack-adapter-installer/src/assembly/assemble_mvnrepo_zip.xml deleted file mode 100644 index 1b1bf0b6b..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-installer/src/assembly/assemble_mvnrepo_zip.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - repo - - zip - - - - false - - - - target/assembly/ - . - - - - - - diff --git a/adaptors/saltstack-adapter/saltstack-adapter-installer/src/main/resources/scripts/install-feature.sh b/adaptors/saltstack-adapter/saltstack-adapter-installer/src/main/resources/scripts/install-feature.sh deleted file mode 100644 index 38782cabb..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-installer/src/main/resources/scripts/install-feature.sh +++ /dev/null @@ -1,42 +0,0 @@ -### -# ============LICENSE_START======================================================= -# ONAP : APPC -# ================================================================================ -# Copyright (C) 2018 Samsung Electronics. All rights reserved. -# ================================================================================ -# -# ============================================================================= -# 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. -# -# -# ============LICENSE_END========================================================= -### - -#!/bin/bash - -ODL_HOME=${ODL_HOME:-/opt/opendaylight/current} -ODL_KARAF_CLIENT=${ODL_KARAF_CLIENT:-${ODL_HOME}/bin/client} -INSTALLERDIR=$(dirname $0) - -REPOZIP=${INSTALLERDIR}/${features.boot}-${project.version}.zip - -if [ -f ${REPOZIP} ] -then - unzip -n -d ${ODL_HOME} ${REPOZIP} -else - echo "ERROR : repo zip ($REPOZIP) not found" - exit 1 -fi - -${ODL_KARAF_CLIENT} feature:repo-add ${features.repositories} -${ODL_KARAF_CLIENT} feature:install ${features.boot} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/.gitignore b/adaptors/saltstack-adapter/saltstack-adapter-provider/.gitignore deleted file mode 100644 index 4e1ad823a..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -# ============LICENSE_START========================================== -# ONAP : CCSDK -# =================================================================== -# Copyright (C) 2017-2018 Samsung Electronics. All rights reserved. -# =================================================================== -# -# Unless otherwise specified, all software contained herein is licensed -# under the Apache License, Version 2.0 (the License); -# you may not use this software 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. -# -# -# ============LICENSE_END============================================ -/bin/ -/target/ -/target-ide/ -/.settings/ diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/pom.xml b/adaptors/saltstack-adapter/saltstack-adapter-provider/pom.xml deleted file mode 100644 index 92e374565..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/pom.xml +++ /dev/null @@ -1,115 +0,0 @@ - - - - - 4.0.0 - - - org.onap.ccsdk.parent - binding-parent - 2.2.0-SNAPSHOT - - - - org.onap.ccsdk.sli.adaptors - saltstack-adapter-provider - 1.3.0-SNAPSHOT - bundle - - ccsdk-sli-adaptors :: ${project.artifactId} - - - - - org.onap.ccsdk.sli.core - sli-core-artifacts - ${project.version} - pom - import - - - - - - com.att.eelf - eelf-core - - - commons-codec - commons-codec - - - commons-logging - commons-logging - 1.2 - - - org.osgi - org.osgi.core - provided - - - org.slf4j - slf4j-api - - - org.slf4j - jcl-over-slf4j - - - - - - - - org.apache.sshd - sshd-core - 1.7.0 - - - - - - org.apache.commons - commons-io - - - - org.codehaus.jettison - jettison - - - - junit - junit - test - - - - org.onap.ccsdk.sli.core - sli-common - - - - org.onap.ccsdk.sli.core - sli-provider - - - - org.json - json - - - - diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdapter.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdapter.java deleted file mode 100644 index 346910a39..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdapter.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2018 Samsung Electronics. All rights reserved. - * ================================================================================ - * - * ============================================================================= - * 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. - * - * - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.saltstack; - -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -import java.util.Map; - -/** - * This interface defines the operations that the Saltstack adapter exposes. - */ -public interface SaltstackAdapter extends SvcLogicJavaPlugin { - /** - * Returns the symbolic name of the adapter - * - * @return The adapter name - */ - String getAdapterName(); - - /* Method to post a single command request for execution on SaltState server - * The response from Saltstack comes in json format and it is automatically put - * to context for DGs access, with a certain prefix*/ - void reqExecCommand(Map params, SvcLogicContext ctx) throws SvcLogicException; - - /* Method for execution of saltstack SLS command on SaltState server - * The response from Saltstack comes in json format and it is automatically put - * to context for DGs access, with a certain prefix*/ - void reqExecSLS(Map params, SvcLogicContext ctx) throws SvcLogicException; - - /* When SLS file is created/available then this Method can be used to post - * the file to saltstack server and execute the SLS file on SaltState server - * The response from Saltstack comes in json format and it is automatically put - * to context for DGs access, with a certain prefix*/ - void reqExecSLSFile(Map params, SvcLogicContext ctx) throws SvcLogicException; -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdapterPropertiesProvider.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdapterPropertiesProvider.java deleted file mode 100755 index a6b707afc..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdapterPropertiesProvider.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2018 Samsung Electronics. All rights reserved. - * ================================================================================ - * - * ============================================================================= - * 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. - * - * - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.saltstack; - -import java.util.Properties; - -public interface SaltstackAdapterPropertiesProvider { - - public Properties getProperties(); -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/ConnectionBuilder.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/ConnectionBuilder.java deleted file mode 100644 index 48469fdd5..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/ConnectionBuilder.java +++ /dev/null @@ -1,172 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2018 Samsung Electronics. All rights reserved. - * ================================================================================ - * - * ============================================================================= - * 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. - * - * - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.saltstack.impl; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.ccsdk.sli.adaptors.saltstack.model.SshException; -import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResult; -import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResultCodes; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -/** - * Returns a custom SSH client - * - based on options - * - can create one with ssl using an X509 certificate that does NOT have a known CA - * - create one which trusts ALL SSL certificates - * - return default sshclient (which only trusts known CAs from default cacerts file for process) this is the default - * option - **/ -public class ConnectionBuilder { - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(ConnectionBuilder.class); - SshConnection sshConnection; - - /** - * Constructor that initializes an ssh client based on username and password - **/ - public ConnectionBuilder(String host, String port, String userName, String userPasswd) { - sshConnection = new SshConnection(host, Integer.parseInt(port), userName, userPasswd); - } - - /** - * Constructor that initializes an ssh client based on ssh certificate - * This is still not supported in 1.3.0 version - **/ - public ConnectionBuilder(String host, String port, String certFile) { - sshConnection = new SshConnection(host, Integer.parseInt(port), certFile); - } - - - /** - * 1. Connect to SSH server. - * 2. Exec remote command over SSH. Return command execution status. - * Command output is written to out or err stream. - * - * @param cmd Commands to execute - * @return command execution status - */ - public SaltstackResult connectNExecute(String cmd, long execTimeout) throws IOException { - return connectNExecute(cmd, false, execTimeout); - } - - /** - * 1. Connect to SSH server with retry enabled. - * 2. Exec remote command over SSH. Return command execution status. - * Command output is written to out or err stream. - * - * @param cmd Commands to execute - * @param withRetry make a SSH connection with default retry. - * @return command execution status - */ - public SaltstackResult connectNExecute(String cmd, boolean withRetry, long execTimeout) - throws IOException { - - SaltstackResult result = new SaltstackResult(); - ByteArrayOutputStream out = null; - ByteArrayOutputStream errs = null; - if (execTimeout >= 0) { - sshConnection.setExecTimeout(execTimeout); - } - - try { - if (withRetry) { - sshConnection.connectWithRetry(); - } else { - sshConnection.connect(); - } - out = new ByteArrayOutputStream(); - errs = new ByteArrayOutputStream(); - int resultCode = sshConnection.execCommand(cmd, out, errs); - sshConnection.disconnect(); - if (resultCode != 0) { - return sortExitStatus(resultCode, errs.toString(), cmd); - } - result.setStatusCode(SaltstackResultCodes.SUCCESS.getValue()); - result.setStatusMessage("Success"); - result.setOutputMessage(out); - } catch (SshException io) { - if (io.toString().equalsIgnoreCase("Authentication failed")) { - logger.error(io.toString()); - result.setStatusCode(SaltstackResultCodes.USER_UNAUTHORIZED.getValue()); - result.setStatusMessage(io.toString()); - return result; - } - logger.error("Caught Exception", io); - result.setStatusCode(SaltstackResultCodes.SSH_EXCEPTION.getValue()); - result.setStatusMessage(io.getMessage()); - } catch (Exception io) { - logger.error("Caught Exception", io); - result.setStatusCode(SaltstackResultCodes.SSH_EXCEPTION.getValue()); - result.setStatusMessage(io.getMessage()); - } finally { - if (out != null) { - out.close(); - } - if (errs != null) { - errs.close(); - } - } - return result; - } - - /** - * Print Reasonable error messages based on SSH Exit status code - * */ - public SaltstackResult sortExitStatus(int exitStatus, String errMess, String cmd) { - SaltstackResult result = new SaltstackResult(); - if (exitStatus == 255 || exitStatus == 1) { - String errMessage = "Error executing command [" + cmd + "] over SSH [" + sshConnection.toString() - + "]. Exit Code " + exitStatus + " and Error message : " + - "Malformed configuration. " + errMess; - logger.error(errMessage); - result.setStatusCode(SaltstackResultCodes.INVALID_COMMAND.getValue()); - result.setStatusMessage(errMessage); - } else if (exitStatus == 5 || exitStatus == 65) { - String errMessage = "Error executing command [" + cmd + "] over SSH [" + sshConnection.toString() - + "]. Exit Code " + exitStatus + " and Error message : " + - "Host not allowed to connect. " + errMess; - logger.error(errMessage); - result.setStatusCode(SaltstackResultCodes.USER_UNAUTHORIZED.getValue()); - result.setStatusMessage(errMessage); - } else if (exitStatus == 67 || exitStatus == 73) { - String errMessage = "Error executing command [" + cmd + "] over SSH [" + sshConnection.toString() - + "]. Exit Code " + exitStatus + " and Error message : " + - "Key exchange failed. " + errMess; - logger.error(errMessage); - result.setStatusCode(SaltstackResultCodes.CERTIFICATE_ERROR.getValue()); - result.setStatusMessage(errMessage); - } else { - String errMessage = "Error executing command [" + cmd + "] over SSH [" + sshConnection.toString() - + "]. Exit Code " + exitStatus + " and Error message : " + errMess; - logger.error(errMessage); - result.setStatusCode(SaltstackResultCodes.UNKNOWN_EXCEPTION.getValue()); - result.setStatusMessage(errMessage); - } - return result; - } -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterImpl.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterImpl.java deleted file mode 100644 index 34321ea59..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterImpl.java +++ /dev/null @@ -1,446 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2018 Samsung Electronics. All rights reserved. - * ================================================================================ - * - * ============================================================================= - * 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. - * - * - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.saltstack.impl; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.json.JSONException; -import org.json.JSONObject; -import org.onap.ccsdk.sli.adaptors.saltstack.SaltstackAdapter; -import org.onap.ccsdk.sli.adaptors.saltstack.SaltstackAdapterPropertiesProvider; -import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackMessageParser; -import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResult; -import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResultCodes; -import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackServerEmulator; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; -import java.util.Properties; - -/** - * This class implements the {@link SaltstackAdapter} interface. This interface defines the behaviors - * that our service provides. - */ -public class SaltstackAdapterImpl implements SaltstackAdapter { - - /** - * The constant for the status code for a failed outcome - */ - @SuppressWarnings("nls") - public static final String OUTCOME_FAILURE = "failure"; - /** - * The constant for the status code for a successful outcome - */ - @SuppressWarnings("nls") - public static final String OUTCOME_SUCCESS = "success"; - public static final String CONNECTION_RETRY = "withRetry"; - private static final String APPC_EXCEPTION_CAUGHT = "APPCException caught"; - /** - * Adapter Name - */ - private static final String ADAPTER_NAME = "Saltstack Adapter"; - private static final String RESULT_CODE_ATTRIBUTE_NAME = "org.onap.appc.adapter.saltstack.result.code"; - private static final String MESSAGE_ATTRIBUTE_NAME = "org.onap.appc.adapter.saltstack.message"; - private static final String ID_ATTRIBUTE_NAME = "org.onap.appc.adapter.saltstack.Id"; - private static final String CLIENT_TYPE_PROPERTY_NAME = "org.onap.appc.adapter.saltstack.clientType"; - private static final String SS_SERVER_HOSTNAME = "org.onap.appc.adapter.saltstack.host"; - private static final String SS_SERVER_PORT = "org.onap.appc.adapter.saltstack.port"; - private static final String SS_SERVER_USERNAME = "org.onap.appc.adapter.saltstack.userName"; - private static final String SS_SERVER_PASSWD = "org.onap.appc.adapter.saltstack.userPasswd"; - private static final String SS_SERVER_SSH_KEY = "org.onap.appc.adapter.saltstack.sshKey"; - - private static final String COMMAND_IN_JSON_OUT = " --out=json --static "; - private static final String COMMAND_CHANGE_DEFAULT_DIR = " cd /srv/salt/ ;"; - - /** - * The logger to be used - */ - private static final EELFLogger logger = EELFManager.getInstance().getLogger(SaltstackAdapterImpl.class); - /** - * Connection object - **/ - private ConnectionBuilder sshClient; - - /** - * Saltstack API Message Handlers - **/ - private SaltstackMessageParser messageProcessor; - - /** - * indicator whether in test mode - **/ - private boolean testMode = false; - - /** - * server emulator object to be used if in test mode - **/ - private SaltstackServerEmulator testServer; - - /** - * This default constructor is used as a work around because the activator wasn't getting called - */ - public SaltstackAdapterImpl() throws SvcLogicException { - initialize(new SaltstackAdapterPropertiesProviderImpl()); - } - - public SaltstackAdapterImpl(SaltstackAdapterPropertiesProvider propProvider) throws SvcLogicException { - initialize(propProvider); - } - - /** - * Used for jUnit test and testing interface - */ - public SaltstackAdapterImpl(boolean mode) { - testMode = mode; - testServer = new SaltstackServerEmulator(); - messageProcessor = new SaltstackMessageParser(); - } - - /** - * Returns the symbolic name of the adapter - * - * @return The adapter name - * @see SaltstackAdapter#getAdapterName() - */ - @Override - public String getAdapterName() { - return ADAPTER_NAME; - } - - /** - * Method posts info to Context memory in case of an error and throws a - * SvcLogicException causing SLI to register this as a failure - */ - @SuppressWarnings("static-method") - private void doFailure(SvcLogicContext svcLogic, int code, String message) throws SvcLogicException { - logger.error(APPC_EXCEPTION_CAUGHT, message); - svcLogic.setStatus(OUTCOME_FAILURE); - svcLogic.setAttribute(RESULT_CODE_ATTRIBUTE_NAME, Integer.toString(code)); - svcLogic.setAttribute(MESSAGE_ATTRIBUTE_NAME, message); - throw new SvcLogicException("Saltstack Adapter Error = " + message); - } - - /** - * initialize the Saltstack adapter based on default and over-ride configuration data - */ - private void initialize(SaltstackAdapterPropertiesProvider propProvider) throws SvcLogicException { - - - Properties props = propProvider.getProperties(); - - // Create the message processor instance - messageProcessor = new SaltstackMessageParser(); - - // Create the ssh client instance - // type of client is extracted from the property file parameter - // org.onap.appc.adapter.saltstack.clientType - // It can be : - // 1. BASIC. SSH Connection using username and password - // 2. SSH_CERT (trust only those whose certificates have been stored in the SSH KEY file) - // 3. DEFAULT SSH Connection without any authentication - - try { - String clientType = props.getProperty(CLIENT_TYPE_PROPERTY_NAME); - logger.info("Saltstack ssh client type set to " + clientType); - - if ("BASIC".equalsIgnoreCase(clientType)) { - logger.info("Creating ssh client connection"); - // set path to keystore file - String sshHost = props.getProperty(SS_SERVER_HOSTNAME); - String sshPort = reqServerPort(props); - String sshUserName = props.getProperty(SS_SERVER_USERNAME); - String sshPassword = props.getProperty(SS_SERVER_PASSWD); - sshClient = new ConnectionBuilder(sshHost, sshPort, sshUserName, sshPassword); - } else if ("SSH_CERT".equalsIgnoreCase(clientType)) { - // set path to keystore file - String sshKey = props.getProperty(SS_SERVER_SSH_KEY); - String sshHost = props.getProperty(SS_SERVER_HOSTNAME); - String sshPort = reqServerPort(props); - logger.info("Creating ssh client with ssh KEY from " + sshKey); - sshClient = new ConnectionBuilder(sshHost, sshPort, sshKey); - } else { - logger.info("No saltstack-adapter.properties defined so reading from DG props"); - sshClient = null; - } - } catch (NumberFormatException e) { - logger.error("Error Initializing Saltstack Adapter due to Unknown Exception", e); - throw new SvcLogicException("Saltstack Adapter Property file parsing Error = port in property file has to be an integer."); - } catch (Exception e) { - logger.error("Error Initializing Saltstack Adapter due to Exception", e); - throw new SvcLogicException("Saltstack Adapter Property file parsing Error = " + e.getMessage()); - } - logger.info("Initialized Saltstack Adapter"); - } - - private String reqServerPort(Properties props) { - // use default port if null - if (props.getProperty(SS_SERVER_PORT) == null) { - return "22"; - } - return props.getProperty(SS_SERVER_PORT); - } - - private void setSSHClient(Map params) throws SvcLogicException { - if (sshClient == null) { - logger.info("saltstack-adapter.properties not defined so reading saltstack host and " + - "auth details from DG's parameters"); - String sshHost = messageProcessor.reqHostNameResult(params); - String sshPort = messageProcessor.reqPortResult(params); - String sshUserName = messageProcessor.reqUserNameResult(params); - String sshPassword = messageProcessor.reqPasswordResult(params); - logger.info("Creating ssh client with BASIC Auth"); - if (!testMode) { - sshClient = new ConnectionBuilder(sshHost, sshPort, sshUserName, sshPassword); - } - } - } - - private String parseEnvParam(JSONObject envParams) { - StringBuilder envParamBuilder = new StringBuilder(); - if (envParams != null) { - for (Object key : envParams.keySet()) { - if (envParamBuilder.length() > 0) { - envParamBuilder.append(", "); - } - envParamBuilder.append(key + "=" + envParams.get((String) key)); - logger.info("EnvParameters : " + envParamBuilder); - } - } - return envParamBuilder.toString(); - } - - private String parseFileParam(JSONObject fileParams) { - StringBuilder fileParamBuilder = new StringBuilder(); - if (fileParams != null) { - for (Object key : fileParams.keySet()) { - fileParamBuilder.append("echo -e \"" + fileParams.get((String) key) + "\" > /srv/salt/" + key).append("; "); - logger.info("FileParameters : " + fileParamBuilder); - } - } - return fileParamBuilder.toString(); - } - - private String putToCommands(SvcLogicContext ctx, String slsFileName, - String applyTo, JSONObject envParams, JSONObject fileParams) throws SvcLogicException { - - StringBuilder constructedCommand = new StringBuilder(); - try { - File file = new File(slsFileName); - String slsFile = file.getName(); - if (!slsFile.substring(slsFile.lastIndexOf("."), - slsFile.length()).equalsIgnoreCase(".sls")) { - doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), "Input file " + - "is not of type .sls"); - } - try(InputStream in = new FileInputStream(file)){ - byte[] data = new byte[(int) file.length()]; - in.read(data); - String str = new String(data, "UTF-8"); - String slsWithoutExtn = stripExtension(slsFile); - constructedCommand.append(parseFileParam(fileParams)).append("echo -e \"").append(str).append("\" > /srv/salt/"). - append(slsFile).append("; ").append(COMMAND_CHANGE_DEFAULT_DIR).append(" salt '"). - append(applyTo).append("' state.apply ").append(slsWithoutExtn).append(" ").append(parseEnvParam(envParams)).append(COMMAND_IN_JSON_OUT); - } - logger.info("Command to be executed on server : " + constructedCommand.toString()); - - } catch (FileNotFoundException e) { - doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), "Input SLS file " + - "not found in path : " + slsFileName + ". " + e.getMessage()); - } catch (IOException e) { - doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), "Input SLS file " + - "error in path : " + slsFileName + ". " + e.getMessage()); - } catch (StringIndexOutOfBoundsException e) { - doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), "Input file " + - "is not of type .sls"); - } - return constructedCommand.toString(); - } - - private String stripExtension(String str) { - if (str == null) { - return null; - } - int pos = str.lastIndexOf("."); - if (pos == -1) { - return str; - } - return str.substring(0, pos); - } - - private String putToCommands(String slsName, String applyTo, JSONObject envParams, JSONObject fileParams) { - - StringBuilder constructedCommand = new StringBuilder(); - - constructedCommand.append(parseFileParam(fileParams)).append(COMMAND_CHANGE_DEFAULT_DIR).append(" salt '").append(applyTo) - .append("' state.apply ").append(slsName).append(" ").append(parseEnvParam(envParams)).append(COMMAND_IN_JSON_OUT); - - logger.info("Command to be executed on server : " + constructedCommand.toString()); - return constructedCommand.toString(); - } - - private void checkResponseStatus(SaltstackResult testResult, SvcLogicContext ctx, String reqID, boolean slsExec) - throws SvcLogicException { - - // Check status of test request returned by Agent - if (testResult.getStatusCode() != SaltstackResultCodes.FINAL_SUCCESS.getValue()) { - ctx.setAttribute(ID_ATTRIBUTE_NAME, reqID); - doFailure(ctx, testResult.getStatusCode(), "Request for execution of command failed. Reason = " + testResult.getStatusMessage()); - } else { - logger.info(String.format("Execution of request : successful.")); - ctx.setAttribute(RESULT_CODE_ATTRIBUTE_NAME, Integer.toString(testResult.getStatusCode())); - ctx.setAttribute(MESSAGE_ATTRIBUTE_NAME, OUTCOME_SUCCESS); - ctx.setAttribute(ID_ATTRIBUTE_NAME, reqID); - } - } - - // Public Method to post single command request to execute saltState. Posts the following back - // to Svc context memory - // org.onap.appc.adapter.saltstack.req.code : 100 if successful - // org.onap.appc.adapter.saltstack.req.messge : any message - // org.onap.appc.adapter.saltstack.req.Id : a unique uuid to reference the request - @Override - public void reqExecCommand(Map params, SvcLogicContext ctx) throws SvcLogicException { - String reqID; - boolean slsExec; - SaltstackResult testResult; - setSSHClient(params); - try { - reqID = messageProcessor.reqId(params); - String commandToExecute = messageProcessor.reqCmd(params); - slsExec = messageProcessor.reqIsSLSExec(params); - long execTimeout = messageProcessor.reqExecTimeout(params); - testResult = execCommand(ctx, params, commandToExecute, execTimeout); - testResult = messageProcessor.parseResponse(ctx, reqID, testResult, slsExec); - checkResponseStatus(testResult, ctx, reqID, slsExec); - } catch (IOException e) { - doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), - "IOException in file stream : " + e.getMessage()); - } - } - - /** - * Public Method to post SLS command request to execute saltState on server. Posts the following back - * to Svc context memory - *

- * org.onap.appc.adapter.saltstack.req.code : 200 if successful - * org.onap.appc.adapter.saltstack.req.messge : any message - * org.onap.appc.adapter.saltstack.req.Id : a unique uuid to reference the request - */ - @Override - public void reqExecSLS(Map params, SvcLogicContext ctx) throws SvcLogicException { - String reqID; - SaltstackResult testResult; - setSSHClient(params); - try { - reqID = messageProcessor.reqId(params); - String slsName = messageProcessor.reqSlsName(params); - String applyTo = messageProcessor.reqApplyToDevices(params); - long execTimeout = messageProcessor.reqExecTimeout(params); - JSONObject envParams = messageProcessor.reqEnvParameters(params); - JSONObject fileParams = messageProcessor.reqFileParameters(params); - - String commandToExecute = putToCommands(slsName, applyTo, envParams, fileParams); - testResult = execCommand(ctx, params, commandToExecute, execTimeout); - testResult = messageProcessor.parseResponse(ctx, reqID, testResult, true); - checkResponseStatus(testResult, ctx, reqID, true); - } catch (IOException e) { - doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), - "IOException in file stream : " + e.getMessage()); - } catch (JSONException e) { - doFailure(ctx, SaltstackResultCodes.INVALID_COMMAND.getValue(), e.getMessage()); - } - } - - /** - * Public Method to post SLS file request to execute saltState. Posts the following back - * to Svc context memory - *

- * org.onap.appc.adapter.saltstack.req.code : 100 if successful - * org.onap.appc.adapter.saltstack.req.messge : any message - * org.onap.appc.adapter.saltstack.req.Id : a unique uuid to reference the request - */ - @Override - public void reqExecSLSFile(Map params, SvcLogicContext ctx) throws SvcLogicException { - String reqID; - SaltstackResult testResult; - setSSHClient(params); - try { - reqID = messageProcessor.reqId(params); - String slsFile = messageProcessor.reqSlsFile(params); - String applyTo = messageProcessor.reqApplyToDevices(params); - long execTimeout = messageProcessor.reqExecTimeout(params); - JSONObject envParams = messageProcessor.reqEnvParameters(params); - JSONObject fileParams = messageProcessor.reqFileParameters(params); - - String commandToExecute = putToCommands(ctx, slsFile, applyTo, envParams, fileParams); - testResult = execCommand(ctx, params, commandToExecute, execTimeout); - testResult = messageProcessor.parseResponse(ctx, reqID, testResult, true); - checkResponseStatus(testResult, ctx, reqID, true); - } catch (IOException e) { - doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), - "IOException in file stream : " + e.getMessage()); - } - } - - public SaltstackResult execCommand(SvcLogicContext ctx, Map params, String commandToExecute, - long execTimeout) - throws SvcLogicException { - - //convert execTimeout to Milliseconds - execTimeout = execTimeout * 1000; - SaltstackResult testResult = new SaltstackResult(); - try { - if (params.get(CONNECTION_RETRY) == null) { - if (!testMode) { - testResult = sshClient.connectNExecute(commandToExecute, execTimeout); - } else { - testResult = testServer.mockReqExec(params); - } - } else if (params.get(CONNECTION_RETRY).equalsIgnoreCase("true")) { - if (!testMode) { - testResult = sshClient.connectNExecute(commandToExecute, true, execTimeout); - } else { - testResult = testServer.mockReqExec(params); - } - } else { - if (!testMode) { - testResult = sshClient.connectNExecute(commandToExecute, execTimeout); - } else { - testResult = testServer.mockReqExec(params); - } - } - } catch (IOException e) { - doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), - "IOException in file stream : " + e.getMessage()); - } - return testResult; - } -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterPropertiesProviderImpl.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterPropertiesProviderImpl.java deleted file mode 100755 index 8f0d9857a..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterPropertiesProviderImpl.java +++ /dev/null @@ -1,192 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2018 Samsung Electronics. All rights reserved. - * ================================================================================ - * - * ============================================================================= - * 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. - * - * - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.saltstack.impl; - -import org.onap.ccsdk.sli.adaptors.saltstack.SaltstackAdapterPropertiesProvider; -import org.onap.ccsdk.sli.core.sli.ConfigurationException; -import org.onap.ccsdk.sli.core.utils.JREFileResolver; -import org.onap.ccsdk.sli.core.utils.KarafRootFileResolver; -import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver; -import org.onap.ccsdk.sli.core.utils.common.CoreDefaultFileResolver; -import org.onap.ccsdk.sli.core.utils.common.SdncConfigEnvVarFileResolver; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Optional; -import java.util.Properties; -import java.util.Vector; - -/** - * Responsible for determining the properties file to use and instantiating the - * SqlResource Service. The priority for properties file - * resolution is as follows: - *

- *

    - *
  1. A directory identified by the system environment variable - * SDNC_CONFIG_DIR
  2. - *
  3. The default directory DEFAULT_DBLIB_PROP_DIR
  4. - *
  5. A directory identified by the JRE argument - * sql-resource.properties
  6. - *
  7. A sql-resource.properties file located in the karaf root - * directory
  8. - *
- */ -public class SaltstackAdapterPropertiesProviderImpl implements SaltstackAdapterPropertiesProvider { - - private static final Logger LOG = LoggerFactory.getLogger(SaltstackAdapterPropertiesProviderImpl.class); - - /** - * The name of the properties file for database configuration - */ - private static final String SALTSTACKADAPTER_PROP_FILE_NAME = "saltstack-adapter.properties"; - - /** - * A prioritized list of strategies for resolving sql-resource properties files. - */ - private Vector saltstackAdapterPropertiesFileResolvers = new Vector<>(); - - /** - * The configuration properties for the db connection. - */ - private Properties properties; - - /** - * Set up the prioritized list of strategies for resolving dblib properties - * files. - */ - public SaltstackAdapterPropertiesProviderImpl() { - saltstackAdapterPropertiesFileResolvers - .add(new SdncConfigEnvVarFileResolver("Using property file (1) from environment variable")); - saltstackAdapterPropertiesFileResolvers.add(new CoreDefaultFileResolver("Using property file (2) from default directory")); - - saltstackAdapterPropertiesFileResolvers.add( - new JREFileResolver("Using property file (3) from JRE argument", SaltstackAdapterPropertiesProviderImpl.class)); - saltstackAdapterPropertiesFileResolvers.add(new KarafRootFileResolver("Using property file (4) from karaf root", this)); - - // determines properties file as according to the priority described in the - // class header comment - final File propertiesFile = determinePropertiesFile(this); - if (propertiesFile != null) { - try (FileInputStream fileInputStream = new FileInputStream(propertiesFile)) { - properties = new Properties(); - properties.load(fileInputStream); - } catch (final IOException e) { - LOG.error("Failed to load properties for file: {}", propertiesFile.toString(), - new ConfigurationException("Failed to load properties for file: " + propertiesFile.toString(), - e)); - } - } else { - // Try to read properties as resource - - InputStream propStr = getClass().getResourceAsStream("/" + SALTSTACKADAPTER_PROP_FILE_NAME); - if (propStr != null) { - properties = new Properties(); - try { - properties.load(propStr); - propStr.close(); - } catch (IOException e) { - properties = null; - } - } - - } - - if (properties == null) { - reportFailure("Missing configuration properties resource(3)", new ConfigurationException( - "Missing configuration properties resource(3): " + SALTSTACKADAPTER_PROP_FILE_NAME)); - - LOG.info("Defaulting org.onap.appc.adapter.saltstack.clientType to NONE"); - - properties = new Properties(); - properties.setProperty("org.onap.appc.adapter.saltstack.clientType", "NONE"); - } - } - - /** - * Reports the method chosen for properties resolution to the - * Logger. - * - * @param message Some user friendly message - * @param fileOptional The file location of the chosen properties file - * @return the file location of the chosen properties file - */ - private static File reportSuccess(final String message, final Optional fileOptional) { - if (fileOptional.isPresent()) { - final File file = fileOptional.get(); - LOG.info("{} {}", message, file.getPath()); - return file; - } - return null; - } - - /** - * Reports fatal errors. This is the case in which no properties file could be - * found. - * - * @param message An appropriate fatal error message - * @param configurationException An exception describing what went wrong during resolution - */ - private static void reportFailure(final String message, final ConfigurationException configurationException) { - - LOG.error("{}", message, configurationException); - } - - /** - * Extract svclogic config properties. - * - * @return the svclogic config properties - */ - public Properties getProperties() { - return properties; - } - - /** - * Determines the sql-resource properties file to use based on the following priority: - *
    - *
  1. A directory identified by the system environment variable - * SDNC_CONFIG_DIR
  2. - *
  3. The default directory DEFAULT_DBLIB_PROP_DIR
  4. - *
  5. A directory identified by the JRE argument - * sql-resource.properties
  6. - *
  7. A sql-resource.properties file located in the karaf root - * directory
  8. - *
- */ - File determinePropertiesFile(final SaltstackAdapterPropertiesProviderImpl resourceProvider) { - - for (final PropertiesFileResolver sliPropertiesFileResolver : saltstackAdapterPropertiesFileResolvers) { - final Optional fileOptional = sliPropertiesFileResolver.resolveFile(SALTSTACKADAPTER_PROP_FILE_NAME); - if (fileOptional.isPresent()) { - return reportSuccess(sliPropertiesFileResolver.getSuccessfulResolutionMessage(), fileOptional); - } - } - - return null; - } -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java deleted file mode 100644 index 25d2d8402..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java +++ /dev/null @@ -1,217 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2018 Samsung Electronics. All rights reserved. - * ================================================================================ - * - * ============================================================================= - * 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. - * - * - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.saltstack.impl; - -import java.io.OutputStream; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.security.KeyPair; -import org.apache.sshd.client.SshClient; -import org.apache.sshd.client.channel.ChannelExec; -import org.apache.sshd.client.future.AuthFuture; -import org.apache.sshd.client.future.OpenFuture; -import org.apache.sshd.client.session.ClientSession; -import org.apache.sshd.common.keyprovider.FileKeyPairProvider; -import org.apache.sshd.common.keyprovider.KeyPairProvider; -import org.onap.ccsdk.sli.adaptors.saltstack.model.Constants; -import org.onap.ccsdk.sli.adaptors.saltstack.model.SshException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -/** - * Implementation of SshConnection interface based on Apache MINA SSHD library. - */ -class SshConnection { - - private static final EELFLogger logger = EELFManager.getInstance().getApplicationLogger(); - - private static final long AUTH_TIMEOUT = 60000; - private static final long EXEC_TIMEOUT = 120000; - private String host; - private int port; - private String username; - private String password; - private long timeout = EXEC_TIMEOUT; - private String keyFile; - private SshClient sshClient; - private ClientSession clientSession; - - public SshConnection(String host, int port, String username, String password, String keyFile) { - this.host = host; - this.port = port; - this.username = username; - this.password = password; - this.keyFile = keyFile; - } - - public SshConnection(String host, int port, String username, String password) { - this(host, port, username, password, null); - } - - public SshConnection(String host, int port, String keyFile) { - this(host, port, null, null, keyFile); - } - - public void connect() { - sshClient = SshClient.setUpDefaultClient(); - sshClient.start(); - try { - clientSession = - sshClient.connect(username, host, port).getSession(); - if (password != null) { - clientSession.addPasswordIdentity(password); - } else if (keyFile != null) { - Path keyFilePath = Paths.get(keyFile); - KeyPairProvider keyPairProvider = new FileKeyPairProvider(keyFilePath); - KeyPair keyPair = keyPairProvider.loadKeys().iterator().next(); - clientSession.addPublicKeyIdentity(keyPair); - } - AuthFuture authFuture = clientSession.auth(); - authFuture.await(AUTH_TIMEOUT); - if (!authFuture.isSuccess()) { - throw new SshException("Error establishing ssh connection to [" + username + "@" + host + ":" + port - + "]. Authentication failed."); - } - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new SshException("Error establishing ssh connection to [" + username + "@" + host + ":" + port + "].", - e); - } - if (logger.isDebugEnabled()) { - logger.debug("SSH: connected to [" + toString() + "]"); - } - } - - public void connectWithRetry() { - int retryCount; - int retryDelay; - int retriesLeft; - retryCount = Constants.DEFAULT_CONNECTION_RETRY_COUNT; - retryDelay = Constants.DEFAULT_CONNECTION_RETRY_DELAY; - retriesLeft = retryCount + 1; - do { - try { - this.connect(); - break; - } catch (RuntimeException e) { - if (retriesLeft > 1) { - logger.debug("SSH Connection failed. Waiting for change in server's state."); - waitForConnection(retryDelay); - retriesLeft--; - logger.debug("Retrying SSH connection. Attempt [" + Integer.toString(retryCount - retriesLeft + 1) - + "] out of [" + retryCount + "]"); - } else { - throw e; - } - } - } while (retriesLeft > 0); - } - - public void disconnect() { - try { - if (logger.isDebugEnabled()) { - logger.debug("SSH: disconnecting from [" + toString() + "]"); - } - clientSession.close(false); - } finally { - if (sshClient != null) { - sshClient.stop(); - } - } - } - - public void setExecTimeout(long timeout) { - this.timeout = timeout; - } - - public int execCommand(String cmd, OutputStream out, OutputStream err) { - return execCommand(cmd, out, err, false); - } - - public int execCommandWithPty(String cmd, OutputStream out) { - return execCommand(cmd, out, out, true); - } - - private int execCommand(String cmd, OutputStream out, OutputStream err, boolean usePty) { - try { - if (logger.isDebugEnabled()) { - logger.debug("SSH: executing command"); - } - ChannelExec client = clientSession.createExecChannel(cmd); - client.setUsePty(usePty); // use pseudo-tty? - client.setOut(out); - client.setErr(err); - OpenFuture openFuture = client.open(); - int exitStatus; - try { - client.wait(timeout); - openFuture.verify(); - Integer exitStatusI = client.getExitStatus(); - if (exitStatusI == null) { - throw new SshException("Error executing command [" + cmd + "] over SSH [" + username + "@" + host - + ":" + port + "]. Operation timed out."); - } - exitStatus = exitStatusI; - } finally { - client.close(false); - } - return exitStatus; - } catch (RuntimeException e) { - throw e; - } catch (Exception e1) { - throw new SshException( - "Error executing command [" + cmd + "] over SSH [" + username + "@" + host + ":" + port + "]", e1); - } - } - - private void waitForConnection(int retryDelay) { - long time = retryDelay * 1000L; - long future = System.currentTimeMillis() + time; - if (time != 0) { - while (System.currentTimeMillis() < future && time > 0) { - try { - Thread.sleep(time); - } catch (InterruptedException e) { - /* - * This is rare, but it can happen if another thread interrupts us while we are sleeping. In that - * case, the thread is resumed before the delay time has actually expired, so re-calculate the - * amount of delay time needed and reenter the sleep until we get to the future time. - */ - time = future - System.currentTimeMillis(); - } - } - } - } - - @Override - public String toString() { - String address = host; - if (username != null) { - address = username + '@' + address + ':' + port; - } - return address; - } -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/Constants.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/Constants.java deleted file mode 100644 index a1826c4e1..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/Constants.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.saltstack.model; - -public class Constants { - public static final String NETCONF_SCHEMA = "sdnctl"; - public static final String SDNCTL_SCHEMA = "sdnctl"; - public static final String DEVICE_AUTHENTICATION_TABLE_NAME = "DEVICE_AUTHENTICATION"; - public static final String CONFIGFILES_TABLE_NAME = "CONFIGFILES"; - public static final String DEVICE_INTERFACE_LOG_TABLE_NAME = "DEVICE_INTERFACE_LOG"; - public static final String FILE_CONTENT_TABLE_FIELD_NAME = "FILE_CONTENT"; - public static final String FILE_NAME_TABLE_FIELD_NAME = "FILE_NAME"; - public static final String USER_NAME_TABLE_FIELD_NAME = "USER_NAME"; - public static final String PASSWORD_TABLE_FIELD_NAME = "PASSWORD"; - public static final String PORT_NUMBER_TABLE_FIELD_NAME = "PORT_NUMBER"; - public static final String VNF_TYPE_TABLE_FIELD_NAME = "VNF_TYPE"; - public static final String SERVICE_INSTANCE_ID_FIELD_NAME = "SERVICE_INSTANCE_ID"; - public static final String REQUEST_ID_FIELD_NAME = "REQUEST_ID"; - public static final String CREATION_DATE_FIELD_NAME = "CREATION_DATE"; - public static final String LOG_FIELD_NAME = "LOG"; - public static final String SDC_ARTIFACTS_TABLE_NAME = "ASDC_ARTIFACTS"; - public static final String PAYLOAD = "payload"; - public static final String CONNECTION_RETRY_DELAY = "org.onap.appc.ssh.connection.retry.delay"; - public static final String CONNECTION_RETRY_COUNT = "org.onap.appc.ssh.connection.retry.count"; - public static final int DEFAULT_CONNECTION_RETRY_DELAY = 60; - public static final int DEFAULT_CONNECTION_RETRY_COUNT = 5; - public static final int DEFAULT_SSH_COMMAND_RETRY_COUNT = 3; - public static final int DEFAULT_CHECKACTIVE_RETRY_COUNT = 3; - public static final int DEFAULT_CHECKACTIVE_RETRY_DELAY = 30; - public static final int DEFAULT_STOP_RETRY_COUNT = 3; - public static final int DEFAULT_STOP_RETRY_DELAY = 30; - public static final String PARAM_IN_CONNECTION_DETAILS = "connection-details"; - public static final String PARAM_IN_NODE_NAME = "node-name"; - public static final String PARAM_IN_NODE_STATUS = "node-status"; - public static final String PARAM_IN_VM_URL = "vm-url"; - public static final String SKIP_EXECUTION_INSTALLER_BIN_FILE = "Skip-execution-installer-bin-file"; - public static final String SKIP_DEPLOY = "Skip-deploy"; - public static final String UPGRADE_VERSION = "upgrade-version"; - public static final String STATE_COMMAND = "/opt/jnetx/skyfall-scp/asp-state.sh | grep -o UP | wc -l"; - public static final String VNFC_STATE_COMMAND = "/opt/jnetx/skyfall-scp/asp-state.sh"; - public static final String RESTART_NODE_COMMAND = "/opt/jnetx/skyfall-scp/asp-stop.sh --restart -f --nodes"; - public static final String START_NODE_COMMAND = "/opt/jnetx/skyfall-scp/asp-start.sh -f --nodes"; - public static final String STOP_NODE_COMMAND = "/opt/jnetx/skyfall-scp/asp-stop.sh -f --nodes"; - public static final int STATE_COMMAND_RESULT = 18; - public static final String FE_STATE_TRUE_TEST_COMMAND = "ssh -t -q fe1 /opt/omni/bin/swmml -e display-platform-status | grep -o TRUE | wc -l"; - public static final int FE_STATE_TRUE_TEST_RESULT = 22; - public static final String FE_STATE_FALSE_TEST_COMMAND = "ssh -t -q fe1 /opt/omni/bin/swmml -e display-platform-status | grep -o FALSE | wc -l"; - public static final int FE_STATE_FALSE_TEST_RESULT = 2; - public static final String FE_OPERATIONAL_TEST_COMMAND = "ssh -t -q fe1 /opt/omni/bin/swmml -e display-platform-status | grep -o 'NOT FULLY OPERATIONAL' | wc -l"; - public static final int FE_OPERATIONAL_TEST_RESULT = 2; - public static final String SMP_CHECK_ACTIVE_STATE_COMMAND = "cat skyfall-scp/runtime/SCP_SMP_*/smp/log/system.log| grep SSS | tail -1"; - public static final String SMP_STATE_ACTIVE = "SMP is active"; - public static final String SMP_STATE_INACTIVE = "SMP is not active"; - public static final String RSYNC_COMMAND = "yes n | /opt/jnetx/skyfall-scp/asp-rsync.sh --check | grep -o 'is active' | wc -l"; - public static final int RSYNC_COMMAND_RESULT = 9; - public static final String PARAM_IN_TIMEOUT = "timeout"; - public static final String PARAM_IN_FILE_URL = "source-file-url"; - public static final String DOWNLOAD_COMMAND = "wget -N %s"; - public static final String[] VM_NAMES = new String[]{"fe1", "fe2", "be1", "be2", "be3", "be4", "be5", "smp1", "smp2"}; - public static final String DEFAULT_DISK_SPACE = "10240000"; - public static final String DF_COMMAND_TEMPLATE = "ssh %s df | grep vda1 | grep -v grep | tr -s ' '|cut -d ' ' -f4"; - public static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message"; - public static final String ATTRIBUTE_ERROR_MESSAGE = "error-message"; - public static final String CONNECTION_DETAILS_FIELD_NAME = "connection-details"; - public static final String VNF_HOST_IP_ADDRESS_FIELD_NAME = "vnf-host-ip-address"; - public static final String VNF_HOST_IP2_ADDRESS_FIELD_NAME = "vnf-host-ip2-address"; - public static final String DG_ERROR_FIELD_NAME = "org.openecom.appc.dg.error"; - - private Constants() { - } -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/JsonParser.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/JsonParser.java deleted file mode 100644 index 3eb353a17..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/JsonParser.java +++ /dev/null @@ -1,89 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2018 Samsung Electronics. All rights - * reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.saltstack.model; - -import org.codehaus.jettison.json.JSONArray; -import org.codehaus.jettison.json.JSONException; -import org.codehaus.jettison.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import static com.google.common.base.Preconditions.checkNotNull; - -public final class JsonParser { - - private static final Logger log = LoggerFactory.getLogger(JsonParser.class); - - private JsonParser() { - // Preventing instantiation of the same. - } - - @SuppressWarnings("unchecked") - public static Map convertToProperties(String s) - throws JSONException { - - checkNotNull(s, "Input should not be null."); - - JSONObject json = new JSONObject(s); - Map wm = new HashMap<>(); - Iterator ii = json.keys(); - while (ii.hasNext()) { - String key1 = ii.next(); - wm.put(key1, json.get(key1)); - } - - Map mm = new HashMap<>(); - - while (!wm.isEmpty()) - for (String key : new ArrayList<>(wm.keySet())) { - Object o = wm.get(key); - wm.remove(key); - - if (o instanceof Boolean || o instanceof Number || o instanceof String) { - mm.put(key, o.toString()); - - log.info("Added property: {} : {}", key, o.toString()); - } else if (o instanceof JSONObject) { - JSONObject jo = (JSONObject) o; - Iterator i = jo.keys(); - while (i.hasNext()) { - String key1 = i.next(); - wm.put(key + "." + key1, jo.get(key1)); - } - } else if (o instanceof JSONArray) { - JSONArray ja = (JSONArray) o; - mm.put(key + "_length", String.valueOf(ja.length())); - - log.info("Added property: {}_length: {}", key, String.valueOf(ja.length())); - - for (int i = 0; i < ja.length(); i++) - wm.put(key + '[' + i + ']', ja.get(i)); - } - } - return mm; - } -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackMessageParser.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackMessageParser.java deleted file mode 100644 index 3bb401ad4..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackMessageParser.java +++ /dev/null @@ -1,412 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2017-2018 Samsung Electronics. All rights reserved. - * ================================================================================ - * - * ============================================================================= - * 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. - * - * - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.saltstack.model; - -/** - * This module implements the APP-C/Saltstack Server interface - * based on the REST API specifications - */ - -import com.google.common.base.Strings; -import org.json.JSONException; -import org.json.JSONObject; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.UUID; - -/** - * Class that validates and constructs requests sent/received from - * Saltstack Server - */ -public class SaltstackMessageParser { - - private static final String SS_AGENT_HOSTNAME_KEY = "HostName"; - private static final String SS_AGENT_PORT_KEY = "Port"; - private static final String PASS_KEY = "Password"; - private static final String USER_KEY = "User"; - private static final String CMD_EXEC = "Cmd"; //cmd - private static final String IS_SLS_EXEC = "SlsExec"; //slsExec - private static final String SS_REQ_ID = "Id"; - private static final String SLS_FILE_LOCATION = "SlsFile"; //slsFile - private static final String SLS_NAME = "SlsName"; //slsName - private static final String MINION_TO_APPLY = "NodeList"; //applyTo - private static final String EXEC_TIMEOUT_TO_APPLY = "Timeout"; //execTimeout - private static final String FILE_PARAMETERS_OPT_KEY = "FileParameters"; - private static final String ENV_PARAMETERS_OPT_KEY = "EnvParameters"; - - private static final Logger LOGGER = LoggerFactory.getLogger(SaltstackMessageParser.class); - - /** - * Method that validates that the Map has enough information - * to query Saltstack server for a result. If so, it returns - * the appropriate PORT number. - */ - public String reqPortResult(Map params) throws SvcLogicException { - // use default port if null - if (params.get(SS_AGENT_PORT_KEY) == null) { - return "22"; - } - return params.get(SS_AGENT_PORT_KEY); - } - - /** - * Method that validates that the Map has enough information - * to query Saltstack server for a result. If so, it returns - * the appropriate HOST name. - */ - public String reqHostNameResult(Map params) throws SvcLogicException { - - throwIfMissingMandatoryParam(params, SS_AGENT_HOSTNAME_KEY); - return params.get(SS_AGENT_HOSTNAME_KEY); - } - - /** - * Method that validates that the Map has enough information - * to query Saltstack server for a result. If so, it returns - * the appropriate request ID. - */ - public String reqId(Map params) { - - if (params.get(SaltstackMessageParser.SS_REQ_ID) == null) { - return UUID.randomUUID().toString(); - } else if (params.get(SaltstackMessageParser.SS_REQ_ID).equalsIgnoreCase("")) { - return UUID.randomUUID().toString(); - } - return params.get(SaltstackMessageParser.SS_REQ_ID); - } - - /** - * Method that validates that the Map has enough information - * to query Saltstack server for a result. If so, it returns - * the appropriate command to execute. - */ - public String reqCmd(Map params) throws SvcLogicException { - - throwIfMissingMandatoryParam(params, CMD_EXEC); - return params.get(SaltstackMessageParser.CMD_EXEC); - } - - /** - * Method that validates that the Map has enough information - * to query Saltstack server for a result. If so, it returns - * the appropriate SLS file location to execute. - */ - public String reqSlsFile(Map params) throws SvcLogicException { - - throwIfMissingMandatoryParam(params, SLS_FILE_LOCATION); - return params.get(SaltstackMessageParser.SLS_FILE_LOCATION); - } - - /** - * Method that validates that the Map has enough information - * to query Saltstack server for a result. If so, it returns - * the appropriate SLS file location to execute. - */ - public String reqSlsName(Map params) throws SvcLogicException { - - throwIfMissingMandatoryParam(params, SLS_NAME); - String slsName = params.get(SaltstackMessageParser.SLS_NAME); - try { - if (slsName.substring(slsName.lastIndexOf("."), slsName.length()).equalsIgnoreCase(".sls")) { - return stripExtension(slsName); - } - } catch (StringIndexOutOfBoundsException e) { - return slsName; - } - return slsName; - } - - private String stripExtension(String str) { - if (str == null) { - return null; - } - int pos = str.lastIndexOf("."); - if (pos == -1) { - return str; - } - return str.substring(0, pos); - } - - /** - * Method that validates that the Map has enough information - * to query Saltstack server for a result. If so, it returns - * the appropriate minions/vnfc to execute the SLS file. - */ - public String reqApplyToDevices(Map params) { - - if (params.get(SaltstackMessageParser.MINION_TO_APPLY) == null) { - return "*"; - } else if (params.get(SaltstackMessageParser.MINION_TO_APPLY).equalsIgnoreCase("")) { - return "*"; - } - return params.get(SaltstackMessageParser.MINION_TO_APPLY); - } - - /** - * Method that validates that the Map has enough information - * to query Saltstack server for a result. If so, it returns - * the appropriate minions/vnfc to execute the SLS file. - */ - public long reqExecTimeout(Map params) { - - if (params.get(SaltstackMessageParser.EXEC_TIMEOUT_TO_APPLY) == null) { - return -1; - } else if (params.get(SaltstackMessageParser.EXEC_TIMEOUT_TO_APPLY).equalsIgnoreCase("")) { - return -1; - } - return Long.parseLong(params.get(SaltstackMessageParser.EXEC_TIMEOUT_TO_APPLY)); - } - - /** - * Method that validates that the Map has enough information - * to query Saltstack server for a result. If so, it returns - * the appropriate EnvParameters to execute the SLS file. - */ - public JSONObject reqEnvParameters(Map params) throws JSONException { - - JSONObject jsonPayload = new JSONObject(); - final String[] optionalTestParam = {SaltstackMessageParser.ENV_PARAMETERS_OPT_KEY}; - parseParam(params, optionalTestParam, jsonPayload); - - return (JSONObject) jsonPayload.remove(SaltstackMessageParser.ENV_PARAMETERS_OPT_KEY); - } - - /** - * Method that validates that the Map has enough information - * to query Saltstack server for a result. If so, it returns - * the appropriate EnvParameters to execute the SLS file. - */ - public JSONObject reqFileParameters(Map params) throws JSONException { - - JSONObject jsonPayload = new JSONObject(); - final String[] optionalTestParam = {SaltstackMessageParser.FILE_PARAMETERS_OPT_KEY}; - parseParam(params, optionalTestParam, jsonPayload); - - return (JSONObject) jsonPayload.remove(SaltstackMessageParser.FILE_PARAMETERS_OPT_KEY); - } - - private void parseParam(Map params, String[] optionalTestParams, JSONObject jsonPayload) - throws JSONException { - - Set optionalParamsSet = new HashSet<>(); - Collections.addAll(optionalParamsSet, optionalTestParams); - - //@formatter:off - params.entrySet() - .stream() - .filter(entry -> optionalParamsSet.contains(entry.getKey())) - .filter(entry -> !Strings.isNullOrEmpty(entry.getValue())) - .forEach(entry -> parseParam(entry, jsonPayload)); - //@formatter:on - } - - private void parseParam(Map.Entry params, JSONObject jsonPayload) - throws JSONException { - String key = params.getKey(); - String payload = params.getValue(); - - switch (key) { - case ENV_PARAMETERS_OPT_KEY: - JSONObject paramsJson = new JSONObject(payload); - jsonPayload.put(key, paramsJson); - break; - - case FILE_PARAMETERS_OPT_KEY: - jsonPayload.put(key, getFilePayload(payload)); - break; - - default: - break; - } - } - - /** - * Return payload with escaped newlines - */ - private JSONObject getFilePayload(String payload) { - String formattedPayload = payload.replace("\n", "\\n").replace("\r", "\\r"); - return new JSONObject(formattedPayload); - } - - /** - * Method that validates that the Map has enough information - * to query Saltstack server for a result. If so, it returns - * the appropriate IsSLSExec true or false. - */ - public boolean reqIsSLSExec(Map params) throws SvcLogicException { - - final String[] mandatoryTestParams = {CMD_EXEC, IS_SLS_EXEC}; - - for (String key : mandatoryTestParams) { - throwIfMissingMandatoryParam(params, key); - } - - return params.get(SaltstackMessageParser.IS_SLS_EXEC).equalsIgnoreCase("true"); - } - - /** - * Method that validates that the Map has enough information - * to query Saltstack server for a result. If so, it returns - * the appropriate Saltstack server login user name. - */ - public String reqUserNameResult(Map params) throws SvcLogicException { - - throwIfMissingMandatoryParam(params, USER_KEY); - return params.get(USER_KEY); - } - - /** - * Method that validates that the Map has enough information - * to query Saltstack server for a result. If so, it returns - * the appropriate Saltstack server login password. - */ - public String reqPasswordResult(Map params) throws SvcLogicException { - - throwIfMissingMandatoryParam(params, PASS_KEY); - return params.get(PASS_KEY); - } - - /** - * This method parses response from the Saltstack Server when we do a post - * and returns an SaltstackResult object. - */ - public SaltstackResult parseResponse(SvcLogicContext ctx, String pfx, - SaltstackResult saltstackResult, boolean slsExec) throws IOException { - int code = saltstackResult.getStatusCode(); - boolean executionStatus = true; - boolean retCodeFound = false; - if (code != SaltstackResultCodes.SUCCESS.getValue()) { - return saltstackResult; - } - ByteArrayOutputStream outStream = saltstackResult.getOutputMessage(); - String outMessage = outStream.toString(); - try { - Map mm = JsonParser.convertToProperties(outMessage); - if (mm != null) { - for (Map.Entry entry : mm.entrySet()) { - if (entry.getKey().contains("retcode")) { - retCodeFound = true; - if (!entry.getValue().equalsIgnoreCase("0")) { - executionStatus = false; - } - } - ctx.setAttribute(pfx + "." + entry.getKey(), entry.getValue()); - LOGGER.info("+++ " + pfx + "." + entry.getKey() + ": [" + entry.getValue() + "]"); - } - } - } catch (org.codehaus.jettison.json.JSONException e) { - if (slsExec) { - return new SaltstackResult(SaltstackResultCodes.INVALID_RESPONSE.getValue(), "error parsing response file" - + " : Output has to be in JSON format"); - } - LOGGER.info("Output not in JSON format"); - return putToProperties(ctx, pfx, saltstackResult); - } catch (Exception e) { - return new SaltstackResult(SaltstackResultCodes.INVALID_RESPONSE_FILE.getValue(), "error parsing response file" - + " : " + e.getMessage()); - } finally { - if (outStream != null) { - outStream.close(); - } - } - if (slsExec) { - if (!retCodeFound) { - if (outMessage != null && !outMessage.equalsIgnoreCase("")) { - return new SaltstackResult(SaltstackResultCodes.COMMAND_EXEC_FAILED_STATUS.getValue(), - outMessage); - } - return new SaltstackResult(SaltstackResultCodes.COMMAND_EXEC_FAILED_STATUS.getValue(), - "error in executing configuration at the server, check your command input"); - } - if (!executionStatus) { - if (outMessage != null && !outMessage.equalsIgnoreCase("")) { - return new SaltstackResult(SaltstackResultCodes.COMMAND_EXEC_FAILED_STATUS.getValue(), - outMessage); - } - return new SaltstackResult(SaltstackResultCodes.COMMAND_EXEC_FAILED_STATUS.getValue(), - "error in executing configuration at the server, check your command input"); - } - } - saltstackResult.setStatusCode(SaltstackResultCodes.FINAL_SUCCESS.getValue()); - return saltstackResult; - } - - public SaltstackResult putToProperties(SvcLogicContext ctx, String pfx, - SaltstackResult saltstackResult) throws IOException { - - ByteArrayOutputStream buffer = saltstackResult.getOutputMessage(); - InputStream inputStream = null; - try { - byte[] bytes = buffer.toByteArray(); - Properties prop = new Properties(); - inputStream = new ByteArrayInputStream(bytes); - prop.load(inputStream); - ctx.setAttribute(pfx + "completeResult", prop.toString()); - for (Object key : prop.keySet()) { - String name = (String) key; - String value = prop.getProperty(name); - if (value != null && value.trim().length() > 0) { - ctx.setAttribute(pfx + "." + name, value.trim()); - LOGGER.info("+++ " + pfx + "." + name + ": [" + value + "]"); - } - } - } catch (Exception e) { - saltstackResult = new SaltstackResult(SaltstackResultCodes.INVALID_RESPONSE_FILE.getValue(), "Error parsing response file." + - " Error = " + e.getMessage()); - } finally { - if (buffer != null && inputStream != null) { - buffer.close(); - inputStream.close(); - } - } - saltstackResult.setStatusCode(SaltstackResultCodes.FINAL_SUCCESS.getValue()); - return saltstackResult; - } - - private void throwIfMissingMandatoryParam(Map params, String key) throws SvcLogicException { - if (!params.containsKey(key)) { - throw new SvcLogicException(String.format( - "Saltstack: Mandatory SaltstackAdapter key %s not found in parameters provided by calling agent !", - key)); - } - if (Strings.isNullOrEmpty(params.get(key))) { - throw new SvcLogicException(String.format( - "Saltstack: Mandatory SaltstackAdapter key %s not found in parameters provided by calling agent !", - key)); - } - } -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResult.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResult.java deleted file mode 100644 index 727cfe314..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResult.java +++ /dev/null @@ -1,102 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2018 Samsung Electronics. All rights reserved. - * ================================================================================ - * - * ============================================================================= - * 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. - * - * - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.saltstack.model; - -import java.io.ByteArrayOutputStream; - -/** - * Simple class to store code and message returned by POST/GET to an Saltstack Server - */ -public class SaltstackResult { - - private static final String EMPTY_VALUE = "UNKNOWN"; - - private int statusCode; - private String statusMessage; - private String results; - private ByteArrayOutputStream out; - private int sshExitStatus; - - public SaltstackResult() { - this(-1, EMPTY_VALUE, EMPTY_VALUE, -1); - } - - public SaltstackResult(int code, String message) { - this(code, message, EMPTY_VALUE, -1); - } - - public SaltstackResult(int code, String message, String result, int sshCode) { - statusCode = code; - statusMessage = message; - results = result; - sshExitStatus = sshCode; - } - - void set(int code, String message, String results) { - this.statusCode = code; - this.statusMessage = message; - this.results = results; - } - - public ByteArrayOutputStream getOutputMessage() { - return out; - } - - public void setOutputMessage(ByteArrayOutputStream out) { - this.out = out; - } - - public int getStatusCode() { - return this.statusCode; - } - - public void setStatusCode(int code) { - this.statusCode = code; - } - - public String getStatusMessage() { - return this.statusMessage; - } - - public void setStatusMessage(String message) { - this.statusMessage = message; - } - - public String getResults() { - return this.results; - } - - public void setResults(String results) { - this.results = results; - } - - public int getSshExitStatus() { - return sshExitStatus; - } - - public void setSshExitStatus(int sshExitStatus) { - this.sshExitStatus = sshExitStatus; - } -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResultCodes.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResultCodes.java deleted file mode 100644 index 932554983..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResultCodes.java +++ /dev/null @@ -1,100 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2018 Samsung Electronics. All rights reserved. - * ================================================================================ - * - * ============================================================================= - * 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. - * - * - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.saltstack.model; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -/** - * enum of the various codes that APP-C uses to resolve different - * status of response from Saltstack Server - **/ - -public enum SaltstackResultCodes { - - // @formatter:off - SUCCESS(400), - KEYSTORE_EXCEPTION(622), - CERTIFICATE_ERROR(610), - IO_EXCEPTION(611), - HOST_UNKNOWN(625), - USER_UNAUTHORIZED(613), - UNKNOWN_EXCEPTION(699), - OPERATION_TIMEOUT(659), - SSL_EXCEPTION(697), - SSH_EXCEPTION(695), - INVALID_COMMAND(698), - INVALID_RESPONSE(601), - INVALID_RESPONSE_FILE(600), - PENDING(100), - REJECTED(101), - FINAL_SUCCESS(200), - CHECK_CTX_FOR_CMD_SUCCESS(250), - COMMAND_EXEC_FAILED_STATUS(670), - REQ_FAILURE(401), - MESSAGE(1), - CODE(0), - INITRESPONSE(0), - FINALRESPONSE(1); - // @formatter:on - - private final Set initCodes = new HashSet<>(Arrays.asList(100, 101)); - private final Set finalCodes = new HashSet<>(Arrays.asList(200, 500)); - private final ArrayList> codeSets = new ArrayList<>(Arrays.asList(initCodes, finalCodes)); - private final Set messageSet = new HashSet<>(Arrays.asList("PENDING", "FINISHED", "TERMINATED")); - private final int value; - - SaltstackResultCodes(int value) { - this.value = value; - } - - ; - - public int getValue() { - return value; - } - - public boolean checkValidCode(int type, int code) { - return codeSets.get(type).contains(code); - } - - public String getValidCodes(int type) { - StringBuilder sb = new StringBuilder("[ "); - codeSets.get(type).stream().forEach(s -> sb.append(s).append(",")); - return sb.append("]").toString(); - } - - public boolean checkValidMessage(String message) { - return messageSet.contains(message); - } - - public String getValidMessages() { - StringBuilder sb = new StringBuilder("[ "); - messageSet.stream().forEach(s -> sb.append(s).append(",")); - return sb.append("]").toString(); - } -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackServerEmulator.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackServerEmulator.java deleted file mode 100644 index 78976562b..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackServerEmulator.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2018 Samsung Electronics. All rights reserved. - * ================================================================================ - * - * ============================================================================= - * 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. - * - * - * ============LICENSE_END========================================================= - */ - - - -/* - * Class to emulate responses from the Saltstack Server that is compliant with the APP-C Saltstack Server - * Interface. Used for jUnit tests to verify code is working. In tests it can be used - * as a replacement for methods from ConnectionBuilder class - */ - -package org.onap.ccsdk.sli.adaptors.saltstack.model; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.io.ByteArrayOutputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Map; - -public class SaltstackServerEmulator { - - private static final String SALTSTATE_FILE_NAME = "fileName"; - private final EELFLogger logger = EELFManager.getInstance().getLogger(SaltstackServerEmulator.class); - - /** - * Method that emulates the response from an Saltstack Server - * when presented with a request to execute a saltState - * Returns an saltstack object result. The response code is always the ssh code 200 (i.e connection successful) - * payload is json string as would be sent back by Saltstack Server - **/ - public SaltstackResult mockReqExec(Map params) { - SaltstackResult result = new SaltstackResult(); - - try { - if (params.get("Test") == "fail") { - result = rejectRequest(result, "Mocked: Fail"); - } else { - String fileName = params.get(SALTSTATE_FILE_NAME); - if (fileName == null) { - throw new FileNotFoundException("No response file found"); - } - result = acceptRequest(result, fileName); - } - } catch (Exception e) { - logger.error("Exception caught", e); - rejectRequest(result, e.getMessage()); - } - return result; - } - - private SaltstackResult rejectRequest(SaltstackResult result, String Message) { - result.setStatusCode(SaltstackResultCodes.REJECTED.getValue()); - result.setStatusMessage("Rejected"); - return result; - } - - private SaltstackResult acceptRequest(SaltstackResult result, String fileName) throws IOException { - result.setStatusCode(SaltstackResultCodes.SUCCESS.getValue()); - result.setStatusMessage("Success"); - Path path = Paths.get(fileName); - byte[] data = Files.readAllBytes(path); - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(data.length); - byteOut.write(data, 0, data.length); - result.setOutputMessage(byteOut); - return result; - } -} \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SshException.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SshException.java deleted file mode 100644 index 037a1e891..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SshException.java +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.adaptors.saltstack.model; - -public class SshException extends RuntimeException { - private static final long serialVersionUID = 1L; - - public SshException(String message) { - super(message); - } - - public SshException(String message, Throwable cause) { - super(message, cause); - } -} \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/resources/org/opendaylight/blueprint/saltstack-adapter-blueprint.xml b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/resources/org/opendaylight/blueprint/saltstack-adapter-blueprint.xml deleted file mode 100755 index e360f8184..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/resources/org/opendaylight/blueprint/saltstack-adapter-blueprint.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - org.onap.ccsdk.sli.adaptors.saltstack.SaltstackAdapter - - - - - diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/resources/saltstack-adapter.properties b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/resources/saltstack-adapter.properties deleted file mode 100644 index 1755f7adf..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/main/resources/saltstack-adapter.properties +++ /dev/null @@ -1,43 +0,0 @@ -### -# ============LICENSE_START======================================================= -# ONAP : CCSDK -# ================================================================================ -# Copyright (C) 2018 Samsung Electronics. All rights reserved. -# ================================================================================ -# -# ============================================================================= -# 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. -# -# -# ============LICENSE_END========================================================= -### -# -# Default properties for the APP-C TestService Adapter -# -# ------------------------------------------------------------------------------------------------- -# -# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded -# to supply configuration options -org.onap.appc.bootstrap.file=appc.properties -org.onap.appc.bootstrap.path=${user.home},/opt/opendaylight/current/properties -appc.application.name=APPC -# -# Define the message resource bundle name to be loaded -org.onap.appc.resources=org.onap/appc/i18n/MessageResources -# -# The name of the adapter. -org.onap.appc.provider.adaptor.name=org.onap.appc.appc_saltstack_adapter -# Default truststore path and password -org.onap.appc.adapter.saltstack.trustStore=/opt/opendaylight/tls-client/mykeystore.js -org.onap.appc.adapter.saltstack.trustStore.trustPasswd=changeit -org.onap.appc.adapter.saltstack.clientType=TRUST_ALL diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestConnectionBuilder.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestConnectionBuilder.java deleted file mode 100644 index 71fcf3454..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestConnectionBuilder.java +++ /dev/null @@ -1,184 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2018 Samsung Electronics. All rights reserved. - * ================================================================================ - * - * ============================================================================= - * 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. - * - * - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.adapter.impl; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.sli.adaptors.saltstack.impl.ConnectionBuilder; -import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResult; - -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.assertEquals; - - -public class TestConnectionBuilder { - - private ConnectionBuilder connBuilder; - private Map params; - - - @Before - public void setup() throws IllegalArgumentException { - String HostName = "test"; - String Port = "10"; - String User = "test"; - String Password = "test"; - connBuilder = new ConnectionBuilder(HostName, Port, User, Password); - - params = new HashMap<>(); - params.put("AgentUrl", "https://192.168.1.1"); - params.put("User", "test"); - params.put("Password", "test"); - } - - @After - public void tearDown() { - connBuilder = null; - params = null; - } - - @Test - public void reqExecCommand_exitStatus255() { - - int exitStatus = 255; - String errFilePath = "src/test/resources/test.json"; - String command = "test"; - - SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); - int status = result.getStatusCode(); - assertEquals(698, status); - } - - @Test - public void reqExecCommand_exitStatus1() { - - int exitStatus = 1; - String errFilePath = "src/test/resources/test.json"; - String command = "test"; - - SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); - int status = result.getStatusCode(); - assertEquals(698, status); - } - - @Test - public void reqExecCommand_exitStatus67() { - - int exitStatus = 67; - String errFilePath = "src/test/resources/test.json"; - String command = "test"; - - SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); - int status = result.getStatusCode(); - assertEquals(610, status); - } - - @Test - public void reqExecCommand_exitStatus73() { - - int exitStatus = 73; - String errFilePath = "src/test/resources/test.json"; - String command = "test"; - - SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); - int status = result.getStatusCode(); - assertEquals(610, status); - } - - @Test - public void reqExecCommand_exitStatus5() { - - int exitStatus = 5; - String errFilePath = "src/test/resources/test.json"; - String command = "test"; - - SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); - int status = result.getStatusCode(); - assertEquals(613, status); - } - - @Test - public void reqExecCommand_exitStatus65() { - - int exitStatus = 65; - String errFilePath = "src/test/resources/test.json"; - String command = "test"; - - SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); - int status = result.getStatusCode(); - assertEquals(613, status); - } - - @Test - public void reqExecCommand_exitStatus67613() { - - int exitStatus = 5; - String errFilePath = "src/test/resources/test.json"; - String command = "test"; - - SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); - int status = result.getStatusCode(); - assertEquals(613, status); - } - - @Test - public void reqExecCommand_exitStatus65613() { - - int exitStatus = 65; - String errFilePath = "src/test/resources/test.json"; - String command = "test"; - - SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); - int status = result.getStatusCode(); - assertEquals(613, status); - } - - @Test - public void reqExecCommand_exitStatusUnknown() { - - int exitStatus = 5121; - String errFilePath = "src/test/resources/test.json"; - String command = "test"; - - SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); - int status = result.getStatusCode(); - assertEquals(699, status); - } - - @Test - public void reqExecCommand_exitStatusNoFile() { - - int exitStatus = 65; - String errFilePath = "src/test/resource/test.json"; - String command = "test"; - - SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); - int status = result.getStatusCode(); - assertEquals(613, status); - } -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestSaltstackAdapterImpl.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestSaltstackAdapterImpl.java deleted file mode 100644 index 22e8c2082..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestSaltstackAdapterImpl.java +++ /dev/null @@ -1,1051 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2018 Samsung Electronics. All rights reserved. - * ================================================================================ - * - * ============================================================================= - * 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. - * - * - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.adapter.impl; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.sli.adaptors.saltstack.impl.SaltstackAdapterImpl; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - - -public class TestSaltstackAdapterImpl { - - private SaltstackAdapterImpl adapter; - private String TestId; - private boolean testMode = true; - private Map params; - private SvcLogicContext svcContext; - - - @Before - public void setup() throws IllegalArgumentException { - testMode = true; - svcContext = new SvcLogicContext(); - adapter = new SaltstackAdapterImpl(testMode); - - params = new HashMap<>(); - params.put("AgentUrl", "https://192.168.1.1"); - params.put("User", "test"); - params.put("Password", "test"); - } - - @After - public void tearDown() { - testMode = false; - adapter = null; - params = null; - svcContext = null; - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_shouldSetFailed() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "fail"); - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("101", status); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_shouldSetUserFailed() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("Password", "test"); - params.put("Test", "fail"); - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("101", status); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_shouldSetHostFailed() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "fail"); - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("101", status); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_shouldSetPortFailed() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "fail"); - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("101", status); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_shouldSetPasswordFailed() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Test", "fail"); - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("101", status); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_shouldSetMandatoryFailed() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("Test", "fail"); - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("101", status); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_NoResponseFile() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("Cmd", "test"); - params.put("SlsExec", "false"); - try { - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("400", status); - } catch (NullPointerException e) { - fail(e.getMessage() + " Unknown exception encountered "); - } - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_NoResponseFileWithRetry() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("withRetry", "true"); - params.put("Cmd", "test"); - params.put("SlsExec", "false"); - try { - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("400", status); - } catch (NullPointerException e) { - fail(e.getMessage() + " Unknown exception encountered "); - } - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_NoResponseFileWithRetryZero() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("withRetry", "0"); - params.put("Cmd", "test"); - params.put("SlsExec", "false"); - try { - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("400", status); - } catch (NullPointerException e) { - fail(e.getMessage() + " Unknown exception encountered "); - } - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_NoResponseFileWithNoRetry() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("withRetry", "false"); - params.put("Cmd", "test"); - params.put("SlsExec", "false"); - - try { - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("400", status); - } catch (NullPointerException e) { - fail(e.getMessage() + " Unknown exception encountered "); - } - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_shouldSetFailure() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Cmd", "test"); - params.put("SlsExec", "test"); - params.put("Test", "fail"); - try { - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("400", status); - } catch (NullPointerException e) { - fail(e.getMessage() + " Unknown exception encountered "); - } - } - - @Test - public void reqExecCommand_shouldSetSuccessNoSLS() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("fileName", "src/test/resources/test.json"); - params.put("Id", "test1"); - params.put("Cmd", "test"); - params.put("SlsExec", "false"); - - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } - - @Test - public void reqExecCommand_shouldSetSuccessExecSLS() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - params.put("Cmd", "test"); - params.put("SlsExec", "true"); - - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_shouldSetFailExecSLS() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("fileName", "src/test/resources/test.json"); - params.put("Id", "test1"); - params.put("Cmd", "test"); - params.put("SlsExec", "true"); - - adapter.reqExecCommand(params, svcContext); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals(TestId, "test1"); - } - - @Test - public void reqExecCommand_shouldSetSuccessFileTxt() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("fileName", "src/test/resources/test.txt"); - params.put("Id", "txt"); - params.put("Cmd", "test"); - params.put("SlsExec", "false"); - - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "txt"); - } - - @Test - public void reqExecCommand_shouldSetSuccessFileNoExtension() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("fileName", "src/test/resources/test"); - params.put("Id", "txt"); - params.put("Cmd", "test"); - params.put("SlsExec", "false"); - - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "txt"); - } - - @Test - public void reqExecCommand_shouldSetSuccessFileInvalidJson() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("fileName", "src/test/resources/test-invalid.json"); - params.put("Id", "test1"); - params.put("Cmd", "test"); - params.put("SlsExec", "false"); - - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_shouldSetFailFileInvalidFile() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("fileName", "src/test/resources/test-none.json"); - params.put("Id", "test1"); - - adapter.reqExecCommand(params, svcContext); - } - - @Test - public void reqExecCommand_shouldSetSuccessFileJsonNoReqID() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("fileName", "src/test/resources/test.json"); - params.put("Cmd", "test"); - params.put("SlsExec", "false"); - - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - } - - @Test - public void reqExecSLSFile_shouldSetSuccessJson() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsFile", "src/test/resources/test.sls"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - params.put("Cmd", "test"); - - adapter.reqExecSLSFile(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } - - @Test(expected = SvcLogicException.class) - public void reqExecSLSFile_NoSLSfile() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsFile", "src/test/resources/test-none.sls"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - - adapter.reqExecSLSFile(params, svcContext); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals(TestId, "test1"); - } - - @Test(expected = SvcLogicException.class) - public void reqExecSLSFile_NoExtn() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsFile", "src/test/resources/test-none"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - - adapter.reqExecSLSFile(params, svcContext); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals(TestId, "test1"); - } - - @Test(expected = SvcLogicException.class) - public void reqExecSLSFile_NoResponsefile() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsFile", "src/test/resources/test.json"); - params.put("fileName", "src/test/resources/test-none.json"); - params.put("Id", "test1"); - - adapter.reqExecSLSFile(params, svcContext); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals(TestId, "test1"); - } - - @Test(expected = SvcLogicException.class) - public void reqExecSLSFile_WithMinionSetNotSLSType() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsFile", "src/test/resources/test.json"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - params.put("Cmd", "test"); - params.put("NodeList", "minion1"); - - adapter.reqExecSLSFile(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } - - @Test - public void reqExecSLSFile_WithMinionSetSuccessSls() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsFile", "src/test/resources/test.sls"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - params.put("Cmd", "test"); - params.put("NodeList", "minion1"); - - adapter.reqExecSLSFile(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } - - @Test(expected = SvcLogicException.class) - public void reqExecSLSFile_WithMinionNoSLSfile() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsFile", "src/test/resources/test-none.json"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - params.put("NodeList", "minion1"); - - adapter.reqExecSLSFile(params, svcContext); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals(TestId, "test1"); - } - - @Test(expected = SvcLogicException.class) - public void reqExecSLSFile_WithMinionNoResponsefile() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsFile", "src/test/resources/test.json"); - params.put("fileName", "src/test/resources/test-none.json"); - params.put("Id", "test1"); - params.put("NodeList", "minion1"); - - adapter.reqExecSLSFile(params, svcContext); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals(TestId, "test1"); - } - - @Test - public void reqExecSLSFile_WithAllMinionSetSuccessJson() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsFile", "src/test/resources/test.sls"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - params.put("Cmd", "test"); - params.put("NodeList", "*"); - - adapter.reqExecSLSFile(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } - - @Test(expected = SvcLogicException.class) - public void reqExecSLSFile_WithAllMinionNoSLSfile() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsFile", "src/test/resources/test-none.json"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - params.put("NodeList", "*"); - - adapter.reqExecSLSFile(params, svcContext); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals(TestId, "test1"); - } - - @Test(expected = SvcLogicException.class) - public void reqExecSLSFile_WithAllMinionNoResponsefile() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsFile", "src/test/resources/test.json"); - params.put("fileName", "src/test/resources/test-none.json"); - params.put("Id", "test1"); - params.put("NodeList", "*"); - - adapter.reqExecSLSFile(params, svcContext); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals(TestId, "test1"); - } - - - @Test - public void reqExecSLS_shouldSetSuccessJson() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsName", "src/test.sls"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - params.put("Cmd", "test"); - - adapter.reqExecSLS(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } - - @Test - public void reqExecSLS_shouldSetNoExtn() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsName", "src/test"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - params.put("Cmd", "test"); - - adapter.reqExecSLS(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } - - @Test(expected = SvcLogicException.class) - public void reqExecSLS_NoResponsefile() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsName", "src/test/resources/test.json"); - params.put("fileName", "src/test/resources/test-none.json"); - params.put("Id", "test1"); - - adapter.reqExecSLS(params, svcContext); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals(TestId, "test1"); - } - - - @Test - public void reqExecSLS_WithMinionSetSuccessSls() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsName", "src/test/resources/test.sls"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - params.put("Cmd", "test"); - params.put("NodeList", "minion1"); - - adapter.reqExecSLS(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } - - - @Test(expected = SvcLogicException.class) - public void reqExecSLS_WithMinionNoResponsefile() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsName", "src/test/resources/test.json"); - params.put("fileName", "src/test/resources/test-none.json"); - params.put("Id", "test1"); - params.put("NodeList", "minion1"); - - adapter.reqExecSLS(params, svcContext); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals(TestId, "test1"); - } - - @Test - public void reqExecSLS_WithAllMinionSetSuccessJson() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsName", "src/test/resources/test.sls"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - params.put("Cmd", "test"); - params.put("NodeList", "*"); - - adapter.reqExecSLS(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } - - - @Test(expected = SvcLogicException.class) - public void reqExecSLS_WithAllMinionNoResponsefile() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - params.put("Test", "success"); - params.put("SlsName", "src/test/resources/test.json"); - params.put("fileName", "src/test/resources/test-none.json"); - params.put("Id", "test1"); - params.put("NodeList", "*"); - - adapter.reqExecSLS(params, svcContext); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals(TestId, "test1"); - } - - - @Test - public void reqExecCommand_shouldSetSuccessReal() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "127.0.0.1"); - params.put("Port", "22"); - params.put("User", "sdn"); - params.put("Password", "foo"); - params.put("Id", "test1"); - params.put("Cmd", "ls -l"); - params.put("SlsExec", "false"); - params.put("Timeout", "120"); - adapter = new SaltstackAdapterImpl(); - try { - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } catch (Exception e) { - //if local ssh is not enabled - System.out.print(e.getMessage()); - } - } - - @Test - public void reqExecCommand_shouldSetSuccessRealSLSCommand() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", ""); - params.put("Port", "2222"); - params.put("User", "root"); - params.put("Password", "vagrant"); - params.put("Id", "test1"); - params.put("Cmd", "salt '*' test.ping --out=json --static"); - params.put("SlsExec", "false"); - params.put("Timeout", "120"); - - adapter = new SaltstackAdapterImpl(); - try { - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - TestId = svcContext.getAttribute("test1.minion1"); - assertEquals(TestId, "true"); - } catch (Exception e) { - //if saltstack ssh IP is not enabled - System.out.print(e.getMessage()); - } - } - - @Test - public void reqExecCommand_shouldSetSuccessRealCommand() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", ""); - params.put("Port", "2222"); - params.put("User", "root"); - params.put("Password", "vagrant"); - params.put("Id", "test1"); - params.put("Cmd", "cd /srv/salt/; salt '*' state.apply vim --out=json --static"); - params.put("SlsExec", "true"); - params.put("Timeout", "120"); - - adapter = new SaltstackAdapterImpl(); - try { - adapter.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } catch (Exception e) { - //if saltstack ssh IP is not enabled - System.out.print(e.getMessage()); - } - } - - @Test - public void reqExecCommand_shouldSetSuccessRealSSL() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", ""); - params.put("Port", "2222"); - params.put("User", "root"); - params.put("Password", "vagrant"); - params.put("Id", "test1"); - params.put("SlsName", "vim"); - params.put("Timeout", "120"); - params.put("NodeList", "minion1"); - - adapter = new SaltstackAdapterImpl(); - try { - adapter.reqExecSLS(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } catch (Exception e) { - //if saltstack ssh IP is not enabled - System.out.print(e.getMessage()); - } - } - - @Test - public void reqExecCommand_shouldSetSuccessEnvParam() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", ""); - params.put("Port", "2222"); - params.put("User", "root"); - params.put("Password", "vagrant"); - params.put("Id", "test1"); - params.put("SlsName", "vim"); - params.put("Timeout", "120"); - params.put("NodeList", "minion1"); - params.put("EnvParameters", "{\"exclude\": bar*}"); - - adapter = new SaltstackAdapterImpl(); - try { - adapter.reqExecSLS(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } catch (Exception e) { - //if saltstack ssh IP is not enabled - System.out.print(e.getMessage()); - } - } - - @Test - public void reqExecCommand_shouldSetSuccessFileParam() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", ""); - params.put("Port", "2222"); - params.put("User", "root"); - params.put("Password", "vagrant"); - params.put("Id", "test1"); - params.put("SlsName", "vim"); - params.put("Timeout", "120"); - params.put("NodeList", "minion1"); - params.put("EnvParameters", "{\"exclude\": \"bar,baz\"}"); - params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}"); - - adapter = new SaltstackAdapterImpl(); - try { - adapter.reqExecSLS(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } catch (Exception e) { - //if saltstack ssh IP is not enabled - System.out.print(e.getMessage()); - } - } - - @Test - public void reqExecCommand_shouldSetSuccessPillarParam() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", ""); - params.put("Port", "2222"); - params.put("User", "root"); - params.put("Password", "vagrant"); - params.put("Id", "test1"); - params.put("SlsName", "vim"); - params.put("Timeout", "120"); - params.put("NodeList", "minion1"); - params.put("EnvParameters", "{\"exclude\": \"bar,baz\", \"pillar\":\"'{\\\"foo\\\": \\\"bar\\\"}'\"}"); - params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}"); - - adapter = new SaltstackAdapterImpl(); - try { - adapter.reqExecSLS(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } catch (Exception e) { - //if saltstack ssh IP is not enabled - System.out.print(e.getMessage()); - } - } - - @Test - public void reqExecCommand_shouldSetSuccessMultiFileParam() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", ""); - params.put("Port", "2222"); - params.put("User", "root"); - params.put("Password", "vagrant"); - params.put("Id", "test1"); - params.put("SlsName", "vim"); - params.put("Timeout", "120"); - params.put("NodeList", "minion1"); - params.put("EnvParameters", "{\"exclude\": bar*}"); - params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\" , \"config-tep.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}"); - - adapter = new SaltstackAdapterImpl(); - try { - adapter.reqExecSLS(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } catch (Exception e) { - //if saltstack ssh IP is not enabled - System.out.print(e.getMessage()); - } - } - - @Test - public void reqExecCommand_shouldSetSuccessSSLFile() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", ""); - params.put("Port", "2222"); - params.put("User", "root"); - params.put("Password", "vagrant"); - params.put("Id", "test1"); - params.put("Timeout", "120"); - params.put("NodeList", "minion1"); - params.put("SlsFile", "src/test/resources/config.sls"); - - adapter = new SaltstackAdapterImpl(); - try { - adapter.reqExecSLSFile(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } catch (Exception e) { - //if saltstack ssh IP is not enabled - System.out.print(e.getMessage()); - } - } - - @Test - public void reqExecCommand_shouldSetSuccessSSLFileMultiFileParam() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", ""); - params.put("Port", "2222"); - params.put("User", "root"); - params.put("Password", "vagrant"); - params.put("Id", "test1"); - params.put("Timeout", "120"); - params.put("NodeList", "minion1"); - params.put("SlsFile", "src/test/resources/config.sls"); - params.put("EnvParameters", "{\"exclude\": bar, \"pillar\":\"'{\\\"foo\\\": \\\"bar\\\"}'\"}"); - params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\" , \"config-tep.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}"); - - adapter = new SaltstackAdapterImpl(); - try { - adapter.reqExecSLSFile(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); - assertEquals("200", status); - assertEquals(TestId, "test1"); - } catch (Exception e) { - //if saltstack ssh IP is not enabled - System.out.print(e.getMessage()); - } - } -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestSaltstackAdapterPropertiesProviderImpl.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestSaltstackAdapterPropertiesProviderImpl.java deleted file mode 100644 index 88acc1919..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestSaltstackAdapterPropertiesProviderImpl.java +++ /dev/null @@ -1,310 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2018 Samsung Electronics. All rights reserved. - * ================================================================================ - * - * ============================================================================= - * 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. - * - * - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.adapter.impl; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.sli.adaptors.saltstack.SaltstackAdapterPropertiesProvider; -import org.onap.ccsdk.sli.adaptors.saltstack.impl.SaltstackAdapterImpl; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -import java.util.Properties; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class TestSaltstackAdapterPropertiesProviderImpl { - - private SaltstackAdapterImpl adapter; - private Properties params; - - - @Before - public void setup() throws IllegalArgumentException { - params = new Properties(); - } - - @After - public void tearDown() { - adapter = null; - params = null; - } - - @Test - public void reqExecCommand_setPropertiesBasicPortNull() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "BASIC"); - params.put("User", "test"); - params.put("Password", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - assertNotNull(propProvider); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_setPropertiesBasicPortString() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "BASIC"); - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "test"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesBasicSuccess() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "BASIC"); - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "10"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - assertNotNull(adapter); - } - - @Test - public void reqExecCommand_setPropertiesSSH_CERTPortNull() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "SSH_CERT"); - params.put("User", "test"); - params.put("Password", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - assertNotNull(propProvider); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_setPropertiesSSH_CERTPortString() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "SSH_CERT"); - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "test"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesSSH_CERTSuccess() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "SSH_CERT"); - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "10"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - assertNotNull(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesBOTHPortNull() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "BOTH"); - params.put("User", "test"); - params.put("Password", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - assertNotNull(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesBOTHSuccess() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "BOTH"); - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "10"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - assertNotNull(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesNonePortNull() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "NONE"); - params.put("User", "test"); - params.put("Password", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - assertNotNull(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesNonePortString() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "NONE"); - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "test"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - assertNotNull(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesNoneSuccess() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "NONE"); - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "10"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - assertNotNull(propProvider); - } - - - @Test - public void reqExecCommand_setPropertiesElsePortNull() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("User", "test"); - params.put("Password", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - assertNotNull(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesElsePortString() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "test"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - assertNotNull(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesElseSuccess() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "10"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - String adaptorName = adapter.getAdapterName(); - assertEquals("Saltstack Adapter", adaptorName); - } - - @Test - public void reqExecCommand_setPropertiesDefault() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - adapter = new SaltstackAdapterImpl(); - assertNotNull(adapter); - } -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/model/TestJsonParser.java b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/model/TestJsonParser.java deleted file mode 100644 index d4eafc1a0..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/model/TestJsonParser.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2018 Samsung Electronics. All rights - * reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.adapter.model; - -import org.codehaus.jettison.json.JSONException; -import org.junit.Test; -import org.onap.ccsdk.sli.adaptors.saltstack.model.JsonParser; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import static org.junit.Assert.assertNotNull; - -public class TestJsonParser { - - private static final Logger log = LoggerFactory.getLogger(TestJsonParser.class); - - @Test - public void test() throws SvcLogicException, IOException, JSONException { - BufferedReader in = new BufferedReader( - new InputStreamReader(ClassLoader.getSystemResourceAsStream("test.json")) - ); - StringBuilder b = new StringBuilder(); - String line; - while ((line = in.readLine()) != null) - b.append(line).append('\n'); - - Map mm = JsonParser.convertToProperties(b.toString()); - - logProperties(mm); - - in.close(); - assertNotNull(mm); - } - - @Test(expected = NullPointerException.class) - public void testNullString() throws SvcLogicException, JSONException { - JsonParser.convertToProperties(null); - } - - private void logProperties(Map mm) { - List ll = new ArrayList<>(); - for (Object o : mm.keySet()) - ll.add((String) o); - Collections.sort(ll); - log.info("Properties:"); - for (String name : ll) - log.info("--- {}: {}", name, mm.get(name)); - } -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/config.sls b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/config.sls deleted file mode 100644 index aff05939b..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/config.sls +++ /dev/null @@ -1,2 +0,0 @@ -vim: - pkg.installed diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/org/onap/ccsdk/default.properties b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/org/onap/ccsdk/default.properties deleted file mode 100644 index e5650e853..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/org/onap/ccsdk/default.properties +++ /dev/null @@ -1,102 +0,0 @@ -### -# ============LICENSE_START======================================================= -# ONAP : CCSDK -# ================================================================================ -# Copyright (C) 2018 Samsung Electronics. All rights reserved. -# ================================================================================ -# -# ============================================================================= -# 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. -# -# -# ============LICENSE_END========================================================= -### -# -# Default properties for the APP-C Provider Adapter -# -# ------------------------------------------------------------------------------------------------- -# -# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded -# to supply configuration options -org.onap.appc.bootstrap.file=appc.properties -org.onap.appc.bootstrap.path=/opt/onap/appc/data/properties,${user.home},. -appc.application.name=APPC -# -# Define the message resource bundle name to be loaded -org.onap.appc.resources=org/onap/appc/i18n/MessageResources -# -# The name of the adapter. -org.onap.appc.provider.adaptor.name=org.onap.appc.appc_provider_adapter -# -# Set up the logging environment -# -org.onap.appc.logging.file=org/onap/appc/logback.xml -org.onap.appc.logging.path=${user.home};etc;../etc -org.onap.appc.logger=org.onap.appc -org.onap.appc.security.logger=org.onap.appc.security -# -# The minimum and maximum provider/tenant context pool sizes. Min=1 means that as soon -# as the provider/tenant is referenced a Context is opened and added to the pool. Max=0 -# means that the upper bound on the pool is unbounded. -org.onap.appc.provider.min.pool=1 -org.onap.appc.provider.max.pool=0 -# -# The following properties are used to configure the retry logic for connection to the -# IaaS provider(s). The retry delay property is the amount of time, in seconds, the -# application waits between retry attempts. The retry limit is the number of retries -# that are allowed before the request is failed. -org.onap.appc.provider.retry.delay=30 -org.onap.appc.provider.retry.limit=10 -# -# The trusted hosts list for SSL access when a certificate is not provided. -# -provider.trusted.hosts=* -# -# The amount of time, in seconds, to wait for a server state change (start->stop, stop->start, etc). -# If the server does not change state to a valid state within the alloted time, the operation -# fails. -org.onap.appc.server.state.change.timeout=300 -# -# The amount of time to wait, in seconds, between subsequent polls to the OpenStack provider -# to refresh the status of a resource we are waiting on. -# -org.onap.appc.openstack.poll.interval=20 -# -# The connection information to connect to the provider we are using. These properties -# are "structured" properties, in that the name is a compound name, where the nodes -# of the name can be ordered (1, 2, 3, ...). All of the properties with the same ordinal -# position are defining the same entity. For example, provider1.type and provider1.name -# are defining the same provider, whereas provider2.name and provider2.type are defining -# the values for a different provider. Any number of providers can be defined in this -# way. -# -# Don't change these 2 right now since they are hard coded in the DG -#provider1.type=appc -#provider1.name=appc -#These you can change -#provider1.identity=appc -#provider1.tenant1.name=appc -#provider1.tenant1.userid=appc -#provider1.tenant1.password=appc -# After a change to the provider make sure to recheck these values with an api call to provider1.identity/tokens -test.expected-regions=1 -test.expected-endpoints=1 -#Your OpenStack IP -#test.ip=192.168.1.2 -# Your OpenStack Platform's Keystone Port (default is 5000) -#test.port=5000 -#test.tenantid=abcde12345fghijk6789lmnopq123rst -#test.vmid=abc12345-1234-5678-890a-abcdefg12345 -# Port 8774 below is default port for OpenStack's Nova API Service -#test.url=http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345 - diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test deleted file mode 100644 index dec578bd9..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test +++ /dev/null @@ -1,30 +0,0 @@ -operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-egress-class-queueing-policing-codes.cos2v-queueing-code = P -operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-egress-class-queueing-policing-codes.cos3-queueing-code = W -operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-per-class-queueing-behaviors.cos2-queueing = WRED -operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-per-class-queueing-behaviors.cos2v-queueing = QueueLimit -operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing = WRED -operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-behaviors.cos2-shaping = Disable -operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-behaviors.cos2v-shaping = Enable -operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-behaviors.cos3-shaping = Disable -operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-codes.cos2-shaping-code = W -operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-codes.cos2v-shaping-code = P -service-configuration-notification-input.ack-final-indicator = Y -service-configuration-notification-input.response-code = 0 -service-configuration-notification-input.response-message = Plc Activation Failed: Device gblond2005me6 Sync-from Failed. Please check device IP address and NCS setup. -service-configuration-notification-input.service-information.service-instance-id = TEST7 -service-configuration-notification-input.service-information.service-type = AVPN -service-configuration-notification-input.svc-request-id = TEST7 -service-data.avpn-ip-port-information.avpn-access-information.access-circuit-id = DHEC.54831.170.ATI -service-data.avpn-ip-port-information.avpn-access-information.access-interface = _1G -service-data.avpn-ip-port-information.avpn-access-information.access-speed = 10000 -service-data.avpn-ip-port-information.avpn-access-information.access-speed-units = Kbps -service-data.avpn-ip-port-information.avpn-access-information.l1-customer-handoff = _1000BASELX -service-data.avpn-ip-port-information.avpn-access-information.managed-ce = N -service-data.avpn-ip-port-information.avpn-access-information.vlan-tag-control = _1Q -service-data.avpn-ip-port-information.clli = LONDENEH -service-data.avpn-ip-port-information.contracted-port-speed = 10000 -service-data.avpn-ip-port-information.contracted-port-speed-units = Kbps -service-data.avpn-ip-port-information.endpoint-information.bundle-id = 33 -service-data.avpn-ip-port-information.endpoint-information.interface-string = ae0 -service-data.service-information.service-instance-id = ICORESITE-2751508 -service-data.service-information.service-type = AVPN diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test-invalid.json b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test-invalid.json deleted file mode 100644 index d16bfccdf..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test-invalid.json +++ /dev/null @@ -1,29 +0,0 @@ -"equipment-data": [ -{ -"server-count": "4", -"max-server-speed": "1600000", -"number-primary-servers": "2", -"equipment-id": "Server1", -"server-model": "Unknown", -"server-id": "Server1", -"test-node": { -"test-inner-node": "Test-Value" -} -} -], -"resource-state": { -"threshold-value": "1600000", -"last-added": "1605000", -"used": "1605000", -"limit-value": "1920000" -}, -"resource-rule": { -"endpoint-position": "VCE-Cust", -"soft-limit-expression": "0.6 * max-server-speed * number-primary-servers", -"resource-name": "Bandwidth", -"service-model": "DUMMY", -"hard-limit-expression": "max-server-speed * number-primary-servers", -"equipment-level": "Server" -}, -"message": "The provisioned access bandwidth is at or exceeds 50% of the total server capacity." -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test-sls.json b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test-sls.json deleted file mode 100644 index bc1c10c8d..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test-sls.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "minion1": { - "retcode": 0, - "pkg_|-install_network_packages_|-install_network_packages_|-installed": { - "comment": "The following packages were installed/updated: lftp\nThe following packages were already installed: rsync, curl", - "name": "install_network_packages", - "start_time": "08:47:16.061765", - "result": true, - "duration": 11086.334, - "__run_num__": 0, - "__sls__": "nettools", - "changes": { - "lftp": { - "new": "4.6.3a-1build2", - "old": "" - } - }, - "__id__": "install_network_packages" - } - }, - "minion2": { - "retcode": 0, - "pkg_|-install_network_packages_|-install_network_packages_|-installed": { - "comment": "All specified packages are already installed", - "name": "curl", - "start_time": "08:47:16.152099", - "result": true, - "duration": 426.493, - "__run_num__": 0, - "__sls__": "nettools", - "changes": {}, - "__id__": "install_network_packages" - } - } -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test.json b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test.json deleted file mode 100644 index 81131d6f4..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "equipment-data": [ - { - "server-count": "4", - "max-server-speed": "1600000", - "number-primary-servers": "2", - "equipment-id": "Server1", - "server-model": "Unknown", - "server-id": "Server1", - "test-node": { - "test-inner-node": "Test-Value" - } - } - ], - "resource-state": { - "threshold-value": "1600000", - "last-added": "1605000", - "used": "1605000", - "limit-value": "1920000" - }, - "resource-rule": { - "endpoint-position": "VCE-Cust", - "soft-limit-expression": "0.6 * max-server-speed * number-primary-servers", - "resource-name": "Bandwidth", - "service-model": "DUMMY", - "hard-limit-expression": "max-server-speed * number-primary-servers", - "equipment-level": "Server" - }, - "message": "The provisioned access bandwidth is at or exceeds 50% of the total server capacity." -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test.sls b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test.sls deleted file mode 100644 index cd76486aa..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test.sls +++ /dev/null @@ -1,30 +0,0 @@ -{ - "equipment-data": [ - { - "server-count": "4", - "max-server-speed": "1600000", - "number-primary-servers": "2", - "equipment-id": "Server1", - "server-model": "Unknown", - "server-id": "Server1", - "test-node" : { - "test-inner-node" : "Test-Value" - } - } - ], - "resource-state": { - "threshold-value": "1600000", - "last-added": "1605000", - "used": "1605000", - "limit-value": "1920000" - }, - "resource-rule": { - "endpoint-position": "VCE-Cust", - "soft-limit-expression": "0.6 * max-server-speed * number-primary-servers", - "resource-name": "Bandwidth", - "service-model": "DUMMY", - "hard-limit-expression": "max-server-speed * number-primary-servers", - "equipment-level": "Server" - }, - "message": "The provisioned access bandwidth is at or exceeds 50% of the total server capacity." -} diff --git a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test.txt b/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test.txt deleted file mode 100644 index dec578bd9..000000000 --- a/adaptors/saltstack-adapter/saltstack-adapter-provider/src/test/resources/test.txt +++ /dev/null @@ -1,30 +0,0 @@ -operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-egress-class-queueing-policing-codes.cos2v-queueing-code = P -operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-egress-class-queueing-policing-codes.cos3-queueing-code = W -operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-per-class-queueing-behaviors.cos2-queueing = WRED -operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-per-class-queueing-behaviors.cos2v-queueing = QueueLimit -operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing = WRED -operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-behaviors.cos2-shaping = Disable -operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-behaviors.cos2v-shaping = Enable -operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-behaviors.cos3-shaping = Disable -operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-codes.cos2-shaping-code = W -operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-codes.cos2v-shaping-code = P -service-configuration-notification-input.ack-final-indicator = Y -service-configuration-notification-input.response-code = 0 -service-configuration-notification-input.response-message = Plc Activation Failed: Device gblond2005me6 Sync-from Failed. Please check device IP address and NCS setup. -service-configuration-notification-input.service-information.service-instance-id = TEST7 -service-configuration-notification-input.service-information.service-type = AVPN -service-configuration-notification-input.svc-request-id = TEST7 -service-data.avpn-ip-port-information.avpn-access-information.access-circuit-id = DHEC.54831.170.ATI -service-data.avpn-ip-port-information.avpn-access-information.access-interface = _1G -service-data.avpn-ip-port-information.avpn-access-information.access-speed = 10000 -service-data.avpn-ip-port-information.avpn-access-information.access-speed-units = Kbps -service-data.avpn-ip-port-information.avpn-access-information.l1-customer-handoff = _1000BASELX -service-data.avpn-ip-port-information.avpn-access-information.managed-ce = N -service-data.avpn-ip-port-information.avpn-access-information.vlan-tag-control = _1Q -service-data.avpn-ip-port-information.clli = LONDENEH -service-data.avpn-ip-port-information.contracted-port-speed = 10000 -service-data.avpn-ip-port-information.contracted-port-speed-units = Kbps -service-data.avpn-ip-port-information.endpoint-information.bundle-id = 33 -service-data.avpn-ip-port-information.endpoint-information.interface-string = ae0 -service-data.service-information.service-instance-id = ICORESITE-2751508 -service-data.service-information.service-type = AVPN diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exe-nonSLS.json b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exe-nonSLS.json deleted file mode 100644 index 562c24ad3..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exe-nonSLS.json +++ /dev/null @@ -1,203 +0,0 @@ -[ - { - "id": "d86e7ee4.ee3f1", - "type": "method", - "name": "saltstack-adapter-1.0", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 492, - "y": 216, - "z": "5945fc3c.78efc4", - "wires": [ - [ - "38662e01.1d3c22" - ] - ] - }, - { - "id": "9997883e.ec9028", - "type": "service-logic", - "name": "APPC 2.0.1", - "module": "APPC", - "version": "2.0.1", - "comments": "", - "xml": "", - "outputs": 1, - "x": 283, - "y": 289, - "z": "5945fc3c.78efc4", - "wires": [ - [ - "d86e7ee4.ee3f1" - ] - ] - }, - { - "id": "d40bf650.8338e8", - "type": "returnFailure", - "name": "return failure", - "xml": "\n\n\n\n", - "comments": "", - "x": 1007, - "y": 373, - "z": "5945fc3c.78efc4", - "wires": [] - }, - { - "id": "38662e01.1d3c22", - "type": "execute", - "name": "execute", - "xml": "\n \n \n \n \n \n \n \n \n", - "comments": "", - "outputs": 1, - "x": 700, - "y": 212, - "z": "5945fc3c.78efc4", - "wires": [ - [ - "7b75e382.6344dc", - "6f108926.d7baf8" - ] - ] - }, - { - "id": "24fb9f79.a6c6c", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 486, - "y": 372, - "z": "5945fc3c.78efc4", - "wires": [ - [ - "c526c44.c850738", - "9c394980.2a56a8" - ] - ] - }, - { - "id": "c526c44.c850738", - "type": "other", - "name": "outcome", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 675, - "y": 371, - "z": "5945fc3c.78efc4", - "wires": [ - [ - "d40bf650.8338e8" - ] - ] - }, - { - "id": "7b75e382.6344dc", - "type": "failure", - "name": "failure", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 951, - "y": 210, - "z": "5945fc3c.78efc4", - "wires": [ - [ - "d40bf650.8338e8" - ] - ] - }, - { - "id": "6f108926.d7baf8", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 298, - "y": 378, - "z": "5945fc3c.78efc4", - "wires": [ - [ - "24fb9f79.a6c6c" - ] - ] - }, - { - "id": "9c394980.2a56a8", - "type": "success", - "name": "success", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 667, - "y": 460, - "z": "5945fc3c.78efc4", - "wires": [ - [ - "1f81a3db.54cd1c" - ] - ] - }, - { - "id": "1f81a3db.54cd1c", - "type": "returnSuccess", - "name": "return success", - "xml": "\n\n\n\n", - "comments": "", - "x": 887, - "y": 460, - "z": "5945fc3c.78efc4", - "wires": [] - }, - { - "id": "fcad80f8.ba2d9", - "type": "dgstart", - "name": "DGSTART", - "outputs": 1, - "x": 261, - "y": 189, - "z": "5945fc3c.78efc4", - "wires": [ - [ - "9997883e.ec9028" - ] - ] - }, - { - "id": "b86e624d.49f0f", - "type": "comment", - "name": "SaltStack Adaptor DG", - "info": "", - "comments": "", - "x": 630, - "y": 75, - "z": "5945fc3c.78efc4", - "wires": [] - }, - { - "id": "83c0578d.061f98", - "type": "comment", - "name": "request-method = reqExecCommand, req-action = \"execute a single non SLS command\"", - "info": "", - "comments": "", - "x": 650, - "y": 155, - "z": "5945fc3c.78efc4", - "wires": [] - }, - { - "id": "f104feb6.558f7", - "type": "comment", - "name": "Assumptions for this DG", - "info": "Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controlls minion1 and minion2. ", - "comments": "", - "x": 627, - "y": 115, - "z": "5945fc3c.78efc4", - "wires": [] - } -] \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exe-nonSLS.xml b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exe-nonSLS.xml deleted file mode 100644 index 6fbbe5b1f..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exe-nonSLS.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-SLSFile.json b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-SLSFile.json deleted file mode 100644 index 7f427674b..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-SLSFile.json +++ /dev/null @@ -1,350 +0,0 @@ -[ - { - "id": "d0ad0305.352fc", - "type": "method", - "name": "saltstack-adapter-1.0", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 552, - "y": 183, - "z": "b84dc629.83cd08", - "wires": [ - [ - "65cc87e2.a95188" - ] - ] - }, - { - "id": "22aefec.e8c7902", - "type": "service-logic", - "name": "APPC 2.0.1", - "module": "APPC", - "version": "2.0.1", - "comments": "", - "xml": "", - "outputs": 1, - "x": 343, - "y": 261, - "z": "b84dc629.83cd08", - "wires": [ - [ - "d0ad0305.352fc" - ] - ] - }, - { - "id": "31587001.4259e", - "type": "returnFailure", - "name": "return failure", - "xml": "\n\n\n\n", - "comments": "", - "x": 1262, - "y": 365, - "z": "b84dc629.83cd08", - "wires": [] - }, - { - "id": "65cc87e2.a95188", - "type": "execute", - "name": "execute", - "xml": "\n \n \n \n \n \n \n \n \n", - "comments": "", - "outputs": 1, - "x": 761, - "y": 185, - "z": "b84dc629.83cd08", - "wires": [ - [ - "f9bf6ee7.cf954", - "7b51c357.a852cc" - ] - ] - }, - { - "id": "42fa1258.aa570c", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 544, - "y": 345, - "z": "b84dc629.83cd08", - "wires": [ - [ - "a7cf236a.84c03", - "c45d597b.20b4c8" - ] - ] - }, - { - "id": "a7cf236a.84c03", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 735, - "y": 343, - "z": "b84dc629.83cd08", - "wires": [ - [ - "31587001.4259e" - ] - ] - }, - { - "id": "f9bf6ee7.cf954", - "type": "failure", - "name": "failure", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 1011, - "y": 182, - "z": "b84dc629.83cd08", - "wires": [ - [ - "31587001.4259e" - ] - ] - }, - { - "id": "7b51c357.a852cc", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 366, - "y": 343, - "z": "b84dc629.83cd08", - "wires": [ - [ - "42fa1258.aa570c" - ] - ] - }, - { - "id": "c45d597b.20b4c8", - "type": "success", - "name": "success", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 351, - "y": 459, - "z": "b84dc629.83cd08", - "wires": [ - [ - "30d5f0f7.0e3c8" - ] - ] - }, - { - "id": "2856792.c401a86", - "type": "returnSuccess", - "name": "return success", - "xml": "\n\n\n\n", - "comments": "", - "x": 1042, - "y": 656, - "z": "b84dc629.83cd08", - "wires": [] - }, - { - "id": "6c359fdc.3b566", - "type": "dgstart", - "name": "DGSTART", - "outputs": 1, - "x": 321, - "y": 161, - "z": "b84dc629.83cd08", - "wires": [ - [ - "22aefec.e8c7902" - ] - ] - }, - { - "id": "b5342c59.29f74", - "type": "comment", - "name": "SaltStack Adaptor DG", - "info": "", - "comments": "", - "x": 693, - "y": 44, - "z": "b84dc629.83cd08", - "wires": [] - }, - { - "id": "19202194.8ff55e", - "type": "comment", - "name": "request-method = reqExecCommand, req-action = \"execute multiple SLS commands\"", - "info": "Here we basically test if minion1 is active by pinging to it, then install vim package to it. \n", - "comments": "", - "x": 711, - "y": 127, - "z": "b84dc629.83cd08", - "wires": [] - }, - { - "id": "a2ebc17e.fa03a", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 396, - "y": 661, - "z": "b84dc629.83cd08", - "wires": [ - [ - "c9345fbb.d6d19" - ] - ] - }, - { - "id": "770411a5.18825", - "type": "execute", - "name": "execute", - "xml": "\n \n \n \n \n \n \n \n \n", - "comments": "", - "outputs": 1, - "x": 773, - "y": 548, - "z": "b84dc629.83cd08", - "wires": [ - [ - "e09a3e12.87428", - "a2ebc17e.fa03a" - ] - ] - }, - { - "id": "e09a3e12.87428", - "type": "failure", - "name": "failure", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 991, - "y": 554, - "z": "b84dc629.83cd08", - "wires": [ - [ - "31587001.4259e" - ] - ] - }, - { - "id": "c9345fbb.d6d19", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 578, - "y": 658, - "z": "b84dc629.83cd08", - "wires": [ - [ - "485e453d.36c75c", - "f1adcf2a.2c456" - ] - ] - }, - { - "id": "485e453d.36c75c", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 783, - "y": 732, - "z": "b84dc629.83cd08", - "wires": [ - [ - "31587001.4259e" - ] - ] - }, - { - "id": "f1adcf2a.2c456", - "type": "success", - "name": "success", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 776, - "y": 658, - "z": "b84dc629.83cd08", - "wires": [ - [ - "2856792.c401a86" - ] - ] - }, - { - "id": "30d5f0f7.0e3c8", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 523, - "y": 459, - "z": "b84dc629.83cd08", - "wires": [ - [ - "15e9ff68.9812a1", - "17d9d7e.4d9a928" - ] - ] - }, - { - "id": "17d9d7e.4d9a928", - "type": "other", - "name": "outcome", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 593, - "y": 550, - "z": "b84dc629.83cd08", - "wires": [ - [ - "770411a5.18825" - ] - ] - }, - { - "id": "15e9ff68.9812a1", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 717, - "y": 459, - "z": "b84dc629.83cd08", - "wires": [ - [ - "31587001.4259e" - ] - ] - }, - { - "id": "b764890c.ed0018", - "type": "comment", - "name": "Assumptions for this DG (example-server)", - "info": "1) Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controlls minion1 and minion2. \n2) We assume that sls file called vim.sls is already present in the path /srv/salt on the server.", - "comments": "", - "x": 693, - "y": 86, - "z": "b84dc629.83cd08", - "wires": [] - } -] \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-SLSFile.xml b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-SLSFile.xml deleted file mode 100644 index fc63bbd7b..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-SLSFile.xml +++ /dev/null @@ -1,112 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-multi-sls.json b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-multi-sls.json deleted file mode 100644 index d7cfef01e..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-multi-sls.json +++ /dev/null @@ -1,399 +0,0 @@ -[ - { - "id": "65f5c0d6.9c4ce", - "type": "method", - "name": "saltstack-adapter-1.0", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 615, - "y": 273, - "z": "6df02477.0463cc", - "wires": [ - [ - "c332cb01.51a3e8" - ] - ] - }, - { - "id": "bf71bd6e.1be5b", - "type": "service-logic", - "name": "APPC 2.0.1", - "module": "APPC", - "version": "2.0.1", - "comments": "", - "xml": "", - "outputs": 1, - "x": 406, - "y": 351, - "z": "6df02477.0463cc", - "wires": [ - [ - "65f5c0d6.9c4ce" - ] - ] - }, - { - "id": "40ce8a6.5f7d174", - "type": "returnFailure", - "name": "return failure", - "xml": "\n\n\n\n", - "comments": "", - "x": 1325, - "y": 455, - "z": "6df02477.0463cc", - "wires": [] - }, - { - "id": "c332cb01.51a3e8", - "type": "execute", - "name": "execute", - "xml": "\n \n \n \n \n \n \n \n \n", - "comments": "", - "outputs": 1, - "x": 824, - "y": 275, - "z": "6df02477.0463cc", - "wires": [ - [ - "5b387684.e51be8", - "4bb6b32e.adfc2c" - ] - ] - }, - { - "id": "16dfbd4f.b6da73", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 607, - "y": 435, - "z": "6df02477.0463cc", - "wires": [ - [ - "24d22f52.ef59a", - "ac765880.a6c548" - ] - ] - }, - { - "id": "24d22f52.ef59a", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 798, - "y": 433, - "z": "6df02477.0463cc", - "wires": [ - [ - "40ce8a6.5f7d174" - ] - ] - }, - { - "id": "5b387684.e51be8", - "type": "failure", - "name": "failure", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 1074, - "y": 272, - "z": "6df02477.0463cc", - "wires": [ - [ - "40ce8a6.5f7d174" - ] - ] - }, - { - "id": "4bb6b32e.adfc2c", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 429, - "y": 433, - "z": "6df02477.0463cc", - "wires": [ - [ - "16dfbd4f.b6da73" - ] - ] - }, - { - "id": "ac765880.a6c548", - "type": "success", - "name": "success", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 414, - "y": 549, - "z": "6df02477.0463cc", - "wires": [ - [ - "2dda30fc.8747" - ] - ] - }, - { - "id": "e45accfe.91615", - "type": "returnSuccess", - "name": "return success", - "xml": "\n\n\n\n", - "comments": "", - "x": 1345, - "y": 757, - "z": "6df02477.0463cc", - "wires": [] - }, - { - "id": "11a891ad.55bc1e", - "type": "dgstart", - "name": "DGSTART", - "outputs": 1, - "x": 384, - "y": 251, - "z": "6df02477.0463cc", - "wires": [ - [ - "bf71bd6e.1be5b" - ] - ] - }, - { - "id": "a56383b.496c48", - "type": "comment", - "name": "SaltStack Adaptor DG", - "info": "", - "comments": "", - "x": 756, - "y": 134, - "z": "6df02477.0463cc", - "wires": [] - }, - { - "id": "cfda30b5.5e166", - "type": "comment", - "name": "request-method = reqExecCommand, req-action = \"execute multiple SLS commands\"", - "info": "Here we basically test if minion1 is active by pinging to it, then install vim package to it. \n", - "comments": "", - "x": 773, - "y": 217, - "z": "6df02477.0463cc", - "wires": [] - }, - { - "id": "a8efb922.f23ce8", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 459, - "y": 751, - "z": "6df02477.0463cc", - "wires": [ - [ - "3ff32215.20cd0e" - ] - ] - }, - { - "id": "df0c0907.d17838", - "type": "execute", - "name": "execute", - "xml": "\n \n \n \n \n \n \n \n \n", - "comments": "", - "outputs": 1, - "x": 836, - "y": 638, - "z": "6df02477.0463cc", - "wires": [ - [ - "1e5bbe2e.9cbb82", - "a8efb922.f23ce8" - ] - ] - }, - { - "id": "1e5bbe2e.9cbb82", - "type": "failure", - "name": "failure", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 1054, - "y": 644, - "z": "6df02477.0463cc", - "wires": [ - [ - "40ce8a6.5f7d174" - ] - ] - }, - { - "id": "3ff32215.20cd0e", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 647, - "y": 745, - "z": "6df02477.0463cc", - "wires": [ - [ - "8e2c712b.784b4", - "3d74cfe5.d41f5" - ] - ] - }, - { - "id": "8e2c712b.784b4", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 830, - "y": 823, - "z": "6df02477.0463cc", - "wires": [ - [ - "40ce8a6.5f7d174" - ] - ] - }, - { - "id": "3d74cfe5.d41f5", - "type": "success", - "name": "success", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 829, - "y": 758, - "z": "6df02477.0463cc", - "wires": [ - [ - "8313564b.004798" - ] - ] - }, - { - "id": "2dda30fc.8747", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 586, - "y": 549, - "z": "6df02477.0463cc", - "wires": [ - [ - "e0133af5.2ca028", - "7f28f521.cf47cc" - ] - ] - }, - { - "id": "7f28f521.cf47cc", - "type": "other", - "name": "outcome", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 656, - "y": 640, - "z": "6df02477.0463cc", - "wires": [ - [ - "df0c0907.d17838" - ] - ] - }, - { - "id": "e0133af5.2ca028", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 780, - "y": 549, - "z": "6df02477.0463cc", - "wires": [ - [ - "40ce8a6.5f7d174" - ] - ] - }, - { - "id": "8313564b.004798", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 986, - "y": 752, - "z": "6df02477.0463cc", - "wires": [ - [ - "13d18d2d.71fbf3", - "2e940add.522a36" - ] - ] - }, - { - "id": "13d18d2d.71fbf3", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 1165, - "y": 825, - "z": "6df02477.0463cc", - "wires": [ - [ - "40ce8a6.5f7d174" - ] - ] - }, - { - "id": "2e940add.522a36", - "type": "success", - "name": "success", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 1156, - "y": 754, - "z": "6df02477.0463cc", - "wires": [ - [ - "e45accfe.91615" - ] - ] - }, - { - "id": "6d6678d2.6a9bd8", - "type": "comment", - "name": "Assumptions for this DG (example-server)", - "info": "Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controlls minion1 and minion2. ", - "comments": "", - "x": 756, - "y": 173, - "z": "6df02477.0463cc", - "wires": [] - } -] \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-multi-sls.xml b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-multi-sls.xml deleted file mode 100644 index cc36b1ca7..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-multi-sls.xml +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-single-SLSComm.json b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-single-SLSComm.json deleted file mode 100644 index 4be0db3dd..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-single-SLSComm.json +++ /dev/null @@ -1,203 +0,0 @@ -[ - { - "id": "bd0f1105.ff214", - "type": "method", - "name": "saltstack-adapter-1.0", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 526, - "y": 238, - "z": "c053ae12.4067b", - "wires": [ - [ - "f4e59dd0.ee45f" - ] - ] - }, - { - "id": "26f2a2b8.90f58e", - "type": "service-logic", - "name": "APPC 2.0.1", - "module": "APPC", - "version": "2.0.1", - "comments": "", - "xml": "", - "outputs": 1, - "x": 317, - "y": 316, - "z": "c053ae12.4067b", - "wires": [ - [ - "bd0f1105.ff214" - ] - ] - }, - { - "id": "55a7736.2789e8c", - "type": "returnFailure", - "name": "return failure", - "xml": "\n\n\n\n", - "comments": "", - "x": 1064, - "y": 453, - "z": "c053ae12.4067b", - "wires": [] - }, - { - "id": "f4e59dd0.ee45f", - "type": "execute", - "name": "execute", - "xml": "\n \n \n \n \n \n \n \n \n", - "comments": "", - "outputs": 1, - "x": 735, - "y": 240, - "z": "c053ae12.4067b", - "wires": [ - [ - "93fca622.05ad58", - "7ce4a659.44c828" - ] - ] - }, - { - "id": "2ceb37d9.a8ba18", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 522, - "y": 398, - "z": "c053ae12.4067b", - "wires": [ - [ - "cd89356c.279678", - "781026e2.01d498" - ] - ] - }, - { - "id": "cd89356c.279678", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 708, - "y": 456, - "z": "c053ae12.4067b", - "wires": [ - [ - "55a7736.2789e8c" - ] - ] - }, - { - "id": "93fca622.05ad58", - "type": "failure", - "name": "failure", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 985, - "y": 237, - "z": "c053ae12.4067b", - "wires": [ - [ - "55a7736.2789e8c" - ] - ] - }, - { - "id": "7ce4a659.44c828", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 332, - "y": 405, - "z": "c053ae12.4067b", - "wires": [ - [ - "2ceb37d9.a8ba18" - ] - ] - }, - { - "id": "781026e2.01d498", - "type": "success", - "name": "success", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 711, - "y": 398, - "z": "c053ae12.4067b", - "wires": [ - [ - "ce510062.8dcc7" - ] - ] - }, - { - "id": "ce510062.8dcc7", - "type": "returnSuccess", - "name": "return success", - "xml": "\n\n\n\n", - "comments": "", - "x": 893, - "y": 399, - "z": "c053ae12.4067b", - "wires": [] - }, - { - "id": "593bd7fb.675368", - "type": "dgstart", - "name": "DGSTART", - "outputs": 1, - "x": 295, - "y": 216, - "z": "c053ae12.4067b", - "wires": [ - [ - "26f2a2b8.90f58e" - ] - ] - }, - { - "id": "901c8408.5fecb8", - "type": "comment", - "name": "SaltStack Adaptor DG", - "info": "", - "comments": "", - "x": 673, - "y": 103, - "z": "c053ae12.4067b", - "wires": [] - }, - { - "id": "cc449713.a1be88", - "type": "comment", - "name": "request-method = reqExecCommand, req-action = \"execute a single SLS command\"", - "info": "Here we just ping to all the minions, and we dont even check if the minions are active. ", - "comments": "", - "x": 684, - "y": 188, - "z": "c053ae12.4067b", - "wires": [] - }, - { - "id": "c07fa80e.7f3ac8", - "type": "comment", - "name": "Assumptions for this DG (example-server)", - "info": "Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controlls minion1 and minion2. ", - "comments": "", - "x": 676, - "y": 144, - "z": "c053ae12.4067b", - "wires": [] - } -] \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-single-SLSComm.xml b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-single-SLSComm.xml deleted file mode 100644 index bd9aea771..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adapter-1.0-exec-single-SLSComm.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0 IDEAL.json b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0 IDEAL.json deleted file mode 100644 index 7fe88f063..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0 IDEAL.json +++ /dev/null @@ -1,214 +0,0 @@ -[ - { - "id": "80b83851.e527b8", - "type": "method", - "name": "saltstack-adapter-1.0", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 676, - "y": 277, - "z": "1f6661d7.1ebd2e", - "wires": [ - [ - "83c8d47e.cb9c98" - ] - ] - }, - { - "id": "41231c44.5d1324", - "type": "service-logic", - "name": "APPC 2.0.1", - "module": "APPC", - "version": "2.0.1", - "comments": "", - "xml": "", - "outputs": 1, - "x": 453, - "y": 276, - "z": "1f6661d7.1ebd2e", - "wires": [ - [ - "80b83851.e527b8" - ] - ] - }, - { - "id": "1f4a794d.fb3be7", - "type": "returnSuccess", - "name": "return success", - "xml": "\n\n\n\n", - "comments": "", - "x": 1055, - "y": 369, - "z": "1f6661d7.1ebd2e", - "wires": [] - }, - { - "id": "5a85036.5a9e2fc", - "type": "dgstart", - "name": "DGSTART", - "outputs": 1, - "x": 284, - "y": 275, - "z": "1f6661d7.1ebd2e", - "wires": [ - [ - "41231c44.5d1324" - ] - ] - }, - { - "id": "b38fc61c.a23438", - "type": "comment", - "name": "SaltStack Adaptor DG", - "info": "", - "comments": "", - "x": 661, - "y": 154, - "z": "1f6661d7.1ebd2e", - "wires": [] - }, - { - "id": "6a821d83.4070e4", - "type": "comment", - "name": "request-method = reqExecSLS, req-action = \"execute SLS\"", - "info": "This would be the ideal adaptor the orchestrator DG will call, this just takes in SlsName.", - "comments": "", - "x": 672, - "y": 239, - "z": "1f6661d7.1ebd2e", - "wires": [] - }, - { - "id": "ba16960c.36bad8", - "type": "comment", - "name": "Assumptions for this DG (example-server)", - "info": "Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controllers minion1 and minion2. ", - "comments": "", - "x": 664, - "y": 195, - "z": "1f6661d7.1ebd2e", - "wires": [] - }, - { - "id": "83c8d47e.cb9c98", - "type": "execute", - "name": "execute", - "xml": "\n \n \n \n \n \n \n \n \n \n \n", - "comments": "", - "outputs": 1, - "x": 366, - "y": 406, - "z": "1f6661d7.1ebd2e", - "wires": [ - [ - "b83f5a23.33f938", - "3354190.eb450e8" - ] - ] - }, - { - "id": "b83f5a23.33f938", - "type": "failure", - "name": "failure", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 559, - "y": 367, - "z": "1f6661d7.1ebd2e", - "wires": [ - [ - "efc02e73.0cf1d" - ] - ] - }, - { - "id": "3354190.eb450e8", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 557, - "y": 439, - "z": "1f6661d7.1ebd2e", - "wires": [ - [ - "88b53985.e42758" - ] - ] - }, - { - "id": "88b53985.e42758", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 709, - "y": 427, - "z": "1f6661d7.1ebd2e", - "wires": [ - [ - "195a294e.61efb7", - "bc1bfd78.146bc" - ] - ] - }, - { - "id": "bc1bfd78.146bc", - "type": "success", - "name": "success", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 872, - "y": 373, - "z": "1f6661d7.1ebd2e", - "wires": [ - [ - "1f4a794d.fb3be7" - ] - ] - }, - { - "id": "195a294e.61efb7", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 869, - "y": 442, - "z": "1f6661d7.1ebd2e", - "wires": [ - [ - "81ddc2e0.dce24" - ] - ] - }, - { - "id": "efc02e73.0cf1d", - "type": "returnFailure", - "name": "return failure", - "xml": "\n\n\n\n", - "comments": "", - "x": 719, - "y": 351, - "z": "1f6661d7.1ebd2e", - "wires": [] - }, - { - "id": "81ddc2e0.dce24", - "type": "returnFailure", - "name": "return failure", - "xml": "\n\n\n\n", - "comments": "", - "x": 1039, - "y": 439, - "z": "1f6661d7.1ebd2e", - "wires": [] - } -] \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0 IDEAL.xml b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0 IDEAL.xml deleted file mode 100644 index 23ec7856b..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0 IDEAL.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0-exec-SLS-applyTo.json b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0-exec-SLS-applyTo.json deleted file mode 100644 index b276f3815..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0-exec-SLS-applyTo.json +++ /dev/null @@ -1,372 +0,0 @@ -[ - { - "id": "edb39979.b1ccd8", - "type": "method", - "name": "saltstack-adapter-1.0", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 476, - "y": 245, - "z": "671ca899.284f68", - "wires": [ - [ - "95c9ba42.6e4aa8" - ] - ] - }, - { - "id": "a16ea11e.f8d1c", - "type": "service-logic", - "name": "APPC 2.0.1", - "module": "APPC", - "version": "2.0.1", - "comments": "", - "xml": "", - "outputs": 1, - "x": 267, - "y": 323, - "z": "671ca899.284f68", - "wires": [ - [ - "edb39979.b1ccd8" - ] - ] - }, - { - "id": "1591f92e.029ca7", - "type": "returnFailure", - "name": "return failure", - "xml": "\n\n\n\n", - "comments": "", - "x": 1191, - "y": 315, - "z": "671ca899.284f68", - "wires": [] - }, - { - "id": "95c9ba42.6e4aa8", - "type": "execute", - "name": "execute", - "xml": "\n \n \n \n \n \n \n \n \n", - "comments": "", - "outputs": 1, - "x": 684, - "y": 251, - "z": "671ca899.284f68", - "wires": [ - [ - "cd0c458a.2430b8", - "69e531e3.4efc3" - ] - ] - }, - { - "id": "38b44d70.9c85d2", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 472, - "y": 405, - "z": "671ca899.284f68", - "wires": [ - [ - "505df598.069b9c", - "5d7292e.22ec06c" - ] - ] - }, - { - "id": "505df598.069b9c", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 658, - "y": 463, - "z": "671ca899.284f68", - "wires": [ - [ - "1591f92e.029ca7" - ] - ] - }, - { - "id": "cd0c458a.2430b8", - "type": "failure", - "name": "failure", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 935, - "y": 244, - "z": "671ca899.284f68", - "wires": [ - [ - "1591f92e.029ca7" - ] - ] - }, - { - "id": "69e531e3.4efc3", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 282, - "y": 412, - "z": "671ca899.284f68", - "wires": [ - [ - "38b44d70.9c85d2" - ] - ] - }, - { - "id": "5d7292e.22ec06c", - "type": "success", - "name": "success", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 661, - "y": 405, - "z": "671ca899.284f68", - "wires": [ - [ - "c9df0cea.f2361" - ] - ] - }, - { - "id": "e4f7eb59.0abb58", - "type": "returnSuccess", - "name": "return success", - "xml": "\n\n\n\n", - "comments": "", - "x": 1079, - "y": 564, - "z": "671ca899.284f68", - "wires": [] - }, - { - "id": "8e586da4.570f1", - "type": "dgstart", - "name": "DGSTART", - "outputs": 1, - "x": 245, - "y": 223, - "z": "671ca899.284f68", - "wires": [ - [ - "a16ea11e.f8d1c" - ] - ] - }, - { - "id": "71387074.137c1", - "type": "comment", - "name": "SaltStack Adaptor DG", - "info": "", - "comments": "", - "x": 623, - "y": 110, - "z": "671ca899.284f68", - "wires": [] - }, - { - "id": "c5e8c62d.021758", - "type": "comment", - "name": "request-method = reqExecSLS, req-action = \"execute SLS\"", - "info": "Here we basically test if minion1 is active by pinging to it, then respective sls file is executed on to it. \n", - "comments": "", - "x": 634, - "y": 195, - "z": "671ca899.284f68", - "wires": [] - }, - { - "id": "1805797.a241487", - "type": "comment", - "name": "Assumptions for this DG (example-server)", - "info": "Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controllers minion1 and minion2. ", - "comments": "", - "x": 626, - "y": 151, - "z": "671ca899.284f68", - "wires": [] - }, - { - "id": "c9df0cea.f2361", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 825, - "y": 405, - "z": "671ca899.284f68", - "wires": [ - [ - "d83d6024.2454d", - "f4d70bbc.f0bc38" - ] - ] - }, - { - "id": "d83d6024.2454d", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 991, - "y": 459, - "z": "671ca899.284f68", - "wires": [ - [ - "1591f92e.029ca7" - ] - ] - }, - { - "id": "f4d70bbc.f0bc38", - "type": "other", - "name": "outcome", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 994, - "y": 401, - "z": "671ca899.284f68", - "wires": [ - [ - "e86d9995.b65c58" - ] - ] - }, - { - "id": "e86d9995.b65c58", - "type": "execute", - "name": "execute", - "xml": "\n \n \n \n \n \n \n \n \n", - "comments": "", - "outputs": 1, - "x": 398, - "y": 593, - "z": "671ca899.284f68", - "wires": [ - [ - "89ff1c2a.08f52", - "e20c4c85.43d3c" - ] - ] - }, - { - "id": "89ff1c2a.08f52", - "type": "failure", - "name": "failure", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 583, - "y": 562, - "z": "671ca899.284f68", - "wires": [ - [ - "6032e33e.5b044c" - ] - ] - }, - { - "id": "e20c4c85.43d3c", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 581, - "y": 634, - "z": "671ca899.284f68", - "wires": [ - [ - "8bb4c177.499c8" - ] - ] - }, - { - "id": "8bb4c177.499c8", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 733, - "y": 622, - "z": "671ca899.284f68", - "wires": [ - [ - "905334fe.934d68", - "9c217c10.9d539" - ] - ] - }, - { - "id": "9c217c10.9d539", - "type": "success", - "name": "success", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 896, - "y": 568, - "z": "671ca899.284f68", - "wires": [ - [ - "e4f7eb59.0abb58" - ] - ] - }, - { - "id": "905334fe.934d68", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 893, - "y": 637, - "z": "671ca899.284f68", - "wires": [ - [ - "7026a88c.5bffd8" - ] - ] - }, - { - "id": "6032e33e.5b044c", - "type": "returnFailure", - "name": "return failure", - "xml": "\n\n\n\n", - "comments": "", - "x": 735, - "y": 559, - "z": "671ca899.284f68", - "wires": [] - }, - { - "id": "7026a88c.5bffd8", - "type": "returnFailure", - "name": "return failure", - "xml": "\n\n\n\n", - "comments": "", - "x": 1054, - "y": 637, - "z": "671ca899.284f68", - "wires": [] - } -] \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0-exec-SLS-applyTo.xml b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0-exec-SLS-applyTo.xml deleted file mode 100644 index cc4538cac..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adapter-1.0-exec-SLS-applyTo.xml +++ /dev/null @@ -1,112 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-SLSFILE.json b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-SLSFILE.json deleted file mode 100644 index b20e7e8da..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-SLSFILE.json +++ /dev/null @@ -1,214 +0,0 @@ -[ - { - "id": "3228200a.5dc1a", - "type": "method", - "name": "saltstack-adapter-1.0", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 679, - "y": 282, - "z": "6d4f912d.f07bc", - "wires": [ - [ - "50b2729f.712eac" - ] - ] - }, - { - "id": "9fb54163.4fb28", - "type": "service-logic", - "name": "APPC 2.0.1", - "module": "APPC", - "version": "2.0.1", - "comments": "", - "xml": "", - "outputs": 1, - "x": 456, - "y": 281, - "z": "6d4f912d.f07bc", - "wires": [ - [ - "3228200a.5dc1a" - ] - ] - }, - { - "id": "49109fbc.a7a14", - "type": "returnSuccess", - "name": "return success", - "xml": "\n\n\n\n", - "comments": "", - "x": 1058, - "y": 374, - "z": "6d4f912d.f07bc", - "wires": [] - }, - { - "id": "d030a396.56232", - "type": "dgstart", - "name": "DGSTART", - "outputs": 1, - "x": 287, - "y": 280, - "z": "6d4f912d.f07bc", - "wires": [ - [ - "9fb54163.4fb28" - ] - ] - }, - { - "id": "281900c4.fd3e8", - "type": "comment", - "name": "SaltStack Adaptor DG", - "info": "", - "comments": "", - "x": 664, - "y": 159, - "z": "6d4f912d.f07bc", - "wires": [] - }, - { - "id": "431a69db.2d2c58", - "type": "comment", - "name": "request-method = reqExecSLS, req-action = \"execute SLS\"", - "info": "This would be the ideal adaptor the orchestrator DG will call, this just takes in SlsName.", - "comments": "", - "x": 675, - "y": 244, - "z": "6d4f912d.f07bc", - "wires": [] - }, - { - "id": "4202e1ce.09495", - "type": "comment", - "name": "Assumptions for this DG (example-server)", - "info": "Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controllers minion1 and minion2. ", - "comments": "", - "x": 667, - "y": 200, - "z": "6d4f912d.f07bc", - "wires": [] - }, - { - "id": "50b2729f.712eac", - "type": "execute", - "name": "execute", - "xml": "\n \n \n \n \n \n \n", - "comments": "", - "outputs": 1, - "x": 369, - "y": 411, - "z": "6d4f912d.f07bc", - "wires": [ - [ - "71746570.35f0dc", - "3e4f7a4a.ae0dc6" - ] - ] - }, - { - "id": "71746570.35f0dc", - "type": "failure", - "name": "failure", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 562, - "y": 372, - "z": "6d4f912d.f07bc", - "wires": [ - [ - "e59a1a81.112a08" - ] - ] - }, - { - "id": "3e4f7a4a.ae0dc6", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 560, - "y": 444, - "z": "6d4f912d.f07bc", - "wires": [ - [ - "59e320fa.12908" - ] - ] - }, - { - "id": "59e320fa.12908", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 712, - "y": 432, - "z": "6d4f912d.f07bc", - "wires": [ - [ - "f81ed07.2135c3", - "eb55b5a9.f0d2f8" - ] - ] - }, - { - "id": "eb55b5a9.f0d2f8", - "type": "success", - "name": "success", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 875, - "y": 378, - "z": "6d4f912d.f07bc", - "wires": [ - [ - "49109fbc.a7a14" - ] - ] - }, - { - "id": "f81ed07.2135c3", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 872, - "y": 447, - "z": "6d4f912d.f07bc", - "wires": [ - [ - "6549631f.8e516c" - ] - ] - }, - { - "id": "e59a1a81.112a08", - "type": "returnFailure", - "name": "return failure", - "xml": "\n\n\n\n", - "comments": "", - "x": 722, - "y": 356, - "z": "6d4f912d.f07bc", - "wires": [] - }, - { - "id": "6549631f.8e516c", - "type": "returnFailure", - "name": "return failure", - "xml": "\n\n\n\n", - "comments": "", - "x": 1042, - "y": 444, - "z": "6d4f912d.f07bc", - "wires": [] - } -] \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-SLSFILE.xml b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-SLSFILE.xml deleted file mode 100644 index 2c5e600fc..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-SLSFILE.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-exec-SLSFile-applyTo.json b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-exec-SLSFile-applyTo.json deleted file mode 100644 index 264950d5e..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-exec-SLSFile-applyTo.json +++ /dev/null @@ -1,372 +0,0 @@ -[ - { - "id": "9a6bf94f.d969f8", - "type": "method", - "name": "saltstack-adapter-1.0", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 498, - "y": 240, - "z": "723548c7.652d78", - "wires": [ - [ - "138ad7ed.403248" - ] - ] - }, - { - "id": "4bb87049.3f546", - "type": "service-logic", - "name": "APPC 2.0.1", - "module": "APPC", - "version": "2.0.1", - "comments": "", - "xml": "", - "outputs": 1, - "x": 289, - "y": 318, - "z": "723548c7.652d78", - "wires": [ - [ - "9a6bf94f.d969f8" - ] - ] - }, - { - "id": "6c593992.106038", - "type": "returnFailure", - "name": "return failure", - "xml": "\n\n\n\n", - "comments": "", - "x": 1202, - "y": 280, - "z": "723548c7.652d78", - "wires": [] - }, - { - "id": "138ad7ed.403248", - "type": "execute", - "name": "execute", - "xml": "\n \n \n \n \n \n \n \n \n", - "comments": "", - "outputs": 1, - "x": 706, - "y": 246, - "z": "723548c7.652d78", - "wires": [ - [ - "167273ed.f0577c", - "954a34ea.701368" - ] - ] - }, - { - "id": "d5841e65.537ba", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 494, - "y": 400, - "z": "723548c7.652d78", - "wires": [ - [ - "ede42371.2f52b", - "d306d7a0.c830e8" - ] - ] - }, - { - "id": "ede42371.2f52b", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 680, - "y": 458, - "z": "723548c7.652d78", - "wires": [ - [ - "6c593992.106038" - ] - ] - }, - { - "id": "167273ed.f0577c", - "type": "failure", - "name": "failure", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 957, - "y": 239, - "z": "723548c7.652d78", - "wires": [ - [ - "6c593992.106038" - ] - ] - }, - { - "id": "954a34ea.701368", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 304, - "y": 407, - "z": "723548c7.652d78", - "wires": [ - [ - "d5841e65.537ba" - ] - ] - }, - { - "id": "d306d7a0.c830e8", - "type": "success", - "name": "success", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 683, - "y": 400, - "z": "723548c7.652d78", - "wires": [ - [ - "5b12ba31.94b3b4" - ] - ] - }, - { - "id": "9ef7fcc3.69279", - "type": "returnSuccess", - "name": "return success", - "xml": "\n\n\n\n", - "comments": "", - "x": 1101, - "y": 559, - "z": "723548c7.652d78", - "wires": [] - }, - { - "id": "7803eeaf.1e31d", - "type": "dgstart", - "name": "DGSTART", - "outputs": 1, - "x": 267, - "y": 218, - "z": "723548c7.652d78", - "wires": [ - [ - "4bb87049.3f546" - ] - ] - }, - { - "id": "9c6f1e7c.2a3d9", - "type": "comment", - "name": "SaltStack Adaptor DG", - "info": "", - "comments": "", - "x": 645, - "y": 105, - "z": "723548c7.652d78", - "wires": [] - }, - { - "id": "93ea02a5.4e792", - "type": "comment", - "name": "request-method = reqExecSLS, req-action = \"execute SLS FILE\"", - "info": "Here we basically test if minion1 is active by pinging to it, then respective sls file is executed on to it. \n", - "comments": "", - "x": 656, - "y": 190, - "z": "723548c7.652d78", - "wires": [] - }, - { - "id": "243edbf.f35fc24", - "type": "comment", - "name": "Assumptions for this DG (example-server)", - "info": "Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controllers minion1 and minion2. ", - "comments": "", - "x": 648, - "y": 146, - "z": "723548c7.652d78", - "wires": [] - }, - { - "id": "5b12ba31.94b3b4", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 847, - "y": 400, - "z": "723548c7.652d78", - "wires": [ - [ - "9bf0915.96f217", - "f6e533d.95d99d" - ] - ] - }, - { - "id": "9bf0915.96f217", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 1013, - "y": 454, - "z": "723548c7.652d78", - "wires": [ - [ - "6c593992.106038" - ] - ] - }, - { - "id": "f6e533d.95d99d", - "type": "other", - "name": "outcome", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 1016, - "y": 396, - "z": "723548c7.652d78", - "wires": [ - [ - "eb57ba41.1d7328" - ] - ] - }, - { - "id": "eb57ba41.1d7328", - "type": "execute", - "name": "execute", - "xml": "\n \n \n \n \n \n \n \n \n", - "comments": "", - "outputs": 1, - "x": 420, - "y": 588, - "z": "723548c7.652d78", - "wires": [ - [ - "892a8f1d.7d77f", - "74be8a6e.975f24" - ] - ] - }, - { - "id": "892a8f1d.7d77f", - "type": "failure", - "name": "failure", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 605, - "y": 557, - "z": "723548c7.652d78", - "wires": [ - [ - "8c091fe.c6cbfe" - ] - ] - }, - { - "id": "74be8a6e.975f24", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 603, - "y": 629, - "z": "723548c7.652d78", - "wires": [ - [ - "3875d695.fd37ca" - ] - ] - }, - { - "id": "3875d695.fd37ca", - "type": "switchNode", - "name": "switch", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 755, - "y": 617, - "z": "723548c7.652d78", - "wires": [ - [ - "2e60af80.ea3a6", - "24ed6dd2.6624c2" - ] - ] - }, - { - "id": "24ed6dd2.6624c2", - "type": "success", - "name": "success", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 918, - "y": 563, - "z": "723548c7.652d78", - "wires": [ - [ - "9ef7fcc3.69279" - ] - ] - }, - { - "id": "2e60af80.ea3a6", - "type": "other", - "name": "other", - "xml": "\n", - "comments": "", - "outputs": 1, - "x": 915, - "y": 632, - "z": "723548c7.652d78", - "wires": [ - [ - "2e4414a7.ba6d4c" - ] - ] - }, - { - "id": "8c091fe.c6cbfe", - "type": "returnFailure", - "name": "return failure", - "xml": "\n\n\n\n", - "comments": "", - "x": 757, - "y": 554, - "z": "723548c7.652d78", - "wires": [] - }, - { - "id": "2e4414a7.ba6d4c", - "type": "returnFailure", - "name": "return failure", - "xml": "\n\n\n\n", - "comments": "", - "x": 1076, - "y": 632, - "z": "723548c7.652d78", - "wires": [] - } -] \ No newline at end of file diff --git a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-exec-SLSFile-applyTo.xml b/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-exec-SLSFile-applyTo.xml deleted file mode 100644 index 16c573add..000000000 --- a/adaptors/saltstack-adapter/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adapter-1.0-exec-SLSFile-applyTo.xml +++ /dev/null @@ -1,112 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/.pydevproject b/adaptors/saltstack-adaptor/.pydevproject new file mode 100644 index 000000000..d001f0aea --- /dev/null +++ b/adaptors/saltstack-adaptor/.pydevproject @@ -0,0 +1,5 @@ + + +Default +python interpreter + diff --git a/adaptors/saltstack-adaptor/README.md b/adaptors/saltstack-adaptor/README.md new file mode 100644 index 000000000..9fdf045e6 --- /dev/null +++ b/adaptors/saltstack-adaptor/README.md @@ -0,0 +1,137 @@ +This source repository contains the code for the CCSDK plugins. + +To compile this code: + +1. Make sure your local Maven settings file ($HOME/.m2/settings.xml) contains references to the ONAP repositories and OpenDaylight repositories. See example-settings.xml for an example. + +2. To compile, run "mvn clean install". + + +***SaltStack Adaptor:*** CCSDK SLI ADAPTORS to support SaltStack server: + +***Connection from CCSDK SLI ADAPTOR Adaptor to SaltStack server:*** + +Create an Adaptor to communicate with the SaltStack server: +1) SaltStack server doesn’t expose any REST API unlike Chef. +2) SSH based communication with the SaltStack server, one command at a time (preferred). This will mean that SaltStack server should have it’s SSH enabled. +3) Create a REST-wrap around SaltStack server like is done for Ansible server. + +***SSH based communication:*** +1) Adaptor can execute commands on the Salt Master and bring back the result and put to the context memory for DG based analysis. (https://docs.saltstack.com/en/latest/ref/modules/all/index.html#all-salt-modules). +2) This can be useful for several reasons, for instance it might be useful to know the interfaces in the minions before executing certain network config based commands. This can simple be done by running, 'salt '*' network.interfaces' on server. +3) SaltStack Server, Output module support: The json-out outputter can be used to display the return data in JSON format. So the DG can put this onto context memory for execution. https://docs.saltstack.com/en/latest/ref/output/all/index.html#all-salt-output +4) Since the command execution on server might take time, a thread can be spawn to make a single SSH command execution in a SYNC manner. The thread executes the command and brings back the result and puts to the context memory for DG’s access. +5) For some specific executions operations like configure and upgrade, each configuration execution on the server will be handled by 2 or more SSH command execution. (1 for sending configuration and another for verifying the result). This will give the DGs and Saltstack adaptor with more control on the SaltStack server. + +***SaltState (SLS) file for execution on the SaltStack server:*** + The desired SLS file can be executed by one of the following three ways: +1) The SLS file for VNF configuration can be assumed to be already on the server, similar to Ansible. In this case, no addition requirements are necessary. We would already know the name of SLS file to execute so the configuration is performed on the VNF. +2) SLS file creation using DG: Create a DG to parse the configuration and create an SLS file using adaptors such as FileRecorder. Then this SLS file can be passed to the adaptor, so the adaptor can send the configuration to server. The adaptor can also send a SLS file to the Saltstack server and then run the command to execute it. +3) Third option is for the configuration SLS file that is to be sent to the VNF after instantiation is attached at the design time. This SLS formula- SaltStack file can be picked up and stored in the DB, as part of UEB listener. This can then be sent to adaptor using DGs. + +***Requirements and benefits of the chosen SSH method:*** +1) The SaltStack server should have it’s SSH enabled. +2) Via ssh user account we should have the access to run saltstack command. +3) Such execution method will give the DGs and adaptor with more refined control on the SaltStack server. +================================================================================================================== + + +***Defining Saltstack server properties:*** Can be done with 2 different methods. +1) Saltstack server details are found in the property file named saltstack-adaptor.properties. Param has to be given with following types. + "org.onap.appc.adaptor.saltstack.clientType"; -> Supported types are (BASIC || SSH_CERT || BOTH). + "org.onap.appc.adaptor.saltstack.host"; -> Saltstack server's host name IP address. + "org.onap.appc.adaptor.saltstack.port"; -> Saltstack server's port to make SSH connection to. + "org.onap.appc.adaptor.saltstack.userName"; -> Saltstack server's SSH UserName. + "org.onap.appc.adaptor.saltstack.userPasswd"; -> Saltstack server's SSH Password. + "org.onap.appc.adaptor.saltstack.sshKey"; -> Saltstack server's SSH KEY file location. +2) All the server related details can also be passed as param to the adaptor from the Directed Graphs. Param has to be given with following types. + "HostName"; -> Saltstack server's host name IP address. + "Port"; -> Saltstack server's port to make SSH connection to. + "Password"; -> Saltstack server's SSH UserName. + "User"; -> Saltstack server's SSH Password. + "withRetry"; -> Specify 'true' if you wanna connect to server with retry. + Note: SSH_CERT based Auth is not supported in this method. + +***Using Saltstack Adaptor Commands and params to pass in: reqExecCommand API:*** + +Method to execute a single command on SaltState server and execute a SLS file located on the server. The command entered should request the output in JSON format, this can be done by appending json-out outputter as specified in https://docs.saltstack.com/en/latest/ref/output/all/salt.output.json_out.html#module-salt.output.json_out and https://docs.saltstack.com/en/2017.7/ref/cli/salt-call.html +The response from Saltstack comes in json format and it is automatically put to context for DGs access, with a certain request-ID as prefix. +If Id is not passed as part of input param, then a random Id will be generated and put to properties in "org.onap.appc.adaptor.saltstack.Id" field. All the output message from the execution will be appended with reqId. +1) Execute a single command on SaltState server : Example command will look like: +1.1) Command to test if all VNFC are running: "salt '*' test.ping --out=json --static" +1.2) To check Network interfaces on your minions: "salt '*' network.interfaces --out=json --static" +1.3) Restart Minion service after upgrade process: "salt minion1 service.restart salt-minion --out=json --static" +Note: If using --out=json, you will probably want --static as well. Without the static option, you will get a separate JSON string per minion which makes JSON output invalid as a whole. This is due to using an iterative outputter. So if you want to feed it to a JSON parser, use --static as well. + +This "reqExecCommand" method gives the Operator/Directed Graphs to execute commands in a fine-tuned manner, which also means the operator/DG-creator should know what to expect as output as a result of command execution (for both success/failure case). +By this way using DGs, the operator can check for success/failure of the executed comment. +If the output is not in JSON format, then the adaptor still tries to convert it into properties, in addition, params that will hold the command execution result for DG access are (note: this is just to check if the command was executed successfully on the server, this doesn't check the status of the command on saltstack server): +Result code at: org.onap.appc.adaptor.saltstack.result.code (On success: This will be always be 250, means command execution was success but the result of the execution is unknown and is to be checked from ctx using DGs) +Message at: org.onap.appc.adaptor.saltstack.message +Both user inputted/auto generated req Id at: org.onap.appc.adaptor.saltstack.Id +To check the status of the command configuration on saltstack server: the user should exactly know what to look for in the context +so the user can identify if the configuration execution on the saltstack server succeded or not. +here for instance, in 1.1) the user should check if $reqId. is set to true in the context memory using DGs. + +2) Execute a SLS file located on the server : Example command will look like: +Knowing the saltstack server has vim.sls file located at "/srv/salt" directory then user can execute the following commands: +1.1) Command to run the vim.sls file on saltstack server: Cmd = "salt '*' state.apply vim --out=json --static" +1.2) Command to run the nettools.sls file on saltstack server: Cmd = "cd /srv/salt/; salt '*' state.apply --out=json --static" +Important thing to note: If the reqExecCommand is used to execute sls file then along with following, + "HostName"; -> Saltstack server's host name IP address. + "Port"; -> Saltstack server's port to make SSH connection to. + "Password"; -> Saltstack server's SSH UserName. + "User"; -> Saltstack server's SSH Password. +the param should contain, + "SlsExec"; -> this variable should be set to true. + "Timeout"; -> set large timeout if your SLS file will take large time to finish executing (in Seconds). + +In this case, params that will hold the command execution result for DG access in Key: +Result code at: org.onap.appc.adaptor.saltstack.result.code (On success: This will be 200, this means the command was executed successfully and also configuration change made using the SLS file was also successful) +Message at: org.onap.appc.adaptor.saltstack.message +Both user inputted/auto generated req Id at: org.onap.appc.adaptor.saltstack.Id +The result code here will be the execution of configuration SLS file on the server. +NOTE: It would be better to use reqExecSLS, where you will only have to specify SLS file name on server to execute it. + + +***Using Saltstack Adaptor Commands and params to pass in: reqExecSLS API:*** + +Method to execute a single sls on SaltState server (Where the SLS file already located on the server). The command entered will only be the SLS file name and the output will be in JSON format automatically. +The response from Saltstack comes in json format and it is automatically put to context for DGs access, with a certain request-ID as prefix. +If request Id (Id) is not passed as part of input param, then a random Id will be generated and put to properties in "org.onap.appc.adaptor.saltstack.Id" field. All the output message from the execution will be appended with reqId. +1) Execute a single command on SaltState server : Example command will look like: + In the context set the "SlsName" to "test.sls" + In the context set the "Timeout"; -> set large timeout if your SLS file will take large time to finish executing (in Seconds). + In the context set the "NodeList" to "minion1" //to the minions or VNFCs you want to apply the SLS file to. + "NodeList" can be empty or set to "*" is the SLS has to be applied to all the minions or VNFCs. + In the context set the "FileParameters: A JSON dictionary where keys are filenames and values are contents of files. The Saltstack Server will utilize this feature to generate files with keys as filenames and values as content. This attribute can be used to generate files that a SSL file may require as part of execution (Optional). + In the context set the "EnvParameters: A JSON dictionary which should list key value pairs to be passed to the Salstack command to run SLS. These values would correspond to instance specific parameters that a playbook may need to execute an action. + +In this case, params that will hold the command execution result for DG access in Key: +Result code at: org.onap.appc.adaptor.saltstack.result.code (On success: This will be 200, this means the command was executed successfully and also configuration change made using the SLS file was also successful) +Message at: org.onap.appc.adaptor.saltstack.message +Both user inputted/auto generated req Id at: org.onap.appc.adaptor.saltstack.Id +The result code here will be the execution of configuration SLS file on the server. + +***Using Saltstack Adaptor Commands and params to pass in: reqExecSLSFile API:*** + +Method to execute a single sls on SaltState server (Where the SLS file in the adaptor). The command entered will only be the SLS file location on the APPC/ODL container and the output from server will be in JSON format automatically. +The response from Saltstack comes in json format and it is automatically put to context for DGs access, with a certain request-ID as prefix. +If request Id (Id) is not passed as part of input param, then a random Id will be generated and put to properties in "org.onap.appc.adaptor.saltstack.Id" field. All the output message from the execution will be appended with reqId. +1) Execute a single command on SaltState server : Example command will look like: + In the context set the "SlsFile" to "/path/to/test.sls" //mention the path of the SLS file in ODL container. + In the context set the "Timeout"; -> set large timeout if your SLS file will take large time to finish executing (in Seconds). + In the context set the "NodeList" to "minion1" //to the minions or VNFCs you want to apply the SLS file to. + "NodeList" can be empty or set to 'minion*' (pattern matching) or set to "*" is the SLS has to be applied to all the minions or VNFCs. + In the context set the "FileParameters: A JSON dictionary where keys are filenames and values are contents of files. The Saltstack Server will utilize this feature to generate files with keys as filenames and values as content. This attribute can be used to generate files that a SSL file may require as part of execution (Optional). + In the context set the "EnvParameters: A JSON dictionary which should list key value pairs to be passed to the Salstack command to run SLS. These values would correspond to instance specific parameters that a playbook may need to execute an action. + +In this case, params that will hold the command execution result for DG access in Key: +Result code at: org.onap.appc.adaptor.saltstack.result.code (On success: This will be 200, this means the command was executed successfully and also configuration change made using the SLS file was also successful) +Message at: org.onap.appc.adaptor.saltstack.message +Both user inputted/auto generated req Id at: org.onap.appc.adaptor.saltstack.Id +The result code here will be the execution of configuration SLS file on the server. + +Control the state system on the minion: by specifying Env Params (pillars) and Files. + +https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.state.html \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/pom.xml b/adaptors/saltstack-adaptor/pom.xml new file mode 100644 index 000000000..45ed3f00b --- /dev/null +++ b/adaptors/saltstack-adaptor/pom.xml @@ -0,0 +1,197 @@ + + + + + 4.0.0 + + + org.onap.ccsdk.parent + odlparent-lite + 2.2.0-SNAPSHOT + + + + org.onap.ccsdk.sli.adaptors + saltstack-adaptor + 1.3.0-SNAPSHOT + pom + + ccsdk-sli-adaptors :: ${project.artifactId} + Abstractions to interact with Saltstack server via REST + + + + saltstack-adaptor-provider + saltstack-adaptor-installer + + + + + + + org.onap.appc + saltstack-adaptor-features + ${project.version} + xml + features + + + + org.onap.appc + saltstack-adaptor-provider + ${project.version} + + + + junit + junit + 4.11 + test + + + + + + + + + + JCenter + JCenter Repository + http://jcenter.bintray.com + + + + + + + + + + + + + + + + maven-javadoc-plugin + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.antlr + antlr4 + ${antlr.version} + + + org.antlr + antlr4-runtime + 4.3 + + + + + + + javadoc-no-fork + test-javadoc-no-fork + + + + aggregate + + aggregate + test-aggregate + + + + + + org.apache.maven.plugins + maven-jxr-plugin + 2.3 + + + aggregate + + aggregate + test-aggregate + + + + + + + maven-surefire-plugin + + + + org.apache.maven.plugins + maven-changelog-plugin + 2.3 + + + dual-report + + range + 30 + + + changelog + file-activity + + + + + + + org.codehaus.mojo + taglist-maven-plugin + 2.4 + + + + + diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-installer/pom.xml b/adaptors/saltstack-adaptor/saltstack-adaptor-installer/pom.xml new file mode 100644 index 000000000..ff85797aa --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-installer/pom.xml @@ -0,0 +1,164 @@ + + + + + 4.0.0 + + + org.onap.ccsdk.parent + odlparent-lite + 2.2.0-SNAPSHOT + + + + org.onap.ccsdk.sli.adaptors + saltstack-adaptor-installer + 1.3.0-SNAPSHOT + pom + + ccsdk-sli-adaptors :: ${project.artifactId} + + + ccsdk-saltstack-adaptor + ${application.name} + + mvn:org.onap.ccsdk.sli.adaptors/${features.boot}/${project.version}/xml/features + + false + + + + + + org.onap.ccsdk.sli.adaptors + saltstack-adaptor-provider + ${project.version} + + + + + + + + maven-assembly-plugin + + + maven-repo-zip + + single + + package + + true + true + + stage/${application.name}-${project.version} + + + + src/assembly/assemble_mvnrepo_zip.xml + + + true + + + + installer-zip + + single + + package + + false + true + ${application.name}-${project.version} + + + + src/assembly/assemble_installer_zip.xml + + + false + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + + copy-dependencies + + prepare-package + + false + + ${project.build.directory}/assembly/system + + false + true + true + true + false + false + org.onap.ccsdk.sli.adaptors + provided + + + + + + maven-resources-plugin + + + copy-version + + copy-resources + + + validate + + ${basedir}/target/stage + + + + src/main/resources/scripts + + + install-feature.sh + + true + + + + + + + + + diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-installer/src/assembly/assemble_installer_zip.xml b/adaptors/saltstack-adaptor/saltstack-adaptor-installer/src/assembly/assemble_installer_zip.xml new file mode 100644 index 000000000..c020f0d4c --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-installer/src/assembly/assemble_installer_zip.xml @@ -0,0 +1,61 @@ + + + + + + adaptor + + zip + + + + false + + + + target/stage/ + ${application.name} + 755 + + *.sh + + + + target/stage/ + ${application.name} + 644 + + *.sh + + + + + + diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-installer/src/assembly/assemble_mvnrepo_zip.xml b/adaptors/saltstack-adaptor/saltstack-adaptor-installer/src/assembly/assemble_mvnrepo_zip.xml new file mode 100644 index 000000000..1b1bf0b6b --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-installer/src/assembly/assemble_mvnrepo_zip.xml @@ -0,0 +1,50 @@ + + + + + + repo + + zip + + + + false + + + + target/assembly/ + . + + + + + + diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-installer/src/main/resources/scripts/install-feature.sh b/adaptors/saltstack-adaptor/saltstack-adaptor-installer/src/main/resources/scripts/install-feature.sh new file mode 100644 index 000000000..38782cabb --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-installer/src/main/resources/scripts/install-feature.sh @@ -0,0 +1,42 @@ +### +# ============LICENSE_START======================================================= +# ONAP : APPC +# ================================================================================ +# Copyright (C) 2018 Samsung Electronics. All rights reserved. +# ================================================================================ +# +# ============================================================================= +# 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. +# +# +# ============LICENSE_END========================================================= +### + +#!/bin/bash + +ODL_HOME=${ODL_HOME:-/opt/opendaylight/current} +ODL_KARAF_CLIENT=${ODL_KARAF_CLIENT:-${ODL_HOME}/bin/client} +INSTALLERDIR=$(dirname $0) + +REPOZIP=${INSTALLERDIR}/${features.boot}-${project.version}.zip + +if [ -f ${REPOZIP} ] +then + unzip -n -d ${ODL_HOME} ${REPOZIP} +else + echo "ERROR : repo zip ($REPOZIP) not found" + exit 1 +fi + +${ODL_KARAF_CLIENT} feature:repo-add ${features.repositories} +${ODL_KARAF_CLIENT} feature:install ${features.boot} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/.gitignore b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/.gitignore new file mode 100644 index 000000000..4e1ad823a --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/.gitignore @@ -0,0 +1,25 @@ +# ============LICENSE_START========================================== +# ONAP : CCSDK +# =================================================================== +# Copyright (C) 2017-2018 Samsung Electronics. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the License); +# you may not use this software 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. +# +# +# ============LICENSE_END============================================ +/bin/ +/target/ +/target-ide/ +/.settings/ diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/pom.xml b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/pom.xml new file mode 100644 index 000000000..3f35fb4f5 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/pom.xml @@ -0,0 +1,115 @@ + + + + + 4.0.0 + + + org.onap.ccsdk.parent + binding-parent + 2.2.0-SNAPSHOT + + + + org.onap.ccsdk.sli.adaptors + saltstack-adaptor-provider + 1.3.0-SNAPSHOT + bundle + + ccsdk-sli-adaptors :: ${project.artifactId} + + + + + org.onap.ccsdk.sli.core + sli-core-artifacts + ${project.version} + pom + import + + + + + + com.att.eelf + eelf-core + + + commons-codec + commons-codec + + + commons-logging + commons-logging + 1.2 + + + org.osgi + org.osgi.core + provided + + + org.slf4j + slf4j-api + + + org.slf4j + jcl-over-slf4j + + + + + + + + org.apache.sshd + sshd-core + 1.7.0 + + + + + + org.apache.commons + commons-io + + + + org.codehaus.jettison + jettison + + + + junit + junit + test + + + + org.onap.ccsdk.sli.core + sli-common + + + + org.onap.ccsdk.sli.core + sli-provider + + + + org.json + json + + + + diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdaptor.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdaptor.java new file mode 100644 index 000000000..dda333852 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdaptor.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. All rights reserved. + * ================================================================================ + * + * ============================================================================= + * 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. + * + * + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.saltstack; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +import java.util.Map; + +/** + * This interface defines the operations that the Saltstack adaptor exposes. + */ +public interface SaltstackAdaptor extends SvcLogicJavaPlugin { + /** + * Returns the symbolic name of the adaptor + * + * @return The adaptor name + */ + String getAdaptorName(); + + /* Method to post a single command request for execution on SaltState server + * The response from Saltstack comes in json format and it is automatically put + * to context for DGs access, with a certain prefix*/ + void reqExecCommand(Map params, SvcLogicContext ctx) throws SvcLogicException; + + /* Method for execution of saltstack SLS command on SaltState server + * The response from Saltstack comes in json format and it is automatically put + * to context for DGs access, with a certain prefix*/ + void reqExecSLS(Map params, SvcLogicContext ctx) throws SvcLogicException; + + /* When SLS file is created/available then this Method can be used to post + * the file to saltstack server and execute the SLS file on SaltState server + * The response from Saltstack comes in json format and it is automatically put + * to context for DGs access, with a certain prefix*/ + void reqExecSLSFile(Map params, SvcLogicContext ctx) throws SvcLogicException; +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdaptorPropertiesProvider.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdaptorPropertiesProvider.java new file mode 100644 index 000000000..fdfc79e66 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/SaltstackAdaptorPropertiesProvider.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. All rights reserved. + * ================================================================================ + * + * ============================================================================= + * 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. + * + * + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.saltstack; + +import java.util.Properties; + +public interface SaltstackAdaptorPropertiesProvider { + + public Properties getProperties(); +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/ConnectionBuilder.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/ConnectionBuilder.java new file mode 100644 index 000000000..48469fdd5 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/ConnectionBuilder.java @@ -0,0 +1,172 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. All rights reserved. + * ================================================================================ + * + * ============================================================================= + * 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. + * + * + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.saltstack.impl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.sli.adaptors.saltstack.model.SshException; +import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResult; +import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResultCodes; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +/** + * Returns a custom SSH client + * - based on options + * - can create one with ssl using an X509 certificate that does NOT have a known CA + * - create one which trusts ALL SSL certificates + * - return default sshclient (which only trusts known CAs from default cacerts file for process) this is the default + * option + **/ +public class ConnectionBuilder { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(ConnectionBuilder.class); + SshConnection sshConnection; + + /** + * Constructor that initializes an ssh client based on username and password + **/ + public ConnectionBuilder(String host, String port, String userName, String userPasswd) { + sshConnection = new SshConnection(host, Integer.parseInt(port), userName, userPasswd); + } + + /** + * Constructor that initializes an ssh client based on ssh certificate + * This is still not supported in 1.3.0 version + **/ + public ConnectionBuilder(String host, String port, String certFile) { + sshConnection = new SshConnection(host, Integer.parseInt(port), certFile); + } + + + /** + * 1. Connect to SSH server. + * 2. Exec remote command over SSH. Return command execution status. + * Command output is written to out or err stream. + * + * @param cmd Commands to execute + * @return command execution status + */ + public SaltstackResult connectNExecute(String cmd, long execTimeout) throws IOException { + return connectNExecute(cmd, false, execTimeout); + } + + /** + * 1. Connect to SSH server with retry enabled. + * 2. Exec remote command over SSH. Return command execution status. + * Command output is written to out or err stream. + * + * @param cmd Commands to execute + * @param withRetry make a SSH connection with default retry. + * @return command execution status + */ + public SaltstackResult connectNExecute(String cmd, boolean withRetry, long execTimeout) + throws IOException { + + SaltstackResult result = new SaltstackResult(); + ByteArrayOutputStream out = null; + ByteArrayOutputStream errs = null; + if (execTimeout >= 0) { + sshConnection.setExecTimeout(execTimeout); + } + + try { + if (withRetry) { + sshConnection.connectWithRetry(); + } else { + sshConnection.connect(); + } + out = new ByteArrayOutputStream(); + errs = new ByteArrayOutputStream(); + int resultCode = sshConnection.execCommand(cmd, out, errs); + sshConnection.disconnect(); + if (resultCode != 0) { + return sortExitStatus(resultCode, errs.toString(), cmd); + } + result.setStatusCode(SaltstackResultCodes.SUCCESS.getValue()); + result.setStatusMessage("Success"); + result.setOutputMessage(out); + } catch (SshException io) { + if (io.toString().equalsIgnoreCase("Authentication failed")) { + logger.error(io.toString()); + result.setStatusCode(SaltstackResultCodes.USER_UNAUTHORIZED.getValue()); + result.setStatusMessage(io.toString()); + return result; + } + logger.error("Caught Exception", io); + result.setStatusCode(SaltstackResultCodes.SSH_EXCEPTION.getValue()); + result.setStatusMessage(io.getMessage()); + } catch (Exception io) { + logger.error("Caught Exception", io); + result.setStatusCode(SaltstackResultCodes.SSH_EXCEPTION.getValue()); + result.setStatusMessage(io.getMessage()); + } finally { + if (out != null) { + out.close(); + } + if (errs != null) { + errs.close(); + } + } + return result; + } + + /** + * Print Reasonable error messages based on SSH Exit status code + * */ + public SaltstackResult sortExitStatus(int exitStatus, String errMess, String cmd) { + SaltstackResult result = new SaltstackResult(); + if (exitStatus == 255 || exitStatus == 1) { + String errMessage = "Error executing command [" + cmd + "] over SSH [" + sshConnection.toString() + + "]. Exit Code " + exitStatus + " and Error message : " + + "Malformed configuration. " + errMess; + logger.error(errMessage); + result.setStatusCode(SaltstackResultCodes.INVALID_COMMAND.getValue()); + result.setStatusMessage(errMessage); + } else if (exitStatus == 5 || exitStatus == 65) { + String errMessage = "Error executing command [" + cmd + "] over SSH [" + sshConnection.toString() + + "]. Exit Code " + exitStatus + " and Error message : " + + "Host not allowed to connect. " + errMess; + logger.error(errMessage); + result.setStatusCode(SaltstackResultCodes.USER_UNAUTHORIZED.getValue()); + result.setStatusMessage(errMessage); + } else if (exitStatus == 67 || exitStatus == 73) { + String errMessage = "Error executing command [" + cmd + "] over SSH [" + sshConnection.toString() + + "]. Exit Code " + exitStatus + " and Error message : " + + "Key exchange failed. " + errMess; + logger.error(errMessage); + result.setStatusCode(SaltstackResultCodes.CERTIFICATE_ERROR.getValue()); + result.setStatusMessage(errMessage); + } else { + String errMessage = "Error executing command [" + cmd + "] over SSH [" + sshConnection.toString() + + "]. Exit Code " + exitStatus + " and Error message : " + errMess; + logger.error(errMessage); + result.setStatusCode(SaltstackResultCodes.UNKNOWN_EXCEPTION.getValue()); + result.setStatusMessage(errMessage); + } + return result; + } +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdaptorImpl.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdaptorImpl.java new file mode 100644 index 000000000..05b1688b6 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdaptorImpl.java @@ -0,0 +1,446 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. All rights reserved. + * ================================================================================ + * + * ============================================================================= + * 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. + * + * + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.saltstack.impl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.json.JSONException; +import org.json.JSONObject; +import org.onap.ccsdk.sli.adaptors.saltstack.SaltstackAdaptor; +import org.onap.ccsdk.sli.adaptors.saltstack.SaltstackAdaptorPropertiesProvider; +import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackMessageParser; +import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResult; +import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResultCodes; +import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackServerEmulator; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.Properties; + +/** + * This class implements the {@link SaltstackAdaptor} interface. This interface defines the behaviors + * that our service provides. + */ +public class SaltstackAdaptorImpl implements SaltstackAdaptor { + + /** + * The constant for the status code for a failed outcome + */ + @SuppressWarnings("nls") + public static final String OUTCOME_FAILURE = "failure"; + /** + * The constant for the status code for a successful outcome + */ + @SuppressWarnings("nls") + public static final String OUTCOME_SUCCESS = "success"; + public static final String CONNECTION_RETRY = "withRetry"; + private static final String APPC_EXCEPTION_CAUGHT = "APPCException caught"; + /** + * Adaptor Name + */ + private static final String Adaptor_NAME = "Saltstack Adaptor"; + private static final String RESULT_CODE_ATTRIBUTE_NAME = "org.onap.appc.adaptor.saltstack.result.code"; + private static final String MESSAGE_ATTRIBUTE_NAME = "org.onap.appc.adaptor.saltstack.message"; + private static final String ID_ATTRIBUTE_NAME = "org.onap.appc.adaptor.saltstack.Id"; + private static final String CLIENT_TYPE_PROPERTY_NAME = "org.onap.appc.adaptor.saltstack.clientType"; + private static final String SS_SERVER_HOSTNAME = "org.onap.appc.adaptor.saltstack.host"; + private static final String SS_SERVER_PORT = "org.onap.appc.adaptor.saltstack.port"; + private static final String SS_SERVER_USERNAME = "org.onap.appc.adaptor.saltstack.userName"; + private static final String SS_SERVER_PASSWD = "org.onap.appc.adaptor.saltstack.userPasswd"; + private static final String SS_SERVER_SSH_KEY = "org.onap.appc.adaptor.saltstack.sshKey"; + + private static final String COMMAND_IN_JSON_OUT = " --out=json --static "; + private static final String COMMAND_CHANGE_DEFAULT_DIR = " cd /srv/salt/ ;"; + + /** + * The logger to be used + */ + private static final EELFLogger logger = EELFManager.getInstance().getLogger(SaltstackAdaptorImpl.class); + /** + * Connection object + **/ + private ConnectionBuilder sshClient; + + /** + * Saltstack API Message Handlers + **/ + private SaltstackMessageParser messageProcessor; + + /** + * indicator whether in test mode + **/ + private boolean testMode = false; + + /** + * server emulator object to be used if in test mode + **/ + private SaltstackServerEmulator testServer; + + /** + * This default constructor is used as a work around because the activator wasn't getting called + */ + public SaltstackAdaptorImpl() throws SvcLogicException { + initialize(new SaltstackAdaptorPropertiesProviderImpl()); + } + + public SaltstackAdaptorImpl(SaltstackAdaptorPropertiesProvider propProvider) throws SvcLogicException { + initialize(propProvider); + } + + /** + * Used for jUnit test and testing interface + */ + public SaltstackAdaptorImpl(boolean mode) { + testMode = mode; + testServer = new SaltstackServerEmulator(); + messageProcessor = new SaltstackMessageParser(); + } + + /** + * Returns the symbolic name of the adaptor + * + * @return The adaptor name + * @see SaltstackAdaptor#getAdaptorName() + */ + @Override + public String getAdaptorName() { + return Adaptor_NAME; + } + + /** + * Method posts info to Context memory in case of an error and throws a + * SvcLogicException causing SLI to register this as a failure + */ + @SuppressWarnings("static-method") + private void doFailure(SvcLogicContext svcLogic, int code, String message) throws SvcLogicException { + logger.error(APPC_EXCEPTION_CAUGHT, message); + svcLogic.setStatus(OUTCOME_FAILURE); + svcLogic.setAttribute(RESULT_CODE_ATTRIBUTE_NAME, Integer.toString(code)); + svcLogic.setAttribute(MESSAGE_ATTRIBUTE_NAME, message); + throw new SvcLogicException("Saltstack Adaptor Error = " + message); + } + + /** + * initialize the Saltstack adaptor based on default and over-ride configuration data + */ + private void initialize(SaltstackAdaptorPropertiesProvider propProvider) throws SvcLogicException { + + + Properties props = propProvider.getProperties(); + + // Create the message processor instance + messageProcessor = new SaltstackMessageParser(); + + // Create the ssh client instance + // type of client is extracted from the property file parameter + // org.onap.appc.adaptor.saltstack.clientType + // It can be : + // 1. BASIC. SSH Connection using username and password + // 2. SSH_CERT (trust only those whose certificates have been stored in the SSH KEY file) + // 3. DEFAULT SSH Connection without any authentication + + try { + String clientType = props.getProperty(CLIENT_TYPE_PROPERTY_NAME); + logger.info("Saltstack ssh client type set to " + clientType); + + if ("BASIC".equalsIgnoreCase(clientType)) { + logger.info("Creating ssh client connection"); + // set path to keystore file + String sshHost = props.getProperty(SS_SERVER_HOSTNAME); + String sshPort = reqServerPort(props); + String sshUserName = props.getProperty(SS_SERVER_USERNAME); + String sshPassword = props.getProperty(SS_SERVER_PASSWD); + sshClient = new ConnectionBuilder(sshHost, sshPort, sshUserName, sshPassword); + } else if ("SSH_CERT".equalsIgnoreCase(clientType)) { + // set path to keystore file + String sshKey = props.getProperty(SS_SERVER_SSH_KEY); + String sshHost = props.getProperty(SS_SERVER_HOSTNAME); + String sshPort = reqServerPort(props); + logger.info("Creating ssh client with ssh KEY from " + sshKey); + sshClient = new ConnectionBuilder(sshHost, sshPort, sshKey); + } else { + logger.info("No saltstack-adaptor.properties defined so reading from DG props"); + sshClient = null; + } + } catch (NumberFormatException e) { + logger.error("Error Initializing Saltstack Adaptor due to Unknown Exception", e); + throw new SvcLogicException("Saltstack Adaptor Property file parsing Error = port in property file has to be an integer."); + } catch (Exception e) { + logger.error("Error Initializing Saltstack Adaptor due to Exception", e); + throw new SvcLogicException("Saltstack Adaptor Property file parsing Error = " + e.getMessage()); + } + logger.info("Initialized Saltstack Adaptor"); + } + + private String reqServerPort(Properties props) { + // use default port if null + if (props.getProperty(SS_SERVER_PORT) == null) { + return "22"; + } + return props.getProperty(SS_SERVER_PORT); + } + + private void setSSHClient(Map params) throws SvcLogicException { + if (sshClient == null) { + logger.info("saltstack-adaptor.properties not defined so reading saltstack host and " + + "auth details from DG's parameters"); + String sshHost = messageProcessor.reqHostNameResult(params); + String sshPort = messageProcessor.reqPortResult(params); + String sshUserName = messageProcessor.reqUserNameResult(params); + String sshPassword = messageProcessor.reqPasswordResult(params); + logger.info("Creating ssh client with BASIC Auth"); + if (!testMode) { + sshClient = new ConnectionBuilder(sshHost, sshPort, sshUserName, sshPassword); + } + } + } + + private String parseEnvParam(JSONObject envParams) { + StringBuilder envParamBuilder = new StringBuilder(); + if (envParams != null) { + for (Object key : envParams.keySet()) { + if (envParamBuilder.length() > 0) { + envParamBuilder.append(", "); + } + envParamBuilder.append(key + "=" + envParams.get((String) key)); + logger.info("EnvParameters : " + envParamBuilder); + } + } + return envParamBuilder.toString(); + } + + private String parseFileParam(JSONObject fileParams) { + StringBuilder fileParamBuilder = new StringBuilder(); + if (fileParams != null) { + for (Object key : fileParams.keySet()) { + fileParamBuilder.append("echo -e \"" + fileParams.get((String) key) + "\" > /srv/salt/" + key).append("; "); + logger.info("FileParameters : " + fileParamBuilder); + } + } + return fileParamBuilder.toString(); + } + + private String putToCommands(SvcLogicContext ctx, String slsFileName, + String applyTo, JSONObject envParams, JSONObject fileParams) throws SvcLogicException { + + StringBuilder constructedCommand = new StringBuilder(); + try { + File file = new File(slsFileName); + String slsFile = file.getName(); + if (!slsFile.substring(slsFile.lastIndexOf("."), + slsFile.length()).equalsIgnoreCase(".sls")) { + doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), "Input file " + + "is not of type .sls"); + } + try(InputStream in = new FileInputStream(file)){ + byte[] data = new byte[(int) file.length()]; + in.read(data); + String str = new String(data, "UTF-8"); + String slsWithoutExtn = stripExtension(slsFile); + constructedCommand.append(parseFileParam(fileParams)).append("echo -e \"").append(str).append("\" > /srv/salt/"). + append(slsFile).append("; ").append(COMMAND_CHANGE_DEFAULT_DIR).append(" salt '"). + append(applyTo).append("' state.apply ").append(slsWithoutExtn).append(" ").append(parseEnvParam(envParams)).append(COMMAND_IN_JSON_OUT); + } + logger.info("Command to be executed on server : " + constructedCommand.toString()); + + } catch (FileNotFoundException e) { + doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), "Input SLS file " + + "not found in path : " + slsFileName + ". " + e.getMessage()); + } catch (IOException e) { + doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), "Input SLS file " + + "error in path : " + slsFileName + ". " + e.getMessage()); + } catch (StringIndexOutOfBoundsException e) { + doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), "Input file " + + "is not of type .sls"); + } + return constructedCommand.toString(); + } + + private String stripExtension(String str) { + if (str == null) { + return null; + } + int pos = str.lastIndexOf("."); + if (pos == -1) { + return str; + } + return str.substring(0, pos); + } + + private String putToCommands(String slsName, String applyTo, JSONObject envParams, JSONObject fileParams) { + + StringBuilder constructedCommand = new StringBuilder(); + + constructedCommand.append(parseFileParam(fileParams)).append(COMMAND_CHANGE_DEFAULT_DIR).append(" salt '").append(applyTo) + .append("' state.apply ").append(slsName).append(" ").append(parseEnvParam(envParams)).append(COMMAND_IN_JSON_OUT); + + logger.info("Command to be executed on server : " + constructedCommand.toString()); + return constructedCommand.toString(); + } + + private void checkResponseStatus(SaltstackResult testResult, SvcLogicContext ctx, String reqID, boolean slsExec) + throws SvcLogicException { + + // Check status of test request returned by Agent + if (testResult.getStatusCode() != SaltstackResultCodes.FINAL_SUCCESS.getValue()) { + ctx.setAttribute(ID_ATTRIBUTE_NAME, reqID); + doFailure(ctx, testResult.getStatusCode(), "Request for execution of command failed. Reason = " + testResult.getStatusMessage()); + } else { + logger.info(String.format("Execution of request : successful.")); + ctx.setAttribute(RESULT_CODE_ATTRIBUTE_NAME, Integer.toString(testResult.getStatusCode())); + ctx.setAttribute(MESSAGE_ATTRIBUTE_NAME, OUTCOME_SUCCESS); + ctx.setAttribute(ID_ATTRIBUTE_NAME, reqID); + } + } + + // Public Method to post single command request to execute saltState. Posts the following back + // to Svc context memory + // org.onap.appc.adaptor.saltstack.req.code : 100 if successful + // org.onap.appc.adaptor.saltstack.req.messge : any message + // org.onap.appc.adaptor.saltstack.req.Id : a unique uuid to reference the request + @Override + public void reqExecCommand(Map params, SvcLogicContext ctx) throws SvcLogicException { + String reqID; + boolean slsExec; + SaltstackResult testResult; + setSSHClient(params); + try { + reqID = messageProcessor.reqId(params); + String commandToExecute = messageProcessor.reqCmd(params); + slsExec = messageProcessor.reqIsSLSExec(params); + long execTimeout = messageProcessor.reqExecTimeout(params); + testResult = execCommand(ctx, params, commandToExecute, execTimeout); + testResult = messageProcessor.parseResponse(ctx, reqID, testResult, slsExec); + checkResponseStatus(testResult, ctx, reqID, slsExec); + } catch (IOException e) { + doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), + "IOException in file stream : " + e.getMessage()); + } + } + + /** + * Public Method to post SLS command request to execute saltState on server. Posts the following back + * to Svc context memory + *

+ * org.onap.appc.adaptor.saltstack.req.code : 200 if successful + * org.onap.appc.adaptor.saltstack.req.messge : any message + * org.onap.appc.adaptor.saltstack.req.Id : a unique uuid to reference the request + */ + @Override + public void reqExecSLS(Map params, SvcLogicContext ctx) throws SvcLogicException { + String reqID; + SaltstackResult testResult; + setSSHClient(params); + try { + reqID = messageProcessor.reqId(params); + String slsName = messageProcessor.reqSlsName(params); + String applyTo = messageProcessor.reqApplyToDevices(params); + long execTimeout = messageProcessor.reqExecTimeout(params); + JSONObject envParams = messageProcessor.reqEnvParameters(params); + JSONObject fileParams = messageProcessor.reqFileParameters(params); + + String commandToExecute = putToCommands(slsName, applyTo, envParams, fileParams); + testResult = execCommand(ctx, params, commandToExecute, execTimeout); + testResult = messageProcessor.parseResponse(ctx, reqID, testResult, true); + checkResponseStatus(testResult, ctx, reqID, true); + } catch (IOException e) { + doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), + "IOException in file stream : " + e.getMessage()); + } catch (JSONException e) { + doFailure(ctx, SaltstackResultCodes.INVALID_COMMAND.getValue(), e.getMessage()); + } + } + + /** + * Public Method to post SLS file request to execute saltState. Posts the following back + * to Svc context memory + *

+ * org.onap.appc.adaptor.saltstack.req.code : 100 if successful + * org.onap.appc.adaptor.saltstack.req.messge : any message + * org.onap.appc.adaptor.saltstack.req.Id : a unique uuid to reference the request + */ + @Override + public void reqExecSLSFile(Map params, SvcLogicContext ctx) throws SvcLogicException { + String reqID; + SaltstackResult testResult; + setSSHClient(params); + try { + reqID = messageProcessor.reqId(params); + String slsFile = messageProcessor.reqSlsFile(params); + String applyTo = messageProcessor.reqApplyToDevices(params); + long execTimeout = messageProcessor.reqExecTimeout(params); + JSONObject envParams = messageProcessor.reqEnvParameters(params); + JSONObject fileParams = messageProcessor.reqFileParameters(params); + + String commandToExecute = putToCommands(ctx, slsFile, applyTo, envParams, fileParams); + testResult = execCommand(ctx, params, commandToExecute, execTimeout); + testResult = messageProcessor.parseResponse(ctx, reqID, testResult, true); + checkResponseStatus(testResult, ctx, reqID, true); + } catch (IOException e) { + doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), + "IOException in file stream : " + e.getMessage()); + } + } + + public SaltstackResult execCommand(SvcLogicContext ctx, Map params, String commandToExecute, + long execTimeout) + throws SvcLogicException { + + //convert execTimeout to Milliseconds + execTimeout = execTimeout * 1000; + SaltstackResult testResult = new SaltstackResult(); + try { + if (params.get(CONNECTION_RETRY) == null) { + if (!testMode) { + testResult = sshClient.connectNExecute(commandToExecute, execTimeout); + } else { + testResult = testServer.mockReqExec(params); + } + } else if (params.get(CONNECTION_RETRY).equalsIgnoreCase("true")) { + if (!testMode) { + testResult = sshClient.connectNExecute(commandToExecute, true, execTimeout); + } else { + testResult = testServer.mockReqExec(params); + } + } else { + if (!testMode) { + testResult = sshClient.connectNExecute(commandToExecute, execTimeout); + } else { + testResult = testServer.mockReqExec(params); + } + } + } catch (IOException e) { + doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), + "IOException in file stream : " + e.getMessage()); + } + return testResult; + } +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdaptorPropertiesProviderImpl.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdaptorPropertiesProviderImpl.java new file mode 100644 index 000000000..c5e4044fb --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdaptorPropertiesProviderImpl.java @@ -0,0 +1,192 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. All rights reserved. + * ================================================================================ + * + * ============================================================================= + * 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. + * + * + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.saltstack.impl; + +import org.onap.ccsdk.sli.adaptors.saltstack.SaltstackAdaptorPropertiesProvider; +import org.onap.ccsdk.sli.core.sli.ConfigurationException; +import org.onap.ccsdk.sli.core.utils.JREFileResolver; +import org.onap.ccsdk.sli.core.utils.KarafRootFileResolver; +import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver; +import org.onap.ccsdk.sli.core.utils.common.CoreDefaultFileResolver; +import org.onap.ccsdk.sli.core.utils.common.SdncConfigEnvVarFileResolver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Optional; +import java.util.Properties; +import java.util.Vector; + +/** + * Responsible for determining the properties file to use and instantiating the + * SqlResource Service. The priority for properties file + * resolution is as follows: + *

+ *

    + *
  1. A directory identified by the system environment variable + * SDNC_CONFIG_DIR
  2. + *
  3. The default directory DEFAULT_DBLIB_PROP_DIR
  4. + *
  5. A directory identified by the JRE argument + * sql-resource.properties
  6. + *
  7. A sql-resource.properties file located in the karaf root + * directory
  8. + *
+ */ +public class SaltstackAdaptorPropertiesProviderImpl implements SaltstackAdaptorPropertiesProvider { + + private static final Logger LOG = LoggerFactory.getLogger(SaltstackAdaptorPropertiesProviderImpl.class); + + /** + * The name of the properties file for database configuration + */ + private static final String SALTSTACKAdaptor_PROP_FILE_NAME = "saltstack-adaptor.properties"; + + /** + * A prioritized list of strategies for resolving sql-resource properties files. + */ + private Vector saltstackAdaptorPropertiesFileResolvers = new Vector<>(); + + /** + * The configuration properties for the db connection. + */ + private Properties properties; + + /** + * Set up the prioritized list of strategies for resolving dblib properties + * files. + */ + public SaltstackAdaptorPropertiesProviderImpl() { + saltstackAdaptorPropertiesFileResolvers + .add(new SdncConfigEnvVarFileResolver("Using property file (1) from environment variable")); + saltstackAdaptorPropertiesFileResolvers.add(new CoreDefaultFileResolver("Using property file (2) from default directory")); + + saltstackAdaptorPropertiesFileResolvers.add( + new JREFileResolver("Using property file (3) from JRE argument", SaltstackAdaptorPropertiesProviderImpl.class)); + saltstackAdaptorPropertiesFileResolvers.add(new KarafRootFileResolver("Using property file (4) from karaf root", this)); + + // determines properties file as according to the priority described in the + // class header comment + final File propertiesFile = determinePropertiesFile(this); + if (propertiesFile != null) { + try (FileInputStream fileInputStream = new FileInputStream(propertiesFile)) { + properties = new Properties(); + properties.load(fileInputStream); + } catch (final IOException e) { + LOG.error("Failed to load properties for file: {}", propertiesFile.toString(), + new ConfigurationException("Failed to load properties for file: " + propertiesFile.toString(), + e)); + } + } else { + // Try to read properties as resource + + InputStream propStr = getClass().getResourceAsStream("/" + SALTSTACKAdaptor_PROP_FILE_NAME); + if (propStr != null) { + properties = new Properties(); + try { + properties.load(propStr); + propStr.close(); + } catch (IOException e) { + properties = null; + } + } + + } + + if (properties == null) { + reportFailure("Missing configuration properties resource(3)", new ConfigurationException( + "Missing configuration properties resource(3): " + SALTSTACKAdaptor_PROP_FILE_NAME)); + + LOG.info("Defaulting org.onap.appc.adaptor.saltstack.clientType to NONE"); + + properties = new Properties(); + properties.setProperty("org.onap.appc.adaptor.saltstack.clientType", "NONE"); + } + } + + /** + * Reports the method chosen for properties resolution to the + * Logger. + * + * @param message Some user friendly message + * @param fileOptional The file location of the chosen properties file + * @return the file location of the chosen properties file + */ + private static File reportSuccess(final String message, final Optional fileOptional) { + if (fileOptional.isPresent()) { + final File file = fileOptional.get(); + LOG.info("{} {}", message, file.getPath()); + return file; + } + return null; + } + + /** + * Reports fatal errors. This is the case in which no properties file could be + * found. + * + * @param message An appropriate fatal error message + * @param configurationException An exception describing what went wrong during resolution + */ + private static void reportFailure(final String message, final ConfigurationException configurationException) { + + LOG.error("{}", message, configurationException); + } + + /** + * Extract svclogic config properties. + * + * @return the svclogic config properties + */ + public Properties getProperties() { + return properties; + } + + /** + * Determines the sql-resource properties file to use based on the following priority: + *
    + *
  1. A directory identified by the system environment variable + * SDNC_CONFIG_DIR
  2. + *
  3. The default directory DEFAULT_DBLIB_PROP_DIR
  4. + *
  5. A directory identified by the JRE argument + * sql-resource.properties
  6. + *
  7. A sql-resource.properties file located in the karaf root + * directory
  8. + *
+ */ + File determinePropertiesFile(final SaltstackAdaptorPropertiesProviderImpl resourceProvider) { + + for (final PropertiesFileResolver sliPropertiesFileResolver : saltstackAdaptorPropertiesFileResolvers) { + final Optional fileOptional = sliPropertiesFileResolver.resolveFile(SALTSTACKAdaptor_PROP_FILE_NAME); + if (fileOptional.isPresent()) { + return reportSuccess(sliPropertiesFileResolver.getSuccessfulResolutionMessage(), fileOptional); + } + } + + return null; + } +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java new file mode 100644 index 000000000..25d2d8402 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java @@ -0,0 +1,217 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. All rights reserved. + * ================================================================================ + * + * ============================================================================= + * 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. + * + * + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.saltstack.impl; + +import java.io.OutputStream; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.KeyPair; +import org.apache.sshd.client.SshClient; +import org.apache.sshd.client.channel.ChannelExec; +import org.apache.sshd.client.future.AuthFuture; +import org.apache.sshd.client.future.OpenFuture; +import org.apache.sshd.client.session.ClientSession; +import org.apache.sshd.common.keyprovider.FileKeyPairProvider; +import org.apache.sshd.common.keyprovider.KeyPairProvider; +import org.onap.ccsdk.sli.adaptors.saltstack.model.Constants; +import org.onap.ccsdk.sli.adaptors.saltstack.model.SshException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +/** + * Implementation of SshConnection interface based on Apache MINA SSHD library. + */ +class SshConnection { + + private static final EELFLogger logger = EELFManager.getInstance().getApplicationLogger(); + + private static final long AUTH_TIMEOUT = 60000; + private static final long EXEC_TIMEOUT = 120000; + private String host; + private int port; + private String username; + private String password; + private long timeout = EXEC_TIMEOUT; + private String keyFile; + private SshClient sshClient; + private ClientSession clientSession; + + public SshConnection(String host, int port, String username, String password, String keyFile) { + this.host = host; + this.port = port; + this.username = username; + this.password = password; + this.keyFile = keyFile; + } + + public SshConnection(String host, int port, String username, String password) { + this(host, port, username, password, null); + } + + public SshConnection(String host, int port, String keyFile) { + this(host, port, null, null, keyFile); + } + + public void connect() { + sshClient = SshClient.setUpDefaultClient(); + sshClient.start(); + try { + clientSession = + sshClient.connect(username, host, port).getSession(); + if (password != null) { + clientSession.addPasswordIdentity(password); + } else if (keyFile != null) { + Path keyFilePath = Paths.get(keyFile); + KeyPairProvider keyPairProvider = new FileKeyPairProvider(keyFilePath); + KeyPair keyPair = keyPairProvider.loadKeys().iterator().next(); + clientSession.addPublicKeyIdentity(keyPair); + } + AuthFuture authFuture = clientSession.auth(); + authFuture.await(AUTH_TIMEOUT); + if (!authFuture.isSuccess()) { + throw new SshException("Error establishing ssh connection to [" + username + "@" + host + ":" + port + + "]. Authentication failed."); + } + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new SshException("Error establishing ssh connection to [" + username + "@" + host + ":" + port + "].", + e); + } + if (logger.isDebugEnabled()) { + logger.debug("SSH: connected to [" + toString() + "]"); + } + } + + public void connectWithRetry() { + int retryCount; + int retryDelay; + int retriesLeft; + retryCount = Constants.DEFAULT_CONNECTION_RETRY_COUNT; + retryDelay = Constants.DEFAULT_CONNECTION_RETRY_DELAY; + retriesLeft = retryCount + 1; + do { + try { + this.connect(); + break; + } catch (RuntimeException e) { + if (retriesLeft > 1) { + logger.debug("SSH Connection failed. Waiting for change in server's state."); + waitForConnection(retryDelay); + retriesLeft--; + logger.debug("Retrying SSH connection. Attempt [" + Integer.toString(retryCount - retriesLeft + 1) + + "] out of [" + retryCount + "]"); + } else { + throw e; + } + } + } while (retriesLeft > 0); + } + + public void disconnect() { + try { + if (logger.isDebugEnabled()) { + logger.debug("SSH: disconnecting from [" + toString() + "]"); + } + clientSession.close(false); + } finally { + if (sshClient != null) { + sshClient.stop(); + } + } + } + + public void setExecTimeout(long timeout) { + this.timeout = timeout; + } + + public int execCommand(String cmd, OutputStream out, OutputStream err) { + return execCommand(cmd, out, err, false); + } + + public int execCommandWithPty(String cmd, OutputStream out) { + return execCommand(cmd, out, out, true); + } + + private int execCommand(String cmd, OutputStream out, OutputStream err, boolean usePty) { + try { + if (logger.isDebugEnabled()) { + logger.debug("SSH: executing command"); + } + ChannelExec client = clientSession.createExecChannel(cmd); + client.setUsePty(usePty); // use pseudo-tty? + client.setOut(out); + client.setErr(err); + OpenFuture openFuture = client.open(); + int exitStatus; + try { + client.wait(timeout); + openFuture.verify(); + Integer exitStatusI = client.getExitStatus(); + if (exitStatusI == null) { + throw new SshException("Error executing command [" + cmd + "] over SSH [" + username + "@" + host + + ":" + port + "]. Operation timed out."); + } + exitStatus = exitStatusI; + } finally { + client.close(false); + } + return exitStatus; + } catch (RuntimeException e) { + throw e; + } catch (Exception e1) { + throw new SshException( + "Error executing command [" + cmd + "] over SSH [" + username + "@" + host + ":" + port + "]", e1); + } + } + + private void waitForConnection(int retryDelay) { + long time = retryDelay * 1000L; + long future = System.currentTimeMillis() + time; + if (time != 0) { + while (System.currentTimeMillis() < future && time > 0) { + try { + Thread.sleep(time); + } catch (InterruptedException e) { + /* + * This is rare, but it can happen if another thread interrupts us while we are sleeping. In that + * case, the thread is resumed before the delay time has actually expired, so re-calculate the + * amount of delay time needed and reenter the sleep until we get to the future time. + */ + time = future - System.currentTimeMillis(); + } + } + } + } + + @Override + public String toString() { + String address = host; + if (username != null) { + address = username + '@' + address + ':' + port; + } + return address; + } +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/Constants.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/Constants.java new file mode 100644 index 000000000..a1826c4e1 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/Constants.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.saltstack.model; + +public class Constants { + public static final String NETCONF_SCHEMA = "sdnctl"; + public static final String SDNCTL_SCHEMA = "sdnctl"; + public static final String DEVICE_AUTHENTICATION_TABLE_NAME = "DEVICE_AUTHENTICATION"; + public static final String CONFIGFILES_TABLE_NAME = "CONFIGFILES"; + public static final String DEVICE_INTERFACE_LOG_TABLE_NAME = "DEVICE_INTERFACE_LOG"; + public static final String FILE_CONTENT_TABLE_FIELD_NAME = "FILE_CONTENT"; + public static final String FILE_NAME_TABLE_FIELD_NAME = "FILE_NAME"; + public static final String USER_NAME_TABLE_FIELD_NAME = "USER_NAME"; + public static final String PASSWORD_TABLE_FIELD_NAME = "PASSWORD"; + public static final String PORT_NUMBER_TABLE_FIELD_NAME = "PORT_NUMBER"; + public static final String VNF_TYPE_TABLE_FIELD_NAME = "VNF_TYPE"; + public static final String SERVICE_INSTANCE_ID_FIELD_NAME = "SERVICE_INSTANCE_ID"; + public static final String REQUEST_ID_FIELD_NAME = "REQUEST_ID"; + public static final String CREATION_DATE_FIELD_NAME = "CREATION_DATE"; + public static final String LOG_FIELD_NAME = "LOG"; + public static final String SDC_ARTIFACTS_TABLE_NAME = "ASDC_ARTIFACTS"; + public static final String PAYLOAD = "payload"; + public static final String CONNECTION_RETRY_DELAY = "org.onap.appc.ssh.connection.retry.delay"; + public static final String CONNECTION_RETRY_COUNT = "org.onap.appc.ssh.connection.retry.count"; + public static final int DEFAULT_CONNECTION_RETRY_DELAY = 60; + public static final int DEFAULT_CONNECTION_RETRY_COUNT = 5; + public static final int DEFAULT_SSH_COMMAND_RETRY_COUNT = 3; + public static final int DEFAULT_CHECKACTIVE_RETRY_COUNT = 3; + public static final int DEFAULT_CHECKACTIVE_RETRY_DELAY = 30; + public static final int DEFAULT_STOP_RETRY_COUNT = 3; + public static final int DEFAULT_STOP_RETRY_DELAY = 30; + public static final String PARAM_IN_CONNECTION_DETAILS = "connection-details"; + public static final String PARAM_IN_NODE_NAME = "node-name"; + public static final String PARAM_IN_NODE_STATUS = "node-status"; + public static final String PARAM_IN_VM_URL = "vm-url"; + public static final String SKIP_EXECUTION_INSTALLER_BIN_FILE = "Skip-execution-installer-bin-file"; + public static final String SKIP_DEPLOY = "Skip-deploy"; + public static final String UPGRADE_VERSION = "upgrade-version"; + public static final String STATE_COMMAND = "/opt/jnetx/skyfall-scp/asp-state.sh | grep -o UP | wc -l"; + public static final String VNFC_STATE_COMMAND = "/opt/jnetx/skyfall-scp/asp-state.sh"; + public static final String RESTART_NODE_COMMAND = "/opt/jnetx/skyfall-scp/asp-stop.sh --restart -f --nodes"; + public static final String START_NODE_COMMAND = "/opt/jnetx/skyfall-scp/asp-start.sh -f --nodes"; + public static final String STOP_NODE_COMMAND = "/opt/jnetx/skyfall-scp/asp-stop.sh -f --nodes"; + public static final int STATE_COMMAND_RESULT = 18; + public static final String FE_STATE_TRUE_TEST_COMMAND = "ssh -t -q fe1 /opt/omni/bin/swmml -e display-platform-status | grep -o TRUE | wc -l"; + public static final int FE_STATE_TRUE_TEST_RESULT = 22; + public static final String FE_STATE_FALSE_TEST_COMMAND = "ssh -t -q fe1 /opt/omni/bin/swmml -e display-platform-status | grep -o FALSE | wc -l"; + public static final int FE_STATE_FALSE_TEST_RESULT = 2; + public static final String FE_OPERATIONAL_TEST_COMMAND = "ssh -t -q fe1 /opt/omni/bin/swmml -e display-platform-status | grep -o 'NOT FULLY OPERATIONAL' | wc -l"; + public static final int FE_OPERATIONAL_TEST_RESULT = 2; + public static final String SMP_CHECK_ACTIVE_STATE_COMMAND = "cat skyfall-scp/runtime/SCP_SMP_*/smp/log/system.log| grep SSS | tail -1"; + public static final String SMP_STATE_ACTIVE = "SMP is active"; + public static final String SMP_STATE_INACTIVE = "SMP is not active"; + public static final String RSYNC_COMMAND = "yes n | /opt/jnetx/skyfall-scp/asp-rsync.sh --check | grep -o 'is active' | wc -l"; + public static final int RSYNC_COMMAND_RESULT = 9; + public static final String PARAM_IN_TIMEOUT = "timeout"; + public static final String PARAM_IN_FILE_URL = "source-file-url"; + public static final String DOWNLOAD_COMMAND = "wget -N %s"; + public static final String[] VM_NAMES = new String[]{"fe1", "fe2", "be1", "be2", "be3", "be4", "be5", "smp1", "smp2"}; + public static final String DEFAULT_DISK_SPACE = "10240000"; + public static final String DF_COMMAND_TEMPLATE = "ssh %s df | grep vda1 | grep -v grep | tr -s ' '|cut -d ' ' -f4"; + public static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message"; + public static final String ATTRIBUTE_ERROR_MESSAGE = "error-message"; + public static final String CONNECTION_DETAILS_FIELD_NAME = "connection-details"; + public static final String VNF_HOST_IP_ADDRESS_FIELD_NAME = "vnf-host-ip-address"; + public static final String VNF_HOST_IP2_ADDRESS_FIELD_NAME = "vnf-host-ip2-address"; + public static final String DG_ERROR_FIELD_NAME = "org.openecom.appc.dg.error"; + + private Constants() { + } +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/JsonParser.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/JsonParser.java new file mode 100644 index 000000000..3eb353a17 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/JsonParser.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.saltstack.model; + +import org.codehaus.jettison.json.JSONArray; +import org.codehaus.jettison.json.JSONException; +import org.codehaus.jettison.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import static com.google.common.base.Preconditions.checkNotNull; + +public final class JsonParser { + + private static final Logger log = LoggerFactory.getLogger(JsonParser.class); + + private JsonParser() { + // Preventing instantiation of the same. + } + + @SuppressWarnings("unchecked") + public static Map convertToProperties(String s) + throws JSONException { + + checkNotNull(s, "Input should not be null."); + + JSONObject json = new JSONObject(s); + Map wm = new HashMap<>(); + Iterator ii = json.keys(); + while (ii.hasNext()) { + String key1 = ii.next(); + wm.put(key1, json.get(key1)); + } + + Map mm = new HashMap<>(); + + while (!wm.isEmpty()) + for (String key : new ArrayList<>(wm.keySet())) { + Object o = wm.get(key); + wm.remove(key); + + if (o instanceof Boolean || o instanceof Number || o instanceof String) { + mm.put(key, o.toString()); + + log.info("Added property: {} : {}", key, o.toString()); + } else if (o instanceof JSONObject) { + JSONObject jo = (JSONObject) o; + Iterator i = jo.keys(); + while (i.hasNext()) { + String key1 = i.next(); + wm.put(key + "." + key1, jo.get(key1)); + } + } else if (o instanceof JSONArray) { + JSONArray ja = (JSONArray) o; + mm.put(key + "_length", String.valueOf(ja.length())); + + log.info("Added property: {}_length: {}", key, String.valueOf(ja.length())); + + for (int i = 0; i < ja.length(); i++) + wm.put(key + '[' + i + ']', ja.get(i)); + } + } + return mm; + } +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackMessageParser.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackMessageParser.java new file mode 100644 index 000000000..03b3eebf9 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackMessageParser.java @@ -0,0 +1,412 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017-2018 Samsung Electronics. All rights reserved. + * ================================================================================ + * + * ============================================================================= + * 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. + * + * + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.saltstack.model; + +/** + * This module implements the APP-C/Saltstack Server interface + * based on the REST API specifications + */ + +import com.google.common.base.Strings; +import org.json.JSONException; +import org.json.JSONObject; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.UUID; + +/** + * Class that validates and constructs requests sent/received from + * Saltstack Server + */ +public class SaltstackMessageParser { + + private static final String SS_AGENT_HOSTNAME_KEY = "HostName"; + private static final String SS_AGENT_PORT_KEY = "Port"; + private static final String PASS_KEY = "Password"; + private static final String USER_KEY = "User"; + private static final String CMD_EXEC = "Cmd"; //cmd + private static final String IS_SLS_EXEC = "SlsExec"; //slsExec + private static final String SS_REQ_ID = "Id"; + private static final String SLS_FILE_LOCATION = "SlsFile"; //slsFile + private static final String SLS_NAME = "SlsName"; //slsName + private static final String MINION_TO_APPLY = "NodeList"; //applyTo + private static final String EXEC_TIMEOUT_TO_APPLY = "Timeout"; //execTimeout + private static final String FILE_PARAMETERS_OPT_KEY = "FileParameters"; + private static final String ENV_PARAMETERS_OPT_KEY = "EnvParameters"; + + private static final Logger LOGGER = LoggerFactory.getLogger(SaltstackMessageParser.class); + + /** + * Method that validates that the Map has enough information + * to query Saltstack server for a result. If so, it returns + * the appropriate PORT number. + */ + public String reqPortResult(Map params) throws SvcLogicException { + // use default port if null + if (params.get(SS_AGENT_PORT_KEY) == null) { + return "22"; + } + return params.get(SS_AGENT_PORT_KEY); + } + + /** + * Method that validates that the Map has enough information + * to query Saltstack server for a result. If so, it returns + * the appropriate HOST name. + */ + public String reqHostNameResult(Map params) throws SvcLogicException { + + throwIfMissingMandatoryParam(params, SS_AGENT_HOSTNAME_KEY); + return params.get(SS_AGENT_HOSTNAME_KEY); + } + + /** + * Method that validates that the Map has enough information + * to query Saltstack server for a result. If so, it returns + * the appropriate request ID. + */ + public String reqId(Map params) { + + if (params.get(SaltstackMessageParser.SS_REQ_ID) == null) { + return UUID.randomUUID().toString(); + } else if (params.get(SaltstackMessageParser.SS_REQ_ID).equalsIgnoreCase("")) { + return UUID.randomUUID().toString(); + } + return params.get(SaltstackMessageParser.SS_REQ_ID); + } + + /** + * Method that validates that the Map has enough information + * to query Saltstack server for a result. If so, it returns + * the appropriate command to execute. + */ + public String reqCmd(Map params) throws SvcLogicException { + + throwIfMissingMandatoryParam(params, CMD_EXEC); + return params.get(SaltstackMessageParser.CMD_EXEC); + } + + /** + * Method that validates that the Map has enough information + * to query Saltstack server for a result. If so, it returns + * the appropriate SLS file location to execute. + */ + public String reqSlsFile(Map params) throws SvcLogicException { + + throwIfMissingMandatoryParam(params, SLS_FILE_LOCATION); + return params.get(SaltstackMessageParser.SLS_FILE_LOCATION); + } + + /** + * Method that validates that the Map has enough information + * to query Saltstack server for a result. If so, it returns + * the appropriate SLS file location to execute. + */ + public String reqSlsName(Map params) throws SvcLogicException { + + throwIfMissingMandatoryParam(params, SLS_NAME); + String slsName = params.get(SaltstackMessageParser.SLS_NAME); + try { + if (slsName.substring(slsName.lastIndexOf("."), slsName.length()).equalsIgnoreCase(".sls")) { + return stripExtension(slsName); + } + } catch (StringIndexOutOfBoundsException e) { + return slsName; + } + return slsName; + } + + private String stripExtension(String str) { + if (str == null) { + return null; + } + int pos = str.lastIndexOf("."); + if (pos == -1) { + return str; + } + return str.substring(0, pos); + } + + /** + * Method that validates that the Map has enough information + * to query Saltstack server for a result. If so, it returns + * the appropriate minions/vnfc to execute the SLS file. + */ + public String reqApplyToDevices(Map params) { + + if (params.get(SaltstackMessageParser.MINION_TO_APPLY) == null) { + return "*"; + } else if (params.get(SaltstackMessageParser.MINION_TO_APPLY).equalsIgnoreCase("")) { + return "*"; + } + return params.get(SaltstackMessageParser.MINION_TO_APPLY); + } + + /** + * Method that validates that the Map has enough information + * to query Saltstack server for a result. If so, it returns + * the appropriate minions/vnfc to execute the SLS file. + */ + public long reqExecTimeout(Map params) { + + if (params.get(SaltstackMessageParser.EXEC_TIMEOUT_TO_APPLY) == null) { + return -1; + } else if (params.get(SaltstackMessageParser.EXEC_TIMEOUT_TO_APPLY).equalsIgnoreCase("")) { + return -1; + } + return Long.parseLong(params.get(SaltstackMessageParser.EXEC_TIMEOUT_TO_APPLY)); + } + + /** + * Method that validates that the Map has enough information + * to query Saltstack server for a result. If so, it returns + * the appropriate EnvParameters to execute the SLS file. + */ + public JSONObject reqEnvParameters(Map params) throws JSONException { + + JSONObject jsonPayload = new JSONObject(); + final String[] optionalTestParam = {SaltstackMessageParser.ENV_PARAMETERS_OPT_KEY}; + parseParam(params, optionalTestParam, jsonPayload); + + return (JSONObject) jsonPayload.remove(SaltstackMessageParser.ENV_PARAMETERS_OPT_KEY); + } + + /** + * Method that validates that the Map has enough information + * to query Saltstack server for a result. If so, it returns + * the appropriate EnvParameters to execute the SLS file. + */ + public JSONObject reqFileParameters(Map params) throws JSONException { + + JSONObject jsonPayload = new JSONObject(); + final String[] optionalTestParam = {SaltstackMessageParser.FILE_PARAMETERS_OPT_KEY}; + parseParam(params, optionalTestParam, jsonPayload); + + return (JSONObject) jsonPayload.remove(SaltstackMessageParser.FILE_PARAMETERS_OPT_KEY); + } + + private void parseParam(Map params, String[] optionalTestParams, JSONObject jsonPayload) + throws JSONException { + + Set optionalParamsSet = new HashSet<>(); + Collections.addAll(optionalParamsSet, optionalTestParams); + + //@formatter:off + params.entrySet() + .stream() + .filter(entry -> optionalParamsSet.contains(entry.getKey())) + .filter(entry -> !Strings.isNullOrEmpty(entry.getValue())) + .forEach(entry -> parseParam(entry, jsonPayload)); + //@formatter:on + } + + private void parseParam(Map.Entry params, JSONObject jsonPayload) + throws JSONException { + String key = params.getKey(); + String payload = params.getValue(); + + switch (key) { + case ENV_PARAMETERS_OPT_KEY: + JSONObject paramsJson = new JSONObject(payload); + jsonPayload.put(key, paramsJson); + break; + + case FILE_PARAMETERS_OPT_KEY: + jsonPayload.put(key, getFilePayload(payload)); + break; + + default: + break; + } + } + + /** + * Return payload with escaped newlines + */ + private JSONObject getFilePayload(String payload) { + String formattedPayload = payload.replace("\n", "\\n").replace("\r", "\\r"); + return new JSONObject(formattedPayload); + } + + /** + * Method that validates that the Map has enough information + * to query Saltstack server for a result. If so, it returns + * the appropriate IsSLSExec true or false. + */ + public boolean reqIsSLSExec(Map params) throws SvcLogicException { + + final String[] mandatoryTestParams = {CMD_EXEC, IS_SLS_EXEC}; + + for (String key : mandatoryTestParams) { + throwIfMissingMandatoryParam(params, key); + } + + return params.get(SaltstackMessageParser.IS_SLS_EXEC).equalsIgnoreCase("true"); + } + + /** + * Method that validates that the Map has enough information + * to query Saltstack server for a result. If so, it returns + * the appropriate Saltstack server login user name. + */ + public String reqUserNameResult(Map params) throws SvcLogicException { + + throwIfMissingMandatoryParam(params, USER_KEY); + return params.get(USER_KEY); + } + + /** + * Method that validates that the Map has enough information + * to query Saltstack server for a result. If so, it returns + * the appropriate Saltstack server login password. + */ + public String reqPasswordResult(Map params) throws SvcLogicException { + + throwIfMissingMandatoryParam(params, PASS_KEY); + return params.get(PASS_KEY); + } + + /** + * This method parses response from the Saltstack Server when we do a post + * and returns an SaltstackResult object. + */ + public SaltstackResult parseResponse(SvcLogicContext ctx, String pfx, + SaltstackResult saltstackResult, boolean slsExec) throws IOException { + int code = saltstackResult.getStatusCode(); + boolean executionStatus = true; + boolean retCodeFound = false; + if (code != SaltstackResultCodes.SUCCESS.getValue()) { + return saltstackResult; + } + ByteArrayOutputStream outStream = saltstackResult.getOutputMessage(); + String outMessage = outStream.toString(); + try { + Map mm = JsonParser.convertToProperties(outMessage); + if (mm != null) { + for (Map.Entry entry : mm.entrySet()) { + if (entry.getKey().contains("retcode")) { + retCodeFound = true; + if (!entry.getValue().equalsIgnoreCase("0")) { + executionStatus = false; + } + } + ctx.setAttribute(pfx + "." + entry.getKey(), entry.getValue()); + LOGGER.info("+++ " + pfx + "." + entry.getKey() + ": [" + entry.getValue() + "]"); + } + } + } catch (org.codehaus.jettison.json.JSONException e) { + if (slsExec) { + return new SaltstackResult(SaltstackResultCodes.INVALID_RESPONSE.getValue(), "error parsing response file" + + " : Output has to be in JSON format"); + } + LOGGER.info("Output not in JSON format"); + return putToProperties(ctx, pfx, saltstackResult); + } catch (Exception e) { + return new SaltstackResult(SaltstackResultCodes.INVALID_RESPONSE_FILE.getValue(), "error parsing response file" + + " : " + e.getMessage()); + } finally { + if (outStream != null) { + outStream.close(); + } + } + if (slsExec) { + if (!retCodeFound) { + if (outMessage != null && !outMessage.equalsIgnoreCase("")) { + return new SaltstackResult(SaltstackResultCodes.COMMAND_EXEC_FAILED_STATUS.getValue(), + outMessage); + } + return new SaltstackResult(SaltstackResultCodes.COMMAND_EXEC_FAILED_STATUS.getValue(), + "error in executing configuration at the server, check your command input"); + } + if (!executionStatus) { + if (outMessage != null && !outMessage.equalsIgnoreCase("")) { + return new SaltstackResult(SaltstackResultCodes.COMMAND_EXEC_FAILED_STATUS.getValue(), + outMessage); + } + return new SaltstackResult(SaltstackResultCodes.COMMAND_EXEC_FAILED_STATUS.getValue(), + "error in executing configuration at the server, check your command input"); + } + } + saltstackResult.setStatusCode(SaltstackResultCodes.FINAL_SUCCESS.getValue()); + return saltstackResult; + } + + public SaltstackResult putToProperties(SvcLogicContext ctx, String pfx, + SaltstackResult saltstackResult) throws IOException { + + ByteArrayOutputStream buffer = saltstackResult.getOutputMessage(); + InputStream inputStream = null; + try { + byte[] bytes = buffer.toByteArray(); + Properties prop = new Properties(); + inputStream = new ByteArrayInputStream(bytes); + prop.load(inputStream); + ctx.setAttribute(pfx + "completeResult", prop.toString()); + for (Object key : prop.keySet()) { + String name = (String) key; + String value = prop.getProperty(name); + if (value != null && value.trim().length() > 0) { + ctx.setAttribute(pfx + "." + name, value.trim()); + LOGGER.info("+++ " + pfx + "." + name + ": [" + value + "]"); + } + } + } catch (Exception e) { + saltstackResult = new SaltstackResult(SaltstackResultCodes.INVALID_RESPONSE_FILE.getValue(), "Error parsing response file." + + " Error = " + e.getMessage()); + } finally { + if (buffer != null && inputStream != null) { + buffer.close(); + inputStream.close(); + } + } + saltstackResult.setStatusCode(SaltstackResultCodes.FINAL_SUCCESS.getValue()); + return saltstackResult; + } + + private void throwIfMissingMandatoryParam(Map params, String key) throws SvcLogicException { + if (!params.containsKey(key)) { + throw new SvcLogicException(String.format( + "Saltstack: Mandatory SaltstackAdaptor key %s not found in parameters provided by calling agent !", + key)); + } + if (Strings.isNullOrEmpty(params.get(key))) { + throw new SvcLogicException(String.format( + "Saltstack: Mandatory SaltstackAdaptor key %s not found in parameters provided by calling agent !", + key)); + } + } +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResult.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResult.java new file mode 100644 index 000000000..727cfe314 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResult.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. All rights reserved. + * ================================================================================ + * + * ============================================================================= + * 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. + * + * + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.saltstack.model; + +import java.io.ByteArrayOutputStream; + +/** + * Simple class to store code and message returned by POST/GET to an Saltstack Server + */ +public class SaltstackResult { + + private static final String EMPTY_VALUE = "UNKNOWN"; + + private int statusCode; + private String statusMessage; + private String results; + private ByteArrayOutputStream out; + private int sshExitStatus; + + public SaltstackResult() { + this(-1, EMPTY_VALUE, EMPTY_VALUE, -1); + } + + public SaltstackResult(int code, String message) { + this(code, message, EMPTY_VALUE, -1); + } + + public SaltstackResult(int code, String message, String result, int sshCode) { + statusCode = code; + statusMessage = message; + results = result; + sshExitStatus = sshCode; + } + + void set(int code, String message, String results) { + this.statusCode = code; + this.statusMessage = message; + this.results = results; + } + + public ByteArrayOutputStream getOutputMessage() { + return out; + } + + public void setOutputMessage(ByteArrayOutputStream out) { + this.out = out; + } + + public int getStatusCode() { + return this.statusCode; + } + + public void setStatusCode(int code) { + this.statusCode = code; + } + + public String getStatusMessage() { + return this.statusMessage; + } + + public void setStatusMessage(String message) { + this.statusMessage = message; + } + + public String getResults() { + return this.results; + } + + public void setResults(String results) { + this.results = results; + } + + public int getSshExitStatus() { + return sshExitStatus; + } + + public void setSshExitStatus(int sshExitStatus) { + this.sshExitStatus = sshExitStatus; + } +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResultCodes.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResultCodes.java new file mode 100644 index 000000000..932554983 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResultCodes.java @@ -0,0 +1,100 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. All rights reserved. + * ================================================================================ + * + * ============================================================================= + * 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. + * + * + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.saltstack.model; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** + * enum of the various codes that APP-C uses to resolve different + * status of response from Saltstack Server + **/ + +public enum SaltstackResultCodes { + + // @formatter:off + SUCCESS(400), + KEYSTORE_EXCEPTION(622), + CERTIFICATE_ERROR(610), + IO_EXCEPTION(611), + HOST_UNKNOWN(625), + USER_UNAUTHORIZED(613), + UNKNOWN_EXCEPTION(699), + OPERATION_TIMEOUT(659), + SSL_EXCEPTION(697), + SSH_EXCEPTION(695), + INVALID_COMMAND(698), + INVALID_RESPONSE(601), + INVALID_RESPONSE_FILE(600), + PENDING(100), + REJECTED(101), + FINAL_SUCCESS(200), + CHECK_CTX_FOR_CMD_SUCCESS(250), + COMMAND_EXEC_FAILED_STATUS(670), + REQ_FAILURE(401), + MESSAGE(1), + CODE(0), + INITRESPONSE(0), + FINALRESPONSE(1); + // @formatter:on + + private final Set initCodes = new HashSet<>(Arrays.asList(100, 101)); + private final Set finalCodes = new HashSet<>(Arrays.asList(200, 500)); + private final ArrayList> codeSets = new ArrayList<>(Arrays.asList(initCodes, finalCodes)); + private final Set messageSet = new HashSet<>(Arrays.asList("PENDING", "FINISHED", "TERMINATED")); + private final int value; + + SaltstackResultCodes(int value) { + this.value = value; + } + + ; + + public int getValue() { + return value; + } + + public boolean checkValidCode(int type, int code) { + return codeSets.get(type).contains(code); + } + + public String getValidCodes(int type) { + StringBuilder sb = new StringBuilder("[ "); + codeSets.get(type).stream().forEach(s -> sb.append(s).append(",")); + return sb.append("]").toString(); + } + + public boolean checkValidMessage(String message) { + return messageSet.contains(message); + } + + public String getValidMessages() { + StringBuilder sb = new StringBuilder("[ "); + messageSet.stream().forEach(s -> sb.append(s).append(",")); + return sb.append("]").toString(); + } +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackServerEmulator.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackServerEmulator.java new file mode 100644 index 000000000..78976562b --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackServerEmulator.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. All rights reserved. + * ================================================================================ + * + * ============================================================================= + * 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. + * + * + * ============LICENSE_END========================================================= + */ + + + +/* + * Class to emulate responses from the Saltstack Server that is compliant with the APP-C Saltstack Server + * Interface. Used for jUnit tests to verify code is working. In tests it can be used + * as a replacement for methods from ConnectionBuilder class + */ + +package org.onap.ccsdk.sli.adaptors.saltstack.model; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import java.io.ByteArrayOutputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Map; + +public class SaltstackServerEmulator { + + private static final String SALTSTATE_FILE_NAME = "fileName"; + private final EELFLogger logger = EELFManager.getInstance().getLogger(SaltstackServerEmulator.class); + + /** + * Method that emulates the response from an Saltstack Server + * when presented with a request to execute a saltState + * Returns an saltstack object result. The response code is always the ssh code 200 (i.e connection successful) + * payload is json string as would be sent back by Saltstack Server + **/ + public SaltstackResult mockReqExec(Map params) { + SaltstackResult result = new SaltstackResult(); + + try { + if (params.get("Test") == "fail") { + result = rejectRequest(result, "Mocked: Fail"); + } else { + String fileName = params.get(SALTSTATE_FILE_NAME); + if (fileName == null) { + throw new FileNotFoundException("No response file found"); + } + result = acceptRequest(result, fileName); + } + } catch (Exception e) { + logger.error("Exception caught", e); + rejectRequest(result, e.getMessage()); + } + return result; + } + + private SaltstackResult rejectRequest(SaltstackResult result, String Message) { + result.setStatusCode(SaltstackResultCodes.REJECTED.getValue()); + result.setStatusMessage("Rejected"); + return result; + } + + private SaltstackResult acceptRequest(SaltstackResult result, String fileName) throws IOException { + result.setStatusCode(SaltstackResultCodes.SUCCESS.getValue()); + result.setStatusMessage("Success"); + Path path = Paths.get(fileName); + byte[] data = Files.readAllBytes(path); + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(data.length); + byteOut.write(data, 0, data.length); + result.setOutputMessage(byteOut); + return result; + } +} \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SshException.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SshException.java new file mode 100644 index 000000000..037a1e891 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SshException.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.saltstack.model; + +public class SshException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public SshException(String message) { + super(message); + } + + public SshException(String message, Throwable cause) { + super(message, cause); + } +} \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/resources/org/opendaylight/blueprint/saltstack-adaptor-blueprint.xml b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/resources/org/opendaylight/blueprint/saltstack-adaptor-blueprint.xml new file mode 100644 index 000000000..b614d29bf --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/resources/org/opendaylight/blueprint/saltstack-adaptor-blueprint.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + org.onap.ccsdk.sli.adaptors.saltstack.SaltstackAdaptor + + + + + diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/resources/saltstack-adaptor.properties b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/resources/saltstack-adaptor.properties new file mode 100644 index 000000000..b37a593fb --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/resources/saltstack-adaptor.properties @@ -0,0 +1,43 @@ +### +# ============LICENSE_START======================================================= +# ONAP : CCSDK +# ================================================================================ +# Copyright (C) 2018 Samsung Electronics. All rights reserved. +# ================================================================================ +# +# ============================================================================= +# 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. +# +# +# ============LICENSE_END========================================================= +### +# +# Default properties for the APP-C TestService Adaptor +# +# ------------------------------------------------------------------------------------------------- +# +# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded +# to supply configuration options +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=${user.home},/opt/opendaylight/current/properties +appc.application.name=APPC +# +# Define the message resource bundle name to be loaded +org.onap.appc.resources=org.onap/appc/i18n/MessageResources +# +# The name of the adaptor. +org.onap.appc.provider.adaptor.name=org.onap.appc.appc_saltstack_adaptor +# Default truststore path and password +org.onap.appc.adaptor.saltstack.trustStore=/opt/opendaylight/tls-client/mykeystore.js +org.onap.appc.adaptor.saltstack.trustStore.trustPasswd=changeit +org.onap.appc.adaptor.saltstack.clientType=TRUST_ALL diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestConnectionBuilder.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestConnectionBuilder.java new file mode 100644 index 000000000..fd6e7811e --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestConnectionBuilder.java @@ -0,0 +1,184 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. All rights reserved. + * ================================================================================ + * + * ============================================================================= + * 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. + * + * + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.ali.adaptors.saltstack.impl; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.adaptors.saltstack.impl.ConnectionBuilder; +import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResult; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + + +public class TestConnectionBuilder { + + private ConnectionBuilder connBuilder; + private Map params; + + + @Before + public void setup() throws IllegalArgumentException { + String HostName = "test"; + String Port = "10"; + String User = "test"; + String Password = "test"; + connBuilder = new ConnectionBuilder(HostName, Port, User, Password); + + params = new HashMap<>(); + params.put("AgentUrl", "https://192.168.1.1"); + params.put("User", "test"); + params.put("Password", "test"); + } + + @After + public void tearDown() { + connBuilder = null; + params = null; + } + + @Test + public void reqExecCommand_exitStatus255() { + + int exitStatus = 255; + String errFilePath = "src/test/resources/test.json"; + String command = "test"; + + SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); + int status = result.getStatusCode(); + assertEquals(698, status); + } + + @Test + public void reqExecCommand_exitStatus1() { + + int exitStatus = 1; + String errFilePath = "src/test/resources/test.json"; + String command = "test"; + + SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); + int status = result.getStatusCode(); + assertEquals(698, status); + } + + @Test + public void reqExecCommand_exitStatus67() { + + int exitStatus = 67; + String errFilePath = "src/test/resources/test.json"; + String command = "test"; + + SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); + int status = result.getStatusCode(); + assertEquals(610, status); + } + + @Test + public void reqExecCommand_exitStatus73() { + + int exitStatus = 73; + String errFilePath = "src/test/resources/test.json"; + String command = "test"; + + SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); + int status = result.getStatusCode(); + assertEquals(610, status); + } + + @Test + public void reqExecCommand_exitStatus5() { + + int exitStatus = 5; + String errFilePath = "src/test/resources/test.json"; + String command = "test"; + + SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); + int status = result.getStatusCode(); + assertEquals(613, status); + } + + @Test + public void reqExecCommand_exitStatus65() { + + int exitStatus = 65; + String errFilePath = "src/test/resources/test.json"; + String command = "test"; + + SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); + int status = result.getStatusCode(); + assertEquals(613, status); + } + + @Test + public void reqExecCommand_exitStatus67613() { + + int exitStatus = 5; + String errFilePath = "src/test/resources/test.json"; + String command = "test"; + + SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); + int status = result.getStatusCode(); + assertEquals(613, status); + } + + @Test + public void reqExecCommand_exitStatus65613() { + + int exitStatus = 65; + String errFilePath = "src/test/resources/test.json"; + String command = "test"; + + SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); + int status = result.getStatusCode(); + assertEquals(613, status); + } + + @Test + public void reqExecCommand_exitStatusUnknown() { + + int exitStatus = 5121; + String errFilePath = "src/test/resources/test.json"; + String command = "test"; + + SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); + int status = result.getStatusCode(); + assertEquals(699, status); + } + + @Test + public void reqExecCommand_exitStatusNoFile() { + + int exitStatus = 65; + String errFilePath = "src/test/resource/test.json"; + String command = "test"; + + SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command); + int status = result.getStatusCode(); + assertEquals(613, status); + } +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSaltstackAdaptorImpl.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSaltstackAdaptorImpl.java new file mode 100644 index 000000000..1a05d50cb --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSaltstackAdaptorImpl.java @@ -0,0 +1,1051 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. All rights reserved. + * ================================================================================ + * + * ============================================================================= + * 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. + * + * + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.ali.adaptors.saltstack.impl; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.adaptors.saltstack.impl.SaltstackAdaptorImpl; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + + +public class TestSaltstackAdaptorImpl { + + private SaltstackAdaptorImpl adaptor; + private String TestId; + private boolean testMode = true; + private Map params; + private SvcLogicContext svcContext; + + + @Before + public void setup() throws IllegalArgumentException { + testMode = true; + svcContext = new SvcLogicContext(); + adaptor = new SaltstackAdaptorImpl(testMode); + + params = new HashMap<>(); + params.put("AgentUrl", "https://192.168.1.1"); + params.put("User", "test"); + params.put("Password", "test"); + } + + @After + public void tearDown() { + testMode = false; + adaptor = null; + params = null; + svcContext = null; + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_shouldSetFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "fail"); + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("101", status); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_shouldSetUserFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("Password", "test"); + params.put("Test", "fail"); + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("101", status); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_shouldSetHostFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "fail"); + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("101", status); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_shouldSetPortFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "fail"); + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("101", status); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_shouldSetPasswordFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Test", "fail"); + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("101", status); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_shouldSetMandatoryFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Test", "fail"); + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("101", status); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_NoResponseFile() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("Cmd", "test"); + params.put("SlsExec", "false"); + try { + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("400", status); + } catch (NullPointerException e) { + fail(e.getMessage() + " Unknown exception encountered "); + } + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_NoResponseFileWithRetry() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("withRetry", "true"); + params.put("Cmd", "test"); + params.put("SlsExec", "false"); + try { + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("400", status); + } catch (NullPointerException e) { + fail(e.getMessage() + " Unknown exception encountered "); + } + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_NoResponseFileWithRetryZero() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("withRetry", "0"); + params.put("Cmd", "test"); + params.put("SlsExec", "false"); + try { + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("400", status); + } catch (NullPointerException e) { + fail(e.getMessage() + " Unknown exception encountered "); + } + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_NoResponseFileWithNoRetry() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("withRetry", "false"); + params.put("Cmd", "test"); + params.put("SlsExec", "false"); + + try { + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("400", status); + } catch (NullPointerException e) { + fail(e.getMessage() + " Unknown exception encountered "); + } + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_shouldSetFailure() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Cmd", "test"); + params.put("SlsExec", "test"); + params.put("Test", "fail"); + try { + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("400", status); + } catch (NullPointerException e) { + fail(e.getMessage() + " Unknown exception encountered "); + } + } + + @Test + public void reqExecCommand_shouldSetSuccessNoSLS() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("fileName", "src/test/resources/test.json"); + params.put("Id", "test1"); + params.put("Cmd", "test"); + params.put("SlsExec", "false"); + + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } + + @Test + public void reqExecCommand_shouldSetSuccessExecSLS() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + params.put("Cmd", "test"); + params.put("SlsExec", "true"); + + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_shouldSetFailExecSLS() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("fileName", "src/test/resources/test.json"); + params.put("Id", "test1"); + params.put("Cmd", "test"); + params.put("SlsExec", "true"); + + adaptor.reqExecCommand(params, svcContext); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + @Test + public void reqExecCommand_shouldSetSuccessFileTxt() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("fileName", "src/test/resources/test.txt"); + params.put("Id", "txt"); + params.put("Cmd", "test"); + params.put("SlsExec", "false"); + + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "txt"); + } + + @Test + public void reqExecCommand_shouldSetSuccessFileNoExtension() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("fileName", "src/test/resources/test"); + params.put("Id", "txt"); + params.put("Cmd", "test"); + params.put("SlsExec", "false"); + + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "txt"); + } + + @Test + public void reqExecCommand_shouldSetSuccessFileInvalidJson() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("fileName", "src/test/resources/test-invalid.json"); + params.put("Id", "test1"); + params.put("Cmd", "test"); + params.put("SlsExec", "false"); + + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_shouldSetFailFileInvalidFile() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("fileName", "src/test/resources/test-none.json"); + params.put("Id", "test1"); + + adaptor.reqExecCommand(params, svcContext); + } + + @Test + public void reqExecCommand_shouldSetSuccessFileJsonNoReqID() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("fileName", "src/test/resources/test.json"); + params.put("Cmd", "test"); + params.put("SlsExec", "false"); + + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + } + + @Test + public void reqExecSLSFile_shouldSetSuccessJson() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsFile", "src/test/resources/test.sls"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + params.put("Cmd", "test"); + + adaptor.reqExecSLSFile(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } + + @Test(expected = SvcLogicException.class) + public void reqExecSLSFile_NoSLSfile() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsFile", "src/test/resources/test-none.sls"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + + adaptor.reqExecSLSFile(params, svcContext); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + @Test(expected = SvcLogicException.class) + public void reqExecSLSFile_NoExtn() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsFile", "src/test/resources/test-none"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + + adaptor.reqExecSLSFile(params, svcContext); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + @Test(expected = SvcLogicException.class) + public void reqExecSLSFile_NoResponsefile() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsFile", "src/test/resources/test.json"); + params.put("fileName", "src/test/resources/test-none.json"); + params.put("Id", "test1"); + + adaptor.reqExecSLSFile(params, svcContext); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + @Test(expected = SvcLogicException.class) + public void reqExecSLSFile_WithMinionSetNotSLSType() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsFile", "src/test/resources/test.json"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + params.put("Cmd", "test"); + params.put("NodeList", "minion1"); + + adaptor.reqExecSLSFile(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } + + @Test + public void reqExecSLSFile_WithMinionSetSuccessSls() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsFile", "src/test/resources/test.sls"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + params.put("Cmd", "test"); + params.put("NodeList", "minion1"); + + adaptor.reqExecSLSFile(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } + + @Test(expected = SvcLogicException.class) + public void reqExecSLSFile_WithMinionNoSLSfile() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsFile", "src/test/resources/test-none.json"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + params.put("NodeList", "minion1"); + + adaptor.reqExecSLSFile(params, svcContext); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + @Test(expected = SvcLogicException.class) + public void reqExecSLSFile_WithMinionNoResponsefile() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsFile", "src/test/resources/test.json"); + params.put("fileName", "src/test/resources/test-none.json"); + params.put("Id", "test1"); + params.put("NodeList", "minion1"); + + adaptor.reqExecSLSFile(params, svcContext); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + @Test + public void reqExecSLSFile_WithAllMinionSetSuccessJson() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsFile", "src/test/resources/test.sls"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + params.put("Cmd", "test"); + params.put("NodeList", "*"); + + adaptor.reqExecSLSFile(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } + + @Test(expected = SvcLogicException.class) + public void reqExecSLSFile_WithAllMinionNoSLSfile() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsFile", "src/test/resources/test-none.json"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + params.put("NodeList", "*"); + + adaptor.reqExecSLSFile(params, svcContext); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + @Test(expected = SvcLogicException.class) + public void reqExecSLSFile_WithAllMinionNoResponsefile() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsFile", "src/test/resources/test.json"); + params.put("fileName", "src/test/resources/test-none.json"); + params.put("Id", "test1"); + params.put("NodeList", "*"); + + adaptor.reqExecSLSFile(params, svcContext); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + + @Test + public void reqExecSLS_shouldSetSuccessJson() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsName", "src/test.sls"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + params.put("Cmd", "test"); + + adaptor.reqExecSLS(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } + + @Test + public void reqExecSLS_shouldSetNoExtn() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsName", "src/test"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + params.put("Cmd", "test"); + + adaptor.reqExecSLS(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } + + @Test(expected = SvcLogicException.class) + public void reqExecSLS_NoResponsefile() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsName", "src/test/resources/test.json"); + params.put("fileName", "src/test/resources/test-none.json"); + params.put("Id", "test1"); + + adaptor.reqExecSLS(params, svcContext); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + + @Test + public void reqExecSLS_WithMinionSetSuccessSls() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsName", "src/test/resources/test.sls"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + params.put("Cmd", "test"); + params.put("NodeList", "minion1"); + + adaptor.reqExecSLS(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } + + + @Test(expected = SvcLogicException.class) + public void reqExecSLS_WithMinionNoResponsefile() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsName", "src/test/resources/test.json"); + params.put("fileName", "src/test/resources/test-none.json"); + params.put("Id", "test1"); + params.put("NodeList", "minion1"); + + adaptor.reqExecSLS(params, svcContext); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + @Test + public void reqExecSLS_WithAllMinionSetSuccessJson() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsName", "src/test/resources/test.sls"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + params.put("Cmd", "test"); + params.put("NodeList", "*"); + + adaptor.reqExecSLS(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } + + + @Test(expected = SvcLogicException.class) + public void reqExecSLS_WithAllMinionNoResponsefile() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "success"); + params.put("SlsName", "src/test/resources/test.json"); + params.put("fileName", "src/test/resources/test-none.json"); + params.put("Id", "test1"); + params.put("NodeList", "*"); + + adaptor.reqExecSLS(params, svcContext); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + + @Test + public void reqExecCommand_shouldSetSuccessReal() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "127.0.0.1"); + params.put("Port", "22"); + params.put("User", "sdn"); + params.put("Password", "foo"); + params.put("Id", "test1"); + params.put("Cmd", "ls -l"); + params.put("SlsExec", "false"); + params.put("Timeout", "120"); + adaptor = new SaltstackAdaptorImpl(); + try { + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } catch (Exception e) { + //if local ssh is not enabled + System.out.print(e.getMessage()); + } + } + + @Test + public void reqExecCommand_shouldSetSuccessRealSLSCommand() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", ""); + params.put("Port", "2222"); + params.put("User", "root"); + params.put("Password", "vagrant"); + params.put("Id", "test1"); + params.put("Cmd", "salt '*' test.ping --out=json --static"); + params.put("SlsExec", "false"); + params.put("Timeout", "120"); + + adaptor = new SaltstackAdaptorImpl(); + try { + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + TestId = svcContext.getAttribute("test1.minion1"); + assertEquals(TestId, "true"); + } catch (Exception e) { + //if saltstack ssh IP is not enabled + System.out.print(e.getMessage()); + } + } + + @Test + public void reqExecCommand_shouldSetSuccessRealCommand() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", ""); + params.put("Port", "2222"); + params.put("User", "root"); + params.put("Password", "vagrant"); + params.put("Id", "test1"); + params.put("Cmd", "cd /srv/salt/; salt '*' state.apply vim --out=json --static"); + params.put("SlsExec", "true"); + params.put("Timeout", "120"); + + adaptor = new SaltstackAdaptorImpl(); + try { + adaptor.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } catch (Exception e) { + //if saltstack ssh IP is not enabled + System.out.print(e.getMessage()); + } + } + + @Test + public void reqExecCommand_shouldSetSuccessRealSSL() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", ""); + params.put("Port", "2222"); + params.put("User", "root"); + params.put("Password", "vagrant"); + params.put("Id", "test1"); + params.put("SlsName", "vim"); + params.put("Timeout", "120"); + params.put("NodeList", "minion1"); + + adaptor = new SaltstackAdaptorImpl(); + try { + adaptor.reqExecSLS(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } catch (Exception e) { + //if saltstack ssh IP is not enabled + System.out.print(e.getMessage()); + } + } + + @Test + public void reqExecCommand_shouldSetSuccessEnvParam() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", ""); + params.put("Port", "2222"); + params.put("User", "root"); + params.put("Password", "vagrant"); + params.put("Id", "test1"); + params.put("SlsName", "vim"); + params.put("Timeout", "120"); + params.put("NodeList", "minion1"); + params.put("EnvParameters", "{\"exclude\": bar*}"); + + adaptor = new SaltstackAdaptorImpl(); + try { + adaptor.reqExecSLS(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } catch (Exception e) { + //if saltstack ssh IP is not enabled + System.out.print(e.getMessage()); + } + } + + @Test + public void reqExecCommand_shouldSetSuccessFileParam() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", ""); + params.put("Port", "2222"); + params.put("User", "root"); + params.put("Password", "vagrant"); + params.put("Id", "test1"); + params.put("SlsName", "vim"); + params.put("Timeout", "120"); + params.put("NodeList", "minion1"); + params.put("EnvParameters", "{\"exclude\": \"bar,baz\"}"); + params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}"); + + adaptor = new SaltstackAdaptorImpl(); + try { + adaptor.reqExecSLS(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } catch (Exception e) { + //if saltstack ssh IP is not enabled + System.out.print(e.getMessage()); + } + } + + @Test + public void reqExecCommand_shouldSetSuccessPillarParam() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", ""); + params.put("Port", "2222"); + params.put("User", "root"); + params.put("Password", "vagrant"); + params.put("Id", "test1"); + params.put("SlsName", "vim"); + params.put("Timeout", "120"); + params.put("NodeList", "minion1"); + params.put("EnvParameters", "{\"exclude\": \"bar,baz\", \"pillar\":\"'{\\\"foo\\\": \\\"bar\\\"}'\"}"); + params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}"); + + adaptor = new SaltstackAdaptorImpl(); + try { + adaptor.reqExecSLS(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } catch (Exception e) { + //if saltstack ssh IP is not enabled + System.out.print(e.getMessage()); + } + } + + @Test + public void reqExecCommand_shouldSetSuccessMultiFileParam() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", ""); + params.put("Port", "2222"); + params.put("User", "root"); + params.put("Password", "vagrant"); + params.put("Id", "test1"); + params.put("SlsName", "vim"); + params.put("Timeout", "120"); + params.put("NodeList", "minion1"); + params.put("EnvParameters", "{\"exclude\": bar*}"); + params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\" , \"config-tep.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}"); + + adaptor = new SaltstackAdaptorImpl(); + try { + adaptor.reqExecSLS(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } catch (Exception e) { + //if saltstack ssh IP is not enabled + System.out.print(e.getMessage()); + } + } + + @Test + public void reqExecCommand_shouldSetSuccessSSLFile() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", ""); + params.put("Port", "2222"); + params.put("User", "root"); + params.put("Password", "vagrant"); + params.put("Id", "test1"); + params.put("Timeout", "120"); + params.put("NodeList", "minion1"); + params.put("SlsFile", "src/test/resources/config.sls"); + + adaptor = new SaltstackAdaptorImpl(); + try { + adaptor.reqExecSLSFile(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } catch (Exception e) { + //if saltstack ssh IP is not enabled + System.out.print(e.getMessage()); + } + } + + @Test + public void reqExecCommand_shouldSetSuccessSSLFileMultiFileParam() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", ""); + params.put("Port", "2222"); + params.put("User", "root"); + params.put("Password", "vagrant"); + params.put("Id", "test1"); + params.put("Timeout", "120"); + params.put("NodeList", "minion1"); + params.put("SlsFile", "src/test/resources/config.sls"); + params.put("EnvParameters", "{\"exclude\": bar, \"pillar\":\"'{\\\"foo\\\": \\\"bar\\\"}'\"}"); + params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\" , \"config-tep.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}"); + + adaptor = new SaltstackAdaptorImpl(); + try { + adaptor.reqExecSLSFile(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.result.code"); + TestId = svcContext.getAttribute("org.onap.appc.adaptor.saltstack.Id"); + assertEquals("200", status); + assertEquals(TestId, "test1"); + } catch (Exception e) { + //if saltstack ssh IP is not enabled + System.out.print(e.getMessage()); + } + } +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSaltstackAdaptorPropertiesProviderImpl.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSaltstackAdaptorPropertiesProviderImpl.java new file mode 100644 index 000000000..8d37a0318 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSaltstackAdaptorPropertiesProviderImpl.java @@ -0,0 +1,310 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. All rights reserved. + * ================================================================================ + * + * ============================================================================= + * 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. + * + * + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.ali.adaptors.saltstack.impl; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.adaptors.saltstack.SaltstackAdaptorPropertiesProvider; +import org.onap.ccsdk.sli.adaptors.saltstack.impl.SaltstackAdaptorImpl; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +import java.util.Properties; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class TestSaltstackAdaptorPropertiesProviderImpl { + + private SaltstackAdaptorImpl adaptor; + private Properties params; + + + @Before + public void setup() throws IllegalArgumentException { + params = new Properties(); + } + + @After + public void tearDown() { + adaptor = null; + params = null; + } + + @Test + public void reqExecCommand_setPropertiesBasicPortNull() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adaptor.saltstack.clientType", "BASIC"); + params.put("User", "test"); + params.put("Password", "test"); + SaltstackAdaptorPropertiesProvider propProvider = new SaltstackAdaptorPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adaptor = new SaltstackAdaptorImpl(propProvider); + assertNotNull(propProvider); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_setPropertiesBasicPortString() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adaptor.saltstack.clientType", "BASIC"); + params.put("org.onap.appc.adaptor.saltstack.host", "test"); + params.put("org.onap.appc.adaptor.saltstack.port", "test"); + params.put("org.onap.appc.adaptor.saltstack.userName", "test"); + params.put("org.onap.appc.adaptor.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adaptor.saltstack.sshKey", "test"); + SaltstackAdaptorPropertiesProvider propProvider = new SaltstackAdaptorPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adaptor = new SaltstackAdaptorImpl(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesBasicSuccess() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adaptor.saltstack.clientType", "BASIC"); + params.put("org.onap.appc.adaptor.saltstack.host", "test"); + params.put("org.onap.appc.adaptor.saltstack.port", "10"); + params.put("org.onap.appc.adaptor.saltstack.userName", "test"); + params.put("org.onap.appc.adaptor.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adaptor.saltstack.sshKey", "test"); + SaltstackAdaptorPropertiesProvider propProvider = new SaltstackAdaptorPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adaptor = new SaltstackAdaptorImpl(propProvider); + assertNotNull(adaptor); + } + + @Test + public void reqExecCommand_setPropertiesSSH_CERTPortNull() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adaptor.saltstack.clientType", "SSH_CERT"); + params.put("User", "test"); + params.put("Password", "test"); + SaltstackAdaptorPropertiesProvider propProvider = new SaltstackAdaptorPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adaptor = new SaltstackAdaptorImpl(propProvider); + assertNotNull(propProvider); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_setPropertiesSSH_CERTPortString() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adaptor.saltstack.clientType", "SSH_CERT"); + params.put("org.onap.appc.adaptor.saltstack.host", "test"); + params.put("org.onap.appc.adaptor.saltstack.port", "test"); + params.put("org.onap.appc.adaptor.saltstack.userName", "test"); + params.put("org.onap.appc.adaptor.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adaptor.saltstack.sshKey", "test"); + SaltstackAdaptorPropertiesProvider propProvider = new SaltstackAdaptorPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adaptor = new SaltstackAdaptorImpl(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesSSH_CERTSuccess() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adaptor.saltstack.clientType", "SSH_CERT"); + params.put("org.onap.appc.adaptor.saltstack.host", "test"); + params.put("org.onap.appc.adaptor.saltstack.port", "10"); + params.put("org.onap.appc.adaptor.saltstack.userName", "test"); + params.put("org.onap.appc.adaptor.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adaptor.saltstack.sshKey", "test"); + SaltstackAdaptorPropertiesProvider propProvider = new SaltstackAdaptorPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adaptor = new SaltstackAdaptorImpl(propProvider); + assertNotNull(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesBOTHPortNull() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adaptor.saltstack.clientType", "BOTH"); + params.put("User", "test"); + params.put("Password", "test"); + SaltstackAdaptorPropertiesProvider propProvider = new SaltstackAdaptorPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adaptor = new SaltstackAdaptorImpl(propProvider); + assertNotNull(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesBOTHSuccess() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adaptor.saltstack.clientType", "BOTH"); + params.put("org.onap.appc.adaptor.saltstack.host", "test"); + params.put("org.onap.appc.adaptor.saltstack.port", "10"); + params.put("org.onap.appc.adaptor.saltstack.userName", "test"); + params.put("org.onap.appc.adaptor.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adaptor.saltstack.sshKey", "test"); + SaltstackAdaptorPropertiesProvider propProvider = new SaltstackAdaptorPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adaptor = new SaltstackAdaptorImpl(propProvider); + assertNotNull(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesNonePortNull() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adaptor.saltstack.clientType", "NONE"); + params.put("User", "test"); + params.put("Password", "test"); + SaltstackAdaptorPropertiesProvider propProvider = new SaltstackAdaptorPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adaptor = new SaltstackAdaptorImpl(propProvider); + assertNotNull(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesNonePortString() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adaptor.saltstack.clientType", "NONE"); + params.put("org.onap.appc.adaptor.saltstack.host", "test"); + params.put("org.onap.appc.adaptor.saltstack.port", "test"); + params.put("org.onap.appc.adaptor.saltstack.userName", "test"); + params.put("org.onap.appc.adaptor.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adaptor.saltstack.sshKey", "test"); + SaltstackAdaptorPropertiesProvider propProvider = new SaltstackAdaptorPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adaptor = new SaltstackAdaptorImpl(propProvider); + assertNotNull(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesNoneSuccess() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adaptor.saltstack.clientType", "NONE"); + params.put("org.onap.appc.adaptor.saltstack.host", "test"); + params.put("org.onap.appc.adaptor.saltstack.port", "10"); + params.put("org.onap.appc.adaptor.saltstack.userName", "test"); + params.put("org.onap.appc.adaptor.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adaptor.saltstack.sshKey", "test"); + SaltstackAdaptorPropertiesProvider propProvider = new SaltstackAdaptorPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adaptor = new SaltstackAdaptorImpl(propProvider); + assertNotNull(propProvider); + } + + + @Test + public void reqExecCommand_setPropertiesElsePortNull() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("User", "test"); + params.put("Password", "test"); + SaltstackAdaptorPropertiesProvider propProvider = new SaltstackAdaptorPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adaptor = new SaltstackAdaptorImpl(propProvider); + assertNotNull(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesElsePortString() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adaptor.saltstack.host", "test"); + params.put("org.onap.appc.adaptor.saltstack.port", "test"); + params.put("org.onap.appc.adaptor.saltstack.userName", "test"); + params.put("org.onap.appc.adaptor.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adaptor.saltstack.sshKey", "test"); + SaltstackAdaptorPropertiesProvider propProvider = new SaltstackAdaptorPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adaptor = new SaltstackAdaptorImpl(propProvider); + assertNotNull(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesElseSuccess() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adaptor.saltstack.host", "test"); + params.put("org.onap.appc.adaptor.saltstack.port", "10"); + params.put("org.onap.appc.adaptor.saltstack.userName", "test"); + params.put("org.onap.appc.adaptor.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adaptor.saltstack.sshKey", "test"); + SaltstackAdaptorPropertiesProvider propProvider = new SaltstackAdaptorPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adaptor = new SaltstackAdaptorImpl(propProvider); + String adaptorName = adaptor.getAdaptorName(); + assertEquals("Saltstack Adaptor", adaptorName); + } + + @Test + public void reqExecCommand_setPropertiesDefault() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + adaptor = new SaltstackAdaptorImpl(); + assertNotNull(adaptor); + } +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/model/TestJsonParser.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/model/TestJsonParser.java new file mode 100644 index 000000000..31ccaee9d --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/model/TestJsonParser.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.ali.adaptors.saltstack.model; + +import org.codehaus.jettison.json.JSONException; +import org.junit.Test; +import org.onap.ccsdk.sli.adaptors.saltstack.model.JsonParser; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import static org.junit.Assert.assertNotNull; + +public class TestJsonParser { + + private static final Logger log = LoggerFactory.getLogger(TestJsonParser.class); + + @Test + public void test() throws SvcLogicException, IOException, JSONException { + BufferedReader in = new BufferedReader( + new InputStreamReader(ClassLoader.getSystemResourceAsStream("test.json")) + ); + StringBuilder b = new StringBuilder(); + String line; + while ((line = in.readLine()) != null) + b.append(line).append('\n'); + + Map mm = JsonParser.convertToProperties(b.toString()); + + logProperties(mm); + + in.close(); + assertNotNull(mm); + } + + @Test(expected = NullPointerException.class) + public void testNullString() throws SvcLogicException, JSONException { + JsonParser.convertToProperties(null); + } + + private void logProperties(Map mm) { + List ll = new ArrayList<>(); + for (Object o : mm.keySet()) + ll.add((String) o); + Collections.sort(ll); + log.info("Properties:"); + for (String name : ll) + log.info("--- {}: {}", name, mm.get(name)); + } +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/config.sls b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/config.sls new file mode 100644 index 000000000..aff05939b --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/config.sls @@ -0,0 +1,2 @@ +vim: + pkg.installed diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/org/onap/ccsdk/default.properties b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/org/onap/ccsdk/default.properties new file mode 100644 index 000000000..ba54b4a53 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/org/onap/ccsdk/default.properties @@ -0,0 +1,102 @@ +### +# ============LICENSE_START======================================================= +# ONAP : CCSDK +# ================================================================================ +# Copyright (C) 2018 Samsung Electronics. All rights reserved. +# ================================================================================ +# +# ============================================================================= +# 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. +# +# +# ============LICENSE_END========================================================= +### +# +# Default properties for the APP-C Provider Adaptor +# +# ------------------------------------------------------------------------------------------------- +# +# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded +# to supply configuration options +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=/opt/onap/appc/data/properties,${user.home},. +appc.application.name=APPC +# +# Define the message resource bundle name to be loaded +org.onap.appc.resources=org/onap/appc/i18n/MessageResources +# +# The name of the adaptor. +org.onap.appc.provider.adaptor.name=org.onap.appc.appc_provider_adaptor +# +# Set up the logging environment +# +org.onap.appc.logging.file=org/onap/appc/logback.xml +org.onap.appc.logging.path=${user.home};etc;../etc +org.onap.appc.logger=org.onap.appc +org.onap.appc.security.logger=org.onap.appc.security +# +# The minimum and maximum provider/tenant context pool sizes. Min=1 means that as soon +# as the provider/tenant is referenced a Context is opened and added to the pool. Max=0 +# means that the upper bound on the pool is unbounded. +org.onap.appc.provider.min.pool=1 +org.onap.appc.provider.max.pool=0 +# +# The following properties are used to configure the retry logic for connection to the +# IaaS provider(s). The retry delay property is the amount of time, in seconds, the +# application waits between retry attempts. The retry limit is the number of retries +# that are allowed before the request is failed. +org.onap.appc.provider.retry.delay=30 +org.onap.appc.provider.retry.limit=10 +# +# The trusted hosts list for SSL access when a certificate is not provided. +# +provider.trusted.hosts=* +# +# The amount of time, in seconds, to wait for a server state change (start->stop, stop->start, etc). +# If the server does not change state to a valid state within the alloted time, the operation +# fails. +org.onap.appc.server.state.change.timeout=300 +# +# The amount of time to wait, in seconds, between subsequent polls to the OpenStack provider +# to refresh the status of a resource we are waiting on. +# +org.onap.appc.openstack.poll.interval=20 +# +# The connection information to connect to the provider we are using. These properties +# are "structured" properties, in that the name is a compound name, where the nodes +# of the name can be ordered (1, 2, 3, ...). All of the properties with the same ordinal +# position are defining the same entity. For example, provider1.type and provider1.name +# are defining the same provider, whereas provider2.name and provider2.type are defining +# the values for a different provider. Any number of providers can be defined in this +# way. +# +# Don't change these 2 right now since they are hard coded in the DG +#provider1.type=appc +#provider1.name=appc +#These you can change +#provider1.identity=appc +#provider1.tenant1.name=appc +#provider1.tenant1.userid=appc +#provider1.tenant1.password=appc +# After a change to the provider make sure to recheck these values with an api call to provider1.identity/tokens +test.expected-regions=1 +test.expected-endpoints=1 +#Your OpenStack IP +#test.ip=192.168.1.2 +# Your OpenStack Platform's Keystone Port (default is 5000) +#test.port=5000 +#test.tenantid=abcde12345fghijk6789lmnopq123rst +#test.vmid=abc12345-1234-5678-890a-abcdefg12345 +# Port 8774 below is default port for OpenStack's Nova API Service +#test.url=http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345 + diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test new file mode 100644 index 000000000..dec578bd9 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test @@ -0,0 +1,30 @@ +operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-egress-class-queueing-policing-codes.cos2v-queueing-code = P +operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-egress-class-queueing-policing-codes.cos3-queueing-code = W +operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-per-class-queueing-behaviors.cos2-queueing = WRED +operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-per-class-queueing-behaviors.cos2v-queueing = QueueLimit +operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing = WRED +operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-behaviors.cos2-shaping = Disable +operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-behaviors.cos2v-shaping = Enable +operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-behaviors.cos3-shaping = Disable +operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-codes.cos2-shaping-code = W +operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-codes.cos2v-shaping-code = P +service-configuration-notification-input.ack-final-indicator = Y +service-configuration-notification-input.response-code = 0 +service-configuration-notification-input.response-message = Plc Activation Failed: Device gblond2005me6 Sync-from Failed. Please check device IP address and NCS setup. +service-configuration-notification-input.service-information.service-instance-id = TEST7 +service-configuration-notification-input.service-information.service-type = AVPN +service-configuration-notification-input.svc-request-id = TEST7 +service-data.avpn-ip-port-information.avpn-access-information.access-circuit-id = DHEC.54831.170.ATI +service-data.avpn-ip-port-information.avpn-access-information.access-interface = _1G +service-data.avpn-ip-port-information.avpn-access-information.access-speed = 10000 +service-data.avpn-ip-port-information.avpn-access-information.access-speed-units = Kbps +service-data.avpn-ip-port-information.avpn-access-information.l1-customer-handoff = _1000BASELX +service-data.avpn-ip-port-information.avpn-access-information.managed-ce = N +service-data.avpn-ip-port-information.avpn-access-information.vlan-tag-control = _1Q +service-data.avpn-ip-port-information.clli = LONDENEH +service-data.avpn-ip-port-information.contracted-port-speed = 10000 +service-data.avpn-ip-port-information.contracted-port-speed-units = Kbps +service-data.avpn-ip-port-information.endpoint-information.bundle-id = 33 +service-data.avpn-ip-port-information.endpoint-information.interface-string = ae0 +service-data.service-information.service-instance-id = ICORESITE-2751508 +service-data.service-information.service-type = AVPN diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test-invalid.json b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test-invalid.json new file mode 100644 index 000000000..d16bfccdf --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test-invalid.json @@ -0,0 +1,29 @@ +"equipment-data": [ +{ +"server-count": "4", +"max-server-speed": "1600000", +"number-primary-servers": "2", +"equipment-id": "Server1", +"server-model": "Unknown", +"server-id": "Server1", +"test-node": { +"test-inner-node": "Test-Value" +} +} +], +"resource-state": { +"threshold-value": "1600000", +"last-added": "1605000", +"used": "1605000", +"limit-value": "1920000" +}, +"resource-rule": { +"endpoint-position": "VCE-Cust", +"soft-limit-expression": "0.6 * max-server-speed * number-primary-servers", +"resource-name": "Bandwidth", +"service-model": "DUMMY", +"hard-limit-expression": "max-server-speed * number-primary-servers", +"equipment-level": "Server" +}, +"message": "The provisioned access bandwidth is at or exceeds 50% of the total server capacity." +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test-sls.json b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test-sls.json new file mode 100644 index 000000000..bc1c10c8d --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test-sls.json @@ -0,0 +1,35 @@ +{ + "minion1": { + "retcode": 0, + "pkg_|-install_network_packages_|-install_network_packages_|-installed": { + "comment": "The following packages were installed/updated: lftp\nThe following packages were already installed: rsync, curl", + "name": "install_network_packages", + "start_time": "08:47:16.061765", + "result": true, + "duration": 11086.334, + "__run_num__": 0, + "__sls__": "nettools", + "changes": { + "lftp": { + "new": "4.6.3a-1build2", + "old": "" + } + }, + "__id__": "install_network_packages" + } + }, + "minion2": { + "retcode": 0, + "pkg_|-install_network_packages_|-install_network_packages_|-installed": { + "comment": "All specified packages are already installed", + "name": "curl", + "start_time": "08:47:16.152099", + "result": true, + "duration": 426.493, + "__run_num__": 0, + "__sls__": "nettools", + "changes": {}, + "__id__": "install_network_packages" + } + } +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test.json b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test.json new file mode 100644 index 000000000..81131d6f4 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test.json @@ -0,0 +1,30 @@ +{ + "equipment-data": [ + { + "server-count": "4", + "max-server-speed": "1600000", + "number-primary-servers": "2", + "equipment-id": "Server1", + "server-model": "Unknown", + "server-id": "Server1", + "test-node": { + "test-inner-node": "Test-Value" + } + } + ], + "resource-state": { + "threshold-value": "1600000", + "last-added": "1605000", + "used": "1605000", + "limit-value": "1920000" + }, + "resource-rule": { + "endpoint-position": "VCE-Cust", + "soft-limit-expression": "0.6 * max-server-speed * number-primary-servers", + "resource-name": "Bandwidth", + "service-model": "DUMMY", + "hard-limit-expression": "max-server-speed * number-primary-servers", + "equipment-level": "Server" + }, + "message": "The provisioned access bandwidth is at or exceeds 50% of the total server capacity." +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test.sls b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test.sls new file mode 100644 index 000000000..cd76486aa --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test.sls @@ -0,0 +1,30 @@ +{ + "equipment-data": [ + { + "server-count": "4", + "max-server-speed": "1600000", + "number-primary-servers": "2", + "equipment-id": "Server1", + "server-model": "Unknown", + "server-id": "Server1", + "test-node" : { + "test-inner-node" : "Test-Value" + } + } + ], + "resource-state": { + "threshold-value": "1600000", + "last-added": "1605000", + "used": "1605000", + "limit-value": "1920000" + }, + "resource-rule": { + "endpoint-position": "VCE-Cust", + "soft-limit-expression": "0.6 * max-server-speed * number-primary-servers", + "resource-name": "Bandwidth", + "service-model": "DUMMY", + "hard-limit-expression": "max-server-speed * number-primary-servers", + "equipment-level": "Server" + }, + "message": "The provisioned access bandwidth is at or exceeds 50% of the total server capacity." +} diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test.txt b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test.txt new file mode 100644 index 000000000..dec578bd9 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/resources/test.txt @@ -0,0 +1,30 @@ +operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-egress-class-queueing-policing-codes.cos2v-queueing-code = P +operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-egress-class-queueing-policing-codes.cos3-queueing-code = W +operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-per-class-queueing-behaviors.cos2-queueing = WRED +operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-per-class-queueing-behaviors.cos2v-queueing = QueueLimit +operational-data.avpn-ip-port-information.port-level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing = WRED +operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-behaviors.cos2-shaping = Disable +operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-behaviors.cos2v-shaping = Enable +operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-behaviors.cos3-shaping = Disable +operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-codes.cos2-shaping-code = W +operational-data.avpn-ip-port-information.port-level-cos.shaping.pe-egress-per-class-shaping-codes.cos2v-shaping-code = P +service-configuration-notification-input.ack-final-indicator = Y +service-configuration-notification-input.response-code = 0 +service-configuration-notification-input.response-message = Plc Activation Failed: Device gblond2005me6 Sync-from Failed. Please check device IP address and NCS setup. +service-configuration-notification-input.service-information.service-instance-id = TEST7 +service-configuration-notification-input.service-information.service-type = AVPN +service-configuration-notification-input.svc-request-id = TEST7 +service-data.avpn-ip-port-information.avpn-access-information.access-circuit-id = DHEC.54831.170.ATI +service-data.avpn-ip-port-information.avpn-access-information.access-interface = _1G +service-data.avpn-ip-port-information.avpn-access-information.access-speed = 10000 +service-data.avpn-ip-port-information.avpn-access-information.access-speed-units = Kbps +service-data.avpn-ip-port-information.avpn-access-information.l1-customer-handoff = _1000BASELX +service-data.avpn-ip-port-information.avpn-access-information.managed-ce = N +service-data.avpn-ip-port-information.avpn-access-information.vlan-tag-control = _1Q +service-data.avpn-ip-port-information.clli = LONDENEH +service-data.avpn-ip-port-information.contracted-port-speed = 10000 +service-data.avpn-ip-port-information.contracted-port-speed-units = Kbps +service-data.avpn-ip-port-information.endpoint-information.bundle-id = 33 +service-data.avpn-ip-port-information.endpoint-information.interface-string = ae0 +service-data.service-information.service-instance-id = ICORESITE-2751508 +service-data.service-information.service-type = AVPN diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exe-nonSLS.json b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exe-nonSLS.json new file mode 100644 index 000000000..c83b89d0e --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exe-nonSLS.json @@ -0,0 +1,203 @@ +[ + { + "id": "d86e7ee4.ee3f1", + "type": "method", + "name": "saltstack-adaptor-1.0", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 492, + "y": 216, + "z": "5945fc3c.78efc4", + "wires": [ + [ + "38662e01.1d3c22" + ] + ] + }, + { + "id": "9997883e.ec9028", + "type": "service-logic", + "name": "APPC 2.0.1", + "module": "APPC", + "version": "2.0.1", + "comments": "", + "xml": "", + "outputs": 1, + "x": 283, + "y": 289, + "z": "5945fc3c.78efc4", + "wires": [ + [ + "d86e7ee4.ee3f1" + ] + ] + }, + { + "id": "d40bf650.8338e8", + "type": "returnFailure", + "name": "return failure", + "xml": "\n\n\n\n", + "comments": "", + "x": 1007, + "y": 373, + "z": "5945fc3c.78efc4", + "wires": [] + }, + { + "id": "38662e01.1d3c22", + "type": "execute", + "name": "execute", + "xml": "\n \n \n \n \n \n \n \n \n", + "comments": "", + "outputs": 1, + "x": 700, + "y": 212, + "z": "5945fc3c.78efc4", + "wires": [ + [ + "7b75e382.6344dc", + "6f108926.d7baf8" + ] + ] + }, + { + "id": "24fb9f79.a6c6c", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 486, + "y": 372, + "z": "5945fc3c.78efc4", + "wires": [ + [ + "c526c44.c850738", + "9c394980.2a56a8" + ] + ] + }, + { + "id": "c526c44.c850738", + "type": "other", + "name": "outcome", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 675, + "y": 371, + "z": "5945fc3c.78efc4", + "wires": [ + [ + "d40bf650.8338e8" + ] + ] + }, + { + "id": "7b75e382.6344dc", + "type": "failure", + "name": "failure", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 951, + "y": 210, + "z": "5945fc3c.78efc4", + "wires": [ + [ + "d40bf650.8338e8" + ] + ] + }, + { + "id": "6f108926.d7baf8", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 298, + "y": 378, + "z": "5945fc3c.78efc4", + "wires": [ + [ + "24fb9f79.a6c6c" + ] + ] + }, + { + "id": "9c394980.2a56a8", + "type": "success", + "name": "success", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 667, + "y": 460, + "z": "5945fc3c.78efc4", + "wires": [ + [ + "1f81a3db.54cd1c" + ] + ] + }, + { + "id": "1f81a3db.54cd1c", + "type": "returnSuccess", + "name": "return success", + "xml": "\n\n\n\n", + "comments": "", + "x": 887, + "y": 460, + "z": "5945fc3c.78efc4", + "wires": [] + }, + { + "id": "fcad80f8.ba2d9", + "type": "dgstart", + "name": "DGSTART", + "outputs": 1, + "x": 261, + "y": 189, + "z": "5945fc3c.78efc4", + "wires": [ + [ + "9997883e.ec9028" + ] + ] + }, + { + "id": "b86e624d.49f0f", + "type": "comment", + "name": "SaltStack Adaptor DG", + "info": "", + "comments": "", + "x": 630, + "y": 75, + "z": "5945fc3c.78efc4", + "wires": [] + }, + { + "id": "83c0578d.061f98", + "type": "comment", + "name": "request-method = reqExecCommand, req-action = \"execute a single non SLS command\"", + "info": "", + "comments": "", + "x": 650, + "y": 155, + "z": "5945fc3c.78efc4", + "wires": [] + }, + { + "id": "f104feb6.558f7", + "type": "comment", + "name": "Assumptions for this DG", + "info": "Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controlls minion1 and minion2. ", + "comments": "", + "x": 627, + "y": 115, + "z": "5945fc3c.78efc4", + "wires": [] + } +] \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exe-nonSLS.xml b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exe-nonSLS.xml new file mode 100644 index 000000000..9c032f8c4 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exe-nonSLS.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-SLSFile.json b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-SLSFile.json new file mode 100644 index 000000000..050e3e8dd --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-SLSFile.json @@ -0,0 +1,350 @@ +[ + { + "id": "d0ad0305.352fc", + "type": "method", + "name": "saltstack-adaptor-1.0", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 552, + "y": 183, + "z": "b84dc629.83cd08", + "wires": [ + [ + "65cc87e2.a95188" + ] + ] + }, + { + "id": "22aefec.e8c7902", + "type": "service-logic", + "name": "APPC 2.0.1", + "module": "APPC", + "version": "2.0.1", + "comments": "", + "xml": "", + "outputs": 1, + "x": 343, + "y": 261, + "z": "b84dc629.83cd08", + "wires": [ + [ + "d0ad0305.352fc" + ] + ] + }, + { + "id": "31587001.4259e", + "type": "returnFailure", + "name": "return failure", + "xml": "\n\n\n\n", + "comments": "", + "x": 1262, + "y": 365, + "z": "b84dc629.83cd08", + "wires": [] + }, + { + "id": "65cc87e2.a95188", + "type": "execute", + "name": "execute", + "xml": "\n \n \n \n \n \n \n \n \n", + "comments": "", + "outputs": 1, + "x": 761, + "y": 185, + "z": "b84dc629.83cd08", + "wires": [ + [ + "f9bf6ee7.cf954", + "7b51c357.a852cc" + ] + ] + }, + { + "id": "42fa1258.aa570c", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 544, + "y": 345, + "z": "b84dc629.83cd08", + "wires": [ + [ + "a7cf236a.84c03", + "c45d597b.20b4c8" + ] + ] + }, + { + "id": "a7cf236a.84c03", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 735, + "y": 343, + "z": "b84dc629.83cd08", + "wires": [ + [ + "31587001.4259e" + ] + ] + }, + { + "id": "f9bf6ee7.cf954", + "type": "failure", + "name": "failure", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 1011, + "y": 182, + "z": "b84dc629.83cd08", + "wires": [ + [ + "31587001.4259e" + ] + ] + }, + { + "id": "7b51c357.a852cc", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 366, + "y": 343, + "z": "b84dc629.83cd08", + "wires": [ + [ + "42fa1258.aa570c" + ] + ] + }, + { + "id": "c45d597b.20b4c8", + "type": "success", + "name": "success", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 351, + "y": 459, + "z": "b84dc629.83cd08", + "wires": [ + [ + "30d5f0f7.0e3c8" + ] + ] + }, + { + "id": "2856792.c401a86", + "type": "returnSuccess", + "name": "return success", + "xml": "\n\n\n\n", + "comments": "", + "x": 1042, + "y": 656, + "z": "b84dc629.83cd08", + "wires": [] + }, + { + "id": "6c359fdc.3b566", + "type": "dgstart", + "name": "DGSTART", + "outputs": 1, + "x": 321, + "y": 161, + "z": "b84dc629.83cd08", + "wires": [ + [ + "22aefec.e8c7902" + ] + ] + }, + { + "id": "b5342c59.29f74", + "type": "comment", + "name": "SaltStack Adaptor DG", + "info": "", + "comments": "", + "x": 693, + "y": 44, + "z": "b84dc629.83cd08", + "wires": [] + }, + { + "id": "19202194.8ff55e", + "type": "comment", + "name": "request-method = reqExecCommand, req-action = \"execute multiple SLS commands\"", + "info": "Here we basically test if minion1 is active by pinging to it, then install vim package to it. \n", + "comments": "", + "x": 711, + "y": 127, + "z": "b84dc629.83cd08", + "wires": [] + }, + { + "id": "a2ebc17e.fa03a", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 396, + "y": 661, + "z": "b84dc629.83cd08", + "wires": [ + [ + "c9345fbb.d6d19" + ] + ] + }, + { + "id": "770411a5.18825", + "type": "execute", + "name": "execute", + "xml": "\n \n \n \n \n \n \n \n \n", + "comments": "", + "outputs": 1, + "x": 773, + "y": 548, + "z": "b84dc629.83cd08", + "wires": [ + [ + "e09a3e12.87428", + "a2ebc17e.fa03a" + ] + ] + }, + { + "id": "e09a3e12.87428", + "type": "failure", + "name": "failure", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 991, + "y": 554, + "z": "b84dc629.83cd08", + "wires": [ + [ + "31587001.4259e" + ] + ] + }, + { + "id": "c9345fbb.d6d19", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 578, + "y": 658, + "z": "b84dc629.83cd08", + "wires": [ + [ + "485e453d.36c75c", + "f1adcf2a.2c456" + ] + ] + }, + { + "id": "485e453d.36c75c", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 783, + "y": 732, + "z": "b84dc629.83cd08", + "wires": [ + [ + "31587001.4259e" + ] + ] + }, + { + "id": "f1adcf2a.2c456", + "type": "success", + "name": "success", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 776, + "y": 658, + "z": "b84dc629.83cd08", + "wires": [ + [ + "2856792.c401a86" + ] + ] + }, + { + "id": "30d5f0f7.0e3c8", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 523, + "y": 459, + "z": "b84dc629.83cd08", + "wires": [ + [ + "15e9ff68.9812a1", + "17d9d7e.4d9a928" + ] + ] + }, + { + "id": "17d9d7e.4d9a928", + "type": "other", + "name": "outcome", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 593, + "y": 550, + "z": "b84dc629.83cd08", + "wires": [ + [ + "770411a5.18825" + ] + ] + }, + { + "id": "15e9ff68.9812a1", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 717, + "y": 459, + "z": "b84dc629.83cd08", + "wires": [ + [ + "31587001.4259e" + ] + ] + }, + { + "id": "b764890c.ed0018", + "type": "comment", + "name": "Assumptions for this DG (example-server)", + "info": "1) Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controlls minion1 and minion2. \n2) We assume that sls file called vim.sls is already present in the path /srv/salt on the server.", + "comments": "", + "x": 693, + "y": 86, + "z": "b84dc629.83cd08", + "wires": [] + } +] \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-SLSFile.xml b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-SLSFile.xml new file mode 100644 index 000000000..85a6a5b67 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-SLSFile.xml @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-multi-sls.json b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-multi-sls.json new file mode 100644 index 000000000..6b465c437 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-multi-sls.json @@ -0,0 +1,399 @@ +[ + { + "id": "65f5c0d6.9c4ce", + "type": "method", + "name": "saltstack-adaptor-1.0", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 615, + "y": 273, + "z": "6df02477.0463cc", + "wires": [ + [ + "c332cb01.51a3e8" + ] + ] + }, + { + "id": "bf71bd6e.1be5b", + "type": "service-logic", + "name": "APPC 2.0.1", + "module": "APPC", + "version": "2.0.1", + "comments": "", + "xml": "", + "outputs": 1, + "x": 406, + "y": 351, + "z": "6df02477.0463cc", + "wires": [ + [ + "65f5c0d6.9c4ce" + ] + ] + }, + { + "id": "40ce8a6.5f7d174", + "type": "returnFailure", + "name": "return failure", + "xml": "\n\n\n\n", + "comments": "", + "x": 1325, + "y": 455, + "z": "6df02477.0463cc", + "wires": [] + }, + { + "id": "c332cb01.51a3e8", + "type": "execute", + "name": "execute", + "xml": "\n \n \n \n \n \n \n \n \n", + "comments": "", + "outputs": 1, + "x": 824, + "y": 275, + "z": "6df02477.0463cc", + "wires": [ + [ + "5b387684.e51be8", + "4bb6b32e.adfc2c" + ] + ] + }, + { + "id": "16dfbd4f.b6da73", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 607, + "y": 435, + "z": "6df02477.0463cc", + "wires": [ + [ + "24d22f52.ef59a", + "ac765880.a6c548" + ] + ] + }, + { + "id": "24d22f52.ef59a", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 798, + "y": 433, + "z": "6df02477.0463cc", + "wires": [ + [ + "40ce8a6.5f7d174" + ] + ] + }, + { + "id": "5b387684.e51be8", + "type": "failure", + "name": "failure", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 1074, + "y": 272, + "z": "6df02477.0463cc", + "wires": [ + [ + "40ce8a6.5f7d174" + ] + ] + }, + { + "id": "4bb6b32e.adfc2c", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 429, + "y": 433, + "z": "6df02477.0463cc", + "wires": [ + [ + "16dfbd4f.b6da73" + ] + ] + }, + { + "id": "ac765880.a6c548", + "type": "success", + "name": "success", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 414, + "y": 549, + "z": "6df02477.0463cc", + "wires": [ + [ + "2dda30fc.8747" + ] + ] + }, + { + "id": "e45accfe.91615", + "type": "returnSuccess", + "name": "return success", + "xml": "\n\n\n\n", + "comments": "", + "x": 1345, + "y": 757, + "z": "6df02477.0463cc", + "wires": [] + }, + { + "id": "11a891ad.55bc1e", + "type": "dgstart", + "name": "DGSTART", + "outputs": 1, + "x": 384, + "y": 251, + "z": "6df02477.0463cc", + "wires": [ + [ + "bf71bd6e.1be5b" + ] + ] + }, + { + "id": "a56383b.496c48", + "type": "comment", + "name": "SaltStack Adaptor DG", + "info": "", + "comments": "", + "x": 756, + "y": 134, + "z": "6df02477.0463cc", + "wires": [] + }, + { + "id": "cfda30b5.5e166", + "type": "comment", + "name": "request-method = reqExecCommand, req-action = \"execute multiple SLS commands\"", + "info": "Here we basically test if minion1 is active by pinging to it, then install vim package to it. \n", + "comments": "", + "x": 773, + "y": 217, + "z": "6df02477.0463cc", + "wires": [] + }, + { + "id": "a8efb922.f23ce8", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 459, + "y": 751, + "z": "6df02477.0463cc", + "wires": [ + [ + "3ff32215.20cd0e" + ] + ] + }, + { + "id": "df0c0907.d17838", + "type": "execute", + "name": "execute", + "xml": "\n \n \n \n \n \n \n \n \n", + "comments": "", + "outputs": 1, + "x": 836, + "y": 638, + "z": "6df02477.0463cc", + "wires": [ + [ + "1e5bbe2e.9cbb82", + "a8efb922.f23ce8" + ] + ] + }, + { + "id": "1e5bbe2e.9cbb82", + "type": "failure", + "name": "failure", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 1054, + "y": 644, + "z": "6df02477.0463cc", + "wires": [ + [ + "40ce8a6.5f7d174" + ] + ] + }, + { + "id": "3ff32215.20cd0e", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 647, + "y": 745, + "z": "6df02477.0463cc", + "wires": [ + [ + "8e2c712b.784b4", + "3d74cfe5.d41f5" + ] + ] + }, + { + "id": "8e2c712b.784b4", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 830, + "y": 823, + "z": "6df02477.0463cc", + "wires": [ + [ + "40ce8a6.5f7d174" + ] + ] + }, + { + "id": "3d74cfe5.d41f5", + "type": "success", + "name": "success", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 829, + "y": 758, + "z": "6df02477.0463cc", + "wires": [ + [ + "8313564b.004798" + ] + ] + }, + { + "id": "2dda30fc.8747", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 586, + "y": 549, + "z": "6df02477.0463cc", + "wires": [ + [ + "e0133af5.2ca028", + "7f28f521.cf47cc" + ] + ] + }, + { + "id": "7f28f521.cf47cc", + "type": "other", + "name": "outcome", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 656, + "y": 640, + "z": "6df02477.0463cc", + "wires": [ + [ + "df0c0907.d17838" + ] + ] + }, + { + "id": "e0133af5.2ca028", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 780, + "y": 549, + "z": "6df02477.0463cc", + "wires": [ + [ + "40ce8a6.5f7d174" + ] + ] + }, + { + "id": "8313564b.004798", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 986, + "y": 752, + "z": "6df02477.0463cc", + "wires": [ + [ + "13d18d2d.71fbf3", + "2e940add.522a36" + ] + ] + }, + { + "id": "13d18d2d.71fbf3", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 1165, + "y": 825, + "z": "6df02477.0463cc", + "wires": [ + [ + "40ce8a6.5f7d174" + ] + ] + }, + { + "id": "2e940add.522a36", + "type": "success", + "name": "success", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 1156, + "y": 754, + "z": "6df02477.0463cc", + "wires": [ + [ + "e45accfe.91615" + ] + ] + }, + { + "id": "6d6678d2.6a9bd8", + "type": "comment", + "name": "Assumptions for this DG (example-server)", + "info": "Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controlls minion1 and minion2. ", + "comments": "", + "x": 756, + "y": 173, + "z": "6df02477.0463cc", + "wires": [] + } +] \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-multi-sls.xml b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-multi-sls.xml new file mode 100644 index 000000000..062ffaab3 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-multi-sls.xml @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-single-SLSComm.json b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-single-SLSComm.json new file mode 100644 index 000000000..f9b103cb1 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-single-SLSComm.json @@ -0,0 +1,203 @@ +[ + { + "id": "bd0f1105.ff214", + "type": "method", + "name": "saltstack-adaptor-1.0", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 526, + "y": 238, + "z": "c053ae12.4067b", + "wires": [ + [ + "f4e59dd0.ee45f" + ] + ] + }, + { + "id": "26f2a2b8.90f58e", + "type": "service-logic", + "name": "APPC 2.0.1", + "module": "APPC", + "version": "2.0.1", + "comments": "", + "xml": "", + "outputs": 1, + "x": 317, + "y": 316, + "z": "c053ae12.4067b", + "wires": [ + [ + "bd0f1105.ff214" + ] + ] + }, + { + "id": "55a7736.2789e8c", + "type": "returnFailure", + "name": "return failure", + "xml": "\n\n\n\n", + "comments": "", + "x": 1064, + "y": 453, + "z": "c053ae12.4067b", + "wires": [] + }, + { + "id": "f4e59dd0.ee45f", + "type": "execute", + "name": "execute", + "xml": "\n \n \n \n \n \n \n \n \n", + "comments": "", + "outputs": 1, + "x": 735, + "y": 240, + "z": "c053ae12.4067b", + "wires": [ + [ + "93fca622.05ad58", + "7ce4a659.44c828" + ] + ] + }, + { + "id": "2ceb37d9.a8ba18", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 522, + "y": 398, + "z": "c053ae12.4067b", + "wires": [ + [ + "cd89356c.279678", + "781026e2.01d498" + ] + ] + }, + { + "id": "cd89356c.279678", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 708, + "y": 456, + "z": "c053ae12.4067b", + "wires": [ + [ + "55a7736.2789e8c" + ] + ] + }, + { + "id": "93fca622.05ad58", + "type": "failure", + "name": "failure", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 985, + "y": 237, + "z": "c053ae12.4067b", + "wires": [ + [ + "55a7736.2789e8c" + ] + ] + }, + { + "id": "7ce4a659.44c828", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 332, + "y": 405, + "z": "c053ae12.4067b", + "wires": [ + [ + "2ceb37d9.a8ba18" + ] + ] + }, + { + "id": "781026e2.01d498", + "type": "success", + "name": "success", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 711, + "y": 398, + "z": "c053ae12.4067b", + "wires": [ + [ + "ce510062.8dcc7" + ] + ] + }, + { + "id": "ce510062.8dcc7", + "type": "returnSuccess", + "name": "return success", + "xml": "\n\n\n\n", + "comments": "", + "x": 893, + "y": 399, + "z": "c053ae12.4067b", + "wires": [] + }, + { + "id": "593bd7fb.675368", + "type": "dgstart", + "name": "DGSTART", + "outputs": 1, + "x": 295, + "y": 216, + "z": "c053ae12.4067b", + "wires": [ + [ + "26f2a2b8.90f58e" + ] + ] + }, + { + "id": "901c8408.5fecb8", + "type": "comment", + "name": "SaltStack Adaptor DG", + "info": "", + "comments": "", + "x": 673, + "y": 103, + "z": "c053ae12.4067b", + "wires": [] + }, + { + "id": "cc449713.a1be88", + "type": "comment", + "name": "request-method = reqExecCommand, req-action = \"execute a single SLS command\"", + "info": "Here we just ping to all the minions, and we dont even check if the minions are active. ", + "comments": "", + "x": 684, + "y": 188, + "z": "c053ae12.4067b", + "wires": [] + }, + { + "id": "c07fa80e.7f3ac8", + "type": "comment", + "name": "Assumptions for this DG (example-server)", + "info": "Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controlls minion1 and minion2. ", + "comments": "", + "x": 676, + "y": 144, + "z": "c053ae12.4067b", + "wires": [] + } +] \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-single-SLSComm.xml b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-single-SLSComm.xml new file mode 100644 index 000000000..5a164d222 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecCommand/APPC_saltstack-adaptor-1.0-exec-single-SLSComm.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0 IDEAL.json b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0 IDEAL.json new file mode 100644 index 000000000..c312afcd0 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0 IDEAL.json @@ -0,0 +1,214 @@ +[ + { + "id": "80b83851.e527b8", + "type": "method", + "name": "saltstack-adaptor-1.0", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 676, + "y": 277, + "z": "1f6661d7.1ebd2e", + "wires": [ + [ + "83c8d47e.cb9c98" + ] + ] + }, + { + "id": "41231c44.5d1324", + "type": "service-logic", + "name": "APPC 2.0.1", + "module": "APPC", + "version": "2.0.1", + "comments": "", + "xml": "", + "outputs": 1, + "x": 453, + "y": 276, + "z": "1f6661d7.1ebd2e", + "wires": [ + [ + "80b83851.e527b8" + ] + ] + }, + { + "id": "1f4a794d.fb3be7", + "type": "returnSuccess", + "name": "return success", + "xml": "\n\n\n\n", + "comments": "", + "x": 1055, + "y": 369, + "z": "1f6661d7.1ebd2e", + "wires": [] + }, + { + "id": "5a85036.5a9e2fc", + "type": "dgstart", + "name": "DGSTART", + "outputs": 1, + "x": 284, + "y": 275, + "z": "1f6661d7.1ebd2e", + "wires": [ + [ + "41231c44.5d1324" + ] + ] + }, + { + "id": "b38fc61c.a23438", + "type": "comment", + "name": "SaltStack Adaptor DG", + "info": "", + "comments": "", + "x": 661, + "y": 154, + "z": "1f6661d7.1ebd2e", + "wires": [] + }, + { + "id": "6a821d83.4070e4", + "type": "comment", + "name": "request-method = reqExecSLS, req-action = \"execute SLS\"", + "info": "This would be the ideal adaptor the orchestrator DG will call, this just takes in SlsName.", + "comments": "", + "x": 672, + "y": 239, + "z": "1f6661d7.1ebd2e", + "wires": [] + }, + { + "id": "ba16960c.36bad8", + "type": "comment", + "name": "Assumptions for this DG (example-server)", + "info": "Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controllers minion1 and minion2. ", + "comments": "", + "x": 664, + "y": 195, + "z": "1f6661d7.1ebd2e", + "wires": [] + }, + { + "id": "83c8d47e.cb9c98", + "type": "execute", + "name": "execute", + "xml": "\n \n \n \n \n \n \n \n \n \n \n", + "comments": "", + "outputs": 1, + "x": 366, + "y": 406, + "z": "1f6661d7.1ebd2e", + "wires": [ + [ + "b83f5a23.33f938", + "3354190.eb450e8" + ] + ] + }, + { + "id": "b83f5a23.33f938", + "type": "failure", + "name": "failure", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 559, + "y": 367, + "z": "1f6661d7.1ebd2e", + "wires": [ + [ + "efc02e73.0cf1d" + ] + ] + }, + { + "id": "3354190.eb450e8", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 557, + "y": 439, + "z": "1f6661d7.1ebd2e", + "wires": [ + [ + "88b53985.e42758" + ] + ] + }, + { + "id": "88b53985.e42758", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 709, + "y": 427, + "z": "1f6661d7.1ebd2e", + "wires": [ + [ + "195a294e.61efb7", + "bc1bfd78.146bc" + ] + ] + }, + { + "id": "bc1bfd78.146bc", + "type": "success", + "name": "success", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 872, + "y": 373, + "z": "1f6661d7.1ebd2e", + "wires": [ + [ + "1f4a794d.fb3be7" + ] + ] + }, + { + "id": "195a294e.61efb7", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 869, + "y": 442, + "z": "1f6661d7.1ebd2e", + "wires": [ + [ + "81ddc2e0.dce24" + ] + ] + }, + { + "id": "efc02e73.0cf1d", + "type": "returnFailure", + "name": "return failure", + "xml": "\n\n\n\n", + "comments": "", + "x": 719, + "y": 351, + "z": "1f6661d7.1ebd2e", + "wires": [] + }, + { + "id": "81ddc2e0.dce24", + "type": "returnFailure", + "name": "return failure", + "xml": "\n\n\n\n", + "comments": "", + "x": 1039, + "y": 439, + "z": "1f6661d7.1ebd2e", + "wires": [] + } +] \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0 IDEAL.xml b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0 IDEAL.xml new file mode 100644 index 000000000..b83cf18bc --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0 IDEAL.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0-exec-SLS-applyTo.json b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0-exec-SLS-applyTo.json new file mode 100644 index 000000000..1ef8af218 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0-exec-SLS-applyTo.json @@ -0,0 +1,372 @@ +[ + { + "id": "edb39979.b1ccd8", + "type": "method", + "name": "saltstack-adaptor-1.0", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 476, + "y": 245, + "z": "671ca899.284f68", + "wires": [ + [ + "95c9ba42.6e4aa8" + ] + ] + }, + { + "id": "a16ea11e.f8d1c", + "type": "service-logic", + "name": "APPC 2.0.1", + "module": "APPC", + "version": "2.0.1", + "comments": "", + "xml": "", + "outputs": 1, + "x": 267, + "y": 323, + "z": "671ca899.284f68", + "wires": [ + [ + "edb39979.b1ccd8" + ] + ] + }, + { + "id": "1591f92e.029ca7", + "type": "returnFailure", + "name": "return failure", + "xml": "\n\n\n\n", + "comments": "", + "x": 1191, + "y": 315, + "z": "671ca899.284f68", + "wires": [] + }, + { + "id": "95c9ba42.6e4aa8", + "type": "execute", + "name": "execute", + "xml": "\n \n \n \n \n \n \n \n \n", + "comments": "", + "outputs": 1, + "x": 684, + "y": 251, + "z": "671ca899.284f68", + "wires": [ + [ + "cd0c458a.2430b8", + "69e531e3.4efc3" + ] + ] + }, + { + "id": "38b44d70.9c85d2", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 472, + "y": 405, + "z": "671ca899.284f68", + "wires": [ + [ + "505df598.069b9c", + "5d7292e.22ec06c" + ] + ] + }, + { + "id": "505df598.069b9c", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 658, + "y": 463, + "z": "671ca899.284f68", + "wires": [ + [ + "1591f92e.029ca7" + ] + ] + }, + { + "id": "cd0c458a.2430b8", + "type": "failure", + "name": "failure", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 935, + "y": 244, + "z": "671ca899.284f68", + "wires": [ + [ + "1591f92e.029ca7" + ] + ] + }, + { + "id": "69e531e3.4efc3", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 282, + "y": 412, + "z": "671ca899.284f68", + "wires": [ + [ + "38b44d70.9c85d2" + ] + ] + }, + { + "id": "5d7292e.22ec06c", + "type": "success", + "name": "success", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 661, + "y": 405, + "z": "671ca899.284f68", + "wires": [ + [ + "c9df0cea.f2361" + ] + ] + }, + { + "id": "e4f7eb59.0abb58", + "type": "returnSuccess", + "name": "return success", + "xml": "\n\n\n\n", + "comments": "", + "x": 1079, + "y": 564, + "z": "671ca899.284f68", + "wires": [] + }, + { + "id": "8e586da4.570f1", + "type": "dgstart", + "name": "DGSTART", + "outputs": 1, + "x": 245, + "y": 223, + "z": "671ca899.284f68", + "wires": [ + [ + "a16ea11e.f8d1c" + ] + ] + }, + { + "id": "71387074.137c1", + "type": "comment", + "name": "SaltStack Adaptor DG", + "info": "", + "comments": "", + "x": 623, + "y": 110, + "z": "671ca899.284f68", + "wires": [] + }, + { + "id": "c5e8c62d.021758", + "type": "comment", + "name": "request-method = reqExecSLS, req-action = \"execute SLS\"", + "info": "Here we basically test if minion1 is active by pinging to it, then respective sls file is executed on to it. \n", + "comments": "", + "x": 634, + "y": 195, + "z": "671ca899.284f68", + "wires": [] + }, + { + "id": "1805797.a241487", + "type": "comment", + "name": "Assumptions for this DG (example-server)", + "info": "Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controllers minion1 and minion2. ", + "comments": "", + "x": 626, + "y": 151, + "z": "671ca899.284f68", + "wires": [] + }, + { + "id": "c9df0cea.f2361", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 825, + "y": 405, + "z": "671ca899.284f68", + "wires": [ + [ + "d83d6024.2454d", + "f4d70bbc.f0bc38" + ] + ] + }, + { + "id": "d83d6024.2454d", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 991, + "y": 459, + "z": "671ca899.284f68", + "wires": [ + [ + "1591f92e.029ca7" + ] + ] + }, + { + "id": "f4d70bbc.f0bc38", + "type": "other", + "name": "outcome", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 994, + "y": 401, + "z": "671ca899.284f68", + "wires": [ + [ + "e86d9995.b65c58" + ] + ] + }, + { + "id": "e86d9995.b65c58", + "type": "execute", + "name": "execute", + "xml": "\n \n \n \n \n \n \n \n \n", + "comments": "", + "outputs": 1, + "x": 398, + "y": 593, + "z": "671ca899.284f68", + "wires": [ + [ + "89ff1c2a.08f52", + "e20c4c85.43d3c" + ] + ] + }, + { + "id": "89ff1c2a.08f52", + "type": "failure", + "name": "failure", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 583, + "y": 562, + "z": "671ca899.284f68", + "wires": [ + [ + "6032e33e.5b044c" + ] + ] + }, + { + "id": "e20c4c85.43d3c", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 581, + "y": 634, + "z": "671ca899.284f68", + "wires": [ + [ + "8bb4c177.499c8" + ] + ] + }, + { + "id": "8bb4c177.499c8", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 733, + "y": 622, + "z": "671ca899.284f68", + "wires": [ + [ + "905334fe.934d68", + "9c217c10.9d539" + ] + ] + }, + { + "id": "9c217c10.9d539", + "type": "success", + "name": "success", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 896, + "y": 568, + "z": "671ca899.284f68", + "wires": [ + [ + "e4f7eb59.0abb58" + ] + ] + }, + { + "id": "905334fe.934d68", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 893, + "y": 637, + "z": "671ca899.284f68", + "wires": [ + [ + "7026a88c.5bffd8" + ] + ] + }, + { + "id": "6032e33e.5b044c", + "type": "returnFailure", + "name": "return failure", + "xml": "\n\n\n\n", + "comments": "", + "x": 735, + "y": 559, + "z": "671ca899.284f68", + "wires": [] + }, + { + "id": "7026a88c.5bffd8", + "type": "returnFailure", + "name": "return failure", + "xml": "\n\n\n\n", + "comments": "", + "x": 1054, + "y": 637, + "z": "671ca899.284f68", + "wires": [] + } +] \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0-exec-SLS-applyTo.xml b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0-exec-SLS-applyTo.xml new file mode 100644 index 000000000..096a39b3d --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLS/APPC_saltstack-adaptor-1.0-exec-SLS-applyTo.xml @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-SLSFILE.json b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-SLSFILE.json new file mode 100644 index 000000000..63b60c62c --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-SLSFILE.json @@ -0,0 +1,214 @@ +[ + { + "id": "3228200a.5dc1a", + "type": "method", + "name": "saltstack-adaptor-1.0", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 679, + "y": 282, + "z": "6d4f912d.f07bc", + "wires": [ + [ + "50b2729f.712eac" + ] + ] + }, + { + "id": "9fb54163.4fb28", + "type": "service-logic", + "name": "APPC 2.0.1", + "module": "APPC", + "version": "2.0.1", + "comments": "", + "xml": "", + "outputs": 1, + "x": 456, + "y": 281, + "z": "6d4f912d.f07bc", + "wires": [ + [ + "3228200a.5dc1a" + ] + ] + }, + { + "id": "49109fbc.a7a14", + "type": "returnSuccess", + "name": "return success", + "xml": "\n\n\n\n", + "comments": "", + "x": 1058, + "y": 374, + "z": "6d4f912d.f07bc", + "wires": [] + }, + { + "id": "d030a396.56232", + "type": "dgstart", + "name": "DGSTART", + "outputs": 1, + "x": 287, + "y": 280, + "z": "6d4f912d.f07bc", + "wires": [ + [ + "9fb54163.4fb28" + ] + ] + }, + { + "id": "281900c4.fd3e8", + "type": "comment", + "name": "SaltStack Adaptor DG", + "info": "", + "comments": "", + "x": 664, + "y": 159, + "z": "6d4f912d.f07bc", + "wires": [] + }, + { + "id": "431a69db.2d2c58", + "type": "comment", + "name": "request-method = reqExecSLS, req-action = \"execute SLS\"", + "info": "This would be the ideal adaptor the orchestrator DG will call, this just takes in SlsName.", + "comments": "", + "x": 675, + "y": 244, + "z": "6d4f912d.f07bc", + "wires": [] + }, + { + "id": "4202e1ce.09495", + "type": "comment", + "name": "Assumptions for this DG (example-server)", + "info": "Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controllers minion1 and minion2. ", + "comments": "", + "x": 667, + "y": 200, + "z": "6d4f912d.f07bc", + "wires": [] + }, + { + "id": "50b2729f.712eac", + "type": "execute", + "name": "execute", + "xml": "\n \n \n \n \n \n \n", + "comments": "", + "outputs": 1, + "x": 369, + "y": 411, + "z": "6d4f912d.f07bc", + "wires": [ + [ + "71746570.35f0dc", + "3e4f7a4a.ae0dc6" + ] + ] + }, + { + "id": "71746570.35f0dc", + "type": "failure", + "name": "failure", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 562, + "y": 372, + "z": "6d4f912d.f07bc", + "wires": [ + [ + "e59a1a81.112a08" + ] + ] + }, + { + "id": "3e4f7a4a.ae0dc6", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 560, + "y": 444, + "z": "6d4f912d.f07bc", + "wires": [ + [ + "59e320fa.12908" + ] + ] + }, + { + "id": "59e320fa.12908", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 712, + "y": 432, + "z": "6d4f912d.f07bc", + "wires": [ + [ + "f81ed07.2135c3", + "eb55b5a9.f0d2f8" + ] + ] + }, + { + "id": "eb55b5a9.f0d2f8", + "type": "success", + "name": "success", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 875, + "y": 378, + "z": "6d4f912d.f07bc", + "wires": [ + [ + "49109fbc.a7a14" + ] + ] + }, + { + "id": "f81ed07.2135c3", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 872, + "y": 447, + "z": "6d4f912d.f07bc", + "wires": [ + [ + "6549631f.8e516c" + ] + ] + }, + { + "id": "e59a1a81.112a08", + "type": "returnFailure", + "name": "return failure", + "xml": "\n\n\n\n", + "comments": "", + "x": 722, + "y": 356, + "z": "6d4f912d.f07bc", + "wires": [] + }, + { + "id": "6549631f.8e516c", + "type": "returnFailure", + "name": "return failure", + "xml": "\n\n\n\n", + "comments": "", + "x": 1042, + "y": 444, + "z": "6d4f912d.f07bc", + "wires": [] + } +] \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-SLSFILE.xml b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-SLSFILE.xml new file mode 100644 index 000000000..996cded80 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-SLSFILE.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-exec-SLSFile-applyTo.json b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-exec-SLSFile-applyTo.json new file mode 100644 index 000000000..4abd80a40 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-exec-SLSFile-applyTo.json @@ -0,0 +1,372 @@ +[ + { + "id": "9a6bf94f.d969f8", + "type": "method", + "name": "saltstack-adaptor-1.0", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 498, + "y": 240, + "z": "723548c7.652d78", + "wires": [ + [ + "138ad7ed.403248" + ] + ] + }, + { + "id": "4bb87049.3f546", + "type": "service-logic", + "name": "APPC 2.0.1", + "module": "APPC", + "version": "2.0.1", + "comments": "", + "xml": "", + "outputs": 1, + "x": 289, + "y": 318, + "z": "723548c7.652d78", + "wires": [ + [ + "9a6bf94f.d969f8" + ] + ] + }, + { + "id": "6c593992.106038", + "type": "returnFailure", + "name": "return failure", + "xml": "\n\n\n\n", + "comments": "", + "x": 1202, + "y": 280, + "z": "723548c7.652d78", + "wires": [] + }, + { + "id": "138ad7ed.403248", + "type": "execute", + "name": "execute", + "xml": "\n \n \n \n \n \n \n \n \n", + "comments": "", + "outputs": 1, + "x": 706, + "y": 246, + "z": "723548c7.652d78", + "wires": [ + [ + "167273ed.f0577c", + "954a34ea.701368" + ] + ] + }, + { + "id": "d5841e65.537ba", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 494, + "y": 400, + "z": "723548c7.652d78", + "wires": [ + [ + "ede42371.2f52b", + "d306d7a0.c830e8" + ] + ] + }, + { + "id": "ede42371.2f52b", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 680, + "y": 458, + "z": "723548c7.652d78", + "wires": [ + [ + "6c593992.106038" + ] + ] + }, + { + "id": "167273ed.f0577c", + "type": "failure", + "name": "failure", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 957, + "y": 239, + "z": "723548c7.652d78", + "wires": [ + [ + "6c593992.106038" + ] + ] + }, + { + "id": "954a34ea.701368", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 304, + "y": 407, + "z": "723548c7.652d78", + "wires": [ + [ + "d5841e65.537ba" + ] + ] + }, + { + "id": "d306d7a0.c830e8", + "type": "success", + "name": "success", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 683, + "y": 400, + "z": "723548c7.652d78", + "wires": [ + [ + "5b12ba31.94b3b4" + ] + ] + }, + { + "id": "9ef7fcc3.69279", + "type": "returnSuccess", + "name": "return success", + "xml": "\n\n\n\n", + "comments": "", + "x": 1101, + "y": 559, + "z": "723548c7.652d78", + "wires": [] + }, + { + "id": "7803eeaf.1e31d", + "type": "dgstart", + "name": "DGSTART", + "outputs": 1, + "x": 267, + "y": 218, + "z": "723548c7.652d78", + "wires": [ + [ + "4bb87049.3f546" + ] + ] + }, + { + "id": "9c6f1e7c.2a3d9", + "type": "comment", + "name": "SaltStack Adaptor DG", + "info": "", + "comments": "", + "x": 645, + "y": 105, + "z": "723548c7.652d78", + "wires": [] + }, + { + "id": "93ea02a5.4e792", + "type": "comment", + "name": "request-method = reqExecSLS, req-action = \"execute SLS FILE\"", + "info": "Here we basically test if minion1 is active by pinging to it, then respective sls file is executed on to it. \n", + "comments": "", + "x": 656, + "y": 190, + "z": "723548c7.652d78", + "wires": [] + }, + { + "id": "243edbf.f35fc24", + "type": "comment", + "name": "Assumptions for this DG (example-server)", + "info": "Here we assume, the saltstack server is the example-vagrant based server. Where, the master saltstact controllers minion1 and minion2. ", + "comments": "", + "x": 648, + "y": 146, + "z": "723548c7.652d78", + "wires": [] + }, + { + "id": "5b12ba31.94b3b4", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 847, + "y": 400, + "z": "723548c7.652d78", + "wires": [ + [ + "9bf0915.96f217", + "f6e533d.95d99d" + ] + ] + }, + { + "id": "9bf0915.96f217", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 1013, + "y": 454, + "z": "723548c7.652d78", + "wires": [ + [ + "6c593992.106038" + ] + ] + }, + { + "id": "f6e533d.95d99d", + "type": "other", + "name": "outcome", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 1016, + "y": 396, + "z": "723548c7.652d78", + "wires": [ + [ + "eb57ba41.1d7328" + ] + ] + }, + { + "id": "eb57ba41.1d7328", + "type": "execute", + "name": "execute", + "xml": "\n \n \n \n \n \n \n \n \n", + "comments": "", + "outputs": 1, + "x": 420, + "y": 588, + "z": "723548c7.652d78", + "wires": [ + [ + "892a8f1d.7d77f", + "74be8a6e.975f24" + ] + ] + }, + { + "id": "892a8f1d.7d77f", + "type": "failure", + "name": "failure", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 605, + "y": 557, + "z": "723548c7.652d78", + "wires": [ + [ + "8c091fe.c6cbfe" + ] + ] + }, + { + "id": "74be8a6e.975f24", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 603, + "y": 629, + "z": "723548c7.652d78", + "wires": [ + [ + "3875d695.fd37ca" + ] + ] + }, + { + "id": "3875d695.fd37ca", + "type": "switchNode", + "name": "switch", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 755, + "y": 617, + "z": "723548c7.652d78", + "wires": [ + [ + "2e60af80.ea3a6", + "24ed6dd2.6624c2" + ] + ] + }, + { + "id": "24ed6dd2.6624c2", + "type": "success", + "name": "success", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 918, + "y": 563, + "z": "723548c7.652d78", + "wires": [ + [ + "9ef7fcc3.69279" + ] + ] + }, + { + "id": "2e60af80.ea3a6", + "type": "other", + "name": "other", + "xml": "\n", + "comments": "", + "outputs": 1, + "x": 915, + "y": 632, + "z": "723548c7.652d78", + "wires": [ + [ + "2e4414a7.ba6d4c" + ] + ] + }, + { + "id": "8c091fe.c6cbfe", + "type": "returnFailure", + "name": "return failure", + "xml": "\n\n\n\n", + "comments": "", + "x": 757, + "y": 554, + "z": "723548c7.652d78", + "wires": [] + }, + { + "id": "2e4414a7.ba6d4c", + "type": "returnFailure", + "name": "return failure", + "xml": "\n\n\n\n", + "comments": "", + "x": 1076, + "y": 632, + "z": "723548c7.652d78", + "wires": [] + } +] \ No newline at end of file diff --git a/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-exec-SLSFile-applyTo.xml b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-exec-SLSFile-applyTo.xml new file mode 100644 index 000000000..1f9559330 --- /dev/null +++ b/adaptors/saltstack-adaptor/saltstack-directed-graphs-sample/reqExecSLSFile/APPC_saltstack-adaptor-1.0-exec-SLSFile-applyTo.xml @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit 1.2.3-korg