From c90edac236dffb7c495e266dd04991de7e8f04b7 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Mon, 25 Mar 2019 13:04:18 -0400 Subject: Migrate ccsdk/apps to ccsdk/cds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue-ID: CCSDK-1177 Issue-ID: CCSDK-1178 Change-Id: I0c02702fbec52211ca367abbba72aebecee8cbaa Signed-off-by: Alexis de Talhouët --- .../modules/commons/db-lib/pom.xml | 10 +- .../db/BluePrintDBLibConfiguration.kt | 56 ------ .../blueprintsprocessor/db/BluePrintDBLibData.kt | 52 ----- .../db/BluePrintDBLibGenericService.kt | 44 ----- .../db/BlueprintProcessorCatalogServiceImpl.kt | 114 ----------- .../db/primary/BluePrintDBLibPropertyService.kt | 105 ---------- .../db/primary/MariaDatabaseConfiguration.kt | 59 ------ .../db/primary/MySqlDatabaseConfiguration.kt | 55 ------ .../db/primary/PrimaryDBLibGenericService.kt | 27 --- .../db/primary/PrimaryDatabaseConfiguration.kt | 82 -------- .../db/primary/domain/BlueprintProcessorModel.kt | 84 -------- .../domain/BlueprintProcessorModelContent.kt | 101 ---------- .../BlueprintProcessorModelContentRepository.kt | 22 --- .../BlueprintProcessorModelRepository.kt | 21 -- .../db/BluePrintDBLibConfiguration.kt | 56 ++++++ .../blueprintsprocessor/db/BluePrintDBLibData.kt | 52 +++++ .../db/BluePrintDBLibGenericService.kt | 44 +++++ .../db/BlueprintProcessorCatalogServiceImpl.kt | 114 +++++++++++ .../db/primary/BluePrintDBLibPropertyService.kt | 105 ++++++++++ .../db/primary/MariaDatabaseConfiguration.kt | 59 ++++++ .../db/primary/MySqlDatabaseConfiguration.kt | 55 ++++++ .../db/primary/PrimaryDBLibGenericService.kt | 27 +++ .../db/primary/PrimaryDatabaseConfiguration.kt | 82 ++++++++ .../db/primary/domain/BlueprintProcessorModel.kt | 84 ++++++++ .../domain/BlueprintProcessorModelContent.kt | 101 ++++++++++ .../BlueprintProcessorModelContentRepository.kt | 22 +++ .../BlueprintProcessorModelRepository.kt | 21 ++ .../db/BlueprintProcessorCatalogServiceImplTest.kt | 52 ----- .../db/primary/PrimaryDatabaseConfigurationTest.kt | 49 ----- .../db/BlueprintProcessorCatalogServiceImplTest.kt | 52 +++++ .../db/primary/PrimaryDatabaseConfigurationTest.kt | 49 +++++ .../db-lib/src/test/resources/logback-test.xml | 2 +- .../modules/commons/dmaap-lib/pom.xml | 4 +- .../dmaap/AafAuthDmaapClientService.kt | 63 ------ .../dmaap/BluePrintDmaapClientService.kt | 102 ---------- .../dmaap/BluePrintDmaapLibConfiguration.kt | 46 ----- .../dmaap/BluePrintDmaapLibPropertyService.kt | 187 ------------------ .../dmaap/DmaapClientProperties.kt | 46 ----- .../dmaap/HttpNoAuthDmaapClientService.kt | 62 ------ .../dmaap/AafAuthDmaapClientService.kt | 63 ++++++ .../dmaap/BluePrintDmaapClientService.kt | 102 ++++++++++ .../dmaap/BluePrintDmaapLibConfiguration.kt | 46 +++++ .../dmaap/BluePrintDmaapLibPropertyService.kt | 187 ++++++++++++++++++ .../dmaap/DmaapClientProperties.kt | 46 +++++ .../dmaap/HttpNoAuthDmaapClientService.kt | 62 ++++++ .../dmaap/TestDmaapEventPublisher.kt | 215 --------------------- .../dmaap/TestDmaapEventPublisher.kt | 215 +++++++++++++++++++++ .../dmaap-lib/src/test/resources/logback-test.xml | 2 +- ms/blueprintsprocessor/modules/commons/pom.xml | 4 +- .../modules/commons/processor-core/pom.xml | 2 +- .../core/BluePrintCoreConfiguration.kt | 49 ----- .../core/BluePrintProperties.kt | 29 --- .../core/api/data/BlueprintProcessorData.kt | 123 ------------ .../core/factory/ComponentNodeFactory.kt | 68 ------- .../blueprintsprocessor/core/utils/PayloadUtils.kt | 47 ----- .../core/BluePrintCoreConfiguration.kt | 49 +++++ .../core/BluePrintProperties.kt | 29 +++ .../core/api/data/BlueprintProcessorData.kt | 123 ++++++++++++ .../core/factory/ComponentNodeFactory.kt | 68 +++++++ .../blueprintsprocessor/core/utils/PayloadUtils.kt | 47 +++++ .../core/BluePrintPropertiesTest.kt | 20 -- .../core/BluePrintPropertiesTest.kt | 20 ++ .../modules/commons/rest-lib/pom.xml | 6 +- .../rest/BluePrintRestLibConfiguration.kt | 39 ---- .../rest/BluePrintRestLibData.kt | 55 ------ .../rest/service/BasicAuthRestClientService.kt | 58 ------ .../service/BluePrintRestLibPropertyService.kt | 129 ------------- .../rest/service/BlueprintWebClientService.kt | 115 ----------- .../rest/service/DME2ProxyRestClientService.kt | 29 --- .../rest/service/SSLBasicAuthRestClientService.kt | 72 ------- .../rest/service/TokenAuthRestClientService.kt | 47 ----- .../rest/utils/WebClientUtils.kt | 35 ---- .../rest/BluePrintRestLibConfiguration.kt | 39 ++++ .../rest/BluePrintRestLibData.kt | 55 ++++++ .../rest/service/BasicAuthRestClientService.kt | 58 ++++++ .../service/BluePrintRestLibPropertyService.kt | 129 +++++++++++++ .../rest/service/BlueprintWebClientService.kt | 115 +++++++++++ .../rest/service/DME2ProxyRestClientService.kt | 29 +++ .../rest/service/SSLBasicAuthRestClientService.kt | 72 +++++++ .../rest/service/TokenAuthRestClientService.kt | 47 +++++ .../rest/utils/WebClientUtils.kt | 35 ++++ .../service/BluePrintRestLibPropertyServiceTest.kt | 58 ------ .../rest/service/RestClientServiceTest.kt | 83 -------- .../service/BluePrintRestLibPropertyServiceTest.kt | 58 ++++++ .../rest/service/RestClientServiceTest.kt | 83 ++++++++ .../rest-lib/src/test/resources/logback-test.xml | 2 +- 86 files changed, 2716 insertions(+), 2716 deletions(-) delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibData.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibGenericService.kt delete mode 100755 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt delete mode 100755 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibData.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibGenericService.kt create mode 100755 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt create mode 100755 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfigurationTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfigurationTest.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/DmaapClientProperties.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/DmaapClientProperties.kt create mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/apps/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt create mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/cds/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/BluePrintCoreConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/BluePrintProperties.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/factory/ComponentNodeFactory.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/utils/PayloadUtils.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintCoreConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintProperties.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/factory/ComponentNodeFactory.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/PayloadUtils.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/BluePrintPropertiesTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintPropertiesTest.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/BluePrintRestLibData.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BlueprintWebClientService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/DME2ProxyRestClientService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/SSLBasicAuthRestClientService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/utils/WebClientUtils.kt create mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt create mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/DME2ProxyRestClientService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLBasicAuthRestClientService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/utils/WebClientUtils.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestClientServiceTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt (limited to 'ms/blueprintsprocessor/modules/commons') diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml b/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml index 045c871ff..faf5578c9 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml +++ b/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml @@ -18,7 +18,7 @@ 4.0.0 - org.onap.ccsdk.apps.blueprintsprocessor + org.onap.ccsdk.cds.blueprintsprocessor commons 0.4.2-SNAPSHOT @@ -30,19 +30,19 @@ - org.onap.ccsdk.apps.controllerblueprints + org.onap.ccsdk.cds.controllerblueprints blueprint-core - org.onap.ccsdk.apps.controllerblueprints + org.onap.ccsdk.cds.controllerblueprints db-resources - org.onap.ccsdk.apps.controllerblueprints + org.onap.ccsdk.cds.controllerblueprints blueprint-validation - org.onap.ccsdk.apps.blueprintsprocessor + org.onap.ccsdk.cds.blueprintsprocessor processor-core diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt deleted file mode 100644 index 3e9ec0cef..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.db - -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties -import org.springframework.boot.context.properties.EnableConfigurationProperties -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration - -@Configuration -@ComponentScan -@EnableConfigurationProperties -open class BluePrintDBLibConfiguration(private var bluePrintProperties: BluePrintProperties) { - - @Bean("primary-database-properties") - open fun getPrimaryProperties(): PrimaryDataSourceProperties { - return bluePrintProperties.propertyBeanType(DBLibConstants.PREFIX_DB_PRIMARY, - PrimaryDataSourceProperties::class.java) - } -} - -class DBLibConstants { - companion object { - const val PREFIX_DB_PRIMARY: String = "blueprintsprocessor.db.primary" - - //list of database - const val MARIA_DB: String = "maria-db" - const val PRIMARY_DB: String = "primary-db" - const val MYSQL_DB: String = "mysql-db" - const val ORACLE_DB: String = "oracle-db" - const val POSTGRES_DB: String = "postgres-db" - - //List of database drivers - const val DRIVER_MARIA_DB = "org.mariadb.jdbc.Driver" - const val DRIVER_MYSQL_DB = "com.mysql.jdbc.Driver" - const val DRIVER_ORACLE_DB = "oracle.jdbc.driver.OracleDriver" - const val DRIVER_POSTGRES_DB = "org.postgresql.Driver" - - - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibData.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibData.kt deleted file mode 100644 index ab2c19a40..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibData.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.db - - -open class DBDataSourceProperties { - lateinit var url: String - lateinit var username: String - lateinit var password: String - open lateinit var driverClassName: String - -} - -open class PrimaryDataSourceProperties: DBDataSourceProperties() { - lateinit var hibernateHbm2ddlAuto: String - lateinit var hibernateDDLAuto: String - lateinit var hibernateNamingStrategy: String - lateinit var hibernateDialect: String -} - -open class MariaDataSourceProperties: DBDataSourceProperties() { - lateinit var hibernateHbm2ddlAuto: String - lateinit var hibernateDDLAuto: String - lateinit var hibernateNamingStrategy: String - lateinit var type: String - lateinit var hibernateDialect: String - override var driverClassName = DBLibConstants.DRIVER_MARIA_DB -} - -open class MySqlDataSourceProperties: DBDataSourceProperties() { - lateinit var hibernateHbm2ddlAuto: String - lateinit var hibernateDDLAuto: String - lateinit var hibernateNamingStrategy: String - lateinit var type: String - lateinit var hibernateDialect: String - override var driverClassName = DBLibConstants.DRIVER_MYSQL_DB -} - diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibGenericService.kt deleted file mode 100644 index aee74d3f4..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibGenericService.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.db - -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate - -interface BluePrintDBLibGenericService { - - fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate - - fun query(sql: String, params: Map): List> - - fun update(sql: String, params: Map): Int -} - -abstract class AbstractDBLibGenericService(private val namedParameterJdbcTemplate: NamedParameterJdbcTemplate) - : BluePrintDBLibGenericService { - - override fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate { - return namedParameterJdbcTemplate - } - - override fun query(sql: String, params: Map): List> { - return namedParameterJdbcTemplate.queryForList(sql, params) - } - - override fun update(sql: String, params: Map): Int { - return namedParameterJdbcTemplate.update(sql, params) - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt deleted file mode 100755 index e94bcff52..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.db - -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel -import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain.BlueprintProcessorModelContent -import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.repository.BlueprintProcessorModelRepository -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants -import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils -import org.onap.ccsdk.apps.controllerblueprints.db.resources.BlueprintCatalogServiceImpl -import org.slf4j.LoggerFactory -import org.springframework.dao.DataIntegrityViolationException -import org.springframework.stereotype.Service -import java.io.File -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths - -/** - * Similar/Duplicate implementation in [org.onap.ccsdk.apps.controllerblueprints.service.load.ControllerBlueprintCatalogServiceImpl] - */ -@Service -class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: BluePrintValidatorService, - private val blueprintConfig: BluePrintCoreConfiguration, - private val blueprintModelRepository: BlueprintProcessorModelRepository) - : BlueprintCatalogServiceImpl(bluePrintRuntimeValidatorService) { - - private val log = LoggerFactory.getLogger(BlueprintProcessorCatalogServiceImpl::class.toString()) - - init { - - log.info("BlueprintProcessorCatalogServiceImpl initialized") - } - - override fun delete(name: String, version: String) = blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(name, version) - - - override fun get(name: String, version: String, extract: Boolean): Path? { - var path = "${blueprintConfig.archivePath}/$name/$version.zip" - - blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also { - it.blueprintModelContent.run { - val file = File(path) - file.parentFile.mkdirs() - file.createNewFile() - file.writeBytes(this!!.content!!).let { - if (extract) { - path = "${blueprintConfig.archivePath}/$name/$version" - BluePrintArchiveUtils.deCompress(file, path) - } - return Paths.get(path) - } - } - } - return null - } - - override fun save(metadata: MutableMap, archiveFile: File) { - val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] - val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] - - blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let { - log.info("Overwriting blueprint model :$artifactName::$artifactVersion") - blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion) - } - - val blueprintModel = BlueprintProcessorModel() - blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] - blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL - blueprintModel.artifactName = artifactName - blueprintModel.artifactVersion = artifactVersion - blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR] - blueprintModel.tags = metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS] - blueprintModel.artifactDescription = "Controller Blueprint for $artifactName:$artifactVersion" - - val blueprintModelContent = BlueprintProcessorModelContent() - blueprintModelContent.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] - blueprintModelContent.contentType = "CBA_ZIP" - blueprintModelContent.name = "$artifactName:$artifactVersion" - blueprintModelContent.description = "$artifactName:$artifactVersion CBA Zip Content" - blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath()) - blueprintModelContent.blueprintModel = blueprintModel - - blueprintModel.blueprintModelContent = blueprintModelContent - - try { - blueprintModelRepository.saveAndFlush(blueprintModel) - } catch (ex: DataIntegrityViolationException) { - throw BluePrintException(ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " + - "is already exist in database: ${ex.message}", ex) - } - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt deleted file mode 100644 index f93c241d4..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright © 2019 Bell Canada Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.db.primary - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties -import org.onap.ccsdk.apps.blueprintsprocessor.db.* -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.springframework.stereotype.Service - -@Service -class BluePrintDBLibPropertySevice(private var bluePrintProperties: BluePrintProperties) { - - fun JdbcTemplate(jsonNode: JsonNode): BluePrintDBLibGenericService { - val dBConnetionProperties = dBDataSourceProperties(jsonNode) - return blueprintDBDataSourceService(dBConnetionProperties) - } - - fun JdbcTemplate(selector: String): BluePrintDBLibGenericService { - val prefix = "blueprintsprocessor.database.$selector" - val dBConnetionProperties = dBDataSourceProperties(prefix) - return blueprintDBDataSourceService(dBConnetionProperties) - } - - private fun dBDataSourceProperties(jsonNode: JsonNode): DBDataSourceProperties { - val type = jsonNode.get("type").textValue() - return when (type) { - DBLibConstants.MYSQL_DB -> { - JacksonUtils.readValue(jsonNode, MySqlDataSourceProperties::class.java)!! - } - DBLibConstants.MARIA_DB -> { - JacksonUtils.readValue(jsonNode, MariaDataSourceProperties::class.java)!! - } - else -> { - throw BluePrintProcessorException("Rest adaptor($type) is not supported") - } - } - } - - private fun dBDataSourceProperties(prefix: String): DBDataSourceProperties { - val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java) - return when (type) { - DBLibConstants.MARIA_DB -> { - mariaDBConnectionProperties(prefix) - } - DBLibConstants.MYSQL_DB -> { - mySqlDBConnectionProperties(prefix) - } - DBLibConstants.ORACLE_DB -> { - TODO("not implemented") - } - DBLibConstants.POSTGRES_DB -> { - TODO("not implemented") - } - DBLibConstants.PRIMARY_DB -> { - primaryDBConnectionProperties(prefix) - } - else -> { - throw BluePrintProcessorException("Rest adaptor($type) is not supported") - } - } - } - - private fun blueprintDBDataSourceService(dBConnetionProperties: DBDataSourceProperties): BluePrintDBLibGenericService { - when (dBConnetionProperties) { - is MariaDataSourceProperties -> { - return MariaDatabaseConfiguration(dBConnetionProperties) - } - is MySqlDataSourceProperties -> { - return MySqlDatabaseConfiguration(dBConnetionProperties) - } - else -> { - throw BluePrintProcessorException("couldn't get rest service for") - } - } - } - - private fun mySqlDBConnectionProperties(prefix: String): MySqlDataSourceProperties { - return bluePrintProperties.propertyBeanType(prefix, MySqlDataSourceProperties::class.java) - } - - private fun mariaDBConnectionProperties(prefix: String): MariaDataSourceProperties { - return bluePrintProperties.propertyBeanType(prefix, MariaDataSourceProperties::class.java) - } - - private fun primaryDBConnectionProperties(prefix: String): PrimaryDataSourceProperties { - return bluePrintProperties.propertyBeanType(prefix, PrimaryDataSourceProperties::class.java) - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt deleted file mode 100644 index c67fb3397..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright © 2019 Bell Canada Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.db.primary - -import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibGenericService -import org.onap.ccsdk.apps.blueprintsprocessor.db.MariaDataSourceProperties -import org.slf4j.LoggerFactory -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate -import org.springframework.jdbc.datasource.DriverManagerDataSource -import org.springframework.orm.jpa.JpaTransactionManager -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter -import org.springframework.transaction.PlatformTransactionManager -import java.util.* -import javax.sql.DataSource - -class MariaDatabaseConfiguration(private val mariaDataSourceProperties: MariaDataSourceProperties) : BluePrintDBLibGenericService { - - override fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate { - return mariaNamedParameterJdbcTemplate(mariaDataSource()) - } - - override fun query(sql: String, params: Map): List> { - return mariaNamedParameterJdbcTemplate(mariaDataSource()).queryForList(sql, params) - } - - override fun update(sql: String, params: Map): Int { - return mariaNamedParameterJdbcTemplate(mariaDataSource()).update(sql, params) - } - - val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!! - - fun mariaDataSource(): DataSource { - val dataSource = DriverManagerDataSource() - dataSource.setDriverClassName(mariaDataSourceProperties.driverClassName) - dataSource.url = mariaDataSourceProperties.url - dataSource.username = mariaDataSourceProperties.username - dataSource.password = mariaDataSourceProperties.password - return dataSource - } - - fun mariaNamedParameterJdbcTemplate(mariaDataSource: DataSource): NamedParameterJdbcTemplate { - return NamedParameterJdbcTemplate(mariaDataSource) - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt deleted file mode 100644 index 2a0dec73e..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright © 2019 Bell Canada Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.db.primary - -import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibGenericService -import org.onap.ccsdk.apps.blueprintsprocessor.db.MySqlDataSourceProperties -import org.slf4j.LoggerFactory -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate -import org.springframework.jdbc.datasource.DriverManagerDataSource -import javax.sql.DataSource - -class MySqlDatabaseConfiguration(private val mySqlDataSourceProperties: MySqlDataSourceProperties) : BluePrintDBLibGenericService { - override fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate { - return mySqlNamedParameterJdbcTemplate(mySqlDataSource()) - } - - override fun query(sql: String, params: Map): List> { - return mySqlNamedParameterJdbcTemplate(mySqlDataSource()).queryForList(sql, params) - } - - override fun update(sql: String, params: Map): Int { - return mySqlNamedParameterJdbcTemplate(mySqlDataSource()).update(sql, params) - } - - val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!! - - fun mySqlDataSource(): DataSource { - val dataSource = DriverManagerDataSource() - dataSource.setDriverClassName(mySqlDataSourceProperties.driverClassName) - dataSource.url = mySqlDataSourceProperties.url - dataSource.username = mySqlDataSourceProperties.username - dataSource.password = mySqlDataSourceProperties.password - return dataSource - } - - fun mySqlNamedParameterJdbcTemplate(mySqlDataSource: DataSource): NamedParameterJdbcTemplate { - return NamedParameterJdbcTemplate(mySqlDataSource) - } - - -} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt deleted file mode 100644 index 5a9265348..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.db.primary - -import org.onap.ccsdk.apps.blueprintsprocessor.db.AbstractDBLibGenericService -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate -import org.springframework.stereotype.Service - -@Service -open class PrimaryDBLibGenericService(primaryNamedParameterJdbcTemplate: NamedParameterJdbcTemplate) - : AbstractDBLibGenericService(primaryNamedParameterJdbcTemplate) { - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt deleted file mode 100644 index 4039b053b..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.db.primary - -import org.onap.ccsdk.apps.blueprintsprocessor.db.PrimaryDataSourceProperties -import org.slf4j.LoggerFactory -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.context.annotation.Primary -import org.springframework.data.jpa.repository.config.EnableJpaRepositories -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate -import org.springframework.jdbc.datasource.DriverManagerDataSource -import org.springframework.orm.jpa.JpaTransactionManager -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter -import org.springframework.transaction.PlatformTransactionManager -import java.util.* -import javax.sql.DataSource - -@Configuration -@EnableJpaRepositories( - basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor.*"], - entityManagerFactoryRef = "primaryEntityManager", - transactionManagerRef = "primaryTransactionManager" -) -open class PrimaryDatabaseConfiguration(private val primaryDataSourceProperties: PrimaryDataSourceProperties) { - val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!! - - @Primary - @Bean("primaryEntityManager") - open fun primaryEntityManager(): LocalContainerEntityManagerFactoryBean { - val em = LocalContainerEntityManagerFactoryBean() - em.dataSource = primaryDataSource() - em.setPackagesToScan("org.onap.ccsdk.apps.blueprintsprocessor.*") - em.jpaVendorAdapter = HibernateJpaVendorAdapter() - val properties = HashMap() - properties["hibernate.hbm2ddl.auto"] = primaryDataSourceProperties.hibernateHbm2ddlAuto - properties["hibernate.dialect"] = primaryDataSourceProperties.hibernateDialect - em.jpaPropertyMap = properties - return em - } - - @Primary - @Bean("primaryDataSource") - open fun primaryDataSource(): DataSource { - val dataSource = DriverManagerDataSource() - dataSource.setDriverClassName(primaryDataSourceProperties.driverClassName) - dataSource.url = primaryDataSourceProperties.url - dataSource.username = primaryDataSourceProperties.username - dataSource.password = primaryDataSourceProperties.password - return dataSource - } - - @Primary - @Bean("primaryTransactionManager") - open fun primaryTransactionManager(): PlatformTransactionManager { - val transactionManager = JpaTransactionManager() - transactionManager.entityManagerFactory = primaryEntityManager().getObject() - log.info("Initialised Primary Transaction Manager for url ${primaryDataSourceProperties.url}") - return transactionManager - } - - @Bean("primaryNamedParameterJdbcTemplate") - open fun primaryNamedParameterJdbcTemplate(primaryDataSource: DataSource): NamedParameterJdbcTemplate { - return NamedParameterJdbcTemplate(primaryDataSource) - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt deleted file mode 100755 index 0935d038c..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain - -import com.fasterxml.jackson.annotation.JsonFormat -import io.swagger.annotations.ApiModelProperty -import javax.persistence.Entity -import javax.persistence.EntityListeners -import javax.persistence.Table -import org.hibernate.annotations.Proxy -import org.springframework.data.annotation.LastModifiedDate -import org.springframework.data.jpa.domain.support.AuditingEntityListener -import java.io.Serializable -import java.util.* -import javax.persistence.CascadeType -import javax.persistence.Column -import javax.persistence.FetchType -import javax.persistence.Id -import javax.persistence.Lob -import javax.persistence.OneToOne -import javax.persistence.Temporal -import javax.persistence.TemporalType - -@EntityListeners(AuditingEntityListener::class) -@Entity -@Table(name = "BLUEPRINT_RUNTIME") -@Proxy(lazy = false) -class BlueprintProcessorModel : Serializable { - - @Id - @Column(name = "blueprint_runtime_id") - var id: String? = null - - @Column(name = "artifact_type") - var artifactType: String? = null - - @Column(name = "artifact_version", nullable = false) - @ApiModelProperty(required = true) - var artifactVersion: String? = null - - @Lob - @Column(name = "artifact_description") - var artifactDescription: String? = null - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "creation_date") - var createdDate = Date() - - @Column(name = "artifact_name", nullable = false) - @ApiModelProperty(required = true) - var artifactName: String? = null - - @Column(name = "updated_by", nullable = false) - @ApiModelProperty(required = true) - var updatedBy: String? = null - - @Lob - @Column(name = "tags", nullable = false) - @ApiModelProperty(required = true) - var tags: String? = null - - @OneToOne(mappedBy = "blueprintModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = [CascadeType.ALL]) - var blueprintModelContent: BlueprintProcessorModelContent? = null - - companion object { - private const val serialVersionUID = 1L - } -} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt deleted file mode 100644 index 58bf8a338..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain - -import com.fasterxml.jackson.annotation.JsonFormat -import io.swagger.annotations.ApiModelProperty -import java.io.Serializable -import java.util.Date -import java.util.Objects -import javax.persistence.Column -import javax.persistence.Entity -import javax.persistence.EntityListeners -import javax.persistence.Id -import javax.persistence.JoinColumn -import javax.persistence.Lob -import javax.persistence.OneToOne -import javax.persistence.Table -import javax.persistence.Temporal -import javax.persistence.TemporalType -import org.springframework.data.annotation.LastModifiedDate -import org.springframework.data.jpa.domain.support.AuditingEntityListener - -@EntityListeners(AuditingEntityListener::class) -@Entity -@Table(name = "BLUEPRINT_CONTENT_RUNTIME") -class BlueprintProcessorModelContent : Serializable { - - @Id - @Column(name = "blueprint_content_runtime_id") - var id: String? = null - - @Column(name = "name", nullable = false) - @ApiModelProperty(required = true) - var name: String? = null - - @Column(name = "content_type", nullable = false) - @ApiModelProperty(required = true) - var contentType: String? = null - - @OneToOne - @JoinColumn(name = "blueprint_runtime_id") - var blueprintModel: BlueprintProcessorModel? = null - - @Lob - @Column(name = "description") - var description: String? = null - - @Lob - @Column(name = "content", nullable = false) - @ApiModelProperty(required = true) - var content: ByteArray? = null - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "updated_date") - var creationDate = Date() - - override fun toString(): String { - return "[" + "id = " + id + - ", name = " + name + - ", contentType = " + contentType + - "]" - } - - override fun equals(o: Any?): Boolean { - - if (o === this) { - return true - } - if (o !is BlueprintProcessorModelContent) { - return false - } - val blueprintModelContent = o as BlueprintProcessorModelContent? - return (id == blueprintModelContent!!.id && name == blueprintModelContent.name - && contentType == blueprintModelContent.contentType) - } - - override fun hashCode(): Int { - return Objects.hash(id, name, contentType) - } - - companion object { - private const val serialVersionUID = 1L - } - -} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt deleted file mode 100644 index e614544e9..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2019 Bell Canada. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.ccsdk.apps.blueprintsprocessor.db.primary.repository - -import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel -import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain.BlueprintProcessorModelContent -import org.onap.ccsdk.apps.controllerblueprints.db.resources.repository.ModelContentRepository - -interface BlueprintProcessorModelContentRepository : ModelContentRepository \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt deleted file mode 100644 index 25f3dac9a..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2019 Bell Canada. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.ccsdk.apps.blueprintsprocessor.db.primary.repository - -import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel -import org.onap.ccsdk.apps.controllerblueprints.db.resources.repository.ModelRepository - -interface BlueprintProcessorModelRepository : ModelRepository diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt new file mode 100644 index 000000000..19e482aab --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt @@ -0,0 +1,56 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db + +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +@Configuration +@ComponentScan +@EnableConfigurationProperties +open class BluePrintDBLibConfiguration(private var bluePrintProperties: BluePrintProperties) { + + @Bean("primary-database-properties") + open fun getPrimaryProperties(): PrimaryDataSourceProperties { + return bluePrintProperties.propertyBeanType(DBLibConstants.PREFIX_DB_PRIMARY, + PrimaryDataSourceProperties::class.java) + } +} + +class DBLibConstants { + companion object { + const val PREFIX_DB_PRIMARY: String = "blueprintsprocessor.db.primary" + + //list of database + const val MARIA_DB: String = "maria-db" + const val PRIMARY_DB: String = "primary-db" + const val MYSQL_DB: String = "mysql-db" + const val ORACLE_DB: String = "oracle-db" + const val POSTGRES_DB: String = "postgres-db" + + //List of database drivers + const val DRIVER_MARIA_DB = "org.mariadb.jdbc.Driver" + const val DRIVER_MYSQL_DB = "com.mysql.jdbc.Driver" + const val DRIVER_ORACLE_DB = "oracle.jdbc.driver.OracleDriver" + const val DRIVER_POSTGRES_DB = "org.postgresql.Driver" + + + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibData.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibData.kt new file mode 100644 index 000000000..b71287d6e --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibData.kt @@ -0,0 +1,52 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db + + +open class DBDataSourceProperties { + lateinit var url: String + lateinit var username: String + lateinit var password: String + open lateinit var driverClassName: String + +} + +open class PrimaryDataSourceProperties: DBDataSourceProperties() { + lateinit var hibernateHbm2ddlAuto: String + lateinit var hibernateDDLAuto: String + lateinit var hibernateNamingStrategy: String + lateinit var hibernateDialect: String +} + +open class MariaDataSourceProperties: DBDataSourceProperties() { + lateinit var hibernateHbm2ddlAuto: String + lateinit var hibernateDDLAuto: String + lateinit var hibernateNamingStrategy: String + lateinit var type: String + lateinit var hibernateDialect: String + override var driverClassName = DBLibConstants.DRIVER_MARIA_DB +} + +open class MySqlDataSourceProperties: DBDataSourceProperties() { + lateinit var hibernateHbm2ddlAuto: String + lateinit var hibernateDDLAuto: String + lateinit var hibernateNamingStrategy: String + lateinit var type: String + lateinit var hibernateDialect: String + override var driverClassName = DBLibConstants.DRIVER_MYSQL_DB +} + diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibGenericService.kt new file mode 100644 index 000000000..0f6314685 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibGenericService.kt @@ -0,0 +1,44 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db + +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate + +interface BluePrintDBLibGenericService { + + fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate + + fun query(sql: String, params: Map): List> + + fun update(sql: String, params: Map): Int +} + +abstract class AbstractDBLibGenericService(private val namedParameterJdbcTemplate: NamedParameterJdbcTemplate) + : BluePrintDBLibGenericService { + + override fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate { + return namedParameterJdbcTemplate + } + + override fun query(sql: String, params: Map): List> { + return namedParameterJdbcTemplate.queryForList(sql, params) + } + + override fun update(sql: String, params: Map): Int { + return namedParameterJdbcTemplate.update(sql, params) + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt new file mode 100755 index 000000000..0a625007f --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt @@ -0,0 +1,114 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db + +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintProcessorModelContent +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintProcessorModelRepository +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.common.ApplicationConstants +import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils +import org.onap.ccsdk.cds.controllerblueprints.db.resources.BlueprintCatalogServiceImpl +import org.slf4j.LoggerFactory +import org.springframework.dao.DataIntegrityViolationException +import org.springframework.stereotype.Service +import java.io.File +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.Paths + +/** + * Similar/Duplicate implementation in [org.onap.ccsdk.cds.controllerblueprints.service.load.ControllerBlueprintCatalogServiceImpl] + */ +@Service +class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: BluePrintValidatorService, + private val blueprintConfig: BluePrintCoreConfiguration, + private val blueprintModelRepository: BlueprintProcessorModelRepository) + : BlueprintCatalogServiceImpl(bluePrintRuntimeValidatorService) { + + private val log = LoggerFactory.getLogger(BlueprintProcessorCatalogServiceImpl::class.toString()) + + init { + + log.info("BlueprintProcessorCatalogServiceImpl initialized") + } + + override fun delete(name: String, version: String) = blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(name, version) + + + override fun get(name: String, version: String, extract: Boolean): Path? { + var path = "${blueprintConfig.archivePath}/$name/$version.zip" + + blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also { + it.blueprintModelContent.run { + val file = File(path) + file.parentFile.mkdirs() + file.createNewFile() + file.writeBytes(this!!.content!!).let { + if (extract) { + path = "${blueprintConfig.archivePath}/$name/$version" + BluePrintArchiveUtils.deCompress(file, path) + } + return Paths.get(path) + } + } + } + return null + } + + override fun save(metadata: MutableMap, archiveFile: File) { + val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] + val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] + + blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let { + log.info("Overwriting blueprint model :$artifactName::$artifactVersion") + blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion) + } + + val blueprintModel = BlueprintProcessorModel() + blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] + blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL + blueprintModel.artifactName = artifactName + blueprintModel.artifactVersion = artifactVersion + blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR] + blueprintModel.tags = metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS] + blueprintModel.artifactDescription = "Controller Blueprint for $artifactName:$artifactVersion" + + val blueprintModelContent = BlueprintProcessorModelContent() + blueprintModelContent.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] + blueprintModelContent.contentType = "CBA_ZIP" + blueprintModelContent.name = "$artifactName:$artifactVersion" + blueprintModelContent.description = "$artifactName:$artifactVersion CBA Zip Content" + blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath()) + blueprintModelContent.blueprintModel = blueprintModel + + blueprintModel.blueprintModelContent = blueprintModelContent + + try { + blueprintModelRepository.saveAndFlush(blueprintModel) + } catch (ex: DataIntegrityViolationException) { + throw BluePrintException(ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " + + "is already exist in database: ${ex.message}", ex) + } + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt new file mode 100644 index 000000000..cf2ca550e --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt @@ -0,0 +1,105 @@ +/* + * Copyright © 2019 Bell Canada Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties +import org.onap.ccsdk.cds.blueprintsprocessor.db.* +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.stereotype.Service + +@Service +class BluePrintDBLibPropertySevice(private var bluePrintProperties: BluePrintProperties) { + + fun JdbcTemplate(jsonNode: JsonNode): BluePrintDBLibGenericService { + val dBConnetionProperties = dBDataSourceProperties(jsonNode) + return blueprintDBDataSourceService(dBConnetionProperties) + } + + fun JdbcTemplate(selector: String): BluePrintDBLibGenericService { + val prefix = "blueprintsprocessor.database.$selector" + val dBConnetionProperties = dBDataSourceProperties(prefix) + return blueprintDBDataSourceService(dBConnetionProperties) + } + + private fun dBDataSourceProperties(jsonNode: JsonNode): DBDataSourceProperties { + val type = jsonNode.get("type").textValue() + return when (type) { + DBLibConstants.MYSQL_DB -> { + JacksonUtils.readValue(jsonNode, MySqlDataSourceProperties::class.java)!! + } + DBLibConstants.MARIA_DB -> { + JacksonUtils.readValue(jsonNode, MariaDataSourceProperties::class.java)!! + } + else -> { + throw BluePrintProcessorException("Rest adaptor($type) is not supported") + } + } + } + + private fun dBDataSourceProperties(prefix: String): DBDataSourceProperties { + val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java) + return when (type) { + DBLibConstants.MARIA_DB -> { + mariaDBConnectionProperties(prefix) + } + DBLibConstants.MYSQL_DB -> { + mySqlDBConnectionProperties(prefix) + } + DBLibConstants.ORACLE_DB -> { + TODO("not implemented") + } + DBLibConstants.POSTGRES_DB -> { + TODO("not implemented") + } + DBLibConstants.PRIMARY_DB -> { + primaryDBConnectionProperties(prefix) + } + else -> { + throw BluePrintProcessorException("Rest adaptor($type) is not supported") + } + } + } + + private fun blueprintDBDataSourceService(dBConnetionProperties: DBDataSourceProperties): BluePrintDBLibGenericService { + when (dBConnetionProperties) { + is MariaDataSourceProperties -> { + return MariaDatabaseConfiguration(dBConnetionProperties) + } + is MySqlDataSourceProperties -> { + return MySqlDatabaseConfiguration(dBConnetionProperties) + } + else -> { + throw BluePrintProcessorException("couldn't get rest service for") + } + } + } + + private fun mySqlDBConnectionProperties(prefix: String): MySqlDataSourceProperties { + return bluePrintProperties.propertyBeanType(prefix, MySqlDataSourceProperties::class.java) + } + + private fun mariaDBConnectionProperties(prefix: String): MariaDataSourceProperties { + return bluePrintProperties.propertyBeanType(prefix, MariaDataSourceProperties::class.java) + } + + private fun primaryDBConnectionProperties(prefix: String): PrimaryDataSourceProperties { + return bluePrintProperties.propertyBeanType(prefix, PrimaryDataSourceProperties::class.java) + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt new file mode 100644 index 000000000..5015388b9 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt @@ -0,0 +1,59 @@ +/* + * Copyright © 2019 Bell Canada Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary + +import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService +import org.onap.ccsdk.cds.blueprintsprocessor.db.MariaDataSourceProperties +import org.slf4j.LoggerFactory +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate +import org.springframework.jdbc.datasource.DriverManagerDataSource +import org.springframework.orm.jpa.JpaTransactionManager +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter +import org.springframework.transaction.PlatformTransactionManager +import java.util.* +import javax.sql.DataSource + +class MariaDatabaseConfiguration(private val mariaDataSourceProperties: MariaDataSourceProperties) : BluePrintDBLibGenericService { + + override fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate { + return mariaNamedParameterJdbcTemplate(mariaDataSource()) + } + + override fun query(sql: String, params: Map): List> { + return mariaNamedParameterJdbcTemplate(mariaDataSource()).queryForList(sql, params) + } + + override fun update(sql: String, params: Map): Int { + return mariaNamedParameterJdbcTemplate(mariaDataSource()).update(sql, params) + } + + val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!! + + fun mariaDataSource(): DataSource { + val dataSource = DriverManagerDataSource() + dataSource.setDriverClassName(mariaDataSourceProperties.driverClassName) + dataSource.url = mariaDataSourceProperties.url + dataSource.username = mariaDataSourceProperties.username + dataSource.password = mariaDataSourceProperties.password + return dataSource + } + + fun mariaNamedParameterJdbcTemplate(mariaDataSource: DataSource): NamedParameterJdbcTemplate { + return NamedParameterJdbcTemplate(mariaDataSource) + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt new file mode 100644 index 000000000..3091674f0 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt @@ -0,0 +1,55 @@ +/* + * Copyright © 2019 Bell Canada Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary + +import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService +import org.onap.ccsdk.cds.blueprintsprocessor.db.MySqlDataSourceProperties +import org.slf4j.LoggerFactory +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate +import org.springframework.jdbc.datasource.DriverManagerDataSource +import javax.sql.DataSource + +class MySqlDatabaseConfiguration(private val mySqlDataSourceProperties: MySqlDataSourceProperties) : BluePrintDBLibGenericService { + override fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate { + return mySqlNamedParameterJdbcTemplate(mySqlDataSource()) + } + + override fun query(sql: String, params: Map): List> { + return mySqlNamedParameterJdbcTemplate(mySqlDataSource()).queryForList(sql, params) + } + + override fun update(sql: String, params: Map): Int { + return mySqlNamedParameterJdbcTemplate(mySqlDataSource()).update(sql, params) + } + + val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!! + + fun mySqlDataSource(): DataSource { + val dataSource = DriverManagerDataSource() + dataSource.setDriverClassName(mySqlDataSourceProperties.driverClassName) + dataSource.url = mySqlDataSourceProperties.url + dataSource.username = mySqlDataSourceProperties.username + dataSource.password = mySqlDataSourceProperties.password + return dataSource + } + + fun mySqlNamedParameterJdbcTemplate(mySqlDataSource: DataSource): NamedParameterJdbcTemplate { + return NamedParameterJdbcTemplate(mySqlDataSource) + } + + +} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt new file mode 100644 index 000000000..896929fbb --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt @@ -0,0 +1,27 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary + +import org.onap.ccsdk.cds.blueprintsprocessor.db.AbstractDBLibGenericService +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate +import org.springframework.stereotype.Service + +@Service +open class PrimaryDBLibGenericService(primaryNamedParameterJdbcTemplate: NamedParameterJdbcTemplate) + : AbstractDBLibGenericService(primaryNamedParameterJdbcTemplate) { + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt new file mode 100644 index 000000000..4ea407ada --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt @@ -0,0 +1,82 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary + +import org.onap.ccsdk.cds.blueprintsprocessor.db.PrimaryDataSourceProperties +import org.slf4j.LoggerFactory +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Primary +import org.springframework.data.jpa.repository.config.EnableJpaRepositories +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate +import org.springframework.jdbc.datasource.DriverManagerDataSource +import org.springframework.orm.jpa.JpaTransactionManager +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter +import org.springframework.transaction.PlatformTransactionManager +import java.util.* +import javax.sql.DataSource + +@Configuration +@EnableJpaRepositories( + basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor.*"], + entityManagerFactoryRef = "primaryEntityManager", + transactionManagerRef = "primaryTransactionManager" +) +open class PrimaryDatabaseConfiguration(private val primaryDataSourceProperties: PrimaryDataSourceProperties) { + val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!! + + @Primary + @Bean("primaryEntityManager") + open fun primaryEntityManager(): LocalContainerEntityManagerFactoryBean { + val em = LocalContainerEntityManagerFactoryBean() + em.dataSource = primaryDataSource() + em.setPackagesToScan("org.onap.ccsdk.cds.blueprintsprocessor.*") + em.jpaVendorAdapter = HibernateJpaVendorAdapter() + val properties = HashMap() + properties["hibernate.hbm2ddl.auto"] = primaryDataSourceProperties.hibernateHbm2ddlAuto + properties["hibernate.dialect"] = primaryDataSourceProperties.hibernateDialect + em.jpaPropertyMap = properties + return em + } + + @Primary + @Bean("primaryDataSource") + open fun primaryDataSource(): DataSource { + val dataSource = DriverManagerDataSource() + dataSource.setDriverClassName(primaryDataSourceProperties.driverClassName) + dataSource.url = primaryDataSourceProperties.url + dataSource.username = primaryDataSourceProperties.username + dataSource.password = primaryDataSourceProperties.password + return dataSource + } + + @Primary + @Bean("primaryTransactionManager") + open fun primaryTransactionManager(): PlatformTransactionManager { + val transactionManager = JpaTransactionManager() + transactionManager.entityManagerFactory = primaryEntityManager().getObject() + log.info("Initialised Primary Transaction Manager for url ${primaryDataSourceProperties.url}") + return transactionManager + } + + @Bean("primaryNamedParameterJdbcTemplate") + open fun primaryNamedParameterJdbcTemplate(primaryDataSource: DataSource): NamedParameterJdbcTemplate { + return NamedParameterJdbcTemplate(primaryDataSource) + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt new file mode 100755 index 000000000..c565262db --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt @@ -0,0 +1,84 @@ +/* + * Copyright © 2019 Bell Canada + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain + +import com.fasterxml.jackson.annotation.JsonFormat +import io.swagger.annotations.ApiModelProperty +import javax.persistence.Entity +import javax.persistence.EntityListeners +import javax.persistence.Table +import org.hibernate.annotations.Proxy +import org.springframework.data.annotation.LastModifiedDate +import org.springframework.data.jpa.domain.support.AuditingEntityListener +import java.io.Serializable +import java.util.* +import javax.persistence.CascadeType +import javax.persistence.Column +import javax.persistence.FetchType +import javax.persistence.Id +import javax.persistence.Lob +import javax.persistence.OneToOne +import javax.persistence.Temporal +import javax.persistence.TemporalType + +@EntityListeners(AuditingEntityListener::class) +@Entity +@Table(name = "BLUEPRINT_RUNTIME") +@Proxy(lazy = false) +class BlueprintProcessorModel : Serializable { + + @Id + @Column(name = "blueprint_runtime_id") + var id: String? = null + + @Column(name = "artifact_type") + var artifactType: String? = null + + @Column(name = "artifact_version", nullable = false) + @ApiModelProperty(required = true) + var artifactVersion: String? = null + + @Lob + @Column(name = "artifact_description") + var artifactDescription: String? = null + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "creation_date") + var createdDate = Date() + + @Column(name = "artifact_name", nullable = false) + @ApiModelProperty(required = true) + var artifactName: String? = null + + @Column(name = "updated_by", nullable = false) + @ApiModelProperty(required = true) + var updatedBy: String? = null + + @Lob + @Column(name = "tags", nullable = false) + @ApiModelProperty(required = true) + var tags: String? = null + + @OneToOne(mappedBy = "blueprintModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = [CascadeType.ALL]) + var blueprintModelContent: BlueprintProcessorModelContent? = null + + companion object { + private const val serialVersionUID = 1L + } +} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt new file mode 100644 index 000000000..dc02d2fd0 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt @@ -0,0 +1,101 @@ +/* + * Copyright © 2019 Bell Canada + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain + +import com.fasterxml.jackson.annotation.JsonFormat +import io.swagger.annotations.ApiModelProperty +import java.io.Serializable +import java.util.Date +import java.util.Objects +import javax.persistence.Column +import javax.persistence.Entity +import javax.persistence.EntityListeners +import javax.persistence.Id +import javax.persistence.JoinColumn +import javax.persistence.Lob +import javax.persistence.OneToOne +import javax.persistence.Table +import javax.persistence.Temporal +import javax.persistence.TemporalType +import org.springframework.data.annotation.LastModifiedDate +import org.springframework.data.jpa.domain.support.AuditingEntityListener + +@EntityListeners(AuditingEntityListener::class) +@Entity +@Table(name = "BLUEPRINT_CONTENT_RUNTIME") +class BlueprintProcessorModelContent : Serializable { + + @Id + @Column(name = "blueprint_content_runtime_id") + var id: String? = null + + @Column(name = "name", nullable = false) + @ApiModelProperty(required = true) + var name: String? = null + + @Column(name = "content_type", nullable = false) + @ApiModelProperty(required = true) + var contentType: String? = null + + @OneToOne + @JoinColumn(name = "blueprint_runtime_id") + var blueprintModel: BlueprintProcessorModel? = null + + @Lob + @Column(name = "description") + var description: String? = null + + @Lob + @Column(name = "content", nullable = false) + @ApiModelProperty(required = true) + var content: ByteArray? = null + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "updated_date") + var creationDate = Date() + + override fun toString(): String { + return "[" + "id = " + id + + ", name = " + name + + ", contentType = " + contentType + + "]" + } + + override fun equals(o: Any?): Boolean { + + if (o === this) { + return true + } + if (o !is BlueprintProcessorModelContent) { + return false + } + val blueprintModelContent = o as BlueprintProcessorModelContent? + return (id == blueprintModelContent!!.id && name == blueprintModelContent.name + && contentType == blueprintModelContent.contentType) + } + + override fun hashCode(): Int { + return Objects.hash(id, name, contentType) + } + + companion object { + private const val serialVersionUID = 1L + } + +} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt new file mode 100644 index 000000000..c914af8f3 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2019 Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository + +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintProcessorModelContent +import org.onap.ccsdk.cds.controllerblueprints.db.resources.repository.ModelContentRepository + +interface BlueprintProcessorModelContentRepository : ModelContentRepository \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt new file mode 100644 index 000000000..4f22bf07d --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2019 Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository + +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel +import org.onap.ccsdk.cds.controllerblueprints.db.resources.repository.ModelRepository + +interface BlueprintProcessorModelRepository : ModelRepository diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt deleted file mode 100644 index 4c953163a..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2019 Bell Canada. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.ccsdk.apps.blueprintsprocessor.db - -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import java.io.File -import java.nio.file.Paths -import kotlin.test.assertTrue - -@RunWith(SpringRunner::class) -@EnableAutoConfiguration -@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) -@TestPropertySource(locations = ["classpath:application-test.properties"]) -class BlueprintProcessorCatalogServiceImplTest { - - @Autowired - lateinit var blueprintCatalog: BluePrintCatalogService - - @Test - fun `test catalog service`() { - val file = Paths.get("./src/test/resources/test-cba.zip").toFile() - assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") - - blueprintCatalog.saveToDatabase(file) - - blueprintCatalog.getFromDatabase("baseconfiguration", "1.0.0") - - blueprintCatalog.deleteFromDatabase("baseconfiguration", "1.0.0") - - File("./src/test/resources/baseconfiguration").deleteRecursively() - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfigurationTest.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfigurationTest.kt deleted file mode 100644 index 3f737e314..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfigurationTest.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.db.primary - -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties -import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibConfiguration -import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import javax.sql.DataSource -import kotlin.test.assertNotNull - -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [BlueprintPropertyConfiguration::class, BluePrintProperties::class, - BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class]) -@TestPropertySource(locations = ["classpath:application-test.properties"]) -@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) -@EnableAutoConfiguration -class PrimaryDatabaseConfigurationTest { - - @Autowired - lateinit var primaryDataSource: DataSource - - @Test - fun testPrimaryDatabaseConfiguration() { - assertNotNull(primaryDataSource, " failed to create primary data source") - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt new file mode 100644 index 000000000..a9a2ae73e --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2019 Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.db + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import java.io.File +import java.nio.file.Paths +import kotlin.test.assertTrue + +@RunWith(SpringRunner::class) +@EnableAutoConfiguration +@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +class BlueprintProcessorCatalogServiceImplTest { + + @Autowired + lateinit var blueprintCatalog: BluePrintCatalogService + + @Test + fun `test catalog service`() { + val file = Paths.get("./src/test/resources/test-cba.zip").toFile() + assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") + + blueprintCatalog.saveToDatabase(file) + + blueprintCatalog.getFromDatabase("baseconfiguration", "1.0.0") + + blueprintCatalog.deleteFromDatabase("baseconfiguration", "1.0.0") + + File("./src/test/resources/baseconfiguration").deleteRecursively() + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfigurationTest.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfigurationTest.kt new file mode 100644 index 000000000..b4a21780b --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfigurationTest.kt @@ -0,0 +1,49 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import javax.sql.DataSource +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [BlueprintPropertyConfiguration::class, BluePrintProperties::class, + BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) +@EnableAutoConfiguration +class PrimaryDatabaseConfigurationTest { + + @Autowired + lateinit var primaryDataSource: DataSource + + @Test + fun testPrimaryDatabaseConfiguration() { + assertNotNull(primaryDataSource, " failed to create primary data source") + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/logback-test.xml index f9ec9fe57..355cd3ace 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/logback-test.xml +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/logback-test.xml @@ -26,7 +26,7 @@ - + diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/pom.xml b/ms/blueprintsprocessor/modules/commons/dmaap-lib/pom.xml index 30f83d389..5f302993a 100644 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/pom.xml +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/pom.xml @@ -21,7 +21,7 @@ 4.0.0 - org.onap.ccsdk.apps.blueprintsprocessor + org.onap.ccsdk.cds.blueprintsprocessor commons 0.4.2-SNAPSHOT @@ -69,7 +69,7 @@ test - org.onap.ccsdk.apps.blueprintsprocessor + org.onap.ccsdk.cds.blueprintsprocessor processor-core diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt deleted file mode 100644 index dd884092d..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CDS - * ================================================================================ - * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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.apps.blueprintsprocessor.dmaap - -import com.att.nsa.mr.client.MRBatchingPublisher -import com.att.nsa.mr.client.MRClientFactory -import com.att.nsa.mr.client.impl.MRSimplerBatchPublisher - -/** - * Representation of DMAAP client service for AAF auth type. - */ -class AafAuthDmaapClientService(private val clientProps: - AafAuthDmaapClientProperties) - : BluePrintDmaapClientService { - - /** - * The constructed DMAAP client. - */ - var clients: MutableList = mutableListOf() - - - /** - * Returns the DMAAP client after constructing it properly with the data - * that is required for AAF auth connection. - */ - override fun getDmaapClient(): MutableList { - if (!clients.isEmpty()) { - return clients - } - val topics = mutableListOf() - topics.addAll(clientProps.topic.split(",")) - - for (t in topics) { - val client = MRClientFactory.createBatchingPublisher( - clientProps.host, t, clientProps.username, - clientProps.password, 1, 1, false, - clientProps.type, "") - val batchPublisher = client as MRSimplerBatchPublisher - batchPublisher.props = clientProps.props - clients.add(client) - } - return clients - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt deleted file mode 100644 index 21d7128e4..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt +++ /dev/null @@ -1,102 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CDS - * ================================================================================ - * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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.apps.blueprintsprocessor.dmaap - -import com.att.nsa.mr.client.MRBatchingPublisher -import com.att.nsa.mr.client.MRPublisher -import org.slf4j.LoggerFactory -import java.io.IOException -import java.util.concurrent.TimeUnit - - -/** - * Abstraction of DMAAP client services that could form DMAAP client from the - * properties provided. This abstraction also provides a mechanism to send - * messages with the given partition in a session and closing the same. - */ -interface BluePrintDmaapClientService { - - /** - * Static variable for logging. - */ - companion object { - var log = LoggerFactory.getLogger( - BluePrintDmaapClientService::class.java)!! - } - - /** - * Returns the properly constructed DMAAP client with the type. - */ - fun getDmaapClient(): MutableList - - /** - * Sends messages to the sessions created by the information provided from - * application.properties and event.properties file - */ - fun sendMessage(msgs: Collection): Boolean { - var success = true - val clients = getDmaapClient() - val dmaapMsgs = mutableListOf() - for (m in msgs) { - dmaapMsgs.add(MRPublisher.message("1", m)) - } - log.info("Sending messages to the DMAAP Server") - for (client in clients) { - try { - client.send(dmaapMsgs) - } catch (e: IOException) { - success = false - log.error(e.message, e) - } - } - return success - } - - /** - * Sends message to the sessions created by the information provided from - * application.properties and event.properties file - */ - fun sendMessage(msg: String): Boolean { - val msgs = mutableListOf() - msgs.add(msg) - return sendMessage(msgs) - } - - /** - * Closes the opened session that was used for sending messages. - */ - fun close(timeout: Long): MutableList>? { - log.debug("Closing the DMAAP producer clients") - var msgs: MutableList> = - mutableListOf() - val clients = getDmaapClient() - for (client in clients) { - try { - var ms = client.close(timeout, TimeUnit.SECONDS) - msgs.add(ms) - } catch (e: IOException) { - log.warn("Unable to cleanly close the connection from the " + - "client $client", e) - } - } - return msgs - } -} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt deleted file mode 100644 index ca1a07ba3..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CDS - * ================================================================================ - * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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.apps.blueprintsprocessor.dmaap - -import org.springframework.boot.context.properties.EnableConfigurationProperties -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration - -/** - * Representation of DMAAP lib configuration to load the required property - * files into the application context. - */ -@Configuration -@ComponentScan -@EnableConfigurationProperties -open class BluePrintDmaapLibConfiguration - -/** - * Util constants required for DMAAP library to use. - */ -class DmaapLibConstants { - companion object { - const val SERVICE_BLUEPRINT_DMAAP_LIB_PROPERTY = "blueprint" + - "-dmaap-lib-property-service" - const val TYPE_HTTP_NO_AUTH = "HTTPNOAUTH" - const val TYPE_HTTP_AAF_AUTH = "HTTPAAF" - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt deleted file mode 100644 index 7abbefbca..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt +++ /dev/null @@ -1,187 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CDS - * ================================================================================ - * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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.apps.blueprintsprocessor.dmaap - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties -import org.onap.ccsdk.apps.blueprintsprocessor.dmaap.DmaapLibConstants.Companion.SERVICE_BLUEPRINT_DMAAP_LIB_PROPERTY -import org.onap.ccsdk.apps.blueprintsprocessor.dmaap.DmaapLibConstants.Companion.TYPE_HTTP_AAF_AUTH -import org.onap.ccsdk.apps.blueprintsprocessor.dmaap.DmaapLibConstants.Companion.TYPE_HTTP_NO_AUTH -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.context.annotation.Configuration -import org.springframework.context.annotation.PropertySource -import org.springframework.context.annotation.PropertySources -import org.springframework.core.env.ConfigurableEnvironment -import org.springframework.core.env.Environment -import org.springframework.core.io.support.ResourcePropertySource -import org.springframework.stereotype.Service -import java.util.Properties - -/** - * Representation of DMAAP lib property service to load the properties - * according to the connection type to the DMAAP server and returning back - * the appropriate DMAAP client to send messages DMAAP client. - */ -@Service(SERVICE_BLUEPRINT_DMAAP_LIB_PROPERTY) -@Configuration -@PropertySources(PropertySource("classpath:event.properties")) -open class BluePrintDmaapLibPropertyService(private var bluePrintProperties: - BluePrintProperties) { - - /** - * Static variable for logging. - */ - companion object { - var log = LoggerFactory.getLogger( - BluePrintDmaapLibPropertyService::class.java)!! - } - - /** - * Environment entity to derive it from the system to load a specific - * property file. - */ - @Autowired - lateinit var env: Environment - - /** - * Returns the DMAAP client by providing the input properties as a JSON - * node. - */ - fun blueprintDmaapClientService(jsonNode: JsonNode): - BluePrintDmaapClientService { - val dmaapProps = dmaapClientProperties(jsonNode) - return blueprintDmaapClientService(dmaapProps) - } - - /** - * Returns the DMAAP client by providing the input properties as a - * selector string. - */ - fun blueprintDmaapClientService(selector: String): - BluePrintDmaapClientService { - val prefix = "blueprintsprocessor.dmaapclient.$selector" - val dmaapProps = dmaapClientProperties(prefix) - return blueprintDmaapClientService(dmaapProps) - } - - /** - * Returns the DMAAP client properties from the type of connection it - * requires. - */ - fun dmaapClientProperties(prefix: String): DmaapClientProperties { - val type = bluePrintProperties.propertyBeanType( - "$prefix.type", String::class.java) - val clientProps : DmaapClientProperties - - when (type) { - TYPE_HTTP_NO_AUTH -> { - clientProps = bluePrintProperties.propertyBeanType( - prefix, HttpNoAuthDmaapClientProperties::class.java) - clientProps.props = parseEventProps() - } - - TYPE_HTTP_AAF_AUTH -> { - clientProps = bluePrintProperties.propertyBeanType( - prefix, AafAuthDmaapClientProperties::class.java) - clientProps.props = parseEventProps() - } - - else -> { - throw BluePrintProcessorException("DMAAP adaptor($type) is " + - "not supported") - } - } - return clientProps - } - - /** - * Returns the DMAAP client properties from the type of connection it - * requires. - */ - fun dmaapClientProperties(jsonNode: JsonNode): DmaapClientProperties { - val type = jsonNode.get("type").textValue() - val clientProps : DmaapClientProperties - - when (type) { - TYPE_HTTP_NO_AUTH -> { - clientProps = JacksonUtils.readValue(jsonNode, - HttpNoAuthDmaapClientProperties::class.java)!! - clientProps.props = parseEventProps() - } - - TYPE_HTTP_AAF_AUTH -> { - clientProps = JacksonUtils.readValue(jsonNode, - AafAuthDmaapClientProperties::class.java)!! - clientProps.props = parseEventProps() - } - - else -> { - throw BluePrintProcessorException("DMAAP adaptor($type) is " + - "not supported") - } - } - return clientProps - } - - /** - * Returns DMAAP client service according to the type of client properties. - */ - private fun blueprintDmaapClientService(clientProps: DmaapClientProperties): - BluePrintDmaapClientService { - when (clientProps) { - is HttpNoAuthDmaapClientProperties -> { - return HttpNoAuthDmaapClientService(clientProps) - } - - is AafAuthDmaapClientProperties -> { - return AafAuthDmaapClientService(clientProps) - } - - else -> { - throw BluePrintProcessorException("Unable to get the DMAAP " + - "client") - } - } - } - - /** - * Parses the event.properties file which contains the default values for - * the connection required. - */ - private fun parseEventProps(): Properties { - val prodProps = Properties() - val proProps = (env as ConfigurableEnvironment).propertySources.get( - "class path resource [event.properties]") - - if (proProps != null) { - val entries = (proProps as ResourcePropertySource).source.entries - for (e in entries) { - prodProps.put(e.key, e.value) - } - } else { - log.error("Unable to load the event.properties file") - } - return prodProps - } -} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/DmaapClientProperties.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/DmaapClientProperties.kt deleted file mode 100644 index 97df2723b..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/DmaapClientProperties.kt +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CDS - * ================================================================================ - * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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.apps.blueprintsprocessor.dmaap - -import java.util.Properties - -/** - * Representation of data required for all DMAAP client. - */ -open class DmaapClientProperties { - lateinit var props: Properties - lateinit var type: String - lateinit var host: String - lateinit var topic: String -} - -/** - * Representation of data required for HTTP no auth DMAAP client. - */ -open class HttpNoAuthDmaapClientProperties : DmaapClientProperties() - -/** - * Representation of data required for AAF auth DMAAP client. - */ -open class AafAuthDmaapClientProperties : DmaapClientProperties() { - lateinit var username: String - lateinit var password: String -} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt deleted file mode 100644 index ad023b962..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CDS - * ================================================================================ - * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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.apps.blueprintsprocessor.dmaap - -import com.att.nsa.mr.client.MRBatchingPublisher -import com.att.nsa.mr.client.MRClientFactory.createSimplePublisher -import com.att.nsa.mr.client.impl.MRSimplerBatchPublisher - -/** - * Representation of DMAAP client service for HTTP no auth type. - */ -class HttpNoAuthDmaapClientService(private val clientProps: - HttpNoAuthDmaapClientProperties) - : BluePrintDmaapClientService { - - /** - * The constructed DMAAP client. - */ - var clients: MutableList = mutableListOf() - - - /** - * Returns the DMAAP client after constructing it properly with the data - * that is required for HTTP no auth connection. - */ - override fun getDmaapClient(): MutableList { - if (!clients.isEmpty()) { - return clients - } - val topics = mutableListOf() - topics.addAll(clientProps.topic.split(",")) - - for (t in topics) { - val client = createSimplePublisher(clientProps.host, t) - val batchPublisher = client as MRSimplerBatchPublisher - batchPublisher.setProtocolFlag(clientProps.type) - batchPublisher.props = clientProps.props - clients.add(client) - } - - return clients - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt new file mode 100644 index 000000000..2dbea8fc9 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CDS + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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.cds.blueprintsprocessor.dmaap + +import com.att.nsa.mr.client.MRBatchingPublisher +import com.att.nsa.mr.client.MRClientFactory +import com.att.nsa.mr.client.impl.MRSimplerBatchPublisher + +/** + * Representation of DMAAP client service for AAF auth type. + */ +class AafAuthDmaapClientService(private val clientProps: + AafAuthDmaapClientProperties) + : BluePrintDmaapClientService { + + /** + * The constructed DMAAP client. + */ + var clients: MutableList = mutableListOf() + + + /** + * Returns the DMAAP client after constructing it properly with the data + * that is required for AAF auth connection. + */ + override fun getDmaapClient(): MutableList { + if (!clients.isEmpty()) { + return clients + } + val topics = mutableListOf() + topics.addAll(clientProps.topic.split(",")) + + for (t in topics) { + val client = MRClientFactory.createBatchingPublisher( + clientProps.host, t, clientProps.username, + clientProps.password, 1, 1, false, + clientProps.type, "") + val batchPublisher = client as MRSimplerBatchPublisher + batchPublisher.props = clientProps.props + clients.add(client) + } + return clients + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt new file mode 100644 index 000000000..a4cb5a3e6 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CDS + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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.cds.blueprintsprocessor.dmaap + +import com.att.nsa.mr.client.MRBatchingPublisher +import com.att.nsa.mr.client.MRPublisher +import org.slf4j.LoggerFactory +import java.io.IOException +import java.util.concurrent.TimeUnit + + +/** + * Abstraction of DMAAP client services that could form DMAAP client from the + * properties provided. This abstraction also provides a mechanism to send + * messages with the given partition in a session and closing the same. + */ +interface BluePrintDmaapClientService { + + /** + * Static variable for logging. + */ + companion object { + var log = LoggerFactory.getLogger( + BluePrintDmaapClientService::class.java)!! + } + + /** + * Returns the properly constructed DMAAP client with the type. + */ + fun getDmaapClient(): MutableList + + /** + * Sends messages to the sessions created by the information provided from + * application.properties and event.properties file + */ + fun sendMessage(msgs: Collection): Boolean { + var success = true + val clients = getDmaapClient() + val dmaapMsgs = mutableListOf() + for (m in msgs) { + dmaapMsgs.add(MRPublisher.message("1", m)) + } + log.info("Sending messages to the DMAAP Server") + for (client in clients) { + try { + client.send(dmaapMsgs) + } catch (e: IOException) { + success = false + log.error(e.message, e) + } + } + return success + } + + /** + * Sends message to the sessions created by the information provided from + * application.properties and event.properties file + */ + fun sendMessage(msg: String): Boolean { + val msgs = mutableListOf() + msgs.add(msg) + return sendMessage(msgs) + } + + /** + * Closes the opened session that was used for sending messages. + */ + fun close(timeout: Long): MutableList>? { + log.debug("Closing the DMAAP producer clients") + var msgs: MutableList> = + mutableListOf() + val clients = getDmaapClient() + for (client in clients) { + try { + var ms = client.close(timeout, TimeUnit.SECONDS) + msgs.add(ms) + } catch (e: IOException) { + log.warn("Unable to cleanly close the connection from the " + + "client $client", e) + } + } + return msgs + } +} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt new file mode 100644 index 000000000..51cd3bf0a --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CDS + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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.cds.blueprintsprocessor.dmaap + +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +/** + * Representation of DMAAP lib configuration to load the required property + * files into the application context. + */ +@Configuration +@ComponentScan +@EnableConfigurationProperties +open class BluePrintDmaapLibConfiguration + +/** + * Util constants required for DMAAP library to use. + */ +class DmaapLibConstants { + companion object { + const val SERVICE_BLUEPRINT_DMAAP_LIB_PROPERTY = "blueprint" + + "-dmaap-lib-property-service" + const val TYPE_HTTP_NO_AUTH = "HTTPNOAUTH" + const val TYPE_HTTP_AAF_AUTH = "HTTPAAF" + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt new file mode 100644 index 000000000..8604d8880 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt @@ -0,0 +1,187 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CDS + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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.cds.blueprintsprocessor.dmaap + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties +import org.onap.ccsdk.cds.blueprintsprocessor.dmaap.DmaapLibConstants.Companion.SERVICE_BLUEPRINT_DMAAP_LIB_PROPERTY +import org.onap.ccsdk.cds.blueprintsprocessor.dmaap.DmaapLibConstants.Companion.TYPE_HTTP_AAF_AUTH +import org.onap.ccsdk.cds.blueprintsprocessor.dmaap.DmaapLibConstants.Companion.TYPE_HTTP_NO_AUTH +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.PropertySource +import org.springframework.context.annotation.PropertySources +import org.springframework.core.env.ConfigurableEnvironment +import org.springframework.core.env.Environment +import org.springframework.core.io.support.ResourcePropertySource +import org.springframework.stereotype.Service +import java.util.Properties + +/** + * Representation of DMAAP lib property service to load the properties + * according to the connection type to the DMAAP server and returning back + * the appropriate DMAAP client to send messages DMAAP client. + */ +@Service(SERVICE_BLUEPRINT_DMAAP_LIB_PROPERTY) +@Configuration +@PropertySources(PropertySource("classpath:event.properties")) +open class BluePrintDmaapLibPropertyService(private var bluePrintProperties: + BluePrintProperties) { + + /** + * Static variable for logging. + */ + companion object { + var log = LoggerFactory.getLogger( + BluePrintDmaapLibPropertyService::class.java)!! + } + + /** + * Environment entity to derive it from the system to load a specific + * property file. + */ + @Autowired + lateinit var env: Environment + + /** + * Returns the DMAAP client by providing the input properties as a JSON + * node. + */ + fun blueprintDmaapClientService(jsonNode: JsonNode): + BluePrintDmaapClientService { + val dmaapProps = dmaapClientProperties(jsonNode) + return blueprintDmaapClientService(dmaapProps) + } + + /** + * Returns the DMAAP client by providing the input properties as a + * selector string. + */ + fun blueprintDmaapClientService(selector: String): + BluePrintDmaapClientService { + val prefix = "blueprintsprocessor.dmaapclient.$selector" + val dmaapProps = dmaapClientProperties(prefix) + return blueprintDmaapClientService(dmaapProps) + } + + /** + * Returns the DMAAP client properties from the type of connection it + * requires. + */ + fun dmaapClientProperties(prefix: String): DmaapClientProperties { + val type = bluePrintProperties.propertyBeanType( + "$prefix.type", String::class.java) + val clientProps : DmaapClientProperties + + when (type) { + TYPE_HTTP_NO_AUTH -> { + clientProps = bluePrintProperties.propertyBeanType( + prefix, HttpNoAuthDmaapClientProperties::class.java) + clientProps.props = parseEventProps() + } + + TYPE_HTTP_AAF_AUTH -> { + clientProps = bluePrintProperties.propertyBeanType( + prefix, AafAuthDmaapClientProperties::class.java) + clientProps.props = parseEventProps() + } + + else -> { + throw BluePrintProcessorException("DMAAP adaptor($type) is " + + "not supported") + } + } + return clientProps + } + + /** + * Returns the DMAAP client properties from the type of connection it + * requires. + */ + fun dmaapClientProperties(jsonNode: JsonNode): DmaapClientProperties { + val type = jsonNode.get("type").textValue() + val clientProps : DmaapClientProperties + + when (type) { + TYPE_HTTP_NO_AUTH -> { + clientProps = JacksonUtils.readValue(jsonNode, + HttpNoAuthDmaapClientProperties::class.java)!! + clientProps.props = parseEventProps() + } + + TYPE_HTTP_AAF_AUTH -> { + clientProps = JacksonUtils.readValue(jsonNode, + AafAuthDmaapClientProperties::class.java)!! + clientProps.props = parseEventProps() + } + + else -> { + throw BluePrintProcessorException("DMAAP adaptor($type) is " + + "not supported") + } + } + return clientProps + } + + /** + * Returns DMAAP client service according to the type of client properties. + */ + private fun blueprintDmaapClientService(clientProps: DmaapClientProperties): + BluePrintDmaapClientService { + when (clientProps) { + is HttpNoAuthDmaapClientProperties -> { + return HttpNoAuthDmaapClientService(clientProps) + } + + is AafAuthDmaapClientProperties -> { + return AafAuthDmaapClientService(clientProps) + } + + else -> { + throw BluePrintProcessorException("Unable to get the DMAAP " + + "client") + } + } + } + + /** + * Parses the event.properties file which contains the default values for + * the connection required. + */ + private fun parseEventProps(): Properties { + val prodProps = Properties() + val proProps = (env as ConfigurableEnvironment).propertySources.get( + "class path resource [event.properties]") + + if (proProps != null) { + val entries = (proProps as ResourcePropertySource).source.entries + for (e in entries) { + prodProps.put(e.key, e.value) + } + } else { + log.error("Unable to load the event.properties file") + } + return prodProps + } +} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/DmaapClientProperties.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/DmaapClientProperties.kt new file mode 100644 index 000000000..9d942943e --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/DmaapClientProperties.kt @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CDS + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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.cds.blueprintsprocessor.dmaap + +import java.util.Properties + +/** + * Representation of data required for all DMAAP client. + */ +open class DmaapClientProperties { + lateinit var props: Properties + lateinit var type: String + lateinit var host: String + lateinit var topic: String +} + +/** + * Representation of data required for HTTP no auth DMAAP client. + */ +open class HttpNoAuthDmaapClientProperties : DmaapClientProperties() + +/** + * Representation of data required for AAF auth DMAAP client. + */ +open class AafAuthDmaapClientProperties : DmaapClientProperties() { + lateinit var username: String + lateinit var password: String +} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt new file mode 100644 index 000000000..8bf50a944 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CDS + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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.cds.blueprintsprocessor.dmaap + +import com.att.nsa.mr.client.MRBatchingPublisher +import com.att.nsa.mr.client.MRClientFactory.createSimplePublisher +import com.att.nsa.mr.client.impl.MRSimplerBatchPublisher + +/** + * Representation of DMAAP client service for HTTP no auth type. + */ +class HttpNoAuthDmaapClientService(private val clientProps: + HttpNoAuthDmaapClientProperties) + : BluePrintDmaapClientService { + + /** + * The constructed DMAAP client. + */ + var clients: MutableList = mutableListOf() + + + /** + * Returns the DMAAP client after constructing it properly with the data + * that is required for HTTP no auth connection. + */ + override fun getDmaapClient(): MutableList { + if (!clients.isEmpty()) { + return clients + } + val topics = mutableListOf() + topics.addAll(clientProps.topic.split(",")) + + for (t in topics) { + val client = createSimplePublisher(clientProps.host, t) + val batchPublisher = client as MRSimplerBatchPublisher + batchPublisher.setProtocolFlag(clientProps.type) + batchPublisher.props = clientProps.props + clients.add(client) + } + + return clients + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/apps/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/apps/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt deleted file mode 100644 index 9b3aae5e6..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/apps/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt +++ /dev/null @@ -1,215 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP - CDS - * ================================================================================ - * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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.ccsdk.apps.blueprintprocessor.dmaap - -import com.fasterxml.jackson.databind.ObjectMapper -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties -import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.dmaap.BluePrintDmaapLibConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.dmaap.BluePrintDmaapLibPropertyService -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.http.HttpStatus -import org.springframework.http.ResponseEntity -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController -import kotlin.test.assertEquals -import kotlin.test.assertNotNull - -/** - * Unit test cases for DMaap publisher code. - */ -@RunWith(SpringRunner::class) -@EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class]) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -@ContextConfiguration(classes = [BluePrintDmaapLibConfiguration::class, TestController::class, - BlueprintPropertyConfiguration::class, BluePrintProperties::class]) -@TestPropertySource(properties = ["server.port=9111", - "blueprintsprocessor.dmaapclient.aai.topic=cds_aai", - "blueprintsprocessor.dmaapclient.aai.type=HTTPNOAUTH", - "blueprintsprocessor.dmaapclient.aai.host=127.0.0.1:9111", - "blueprintsprocessor.dmaapclient.multi.topic=cds_multi1,cds_multi2", - "blueprintsprocessor.dmaapclient.multi.type=HTTPNOAUTH", - "blueprintsprocessor.dmaapclient.multi.host=127.0.0.1:9111"]) -class TestDmaapEventPublisher { - - @Autowired - lateinit var dmaapService : BluePrintDmaapLibPropertyService - - /** - * Tests the event properties being set properly and sent as request. - */ - @Test - fun testEventProperties() { - val strList = mutableListOf() - val dmaapClient = dmaapService.blueprintDmaapClientService("aai") - - strList.add("{\n" + - " \"a\" : \"hello\"\n" + - "}") - dmaapClient.sendMessage(strList) - val msgs = dmaapClient.close(2) - assertEquals(msgs!!.size, 1) - val topic1 = msgs.get(0) - assertEquals(topic1!!.size, 0) - } - - /** - * Tests the event properties being set properly and sent as request with - * single message. - */ - @Test - fun testEventPropertiesWithSingleMsg() { - val dmaapClient = dmaapService.blueprintDmaapClientService("aai") - val str : String = "{\n" + - " \"a\" : \"hello\"\n" + - "}" - dmaapClient.sendMessage(str) - val msgs = dmaapClient.close(2) - assertEquals(msgs!!.size, 1) - val topic1 = msgs.get(0) - assertEquals(topic1!!.size, 0) - } - - /** - * Tests the event properties with multiple topics. - */ - @Test - fun testMultiTopicProperties() { - val strList = mutableListOf() - val dmaapClient = dmaapService.blueprintDmaapClientService("multi") - - strList.add("{\n" + - " \"a\" : \"hello\"\n" + - "}") - dmaapClient.sendMessage(strList) - val msgs = dmaapClient.close(2) - assertEquals(msgs!!.size, 2) - val topic1 = msgs.get(0) - assertEquals(topic1!!.size, 0) - val topic2 = msgs.get(1) - assertEquals(topic2!!.size, 0) - } - - - /** - * Tests the event properties with multiple topics with JSON node as input. - */ - @Test - fun testMultiTopicPropertiesWithJsonInput() { - val jsonString = "{\n" + - " \"topic\" : \"cds_json1,cds_json2\",\n" + - " \"type\" : \"HTTPNOAUTH\",\n" + - " \"host\" : \"127.0.0.1:9111\"\n" + - "}" - val mapper = ObjectMapper() - val node = mapper.readTree(jsonString) - val strList = mutableListOf() - val dmaapClient = dmaapService.blueprintDmaapClientService(node) - - strList.add("{\n" + - " \"a\" : \"hello\"\n" + - "}") - dmaapClient.sendMessage(strList) - val msgs = dmaapClient.close(2) - assertEquals(msgs!!.size, 2) - val topic1 = msgs.get(0) - assertEquals(topic1!!.size, 0) - val topic2 = msgs.get(1) - assertEquals(topic2!!.size, 0) - } - - - /** - * Tests the event properties with multiple messages. - */ - @Test - fun testMultiMsgsProperties() { - val strList = mutableListOf() - val dmaapClient = dmaapService.blueprintDmaapClientService("aai") - - strList.add("{\n" + - " \"a\" : \"hello\"\n" + - "}") - strList.add("{\n" + - " \"a\" : \"second\"\n" + - "}") - dmaapClient.sendMessage(strList) - val msgs = dmaapClient.close(2) - assertEquals(msgs!!.size, 1) - val topic1 = msgs.get(0) - assertEquals(topic1!!.size, 0) - } - - /** - * Tests the DMAAP client properties generated with the complete prefix. - */ - @Test - fun testDmaapClientProperties() { - val properties = dmaapService.dmaapClientProperties( - "blueprintsprocessor.dmaapclient.aai") - assertNotNull(properties, "failed to create property bean") - assertNotNull(properties.host, "failed to get url property" + - " in property bean") - } - - /** - * Tests the blueprint DMAAP client service with only selector prefix. - */ - @Test - fun testBlueprintDmaapClientService() { - val blueprintDmaapClientService = - dmaapService.blueprintDmaapClientService("aai") - assertNotNull(blueprintDmaapClientService, - "failed to create blueprintDmaapClientService") - } - -} - -/** - * Rest controller for testing the client request that is sent. - */ -@RestController -@RequestMapping(path = ["/events"]) -open class TestController { - - /** - * Accepts request for a topic and sends a message as response. - */ - @PostMapping(path = ["/{topic}"]) - fun postTopic(@PathVariable(value = "topic") topic : String): - ResponseEntity { - var a = "{\n" + - " \"message\" : \"The message is published into $topic " + - "topic\"\n" + - "}" - return ResponseEntity(a, HttpStatus.OK) - } -} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/cds/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/cds/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt new file mode 100644 index 000000000..65d877518 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/cds/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt @@ -0,0 +1,215 @@ +/* + * ============LICENSE_START======================================================= + * ONAP - CDS + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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.ccsdk.apps.blueprintprocessor.dmaap + +import com.fasterxml.jackson.databind.ObjectMapper +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.dmaap.BluePrintDmaapLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.dmaap.BluePrintDmaapLibPropertyService +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +/** + * Unit test cases for DMaap publisher code. + */ +@RunWith(SpringRunner::class) +@EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class]) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@ContextConfiguration(classes = [BluePrintDmaapLibConfiguration::class, TestController::class, + BlueprintPropertyConfiguration::class, BluePrintProperties::class]) +@TestPropertySource(properties = ["server.port=9111", + "blueprintsprocessor.dmaapclient.aai.topic=cds_aai", + "blueprintsprocessor.dmaapclient.aai.type=HTTPNOAUTH", + "blueprintsprocessor.dmaapclient.aai.host=127.0.0.1:9111", + "blueprintsprocessor.dmaapclient.multi.topic=cds_multi1,cds_multi2", + "blueprintsprocessor.dmaapclient.multi.type=HTTPNOAUTH", + "blueprintsprocessor.dmaapclient.multi.host=127.0.0.1:9111"]) +class TestDmaapEventPublisher { + + @Autowired + lateinit var dmaapService : BluePrintDmaapLibPropertyService + + /** + * Tests the event properties being set properly and sent as request. + */ + @Test + fun testEventProperties() { + val strList = mutableListOf() + val dmaapClient = dmaapService.blueprintDmaapClientService("aai") + + strList.add("{\n" + + " \"a\" : \"hello\"\n" + + "}") + dmaapClient.sendMessage(strList) + val msgs = dmaapClient.close(2) + assertEquals(msgs!!.size, 1) + val topic1 = msgs.get(0) + assertEquals(topic1!!.size, 0) + } + + /** + * Tests the event properties being set properly and sent as request with + * single message. + */ + @Test + fun testEventPropertiesWithSingleMsg() { + val dmaapClient = dmaapService.blueprintDmaapClientService("aai") + val str : String = "{\n" + + " \"a\" : \"hello\"\n" + + "}" + dmaapClient.sendMessage(str) + val msgs = dmaapClient.close(2) + assertEquals(msgs!!.size, 1) + val topic1 = msgs.get(0) + assertEquals(topic1!!.size, 0) + } + + /** + * Tests the event properties with multiple topics. + */ + @Test + fun testMultiTopicProperties() { + val strList = mutableListOf() + val dmaapClient = dmaapService.blueprintDmaapClientService("multi") + + strList.add("{\n" + + " \"a\" : \"hello\"\n" + + "}") + dmaapClient.sendMessage(strList) + val msgs = dmaapClient.close(2) + assertEquals(msgs!!.size, 2) + val topic1 = msgs.get(0) + assertEquals(topic1!!.size, 0) + val topic2 = msgs.get(1) + assertEquals(topic2!!.size, 0) + } + + + /** + * Tests the event properties with multiple topics with JSON node as input. + */ + @Test + fun testMultiTopicPropertiesWithJsonInput() { + val jsonString = "{\n" + + " \"topic\" : \"cds_json1,cds_json2\",\n" + + " \"type\" : \"HTTPNOAUTH\",\n" + + " \"host\" : \"127.0.0.1:9111\"\n" + + "}" + val mapper = ObjectMapper() + val node = mapper.readTree(jsonString) + val strList = mutableListOf() + val dmaapClient = dmaapService.blueprintDmaapClientService(node) + + strList.add("{\n" + + " \"a\" : \"hello\"\n" + + "}") + dmaapClient.sendMessage(strList) + val msgs = dmaapClient.close(2) + assertEquals(msgs!!.size, 2) + val topic1 = msgs.get(0) + assertEquals(topic1!!.size, 0) + val topic2 = msgs.get(1) + assertEquals(topic2!!.size, 0) + } + + + /** + * Tests the event properties with multiple messages. + */ + @Test + fun testMultiMsgsProperties() { + val strList = mutableListOf() + val dmaapClient = dmaapService.blueprintDmaapClientService("aai") + + strList.add("{\n" + + " \"a\" : \"hello\"\n" + + "}") + strList.add("{\n" + + " \"a\" : \"second\"\n" + + "}") + dmaapClient.sendMessage(strList) + val msgs = dmaapClient.close(2) + assertEquals(msgs!!.size, 1) + val topic1 = msgs.get(0) + assertEquals(topic1!!.size, 0) + } + + /** + * Tests the DMAAP client properties generated with the complete prefix. + */ + @Test + fun testDmaapClientProperties() { + val properties = dmaapService.dmaapClientProperties( + "blueprintsprocessor.dmaapclient.aai") + assertNotNull(properties, "failed to create property bean") + assertNotNull(properties.host, "failed to get url property" + + " in property bean") + } + + /** + * Tests the blueprint DMAAP client service with only selector prefix. + */ + @Test + fun testBlueprintDmaapClientService() { + val blueprintDmaapClientService = + dmaapService.blueprintDmaapClientService("aai") + assertNotNull(blueprintDmaapClientService, + "failed to create blueprintDmaapClientService") + } + +} + +/** + * Rest controller for testing the client request that is sent. + */ +@RestController +@RequestMapping(path = ["/events"]) +open class TestController { + + /** + * Accepts request for a topic and sends a message as response. + */ + @PostMapping(path = ["/{topic}"]) + fun postTopic(@PathVariable(value = "topic") topic : String): + ResponseEntity { + var a = "{\n" + + " \"message\" : \"The message is published into $topic " + + "topic\"\n" + + "}" + return ResponseEntity(a, HttpStatus.OK) + } +} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/resources/logback-test.xml index 0f76057ad..ebb41b854 100644 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/resources/logback-test.xml +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/resources/logback-test.xml @@ -31,7 +31,7 @@ - + diff --git a/ms/blueprintsprocessor/modules/commons/pom.xml b/ms/blueprintsprocessor/modules/commons/pom.xml index 205fd94c5..ebd905248 100755 --- a/ms/blueprintsprocessor/modules/commons/pom.xml +++ b/ms/blueprintsprocessor/modules/commons/pom.xml @@ -20,7 +20,7 @@ 4.0.0 - org.onap.ccsdk.apps.blueprintsprocessor + org.onap.ccsdk.cds.blueprintsprocessor modules 0.4.2-SNAPSHOT @@ -38,7 +38,7 @@ - org.onap.ccsdk.apps.controllerblueprints + org.onap.ccsdk.cds.controllerblueprints resource-dict diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/pom.xml b/ms/blueprintsprocessor/modules/commons/processor-core/pom.xml index 32e4b3d4a..93a9b793a 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/pom.xml +++ b/ms/blueprintsprocessor/modules/commons/processor-core/pom.xml @@ -19,7 +19,7 @@ 4.0.0 - org.onap.ccsdk.apps.blueprintsprocessor + org.onap.ccsdk.cds.blueprintsprocessor commons 0.4.2-SNAPSHOT diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/BluePrintCoreConfiguration.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/BluePrintCoreConfiguration.kt deleted file mode 100644 index 07e494a1a..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/BluePrintCoreConfiguration.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.core - -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.context.properties.bind.Binder -import org.springframework.boot.context.properties.source.ConfigurationPropertySources -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.core.env.Environment - - -@Configuration -open class BluePrintCoreConfiguration { - - @Value("\${blueprintsprocessor.blueprintDeployPath}") - lateinit var deployPath: String - - @Value("\${blueprintsprocessor.blueprintArchivePath}") - lateinit var archivePath: String - -} - -@Configuration -open class BlueprintPropertyConfiguration { - @Autowired - lateinit var environment: Environment - - @Bean - open fun bluePrintPropertyBinder(): Binder { - val configurationPropertySource = ConfigurationPropertySources.get(environment) - return Binder(configurationPropertySource) - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/BluePrintProperties.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/BluePrintProperties.kt deleted file mode 100644 index 10b8ceb5e..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/BluePrintProperties.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.core - -import org.springframework.boot.context.properties.bind.Bindable -import org.springframework.boot.context.properties.bind.Binder -import org.springframework.stereotype.Service - -@Service -open class BluePrintProperties(var bluePrintPropertyBinder: Binder) { - - fun propertyBeanType(prefix: String, type: Class): T { - return bluePrintPropertyBinder.bind(prefix, Bindable.of(type)).get() - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt deleted file mode 100644 index 41bbd1dfd..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.core.api.data - -import com.fasterxml.jackson.annotation.JsonFormat -import com.fasterxml.jackson.databind.node.ObjectNode -import io.swagger.annotations.ApiModelProperty -import java.util.* - -/** - * BlueprintProcessorData - * @author Brinda Santh - * DATE : 8/15/2018 - */ - -open class ExecutionServiceInput { - @get:ApiModelProperty(required = true) - lateinit var commonHeader: CommonHeader - @get:ApiModelProperty(required = true) - lateinit var actionIdentifiers: ActionIdentifiers - @get:ApiModelProperty(required = true) - lateinit var payload: ObjectNode -} - -open class ExecutionServiceOutput { - @get:ApiModelProperty(required = true) - lateinit var commonHeader: CommonHeader - @get:ApiModelProperty(required = true) - lateinit var actionIdentifiers: ActionIdentifiers - @get:ApiModelProperty(required = true) - var status: Status = Status() - @get:ApiModelProperty(required = true) - lateinit var payload: ObjectNode -} - -const val ACTION_MODE_ASYNC = "async" -const val ACTION_MODE_SYNC = "sync" - -open class ActionIdentifiers { - @get:ApiModelProperty(required = false) - lateinit var blueprintName: String - @get:ApiModelProperty(required = false) - lateinit var blueprintVersion: String - @get:ApiModelProperty(required = true) - lateinit var actionName: String - @get:ApiModelProperty(required = true, allowableValues = "sync, async") - lateinit var mode: String -} - -open class CommonHeader { - @get:ApiModelProperty(required = true, example = "2012-04-23T18:25:43.511Z") - @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - var timestamp: Date = Date() - @get:ApiModelProperty(required = true) - lateinit var originatorId: String - @get:ApiModelProperty(required = true) - lateinit var requestId: String - @get:ApiModelProperty(required = true) - lateinit var subRequestId: String - @get:ApiModelProperty(required = false) - var flags: Flags? = null -} - -open class Flags { - var isForce: Boolean = false - @get:ApiModelProperty(value = "3600") - var ttl: Int = 3600 -} - -open class Status { - @get:ApiModelProperty(required = true) - var code: Int = 200 - @get:ApiModelProperty(required = true) - var eventType: String = "EVENT-ACTION-RESPONSE" - @get:ApiModelProperty(required = true, example = "2012-04-23T18:25:43.511Z") - @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - var timestamp: Date = Date() - @get:ApiModelProperty(required = false) - var errorMessage: String? = null - @get:ApiModelProperty(required = true) - var message: String = "success" -} - -open class BluePrintManagementInput { - @get:ApiModelProperty(required = true) - lateinit var commonHeader: CommonHeader - @get:ApiModelProperty(required = false) - lateinit var blueprintName: String - @get:ApiModelProperty(required = false) - lateinit var blueprintVersion: String - @get:ApiModelProperty(required = true) - lateinit var fileChunk: FileChunk -} - -open class FileChunk { - @get:ApiModelProperty(required = true) - lateinit var chunk: ByteArray -} - -open class BluePrintManagementOutput { - @get:ApiModelProperty(required = true) - lateinit var commonHeader: CommonHeader - @get:ApiModelProperty(required = true) - var status: Status = Status() -} - - - diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/factory/ComponentNodeFactory.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/factory/ComponentNodeFactory.kt deleted file mode 100644 index 9c6e50752..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/factory/ComponentNodeFactory.kt +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.core.factory - -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.springframework.context.ApplicationContext -import org.springframework.context.ApplicationContextAware - -/** - * ComponentNode - * - * @author Brinda Santh - */ -interface ComponentNode { - - @Throws(BluePrintProcessorException::class) - fun validate(context: MutableMap, componentContext: MutableMap) - - @Throws(BluePrintProcessorException::class) - fun process(context: MutableMap, componentContext: MutableMap) - - @Throws(BluePrintProcessorException::class) - fun errorHandle(context: MutableMap, componentContext: MutableMap) - - @Throws(BluePrintProcessorException::class) - fun reTrigger(context: MutableMap, componentContext: MutableMap) -} - -/** - * ComponentNodeFactory - * - * @author Brinda Santh - */ -open class ComponentNodeFactory : ApplicationContextAware { - private val log = EELFManager.getInstance().getLogger(ComponentNodeFactory::class.java) - - var componentNodes: MutableMap = hashMapOf() - - fun getInstance(instanceName: String): ComponentNode? { - log.trace("looking for Component Nodes : {}", instanceName) - return componentNodes.get(instanceName) - } - - fun injectInstance(instanceName: String, componentNode: ComponentNode) { - this.componentNodes[instanceName] = componentNode - } - - override fun setApplicationContext(context: ApplicationContext) { - componentNodes = context.getBeansOfType(ComponentNode::class.java) - log.info("Injected Component Nodes : {}", componentNodes) - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/utils/PayloadUtils.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/utils/PayloadUtils.kt deleted file mode 100644 index 31dca33b8..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/utils/PayloadUtils.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.core.utils - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService - - -class PayloadUtils { - - companion object { - - fun prepareInputsFromWorkflowPayload(bluePrintRuntimeService: BluePrintRuntimeService<*>, payload: JsonNode, workflowName: String) { - val input = payload.get("$workflowName-request") - bluePrintRuntimeService.assignWorkflowInputs(workflowName, input) - } - - fun prepareDynamicInputsFromWorkflowPayload(bluePrintRuntimeService: BluePrintRuntimeService<*>, payload: JsonNode, workflowName: String) { - val input = payload.get("$workflowName-request") - val propertyFields = input.get("$workflowName-properties") - prepareDynamicInputsFromComponentPayload(bluePrintRuntimeService, propertyFields) - } - - fun prepareDynamicInputsFromComponentPayload(bluePrintRuntimeService: BluePrintRuntimeService<*>, payload: JsonNode) { - payload.fields().forEach { property -> - val path = StringBuilder(BluePrintConstants.PATH_INPUTS) - .append(BluePrintConstants.PATH_DIVIDER).append(property.key).toString() - bluePrintRuntimeService.put(path, property.value) - } - } - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintCoreConfiguration.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintCoreConfiguration.kt new file mode 100644 index 000000000..03b847e51 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintCoreConfiguration.kt @@ -0,0 +1,49 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.core + +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.annotation.Value +import org.springframework.boot.context.properties.bind.Binder +import org.springframework.boot.context.properties.source.ConfigurationPropertySources +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.core.env.Environment + + +@Configuration +open class BluePrintCoreConfiguration { + + @Value("\${blueprintsprocessor.blueprintDeployPath}") + lateinit var deployPath: String + + @Value("\${blueprintsprocessor.blueprintArchivePath}") + lateinit var archivePath: String + +} + +@Configuration +open class BlueprintPropertyConfiguration { + @Autowired + lateinit var environment: Environment + + @Bean + open fun bluePrintPropertyBinder(): Binder { + val configurationPropertySource = ConfigurationPropertySources.get(environment) + return Binder(configurationPropertySource) + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintProperties.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintProperties.kt new file mode 100644 index 000000000..e2a4808a6 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintProperties.kt @@ -0,0 +1,29 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.core + +import org.springframework.boot.context.properties.bind.Bindable +import org.springframework.boot.context.properties.bind.Binder +import org.springframework.stereotype.Service + +@Service +open class BluePrintProperties(var bluePrintPropertyBinder: Binder) { + + fun propertyBeanType(prefix: String, type: Class): T { + return bluePrintPropertyBinder.bind(prefix, Bindable.of(type)).get() + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt new file mode 100644 index 000000000..a73c6a7d1 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt @@ -0,0 +1,123 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.core.api.data + +import com.fasterxml.jackson.annotation.JsonFormat +import com.fasterxml.jackson.databind.node.ObjectNode +import io.swagger.annotations.ApiModelProperty +import java.util.* + +/** + * BlueprintProcessorData + * @author Brinda Santh + * DATE : 8/15/2018 + */ + +open class ExecutionServiceInput { + @get:ApiModelProperty(required = true) + lateinit var commonHeader: CommonHeader + @get:ApiModelProperty(required = true) + lateinit var actionIdentifiers: ActionIdentifiers + @get:ApiModelProperty(required = true) + lateinit var payload: ObjectNode +} + +open class ExecutionServiceOutput { + @get:ApiModelProperty(required = true) + lateinit var commonHeader: CommonHeader + @get:ApiModelProperty(required = true) + lateinit var actionIdentifiers: ActionIdentifiers + @get:ApiModelProperty(required = true) + var status: Status = Status() + @get:ApiModelProperty(required = true) + lateinit var payload: ObjectNode +} + +const val ACTION_MODE_ASYNC = "async" +const val ACTION_MODE_SYNC = "sync" + +open class ActionIdentifiers { + @get:ApiModelProperty(required = false) + lateinit var blueprintName: String + @get:ApiModelProperty(required = false) + lateinit var blueprintVersion: String + @get:ApiModelProperty(required = true) + lateinit var actionName: String + @get:ApiModelProperty(required = true, allowableValues = "sync, async") + lateinit var mode: String +} + +open class CommonHeader { + @get:ApiModelProperty(required = true, example = "2012-04-23T18:25:43.511Z") + @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + var timestamp: Date = Date() + @get:ApiModelProperty(required = true) + lateinit var originatorId: String + @get:ApiModelProperty(required = true) + lateinit var requestId: String + @get:ApiModelProperty(required = true) + lateinit var subRequestId: String + @get:ApiModelProperty(required = false) + var flags: Flags? = null +} + +open class Flags { + var isForce: Boolean = false + @get:ApiModelProperty(value = "3600") + var ttl: Int = 3600 +} + +open class Status { + @get:ApiModelProperty(required = true) + var code: Int = 200 + @get:ApiModelProperty(required = true) + var eventType: String = "EVENT-ACTION-RESPONSE" + @get:ApiModelProperty(required = true, example = "2012-04-23T18:25:43.511Z") + @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + var timestamp: Date = Date() + @get:ApiModelProperty(required = false) + var errorMessage: String? = null + @get:ApiModelProperty(required = true) + var message: String = "success" +} + +open class BluePrintManagementInput { + @get:ApiModelProperty(required = true) + lateinit var commonHeader: CommonHeader + @get:ApiModelProperty(required = false) + lateinit var blueprintName: String + @get:ApiModelProperty(required = false) + lateinit var blueprintVersion: String + @get:ApiModelProperty(required = true) + lateinit var fileChunk: FileChunk +} + +open class FileChunk { + @get:ApiModelProperty(required = true) + lateinit var chunk: ByteArray +} + +open class BluePrintManagementOutput { + @get:ApiModelProperty(required = true) + lateinit var commonHeader: CommonHeader + @get:ApiModelProperty(required = true) + var status: Status = Status() +} + + + diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/factory/ComponentNodeFactory.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/factory/ComponentNodeFactory.kt new file mode 100644 index 000000000..a32d61e2f --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/factory/ComponentNodeFactory.kt @@ -0,0 +1,68 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.core.factory + +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.springframework.context.ApplicationContext +import org.springframework.context.ApplicationContextAware + +/** + * ComponentNode + * + * @author Brinda Santh + */ +interface ComponentNode { + + @Throws(BluePrintProcessorException::class) + fun validate(context: MutableMap, componentContext: MutableMap) + + @Throws(BluePrintProcessorException::class) + fun process(context: MutableMap, componentContext: MutableMap) + + @Throws(BluePrintProcessorException::class) + fun errorHandle(context: MutableMap, componentContext: MutableMap) + + @Throws(BluePrintProcessorException::class) + fun reTrigger(context: MutableMap, componentContext: MutableMap) +} + +/** + * ComponentNodeFactory + * + * @author Brinda Santh + */ +open class ComponentNodeFactory : ApplicationContextAware { + private val log = EELFManager.getInstance().getLogger(ComponentNodeFactory::class.java) + + var componentNodes: MutableMap = hashMapOf() + + fun getInstance(instanceName: String): ComponentNode? { + log.trace("looking for Component Nodes : {}", instanceName) + return componentNodes.get(instanceName) + } + + fun injectInstance(instanceName: String, componentNode: ComponentNode) { + this.componentNodes[instanceName] = componentNode + } + + override fun setApplicationContext(context: ApplicationContext) { + componentNodes = context.getBeansOfType(ComponentNode::class.java) + log.info("Injected Component Nodes : {}", componentNodes) + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/PayloadUtils.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/PayloadUtils.kt new file mode 100644 index 000000000..9eb95e679 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/PayloadUtils.kt @@ -0,0 +1,47 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.core.utils + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService + + +class PayloadUtils { + + companion object { + + fun prepareInputsFromWorkflowPayload(bluePrintRuntimeService: BluePrintRuntimeService<*>, payload: JsonNode, workflowName: String) { + val input = payload.get("$workflowName-request") + bluePrintRuntimeService.assignWorkflowInputs(workflowName, input) + } + + fun prepareDynamicInputsFromWorkflowPayload(bluePrintRuntimeService: BluePrintRuntimeService<*>, payload: JsonNode, workflowName: String) { + val input = payload.get("$workflowName-request") + val propertyFields = input.get("$workflowName-properties") + prepareDynamicInputsFromComponentPayload(bluePrintRuntimeService, propertyFields) + } + + fun prepareDynamicInputsFromComponentPayload(bluePrintRuntimeService: BluePrintRuntimeService<*>, payload: JsonNode) { + payload.fields().forEach { property -> + val path = StringBuilder(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(property.key).toString() + bluePrintRuntimeService.put(path, property.value) + } + } + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/BluePrintPropertiesTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/BluePrintPropertiesTest.kt deleted file mode 100644 index 66de11fde..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/BluePrintPropertiesTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.core - -// TODO -open class BluePrintPropertiesTest \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintPropertiesTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintPropertiesTest.kt new file mode 100644 index 000000000..3dd629c13 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintPropertiesTest.kt @@ -0,0 +1,20 @@ +/* + * Copyright © 2019 Bell Canada + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.core + +// TODO +open class BluePrintPropertiesTest \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/pom.xml b/ms/blueprintsprocessor/modules/commons/rest-lib/pom.xml index 1ed157dcc..054f2386e 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/pom.xml +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/pom.xml @@ -18,7 +18,7 @@ 4.0.0 - org.onap.ccsdk.apps.blueprintsprocessor + org.onap.ccsdk.cds.blueprintsprocessor commons 0.4.2-SNAPSHOT @@ -29,11 +29,11 @@ Blueprints Processor Rest Lib - org.onap.ccsdk.apps.controllerblueprints + org.onap.ccsdk.cds.controllerblueprints blueprint-core - org.onap.ccsdk.apps.blueprintsprocessor + org.onap.ccsdk.cds.blueprintsprocessor processor-core diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt deleted file mode 100644 index 7af91c6fe..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.rest - -import org.springframework.boot.context.properties.EnableConfigurationProperties -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration - -@Configuration -@ComponentScan -@EnableConfigurationProperties -open class BluePrintRestLibConfiguration - - -class RestLibConstants { - companion object { - const val SERVICE_BLUEPRINT_REST_LIB_PROPERTY = "blueprint-rest-lib-property-service" - const val TYPE_TOKEN_AUTH = "token-auth" - const val TYPE_BASIC_AUTH = "basic-auth" - const val TYPE_SSL_BASIC_AUTH = "ssl-basic-auth" - const val TYPE_DME2_PROXY = "dme2-proxy" - const val TYPE_POLICY_MANAGER = "policy-manager" - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/BluePrintRestLibData.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/BluePrintRestLibData.kt deleted file mode 100644 index dd4d9f7d7..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/BluePrintRestLibData.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.rest - -open class RestClientProperties { - lateinit var type: String - lateinit var url: String -} - -open class BasicAuthRestClientProperties : RestClientProperties() { - lateinit var password: String - lateinit var username: String -} - -open class TokenAuthRestClientProperties : RestClientProperties() { - var token: String? = null -} - -open class SSLBasicAuthRestClientProperties : RestClientProperties() { - lateinit var keyStoreInstance: String // JKS, PKCS12 - lateinit var sslTrust: String - lateinit var sslTrustPassword: String - lateinit var sslKey: String - lateinit var sslKeyPassword: String -} - -open class DME2RestClientProperties : RestClientProperties() { - lateinit var service: String - lateinit var subContext: String - lateinit var version: String - lateinit var envContext: String - lateinit var routeOffer: String - var partner: String? = null - lateinit var appId: String -} - -open class PolicyManagerRestClientProperties : RestClientProperties() { - lateinit var env: String - lateinit var clientAuth: String - lateinit var authorisation: String -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt deleted file mode 100644 index 98a4fd58f..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright © 2017-2019 AT&T, Bell Canada, Nordix Foundation - * - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.rest.service - -import org.apache.http.message.BasicHeader -import org.onap.ccsdk.apps.blueprintsprocessor.rest.BasicAuthRestClientProperties -import org.springframework.http.HttpHeaders -import org.springframework.http.MediaType -import java.nio.charset.Charset -import java.util.* - -class BasicAuthRestClientService(private val restClientProperties: BasicAuthRestClientProperties) : - BlueprintWebClientService { - - override fun defaultHeaders(): Map { - val encodedCredentials = setBasicAuth(restClientProperties.username, restClientProperties.password) - return mapOf( - HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, - HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE, - HttpHeaders.AUTHORIZATION to "Basic $encodedCredentials") - } - - override fun host(uri: String): String { - return restClientProperties.url + uri - } - - override fun convertToBasicHeaders(headers: Map): Array { - val customHeaders: MutableMap = headers.toMutableMap() - if (!headers.containsKey(HttpHeaders.AUTHORIZATION)) { - val encodedCredentials = setBasicAuth(restClientProperties.username, restClientProperties.password) - customHeaders[HttpHeaders.AUTHORIZATION] = "Basic $encodedCredentials" - } - return super.convertToBasicHeaders(customHeaders) - } - - private fun setBasicAuth(username: String, password: String): String { - val credentialsString = "$username:$password" - return Base64.getEncoder().encodeToString(credentialsString.toByteArray(Charset.defaultCharset())) - } - - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt deleted file mode 100644 index 3888bb724..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright © 2017-2019 AT&T, Bell Canada - * Modifications Copyright © 2019 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.rest.service - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties -import org.onap.ccsdk.apps.blueprintsprocessor.rest.BasicAuthRestClientProperties -import org.onap.ccsdk.apps.blueprintsprocessor.rest.DME2RestClientProperties -import org.onap.ccsdk.apps.blueprintsprocessor.rest.PolicyManagerRestClientProperties -import org.onap.ccsdk.apps.blueprintsprocessor.rest.RestClientProperties -import org.onap.ccsdk.apps.blueprintsprocessor.rest.RestLibConstants -import org.onap.ccsdk.apps.blueprintsprocessor.rest.SSLBasicAuthRestClientProperties -import org.onap.ccsdk.apps.blueprintsprocessor.rest.TokenAuthRestClientProperties -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.springframework.stereotype.Service - -@Service(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY) -open class BluePrintRestLibPropertyService(private var bluePrintProperties: BluePrintProperties) { - - fun blueprintWebClientService(jsonNode: JsonNode): BlueprintWebClientService { - val restClientProperties = restClientProperties(jsonNode) - return blueprintWebClientService(restClientProperties) - } - - fun blueprintWebClientService(selector: String): BlueprintWebClientService { - val prefix = "blueprintsprocessor.restclient.$selector" - val restClientProperties = restClientProperties(prefix) - return blueprintWebClientService(restClientProperties) - } - - fun restClientProperties(prefix: String): RestClientProperties { - val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java) - return when (type) { - RestLibConstants.TYPE_BASIC_AUTH -> { - basicAuthRestClientProperties(prefix) - } - RestLibConstants.TYPE_SSL_BASIC_AUTH -> { - sslBasicAuthRestClientProperties(prefix) - } - RestLibConstants.TYPE_DME2_PROXY -> { - dme2ProxyClientProperties(prefix) - } - RestLibConstants.TYPE_POLICY_MANAGER -> { - policyManagerRestClientProperties(prefix) - } - else -> { - throw BluePrintProcessorException("Rest adaptor($type) is not supported") - } - } - } - - private fun restClientProperties(jsonNode: JsonNode): RestClientProperties { - val type = jsonNode.get("type").textValue() - return when (type) { - RestLibConstants.TYPE_TOKEN_AUTH -> { - JacksonUtils.readValue(jsonNode, TokenAuthRestClientProperties::class.java)!! - } - RestLibConstants.TYPE_BASIC_AUTH -> { - JacksonUtils.readValue(jsonNode, BasicAuthRestClientProperties::class.java)!! - } - RestLibConstants.TYPE_SSL_BASIC_AUTH -> { - JacksonUtils.readValue(jsonNode, SSLBasicAuthRestClientProperties::class.java)!! - } - RestLibConstants.TYPE_DME2_PROXY -> { - JacksonUtils.readValue(jsonNode, DME2RestClientProperties::class.java)!! - } - RestLibConstants.TYPE_POLICY_MANAGER -> { - JacksonUtils.readValue(jsonNode, PolicyManagerRestClientProperties::class.java)!! - } - else -> { - throw BluePrintProcessorException("Rest adaptor($type) is not supported") - } - } - } - - private fun blueprintWebClientService(restClientProperties: RestClientProperties): BlueprintWebClientService { - when (restClientProperties) { - is TokenAuthRestClientProperties -> { - return TokenAuthRestClientService(restClientProperties) - } - is BasicAuthRestClientProperties -> { - return BasicAuthRestClientService(restClientProperties) - } - is SSLBasicAuthRestClientProperties -> { - return SSLBasicAuthRestClientService(restClientProperties) - } - is DME2RestClientProperties -> { - return DME2ProxyRestClientService(restClientProperties) - } - else -> { - throw BluePrintProcessorException("couldn't get rest service for") - } - } - } - - private fun basicAuthRestClientProperties(prefix: String): BasicAuthRestClientProperties { - return bluePrintProperties.propertyBeanType(prefix, BasicAuthRestClientProperties::class.java) - } - - private fun sslBasicAuthRestClientProperties(prefix: String): SSLBasicAuthRestClientProperties { - return bluePrintProperties.propertyBeanType(prefix, SSLBasicAuthRestClientProperties::class.java) - } - - private fun dme2ProxyClientProperties(prefix: String): DME2RestClientProperties { - return bluePrintProperties.propertyBeanType(prefix, DME2RestClientProperties::class.java) - } - - private fun policyManagerRestClientProperties(prefix: String): PolicyManagerRestClientProperties { - return bluePrintProperties.propertyBeanType(prefix, PolicyManagerRestClientProperties::class.java) - } -} - - diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BlueprintWebClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BlueprintWebClientService.kt deleted file mode 100644 index 0629909ec..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BlueprintWebClientService.kt +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright © 2017-2019 AT&T, Bell Canada, Nordix Foundation - * - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.rest.service - -import org.apache.commons.io.IOUtils -import org.apache.http.client.methods.* -import org.apache.http.entity.StringEntity -import org.apache.http.impl.client.CloseableHttpClient -import org.apache.http.impl.client.HttpClients -import org.apache.http.message.BasicHeader -import org.onap.ccsdk.apps.blueprintsprocessor.rest.utils.WebClientUtils -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.springframework.http.HttpMethod -import java.nio.charset.Charset - -interface BlueprintWebClientService { - - fun defaultHeaders(): Map - - fun host(uri: String): String - - fun httpClient(): CloseableHttpClient { - return HttpClients.custom() - .addInterceptorFirst(WebClientUtils.logRequest()) - .addInterceptorLast(WebClientUtils.logResponse()) - .build() - } - - fun exchangeResource(methodType: String, path: String, request: String): String { - return this.exchangeResource(methodType, path, request, defaultHeaders()) - } - - fun exchangeResource(methodType: String, path: String, request: String, headers: Map): String { - val convertedHeaders: Array = convertToBasicHeaders(headers) - return when (HttpMethod.resolve(methodType)) { - HttpMethod.DELETE -> delete(path, convertedHeaders) - HttpMethod.GET -> get(path, convertedHeaders) - HttpMethod.POST -> post(path, request, convertedHeaders) - HttpMethod.PUT -> put(path, request, convertedHeaders) - HttpMethod.PATCH -> patch(path, request, convertedHeaders) - else -> throw BluePrintProcessorException("Unsupported methodType($methodType)") - } - } - - fun convertToBasicHeaders(headers: Map): Array { - val convertedHeaders = Array(headers.size){ BasicHeader("","") } - var currentElement = 0 - for ((name, value) in headers) { - convertedHeaders[currentElement++] = BasicHeader(name, value) - } - return convertedHeaders - } - - fun delete(path: String, headers: Array): String { - val httpDelete = HttpDelete(host(path)) - httpDelete.setHeaders(headers) - httpClient().execute(httpDelete).entity.content.use { - return IOUtils.toString(it, Charset.defaultCharset()) - } - } - - fun get(path: String, headers: Array): String { - val httpGet = HttpGet(host(path)) - httpGet.setHeaders(headers) - httpClient().execute(httpGet).entity.content.use { - return IOUtils.toString(it, Charset.defaultCharset()) - } - } - - fun post(path: String, request: String, headers: Array): String { - val httpPost = HttpPost(host(path)) - val entity = StringEntity(request) - httpPost.entity = entity - httpPost.setHeaders(headers) - httpClient().execute(httpPost).entity.content.use { - return IOUtils.toString(it, Charset.defaultCharset()) - } - } - - fun put(path: String, request: String, headers: Array): String { - val httpPut = HttpPut(host(path)) - val entity = StringEntity(request) - httpPut.entity = entity - httpPut.setHeaders(headers) - httpClient().execute(httpPut).entity.content.use { - return IOUtils.toString(it, Charset.defaultCharset()) - } - } - - fun patch(path: String, request: String, headers: Array): String { - val httpPatch = HttpPatch(host(path)) - val entity = StringEntity(request) - httpPatch.entity = entity - httpPatch.setHeaders(headers) - httpClient().execute(httpPatch).entity.content.use { - return IOUtils.toString(it, Charset.defaultCharset()) - } - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/DME2ProxyRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/DME2ProxyRestClientService.kt deleted file mode 100644 index 94e146d8b..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/DME2ProxyRestClientService.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright © 2017-2019 AT&T, Bell Canada - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.rest.service - -import org.onap.ccsdk.apps.blueprintsprocessor.rest.RestClientProperties - -class DME2ProxyRestClientService(restClientProperties: RestClientProperties) : BlueprintWebClientService { - override fun defaultHeaders(): Map { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun host(uri: String): String { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/SSLBasicAuthRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/SSLBasicAuthRestClientService.kt deleted file mode 100644 index 2bfacf417..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/SSLBasicAuthRestClientService.kt +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright © 2017-2019 AT&T, Bell Canada - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.rest.service - -import org.apache.http.conn.ssl.SSLConnectionSocketFactory -import org.apache.http.impl.client.CloseableHttpClient -import org.apache.http.impl.client.HttpClients -import org.apache.http.ssl.SSLContextBuilder -import org.onap.ccsdk.apps.blueprintsprocessor.rest.SSLBasicAuthRestClientProperties -import org.onap.ccsdk.apps.blueprintsprocessor.rest.utils.WebClientUtils -import org.springframework.http.HttpHeaders -import org.springframework.http.MediaType -import java.io.File -import java.io.FileInputStream -import java.security.KeyStore -import java.security.cert.X509Certificate - -class SSLBasicAuthRestClientService(private val restClientProperties: SSLBasicAuthRestClientProperties) : - BlueprintWebClientService { - - override fun defaultHeaders(): Map { - return mapOf( - HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, - HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE) - } - - override fun host(uri: String): String { - return restClientProperties.url + uri - } - - override fun httpClient(): CloseableHttpClient { - - val keystoreInstance = restClientProperties.keyStoreInstance - val sslKey = restClientProperties.sslKey - val sslKeyPwd = restClientProperties.sslKeyPassword - val sslTrust = restClientProperties.sslTrust - val sslTrustPwd = restClientProperties.sslTrustPassword - - val acceptingTrustStrategy = { chain: Array, authType: String -> true } - - FileInputStream(sslKey).use { keyInput -> - val keyStore = KeyStore.getInstance(keystoreInstance) - keyStore.load(keyInput, sslKeyPwd.toCharArray()) - - val sslContext = - SSLContextBuilder.create() - .loadKeyMaterial(keyStore, sslKeyPwd.toCharArray()) - .loadTrustMaterial(File(sslTrust), sslTrustPwd.toCharArray(), acceptingTrustStrategy).build() - - val csf = SSLConnectionSocketFactory(sslContext!!) - - return HttpClients.custom() - .addInterceptorFirst(WebClientUtils.logRequest()) - .addInterceptorLast(WebClientUtils.logResponse()) - .setSSLSocketFactory(csf).build() - } - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt deleted file mode 100644 index d5dec3ae5..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright © 2019 Bell Canada, Nordix Foundation - * - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.rest.service - -import org.apache.http.message.BasicHeader -import org.onap.ccsdk.apps.blueprintsprocessor.rest.TokenAuthRestClientProperties -import org.springframework.http.HttpHeaders -import org.springframework.http.MediaType - -class TokenAuthRestClientService(private val restClientProperties: TokenAuthRestClientProperties) : - BlueprintWebClientService { - - override fun defaultHeaders(): Map { - return mapOf( - HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, - HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE, - HttpHeaders.AUTHORIZATION to restClientProperties.token!!) - } - - override fun convertToBasicHeaders(headers: Map): Array { - val customHeaders: MutableMap = headers.toMutableMap() - if (!headers.containsKey(HttpHeaders.AUTHORIZATION)) { - customHeaders[HttpHeaders.AUTHORIZATION] = restClientProperties.token!! - } - return super.convertToBasicHeaders(customHeaders) - } - - override fun host(uri: String): String { - return restClientProperties.url + uri - } -} diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/utils/WebClientUtils.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/utils/WebClientUtils.kt deleted file mode 100644 index b9a014e35..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/utils/WebClientUtils.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.rest.utils - -import org.apache.http.HttpRequestInterceptor -import org.apache.http.HttpResponseInterceptor -import org.slf4j.Logger -import org.slf4j.LoggerFactory - -class WebClientUtils { - companion object { - - val log: Logger = LoggerFactory.getLogger(WebClientUtils::class.java) - - fun logRequest(): HttpRequestInterceptor = - HttpRequestInterceptor { request, _ -> log.info("Rest request method(${request?.requestLine?.method}), url(${request?.requestLine?.uri})") } - - fun logResponse(): HttpResponseInterceptor = - HttpResponseInterceptor { response, _ -> log.info("Response status(${response.statusLine.statusCode} - ${response.statusLine.reasonPhrase})") } - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt new file mode 100644 index 000000000..05143f3d8 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt @@ -0,0 +1,39 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.rest + +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +@Configuration +@ComponentScan +@EnableConfigurationProperties +open class BluePrintRestLibConfiguration + + +class RestLibConstants { + companion object { + const val SERVICE_BLUEPRINT_REST_LIB_PROPERTY = "blueprint-rest-lib-property-service" + const val TYPE_TOKEN_AUTH = "token-auth" + const val TYPE_BASIC_AUTH = "basic-auth" + const val TYPE_SSL_BASIC_AUTH = "ssl-basic-auth" + const val TYPE_DME2_PROXY = "dme2-proxy" + const val TYPE_POLICY_MANAGER = "policy-manager" + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt new file mode 100644 index 000000000..4e6e62efb --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt @@ -0,0 +1,55 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.rest + +open class RestClientProperties { + lateinit var type: String + lateinit var url: String +} + +open class BasicAuthRestClientProperties : RestClientProperties() { + lateinit var password: String + lateinit var username: String +} + +open class TokenAuthRestClientProperties : RestClientProperties() { + var token: String? = null +} + +open class SSLBasicAuthRestClientProperties : RestClientProperties() { + lateinit var keyStoreInstance: String // JKS, PKCS12 + lateinit var sslTrust: String + lateinit var sslTrustPassword: String + lateinit var sslKey: String + lateinit var sslKeyPassword: String +} + +open class DME2RestClientProperties : RestClientProperties() { + lateinit var service: String + lateinit var subContext: String + lateinit var version: String + lateinit var envContext: String + lateinit var routeOffer: String + var partner: String? = null + lateinit var appId: String +} + +open class PolicyManagerRestClientProperties : RestClientProperties() { + lateinit var env: String + lateinit var clientAuth: String + lateinit var authorisation: String +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt new file mode 100644 index 000000000..7737fd1a5 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt @@ -0,0 +1,58 @@ +/* + * Copyright © 2017-2019 AT&T, Bell Canada, Nordix Foundation + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.rest.service + +import org.apache.http.message.BasicHeader +import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties +import org.springframework.http.HttpHeaders +import org.springframework.http.MediaType +import java.nio.charset.Charset +import java.util.* + +class BasicAuthRestClientService(private val restClientProperties: BasicAuthRestClientProperties) : + BlueprintWebClientService { + + override fun defaultHeaders(): Map { + val encodedCredentials = setBasicAuth(restClientProperties.username, restClientProperties.password) + return mapOf( + HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, + HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE, + HttpHeaders.AUTHORIZATION to "Basic $encodedCredentials") + } + + override fun host(uri: String): String { + return restClientProperties.url + uri + } + + override fun convertToBasicHeaders(headers: Map): Array { + val customHeaders: MutableMap = headers.toMutableMap() + if (!headers.containsKey(HttpHeaders.AUTHORIZATION)) { + val encodedCredentials = setBasicAuth(restClientProperties.username, restClientProperties.password) + customHeaders[HttpHeaders.AUTHORIZATION] = "Basic $encodedCredentials" + } + return super.convertToBasicHeaders(customHeaders) + } + + private fun setBasicAuth(username: String, password: String): String { + val credentialsString = "$username:$password" + return Base64.getEncoder().encodeToString(credentialsString.toByteArray(Charset.defaultCharset())) + } + + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt new file mode 100644 index 000000000..dc974468b --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt @@ -0,0 +1,129 @@ +/* + * Copyright © 2017-2019 AT&T, Bell Canada + * Modifications Copyright © 2019 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.rest.service + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.DME2RestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.PolicyManagerRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestLibConstants +import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLBasicAuthRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.TokenAuthRestClientProperties +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.stereotype.Service + +@Service(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY) +open class BluePrintRestLibPropertyService(private var bluePrintProperties: BluePrintProperties) { + + fun blueprintWebClientService(jsonNode: JsonNode): BlueprintWebClientService { + val restClientProperties = restClientProperties(jsonNode) + return blueprintWebClientService(restClientProperties) + } + + fun blueprintWebClientService(selector: String): BlueprintWebClientService { + val prefix = "blueprintsprocessor.restclient.$selector" + val restClientProperties = restClientProperties(prefix) + return blueprintWebClientService(restClientProperties) + } + + fun restClientProperties(prefix: String): RestClientProperties { + val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java) + return when (type) { + RestLibConstants.TYPE_BASIC_AUTH -> { + basicAuthRestClientProperties(prefix) + } + RestLibConstants.TYPE_SSL_BASIC_AUTH -> { + sslBasicAuthRestClientProperties(prefix) + } + RestLibConstants.TYPE_DME2_PROXY -> { + dme2ProxyClientProperties(prefix) + } + RestLibConstants.TYPE_POLICY_MANAGER -> { + policyManagerRestClientProperties(prefix) + } + else -> { + throw BluePrintProcessorException("Rest adaptor($type) is not supported") + } + } + } + + private fun restClientProperties(jsonNode: JsonNode): RestClientProperties { + val type = jsonNode.get("type").textValue() + return when (type) { + RestLibConstants.TYPE_TOKEN_AUTH -> { + JacksonUtils.readValue(jsonNode, TokenAuthRestClientProperties::class.java)!! + } + RestLibConstants.TYPE_BASIC_AUTH -> { + JacksonUtils.readValue(jsonNode, BasicAuthRestClientProperties::class.java)!! + } + RestLibConstants.TYPE_SSL_BASIC_AUTH -> { + JacksonUtils.readValue(jsonNode, SSLBasicAuthRestClientProperties::class.java)!! + } + RestLibConstants.TYPE_DME2_PROXY -> { + JacksonUtils.readValue(jsonNode, DME2RestClientProperties::class.java)!! + } + RestLibConstants.TYPE_POLICY_MANAGER -> { + JacksonUtils.readValue(jsonNode, PolicyManagerRestClientProperties::class.java)!! + } + else -> { + throw BluePrintProcessorException("Rest adaptor($type) is not supported") + } + } + } + + private fun blueprintWebClientService(restClientProperties: RestClientProperties): BlueprintWebClientService { + when (restClientProperties) { + is TokenAuthRestClientProperties -> { + return TokenAuthRestClientService(restClientProperties) + } + is BasicAuthRestClientProperties -> { + return BasicAuthRestClientService(restClientProperties) + } + is SSLBasicAuthRestClientProperties -> { + return SSLBasicAuthRestClientService(restClientProperties) + } + is DME2RestClientProperties -> { + return DME2ProxyRestClientService(restClientProperties) + } + else -> { + throw BluePrintProcessorException("couldn't get rest service for") + } + } + } + + private fun basicAuthRestClientProperties(prefix: String): BasicAuthRestClientProperties { + return bluePrintProperties.propertyBeanType(prefix, BasicAuthRestClientProperties::class.java) + } + + private fun sslBasicAuthRestClientProperties(prefix: String): SSLBasicAuthRestClientProperties { + return bluePrintProperties.propertyBeanType(prefix, SSLBasicAuthRestClientProperties::class.java) + } + + private fun dme2ProxyClientProperties(prefix: String): DME2RestClientProperties { + return bluePrintProperties.propertyBeanType(prefix, DME2RestClientProperties::class.java) + } + + private fun policyManagerRestClientProperties(prefix: String): PolicyManagerRestClientProperties { + return bluePrintProperties.propertyBeanType(prefix, PolicyManagerRestClientProperties::class.java) + } +} + + diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt new file mode 100644 index 000000000..b34d66d19 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt @@ -0,0 +1,115 @@ +/* + * Copyright © 2017-2019 AT&T, Bell Canada, Nordix Foundation + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.rest.service + +import org.apache.commons.io.IOUtils +import org.apache.http.client.methods.* +import org.apache.http.entity.StringEntity +import org.apache.http.impl.client.CloseableHttpClient +import org.apache.http.impl.client.HttpClients +import org.apache.http.message.BasicHeader +import org.onap.ccsdk.cds.blueprintsprocessor.rest.utils.WebClientUtils +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.springframework.http.HttpMethod +import java.nio.charset.Charset + +interface BlueprintWebClientService { + + fun defaultHeaders(): Map + + fun host(uri: String): String + + fun httpClient(): CloseableHttpClient { + return HttpClients.custom() + .addInterceptorFirst(WebClientUtils.logRequest()) + .addInterceptorLast(WebClientUtils.logResponse()) + .build() + } + + fun exchangeResource(methodType: String, path: String, request: String): String { + return this.exchangeResource(methodType, path, request, defaultHeaders()) + } + + fun exchangeResource(methodType: String, path: String, request: String, headers: Map): String { + val convertedHeaders: Array = convertToBasicHeaders(headers) + return when (HttpMethod.resolve(methodType)) { + HttpMethod.DELETE -> delete(path, convertedHeaders) + HttpMethod.GET -> get(path, convertedHeaders) + HttpMethod.POST -> post(path, request, convertedHeaders) + HttpMethod.PUT -> put(path, request, convertedHeaders) + HttpMethod.PATCH -> patch(path, request, convertedHeaders) + else -> throw BluePrintProcessorException("Unsupported methodType($methodType)") + } + } + + fun convertToBasicHeaders(headers: Map): Array { + val convertedHeaders = Array(headers.size){ BasicHeader("","") } + var currentElement = 0 + for ((name, value) in headers) { + convertedHeaders[currentElement++] = BasicHeader(name, value) + } + return convertedHeaders + } + + fun delete(path: String, headers: Array): String { + val httpDelete = HttpDelete(host(path)) + httpDelete.setHeaders(headers) + httpClient().execute(httpDelete).entity.content.use { + return IOUtils.toString(it, Charset.defaultCharset()) + } + } + + fun get(path: String, headers: Array): String { + val httpGet = HttpGet(host(path)) + httpGet.setHeaders(headers) + httpClient().execute(httpGet).entity.content.use { + return IOUtils.toString(it, Charset.defaultCharset()) + } + } + + fun post(path: String, request: String, headers: Array): String { + val httpPost = HttpPost(host(path)) + val entity = StringEntity(request) + httpPost.entity = entity + httpPost.setHeaders(headers) + httpClient().execute(httpPost).entity.content.use { + return IOUtils.toString(it, Charset.defaultCharset()) + } + } + + fun put(path: String, request: String, headers: Array): String { + val httpPut = HttpPut(host(path)) + val entity = StringEntity(request) + httpPut.entity = entity + httpPut.setHeaders(headers) + httpClient().execute(httpPut).entity.content.use { + return IOUtils.toString(it, Charset.defaultCharset()) + } + } + + fun patch(path: String, request: String, headers: Array): String { + val httpPatch = HttpPatch(host(path)) + val entity = StringEntity(request) + httpPatch.entity = entity + httpPatch.setHeaders(headers) + httpClient().execute(httpPatch).entity.content.use { + return IOUtils.toString(it, Charset.defaultCharset()) + } + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/DME2ProxyRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/DME2ProxyRestClientService.kt new file mode 100644 index 000000000..8e0a2d3f0 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/DME2ProxyRestClientService.kt @@ -0,0 +1,29 @@ +/* + * Copyright © 2017-2019 AT&T, Bell Canada + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.rest.service + +import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestClientProperties + +class DME2ProxyRestClientService(restClientProperties: RestClientProperties) : BlueprintWebClientService { + override fun defaultHeaders(): Map { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun host(uri: String): String { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLBasicAuthRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLBasicAuthRestClientService.kt new file mode 100644 index 000000000..3d3b0a57e --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLBasicAuthRestClientService.kt @@ -0,0 +1,72 @@ +/* + * Copyright © 2017-2019 AT&T, Bell Canada + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.rest.service + +import org.apache.http.conn.ssl.SSLConnectionSocketFactory +import org.apache.http.impl.client.CloseableHttpClient +import org.apache.http.impl.client.HttpClients +import org.apache.http.ssl.SSLContextBuilder +import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLBasicAuthRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.utils.WebClientUtils +import org.springframework.http.HttpHeaders +import org.springframework.http.MediaType +import java.io.File +import java.io.FileInputStream +import java.security.KeyStore +import java.security.cert.X509Certificate + +class SSLBasicAuthRestClientService(private val restClientProperties: SSLBasicAuthRestClientProperties) : + BlueprintWebClientService { + + override fun defaultHeaders(): Map { + return mapOf( + HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, + HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE) + } + + override fun host(uri: String): String { + return restClientProperties.url + uri + } + + override fun httpClient(): CloseableHttpClient { + + val keystoreInstance = restClientProperties.keyStoreInstance + val sslKey = restClientProperties.sslKey + val sslKeyPwd = restClientProperties.sslKeyPassword + val sslTrust = restClientProperties.sslTrust + val sslTrustPwd = restClientProperties.sslTrustPassword + + val acceptingTrustStrategy = { chain: Array, authType: String -> true } + + FileInputStream(sslKey).use { keyInput -> + val keyStore = KeyStore.getInstance(keystoreInstance) + keyStore.load(keyInput, sslKeyPwd.toCharArray()) + + val sslContext = + SSLContextBuilder.create() + .loadKeyMaterial(keyStore, sslKeyPwd.toCharArray()) + .loadTrustMaterial(File(sslTrust), sslTrustPwd.toCharArray(), acceptingTrustStrategy).build() + + val csf = SSLConnectionSocketFactory(sslContext!!) + + return HttpClients.custom() + .addInterceptorFirst(WebClientUtils.logRequest()) + .addInterceptorLast(WebClientUtils.logResponse()) + .setSSLSocketFactory(csf).build() + } + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt new file mode 100644 index 000000000..609267eb9 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt @@ -0,0 +1,47 @@ +/* + * Copyright © 2019 Bell Canada, Nordix Foundation + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.rest.service + +import org.apache.http.message.BasicHeader +import org.onap.ccsdk.cds.blueprintsprocessor.rest.TokenAuthRestClientProperties +import org.springframework.http.HttpHeaders +import org.springframework.http.MediaType + +class TokenAuthRestClientService(private val restClientProperties: TokenAuthRestClientProperties) : + BlueprintWebClientService { + + override fun defaultHeaders(): Map { + return mapOf( + HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, + HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE, + HttpHeaders.AUTHORIZATION to restClientProperties.token!!) + } + + override fun convertToBasicHeaders(headers: Map): Array { + val customHeaders: MutableMap = headers.toMutableMap() + if (!headers.containsKey(HttpHeaders.AUTHORIZATION)) { + customHeaders[HttpHeaders.AUTHORIZATION] = restClientProperties.token!! + } + return super.convertToBasicHeaders(customHeaders) + } + + override fun host(uri: String): String { + return restClientProperties.url + uri + } +} diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/utils/WebClientUtils.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/utils/WebClientUtils.kt new file mode 100644 index 000000000..42006569f --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/utils/WebClientUtils.kt @@ -0,0 +1,35 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.rest.utils + +import org.apache.http.HttpRequestInterceptor +import org.apache.http.HttpResponseInterceptor +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +class WebClientUtils { + companion object { + + val log: Logger = LoggerFactory.getLogger(WebClientUtils::class.java) + + fun logRequest(): HttpRequestInterceptor = + HttpRequestInterceptor { request, _ -> log.info("Rest request method(${request?.requestLine?.method}), url(${request?.requestLine?.uri})") } + + fun logResponse(): HttpResponseInterceptor = + HttpResponseInterceptor { response, _ -> log.info("Response status(${response.statusLine.statusCode} - ${response.statusLine.reasonPhrase})") } + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt deleted file mode 100644 index d6e5549a6..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.rest.service - -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties -import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.rest.BluePrintRestLibConfiguration -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import kotlin.test.assertNotNull - - -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [BluePrintRestLibConfiguration::class, BlueprintPropertyConfiguration::class, BluePrintProperties::class]) -@TestPropertySource(properties = -["blueprintsprocessor.restclient.sample.type=basic-auth", - "blueprintsprocessor.restclient.sample.url=http://localhost:8080", - "blueprintsprocessor.restclient.sample.userId=sampleuser"]) - -class BluePrintRestLibPropertyServiceTest { - - @Autowired - lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService - - @Test - fun testRestClientProperties() { - val properties = bluePrintRestLibPropertyService.restClientProperties("blueprintsprocessor.restclient.sample") - assertNotNull(properties, "failed to create property bean") - assertNotNull(properties.url, "failed to get url property in property bean") - } - - @Test - fun testBlueprintWebClientService() { - val blueprintWebClientService = bluePrintRestLibPropertyService.blueprintWebClientService("sample") - assertNotNull(blueprintWebClientService, "failed to create blueprintWebClientService") - } - -} - diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestClientServiceTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestClientServiceTest.kt deleted file mode 100644 index 0390550cc..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestClientServiceTest.kt +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Copyright (C) 2019 Nordix Foundation - * - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.rest.service - -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties -import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.rest.BluePrintRestLibConfiguration -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.http.HttpMethod -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PatchMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertNotNull - -@RunWith(SpringRunner::class) -@EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class]) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -@ContextConfiguration(classes = [BluePrintRestLibConfiguration::class, BlueprintPropertyConfiguration::class, - SampleController::class, BluePrintProperties::class, BluePrintProperties::class]) -@TestPropertySource(properties = -["blueprintsprocessor.restclient.sample.type=basic-auth", - "blueprintsprocessor.restclient.sample.url=http://127.0.0.1:8080", - "blueprintsprocessor.restclient.sample.username=sampleuser", - "blueprintsprocessor.restclient.sample.password=sampletoken"]) -class RestClientServiceTest { - - @Autowired - lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService - - @Test - fun testBaseAuth() { - val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("sample") - val headers = mutableMapOf() - headers["X-Transaction-Id"] = "1234" - val response = restClientService.exchangeResource(HttpMethod.GET.name, "/sample/name", "") - assertNotNull(response, "failed to get response") - } - - @Test - fun testPatch() { - val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("sample") - val response = restClientService.exchangeResource(HttpMethod.PATCH.name, "/sample/name", "") - assertEquals("Patch request successful", response, "failed to get patch response") - } - -} - -@RestController -@RequestMapping("/sample") -open class SampleController { - @GetMapping("/name") - fun getName(): String = "Sample Controller" - @PatchMapping("/name") - fun patchName(): String = "Patch request successful" -} - diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt new file mode 100644 index 000000000..c57745713 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt @@ -0,0 +1,58 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.rest.service + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.rest.BluePrintRestLibConfiguration +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertNotNull + + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [BluePrintRestLibConfiguration::class, BlueprintPropertyConfiguration::class, BluePrintProperties::class]) +@TestPropertySource(properties = +["blueprintsprocessor.restclient.sample.type=basic-auth", + "blueprintsprocessor.restclient.sample.url=http://localhost:8080", + "blueprintsprocessor.restclient.sample.userId=sampleuser"]) + +class BluePrintRestLibPropertyServiceTest { + + @Autowired + lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService + + @Test + fun testRestClientProperties() { + val properties = bluePrintRestLibPropertyService.restClientProperties("blueprintsprocessor.restclient.sample") + assertNotNull(properties, "failed to create property bean") + assertNotNull(properties.url, "failed to get url property in property bean") + } + + @Test + fun testBlueprintWebClientService() { + val blueprintWebClientService = bluePrintRestLibPropertyService.blueprintWebClientService("sample") + assertNotNull(blueprintWebClientService, "failed to create blueprintWebClientService") + } + +} + diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt new file mode 100644 index 000000000..6da59399e --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt @@ -0,0 +1,83 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Copyright (C) 2019 Nordix Foundation + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.rest.service + +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.rest.BluePrintRestLibConfiguration +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.http.HttpMethod +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PatchMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class]) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@ContextConfiguration(classes = [BluePrintRestLibConfiguration::class, BlueprintPropertyConfiguration::class, + SampleController::class, BluePrintProperties::class, BluePrintProperties::class]) +@TestPropertySource(properties = +["blueprintsprocessor.restclient.sample.type=basic-auth", + "blueprintsprocessor.restclient.sample.url=http://127.0.0.1:8080", + "blueprintsprocessor.restclient.sample.username=sampleuser", + "blueprintsprocessor.restclient.sample.password=sampletoken"]) +class RestClientServiceTest { + + @Autowired + lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService + + @Test + fun testBaseAuth() { + val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("sample") + val headers = mutableMapOf() + headers["X-Transaction-Id"] = "1234" + val response = restClientService.exchangeResource(HttpMethod.GET.name, "/sample/name", "") + assertNotNull(response, "failed to get response") + } + + @Test + fun testPatch() { + val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("sample") + val response = restClientService.exchangeResource(HttpMethod.PATCH.name, "/sample/name", "") + assertEquals("Patch request successful", response, "failed to get patch response") + } + +} + +@RestController +@RequestMapping("/sample") +open class SampleController { + @GetMapping("/name") + fun getName(): String = "Sample Controller" + @PatchMapping("/name") + fun patchName(): String = "Patch request successful" +} + diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/resources/logback-test.xml index f9ec9fe57..355cd3ace 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/resources/logback-test.xml +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/resources/logback-test.xml @@ -26,7 +26,7 @@ - + -- cgit 1.2.3-korg