From 6a6d3afd489ea3b8945f1cdd8a8a74afdcc5221a Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Thu, 10 Oct 2019 15:34:00 -0700 Subject: Dmaap micro service jar Creating a service running in a standalone jar to handle the publishing and recieving of dmaap messages for appc. Dmaap adapter and event listener code is copeid from the main appc project. It will be moved in a later commit. Change-Id: I3fa7b5dc60345f0f38f763a243150b8472f985ac Signed-off-by: Patrick Brady Issue-ID: APPC-1744 --- .../appc-message-adapter-factory/.gitignore | 1 + .../appc-message-adapter-factory/pom.xml | 79 ++++++++++++++++++++++ .../factory/DmaapMessageAdapterFactoryImpl.java | 59 ++++++++++++++++ .../onap/appc/adapter/factory/MessageService.java | 58 ++++++++++++++++ .../resources/org/onap/appc/default.properties | 25 +++++++ .../DmaapMessageAdapterFactoryImplTest.java | 58 ++++++++++++++++ .../appc/adapter/factory/MessageServiceTest.java | 49 ++++++++++++++ 7 files changed, 329 insertions(+) create mode 100644 services/appc-dmaap-service/appc-message-adapter-factory/.gitignore create mode 100644 services/appc-dmaap-service/appc-message-adapter-factory/pom.xml create mode 100644 services/appc-dmaap-service/appc-message-adapter-factory/src/main/java/org/onap/appc/adapter/factory/DmaapMessageAdapterFactoryImpl.java create mode 100644 services/appc-dmaap-service/appc-message-adapter-factory/src/main/java/org/onap/appc/adapter/factory/MessageService.java create mode 100644 services/appc-dmaap-service/appc-message-adapter-factory/src/main/resources/org/onap/appc/default.properties create mode 100644 services/appc-dmaap-service/appc-message-adapter-factory/src/test/java/org/onap/appc/adapter/factory/DmaapMessageAdapterFactoryImplTest.java create mode 100644 services/appc-dmaap-service/appc-message-adapter-factory/src/test/java/org/onap/appc/adapter/factory/MessageServiceTest.java (limited to 'services/appc-dmaap-service/appc-message-adapter-factory') diff --git a/services/appc-dmaap-service/appc-message-adapter-factory/.gitignore b/services/appc-dmaap-service/appc-message-adapter-factory/.gitignore new file mode 100644 index 000000000..eacf31a67 --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-factory/.gitignore @@ -0,0 +1 @@ +/target-ide/ diff --git a/services/appc-dmaap-service/appc-message-adapter-factory/pom.xml b/services/appc-dmaap-service/appc-message-adapter-factory/pom.xml new file mode 100644 index 000000000..f234c92dd --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-factory/pom.xml @@ -0,0 +1,79 @@ + + + + 4.0.0 + + org.onap.appc.parent + binding-parent + 2.6.2 + + + + org.onap.appc.services.dmaap + appc-message-adapter-factory + jar + appc-message-adapter-factory + + + + + org.onap.appc.services.dmaap + appc-dmaap-adapter-bundle + ${project.version} + provided + + + + org.onap.appc.services.dmaap + appc-message-adapter-api + ${project.version} + provided + + + + junit + junit + test + + + + + org.mockito + mockito-core + test + + + org.powermock + powermock-api-mockito + test + + + + org.powermock + powermock-module-junit4 + test + + + + + 1.7.0-SNAPSHOT + diff --git a/services/appc-dmaap-service/appc-message-adapter-factory/src/main/java/org/onap/appc/adapter/factory/DmaapMessageAdapterFactoryImpl.java b/services/appc-dmaap-service/appc-message-adapter-factory/src/main/java/org/onap/appc/adapter/factory/DmaapMessageAdapterFactoryImpl.java new file mode 100644 index 000000000..d182f4769 --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-factory/src/main/java/org/onap/appc/adapter/factory/DmaapMessageAdapterFactoryImpl.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2019 Ericsson + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.appc.adapter.factory; + +import java.util.Collection; +import java.util.Set; + +import org.onap.appc.adapter.message.Consumer; +import org.onap.appc.adapter.message.MessageAdapterFactory; +import org.onap.appc.adapter.message.Producer; +import org.onap.appc.adapter.messaging.dmaap.http.HttpDmaapConsumerImpl; +import org.onap.appc.adapter.messaging.dmaap.http.HttpDmaapProducerImpl; + +public class DmaapMessageAdapterFactoryImpl implements MessageAdapterFactory { + + + @Override + public Producer createProducer(Collection pools, String writeTopic, String apiKey, String apiSecret) { + return new HttpDmaapProducerImpl(pools, writeTopic); + } + + @Override + public Producer createProducer(Collection pools, Set writeTopics, String apiKey, String apiSecret) { + String topic = ""; + for(String s : writeTopics){ + topic = s; + } + return new HttpDmaapProducerImpl(pools, topic); + } + + @Override + public Consumer createConsumer(Collection pool, String readTopic, + String clientName, String clientId, String filterJson, String apiKey, String apiSecret) { + return new HttpDmaapConsumerImpl(pool, readTopic, clientName, clientId, apiKey, apiSecret, filterJson); + } +} diff --git a/services/appc-dmaap-service/appc-message-adapter-factory/src/main/java/org/onap/appc/adapter/factory/MessageService.java b/services/appc-dmaap-service/appc-message-adapter-factory/src/main/java/org/onap/appc/adapter/factory/MessageService.java new file mode 100644 index 000000000..f7c51be29 --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-factory/src/main/java/org/onap/appc/adapter/factory/MessageService.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.adapter.factory; +/** + * The message service types that are available. Only DMaaP available + **/ +public enum MessageService { + DMaaP("dmaap"); + + private String val; + + private MessageService(String val) { + this.val = val; + } + + public String getValue() { + return val; + } + + /** + * Tries to match a string to a MessageService. If no match is found, returns the default (DMaaP) + * + * @param input + * the string to try and match + * @return A MessasgeService + */ + public static MessageService parse(String input) { + if (input != null) { + for (MessageService ms : MessageService.values()) { + if (input.equalsIgnoreCase(ms.getValue())) { + return ms; + } + } + } + return MessageService.DMaaP; // Default + } +} diff --git a/services/appc-dmaap-service/appc-message-adapter-factory/src/main/resources/org/onap/appc/default.properties b/services/appc-dmaap-service/appc-message-adapter-factory/src/main/resources/org/onap/appc/default.properties new file mode 100644 index 000000000..da25a66a4 --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-factory/src/main/resources/org/onap/appc/default.properties @@ -0,0 +1,25 @@ +### +# ============LICENSE_START======================================================= +# ONAP : APPC +# ================================================================================ +# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Copyright (C) 2017 Amdocs +# ============================================================================= +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END========================================================= +### + +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=/opt/onap/appc/data/properties,${user.home},. diff --git a/services/appc-dmaap-service/appc-message-adapter-factory/src/test/java/org/onap/appc/adapter/factory/DmaapMessageAdapterFactoryImplTest.java b/services/appc-dmaap-service/appc-message-adapter-factory/src/test/java/org/onap/appc/adapter/factory/DmaapMessageAdapterFactoryImplTest.java new file mode 100644 index 000000000..bfc469d7b --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-factory/src/test/java/org/onap/appc/adapter/factory/DmaapMessageAdapterFactoryImplTest.java @@ -0,0 +1,58 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 Ericsson + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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.appc.adapter.factory; + +import static org.junit.Assert.assertTrue; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import org.junit.Before; +import org.junit.Test; +import org.onap.appc.adapter.message.Consumer; +import org.onap.appc.adapter.message.Producer; + +public class DmaapMessageAdapterFactoryImplTest { + + private DmaapMessageAdapterFactoryImpl factory; + private Collection pools; + + @Before + public void setup() { + factory = new DmaapMessageAdapterFactoryImpl(); + pools = new ArrayList<>(); + pools.add("http://server:1"); + } + + @Test + public void testCreateProducer() { + Set writeTopics = new HashSet<>(); + assertTrue(factory.createProducer(pools, writeTopics, null, null) instanceof Producer); + assertTrue(factory.createProducer(pools, "TEST" , null, null) instanceof Producer); + } + + @Test + public void testCreateConsumer() { + assertTrue(factory.createConsumer(pools, "TEST", null, null, null, null, null) instanceof Consumer); + } + +} diff --git a/services/appc-dmaap-service/appc-message-adapter-factory/src/test/java/org/onap/appc/adapter/factory/MessageServiceTest.java b/services/appc-dmaap-service/appc-message-adapter-factory/src/test/java/org/onap/appc/adapter/factory/MessageServiceTest.java new file mode 100644 index 000000000..47fa1f6f3 --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-factory/src/test/java/org/onap/appc/adapter/factory/MessageServiceTest.java @@ -0,0 +1,49 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : APPC +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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.appc.adapter.factory; + +import org.junit.Assert; +import org.junit.Test; + +public class MessageServiceTest { + + private MessageService messageService = MessageService.DMaaP; + + @Test + public void testName() { + Assert.assertEquals("DMaaP", messageService.name()); + } + + @Test + public void testGetValue() { + Assert.assertEquals("dmaap", messageService.getValue()); + } + + @Test + public void testParse() { + Assert.assertEquals(messageService, MessageService.parse("DMAAP")); + } + + @Test + public void testParse_Null() { + Assert.assertEquals(MessageService.DMaaP, MessageService.parse(null)); + } + +} -- cgit 1.2.3-korg