From adcd4f2bc695840e9ecbc05003bc52c675f22fec Mon Sep 17 00:00:00 2001 From: KAPIL SINGAL Date: Fri, 22 Jan 2021 11:49:51 -0500 Subject: Renaming Files having BluePrint to have Blueprint Replacing BluePrint with Blueprint throughout Issue-ID: CCSDK-3098 Signed-off-by: KAPIL SINGAL Change-Id: Ibee8bad07ae7d9287073db2d4f2f2cd730fa8b96 --- .../db/BluePrintDBLibConfiguration.kt | 81 ---- .../blueprintsprocessor/db/BluePrintDBLibData.kt | 52 -- .../db/BluePrintDBLibGenericService.kt | 44 -- .../db/BlueprintDBLibConfiguration.kt | 81 ++++ .../blueprintsprocessor/db/BlueprintDBLibData.kt | 52 ++ .../db/BlueprintDBLibGenericService.kt | 44 ++ .../db/DatabasePropertiesDSL.kt | 30 +- .../db/primary/BluePrintDBLibPropertyService.kt | 79 --- .../db/primary/BlueprintDBLibPropertyService.kt | 79 +++ .../db/primary/MariaDatabaseConfiguration.kt | 4 +- .../db/primary/MySqlDatabaseConfiguration.kt | 4 +- .../primary/service/BlueprintCatalogServiceImpl.kt | 38 +- .../BlueprintProcessorCatalogServiceImpl.kt | 54 +-- .../db/BlueprintProcessorCatalogServiceImplTest.kt | 20 +- .../db/DatabasePropertiesDSLTest.kt | 10 +- .../db/TestDatabaseConfiguration.kt | 2 +- .../MockBlueprintProcessorCatalogServiceImpl.kt | 12 +- .../dmaap/AafAuthDmaapClientService.kt | 2 +- .../dmaap/BluePrintDmaapClientService.kt | 106 ---- .../dmaap/BluePrintDmaapLibConfiguration.kt | 48 -- .../dmaap/BluePrintDmaapLibPropertyService.kt | 202 -------- .../dmaap/BlueprintDmaapClientService.kt | 106 ++++ .../dmaap/BlueprintDmaapLibConfiguration.kt | 48 ++ .../dmaap/BlueprintDmaapLibPropertyService.kt | 202 ++++++++ .../dmaap/HttpNoAuthDmaapClientService.kt | 2 +- .../dmaap/TestDmaapEventPublisher.kt | 14 +- .../grpc/BluePrintGrpcExtensions.kt | 27 -- .../grpc/BluePrintGrpcLibConfiguration.kt | 55 --- .../grpc/BluePrintGrpcLibData.kt | 67 --- .../grpc/BlueprintGrpcExtensions.kt | 27 ++ .../grpc/BlueprintGrpcLibConfiguration.kt | 55 +++ .../grpc/BlueprintGrpcLibData.kt | 67 +++ .../blueprintsprocessor/grpc/GrpcPropertiesDSL.kt | 60 +-- .../interceptor/GrpcServerLoggingInterceptor.kt | 22 +- .../grpc/service/BasicAuthGrpcClientService.kt | 2 +- .../service/BluePrintGrpcLibPropertyService.kt | 182 ------- .../grpc/service/BluePrintGrpcService.kt | 31 -- .../service/BlueprintGrpcLibPropertyService.kt | 182 +++++++ .../grpc/service/BlueprintGrpcService.kt | 31 ++ .../grpc/service/GrpcLoggerService.kt | 14 +- .../grpc/service/TLSAuthGrpcClientService.kt | 2 +- .../grpc/service/TLSAuthGrpcServerService.kt | 2 +- .../grpc/service/TokenAuthGrpcClientService.kt | 2 +- .../grpc/GrpcPropertiesDSLTest.kt | 18 +- .../service/BluePrintGrpcLibPropertyServiceTest.kt | 218 --------- .../grpc/service/BluePrintGrpcServerTest.kt | 110 ----- .../service/BlueprintGrpcLibPropertyServiceTest.kt | 218 +++++++++ .../grpc/service/BlueprintGrpcServerTest.kt | 110 +++++ .../service/MockTLSBluePrintProcessingServer.kt | 92 ---- .../service/MockTLSBlueprintProcessingServer.kt | 92 ++++ .../message/BluePrintMessageExtensions.kt | 31 -- .../message/BluePrintMessageLibConfiguration.kt | 71 --- .../message/BluePrintMessageLibData.kt | 264 ---------- .../message/BlueprintMessageExtensions.kt | 31 ++ .../message/BlueprintMessageLibConfiguration.kt | 71 +++ .../message/BlueprintMessageLibData.kt | 264 ++++++++++ .../message/MessagePropertiesDSL.kt | 94 ++-- .../kafka/AbstractKafkaTopologyComponents.kt | 6 +- .../message/kafka/KafkaJDBCStores.kt | 8 +- .../service/BluePrintMessageLibPropertyService.kt | 221 --------- .../service/BlueprintMessageConsumerService.kt | 6 +- .../service/BlueprintMessageLibPropertyService.kt | 221 +++++++++ .../message/service/KafkaStreamsConsumerService.kt | 6 +- .../message/service/MessageLoggerService.kt | 14 +- .../message/MessagePropertiesDSLTest.kt | 18 +- .../service/BlueprintMessageConsumerServiceTest.kt | 12 +- .../service/BlueprintMessageProducerServiceTest.kt | 18 +- .../service/KafkaStreamsConsumerServiceTest.kt | 12 +- .../message/service/MessageLoggerServiceTest.kt | 4 +- .../message/service/MockKafkaTopologyComponents.kt | 4 +- .../nats/BluePrintNatsExtensions.kt | 36 -- .../nats/BluePrintNatsLibConfiguration.kt | 49 -- .../nats/BluePrintNatsLibData.kt | 45 -- .../nats/BlueprintNatsExtensions.kt | 36 ++ .../nats/BlueprintNatsLibConfiguration.kt | 49 ++ .../nats/BlueprintNatsLibData.kt | 45 ++ .../blueprintsprocessor/nats/NatsPropertiesDSL.kt | 30 +- .../service/BluePrintNatsLibPropertyService.kt | 95 ---- .../nats/service/BluePrintNatsService.kt | 143 ------ .../service/BlueprintNatsLibPropertyService.kt | 95 ++++ .../nats/service/BlueprintNatsService.kt | 143 ++++++ .../nats/service/TLSAuthNatsService.kt | 2 +- .../nats/service/TokenAuthNatsService.kt | 2 +- .../nats/utils/NatsClusterUtils.kt | 6 +- .../nats/NatsPropertiesDSLTest.kt | 10 +- .../nats/service/BluePrintNatsExtensionsTest.kt | 51 -- .../service/BluePrintNatsLibPropertyServiceTest.kt | 56 --- .../nats/service/BluePrintNatsServiceTest.kt | 267 ----------- .../nats/service/BlueprintNatsExtensionsTest.kt | 51 ++ .../service/BlueprintNatsLibPropertyServiceTest.kt | 56 +++ .../nats/service/BlueprintNatsServiceTest.kt | 267 +++++++++++ .../core/BluePrintCoreConfiguration.kt | 88 ---- .../core/BlueprintCoreConfiguration.kt | 88 ++++ .../core/api/data/BlueprintProcessorData.kt | 4 +- .../core/cluster/BluePrintClusterExtensions.kt | 75 --- .../core/cluster/BlueprintClusterExtensions.kt | 75 +++ .../core/cluster/HazelcastClusterService.kt | 24 +- .../core/factory/ComponentNodeFactory.kt | 10 +- .../BlueprintCompilerCacheMessageListener.kt | 12 +- .../core/service/BluePrintClusterService.kt | 106 ---- .../core/service/BlueprintClusterService.kt | 106 ++++ .../blueprintsprocessor/core/utils/PayloadUtils.kt | 18 +- .../core/BluePrintPropertiesTest.kt | 20 - .../core/BlueprintPropertiesTest.kt | 20 + .../core/cluster/BluePrintClusterExtensionsTest.kt | 74 --- .../core/cluster/BlueprintClusterExtensionsTest.kt | 74 +++ .../core/cluster/HazelcastClusterServiceTest.kt | 30 +- .../core/utils/BluePrintMappingsTest.kt | 137 ------ .../core/utils/BlueprintMappingsTest.kt | 137 ++++++ .../rest/BluePrintRestLibConfiguration.kt | 61 --- .../rest/BluePrintRestLibData.kt | 66 --- .../rest/BlueprintRestLibConfiguration.kt | 61 +++ .../rest/BlueprintRestLibData.kt | 66 +++ .../rest/RestClientPropertiesDSL.kt | 34 +- .../service/BluePrintRestLibPropertyService.kt | 222 --------- .../service/BlueprintRestLibPropertyService.kt | 222 +++++++++ .../rest/service/BlueprintWebClientService.kt | 18 +- .../rest/service/RestLoggerService.kt | 16 +- .../service/BluePrintRestLibPropertyServiceTest.kt | 532 --------------------- .../service/BlueprintRestLibPropertyServiceTest.kt | 532 +++++++++++++++++++++ .../rest/service/RestClientPropertiesDSLTest.kt | 10 +- .../rest/service/RestClientServiceTest.kt | 12 +- .../ssh/BluePrintSshLibConfiguration.kt | 51 -- .../blueprintsprocessor/ssh/BluePrintSshLibData.kt | 34 -- .../ssh/BlueprintSshLibConfiguration.kt | 51 ++ .../blueprintsprocessor/ssh/BlueprintSshLibData.kt | 34 ++ .../blueprintsprocessor/ssh/SshPropertiesDSL.kt | 26 +- .../ssh/service/BasicAuthSshClientService.kt | 10 +- .../ssh/service/BluePrintSshLibPropertyService.kt | 87 ---- .../ssh/service/BlueprintSshLibPropertyService.kt | 87 ++++ .../ssh/SshPropertiesDSLTest.kt | 10 +- .../service/BluePrintSshLibPropertyServiceTest.kt | 64 --- .../ssh/service/BlueprintSshClientServiceTest.kt | 14 +- .../service/BlueprintSshLibPropertyServiceTest.kt | 64 +++ 134 files changed, 4747 insertions(+), 4747 deletions(-) delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibData.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibGenericService.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 delete 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/BlueprintDBLibPropertyService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt delete 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/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 delete mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcExtensions.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibData.kt create mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BlueprintGrpcExtensions.kt create mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BlueprintGrpcLibConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BlueprintGrpcLibData.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcLibPropertyService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyServiceTest.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcServerTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcLibPropertyServiceTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcServerTest.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/MockTLSBluePrintProcessingServer.kt create mode 100644 ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/MockTLSBlueprintProcessingServer.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BluePrintMessageExtensions.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BluePrintMessageLibConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BluePrintMessageLibData.kt create mode 100644 ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BlueprintMessageExtensions.kt create mode 100644 ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BlueprintMessageLibConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BlueprintMessageLibData.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BluePrintMessageLibPropertyService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageLibPropertyService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BluePrintNatsExtensions.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BluePrintNatsLibConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BluePrintNatsLibData.kt create mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BlueprintNatsExtensions.kt create mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BlueprintNatsLibConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BlueprintNatsLibData.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsLibPropertyService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsLibPropertyService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsExtensionsTest.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsLibPropertyServiceTest.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsServiceTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsExtensionsTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsLibPropertyServiceTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsServiceTest.kt delete 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/BlueprintCoreConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensions.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensions.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BluePrintClusterService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BlueprintClusterService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/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/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensionsTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensionsTest.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappingsTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BlueprintMappingsTest.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt delete 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/BlueprintRestLibConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BlueprintRestLibData.kt delete 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/BlueprintRestLibPropertyService.kt delete 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/BlueprintRestLibPropertyServiceTest.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibData.kt create mode 100644 ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BlueprintSshLibConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BlueprintSshLibData.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshLibPropertyService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyServiceTest.kt create mode 100644 ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshLibPropertyServiceTest.kt (limited to 'ms/blueprintsprocessor/modules/commons') 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 deleted file mode 100644 index d4b3f807b..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt +++ /dev/null @@ -1,81 +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.cds.blueprintsprocessor.db - -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.BluePrintDBLibPropertyService -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService -import org.springframework.boot.context.properties.EnableConfigurationProperties -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.context.annotation.Import -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate -import javax.sql.DataSource - -@Configuration -@Import( - BluePrintPropertyConfiguration::class, - BluePrintPropertiesService::class, - BluePrintCoreConfiguration::class -) -@EnableConfigurationProperties -open class BluePrintDBLibConfiguration(private var bluePrintPropertiesService: BluePrintPropertiesService) { - - @Bean("primary-database-properties") - open fun getPrimaryProperties(): PrimaryDataSourceProperties { - return bluePrintPropertiesService.propertyBeanType( - DBLibConstants.PREFIX_DB, - PrimaryDataSourceProperties::class.java - ) - } - - @Bean("primaryNamedParameterJdbcTemplate") - open fun primaryNamedParameterJdbcTemplate(primaryDataSource: DataSource): NamedParameterJdbcTemplate { - return NamedParameterJdbcTemplate(primaryDataSource) - } -} - -/** - * Exposed Dependency Service by this SSH Lib Module - */ -fun BluePrintDependencyService.dbLibPropertyService(): BluePrintDBLibPropertyService = - instance(BluePrintDBLibPropertyService::class) - -fun BluePrintDependencyService.primaryDBLibGenericService(): BluePrintDBLibGenericService = - instance(PrimaryDBLibGenericService::class) - -class DBLibConstants { - companion object { - - const val PREFIX_DB: String = "blueprintsprocessor.db" - - // list of database - const val MARIA_DB: String = "maria-db" - const val PROCESSOR_DB: String = "processor-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" - } -} 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 deleted file mode 100644 index 7023106eb..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/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.cds.blueprintsprocessor.db - -open class DBDataSourceProperties { - - var type: String = DBLibConstants.MARIA_DB - 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 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 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 deleted file mode 100644 index aeb87fd66..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/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.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) - } -} 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..f11832beb --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintDBLibConfiguration.kt @@ -0,0 +1,81 @@ +/* + * 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.BlueprintCoreConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.BlueprintDBLibPropertyService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintDependencyService +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Import +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate +import javax.sql.DataSource + +@Configuration +@Import( + BlueprintPropertyConfiguration::class, + BlueprintPropertiesService::class, + BlueprintCoreConfiguration::class +) +@EnableConfigurationProperties +open class BlueprintDBLibConfiguration(private var bluePrintPropertiesService: BlueprintPropertiesService) { + + @Bean("primary-database-properties") + open fun getPrimaryProperties(): PrimaryDataSourceProperties { + return bluePrintPropertiesService.propertyBeanType( + DBLibConstants.PREFIX_DB, + PrimaryDataSourceProperties::class.java + ) + } + + @Bean("primaryNamedParameterJdbcTemplate") + open fun primaryNamedParameterJdbcTemplate(primaryDataSource: DataSource): NamedParameterJdbcTemplate { + return NamedParameterJdbcTemplate(primaryDataSource) + } +} + +/** + * Exposed Dependency Service by this SSH Lib Module + */ +fun BlueprintDependencyService.dbLibPropertyService(): BlueprintDBLibPropertyService = + instance(BlueprintDBLibPropertyService::class) + +fun BlueprintDependencyService.primaryDBLibGenericService(): BlueprintDBLibGenericService = + instance(PrimaryDBLibGenericService::class) + +class DBLibConstants { + companion object { + + const val PREFIX_DB: String = "blueprintsprocessor.db" + + // list of database + const val MARIA_DB: String = "maria-db" + const val PROCESSOR_DB: String = "processor-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" + } +} 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..7023106eb --- /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 { + + var type: String = DBLibConstants.MARIA_DB + 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 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 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..6c382377d --- /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) + } +} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSL.kt index 34dd0a417..fd51da152 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSL.kt @@ -17,8 +17,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintTypes import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType @@ -30,25 +30,25 @@ import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType /** Relationships Types DSL for Database Producer */ fun ServiceTemplateBuilder.relationshipTypeConnectsToDb() { - val relationshipType = BluePrintTypes.relationshipTypeConnectsToDb() + val relationshipType = BlueprintTypes.relationshipTypeConnectsToDb() if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() this.relationshipTypes!![relationshipType.id!!] = relationshipType } -fun BluePrintTypes.relationshipTypeConnectsToDb(): RelationshipType { +fun BlueprintTypes.relationshipTypeConnectsToDb(): RelationshipType { return relationshipType( - id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB, - version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, + id = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB, + version = BlueprintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, description = "Relationship connects to through Database." ) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintConstants.DATA_TYPE_MAP, + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintConstants.DATA_TYPE_MAP, true, "Connection Config details." ) - validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) + validTargetTypes(arrayListOf(BlueprintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) } } @@ -66,25 +66,25 @@ fun TopologyTemplateBuilder.relationshipTemplateDb( class DbRelationshipTemplateBuilder(name: String, description: String) : RelationshipTemplateBuilder( name, - BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB, description + BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB, description ) { fun mariaDb(block: DbMariaDataSourcePropertiesAssignmentBuilder.() -> Unit) { - property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.mariaDbProperties(block)) + property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.mariaDbProperties(block)) } fun mySqlDb(block: DbMySqlDataSourcePropertiesAssignmentBuilder.() -> Unit) { - property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.mySqlDbProperties(block)) + property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.mySqlDbProperties(block)) } } -fun BluePrintTypes.mariaDbProperties(block: DbMariaDataSourcePropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.mariaDbProperties(block: DbMariaDataSourcePropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = DbMariaDataSourcePropertiesAssignmentBuilder().apply(block).build() assignments[DBDataSourceProperties::type.name] = DBLibConstants.MARIA_DB.asJsonPrimitive() return assignments.asJsonNode() } -fun BluePrintTypes.mySqlDbProperties(block: DbMySqlDataSourcePropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.mySqlDbProperties(block: DbMySqlDataSourcePropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = DbMySqlDataSourcePropertiesAssignmentBuilder().apply(block).build() assignments[DBDataSourceProperties::type.name] = DBLibConstants.MYSQL_DB.asJsonPrimitive() return assignments.asJsonNode() 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 deleted file mode 100644 index 79f5c09bc..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt +++ /dev/null @@ -1,79 +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.cds.blueprintsprocessor.db.primary - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService -import org.onap.ccsdk.cds.blueprintsprocessor.db.DBDataSourceProperties -import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants.Companion.MARIA_DB -import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants.Companion.MYSQL_DB -import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants.Companion.PROCESSOR_DB -import org.onap.ccsdk.cds.blueprintsprocessor.db.MariaDataSourceProperties -import org.onap.ccsdk.cds.blueprintsprocessor.db.MySqlDataSourceProperties -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.springframework.stereotype.Service - -@Service -class BluePrintDBLibPropertyService(private var bluePrintPropertiesService: BluePrintPropertiesService) { - - fun JdbcTemplate(jsonNode: JsonNode): BluePrintDBLibGenericService = - blueprintDBDataSourceService(dBDataSourceProperties(jsonNode)) - - fun JdbcTemplate(selector: String): BluePrintDBLibGenericService = - blueprintDBDataSourceService(dBDataSourceProperties("blueprintsprocessor.db.$selector")) - - private fun dBDataSourceProperties(jsonNode: JsonNode): DBDataSourceProperties = - when (val type = jsonNode.get("type").textValue()) { - MYSQL_DB -> JacksonUtils.readValue(jsonNode, MySqlDataSourceProperties::class.java) - MARIA_DB -> JacksonUtils.readValue(jsonNode, MariaDataSourceProperties::class.java) - else -> { - throw BluePrintProcessorException( - "DB type ($type) is not supported. Valid types: $MARIA_DB, $MYSQL_DB" - ) - } - }!! - - private fun dBDataSourceProperties(prefix: String): DBDataSourceProperties = - bluePrintPropertiesService.propertyBeanType("$prefix.type", String::class.java).let { - return when (it) { - MARIA_DB, PROCESSOR_DB -> mariaDBConnectionProperties(prefix) - MYSQL_DB -> mySqlDBConnectionProperties(prefix) - else -> { - throw BluePrintProcessorException( - "DB type ($it) is not supported. Valid types: $MARIA_DB, $MYSQL_DB, $PROCESSOR_DB" - ) - } - } - } - - private fun blueprintDBDataSourceService(dBConnetionProperties: DBDataSourceProperties): BluePrintDBLibGenericService = - when (dBConnetionProperties) { - is MariaDataSourceProperties -> MariaDatabaseConfiguration(dBConnetionProperties) - is MySqlDataSourceProperties -> MySqlDatabaseConfiguration(dBConnetionProperties) - else -> throw BluePrintProcessorException( - "Failed to create db configuration for ${dBConnetionProperties.url}" - ) - } - - private fun mySqlDBConnectionProperties(prefix: String): MySqlDataSourceProperties = - bluePrintPropertiesService.propertyBeanType(prefix, MySqlDataSourceProperties::class.java) - - private fun mariaDBConnectionProperties(prefix: String): MariaDataSourceProperties = - bluePrintPropertiesService.propertyBeanType(prefix, MariaDataSourceProperties::class.java) -} 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..b272a9708 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BlueprintDBLibPropertyService.kt @@ -0,0 +1,79 @@ +/* + * 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.BlueprintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.db.BlueprintDBLibGenericService +import org.onap.ccsdk.cds.blueprintsprocessor.db.DBDataSourceProperties +import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants.Companion.MARIA_DB +import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants.Companion.MYSQL_DB +import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants.Companion.PROCESSOR_DB +import org.onap.ccsdk.cds.blueprintsprocessor.db.MariaDataSourceProperties +import org.onap.ccsdk.cds.blueprintsprocessor.db.MySqlDataSourceProperties +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.stereotype.Service + +@Service +class BlueprintDBLibPropertyService(private var bluePrintPropertiesService: BlueprintPropertiesService) { + + fun JdbcTemplate(jsonNode: JsonNode): BlueprintDBLibGenericService = + blueprintDBDataSourceService(dBDataSourceProperties(jsonNode)) + + fun JdbcTemplate(selector: String): BlueprintDBLibGenericService = + blueprintDBDataSourceService(dBDataSourceProperties("blueprintsprocessor.db.$selector")) + + private fun dBDataSourceProperties(jsonNode: JsonNode): DBDataSourceProperties = + when (val type = jsonNode.get("type").textValue()) { + MYSQL_DB -> JacksonUtils.readValue(jsonNode, MySqlDataSourceProperties::class.java) + MARIA_DB -> JacksonUtils.readValue(jsonNode, MariaDataSourceProperties::class.java) + else -> { + throw BlueprintProcessorException( + "DB type ($type) is not supported. Valid types: $MARIA_DB, $MYSQL_DB" + ) + } + }!! + + private fun dBDataSourceProperties(prefix: String): DBDataSourceProperties = + bluePrintPropertiesService.propertyBeanType("$prefix.type", String::class.java).let { + return when (it) { + MARIA_DB, PROCESSOR_DB -> mariaDBConnectionProperties(prefix) + MYSQL_DB -> mySqlDBConnectionProperties(prefix) + else -> { + throw BlueprintProcessorException( + "DB type ($it) is not supported. Valid types: $MARIA_DB, $MYSQL_DB, $PROCESSOR_DB" + ) + } + } + } + + private fun blueprintDBDataSourceService(dBConnetionProperties: DBDataSourceProperties): BlueprintDBLibGenericService = + when (dBConnetionProperties) { + is MariaDataSourceProperties -> MariaDatabaseConfiguration(dBConnetionProperties) + is MySqlDataSourceProperties -> MySqlDatabaseConfiguration(dBConnetionProperties) + else -> throw BlueprintProcessorException( + "Failed to create db configuration for ${dBConnetionProperties.url}" + ) + } + + private fun mySqlDBConnectionProperties(prefix: String): MySqlDataSourceProperties = + bluePrintPropertiesService.propertyBeanType(prefix, MySqlDataSourceProperties::class.java) + + private fun mariaDBConnectionProperties(prefix: String): MariaDataSourceProperties = + bluePrintPropertiesService.propertyBeanType(prefix, MariaDataSourceProperties::class.java) +} 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 index 82895257a..6132190c2 100644 --- 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 @@ -16,14 +16,14 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary -import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService +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 javax.sql.DataSource -class MariaDatabaseConfiguration(private val mariaDataSourceProperties: MariaDataSourceProperties) : BluePrintDBLibGenericService { +class MariaDatabaseConfiguration(private val mariaDataSourceProperties: MariaDataSourceProperties) : BlueprintDBLibGenericService { val log = LoggerFactory.getLogger(MariaDatabaseConfiguration::class.java)!! 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 index 0761b72d2..ea13dfb83 100644 --- 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 @@ -16,14 +16,14 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary -import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService +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 { +class MySqlDatabaseConfiguration(private val mySqlDataSourceProperties: MySqlDataSourceProperties) : BlueprintDBLibGenericService { override fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate { return mySqlNamedParameterJdbcTemplate(mySqlDataSource()) diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintCatalogServiceImpl.kt index 9d1826395..fe6da176b 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintCatalogServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintCatalogServiceImpl.kt @@ -18,16 +18,16 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.service -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException +import org.onap.ccsdk.cds.controllerblueprints.core.config.BlueprintLoadConfiguration import org.onap.ccsdk.cds.controllerblueprints.core.deCompress -import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService -import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintCatalogService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintValidatorService import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BlueprintArchiveUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BlueprintMetadataUtils import org.slf4j.LoggerFactory import java.io.File import java.nio.file.Path @@ -35,9 +35,9 @@ import javax.persistence.MappedSuperclass @MappedSuperclass abstract class BlueprintCatalogServiceImpl( - private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, - private val blueprintValidator: BluePrintValidatorService -) : BluePrintCatalogService { + private val bluePrintLoadConfiguration: BlueprintLoadConfiguration, + private val blueprintValidator: BlueprintValidatorService +) : BlueprintCatalogService { private val log = LoggerFactory.getLogger(BlueprintCatalogServiceImpl::class.java)!! @@ -51,8 +51,8 @@ abstract class BlueprintCatalogServiceImpl( workingDir = blueprintFile.absolutePath archiveFile = normalizedFile(bluePrintLoadConfiguration.blueprintArchivePath, processingId, "cba.zip") - if (!BluePrintArchiveUtils.compress(blueprintFile, archiveFile)) { - throw BluePrintException("Fail to compress blueprint") + if (!BlueprintArchiveUtils.compress(blueprintFile, archiveFile)) { + throw BlueprintException("Fail to compress blueprint") } } else { // Compressed File @@ -63,16 +63,16 @@ abstract class BlueprintCatalogServiceImpl( blueprintFile.deCompress(workingDir) } - var valid = BluePrintConstants.FLAG_N + var valid = BlueprintConstants.FLAG_N if (validate) { - blueprintValidator.validateBluePrints(workingDir!!) - valid = BluePrintConstants.FLAG_Y + blueprintValidator.validateBlueprints(workingDir!!) + valid = BlueprintConstants.FLAG_Y } - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(processingId, workingDir!!) + val bluePrintRuntimeService = BlueprintMetadataUtils.getBlueprintRuntime(processingId, workingDir!!) val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! - metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = processingId - metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] = valid + metadata[BlueprintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = processingId + metadata[BlueprintConstants.PROPERTY_BLUEPRINT_VALID] = valid save(metadata, archiveFile) @@ -83,7 +83,7 @@ abstract class BlueprintCatalogServiceImpl( name, version, extract ) - ?: throw BluePrintException("Could not find blueprint $name:$version from database") + ?: throw BlueprintException("Could not find blueprint $name:$version from database") override suspend fun deleteFromDatabase(name: String, version: String) = delete(name, version) diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintProcessorCatalogServiceImpl.kt index 6637c62ec..10a526365 100755 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintProcessorCatalogServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintProcessorCatalogServiceImpl.kt @@ -23,21 +23,21 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.cluster.optionalClusterServic import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelContent import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelRepository -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.common.ApplicationConstants -import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.config.BlueprintLoadConfiguration import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode import org.onap.ccsdk.cds.controllerblueprints.core.deCompress import org.onap.ccsdk.cds.controllerblueprints.core.deleteNBDir -import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintValidatorService import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName import org.onap.ccsdk.cds.controllerblueprints.core.reCreateNBDirs -import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils +import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BlueprintCompileCache +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintDependencyService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BlueprintFileUtils import org.slf4j.LoggerFactory import org.springframework.dao.DataIntegrityViolationException import org.springframework.stereotype.Service @@ -51,8 +51,8 @@ import java.util.UUID */ @Service("blueprintsProcessorCatalogService") class BlueprintProcessorCatalogServiceImpl( - bluePrintRuntimeValidatorService: BluePrintValidatorService, - private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, + bluePrintRuntimeValidatorService: BlueprintValidatorService, + private val bluePrintLoadConfiguration: BlueprintLoadConfiguration, private val blueprintModelRepository: BlueprintModelRepository ) : BlueprintCatalogServiceImpl(bluePrintLoadConfiguration, bluePrintRuntimeValidatorService) { @@ -61,7 +61,7 @@ class BlueprintProcessorCatalogServiceImpl( override suspend fun delete(name: String, version: String) { // Clean blueprint script cache - val cacheKey = BluePrintFileUtils + val cacheKey = BlueprintFileUtils .compileCacheKey(normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, name, version)) cleanClassLoader(cacheKey) log.info("removed cba file name($name), version($version) from cache") @@ -100,11 +100,11 @@ class BlueprintProcessorCatalogServiceImpl( } check(deployFile.exists() && deployFile.list().isNotEmpty()) { - throw BluePrintProcessorException("file check failed") + throw BlueprintProcessorException("file check failed") } } catch (e: Exception) { deleteNBDir(deployFile.absolutePath) - throw BluePrintProcessorException( + throw BlueprintProcessorException( "failed to get get cba file name($name), version($version) from db" + " : ${e.message}" ) @@ -121,11 +121,11 @@ class BlueprintProcessorCatalogServiceImpl( } override suspend fun save(metadata: MutableMap, archiveFile: File) { - val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] - val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] + val artifactName = metadata[BlueprintConstants.METADATA_TEMPLATE_NAME] + val artifactVersion = metadata[BlueprintConstants.METADATA_TEMPLATE_VERSION] check(archiveFile.isFile && !archiveFile.isDirectory) { - throw BluePrintException("Not a valid Archive file(${archiveFile.absolutePath})") + throw BlueprintException("Not a valid Archive file(${archiveFile.absolutePath})") } blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let { @@ -134,7 +134,7 @@ class BlueprintProcessorCatalogServiceImpl( val deployFile = normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, artifactName, artifactVersion) - val cacheKey = BluePrintFileUtils.compileCacheKey(deployFile) + val cacheKey = BlueprintFileUtils.compileCacheKey(deployFile) cleanClassLoader(cacheKey) deleteNBDir(deployFile).let { @@ -144,20 +144,20 @@ class BlueprintProcessorCatalogServiceImpl( } val blueprintModel = BlueprintModel() - blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] + blueprintModel.id = metadata[BlueprintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL - blueprintModel.published = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] - ?: BluePrintConstants.FLAG_N + blueprintModel.published = metadata[BlueprintConstants.PROPERTY_BLUEPRINT_VALID] + ?: BlueprintConstants.FLAG_N blueprintModel.artifactName = artifactName blueprintModel.artifactVersion = artifactVersion - blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]!! - blueprintModel.tags = metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS]!! + blueprintModel.updatedBy = metadata[BlueprintConstants.METADATA_TEMPLATE_AUTHOR]!! + blueprintModel.tags = metadata[BlueprintConstants.METADATA_TEMPLATE_TAGS]!! val description = - if (null != metadata[BluePrintConstants.METADATA_TEMPLATE_DESCRIPTION]) metadata[BluePrintConstants.METADATA_TEMPLATE_DESCRIPTION] else "" + if (null != metadata[BlueprintConstants.METADATA_TEMPLATE_DESCRIPTION]) metadata[BlueprintConstants.METADATA_TEMPLATE_DESCRIPTION] else "" blueprintModel.artifactDescription = description val blueprintModelContent = BlueprintModelContent() - blueprintModelContent.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] + blueprintModelContent.id = metadata[BlueprintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] blueprintModelContent.contentType = "CBA_ZIP" blueprintModelContent.name = "$artifactName:$artifactVersion" blueprintModelContent.description = "$artifactName:$artifactVersion CBA Zip Content" @@ -169,7 +169,7 @@ class BlueprintProcessorCatalogServiceImpl( try { blueprintModelRepository.saveAndFlush(blueprintModel) } catch (ex: DataIntegrityViolationException) { - throw BluePrintException( + throw BlueprintException( ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " + "is already exist in database: ${ex.message}", @@ -179,9 +179,9 @@ class BlueprintProcessorCatalogServiceImpl( } private suspend fun cleanClassLoader(cacheKey: String) { - val clusterService = BluePrintDependencyService.optionalClusterService() + val clusterService = BlueprintDependencyService.optionalClusterService() if (null == clusterService) - BluePrintCompileCache.cleanClassLoader(cacheKey) + BlueprintCompileCache.cleanClassLoader(cacheKey) else { log.info("Sending ClusterMessage: Clean Classloader Cache") clusterService.sendMessage(BlueprintClusterTopic.BLUEPRINT_CLEAN_COMPILER_CACHE, cacheKey) 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 index b7b1f78cf..4084e156c 100644 --- 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 @@ -20,16 +20,16 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db import kotlinx.coroutines.runBlocking import org.junit.Test import org.junit.runner.RunWith -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintCoreConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.db.mock.MockBlueprintProcessorCatalogServiceImpl import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.service.BlueprintCatalogServiceImpl import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.service.BlueprintProcessorCatalogServiceImpl -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants import org.onap.ccsdk.cds.controllerblueprints.core.compress import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BlueprintMetadataUtils import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.context.annotation.ComponentScan @@ -46,7 +46,7 @@ import kotlin.test.assertTrue @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor"]) @ContextConfiguration( classes = [ - BlueprintProcessorCatalogServiceImpl::class, BluePrintCoreConfiguration::class, + BlueprintProcessorCatalogServiceImpl::class, BlueprintCoreConfiguration::class, MockBlueprintProcessorCatalogServiceImpl::class ] ) @@ -57,9 +57,9 @@ class BlueprintProcessorCatalogServiceImplTest { lateinit var blueprintsProcessorCatalogService: BlueprintCatalogServiceImpl @Autowired - lateinit var blueprintCoreConfiguration: BluePrintCoreConfiguration + lateinit var blueprintCoreConfiguration: BlueprintCoreConfiguration - private lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + private lateinit var bluePrintRuntimeService: BlueprintRuntimeService<*> private val blueprintId = "1234" @@ -72,7 +72,7 @@ class BlueprintProcessorCatalogServiceImplTest { normalizedFile("./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") .compress(normalizedFile("./target/blueprints/generated-cba.zip")) - bluePrintRuntimeService = BluePrintMetadataUtils.bluePrintRuntime( + bluePrintRuntimeService = BlueprintMetadataUtils.bluePrintRuntime( blueprintId, "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" ) @@ -103,7 +103,7 @@ class BlueprintProcessorCatalogServiceImplTest { val file = normalizedFile("./target/blueprints/generated-cba.zip") assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! - metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId + metadata[BlueprintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId blueprintsProcessorCatalogService.save(metadata, file) } @@ -115,7 +115,7 @@ class BlueprintProcessorCatalogServiceImplTest { val file = normalizedFile("./target/blueprints/generated-cba.zip") assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! - metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId + metadata[BlueprintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId blueprintsProcessorCatalogService.save(metadata, file) blueprintsProcessorCatalogService.get("baseconfiguration", "1.0.0", true) diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSLTest.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSLTest.kt index dd84e5b02..d182651af 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSLTest.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSLTest.kt @@ -17,7 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate import kotlin.test.assertEquals @@ -68,12 +68,12 @@ class DatabasePropertiesDSLTest { assertNotNull(relationshipTypes, "failed to get relationship types") assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" ) assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB}" ) } } diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/TestDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/TestDatabaseConfiguration.kt index d8192acfa..38a8ef427 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/TestDatabaseConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/TestDatabaseConfiguration.kt @@ -27,7 +27,7 @@ import org.springframework.transaction.PlatformTransactionManager import javax.sql.DataSource @Configuration -@Import(BluePrintDBLibConfiguration::class) +@Import(BlueprintDBLibConfiguration::class) @EnableJpaRepositories( basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor.db.primary"], entityManagerFactoryRef = "primaryEntityManager", diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/mock/MockBlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/mock/MockBlueprintProcessorCatalogServiceImpl.kt index 248181f16..6135f5bbd 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/mock/MockBlueprintProcessorCatalogServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/mock/MockBlueprintProcessorCatalogServiceImpl.kt @@ -17,8 +17,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.mock import io.mockk.coEvery import io.mockk.mockk -import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintValidatorService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintRuntimeService import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @@ -26,10 +26,10 @@ import org.springframework.context.annotation.Configuration open class MockBlueprintProcessorCatalogServiceImpl { @Bean(name = ["bluePrintRuntimeValidatorService"]) - open fun bluePrintRuntimeValidatorService(): BluePrintValidatorService { - val bluePrintValidatorService = mockk() - coEvery { bluePrintValidatorService.validateBluePrints(any()) } returns true - coEvery { bluePrintValidatorService.validateBluePrints(any>()) } returns true + open fun bluePrintRuntimeValidatorService(): BlueprintValidatorService { + val bluePrintValidatorService = mockk() + coEvery { bluePrintValidatorService.validateBlueprints(any()) } returns true + coEvery { bluePrintValidatorService.validateBlueprints(any>()) } returns true return bluePrintValidatorService } } 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 index dfe95733f..587e020a4 100644 --- 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 @@ -30,7 +30,7 @@ import com.att.nsa.mr.client.impl.MRSimplerBatchPublisher class AafAuthDmaapClientService( private val clientProps: AafAuthDmaapClientProperties ) : - BluePrintDmaapClientService { + BlueprintDmaapClientService { /** * The constructed DMAAP client. 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 deleted file mode 100644 index 82c3f3a80..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt +++ /dev/null @@ -1,106 +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.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 deleted file mode 100644 index 20d9afdef..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt +++ /dev/null @@ -1,48 +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.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" - } -} 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 deleted file mode 100644 index e5c9d432f..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt +++ /dev/null @@ -1,202 +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.cds.blueprintsprocessor.dmaap - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -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 bluePrintPropertiesService: BluePrintPropertiesService) { - - /** - * 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 = bluePrintPropertiesService.propertyBeanType( - "$prefix.type", String::class.java - ) - val clientProps: DmaapClientProperties - - when (type) { - TYPE_HTTP_NO_AUTH -> { - clientProps = bluePrintPropertiesService.propertyBeanType( - prefix, HttpNoAuthDmaapClientProperties::class.java - ) - clientProps.props = parseEventProps() - } - - TYPE_HTTP_AAF_AUTH -> { - clientProps = bluePrintPropertiesService.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/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..c275e7e8b --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BlueprintDmaapClientService.kt @@ -0,0 +1,106 @@ +/*- + * ============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..c64c33231 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BlueprintDmaapLibConfiguration.kt @@ -0,0 +1,48 @@ +/*- + * ============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" + } +} 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..7bc9d605f --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BlueprintDmaapLibPropertyService.kt @@ -0,0 +1,202 @@ +/*- + * ============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.BlueprintPropertiesService +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 bluePrintPropertiesService: BlueprintPropertiesService) { + + /** + * 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 = bluePrintPropertiesService.propertyBeanType( + "$prefix.type", String::class.java + ) + val clientProps: DmaapClientProperties + + when (type) { + TYPE_HTTP_NO_AUTH -> { + clientProps = bluePrintPropertiesService.propertyBeanType( + prefix, HttpNoAuthDmaapClientProperties::class.java + ) + clientProps.props = parseEventProps() + } + + TYPE_HTTP_AAF_AUTH -> { + clientProps = bluePrintPropertiesService.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/HttpNoAuthDmaapClientService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt index d4adfcaac..4f9f89ae2 100644 --- 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 @@ -31,7 +31,7 @@ class HttpNoAuthDmaapClientService( private val clientProps: HttpNoAuthDmaapClientProperties ) : - BluePrintDmaapClientService { + BlueprintDmaapClientService { /** * The constructed DMAAP client. 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 index e6043caae..c44f6a4a3 100644 --- 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 @@ -23,10 +23,10 @@ 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.BluePrintPropertiesService -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.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService +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 @@ -51,8 +51,8 @@ import kotlin.test.assertNotNull @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @ContextConfiguration( classes = [ - BluePrintDmaapLibConfiguration::class, TestController::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class + BlueprintDmaapLibConfiguration::class, TestController::class, + BlueprintPropertyConfiguration::class, BlueprintPropertiesService::class ] ) @TestPropertySource( @@ -69,7 +69,7 @@ import kotlin.test.assertNotNull class TestDmaapEventPublisher { @Autowired - lateinit var dmaapService: BluePrintDmaapLibPropertyService + lateinit var dmaapService: BlueprintDmaapLibPropertyService /** * Tests the event properties being set properly and sent as request. diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcExtensions.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcExtensions.kt deleted file mode 100644 index 97b462a3c..000000000 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcExtensions.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright © 2018-2019 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.grpc - -import io.grpc.Metadata - -fun Metadata.getStringKey(key: String): String? { - return this.get(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER)) -} - -fun Metadata.putStringKeyValue(key: String, value: String) { - this.put(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER), value) -} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt deleted file mode 100644 index e94400d9b..000000000 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright © 2019 IBM. - * Modifications Copyright © 2018-2019 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.grpc - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.BluePrintGrpcClientService -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.BluePrintGrpcLibPropertyService -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration - -@Configuration -@ComponentScan -open class BluePrintGrpcLibConfiguration - -/** - * Exposed Dependency Service by this GRPC Lib Module - */ -fun BluePrintDependencyService.grpcLibPropertyService(): BluePrintGrpcLibPropertyService = - instance(GRPCLibConstants.SERVICE_BLUEPRINT_GRPC_LIB_PROPERTY) - -fun BluePrintDependencyService.grpcClientService(selector: String): BluePrintGrpcClientService { - return grpcLibPropertyService().blueprintGrpcClientService(selector) -} - -fun BluePrintDependencyService.grpcClientService(jsonNode: JsonNode): BluePrintGrpcClientService { - return grpcLibPropertyService().blueprintGrpcClientService(jsonNode) -} - -class GRPCLibConstants { - companion object { - - const val SERVICE_BLUEPRINT_GRPC_LIB_PROPERTY = "blueprint-grpc-lib-property-service" - const val PROPERTY_GRPC_CLIENT_PREFIX = "blueprintsprocessor.grpcclient." - const val PROPERTY_GRPC_SERVER_PREFIX = "blueprintsprocessor.grpcserver." - const val TYPE_TOKEN_AUTH = "token-auth" - const val TYPE_BASIC_AUTH = "basic-auth" - const val TYPE_TLS_AUTH = "tls-auth" - } -} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibData.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibData.kt deleted file mode 100644 index ebb9a5b32..000000000 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibData.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright © 2019 IBM. - * Modifications Copyright © 2018-2019 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.grpc - -/** GRPC Server Properties */ -open class GrpcServerProperties { - - lateinit var type: String - var port: Int = -1 -} - -open class TokenAuthGrpcServerProperties : GrpcServerProperties() { - - lateinit var token: String -} - -open class TLSAuthGrpcServerProperties : GrpcServerProperties() { - - lateinit var certChain: String - lateinit var privateKey: String - - /** Below Used only for Mutual TLS */ - var trustCertCollection: String? = null -} - -/** GRPC Client Properties */ -open class GrpcClientProperties { - - lateinit var type: String - lateinit var host: String - var port: Int = -1 -} - -open class TokenAuthGrpcClientProperties : GrpcClientProperties() { - - lateinit var token: String -} - -open class TLSAuthGrpcClientProperties : GrpcClientProperties() { - - var trustCertCollection: String? = null - - /** Below Used only for Mutual TLS */ - var clientCertChain: String? = null - var clientPrivateKey: String? = null -} - -open class BasicAuthGrpcClientProperties : GrpcClientProperties() { - - lateinit var username: String - lateinit var password: String -} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BlueprintGrpcExtensions.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BlueprintGrpcExtensions.kt new file mode 100644 index 000000000..97b462a3c --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BlueprintGrpcExtensions.kt @@ -0,0 +1,27 @@ +/* + * Copyright © 2018-2019 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.grpc + +import io.grpc.Metadata + +fun Metadata.getStringKey(key: String): String? { + return this.get(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER)) +} + +fun Metadata.putStringKeyValue(key: String, value: String) { + this.put(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER), value) +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BlueprintGrpcLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BlueprintGrpcLibConfiguration.kt new file mode 100644 index 000000000..806e4c6f2 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BlueprintGrpcLibConfiguration.kt @@ -0,0 +1,55 @@ +/* + * Copyright © 2019 IBM. + * Modifications Copyright © 2018-2019 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.grpc + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.BlueprintGrpcClientService +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.BlueprintGrpcLibPropertyService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintDependencyService +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +@Configuration +@ComponentScan +open class BlueprintGrpcLibConfiguration + +/** + * Exposed Dependency Service by this GRPC Lib Module + */ +fun BlueprintDependencyService.grpcLibPropertyService(): BlueprintGrpcLibPropertyService = + instance(GRPCLibConstants.SERVICE_BLUEPRINT_GRPC_LIB_PROPERTY) + +fun BlueprintDependencyService.grpcClientService(selector: String): BlueprintGrpcClientService { + return grpcLibPropertyService().blueprintGrpcClientService(selector) +} + +fun BlueprintDependencyService.grpcClientService(jsonNode: JsonNode): BlueprintGrpcClientService { + return grpcLibPropertyService().blueprintGrpcClientService(jsonNode) +} + +class GRPCLibConstants { + companion object { + + const val SERVICE_BLUEPRINT_GRPC_LIB_PROPERTY = "blueprint-grpc-lib-property-service" + const val PROPERTY_GRPC_CLIENT_PREFIX = "blueprintsprocessor.grpcclient." + const val PROPERTY_GRPC_SERVER_PREFIX = "blueprintsprocessor.grpcserver." + const val TYPE_TOKEN_AUTH = "token-auth" + const val TYPE_BASIC_AUTH = "basic-auth" + const val TYPE_TLS_AUTH = "tls-auth" + } +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BlueprintGrpcLibData.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BlueprintGrpcLibData.kt new file mode 100644 index 000000000..ebb9a5b32 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BlueprintGrpcLibData.kt @@ -0,0 +1,67 @@ +/* + * Copyright © 2019 IBM. + * Modifications Copyright © 2018-2019 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.grpc + +/** GRPC Server Properties */ +open class GrpcServerProperties { + + lateinit var type: String + var port: Int = -1 +} + +open class TokenAuthGrpcServerProperties : GrpcServerProperties() { + + lateinit var token: String +} + +open class TLSAuthGrpcServerProperties : GrpcServerProperties() { + + lateinit var certChain: String + lateinit var privateKey: String + + /** Below Used only for Mutual TLS */ + var trustCertCollection: String? = null +} + +/** GRPC Client Properties */ +open class GrpcClientProperties { + + lateinit var type: String + lateinit var host: String + var port: Int = -1 +} + +open class TokenAuthGrpcClientProperties : GrpcClientProperties() { + + lateinit var token: String +} + +open class TLSAuthGrpcClientProperties : GrpcClientProperties() { + + var trustCertCollection: String? = null + + /** Below Used only for Mutual TLS */ + var clientCertChain: String? = null + var clientPrivateKey: String? = null +} + +open class BasicAuthGrpcClientProperties : GrpcClientProperties() { + + lateinit var username: String + lateinit var password: String +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSL.kt index 8063e8909..853f74930 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSL.kt @@ -17,8 +17,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintTypes import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType @@ -30,48 +30,48 @@ import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType /** Relationships Types DSL for GRPC Server Producer */ fun ServiceTemplateBuilder.relationshipTypeConnectsToGrpcServer() { - val relationshipType = BluePrintTypes.relationshipTypeConnectsToGrpcServer() + val relationshipType = BlueprintTypes.relationshipTypeConnectsToGrpcServer() if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() this.relationshipTypes!![relationshipType.id!!] = relationshipType } -fun BluePrintTypes.relationshipTypeConnectsToGrpcServer(): RelationshipType { +fun BlueprintTypes.relationshipTypeConnectsToGrpcServer(): RelationshipType { return relationshipType( - id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER, - version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, + id = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER, + version = BlueprintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, description = "Relationship connects to through GRPC Server." ) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintConstants.DATA_TYPE_MAP, + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintConstants.DATA_TYPE_MAP, true, "Connection Config details." ) - validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) + validTargetTypes(arrayListOf(BlueprintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) } } fun ServiceTemplateBuilder.relationshipTypeConnectsToGrpcClient() { - val relationshipType = BluePrintTypes.relationshipTypeConnectsToGrpcClient() + val relationshipType = BlueprintTypes.relationshipTypeConnectsToGrpcClient() if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() this.relationshipTypes!![relationshipType.id!!] = relationshipType } -fun BluePrintTypes.relationshipTypeConnectsToGrpcClient(): RelationshipType { +fun BlueprintTypes.relationshipTypeConnectsToGrpcClient(): RelationshipType { return relationshipType( - id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT, - version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, + id = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT, + version = BlueprintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, description = "Relationship connects to through GRPC Client." ) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintConstants.DATA_TYPE_MAP, + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintConstants.DATA_TYPE_MAP, true, "Connection Config details." ) - validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) + validTargetTypes(arrayListOf(BlueprintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) } } @@ -89,25 +89,25 @@ fun TopologyTemplateBuilder.relationshipTemplateGrpcServer( class GrpcServerRelationshipTemplateBuilder(name: String, description: String) : RelationshipTemplateBuilder( name, - BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER, description + BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER, description ) { fun tokenAuth(block: GrpcServerTokenAuthPropertiesAssignmentBuilder.() -> Unit) { - property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tokenAuthGrpcServerProperties(block)) + property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.tokenAuthGrpcServerProperties(block)) } fun tlsAuth(block: GrpcServerTLSAuthPropertiesAssignmentBuilder.() -> Unit) { - property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tlsAuthGrpcServerProperties(block)) + property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.tlsAuthGrpcServerProperties(block)) } } -fun BluePrintTypes.tokenAuthGrpcServerProperties(block: GrpcServerTokenAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.tokenAuthGrpcServerProperties(block: GrpcServerTokenAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = GrpcServerTokenAuthPropertiesAssignmentBuilder().apply(block).build() assignments[GrpcServerProperties::type.name] = GRPCLibConstants.TYPE_TOKEN_AUTH.asJsonPrimitive() return assignments.asJsonNode() } -fun BluePrintTypes.tlsAuthGrpcServerProperties(block: GrpcServerTLSAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.tlsAuthGrpcServerProperties(block: GrpcServerTLSAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = GrpcServerTLSAuthPropertiesAssignmentBuilder().apply(block).build() assignments[GrpcServerProperties::type.name] = GRPCLibConstants.TYPE_TLS_AUTH.asJsonPrimitive() return assignments.asJsonNode() @@ -158,35 +158,35 @@ fun TopologyTemplateBuilder.relationshipTemplateGrpcClient( class GrpcClientRelationshipTemplateBuilder(name: String, description: String) : RelationshipTemplateBuilder( name, - BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT, description + BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT, description ) { fun basicAuth(block: GrpcClientBasicAuthPropertiesAssignmentBuilder.() -> Unit) { - property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.basicAuthGrpcClientProperties(block)) + property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.basicAuthGrpcClientProperties(block)) } fun tokenAuth(block: GrpcClientTokenAuthPropertiesAssignmentBuilder.() -> Unit) { - property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tokenAuthGrpcClientProperties(block)) + property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.tokenAuthGrpcClientProperties(block)) } fun tlsAuth(block: GrpcClientTLSAuthPropertiesAssignmentBuilder.() -> Unit) { - property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tlsAuthGrpcClientProperties(block)) + property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.tlsAuthGrpcClientProperties(block)) } } -fun BluePrintTypes.basicAuthGrpcClientProperties(block: GrpcClientBasicAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.basicAuthGrpcClientProperties(block: GrpcClientBasicAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = GrpcClientBasicAuthPropertiesAssignmentBuilder().apply(block).build() assignments[GrpcClientProperties::type.name] = GRPCLibConstants.TYPE_BASIC_AUTH.asJsonPrimitive() return assignments.asJsonNode() } -fun BluePrintTypes.tokenAuthGrpcClientProperties(block: GrpcClientTokenAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.tokenAuthGrpcClientProperties(block: GrpcClientTokenAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = GrpcClientTokenAuthPropertiesAssignmentBuilder().apply(block).build() assignments[GrpcClientProperties::type.name] = GRPCLibConstants.TYPE_TOKEN_AUTH.asJsonPrimitive() return assignments.asJsonNode() } -fun BluePrintTypes.tlsAuthGrpcClientProperties(block: GrpcClientTLSAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.tlsAuthGrpcClientProperties(block: GrpcClientTLSAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = GrpcClientTLSAuthPropertiesAssignmentBuilder().apply(block).build() assignments[GrpcClientProperties::type.name] = GRPCLibConstants.TYPE_TLS_AUTH.asJsonPrimitive() return assignments.asJsonNode() diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcServerLoggingInterceptor.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcServerLoggingInterceptor.kt index aaa4d5f26..7465ba044 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcServerLoggingInterceptor.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcServerLoggingInterceptor.kt @@ -23,11 +23,11 @@ import io.grpc.ServerCall import io.grpc.ServerCallHandler import io.grpc.ServerInterceptor import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.GrpcLoggerService -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.logger -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintDownloadInput -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintRemoveInput -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput +import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintDownloadInput +import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintRemoveInput +import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintUploadInput import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput import org.slf4j.MDC @@ -62,22 +62,22 @@ class GrpcServerLoggingInterceptor : ServerInterceptor { when (message) { is ExecutionServiceInput -> { val commonHeader = message.commonHeader - ?: throw BluePrintProcessorException("missing common header in request") + ?: throw BlueprintProcessorException("missing common header in request") loggingService.grpcRequesting(call, commonHeader, next) } - is BluePrintUploadInput -> { + is BlueprintUploadInput -> { val commonHeader = message.commonHeader - ?: throw BluePrintProcessorException("missing common header in request") + ?: throw BlueprintProcessorException("missing common header in request") loggingService.grpcRequesting(call, commonHeader, next) } - is BluePrintDownloadInput -> { + is BlueprintDownloadInput -> { val commonHeader = message.commonHeader - ?: throw BluePrintProcessorException("missing common header in request") + ?: throw BlueprintProcessorException("missing common header in request") loggingService.grpcRequesting(call, commonHeader, next) } - is BluePrintRemoveInput -> { + is BlueprintRemoveInput -> { val commonHeader = message.commonHeader - ?: throw BluePrintProcessorException("missing common header in request") + ?: throw BlueprintProcessorException("missing common header in request") loggingService.grpcRequesting(call, commonHeader, next) } else -> { diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BasicAuthGrpcClientService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BasicAuthGrpcClientService.kt index f7be8c66d..72453f596 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BasicAuthGrpcClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BasicAuthGrpcClientService.kt @@ -22,7 +22,7 @@ import io.grpc.netty.NettyChannelBuilder import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BasicAuthGrpcClientProperties open class BasicAuthGrpcClientService(private val basicAuthGrpcClientProperties: BasicAuthGrpcClientProperties) : - BluePrintGrpcClientService { + BlueprintGrpcClientService { override suspend fun channel(): ManagedChannel { val managedChannel = NettyChannelBuilder diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt deleted file mode 100644 index a102ee6da..000000000 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright © 2019 IBM. - * Modifications Copyright © 2018-2019 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.grpc.service - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BasicAuthGrpcClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GRPCLibConstants -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GrpcClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GrpcServerProperties -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcServerProperties -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcServerProperties -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.cds.controllerblueprints.core.returnNullIfMissing -import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.springframework.stereotype.Service - -@Service(GRPCLibConstants.SERVICE_BLUEPRINT_GRPC_LIB_PROPERTY) -open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesService: BluePrintPropertiesService) { - - fun blueprintGrpcServerService(jsonNode: JsonNode): BluePrintGrpcServerService { - val grpcServerProperties = grpcServerProperties(jsonNode) - return blueprintGrpcServerService(grpcServerProperties) - } - - fun blueprintGrpcServerService(selector: String): BluePrintGrpcServerService { - val prefix = "${GRPCLibConstants.PROPERTY_GRPC_SERVER_PREFIX}$selector" - val grpcServerProperties = grpcServerProperties(prefix) - return blueprintGrpcServerService(grpcServerProperties) - } - - /** GRPC Server Lib Property Service */ - fun grpcServerProperties(jsonNode: JsonNode): GrpcServerProperties { - return when (val type = jsonNode.get("type").textValue()) { - GRPCLibConstants.TYPE_TOKEN_AUTH -> { - JacksonUtils.readValue(jsonNode, TokenAuthGrpcServerProperties::class.java)!! - } - GRPCLibConstants.TYPE_TLS_AUTH -> { - JacksonUtils.readValue(jsonNode, TLSAuthGrpcServerProperties::class.java)!! - } - else -> { - throw BluePrintProcessorException("Grpc type($type) not supported") - } - } - } - - fun grpcServerProperties(prefix: String): GrpcServerProperties { - val type = bluePrintPropertiesService.propertyBeanType( - "$prefix.type", String::class.java - ) - return when (type) { - GRPCLibConstants.TYPE_TOKEN_AUTH -> { - tokenAuthGrpcServerProperties(prefix) - } - GRPCLibConstants.TYPE_TLS_AUTH -> { - tlsAuthGrpcServerProperties(prefix) - } - else -> { - throw BluePrintProcessorException("Grpc type($type) not supported") - } - } - } - - private fun tokenAuthGrpcServerProperties(prefix: String): TokenAuthGrpcServerProperties { - return bluePrintPropertiesService.propertyBeanType(prefix, TokenAuthGrpcServerProperties::class.java) - } - - private fun tlsAuthGrpcServerProperties(prefix: String): TLSAuthGrpcServerProperties { - return bluePrintPropertiesService.propertyBeanType(prefix, TLSAuthGrpcServerProperties::class.java) - } - - private fun blueprintGrpcServerService(grpcServerProperties: GrpcServerProperties): - BluePrintGrpcServerService { - when (grpcServerProperties) { - is TLSAuthGrpcServerProperties -> { - return TLSAuthGrpcServerService(grpcServerProperties) - } - else -> { - throw BluePrintProcessorException("couldn't get grpc client service for properties $grpcServerProperties") - } - } - } - - /** GRPC Client Lib Property Service */ - - fun blueprintGrpcClientService(jsonNode: JsonNode): BluePrintGrpcClientService { - val restClientProperties = grpcClientProperties(jsonNode) - return blueprintGrpcClientService(restClientProperties) - } - - fun blueprintGrpcClientService(selector: String): BluePrintGrpcClientService { - val prefix = "${GRPCLibConstants.PROPERTY_GRPC_CLIENT_PREFIX}$selector" - val restClientProperties = grpcClientProperties(prefix) - return blueprintGrpcClientService(restClientProperties) - } - - fun grpcClientProperties(jsonNode: JsonNode): GrpcClientProperties { - val type = jsonNode.get("type").returnNullIfMissing()?.textValue() - ?: BluePrintProcessorException("missing type property") - return when (type) { - GRPCLibConstants.TYPE_TOKEN_AUTH -> { - JacksonUtils.readValue(jsonNode, TokenAuthGrpcClientProperties::class.java)!! - } - GRPCLibConstants.TYPE_TLS_AUTH -> { - JacksonUtils.readValue(jsonNode, TLSAuthGrpcClientProperties::class.java)!! - } - GRPCLibConstants.TYPE_BASIC_AUTH -> { - JacksonUtils.readValue(jsonNode, BasicAuthGrpcClientProperties::class.java)!! - } - else -> { - throw BluePrintProcessorException("Grpc type($type) not supported") - } - } - } - - fun grpcClientProperties(prefix: String): GrpcClientProperties { - val type = bluePrintPropertiesService.propertyBeanType( - "$prefix.type", String::class.java - ) - return when (type) { - GRPCLibConstants.TYPE_TOKEN_AUTH -> { - tokenAuthGrpcClientProperties(prefix) - } - GRPCLibConstants.TYPE_TLS_AUTH -> { - tlsAuthGrpcClientProperties(prefix) - } - GRPCLibConstants.TYPE_BASIC_AUTH -> { - basicAuthGrpcClientProperties(prefix) - } - else -> { - throw BluePrintProcessorException("Grpc type($type) not supported") - } - } - } - - fun blueprintGrpcClientService(grpcClientProperties: GrpcClientProperties): - BluePrintGrpcClientService { - return when (grpcClientProperties) { - is TokenAuthGrpcClientProperties -> { - TokenAuthGrpcClientService(grpcClientProperties) - } - is TLSAuthGrpcClientProperties -> { - TLSAuthGrpcClientService(grpcClientProperties) - } - is BasicAuthGrpcClientProperties -> { - BasicAuthGrpcClientService(grpcClientProperties) - } - else -> { - throw BluePrintProcessorException("couldn't get grpc service for type(${grpcClientProperties.type})") - } - } - } - - private fun tokenAuthGrpcClientProperties(prefix: String): TokenAuthGrpcClientProperties { - return bluePrintPropertiesService.propertyBeanType(prefix, TokenAuthGrpcClientProperties::class.java) - } - - private fun tlsAuthGrpcClientProperties(prefix: String): TLSAuthGrpcClientProperties { - return bluePrintPropertiesService.propertyBeanType(prefix, TLSAuthGrpcClientProperties::class.java) - } - - private fun basicAuthGrpcClientProperties(prefix: String): BasicAuthGrpcClientProperties { - return bluePrintPropertiesService.propertyBeanType(prefix, BasicAuthGrpcClientProperties::class.java) - } -} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcService.kt deleted file mode 100644 index d2db14a53..000000000 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcService.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright © 2019 IBM. - * Modifications Copyright © 2018-2019 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.grpc.service - -import io.grpc.ManagedChannel -import io.grpc.netty.NettyServerBuilder - -interface BluePrintGrpcServerService { - - fun serverBuilder(): NettyServerBuilder -} - -interface BluePrintGrpcClientService { - - suspend fun channel(): ManagedChannel -} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcLibPropertyService.kt new file mode 100644 index 000000000..9b95edfc3 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcLibPropertyService.kt @@ -0,0 +1,182 @@ +/* + * Copyright © 2019 IBM. + * Modifications Copyright © 2018-2019 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.grpc.service + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BasicAuthGrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GRPCLibConstants +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GrpcServerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcServerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcServerProperties +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.returnNullIfMissing +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.stereotype.Service + +@Service(GRPCLibConstants.SERVICE_BLUEPRINT_GRPC_LIB_PROPERTY) +open class BlueprintGrpcLibPropertyService(private var bluePrintPropertiesService: BlueprintPropertiesService) { + + fun blueprintGrpcServerService(jsonNode: JsonNode): BlueprintGrpcServerService { + val grpcServerProperties = grpcServerProperties(jsonNode) + return blueprintGrpcServerService(grpcServerProperties) + } + + fun blueprintGrpcServerService(selector: String): BlueprintGrpcServerService { + val prefix = "${GRPCLibConstants.PROPERTY_GRPC_SERVER_PREFIX}$selector" + val grpcServerProperties = grpcServerProperties(prefix) + return blueprintGrpcServerService(grpcServerProperties) + } + + /** GRPC Server Lib Property Service */ + fun grpcServerProperties(jsonNode: JsonNode): GrpcServerProperties { + return when (val type = jsonNode.get("type").textValue()) { + GRPCLibConstants.TYPE_TOKEN_AUTH -> { + JacksonUtils.readValue(jsonNode, TokenAuthGrpcServerProperties::class.java)!! + } + GRPCLibConstants.TYPE_TLS_AUTH -> { + JacksonUtils.readValue(jsonNode, TLSAuthGrpcServerProperties::class.java)!! + } + else -> { + throw BlueprintProcessorException("Grpc type($type) not supported") + } + } + } + + fun grpcServerProperties(prefix: String): GrpcServerProperties { + val type = bluePrintPropertiesService.propertyBeanType( + "$prefix.type", String::class.java + ) + return when (type) { + GRPCLibConstants.TYPE_TOKEN_AUTH -> { + tokenAuthGrpcServerProperties(prefix) + } + GRPCLibConstants.TYPE_TLS_AUTH -> { + tlsAuthGrpcServerProperties(prefix) + } + else -> { + throw BlueprintProcessorException("Grpc type($type) not supported") + } + } + } + + private fun tokenAuthGrpcServerProperties(prefix: String): TokenAuthGrpcServerProperties { + return bluePrintPropertiesService.propertyBeanType(prefix, TokenAuthGrpcServerProperties::class.java) + } + + private fun tlsAuthGrpcServerProperties(prefix: String): TLSAuthGrpcServerProperties { + return bluePrintPropertiesService.propertyBeanType(prefix, TLSAuthGrpcServerProperties::class.java) + } + + private fun blueprintGrpcServerService(grpcServerProperties: GrpcServerProperties): + BlueprintGrpcServerService { + when (grpcServerProperties) { + is TLSAuthGrpcServerProperties -> { + return TLSAuthGrpcServerService(grpcServerProperties) + } + else -> { + throw BlueprintProcessorException("couldn't get grpc client service for properties $grpcServerProperties") + } + } + } + + /** GRPC Client Lib Property Service */ + + fun blueprintGrpcClientService(jsonNode: JsonNode): BlueprintGrpcClientService { + val restClientProperties = grpcClientProperties(jsonNode) + return blueprintGrpcClientService(restClientProperties) + } + + fun blueprintGrpcClientService(selector: String): BlueprintGrpcClientService { + val prefix = "${GRPCLibConstants.PROPERTY_GRPC_CLIENT_PREFIX}$selector" + val restClientProperties = grpcClientProperties(prefix) + return blueprintGrpcClientService(restClientProperties) + } + + fun grpcClientProperties(jsonNode: JsonNode): GrpcClientProperties { + val type = jsonNode.get("type").returnNullIfMissing()?.textValue() + ?: BlueprintProcessorException("missing type property") + return when (type) { + GRPCLibConstants.TYPE_TOKEN_AUTH -> { + JacksonUtils.readValue(jsonNode, TokenAuthGrpcClientProperties::class.java)!! + } + GRPCLibConstants.TYPE_TLS_AUTH -> { + JacksonUtils.readValue(jsonNode, TLSAuthGrpcClientProperties::class.java)!! + } + GRPCLibConstants.TYPE_BASIC_AUTH -> { + JacksonUtils.readValue(jsonNode, BasicAuthGrpcClientProperties::class.java)!! + } + else -> { + throw BlueprintProcessorException("Grpc type($type) not supported") + } + } + } + + fun grpcClientProperties(prefix: String): GrpcClientProperties { + val type = bluePrintPropertiesService.propertyBeanType( + "$prefix.type", String::class.java + ) + return when (type) { + GRPCLibConstants.TYPE_TOKEN_AUTH -> { + tokenAuthGrpcClientProperties(prefix) + } + GRPCLibConstants.TYPE_TLS_AUTH -> { + tlsAuthGrpcClientProperties(prefix) + } + GRPCLibConstants.TYPE_BASIC_AUTH -> { + basicAuthGrpcClientProperties(prefix) + } + else -> { + throw BlueprintProcessorException("Grpc type($type) not supported") + } + } + } + + fun blueprintGrpcClientService(grpcClientProperties: GrpcClientProperties): + BlueprintGrpcClientService { + return when (grpcClientProperties) { + is TokenAuthGrpcClientProperties -> { + TokenAuthGrpcClientService(grpcClientProperties) + } + is TLSAuthGrpcClientProperties -> { + TLSAuthGrpcClientService(grpcClientProperties) + } + is BasicAuthGrpcClientProperties -> { + BasicAuthGrpcClientService(grpcClientProperties) + } + else -> { + throw BlueprintProcessorException("couldn't get grpc service for type(${grpcClientProperties.type})") + } + } + } + + private fun tokenAuthGrpcClientProperties(prefix: String): TokenAuthGrpcClientProperties { + return bluePrintPropertiesService.propertyBeanType(prefix, TokenAuthGrpcClientProperties::class.java) + } + + private fun tlsAuthGrpcClientProperties(prefix: String): TLSAuthGrpcClientProperties { + return bluePrintPropertiesService.propertyBeanType(prefix, TLSAuthGrpcClientProperties::class.java) + } + + private fun basicAuthGrpcClientProperties(prefix: String): BasicAuthGrpcClientProperties { + return bluePrintPropertiesService.propertyBeanType(prefix, BasicAuthGrpcClientProperties::class.java) + } +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcService.kt new file mode 100644 index 000000000..a9485b3c3 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcService.kt @@ -0,0 +1,31 @@ +/* + * Copyright © 2019 IBM. + * Modifications Copyright © 2018-2019 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.grpc.service + +import io.grpc.ManagedChannel +import io.grpc.netty.NettyServerBuilder + +interface BlueprintGrpcServerService { + + fun serverBuilder(): NettyServerBuilder +} + +interface BlueprintGrpcClientService { + + suspend fun channel(): ManagedChannel +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt index 732f4fecf..a2be05d4d 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt @@ -23,11 +23,11 @@ import io.grpc.ServerCallHandler import org.onap.ccsdk.cds.blueprintsprocessor.grpc.getStringKey import org.onap.ccsdk.cds.blueprintsprocessor.grpc.putStringKeyValue import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_INVOCATION_ID -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_PARTNER_NAME -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_REQUEST_ID -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants.ONAP_INVOCATION_ID +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants.ONAP_PARTNER_NAME +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants.ONAP_REQUEST_ID +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.defaultToEmpty import org.onap.ccsdk.cds.controllerblueprints.core.defaultToUUID import org.onap.ccsdk.cds.controllerblueprints.core.logger @@ -75,7 +75,7 @@ class GrpcLoggerService { val localhost = InetAddress.getLocalHost() val clientSocketAddress = call.attributes.get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR) as? InetSocketAddress - ?: throw BluePrintProcessorException("failed to get client address") + ?: throw BlueprintProcessorException("failed to get client address") val serviceName = call.methodDescriptor.fullMethodName MDC.put("InvokeTimestamp", ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)) @@ -94,7 +94,7 @@ class GrpcLoggerService { fun grpcInvoking(requestHeader: Metadata) { requestHeader.putStringKeyValue(ONAP_REQUEST_ID, MDC.get("InvocationID").defaultToUUID()) requestHeader.putStringKeyValue(ONAP_INVOCATION_ID, UUID.randomUUID().toString()) - requestHeader.putStringKeyValue(ONAP_PARTNER_NAME, BluePrintConstants.APP_NAME) + requestHeader.putStringKeyValue(ONAP_PARTNER_NAME, BlueprintConstants.APP_NAME) } /** Used when server returns response */ diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcClientService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcClientService.kt index 44df5fbe5..a8374d6e7 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcClientService.kt @@ -26,7 +26,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.grpc.interceptor.GrpcClientLogging import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile class TLSAuthGrpcClientService(private val tlsAuthGrpcClientProperties: TLSAuthGrpcClientProperties) : - BluePrintGrpcClientService { + BlueprintGrpcClientService { override suspend fun channel(): ManagedChannel { diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcServerService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcServerService.kt index 915ea1730..c5f8df425 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcServerService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcServerService.kt @@ -25,7 +25,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcServerProperties import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile class TLSAuthGrpcServerService(private val tlsAuthGrpcServerProperties: TLSAuthGrpcServerProperties) : - BluePrintGrpcServerService { + BlueprintGrpcServerService { override fun serverBuilder(): NettyServerBuilder { return NettyServerBuilder diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TokenAuthGrpcClientService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TokenAuthGrpcClientService.kt index 4c991df1f..b14e1d6ad 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TokenAuthGrpcClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TokenAuthGrpcClientService.kt @@ -30,7 +30,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcClientProperties import org.onap.ccsdk.cds.blueprintsprocessor.grpc.interceptor.GrpcClientLoggingInterceptor class TokenAuthGrpcClientService(private val tokenAuthGrpcClientProperties: TokenAuthGrpcClientProperties) : - BluePrintGrpcClientService { + BlueprintGrpcClientService { override suspend fun channel(): ManagedChannel { val target = diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSLTest.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSLTest.kt index 3de857fa5..1e7000e37 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSLTest.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSLTest.kt @@ -17,7 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate import kotlin.test.assertEquals @@ -60,12 +60,12 @@ class GrpcPropertiesDSLTest { assertNotNull(relationshipTypes, "failed to get relationship types") assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" ) assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER}" ) } @@ -115,12 +115,12 @@ class GrpcPropertiesDSLTest { assertNotNull(relationshipTypes, "failed to get relationship types") assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" ) assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT}" ) } } diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyServiceTest.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyServiceTest.kt deleted file mode 100644 index 30722c8e3..000000000 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyServiceTest.kt +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright © 2019 IBM. - * Modifications Copyright © 2018-2019 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.grpc.service - -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.ObjectMapper -import org.junit.Assert -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BasicAuthGrpcClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BluePrintGrpcLibConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcServerProperties -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcClientProperties -import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType -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.assertEquals -import kotlin.test.assertNotNull -import kotlin.test.assertTrue - -@RunWith(SpringRunner::class) -@ContextConfiguration( - classes = [ - BluePrintGrpcLibConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class - ] -) -@TestPropertySource( - properties = - [ - "blueprintsprocessor.grpcclient.sample.type=basic-auth", - "blueprintsprocessor.grpcclient.sample.host=127.0.0.1", - "blueprintsprocessor.grpcclient.sample.port=50505", - "blueprintsprocessor.grpcclient.sample.username=sampleuser", - "blueprintsprocessor.grpcclient.sample.password=sampleuser", - - "blueprintsprocessor.grpcclient.token.type=token-auth", - "blueprintsprocessor.grpcclient.token.host=127.0.0.1", - "blueprintsprocessor.grpcclient.token.port=50505", - "blueprintsprocessor.grpcclient.token.username=sampleuser", - "blueprintsprocessor.grpcclient.token.password=sampleuser", - - "blueprintsprocessor.grpcserver.tls-sample.type=tls-auth", - "blueprintsprocessor.grpcserver.tls-sample.port=50505", - "blueprintsprocessor.grpcserver.tls-sample.certChain=server1.pem", - "blueprintsprocessor.grpcserver.tls-sample.privateKey=server1.key", - "blueprintsprocessor.grpcserver.tls-sample.trustCertCollection=ca.pem", - - "blueprintsprocessor.grpcclient.tls-sample.type=tls-auth", - "blueprintsprocessor.grpcclient.tls-sample.host=127.0.0.1", - "blueprintsprocessor.grpcclient.tls-sample.port=50505", - "blueprintsprocessor.grpcclient.tls-sample.trustCertCollection=ca.pem", - "blueprintsprocessor.grpcclient.tls-sample.clientCertChain=client.pem", - "blueprintsprocessor.grpcclient.tls-sample.clientPrivateKey=client.key" - ] -) -class BluePrintGrpcLibPropertyServiceTest { - - @Autowired - lateinit var bluePrintGrpcLibPropertyService: BluePrintGrpcLibPropertyService - - /** - * Tests the GRPC client properties with selector for basic auth. - */ - @Test - fun testGrpcClientProperties() { - val properties = bluePrintGrpcLibPropertyService.grpcClientProperties( - "blueprintsprocessor.grpcclient.sample" - ) - as BasicAuthGrpcClientProperties - assertNotNull(properties, "failed to create property bean") - assertNotNull( - properties.host, "failed to get host property in property bean" - ) - assertNotNull( - properties.port, "failed to get host property in property bean" - ) - assertNotNull( - properties.username, "failed to get host property in property bean" - ) - assertNotNull( - properties.password, "failed to get host property in property bean" - ) - } - - /** - * Tests the GRPC client properties with JSON node for token auth. - */ - @Test - fun testGrpcClientPropertiesWithJson() { - val json: String = "{\n" + - " \"type\" : \"token-auth\",\n" + - " \"host\" : \"127.0.0.1\",\n" + - " \"port\" : \"50505\"\n" + - "}" - val mapper = ObjectMapper() - val actualObj: JsonNode = mapper.readTree(json) - val properties = bluePrintGrpcLibPropertyService.grpcClientProperties( - actualObj - ) as TokenAuthGrpcClientProperties - assertNotNull(properties, "failed to create property bean") - assertEquals(properties.host, "127.0.0.1") - assertNotNull(properties.port, "50505") - } - - /** - * Tests the GRPC client service with selector for basic auth. - */ - @Test - fun testGrpcClientServiceBasic() { - val svc = bluePrintGrpcLibPropertyService.blueprintGrpcClientService( - "sample" - ) - assertTrue(svc is BasicAuthGrpcClientService) - } - - /** - * Tests the GRPC client service with selector for token auth. - */ - @Test - fun testGrpcClientServiceToken() { - val svc = bluePrintGrpcLibPropertyService.blueprintGrpcClientService( - "token" - ) - assertTrue(svc is TokenAuthGrpcClientService) - } - - /** - * Tests the GRPC client service with JSON node for basic auth. - */ - @Test - fun testGrpcClientServiceWithJson() { - val json: String = "{\n" + - " \"type\" : \"basic-auth\",\n" + - " \"host\" : \"127.0.0.1\",\n" + - " \"port\" : \"50505\",\n" + - " \"username\" : \"sampleuser\",\n" + - " \"password\" : \"samplepwd\"\n" + - "}" - val mapper = ObjectMapper() - val actualObj: JsonNode = mapper.readTree(json) - val svc = bluePrintGrpcLibPropertyService - .blueprintGrpcClientService(actualObj) - assertTrue(svc is BasicAuthGrpcClientService) - } - - @Test - fun testGrpcClientTLSProperties() { - val properties = bluePrintGrpcLibPropertyService - .grpcClientProperties("blueprintsprocessor.grpcclient.tls-sample") as TLSAuthGrpcClientProperties - assertNotNull(properties, "failed to create property bean") - assertNotNull(properties.host, "failed to get host property in property bean") - assertNotNull(properties.port, "failed to get host property in property bean") - assertNotNull(properties.trustCertCollection, "failed to get trustCertCollection property in property bean") - assertNotNull(properties.clientCertChain, "failed to get clientCertChain property in property bean") - assertNotNull(properties.clientPrivateKey, "failed to get clientPrivateKey property in property bean") - - val configDsl = """{ - "type" : "tls-auth", - "host" : "localhost", - "port" : "50505", - "trustCertCollection" : "server1.pem", - "clientCertChain" : "server1.key", - "clientPrivateKey" : "ca.pem" - } - """.trimIndent() - val jsonProperties = bluePrintGrpcLibPropertyService - .grpcClientProperties(configDsl.jsonAsJsonType()) as TLSAuthGrpcClientProperties - assertNotNull(jsonProperties, "failed to create property bean from json") - } - - @Test - fun testGrpcServerTLSProperties() { - val properties = bluePrintGrpcLibPropertyService - .grpcServerProperties("blueprintsprocessor.grpcserver.tls-sample") as TLSAuthGrpcServerProperties - assertNotNull(properties, "failed to create property bean") - assertNotNull(properties.port, "failed to get host property in property bean") - assertNotNull(properties.trustCertCollection, "failed to get trustCertCollection property in property bean") - assertNotNull(properties.certChain, "failed to get certChain property in property bean") - assertNotNull(properties.privateKey, "failed to get privateKey property in property bean") - - val configDsl = """{ - "type" : "tls-auth", - "port" : "50505", - "certChain" : "server1.pem", - "privateKey" : "server1.key", - "trustCertCollection" : "ca.pem" - } - """.trimIndent() - val jsonProperties = bluePrintGrpcLibPropertyService - .grpcServerProperties(configDsl.jsonAsJsonType()) as TLSAuthGrpcServerProperties - assertNotNull(jsonProperties, "failed to create property bean from json") - - val grpcServerService = bluePrintGrpcLibPropertyService.blueprintGrpcServerService("tls-sample") - assertNotNull(grpcServerService, "failed to get grpc server service") - Assert.assertEquals(TLSAuthGrpcServerService::class.java, grpcServerService.javaClass) - } -} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcServerTest.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcServerTest.kt deleted file mode 100644 index 026fe5af5..000000000 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcServerTest.kt +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright © 2018-2019 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.grpc.service - -import com.github.marcoferrer.krotoplus.coroutines.client.clientCallBidiStreaming -import com.google.protobuf.util.JsonFormat -import kotlinx.coroutines.channels.consumeEach -import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking -import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ACTION_MODE_SYNC -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GRPCLibConstants -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcServerProperties -import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers -import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader -import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType -import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc -import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput -import java.util.UUID -import kotlin.test.Test -import kotlin.test.assertNotNull - -class BluePrintGrpcServerTest { - - private val tlsAuthGrpcServerProperties = TLSAuthGrpcServerProperties().apply { - port = 50052 - type = GRPCLibConstants.TYPE_TLS_AUTH - certChain = "src/test/resources/tls-manual/py-executor-chain.pem" - privateKey = "src/test/resources/tls-manual/py-executor-key.pem" - } - - private val tlsAuthGrpcClientProperties = TLSAuthGrpcClientProperties().apply { - host = "localhost" - port = 50052 - type = GRPCLibConstants.TYPE_TLS_AUTH - trustCertCollection = "src/test/resources/tls-manual/py-executor-chain.pem" - } - - @Test - fun testGrpcTLSContext() { - val tlsAuthGrpcServerService = TLSAuthGrpcServerService(tlsAuthGrpcServerProperties) - val sslContext = tlsAuthGrpcServerService.sslContext() - assertNotNull(sslContext, "failed to create grpc server ssl context") - - val tlsAuthGrpcClientService = TLSAuthGrpcClientService(tlsAuthGrpcClientProperties) - val clientSslContext = tlsAuthGrpcClientService.sslContext() - assertNotNull(clientSslContext, "failed to create grpc client ssl context") - } - - /** TLS Client Integration testing, GRPC TLS Junit testing is not supported. */ - // @Test - fun testGrpcTLSServerIntegration() { - runBlocking { - val tlsAuthGrpcClientService = TLSAuthGrpcClientService(tlsAuthGrpcClientProperties) - val grpcChannel = tlsAuthGrpcClientService.channel() - /** Get Send and Receive Channel for bidirectional process method*/ - val (reqChannel, resChannel) = clientCallBidiStreaming( - BluePrintProcessingServiceGrpc.getProcessMethod(), - grpcChannel - ) - launch { - resChannel.consumeEach { - log.info("Received Response") - if (it.status.eventType == EventType.EVENT_COMPONENT_EXECUTED) { - resChannel.cancel() - } - } - } - val request = getRequest("12345") - reqChannel.send(request) - } - } - - private fun getRequest(requestId: String): ExecutionServiceInput { - val commonHeader = CommonHeader.newBuilder() - .setTimestamp("2012-04-23T18:25:43.511Z") - .setOriginatorId("System") - .setRequestId(requestId) - .setSubRequestId("$requestId-" + UUID.randomUUID().toString()).build() - val actionIdentifier = ActionIdentifiers.newBuilder() - .setActionName("SampleScript") - .setBlueprintName("sample-cba") - .setBlueprintVersion("1.0.0") - .setMode(ACTION_MODE_SYNC) - .build() - val jsonContent = """{ "key1" : "value1" }""" - val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder - JsonFormat.parser().merge(jsonContent, payloadBuilder) - - return ExecutionServiceInput.newBuilder() - .setCommonHeader(commonHeader) - .setActionIdentifiers(actionIdentifier) - .setPayload(payloadBuilder.build()) - .build() - } -} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcLibPropertyServiceTest.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcLibPropertyServiceTest.kt new file mode 100644 index 000000000..40e245ade --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcLibPropertyServiceTest.kt @@ -0,0 +1,218 @@ +/* + * Copyright © 2019 IBM. + * Modifications Copyright © 2018-2019 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.grpc.service + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.ObjectMapper +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BasicAuthGrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BlueprintGrpcLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcServerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcClientProperties +import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType +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.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertTrue + +@RunWith(SpringRunner::class) +@ContextConfiguration( + classes = [ + BlueprintGrpcLibConfiguration::class, + BlueprintPropertyConfiguration::class, BlueprintPropertiesService::class + ] +) +@TestPropertySource( + properties = + [ + "blueprintsprocessor.grpcclient.sample.type=basic-auth", + "blueprintsprocessor.grpcclient.sample.host=127.0.0.1", + "blueprintsprocessor.grpcclient.sample.port=50505", + "blueprintsprocessor.grpcclient.sample.username=sampleuser", + "blueprintsprocessor.grpcclient.sample.password=sampleuser", + + "blueprintsprocessor.grpcclient.token.type=token-auth", + "blueprintsprocessor.grpcclient.token.host=127.0.0.1", + "blueprintsprocessor.grpcclient.token.port=50505", + "blueprintsprocessor.grpcclient.token.username=sampleuser", + "blueprintsprocessor.grpcclient.token.password=sampleuser", + + "blueprintsprocessor.grpcserver.tls-sample.type=tls-auth", + "blueprintsprocessor.grpcserver.tls-sample.port=50505", + "blueprintsprocessor.grpcserver.tls-sample.certChain=server1.pem", + "blueprintsprocessor.grpcserver.tls-sample.privateKey=server1.key", + "blueprintsprocessor.grpcserver.tls-sample.trustCertCollection=ca.pem", + + "blueprintsprocessor.grpcclient.tls-sample.type=tls-auth", + "blueprintsprocessor.grpcclient.tls-sample.host=127.0.0.1", + "blueprintsprocessor.grpcclient.tls-sample.port=50505", + "blueprintsprocessor.grpcclient.tls-sample.trustCertCollection=ca.pem", + "blueprintsprocessor.grpcclient.tls-sample.clientCertChain=client.pem", + "blueprintsprocessor.grpcclient.tls-sample.clientPrivateKey=client.key" + ] +) +class BlueprintGrpcLibPropertyServiceTest { + + @Autowired + lateinit var bluePrintGrpcLibPropertyService: BlueprintGrpcLibPropertyService + + /** + * Tests the GRPC client properties with selector for basic auth. + */ + @Test + fun testGrpcClientProperties() { + val properties = bluePrintGrpcLibPropertyService.grpcClientProperties( + "blueprintsprocessor.grpcclient.sample" + ) + as BasicAuthGrpcClientProperties + assertNotNull(properties, "failed to create property bean") + assertNotNull( + properties.host, "failed to get host property in property bean" + ) + assertNotNull( + properties.port, "failed to get host property in property bean" + ) + assertNotNull( + properties.username, "failed to get host property in property bean" + ) + assertNotNull( + properties.password, "failed to get host property in property bean" + ) + } + + /** + * Tests the GRPC client properties with JSON node for token auth. + */ + @Test + fun testGrpcClientPropertiesWithJson() { + val json: String = "{\n" + + " \"type\" : \"token-auth\",\n" + + " \"host\" : \"127.0.0.1\",\n" + + " \"port\" : \"50505\"\n" + + "}" + val mapper = ObjectMapper() + val actualObj: JsonNode = mapper.readTree(json) + val properties = bluePrintGrpcLibPropertyService.grpcClientProperties( + actualObj + ) as TokenAuthGrpcClientProperties + assertNotNull(properties, "failed to create property bean") + assertEquals(properties.host, "127.0.0.1") + assertNotNull(properties.port, "50505") + } + + /** + * Tests the GRPC client service with selector for basic auth. + */ + @Test + fun testGrpcClientServiceBasic() { + val svc = bluePrintGrpcLibPropertyService.blueprintGrpcClientService( + "sample" + ) + assertTrue(svc is BasicAuthGrpcClientService) + } + + /** + * Tests the GRPC client service with selector for token auth. + */ + @Test + fun testGrpcClientServiceToken() { + val svc = bluePrintGrpcLibPropertyService.blueprintGrpcClientService( + "token" + ) + assertTrue(svc is TokenAuthGrpcClientService) + } + + /** + * Tests the GRPC client service with JSON node for basic auth. + */ + @Test + fun testGrpcClientServiceWithJson() { + val json: String = "{\n" + + " \"type\" : \"basic-auth\",\n" + + " \"host\" : \"127.0.0.1\",\n" + + " \"port\" : \"50505\",\n" + + " \"username\" : \"sampleuser\",\n" + + " \"password\" : \"samplepwd\"\n" + + "}" + val mapper = ObjectMapper() + val actualObj: JsonNode = mapper.readTree(json) + val svc = bluePrintGrpcLibPropertyService + .blueprintGrpcClientService(actualObj) + assertTrue(svc is BasicAuthGrpcClientService) + } + + @Test + fun testGrpcClientTLSProperties() { + val properties = bluePrintGrpcLibPropertyService + .grpcClientProperties("blueprintsprocessor.grpcclient.tls-sample") as TLSAuthGrpcClientProperties + assertNotNull(properties, "failed to create property bean") + assertNotNull(properties.host, "failed to get host property in property bean") + assertNotNull(properties.port, "failed to get host property in property bean") + assertNotNull(properties.trustCertCollection, "failed to get trustCertCollection property in property bean") + assertNotNull(properties.clientCertChain, "failed to get clientCertChain property in property bean") + assertNotNull(properties.clientPrivateKey, "failed to get clientPrivateKey property in property bean") + + val configDsl = """{ + "type" : "tls-auth", + "host" : "localhost", + "port" : "50505", + "trustCertCollection" : "server1.pem", + "clientCertChain" : "server1.key", + "clientPrivateKey" : "ca.pem" + } + """.trimIndent() + val jsonProperties = bluePrintGrpcLibPropertyService + .grpcClientProperties(configDsl.jsonAsJsonType()) as TLSAuthGrpcClientProperties + assertNotNull(jsonProperties, "failed to create property bean from json") + } + + @Test + fun testGrpcServerTLSProperties() { + val properties = bluePrintGrpcLibPropertyService + .grpcServerProperties("blueprintsprocessor.grpcserver.tls-sample") as TLSAuthGrpcServerProperties + assertNotNull(properties, "failed to create property bean") + assertNotNull(properties.port, "failed to get host property in property bean") + assertNotNull(properties.trustCertCollection, "failed to get trustCertCollection property in property bean") + assertNotNull(properties.certChain, "failed to get certChain property in property bean") + assertNotNull(properties.privateKey, "failed to get privateKey property in property bean") + + val configDsl = """{ + "type" : "tls-auth", + "port" : "50505", + "certChain" : "server1.pem", + "privateKey" : "server1.key", + "trustCertCollection" : "ca.pem" + } + """.trimIndent() + val jsonProperties = bluePrintGrpcLibPropertyService + .grpcServerProperties(configDsl.jsonAsJsonType()) as TLSAuthGrpcServerProperties + assertNotNull(jsonProperties, "failed to create property bean from json") + + val grpcServerService = bluePrintGrpcLibPropertyService.blueprintGrpcServerService("tls-sample") + assertNotNull(grpcServerService, "failed to get grpc server service") + Assert.assertEquals(TLSAuthGrpcServerService::class.java, grpcServerService.javaClass) + } +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcServerTest.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcServerTest.kt new file mode 100644 index 000000000..130175e64 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BlueprintGrpcServerTest.kt @@ -0,0 +1,110 @@ +/* + * Copyright © 2018-2019 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.grpc.service + +import com.github.marcoferrer.krotoplus.coroutines.client.clientCallBidiStreaming +import com.google.protobuf.util.JsonFormat +import kotlinx.coroutines.channels.consumeEach +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ACTION_MODE_SYNC +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GRPCLibConstants +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcServerProperties +import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers +import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader +import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType +import org.onap.ccsdk.cds.controllerblueprints.processing.api.BlueprintProcessingServiceGrpc +import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput +import java.util.UUID +import kotlin.test.Test +import kotlin.test.assertNotNull + +class BlueprintGrpcServerTest { + + private val tlsAuthGrpcServerProperties = TLSAuthGrpcServerProperties().apply { + port = 50052 + type = GRPCLibConstants.TYPE_TLS_AUTH + certChain = "src/test/resources/tls-manual/py-executor-chain.pem" + privateKey = "src/test/resources/tls-manual/py-executor-key.pem" + } + + private val tlsAuthGrpcClientProperties = TLSAuthGrpcClientProperties().apply { + host = "localhost" + port = 50052 + type = GRPCLibConstants.TYPE_TLS_AUTH + trustCertCollection = "src/test/resources/tls-manual/py-executor-chain.pem" + } + + @Test + fun testGrpcTLSContext() { + val tlsAuthGrpcServerService = TLSAuthGrpcServerService(tlsAuthGrpcServerProperties) + val sslContext = tlsAuthGrpcServerService.sslContext() + assertNotNull(sslContext, "failed to create grpc server ssl context") + + val tlsAuthGrpcClientService = TLSAuthGrpcClientService(tlsAuthGrpcClientProperties) + val clientSslContext = tlsAuthGrpcClientService.sslContext() + assertNotNull(clientSslContext, "failed to create grpc client ssl context") + } + + /** TLS Client Integration testing, GRPC TLS Junit testing is not supported. */ + // @Test + fun testGrpcTLSServerIntegration() { + runBlocking { + val tlsAuthGrpcClientService = TLSAuthGrpcClientService(tlsAuthGrpcClientProperties) + val grpcChannel = tlsAuthGrpcClientService.channel() + /** Get Send and Receive Channel for bidirectional process method*/ + val (reqChannel, resChannel) = clientCallBidiStreaming( + BlueprintProcessingServiceGrpc.getProcessMethod(), + grpcChannel + ) + launch { + resChannel.consumeEach { + log.info("Received Response") + if (it.status.eventType == EventType.EVENT_COMPONENT_EXECUTED) { + resChannel.cancel() + } + } + } + val request = getRequest("12345") + reqChannel.send(request) + } + } + + private fun getRequest(requestId: String): ExecutionServiceInput { + val commonHeader = CommonHeader.newBuilder() + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId(requestId) + .setSubRequestId("$requestId-" + UUID.randomUUID().toString()).build() + val actionIdentifier = ActionIdentifiers.newBuilder() + .setActionName("SampleScript") + .setBlueprintName("sample-cba") + .setBlueprintVersion("1.0.0") + .setMode(ACTION_MODE_SYNC) + .build() + val jsonContent = """{ "key1" : "value1" }""" + val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder + JsonFormat.parser().merge(jsonContent, payloadBuilder) + + return ExecutionServiceInput.newBuilder() + .setCommonHeader(commonHeader) + .setActionIdentifiers(actionIdentifier) + .setPayload(payloadBuilder.build()) + .build() + } +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/MockTLSBluePrintProcessingServer.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/MockTLSBluePrintProcessingServer.kt deleted file mode 100644 index 78fa27d3a..000000000 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/MockTLSBluePrintProcessingServer.kt +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright © 2018-2019 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.grpc.service - -import io.grpc.stub.StreamObserver -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GRPCLibConstants -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcServerProperties -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.interceptor.GrpcServerLoggingInterceptor -import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType -import org.onap.ccsdk.cds.controllerblueprints.common.api.Status -import org.onap.ccsdk.cds.controllerblueprints.core.logger -import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc -import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput -import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput - -val log = logger(MockTLSBluePrintProcessingServer::class) - -/** For Integration testing stat this server, Set the working path to run this method */ -fun main() { - try { - val tlsAuthGrpcServerProperties = TLSAuthGrpcServerProperties().apply { - port = 50052 - type = GRPCLibConstants.TYPE_TLS_AUTH - certChain = "src/test/resources/tls-manual/py-executor-chain.pem" - privateKey = "src/test/resources/tls-manual/py-executor-key.pem" - } - val server = TLSAuthGrpcServerService(tlsAuthGrpcServerProperties).serverBuilder() - .intercept(GrpcServerLoggingInterceptor()) - .addService(MockTLSBluePrintProcessingServer()) - .build() - server.start() - log.info("GRPC Serve started(${server.isShutdown}) on port(${server.port})...") - server.awaitTermination() - } catch (e: Exception) { - log.error("Failed to start tls grpc integration server", e) - } -} - -class MockTLSBluePrintProcessingServer : BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase() { - - override fun process(responseObserver: StreamObserver): StreamObserver { - - return object : StreamObserver { - override fun onNext(executionServiceInput: ExecutionServiceInput) { - log.info( - "Received requestId(${executionServiceInput.commonHeader.requestId}) " + - "subRequestId(${executionServiceInput.commonHeader.subRequestId})" - ) - responseObserver.onNext(buildResponse(executionServiceInput)) - responseObserver.onCompleted() - } - - override fun onError(error: Throwable) { - log.debug("Fail to process message", error) - responseObserver.onError( - io.grpc.Status.INTERNAL - .withDescription(error.message) - .asException() - ) - } - - override fun onCompleted() { - log.info("Completed") - } - } - } - - private fun buildResponse(input: ExecutionServiceInput): ExecutionServiceOutput { - val status = Status.newBuilder().setCode(200) - .setEventType(EventType.EVENT_COMPONENT_EXECUTED) - .build() - return ExecutionServiceOutput.newBuilder() - .setCommonHeader(input.commonHeader) - .setActionIdentifiers(input.actionIdentifiers) - .setStatus(status) - .build() - } -} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/MockTLSBlueprintProcessingServer.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/MockTLSBlueprintProcessingServer.kt new file mode 100644 index 000000000..5426d7327 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/MockTLSBlueprintProcessingServer.kt @@ -0,0 +1,92 @@ +/* + * Copyright © 2018-2019 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.grpc.service + +import io.grpc.stub.StreamObserver +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GRPCLibConstants +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcServerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.interceptor.GrpcServerLoggingInterceptor +import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType +import org.onap.ccsdk.cds.controllerblueprints.common.api.Status +import org.onap.ccsdk.cds.controllerblueprints.core.logger +import org.onap.ccsdk.cds.controllerblueprints.processing.api.BlueprintProcessingServiceGrpc +import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput +import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput + +val log = logger(MockTLSBlueprintProcessingServer::class) + +/** For Integration testing stat this server, Set the working path to run this method */ +fun main() { + try { + val tlsAuthGrpcServerProperties = TLSAuthGrpcServerProperties().apply { + port = 50052 + type = GRPCLibConstants.TYPE_TLS_AUTH + certChain = "src/test/resources/tls-manual/py-executor-chain.pem" + privateKey = "src/test/resources/tls-manual/py-executor-key.pem" + } + val server = TLSAuthGrpcServerService(tlsAuthGrpcServerProperties).serverBuilder() + .intercept(GrpcServerLoggingInterceptor()) + .addService(MockTLSBlueprintProcessingServer()) + .build() + server.start() + log.info("GRPC Serve started(${server.isShutdown}) on port(${server.port})...") + server.awaitTermination() + } catch (e: Exception) { + log.error("Failed to start tls grpc integration server", e) + } +} + +class MockTLSBlueprintProcessingServer : BlueprintProcessingServiceGrpc.BlueprintProcessingServiceImplBase() { + + override fun process(responseObserver: StreamObserver): StreamObserver { + + return object : StreamObserver { + override fun onNext(executionServiceInput: ExecutionServiceInput) { + log.info( + "Received requestId(${executionServiceInput.commonHeader.requestId}) " + + "subRequestId(${executionServiceInput.commonHeader.subRequestId})" + ) + responseObserver.onNext(buildResponse(executionServiceInput)) + responseObserver.onCompleted() + } + + override fun onError(error: Throwable) { + log.debug("Fail to process message", error) + responseObserver.onError( + io.grpc.Status.INTERNAL + .withDescription(error.message) + .asException() + ) + } + + override fun onCompleted() { + log.info("Completed") + } + } + } + + private fun buildResponse(input: ExecutionServiceInput): ExecutionServiceOutput { + val status = Status.newBuilder().setCode(200) + .setEventType(EventType.EVENT_COMPONENT_EXECUTED) + .build() + return ExecutionServiceOutput.newBuilder() + .setCommonHeader(input.commonHeader) + .setActionIdentifiers(input.actionIdentifiers) + .setStatus(status) + .build() + } +} diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BluePrintMessageExtensions.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BluePrintMessageExtensions.kt deleted file mode 100644 index 509689eca..000000000 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BluePrintMessageExtensions.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright © 2018-2019 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.message - -import org.apache.kafka.common.header.Headers -import org.apache.kafka.common.header.internals.RecordHeader -import java.nio.charset.Charset - -fun T?.toMap(): MutableMap { - val map: MutableMap = hashMapOf() - this?.forEach { map[it.key()] = String(it.value(), Charset.defaultCharset()) } - return map -} - -fun Headers.addHeader(key: String, value: String) { - this.add(RecordHeader(key, value.toByteArray())) -} diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BluePrintMessageLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BluePrintMessageLibConfiguration.kt deleted file mode 100644 index 659295a6b..000000000 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BluePrintMessageLibConfiguration.kt +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright © 2019 IBM. - * Modifications Copyright © 2018-2019 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.message - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.blueprintsprocessor.message.service.BluePrintMessageLibPropertyService -import org.onap.ccsdk.cds.blueprintsprocessor.message.service.BlueprintMessageConsumerService -import org.onap.ccsdk.cds.blueprintsprocessor.message.service.BlueprintMessageProducerService -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService -import org.springframework.boot.context.properties.EnableConfigurationProperties -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration - -@Configuration -@ComponentScan -@EnableConfigurationProperties -open class BluePrintMessageLibConfiguration - -/** - * Exposed Dependency Service by this Message Lib Module - */ -fun BluePrintDependencyService.messageLibPropertyService(): BluePrintMessageLibPropertyService = - instance(MessageLibConstants.SERVICE_BLUEPRINT_MESSAGE_LIB_PROPERTY) - -/** Extension functions for message producer service **/ -fun BluePrintDependencyService.messageProducerService(selector: String): BlueprintMessageProducerService { - return messageLibPropertyService().blueprintMessageProducerService(selector) -} - -fun BluePrintDependencyService.messageProducerService(jsonNode: JsonNode): BlueprintMessageProducerService { - return messageLibPropertyService().blueprintMessageProducerService(jsonNode) -} - -/** Extension functions for message consumer service **/ -fun BluePrintDependencyService.messageConsumerService(selector: String): BlueprintMessageConsumerService { - return messageLibPropertyService().blueprintMessageConsumerService(selector) -} - -fun BluePrintDependencyService.messageConsumerService(jsonNode: JsonNode): BlueprintMessageConsumerService { - return messageLibPropertyService().blueprintMessageConsumerService(jsonNode) -} - -class MessageLibConstants { - companion object { - - const val SERVICE_BLUEPRINT_MESSAGE_LIB_PROPERTY = "blueprint-message-lib-property-service" - const val PROPERTY_MESSAGE_CONSUMER_PREFIX = "blueprintsprocessor.messageconsumer." - const val PROPERTY_MESSAGE_PRODUCER_PREFIX = "blueprintsprocessor.messageproducer." - const val TYPE_KAFKA_BASIC_AUTH = "kafka-basic-auth" - const val TYPE_KAFKA_SCRAM_SSL_AUTH = "kafka-scram-ssl-auth" - const val TYPE_KAFKA_SSL_AUTH = "kafka-ssl-auth" - const val TYPE_KAFKA_STREAMS_BASIC_AUTH = "kafka-streams-basic-auth" - const val TYPE_KAFKA_STREAMS_SSL_AUTH = "kafka-streams-ssl-auth" - const val TYPE_KAFKA_STREAMS_SCRAM_SSL_AUTH = "kafka-streams-scram-ssl-auth" - } -} diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BluePrintMessageLibData.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BluePrintMessageLibData.kt deleted file mode 100644 index 67dba1f19..000000000 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BluePrintMessageLibData.kt +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright © 2019 IBM. - * Modifications Copyright © 2018-2019 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.message - -import org.apache.kafka.clients.CommonClientConfigs -import org.apache.kafka.clients.consumer.ConsumerConfig -import org.apache.kafka.clients.producer.ProducerConfig -import org.apache.kafka.common.config.SaslConfigs -import org.apache.kafka.common.config.SslConfigs -import org.apache.kafka.common.security.auth.SecurityProtocol -import org.apache.kafka.common.security.scram.ScramLoginModule -import org.apache.kafka.common.serialization.ByteArrayDeserializer -import org.apache.kafka.common.serialization.ByteArraySerializer -import org.apache.kafka.common.serialization.StringDeserializer -import org.apache.kafka.common.serialization.StringSerializer -import org.apache.kafka.streams.StreamsConfig - -/** Common Properties **/ -abstract class CommonProperties { - - lateinit var type: String - lateinit var topic: String - lateinit var bootstrapServers: String - - open fun getConfig(): HashMap { - val configProps = hashMapOf() - configProps[ProducerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers - return configProps - } -} - -/** Message Producer */ -/** Message Producer Properties **/ -abstract class MessageProducerProperties : CommonProperties() - -/** Basic Auth */ -open class KafkaBasicAuthMessageProducerProperties : MessageProducerProperties() { - - var clientId: String? = null - var acks: String = "all" // strongest producing guarantee - var maxBlockMs: Int = 250 // max blocking time in ms to send a message - var reconnectBackOffMs: Int = 60 * 60 * 1000 // time in ms before retrying connection (1 hour) - var enableIdempotence: Boolean = true // ensure we don't push duplicates - - override fun getConfig(): HashMap { - val configProps = super.getConfig() - configProps[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java - configProps[ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG] = ByteArraySerializer::class.java - configProps[ProducerConfig.ACKS_CONFIG] = acks - configProps[ProducerConfig.MAX_BLOCK_MS_CONFIG] = maxBlockMs - configProps[ProducerConfig.RECONNECT_BACKOFF_MS_CONFIG] = reconnectBackOffMs - configProps[ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG] = enableIdempotence - if (clientId != null) { - configProps[ProducerConfig.CLIENT_ID_CONFIG] = clientId!! - } - return configProps - } -} - -/** SSL Auth */ -open class KafkaSslAuthMessageProducerProperties : KafkaBasicAuthMessageProducerProperties() { - - lateinit var truststore: String - lateinit var truststorePassword: String - var truststoreType: String = SslConfigs.DEFAULT_SSL_TRUSTSTORE_TYPE - var keystore: String? = null - var keystorePassword: String? = null - var keystoreType: String = SslConfigs.DEFAULT_SSL_KEYSTORE_TYPE - var sslEndpointIdentificationAlgorithm: String = SslConfigs.DEFAULT_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM - - override fun getConfig(): HashMap { - val configProps = super.getConfig() - configProps[CommonClientConfigs.SECURITY_PROTOCOL_CONFIG] = SecurityProtocol.SSL.toString() - configProps[SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG] = truststoreType - configProps[SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG] = truststore!! - configProps[SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG] = truststorePassword!! - if (keystore != null) { - configProps[SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG] = keystore!! - configProps[SslConfigs.SSL_KEYSTORE_TYPE_CONFIG] = keystoreType - configProps[SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG] = keystorePassword!! - } - configProps[SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG] = sslEndpointIdentificationAlgorithm - - return configProps - } -} - -/** (SASL) SCRAM SSL Auth */ -class KafkaScramSslAuthMessageProducerProperties : KafkaSslAuthMessageProducerProperties() { - - var saslMechanism: String = "SCRAM-SHA-512" - lateinit var scramUsername: String - lateinit var scramPassword: String - - override fun getConfig(): HashMap { - val configProps = super.getConfig() - configProps[CommonClientConfigs.SECURITY_PROTOCOL_CONFIG] = SecurityProtocol.SASL_SSL.toString() - configProps[SaslConfigs.SASL_MECHANISM] = saslMechanism - configProps[SaslConfigs.SASL_JAAS_CONFIG] = "${ScramLoginModule::class.java.canonicalName} required " + - "username=\"${scramUsername}\" " + - "password=\"${scramPassword}\";" - return configProps - } -} - -/** Consumer */ -abstract class MessageConsumerProperties : CommonProperties() -/** Kafka Streams */ -/** Streams properties */ - -/** Basic Auth */ -open class KafkaStreamsBasicAuthConsumerProperties : MessageConsumerProperties() { - - lateinit var applicationId: String - var autoOffsetReset: String = "latest" - var processingGuarantee: String = StreamsConfig.EXACTLY_ONCE - - override fun getConfig(): HashMap { - val configProperties = super.getConfig() - configProperties[StreamsConfig.APPLICATION_ID_CONFIG] = applicationId - configProperties[ConsumerConfig.AUTO_OFFSET_RESET_CONFIG] = autoOffsetReset - configProperties[StreamsConfig.PROCESSING_GUARANTEE_CONFIG] = processingGuarantee - return configProperties - } -} - -/** SSL Auth */ -open class KafkaStreamsSslAuthConsumerProperties : KafkaStreamsBasicAuthConsumerProperties() { - - lateinit var truststore: String - lateinit var truststorePassword: String - var truststoreType: String = SslConfigs.DEFAULT_SSL_TRUSTSTORE_TYPE - var keystore: String? = null - var keystorePassword: String? = null - var keystoreType: String = SslConfigs.DEFAULT_SSL_KEYSTORE_TYPE - var sslEndpointIdentificationAlgorithm: String = SslConfigs.DEFAULT_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM - - override fun getConfig(): HashMap { - val configProps = super.getConfig() - configProps[CommonClientConfigs.SECURITY_PROTOCOL_CONFIG] = SecurityProtocol.SSL.toString() - configProps[SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG] = truststoreType - configProps[SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG] = truststore!! - configProps[SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG] = truststorePassword!! - if (keystore != null) { - configProps[SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG] = keystore!! - configProps[SslConfigs.SSL_KEYSTORE_TYPE_CONFIG] = keystoreType - configProps[SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG] = keystorePassword!! - } - configProps[SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG] = sslEndpointIdentificationAlgorithm - return configProps - } -} - -/** (SASL) SCRAM SSL Auth */ -class KafkaStreamsScramSslAuthConsumerProperties : KafkaStreamsSslAuthConsumerProperties() { - - var saslMechanism: String = "SCRAM-SHA-512" - lateinit var scramUsername: String - lateinit var scramPassword: String - - override fun getConfig(): HashMap { - val configProps = super.getConfig() - configProps[CommonClientConfigs.SECURITY_PROTOCOL_CONFIG] = SecurityProtocol.SASL_SSL.toString() - configProps[SaslConfigs.SASL_MECHANISM] = saslMechanism - configProps[SaslConfigs.SASL_JAAS_CONFIG] = "${ScramLoginModule::class.java.canonicalName} required " + - "username=\"${scramUsername}\" " + - "password=\"${scramPassword}\";" - return configProps - } -} - -/** Message Consumer */ -/** Message Consumer Properties **/ -/** Basic Auth */ -open class KafkaBasicAuthMessageConsumerProperties : MessageConsumerProperties() { - - lateinit var groupId: String - lateinit var clientId: String - var autoCommit: Boolean = true - var autoOffsetReset: String = "latest" - var pollMillSec: Long = 1000 - var pollRecords: Int = -1 - - override fun getConfig(): HashMap { - val configProperties = super.getConfig() - configProperties[ConsumerConfig.GROUP_ID_CONFIG] = groupId - configProperties[ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG] = autoCommit - /** - * earliest: automatically reset the offset to the earliest offset - * latest: automatically reset the offset to the latest offset - */ - configProperties[ConsumerConfig.AUTO_OFFSET_RESET_CONFIG] = autoOffsetReset - configProperties[ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG] = StringDeserializer::class.java - configProperties[ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG] = ByteArrayDeserializer::class.java - configProperties[ConsumerConfig.CLIENT_ID_CONFIG] = clientId - - /** To handle Back pressure, Get only configured record for processing */ - if (pollRecords > 0) { - configProperties[ConsumerConfig.MAX_POLL_RECORDS_CONFIG] = pollRecords - } - - return configProperties - } -} - -/** SSL Auth */ -open class KafkaSslAuthMessageConsumerProperties : KafkaBasicAuthMessageConsumerProperties() { - - lateinit var truststore: String - lateinit var truststorePassword: String - var truststoreType: String = SslConfigs.DEFAULT_SSL_TRUSTSTORE_TYPE - var keystore: String? = null - var keystorePassword: String? = null - var keystoreType: String = SslConfigs.DEFAULT_SSL_KEYSTORE_TYPE - var sslEndpointIdentificationAlgorithm: String = SslConfigs.DEFAULT_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM - - override fun getConfig(): HashMap { - val configProps = super.getConfig() - configProps[CommonClientConfigs.SECURITY_PROTOCOL_CONFIG] = SecurityProtocol.SSL.toString() - configProps[SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG] = truststoreType - configProps[SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG] = truststore!! - configProps[SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG] = truststorePassword!! - if (keystore != null) { - configProps[SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG] = keystore!! - configProps[SslConfigs.SSL_KEYSTORE_TYPE_CONFIG] = keystoreType - configProps[SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG] = keystorePassword!! - } - configProps[SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG] = sslEndpointIdentificationAlgorithm - return configProps - } -} - -/** (SASL) SCRAM SSL Auth */ -class KafkaScramSslAuthMessageConsumerProperties : KafkaSslAuthMessageConsumerProperties() { - - var saslMechanism: String = "SCRAM-SHA-512" - lateinit var scramUsername: String - lateinit var scramPassword: String - - override fun getConfig(): HashMap { - val configProps = super.getConfig() - configProps[CommonClientConfigs.SECURITY_PROTOCOL_CONFIG] = SecurityProtocol.SASL_SSL.toString() - configProps[SaslConfigs.SASL_MECHANISM] = saslMechanism - configProps[SaslConfigs.SASL_JAAS_CONFIG] = "${ScramLoginModule::class.java.canonicalName} required " + - "username=\"${scramUsername}\" " + - "password=\"${scramPassword}\";" - return configProps - } -} diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BlueprintMessageExtensions.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BlueprintMessageExtensions.kt new file mode 100644 index 000000000..509689eca --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BlueprintMessageExtensions.kt @@ -0,0 +1,31 @@ +/* + * Copyright © 2018-2019 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.message + +import org.apache.kafka.common.header.Headers +import org.apache.kafka.common.header.internals.RecordHeader +import java.nio.charset.Charset + +fun T?.toMap(): MutableMap { + val map: MutableMap = hashMapOf() + this?.forEach { map[it.key()] = String(it.value(), Charset.defaultCharset()) } + return map +} + +fun Headers.addHeader(key: String, value: String) { + this.add(RecordHeader(key, value.toByteArray())) +} diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BlueprintMessageLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BlueprintMessageLibConfiguration.kt new file mode 100644 index 000000000..88931d13f --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BlueprintMessageLibConfiguration.kt @@ -0,0 +1,71 @@ +/* + * Copyright © 2019 IBM. + * Modifications Copyright © 2018-2019 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.message + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.blueprintsprocessor.message.service.BlueprintMessageLibPropertyService +import org.onap.ccsdk.cds.blueprintsprocessor.message.service.BlueprintMessageConsumerService +import org.onap.ccsdk.cds.blueprintsprocessor.message.service.BlueprintMessageProducerService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintDependencyService +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +@Configuration +@ComponentScan +@EnableConfigurationProperties +open class BlueprintMessageLibConfiguration + +/** + * Exposed Dependency Service by this Message Lib Module + */ +fun BlueprintDependencyService.messageLibPropertyService(): BlueprintMessageLibPropertyService = + instance(MessageLibConstants.SERVICE_BLUEPRINT_MESSAGE_LIB_PROPERTY) + +/** Extension functions for message producer service **/ +fun BlueprintDependencyService.messageProducerService(selector: String): BlueprintMessageProducerService { + return messageLibPropertyService().blueprintMessageProducerService(selector) +} + +fun BlueprintDependencyService.messageProducerService(jsonNode: JsonNode): BlueprintMessageProducerService { + return messageLibPropertyService().blueprintMessageProducerService(jsonNode) +} + +/** Extension functions for message consumer service **/ +fun BlueprintDependencyService.messageConsumerService(selector: String): BlueprintMessageConsumerService { + return messageLibPropertyService().blueprintMessageConsumerService(selector) +} + +fun BlueprintDependencyService.messageConsumerService(jsonNode: JsonNode): BlueprintMessageConsumerService { + return messageLibPropertyService().blueprintMessageConsumerService(jsonNode) +} + +class MessageLibConstants { + companion object { + + const val SERVICE_BLUEPRINT_MESSAGE_LIB_PROPERTY = "blueprint-message-lib-property-service" + const val PROPERTY_MESSAGE_CONSUMER_PREFIX = "blueprintsprocessor.messageconsumer." + const val PROPERTY_MESSAGE_PRODUCER_PREFIX = "blueprintsprocessor.messageproducer." + const val TYPE_KAFKA_BASIC_AUTH = "kafka-basic-auth" + const val TYPE_KAFKA_SCRAM_SSL_AUTH = "kafka-scram-ssl-auth" + const val TYPE_KAFKA_SSL_AUTH = "kafka-ssl-auth" + const val TYPE_KAFKA_STREAMS_BASIC_AUTH = "kafka-streams-basic-auth" + const val TYPE_KAFKA_STREAMS_SSL_AUTH = "kafka-streams-ssl-auth" + const val TYPE_KAFKA_STREAMS_SCRAM_SSL_AUTH = "kafka-streams-scram-ssl-auth" + } +} diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BlueprintMessageLibData.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BlueprintMessageLibData.kt new file mode 100644 index 000000000..67dba1f19 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/BlueprintMessageLibData.kt @@ -0,0 +1,264 @@ +/* + * Copyright © 2019 IBM. + * Modifications Copyright © 2018-2019 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.message + +import org.apache.kafka.clients.CommonClientConfigs +import org.apache.kafka.clients.consumer.ConsumerConfig +import org.apache.kafka.clients.producer.ProducerConfig +import org.apache.kafka.common.config.SaslConfigs +import org.apache.kafka.common.config.SslConfigs +import org.apache.kafka.common.security.auth.SecurityProtocol +import org.apache.kafka.common.security.scram.ScramLoginModule +import org.apache.kafka.common.serialization.ByteArrayDeserializer +import org.apache.kafka.common.serialization.ByteArraySerializer +import org.apache.kafka.common.serialization.StringDeserializer +import org.apache.kafka.common.serialization.StringSerializer +import org.apache.kafka.streams.StreamsConfig + +/** Common Properties **/ +abstract class CommonProperties { + + lateinit var type: String + lateinit var topic: String + lateinit var bootstrapServers: String + + open fun getConfig(): HashMap { + val configProps = hashMapOf() + configProps[ProducerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers + return configProps + } +} + +/** Message Producer */ +/** Message Producer Properties **/ +abstract class MessageProducerProperties : CommonProperties() + +/** Basic Auth */ +open class KafkaBasicAuthMessageProducerProperties : MessageProducerProperties() { + + var clientId: String? = null + var acks: String = "all" // strongest producing guarantee + var maxBlockMs: Int = 250 // max blocking time in ms to send a message + var reconnectBackOffMs: Int = 60 * 60 * 1000 // time in ms before retrying connection (1 hour) + var enableIdempotence: Boolean = true // ensure we don't push duplicates + + override fun getConfig(): HashMap { + val configProps = super.getConfig() + configProps[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java + configProps[ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG] = ByteArraySerializer::class.java + configProps[ProducerConfig.ACKS_CONFIG] = acks + configProps[ProducerConfig.MAX_BLOCK_MS_CONFIG] = maxBlockMs + configProps[ProducerConfig.RECONNECT_BACKOFF_MS_CONFIG] = reconnectBackOffMs + configProps[ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG] = enableIdempotence + if (clientId != null) { + configProps[ProducerConfig.CLIENT_ID_CONFIG] = clientId!! + } + return configProps + } +} + +/** SSL Auth */ +open class KafkaSslAuthMessageProducerProperties : KafkaBasicAuthMessageProducerProperties() { + + lateinit var truststore: String + lateinit var truststorePassword: String + var truststoreType: String = SslConfigs.DEFAULT_SSL_TRUSTSTORE_TYPE + var keystore: String? = null + var keystorePassword: String? = null + var keystoreType: String = SslConfigs.DEFAULT_SSL_KEYSTORE_TYPE + var sslEndpointIdentificationAlgorithm: String = SslConfigs.DEFAULT_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM + + override fun getConfig(): HashMap { + val configProps = super.getConfig() + configProps[CommonClientConfigs.SECURITY_PROTOCOL_CONFIG] = SecurityProtocol.SSL.toString() + configProps[SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG] = truststoreType + configProps[SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG] = truststore!! + configProps[SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG] = truststorePassword!! + if (keystore != null) { + configProps[SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG] = keystore!! + configProps[SslConfigs.SSL_KEYSTORE_TYPE_CONFIG] = keystoreType + configProps[SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG] = keystorePassword!! + } + configProps[SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG] = sslEndpointIdentificationAlgorithm + + return configProps + } +} + +/** (SASL) SCRAM SSL Auth */ +class KafkaScramSslAuthMessageProducerProperties : KafkaSslAuthMessageProducerProperties() { + + var saslMechanism: String = "SCRAM-SHA-512" + lateinit var scramUsername: String + lateinit var scramPassword: String + + override fun getConfig(): HashMap { + val configProps = super.getConfig() + configProps[CommonClientConfigs.SECURITY_PROTOCOL_CONFIG] = SecurityProtocol.SASL_SSL.toString() + configProps[SaslConfigs.SASL_MECHANISM] = saslMechanism + configProps[SaslConfigs.SASL_JAAS_CONFIG] = "${ScramLoginModule::class.java.canonicalName} required " + + "username=\"${scramUsername}\" " + + "password=\"${scramPassword}\";" + return configProps + } +} + +/** Consumer */ +abstract class MessageConsumerProperties : CommonProperties() +/** Kafka Streams */ +/** Streams properties */ + +/** Basic Auth */ +open class KafkaStreamsBasicAuthConsumerProperties : MessageConsumerProperties() { + + lateinit var applicationId: String + var autoOffsetReset: String = "latest" + var processingGuarantee: String = StreamsConfig.EXACTLY_ONCE + + override fun getConfig(): HashMap { + val configProperties = super.getConfig() + configProperties[StreamsConfig.APPLICATION_ID_CONFIG] = applicationId + configProperties[ConsumerConfig.AUTO_OFFSET_RESET_CONFIG] = autoOffsetReset + configProperties[StreamsConfig.PROCESSING_GUARANTEE_CONFIG] = processingGuarantee + return configProperties + } +} + +/** SSL Auth */ +open class KafkaStreamsSslAuthConsumerProperties : KafkaStreamsBasicAuthConsumerProperties() { + + lateinit var truststore: String + lateinit var truststorePassword: String + var truststoreType: String = SslConfigs.DEFAULT_SSL_TRUSTSTORE_TYPE + var keystore: String? = null + var keystorePassword: String? = null + var keystoreType: String = SslConfigs.DEFAULT_SSL_KEYSTORE_TYPE + var sslEndpointIdentificationAlgorithm: String = SslConfigs.DEFAULT_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM + + override fun getConfig(): HashMap { + val configProps = super.getConfig() + configProps[CommonClientConfigs.SECURITY_PROTOCOL_CONFIG] = SecurityProtocol.SSL.toString() + configProps[SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG] = truststoreType + configProps[SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG] = truststore!! + configProps[SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG] = truststorePassword!! + if (keystore != null) { + configProps[SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG] = keystore!! + configProps[SslConfigs.SSL_KEYSTORE_TYPE_CONFIG] = keystoreType + configProps[SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG] = keystorePassword!! + } + configProps[SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG] = sslEndpointIdentificationAlgorithm + return configProps + } +} + +/** (SASL) SCRAM SSL Auth */ +class KafkaStreamsScramSslAuthConsumerProperties : KafkaStreamsSslAuthConsumerProperties() { + + var saslMechanism: String = "SCRAM-SHA-512" + lateinit var scramUsername: String + lateinit var scramPassword: String + + override fun getConfig(): HashMap { + val configProps = super.getConfig() + configProps[CommonClientConfigs.SECURITY_PROTOCOL_CONFIG] = SecurityProtocol.SASL_SSL.toString() + configProps[SaslConfigs.SASL_MECHANISM] = saslMechanism + configProps[SaslConfigs.SASL_JAAS_CONFIG] = "${ScramLoginModule::class.java.canonicalName} required " + + "username=\"${scramUsername}\" " + + "password=\"${scramPassword}\";" + return configProps + } +} + +/** Message Consumer */ +/** Message Consumer Properties **/ +/** Basic Auth */ +open class KafkaBasicAuthMessageConsumerProperties : MessageConsumerProperties() { + + lateinit var groupId: String + lateinit var clientId: String + var autoCommit: Boolean = true + var autoOffsetReset: String = "latest" + var pollMillSec: Long = 1000 + var pollRecords: Int = -1 + + override fun getConfig(): HashMap { + val configProperties = super.getConfig() + configProperties[ConsumerConfig.GROUP_ID_CONFIG] = groupId + configProperties[ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG] = autoCommit + /** + * earliest: automatically reset the offset to the earliest offset + * latest: automatically reset the offset to the latest offset + */ + configProperties[ConsumerConfig.AUTO_OFFSET_RESET_CONFIG] = autoOffsetReset + configProperties[ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG] = StringDeserializer::class.java + configProperties[ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG] = ByteArrayDeserializer::class.java + configProperties[ConsumerConfig.CLIENT_ID_CONFIG] = clientId + + /** To handle Back pressure, Get only configured record for processing */ + if (pollRecords > 0) { + configProperties[ConsumerConfig.MAX_POLL_RECORDS_CONFIG] = pollRecords + } + + return configProperties + } +} + +/** SSL Auth */ +open class KafkaSslAuthMessageConsumerProperties : KafkaBasicAuthMessageConsumerProperties() { + + lateinit var truststore: String + lateinit var truststorePassword: String + var truststoreType: String = SslConfigs.DEFAULT_SSL_TRUSTSTORE_TYPE + var keystore: String? = null + var keystorePassword: String? = null + var keystoreType: String = SslConfigs.DEFAULT_SSL_KEYSTORE_TYPE + var sslEndpointIdentificationAlgorithm: String = SslConfigs.DEFAULT_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM + + override fun getConfig(): HashMap { + val configProps = super.getConfig() + configProps[CommonClientConfigs.SECURITY_PROTOCOL_CONFIG] = SecurityProtocol.SSL.toString() + configProps[SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG] = truststoreType + configProps[SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG] = truststore!! + configProps[SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG] = truststorePassword!! + if (keystore != null) { + configProps[SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG] = keystore!! + configProps[SslConfigs.SSL_KEYSTORE_TYPE_CONFIG] = keystoreType + configProps[SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG] = keystorePassword!! + } + configProps[SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG] = sslEndpointIdentificationAlgorithm + return configProps + } +} + +/** (SASL) SCRAM SSL Auth */ +class KafkaScramSslAuthMessageConsumerProperties : KafkaSslAuthMessageConsumerProperties() { + + var saslMechanism: String = "SCRAM-SHA-512" + lateinit var scramUsername: String + lateinit var scramPassword: String + + override fun getConfig(): HashMap { + val configProps = super.getConfig() + configProps[CommonClientConfigs.SECURITY_PROTOCOL_CONFIG] = SecurityProtocol.SASL_SSL.toString() + configProps[SaslConfigs.SASL_MECHANISM] = saslMechanism + configProps[SaslConfigs.SASL_JAAS_CONFIG] = "${ScramLoginModule::class.java.canonicalName} required " + + "username=\"${scramUsername}\" " + + "password=\"${scramPassword}\";" + return configProps + } +} diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSL.kt index 8b31de9b9..527374f02 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSL.kt @@ -17,8 +17,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.message import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintTypes import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType @@ -30,48 +30,48 @@ import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType /** Relationships Types DSL for Message Producer */ fun ServiceTemplateBuilder.relationshipTypeConnectsToMessageProducer() { - val relationshipType = BluePrintTypes.relationshipTypeConnectsToMessageProducer() + val relationshipType = BlueprintTypes.relationshipTypeConnectsToMessageProducer() if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() this.relationshipTypes!![relationshipType.id!!] = relationshipType } -fun BluePrintTypes.relationshipTypeConnectsToMessageProducer(): RelationshipType { +fun BlueprintTypes.relationshipTypeConnectsToMessageProducer(): RelationshipType { return relationshipType( - id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER, - version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, + id = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER, + version = BlueprintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, description = "Relationship connects to through message producer." ) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintConstants.DATA_TYPE_MAP, + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintConstants.DATA_TYPE_MAP, true, "Connection Config details." ) - validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) + validTargetTypes(arrayListOf(BlueprintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) } } fun ServiceTemplateBuilder.relationshipTypeConnectsToMessageConsumer() { - val relationshipType = BluePrintTypes.relationshipTypeConnectsToMessageConsumer() + val relationshipType = BlueprintTypes.relationshipTypeConnectsToMessageConsumer() if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() this.relationshipTypes!![relationshipType.id!!] = relationshipType } -fun BluePrintTypes.relationshipTypeConnectsToMessageConsumer(): RelationshipType { +fun BlueprintTypes.relationshipTypeConnectsToMessageConsumer(): RelationshipType { return relationshipType( - id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER, - version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, + id = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER, + version = BlueprintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, description = "Relationship type connects to message consumer." ) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintConstants.DATA_TYPE_MAP, + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintConstants.DATA_TYPE_MAP, true, "Connection Config details." ) - validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) + validTargetTypes(arrayListOf(BlueprintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) } } @@ -90,46 +90,46 @@ fun TopologyTemplateBuilder.relationshipTemplateMessageProducer( class MessageProducerRelationshipTemplateBuilder(name: String, description: String) : RelationshipTemplateBuilder( name, - BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER, description + BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER, description ) { fun kafkaBasicAuth(block: KafkaBasicAuthMessageProducerPropertiesAssignmentBuilder.() -> Unit) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintTypes.kafkaBasicAuthMessageProducerProperties(block) + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintTypes.kafkaBasicAuthMessageProducerProperties(block) ) } fun kafkaSslAuth(block: KafkaSslAuthMessageProducerPropertiesAssignmentBuilder.() -> Unit) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintTypes.kafkaSslAuthMessageProducerProperties(block) + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintTypes.kafkaSslAuthMessageProducerProperties(block) ) } fun kafkaScramSslAuth(block: KafkaScramSslAuthMessageProducerPropertiesAssignmentBuilder.() -> Unit) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintTypes.kafkaScramSslAuthMessageProducerProperties(block) + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintTypes.kafkaScramSslAuthMessageProducerProperties(block) ) } } -fun BluePrintTypes.kafkaBasicAuthMessageProducerProperties(block: KafkaBasicAuthMessageProducerPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.kafkaBasicAuthMessageProducerProperties(block: KafkaBasicAuthMessageProducerPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = KafkaBasicAuthMessageProducerPropertiesAssignmentBuilder().apply(block).build() assignments[KafkaBasicAuthMessageProducerProperties::type.name] = MessageLibConstants.TYPE_KAFKA_BASIC_AUTH.asJsonPrimitive() return assignments.asJsonType() } -fun BluePrintTypes.kafkaSslAuthMessageProducerProperties(block: KafkaSslAuthMessageProducerPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.kafkaSslAuthMessageProducerProperties(block: KafkaSslAuthMessageProducerPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = KafkaSslAuthMessageProducerPropertiesAssignmentBuilder().apply(block).build() assignments[KafkaSslAuthMessageProducerProperties::type.name] = MessageLibConstants.TYPE_KAFKA_SSL_AUTH.asJsonPrimitive() return assignments.asJsonType() } -fun BluePrintTypes.kafkaScramSslAuthMessageProducerProperties(block: KafkaScramSslAuthMessageProducerPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.kafkaScramSslAuthMessageProducerProperties(block: KafkaScramSslAuthMessageProducerPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = KafkaScramSslAuthMessageProducerPropertiesAssignmentBuilder().apply(block).build() assignments[KafkaScramSslAuthMessageProducerProperties::type.name] = MessageLibConstants.TYPE_KAFKA_SCRAM_SSL_AUTH.asJsonPrimitive() @@ -245,88 +245,88 @@ fun TopologyTemplateBuilder.relationshipTemplateMessageConsumer( class MessageConsumerRelationshipTemplateBuilder(name: String, description: String) : RelationshipTemplateBuilder( name, - BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER, description + BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER, description ) { fun kafkaBasicAuth(block: KafkaBasicAuthMessageConsumerPropertiesAssignmentBuilder.() -> Unit) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintTypes.kafkaBasicAuthMessageConsumerProperties(block) + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintTypes.kafkaBasicAuthMessageConsumerProperties(block) ) } fun kafkaSslAuth(block: KafkaSslAuthMessageConsumerPropertiesAssignmentBuilder.() -> Unit) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintTypes.kafkaSslAuthMessageConsumerProperties(block) + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintTypes.kafkaSslAuthMessageConsumerProperties(block) ) } fun kafkaScramSslAuth(block: KafkaScramSslAuthMessageConsumerPropertiesAssignmentBuilder.() -> Unit) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintTypes.kafkaScramSslAuthMessageConsumerProperties(block) + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintTypes.kafkaScramSslAuthMessageConsumerProperties(block) ) } fun kafkaStreamsBasicAuth(block: KafkaStreamsBasicAuthConsumerPropertiesAssignmentBuilder.() -> Unit) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintTypes.kafkaStreamsBasicAuthConsumerProperties(block) + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintTypes.kafkaStreamsBasicAuthConsumerProperties(block) ) } fun kafkaStreamsSslAuth(block: KafkaStreamsSslAuthConsumerPropertiesAssignmentBuilder.() -> Unit) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintTypes.kafkaStreamsSslAuthConsumerProperties(block) + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintTypes.kafkaStreamsSslAuthConsumerProperties(block) ) } fun kafkaStreamsScramSslAuth(block: KafkaStreamsScramSslAuthConsumerPropertiesAssignmentBuilder.() -> Unit) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintTypes.kafkaStreamsScramSslAuthConsumerProperties(block) + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintTypes.kafkaStreamsScramSslAuthConsumerProperties(block) ) } } -fun BluePrintTypes.kafkaBasicAuthMessageConsumerProperties(block: KafkaBasicAuthMessageConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.kafkaBasicAuthMessageConsumerProperties(block: KafkaBasicAuthMessageConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = KafkaBasicAuthMessageConsumerPropertiesAssignmentBuilder().apply(block).build() assignments[KafkaBasicAuthMessageConsumerProperties::type.name] = MessageLibConstants.TYPE_KAFKA_BASIC_AUTH.asJsonPrimitive() return assignments.asJsonType() } -fun BluePrintTypes.kafkaSslAuthMessageConsumerProperties(block: KafkaSslAuthMessageConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.kafkaSslAuthMessageConsumerProperties(block: KafkaSslAuthMessageConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = KafkaSslAuthMessageConsumerPropertiesAssignmentBuilder().apply(block).build() assignments[KafkaSslAuthMessageConsumerProperties::type.name] = MessageLibConstants.TYPE_KAFKA_SSL_AUTH.asJsonPrimitive() return assignments.asJsonType() } -fun BluePrintTypes.kafkaScramSslAuthMessageConsumerProperties(block: KafkaScramSslAuthMessageConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.kafkaScramSslAuthMessageConsumerProperties(block: KafkaScramSslAuthMessageConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = KafkaScramSslAuthMessageConsumerPropertiesAssignmentBuilder().apply(block).build() assignments[KafkaScramSslAuthMessageConsumerProperties::type.name] = MessageLibConstants.TYPE_KAFKA_SCRAM_SSL_AUTH.asJsonPrimitive() return assignments.asJsonType() } -fun BluePrintTypes.kafkaStreamsBasicAuthConsumerProperties(block: KafkaStreamsBasicAuthConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.kafkaStreamsBasicAuthConsumerProperties(block: KafkaStreamsBasicAuthConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = KafkaStreamsBasicAuthConsumerPropertiesAssignmentBuilder().apply(block).build() assignments[KafkaStreamsBasicAuthConsumerProperties::type.name] = MessageLibConstants.TYPE_KAFKA_STREAMS_BASIC_AUTH.asJsonPrimitive() return assignments.asJsonType() } -fun BluePrintTypes.kafkaStreamsSslAuthConsumerProperties(block: KafkaStreamsSslAuthConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.kafkaStreamsSslAuthConsumerProperties(block: KafkaStreamsSslAuthConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = KafkaStreamsSslAuthConsumerPropertiesAssignmentBuilder().apply(block).build() assignments[KafkaStreamsSslAuthConsumerProperties::type.name] = MessageLibConstants.TYPE_KAFKA_STREAMS_SSL_AUTH.asJsonPrimitive() return assignments.asJsonType() } -fun BluePrintTypes.kafkaStreamsScramSslAuthConsumerProperties(block: KafkaStreamsScramSslAuthConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.kafkaStreamsScramSslAuthConsumerProperties(block: KafkaStreamsScramSslAuthConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = KafkaStreamsScramSslAuthConsumerPropertiesAssignmentBuilder().apply(block).build() assignments[KafkaStreamsScramSslAuthConsumerProperties::type.name] = MessageLibConstants.TYPE_KAFKA_STREAMS_SCRAM_SSL_AUTH.asJsonPrimitive() diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/kafka/AbstractKafkaTopologyComponents.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/kafka/AbstractKafkaTopologyComponents.kt index 72a70893a..23eca18a3 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/kafka/AbstractKafkaTopologyComponents.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/kafka/AbstractKafkaTopologyComponents.kt @@ -24,9 +24,9 @@ import org.apache.kafka.streams.processor.Punctuator import org.onap.ccsdk.cds.controllerblueprints.core.logger /** CDS Kafka Stream Processor abstract class to implement */ -abstract class AbstractBluePrintMessageProcessor : Processor { +abstract class AbstractBlueprintMessageProcessor : Processor { - private val log = logger(AbstractBluePrintMessageProcessor::class) + private val log = logger(AbstractBlueprintMessageProcessor::class) lateinit var processorContext: ProcessorContext @@ -51,7 +51,7 @@ abstract class AbstractBluePrintMessageProcessor : Processor { } /** CDS Kafka Stream Punctuator abstract class to implement */ -abstract class AbstractBluePrintMessagePunctuator : Punctuator { +abstract class AbstractBlueprintMessagePunctuator : Punctuator { lateinit var processorContext: ProcessorContext diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/kafka/KafkaJDBCStores.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/kafka/KafkaJDBCStores.kt index 86ccd74a2..ecf5870ab 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/kafka/KafkaJDBCStores.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/kafka/KafkaJDBCStores.kt @@ -21,10 +21,10 @@ import org.apache.kafka.streams.processor.ProcessorContext import org.apache.kafka.streams.processor.StateStore import org.apache.kafka.streams.state.StoreBuilder import org.apache.kafka.streams.state.StoreSupplier -import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService +import org.onap.ccsdk.cds.blueprintsprocessor.db.BlueprintDBLibGenericService import org.onap.ccsdk.cds.blueprintsprocessor.db.primaryDBLibGenericService import org.onap.ccsdk.cds.controllerblueprints.core.logger -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintDependencyService import java.util.* @@ -32,7 +32,7 @@ class KafkaJDBCKeyStoreSupplier(private val name: String) : StoreSupplier { - bluePrintPropertiesService.propertyBeanType( - prefix, KafkaBasicAuthMessageProducerProperties::class.java - ) - } - MessageLibConstants.TYPE_KAFKA_SSL_AUTH -> { - bluePrintPropertiesService.propertyBeanType( - prefix, KafkaSslAuthMessageProducerProperties::class.java - ) - } - MessageLibConstants.TYPE_KAFKA_SCRAM_SSL_AUTH -> { - bluePrintPropertiesService.propertyBeanType( - prefix, KafkaScramSslAuthMessageProducerProperties::class.java - ) - } - else -> { - throw BluePrintProcessorException("Message adaptor($type) is not supported") - } - } - } - - fun messageProducerProperties(jsonNode: JsonNode): MessageProducerProperties { - val type = jsonNode.get("type").textValue() - return when (type) { - MessageLibConstants.TYPE_KAFKA_BASIC_AUTH -> { - JacksonUtils.readValue(jsonNode, KafkaBasicAuthMessageProducerProperties::class.java)!! - } - MessageLibConstants.TYPE_KAFKA_SSL_AUTH -> { - JacksonUtils.readValue(jsonNode, KafkaSslAuthMessageProducerProperties::class.java)!! - } - MessageLibConstants.TYPE_KAFKA_SCRAM_SSL_AUTH -> { - JacksonUtils.readValue(jsonNode, KafkaScramSslAuthMessageProducerProperties::class.java)!! - } - else -> { - throw BluePrintProcessorException("Message adaptor($type) is not supported") - } - } - } - - /** Consumer Property Lib Service Implementation **/ - - /** Return Message Consumer Service for [jsonNode] definitions. */ - fun blueprintMessageConsumerService(jsonNode: JsonNode): BlueprintMessageConsumerService { - val messageConsumerProperties = messageConsumerProperties(jsonNode) - return blueprintMessageConsumerService(messageConsumerProperties) - } - - /** Return Message Consumer Service for [selector] definitions. */ - fun blueprintMessageConsumerService(selector: String): BlueprintMessageConsumerService { - val prefix = "${MessageLibConstants.PROPERTY_MESSAGE_CONSUMER_PREFIX}$selector" - val messageClientProperties = messageConsumerProperties(prefix) - return blueprintMessageConsumerService(messageClientProperties) - } - - /** Return Message Consumer Properties for [prefix] definitions. */ - fun messageConsumerProperties(prefix: String): MessageConsumerProperties { - val type = bluePrintPropertiesService.propertyBeanType("$prefix.type", String::class.java) - return when (type) { - /** Message Consumer */ - MessageLibConstants.TYPE_KAFKA_BASIC_AUTH -> { - bluePrintPropertiesService.propertyBeanType( - prefix, KafkaBasicAuthMessageConsumerProperties::class.java - ) - } - MessageLibConstants.TYPE_KAFKA_SSL_AUTH -> { - bluePrintPropertiesService.propertyBeanType( - prefix, KafkaSslAuthMessageConsumerProperties::class.java - ) - } - MessageLibConstants.TYPE_KAFKA_SCRAM_SSL_AUTH -> { - bluePrintPropertiesService.propertyBeanType( - prefix, KafkaScramSslAuthMessageConsumerProperties::class.java - ) - } - /** Stream Consumer */ - MessageLibConstants.TYPE_KAFKA_STREAMS_BASIC_AUTH -> { - bluePrintPropertiesService.propertyBeanType( - prefix, KafkaStreamsBasicAuthConsumerProperties::class.java - ) - } - MessageLibConstants.TYPE_KAFKA_STREAMS_SSL_AUTH -> { - bluePrintPropertiesService.propertyBeanType( - prefix, KafkaStreamsSslAuthConsumerProperties::class.java - ) - } - MessageLibConstants.TYPE_KAFKA_STREAMS_SCRAM_SSL_AUTH -> { - bluePrintPropertiesService.propertyBeanType( - prefix, KafkaStreamsScramSslAuthConsumerProperties::class.java - ) - } - else -> { - throw BluePrintProcessorException("Message adaptor($type) is not supported") - } - } - } - - fun messageConsumerProperties(jsonNode: JsonNode): MessageConsumerProperties { - val type = jsonNode.get("type").textValue() - return when (type) { - /** Message Consumer */ - MessageLibConstants.TYPE_KAFKA_BASIC_AUTH -> { - JacksonUtils.readValue(jsonNode, KafkaBasicAuthMessageConsumerProperties::class.java)!! - } - MessageLibConstants.TYPE_KAFKA_SSL_AUTH -> { - JacksonUtils.readValue(jsonNode, KafkaSslAuthMessageConsumerProperties::class.java)!! - } - MessageLibConstants.TYPE_KAFKA_SCRAM_SSL_AUTH -> { - JacksonUtils.readValue(jsonNode, KafkaScramSslAuthMessageConsumerProperties::class.java)!! - } - /** Stream Consumer */ - MessageLibConstants.TYPE_KAFKA_STREAMS_BASIC_AUTH -> { - JacksonUtils.readValue(jsonNode, KafkaStreamsBasicAuthConsumerProperties::class.java)!! - } - MessageLibConstants.TYPE_KAFKA_STREAMS_SSL_AUTH -> { - JacksonUtils.readValue(jsonNode, KafkaStreamsSslAuthConsumerProperties::class.java)!! - } - MessageLibConstants.TYPE_KAFKA_STREAMS_SCRAM_SSL_AUTH -> { - JacksonUtils.readValue(jsonNode, KafkaStreamsScramSslAuthConsumerProperties::class.java)!! - } - else -> { - throw BluePrintProcessorException("Message adaptor($type) is not supported") - } - } - } - - private fun blueprintMessageConsumerService(messageConsumerProperties: MessageConsumerProperties): - BlueprintMessageConsumerService { - - when (messageConsumerProperties.type) { - /** Message Consumer */ - MessageLibConstants.TYPE_KAFKA_BASIC_AUTH -> { - return KafkaMessageConsumerService( - messageConsumerProperties as KafkaBasicAuthMessageConsumerProperties - ) - } - MessageLibConstants.TYPE_KAFKA_SSL_AUTH -> { - return KafkaMessageConsumerService( - messageConsumerProperties as KafkaSslAuthMessageConsumerProperties - ) - } - MessageLibConstants.TYPE_KAFKA_SCRAM_SSL_AUTH -> { - return KafkaMessageConsumerService( - messageConsumerProperties as KafkaScramSslAuthMessageConsumerProperties - ) - } - /** Stream Consumer */ - MessageLibConstants.TYPE_KAFKA_STREAMS_BASIC_AUTH -> { - return KafkaStreamsConsumerService( - messageConsumerProperties as KafkaStreamsBasicAuthConsumerProperties - ) - } - MessageLibConstants.TYPE_KAFKA_STREAMS_SSL_AUTH -> { - return KafkaStreamsConsumerService( - messageConsumerProperties as KafkaStreamsSslAuthConsumerProperties - ) - } - MessageLibConstants.TYPE_KAFKA_STREAMS_SCRAM_SSL_AUTH -> { - return KafkaStreamsConsumerService( - messageConsumerProperties as KafkaStreamsScramSslAuthConsumerProperties - ) - } - else -> { - throw BluePrintProcessorException("couldn't get message client service for ${messageConsumerProperties.type}") - } - } - } -} diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageConsumerService.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageConsumerService.kt index b39d89bfd..887a7a7b8 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageConsumerService.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageConsumerService.kt @@ -23,7 +23,7 @@ import org.apache.kafka.clients.consumer.ConsumerRecord import org.apache.kafka.clients.consumer.ConsumerRecords import org.apache.kafka.streams.Topology import org.onap.ccsdk.cds.blueprintsprocessor.message.MessageConsumerProperties -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException /** Consumer Function Interfaces */ interface ConsumerFunction @@ -47,7 +47,7 @@ interface BlueprintMessageConsumerService { /** Consume with [additionalConfig], so that we can execute dynamic function [consumerFunction] */ suspend fun consume(additionalConfig: Map?, consumerFunction: ConsumerFunction) { - throw BluePrintProcessorException("Not Implemented") + throw BlueprintProcessorException("Not Implemented") } /** Consume the [topics] with [additionalConfig], so that we can execute dynamic function [consumerFunction] */ @@ -56,7 +56,7 @@ interface BlueprintMessageConsumerService { additionalConfig: Map?, consumerFunction: ConsumerFunction ) { - throw BluePrintProcessorException("Not Implemented") + throw BlueprintProcessorException("Not Implemented") } /** close the channel, consumer and other resources */ diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageLibPropertyService.kt new file mode 100644 index 000000000..9e0c537cf --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageLibPropertyService.kt @@ -0,0 +1,221 @@ +/* + * Copyright © 2019 IBM. + * Modifications Copyright © 2018-2019 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.message.service + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.message.KafkaBasicAuthMessageConsumerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.message.KafkaBasicAuthMessageProducerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.message.KafkaScramSslAuthMessageConsumerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.message.KafkaScramSslAuthMessageProducerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.message.KafkaSslAuthMessageConsumerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.message.KafkaSslAuthMessageProducerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.message.KafkaStreamsBasicAuthConsumerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.message.KafkaStreamsScramSslAuthConsumerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.message.KafkaStreamsSslAuthConsumerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.message.MessageConsumerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.message.MessageLibConstants +import org.onap.ccsdk.cds.blueprintsprocessor.message.MessageProducerProperties +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.stereotype.Service + +@Service(MessageLibConstants.SERVICE_BLUEPRINT_MESSAGE_LIB_PROPERTY) +open class BlueprintMessageLibPropertyService(private var bluePrintPropertiesService: BlueprintPropertiesService) { + + fun blueprintMessageProducerService(jsonNode: JsonNode): BlueprintMessageProducerService { + val messageClientProperties = messageProducerProperties(jsonNode) + return KafkaMessageProducerService(messageClientProperties) + } + + fun blueprintMessageProducerService(selector: String): BlueprintMessageProducerService { + val prefix = "${MessageLibConstants.PROPERTY_MESSAGE_PRODUCER_PREFIX}$selector" + val messageClientProperties = messageProducerProperties(prefix) + return KafkaMessageProducerService(messageClientProperties) + } + + fun messageProducerProperties(prefix: String): MessageProducerProperties { + val type = bluePrintPropertiesService.propertyBeanType("$prefix.type", String::class.java) + return when (type) { + MessageLibConstants.TYPE_KAFKA_BASIC_AUTH -> { + bluePrintPropertiesService.propertyBeanType( + prefix, KafkaBasicAuthMessageProducerProperties::class.java + ) + } + MessageLibConstants.TYPE_KAFKA_SSL_AUTH -> { + bluePrintPropertiesService.propertyBeanType( + prefix, KafkaSslAuthMessageProducerProperties::class.java + ) + } + MessageLibConstants.TYPE_KAFKA_SCRAM_SSL_AUTH -> { + bluePrintPropertiesService.propertyBeanType( + prefix, KafkaScramSslAuthMessageProducerProperties::class.java + ) + } + else -> { + throw BlueprintProcessorException("Message adaptor($type) is not supported") + } + } + } + + fun messageProducerProperties(jsonNode: JsonNode): MessageProducerProperties { + val type = jsonNode.get("type").textValue() + return when (type) { + MessageLibConstants.TYPE_KAFKA_BASIC_AUTH -> { + JacksonUtils.readValue(jsonNode, KafkaBasicAuthMessageProducerProperties::class.java)!! + } + MessageLibConstants.TYPE_KAFKA_SSL_AUTH -> { + JacksonUtils.readValue(jsonNode, KafkaSslAuthMessageProducerProperties::class.java)!! + } + MessageLibConstants.TYPE_KAFKA_SCRAM_SSL_AUTH -> { + JacksonUtils.readValue(jsonNode, KafkaScramSslAuthMessageProducerProperties::class.java)!! + } + else -> { + throw BlueprintProcessorException("Message adaptor($type) is not supported") + } + } + } + + /** Consumer Property Lib Service Implementation **/ + + /** Return Message Consumer Service for [jsonNode] definitions. */ + fun blueprintMessageConsumerService(jsonNode: JsonNode): BlueprintMessageConsumerService { + val messageConsumerProperties = messageConsumerProperties(jsonNode) + return blueprintMessageConsumerService(messageConsumerProperties) + } + + /** Return Message Consumer Service for [selector] definitions. */ + fun blueprintMessageConsumerService(selector: String): BlueprintMessageConsumerService { + val prefix = "${MessageLibConstants.PROPERTY_MESSAGE_CONSUMER_PREFIX}$selector" + val messageClientProperties = messageConsumerProperties(prefix) + return blueprintMessageConsumerService(messageClientProperties) + } + + /** Return Message Consumer Properties for [prefix] definitions. */ + fun messageConsumerProperties(prefix: String): MessageConsumerProperties { + val type = bluePrintPropertiesService.propertyBeanType("$prefix.type", String::class.java) + return when (type) { + /** Message Consumer */ + MessageLibConstants.TYPE_KAFKA_BASIC_AUTH -> { + bluePrintPropertiesService.propertyBeanType( + prefix, KafkaBasicAuthMessageConsumerProperties::class.java + ) + } + MessageLibConstants.TYPE_KAFKA_SSL_AUTH -> { + bluePrintPropertiesService.propertyBeanType( + prefix, KafkaSslAuthMessageConsumerProperties::class.java + ) + } + MessageLibConstants.TYPE_KAFKA_SCRAM_SSL_AUTH -> { + bluePrintPropertiesService.propertyBeanType( + prefix, KafkaScramSslAuthMessageConsumerProperties::class.java + ) + } + /** Stream Consumer */ + MessageLibConstants.TYPE_KAFKA_STREAMS_BASIC_AUTH -> { + bluePrintPropertiesService.propertyBeanType( + prefix, KafkaStreamsBasicAuthConsumerProperties::class.java + ) + } + MessageLibConstants.TYPE_KAFKA_STREAMS_SSL_AUTH -> { + bluePrintPropertiesService.propertyBeanType( + prefix, KafkaStreamsSslAuthConsumerProperties::class.java + ) + } + MessageLibConstants.TYPE_KAFKA_STREAMS_SCRAM_SSL_AUTH -> { + bluePrintPropertiesService.propertyBeanType( + prefix, KafkaStreamsScramSslAuthConsumerProperties::class.java + ) + } + else -> { + throw BlueprintProcessorException("Message adaptor($type) is not supported") + } + } + } + + fun messageConsumerProperties(jsonNode: JsonNode): MessageConsumerProperties { + val type = jsonNode.get("type").textValue() + return when (type) { + /** Message Consumer */ + MessageLibConstants.TYPE_KAFKA_BASIC_AUTH -> { + JacksonUtils.readValue(jsonNode, KafkaBasicAuthMessageConsumerProperties::class.java)!! + } + MessageLibConstants.TYPE_KAFKA_SSL_AUTH -> { + JacksonUtils.readValue(jsonNode, KafkaSslAuthMessageConsumerProperties::class.java)!! + } + MessageLibConstants.TYPE_KAFKA_SCRAM_SSL_AUTH -> { + JacksonUtils.readValue(jsonNode, KafkaScramSslAuthMessageConsumerProperties::class.java)!! + } + /** Stream Consumer */ + MessageLibConstants.TYPE_KAFKA_STREAMS_BASIC_AUTH -> { + JacksonUtils.readValue(jsonNode, KafkaStreamsBasicAuthConsumerProperties::class.java)!! + } + MessageLibConstants.TYPE_KAFKA_STREAMS_SSL_AUTH -> { + JacksonUtils.readValue(jsonNode, KafkaStreamsSslAuthConsumerProperties::class.java)!! + } + MessageLibConstants.TYPE_KAFKA_STREAMS_SCRAM_SSL_AUTH -> { + JacksonUtils.readValue(jsonNode, KafkaStreamsScramSslAuthConsumerProperties::class.java)!! + } + else -> { + throw BlueprintProcessorException("Message adaptor($type) is not supported") + } + } + } + + private fun blueprintMessageConsumerService(messageConsumerProperties: MessageConsumerProperties): + BlueprintMessageConsumerService { + + when (messageConsumerProperties.type) { + /** Message Consumer */ + MessageLibConstants.TYPE_KAFKA_BASIC_AUTH -> { + return KafkaMessageConsumerService( + messageConsumerProperties as KafkaBasicAuthMessageConsumerProperties + ) + } + MessageLibConstants.TYPE_KAFKA_SSL_AUTH -> { + return KafkaMessageConsumerService( + messageConsumerProperties as KafkaSslAuthMessageConsumerProperties + ) + } + MessageLibConstants.TYPE_KAFKA_SCRAM_SSL_AUTH -> { + return KafkaMessageConsumerService( + messageConsumerProperties as KafkaScramSslAuthMessageConsumerProperties + ) + } + /** Stream Consumer */ + MessageLibConstants.TYPE_KAFKA_STREAMS_BASIC_AUTH -> { + return KafkaStreamsConsumerService( + messageConsumerProperties as KafkaStreamsBasicAuthConsumerProperties + ) + } + MessageLibConstants.TYPE_KAFKA_STREAMS_SSL_AUTH -> { + return KafkaStreamsConsumerService( + messageConsumerProperties as KafkaStreamsSslAuthConsumerProperties + ) + } + MessageLibConstants.TYPE_KAFKA_STREAMS_SCRAM_SSL_AUTH -> { + return KafkaStreamsConsumerService( + messageConsumerProperties as KafkaStreamsScramSslAuthConsumerProperties + ) + } + else -> { + throw BlueprintProcessorException("couldn't get message client service for ${messageConsumerProperties.type}") + } + } + } +} diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/KafkaStreamsConsumerService.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/KafkaStreamsConsumerService.kt index 4340e4815..beaa995df 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/KafkaStreamsConsumerService.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/KafkaStreamsConsumerService.kt @@ -20,7 +20,7 @@ import kotlinx.coroutines.channels.Channel import org.apache.kafka.clients.consumer.ConsumerRecord import org.apache.kafka.streams.KafkaStreams import org.onap.ccsdk.cds.blueprintsprocessor.message.MessageConsumerProperties -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.logger import java.util.Properties @@ -41,11 +41,11 @@ open class KafkaStreamsConsumerService(private val messageConsumerProperties: Me } override suspend fun subscribe(additionalConfig: Map?): Channel> { - throw BluePrintProcessorException("not implemented") + throw BlueprintProcessorException("not implemented") } override suspend fun subscribe(topics: List, additionalConfig: Map?): Channel> { - throw BluePrintProcessorException("not implemented") + throw BlueprintProcessorException("not implemented") } override suspend fun consume(additionalConfig: Map?, consumerFunction: ConsumerFunction) { diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MessageLoggerService.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MessageLoggerService.kt index 90b850017..7e5f35d15 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MessageLoggerService.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MessageLoggerService.kt @@ -21,7 +21,7 @@ import org.apache.kafka.common.header.Headers import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader import org.onap.ccsdk.cds.blueprintsprocessor.message.addHeader import org.onap.ccsdk.cds.blueprintsprocessor.message.toMap -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants import org.onap.ccsdk.cds.controllerblueprints.core.defaultToEmpty import org.onap.ccsdk.cds.controllerblueprints.core.defaultToUUID import org.onap.ccsdk.cds.controllerblueprints.core.logger @@ -46,9 +46,9 @@ class MessageLoggerService { fun messageConsuming(consumerRecord: ConsumerRecord<*, *>) { val headers = consumerRecord.headers().toMap() - val requestID = headers[BluePrintConstants.ONAP_REQUEST_ID].defaultToUUID() - val invocationID = headers[BluePrintConstants.ONAP_INVOCATION_ID].defaultToUUID() - val partnerName = headers[BluePrintConstants.ONAP_PARTNER_NAME] ?: "UNKNOWN" + val requestID = headers[BlueprintConstants.ONAP_REQUEST_ID].defaultToUUID() + val invocationID = headers[BlueprintConstants.ONAP_INVOCATION_ID].defaultToUUID() + val partnerName = headers[BlueprintConstants.ONAP_PARTNER_NAME] ?: "UNKNOWN" messageConsuming(requestID, invocationID, partnerName, consumerRecord) } @@ -83,9 +83,9 @@ class MessageLoggerService { */ fun messageProducing(requestHeader: Headers) { val localhost = InetAddress.getLocalHost() - requestHeader.addHeader(BluePrintConstants.ONAP_REQUEST_ID, MDC.get("InvocationID").defaultToUUID()) - requestHeader.addHeader(BluePrintConstants.ONAP_INVOCATION_ID, UUID.randomUUID().toString()) - requestHeader.addHeader(BluePrintConstants.ONAP_PARTNER_NAME, BluePrintConstants.APP_NAME) + requestHeader.addHeader(BlueprintConstants.ONAP_REQUEST_ID, MDC.get("InvocationID").defaultToUUID()) + requestHeader.addHeader(BlueprintConstants.ONAP_INVOCATION_ID, UUID.randomUUID().toString()) + requestHeader.addHeader(BlueprintConstants.ONAP_PARTNER_NAME, BlueprintConstants.APP_NAME) requestHeader.addHeader("ClientIPAddress", localhost.hostAddress) } diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSLTest.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSLTest.kt index b68678baf..8130016a8 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSLTest.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSLTest.kt @@ -18,7 +18,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.message import org.apache.kafka.streams.StreamsConfig import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate import kotlin.test.assertEquals @@ -67,12 +67,12 @@ class MessagePropertiesDSLTest { assertNotNull(relationshipTypes, "failed to get relationship types") assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" ) assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER}" ) } @@ -138,12 +138,12 @@ class MessagePropertiesDSLTest { assertNotNull(relationshipTypes, "failed to get relationship types") assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" ) assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER}" ) } } diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageConsumerServiceTest.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageConsumerServiceTest.kt index a69f9f51a..f240f76c0 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageConsumerServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageConsumerServiceTest.kt @@ -40,9 +40,9 @@ import org.apache.kafka.common.serialization.ByteArrayDeserializer import org.apache.kafka.common.serialization.StringDeserializer import org.junit.Test import org.junit.runner.RunWith -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.message.BluePrintMessageLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.message.BlueprintMessageLibConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.message.MessageConsumerProperties import org.onap.ccsdk.cds.blueprintsprocessor.message.MessageLibConstants import org.onap.ccsdk.cds.controllerblueprints.core.logger @@ -60,8 +60,8 @@ import kotlin.test.assertTrue @DirtiesContext @ContextConfiguration( classes = [ - BluePrintMessageLibConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class + BlueprintMessageLibConfiguration::class, + BlueprintPropertyConfiguration::class, BlueprintPropertiesService::class ] ) @TestPropertySource( @@ -98,7 +98,7 @@ open class BlueprintMessageConsumerServiceTest { val log = logger(BlueprintMessageConsumerServiceTest::class) @Autowired - lateinit var bluePrintMessageLibPropertyService: BluePrintMessageLibPropertyService + lateinit var bluePrintMessageLibPropertyService: BlueprintMessageLibPropertyService @Test fun testKafkaBasicAuthConsumerService() { diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageProducerServiceTest.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageProducerServiceTest.kt index f88caa173..2293ceec3 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageProducerServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/BlueprintMessageProducerServiceTest.kt @@ -32,9 +32,9 @@ import org.apache.kafka.common.security.scram.ScramLoginModule import org.apache.kafka.common.serialization.ByteArraySerializer import org.apache.kafka.common.serialization.StringSerializer import org.junit.runner.RunWith -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.message.BluePrintMessageLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.message.BlueprintMessageLibConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.message.MessageLibConstants import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.annotation.DirtiesContext @@ -50,8 +50,8 @@ import kotlin.test.assertTrue @DirtiesContext @ContextConfiguration( classes = [ - BluePrintMessageLibConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class + BlueprintMessageLibConfiguration::class, + BlueprintPropertyConfiguration::class, BlueprintPropertiesService::class ] ) @TestPropertySource( @@ -72,7 +72,7 @@ import kotlin.test.assertTrue open class BlueprintMessageProducerServiceTest { @Autowired - lateinit var bluePrintMessageLibPropertyService: BluePrintMessageLibPropertyService + lateinit var bluePrintMessageLibPropertyService: BlueprintMessageLibPropertyService @Test fun testKafkaScramSslAuthProducerService() { @@ -87,11 +87,11 @@ open class BlueprintMessageProducerServiceTest { every { mockKafkaTemplate.send(any(), any()) } returns responseMock - val spyBluePrintMessageProducerService = spyk(blueprintMessageProducerService, recordPrivateCalls = true) + val spyBlueprintMessageProducerService = spyk(blueprintMessageProducerService, recordPrivateCalls = true) - every { spyBluePrintMessageProducerService.messageTemplate(any()) } returns mockKafkaTemplate + every { spyBlueprintMessageProducerService.messageTemplate(any()) } returns mockKafkaTemplate - val response = spyBluePrintMessageProducerService.sendMessage("mykey", "Testing message") + val response = spyBlueprintMessageProducerService.sendMessage("mykey", "Testing message") assertTrue(response, "failed to get command response") } } diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/KafkaStreamsConsumerServiceTest.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/KafkaStreamsConsumerServiceTest.kt index f488a4c74..70968ef0c 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/KafkaStreamsConsumerServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/KafkaStreamsConsumerServiceTest.kt @@ -26,9 +26,9 @@ import org.apache.kafka.streams.processor.ProcessorSupplier import org.apache.kafka.streams.state.Stores import org.junit.Test import org.junit.runner.RunWith -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.message.BluePrintMessageLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.message.BlueprintMessageLibConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.message.KafkaStreamsBasicAuthConsumerProperties import org.onap.ccsdk.cds.blueprintsprocessor.message.MessageConsumerProperties import org.springframework.beans.factory.annotation.Autowired @@ -42,8 +42,8 @@ import kotlin.test.assertNotNull @DirtiesContext @ContextConfiguration( classes = [ - BluePrintMessageLibConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class + BlueprintMessageLibConfiguration::class, + BlueprintPropertyConfiguration::class, BlueprintPropertiesService::class ] ) @TestPropertySource( @@ -72,7 +72,7 @@ import kotlin.test.assertNotNull class KafkaStreamsConsumerServiceTest { @Autowired - lateinit var bluePrintMessageLibPropertyService: BluePrintMessageLibPropertyService + lateinit var bluePrintMessageLibPropertyService: BlueprintMessageLibPropertyService @Test fun testProperties() { diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MessageLoggerServiceTest.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MessageLoggerServiceTest.kt index 3dce3344f..dc36ac675 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MessageLoggerServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MessageLoggerServiceTest.kt @@ -23,7 +23,7 @@ import org.apache.kafka.common.header.internals.RecordHeaders import org.junit.Test import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader import org.onap.ccsdk.cds.blueprintsprocessor.message.toMap -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants import org.slf4j.MDC import kotlin.test.assertEquals @@ -51,7 +51,7 @@ class MessageLoggerServiceTest { val mockHeaders = RecordHeaders() messageLoggerService.messageProducing(mockHeaders) val map = mockHeaders.toMap() - assertEquals("1234-12", map[BluePrintConstants.ONAP_REQUEST_ID]) + assertEquals("1234-12", map[BlueprintConstants.ONAP_REQUEST_ID]) messageLoggerService.messageConsumingExisting() } diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MockKafkaTopologyComponents.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MockKafkaTopologyComponents.kt index aa38b6e5c..97a81f1cd 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MockKafkaTopologyComponents.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MockKafkaTopologyComponents.kt @@ -22,7 +22,7 @@ import org.apache.kafka.common.serialization.Serializer import org.apache.kafka.streams.processor.Processor import org.apache.kafka.streams.processor.ProcessorContext import org.apache.kafka.streams.state.KeyValueStore -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString import org.onap.ccsdk.cds.controllerblueprints.core.logger import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils @@ -48,7 +48,7 @@ open class PriorityMessageSerde : Serde { return object : Deserializer { override fun deserialize(topic: String, data: ByteArray): PriorityMessage { return JacksonUtils.readValue(String(data), PriorityMessage::class.java) - ?: throw BluePrintProcessorException("failed to convert") + ?: throw BlueprintProcessorException("failed to convert") } override fun configure(configs: MutableMap?, isKey: Boolean) { diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BluePrintNatsExtensions.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BluePrintNatsExtensions.kt deleted file mode 100644 index a585c972b..000000000 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BluePrintNatsExtensions.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright © 2018-2019 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.nats - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType - -fun io.nats.client.Message.strData(): String { - return String(this.data) -} - -fun io.nats.streaming.Message.strData(): String { - return String(this.data) -} - -fun io.nats.client.Message.asJsonType(): JsonNode { - return this.data.asJsonType() -} - -fun io.nats.streaming.Message.asJsonType(): JsonNode { - return this.data.asJsonType() -} diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BluePrintNatsLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BluePrintNatsLibConfiguration.kt deleted file mode 100644 index a47dd8918..000000000 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BluePrintNatsLibConfiguration.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright © 2018-2019 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.nats - -import org.onap.ccsdk.cds.blueprintsprocessor.nats.service.BluePrintNatsLibPropertyService -import org.onap.ccsdk.cds.blueprintsprocessor.nats.service.BluePrintNatsService -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration - -@Configuration -@ComponentScan -open class BluePrintNatsLibConfiguration - -/** - * Exposed Dependency Service by this NATS Lib Module - */ -fun BluePrintDependencyService.natsLibPropertyService(): BluePrintNatsLibPropertyService = - instance(NatsLibConstants.SERVICE_BLUEPRINT_NATS_LIB_PROPERTY) - -fun BluePrintDependencyService.controllerNatsService(): BluePrintNatsService { - return natsLibPropertyService().bluePrintNatsService(NatsLibConstants.DEFULT_NATS_SELECTOR) -} - -class NatsLibConstants { - companion object { - - const val SERVICE_BLUEPRINT_NATS_LIB_PROPERTY = "blueprint-nats-lib-property-service" - const val DEFULT_NATS_SELECTOR = "cds-controller" - const val PROPERTY_NATS_PREFIX = "blueprintsprocessor.nats." - const val PROPERTY_NATS_CLUSTER_ID = "NATS_CLUSTER_ID" - const val TYPE_TOKEN_AUTH = "token-auth" - const val TYPE_TLS_AUTH = "tls-auth" - } -} diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BluePrintNatsLibData.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BluePrintNatsLibData.kt deleted file mode 100644 index a989dcf1e..000000000 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BluePrintNatsLibData.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright © 2018-2019 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.nats - -import org.onap.ccsdk.cds.blueprintsprocessor.nats.utils.NatsClusterUtils -import org.onap.ccsdk.cds.controllerblueprints.core.utils.ClusterUtils - -open class NatsConnectionProperties { - - lateinit var type: String - var clusterId: String = NatsClusterUtils.clusterId() - var clientId: String = ClusterUtils.clusterNodeId() - lateinit var host: String - - /** Rest endpoint selector to access Monitoring API */ - var monitoringSelector: String? = null -} - -open class TokenAuthNatsConnectionProperties : NatsConnectionProperties() { - - lateinit var token: String -} - -open class TLSAuthNatsConnectionProperties : NatsConnectionProperties() { - - var trustCertCollection: String? = null - - /** Below Used only for Mutual TLS */ - var clientCertChain: String? = null - var clientPrivateKey: String? = null -} diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BlueprintNatsExtensions.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BlueprintNatsExtensions.kt new file mode 100644 index 000000000..a585c972b --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BlueprintNatsExtensions.kt @@ -0,0 +1,36 @@ +/* + * Copyright © 2018-2019 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.nats + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType + +fun io.nats.client.Message.strData(): String { + return String(this.data) +} + +fun io.nats.streaming.Message.strData(): String { + return String(this.data) +} + +fun io.nats.client.Message.asJsonType(): JsonNode { + return this.data.asJsonType() +} + +fun io.nats.streaming.Message.asJsonType(): JsonNode { + return this.data.asJsonType() +} diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BlueprintNatsLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BlueprintNatsLibConfiguration.kt new file mode 100644 index 000000000..c83906c3f --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BlueprintNatsLibConfiguration.kt @@ -0,0 +1,49 @@ +/* + * Copyright © 2018-2019 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.nats + +import org.onap.ccsdk.cds.blueprintsprocessor.nats.service.BlueprintNatsLibPropertyService +import org.onap.ccsdk.cds.blueprintsprocessor.nats.service.BlueprintNatsService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintDependencyService +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +@Configuration +@ComponentScan +open class BlueprintNatsLibConfiguration + +/** + * Exposed Dependency Service by this NATS Lib Module + */ +fun BlueprintDependencyService.natsLibPropertyService(): BlueprintNatsLibPropertyService = + instance(NatsLibConstants.SERVICE_BLUEPRINT_NATS_LIB_PROPERTY) + +fun BlueprintDependencyService.controllerNatsService(): BlueprintNatsService { + return natsLibPropertyService().bluePrintNatsService(NatsLibConstants.DEFULT_NATS_SELECTOR) +} + +class NatsLibConstants { + companion object { + + const val SERVICE_BLUEPRINT_NATS_LIB_PROPERTY = "blueprint-nats-lib-property-service" + const val DEFULT_NATS_SELECTOR = "cds-controller" + const val PROPERTY_NATS_PREFIX = "blueprintsprocessor.nats." + const val PROPERTY_NATS_CLUSTER_ID = "NATS_CLUSTER_ID" + const val TYPE_TOKEN_AUTH = "token-auth" + const val TYPE_TLS_AUTH = "tls-auth" + } +} diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BlueprintNatsLibData.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BlueprintNatsLibData.kt new file mode 100644 index 000000000..a989dcf1e --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/BlueprintNatsLibData.kt @@ -0,0 +1,45 @@ +/* + * Copyright © 2018-2019 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.nats + +import org.onap.ccsdk.cds.blueprintsprocessor.nats.utils.NatsClusterUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.ClusterUtils + +open class NatsConnectionProperties { + + lateinit var type: String + var clusterId: String = NatsClusterUtils.clusterId() + var clientId: String = ClusterUtils.clusterNodeId() + lateinit var host: String + + /** Rest endpoint selector to access Monitoring API */ + var monitoringSelector: String? = null +} + +open class TokenAuthNatsConnectionProperties : NatsConnectionProperties() { + + lateinit var token: String +} + +open class TLSAuthNatsConnectionProperties : NatsConnectionProperties() { + + var trustCertCollection: String? = null + + /** Below Used only for Mutual TLS */ + var clientCertChain: String? = null + var clientPrivateKey: String? = null +} diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSL.kt index 4c5471796..9e771a6e5 100644 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSL.kt @@ -17,8 +17,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.nats import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintTypes import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType @@ -30,25 +30,25 @@ import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType /** Relationships Types DSL for NATS Producer */ fun ServiceTemplateBuilder.relationshipTypeConnectsToNats() { - val relationshipType = BluePrintTypes.relationshipTypeConnectsToNats() + val relationshipType = BlueprintTypes.relationshipTypeConnectsToNats() if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() this.relationshipTypes!![relationshipType.id!!] = relationshipType } -fun BluePrintTypes.relationshipTypeConnectsToNats(): RelationshipType { +fun BlueprintTypes.relationshipTypeConnectsToNats(): RelationshipType { return relationshipType( - id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_NATS, - version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, + id = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_NATS, + version = BlueprintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, description = "Relationship connects to through NATS Client." ) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintConstants.DATA_TYPE_MAP, + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintConstants.DATA_TYPE_MAP, true, "Connection Config details." ) - validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) + validTargetTypes(arrayListOf(BlueprintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) } } @@ -66,25 +66,25 @@ fun TopologyTemplateBuilder.relationshipTemplateNats( class NatsRelationshipTemplateBuilder(name: String, description: String) : RelationshipTemplateBuilder( name, - BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_NATS, description + BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_NATS, description ) { fun tokenAuth(block: NatsTokenAuthPropertiesAssignmentBuilder.() -> Unit) { - property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tokenAuthNatsProperties(block)) + property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.tokenAuthNatsProperties(block)) } fun tlsAuth(block: NatsTLSAuthPropertiesAssignmentBuilder.() -> Unit) { - property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tlsAuthNatsProperties(block)) + property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.tlsAuthNatsProperties(block)) } } -fun BluePrintTypes.tokenAuthNatsProperties(block: NatsTokenAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.tokenAuthNatsProperties(block: NatsTokenAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = NatsTokenAuthPropertiesAssignmentBuilder().apply(block).build() assignments[NatsConnectionProperties::type.name] = NatsLibConstants.TYPE_TOKEN_AUTH.asJsonPrimitive() return assignments.asJsonNode() } -fun BluePrintTypes.tlsAuthNatsProperties(block: NatsTLSAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.tlsAuthNatsProperties(block: NatsTLSAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = NatsTLSAuthPropertiesAssignmentBuilder().apply(block).build() assignments[NatsConnectionProperties::type.name] = NatsLibConstants.TYPE_TLS_AUTH.asJsonPrimitive() return assignments.asJsonNode() diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsLibPropertyService.kt deleted file mode 100644 index 1ac44bc94..000000000 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsLibPropertyService.kt +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright © 2018-2019 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.nats.service - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.nats.NatsConnectionProperties -import org.onap.ccsdk.cds.blueprintsprocessor.nats.NatsLibConstants -import org.onap.ccsdk.cds.blueprintsprocessor.nats.TLSAuthNatsConnectionProperties -import org.onap.ccsdk.cds.blueprintsprocessor.nats.TokenAuthNatsConnectionProperties -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.springframework.stereotype.Service - -@Service(NatsLibConstants.SERVICE_BLUEPRINT_NATS_LIB_PROPERTY) -open class BluePrintNatsLibPropertyService(private var bluePrintPropertiesService: BluePrintPropertiesService) { - - fun bluePrintNatsService(jsonNode: JsonNode): BluePrintNatsService { - val natsConnectionProperties = natsConnectionProperties(jsonNode) - return bluePrintNatsService(natsConnectionProperties) - } - - fun bluePrintNatsService(selector: String): BluePrintNatsService { - val prefix = "${NatsLibConstants.PROPERTY_NATS_PREFIX}$selector" - val natsConnectionProperties = natsConnectionProperties(prefix) - return bluePrintNatsService(natsConnectionProperties) - } - - /** NATS Lib Property Service */ - fun natsConnectionProperties(jsonNode: JsonNode): NatsConnectionProperties { - return when (val type = jsonNode.get("type").textValue()) { - NatsLibConstants.TYPE_TOKEN_AUTH -> { - JacksonUtils.readValue(jsonNode, TokenAuthNatsConnectionProperties::class.java)!! - } - NatsLibConstants.TYPE_TLS_AUTH -> { - JacksonUtils.readValue(jsonNode, TLSAuthNatsConnectionProperties::class.java)!! - } - else -> { - throw BluePrintProcessorException("NATS type($type) not supported") - } - } - } - - fun natsConnectionProperties(prefix: String): NatsConnectionProperties { - val type = bluePrintPropertiesService.propertyBeanType("$prefix.type", String::class.java) - return when (type) { - NatsLibConstants.TYPE_TOKEN_AUTH -> { - tokenAuthNatsConnectionProperties(prefix) - } - NatsLibConstants.TYPE_TLS_AUTH -> { - tlsAuthNatsConnectionProperties(prefix) - } - else -> { - throw BluePrintProcessorException("NATS type($type) not supported") - } - } - } - - private fun tokenAuthNatsConnectionProperties(prefix: String): TokenAuthNatsConnectionProperties { - return bluePrintPropertiesService.propertyBeanType(prefix, TokenAuthNatsConnectionProperties::class.java) - } - - private fun tlsAuthNatsConnectionProperties(prefix: String): TLSAuthNatsConnectionProperties { - return bluePrintPropertiesService.propertyBeanType(prefix, TLSAuthNatsConnectionProperties::class.java) - } - - fun bluePrintNatsService(natsConnectionProperties: NatsConnectionProperties): - BluePrintNatsService { - return when (natsConnectionProperties) { - is TokenAuthNatsConnectionProperties -> { - TokenAuthNatsService(natsConnectionProperties) - } - is TLSAuthNatsConnectionProperties -> { - TLSAuthNatsService(natsConnectionProperties) - } - else -> { - throw BluePrintProcessorException("couldn't get NATS service for properties $natsConnectionProperties") - } - } - } -} diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsService.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsService.kt deleted file mode 100644 index 9548fe78d..000000000 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsService.kt +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright © 2018-2019 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. - */ - -@file:Suppress("BlockingMethodInNonBlockingContext") - -package org.onap.ccsdk.cds.blueprintsprocessor.nats.service - -import io.nats.client.Dispatcher -import io.nats.streaming.MessageHandler -import io.nats.streaming.StreamingConnection -import io.nats.streaming.Subscription -import io.nats.streaming.SubscriptionOptions -import java.time.Duration - -interface BluePrintNatsService { - - /** Create and Return the NATS streaming connection */ - suspend fun connection(): StreamingConnection - - /** Send one request [message] to the [subject] and get only one reply - * The request message subscriber may be multi instances consumer or load balance consumer. - * If it is multi instances consumer, then we will get only first responses from subscribers. - * - */ - suspend fun requestAndGetOneReply(subject: String, message: ByteArray, timeout: Long): io.nats.client.Message { - return connection().natsConnection.request(subject, message, Duration.ofMillis(timeout)) - } - - /** Send one request [message] to the [subject] and get multiple replies in [replySubject] with [messageHandler] - * The request message subscriber may be multi instances consumer or load balance consumer. - * If it is multi instances consumer, then we will get multiple responses from subscribers. - * Include the unSubscribe logic's in [messageHandler] implementation. - */ - suspend fun requestAndGetMultipleReplies( - subject: String, - replySubject: String, - message: ByteArray, - messageHandler: io.nats.client.MessageHandler - ) { - val natsConnection = connection().natsConnection - val dispatcher = natsConnection.createDispatcher(messageHandler) - /** Reply subject consumer */ - dispatcher.subscribe(replySubject) - - /** Publish the request message and expect the reply messages in reply subject consumer */ - natsConnection.publish(subject, replySubject, message) - } - - /** Synchronous reply Subscribe the [subject] with the [messageHandler]. - * This is used only the message has to be consumed by all instances in the cluster and message handler must reply. - */ - suspend fun replySubscribe( - subject: String, - messageHandler: io.nats.client.MessageHandler - ): Dispatcher { - val natsConnection = connection().natsConnection - val dispatcher = natsConnection.createDispatcher(messageHandler) - return dispatcher.subscribe(subject) - } - - /** - * Synchronous reply Subscriber will listen for [subject] with [loadBalanceGroup]. - * This is used only the message has to be consumed by only one instance in the cluster. - * server will now load balance messages between the members of the queue group and message handler must reply. - */ - suspend fun loadBalanceReplySubscribe( - subject: String, - loadBalanceGroup: String, - messageHandler: io.nats.client.MessageHandler - ): Dispatcher { - val natsConnection = connection().natsConnection - val dispatcher = natsConnection.createDispatcher(messageHandler) - return dispatcher.subscribe(subject, loadBalanceGroup) - } - - /** Publish the [message] to all subscribers on the [subject] */ - suspend fun publish(subject: String, message: ByteArray) { - connection().publish(subject, message) - } - - /** Subscribe the [subject] with the [messageHandler]. - * This is used only the message has to be consumed by all instances in the cluster. - */ - suspend fun subscribe( - subject: String, - messageHandler: MessageHandler - ): Subscription { - return connection().subscribe(subject, messageHandler) - } - - /** Subscribe the [subject] with the [messageHandler] and [subscriptionOptions]. - * This is used only the message has to be consumed by all instances in the cluster. - */ - suspend fun subscribe( - subject: String, - messageHandler: MessageHandler, - subscriptionOptions: SubscriptionOptions - ): Subscription { - return connection().subscribe(subject, messageHandler, subscriptionOptions) - } - - /** - * https://docs.nats.io/developing-with-nats/receiving/queues - * subscribers will listen for [subject] with [loadBalanceGroup]. - * This is used only the message has to be consumed by only one instance in the cluster. - * server will now load balance messages between the members of the queue group. - */ - suspend fun loadBalanceSubscribe( - subject: String, - loadBalanceGroup: String, - messageHandler: MessageHandler - ): Subscription { - return connection().subscribe(subject, loadBalanceGroup, messageHandler) - } - - /** - * https://docs.nats.io/developing-with-nats/receiving/queues - * subscribers will listen for [subject] with [loadBalanceGroup] and [subscriptionOptions]. - * This is used only the message has to be consumed by only one instance in the cluster. - * server will now load balance messages between the members of the queue group. - */ - suspend fun loadBalanceSubscribe( - subject: String, - loadBalanceGroup: String, - messageHandler: MessageHandler, - subscriptionOptions: SubscriptionOptions - ): Subscription { - return connection().subscribe(subject, loadBalanceGroup, messageHandler, subscriptionOptions) - } -} diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsLibPropertyService.kt new file mode 100644 index 000000000..457bf8703 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsLibPropertyService.kt @@ -0,0 +1,95 @@ +/* + * Copyright © 2018-2019 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.nats.service + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.nats.NatsConnectionProperties +import org.onap.ccsdk.cds.blueprintsprocessor.nats.NatsLibConstants +import org.onap.ccsdk.cds.blueprintsprocessor.nats.TLSAuthNatsConnectionProperties +import org.onap.ccsdk.cds.blueprintsprocessor.nats.TokenAuthNatsConnectionProperties +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.stereotype.Service + +@Service(NatsLibConstants.SERVICE_BLUEPRINT_NATS_LIB_PROPERTY) +open class BlueprintNatsLibPropertyService(private var bluePrintPropertiesService: BlueprintPropertiesService) { + + fun bluePrintNatsService(jsonNode: JsonNode): BlueprintNatsService { + val natsConnectionProperties = natsConnectionProperties(jsonNode) + return bluePrintNatsService(natsConnectionProperties) + } + + fun bluePrintNatsService(selector: String): BlueprintNatsService { + val prefix = "${NatsLibConstants.PROPERTY_NATS_PREFIX}$selector" + val natsConnectionProperties = natsConnectionProperties(prefix) + return bluePrintNatsService(natsConnectionProperties) + } + + /** NATS Lib Property Service */ + fun natsConnectionProperties(jsonNode: JsonNode): NatsConnectionProperties { + return when (val type = jsonNode.get("type").textValue()) { + NatsLibConstants.TYPE_TOKEN_AUTH -> { + JacksonUtils.readValue(jsonNode, TokenAuthNatsConnectionProperties::class.java)!! + } + NatsLibConstants.TYPE_TLS_AUTH -> { + JacksonUtils.readValue(jsonNode, TLSAuthNatsConnectionProperties::class.java)!! + } + else -> { + throw BlueprintProcessorException("NATS type($type) not supported") + } + } + } + + fun natsConnectionProperties(prefix: String): NatsConnectionProperties { + val type = bluePrintPropertiesService.propertyBeanType("$prefix.type", String::class.java) + return when (type) { + NatsLibConstants.TYPE_TOKEN_AUTH -> { + tokenAuthNatsConnectionProperties(prefix) + } + NatsLibConstants.TYPE_TLS_AUTH -> { + tlsAuthNatsConnectionProperties(prefix) + } + else -> { + throw BlueprintProcessorException("NATS type($type) not supported") + } + } + } + + private fun tokenAuthNatsConnectionProperties(prefix: String): TokenAuthNatsConnectionProperties { + return bluePrintPropertiesService.propertyBeanType(prefix, TokenAuthNatsConnectionProperties::class.java) + } + + private fun tlsAuthNatsConnectionProperties(prefix: String): TLSAuthNatsConnectionProperties { + return bluePrintPropertiesService.propertyBeanType(prefix, TLSAuthNatsConnectionProperties::class.java) + } + + fun bluePrintNatsService(natsConnectionProperties: NatsConnectionProperties): + BlueprintNatsService { + return when (natsConnectionProperties) { + is TokenAuthNatsConnectionProperties -> { + TokenAuthNatsService(natsConnectionProperties) + } + is TLSAuthNatsConnectionProperties -> { + TLSAuthNatsService(natsConnectionProperties) + } + else -> { + throw BlueprintProcessorException("couldn't get NATS service for properties $natsConnectionProperties") + } + } + } +} diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsService.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsService.kt new file mode 100644 index 000000000..67de95133 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsService.kt @@ -0,0 +1,143 @@ +/* + * Copyright © 2018-2019 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. + */ + +@file:Suppress("BlockingMethodInNonBlockingContext") + +package org.onap.ccsdk.cds.blueprintsprocessor.nats.service + +import io.nats.client.Dispatcher +import io.nats.streaming.MessageHandler +import io.nats.streaming.StreamingConnection +import io.nats.streaming.Subscription +import io.nats.streaming.SubscriptionOptions +import java.time.Duration + +interface BlueprintNatsService { + + /** Create and Return the NATS streaming connection */ + suspend fun connection(): StreamingConnection + + /** Send one request [message] to the [subject] and get only one reply + * The request message subscriber may be multi instances consumer or load balance consumer. + * If it is multi instances consumer, then we will get only first responses from subscribers. + * + */ + suspend fun requestAndGetOneReply(subject: String, message: ByteArray, timeout: Long): io.nats.client.Message { + return connection().natsConnection.request(subject, message, Duration.ofMillis(timeout)) + } + + /** Send one request [message] to the [subject] and get multiple replies in [replySubject] with [messageHandler] + * The request message subscriber may be multi instances consumer or load balance consumer. + * If it is multi instances consumer, then we will get multiple responses from subscribers. + * Include the unSubscribe logic's in [messageHandler] implementation. + */ + suspend fun requestAndGetMultipleReplies( + subject: String, + replySubject: String, + message: ByteArray, + messageHandler: io.nats.client.MessageHandler + ) { + val natsConnection = connection().natsConnection + val dispatcher = natsConnection.createDispatcher(messageHandler) + /** Reply subject consumer */ + dispatcher.subscribe(replySubject) + + /** Publish the request message and expect the reply messages in reply subject consumer */ + natsConnection.publish(subject, replySubject, message) + } + + /** Synchronous reply Subscribe the [subject] with the [messageHandler]. + * This is used only the message has to be consumed by all instances in the cluster and message handler must reply. + */ + suspend fun replySubscribe( + subject: String, + messageHandler: io.nats.client.MessageHandler + ): Dispatcher { + val natsConnection = connection().natsConnection + val dispatcher = natsConnection.createDispatcher(messageHandler) + return dispatcher.subscribe(subject) + } + + /** + * Synchronous reply Subscriber will listen for [subject] with [loadBalanceGroup]. + * This is used only the message has to be consumed by only one instance in the cluster. + * server will now load balance messages between the members of the queue group and message handler must reply. + */ + suspend fun loadBalanceReplySubscribe( + subject: String, + loadBalanceGroup: String, + messageHandler: io.nats.client.MessageHandler + ): Dispatcher { + val natsConnection = connection().natsConnection + val dispatcher = natsConnection.createDispatcher(messageHandler) + return dispatcher.subscribe(subject, loadBalanceGroup) + } + + /** Publish the [message] to all subscribers on the [subject] */ + suspend fun publish(subject: String, message: ByteArray) { + connection().publish(subject, message) + } + + /** Subscribe the [subject] with the [messageHandler]. + * This is used only the message has to be consumed by all instances in the cluster. + */ + suspend fun subscribe( + subject: String, + messageHandler: MessageHandler + ): Subscription { + return connection().subscribe(subject, messageHandler) + } + + /** Subscribe the [subject] with the [messageHandler] and [subscriptionOptions]. + * This is used only the message has to be consumed by all instances in the cluster. + */ + suspend fun subscribe( + subject: String, + messageHandler: MessageHandler, + subscriptionOptions: SubscriptionOptions + ): Subscription { + return connection().subscribe(subject, messageHandler, subscriptionOptions) + } + + /** + * https://docs.nats.io/developing-with-nats/receiving/queues + * subscribers will listen for [subject] with [loadBalanceGroup]. + * This is used only the message has to be consumed by only one instance in the cluster. + * server will now load balance messages between the members of the queue group. + */ + suspend fun loadBalanceSubscribe( + subject: String, + loadBalanceGroup: String, + messageHandler: MessageHandler + ): Subscription { + return connection().subscribe(subject, loadBalanceGroup, messageHandler) + } + + /** + * https://docs.nats.io/developing-with-nats/receiving/queues + * subscribers will listen for [subject] with [loadBalanceGroup] and [subscriptionOptions]. + * This is used only the message has to be consumed by only one instance in the cluster. + * server will now load balance messages between the members of the queue group. + */ + suspend fun loadBalanceSubscribe( + subject: String, + loadBalanceGroup: String, + messageHandler: MessageHandler, + subscriptionOptions: SubscriptionOptions + ): Subscription { + return connection().subscribe(subject, loadBalanceGroup, messageHandler, subscriptionOptions) + } +} diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/TLSAuthNatsService.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/TLSAuthNatsService.kt index 00a972eff..1bde8e534 100644 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/TLSAuthNatsService.kt +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/TLSAuthNatsService.kt @@ -25,7 +25,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.splitCommaAsList import javax.net.ssl.SSLContext open class TLSAuthNatsService(private val natsConnectionProperties: TLSAuthNatsConnectionProperties) : - BluePrintNatsService { + BlueprintNatsService { lateinit var streamingConnection: StreamingConnection diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/TokenAuthNatsService.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/TokenAuthNatsService.kt index 7c24b70d0..9d4aacfbd 100644 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/TokenAuthNatsService.kt +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/TokenAuthNatsService.kt @@ -25,7 +25,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.logger import org.onap.ccsdk.cds.controllerblueprints.core.splitCommaAsList open class TokenAuthNatsService(private val natsConnectionProperties: TokenAuthNatsConnectionProperties) : - BluePrintNatsService { + BlueprintNatsService { private val log = logger(TokenAuthNatsService::class) diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/utils/NatsClusterUtils.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/utils/NatsClusterUtils.kt index a7726a14b..a155a076d 100644 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/utils/NatsClusterUtils.kt +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/utils/NatsClusterUtils.kt @@ -17,7 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.nats.utils import org.onap.ccsdk.cds.blueprintsprocessor.nats.NatsLibConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants import org.onap.ccsdk.cds.controllerblueprints.core.utils.ClusterUtils object NatsClusterUtils { @@ -32,7 +32,7 @@ object NatsClusterUtils { } fun currentApplicationSubject(subject: String): String { - return "${BluePrintConstants.APP_NAME}.$subject" + return "${BlueprintConstants.APP_NAME}.$subject" } fun currentNodeDurable(subject: String): String { @@ -40,6 +40,6 @@ object NatsClusterUtils { } fun applicationLoadBalanceGroup(): String { - return "${BluePrintConstants.APP_NAME}" + return "${BlueprintConstants.APP_NAME}" } } diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSLTest.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSLTest.kt index a95b900fe..fa70f0738 100644 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSLTest.kt +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSLTest.kt @@ -17,7 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.nats import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants import org.onap.ccsdk.cds.controllerblueprints.core.dsl.getInput import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate @@ -59,12 +59,12 @@ class NatsPropertiesDSLTest { assertNotNull(relationshipTypes, "failed to get relationship types") assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" ) assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_NATS], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_NATS}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_NATS], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_NATS}" ) } } diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsExtensionsTest.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsExtensionsTest.kt deleted file mode 100644 index ec120dc18..000000000 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsExtensionsTest.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright © 2018-2019 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.nats.service - -import io.mockk.every -import io.mockk.mockk -import org.junit.Test -import org.onap.ccsdk.cds.blueprintsprocessor.nats.asJsonType -import org.onap.ccsdk.cds.blueprintsprocessor.nats.strData -import org.onap.ccsdk.cds.controllerblueprints.core.asByteArray -import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString -import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType -import java.nio.charset.Charset -import kotlin.test.assertEquals - -class BluePrintNatsExtensionsTest { - - @Test - fun testMessageStrConversion() { - val mockMessage = mockk() - every { mockMessage.data } returns "I am message".toByteArray(Charset.defaultCharset()) - - val messageData = mockMessage.strData() - assertEquals("I am message", messageData) - } - - @Test - fun testMessageJsonConversion() { - val json = """{"name":"value"}""" - - val mockMessage = mockk() - every { mockMessage.data } returns json.jsonAsJsonType().asByteArray() - - val messageData = mockMessage.asJsonType().asJsonString() - assertEquals(json, messageData) - } -} diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsLibPropertyServiceTest.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsLibPropertyServiceTest.kt deleted file mode 100644 index 9a332d589..000000000 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsLibPropertyServiceTest.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright © 2018-2019 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.nats.service - -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.nats.BluePrintNatsLibConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.nats.NatsLibConstants -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.assertTrue - -@RunWith(SpringRunner::class) -@ContextConfiguration( - classes = [ - BluePrintNatsLibConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class - ] -) -@TestPropertySource( - properties = - [ - "blueprintsprocessor.nats.cds-controller.type=token-auth", - "blueprintsprocessor.nats.cds-controller.host=nats://localhost:4222", - "blueprintsprocessor.nats.cds-controller.token=tokenAuth" - ] -) -class BluePrintNatsLibPropertyServiceTest { - - @Autowired - lateinit var bluePrintNatsLibPropertyService: BluePrintNatsLibPropertyService - - @Test - fun testNatsProperties() { - assertTrue(::bluePrintNatsLibPropertyService.isInitialized) - bluePrintNatsLibPropertyService.bluePrintNatsService(NatsLibConstants.DEFULT_NATS_SELECTOR) - } -} diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsServiceTest.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsServiceTest.kt deleted file mode 100644 index 721828ac9..000000000 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BluePrintNatsServiceTest.kt +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright © 2018-2019 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.nats.service - -import io.mockk.every -import io.mockk.mockk -import io.mockk.spyk -import io.nats.streaming.MessageHandler -import kotlinx.coroutines.delay -import kotlinx.coroutines.runBlocking -import org.junit.Test -import org.onap.ccsdk.cds.blueprintsprocessor.nats.NatsConnectionProperties -import org.onap.ccsdk.cds.blueprintsprocessor.nats.NatsLibConstants -import org.onap.ccsdk.cds.blueprintsprocessor.nats.TokenAuthNatsConnectionProperties -import org.onap.ccsdk.cds.blueprintsprocessor.nats.strData -import org.onap.ccsdk.cds.blueprintsprocessor.nats.utils.SubscriptionOptionsUtils -import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType -import kotlin.test.assertNotNull - -class BluePrintNatsServiceTest { - - @Test - fun testTokenAuthNatService() { - val configuration = """{ - "type" : "${NatsLibConstants.TYPE_TOKEN_AUTH}", - "host" : "nats://localhost:4222", - "token" : "tokenAuth" - } - """.trimIndent() - - val bluePrintNatsLibPropertyService = BluePrintNatsLibPropertyService(mockk()) - - val spkBluePrintNatsLibPropertyService = spyk(bluePrintNatsLibPropertyService) - every { - spkBluePrintNatsLibPropertyService - .bluePrintNatsService(any()) - } returns TokenAuthNatsService( - mockk() - ) - - val bluePrintNatsService = - spkBluePrintNatsLibPropertyService.bluePrintNatsService(configuration.jsonAsJsonType()) - assertNotNull(bluePrintNatsService, "failed to get NATS Service") - } - - @Test - fun testTLSAuthNatService() { - val configuration = """{ - "type" : "${NatsLibConstants.TYPE_TLS_AUTH}", - "host" : "nats://localhost:4222" - } - """.trimIndent() - - val bluePrintNatsLibPropertyService = BluePrintNatsLibPropertyService(mockk()) - - val spkBluePrintNatsLibPropertyService = spyk(bluePrintNatsLibPropertyService) - every { - spkBluePrintNatsLibPropertyService - .bluePrintNatsService(any()) - } returns TLSAuthNatsService( - mockk() - ) - - val bluePrintNatsService = - spkBluePrintNatsLibPropertyService.bluePrintNatsService(configuration.jsonAsJsonType()) - assertNotNull(bluePrintNatsService, "failed to get NATS Service") - } - - /** Enable to test only on local desktop. Don't enable in Build server - * Start the Server with : nats-streaming-server -cid cds-cluster --auth tokenAuth -m 8222 -V - */ - // @Test - fun localIntegrationTest() { - runBlocking { - - val connectionProperties = TokenAuthNatsConnectionProperties().apply { - host = "nats://localhost:4222,nats://localhost:4223" - clientId = "client-1" - token = "tokenAuth" - } - val natsService = TokenAuthNatsService(connectionProperties) - val streamingConnection = natsService.connection() - assertNotNull(streamingConnection, "failed to create nats connection") - - val connectionProperties2 = TokenAuthNatsConnectionProperties().apply { - host = "nats://localhost:4222,nats://localhost:4223" - clientId = "client-2" - token = "tokenAuth" - } - val tlsAuthNatsService2 = TokenAuthNatsService(connectionProperties2) - val streamingConnection2 = tlsAuthNatsService2.connection() - assertNotNull(streamingConnection2, "failed to create nats connection 2") - - testMultiPublish(natsService) - testLoadBalance(natsService) - testLimitSubscription(natsService) - testRequestReply(natsService) - testMultiRequestReply(natsService) - delay(1000) - } - } - - private fun testMultiPublish(natsService: BluePrintNatsService) { - runBlocking { - /** Multiple Publish Message Test **/ - val messageHandler1 = - MessageHandler { message -> println("Multi Publish Message Handler 1: ${message.strData()}") } - val messageHandler2 = - MessageHandler { message -> println("Multi Publish Message Handler 2: ${message.strData()}") } - - natsService.subscribe("multi-publish", messageHandler1) - natsService.subscribe("multi-publish", messageHandler2) - - repeat(5) { - natsService.publish("multi-publish", "multi publish message-$it".toByteArray()) - } - } - } - - private fun testLoadBalance(natsService: BluePrintNatsService) { - runBlocking { - /** Load balance Publish Message Test **/ - val lbMessageHandler1 = - MessageHandler { message -> println("LB Publish Message Handler 1: ${message.strData()}") } - val lbMessageHandler2 = - MessageHandler { message -> println("LB Publish Message Handler 2: ${message.strData()}") } - - val sub1 = natsService.loadBalanceSubscribe("lb-publish", "lb-group", lbMessageHandler1) - val sub2 = natsService.loadBalanceSubscribe("lb-publish", "lb-group", lbMessageHandler2) - - repeat(5) { - natsService.publish("lb-publish", "lb publish message-$it".toByteArray()) - } - sub1.unsubscribe() - sub2.unsubscribe() - } - } - - private fun testLimitSubscription(natsService: BluePrintNatsService) { - runBlocking { - /** Load balance Publish Message Test **/ - val lbMessageHandler1 = - MessageHandler { message -> - runBlocking { - println("LB Publish Message Handler 1: ${message.strData()}") - message.ack() - } - } - val lbMessageHandler2 = - MessageHandler { message -> - runBlocking { - println("LB Publish Message Handler 2: ${message.strData()}") - message.ack() - } - } - - val sub1 = natsService.loadBalanceSubscribe( - "lb-publish", "lb-group", lbMessageHandler1, - SubscriptionOptionsUtils.manualAckWithRateLimit(1) - ) - val sub2 = natsService.loadBalanceSubscribe( - "lb-publish", "lb-group", lbMessageHandler2, - SubscriptionOptionsUtils.manualAckWithRateLimit(1) - ) - - repeat(10) { - natsService.publish("lb-publish", "lb limit message-$it".toByteArray()) - } - sub1.unsubscribe() - sub2.unsubscribe() - } - } - - private fun testRequestReply(natsService: BluePrintNatsService) { - runBlocking { - val lbMessageHandler1 = io.nats.client.MessageHandler { message -> - println("LB RR Request Handler 1: ${String(message.data)} will reply to(${message.replyTo})") - message.connection.publish( - message.replyTo, - "Notification ${String(message.data)} reply from 1".toByteArray() - ) - } - - val lbMessageHandler2 = io.nats.client.MessageHandler { message -> - println("LB RR Request Handler 2: ${String(message.data)} will reply to(${message.replyTo})") - message.connection.publish( - message.replyTo, - "Notification ${String(message.data)} reply from 2".toByteArray() - ) - } - - natsService.loadBalanceReplySubscribe("rr-request", "rr-group", lbMessageHandler1) - natsService.loadBalanceReplySubscribe("rr-request", "rr-group", lbMessageHandler2) - - repeat(5) { - val message = natsService.requestAndGetOneReply( - "rr-request", - "rr message-$it".toByteArray(), - 1000 - ) - println("Received : ${message.strData()}") - } - } - } - - private fun testMultiRequestReply(natsService: BluePrintNatsService) { - runBlocking { - /** Request Reply **/ - val lbMessageHandler1 = io.nats.client.MessageHandler { message -> - println("LB RR Request Handler 1: ${String(message.data)} will reply to(${message.replyTo})") - message.connection.publish( - message.replyTo, - "Notification ${message.strData()} reply from 1".toByteArray() - ) - message.connection.publish( - message.replyTo, - "Completion ${message.strData()} reply from 1".toByteArray() - ) - } - val lbMessageHandler2 = io.nats.client.MessageHandler { message -> - println("LB RR Request Handler 2: ${message.strData()} will reply to(${message.replyTo})") - message.connection.publish( - message.replyTo, - "Notification ${message.strData()} reply from 2".toByteArray() - ) - message.connection.publish( - message.replyTo, - "Completion ${message.strData()} reply from 2".toByteArray() - ) - } - - natsService.loadBalanceReplySubscribe("rr-request", "rr-group", lbMessageHandler1) - natsService.loadBalanceReplySubscribe("rr-request", "rr-group", lbMessageHandler2) - - /** Should unsubscribe on completion message */ - val rrReplyMessageHandler = io.nats.client.MessageHandler { message -> - val messageContent = message.strData() - println("RR Reply Handler : $messageContent") - if (messageContent.startsWith("Completion")) { - message.subscription.unsubscribe() - } - } - repeat(5) { - natsService.requestAndGetMultipleReplies( - "rr-request", - "rr-reply-$it", - "rr message-$it".toByteArray(), - rrReplyMessageHandler - ) - } - } - } -} diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsExtensionsTest.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsExtensionsTest.kt new file mode 100644 index 000000000..816b6c809 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsExtensionsTest.kt @@ -0,0 +1,51 @@ +/* + * Copyright © 2018-2019 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.nats.service + +import io.mockk.every +import io.mockk.mockk +import org.junit.Test +import org.onap.ccsdk.cds.blueprintsprocessor.nats.asJsonType +import org.onap.ccsdk.cds.blueprintsprocessor.nats.strData +import org.onap.ccsdk.cds.controllerblueprints.core.asByteArray +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString +import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType +import java.nio.charset.Charset +import kotlin.test.assertEquals + +class BlueprintNatsExtensionsTest { + + @Test + fun testMessageStrConversion() { + val mockMessage = mockk() + every { mockMessage.data } returns "I am message".toByteArray(Charset.defaultCharset()) + + val messageData = mockMessage.strData() + assertEquals("I am message", messageData) + } + + @Test + fun testMessageJsonConversion() { + val json = """{"name":"value"}""" + + val mockMessage = mockk() + every { mockMessage.data } returns json.jsonAsJsonType().asByteArray() + + val messageData = mockMessage.asJsonType().asJsonString() + assertEquals(json, messageData) + } +} diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsLibPropertyServiceTest.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsLibPropertyServiceTest.kt new file mode 100644 index 000000000..5ef4a72c6 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsLibPropertyServiceTest.kt @@ -0,0 +1,56 @@ +/* + * Copyright © 2018-2019 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.nats.service + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.nats.BlueprintNatsLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.nats.NatsLibConstants +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.assertTrue + +@RunWith(SpringRunner::class) +@ContextConfiguration( + classes = [ + BlueprintNatsLibConfiguration::class, + BlueprintPropertyConfiguration::class, BlueprintPropertiesService::class + ] +) +@TestPropertySource( + properties = + [ + "blueprintsprocessor.nats.cds-controller.type=token-auth", + "blueprintsprocessor.nats.cds-controller.host=nats://localhost:4222", + "blueprintsprocessor.nats.cds-controller.token=tokenAuth" + ] +) +class BlueprintNatsLibPropertyServiceTest { + + @Autowired + lateinit var bluePrintNatsLibPropertyService: BlueprintNatsLibPropertyService + + @Test + fun testNatsProperties() { + assertTrue(::bluePrintNatsLibPropertyService.isInitialized) + bluePrintNatsLibPropertyService.bluePrintNatsService(NatsLibConstants.DEFULT_NATS_SELECTOR) + } +} diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsServiceTest.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsServiceTest.kt new file mode 100644 index 000000000..8e7ee63f1 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/service/BlueprintNatsServiceTest.kt @@ -0,0 +1,267 @@ +/* + * Copyright © 2018-2019 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.nats.service + +import io.mockk.every +import io.mockk.mockk +import io.mockk.spyk +import io.nats.streaming.MessageHandler +import kotlinx.coroutines.delay +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.onap.ccsdk.cds.blueprintsprocessor.nats.NatsConnectionProperties +import org.onap.ccsdk.cds.blueprintsprocessor.nats.NatsLibConstants +import org.onap.ccsdk.cds.blueprintsprocessor.nats.TokenAuthNatsConnectionProperties +import org.onap.ccsdk.cds.blueprintsprocessor.nats.strData +import org.onap.ccsdk.cds.blueprintsprocessor.nats.utils.SubscriptionOptionsUtils +import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType +import kotlin.test.assertNotNull + +class BlueprintNatsServiceTest { + + @Test + fun testTokenAuthNatService() { + val configuration = """{ + "type" : "${NatsLibConstants.TYPE_TOKEN_AUTH}", + "host" : "nats://localhost:4222", + "token" : "tokenAuth" + } + """.trimIndent() + + val bluePrintNatsLibPropertyService = BlueprintNatsLibPropertyService(mockk()) + + val spkBlueprintNatsLibPropertyService = spyk(bluePrintNatsLibPropertyService) + every { + spkBlueprintNatsLibPropertyService + .bluePrintNatsService(any()) + } returns TokenAuthNatsService( + mockk() + ) + + val bluePrintNatsService = + spkBlueprintNatsLibPropertyService.bluePrintNatsService(configuration.jsonAsJsonType()) + assertNotNull(bluePrintNatsService, "failed to get NATS Service") + } + + @Test + fun testTLSAuthNatService() { + val configuration = """{ + "type" : "${NatsLibConstants.TYPE_TLS_AUTH}", + "host" : "nats://localhost:4222" + } + """.trimIndent() + + val bluePrintNatsLibPropertyService = BlueprintNatsLibPropertyService(mockk()) + + val spkBlueprintNatsLibPropertyService = spyk(bluePrintNatsLibPropertyService) + every { + spkBlueprintNatsLibPropertyService + .bluePrintNatsService(any()) + } returns TLSAuthNatsService( + mockk() + ) + + val bluePrintNatsService = + spkBlueprintNatsLibPropertyService.bluePrintNatsService(configuration.jsonAsJsonType()) + assertNotNull(bluePrintNatsService, "failed to get NATS Service") + } + + /** Enable to test only on local desktop. Don't enable in Build server + * Start the Server with : nats-streaming-server -cid cds-cluster --auth tokenAuth -m 8222 -V + */ + // @Test + fun localIntegrationTest() { + runBlocking { + + val connectionProperties = TokenAuthNatsConnectionProperties().apply { + host = "nats://localhost:4222,nats://localhost:4223" + clientId = "client-1" + token = "tokenAuth" + } + val natsService = TokenAuthNatsService(connectionProperties) + val streamingConnection = natsService.connection() + assertNotNull(streamingConnection, "failed to create nats connection") + + val connectionProperties2 = TokenAuthNatsConnectionProperties().apply { + host = "nats://localhost:4222,nats://localhost:4223" + clientId = "client-2" + token = "tokenAuth" + } + val tlsAuthNatsService2 = TokenAuthNatsService(connectionProperties2) + val streamingConnection2 = tlsAuthNatsService2.connection() + assertNotNull(streamingConnection2, "failed to create nats connection 2") + + testMultiPublish(natsService) + testLoadBalance(natsService) + testLimitSubscription(natsService) + testRequestReply(natsService) + testMultiRequestReply(natsService) + delay(1000) + } + } + + private fun testMultiPublish(natsService: BlueprintNatsService) { + runBlocking { + /** Multiple Publish Message Test **/ + val messageHandler1 = + MessageHandler { message -> println("Multi Publish Message Handler 1: ${message.strData()}") } + val messageHandler2 = + MessageHandler { message -> println("Multi Publish Message Handler 2: ${message.strData()}") } + + natsService.subscribe("multi-publish", messageHandler1) + natsService.subscribe("multi-publish", messageHandler2) + + repeat(5) { + natsService.publish("multi-publish", "multi publish message-$it".toByteArray()) + } + } + } + + private fun testLoadBalance(natsService: BlueprintNatsService) { + runBlocking { + /** Load balance Publish Message Test **/ + val lbMessageHandler1 = + MessageHandler { message -> println("LB Publish Message Handler 1: ${message.strData()}") } + val lbMessageHandler2 = + MessageHandler { message -> println("LB Publish Message Handler 2: ${message.strData()}") } + + val sub1 = natsService.loadBalanceSubscribe("lb-publish", "lb-group", lbMessageHandler1) + val sub2 = natsService.loadBalanceSubscribe("lb-publish", "lb-group", lbMessageHandler2) + + repeat(5) { + natsService.publish("lb-publish", "lb publish message-$it".toByteArray()) + } + sub1.unsubscribe() + sub2.unsubscribe() + } + } + + private fun testLimitSubscription(natsService: BlueprintNatsService) { + runBlocking { + /** Load balance Publish Message Test **/ + val lbMessageHandler1 = + MessageHandler { message -> + runBlocking { + println("LB Publish Message Handler 1: ${message.strData()}") + message.ack() + } + } + val lbMessageHandler2 = + MessageHandler { message -> + runBlocking { + println("LB Publish Message Handler 2: ${message.strData()}") + message.ack() + } + } + + val sub1 = natsService.loadBalanceSubscribe( + "lb-publish", "lb-group", lbMessageHandler1, + SubscriptionOptionsUtils.manualAckWithRateLimit(1) + ) + val sub2 = natsService.loadBalanceSubscribe( + "lb-publish", "lb-group", lbMessageHandler2, + SubscriptionOptionsUtils.manualAckWithRateLimit(1) + ) + + repeat(10) { + natsService.publish("lb-publish", "lb limit message-$it".toByteArray()) + } + sub1.unsubscribe() + sub2.unsubscribe() + } + } + + private fun testRequestReply(natsService: BlueprintNatsService) { + runBlocking { + val lbMessageHandler1 = io.nats.client.MessageHandler { message -> + println("LB RR Request Handler 1: ${String(message.data)} will reply to(${message.replyTo})") + message.connection.publish( + message.replyTo, + "Notification ${String(message.data)} reply from 1".toByteArray() + ) + } + + val lbMessageHandler2 = io.nats.client.MessageHandler { message -> + println("LB RR Request Handler 2: ${String(message.data)} will reply to(${message.replyTo})") + message.connection.publish( + message.replyTo, + "Notification ${String(message.data)} reply from 2".toByteArray() + ) + } + + natsService.loadBalanceReplySubscribe("rr-request", "rr-group", lbMessageHandler1) + natsService.loadBalanceReplySubscribe("rr-request", "rr-group", lbMessageHandler2) + + repeat(5) { + val message = natsService.requestAndGetOneReply( + "rr-request", + "rr message-$it".toByteArray(), + 1000 + ) + println("Received : ${message.strData()}") + } + } + } + + private fun testMultiRequestReply(natsService: BlueprintNatsService) { + runBlocking { + /** Request Reply **/ + val lbMessageHandler1 = io.nats.client.MessageHandler { message -> + println("LB RR Request Handler 1: ${String(message.data)} will reply to(${message.replyTo})") + message.connection.publish( + message.replyTo, + "Notification ${message.strData()} reply from 1".toByteArray() + ) + message.connection.publish( + message.replyTo, + "Completion ${message.strData()} reply from 1".toByteArray() + ) + } + val lbMessageHandler2 = io.nats.client.MessageHandler { message -> + println("LB RR Request Handler 2: ${message.strData()} will reply to(${message.replyTo})") + message.connection.publish( + message.replyTo, + "Notification ${message.strData()} reply from 2".toByteArray() + ) + message.connection.publish( + message.replyTo, + "Completion ${message.strData()} reply from 2".toByteArray() + ) + } + + natsService.loadBalanceReplySubscribe("rr-request", "rr-group", lbMessageHandler1) + natsService.loadBalanceReplySubscribe("rr-request", "rr-group", lbMessageHandler2) + + /** Should unsubscribe on completion message */ + val rrReplyMessageHandler = io.nats.client.MessageHandler { message -> + val messageContent = message.strData() + println("RR Reply Handler : $messageContent") + if (messageContent.startsWith("Completion")) { + message.subscription.unsubscribe() + } + } + repeat(5) { + natsService.requestAndGetMultipleReplies( + "rr-request", + "rr-reply-$it", + "rr message-$it".toByteArray(), + rrReplyMessageHandler + ) + } + } + } +} 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 deleted file mode 100644 index 2a4d05dcb..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintCoreConfiguration.kt +++ /dev/null @@ -1,88 +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.cds.blueprintsprocessor.core - -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration -import org.onap.ccsdk.cds.controllerblueprints.core.logger -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.context.properties.bind.Bindable -import org.springframework.boot.context.properties.bind.Binder -import org.springframework.context.ApplicationContext -import org.springframework.context.ApplicationContextAware -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.core.env.Environment -import org.springframework.stereotype.Service - -@Configuration -open class BluePrintCoreConfiguration(private val bluePrintPropertiesService: BluePrintPropertiesService) { - - companion object { - - const val PREFIX_BLUEPRINT_PROCESSOR = "blueprintsprocessor" - } - - @Bean - open fun bluePrintLoadConfiguration(): BluePrintLoadConfiguration { - return bluePrintPropertiesService - .propertyBeanType(PREFIX_BLUEPRINT_PROCESSOR, BluePrintLoadConfiguration::class.java) - } -} - -@Configuration -open class BluePrintPropertyConfiguration { - - @Autowired - lateinit var environment: Environment - - @Bean - open fun bluePrintPropertyBinder(): Binder { - return Binder.get(environment) - } -} - -@Service -open class BluePrintPropertiesService(private var bluePrintPropertyConfig: BluePrintPropertyConfiguration) { - - private val log = logger(BluePrintPropertiesService::class) - - fun propertyBeanType(prefix: String, type: Class): T { - return try { - bluePrintPropertyConfig.bluePrintPropertyBinder().bind(prefix, Bindable.of(type)).get() - } catch (e: NoSuchElementException) { - val errMsg = "Error: missing property \"$prefix\"... Check the application.properties file." - log.error(errMsg) - throw BluePrintProcessorException(e, errMsg) - } - } -} - -@Configuration -// Add Conditional property , If we try to manage on Application level -open class BlueprintDependencyConfiguration : ApplicationContextAware { - - private val log = LoggerFactory.getLogger(BlueprintDependencyConfiguration::class.java)!! - - override fun setApplicationContext(applicationContext: ApplicationContext) { - BluePrintDependencyService.inject(applicationContext) - log.info("Dependency Management module created...") - } -} 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..782a7b033 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BlueprintCoreConfiguration.kt @@ -0,0 +1,88 @@ +/* + * 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.core + +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.config.BlueprintLoadConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.logger +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintDependencyService +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.context.properties.bind.Bindable +import org.springframework.boot.context.properties.bind.Binder +import org.springframework.context.ApplicationContext +import org.springframework.context.ApplicationContextAware +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.core.env.Environment +import org.springframework.stereotype.Service + +@Configuration +open class BlueprintCoreConfiguration(private val bluePrintPropertiesService: BlueprintPropertiesService) { + + companion object { + + const val PREFIX_BLUEPRINT_PROCESSOR = "blueprintsprocessor" + } + + @Bean + open fun bluePrintLoadConfiguration(): BlueprintLoadConfiguration { + return bluePrintPropertiesService + .propertyBeanType(PREFIX_BLUEPRINT_PROCESSOR, BlueprintLoadConfiguration::class.java) + } +} + +@Configuration +open class BlueprintPropertyConfiguration { + + @Autowired + lateinit var environment: Environment + + @Bean + open fun bluePrintPropertyBinder(): Binder { + return Binder.get(environment) + } +} + +@Service +open class BlueprintPropertiesService(private var bluePrintPropertyConfig: BlueprintPropertyConfiguration) { + + private val log = logger(BlueprintPropertiesService::class) + + fun propertyBeanType(prefix: String, type: Class): T { + return try { + bluePrintPropertyConfig.bluePrintPropertyBinder().bind(prefix, Bindable.of(type)).get() + } catch (e: NoSuchElementException) { + val errMsg = "Error: missing property \"$prefix\"... Check the application.properties file." + log.error(errMsg) + throw BlueprintProcessorException(e, errMsg) + } + } +} + +@Configuration +// Add Conditional property , If we try to manage on Application level +open class BlueprintDependencyConfiguration : ApplicationContextAware { + + private val log = LoggerFactory.getLogger(BlueprintDependencyConfiguration::class.java)!! + + override fun setApplicationContext(applicationContext: ApplicationContext) { + BlueprintDependencyService.inject(applicationContext) + log.info("Dependency Management module created...") + } +} 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 index 61997061b..924aed898 100644 --- 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 @@ -23,7 +23,7 @@ import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.node.ObjectNode import io.swagger.annotations.ApiModelProperty import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants import java.util.Date import java.util.UUID @@ -154,7 +154,7 @@ open class Status { var errorMessage: String? = null @get:ApiModelProperty(required = true, value = "Message providing request status") - var message: String = BluePrintConstants.STATUS_SUCCESS + var message: String = BlueprintConstants.STATUS_SUCCESS } open class StepData { diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensions.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensions.kt deleted file mode 100644 index 0a58857f7..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensions.kt +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright © 2018-2019 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.cluster - -import com.hazelcast.cluster.Member -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.newSingleThreadContext -import kotlinx.coroutines.withContext -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterService -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterLock -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterMember -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.cds.controllerblueprints.core.MDCContext -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService - -/** - * Exposed Dependency Service by this Hazelcast Lib Module - */ -fun BluePrintDependencyService.clusterService(): BluePrintClusterService = - instance(HazelcastClusterService::class) - -/** Optional Cluster Service, returns only if Cluster is enabled */ -fun BluePrintDependencyService.optionalClusterService(): BluePrintClusterService? { - return if (BluePrintConstants.CLUSTER_ENABLED) { - BluePrintDependencyService.clusterService() - } else null -} - -/** Extension to convert Hazelcast Member to Blueprints Cluster Member */ -fun Member.toClusterMember(): ClusterMember { - val memberName: String = this.getAttribute(BluePrintConstants.PROPERTY_CLUSTER_NODE_ID) ?: this.uuid.toString() - return ClusterMember( - id = this.uuid.toString(), - name = memberName, - memberAddress = this.address.toString() - ) -} - -/** - * This function will try to acquire the lock and then execute the provided block. - * If the lock cannot be acquired within timeout, a BlueprintException will be thrown. - * - * Since a lock can only be unlocked by the the thread which acquired the lock, - * this function will confine coroutines within the block to a dedicated thread. - */ -suspend fun ClusterLock.executeWithLock(acquireLockTimeout: Long, block: suspend () -> R): R { - val lock = this - return newSingleThreadContext(lock.name()).use { - withContext(GlobalScope.coroutineContext[MDCContext]?.plus(it) ?: it) { - if (lock.tryLock(acquireLockTimeout)) { - try { - block() - } finally { - lock.unLock() - } - } else - throw BluePrintException("Failed to acquire lock within timeout") - } - } -} diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensions.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensions.kt new file mode 100644 index 000000000..f0504555f --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensions.kt @@ -0,0 +1,75 @@ +/* + * Copyright © 2018-2019 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.cluster + +import com.hazelcast.cluster.Member +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.newSingleThreadContext +import kotlinx.coroutines.withContext +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterService +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterLock +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterMember +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException +import org.onap.ccsdk.cds.controllerblueprints.core.MDCContext +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintDependencyService + +/** + * Exposed Dependency Service by this Hazelcast Lib Module + */ +fun BlueprintDependencyService.clusterService(): BlueprintClusterService = + instance(HazelcastClusterService::class) + +/** Optional Cluster Service, returns only if Cluster is enabled */ +fun BlueprintDependencyService.optionalClusterService(): BlueprintClusterService? { + return if (BlueprintConstants.CLUSTER_ENABLED) { + BlueprintDependencyService.clusterService() + } else null +} + +/** Extension to convert Hazelcast Member to Blueprints Cluster Member */ +fun Member.toClusterMember(): ClusterMember { + val memberName: String = this.getAttribute(BlueprintConstants.PROPERTY_CLUSTER_NODE_ID) ?: this.uuid.toString() + return ClusterMember( + id = this.uuid.toString(), + name = memberName, + memberAddress = this.address.toString() + ) +} + +/** + * This function will try to acquire the lock and then execute the provided block. + * If the lock cannot be acquired within timeout, a BlueprintException will be thrown. + * + * Since a lock can only be unlocked by the the thread which acquired the lock, + * this function will confine coroutines within the block to a dedicated thread. + */ +suspend fun ClusterLock.executeWithLock(acquireLockTimeout: Long, block: suspend () -> R): R { + val lock = this + return newSingleThreadContext(lock.name()).use { + withContext(GlobalScope.coroutineContext[MDCContext]?.plus(it) ?: it) { + if (lock.tryLock(acquireLockTimeout)) { + try { + block() + } finally { + lock.unLock() + } + } else + throw BlueprintException("Failed to acquire lock within timeout") + } + } +} diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterService.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterService.kt index fb9056776..613fc4a58 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterService.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterService.kt @@ -33,15 +33,15 @@ import com.hazelcast.scheduledexecutor.IScheduledExecutorService import com.hazelcast.topic.Message import com.hazelcast.topic.MessageListener import kotlinx.coroutines.delay -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterMessage -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterService +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterMessage +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterService import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterMessageListener import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterInfo import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterJoinedEvent import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterLock import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterMember -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.logger import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.onap.ccsdk.cds.controllerblueprints.core.utils.ClusterUtils @@ -53,7 +53,7 @@ import java.util.UUID import java.util.concurrent.TimeUnit @Service -open class HazelcastClusterService(private val applicationEventPublisher: ApplicationEventPublisher) : BluePrintClusterService { +open class HazelcastClusterService(private val applicationEventPublisher: ApplicationEventPublisher) : BlueprintClusterService { private val log = logger(HazelcastClusterService::class) lateinit var hazelcast: HazelcastInstance @@ -78,12 +78,12 @@ open class HazelcastClusterService(private val applicationEventPublisher: Applic } is ClusterInfo -> { - System.setProperty(BluePrintConstants.PROPERTY_CLUSTER_ID, configuration.id) - System.setProperty(BluePrintConstants.PROPERTY_CLUSTER_NODE_ID, configuration.nodeId) + System.setProperty(BlueprintConstants.PROPERTY_CLUSTER_ID, configuration.id) + System.setProperty(BlueprintConstants.PROPERTY_CLUSTER_NODE_ID, configuration.nodeId) val memberAttributeConfig = MemberAttributeConfig() memberAttributeConfig.setAttribute( - BluePrintConstants.PROPERTY_CLUSTER_NODE_ID, + BlueprintConstants.PROPERTY_CLUSTER_NODE_ID, configuration.nodeId ) @@ -122,7 +122,7 @@ open class HazelcastClusterService(private val applicationEventPublisher: Applic } } else -> { - throw BluePrintProcessorException("couldn't understand the cluster configuration") + throw BlueprintProcessorException("couldn't understand the cluster configuration") } } @@ -179,7 +179,7 @@ open class HazelcastClusterService(private val applicationEventPublisher: Applic return ClusterLockImpl(hazelcast, name) } - /** Return interface may change and it will be included in BluePrintClusterService */ + /** Return interface may change and it will be included in BlueprintClusterService */ @UseExperimental suspend fun clusterScheduler(name: String): IScheduledExecutorService { check(::hazelcast.isInitialized) { "failed to start and join cluster" } @@ -225,7 +225,7 @@ open class HazelcastClusterService(private val applicationEventPublisher: Applic check(::hazelcast.isInitialized) { "failed to start and join cluster" } val applicationMembers: MutableMap = hashMapOf() hazelcast.cluster.members.map { member -> - val memberName: String = member.getAttribute(BluePrintConstants.PROPERTY_CLUSTER_NODE_ID) + val memberName: String = member.getAttribute(BlueprintConstants.PROPERTY_CLUSTER_NODE_ID) if (memberName.startsWith(appName, true)) { applicationMembers[memberName] = member } @@ -300,7 +300,7 @@ open class ClusterLockImpl(private val hazelcast: HazelcastInstance, private val class HazelcastMessageListenerAdapter(val listener: BlueprintClusterMessageListener) : MessageListener { override fun onMessage(message: Message?) = message?.let { - BluePrintClusterMessage( + BlueprintClusterMessage( BlueprintClusterTopic.valueOf(it.source as String), it.messageObject, it.publishTime, 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 index 2f925dc5b..46ab25e23 100644 --- 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 @@ -17,7 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.core.factory -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException import org.slf4j.LoggerFactory import org.springframework.context.ApplicationContext import org.springframework.context.ApplicationContextAware @@ -29,16 +29,16 @@ import org.springframework.context.ApplicationContextAware */ interface ComponentNode { - @Throws(BluePrintProcessorException::class) + @Throws(BlueprintProcessorException::class) fun validate(context: MutableMap, componentContext: MutableMap) - @Throws(BluePrintProcessorException::class) + @Throws(BlueprintProcessorException::class) fun process(context: MutableMap, componentContext: MutableMap) - @Throws(BluePrintProcessorException::class) + @Throws(BlueprintProcessorException::class) fun errorHandle(context: MutableMap, componentContext: MutableMap) - @Throws(BluePrintProcessorException::class) + @Throws(BlueprintProcessorException::class) fun reTrigger(context: MutableMap, componentContext: MutableMap) } diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListener.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListener.kt index 3833379c9..64b4f0ac5 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListener.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListener.kt @@ -17,19 +17,19 @@ package org.onap.ccsdk.cds.blueprintsprocessor.core.listeners import org.onap.ccsdk.cds.blueprintsprocessor.core.cluster.BlueprintClusterTopic -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterMessage -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterService +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterMessage +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterService import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterMessageListener import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterJoinedEvent import org.onap.ccsdk.cds.controllerblueprints.core.logger -import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache +import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BlueprintCompileCache import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty import org.springframework.context.event.EventListener import org.springframework.stereotype.Component @Component @ConditionalOnProperty("CLUSTER_ENABLED", havingValue = "true") -open class BlueprintCompilerCacheMessageListener(private val clusterService: BluePrintClusterService) : BlueprintClusterMessageListener { +open class BlueprintCompilerCacheMessageListener(private val clusterService: BlueprintClusterService) : BlueprintClusterMessageListener { private val log = logger(BlueprintCompilerCacheMessageListener::class) @EventListener(ClusterJoinedEvent::class) @@ -38,10 +38,10 @@ open class BlueprintCompilerCacheMessageListener(private val clusterService: Blu clusterService.addBlueprintClusterMessageListener(BlueprintClusterTopic.BLUEPRINT_CLEAN_COMPILER_CACHE, this) } - override fun onMessage(message: BluePrintClusterMessage?) { + override fun onMessage(message: BlueprintClusterMessage?) { message?.let { log.info("Received ClusterMessage - Cleaning compile cache for blueprint (${it.payload})") - BluePrintCompileCache.cleanClassLoader(it.payload) + BlueprintCompileCache.cleanClassLoader(it.payload) } } } diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BluePrintClusterService.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BluePrintClusterService.kt deleted file mode 100644 index f7ba6f25f..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BluePrintClusterService.kt +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright © 2018-2019 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.service - -import org.onap.ccsdk.cds.blueprintsprocessor.core.cluster.BlueprintClusterTopic -import org.springframework.context.ApplicationEvent -import java.time.Duration -import java.util.Properties -import java.util.UUID - -interface BluePrintClusterService { - - /** Start the cluster with [clusterInfo], By default clustering service is disabled. - * Application module has to start cluster */ - suspend fun startCluster(configuration: T) - - fun clusterJoined(): Boolean - - fun isClient(): Boolean - - fun isLiteMember(): Boolean - - /** Returns [partitionGroup] master member */ - suspend fun masterMember(partitionGroup: String): ClusterMember - - /** Returns all the data cluster members */ - suspend fun allMembers(): Set - - /** - * Returns application cluster members for [appName] joined as server or lite member, - * Node joined as client won't be visible. Here the assumption is node-id is combination of - * application id and replica number, for an example Application cds-cluster then the node ids will be - * cds-cluster-1, cds-cluster-2, cds-cluster-3 - */ - suspend fun applicationMembers(appName: String): Set - - /** Create and get or get the distributed data map store with [name] */ - suspend fun clusterMapStore(name: String): MutableMap - - /** Create and get the distributed lock with [name] */ - suspend fun clusterLock(name: String): ClusterLock - - /** Shut down the cluster with [duration] */ - suspend fun shutDown(duration: Duration) - - /** Send [message] to the listener(s) of a [topic] */ - suspend fun sendMessage(topic: BlueprintClusterTopic, message: T) - - /** Register a [listener] to a [topic] and returns his UUID */ - fun addBlueprintClusterMessageListener(topic: BlueprintClusterTopic, listener: BlueprintClusterMessageListener): UUID - - /** Unregister a listener from a [topic] using his [uuid] and returns true if it succeeded */ - fun removeBlueprintClusterMessageListener(topic: BlueprintClusterTopic, uuid: UUID): Boolean -} - -data class ClusterInfo( - val id: String, - val nodeId: String, - var joinAsClient: Boolean = false, - var properties: Properties?, - var configFile: String -) - -data class ClusterMember( - val id: String, - val name: String, - val memberAddress: String?, - val state: String? = null -) - -interface ClusterLock { - - fun name(): String - suspend fun lock() - suspend fun fenceLock(): String - suspend fun tryLock(timeout: Long): Boolean - suspend fun tryFenceLock(timeout: Long): String - suspend fun unLock() - fun isLocked(): Boolean - fun isLockedByCurrentThread(): Boolean - fun close() -} - -class BluePrintClusterMessage(val topic: BlueprintClusterTopic, val payload: E, publishTime: Long, clusterMember: ClusterMember) - -interface BlueprintClusterMessageListener { - fun onMessage(message: BluePrintClusterMessage?) -} - -class ClusterJoinedEvent(source: Any) : ApplicationEvent(source) - -const val CDS_LOCK_GROUP = "cds-lock" diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BlueprintClusterService.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BlueprintClusterService.kt new file mode 100644 index 000000000..900ae927b --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/service/BlueprintClusterService.kt @@ -0,0 +1,106 @@ +/* + * Copyright © 2018-2019 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.service + +import org.onap.ccsdk.cds.blueprintsprocessor.core.cluster.BlueprintClusterTopic +import org.springframework.context.ApplicationEvent +import java.time.Duration +import java.util.Properties +import java.util.UUID + +interface BlueprintClusterService { + + /** Start the cluster with [clusterInfo], By default clustering service is disabled. + * Application module has to start cluster */ + suspend fun startCluster(configuration: T) + + fun clusterJoined(): Boolean + + fun isClient(): Boolean + + fun isLiteMember(): Boolean + + /** Returns [partitionGroup] master member */ + suspend fun masterMember(partitionGroup: String): ClusterMember + + /** Returns all the data cluster members */ + suspend fun allMembers(): Set + + /** + * Returns application cluster members for [appName] joined as server or lite member, + * Node joined as client won't be visible. Here the assumption is node-id is combination of + * application id and replica number, for an example Application cds-cluster then the node ids will be + * cds-cluster-1, cds-cluster-2, cds-cluster-3 + */ + suspend fun applicationMembers(appName: String): Set + + /** Create and get or get the distributed data map store with [name] */ + suspend fun clusterMapStore(name: String): MutableMap + + /** Create and get the distributed lock with [name] */ + suspend fun clusterLock(name: String): ClusterLock + + /** Shut down the cluster with [duration] */ + suspend fun shutDown(duration: Duration) + + /** Send [message] to the listener(s) of a [topic] */ + suspend fun sendMessage(topic: BlueprintClusterTopic, message: T) + + /** Register a [listener] to a [topic] and returns his UUID */ + fun addBlueprintClusterMessageListener(topic: BlueprintClusterTopic, listener: BlueprintClusterMessageListener): UUID + + /** Unregister a listener from a [topic] using his [uuid] and returns true if it succeeded */ + fun removeBlueprintClusterMessageListener(topic: BlueprintClusterTopic, uuid: UUID): Boolean +} + +data class ClusterInfo( + val id: String, + val nodeId: String, + var joinAsClient: Boolean = false, + var properties: Properties?, + var configFile: String +) + +data class ClusterMember( + val id: String, + val name: String, + val memberAddress: String?, + val state: String? = null +) + +interface ClusterLock { + + fun name(): String + suspend fun lock() + suspend fun fenceLock(): String + suspend fun tryLock(timeout: Long): Boolean + suspend fun tryFenceLock(timeout: Long): String + suspend fun unLock() + fun isLocked(): Boolean + fun isLockedByCurrentThread(): Boolean + fun close() +} + +class BlueprintClusterMessage(val topic: BlueprintClusterTopic, val payload: E, publishTime: Long, clusterMember: ClusterMember) + +interface BlueprintClusterMessageListener { + fun onMessage(message: BlueprintClusterMessage?) +} + +class ClusterJoinedEvent(source: Any) : ApplicationEvent(source) + +const val CDS_LOCK_GROUP = "cds-lock" 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 index 72e5654d4..4ac59802b 100644 --- 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 @@ -17,11 +17,11 @@ 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.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString import org.onap.ccsdk.cds.controllerblueprints.core.returnNullIfMissing -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils object PayloadUtils { @@ -38,11 +38,11 @@ object PayloadUtils { fun getResponseDataFromPayload(workflowName: String, responsePayload: JsonNode): JsonNode { return responsePayload.get("$workflowName-response").returnNullIfMissing() - ?: throw BluePrintProcessorException("failed to get property($workflowName-response)") + ?: throw BlueprintProcessorException("failed to get property($workflowName-response)") } fun prepareInputsFromWorkflowPayload( - bluePrintRuntimeService: BluePrintRuntimeService<*>, + bluePrintRuntimeService: BlueprintRuntimeService<*>, payload: JsonNode, workflowName: String ) { @@ -51,7 +51,7 @@ object PayloadUtils { } fun prepareDynamicInputsFromWorkflowPayload( - bluePrintRuntimeService: BluePrintRuntimeService<*>, + bluePrintRuntimeService: BlueprintRuntimeService<*>, payload: JsonNode, workflowName: String ) { @@ -61,12 +61,12 @@ object PayloadUtils { } fun prepareDynamicInputsFromComponentPayload( - bluePrintRuntimeService: BluePrintRuntimeService<*>, + bluePrintRuntimeService: BlueprintRuntimeService<*>, payload: JsonNode ) { payload.fields().forEach { property -> - val path = StringBuilder(BluePrintConstants.PATH_INPUTS) - .append(BluePrintConstants.PATH_DIVIDER).append(property.key).toString() + val path = StringBuilder(BlueprintConstants.PATH_INPUTS) + .append(BlueprintConstants.PATH_DIVIDER).append(property.key).toString() bluePrintRuntimeService.put(path, property.value) } } 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 deleted file mode 100644 index c27285020..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/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.cds.blueprintsprocessor.core - -// TODO -open class BluePrintPropertiesTest 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..fa2e4d41a --- /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 diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensionsTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensionsTest.kt deleted file mode 100644 index 95394e7a9..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BluePrintClusterExtensionsTest.kt +++ /dev/null @@ -1,74 +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.cds.blueprintsprocessor.core.cluster - -import io.mockk.every -import io.mockk.mockk -import io.mockk.verify -import kotlinx.coroutines.runBlocking -import org.junit.Before -import org.junit.Test -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterLock -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException -import kotlin.test.assertEquals - -class BluePrintClusterExtensionsTest { - - private lateinit var clusterLockMock: ClusterLock - - @Before - fun setup() { - clusterLockMock = mockk() - every { clusterLockMock.name() } returns "mock-lock" - } - - @Test - fun `executeWithLock - should call unlock and return block result`() { - runBlocking { - every { runBlocking { clusterLockMock.tryLock(more(0L)) } } returns true - every { runBlocking { clusterLockMock.unLock() } } returns Unit - - val result = clusterLockMock.executeWithLock(1_000) { "result" } - - verify { runBlocking { clusterLockMock.unLock() } } - assertEquals("result", result) - } - } - - @Test - fun `executeWithLock - should call unlock even when block throws exception`() { - runBlocking { - every { runBlocking { clusterLockMock.tryLock(more(0L)) } } returns true - every { runBlocking { clusterLockMock.unLock() } } returns Unit - - try { - clusterLockMock.executeWithLock(1_000) { throw RuntimeException("It crashed") } - } catch (e: Exception) { - } - - verify { runBlocking { clusterLockMock.unLock() } } - } - } - - @Test(expected = BluePrintException::class) - fun `executeWithLock - should throw exception when lock was not acquired within timeout`() { - runBlocking { - every { runBlocking { clusterLockMock.tryLock(eq(0L)) } } returns false - clusterLockMock.executeWithLock(0) { "Will not run" } - } - } -} diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensionsTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensionsTest.kt new file mode 100644 index 000000000..ead24b58d --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/BlueprintClusterExtensionsTest.kt @@ -0,0 +1,74 @@ +/* + * 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.cluster + +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import kotlinx.coroutines.runBlocking +import org.junit.Before +import org.junit.Test +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterLock +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException +import kotlin.test.assertEquals + +class BlueprintClusterExtensionsTest { + + private lateinit var clusterLockMock: ClusterLock + + @Before + fun setup() { + clusterLockMock = mockk() + every { clusterLockMock.name() } returns "mock-lock" + } + + @Test + fun `executeWithLock - should call unlock and return block result`() { + runBlocking { + every { runBlocking { clusterLockMock.tryLock(more(0L)) } } returns true + every { runBlocking { clusterLockMock.unLock() } } returns Unit + + val result = clusterLockMock.executeWithLock(1_000) { "result" } + + verify { runBlocking { clusterLockMock.unLock() } } + assertEquals("result", result) + } + } + + @Test + fun `executeWithLock - should call unlock even when block throws exception`() { + runBlocking { + every { runBlocking { clusterLockMock.tryLock(more(0L)) } } returns true + every { runBlocking { clusterLockMock.unLock() } } returns Unit + + try { + clusterLockMock.executeWithLock(1_000) { throw RuntimeException("It crashed") } + } catch (e: Exception) { + } + + verify { runBlocking { clusterLockMock.unLock() } } + } + } + + @Test(expected = BlueprintException::class) + fun `executeWithLock - should throw exception when lock was not acquired within timeout`() { + runBlocking { + every { runBlocking { clusterLockMock.tryLock(eq(0L)) } } returns false + clusterLockMock.executeWithLock(0) { "Will not run" } + } + } +} diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterServiceTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterServiceTest.kt index ded017940..91ad657a2 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterServiceTest.kt @@ -33,11 +33,11 @@ import kotlinx.coroutines.withContext import org.junit.After import org.junit.Before import org.junit.Test -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterMessage -import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterService +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterMessage +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterService import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterMessageListener import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterInfo -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.logger import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile @@ -61,8 +61,8 @@ class HazelcastClusterServiceTest { @Test fun testClientFileSystemYamlConfig() { - System.setProperty(BluePrintConstants.PROPERTY_CLUSTER_ID, "test-cluster") - System.setProperty(BluePrintConstants.PROPERTY_CLUSTER_NODE_ID, "node-1234") + System.setProperty(BlueprintConstants.PROPERTY_CLUSTER_ID, "test-cluster") + System.setProperty(BlueprintConstants.PROPERTY_CLUSTER_NODE_ID, "node-1234") System.setProperty( "hazelcast.client.config", normalizedFile("./src/test/resources/hazelcast/hazelcast-client.yaml").absolutePath @@ -75,8 +75,8 @@ class HazelcastClusterServiceTest { @Test fun testServerFileSystemYamlConfig() { - System.setProperty(BluePrintConstants.PROPERTY_CLUSTER_ID, "test-cluster") - System.setProperty(BluePrintConstants.PROPERTY_CLUSTER_NODE_ID, "node-1234") + System.setProperty(BlueprintConstants.PROPERTY_CLUSTER_ID, "test-cluster") + System.setProperty(BlueprintConstants.PROPERTY_CLUSTER_NODE_ID, "node-1234") val configFile = normalizedFile("./src/test/resources/hazelcast/hazelcast.yaml") val config = FileSystemYamlConfig(configFile) assertNotNull(config) @@ -105,7 +105,7 @@ class HazelcastClusterServiceTest { } } - private suspend fun testMessageReceived(bluePrintClusterServices: List) { + private suspend fun testMessageReceived(bluePrintClusterServices: List) { val sender = bluePrintClusterServices[0] as HazelcastClusterService val receiver = bluePrintClusterServices[1] as HazelcastClusterService val messageSent = "hello world" @@ -113,7 +113,7 @@ class HazelcastClusterServiceTest { val uuid = receiver.addBlueprintClusterMessageListener( BlueprintClusterTopic.BLUEPRINT_CLEAN_COMPILER_CACHE, object : BlueprintClusterMessageListener { - override fun onMessage(message: BluePrintClusterMessage?) { + override fun onMessage(message: BlueprintClusterMessage?) { log.info("Message received - ${message?.payload}") isMessageReceived = messageSent == message?.payload } @@ -132,7 +132,7 @@ class HazelcastClusterServiceTest { private suspend fun createCluster( ids: List, joinAsClient: Boolean? = false - ): List { + ): List { return withContext(Dispatchers.Default) { val deferred = ids.map { id -> @@ -164,7 +164,7 @@ class HazelcastClusterServiceTest { } } - private suspend fun testDistributedStore(bluePrintClusterServices: List) { + private suspend fun testDistributedStore(bluePrintClusterServices: List) { /** Test Distributed store creation */ repeat(2) { storeId -> val store = bluePrintClusterServices[0].clusterMapStore( @@ -187,7 +187,7 @@ class HazelcastClusterServiceTest { } } - private suspend fun testDistributedLock(bluePrintClusterServices: List) { + private suspend fun testDistributedLock(bluePrintClusterServices: List) { val lockName = "sample-lock" withContext(Dispatchers.IO) { val deferred = async { @@ -218,7 +218,7 @@ class HazelcastClusterServiceTest { } private suspend fun executeLock( - bluePrintClusterService: BluePrintClusterService, + bluePrintClusterService: BlueprintClusterService, lockId: String, lockName: String ) { @@ -237,7 +237,7 @@ class HazelcastClusterServiceTest { distributedLock.close() } - private suspend fun executeScheduler(bluePrintClusterService: BluePrintClusterService) { + private suspend fun executeScheduler(bluePrintClusterService: BlueprintClusterService) { log.info("initialising ...") val hazelcastClusterService = bluePrintClusterService as HazelcastClusterService @@ -251,7 +251,7 @@ class HazelcastClusterServiceTest { // scheduler.scheduleOnAllMembersAtFixedRate(SampleSchedulerTask(), 0, 5, TimeUnit.SECONDS) } - private suspend fun printReachableMembers(bluePrintClusterServices: List) { + private suspend fun printReachableMembers(bluePrintClusterServices: List) { bluePrintClusterServices.forEach { bluePrintClusterService -> val hazelcastClusterService = bluePrintClusterService as HazelcastClusterService val hazelcast = hazelcastClusterService.hazelcast diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappingsTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappingsTest.kt deleted file mode 100644 index e8bdbf9ef..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappingsTest.kt +++ /dev/null @@ -1,137 +0,0 @@ -package org.onap.ccsdk.cds.blueprintsprocessor.core.utils - -import org.junit.Assert -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Flags -import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers -import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader -import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType -import org.onap.ccsdk.cds.controllerblueprints.common.api.Flag -import org.onap.ccsdk.cds.controllerblueprints.core.utils.currentTimestamp -import org.springframework.test.context.junit4.SpringRunner -import java.text.SimpleDateFormat - -@RunWith(SpringRunner::class) -class BluePrintMappingsTest { - - val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - val dateString = "2019-01-16T18:25:43.511Z" - val dateForTest = formatter.parse(dateString) - - val flag = Flag.newBuilder().setIsForce(false).setTtl(1).build() - - fun createFlag(): Flags { - val flag = Flags() - flag.isForce = false - flag.ttl = 1 - return flag - } - - @Test - fun flagToJavaTest() { - val flag2 = flag.toJava() - - Assert.assertEquals(flag.isForce, flag2.isForce) - Assert.assertEquals(flag.ttl, flag2.ttl) - } - - @Test - fun flagToProtoTest() { - val flag = createFlag() - val flag2 = flag.toProto() - - Assert.assertEquals(flag.isForce, flag2.isForce) - Assert.assertEquals(flag.ttl, flag2.ttl) - } - - fun createStatus(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status { - val status = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status() - status.code = 400 - status.errorMessage = "Concurrent modification exception" - status.eventType = EventType.EVENT_COMPONENT_PROCESSING.name - status.message = "Error uploading data" - status.timestamp = dateForTest - return status - } - - @Test - fun statusToProtoTest() { - val status = createStatus() - val status2 = status.toProto() - - Assert.assertEquals(status.code, status2.code) - Assert.assertEquals(status.errorMessage, status2.errorMessage) - Assert.assertEquals(status.eventType, status2.eventType.name) - Assert.assertEquals(status.message, status2.message) - Assert.assertEquals(status.timestamp.toString(), status2.timestamp) - } - - @Test - fun commonHeaderToJavaTest() { - val flag = Flag.newBuilder().setIsForce(true).setTtl(2).build() - - val commonHeader = - CommonHeader.newBuilder().setOriginatorId("Origin").setRequestId("requestID").setSubRequestId("subRequestID").setTimestamp(dateString) - .setFlag(flag).build() - val commonHeader2 = commonHeader.toJava() - - Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) - Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) - Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) - Assert.assertEquals(commonHeader.timestamp, formatter.format(commonHeader2.timestamp)) - } - - fun createCommonHeader(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader { - val commonHeader = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader() - commonHeader.flags = createFlag() - commonHeader.originatorId = "1234" - commonHeader.requestId = "2345" - commonHeader.subRequestId = "0123" - commonHeader.timestamp = dateForTest - return commonHeader - } - - @Test - fun commonHeaderToProtoTest() { - val commonHeader = createCommonHeader() - val commonHeader2 = commonHeader.toProto() - Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) - Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) - Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) - Assert.assertEquals(commonHeader.timestamp.currentTimestamp(), commonHeader2.timestamp) - } - - @Test - fun actionIdentifierToJavaTest() { - val actionIdentifiers = - ActionIdentifiers.newBuilder().setActionName("Process Action").setBlueprintName("BlueprintName").setBlueprintVersion("3.0") - .setMode("Execution").build() - val actionIdentifiers2 = actionIdentifiers.toJava() - - Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) - Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) - Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) - Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) - } - - fun createActionIdentifier(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers { - val ac = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers() - ac.mode = "mode" - ac.blueprintVersion = "version" - ac.blueprintName = "name" - ac.actionName = "action" - return ac - } - - @Test - fun actionIdentifierToProtoTest() { - val actionIdentifiers = createActionIdentifier() - val actionIdentifiers2 = actionIdentifiers.toProto() - - Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) - Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) - Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) - Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) - } -} diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BlueprintMappingsTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BlueprintMappingsTest.kt new file mode 100644 index 000000000..1549c9cdf --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BlueprintMappingsTest.kt @@ -0,0 +1,137 @@ +package org.onap.ccsdk.cds.blueprintsprocessor.core.utils + +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Flags +import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers +import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader +import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType +import org.onap.ccsdk.cds.controllerblueprints.common.api.Flag +import org.onap.ccsdk.cds.controllerblueprints.core.utils.currentTimestamp +import org.springframework.test.context.junit4.SpringRunner +import java.text.SimpleDateFormat + +@RunWith(SpringRunner::class) +class BlueprintMappingsTest { + + val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + val dateString = "2019-01-16T18:25:43.511Z" + val dateForTest = formatter.parse(dateString) + + val flag = Flag.newBuilder().setIsForce(false).setTtl(1).build() + + fun createFlag(): Flags { + val flag = Flags() + flag.isForce = false + flag.ttl = 1 + return flag + } + + @Test + fun flagToJavaTest() { + val flag2 = flag.toJava() + + Assert.assertEquals(flag.isForce, flag2.isForce) + Assert.assertEquals(flag.ttl, flag2.ttl) + } + + @Test + fun flagToProtoTest() { + val flag = createFlag() + val flag2 = flag.toProto() + + Assert.assertEquals(flag.isForce, flag2.isForce) + Assert.assertEquals(flag.ttl, flag2.ttl) + } + + fun createStatus(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status { + val status = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status() + status.code = 400 + status.errorMessage = "Concurrent modification exception" + status.eventType = EventType.EVENT_COMPONENT_PROCESSING.name + status.message = "Error uploading data" + status.timestamp = dateForTest + return status + } + + @Test + fun statusToProtoTest() { + val status = createStatus() + val status2 = status.toProto() + + Assert.assertEquals(status.code, status2.code) + Assert.assertEquals(status.errorMessage, status2.errorMessage) + Assert.assertEquals(status.eventType, status2.eventType.name) + Assert.assertEquals(status.message, status2.message) + Assert.assertEquals(status.timestamp.toString(), status2.timestamp) + } + + @Test + fun commonHeaderToJavaTest() { + val flag = Flag.newBuilder().setIsForce(true).setTtl(2).build() + + val commonHeader = + CommonHeader.newBuilder().setOriginatorId("Origin").setRequestId("requestID").setSubRequestId("subRequestID").setTimestamp(dateString) + .setFlag(flag).build() + val commonHeader2 = commonHeader.toJava() + + Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) + Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) + Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) + Assert.assertEquals(commonHeader.timestamp, formatter.format(commonHeader2.timestamp)) + } + + fun createCommonHeader(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader { + val commonHeader = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader() + commonHeader.flags = createFlag() + commonHeader.originatorId = "1234" + commonHeader.requestId = "2345" + commonHeader.subRequestId = "0123" + commonHeader.timestamp = dateForTest + return commonHeader + } + + @Test + fun commonHeaderToProtoTest() { + val commonHeader = createCommonHeader() + val commonHeader2 = commonHeader.toProto() + Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) + Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) + Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) + Assert.assertEquals(commonHeader.timestamp.currentTimestamp(), commonHeader2.timestamp) + } + + @Test + fun actionIdentifierToJavaTest() { + val actionIdentifiers = + ActionIdentifiers.newBuilder().setActionName("Process Action").setBlueprintName("BlueprintName").setBlueprintVersion("3.0") + .setMode("Execution").build() + val actionIdentifiers2 = actionIdentifiers.toJava() + + Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) + Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) + Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) + Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) + } + + fun createActionIdentifier(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers { + val ac = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers() + ac.mode = "mode" + ac.blueprintVersion = "version" + ac.blueprintName = "name" + ac.actionName = "action" + return ac + } + + @Test + fun actionIdentifierToProtoTest() { + val actionIdentifiers = createActionIdentifier() + val actionIdentifiers2 = actionIdentifiers.toProto() + + Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) + Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) + Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) + Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) + } +} 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 deleted file mode 100644 index 6e9e4b554..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 IBM. - * Modifications Copyright © 2019 Huawei. - * - * 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 com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService -import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService -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 - -/** - * Exposed Dependency Service by this Rest Lib Module - */ -fun BluePrintDependencyService.restLibPropertyService(): BluePrintRestLibPropertyService = - instance(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY) - -fun BluePrintDependencyService.restClientService(selector: String): BlueprintWebClientService { - return restLibPropertyService().blueprintWebClientService(selector) -} - -fun BluePrintDependencyService.restClientService(jsonNode: JsonNode): BlueprintWebClientService { - return restLibPropertyService().blueprintWebClientService(jsonNode) -} - -class RestLibConstants { - companion object { - - const val SERVICE_BLUEPRINT_REST_LIB_PROPERTY = "blueprint-rest-lib-property-service" - const val PROPERTY_REST_CLIENT_PREFIX = "blueprintsprocessor.restclient." - const val PROPERTY_TYPE = "type" - 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_SSL_TOKEN_AUTH = "ssl-token-auth" - const val TYPE_SSL_NO_AUTH = "ssl-no-auth" - const val TYPE_POLICY_MANAGER = "policy-manager" - } -} 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 deleted file mode 100644 index a227cf24e..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Huawei. - * Modifications 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.rest - -open class RestClientProperties { - - lateinit var type: String - lateinit var url: String - var additionalHeaders: Map? = null -} - -open class SSLRestClientProperties : RestClientProperties() { - - lateinit var keyStoreInstance: String // JKS, PKCS12 - lateinit var sslTrust: String - lateinit var sslTrustPassword: String - var sslTrustIgnoreHostname: Boolean = false - var sslKey: String? = null - var sslKeyPassword: String? = null -} - -// FIXME("Define basic auth userName and password properties") -open class SSLBasicAuthRestClientProperties : SSLRestClientProperties() { - - var basicAuth: BasicAuthRestClientProperties? = null -} - -// FIXME("Define token properties") -open class SSLTokenAuthRestClientProperties : SSLRestClientProperties() { - - var tokenAuth: TokenAuthRestClientProperties? = null -} - -open class BasicAuthRestClientProperties : RestClientProperties() { - - lateinit var password: String - lateinit var username: String -} - -open class TokenAuthRestClientProperties : RestClientProperties() { - - var token: String? = null -} - -open class PolicyManagerRestClientProperties : RestClientProperties() { - - lateinit var env: String - lateinit var clientAuth: String - lateinit var authorisation: String -} 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..701fd172f --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BlueprintRestLibConfiguration.kt @@ -0,0 +1,61 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. + * Modifications Copyright © 2019 Huawei. + * + * 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 com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintRestLibPropertyService +import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintDependencyService +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 + +/** + * Exposed Dependency Service by this Rest Lib Module + */ +fun BlueprintDependencyService.restLibPropertyService(): BlueprintRestLibPropertyService = + instance(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY) + +fun BlueprintDependencyService.restClientService(selector: String): BlueprintWebClientService { + return restLibPropertyService().blueprintWebClientService(selector) +} + +fun BlueprintDependencyService.restClientService(jsonNode: JsonNode): BlueprintWebClientService { + return restLibPropertyService().blueprintWebClientService(jsonNode) +} + +class RestLibConstants { + companion object { + + const val SERVICE_BLUEPRINT_REST_LIB_PROPERTY = "blueprint-rest-lib-property-service" + const val PROPERTY_REST_CLIENT_PREFIX = "blueprintsprocessor.restclient." + const val PROPERTY_TYPE = "type" + 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_SSL_TOKEN_AUTH = "ssl-token-auth" + const val TYPE_SSL_NO_AUTH = "ssl-no-auth" + const val TYPE_POLICY_MANAGER = "policy-manager" + } +} 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..a227cf24e --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BlueprintRestLibData.kt @@ -0,0 +1,66 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Huawei. + * Modifications 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.rest + +open class RestClientProperties { + + lateinit var type: String + lateinit var url: String + var additionalHeaders: Map? = null +} + +open class SSLRestClientProperties : RestClientProperties() { + + lateinit var keyStoreInstance: String // JKS, PKCS12 + lateinit var sslTrust: String + lateinit var sslTrustPassword: String + var sslTrustIgnoreHostname: Boolean = false + var sslKey: String? = null + var sslKeyPassword: String? = null +} + +// FIXME("Define basic auth userName and password properties") +open class SSLBasicAuthRestClientProperties : SSLRestClientProperties() { + + var basicAuth: BasicAuthRestClientProperties? = null +} + +// FIXME("Define token properties") +open class SSLTokenAuthRestClientProperties : SSLRestClientProperties() { + + var tokenAuth: TokenAuthRestClientProperties? = null +} + +open class BasicAuthRestClientProperties : RestClientProperties() { + + lateinit var password: String + lateinit var username: String +} + +open class TokenAuthRestClientProperties : RestClientProperties() { + + var token: String? = null +} + +open class PolicyManagerRestClientProperties : RestClientProperties() { + + lateinit var env: String + lateinit var clientAuth: String + lateinit var authorisation: String +} diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt index ca1046dde..45b9e3827 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt @@ -17,8 +17,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.rest import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintTypes import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType @@ -30,25 +30,25 @@ import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType /** Relationships Type DSL for Rest */ fun ServiceTemplateBuilder.relationshipTypeConnectsToRestClient() { - val relationshipType = BluePrintTypes.relationshipTypeConnectsToRestClient() + val relationshipType = BlueprintTypes.relationshipTypeConnectsToRestClient() if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() this.relationshipTypes!![relationshipType.id!!] = relationshipType } -fun BluePrintTypes.relationshipTypeConnectsToRestClient(): RelationshipType { +fun BlueprintTypes.relationshipTypeConnectsToRestClient(): RelationshipType { return relationshipType( - id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT, - version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, + id = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT, + version = BlueprintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, description = "Relationship connects to through" ) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintConstants.DATA_TYPE_MAP, + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintConstants.DATA_TYPE_MAP, true, "Connection Config details." ) - validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) + validTargetTypes(arrayListOf(BlueprintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) } } @@ -66,35 +66,35 @@ fun TopologyTemplateBuilder.relationshipTemplateRestClient( open class RestClientRelationshipTemplateBuilder(name: String, description: String) : RelationshipTemplateBuilder( name, - BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT, description + BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT, description ) { fun basicAuth(block: BasicAuthRestClientPropertiesAssignmentBuilder.() -> Unit) { - property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.basicAuthRestClientProperties(block)) + property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.basicAuthRestClientProperties(block)) } fun tokenAuth(block: TokenAuthRestClientPropertiesAssignmentBuilder.() -> Unit) { - property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tokenAuthRestClientProperties(block)) + property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.tokenAuthRestClientProperties(block)) } fun sslAuth(block: SslAuthRestClientPropertiesAssignmentBuilder.() -> Unit) { - property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.sslRestClientProperties(block)) + property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.sslRestClientProperties(block)) } } -fun BluePrintTypes.basicAuthRestClientProperties(block: BasicAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.basicAuthRestClientProperties(block: BasicAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = BasicAuthRestClientPropertiesAssignmentBuilder().apply(block).build() assignments[RestClientProperties::type.name] = RestLibConstants.TYPE_BASIC_AUTH.asJsonPrimitive() return assignments.asJsonType() } -fun BluePrintTypes.tokenAuthRestClientProperties(block: TokenAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.tokenAuthRestClientProperties(block: TokenAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = TokenAuthRestClientPropertiesAssignmentBuilder().apply(block).build() assignments[RestClientProperties::type.name] = RestLibConstants.TYPE_TOKEN_AUTH.asJsonPrimitive() return assignments.asJsonType() } -fun BluePrintTypes.sslRestClientProperties(block: SslAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.sslRestClientProperties(block: SslAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = SslAuthRestClientPropertiesAssignmentBuilder().apply(block).build() assignments[RestClientProperties::type.name] = RestLibConstants.TYPE_SSL_NO_AUTH.asJsonPrimitive() return assignments.asJsonType() 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 deleted file mode 100644 index a2c68ec68..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright © 2017-2019 AT&T, Bell Canada - * Modifications Copyright © 2019 IBM. - * Modifications Copyright © 2019 Huawei. - * - * 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.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties -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.SSLRestClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLTokenAuthRestClientProperties -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 bluePrintPropertiesService: BluePrintPropertiesService) { - - private var preInterceptor: PreInterceptor? = null - private var postInterceptor: PostInterceptor? = null - - fun setInterceptors(preInterceptor: PreInterceptor?, postInterceptor: PostInterceptor?) { - this.preInterceptor = preInterceptor - this.postInterceptor = postInterceptor - } - - fun clearInterceptors() { - this.preInterceptor = null - this.postInterceptor = null - } - - open fun blueprintWebClientService(jsonNode: JsonNode): BlueprintWebClientService { - val service = preInterceptor?.getInstance(jsonNode) - ?: blueprintWebClientService(restClientProperties(jsonNode)) - return postInterceptor?.getInstance(jsonNode, service) ?: service - } - - open fun blueprintWebClientService(selector: String): BlueprintWebClientService { - val service = preInterceptor?.getInstance(selector) ?: run { - val prefix = "blueprintsprocessor.restclient.$selector" - val restClientProperties = restClientProperties(prefix) - blueprintWebClientService(restClientProperties) - } - return postInterceptor?.getInstance(selector, service) ?: service - } - - fun restClientProperties(prefix: String): RestClientProperties { - val type = bluePrintPropertiesService.propertyBeanType( - "$prefix.type", String::class.java - ) - return when (type) { - RestLibConstants.TYPE_BASIC_AUTH -> { - basicAuthRestClientProperties(prefix) - } - RestLibConstants.TYPE_TOKEN_AUTH -> { - tokenRestClientProperties(prefix) - } - RestLibConstants.TYPE_SSL_BASIC_AUTH -> { - sslBasicAuthRestClientProperties(prefix) - } - RestLibConstants.TYPE_SSL_TOKEN_AUTH -> { - sslTokenAuthRestClientProperties(prefix) - } - RestLibConstants.TYPE_SSL_NO_AUTH -> { - sslNoAuthRestClientProperties(prefix) - } - - RestLibConstants.TYPE_POLICY_MANAGER -> { - policyManagerRestClientProperties(prefix) - } - else -> { - throw BluePrintProcessorException( - "Rest adaptor($type) is" + - " not supported" - ) - } - } - } - - 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_POLICY_MANAGER -> { - JacksonUtils.readValue(jsonNode, PolicyManagerRestClientProperties::class.java)!! - } - RestLibConstants.TYPE_SSL_BASIC_AUTH -> { - JacksonUtils.readValue(jsonNode, SSLBasicAuthRestClientProperties::class.java)!! - } - RestLibConstants.TYPE_SSL_TOKEN_AUTH -> { - JacksonUtils.readValue(jsonNode, SSLTokenAuthRestClientProperties::class.java)!! - } - RestLibConstants.TYPE_SSL_NO_AUTH -> { - JacksonUtils.readValue(jsonNode, SSLRestClientProperties::class.java)!! - } - else -> { - throw BluePrintProcessorException( - "Rest adaptor($type) is not supported" - ) - } - } - } - - private fun blueprintWebClientService(restClientProperties: RestClientProperties): - BlueprintWebClientService { - - when (restClientProperties) { - is SSLRestClientProperties -> { - return SSLRestClientService(restClientProperties) - } - is TokenAuthRestClientProperties -> { - return TokenAuthRestClientService(restClientProperties) - } - is BasicAuthRestClientProperties -> { - return BasicAuthRestClientService(restClientProperties) - } - else -> { - throw BluePrintProcessorException("couldn't get rest service for type:${restClientProperties.type} uri: ${restClientProperties.url}") - } - } - } - - private fun tokenRestClientProperties(prefix: String): - TokenAuthRestClientProperties { - return bluePrintPropertiesService.propertyBeanType( - prefix, TokenAuthRestClientProperties::class.java - ) - } - - private fun basicAuthRestClientProperties(prefix: String): - BasicAuthRestClientProperties { - return bluePrintPropertiesService.propertyBeanType( - prefix, BasicAuthRestClientProperties::class.java - ) - } - - private fun sslBasicAuthRestClientProperties(prefix: String): - SSLRestClientProperties { - - val sslProps: SSLBasicAuthRestClientProperties = - bluePrintPropertiesService.propertyBeanType( - prefix, SSLBasicAuthRestClientProperties::class.java - ) - val basicProps: BasicAuthRestClientProperties = - bluePrintPropertiesService.propertyBeanType( - prefix, BasicAuthRestClientProperties::class.java - ) - sslProps.basicAuth = basicProps - return sslProps - } - - private fun sslTokenAuthRestClientProperties(prefix: String): - SSLRestClientProperties { - - val sslProps: SSLTokenAuthRestClientProperties = - bluePrintPropertiesService.propertyBeanType( - prefix, - SSLTokenAuthRestClientProperties::class.java - ) - val basicProps: TokenAuthRestClientProperties = - bluePrintPropertiesService.propertyBeanType( - prefix, - TokenAuthRestClientProperties::class.java - ) - sslProps.tokenAuth = basicProps - return sslProps - } - - private fun sslNoAuthRestClientProperties(prefix: String): - SSLRestClientProperties { - return bluePrintPropertiesService.propertyBeanType( - prefix, SSLRestClientProperties::class.java - ) - } - - private fun policyManagerRestClientProperties(prefix: String): - PolicyManagerRestClientProperties { - return bluePrintPropertiesService.propertyBeanType( - prefix, PolicyManagerRestClientProperties::class.java - ) - } - - interface PreInterceptor { - - fun getInstance(jsonNode: JsonNode): BlueprintWebClientService? - - fun getInstance(selector: String): BlueprintWebClientService? - } - - interface PostInterceptor { - - fun getInstance(jsonNode: JsonNode, service: BlueprintWebClientService): BlueprintWebClientService - - fun getInstance(selector: String, service: BlueprintWebClientService): BlueprintWebClientService - } -} 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..d28bd77db --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintRestLibPropertyService.kt @@ -0,0 +1,222 @@ +/* + * Copyright © 2017-2019 AT&T, Bell Canada + * Modifications Copyright © 2019 IBM. + * Modifications Copyright © 2019 Huawei. + * + * 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.BlueprintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties +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.SSLRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLTokenAuthRestClientProperties +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 bluePrintPropertiesService: BlueprintPropertiesService) { + + private var preInterceptor: PreInterceptor? = null + private var postInterceptor: PostInterceptor? = null + + fun setInterceptors(preInterceptor: PreInterceptor?, postInterceptor: PostInterceptor?) { + this.preInterceptor = preInterceptor + this.postInterceptor = postInterceptor + } + + fun clearInterceptors() { + this.preInterceptor = null + this.postInterceptor = null + } + + open fun blueprintWebClientService(jsonNode: JsonNode): BlueprintWebClientService { + val service = preInterceptor?.getInstance(jsonNode) + ?: blueprintWebClientService(restClientProperties(jsonNode)) + return postInterceptor?.getInstance(jsonNode, service) ?: service + } + + open fun blueprintWebClientService(selector: String): BlueprintWebClientService { + val service = preInterceptor?.getInstance(selector) ?: run { + val prefix = "blueprintsprocessor.restclient.$selector" + val restClientProperties = restClientProperties(prefix) + blueprintWebClientService(restClientProperties) + } + return postInterceptor?.getInstance(selector, service) ?: service + } + + fun restClientProperties(prefix: String): RestClientProperties { + val type = bluePrintPropertiesService.propertyBeanType( + "$prefix.type", String::class.java + ) + return when (type) { + RestLibConstants.TYPE_BASIC_AUTH -> { + basicAuthRestClientProperties(prefix) + } + RestLibConstants.TYPE_TOKEN_AUTH -> { + tokenRestClientProperties(prefix) + } + RestLibConstants.TYPE_SSL_BASIC_AUTH -> { + sslBasicAuthRestClientProperties(prefix) + } + RestLibConstants.TYPE_SSL_TOKEN_AUTH -> { + sslTokenAuthRestClientProperties(prefix) + } + RestLibConstants.TYPE_SSL_NO_AUTH -> { + sslNoAuthRestClientProperties(prefix) + } + + RestLibConstants.TYPE_POLICY_MANAGER -> { + policyManagerRestClientProperties(prefix) + } + else -> { + throw BlueprintProcessorException( + "Rest adaptor($type) is" + + " not supported" + ) + } + } + } + + 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_POLICY_MANAGER -> { + JacksonUtils.readValue(jsonNode, PolicyManagerRestClientProperties::class.java)!! + } + RestLibConstants.TYPE_SSL_BASIC_AUTH -> { + JacksonUtils.readValue(jsonNode, SSLBasicAuthRestClientProperties::class.java)!! + } + RestLibConstants.TYPE_SSL_TOKEN_AUTH -> { + JacksonUtils.readValue(jsonNode, SSLTokenAuthRestClientProperties::class.java)!! + } + RestLibConstants.TYPE_SSL_NO_AUTH -> { + JacksonUtils.readValue(jsonNode, SSLRestClientProperties::class.java)!! + } + else -> { + throw BlueprintProcessorException( + "Rest adaptor($type) is not supported" + ) + } + } + } + + private fun blueprintWebClientService(restClientProperties: RestClientProperties): + BlueprintWebClientService { + + when (restClientProperties) { + is SSLRestClientProperties -> { + return SSLRestClientService(restClientProperties) + } + is TokenAuthRestClientProperties -> { + return TokenAuthRestClientService(restClientProperties) + } + is BasicAuthRestClientProperties -> { + return BasicAuthRestClientService(restClientProperties) + } + else -> { + throw BlueprintProcessorException("couldn't get rest service for type:${restClientProperties.type} uri: ${restClientProperties.url}") + } + } + } + + private fun tokenRestClientProperties(prefix: String): + TokenAuthRestClientProperties { + return bluePrintPropertiesService.propertyBeanType( + prefix, TokenAuthRestClientProperties::class.java + ) + } + + private fun basicAuthRestClientProperties(prefix: String): + BasicAuthRestClientProperties { + return bluePrintPropertiesService.propertyBeanType( + prefix, BasicAuthRestClientProperties::class.java + ) + } + + private fun sslBasicAuthRestClientProperties(prefix: String): + SSLRestClientProperties { + + val sslProps: SSLBasicAuthRestClientProperties = + bluePrintPropertiesService.propertyBeanType( + prefix, SSLBasicAuthRestClientProperties::class.java + ) + val basicProps: BasicAuthRestClientProperties = + bluePrintPropertiesService.propertyBeanType( + prefix, BasicAuthRestClientProperties::class.java + ) + sslProps.basicAuth = basicProps + return sslProps + } + + private fun sslTokenAuthRestClientProperties(prefix: String): + SSLRestClientProperties { + + val sslProps: SSLTokenAuthRestClientProperties = + bluePrintPropertiesService.propertyBeanType( + prefix, + SSLTokenAuthRestClientProperties::class.java + ) + val basicProps: TokenAuthRestClientProperties = + bluePrintPropertiesService.propertyBeanType( + prefix, + TokenAuthRestClientProperties::class.java + ) + sslProps.tokenAuth = basicProps + return sslProps + } + + private fun sslNoAuthRestClientProperties(prefix: String): + SSLRestClientProperties { + return bluePrintPropertiesService.propertyBeanType( + prefix, SSLRestClientProperties::class.java + ) + } + + private fun policyManagerRestClientProperties(prefix: String): + PolicyManagerRestClientProperties { + return bluePrintPropertiesService.propertyBeanType( + prefix, PolicyManagerRestClientProperties::class.java + ) + } + + interface PreInterceptor { + + fun getInstance(jsonNode: JsonNode): BlueprintWebClientService? + + fun getInstance(selector: String): BlueprintWebClientService? + } + + interface PostInterceptor { + + fun getInstance(jsonNode: JsonNode, service: BlueprintWebClientService): BlueprintWebClientService + + fun getInstance(selector: String, service: BlueprintWebClientService): BlueprintWebClientService + } +} 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 index 945d29850..43dbcbeb2 100644 --- 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 @@ -36,9 +36,9 @@ import org.apache.http.message.BasicHeader import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestClientProperties import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestLibConstants import org.onap.ccsdk.cds.blueprintsprocessor.rest.utils.WebClientUtils -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintRetryException -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintIOUtils +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintRetryException +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BlueprintIOUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.springframework.http.HttpHeaders import org.springframework.http.HttpMethod @@ -59,7 +59,7 @@ interface BlueprintWebClientService { .build() } - /** High performance non blocking Retry function, If execution block [block] throws BluePrintRetryException + /** High performance non blocking Retry function, If execution block [block] throws BlueprintRetryException * exception then this will perform wait and retrigger accoring to times [times] with delay [delay] */ suspend fun retry( @@ -69,11 +69,11 @@ interface BlueprintWebClientService { block: suspend (Int) -> T ): T { val exceptionBlock = { e: Exception -> - if (e !is BluePrintRetryException) { + if (e !is BlueprintRetryException) { throw e } } - return BluePrintIOUtils.retry(times, initialDelay, delay, block, exceptionBlock) + return BlueprintIOUtils.retry(times, initialDelay, delay, block, exceptionBlock) } fun exchangeResource(methodType: String, path: String, request: String): WebClientResponse { @@ -98,7 +98,7 @@ interface BlueprintWebClientService { HttpMethod.POST -> post(path, request, convertedHeaders, String::class.java) HttpMethod.PUT -> put(path, request, convertedHeaders, String::class.java) HttpMethod.PATCH -> patch(path, request, convertedHeaders, String::class.java) - else -> throw BluePrintProcessorException( + else -> throw BlueprintProcessorException( "Unsupported methodType($methodType) attempted on path($path)" ) } @@ -270,7 +270,7 @@ interface BlueprintWebClientService { HttpMethod.DELETE -> deleteNB(path, convertedHeaders, responseType) HttpMethod.PUT -> putNB(path, request, convertedHeaders, responseType) HttpMethod.PATCH -> patchNB(path, request, convertedHeaders, responseType) - else -> throw BluePrintProcessorException("Unsupported methodType($methodType)") + else -> throw BlueprintProcessorException("Unsupported methodType($methodType)") } } @@ -323,7 +323,7 @@ interface BlueprintWebClientService { " User-supplied \"additionalHeaders\" cannot contain AUTHORIZATION header with" + " auth-type \"${RestLibConstants.TYPE_BASIC_AUTH}\"" WebClientUtils.log.error(errMsg) - throw BluePrintProcessorException(errMsg) + throw BlueprintProcessorException(errMsg) } else { customHeaders.putAll(it) } diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt index 611c0855d..8c7ba6573 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt @@ -29,12 +29,12 @@ import kotlinx.coroutines.reactor.ReactorContext import kotlinx.coroutines.reactor.asCoroutineContext import kotlinx.coroutines.withContext import org.apache.http.message.BasicHeader -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_INVOCATION_ID -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_ORIGINATOR_ID -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_PARTNER_NAME -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_REQUEST_ID -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_SUBREQUEST_ID +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants.ONAP_INVOCATION_ID +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants.ONAP_ORIGINATOR_ID +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants.ONAP_PARTNER_NAME +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants.ONAP_REQUEST_ID +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants.ONAP_SUBREQUEST_ID import org.onap.ccsdk.cds.controllerblueprints.core.MDCContext import org.onap.ccsdk.cds.controllerblueprints.core.defaultToEmpty import org.onap.ccsdk.cds.controllerblueprints.core.defaultToUUID @@ -65,7 +65,7 @@ class RestLoggerService { fun httpInvoking(headers: Array) { headers.plusElement(BasicHeader(ONAP_REQUEST_ID, MDC.get("InvocationID").defaultToUUID())) headers.plusElement(BasicHeader(ONAP_INVOCATION_ID, UUID.randomUUID().toString())) - headers.plusElement(BasicHeader(ONAP_PARTNER_NAME, BluePrintConstants.APP_NAME)) + headers.plusElement(BasicHeader(ONAP_PARTNER_NAME, BlueprintConstants.APP_NAME)) } } @@ -98,7 +98,7 @@ class RestLoggerService { resHeaders[ONAP_SUBREQUEST_ID] = MDC.get("SubRequestID") resHeaders[ONAP_ORIGINATOR_ID] = MDC.get("OriginatorID") resHeaders[ONAP_INVOCATION_ID] = MDC.get("InvocationID") - resHeaders[ONAP_PARTNER_NAME] = BluePrintConstants.APP_NAME + resHeaders[ONAP_PARTNER_NAME] = BlueprintConstants.APP_NAME } catch (e: Exception) { log.warn("couldn't set response headers", e) } finally { 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 deleted file mode 100644 index f45d1cd69..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt +++ /dev/null @@ -1,532 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * Modifications Copyright © 2019 Huawei. - * Modifications 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.rest.service - -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.ObjectMapper -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.rest.BluePrintRestLibConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLBasicAuthRestClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLRestClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLTokenAuthRestClientProperties -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.http.HttpHeaders -import org.springframework.http.MediaType -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import kotlin.test.assertEquals -import kotlin.test.assertFailsWith -import kotlin.test.assertNotNull - -@RunWith(SpringRunner::class) -@ContextConfiguration( - classes = [ - BluePrintRestLibConfiguration::class, BluePrintPropertyConfiguration::class, - BluePrintPropertiesService::class - ] -) -@TestPropertySource( - properties = - [ - "blueprintsprocessor.restclient.sample.type=basic-auth", - "blueprintsprocessor.restclient.sample.url=http://localhost:8080", - "blueprintsprocessor.restclient.sample.userId=sampleuser", - "blueprintsprocessor.restclient.sslbasic.type=ssl-basic-auth", - "blueprintsprocessor.restclient.sslbasic.url=https://localhost:8443", - "blueprintsprocessor.restclient.sslbasic.username=admin", - "blueprintsprocessor.restclient.sslbasic.password=cds", - "blueprintsprocessor.restclient.sslbasic.keyStoreInstance=PKCS12", - "blueprintsprocessor.restclient.sslbasic.sslTrust=src/test/resources/keystore.p12", - "blueprintsprocessor.restclient.sslbasic.sslTrustPassword=changeit", - "blueprintsprocessor.restclient.ssltoken.type=ssl-token-auth", - "blueprintsprocessor.restclient.ssltoken.url=https://localhost:8443", - "blueprintsprocessor.restclient.ssltoken.token=72178473kjshdkjgvbsdkjv903274908", - "blueprintsprocessor.restclient.ssltoken.keyStoreInstance=PKCS12", - "blueprintsprocessor.restclient.ssltoken.sslTrust=src/test/resources/keystore.p12", - "blueprintsprocessor.restclient.ssltoken.sslTrustPassword=changeit", - "blueprintsprocessor.restclient.ssl.type=ssl-no-auth", - "blueprintsprocessor.restclient.ssl.url=https://localhost:8443", - "blueprintsprocessor.restclient.ssl.keyStoreInstance=PKCS12", - "blueprintsprocessor.restclient.ssl.sslTrust=src/test/resources/keystore.p12", - "blueprintsprocessor.restclient.ssl.sslTrustPassword=changeit", - "blueprintsprocessor.restclient.ssl.sslKey=src/test/resources/keystore.p12", - "blueprintsprocessor.restclient.ssl.sslKeyPassword=changeit" - ] -) -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 testSSLBasicProperties() { - val properties = bluePrintRestLibPropertyService.restClientProperties( - "blueprintsprocessor.restclient.sslbasic" - ) - assertNotNull(properties, "failed to create property bean") - val p: SSLBasicAuthRestClientProperties = - properties as SSLBasicAuthRestClientProperties - - assertEquals(p.basicAuth!!.username, "admin") - assertEquals(p.basicAuth!!.password, "cds") - assertEquals(p.sslTrust, "src/test/resources/keystore.p12") - assertEquals(p.sslTrustPassword, "changeit") - assertEquals(p.keyStoreInstance, "PKCS12") - } - - @Test - fun testSSLTokenProperties() { - val properties = bluePrintRestLibPropertyService.restClientProperties( - "blueprintsprocessor.restclient.ssltoken" - ) - assertNotNull(properties, "failed to create property bean") - - val p: SSLTokenAuthRestClientProperties = - properties as SSLTokenAuthRestClientProperties - - assertEquals(p.tokenAuth!!.token!!, "72178473kjshdkjgvbsdkjv903274908") - assertEquals(p.sslTrust, "src/test/resources/keystore.p12") - assertEquals(p.sslTrustPassword, "changeit") - assertEquals(p.keyStoreInstance, "PKCS12") - } - - @Test - fun testSSLNoAuthProperties() { - val properties = bluePrintRestLibPropertyService.restClientProperties( - "blueprintsprocessor.restclient.ssl" - ) - assertNotNull(properties, "failed to create property bean") - - val p: SSLRestClientProperties = - properties as SSLRestClientProperties - - assertEquals(p.sslTrust, "src/test/resources/keystore.p12") - assertEquals(p.sslTrustPassword, "changeit") - assertEquals(p.keyStoreInstance, "PKCS12") - assertEquals(p.sslKey, "src/test/resources/keystore.p12") - assertEquals(p.sslKeyPassword, "changeit") - } - - @Test - fun testSSLBasicPropertiesAsJson() { - val actualObj: JsonNode = defaultMapper.readTree(sslBasicAuthEndpointWithHeadersField()) - val properties = bluePrintRestLibPropertyService.restClientProperties( - actualObj - ) - assertNotNull(properties, "failed to create property bean") - val p: SSLBasicAuthRestClientProperties = properties as SSLBasicAuthRestClientProperties - - assertEquals("admin", p.basicAuth!!.username) - assertEquals("cds", p.basicAuth!!.password) - assertEquals("src/test/resources/keystore.p12", p.sslTrust) - assertEquals("changeit", p.sslTrustPassword) - assertEquals("PKCS12", p.keyStoreInstance) - assertEquals("ssl-basic-auth", p.type) - assertEquals("https://localhost:8443", p.url) - } - - @Test - fun testSSLTokenPropertiesAsJson() { - val actualObj: JsonNode = defaultMapper.readTree(sslTokenAuthEndpointWithHeadersField()) - val properties = - bluePrintRestLibPropertyService.restClientProperties(actualObj) - assertNotNull(properties, "failed to create property bean") - - val p: SSLTokenAuthRestClientProperties = properties as SSLTokenAuthRestClientProperties - - assertEquals("72178473kjshdkjgvbsdkjv903274908", p.tokenAuth!!.token!!) - assertEquals("src/test/resources/keystore.p12", p.sslTrust) - assertEquals("changeit", p.sslTrustPassword) - assertEquals("PKCS12", p.keyStoreInstance) - assertEquals("ssl-token-auth", p.type) - assertEquals("https://localhost:8443", p.url) - } - - @Test - fun testSSLNoAuthPropertiesAsJson() { - val actualObj: JsonNode = defaultMapper.readTree(sslNoAuthEndpointWithHeadersField()) - val properties = bluePrintRestLibPropertyService.restClientProperties( - actualObj - ) - assertNotNull(properties, "failed to create property bean") - - val p: SSLRestClientProperties = - properties as SSLRestClientProperties - - assertEquals("src/test/resources/keystore.p12", p.sslTrust) - assertEquals("changeit", p.sslTrustPassword) - assertEquals("PKCS12", p.keyStoreInstance) - assertEquals("src/test/resources/keystore.p12", p.sslKey) - assertEquals("changeit", p.sslKeyPassword) - assertEquals("ssl-no-auth", p.type) - assertEquals("https://localhost:8443", p.url) - } - - @Test - fun testBlueprintWebClientService() { - val blueprintWebClientService = bluePrintRestLibPropertyService - .blueprintWebClientService("sample") - assertNotNull( - blueprintWebClientService, - "failed to create blueprintWebClientService" - ) - } - - @Test - fun testBlueprintWebClientServiceWithJsonNode() { - val actualObj: JsonNode = defaultMapper.readTree(sslBasicAuthEndpointWithHeadersField()) - val blueprintWebClientService = bluePrintRestLibPropertyService - .blueprintWebClientService(actualObj) - assertNotNull(blueprintWebClientService, "failed to create blueprintWebClientService") - } - - // pass the result of $typeEndpointWithHeadersField() output with and without headers to compare. - private fun validateHeadersDidNotChangeWithEmptyAdditionalHeaders(noHeaders: String, withHeaders: String) { - val parsedObj: JsonNode = defaultMapper.readTree(noHeaders) - val bpWebClientService = - bluePrintRestLibPropertyService.blueprintWebClientService(parsedObj) - val extractedHeaders = bpWebClientService.convertToBasicHeaders(mapOf()) - - val parsedObjWithHeaders: JsonNode = defaultMapper.readTree(withHeaders) - val bpWebClientServiceWithHeaders = - bluePrintRestLibPropertyService.blueprintWebClientService(parsedObjWithHeaders) - val extractedHeadersWithAdditionalHeaders = bpWebClientServiceWithHeaders.convertToBasicHeaders(mapOf()) - // Array> -> Map - val headersMap = extractedHeaders.map { it.name to it.value }.toMap() - val additionalHeadersMap = extractedHeadersWithAdditionalHeaders.map { it.name to it.value }.toMap() - assertEquals(headersMap, additionalHeadersMap) - } - - @Test - fun `BasicAuth WebClientService with empty additionalHeaders does not modify headers`() { - val endPointJson = basicAuthEndpointWithHeadersField() - val endPointWithHeadersJson = basicAuthEndpointWithHeadersField(emptyAdditionalHeaders) - validateHeadersDidNotChangeWithEmptyAdditionalHeaders(endPointJson, endPointWithHeadersJson) - } - - private fun acceptsOneAdditionalHeadersTest(endPointWithHeadersJson: String) { - val parsedObj: JsonNode = defaultMapper.readTree(endPointWithHeadersJson) - val bpWebClientService = - bluePrintRestLibPropertyService.blueprintWebClientService(parsedObj) - val extractedHeaders = bpWebClientService.convertToBasicHeaders(mapOf()) - assertEquals(1, extractedHeaders.filter { it.name == "key1" }.count()) - } - - @Test - fun `BasicAuth WebClientService accepts one additionalHeaders`() { - val endPointWithHeadersJson = basicAuthEndpointWithHeadersField(oneAdditionalParameter) - acceptsOneAdditionalHeadersTest(endPointWithHeadersJson) - } - - private fun acceptsMultipleAdditionalHeaders(endPointWithHeadersJson: String) { - val parsedObj: JsonNode = defaultMapper.readTree(endPointWithHeadersJson) - val bpWebClientService = - bluePrintRestLibPropertyService.blueprintWebClientService(parsedObj) - val extractedHeaders = bpWebClientService.convertToBasicHeaders(mapOf()) - assertEquals(1, extractedHeaders.filter { it.name == "key1" }.count()) - assertEquals(1, extractedHeaders.filter { it.name == "key2" }.count()) - assertEquals(1, extractedHeaders.filter { it.name == "key3" }.count()) - } - - @Test - fun `BasicAuth WebClientService accepts multiple additionalHeaders`() { - val endPointWithHeadersJson = basicAuthEndpointWithHeadersField(threeAdditionalHeaders) - acceptsMultipleAdditionalHeaders(endPointWithHeadersJson) - } - - private fun additionalHeadersChangedContentTypeToAPPLICATION_XML(endPointWithHeadersJson: String) { - val parsedObj: JsonNode = defaultMapper.readTree(endPointWithHeadersJson) - val bpWebClientService = - bluePrintRestLibPropertyService.blueprintWebClientService(parsedObj) - val extractedHeaders = bpWebClientService.convertToBasicHeaders(mapOf()) - assertEquals( - MediaType.APPLICATION_XML.toString(), - extractedHeaders.filter { it.name == HttpHeaders.CONTENT_TYPE }[0].value!! - ) - } - - @Test - fun `BasicAuth WebClientService additionalHeaders can overwrite default Content-Type`() { - // default content type is application/json - val endPointWithHeadersJson = basicAuthEndpointWithHeadersField(contentTypeAdditionalHeader) - additionalHeadersChangedContentTypeToAPPLICATION_XML(endPointWithHeadersJson) - } - - // called from within "assertFailsWith(exceptionClass = BluePrintProcessorException::class) {" - private fun attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson: String) { - val parsedObj: JsonNode = defaultMapper.readTree(endPointWithHeadersJson) - val bpWebClientService = - bluePrintRestLibPropertyService.blueprintWebClientService(parsedObj) - bpWebClientService.convertToBasicHeaders(mapOf()) - } - - @Test - fun `BasicAuth WebClientService throws BlueprintProcessorException if additionalHeaders contain Authorization`() { - assertFailsWith(exceptionClass = BluePrintProcessorException::class) { - val endPointWithHeadersJson = basicAuthEndpointWithHeadersField(additionalHeadersWithAuth) - attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) - } - // spec says headers are case insensitive... - assertFailsWith(exceptionClass = BluePrintProcessorException::class) { - val endPointWithHeadersJson = basicAuthEndpointWithHeadersField(additionalHeadersWithAuthLowercased) - attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) - } - } - - @Test - fun `TokenAuth WebClientService with empty additionalHeaders does not modify headers`() { - val endPointJson = sslTokenAuthEndpointWithHeadersField() - val endPointWithHeadersJson = sslTokenAuthEndpointWithHeadersField(emptyAdditionalHeaders) - validateHeadersDidNotChangeWithEmptyAdditionalHeaders(endPointJson, endPointWithHeadersJson) - } - - @Test - fun `TokenAuth WebClientService accepts one additionalHeaders`() { - val endPointWithHeadersJson = sslTokenAuthEndpointWithHeadersField(oneAdditionalParameter) - acceptsOneAdditionalHeadersTest(endPointWithHeadersJson) - } - - @Test - fun `TokenAuth WebClientService accepts multiple additionalHeaders`() { - val endPointWithHeadersJson = sslTokenAuthEndpointWithHeadersField(threeAdditionalHeaders) - acceptsMultipleAdditionalHeaders(endPointWithHeadersJson) - } - - @Test - fun `TokenAuth WebClientService additionalHeaders can overwrite default Content-Type`() { - // default content type is application/json - val endPointWithHeadersJson = sslTokenAuthEndpointWithHeadersField(contentTypeAdditionalHeader) - additionalHeadersChangedContentTypeToAPPLICATION_XML(endPointWithHeadersJson) - } - - @Test - fun `TokenAuth WebClientService throws BlueprintProcessorException if additionalHeaders contain Authorization`() { - assertFailsWith(exceptionClass = BluePrintProcessorException::class) { - val endPointWithHeadersJson = sslTokenAuthEndpointWithHeadersField(additionalHeadersWithAuth) - attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) - } - // spec says headers are case insensitive... - assertFailsWith(exceptionClass = BluePrintProcessorException::class) { - val endPointWithHeadersJson = sslTokenAuthEndpointWithHeadersField(additionalHeadersWithAuthLowercased) - attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) - } - } - - // TESTS FOR SSL BASIC AUTH headers - @Test - fun `SSLBasicAuth WebClientService with empty additionalHeaders does not modify headers`() { - val endPointJson = sslBasicAuthEndpointWithHeadersField() - val endPointWithHeadersJson = sslBasicAuthEndpointWithHeadersField(emptyAdditionalHeaders) - validateHeadersDidNotChangeWithEmptyAdditionalHeaders(endPointJson, endPointWithHeadersJson) - } - - @Test - fun `SSLBasicAuth WebClientService accepts one additionalHeaders`() { - val endPointWithHeadersJson = sslBasicAuthEndpointWithHeadersField(oneAdditionalParameter) - acceptsOneAdditionalHeadersTest(endPointWithHeadersJson) - } - - @Test - fun `SSLBasicAuth WebClientService accepts multiple additionalHeaders`() { - val endPointWithHeadersJson = sslBasicAuthEndpointWithHeadersField(threeAdditionalHeaders) - acceptsMultipleAdditionalHeaders(endPointWithHeadersJson) - } - - @Test - fun `SSLBasicAuth WebClientService additionalHeaders can overwrite default Content-Type`() { - // default content type is application/json - val endPointWithHeadersJson = sslBasicAuthEndpointWithHeadersField(contentTypeAdditionalHeader) - additionalHeadersChangedContentTypeToAPPLICATION_XML(endPointWithHeadersJson) - } - - @Test - fun `SSLBasicAuth WebClientService throws BlueprintProcessorException if additionalHeaders contain Authorization`() { - assertFailsWith(exceptionClass = BluePrintProcessorException::class) { - val endPointWithHeadersJson = sslBasicAuthEndpointWithHeadersField(additionalHeadersWithAuth) - attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) - } - // spec says headers are case insensitive... - assertFailsWith(exceptionClass = BluePrintProcessorException::class) { - val endPointWithHeadersJson = sslBasicAuthEndpointWithHeadersField(additionalHeadersWithAuthLowercased) - attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) - } - } - - // SSL-NO-AUTH headers tests - @Test - fun `SSLNoAuth WebClientService with empty additionalHeaders does not modify headers`() { - val endPointJson = sslNoAuthEndpointWithHeadersField() - val endPointWithHeadersJson = sslNoAuthEndpointWithHeadersField(emptyAdditionalHeaders) - validateHeadersDidNotChangeWithEmptyAdditionalHeaders(endPointJson, endPointWithHeadersJson) - } - - @Test - fun `SSLNoAuth WebClientService accepts one additionalHeaders`() { - val endPointWithHeadersJson = sslNoAuthEndpointWithHeadersField(oneAdditionalParameter) - acceptsOneAdditionalHeadersTest(endPointWithHeadersJson) - } - - @Test - fun `SSLNoAuth WebClientService accepts multiple additionalHeaders`() { - val endPointWithHeadersJson = sslNoAuthEndpointWithHeadersField(threeAdditionalHeaders) - acceptsMultipleAdditionalHeaders(endPointWithHeadersJson) - } - - @Test - fun `SSLNoAuth WebClientService additionalHeaders can overwrite default Content-Type`() { - // default content type is application/json - val endPointWithHeadersJson = sslNoAuthEndpointWithHeadersField(contentTypeAdditionalHeader) - additionalHeadersChangedContentTypeToAPPLICATION_XML(endPointWithHeadersJson) - } - - @Test - fun `SSLNoAuth WebClientService throws BlueprintProcessorException if additionalHeaders contain Authorization`() { - assertFailsWith(exceptionClass = BluePrintProcessorException::class) { - val endPointWithHeadersJson = sslNoAuthEndpointWithHeadersField(additionalHeadersWithAuth) - attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) - } - // spec says headers are case insensitive... - assertFailsWith(exceptionClass = BluePrintProcessorException::class) { - val endPointWithHeadersJson = sslNoAuthEndpointWithHeadersField(additionalHeadersWithAuthLowercased) - attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) - } - } - - companion object BluePrintRestLibPropertyServiceTest { - - val defaultMapper = ObjectMapper() - val expectedTokenAuthDefaultHeaders = mapOf( - "Content-Type" to "application/json", - "Accept" to "application/json", - "Authorization" to "72178473kjshdkjgvbsdkjv903274908" - ) - - val endPointWithHeadersJsonWithBasicAuthHeader = basicAuthEndpointWithHeadersField( - """, - "additionalHeaders" : { - "authorization": "Basic aGF2ZTphbmljZWRheQo=" - } - """.trimIndent() - ) - - private fun sslTokenAuthEndpointWithHeadersField(headers: String = ""): String = - """{ - "type" : "ssl-token-auth", - "url" : "https://localhost:8443", - "keyStoreInstance" : "PKCS12", - "sslTrust" : "src/test/resources/keystore.p12", - "sslTrustPassword" : "changeit", - "tokenAuth" : { - "token" : "72178473kjshdkjgvbsdkjv903274908" - }$headers - } - """.trimIndent() - - private fun sslBasicAuthEndpointWithHeadersField(headers: String = ""): String = - """{ - "type" : "ssl-basic-auth", - "url" : "https://localhost:8443", - "keyStoreInstance" : "PKCS12", - "sslTrust" : "src/test/resources/keystore.p12", - "sslTrustPassword" : "changeit", - "basicAuth" : { - "username" : "admin", - "password" : "cds" - }$headers - } - """.trimIndent() - - private fun sslNoAuthEndpointWithHeadersField(headers: String = ""): String = """{ - "type" : "ssl-no-auth", - "url" : "https://localhost:8443", - "keyStoreInstance" : "PKCS12", - "sslTrust" : "src/test/resources/keystore.p12", - "sslTrustPassword" : "changeit", - "sslKey" : "src/test/resources/keystore.p12", - "sslKeyPassword" : "changeit"$headers - } - """.trimIndent() - - // Don't forget to supply "," as the first char to make valid JSON - private fun basicAuthEndpointWithHeadersField(headers: String = ""): String = - """{ - "type": "basic-auth", - "url": "http://127.0.0.1:8000", - "username": "user", - "password": "pass"$headers - } - """.trimIndent() - - private val emptyAdditionalHeaders = """, - "additionalHeaders" : { - } - """.trimIndent() - - private val oneAdditionalParameter = """, - "additionalHeaders" : { - "key1": "value1" - } - """.trimIndent() - - private val threeAdditionalHeaders = """, - "additionalHeaders" : { - "key1": "value1", - "key2": "value2", - "key3": "value3" - } - """.trimIndent() - - private val contentTypeAdditionalHeader = """, - "additionalHeaders" : { - "${HttpHeaders.CONTENT_TYPE}": "${MediaType.APPLICATION_XML}" - } - """.trimIndent() - - private val additionalHeadersWithAuth = """, - "additionalHeaders" : { - "Authorization": "Basic aGF2ZTphbmljZWRheQo=" - } - """.trimIndent() - - private val additionalHeadersWithAuthLowercased = """, - "additionalHeaders" : { - "authorization": "Basic aGF2ZTphbmljZWRheQo=" - } - """.trimIndent() - } -} 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..117fbbd25 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintRestLibPropertyServiceTest.kt @@ -0,0 +1,532 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * Modifications Copyright © 2019 Huawei. + * Modifications 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.rest.service + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.ObjectMapper +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.rest.BlueprintRestLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLBasicAuthRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLTokenAuthRestClientProperties +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.http.HttpHeaders +import org.springframework.http.MediaType +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration( + classes = [ + BlueprintRestLibConfiguration::class, BlueprintPropertyConfiguration::class, + BlueprintPropertiesService::class + ] +) +@TestPropertySource( + properties = + [ + "blueprintsprocessor.restclient.sample.type=basic-auth", + "blueprintsprocessor.restclient.sample.url=http://localhost:8080", + "blueprintsprocessor.restclient.sample.userId=sampleuser", + "blueprintsprocessor.restclient.sslbasic.type=ssl-basic-auth", + "blueprintsprocessor.restclient.sslbasic.url=https://localhost:8443", + "blueprintsprocessor.restclient.sslbasic.username=admin", + "blueprintsprocessor.restclient.sslbasic.password=cds", + "blueprintsprocessor.restclient.sslbasic.keyStoreInstance=PKCS12", + "blueprintsprocessor.restclient.sslbasic.sslTrust=src/test/resources/keystore.p12", + "blueprintsprocessor.restclient.sslbasic.sslTrustPassword=changeit", + "blueprintsprocessor.restclient.ssltoken.type=ssl-token-auth", + "blueprintsprocessor.restclient.ssltoken.url=https://localhost:8443", + "blueprintsprocessor.restclient.ssltoken.token=72178473kjshdkjgvbsdkjv903274908", + "blueprintsprocessor.restclient.ssltoken.keyStoreInstance=PKCS12", + "blueprintsprocessor.restclient.ssltoken.sslTrust=src/test/resources/keystore.p12", + "blueprintsprocessor.restclient.ssltoken.sslTrustPassword=changeit", + "blueprintsprocessor.restclient.ssl.type=ssl-no-auth", + "blueprintsprocessor.restclient.ssl.url=https://localhost:8443", + "blueprintsprocessor.restclient.ssl.keyStoreInstance=PKCS12", + "blueprintsprocessor.restclient.ssl.sslTrust=src/test/resources/keystore.p12", + "blueprintsprocessor.restclient.ssl.sslTrustPassword=changeit", + "blueprintsprocessor.restclient.ssl.sslKey=src/test/resources/keystore.p12", + "blueprintsprocessor.restclient.ssl.sslKeyPassword=changeit" + ] +) +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 testSSLBasicProperties() { + val properties = bluePrintRestLibPropertyService.restClientProperties( + "blueprintsprocessor.restclient.sslbasic" + ) + assertNotNull(properties, "failed to create property bean") + val p: SSLBasicAuthRestClientProperties = + properties as SSLBasicAuthRestClientProperties + + assertEquals(p.basicAuth!!.username, "admin") + assertEquals(p.basicAuth!!.password, "cds") + assertEquals(p.sslTrust, "src/test/resources/keystore.p12") + assertEquals(p.sslTrustPassword, "changeit") + assertEquals(p.keyStoreInstance, "PKCS12") + } + + @Test + fun testSSLTokenProperties() { + val properties = bluePrintRestLibPropertyService.restClientProperties( + "blueprintsprocessor.restclient.ssltoken" + ) + assertNotNull(properties, "failed to create property bean") + + val p: SSLTokenAuthRestClientProperties = + properties as SSLTokenAuthRestClientProperties + + assertEquals(p.tokenAuth!!.token!!, "72178473kjshdkjgvbsdkjv903274908") + assertEquals(p.sslTrust, "src/test/resources/keystore.p12") + assertEquals(p.sslTrustPassword, "changeit") + assertEquals(p.keyStoreInstance, "PKCS12") + } + + @Test + fun testSSLNoAuthProperties() { + val properties = bluePrintRestLibPropertyService.restClientProperties( + "blueprintsprocessor.restclient.ssl" + ) + assertNotNull(properties, "failed to create property bean") + + val p: SSLRestClientProperties = + properties as SSLRestClientProperties + + assertEquals(p.sslTrust, "src/test/resources/keystore.p12") + assertEquals(p.sslTrustPassword, "changeit") + assertEquals(p.keyStoreInstance, "PKCS12") + assertEquals(p.sslKey, "src/test/resources/keystore.p12") + assertEquals(p.sslKeyPassword, "changeit") + } + + @Test + fun testSSLBasicPropertiesAsJson() { + val actualObj: JsonNode = defaultMapper.readTree(sslBasicAuthEndpointWithHeadersField()) + val properties = bluePrintRestLibPropertyService.restClientProperties( + actualObj + ) + assertNotNull(properties, "failed to create property bean") + val p: SSLBasicAuthRestClientProperties = properties as SSLBasicAuthRestClientProperties + + assertEquals("admin", p.basicAuth!!.username) + assertEquals("cds", p.basicAuth!!.password) + assertEquals("src/test/resources/keystore.p12", p.sslTrust) + assertEquals("changeit", p.sslTrustPassword) + assertEquals("PKCS12", p.keyStoreInstance) + assertEquals("ssl-basic-auth", p.type) + assertEquals("https://localhost:8443", p.url) + } + + @Test + fun testSSLTokenPropertiesAsJson() { + val actualObj: JsonNode = defaultMapper.readTree(sslTokenAuthEndpointWithHeadersField()) + val properties = + bluePrintRestLibPropertyService.restClientProperties(actualObj) + assertNotNull(properties, "failed to create property bean") + + val p: SSLTokenAuthRestClientProperties = properties as SSLTokenAuthRestClientProperties + + assertEquals("72178473kjshdkjgvbsdkjv903274908", p.tokenAuth!!.token!!) + assertEquals("src/test/resources/keystore.p12", p.sslTrust) + assertEquals("changeit", p.sslTrustPassword) + assertEquals("PKCS12", p.keyStoreInstance) + assertEquals("ssl-token-auth", p.type) + assertEquals("https://localhost:8443", p.url) + } + + @Test + fun testSSLNoAuthPropertiesAsJson() { + val actualObj: JsonNode = defaultMapper.readTree(sslNoAuthEndpointWithHeadersField()) + val properties = bluePrintRestLibPropertyService.restClientProperties( + actualObj + ) + assertNotNull(properties, "failed to create property bean") + + val p: SSLRestClientProperties = + properties as SSLRestClientProperties + + assertEquals("src/test/resources/keystore.p12", p.sslTrust) + assertEquals("changeit", p.sslTrustPassword) + assertEquals("PKCS12", p.keyStoreInstance) + assertEquals("src/test/resources/keystore.p12", p.sslKey) + assertEquals("changeit", p.sslKeyPassword) + assertEquals("ssl-no-auth", p.type) + assertEquals("https://localhost:8443", p.url) + } + + @Test + fun testBlueprintWebClientService() { + val blueprintWebClientService = bluePrintRestLibPropertyService + .blueprintWebClientService("sample") + assertNotNull( + blueprintWebClientService, + "failed to create blueprintWebClientService" + ) + } + + @Test + fun testBlueprintWebClientServiceWithJsonNode() { + val actualObj: JsonNode = defaultMapper.readTree(sslBasicAuthEndpointWithHeadersField()) + val blueprintWebClientService = bluePrintRestLibPropertyService + .blueprintWebClientService(actualObj) + assertNotNull(blueprintWebClientService, "failed to create blueprintWebClientService") + } + + // pass the result of $typeEndpointWithHeadersField() output with and without headers to compare. + private fun validateHeadersDidNotChangeWithEmptyAdditionalHeaders(noHeaders: String, withHeaders: String) { + val parsedObj: JsonNode = defaultMapper.readTree(noHeaders) + val bpWebClientService = + bluePrintRestLibPropertyService.blueprintWebClientService(parsedObj) + val extractedHeaders = bpWebClientService.convertToBasicHeaders(mapOf()) + + val parsedObjWithHeaders: JsonNode = defaultMapper.readTree(withHeaders) + val bpWebClientServiceWithHeaders = + bluePrintRestLibPropertyService.blueprintWebClientService(parsedObjWithHeaders) + val extractedHeadersWithAdditionalHeaders = bpWebClientServiceWithHeaders.convertToBasicHeaders(mapOf()) + // Array> -> Map + val headersMap = extractedHeaders.map { it.name to it.value }.toMap() + val additionalHeadersMap = extractedHeadersWithAdditionalHeaders.map { it.name to it.value }.toMap() + assertEquals(headersMap, additionalHeadersMap) + } + + @Test + fun `BasicAuth WebClientService with empty additionalHeaders does not modify headers`() { + val endPointJson = basicAuthEndpointWithHeadersField() + val endPointWithHeadersJson = basicAuthEndpointWithHeadersField(emptyAdditionalHeaders) + validateHeadersDidNotChangeWithEmptyAdditionalHeaders(endPointJson, endPointWithHeadersJson) + } + + private fun acceptsOneAdditionalHeadersTest(endPointWithHeadersJson: String) { + val parsedObj: JsonNode = defaultMapper.readTree(endPointWithHeadersJson) + val bpWebClientService = + bluePrintRestLibPropertyService.blueprintWebClientService(parsedObj) + val extractedHeaders = bpWebClientService.convertToBasicHeaders(mapOf()) + assertEquals(1, extractedHeaders.filter { it.name == "key1" }.count()) + } + + @Test + fun `BasicAuth WebClientService accepts one additionalHeaders`() { + val endPointWithHeadersJson = basicAuthEndpointWithHeadersField(oneAdditionalParameter) + acceptsOneAdditionalHeadersTest(endPointWithHeadersJson) + } + + private fun acceptsMultipleAdditionalHeaders(endPointWithHeadersJson: String) { + val parsedObj: JsonNode = defaultMapper.readTree(endPointWithHeadersJson) + val bpWebClientService = + bluePrintRestLibPropertyService.blueprintWebClientService(parsedObj) + val extractedHeaders = bpWebClientService.convertToBasicHeaders(mapOf()) + assertEquals(1, extractedHeaders.filter { it.name == "key1" }.count()) + assertEquals(1, extractedHeaders.filter { it.name == "key2" }.count()) + assertEquals(1, extractedHeaders.filter { it.name == "key3" }.count()) + } + + @Test + fun `BasicAuth WebClientService accepts multiple additionalHeaders`() { + val endPointWithHeadersJson = basicAuthEndpointWithHeadersField(threeAdditionalHeaders) + acceptsMultipleAdditionalHeaders(endPointWithHeadersJson) + } + + private fun additionalHeadersChangedContentTypeToAPPLICATION_XML(endPointWithHeadersJson: String) { + val parsedObj: JsonNode = defaultMapper.readTree(endPointWithHeadersJson) + val bpWebClientService = + bluePrintRestLibPropertyService.blueprintWebClientService(parsedObj) + val extractedHeaders = bpWebClientService.convertToBasicHeaders(mapOf()) + assertEquals( + MediaType.APPLICATION_XML.toString(), + extractedHeaders.filter { it.name == HttpHeaders.CONTENT_TYPE }[0].value!! + ) + } + + @Test + fun `BasicAuth WebClientService additionalHeaders can overwrite default Content-Type`() { + // default content type is application/json + val endPointWithHeadersJson = basicAuthEndpointWithHeadersField(contentTypeAdditionalHeader) + additionalHeadersChangedContentTypeToAPPLICATION_XML(endPointWithHeadersJson) + } + + // called from within "assertFailsWith(exceptionClass = BlueprintProcessorException::class) {" + private fun attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson: String) { + val parsedObj: JsonNode = defaultMapper.readTree(endPointWithHeadersJson) + val bpWebClientService = + bluePrintRestLibPropertyService.blueprintWebClientService(parsedObj) + bpWebClientService.convertToBasicHeaders(mapOf()) + } + + @Test + fun `BasicAuth WebClientService throws BlueprintProcessorException if additionalHeaders contain Authorization`() { + assertFailsWith(exceptionClass = BlueprintProcessorException::class) { + val endPointWithHeadersJson = basicAuthEndpointWithHeadersField(additionalHeadersWithAuth) + attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) + } + // spec says headers are case insensitive... + assertFailsWith(exceptionClass = BlueprintProcessorException::class) { + val endPointWithHeadersJson = basicAuthEndpointWithHeadersField(additionalHeadersWithAuthLowercased) + attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) + } + } + + @Test + fun `TokenAuth WebClientService with empty additionalHeaders does not modify headers`() { + val endPointJson = sslTokenAuthEndpointWithHeadersField() + val endPointWithHeadersJson = sslTokenAuthEndpointWithHeadersField(emptyAdditionalHeaders) + validateHeadersDidNotChangeWithEmptyAdditionalHeaders(endPointJson, endPointWithHeadersJson) + } + + @Test + fun `TokenAuth WebClientService accepts one additionalHeaders`() { + val endPointWithHeadersJson = sslTokenAuthEndpointWithHeadersField(oneAdditionalParameter) + acceptsOneAdditionalHeadersTest(endPointWithHeadersJson) + } + + @Test + fun `TokenAuth WebClientService accepts multiple additionalHeaders`() { + val endPointWithHeadersJson = sslTokenAuthEndpointWithHeadersField(threeAdditionalHeaders) + acceptsMultipleAdditionalHeaders(endPointWithHeadersJson) + } + + @Test + fun `TokenAuth WebClientService additionalHeaders can overwrite default Content-Type`() { + // default content type is application/json + val endPointWithHeadersJson = sslTokenAuthEndpointWithHeadersField(contentTypeAdditionalHeader) + additionalHeadersChangedContentTypeToAPPLICATION_XML(endPointWithHeadersJson) + } + + @Test + fun `TokenAuth WebClientService throws BlueprintProcessorException if additionalHeaders contain Authorization`() { + assertFailsWith(exceptionClass = BlueprintProcessorException::class) { + val endPointWithHeadersJson = sslTokenAuthEndpointWithHeadersField(additionalHeadersWithAuth) + attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) + } + // spec says headers are case insensitive... + assertFailsWith(exceptionClass = BlueprintProcessorException::class) { + val endPointWithHeadersJson = sslTokenAuthEndpointWithHeadersField(additionalHeadersWithAuthLowercased) + attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) + } + } + + // TESTS FOR SSL BASIC AUTH headers + @Test + fun `SSLBasicAuth WebClientService with empty additionalHeaders does not modify headers`() { + val endPointJson = sslBasicAuthEndpointWithHeadersField() + val endPointWithHeadersJson = sslBasicAuthEndpointWithHeadersField(emptyAdditionalHeaders) + validateHeadersDidNotChangeWithEmptyAdditionalHeaders(endPointJson, endPointWithHeadersJson) + } + + @Test + fun `SSLBasicAuth WebClientService accepts one additionalHeaders`() { + val endPointWithHeadersJson = sslBasicAuthEndpointWithHeadersField(oneAdditionalParameter) + acceptsOneAdditionalHeadersTest(endPointWithHeadersJson) + } + + @Test + fun `SSLBasicAuth WebClientService accepts multiple additionalHeaders`() { + val endPointWithHeadersJson = sslBasicAuthEndpointWithHeadersField(threeAdditionalHeaders) + acceptsMultipleAdditionalHeaders(endPointWithHeadersJson) + } + + @Test + fun `SSLBasicAuth WebClientService additionalHeaders can overwrite default Content-Type`() { + // default content type is application/json + val endPointWithHeadersJson = sslBasicAuthEndpointWithHeadersField(contentTypeAdditionalHeader) + additionalHeadersChangedContentTypeToAPPLICATION_XML(endPointWithHeadersJson) + } + + @Test + fun `SSLBasicAuth WebClientService throws BlueprintProcessorException if additionalHeaders contain Authorization`() { + assertFailsWith(exceptionClass = BlueprintProcessorException::class) { + val endPointWithHeadersJson = sslBasicAuthEndpointWithHeadersField(additionalHeadersWithAuth) + attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) + } + // spec says headers are case insensitive... + assertFailsWith(exceptionClass = BlueprintProcessorException::class) { + val endPointWithHeadersJson = sslBasicAuthEndpointWithHeadersField(additionalHeadersWithAuthLowercased) + attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) + } + } + + // SSL-NO-AUTH headers tests + @Test + fun `SSLNoAuth WebClientService with empty additionalHeaders does not modify headers`() { + val endPointJson = sslNoAuthEndpointWithHeadersField() + val endPointWithHeadersJson = sslNoAuthEndpointWithHeadersField(emptyAdditionalHeaders) + validateHeadersDidNotChangeWithEmptyAdditionalHeaders(endPointJson, endPointWithHeadersJson) + } + + @Test + fun `SSLNoAuth WebClientService accepts one additionalHeaders`() { + val endPointWithHeadersJson = sslNoAuthEndpointWithHeadersField(oneAdditionalParameter) + acceptsOneAdditionalHeadersTest(endPointWithHeadersJson) + } + + @Test + fun `SSLNoAuth WebClientService accepts multiple additionalHeaders`() { + val endPointWithHeadersJson = sslNoAuthEndpointWithHeadersField(threeAdditionalHeaders) + acceptsMultipleAdditionalHeaders(endPointWithHeadersJson) + } + + @Test + fun `SSLNoAuth WebClientService additionalHeaders can overwrite default Content-Type`() { + // default content type is application/json + val endPointWithHeadersJson = sslNoAuthEndpointWithHeadersField(contentTypeAdditionalHeader) + additionalHeadersChangedContentTypeToAPPLICATION_XML(endPointWithHeadersJson) + } + + @Test + fun `SSLNoAuth WebClientService throws BlueprintProcessorException if additionalHeaders contain Authorization`() { + assertFailsWith(exceptionClass = BlueprintProcessorException::class) { + val endPointWithHeadersJson = sslNoAuthEndpointWithHeadersField(additionalHeadersWithAuth) + attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) + } + // spec says headers are case insensitive... + assertFailsWith(exceptionClass = BlueprintProcessorException::class) { + val endPointWithHeadersJson = sslNoAuthEndpointWithHeadersField(additionalHeadersWithAuthLowercased) + attemptToPutAuthorizationHeaderIntoAdditionalHeaders(endPointWithHeadersJson) + } + } + + companion object BlueprintRestLibPropertyServiceTest { + + val defaultMapper = ObjectMapper() + val expectedTokenAuthDefaultHeaders = mapOf( + "Content-Type" to "application/json", + "Accept" to "application/json", + "Authorization" to "72178473kjshdkjgvbsdkjv903274908" + ) + + val endPointWithHeadersJsonWithBasicAuthHeader = basicAuthEndpointWithHeadersField( + """, + "additionalHeaders" : { + "authorization": "Basic aGF2ZTphbmljZWRheQo=" + } + """.trimIndent() + ) + + private fun sslTokenAuthEndpointWithHeadersField(headers: String = ""): String = + """{ + "type" : "ssl-token-auth", + "url" : "https://localhost:8443", + "keyStoreInstance" : "PKCS12", + "sslTrust" : "src/test/resources/keystore.p12", + "sslTrustPassword" : "changeit", + "tokenAuth" : { + "token" : "72178473kjshdkjgvbsdkjv903274908" + }$headers + } + """.trimIndent() + + private fun sslBasicAuthEndpointWithHeadersField(headers: String = ""): String = + """{ + "type" : "ssl-basic-auth", + "url" : "https://localhost:8443", + "keyStoreInstance" : "PKCS12", + "sslTrust" : "src/test/resources/keystore.p12", + "sslTrustPassword" : "changeit", + "basicAuth" : { + "username" : "admin", + "password" : "cds" + }$headers + } + """.trimIndent() + + private fun sslNoAuthEndpointWithHeadersField(headers: String = ""): String = """{ + "type" : "ssl-no-auth", + "url" : "https://localhost:8443", + "keyStoreInstance" : "PKCS12", + "sslTrust" : "src/test/resources/keystore.p12", + "sslTrustPassword" : "changeit", + "sslKey" : "src/test/resources/keystore.p12", + "sslKeyPassword" : "changeit"$headers + } + """.trimIndent() + + // Don't forget to supply "," as the first char to make valid JSON + private fun basicAuthEndpointWithHeadersField(headers: String = ""): String = + """{ + "type": "basic-auth", + "url": "http://127.0.0.1:8000", + "username": "user", + "password": "pass"$headers + } + """.trimIndent() + + private val emptyAdditionalHeaders = """, + "additionalHeaders" : { + } + """.trimIndent() + + private val oneAdditionalParameter = """, + "additionalHeaders" : { + "key1": "value1" + } + """.trimIndent() + + private val threeAdditionalHeaders = """, + "additionalHeaders" : { + "key1": "value1", + "key2": "value2", + "key3": "value3" + } + """.trimIndent() + + private val contentTypeAdditionalHeader = """, + "additionalHeaders" : { + "${HttpHeaders.CONTENT_TYPE}": "${MediaType.APPLICATION_XML}" + } + """.trimIndent() + + private val additionalHeadersWithAuth = """, + "additionalHeaders" : { + "Authorization": "Basic aGF2ZTphbmljZWRheQo=" + } + """.trimIndent() + + private val additionalHeadersWithAuthLowercased = """, + "additionalHeaders" : { + "authorization": "Basic aGF2ZTphbmljZWRheQo=" + } + """.trimIndent() + } +} diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt index f06f827ad..6b083aaad 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt @@ -19,7 +19,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.rest.service import org.junit.Test import org.onap.ccsdk.cds.blueprintsprocessor.rest.relationshipTemplateRestClient import org.onap.ccsdk.cds.blueprintsprocessor.rest.relationshipTypeConnectsToRestClient -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate import kotlin.test.assertEquals @@ -73,12 +73,12 @@ class RestClientPropertiesDSLTest { assertNotNull(relationshipTypes, "failed to get relationship types") assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" ) assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT}" ) } } 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 index 030996685..e14e035a9 100644 --- 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 @@ -27,9 +27,9 @@ import org.junit.After import org.junit.Before import org.junit.Test import org.junit.runner.RunWith -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.rest.BluePrintRestLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService +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 @@ -66,9 +66,9 @@ import kotlin.test.assertNotNull @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @ContextConfiguration( classes = [ - BluePrintRestLibConfiguration::class, SampleController::class, + BlueprintRestLibConfiguration::class, SampleController::class, SecurityConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class + BlueprintPropertyConfiguration::class, BlueprintPropertiesService::class ] ) @TestPropertySource( @@ -96,7 +96,7 @@ import kotlin.test.assertNotNull class RestClientServiceTest { @Autowired - lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService + lateinit var bluePrintRestLibPropertyService: BlueprintRestLibPropertyService @Autowired lateinit var httpHandler: HttpHandler diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibConfiguration.kt deleted file mode 100644 index dc10722cc..000000000 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibConfiguration.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.ssh - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.blueprintsprocessor.ssh.service.BluePrintSshLibPropertyService -import org.onap.ccsdk.cds.blueprintsprocessor.ssh.service.BlueprintSshClientService -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService -import org.springframework.boot.context.properties.EnableConfigurationProperties -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration - -@Configuration -@ComponentScan -@EnableConfigurationProperties -open class BluePrintSshLibConfiguration - -/** - * Exposed Dependency Service by this SSH Lib Module - */ -fun BluePrintDependencyService.sshLibPropertyService(): BluePrintSshLibPropertyService = - instance(SshLibConstants.SERVICE_BLUEPRINT_SSH_LIB_PROPERTY) - -fun BluePrintDependencyService.sshClientService(selector: String): BlueprintSshClientService = - sshLibPropertyService().blueprintSshClientService(selector) - -fun BluePrintDependencyService.sshClientService(jsonNode: JsonNode): BlueprintSshClientService = - sshLibPropertyService().blueprintSshClientService(jsonNode) - -class SshLibConstants { - companion object { - - const val SERVICE_BLUEPRINT_SSH_LIB_PROPERTY = "blueprint-ssh-lib-property-service" - const val PROPERTY_SSH_CLIENT_PREFIX = "blueprintsprocessor.sshclient." - const val TYPE_BASIC_AUTH = "basic-auth" - } -} diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibData.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibData.kt deleted file mode 100644 index 295021f21..000000000 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibData.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright © 2019 IBM. - * - * Modifications Copyright © 2020 IBM, 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.ssh - -open class SshClientProperties { - - lateinit var type: String - lateinit var host: String - var port: Int = 22 - var connectionTimeOut: Long = 3000 - var logging: Boolean = false // print command result in cds logs -} - -open class BasicAuthSshClientProperties : SshClientProperties() { - - lateinit var password: String - lateinit var username: String -} diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BlueprintSshLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BlueprintSshLibConfiguration.kt new file mode 100644 index 000000000..7b471870b --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BlueprintSshLibConfiguration.kt @@ -0,0 +1,51 @@ +/* + * 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.ssh + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.blueprintsprocessor.ssh.service.BlueprintSshLibPropertyService +import org.onap.ccsdk.cds.blueprintsprocessor.ssh.service.BlueprintSshClientService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintDependencyService +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +@Configuration +@ComponentScan +@EnableConfigurationProperties +open class BlueprintSshLibConfiguration + +/** + * Exposed Dependency Service by this SSH Lib Module + */ +fun BlueprintDependencyService.sshLibPropertyService(): BlueprintSshLibPropertyService = + instance(SshLibConstants.SERVICE_BLUEPRINT_SSH_LIB_PROPERTY) + +fun BlueprintDependencyService.sshClientService(selector: String): BlueprintSshClientService = + sshLibPropertyService().blueprintSshClientService(selector) + +fun BlueprintDependencyService.sshClientService(jsonNode: JsonNode): BlueprintSshClientService = + sshLibPropertyService().blueprintSshClientService(jsonNode) + +class SshLibConstants { + companion object { + + const val SERVICE_BLUEPRINT_SSH_LIB_PROPERTY = "blueprint-ssh-lib-property-service" + const val PROPERTY_SSH_CLIENT_PREFIX = "blueprintsprocessor.sshclient." + const val TYPE_BASIC_AUTH = "basic-auth" + } +} diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BlueprintSshLibData.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BlueprintSshLibData.kt new file mode 100644 index 000000000..295021f21 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BlueprintSshLibData.kt @@ -0,0 +1,34 @@ +/* + * Copyright © 2019 IBM. + * + * Modifications Copyright © 2020 IBM, 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.ssh + +open class SshClientProperties { + + lateinit var type: String + lateinit var host: String + var port: Int = 22 + var connectionTimeOut: Long = 3000 + var logging: Boolean = false // print command result in cds logs +} + +open class BasicAuthSshClientProperties : SshClientProperties() { + + lateinit var password: String + lateinit var username: String +} diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSL.kt index a7702d4fb..256924c5f 100644 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSL.kt @@ -19,8 +19,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.ssh import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintTypes import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType @@ -32,25 +32,25 @@ import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType /** Relationships Types DSL for Message Producer */ fun ServiceTemplateBuilder.relationshipTypeConnectsToSshClient() { - val relationshipType = BluePrintTypes.relationshipTypeConnectsToSshClient() + val relationshipType = BlueprintTypes.relationshipTypeConnectsToSshClient() if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() this.relationshipTypes!![relationshipType.id!!] = relationshipType } -fun BluePrintTypes.relationshipTypeConnectsToSshClient(): RelationshipType { +fun BlueprintTypes.relationshipTypeConnectsToSshClient(): RelationshipType { return relationshipType( - id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_SSH_CLIENT, - version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, + id = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_SSH_CLIENT, + version = BlueprintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, description = "Relationship connects to through SSH Client." ) { property( - BluePrintConstants.PROPERTY_CONNECTION_CONFIG, - BluePrintConstants.DATA_TYPE_MAP, + BlueprintConstants.PROPERTY_CONNECTION_CONFIG, + BlueprintConstants.DATA_TYPE_MAP, true, "Connection Config details." ) - validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) + validTargetTypes(arrayListOf(BlueprintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) } } @@ -68,15 +68,15 @@ fun TopologyTemplateBuilder.relationshipTemplateSshClient( open class SshRelationshipTemplateBuilder(name: String, description: String) : RelationshipTemplateBuilder( name, - BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_SSH_CLIENT, description + BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_SSH_CLIENT, description ) { fun basicAuth(block: BasicAuthSshClientPropertiesAssignmentBuilder.() -> Unit) { - property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.basicAuthSshProperties(block)) + property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.basicAuthSshProperties(block)) } } -fun BluePrintTypes.basicAuthSshProperties(block: BasicAuthSshClientPropertiesAssignmentBuilder.() -> Unit): JsonNode { +fun BlueprintTypes.basicAuthSshProperties(block: BasicAuthSshClientPropertiesAssignmentBuilder.() -> Unit): JsonNode { val sshProperties = BasicAuthSshClientPropertiesAssignmentBuilder().apply(block).build() sshProperties[SshClientProperties::type.name] = SshLibConstants.TYPE_BASIC_AUTH.asJsonPrimitive() return sshProperties.asJsonType() diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BasicAuthSshClientService.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BasicAuthSshClientService.kt index 6ee73c238..46756e63a 100644 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BasicAuthSshClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BasicAuthSshClientService.kt @@ -25,7 +25,7 @@ import org.apache.sshd.client.channel.ClientChannelEvent import org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier import org.apache.sshd.client.session.ClientSession import org.onap.ccsdk.cds.blueprintsprocessor.ssh.BasicAuthSshClientProperties -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException import org.slf4j.LoggerFactory import java.io.ByteArrayOutputStream import java.io.IOException @@ -76,7 +76,7 @@ open class BasicAuthSshClientService(private val basicAuthSshClientProperties: B channel!!.err = ByteArrayOutputStream() channel!!.open() } catch (e: Exception) { - throw BluePrintProcessorException("Failed to start Shell channel: ${e.message}") + throw BlueprintProcessorException("Failed to start Shell channel: ${e.message}") } } @@ -97,7 +97,7 @@ open class BasicAuthSshClientService(private val basicAuthSshClientProperties: B } } } catch (e: Exception) { - throw BluePrintProcessorException("Failed to execute commands, below the error message : ${e.message}") + throw BlueprintProcessorException("Failed to execute commands, below the error message : ${e.message}") } return response } @@ -111,7 +111,7 @@ open class BasicAuthSshClientService(private val basicAuthSshClientProperties: B teeOutput!!.flush() deviceOutput = waitForPrompt(timeOut) } catch (e: IOException) { - throw BluePrintProcessorException("Exception during command execution: ${e.message}", e) + throw BlueprintProcessorException("Exception during command execution: ${e.message}", e) } if (detectFailure(deviceOutput)) { @@ -130,7 +130,7 @@ open class BasicAuthSshClientService(private val basicAuthSshClientProperties: B Collections.unmodifiableSet(EnumSet.of(ClientChannelEvent.CLOSED)), timeOut ) if (channel!!.out.toString().indexOfAny(arrayListOf("$", ">", "#")) <= 0 && waitMask.contains(ClientChannelEvent.TIMEOUT)) { - throw BluePrintProcessorException("Timeout: Failed to retrieve commands result in $timeOut ms") + throw BlueprintProcessorException("Timeout: Failed to retrieve commands result in $timeOut ms") } val outputResult = channel!!.out.toString() channel!!.out.flush() diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyService.kt deleted file mode 100644 index 90a1746e8..000000000 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyService.kt +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.ssh.service - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.ssh.BasicAuthSshClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.ssh.SshClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.ssh.SshLibConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.springframework.stereotype.Service - -@Service(SshLibConstants.SERVICE_BLUEPRINT_SSH_LIB_PROPERTY) -open class BluePrintSshLibPropertyService(private var bluePrintProperties: BluePrintPropertiesService) { - - fun blueprintSshClientService(jsonNode: JsonNode): BlueprintSshClientService { - val restClientProperties = sshClientProperties(jsonNode) - return blueprintSshClientService(restClientProperties) - } - - fun blueprintSshClientService(selector: String): BlueprintSshClientService { - val prefix = "${SshLibConstants.PROPERTY_SSH_CLIENT_PREFIX}$selector" - val sshClientProperties = sshClientProperties(prefix) - return blueprintSshClientService(sshClientProperties) - } - - fun sshClientProperties(prefix: String): SshClientProperties { - val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java) - return when (type) { - SshLibConstants.TYPE_BASIC_AUTH -> { - basicAuthSshClientProperties(prefix) - } - else -> { - throw BluePrintProcessorException("SSH adaptor($type) is not supported") - } - } - } - - fun sshClientProperties(jsonNode: JsonNode): SshClientProperties { - val type = jsonNode.get("type")?.textValue() - ?: throw BluePrintProcessorException("missing type field in ssh client properties") - return when (type) { - SshLibConstants.TYPE_BASIC_AUTH -> { - JacksonUtils.readValue( - jsonNode, - BasicAuthSshClientProperties::class.java - )!! - } - else -> { - throw BluePrintProcessorException("SSH adaptor($type) is not supported") - } - } - } - - private fun blueprintSshClientService(sshClientProperties: SshClientProperties): BlueprintSshClientService { - - when (sshClientProperties) { - is BasicAuthSshClientProperties -> { - return BasicAuthSshClientService(sshClientProperties) - } - else -> { - throw BluePrintProcessorException("couldn't get SSH client service for") - } - } - } - - private fun basicAuthSshClientProperties(prefix: String): BasicAuthSshClientProperties { - return bluePrintProperties.propertyBeanType( - prefix, BasicAuthSshClientProperties::class.java - ) - } -} diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshLibPropertyService.kt new file mode 100644 index 000000000..4803d5f52 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshLibPropertyService.kt @@ -0,0 +1,87 @@ +/* + * 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.ssh.service + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.ssh.BasicAuthSshClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.ssh.SshClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.ssh.SshLibConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.stereotype.Service + +@Service(SshLibConstants.SERVICE_BLUEPRINT_SSH_LIB_PROPERTY) +open class BlueprintSshLibPropertyService(private var bluePrintProperties: BlueprintPropertiesService) { + + fun blueprintSshClientService(jsonNode: JsonNode): BlueprintSshClientService { + val restClientProperties = sshClientProperties(jsonNode) + return blueprintSshClientService(restClientProperties) + } + + fun blueprintSshClientService(selector: String): BlueprintSshClientService { + val prefix = "${SshLibConstants.PROPERTY_SSH_CLIENT_PREFIX}$selector" + val sshClientProperties = sshClientProperties(prefix) + return blueprintSshClientService(sshClientProperties) + } + + fun sshClientProperties(prefix: String): SshClientProperties { + val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java) + return when (type) { + SshLibConstants.TYPE_BASIC_AUTH -> { + basicAuthSshClientProperties(prefix) + } + else -> { + throw BlueprintProcessorException("SSH adaptor($type) is not supported") + } + } + } + + fun sshClientProperties(jsonNode: JsonNode): SshClientProperties { + val type = jsonNode.get("type")?.textValue() + ?: throw BlueprintProcessorException("missing type field in ssh client properties") + return when (type) { + SshLibConstants.TYPE_BASIC_AUTH -> { + JacksonUtils.readValue( + jsonNode, + BasicAuthSshClientProperties::class.java + )!! + } + else -> { + throw BlueprintProcessorException("SSH adaptor($type) is not supported") + } + } + } + + private fun blueprintSshClientService(sshClientProperties: SshClientProperties): BlueprintSshClientService { + + when (sshClientProperties) { + is BasicAuthSshClientProperties -> { + return BasicAuthSshClientService(sshClientProperties) + } + else -> { + throw BlueprintProcessorException("couldn't get SSH client service for") + } + } + } + + private fun basicAuthSshClientProperties(prefix: String): BasicAuthSshClientProperties { + return bluePrintProperties.propertyBeanType( + prefix, BasicAuthSshClientProperties::class.java + ) + } +} diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSLTest.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSLTest.kt index 85891b1b5..510dc7de8 100644 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSLTest.kt +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSLTest.kt @@ -17,7 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.ssh import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate import kotlin.test.assertEquals @@ -53,12 +53,12 @@ class SshPropertiesDSLTest { assertNotNull(relationshipTypes, "failed to get relationship types") assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" ) assertNotNull( - relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_SSH_CLIENT], - "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_SSH_CLIENT}" + relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_SSH_CLIENT], + "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_SSH_CLIENT}" ) } } diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyServiceTest.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyServiceTest.kt deleted file mode 100644 index 43a997ae9..000000000 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyServiceTest.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.ssh.service - -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.ssh.BasicAuthSshClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.ssh.BluePrintSshLibConfiguration -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.assertEquals -import kotlin.test.assertNotNull - -@RunWith(SpringRunner::class) -@ContextConfiguration( - classes = [ - BluePrintSshLibConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class - ] -) -@TestPropertySource( - properties = - [ - "blueprintsprocessor.sshclient.sample.type=basic-auth", - "blueprintsprocessor.sshclient.sample.host=127.0.0.1", - "blueprintsprocessor.sshclient.sample.port=22", - "blueprintsprocessor.sshclient.sample.password=1234", - "blueprintsprocessor.sshclient.sample.username=dummy" - ] -) -class BluePrintSshLibPropertyServiceTest { - - @Autowired - lateinit var bluePrintSshLibPropertyService: BluePrintSshLibPropertyService - - @Test - fun testRestClientProperties() { - val properties = bluePrintSshLibPropertyService - .sshClientProperties("blueprintsprocessor.sshclient.sample") as BasicAuthSshClientProperties - assertNotNull(properties, "failed to create property bean") - assertEquals(properties.host, "127.0.0.1", "failed to match host property") - assertEquals(properties.port, 22, "failed to match port property") - assertEquals(properties.password, "1234", "failed to match host property") - assertEquals(properties.username, "dummy", "failed to match host property") - } -} diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshClientServiceTest.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshClientServiceTest.kt index 1cf0de52b..1c9d8d14b 100644 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshClientServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshClientServiceTest.kt @@ -28,9 +28,9 @@ import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider import org.apache.sshd.server.session.ServerSession import org.apache.sshd.server.shell.ProcessShellCommandFactory import org.junit.runner.RunWith -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.ssh.BluePrintSshLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.ssh.BlueprintSshLibConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.ssh.service.echoShell.EchoShellFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration @@ -47,8 +47,8 @@ import kotlin.test.assertTrue @RunWith(SpringRunner::class) @ContextConfiguration( classes = [ - BluePrintSshLibConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class + BlueprintSshLibConfiguration::class, + BlueprintPropertyConfiguration::class, BlueprintPropertiesService::class ] ) @TestPropertySource( @@ -64,9 +64,9 @@ import kotlin.test.assertTrue class BlueprintSshClientServiceTest { @Autowired - lateinit var bluePrintSshLibPropertyService: BluePrintSshLibPropertyService + lateinit var bluePrintSshLibPropertyService: BlueprintSshLibPropertyService - lateinit var bluePrintSshLibPropertyServiceMock: BluePrintSshLibPropertyService + lateinit var bluePrintSshLibPropertyServiceMock: BlueprintSshLibPropertyService private lateinit var sshServer: SshServer diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshLibPropertyServiceTest.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshLibPropertyServiceTest.kt new file mode 100644 index 000000000..88c734aa4 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshLibPropertyServiceTest.kt @@ -0,0 +1,64 @@ +/* + * 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.ssh.service + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.ssh.BasicAuthSshClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.ssh.BlueprintSshLibConfiguration +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.assertEquals +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration( + classes = [ + BlueprintSshLibConfiguration::class, + BlueprintPropertyConfiguration::class, BlueprintPropertiesService::class + ] +) +@TestPropertySource( + properties = + [ + "blueprintsprocessor.sshclient.sample.type=basic-auth", + "blueprintsprocessor.sshclient.sample.host=127.0.0.1", + "blueprintsprocessor.sshclient.sample.port=22", + "blueprintsprocessor.sshclient.sample.password=1234", + "blueprintsprocessor.sshclient.sample.username=dummy" + ] +) +class BlueprintSshLibPropertyServiceTest { + + @Autowired + lateinit var bluePrintSshLibPropertyService: BlueprintSshLibPropertyService + + @Test + fun testRestClientProperties() { + val properties = bluePrintSshLibPropertyService + .sshClientProperties("blueprintsprocessor.sshclient.sample") as BasicAuthSshClientProperties + assertNotNull(properties, "failed to create property bean") + assertEquals(properties.host, "127.0.0.1", "failed to match host property") + assertEquals(properties.port, 22, "failed to match port property") + assertEquals(properties.password, "1234", "failed to match host property") + assertEquals(properties.username, "dummy", "failed to match host property") + } +} -- cgit 1.2.3-korg