Change code to use dmaap microservice 17/97717/5
authorPatrick Brady <patrick.brady@att.com>
Tue, 29 Oct 2019 19:50:10 +0000 (12:50 -0700)
committerTakamune Cho <takamune.cho@att.com>
Fri, 8 Nov 2019 16:39:57 +0000 (16:39 +0000)
Change method calls that used to go to the dmaap adapter, to
now go to the appc service communicator, which connects to the
dmaap micro service.

Change-Id: I619fcb408e14fa0b926950192463d9c92ab7dbba
Signed-off-by: Patrick Brady <patrick.brady@att.com>
Issue-ID: APPC-1744

36 files changed:
appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/pom.xml
appc-adapters/pom.xml
appc-dg-util/appc-dg-util-bundle/pom.xml
appc-dg/appc-dg-shared/appc-dg-common/pom.xml
appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImpl.java
appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImpl.java
appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/OSGI-INF/blueprint/blueprint.xml
appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java
appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java [deleted file]
appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImplTest.java
appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/MockEventSender.java [new file with mode: 0644]
appc-dispatcher/appc-command-executor/appc-command-executor-core/pom.xml
appc-dispatcher/appc-request-handler/appc-request-handler-core/pom.xml
appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/messageadapter/impl/MessageAdapterImpl.java
appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/messageadapter/impl/MessageAdapterImplTest.java
appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/RequestHandlerTest.java
appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/LocalRequestHanlderTestHelper.java
appc-dispatcher/appc-request-handler/appc-request-handler-features/onap-appc-request-handler/pom.xml
appc-oam/appc-oam-bundle/pom.xml
appc-oam/appc-oam-bundle/src/main/java/org/onap/appc/oam/messageadapter/MessageAdapter.java
appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/messageadapter/MessageAdapterTest.java
appc-sdc-listener/appc-sdc-listener-bundle/pom.xml
appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/artifacts/impl/AbstractArtifactProcessor.java
appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/artifacts/impl/ArtifactProcessorFactory.java
appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/artifacts/impl/ConfigArtifactProcessor.java
appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/artifacts/impl/LicenseArtifactProcessor.java
appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/artifacts/impl/ToscaCsarArtifactProcessor.java
appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/SdcCallback.java
appc-sdc-listener/appc-sdc-listener-bundle/src/test/java/org/onap/appc/sdc/artifacts/impl/TestAbstractArtifactProcessor.java
appc-sdc-listener/appc-sdc-listener-bundle/src/test/java/org/onap/appc/sdc/artifacts/impl/TestArtifactProcessor.java
appc-sdc-listener/appc-sdc-listener-bundle/src/test/java/org/onap/appc/sdc/artifacts/impl/TestConfigArtifcatProcessor.java
appc-sdc-listener/appc-sdc-listener-bundle/src/test/java/org/onap/appc/sdc/artifacts/impl/TestLicenseArtifactProcessor.java
appc-sdc-listener/appc-sdc-listener-bundle/src/test/java/org/onap/appc/sdc/artifacts/impl/TestToscaCsarArtifactProcessor.java
appc-sdc-listener/appc-sdc-listener-bundle/src/test/java/org/onap/appc/sdc/listener/SdcCallbackTest.java
pom.xml
services/appc-dmaap-service/appc-dmaap-event-service/src/main/java/org/onap/appc/services/dmaapService/AuthenticationConfig.java

index 7286ec9..d6168a3 100644 (file)
                        <artifactId>appc-common-bundle</artifactId>
                        <version>${project.version}</version>
                </dependency>
+               <dependency>
+                       <groupId>org.onap.appc</groupId>
+                       <artifactId>appc-service-communicator-bundle</artifactId>
+                       <version>${project.version}</version>
+               </dependency>
                <dependency>
                        <groupId>javax</groupId>
                        <artifactId>javaee-api</artifactId>
index ee88e66..0e06886 100644 (file)
@@ -3,7 +3,7 @@
   ============LICENSE_START=======================================================
   ONAP : APPC
   ================================================================================
-  Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+  Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
   Copyright (C) 2017 Amdocs
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,7 +35,6 @@
                <module>appc-chef-adapter</module>
                <module>appc-rest-adapter</module>
                <module>appc-iaas-adapter</module>
-               <module>appc-dmaap-adapter</module>
                <module>appc-netconf-adapter</module>
                <module>appc-ssh-adapter</module>
                <module>appc-rest-healthcheck-adapter</module>
index f59079a..f57a544 100644 (file)
             <groupId>org.json</groupId>
             <artifactId>json</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.onap.appc</groupId>
-            <artifactId>appc-dmaap-adapter-bundle</artifactId>
-            <version>${project.version}</version>
-        </dependency>
         <dependency>
             <groupId>org.onap.appc</groupId>
             <artifactId>appc-netconf-adapter-bundle</artifactId>
index d478c83..d0b3786 100644 (file)
@@ -3,7 +3,7 @@
   ============LICENSE_START=======================================================
   ONAP : APPC
   ================================================================================
-  Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+  Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
   Copyright (C) 2017 Amdocs
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
                </dependency>
                <dependency>
                        <groupId>org.onap.appc</groupId>
-                       <artifactId>appc-message-adapter-api</artifactId>
+                       <artifactId>appc-service-communicator-bundle</artifactId>
                        <version>${project.version}</version>
-                       <scope>provided</scope>
-                       <!-- TODO: WA for fixing build, clueanup dependency tree -->
-                       <exclusions>
-                               <exclusion>
-                                       <groupId>equinoxSDK381</groupId>
-                                       <artifactId>org.eclipse.osgi</artifactId>
-                               </exclusion>
-                       </exclusions>
-               </dependency>
-               <dependency>
-                       <groupId>org.onap.appc</groupId>
-                       <artifactId>appc-dmaap-adapter-bundle</artifactId>
-                       <version>${project.version}</version>
-                       <scope>provided</scope>
-                       <!-- TODO: WA for fixing build, clueanup dependency tree -->
-                       <exclusions>
-                               <exclusion>
-                                       <groupId>equinoxSDK381</groupId>
-                                       <artifactId>org.eclipse.osgi</artifactId>
-                               </exclusion>
-                       </exclusions>
-               </dependency>
-               <dependency>
-                       <groupId>org.onap.appc</groupId>
-                       <artifactId>appc-message-adapter-factory</artifactId>
-                       <version>${project.version}</version>
-                       <scope>provided</scope>
-                       <!-- TODO: WA for fixing build, clueanup dependency tree -->
-                       <exclusions>
-                               <exclusion>
-                                       <groupId>equinoxSDK381</groupId>
-                                       <artifactId>org.eclipse.osgi</artifactId>
-                               </exclusion>
-                       </exclusions>
                </dependency>
                <dependency>
                        <groupId>org.onap.ccsdk.sli.core</groupId>
                                                <Bundle-SymbolicName>appc-dg-common</Bundle-SymbolicName>
                                                <Export-Package>org.onap.appc.dg.common,org.onap.appc.dg.common.objects,org.onap.appc.dg.common.utils</Export-Package>
                                                <Private-Package>org.onap.appc.dg.common.impl.*</Private-Package>
