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 --- .../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 +- 8 files changed, 358 insertions(+), 358 deletions(-) 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 (limited to 'ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin') 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. -- cgit 1.2.3-korg