From 1843caa854f58b133e2c97e5d75a4705f2942280 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Mon, 21 Oct 2019 19:05:35 -0700 Subject: [PATCH] Feature for micro service communication The appc-service-communicator feature will be responsible for communication between any appc microservices which are developed. The appc dmaap micro service connector is part of this feature. MessagingConnector.java is the main new class here. Some code is copied from appc event listener and dmaap adapter. Will be moved in a later commit. Change-Id: Ic57f5ee6a9ab1538c6ddaa3e7c25ac0c9797fae0 Signed-off-by: Patrick Brady Issue-ID: APPC-1744 --- .../appc-service-communicator-bundle/.gitignore | 1 + .../appc-service-communicator-bundle/pom.xml | 166 +++++++++++++++++++++ .../srvcomm/messaging/AuthenticationException.java | 28 ++++ .../appc/srvcomm/messaging/CommonHttpClient.java | 106 +++++++++++++ .../appc/srvcomm/messaging/MessageDestination.java | 28 ++++ .../appc/srvcomm/messaging/MessagingConnector.java | 154 +++++++++++++++++++ .../appc/srvcomm/messaging/event/EventHeader.java | 65 ++++++++ .../appc/srvcomm/messaging/event/EventMessage.java | 98 ++++++++++++ .../appc/srvcomm/messaging/event/EventSender.java | 97 ++++++++++++ .../appc/srvcomm/messaging/event/EventStatus.java | 57 +++++++ .../resources/org/onap/appc/default.properties | 27 ++++ .../resources/org/onap/appc/default.properties | 38 +++++ .../features-appc-service-communicator/.gitignore | 1 + .../features-appc-service-communicator/pom.xml | 49 ++++++ .../onap-appc-service-communicator/.gitignore | 1 + .../onap-appc-service-communicator/pom.xml | 68 +++++++++ .../appc-service-communicator-features/pom.xml | 43 ++++++ .../appc-service-communicator-installer/.gitignore | 24 +++ .../appc-service-communicator-installer/pom.xml | 164 ++++++++++++++++++++ .../src/assembly/assemble_installer_zip.xml | 61 ++++++++ .../src/assembly/assemble_mvnrepo_zip.xml | 49 ++++++ .../src/main/resources/scripts/install-feature.sh | 49 ++++++ appc-service-communicator/pom.xml | 42 ++++++ 23 files changed, 1416 insertions(+) create mode 100644 appc-service-communicator/appc-service-communicator-bundle/.gitignore create mode 100644 appc-service-communicator/appc-service-communicator-bundle/pom.xml create mode 100644 appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/AuthenticationException.java create mode 100644 appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/CommonHttpClient.java create mode 100644 appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/MessageDestination.java create mode 100644 appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/MessagingConnector.java create mode 100644 appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventHeader.java create mode 100644 appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventMessage.java create mode 100644 appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventSender.java create mode 100644 appc-service-communicator/appc-service-communicator-bundle/src/main/java/org/onap/appc/srvcomm/messaging/event/EventStatus.java create mode 100644 appc-service-communicator/appc-service-communicator-bundle/src/main/resources/org/onap/appc/default.properties create mode 100644 appc-service-communicator/appc-service-communicator-bundle/src/test/resources/org/onap/appc/default.properties create mode 100644 appc-service-communicator/appc-service-communicator-features/features-appc-service-communicator/.gitignore create mode 100644 appc-service-communicator/appc-service-communicator-features/features-appc-service-communicator/pom.xml create mode 100644 appc-service-communicator/appc-service-communicator-features/onap-appc-service-communicator/.gitignore create mode 100644 appc-service-communicator/appc-service-communicator-features/onap-appc-service-communicator/pom.xml create mode 100644 appc-service-communicator/appc-service-communicator-features/pom.xml create mode 100644 appc-service-communicator/appc-service-communicator-installer/.gitignore create mode 100644 appc-service-communicator/appc-service-communicator-installer/pom.xml create mode 100644 appc-service-communicator/appc-service-communicator-installer/src/assembly/assemble_installer_zip.xml create mode 100644 appc-service-communicator/appc-service-communicator-installer/src/assembly/assemble_mvnrepo_zip.xml create mode 100755 appc-service-communicator/appc-service-communicator-installer/src/main/resources/scripts/install-feature.sh create mode 100644 appc-service-communicator/pom.xml 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 @@ + + + + 4.0.0 + + org.onap.appc.parent + binding-parent + 2.6.2 + + + org.onap.appc + appc-service-communicator-bundle + bundle + Service Communicator - bundle + + + + org.apache.httpcomponents + httpclient + + + org.onap.appc + appc-common-bundle + ${project.version} + + + + ch.qos.logback + logback-classic + ${logback.version} + + + com.att.eelf + eelf-core + + + ch.qos.logback + logback-classic + + + + + + junit + junit + test + + + + commons-codec + commons-codec + + + + commons-lang + commons-lang + + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-annotations + + + + org.mockito + mockito-core + + + org.osgi + org.osgi.core + provided + + + org.onap.ccsdk.sli.core + sli-common + compile + + + + org.onap.ccsdk.sli.core + dblib-provider + + + slf4j-simple + org.slf4j + + + + + + org.onap.ccsdk.sli.core + sli-provider + compile + + + + org.onap.ccsdk.sli.core + dblib-provider + + + + + + org.json + json + + + commons-io + commons-io + + + + javax.ws.rs + javax.ws.rs-api + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.version} + org.onap.appc.srvcomm.messaging,org.onap.appc.srvcomm.messaging.event + com.att.eelf.configuration,*;resolution:=optional + logback-classic, + logback-core,dmaapClient;scope=compile|runtime;artifactId=!org.eclipse.osgi|slf4j-api|slf4j-simple|jcl-over-slf4j| + true + + + + + + 1.7.0-SNAPSHOT + 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": "", + }, + "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 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=: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; diff --git a/appc-service-communicator/appc-service-communicator-features/features-appc-service-communicator/.gitignore b/appc-service-communicator/appc-service-communicator-features/features-appc-service-communicator/.gitignore new file mode 100644 index 000000000..eacf31a67 --- /dev/null +++ b/appc-service-communicator/appc-service-communicator-features/features-appc-service-communicator/.gitignore @@ -0,0 +1 @@ +/target-ide/ diff --git a/appc-service-communicator/appc-service-communicator-features/features-appc-service-communicator/pom.xml b/appc-service-communicator/appc-service-communicator-features/features-appc-service-communicator/pom.xml new file mode 100644 index 000000000..cf30df89a --- /dev/null +++ b/appc-service-communicator/appc-service-communicator-features/features-appc-service-communicator/pom.xml @@ -0,0 +1,49 @@ + + + + 4.0.0 + + + org.onap.appc.parent + feature-repo-parent + 2.6.2 + + + + org.onap.appc + features-appc-service-communicator + 1.7.0-SNAPSHOT + feature + + + + + + org.onap.appc + onap-appc-service-communicator + ${project.version} + xml + features + + + + diff --git a/appc-service-communicator/appc-service-communicator-features/onap-appc-service-communicator/.gitignore b/appc-service-communicator/appc-service-communicator-features/onap-appc-service-communicator/.gitignore new file mode 100644 index 000000000..eacf31a67 --- /dev/null +++ b/appc-service-communicator/appc-service-communicator-features/onap-appc-service-communicator/.gitignore @@ -0,0 +1 @@ +/target-ide/ diff --git a/appc-service-communicator/appc-service-communicator-features/onap-appc-service-communicator/pom.xml b/appc-service-communicator/appc-service-communicator-features/onap-appc-service-communicator/pom.xml new file mode 100644 index 000000000..b0b5bd417 --- /dev/null +++ b/appc-service-communicator/appc-service-communicator-features/onap-appc-service-communicator/pom.xml @@ -0,0 +1,68 @@ + + + + 4.0.0 + + + org.onap.appc.parent + single-feature-parent + 2.6.2 + + + + org.onap.appc + onap-appc-service-communicator + 1.7.0-SNAPSHOT + feature + + + + + + org.onap.appc + appc-service-communicator-bundle + ${project.version} + + + + + + + org.apache.karaf.tooling + karaf-maven-plugin + true + + false + + slf4j-api + tomcat-jdbc + tomcat-juli + httpcore + httpclient + org.eclipse.osgi + + + + + + + diff --git a/appc-service-communicator/appc-service-communicator-features/pom.xml b/appc-service-communicator/appc-service-communicator-features/pom.xml new file mode 100644 index 000000000..29ca05c54 --- /dev/null +++ b/appc-service-communicator/appc-service-communicator-features/pom.xml @@ -0,0 +1,43 @@ + + + + 4.0.0 + + + org.onap.appc.parent + odlparent-lite + 2.6.2 + + + + org.onap.appc + appc-service-communicator-feature-aggregator + 1.7.0-SNAPSHOT + pom + + + + + onap-appc-service-communicator + features-appc-service-communicator + + diff --git a/appc-service-communicator/appc-service-communicator-installer/.gitignore b/appc-service-communicator/appc-service-communicator-installer/.gitignore new file mode 100644 index 000000000..8d5c481a8 --- /dev/null +++ b/appc-service-communicator/appc-service-communicator-installer/.gitignore @@ -0,0 +1,24 @@ +# ============LICENSE_START========================================== +# ONAP : APPC +# =================================================================== +# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the License); +# you may not use this software 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. +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# ============LICENSE_END============================================ +/target/ +/target-ide/ +/.settings/ diff --git a/appc-service-communicator/appc-service-communicator-installer/pom.xml b/appc-service-communicator/appc-service-communicator-installer/pom.xml new file mode 100644 index 000000000..5cbd64dd1 --- /dev/null +++ b/appc-service-communicator/appc-service-communicator-installer/pom.xml @@ -0,0 +1,164 @@ + + + + 4.0.0 + + odlparent-lite + org.onap.appc.parent + 2.6.2 + + + org.onap.appc + appc-service-communicator-installer + dMaaP Adapter - Karaf Installer + pom + + + appc-service-communicator + appc-service-communicator + mvn:org.onap.appc/onap-appc-service-communicator/${project.version}/xml/features + false + + + + + org.onap.appc + onap-appc-service-communicator + ${project.version} + features + xml + + + * + * + + + + + + org.onap.appc + appc-service-communicator-bundle + ${project.version} + + + + + + + maven-assembly-plugin + + + maven-repo-zip + + single + + package + + false + false + stage/${application.name}-${project.version} + + src/assembly/assemble_mvnrepo_zip.xml + + + + + installer-zip + + single + + package + + false + true + ${application.name}-${project.version} + + src/assembly/assemble_installer_zip.xml + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + + copy-dependencies + + prepare-package + + false + ${project.build.directory}/assembly/system + false + true + true + true + false + false + org.opendaylight + provided + + + com.fasterxml.jackson.core + jackson-annotations + 2.5.4 + jar + + + + + + + + maven-resources-plugin + + + copy-version + + copy-resources + + + validate + + ${basedir}/target/stage + + + src/main/resources/scripts + + install-feature.sh + + true + + + + + + + + + + + 1.7.0-SNAPSHOT + diff --git a/appc-service-communicator/appc-service-communicator-installer/src/assembly/assemble_installer_zip.xml b/appc-service-communicator/appc-service-communicator-installer/src/assembly/assemble_installer_zip.xml new file mode 100644 index 000000000..d35f40d83 --- /dev/null +++ b/appc-service-communicator/appc-service-communicator-installer/src/assembly/assemble_installer_zip.xml @@ -0,0 +1,61 @@ + + + + + + adapter + + zip + + + + false + + + + target/stage/ + ${application.name} + 755 + + *.sh + + + + target/stage/ + ${application.name} + 644 + + *.sh + + + + + + + diff --git a/appc-service-communicator/appc-service-communicator-installer/src/assembly/assemble_mvnrepo_zip.xml b/appc-service-communicator/appc-service-communicator-installer/src/assembly/assemble_mvnrepo_zip.xml new file mode 100644 index 000000000..46f5607aa --- /dev/null +++ b/appc-service-communicator/appc-service-communicator-installer/src/assembly/assemble_mvnrepo_zip.xml @@ -0,0 +1,49 @@ + + + + + + adapter + + zip + + + + false + + + + target/assembly/ + . + + + + + + diff --git a/appc-service-communicator/appc-service-communicator-installer/src/main/resources/scripts/install-feature.sh b/appc-service-communicator/appc-service-communicator-installer/src/main/resources/scripts/install-feature.sh new file mode 100755 index 000000000..836910190 --- /dev/null +++ b/appc-service-communicator/appc-service-communicator-installer/src/main/resources/scripts/install-feature.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +### +# ============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========================================================= +### + +ODL_HOME=${ODL_HOME:-/opt/opendaylight/current} +ODL_KARAF_CLIENT=${ODL_KARAF_CLIENT:-${ODL_HOME}/bin/client} +ODL_KARAF_CLIENT_OPTS=${ODL_KARAF_CLIENT_OPTS:-""} +INSTALLERDIR=$(dirname $0) + +REPOZIP=${INSTALLERDIR}/${features.boot}-${project.version}.zip + +if [ -f ${REPOZIP} ] +then + unzip -n -d ${ODL_HOME} ${REPOZIP} + +fi + +COUNT=0 +while [ $COUNT -lt 10 ]; do + ${ODL_KARAF_CLIENT} ${ODL_KARAF_CLIENT_OPTS} feature:repo-add ${features.repositories} 2> /tmp/installErr + cat /tmp/installErr + if grep -q 'Failed to get the session' /tmp/installErr; then + sleep 10 + else + let COUNT=10 + fi + let COUNT=COUNT+1 +done diff --git a/appc-service-communicator/pom.xml b/appc-service-communicator/pom.xml new file mode 100644 index 000000000..cedb308dd --- /dev/null +++ b/appc-service-communicator/pom.xml @@ -0,0 +1,42 @@ + + + + 4.0.0 + + org.onap.appc.parent + odlparent-lite + 2.6.2 + + + org.onap.appc + appc-service-communicator + Service Communicator + Provides an interface between the main appc and appc microservices + pom + + + appc-service-communicator-bundle + appc-service-communicator-features + appc-service-communicator-installer + + 1.7.0-SNAPSHOT + -- 2.16.6