-                                               <Import-Package>org.onap.appc.adapter.message.*,org.onap.appc.adapter.factory.*,org.onap.appc.adapter.messaging.*,
-                                                       *;resolution:=optional</Import-Package>
+                                               <Import-Package>org.onap.appc.srvcomm.messaging.event,org.onap.appc.srvcomm.messaging,*;resolution:=optional</Import-Package>
                                                <Embed-Dependency>appc-dg-mdsal-bundle,appc-dg-domain-model-lib,appc-dg-dependency-model,jackson-dataformat-yaml,jackson-databind,jackson-core,jackson-annotations;scope=compile|runtime;inline=false;artifactId=!org.eclipse.osgi</Embed-Dependency>
 
                                                <!--Embed-Dependency>eelf-core,logback-core,logback-classic;scope=compile|runtime;inline=false</Embed-Dependency-->
index b244d31..c69d1fe 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
@@ -25,11 +25,11 @@ package org.onap.appc.dg.common.impl;
 
 import java.util.Map;
 import org.apache.commons.lang3.StringUtils;
-import org.onap.appc.adapter.message.EventSender;
-import org.onap.appc.adapter.message.MessageDestination;
-import org.onap.appc.adapter.message.event.EventHeader;
-import org.onap.appc.adapter.message.event.EventMessage;
-import org.onap.appc.adapter.message.event.EventStatus;
+import org.onap.appc.srvcomm.messaging.event.EventSender;
+import org.onap.appc.srvcomm.messaging.MessageDestination;
+import org.onap.appc.srvcomm.messaging.event.EventHeader;
+import org.onap.appc.srvcomm.messaging.event.EventMessage;
+import org.onap.appc.srvcomm.messaging.event.EventStatus;
 import org.onap.appc.dg.common.DCAEReporterPlugin;
 import org.onap.appc.exceptions.APPCException;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
index 4cef625..3efbc02 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * ================================================================================
@@ -36,11 +36,10 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 import org.apache.commons.lang3.StringUtils;
-import org.onap.appc.adapter.message.MessageAdapterFactory;
-import org.onap.appc.adapter.message.Producer;
 import org.onap.appc.configuration.ConfigurationFactory;
 import org.onap.appc.dg.common.IntermediateMessageSender;
 import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.srvcomm.messaging.MessagingConnector;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.FrameworkUtil;
@@ -52,8 +51,9 @@ public class IntermediateMessageSenderImpl implements IntermediateMessageSender
 
     private static final String PARAM_MESSAGE = "message";
     private static final String ATTR_REQUEST_ID = "input.common-header.request-id";
+    private static final String PROPERTIES_PREFIX = "appc.LCM";
 
-    private Producer producer;
+    private MessagingConnector messageService;
 
     private static final String STATUS = "STATUS";
     private static final String FAILURE = "FAILURE";
@@ -64,29 +64,10 @@ public class IntermediateMessageSenderImpl implements IntermediateMessageSender
     private static final String MSO = "MSO";
 
     public void init() {
-        Properties properties =  ConfigurationFactory.getConfiguration().getProperties();
-
-        String writeTopic = properties.getProperty("appc.LCM.topic.write");
-        String apiKey = properties.getProperty("appc.LCM.client.key");
-        String apiSecret = properties.getProperty("appc.LCM.client.secret");
-        String hostNames = properties.getProperty("appc.LCM.poolMembers");
-
-        logger.debug("Configuration Read : writeTopic = " + writeTopic + ", " +
-            "hostNames = " + hostNames);
-
-        Set<String> pool = new HashSet<>();
-        if (!StringUtils.isEmpty(hostNames)) {
-            pool.addAll(Arrays.asList(hostNames.split(",")));
-        }
-
-        BundleContext ctx = FrameworkUtil.getBundle(IntermediateMessageSenderImpl.class).getBundleContext();
-        if (ctx != null) {
-            ServiceReference svcRef = ctx.getServiceReference(MessageAdapterFactory.class.getName());
-            if (svcRef != null) {
-                MessageAdapterFactory messageAdapterFactory = ((MessageAdapterFactory) ctx.getService(svcRef));
-                    producer = messageAdapterFactory.createProducer(pool, writeTopic, apiKey, apiSecret);
-            }
-        }
+        messageService = new MessagingConnector();
+    }
+    public void init(MessagingConnector messagingConnector) {
+        messageService = messagingConnector;
     }
 
     @Override
@@ -97,7 +78,7 @@ public class IntermediateMessageSenderImpl implements IntermediateMessageSender
             validateInputs(params, context);
             String jsonMessage = getJsonMessage(params, context);
             logger.debug("Constructed JSON Message : " + jsonMessage);
