From c90edac236dffb7c495e266dd04991de7e8f04b7 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Mon, 25 Mar 2019 13:04:18 -0400 Subject: Migrate ccsdk/apps to ccsdk/cds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue-ID: CCSDK-1177 Issue-ID: CCSDK-1178 Change-Id: I0c02702fbec52211ca367abbba72aebecee8cbaa Signed-off-by: Alexis de Talhouët --- .../dmaap/AafAuthDmaapClientService.kt | 63 ------ .../dmaap/BluePrintDmaapClientService.kt | 102 ---------- .../dmaap/BluePrintDmaapLibConfiguration.kt | 46 ----- .../dmaap/BluePrintDmaapLibPropertyService.kt | 187 ------------------ .../dmaap/DmaapClientProperties.kt | 46 ----- .../dmaap/HttpNoAuthDmaapClientService.kt | 62 ------ .../dmaap/AafAuthDmaapClientService.kt | 63 ++++++ .../dmaap/BluePrintDmaapClientService.kt | 102 ++++++++++ .../dmaap/BluePrintDmaapLibConfiguration.kt | 46 +++++ .../dmaap/BluePrintDmaapLibPropertyService.kt | 187 ++++++++++++++++++ .../dmaap/DmaapClientProperties.kt | 46 +++++ .../dmaap/HttpNoAuthDmaapClientService.kt | 62 ++++++ .../dmaap/TestDmaapEventPublisher.kt | 215 --------------------- .../dmaap/TestDmaapEventPublisher.kt | 215 +++++++++++++++++++++ .../dmaap-lib/src/test/resources/logback-test.xml | 2 +- 15 files changed, 722 insertions(+), 722 deletions(-) delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/DmaapClientProperties.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt create mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/DmaapClientProperties.kt create mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/apps/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt create mode 100644 ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/cds/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt (limited to 'ms/blueprintsprocessor/modules/commons/dmaap-lib/src') diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt deleted file mode 100644 index dd884092d..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CDS - * ================================================================================ - * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.dmaap - -import com.att.nsa.mr.client.MRBatchingPublisher -import com.att.nsa.mr.client.MRClientFactory -import com.att.nsa.mr.client.impl.MRSimplerBatchPublisher - -/** - * Representation of DMAAP client service for AAF auth type. - */ -class AafAuthDmaapClientService(private val clientProps: - AafAuthDmaapClientProperties) - : BluePrintDmaapClientService { - - /** - * The constructed DMAAP client. - */ - var clients: MutableList = mutableListOf() - - - /** - * Returns the DMAAP client after constructing it properly with the data - * that is required for AAF auth connection. - */ - override fun getDmaapClient(): MutableList { - if (!clients.isEmpty()) { - return clients - } - val topics = mutableListOf() - topics.addAll(clientProps.topic.split(",")) - - for (t in topics) { - val client = MRClientFactory.createBatchingPublisher( - clientProps.host, t, clientProps.username, - clientProps.password, 1, 1, false, - clientProps.type, "") - val batchPublisher = client as MRSimplerBatchPublisher - batchPublisher.props = clientProps.props - clients.add(client) - } - return clients - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt deleted file mode 100644 index 21d7128e4..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt +++ /dev/null @@ -1,102 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CDS - * ================================================================================ - * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.dmaap - -import com.att.nsa.mr.client.MRBatchingPublisher -import com.att.nsa.mr.client.MRPublisher -import org.slf4j.LoggerFactory -import java.io.IOException -import java.util.concurrent.TimeUnit - - -/** - * Abstraction of DMAAP client services that could form DMAAP client from the - * properties provided. This abstraction also provides a mechanism to send - * messages with the given partition in a session and closing the same. - */ -interface BluePrintDmaapClientService { - - /** - * Static variable for logging. - */ - companion object { - var log = LoggerFactory.getLogger( - BluePrintDmaapClientService::class.java)!! - } - - /** - * Returns the properly constructed DMAAP client with the type. - */ - fun getDmaapClient(): MutableList - - /** - * Sends messages to the sessions created by the information provided from - * application.properties and event.properties file - */ - fun sendMessage(msgs: Collection): Boolean { - var success = true - val clients = getDmaapClient() - val dmaapMsgs = mutableListOf() - for (m in msgs) { - dmaapMsgs.add(MRPublisher.message("1", m)) - } - log.info("Sending messages to the DMAAP Server") - for (client in clients) { - try { - client.send(dmaapMsgs) - } catch (e: IOException) { - success = false - log.error(e.message, e) - } - } - return success - } - - /** - * Sends message to the sessions created by the information provided from - * application.properties and event.properties file - */ - fun sendMessage(msg: String): Boolean { - val msgs = mutableListOf() - msgs.add(msg) - return sendMessage(msgs) - } - - /** - * Closes the opened session that was used for sending messages. - */ - fun close(timeout: Long): MutableList>? { - log.debug("Closing the DMAAP producer clients") - var msgs: MutableList> = - mutableListOf() - val clients = getDmaapClient() - for (client in clients) { - try { - var ms = client.close(timeout, TimeUnit.SECONDS) - msgs.add(ms) - } catch (e: IOException) { - log.warn("Unable to cleanly close the connection from the " + - "client $client", e) - } - } - return msgs - } -} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt deleted file mode 100644 index ca1a07ba3..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CDS - * ================================================================================ - * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.dmaap - -import org.springframework.boot.context.properties.EnableConfigurationProperties -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration - -/** - * Representation of DMAAP lib configuration to load the required property - * files into the application context. - */ -@Configuration -@ComponentScan -@EnableConfigurationProperties -open class BluePrintDmaapLibConfiguration - -/** - * Util constants required for DMAAP library to use. - */ -class DmaapLibConstants { - companion object { - const val SERVICE_BLUEPRINT_DMAAP_LIB_PROPERTY = "blueprint" + - "-dmaap-lib-property-service" - const val TYPE_HTTP_NO_AUTH = "HTTPNOAUTH" - const val TYPE_HTTP_AAF_AUTH = "HTTPAAF" - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt deleted file mode 100644 index 7abbefbca..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt +++ /dev/null @@ -1,187 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CDS - * ================================================================================ - * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.dmaap - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties -import org.onap.ccsdk.apps.blueprintsprocessor.dmaap.DmaapLibConstants.Companion.SERVICE_BLUEPRINT_DMAAP_LIB_PROPERTY -import org.onap.ccsdk.apps.blueprintsprocessor.dmaap.DmaapLibConstants.Companion.TYPE_HTTP_AAF_AUTH -import org.onap.ccsdk.apps.blueprintsprocessor.dmaap.DmaapLibConstants.Companion.TYPE_HTTP_NO_AUTH -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.context.annotation.Configuration -import org.springframework.context.annotation.PropertySource -import org.springframework.context.annotation.PropertySources -import org.springframework.core.env.ConfigurableEnvironment -import org.springframework.core.env.Environment -import org.springframework.core.io.support.ResourcePropertySource -import org.springframework.stereotype.Service -import java.util.Properties - -/** - * Representation of DMAAP lib property service to load the properties - * according to the connection type to the DMAAP server and returning back - * the appropriate DMAAP client to send messages DMAAP client. - */ -@Service(SERVICE_BLUEPRINT_DMAAP_LIB_PROPERTY) -@Configuration -@PropertySources(PropertySource("classpath:event.properties")) -open class BluePrintDmaapLibPropertyService(private var bluePrintProperties: - BluePrintProperties) { - - /** - * Static variable for logging. - */ - companion object { - var log = LoggerFactory.getLogger( - BluePrintDmaapLibPropertyService::class.java)!! - } - - /** - * Environment entity to derive it from the system to load a specific - * property file. - */ - @Autowired - lateinit var env: Environment - - /** - * Returns the DMAAP client by providing the input properties as a JSON - * node. - */ - fun blueprintDmaapClientService(jsonNode: JsonNode): - BluePrintDmaapClientService { - val dmaapProps = dmaapClientProperties(jsonNode) - return blueprintDmaapClientService(dmaapProps) - } - - /** - * Returns the DMAAP client by providing the input properties as a - * selector string. - */ - fun blueprintDmaapClientService(selector: String): - BluePrintDmaapClientService { - val prefix = "blueprintsprocessor.dmaapclient.$selector" - val dmaapProps = dmaapClientProperties(prefix) - return blueprintDmaapClientService(dmaapProps) - } - - /** - * Returns the DMAAP client properties from the type of connection it - * requires. - */ - fun dmaapClientProperties(prefix: String): DmaapClientProperties { - val type = bluePrintProperties.propertyBeanType( - "$prefix.type", String::class.java) - val clientProps : DmaapClientProperties - - when (type) { - TYPE_HTTP_NO_AUTH -> { - clientProps = bluePrintProperties.propertyBeanType( - prefix, HttpNoAuthDmaapClientProperties::class.java) - clientProps.props = parseEventProps() - } - - TYPE_HTTP_AAF_AUTH -> { - clientProps = bluePrintProperties.propertyBeanType( - prefix, AafAuthDmaapClientProperties::class.java) - clientProps.props = parseEventProps() - } - - else -> { - throw BluePrintProcessorException("DMAAP adaptor($type) is " + - "not supported") - } - } - return clientProps - } - - /** - * Returns the DMAAP client properties from the type of connection it - * requires. - */ - fun dmaapClientProperties(jsonNode: JsonNode): DmaapClientProperties { - val type = jsonNode.get("type").textValue() - val clientProps : DmaapClientProperties - - when (type) { - TYPE_HTTP_NO_AUTH -> { - clientProps = JacksonUtils.readValue(jsonNode, - HttpNoAuthDmaapClientProperties::class.java)!! - clientProps.props = parseEventProps() - } - - TYPE_HTTP_AAF_AUTH -> { - clientProps = JacksonUtils.readValue(jsonNode, - AafAuthDmaapClientProperties::class.java)!! - clientProps.props = parseEventProps() - } - - else -> { - throw BluePrintProcessorException("DMAAP adaptor($type) is " + - "not supported") - } - } - return clientProps - } - - /** - * Returns DMAAP client service according to the type of client properties. - */ - private fun blueprintDmaapClientService(clientProps: DmaapClientProperties): - BluePrintDmaapClientService { - when (clientProps) { - is HttpNoAuthDmaapClientProperties -> { - return HttpNoAuthDmaapClientService(clientProps) - } - - is AafAuthDmaapClientProperties -> { - return AafAuthDmaapClientService(clientProps) - } - - else -> { - throw BluePrintProcessorException("Unable to get the DMAAP " + - "client") - } - } - } - - /** - * Parses the event.properties file which contains the default values for - * the connection required. - */ - private fun parseEventProps(): Properties { - val prodProps = Properties() - val proProps = (env as ConfigurableEnvironment).propertySources.get( - "class path resource [event.properties]") - - if (proProps != null) { - val entries = (proProps as ResourcePropertySource).source.entries - for (e in entries) { - prodProps.put(e.key, e.value) - } - } else { - log.error("Unable to load the event.properties file") - } - return prodProps - } -} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/DmaapClientProperties.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/DmaapClientProperties.kt deleted file mode 100644 index 97df2723b..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/DmaapClientProperties.kt +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CDS - * ================================================================================ - * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.dmaap - -import java.util.Properties - -/** - * Representation of data required for all DMAAP client. - */ -open class DmaapClientProperties { - lateinit var props: Properties - lateinit var type: String - lateinit var host: String - lateinit var topic: String -} - -/** - * Representation of data required for HTTP no auth DMAAP client. - */ -open class HttpNoAuthDmaapClientProperties : DmaapClientProperties() - -/** - * Representation of data required for AAF auth DMAAP client. - */ -open class AafAuthDmaapClientProperties : DmaapClientProperties() { - lateinit var username: String - lateinit var password: String -} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt deleted file mode 100644 index ad023b962..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CDS - * ================================================================================ - * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.dmaap - -import com.att.nsa.mr.client.MRBatchingPublisher -import com.att.nsa.mr.client.MRClientFactory.createSimplePublisher -import com.att.nsa.mr.client.impl.MRSimplerBatchPublisher - -/** - * Representation of DMAAP client service for HTTP no auth type. - */ -class HttpNoAuthDmaapClientService(private val clientProps: - HttpNoAuthDmaapClientProperties) - : BluePrintDmaapClientService { - - /** - * The constructed DMAAP client. - */ - var clients: MutableList = mutableListOf() - - - /** - * Returns the DMAAP client after constructing it properly with the data - * that is required for HTTP no auth connection. - */ - override fun getDmaapClient(): MutableList { - if (!clients.isEmpty()) { - return clients - } - val topics = mutableListOf() - topics.addAll(clientProps.topic.split(",")) - - for (t in topics) { - val client = createSimplePublisher(clientProps.host, t) - val batchPublisher = client as MRSimplerBatchPublisher - batchPublisher.setProtocolFlag(clientProps.type) - batchPublisher.props = clientProps.props - clients.add(client) - } - - return clients - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt new file mode 100644 index 000000000..2dbea8fc9 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/AafAuthDmaapClientService.kt @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CDS + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.dmaap + +import com.att.nsa.mr.client.MRBatchingPublisher +import com.att.nsa.mr.client.MRClientFactory +import com.att.nsa.mr.client.impl.MRSimplerBatchPublisher + +/** + * Representation of DMAAP client service for AAF auth type. + */ +class AafAuthDmaapClientService(private val clientProps: + AafAuthDmaapClientProperties) + : BluePrintDmaapClientService { + + /** + * The constructed DMAAP client. + */ + var clients: MutableList = mutableListOf() + + + /** + * Returns the DMAAP client after constructing it properly with the data + * that is required for AAF auth connection. + */ + override fun getDmaapClient(): MutableList { + if (!clients.isEmpty()) { + return clients + } + val topics = mutableListOf() + topics.addAll(clientProps.topic.split(",")) + + for (t in topics) { + val client = MRClientFactory.createBatchingPublisher( + clientProps.host, t, clientProps.username, + clientProps.password, 1, 1, false, + clientProps.type, "") + val batchPublisher = client as MRSimplerBatchPublisher + batchPublisher.props = clientProps.props + clients.add(client) + } + return clients + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt new file mode 100644 index 000000000..a4cb5a3e6 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapClientService.kt @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CDS + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.dmaap + +import com.att.nsa.mr.client.MRBatchingPublisher +import com.att.nsa.mr.client.MRPublisher +import org.slf4j.LoggerFactory +import java.io.IOException +import java.util.concurrent.TimeUnit + + +/** + * Abstraction of DMAAP client services that could form DMAAP client from the + * properties provided. This abstraction also provides a mechanism to send + * messages with the given partition in a session and closing the same. + */ +interface BluePrintDmaapClientService { + + /** + * Static variable for logging. + */ + companion object { + var log = LoggerFactory.getLogger( + BluePrintDmaapClientService::class.java)!! + } + + /** + * Returns the properly constructed DMAAP client with the type. + */ + fun getDmaapClient(): MutableList + + /** + * Sends messages to the sessions created by the information provided from + * application.properties and event.properties file + */ + fun sendMessage(msgs: Collection): Boolean { + var success = true + val clients = getDmaapClient() + val dmaapMsgs = mutableListOf() + for (m in msgs) { + dmaapMsgs.add(MRPublisher.message("1", m)) + } + log.info("Sending messages to the DMAAP Server") + for (client in clients) { + try { + client.send(dmaapMsgs) + } catch (e: IOException) { + success = false + log.error(e.message, e) + } + } + return success + } + + /** + * Sends message to the sessions created by the information provided from + * application.properties and event.properties file + */ + fun sendMessage(msg: String): Boolean { + val msgs = mutableListOf() + msgs.add(msg) + return sendMessage(msgs) + } + + /** + * Closes the opened session that was used for sending messages. + */ + fun close(timeout: Long): MutableList>? { + log.debug("Closing the DMAAP producer clients") + var msgs: MutableList> = + mutableListOf() + val clients = getDmaapClient() + for (client in clients) { + try { + var ms = client.close(timeout, TimeUnit.SECONDS) + msgs.add(ms) + } catch (e: IOException) { + log.warn("Unable to cleanly close the connection from the " + + "client $client", e) + } + } + return msgs + } +} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt new file mode 100644 index 000000000..51cd3bf0a --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibConfiguration.kt @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CDS + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.dmaap + +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +/** + * Representation of DMAAP lib configuration to load the required property + * files into the application context. + */ +@Configuration +@ComponentScan +@EnableConfigurationProperties +open class BluePrintDmaapLibConfiguration + +/** + * Util constants required for DMAAP library to use. + */ +class DmaapLibConstants { + companion object { + const val SERVICE_BLUEPRINT_DMAAP_LIB_PROPERTY = "blueprint" + + "-dmaap-lib-property-service" + const val TYPE_HTTP_NO_AUTH = "HTTPNOAUTH" + const val TYPE_HTTP_AAF_AUTH = "HTTPAAF" + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt new file mode 100644 index 000000000..8604d8880 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/BluePrintDmaapLibPropertyService.kt @@ -0,0 +1,187 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CDS + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.dmaap + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties +import org.onap.ccsdk.cds.blueprintsprocessor.dmaap.DmaapLibConstants.Companion.SERVICE_BLUEPRINT_DMAAP_LIB_PROPERTY +import org.onap.ccsdk.cds.blueprintsprocessor.dmaap.DmaapLibConstants.Companion.TYPE_HTTP_AAF_AUTH +import org.onap.ccsdk.cds.blueprintsprocessor.dmaap.DmaapLibConstants.Companion.TYPE_HTTP_NO_AUTH +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.PropertySource +import org.springframework.context.annotation.PropertySources +import org.springframework.core.env.ConfigurableEnvironment +import org.springframework.core.env.Environment +import org.springframework.core.io.support.ResourcePropertySource +import org.springframework.stereotype.Service +import java.util.Properties + +/** + * Representation of DMAAP lib property service to load the properties + * according to the connection type to the DMAAP server and returning back + * the appropriate DMAAP client to send messages DMAAP client. + */ +@Service(SERVICE_BLUEPRINT_DMAAP_LIB_PROPERTY) +@Configuration +@PropertySources(PropertySource("classpath:event.properties")) +open class BluePrintDmaapLibPropertyService(private var bluePrintProperties: + BluePrintProperties) { + + /** + * Static variable for logging. + */ + companion object { + var log = LoggerFactory.getLogger( + BluePrintDmaapLibPropertyService::class.java)!! + } + + /** + * Environment entity to derive it from the system to load a specific + * property file. + */ + @Autowired + lateinit var env: Environment + + /** + * Returns the DMAAP client by providing the input properties as a JSON + * node. + */ + fun blueprintDmaapClientService(jsonNode: JsonNode): + BluePrintDmaapClientService { + val dmaapProps = dmaapClientProperties(jsonNode) + return blueprintDmaapClientService(dmaapProps) + } + + /** + * Returns the DMAAP client by providing the input properties as a + * selector string. + */ + fun blueprintDmaapClientService(selector: String): + BluePrintDmaapClientService { + val prefix = "blueprintsprocessor.dmaapclient.$selector" + val dmaapProps = dmaapClientProperties(prefix) + return blueprintDmaapClientService(dmaapProps) + } + + /** + * Returns the DMAAP client properties from the type of connection it + * requires. + */ + fun dmaapClientProperties(prefix: String): DmaapClientProperties { + val type = bluePrintProperties.propertyBeanType( + "$prefix.type", String::class.java) + val clientProps : DmaapClientProperties + + when (type) { + TYPE_HTTP_NO_AUTH -> { + clientProps = bluePrintProperties.propertyBeanType( + prefix, HttpNoAuthDmaapClientProperties::class.java) + clientProps.props = parseEventProps() + } + + TYPE_HTTP_AAF_AUTH -> { + clientProps = bluePrintProperties.propertyBeanType( + prefix, AafAuthDmaapClientProperties::class.java) + clientProps.props = parseEventProps() + } + + else -> { + throw BluePrintProcessorException("DMAAP adaptor($type) is " + + "not supported") + } + } + return clientProps + } + + /** + * Returns the DMAAP client properties from the type of connection it + * requires. + */ + fun dmaapClientProperties(jsonNode: JsonNode): DmaapClientProperties { + val type = jsonNode.get("type").textValue() + val clientProps : DmaapClientProperties + + when (type) { + TYPE_HTTP_NO_AUTH -> { + clientProps = JacksonUtils.readValue(jsonNode, + HttpNoAuthDmaapClientProperties::class.java)!! + clientProps.props = parseEventProps() + } + + TYPE_HTTP_AAF_AUTH -> { + clientProps = JacksonUtils.readValue(jsonNode, + AafAuthDmaapClientProperties::class.java)!! + clientProps.props = parseEventProps() + } + + else -> { + throw BluePrintProcessorException("DMAAP adaptor($type) is " + + "not supported") + } + } + return clientProps + } + + /** + * Returns DMAAP client service according to the type of client properties. + */ + private fun blueprintDmaapClientService(clientProps: DmaapClientProperties): + BluePrintDmaapClientService { + when (clientProps) { + is HttpNoAuthDmaapClientProperties -> { + return HttpNoAuthDmaapClientService(clientProps) + } + + is AafAuthDmaapClientProperties -> { + return AafAuthDmaapClientService(clientProps) + } + + else -> { + throw BluePrintProcessorException("Unable to get the DMAAP " + + "client") + } + } + } + + /** + * Parses the event.properties file which contains the default values for + * the connection required. + */ + private fun parseEventProps(): Properties { + val prodProps = Properties() + val proProps = (env as ConfigurableEnvironment).propertySources.get( + "class path resource [event.properties]") + + if (proProps != null) { + val entries = (proProps as ResourcePropertySource).source.entries + for (e in entries) { + prodProps.put(e.key, e.value) + } + } else { + log.error("Unable to load the event.properties file") + } + return prodProps + } +} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/DmaapClientProperties.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/DmaapClientProperties.kt new file mode 100644 index 000000000..9d942943e --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/DmaapClientProperties.kt @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CDS + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.dmaap + +import java.util.Properties + +/** + * Representation of data required for all DMAAP client. + */ +open class DmaapClientProperties { + lateinit var props: Properties + lateinit var type: String + lateinit var host: String + lateinit var topic: String +} + +/** + * Representation of data required for HTTP no auth DMAAP client. + */ +open class HttpNoAuthDmaapClientProperties : DmaapClientProperties() + +/** + * Representation of data required for AAF auth DMAAP client. + */ +open class AafAuthDmaapClientProperties : DmaapClientProperties() { + lateinit var username: String + lateinit var password: String +} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt new file mode 100644 index 000000000..8bf50a944 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/dmaap/HttpNoAuthDmaapClientService.kt @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CDS + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.dmaap + +import com.att.nsa.mr.client.MRBatchingPublisher +import com.att.nsa.mr.client.MRClientFactory.createSimplePublisher +import com.att.nsa.mr.client.impl.MRSimplerBatchPublisher + +/** + * Representation of DMAAP client service for HTTP no auth type. + */ +class HttpNoAuthDmaapClientService(private val clientProps: + HttpNoAuthDmaapClientProperties) + : BluePrintDmaapClientService { + + /** + * The constructed DMAAP client. + */ + var clients: MutableList = mutableListOf() + + + /** + * Returns the DMAAP client after constructing it properly with the data + * that is required for HTTP no auth connection. + */ + override fun getDmaapClient(): MutableList { + if (!clients.isEmpty()) { + return clients + } + val topics = mutableListOf() + topics.addAll(clientProps.topic.split(",")) + + for (t in topics) { + val client = createSimplePublisher(clientProps.host, t) + val batchPublisher = client as MRSimplerBatchPublisher + batchPublisher.setProtocolFlag(clientProps.type) + batchPublisher.props = clientProps.props + clients.add(client) + } + + return clients + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/apps/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/apps/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt deleted file mode 100644 index 9b3aae5e6..000000000 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/apps/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt +++ /dev/null @@ -1,215 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP - CDS - * ================================================================================ - * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.ccsdk.apps.blueprintprocessor.dmaap - -import com.fasterxml.jackson.databind.ObjectMapper -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties -import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.dmaap.BluePrintDmaapLibConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.dmaap.BluePrintDmaapLibPropertyService -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.http.HttpStatus -import org.springframework.http.ResponseEntity -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController -import kotlin.test.assertEquals -import kotlin.test.assertNotNull - -/** - * Unit test cases for DMaap publisher code. - */ -@RunWith(SpringRunner::class) -@EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class]) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -@ContextConfiguration(classes = [BluePrintDmaapLibConfiguration::class, TestController::class, - BlueprintPropertyConfiguration::class, BluePrintProperties::class]) -@TestPropertySource(properties = ["server.port=9111", - "blueprintsprocessor.dmaapclient.aai.topic=cds_aai", - "blueprintsprocessor.dmaapclient.aai.type=HTTPNOAUTH", - "blueprintsprocessor.dmaapclient.aai.host=127.0.0.1:9111", - "blueprintsprocessor.dmaapclient.multi.topic=cds_multi1,cds_multi2", - "blueprintsprocessor.dmaapclient.multi.type=HTTPNOAUTH", - "blueprintsprocessor.dmaapclient.multi.host=127.0.0.1:9111"]) -class TestDmaapEventPublisher { - - @Autowired - lateinit var dmaapService : BluePrintDmaapLibPropertyService - - /** - * Tests the event properties being set properly and sent as request. - */ - @Test - fun testEventProperties() { - val strList = mutableListOf() - val dmaapClient = dmaapService.blueprintDmaapClientService("aai") - - strList.add("{\n" + - " \"a\" : \"hello\"\n" + - "}") - dmaapClient.sendMessage(strList) - val msgs = dmaapClient.close(2) - assertEquals(msgs!!.size, 1) - val topic1 = msgs.get(0) - assertEquals(topic1!!.size, 0) - } - - /** - * Tests the event properties being set properly and sent as request with - * single message. - */ - @Test - fun testEventPropertiesWithSingleMsg() { - val dmaapClient = dmaapService.blueprintDmaapClientService("aai") - val str : String = "{\n" + - " \"a\" : \"hello\"\n" + - "}" - dmaapClient.sendMessage(str) - val msgs = dmaapClient.close(2) - assertEquals(msgs!!.size, 1) - val topic1 = msgs.get(0) - assertEquals(topic1!!.size, 0) - } - - /** - * Tests the event properties with multiple topics. - */ - @Test - fun testMultiTopicProperties() { - val strList = mutableListOf() - val dmaapClient = dmaapService.blueprintDmaapClientService("multi") - - strList.add("{\n" + - " \"a\" : \"hello\"\n" + - "}") - dmaapClient.sendMessage(strList) - val msgs = dmaapClient.close(2) - assertEquals(msgs!!.size, 2) - val topic1 = msgs.get(0) - assertEquals(topic1!!.size, 0) - val topic2 = msgs.get(1) - assertEquals(topic2!!.size, 0) - } - - - /** - * Tests the event properties with multiple topics with JSON node as input. - */ - @Test - fun testMultiTopicPropertiesWithJsonInput() { - val jsonString = "{\n" + - " \"topic\" : \"cds_json1,cds_json2\",\n" + - " \"type\" : \"HTTPNOAUTH\",\n" + - " \"host\" : \"127.0.0.1:9111\"\n" + - "}" - val mapper = ObjectMapper() - val node = mapper.readTree(jsonString) - val strList = mutableListOf() - val dmaapClient = dmaapService.blueprintDmaapClientService(node) - - strList.add("{\n" + - " \"a\" : \"hello\"\n" + - "}") - dmaapClient.sendMessage(strList) - val msgs = dmaapClient.close(2) - assertEquals(msgs!!.size, 2) - val topic1 = msgs.get(0) - assertEquals(topic1!!.size, 0) - val topic2 = msgs.get(1) - assertEquals(topic2!!.size, 0) - } - - - /** - * Tests the event properties with multiple messages. - */ - @Test - fun testMultiMsgsProperties() { - val strList = mutableListOf() - val dmaapClient = dmaapService.blueprintDmaapClientService("aai") - - strList.add("{\n" + - " \"a\" : \"hello\"\n" + - "}") - strList.add("{\n" + - " \"a\" : \"second\"\n" + - "}") - dmaapClient.sendMessage(strList) - val msgs = dmaapClient.close(2) - assertEquals(msgs!!.size, 1) - val topic1 = msgs.get(0) - assertEquals(topic1!!.size, 0) - } - - /** - * Tests the DMAAP client properties generated with the complete prefix. - */ - @Test - fun testDmaapClientProperties() { - val properties = dmaapService.dmaapClientProperties( - "blueprintsprocessor.dmaapclient.aai") - assertNotNull(properties, "failed to create property bean") - assertNotNull(properties.host, "failed to get url property" + - " in property bean") - } - - /** - * Tests the blueprint DMAAP client service with only selector prefix. - */ - @Test - fun testBlueprintDmaapClientService() { - val blueprintDmaapClientService = - dmaapService.blueprintDmaapClientService("aai") - assertNotNull(blueprintDmaapClientService, - "failed to create blueprintDmaapClientService") - } - -} - -/** - * Rest controller for testing the client request that is sent. - */ -@RestController -@RequestMapping(path = ["/events"]) -open class TestController { - - /** - * Accepts request for a topic and sends a message as response. - */ - @PostMapping(path = ["/{topic}"]) - fun postTopic(@PathVariable(value = "topic") topic : String): - ResponseEntity { - var a = "{\n" + - " \"message\" : \"The message is published into $topic " + - "topic\"\n" + - "}" - return ResponseEntity(a, HttpStatus.OK) - } -} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/cds/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/cds/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt new file mode 100644 index 000000000..65d877518 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/kotlin/org/ccsdk/cds/blueprintprocessor/dmaap/TestDmaapEventPublisher.kt @@ -0,0 +1,215 @@ +/* + * ============LICENSE_START======================================================= + * ONAP - CDS + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.ccsdk.apps.blueprintprocessor.dmaap + +import com.fasterxml.jackson.databind.ObjectMapper +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.dmaap.BluePrintDmaapLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.dmaap.BluePrintDmaapLibPropertyService +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +/** + * Unit test cases for DMaap publisher code. + */ +@RunWith(SpringRunner::class) +@EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class]) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@ContextConfiguration(classes = [BluePrintDmaapLibConfiguration::class, TestController::class, + BlueprintPropertyConfiguration::class, BluePrintProperties::class]) +@TestPropertySource(properties = ["server.port=9111", + "blueprintsprocessor.dmaapclient.aai.topic=cds_aai", + "blueprintsprocessor.dmaapclient.aai.type=HTTPNOAUTH", + "blueprintsprocessor.dmaapclient.aai.host=127.0.0.1:9111", + "blueprintsprocessor.dmaapclient.multi.topic=cds_multi1,cds_multi2", + "blueprintsprocessor.dmaapclient.multi.type=HTTPNOAUTH", + "blueprintsprocessor.dmaapclient.multi.host=127.0.0.1:9111"]) +class TestDmaapEventPublisher { + + @Autowired + lateinit var dmaapService : BluePrintDmaapLibPropertyService + + /** + * Tests the event properties being set properly and sent as request. + */ + @Test + fun testEventProperties() { + val strList = mutableListOf() + val dmaapClient = dmaapService.blueprintDmaapClientService("aai") + + strList.add("{\n" + + " \"a\" : \"hello\"\n" + + "}") + dmaapClient.sendMessage(strList) + val msgs = dmaapClient.close(2) + assertEquals(msgs!!.size, 1) + val topic1 = msgs.get(0) + assertEquals(topic1!!.size, 0) + } + + /** + * Tests the event properties being set properly and sent as request with + * single message. + */ + @Test + fun testEventPropertiesWithSingleMsg() { + val dmaapClient = dmaapService.blueprintDmaapClientService("aai") + val str : String = "{\n" + + " \"a\" : \"hello\"\n" + + "}" + dmaapClient.sendMessage(str) + val msgs = dmaapClient.close(2) + assertEquals(msgs!!.size, 1) + val topic1 = msgs.get(0) + assertEquals(topic1!!.size, 0) + } + + /** + * Tests the event properties with multiple topics. + */ + @Test + fun testMultiTopicProperties() { + val strList = mutableListOf() + val dmaapClient = dmaapService.blueprintDmaapClientService("multi") + + strList.add("{\n" + + " \"a\" : \"hello\"\n" + + "}") + dmaapClient.sendMessage(strList) + val msgs = dmaapClient.close(2) + assertEquals(msgs!!.size, 2) + val topic1 = msgs.get(0) + assertEquals(topic1!!.size, 0) + val topic2 = msgs.get(1) + assertEquals(topic2!!.size, 0) + } + + + /** + * Tests the event properties with multiple topics with JSON node as input. + */ + @Test + fun testMultiTopicPropertiesWithJsonInput() { + val jsonString = "{\n" + + " \"topic\" : \"cds_json1,cds_json2\",\n" + + " \"type\" : \"HTTPNOAUTH\",\n" + + " \"host\" : \"127.0.0.1:9111\"\n" + + "}" + val mapper = ObjectMapper() + val node = mapper.readTree(jsonString) + val strList = mutableListOf() + val dmaapClient = dmaapService.blueprintDmaapClientService(node) + + strList.add("{\n" + + " \"a\" : \"hello\"\n" + + "}") + dmaapClient.sendMessage(strList) + val msgs = dmaapClient.close(2) + assertEquals(msgs!!.size, 2) + val topic1 = msgs.get(0) + assertEquals(topic1!!.size, 0) + val topic2 = msgs.get(1) + assertEquals(topic2!!.size, 0) + } + + + /** + * Tests the event properties with multiple messages. + */ + @Test + fun testMultiMsgsProperties() { + val strList = mutableListOf() + val dmaapClient = dmaapService.blueprintDmaapClientService("aai") + + strList.add("{\n" + + " \"a\" : \"hello\"\n" + + "}") + strList.add("{\n" + + " \"a\" : \"second\"\n" + + "}") + dmaapClient.sendMessage(strList) + val msgs = dmaapClient.close(2) + assertEquals(msgs!!.size, 1) + val topic1 = msgs.get(0) + assertEquals(topic1!!.size, 0) + } + + /** + * Tests the DMAAP client properties generated with the complete prefix. + */ + @Test + fun testDmaapClientProperties() { + val properties = dmaapService.dmaapClientProperties( + "blueprintsprocessor.dmaapclient.aai") + assertNotNull(properties, "failed to create property bean") + assertNotNull(properties.host, "failed to get url property" + + " in property bean") + } + + /** + * Tests the blueprint DMAAP client service with only selector prefix. + */ + @Test + fun testBlueprintDmaapClientService() { + val blueprintDmaapClientService = + dmaapService.blueprintDmaapClientService("aai") + assertNotNull(blueprintDmaapClientService, + "failed to create blueprintDmaapClientService") + } + +} + +/** + * Rest controller for testing the client request that is sent. + */ +@RestController +@RequestMapping(path = ["/events"]) +open class TestController { + + /** + * Accepts request for a topic and sends a message as response. + */ + @PostMapping(path = ["/{topic}"]) + fun postTopic(@PathVariable(value = "topic") topic : String): + ResponseEntity { + var a = "{\n" + + " \"message\" : \"The message is published into $topic " + + "topic\"\n" + + "}" + return ResponseEntity(a, HttpStatus.OK) + } +} diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/resources/logback-test.xml index 0f76057ad..ebb41b854 100644 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/resources/logback-test.xml +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/src/test/resources/logback-test.xml @@ -31,7 +31,7 @@ - + -- cgit 1.2.3-korg