aboutsummaryrefslogtreecommitdiffstats
path: root/appc-service-communicator/appc-service-communicator-bundle
diff options
context:
space:
mode:
Diffstat (limited to 'appc-service-communicator/appc-service-communicator-bundle')
-rw-r--r--appc-service-communicator/appc-service-communicator-bundle/.gitignore1
-rw-r--r--appc-service-communicator/appc-service-communicator-bundle/pom.xml166
-rw-r--r--appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/AuthenticationException.java28
-rw-r--r--appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/CommonHttpClient.java106
-rw-r--r--appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/MessageDestination.java28
-rw-r--r--appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/MessagingConnector.java154
-rw-r--r--appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventHeader.java65
-rw-r--r--appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventMessage.java98
-rw-r--r--appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventSender.java97
-rw-r--r--appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventStatus.java57
-rw-r--r--appc-service-communicator/appc-service-communicator-bundle/src/main/resources/org/onap/appc/default.properties27
-rw-r--r--appc-service-communicator/appc-service-communicator-bundle/src/test/resources/org/onap/appc/default.properties38
12 files changed, 865 insertions, 0 deletions
diff --git a/appc-service-communicator/appc-service-communicator-bundle/.gitignore b/appc-service-communicator/appc-service-communicator-bundle/.gitignore
new file mode 100644
index 000000000..eacf31a67
--- /dev/null
+++ b/appc-service-communicator/appc-service-communicator-bundle/.gitignore
@@ -0,0 +1 @@
+/target-ide/
diff --git a/appc-service-communicator/appc-service-communicator-bundle/pom.xml b/appc-service-communicator/appc-service-communicator-bundle/pom.xml
new file mode 100644
index 000000000..b93b25685
--- /dev/null
+++ b/appc-service-communicator/appc-service-communicator-bundle/pom.xml
@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============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=========================================================
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.appc.parent</groupId>
+ <artifactId>binding-parent</artifactId>
+ <version>2.6.2</version>
+ <relativePath />
+ </parent>
+ <groupId>org.onap.appc</groupId>
+ <artifactId>appc-service-communicator-bundle</artifactId>
+ <packaging>bundle</packaging>
+ <name>Service Communicator - bundle</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.appc</groupId>
+ <artifactId>appc-common-bundle</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>${logback.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.att.eelf</groupId>
+ <artifactId>eelf-core</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>sli-common</artifactId>
+ <scope>compile</scope>
+ <!-- Added exclusion to prevent missing dependency issue on dblib -->
+ <exclusions>
+ <exclusion>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>dblib-provider</artifactId>
+ </exclusion>
+ <exclusion>
+ <artifactId>slf4j-simple</artifactId>
+ <groupId>org.slf4j</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>sli-provider</artifactId>
+ <scope>compile</scope>
+ <!-- Added exclusion to prevent missing dependency issue on dblib -->
+ <exclusions>
+ <exclusion>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>dblib-provider</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Version>${project.version}</Bundle-Version>
+ <Export-Package>org.onap.appc.srvcomm.messaging,org.onap.appc.srvcomm.messaging.event</Export-Package>
+ <Import-Package>com.att.eelf.configuration,*;resolution:=optional</Import-Package>
+ <Embed-Dependency>logback-classic,
+ logback-core,dmaapClient;scope=compile|runtime;artifactId=!org.eclipse.osgi|slf4j-api|slf4j-simple|jcl-over-slf4j|</Embed-Dependency>
+ <Embed-Transitive>true</Embed-Transitive>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <version>1.7.0-SNAPSHOT</version>
+</project>
diff --git a/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/AuthenticationException.java b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/AuthenticationException.java
new file mode 100644
index 000000000..c04e9bc2b
--- /dev/null
+++ b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/AuthenticationException.java
@@ -0,0 +1,28 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia. 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.srvcomm.messaging;
+
+class AuthenticationException extends Exception {
+
+ public AuthenticationException(String message) {
+ super(message);
+ }
+}
diff --git a/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/CommonHttpClient.java b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/CommonHttpClient.java
new file mode 100644
index 000000000..6bfc553b3
--- /dev/null
+++ b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/CommonHttpClient.java
@@ -0,0 +1,106 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * 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");
+ * 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.srvcomm.messaging;
+
+import java.net.URI;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.http.auth.AuthenticationException;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.config.RequestConfig.Builder;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+
+abstract class CommonHttpClient {
+
+ private static final int HTTP_PORT = 3904;
+ private static final int HTTPS_PORT = 3905;
+ private static final int TIMEOUT_OFFSET = 5000;
+
+ private String authStr;
+
+ protected void setBasicAuth(String username, String password) {
+ if (username != null && password != null) {
+ String plain = String.format("%s:%s", username, password);
+ authStr = Base64.encodeBase64String(plain.getBytes());
+ } else {
+ authStr = null;
+ }
+ }
+
+ protected HttpGet getReq(URI uri, int timeoutMs) throws AuthenticationException {
+
+ HttpGet out = (uri == null) ? new HttpGet() : new HttpGet(uri);
+ if (authStr != null) {
+ out.setHeader("Authorization", String.format("Basic %s", authStr));
+ }
+
+ out.setConfig(getConfig(timeoutMs));
+ return out;
+ }
+
+ protected HttpPost postReq(String url) throws AuthenticationException {
+
+ HttpPost out = (url == null) ? new HttpPost() : new HttpPost(url);
+ if (authStr != null) {
+ out.setHeader("Authorization", String.format("Basic %s", authStr));
+ }
+ out.setConfig(getConfig(0));
+ return out;
+ }
+
+ private RequestConfig getConfig(int timeoutMs) {
+ Builder builder = RequestConfig.custom();
+ builder.setSocketTimeout(timeoutMs + TIMEOUT_OFFSET);
+ return builder.build();
+ }
+
+ protected CloseableHttpClient getClient() {
+ return HttpClientBuilder.create().build();
+ }
+
+ protected String formatHostString(String host) {
+ return formatHostString(host, host.contains(String.valueOf(HTTPS_PORT)));
+ }
+
+ private String formatHostString(String host, boolean useHttps) {
+ // Trim trailing slash
+ String out = host.endsWith("/") ? host.substring(0, host.length() - 1) : host;
+
+ boolean hasProtocol = out.startsWith("http");
+ boolean hasPort = out.contains(":");
+
+ // Add protocol
+ if (!hasProtocol) {
+ out = String.format("%s%s", (useHttps) ? "https://" : "http://", out);
+ }
+ // Add port
+ if (!hasPort) {
+ out = String.format("%s:%d", out, (useHttps) ? HTTPS_PORT : HTTP_PORT);
+ }
+ return out;
+ }
+}
diff --git a/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/MessageDestination.java b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/MessageDestination.java
new file mode 100644
index 000000000..d71babc5b
--- /dev/null
+++ b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/MessageDestination.java
@@ -0,0 +1,28 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * 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");
+ * 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.srvcomm.messaging;
+
+public enum MessageDestination {
+ DCAE
+}
diff --git a/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/MessagingConnector.java b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/MessagingConnector.java
new file mode 100644
index 000000000..934317f1c
--- /dev/null
+++ b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/MessagingConnector.java
@@ -0,0 +1,154 @@
+/*-
+ * ============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.srvcomm.messaging;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Properties;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.onap.appc.configuration.ConfigurationFactory;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class MessagingConnector {
+
+ private static final EELFLogger LOG = EELFManager.getInstance().getLogger(MessagingConnector.class);
+
+ private final String URL;
+ private final String USER;
+ private final String PASSWORD;
+ private final String PROPERTIES_PREFIX = "appc.srvcomm.messaging";
+
+ public MessagingConnector() {
+ Properties props = ConfigurationFactory.getConfiguration().getProperties();
+ String url = props.getProperty(PROPERTIES_PREFIX + ".url");
+ if(!isNullOrEmpty(url)) {
+ this.URL = url;
+ } else {
+ this.URL = "localhost:8080";
+ }
+ String username = props.getProperty(PROPERTIES_PREFIX + ".username");
+ String password = props.getProperty(PROPERTIES_PREFIX + ".password");
+ //Both username and password properties need to be set. One or the other
+ //can't be set.
+ if(isNullOrEmpty(username, password)) {
+ USER = null;
+ PASSWORD = null;
+ } else {
+ USER = username;
+ PASSWORD = password;
+ }
+ }
+
+ public boolean isNullOrEmpty(String... strings) {
+ for(String s : strings) {
+ if(s == null || s.isEmpty()){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean publishMessage(String propertySet, String partition, String data) {
+ return publishMessage(propertySet, partition, null, data);
+ }
+
+ public boolean publishMessage(String propertySet, String partition, String topic, String data) {
+ HttpPost post = new HttpPost(URL);
+ //check if we need to enable authentication
+ if(USER != null) {
+ String authStr = getBasicAuth(USER, PASSWORD);
+ post.setHeader("Authorization", String.format("Basic %s", authStr));
+ }
+ //encode the message so it can be sent to the dmaap client jar
+ String body = bodyLine(propertySet, partition, topic, data);
+ try {
+ post.setEntity(new StringEntity(body));
+ } catch (UnsupportedEncodingException e) {
+ LOG.error("Error during publishMessage",e);
+ }
+ try {
+ CloseableHttpResponse response = getClient().execute(post);
+ if (response.getStatusLine().getStatusCode() == 200) {
+ return true;
+ } else {
+ LOG.error(response.getStatusLine().getStatusCode() +
+ " Error during publishMessage: " +
+ response.getStatusLine().getReasonPhrase() +
+ " See messaging service jar logs.");
+ return false;
+ }
+ } catch (ClientProtocolException e) {
+ LOG.error("Error during publishMessage",e);
+ } catch (IOException e) {
+ LOG.error("Error during publishMessage",e);
+ }
+ return false;
+
+ }
+
+ /**
+ * Format the body for the application/cambria content type with no partitioning. See
+ *
+ * @param propertySet
+ * The prefix of the properties that the dmaap service should look up in order to
+ * get the correct properties for the message being sent.
+ * @param partition
+ * The dmaap partition that the message should be published to
+ * @param topic
+ * The dmaap topic that the message should be published to. Leave this unset in order
+ * to use the topic that is in the property files.
+ * @param message
+ * The message to publish
+ * @return A string in the application/cambria content type
+ */
+ private String bodyLine(String propertySet, String partition, String topic, String message) {
+ String prop = (propertySet == null) ? "" : propertySet;
+ String prt = (partition == null) ? "" : partition;
+ String msg = (message == null) ? "" : message;
+ String top = (topic == null) ? "" : topic;
+ return String.format("%d.%d.%d.%d.%s%s%s%s", prop.length(),prt.length(), top.length(),
+ msg.length(), prop, prt, top, msg);
+ }
+
+ protected CloseableHttpClient getClient() {
+ return HttpClientBuilder.create().build();
+ }
+
+ protected String getBasicAuth(String username, String password) {
+ if (username != null && password != null) {
+ String plain = String.format("%s:%s", username, password);
+ return Base64.encodeBase64String(plain.getBytes());
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventHeader.java b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventHeader.java
new file mode 100644
index 000000000..0f74589ca
--- /dev/null
+++ b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventHeader.java
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * 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");
+ * 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.srvcomm.messaging.event;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class EventHeader {
+
+ @JsonProperty("eventTime")
+ private final String eventTime;
+
+ @JsonProperty("apiVer")
+ private final String apiVer;
+
+ @JsonProperty("eventId")
+ private final String eventId;
+
+ public EventHeader(String eventTime, String apiVer, String eventId) {
+ this.eventTime = eventTime;
+ this.apiVer = apiVer;
+ this.eventId = eventId;
+ }
+
+ public String getEventTime() {
+ return eventTime;
+ }
+
+ public String getApiVer() {
+ return apiVer;
+ }
+
+ public String getEventId() {
+ return eventId;
+ }
+
+ @Override
+ public String toString() {
+ return "EventHeader{" +
+ "eventTime='" + eventTime + '\'' +
+ ", apiVer='" + apiVer + '\'' +
+ ", eventId='" + eventId + '\'' +
+ '}';
+ }
+}
diff --git a/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventMessage.java b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventMessage.java
new file mode 100644
index 000000000..ca6a2d22c
--- /dev/null
+++ b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventMessage.java
@@ -0,0 +1,98 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * 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");
+ * 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.srvcomm.messaging.event;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
+import java.io.IOException;
+import java.io.Serializable;
+
+/*
+ {
+ "EventHeader": {
+ "eventTime": "2016-03-15T10:59:33.79Z",
+ "apiVer": "1.01",
+ "EventId": "<ECOMP_EVENT_ID>",
+ },
+ "EventStatus": {
+ "code": "NNN",
+ "reason": "A reason"
+ }
+ }
+*/
+
+
+@JsonSerialize(include = Inclusion.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class EventMessage implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ @JsonProperty("eventHeader")
+ private EventHeader eventHeader;
+ @JsonProperty("eventStatus")
+ private EventStatus eventStatus;
+
+ public EventMessage(EventHeader eventHeader, EventStatus eventStatus) {
+ this.eventHeader = eventHeader;
+ this.eventStatus = eventStatus;
+ }
+
+ public EventHeader getEventHeader() {
+ return eventHeader;
+ }
+
+ public void setEventHeader(EventHeader eventHeader) {
+ this.eventHeader = eventHeader;
+ }
+
+ public EventStatus getEventStatus() {
+ return eventStatus;
+ }
+
+ public void setEventStatus(EventStatus eventStatus) {
+ this.eventStatus = eventStatus;
+ }
+
+ public String toJson() {
+ try {
+ return OBJECT_MAPPER.writeValueAsString(this);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "EventMessage{" +
+ "eventHeader=" + eventHeader +
+ ", eventStatus=" + eventStatus +
+ '}';
+ }
+}
diff --git a/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventSender.java b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventSender.java
new file mode 100644
index 000000000..c15670838
--- /dev/null
+++ b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventSender.java
@@ -0,0 +1,97 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2019 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.srvcomm.messaging.event;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.appc.configuration.Configuration;
+import org.onap.appc.configuration.ConfigurationFactory;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.srvcomm.messaging.MessageDestination;
+import org.onap.appc.srvcomm.messaging.MessagingConnector;
+import java.util.Date;
+import java.util.Map;
+
+
+public class EventSender
+{
+ private final EELFLogger LOG = EELFManager.getInstance().getLogger(EventSender.class);
+ public static final String PROPERTY_PREFIX = "dmaap.event";
+
+ private static Configuration configuration = ConfigurationFactory.getConfiguration();
+
+ private MessagingConnector messagingConnector;
+
+ public EventSender(){
+ messagingConnector = new MessagingConnector();
+ }
+
+ public boolean sendEvent(MessageDestination destination, EventMessage msg) {
+ String jsonStr = msg.toJson();
+ String id = msg.getEventHeader().getEventId();
+ LOG.info(String.format("Posting Message [%s - %s]", id, jsonStr));
+ String propertyPrefix = destination.toString() + "." + PROPERTY_PREFIX;
+ return messagingConnector.publishMessage(propertyPrefix, id, jsonStr);
+ }
+
+ public boolean sendEvent(MessageDestination destination, EventMessage msg, String eventTopicName) {
+ String jsonStr = msg.toJson();
+ String id = msg.getEventHeader().getEventId();
+ LOG.info(String.format("Posting Message [%s - %s]", id, jsonStr));
+ String propertyPrefix = destination.toString() + "." + PROPERTY_PREFIX;
+ return messagingConnector.publishMessage(propertyPrefix, id, eventTopicName, jsonStr);
+ }
+
+ public boolean sendEvent(MessageDestination destination, Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+
+ if (params == null) {
+ String message = "Parameters map is empty (null)";
+ LOG.error(message);
+ throw new APPCException(message);
+ }
+ String eventTime = new Date(System.currentTimeMillis()).toString();
+ String apiVer = params.get("apiVer");
+ String eventId = params.get("eventId");
+ String reason = params.get("reason");
+ String entityId = params.get("entityId");
+ if(entityId != null){
+ reason += "(" + entityId + ")";
+ }
+ Integer code = Integer.getInteger(params.get("code"), 500);
+
+ if (eventTime == null || apiVer == null || eventId == null || reason == null) {
+ String message = String.format("Missing input parameters: %s", params);
+ LOG.error(message);
+ throw new APPCException(message);
+ }
+ EventMessage eventMessage = new EventMessage(
+ new EventHeader(eventTime, apiVer, eventId),
+ new EventStatus(code, reason));
+
+ return sendEvent(destination, eventMessage);
+ }
+}
diff --git a/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventStatus.java b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventStatus.java
new file mode 100644
index 000000000..eb99e347c
--- /dev/null
+++ b/appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventStatus.java
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * 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");
+ * 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.srvcomm.messaging.event;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class EventStatus {
+
+ @JsonProperty("code")
+ private final Integer code;
+
+ @JsonProperty("reason")
+ private final String reason;
+
+ public EventStatus(Integer code, String aReason) {
+ this.code = code;
+ reason = aReason;
+ }
+
+
+ public Integer getCode() {
+ return code;
+ }
+
+ public String getReason() {
+ return reason;
+ }
+
+ @Override
+ public String toString() {
+ return "EventStatus{" +
+ "code=" + code +
+ ", reason='" + reason + '\'' +
+ '}';
+ }
+}
diff --git a/appc-service-communicator/appc-service-communicator-bundle/src/main/resources/org/onap/appc/default.properties b/appc-service-communicator/appc-service-communicator-bundle/src/main/resources/org/onap/appc/default.properties
new file mode 100644
index 000000000..218cafe6e
--- /dev/null
+++ b/appc-service-communicator/appc-service-communicator-bundle/src/main/resources/org/onap/appc/default.properties
@@ -0,0 +1,27 @@
+###
+# ============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=========================================================
+###
+
+# ${user.home} usually goes to /root if instantiation uses the appc-docker approach
+
+org.onap.appc.bootstrap.file=appc.properties
+org.onap.appc.bootstrap.path=/opt/onap/appc/data/properties,${user.home},.
diff --git a/appc-service-communicator/appc-service-communicator-bundle/src/test/resources/org/onap/appc/default.properties b/appc-service-communicator/appc-service-communicator-bundle/src/test/resources/org/onap/appc/default.properties
new file mode 100644
index 000000000..8dea0a61d
--- /dev/null
+++ b/appc-service-communicator/appc-service-communicator-bundle/src/test/resources/org/onap/appc/default.properties
@@ -0,0 +1,38 @@
+###
+# ============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=test.properties
+org.onap.appc.bootstrap.path=/opt/onap/appc/data/properties,${user.home},.
+
+# Properties commented out below are provided in appc.properties
+poolMembers=10.0.0.1
+#event.pool.members=<DMAAP_IP>:3904
+
+topic.read=APPC-CL
+topic.read.timeout=5
+topic.write=APPC-CL
+event.topic.write=APPC-CL
+client.name=APPC-CLIENT-DMAAP-ADAPTER-TEST
+client.name.id=0
+
+metric.enabled=false;