-            producer.post("", jsonMessage);
+            messageService.publishMessage(PROPERTIES_PREFIX, "", jsonMessage);
             context.setAttribute(prefix + STATUS, SUCCESS);
         } catch (Exception e) {
             String errorMessage = "Error sending intermediate message to initiator " + e.getMessage();
index ff6b824..a90f463 100644 (file)
@@ -3,7 +3,7 @@
   ============LICENSE_START=======================================================
   ONAP : APPC
   ================================================================================
-  Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+  Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
   ================================================================================
   Copyright (C) 2017 Amdocs
   =============================================================================
@@ -33,7 +33,7 @@
     <service id="JsonDgUtil" interface="org.onap.appc.dg.common.JsonDgUtil" ref="JsonDgUtilBean"/>
 
     <reference id="eventSenderReference" availability="mandatory" activation="eager"
-               interface="org.onap.appc.adapter.message.EventSender"/>
+               interface="org.onap.appc.srvcomm.messaging.event.EventSender"/>
 
     <bean id="DCAEReporterPluginBean" class="org.onap.appc.dg.common.impl.DCAEReporterPluginImpl"
           scope="singleton">
index 95f7ba7..1816f52 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * ================================================================================
@@ -30,27 +30,16 @@ import java.util.Map;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Matchers;
 import org.mockito.Mockito;
-import org.mockito.Spy;
-import org.onap.appc.adapter.message.EventSender;
-import org.onap.appc.adapter.message.MessageDestination;
-import org.onap.appc.adapter.message.event.EventMessage;
 import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.srvcomm.messaging.MessageDestination;
+import org.onap.appc.srvcomm.messaging.event.EventMessage;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.ServiceReference;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
 
 
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(FrameworkUtil.class)
 public class DCAEReporterPluginImplTest {
     private SvcLogicContext ctx;
     private Map<String, String> params;
@@ -59,10 +48,8 @@ public class DCAEReporterPluginImplTest {
     private final Bundle bundleService = Mockito.mock(Bundle.class);
     private final ServiceReference sref = Mockito.mock(ServiceReference.class);
 
-    @InjectMocks
     private DCAEReporterPluginImpl dcaeReporterPlugin;
-    @Spy
-    private EventSenderMock eventSender = new EventSenderMock();
+    private MockEventSender eventSender;
 
     private String apiVer = "2.0.0";
     private String requestId = "123";
@@ -71,11 +58,10 @@ public class DCAEReporterPluginImplTest {
     @SuppressWarnings("unchecked")
     @Before
     public void setUp() throws NoSuchFieldException, IllegalAccessException {
-        PowerMockito.mockStatic(FrameworkUtil.class);
-        PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
-        PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
-        PowerMockito.when(bundleContext.getServiceReference(Matchers.any(Class.class))).thenReturn(sref);
-        PowerMockito.when(bundleContext.<EventSender>getService(sref)).thenReturn(eventSender);
+        eventSender = new MockEventSender();
+        dcaeReporterPlugin = new DCAEReporterPluginImpl();
+        dcaeReporterPlugin.setEventSender(eventSender);
+        
     }
 
     @Test
@@ -110,7 +96,7 @@ public class DCAEReporterPluginImplTest {
         ctx.setAttribute("input.common-header.api-ver", apiVer);
         ctx.setAttribute("input.common-header.request-id", requestId);
         dcaeReporterPlugin.report(params, ctx);
-        EventMessage msg = eventSender.getMsg();
+        EventMessage msg = eventSender.getMessage();
         Assert.assertEquals("ERROR DESCRIPTION", msg.getEventStatus().getReason());
     }
 
@@ -120,14 +106,15 @@ public class DCAEReporterPluginImplTest {
         params = new HashMap<>();
         params.put(Constants.DG_ERROR_CODE, "200");
         dcaeReporterPlugin.reportSuccess(params, ctx);
-        EventMessage msg = eventSender.getMsg();
+        EventMessage msg = eventSender.getMessage();
         Assert.assertEquals(new Integer(500), msg.getEventStatus().getCode());
     }
 
     private void errorReasonNullAssert() throws APPCException {
+        eventSender.reset();
         dcaeReporterPlugin.report(params, ctx);
         MessageDestination destination = eventSender.getDestination();
-        EventMessage msg = eventSender.getMsg();
+        EventMessage msg = eventSender.getMessage();
         Assert.assertEquals("wrong API version", apiVer, msg.getEventHeader().getApiVer());
         Assert.assertEquals("wrong requestId", requestId, msg.getEventHeader().getEventId());
         Assert.assertEquals("wrong error message", "Unknown", msg.getEventStatus().getReason());
@@ -135,9 +122,10 @@ public class DCAEReporterPluginImplTest {
     }
 
     private void positiveAssert() throws APPCException {
+        eventSender.reset();
         dcaeReporterPlugin.report(params, ctx);
         MessageDestination destination = eventSender.getDestination();
-        EventMessage msg = eventSender.getMsg();
+        EventMessage msg = eventSender.getMessage();
         Assert.assertEquals("wrong API version", apiVer, msg.getEventHeader().getApiVer());
         Assert.assertEquals("wrong requestId", requestId, msg.getEventHeader().getEventId());
         Assert.assertEquals("wrong error message", error, msg.getEventStatus().getReason());
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java
deleted file mode 100644 (file)
index 5495995..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*-
- * ============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.dg.common.impl;
-
-import java.util.Map;
-import org.onap.appc.adapter.message.EventSender;
-import org.onap.appc.adapter.message.MessageDestination;
-import org.onap.appc.adapter.message.event.EventMessage;
-import org.onap.appc.exceptions.APPCException;
-import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-
-
-public class EventSenderMock implements EventSender {
-    EventMessage msg;
-    MessageDestination destination;
-
-    @Override
-    public boolean sendEvent(MessageDestination destination, EventMessage msg) {
-        if (destination != null && msg != null){
-            this.msg = msg;
-            this.destination = destination;
-            return true;
-        }
-        else{
-            return false;
-        }
-    }
-
-    @Override
-    public boolean sendEvent(MessageDestination destination, EventMessage msg, String eventTopicName) {
-        return false;
-    }
-
-    @Override
-    public boolean sendEvent(MessageDestination destination, Map<String, String> params, SvcLogicContext ctx) throws APPCException {
-        return false;
-    }
-
-    public EventMessage getMsg() {
-        return msg;
-    }
-
-    public MessageDestination getDestination() {
-        return destination;
-    }
-}
index 74c1ec7..33761f9 100644 (file)
@@ -3,7 +3,9 @@
  * ONAP : APPC
  * ================================================================================
  * Copyright (C) 2018 Ericsson
- * =============================================================================
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. 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
@@ -24,58 +26,27 @@ package org.onap.appc.dg.common.impl;
 import java.util.HashMap;
 import java.util.Map;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Matchers;
 import org.mockito.Mockito;
-import org.mockito.Spy;
-import org.onap.appc.adapter.message.MessageAdapterFactory;
-import org.onap.appc.adapter.message.Producer;
+import org.onap.appc.srvcomm.messaging.MessagingConnector;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
 
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(FrameworkUtil.class)
 public class IntermediateMessageSenderImplTest {
 
     private SvcLogicContext ctx;
     private Map<String, String> params;
 
-    private final BundleContext bundleContext = Mockito.mock(BundleContext.class);
-    private final Bundle bundleService = Mockito.mock(Bundle.class);
-    private final ServiceReference sref = Mockito.mock(ServiceReference.class);
-    private final MessageAdapterFactory mockFactory = Mockito.mock(MessageAdapterFactory.class);
-    private final Producer mockProducer = Mockito.mock(Producer.class);
 
-    @InjectMocks
     private IntermediateMessageSenderImpl intermediateMessageSenderImpl;
 
-    @Spy
-    private EventSenderMock eventSender = new EventSenderMock();
 
-    @SuppressWarnings("unchecked")
-    @Before
-    public void setUp() throws NoSuchFieldException, IllegalAccessException {
-        PowerMockito.mockStatic(FrameworkUtil.class);
-        PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
-        PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
-        PowerMockito.when(bundleContext.getServiceReference(Matchers.any(Class.class))).thenReturn(sref);
-        PowerMockito.when(bundleContext.<MessageAdapterFactory>getService(sref)).thenReturn(mockFactory);
-        PowerMockito.when(mockFactory.createProducer(Matchers.anyCollection(), Mockito.anyString(), Mockito.anyString(),
-                Mockito.anyString())).thenReturn(mockProducer);
-    }
 
     @Test
     public void testSendEmptyMessage() {
-        intermediateMessageSenderImpl.init();
+        intermediateMessageSenderImpl = new IntermediateMessageSenderImpl();
+        MessagingConnector msgConn = Mockito.mock(MessagingConnector.class);
+        Mockito.when(msgConn.publishMessage(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(false);
+        intermediateMessageSenderImpl.init(msgConn);
         ctx = new SvcLogicContext();
         params = new HashMap<>();
         intermediateMessageSenderImpl.sendMessage(params, ctx);
@@ -84,7 +55,10 @@ public class IntermediateMessageSenderImplTest {
 
     @Test
     public void testSendMessage() {
-        intermediateMessageSenderImpl.init();
+        intermediateMessageSenderImpl = new IntermediateMessageSenderImpl();
+        MessagingConnector msgConn = Mockito.mock(MessagingConnector.class);
+        Mockito.when(msgConn.publishMessage(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(true);
+        intermediateMessageSenderImpl.init(msgConn);
         ctx = new SvcLogicContext();
         ctx.setAttribute("input.common-header.request-id", "REQUEST-ID");
         params = new HashMap<>();
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/MockEventSender.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/MockEventSender.java
new file mode 100644 (file)
index 0000000..2a795e9
--- /dev/null
@@ -0,0 +1,52 @@
+package org.onap.appc.dg.common.impl;
+
+import org.onap.appc.srvcomm.messaging.MessageDestination;
+import org.onap.appc.srvcomm.messaging.event.EventMessage;
+import org.onap.appc.srvcomm.messaging.event.EventSender;
+
+public class MockEventSender extends EventSender {
+    
+    private EventMessage eventMessage;
+    private String topic;
+    private MessageDestination dest;
+    private boolean success = true;
+    
+    @Override
+    public boolean sendEvent(MessageDestination destination, EventMessage msg, String eventTopicName) {
+        eventMessage = msg;
+        topic = eventTopicName;
+        dest = destination;
+        return success;
+    }
+    
+    @Override
+    public boolean sendEvent(MessageDestination destination, EventMessage msg) {
+        eventMessage = msg;
+        topic = null;
+        dest = destination;
+        return success;
+    }
+    public void reset() {
+        eventMessage = null;
+        topic = null;
+        dest = null;
+        success = true;
+    }
+    
+    public void setSuccess(boolean success) {
+        this.success = success;
+    }
+    
+    public EventMessage getMessage() {
+        return eventMessage;
+    }
+    
+    public String getTopic() {
+        return topic;
+    }
+    
+    public MessageDestination getDestination() {
+        return dest;
+    }
+
+}
index d8c0201..8a77af8 100644 (file)
             <artifactId>appc-data-access-lib</artifactId>
             <version>${project.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.onap.appc</groupId>
-            <artifactId>appc-dmaap-adapter-bundle</artifactId>
-            <version>${project.version}</version>
-        </dependency>
         <dependency>
             <groupId>org.onap.appc</groupId>
             <artifactId>appc-lifecycle-management-api</artifactId>
index e61bf1d..5bdf34e 100644 (file)
         </dependency>
         <dependency>
             <groupId>org.onap.appc</groupId>
-            <artifactId>appc-dmaap-adapter-bundle</artifactId>
-            <version>${project.version}</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.onap.appc</groupId>
-            <artifactId>appc-message-adapter-api</artifactId>
-            <version>${project.version}</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.onap.appc</groupId>
-            <artifactId>appc-message-adapter-factory</artifactId>
+            <artifactId>appc-service-communicator-bundle</artifactId>
             <version>${project.version}</version>
             <scope>provided</scope>
         </dependency>
index 8c518fe..65f5155 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * ================================================================================
 
 package org.onap.appc.messageadapter.impl;
 
-
-import org.onap.appc.adapter.factory.MessageService;
-import org.onap.appc.adapter.message.MessageAdapterFactory;
-import org.onap.appc.adapter.message.Producer;
-import org.onap.appc.configuration.Configuration;
-import org.onap.appc.configuration.ConfigurationFactory;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -39,23 +33,12 @@ import org.onap.appc.domainmodel.lcm.ResponseContext;
 import org.onap.appc.domainmodel.lcm.VNFOperation;
 import org.onap.appc.messageadapter.MessageAdapter;
 import org.onap.appc.requesthandler.conv.Converter;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
-
-import java.util.HashSet;
-import java.util.Properties;
+import org.onap.appc.srvcomm.messaging.MessagingConnector;
 
 public class MessageAdapterImpl implements MessageAdapter{
 
-    private MessageService messageService;
-    private Producer producer;
+    private MessagingConnector messageService;
     private String partition ;
-    private Configuration configuration;
-    private HashSet<String> pool;
-    private String writeTopic;
-    private String apiKey;
-    private String apiSecret;
 
     private static final EELFLogger logger = EELFManager.getInstance().getLogger(MessageAdapterImpl.class);
 
@@ -65,44 +48,12 @@ public class MessageAdapterImpl implements MessageAdapter{
     @Override
     public void init(){
        logger.debug("MessageAdapterImpl - init");
-        this.producer = getProducer();
-    }
-
-    private Producer getProducer() {
-        configuration = ConfigurationFactory.getConfiguration();
-        Properties properties = configuration.getProperties();
-        updateProperties(properties);
-
-        BundleContext ctx = FrameworkUtil.getBundle(MessageAdapterImpl.class).getBundleContext();
-        if (ctx != null) {
-            ServiceReference svcRef = ctx.getServiceReference(MessageAdapterFactory.class.getName());
-            if (svcRef != null) {
-                producer = ((MessageAdapterFactory) ctx.getService(svcRef)).createProducer(pool, writeTopic, apiKey, apiSecret);
-            }
-        }
-        return producer;
+        this.messageService = new MessagingConnector();
     }
-
-
-    private void updateProperties(Properties props) {
-        if (logger.isTraceEnabled()) {
-            logger.trace("Entering to updateProperties with Properties = " + ObjectUtils.toString(props));
-        }
-        pool = new HashSet<>();
-        if (props != null) {
-            // readTopic = props.getProperty("dmaap.topic.read");
-            writeTopic = props.getProperty("appc.LCM.topic.write");
-            apiKey = props.getProperty("appc.LCM.client.key");
-            apiSecret = props.getProperty("appc.LCM.client.secret");
-            messageService = MessageService.parse(props.getProperty("message.service.type"));
-            //  READ_TIMEOUT = Integer.valueOf(props.getProperty("dmaap.topic.read.timeout", String.valueOf(READ_TIMEOUT)));
-            String hostnames = props.getProperty("appc.LCM.poolMembers");
-            if (hostnames != null && !hostnames.isEmpty()) {
-                for (String name : hostnames.split(",")) {
-                    pool.add(name);
-                }
-            }
-        }
+    
+    public void init(MessagingConnector connector) {
+        logger.debug("MessageAdapterImpl - init");
+        this.messageService = connector;
     }
 
     /**
@@ -125,7 +76,7 @@ public class MessageAdapterImpl implements MessageAdapter{
                 logger.debug("DMaaP Response = " + jsonMessage);
             }
             logger.debug("Before Invoking producer.post(): jsonMessage is::" + jsonMessage);
-            success = producer.post(this.partition, jsonMessage);
+            success = messageService.publishMessage("appc.LCM", this.partition, jsonMessage);
             logger.debug("After Invoking producer.post()");
         } catch (JsonProcessingException e1) {
             logger.error("Error generating Json from DMaaP message " + e1.getMessage());
index d5c3534..81c0026 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (C) 2019 Ericsson
  * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. 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
 
 package org.onap.appc.messageadapter.impl;
 
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+
+import javax.ws.rs.core.Response.Status;
+
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.runner.RunWith;
 import org.mockito.Mockito;
-import org.mockito.internal.util.reflection.Whitebox;
-import org.onap.appc.adapter.message.MessageAdapterFactory;
-import org.onap.appc.adapter.message.Producer;
-import org.onap.appc.configuration.Configuration;
-import org.onap.appc.configuration.ConfigurationFactory;
-import org.onap.appc.requesthandler.conv.Converter;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.onap.appc.domainmodel.lcm.CommonHeader;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+import org.onap.appc.domainmodel.lcm.VNFOperation;
+import org.onap.appc.srvcomm.messaging.MessagingConnector;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 import com.fasterxml.jackson.core.JsonProcessingException;
-import com.att.eelf.configuration.EELFLogger.Level;
 
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({FrameworkUtil.class, Converter.class})
 public class MessageAdapterImplTest {
 
-    private Configuration mockConfig = ConfigurationFactory.getConfiguration();
-    private final BundleContext bundleContext = Mockito.mock(BundleContext.class);
-    private final Bundle bundleService = Mockito.mock(Bundle.class);
-    private final ServiceReference sref = Mockito.mock(ServiceReference.class);
-    private final Producer producer = Mockito.mock(Producer.class);
+    private final MessagingConnector connector = Mockito.mock(MessagingConnector.class);
     private static final EELFLogger logger = EELFManager.getInstance().getLogger(MessageAdapterImpl.class);
-    private MessageAdapterImpl impl;
-
+    private final MessageAdapterImpl impl = new MessageAdapterImpl();
+    
     @Before
-    public void setUp() throws Exception {
-        logger.setLevel(Level.TRACE);
-        impl = PowerMockito.spy(new MessageAdapterImpl());
-        //originalLogger = (EELFLogger) Whitebox.getInternalState(MessageAdapterImpl.class, "logger");
-        Whitebox.setInternalState(impl, "configuration", mockConfig);
-        PowerMockito.mockStatic(FrameworkUtil.class);
-        PowerMockito.when(FrameworkUtil.getBundle(MessageAdapterImpl.class)).thenReturn(bundleService);
-        PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
-        PowerMockito.when(bundleContext.getServiceReference(MessageAdapterFactory.class.getName())).thenReturn(sref);
-        PowerMockito.when(bundleContext.getService(sref)).thenReturn(producer);
-        PowerMockito.mockStatic(Converter.class);
-        PowerMockito.when(Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(
-                Mockito.any(), Mockito.any(), Mockito.any())).thenReturn("{}");
+    public void setUp() {
+        impl.init(connector);
     }
 
     @Test
     public void testSuccess() throws JsonProcessingException {
-        PowerMockito.when(Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(
-                Mockito.any(), Mockito.any(), Mockito.any())).thenReturn("{}");
-        Mockito.when(producer.post(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
-        Whitebox.setInternalState(impl, "producer", producer);
-        Whitebox.setInternalState(impl, "partition", "PARTITION");
-        assertTrue(impl.post(null, null, null));
-    }
 
-    @Test
-    public void testJsonException() throws JsonProcessingException {
-        PowerMockito.when(Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(
-                Mockito.any(), Mockito.any(), Mockito.any())).thenThrow(new JsonProcessingException("TEST") {});
-        Whitebox.setInternalState(impl, "partition", "PARTITION");
-        assertFalse(impl.post(null, null, null));
+        ResponseContext context = new ResponseContext();
+        context.setPayload("payload");
+        org.onap.appc.domainmodel.lcm.Status status = new org.onap.appc.domainmodel.lcm.Status();
+        status.setCode(200);
+        status.setMessage("success");
+        context.setStatus(status);
+        CommonHeader commonHeader = new CommonHeader();
+        commonHeader.setRequestId("test123");
+        commonHeader.setSubRequestId("test456");
+        context.setCommonHeader(commonHeader);
+        Mockito.when(connector.publishMessage(Mockito.any(), Mockito.any(),Mockito.any())).thenReturn(true);
+        assertTrue(impl.post(VNFOperation.Start, "test", context));
     }
 
-    @Test
-    public void testException() throws JsonProcessingException {
-        PowerMockito.when(Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(
-                Mockito.any(), Mockito.any(), Mockito.any())).thenThrow(new RuntimeException());
-        Whitebox.setInternalState(impl, "partition", "PARTITION");
-        assertFalse(impl.post(null, null, null));
-    }
 }
index 2c41032..89bb13f 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
@@ -31,8 +31,6 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Matchers;
 import org.mockito.Mockito;
-import org.onap.appc.adapter.factory.DmaapMessageAdapterFactoryImpl;
-import org.onap.appc.adapter.message.MessageAdapterFactory;
 import org.onap.appc.configuration.Configuration;
 import org.onap.appc.configuration.ConfigurationFactory;
 import org.onap.appc.domainmodel.lcm.ActionIdentifiers;
@@ -97,12 +95,6 @@ public class RequestHandlerTest {
     private LockManager lockManager;
     private Configuration configuration;
 
-    private final BundleContext bundleContext=Mockito.mock(BundleContext.class);
-    private final Bundle bundleService=Mockito.mock(Bundle.class);
-    private final ServiceReference sref=Mockito.mock(ServiceReference.class);
-    private MessageAdapterFactory factory = new DmaapMessageAdapterFactoryImpl();
-
-    
     @Before
     public void init() throws Exception {
         configuration = ConfigurationFactory.getConfiguration();
@@ -112,10 +104,6 @@ public class RequestHandlerTest {
         configuration.setProperty("appc.LCM.client.secret" , "TEST");
         
         PowerMockito.mockStatic(FrameworkUtil.class);
-        PowerMockito.when(FrameworkUtil.getBundle(MessageAdapterImpl.class)).thenReturn(bundleService);
-        PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
-        PowerMockito.when(bundleContext.getServiceReference(MessageAdapterFactory.class.getName())).thenReturn(sref);
-        PowerMockito.when(bundleContext.getService(sref)).thenReturn(factory);
         
     
         requestHandler = new RequestHandlerImpl();
index a6bbe57..64f9e22 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
@@ -24,8 +24,6 @@
 package org.onap.appc.requesthandler.impl;
 
 import org.mockito.Mockito;
-import org.onap.appc.adapter.message.MessageAdapterFactory;
-import org.onap.appc.adapter.message.Producer;
 import org.onap.appc.domainmodel.lcm.ActionIdentifiers;
 import org.onap.appc.domainmodel.lcm.ActionLevel;
 import org.onap.appc.domainmodel.lcm.CommonHeader;
@@ -116,14 +114,5 @@ public interface LocalRequestHanlderTestHelper {
 
         BundleContext myBundleContext = mock(BundleContext.class);
         Mockito.when(myBundle.getBundleContext()).thenReturn(myBundleContext);
-
-        ServiceReference svcRef = mock(ServiceReference.class);
-        Mockito.when(myBundleContext.getServiceReference(MessageAdapterFactory.class.getName())).thenReturn(svcRef);
-
-        Producer producer = mock(Producer.class);
-        MessageAdapterFactory factory = mock(MessageAdapterFactory.class);
-        Mockito.when(myBundleContext.getService(svcRef)).thenReturn(factory);
-        Mockito.when(factory.createProducer(anyCollectionOf(String.class), anyString(), anyString(), anyString()))
-        .thenReturn(producer);
     }
 }
index 2333488..0663bd6 100644 (file)
@@ -3,7 +3,7 @@
 ============LICENSE_START=======================================================
 ONAP : APPC
 ================================================================================
-Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+Copyright (C) 2018-2019 AT&T Intellectual Property. 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.
@@ -67,7 +67,7 @@ limitations under the License.
         </dependency>
         <dependency>
             <groupId>org.onap.appc</groupId>
-            <artifactId>appc-message-adapter-api</artifactId>
+            <artifactId>appc-service-communicator-bundle</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
index 5970f79..ef9d46d 100644 (file)
             <artifactId>json</artifactId>
         </dependency>
 
-
-        <dependency>
-            <groupId>org.onap.appc</groupId>
-            <artifactId>appc-message-adapter-api</artifactId>
-            <version>${project.version}</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.onap.appc</groupId>
-            <artifactId>appc-message-adapter-factory</artifactId>
-            <version>${project.version}</version>
-            <scope>provided</scope>
-        </dependency>
         <dependency>
             <groupId>org.onap.appc</groupId>
-            <artifactId>appc-dmaap-adapter-bundle</artifactId>
+            <artifactId>appc-service-communicator-bundle</artifactId>
             <version>${project.version}</version>
             <scope>provided</scope>
         </dependency>
index 7112b7d..f316051 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
@@ -27,118 +27,51 @@ import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import org.apache.commons.lang.ObjectUtils;
-import org.onap.appc.adapter.message.MessageAdapterFactory;
-import org.onap.appc.adapter.message.Producer;
-import org.onap.appc.configuration.Configuration;
-import org.onap.appc.configuration.ConfigurationFactory;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
-
-import java.util.HashSet;
-import java.util.Properties;
+import org.onap.appc.srvcomm.messaging.MessagingConnector;
 
 public class MessageAdapter {
 
     private final EELFLogger logger = EELFManager.getInstance().getLogger(MessageAdapter.class);
 
-    private final String PROP_APPC_OAM_DISABLED = "appc.OAM.disabled";
-    private final String PROP_APPC_OAM_TOPIC_WRITE = "appc.OAM.topic.write";
-    private String PROP_APPC_OAM_CLIENT_KEY = "appc.OAM.client.key";
-    private String PROP_APPC_OAM_CLIENT_SECRET = "appc.OAM.client.secret";
-    private String PROP_APPC_OAM_POOLMEMBERS = "appc.OAM.poolMembers";
+    private static final String  PROPERTIES_PREFIX = "appc.OAM";
 
-    private Producer producer;
+    private MessagingConnector messagingConnector;
     private String partition;
-    private Configuration configuration;
-    private HashSet<String> pool;
-    private String writeTopic;
-    private String apiKey;
-    private String apiSecret;
     private boolean isDisabled;
 
     /**
      * Initialize producer client to post messages using configuration properties.
      */
     public void init() {
-        configuration = ConfigurationFactory.getConfiguration();
-        Properties properties = configuration.getProperties();
-        updateProperties(properties);
 
         if (isAppcOamPropsListenerEnabled()) {
-            createProducer();
+            messagingConnector = new MessagingConnector();
         } else {
             logger.warn(String.format("The listener %s is disabled and will not be run", "appc.OAM"));
         }
     }
+    
+    public void init(MessagingConnector connector) {
 
-    /**
-     * Create producer using MessageAdapterFactory which is found through bundle context.
-     */
-    void createProducer() {
-        BundleContext ctx = FrameworkUtil.getBundle(MessageAdapter.class).getBundleContext();
-        if (ctx == null) {
-            logger.warn("MessageAdapter cannot create producer due to no bundle context.");
-            return;
-        }
-
-        ServiceReference svcRef = ctx.getServiceReference(MessageAdapterFactory.class.getName());
-        if (svcRef == null) {
-            logger.warn("MessageAdapter cannot create producer due to no MessageAdapterFactory service reference.");
-            return;
-        }
-
-        Producer localProducer = ((MessageAdapterFactory) ctx.getService(svcRef)).createProducer(pool, writeTopic,
-                apiKey, apiSecret);
-
-        for (String url : pool) {
-            if (url.contains("3905") || url.contains("https")) {
-                localProducer.useHttps(true);
-                break;
-            }
+        if (isAppcOamPropsListenerEnabled()) {
+            messagingConnector = connector;
+        } else {
+            logger.warn(String.format("The listener %s is disabled and will not be run", "appc.OAM"));
         }
-
-        producer = localProducer;
-
-        logger.debug("MessageAdapter created producer.");
     }
 
-    /**
-     * Read property value to set writeTopic, apiKey, apiSecret and pool.
-     *
-     * @param props of configuration
-     */
-    private void updateProperties(Properties props) {
-        logger.trace("Entering to updateProperties with Properties = " + ObjectUtils.toString(props));
-
-        pool = new HashSet<>();
-        if (props != null) {
-            isDisabled = Boolean.parseBoolean(props.getProperty(PROP_APPC_OAM_DISABLED));
-            writeTopic = props.getProperty(PROP_APPC_OAM_TOPIC_WRITE);
-            apiKey = props.getProperty(PROP_APPC_OAM_CLIENT_KEY);
-            apiSecret = props.getProperty(PROP_APPC_OAM_CLIENT_SECRET);
-            String hostnames = props.getProperty(PROP_APPC_OAM_POOLMEMBERS);
-            if (hostnames != null && !hostnames.isEmpty()) {
-                for (String name : hostnames.split(",")) {
-                    pool.add(name);
-                }
-            }
-        }
-    }
 
     /**
      * Get producer. If it is null, call createProducer to create it again.
      *
      * @return Producer
      */
-    Producer getProducer() {
-        if (producer == null) {
-            // In case, producer was not properly set yet, set it again.
-            logger.info("Calling createProducer as producer is null.");
-            createProducer();
+    MessagingConnector getMessagingConnector() {
+        if (messagingConnector == null) {
+            messagingConnector = new MessagingConnector();
         }
 
-        return producer;
+        return messagingConnector;
     }
 
     /**
@@ -161,8 +94,8 @@ public class MessageAdapter {
                 logger.debug("UEB Response = " + jsonMessage);
             }
 
-            Producer myProducer = getProducer();
-            success = myProducer != null && myProducer.post(this.partition, jsonMessage);
+            MessagingConnector connector = getMessagingConnector();
+            success = connector != null && connector.publishMessage(PROPERTIES_PREFIX, this.partition, jsonMessage);
         } catch (JsonProcessingException e1) {
             logger.error("Error generating Json from UEB message " + e1.getMessage());
             success = false;
index bb73dfe..122ca9f 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * ================================================================================
@@ -29,8 +29,6 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.onap.appc.adapter.message.MessageAdapterFactory;
-import org.onap.appc.adapter.message.Producer;
 import org.onap.appc.configuration.Configuration;
 import org.mockito.Mockito;
 import org.opendaylight.yang.gen.v1.org.onap.appc.oam.rev170303.common.header.CommonHeader;
@@ -61,85 +59,15 @@ import static org.powermock.api.mockito.PowerMockito.mockStatic;
 @PrepareForTest({FrameworkUtil.class, ConfigurationFactory.class, Converter.class})
 public class MessageAdapterTest {
 
-    private Producer fakeProducer;
 
     private MessageAdapter messageAdapter;
 
 
     @Before
     public final void setup() throws Exception {
-        fakeProducer = mock(Producer.class);
         messageAdapter = new MessageAdapter();
     }
 
-    @Test
-    public void testGetProducerReturnsNull() throws Exception {
-        MessageAdapter maSpy = Mockito.spy(messageAdapter);
-        Mockito.doNothing().when(maSpy).createProducer();
-
-        Producer producer = maSpy.getProducer();
-        Assert.assertTrue("getProducer() did not return null", producer == null);
-        Producer mySpyProducer = Whitebox.getInternalState(maSpy, "producer");
-        Assert.assertTrue("MessageAdapter producer is not null", mySpyProducer == null);
-        Mockito.verify(maSpy, Mockito.times(1)).createProducer();
-    }
-
-    @Test
-    public void testGetProducerWithExistingProducer() throws Exception {
-        MessageAdapter maSpy = Mockito.spy(messageAdapter);
-        Whitebox.setInternalState(maSpy, "producer", fakeProducer);
-
-        Producer producer = maSpy.getProducer();
-        Assert.assertTrue("getProducer() returned null", producer == fakeProducer);
-        Mockito.verify(maSpy, Mockito.times(0)).createProducer();
-    }
-
-    @Test
-    public void testGetProducerWithCreateProducer() throws Exception {
-        MessageAdapter maSpy = Mockito.spy(messageAdapter);
-        Whitebox.setInternalState(maSpy, "producer", (Object) null);
-        HashSet<String> pool = new HashSet<>();
-        pool.add("NOT_HTTPS");
-        pool.add("https");
-        Whitebox.setInternalState(maSpy, "pool", pool);
-
-        // Prepare all mocks
-        mockStatic(FrameworkUtil.class);
-        Bundle maBundle = mock(Bundle.class);
-        PowerMockito.when(FrameworkUtil.getBundle(MessageAdapter.class)).thenReturn(maBundle);
-
-        BundleContext maBundleContext = mock(BundleContext.class);
-        Mockito.when(maBundle.getBundleContext()).thenReturn(maBundleContext);
-
-        ServiceReference svcRef = mock(ServiceReference.class);
-        Mockito.when(maBundleContext.getServiceReference(MessageAdapterFactory.class.getName())).thenReturn(svcRef);
-
-        MessageAdapterFactory maFactory = mock(MessageAdapterFactory.class);
-        Mockito.when(maBundleContext.getService(svcRef)).thenReturn(maFactory);
-        Mockito.when(maFactory.createProducer(pool, (String) null, null, null)).thenReturn(fakeProducer);
-
-        Producer producer = maSpy.getProducer();
-        Assert.assertTrue("getProducer() result does not match", producer == fakeProducer);
-        Producer mySpyProducer = Whitebox.getInternalState(maSpy, "producer");
-        Assert.assertTrue("MessageAdapter producer does not match",mySpyProducer == fakeProducer);
-        Mockito.verify(maSpy, Mockito.times(1)).createProducer();
-    }
-
-    @Test
-    public void testUpdateProperties() {
-        MessageAdapter maSpy = Mockito.spy(messageAdapter);
-        Mockito.doNothing().when(maSpy).createProducer();
-        Whitebox.setInternalState(maSpy, "isDisabled", false);
-        PowerMockito.mockStatic(ConfigurationFactory.class);
-        Configuration mockConfig = Mockito.mock(Configuration.class);
-        Properties properties = new Properties();
-        properties.setProperty("appc.OAM.poolMembers", "hostname1,hostname2");
-        Mockito.when(ConfigurationFactory.getConfiguration()).thenReturn(mockConfig);
-        Mockito.doReturn(properties).when(mockConfig).getProperties();
-        maSpy.init();
-        assertEquals(2, ((Set<String>)Whitebox.getInternalState(maSpy, "pool")).size());
-    }
-
     @Test
     public void testPost() throws JsonProcessingException {
         MessageAdapter maSpy = Mockito.spy(messageAdapter);
@@ -158,7 +86,6 @@ public class MessageAdapterTest {
         Mockito.when(Converter.convAsyncResponseToUebOutgoingMessageJsonString(oamContext)).thenReturn("{cambriaPartition='MSO', rpcName='maintenance_mode',"
                 + " body=Body{output=MaintenanceModeOutput [_commonHeader=CommonHeader, hashCode: 14584991,"
                 + " _status=Status, hashCode: 24801521, augmentation=[]]}}");
-        Mockito.doNothing().when(maSpy).createProducer();
         maSpy.post(oamContext);
         Mockito.verify(mockLogger).trace(Mockito.contains("Entering to post"));
         Mockito.verify(mockLogger).trace("Exiting from post with (success = false)");
@@ -180,7 +107,6 @@ public class MessageAdapterTest {
         Whitebox.setInternalState(maSpy, "logger", mockLogger);
         PowerMockito.mockStatic(Converter.class);
         Mockito.when(Converter.convAsyncResponseToUebOutgoingMessageJsonString(oamContext)).thenThrow(new JsonProcessingException("ERROR") {});
-        Mockito.doNothing().when(maSpy).createProducer();
         maSpy.post(oamContext);
         Mockito.verify(mockLogger).error(Mockito.contains("Error generating Json from UEB message"));
     }
@@ -201,8 +127,7 @@ public class MessageAdapterTest {
         Whitebox.setInternalState(maSpy, "logger", mockLogger);
         PowerMockito.mockStatic(Converter.class);
         Mockito.when(Converter.convAsyncResponseToUebOutgoingMessageJsonString(oamContext)).thenThrow(new RuntimeException("ERROR"));
-        Mockito.doNothing().when(maSpy).createProducer();
         maSpy.post(oamContext);
         Mockito.verify(mockLogger).error(Mockito.contains("Error sending message to UEB ERROR"), Mockito.any(RuntimeException.class));
     }
-}
\ No newline at end of file
+}
index dff3183..f74e840 100644 (file)
@@ -87,13 +87,7 @@ limitations under the License.
 
                <dependency>
                        <groupId>org.onap.appc</groupId>
-                       <artifactId>appc-message-adapter-api</artifactId>
-                       <version>${project.version}</version>
-               </dependency>
-
-               <dependency>
-                       <groupId>org.onap.appc</groupId>
-                       <artifactId>appc-message-adapter-factory</artifactId>
+                       <artifactId>appc-service-communicator-bundle</artifactId>
                        <version>${project.version}</version>
                </dependency>
 
index 26092cc..87fa88e 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
 
 package org.onap.appc.sdc.artifacts.impl;
 
-import org.onap.appc.adapter.message.EventSender;
-import org.onap.appc.adapter.message.MessageDestination;
-import org.onap.appc.adapter.message.event.EventHeader;
-import org.onap.appc.adapter.message.event.EventMessage;
-import org.onap.appc.adapter.message.event.EventStatus;
+import org.onap.appc.srvcomm.messaging.event.EventSender;
+import org.onap.appc.srvcomm.messaging.MessageDestination;
+import org.onap.appc.srvcomm.messaging.event.EventHeader;
+import org.onap.appc.srvcomm.messaging.event.EventMessage;
+import org.onap.appc.srvcomm.messaging.event.EventStatus;
 import org.onap.appc.sdc.listener.Util;
 import org.onap.appc.exceptions.APPCException;
 import com.att.eelf.configuration.EELFLogger;
index 315f4cd..11398ee 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
@@ -24,7 +24,7 @@ package org.onap.appc.sdc.artifacts.impl;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
-import org.onap.appc.adapter.message.EventSender;
+import org.onap.appc.srvcomm.messaging.event.EventSender;
 import org.onap.appc.sdc.artifacts.ArtifactProcessor;
 import org.onap.appc.sdc.artifacts.object.ArtifactType;
 import org.onap.sdc.api.IDistributionClient;
index 30b34ae..8435b29 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
@@ -24,7 +24,7 @@ package org.onap.appc.sdc.artifacts.impl;
 
 import java.net.MalformedURLException;
 import java.net.URI;
-import org.onap.appc.adapter.message.EventSender;
+import org.onap.appc.srvcomm.messaging.event.EventSender;
 import org.onap.appc.exceptions.APPCException;
 import org.onap.appc.sdc.artifacts.object.SDCArtifact;
 import org.onap.appc.sdc.listener.ProviderOperations;
index bf61f24..cc3c60e 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
@@ -22,7 +22,7 @@
 
 package org.onap.appc.sdc.artifacts.impl;
 
-import org.onap.appc.adapter.message.EventSender;
+import org.onap.appc.srvcomm.messaging.event.EventSender;
 import org.onap.appc.exceptions.APPCException;
 import org.onap.appc.licmgr.Constants;
 import com.att.eelf.configuration.EELFLogger;
index dbce362..94159e1 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
@@ -28,7 +28,7 @@ import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
 import org.apache.commons.lang.StringUtils;
-import org.onap.appc.adapter.message.EventSender;
+import org.onap.appc.srvcomm.messaging.event.EventSender;
 import org.onap.appc.exceptions.APPCException;
 import org.onap.appc.sdc.artifacts.helper.DependencyModelGenerator;
 import org.onap.appc.sdc.artifacts.object.Resource;
index 516784c..112878e 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
@@ -26,7 +26,7 @@ package org.onap.appc.sdc.listener;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
-import org.onap.appc.adapter.message.EventSender;
+import org.onap.appc.srvcomm.messaging.event.EventSender;
 import org.onap.appc.sdc.artifacts.ArtifactProcessor;
 import org.onap.appc.sdc.artifacts.impl.ArtifactProcessorFactory;
 import org.onap.sdc.api.IDistributionClient;
index 1f5e4e1..439b6cd 100644 (file)
@@ -29,7 +29,7 @@ import org.junit.runner.RunWith;
 import org.mockito.Mockito;
 import org.mockito.internal.util.reflection.Whitebox;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.appc.adapter.message.EventSender;
+import org.onap.appc.srvcomm.messaging.event.EventSender;
 import org.onap.sdc.api.IDistributionClient;
 import org.onap.sdc.api.notification.IArtifactInfo;
 import org.onap.sdc.api.notification.INotificationData;
index dc00c37..7948d91 100644 (file)
@@ -25,8 +25,8 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
-import org.onap.appc.adapter.message.EventSender;
 import org.onap.appc.sdc.artifacts.object.SDCArtifact;
+import org.onap.appc.srvcomm.messaging.event.EventSender;
 import org.onap.sdc.api.IDistributionClient;
 import org.onap.sdc.api.notification.IArtifactInfo;
 import org.onap.sdc.api.notification.INotificationData;
index c11ca74..0a8fe41 100644 (file)
@@ -28,12 +28,12 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mockito;
-import org.onap.appc.adapter.message.EventSender;
 import org.onap.appc.exceptions.APPCException;
 import org.onap.appc.sdc.artifacts.object.SDCArtifact;
 import org.onap.appc.sdc.listener.ProviderOperations;
 import org.onap.appc.sdc.listener.ProviderResponse;
 import org.onap.appc.sdc.listener.Util;
+import org.onap.appc.srvcomm.messaging.event.EventSender;
 import org.onap.sdc.api.IDistributionClient;
 import org.onap.sdc.api.notification.IArtifactInfo;
 import org.onap.sdc.api.notification.INotificationData;
index 6f70681..7516855 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
@@ -32,10 +32,10 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Matchers;
 import org.mockito.Mockito;
-import org.onap.appc.adapter.message.EventSender;
 import org.onap.appc.exceptions.APPCException;
 import org.onap.appc.sdc.artifacts.helper.ArtifactStorageService;
 import org.onap.appc.sdc.artifacts.object.SDCArtifact;
+import org.onap.appc.srvcomm.messaging.event.EventSender;
 import org.onap.sdc.api.IDistributionClient;
 import org.onap.sdc.api.notification.IArtifactInfo;
 import org.onap.sdc.api.notification.INotificationData;
index 738febe..d97b568 100644 (file)
@@ -24,11 +24,11 @@ import static org.mockito.Mockito.when;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
-import org.onap.appc.adapter.message.EventSender;
 import org.onap.appc.exceptions.APPCException;
 import org.onap.appc.sdc.artifacts.helper.ArtifactStorageService;
 import org.onap.appc.sdc.artifacts.helper.DependencyModelGenerator;
 import org.onap.appc.sdc.artifacts.object.SDCArtifact;
+import org.onap.appc.srvcomm.messaging.event.EventSender;
 import org.onap.sdc.api.IDistributionClient;
 import org.onap.sdc.api.notification.IArtifactInfo;
 import org.onap.sdc.api.notification.INotificationData;
index 2dcdb4d..1567b78 100644 (file)
@@ -29,13 +29,13 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Matchers;
 import org.mockito.Mockito;
-import org.onap.appc.adapter.message.EventSender;
 import org.onap.appc.sdc.artifacts.helper.ArtifactStorageService;
 import org.onap.appc.sdc.artifacts.helper.DependencyModelGenerator;
 import org.onap.appc.sdc.artifacts.impl.ArtifactProcessorFactory;
 import org.onap.appc.sdc.artifacts.impl.ToscaCsarArtifactProcessor;
 import org.onap.appc.sdc.artifacts.object.SDCArtifact;
 import org.onap.appc.sdc.artifacts.object.SDCReference;
+import org.onap.appc.srvcomm.messaging.event.EventSender;
 import org.onap.sdc.api.IDistributionClient;
 import org.onap.sdc.api.consumer.INotificationCallback;
 import org.onap.sdc.api.notification.IArtifactInfo;
diff --git a/pom.xml b/pom.xml
index 3098511..35d8ff6 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -621,8 +621,8 @@ limitations under the License.
             </activation>
             <modules>
                 <module>appc-adapters</module>
+                <module>appc-service-communicator</module>
                 <module>appc-provider</module>
-                <module>appc-event-listener</module>
                 <module>appc-sdc-listener</module>
                 <module>appc-lifecycle-management</module>
                 <module>appc-oam</module>
index 4031a51..21438e6 100644 (file)
@@ -1,3 +1,24 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. 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.appc.services.dmaapService;
 
 import java.util.Properties;
@@ -17,7 +38,7 @@ public class AuthenticationConfig extends WebSecurityConfigurerAdapter {
     private final String PROPERTIES_PREFIX = "appc.srvcomm.messaging";
     private final String DEFAULT_USER = "appc";
     private final String DEFAULT_PASSWORD = "onapappc";
-    
+
     @Override
     protected void configure(HttpSecurity http) throws Exception {
         http.csrf().disable().authorizeRequests().anyRequest().authenticated().and().httpBasic();