From 781b1a6df324419c846c84ea983c18fc8362bfd3 Mon Sep 17 00:00:00 2001
From: Patrick Brady
Date: Wed, 13 Dec 2017 11:19:06 -0800
Subject: Third part of onap rename
This part of the commit changes the folder structure on all other
folders of appc.
Change-Id: I8acfa11cdfcdcd36be0e137245d1dd7324f1abd3
Signed-off-by: Patrick Brady
Issue-ID: APPC-13
---
.../org/onap/appc/listener/AbstractListener.java | 162 ++++++++++
.../appc/listener/AppcEventListenerActivator.java | 201 ++++++++++++
.../java/org/onap/appc/listener/Controller.java | 58 ++++
.../java/org/onap/appc/listener/EventHandler.java | 188 +++++++++++
.../org/onap/appc/listener/LCM/conv/Converter.java | 105 +++++++
.../onap/appc/listener/LCM/impl/ListenerImpl.java | 164 ++++++++++
.../onap/appc/listener/LCM/impl/WorkerImpl.java | 127 ++++++++
.../appc/listener/LCM/model/ActionIdentifiers.java | 84 +++++
.../onap/appc/listener/LCM/model/CommonHeader.java | 115 +++++++
.../listener/LCM/model/DmaapIncomingMessage.java | 53 ++++
.../onap/appc/listener/LCM/model/DmaapMessage.java | 119 +++++++
.../listener/LCM/model/DmaapOutgoingMessage.java | 53 ++++
.../onap/appc/listener/LCM/model/InputBody.java | 89 ++++++
.../onap/appc/listener/LCM/model/OutputBody.java | 101 ++++++
.../appc/listener/LCM/model/ResponseStatus.java | 73 +++++
.../GenericProviderOperationRequestFormatter.java | 84 +++++
.../ProviderOperationRequestFormatter.java | 45 +++
.../listener/LCM/operation/ProviderOperations.java | 263 ++++++++++++++++
.../main/java/org/onap/appc/listener/Listener.java | 75 +++++
.../org/onap/appc/listener/ListenerProperties.java | 285 +++++++++++++++++
.../onap/appc/listener/demo/impl/ListenerImpl.java | 132 ++++++++
.../listener/demo/impl/ProviderOperations.java | 294 ++++++++++++++++++
.../onap/appc/listener/demo/impl/WorkerImpl.java | 85 +++++
.../org/onap/appc/listener/demo/model/Action.java | 58 ++++
.../appc/listener/demo/model/CommonMessage.java | 343 +++++++++++++++++++++
.../appc/listener/demo/model/IncomingMessage.java | 91 ++++++
.../appc/listener/demo/model/OutgoingMessage.java | 195 ++++++++++++
.../org/onap/appc/listener/demo/model/Status.java | 72 +++++
.../onap/appc/listener/impl/ControllerImpl.java | 129 ++++++++
.../onap/appc/listener/impl/EventHandlerImpl.java | 337 ++++++++++++++++++++
.../java/org/onap/appc/listener/util/Mapper.java | 137 ++++++++
.../openecomp/appc/listener/AbstractListener.java | 162 ----------
.../appc/listener/AppcEventListenerActivator.java | 201 ------------
.../org/openecomp/appc/listener/Controller.java | 58 ----
.../org/openecomp/appc/listener/EventHandler.java | 188 -----------
.../appc/listener/LCM/conv/Converter.java | 105 -------
.../appc/listener/LCM/impl/ListenerImpl.java | 164 ----------
.../appc/listener/LCM/impl/WorkerImpl.java | 127 --------
.../appc/listener/LCM/model/ActionIdentifiers.java | 84 -----
.../appc/listener/LCM/model/CommonHeader.java | 115 -------
.../listener/LCM/model/DmaapIncomingMessage.java | 53 ----
.../appc/listener/LCM/model/DmaapMessage.java | 119 -------
.../listener/LCM/model/DmaapOutgoingMessage.java | 53 ----
.../appc/listener/LCM/model/InputBody.java | 89 ------
.../appc/listener/LCM/model/OutputBody.java | 101 ------
.../appc/listener/LCM/model/ResponseStatus.java | 73 -----
.../GenericProviderOperationRequestFormatter.java | 84 -----
.../ProviderOperationRequestFormatter.java | 45 ---
.../listener/LCM/operation/ProviderOperations.java | 263 ----------------
.../java/org/openecomp/appc/listener/Listener.java | 75 -----
.../appc/listener/ListenerProperties.java | 285 -----------------
.../appc/listener/demo/impl/ListenerImpl.java | 132 --------
.../listener/demo/impl/ProviderOperations.java | 294 ------------------
.../appc/listener/demo/impl/WorkerImpl.java | 85 -----
.../openecomp/appc/listener/demo/model/Action.java | 58 ----
.../appc/listener/demo/model/CommonMessage.java | 343 ---------------------
.../appc/listener/demo/model/IncomingMessage.java | 91 ------
.../appc/listener/demo/model/OutgoingMessage.java | 195 ------------
.../openecomp/appc/listener/demo/model/Status.java | 72 -----
.../appc/listener/impl/ControllerImpl.java | 129 --------
.../appc/listener/impl/EventHandlerImpl.java | 337 --------------------
.../org/openecomp/appc/listener/util/Mapper.java | 137 --------
62 files changed, 4317 insertions(+), 4317 deletions(-)
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AbstractListener.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AppcEventListenerActivator.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/Controller.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/EventHandler.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/conv/Converter.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/impl/ListenerImpl.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/impl/WorkerImpl.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/ActionIdentifiers.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/CommonHeader.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/DmaapIncomingMessage.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/DmaapMessage.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/DmaapOutgoingMessage.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/InputBody.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/OutputBody.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/ResponseStatus.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/GenericProviderOperationRequestFormatter.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/ProviderOperationRequestFormatter.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/ProviderOperations.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/Listener.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/ListenerProperties.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/impl/ListenerImpl.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/impl/ProviderOperations.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/impl/WorkerImpl.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/Action.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/CommonMessage.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/IncomingMessage.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/OutgoingMessage.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/Status.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/ControllerImpl.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java
create mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/util/Mapper.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/AbstractListener.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/AppcEventListenerActivator.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/Controller.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/EventHandler.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/conv/Converter.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/impl/ListenerImpl.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/impl/WorkerImpl.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/ActionIdentifiers.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/CommonHeader.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/DmaapIncomingMessage.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/DmaapMessage.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/DmaapOutgoingMessage.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/InputBody.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/OutputBody.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/ResponseStatus.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/operation/GenericProviderOperationRequestFormatter.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/operation/ProviderOperationRequestFormatter.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/operation/ProviderOperations.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/Listener.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/ListenerProperties.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/impl/ListenerImpl.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/impl/ProviderOperations.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/impl/WorkerImpl.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/Action.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/CommonMessage.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/IncomingMessage.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/OutgoingMessage.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/Status.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/impl/ControllerImpl.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/impl/EventHandlerImpl.java
delete mode 100644 appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/util/Mapper.java
(limited to 'appc-event-listener/appc-event-listener-bundle/src/main/java')
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AbstractListener.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AbstractListener.java
new file mode 100644
index 000000000..89c75a357
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AbstractListener.java
@@ -0,0 +1,162 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener;
+
+import java.security.SecureRandom;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.RejectedExecutionHandler;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.commons.lang3.concurrent.BasicThreadFactory;
+import org.onap.appc.listener.impl.EventHandlerImpl;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public abstract class AbstractListener implements Listener {
+
+ private final EELFLogger LOG = EELFManager.getInstance().getLogger(AbstractListener.class);
+
+ protected AtomicBoolean run = new AtomicBoolean(false);
+
+ protected int QUEUED_MIN = 1;
+ protected int QUEUED_MAX = 10;
+
+ protected int THREAD_MIN = 4;
+ protected int THREAD_MAX = THREAD_MIN; // Fixed thread pool
+ protected int THREAD_SCALE_DOWN_SEC = 10; // Number of seconds to wait until we remove idle threads
+
+ protected ThreadPoolExecutor executor;
+
+ protected EventHandler dmaap;
+
+ protected ListenerProperties props;
+
+ private String listenerId;
+
+ public AbstractListener(ListenerProperties props) {
+ updateProperties(props);
+
+ dmaap = new EventHandlerImpl(props);
+ if (dmaap.getClientId().equals("0")) {
+ dmaap.setClientId(String.valueOf(new SecureRandom().nextInt(1000)));
+ }
+
+ BlockingQueue threadQueue = new ArrayBlockingQueue(QUEUED_MAX + QUEUED_MIN + 1);
+ executor = new ThreadPoolExecutor(THREAD_MIN, THREAD_MAX, THREAD_SCALE_DOWN_SEC, TimeUnit.SECONDS, threadQueue,
+ new JobRejectionHandler());
+
+ // Custom Named thread factory
+ BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("DMaaP-Worker-%d").build();
+ executor.setThreadFactory(threadFactory);
+
+ run.set(true);
+ }
+
+ /**
+ * Starts a loop that will only end after stop() or stopNow() are called. The loop will read messages off the DMaaP
+ * topic and perform some action on them while writing messages back to DMaaP at critical points in the execution.
+ * Inherited from Runnable.
+ *
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run() {
+ LOG.error("Listener.run() has not been implemented");
+ }
+
+ @Override
+ public void stop() {
+ run.set(false);
+ LOG.info(String.format("Stopping with %d messages in queue", executor.getQueue().size()));
+ executor.shutdown();
+ try {
+ executor.awaitTermination(10, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ LOG.error("Listener graceful stop() failed", e);
+ }
+
+ // close DMaaP clients
+ if (dmaap != null) {
+ dmaap.closeClients();
+ }
+ LOG.info("Listener Thread Pool Finished");
+ }
+
+ @Override
+ public void stopNow() {
+ run.set(false);
+ LOG.info(String.format("StopNow called. Orphaning %d messages in the queue", executor.getQueue().size()));
+ executor.getQueue().clear();
+ stop();
+ }
+
+ @Override
+ public String getBenchmark() {
+ return String.format("%s - No benchmarking implemented.", getListenerId());
+ }
+
+ @Override
+ public String getListenerId() {
+ return listenerId;
+ }
+
+ // Sets the id of the listener in
+ @Override
+ public void setListenerId(String id) {
+ listenerId = id;
+ }
+
+ private void updateProperties(ListenerProperties properties) {
+ this.props = properties;
+ QUEUED_MIN =
+ Integer.valueOf(props.getProperty(ListenerProperties.KEYS.THREADS_MIN_QUEUE, String.valueOf(QUEUED_MIN)));
+ QUEUED_MAX =
+ Integer.valueOf(props.getProperty(ListenerProperties.KEYS.THREADS_MAX_QUEUE, String.valueOf(QUEUED_MAX)));
+ THREAD_MIN =
+ Integer.valueOf(props.getProperty(ListenerProperties.KEYS.THREADS_MIN_POOL, String.valueOf(THREAD_MIN)));
+ THREAD_MAX =
+ Integer.valueOf(props.getProperty(ListenerProperties.KEYS.THREADS_MAX_POOL, String.valueOf(THREAD_MAX)));
+
+ listenerId = props.getPrefix();
+ }
+
+ /**
+ * This class will be used to handle what happens when we cannot add a job because of a ThreadPool issue. It does
+ * not get invoked if there is any fault with the job. NOTE: So far, this has only been seen when doing a
+ * {@link Listener#stopNow}
+ *
+ */
+ class JobRejectionHandler implements RejectedExecutionHandler {
+ @Override
+ public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
+ LOG.error(String.format("A job was rejected. [%s]", r));
+ }
+
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AppcEventListenerActivator.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AppcEventListenerActivator.java
new file mode 100644
index 000000000..0b1eb5328
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AppcEventListenerActivator.java
@@ -0,0 +1,201 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener;
+
+import org.onap.appc.configuration.Configuration;
+import org.onap.appc.configuration.ConfigurationFactory;
+import org.onap.appc.listener.impl.ControllerImpl;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * This activator is used to initialize and terminate the dmaap listener controller and pool(s)
+ *
+ * The DMaaP listener is responsible for listening to a topic on the Universal Event Bus and reading in messages that
+ * conform to the DCAE message format for APPC. These messages will then be parsed and passed along to the APPC Provider
+ * to take action on. The listener will also send messages out on DMaaP during critical phases. The messages sent out
+ * will have a status of:
+ *
+ * - PENDING - The listener has read the message off of DMaaP and has put it in the queue to be processed
+ * - ACTIVE - The listener has begun actually processing the request and is waiting on the appc provider to
+ * complete the request
+ * - SUCCESS or FAILURE - The listener has gotten a response back from the appc provider. If it is a
+ * FAILURE, a message should also be included
+ *
+ *
+ *
+ * Activation of the bundle will provision 1 controller that in turn will provision 1 (or in the future more) listener
+ * to interact with DMaaP. Each listener will have a queue of messages read off of DMaaP and a thread pool of workers to
+ * process them. This worker is responsible for contacting appc provider to perform the action
+ *
+ *
+ * When the bundle is deactivated, the stopNow() method is called and the thread pool is emptied and all remaining jobs
+ * are orphaned. Alternatively stop() could be called which would allow all remaining jobs in the queue to complete at
+ * the cost of longer run time.
+ *
+ *
+ * @since Aug 30, 2015
+ * @version $Id$
+ */
+public class AppcEventListenerActivator implements BundleActivator {
+
+ /**
+ * The bundle registration
+ */
+ private ServiceRegistration registration = null;
+
+ /**
+ * The configuration object
+ */
+ private Configuration configuration;
+
+ /**
+ * The bundle context
+ */
+ private static BundleContext context;
+
+ /**
+ * The reference to the actual implementation object that implements the services
+ */
+ private Controller adapter;
+
+ /**
+ * The logger to be used
+ */
+ private final EELFLogger LOG = EELFManager.getInstance().getLogger(AppcEventListenerActivator.class);
+
+ /**
+ * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
+ * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
+ *
+ * This method must complete and return to its caller in a timely manner.
+ *
+ *
+ * @param ctx
+ * The execution context of the bundle being started.
+ * @throws java.lang.Exception
+ * If this method throws an exception, this bundle is marked as stopped and the Framework will remove
+ * this bundle's listeners, unregister all services registered by this bundle, and release all services
+ * used by this bundle.
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext ctx) throws Exception {
+ LOG.info("Starting Bundle " + getName());
+
+ context = ctx;
+
+ configuration = ConfigurationFactory.getConfiguration();
+
+ Properties props = configuration.getProperties();
+
+ Set listeners = new HashSet<>();
+
+ // Configure event listener for the demo use case
+ ListenerProperties demoProps = new ListenerProperties("appc.demo", props);
+ demoProps.setListenerClass(org.onap.appc.listener.demo.impl.ListenerImpl.class);
+ listeners.add(demoProps);
+
+ // ===========================================================================
+
+ ListenerProperties clLCMProps = new ListenerProperties("appc.LCM", props);
+ clLCMProps.setListenerClass(org.onap.appc.listener.LCM.impl.ListenerImpl.class);
+ listeners.add(clLCMProps);
+
+ // Configure the OAM properties
+ String oamPropKeyPrefix = "appc.OAM";
+ ListenerProperties oamProps = new ListenerProperties(oamPropKeyPrefix, props);
+ if (isAppcOamPropsListenerEnabled(oamProps)) {
+ oamProps.setListenerClass(org.onap.appc.listener.LCM.impl.ListenerImpl.class);
+ listeners.add(oamProps);
+ } else {
+ LOG.warn(String.format("The listener %s is disabled and will not be run", oamPropKeyPrefix));
+ }
+
+ adapter = new ControllerImpl(listeners);
+ if (ctx != null && registration == null) {
+ LOG.info("Registering service DMaaP Controller");
+ registration = ctx.registerService(Controller.class, adapter, null);
+ }
+ adapter.start();
+
+ LOG.info("DMaaP Listener started successfully");
+ }
+
+ /**
+ * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
+ * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
+ * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
+ * call any Framework objects.
+ *
+ * This method must complete and return to its caller in a timely manner.
+ *
+ *
+ * @param ctx
+ * The execution context of the bundle being stopped.
+ * @throws java.lang.Exception
+ * If this method throws an exception, the bundle is still marked as stopped, and the Framework will
+ * remove the bundle's listeners, unregister all services registered by the bundle, and release all
+ * services used by the bundle. *
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext ctx) throws Exception {
+ boolean stopNow = true;
+ LOG.info("Stopping DMaaP Listener. StopNow=" + stopNow);
+ adapter.stop(stopNow);
+ if (registration != null) {
+ registration.unregister();
+ registration = null;
+ }
+ LOG.info("DMaaP Listener stopped successfully");
+ }
+
+ public String getName() {
+ return "DMaaP Listener";
+ }
+
+ /**
+ * Check if AppcOam props disable listener or not
+ *
+ * @param listenerProperties of ListenerProperties objext
+ * @return false only if AppcOam disabled key is defined and equal to true. Otherwise, return true.
+ */
+ private boolean isAppcOamPropsListenerEnabled(ListenerProperties listenerProperties) {
+ final Properties appcOamProperties = listenerProperties.getProperties();
+
+ return appcOamProperties == null
+ || !Boolean.parseBoolean(appcOamProperties.getProperty(
+ ListenerProperties.KEYS.DISABLED.getPropertySuffix()));
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/Controller.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/Controller.java
new file mode 100644
index 000000000..4fce8972b
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/Controller.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener;
+
+import java.util.Map;
+
+/**
+ * A controller is responsible for creating a listener for each ListenerProperties object that is passed in to it on
+ * instantiation. The controller will create a thread pool that will contain all of the listener threads so no listener
+ * can crash the controller.
+ *
+ */
+public interface Controller {
+
+ /**
+ * Creates a new thread in the thread pool for an implementation of the {@see #Listener} class set in the
+ * ListenerProperties. This thread is run immediately after it is created.
+ */
+ public void start();
+
+ /**
+ * Stops each of the listeners known by this controller. Takes an optional parameter that indicates the the listener
+ * should stop immediately rather than waiting for all threads to complete.
+ *
+ * @param stopNow
+ * Determines what method the listeners should use to shutdown. If true, listeners will use the stopNow()
+ * method. Otherwise they will use the stop() method.
+ */
+ public void stop(boolean stopNow);
+
+ /**
+ * @return A Map of ListenerProperties and the Listener object that is running in the controllers thread pool.
+ */
+ public Map getListeners();
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/EventHandler.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/EventHandler.java
new file mode 100644
index 000000000..9ec81b831
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/EventHandler.java
@@ -0,0 +1,188 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * EventHandler defines a class that wraps DMaaP operations (most notably Get Message and Post Message) to make them
+ * easier to use.
+ *
+ */
+public interface EventHandler {
+
+ /**
+ * Gets a list of messages as Strings on the read topic.
+ *
+ * @return A list of String messages. Never returns null.
+ */
+ public List getIncomingEvents();
+
+ /**
+ * Gets a list of messages as String on the read topic.
+ *
+ * @param limit
+ * The maximum amount of entries to return
+ * @return A list of String messages. Never returns null.
+ */
+ public List getIncomingEvents(int limit);
+
+ /**
+ * Gets a list of messages Mapped to the given Class. If a message cannot be mapped to that class, it is discarded.
+ *
+ * @param cls
+ * The class to map the message to.
+ * @return A list of objects of the provided class. Never returns null.
+ */
+ public List getIncomingEvents(Class cls);
+
+ /**
+ * Gets a list of messages Mapped to the given Class. If a message cannot be mapped to that class, it is discarded.
+ *
+ * @param cls
+ * The class to map the message to.
+ * @param limit
+ * The maximum amount of entries to return
+ * @return A list of objects of the provided class. Never returns null.
+ */
+ public List getIncomingEvents(Class cls, int limit);
+
+ /**
+ * Posts the String message to the write topic(s).
+ *
+ * @param event
+ * The String to post.
+ */
+ public void postStatus(String event);
+
+ /**
+ * Posts the String message to the write topic(s) on the specified partition. Partitions are only used to guarantee
+ * ordering and do not impact if data is retreived.
+ *
+ * @param partition
+ * The partition to post to or null if no partition should be used.
+ * @param event
+ * The String to post.
+ */
+ public void postStatus(String partition, String event);
+
+ /**
+ * @return The client/group id used to read messages
+ */
+ public String getClientId();
+
+ /**
+ * Set the client/group id used to read messages
+ *
+ * @param clientId
+ * The new clientId to use
+ */
+ public void setClientId(String clientId);
+
+ /**
+ * @return The client/group name to use.
+ */
+ public String getClientName();
+
+ /**
+ * Set the client/group name used to read messages.
+ *
+ * @param clientName
+ * The new clientName to use
+ */
+ public void setClientName(String clientName);
+
+ /**
+ * @return The name of the topic to read from
+ */
+ public String getReadTopic();
+
+ /**
+ * Set the name of the topic to read from.
+ *
+ * @param topic
+ * The new topic to read from
+ */
+ public void setReadTopic(String topic);
+
+ /**
+ * @return The name of the topic to write to
+ */
+ public Set getWriteTopics();
+
+ /**
+ * Set the name of the topic to write to
+ *
+ * @param topic
+ * The new topic to write to
+ */
+ public void setWriteTopics(Set topic);
+
+ /**
+ * Adds a DMaaP host to the host pool
+ *
+ * @param host
+ * The host to add to the pool in <host>:<port> format
+ */
+ public void addToPool(String host);
+
+ /**
+ * Remove the host name from the pool if it exists
+ *
+ * @param host
+ * The host to add to the pool in <host>:<port> format
+ */
+ public void removeFromPool(String host);
+
+ /**
+ * Get all of the hosts in the DMaaP pool
+ *
+ * @return A collection of host in <host>:<port> format
+ */
+ public Collection getPool();
+
+ /**
+ * Clear any provided api credentials and make future requests as an unauthenticated user
+ */
+ public void clearCredentials();
+
+ /**
+ * Set the api credentials and make future requests as an authenticated user
+ *
+ * @param access
+ * The access portion of the credentials (either user name or api key)
+ * @param secret
+ * The secret portion of the credentials (either password or api secret)
+ */
+ public void setCredentials(String access, String secret);
+
+ /**
+ * Close consumer/producer DMaaP clients
+ */
+ public void closeClients();
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/conv/Converter.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/conv/Converter.java
new file mode 100644
index 000000000..4cef18c87
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/conv/Converter.java
@@ -0,0 +1,105 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.LCM.conv;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.*;
+import org.apache.commons.lang3.StringUtils;
+import org.json.JSONObject;
+import org.onap.appc.listener.LCM.model.DmaapMessage;
+import org.onap.appc.listener.LCM.model.DmaapOutgoingMessage;
+import org.onap.appc.listener.util.Mapper;
+
+public class Converter {
+
+ public static DmaapOutgoingMessage convJsonNodeToDmaapOutgoingMessage(DmaapMessage event, JsonNode inObj) {
+ DmaapOutgoingMessage outObj = new DmaapOutgoingMessage();
+ outObj.setBody(inObj);
+ outObj.setRpcName(event.getRpcName());
+ outObj.setVersion(event.getVersion());
+ outObj.setType("response");
+ outObj.setCorrelationID(event.getCorrelationID());
+ return outObj;
+ }
+
+ public static String convDmaapOutgoingMessageToJsonString(DmaapMessage inObj) throws JsonProcessingException {
+// return Mapper.toJsonString(inObj);
+ ObjectMapper objectMapper = new ObjectMapper();
+ ObjectWriter writer = objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL).configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY,true)
+ .writer().withFeatures(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
+ return writer.writeValueAsString(inObj);
+
+ }
+
+ public static DmaapOutgoingMessage buildDmaapOutgoingMessageWithUnexpectedError(DmaapMessage event,Exception inputException) {
+ DmaapOutgoingMessage dmaapOutgoingMessage = null;
+ String errMsg = StringUtils.isEmpty(inputException.getMessage())? inputException.toString() : inputException.getMessage();
+ JSONObject commonHeaderJsonObject = Mapper.toJsonObject(event.getBody().get("input").get("common-header"));
+ JSONObject jsonObjectOutput = new JSONObject().accumulate("common-header", commonHeaderJsonObject).accumulate("status", new JSONObject().accumulate("code",200).accumulate("value",errMsg));
+ dmaapOutgoingMessage = new DmaapOutgoingMessage();
+ dmaapOutgoingMessage.setRpcName(event.getRpcName());
+ dmaapOutgoingMessage.setCorrelationID(event.getCorrelationID());
+ dmaapOutgoingMessage.setType("error");
+ dmaapOutgoingMessage.setVersion(event.getVersion());
+ JSONObject jsonObjectBody = new JSONObject().accumulate("output",jsonObjectOutput);
+ JsonNode jsonNodeBody = Mapper.toJsonNodeFromJsonString(jsonObjectBody.toString());
+ dmaapOutgoingMessage.setBody(jsonNodeBody);
+ return dmaapOutgoingMessage;
+ }
+
+ public static String extractRequestIdWithSubId(JsonNode dmaapBody) {
+ //TODO: null pointer exception if dmaapBody is null, check if null or ensure is not null before calling
+ JsonNode commonHeaderJsonNode = dmaapBody.get("input").get("common-header");
+ String requestId = getValue(commonHeaderJsonNode,"request-id","");
+ String subRequestId = getValue(commonHeaderJsonNode,"sub-request-id","");
+ if(!StringUtils.isEmpty(subRequestId)){
+ requestId = requestId +"-"+subRequestId;
+ }
+ return requestId;
+ }
+
+ public static Integer extractStatusCode(JsonNode event) {
+ Integer statusCode;
+ statusCode = event.get("output").get("status").get("code").asInt();
+ return statusCode;
+ }
+
+ private static String getValue(JsonNode jsonNode,String name,String defaultValue){
+ if(jsonNode == null){
+ return defaultValue;
+ }
+ JsonNode childJsonNode = jsonNode.get(name);
+ if(childJsonNode == null){
+ return defaultValue;
+ }
+ String value = childJsonNode.asText();
+ if(value == null){
+ return defaultValue;
+ }
+ return value;
+ }
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/impl/ListenerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/impl/ListenerImpl.java
new file mode 100644
index 000000000..41a6f92ee
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/impl/ListenerImpl.java
@@ -0,0 +1,164 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.LCM.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.appc.listener.AbstractListener;
+import org.onap.appc.listener.ListenerProperties;
+import org.onap.appc.listener.LCM.conv.Converter;
+import org.onap.appc.listener.LCM.model.DmaapIncomingMessage;
+import org.onap.appc.listener.LCM.operation.ProviderOperations;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResourceManager;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+import java.util.concurrent.RejectedExecutionException;
+
+public class ListenerImpl extends AbstractListener {
+
+ private final EELFLogger LOG = EELFManager.getInstance().getLogger(ListenerImpl.class);
+
+ private long startTime = 0;
+
+ private final ProviderOperations providerOperations;
+
+ public ListenerImpl(ListenerProperties props) {
+ super(props);
+
+ String url = props.getProperty("provider.url");
+ LOG.info("DMaaP Provider Endpoint: " + url);
+ providerOperations = new ProviderOperations();
+ providerOperations.setUrl(url);
+
+ // Set Basic Auth
+ String user = props.getProperty("provider.user");
+ String pass = props.getProperty("provider.pass");
+ providerOperations.setAuthentication(user, pass);
+ }
+
+ @Override
+ public void run() {
+ // Some vars for benchmarking
+ startTime = System.currentTimeMillis();
+
+ LOG.info("Running DMaaP Listener");
+
+ while (run.get()) {
+ // Only update if the queue is low. otherwise we read in more
+ // messages than we need
+ try {
+ if (executor.getQueue().size() <= QUEUED_MIN) {
+ LOG.debug("DMaaP queue running low. Querying for more jobs");
+
+
+ List messages = dmaap.getIncomingEvents(DmaapIncomingMessage.class, QUEUED_MAX);
+ LOG.debug(String.format("Read %d messages from dmaap", messages.size()));
+ for (DmaapIncomingMessage incoming : messages) {
+ // Acknowledge that we read the event
+ if (isValid(incoming)) {
+ String requestIdWithSubId = getRequestIdWithSubId(incoming.getBody());
+ LOG.info("Acknowledging Message: " + requestIdWithSubId);
+ }
+ }
+ for (DmaapIncomingMessage incoming : messages) {
+ String requestIdWithSubId = getRequestIdWithSubId(incoming.getBody());
+ // Add to pool if still running
+ if (run.get()) {
+ if (isValid(incoming)) {
+ LOG.info(String.format("Adding DMaaP message to pool queue [%s]", requestIdWithSubId));
+ try {
+ executor.execute(new WorkerImpl(incoming, dmaap, providerOperations));
+ } catch (RejectedExecutionException rejectEx) {
+ LOG.error("Task Rejected: ", rejectEx);
+ }
+ } else {
+ // Badly formed message
+ LOG.error("Message was not valid. Rejecting message: "+incoming);
+ }
+ } else {
+ if (isValid(incoming)) {
+ LOG.info("Run stopped. Orphaning Message: " + requestIdWithSubId);
+ }
+ else {
+ // Badly formed message
+ LOG.error("Message was not valid. Rejecting message: "+incoming);
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ LOG.error("Exception " + e.getClass().getSimpleName() + " caught in DMaaP listener");
+ LOG.error(EELFResourceManager.format(e));
+ LOG.error("DMaaP Listener logging and ignoring the exception, continue...");
+ }
+ }
+
+ LOG.info("Stopping DMaaP Listener thread");
+
+ // We've told the listener to stop
+ // TODO - Should we:
+ // 1) Put a message back on the queue indicating that APP-C never got to
+ // the message
+ // or
+ // 2) Let downstream figure it out after timeout between PENDING and
+ // ACTIVE messages
+ }
+
+ private boolean isValid(DmaapIncomingMessage incoming) {
+ return ((incoming != null) &&
+ incoming.getBody() != null
+ && !StringUtils.isEmpty(incoming.getRpcName()));
+ }
+
+ @Override
+ public String getBenchmark() {
+ long time = System.currentTimeMillis();
+ DateFormat df = new SimpleDateFormat("HH:mm:ss");
+ df.setTimeZone(TimeZone.getTimeZone("UTC"));
+ String runningTime = df.format(new Date(time - startTime));
+
+ String out = String.format("Running for %s and completed %d jobs using %d threads.", runningTime,
+ executor.getCompletedTaskCount(), executor.getPoolSize());
+ LOG.info("***BENCHMARK*** " + out);
+ return out;
+ }
+
+ private String getRequestIdWithSubId(JsonNode event){
+ String requestId = "";
+ try {
+ requestId = Converter.extractRequestIdWithSubId(event);
+ } catch (Exception e) {
+ LOG.error("failed to parse request-id and sub-request-id. Json not in expected format", e);
+ }
+ return requestId;
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/impl/WorkerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/impl/WorkerImpl.java
new file mode 100644
index 000000000..9334a8fad
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/impl/WorkerImpl.java
@@ -0,0 +1,127 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.LCM.impl;
+
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.listener.EventHandler;
+import org.onap.appc.listener.LCM.conv.Converter;
+import org.onap.appc.listener.LCM.model.DmaapMessage;
+import org.onap.appc.listener.LCM.model.DmaapOutgoingMessage;
+import org.onap.appc.listener.LCM.operation.ProviderOperations;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+
+public class WorkerImpl implements Runnable {
+
+ private final EELFLogger LOG = EELFManager.getInstance().getLogger(WorkerImpl.class);
+
+ // Should have all of the data we need for processing
+ private DmaapMessage event;
+
+ // So we can post messages from inside the worker.
+ private EventHandler dmaap;
+
+ //so we know were to post the messages
+ private final ProviderOperations providerOperations;
+
+
+ public WorkerImpl(DmaapMessage message, EventHandler dmaap, ProviderOperations providerOperations) {
+ this.event = message;
+ this.dmaap = dmaap;
+ this.providerOperations = providerOperations;
+ }
+
+ @Override
+ public void run() {
+ String requestIdWithSubId = extractRequestIdWithSubId(event.getBody());
+ LOG.debug(String.format("Started working on %s", requestIdWithSubId));
+
+ // Run the dg in a try catch to handle all exceptions and update the
+ // message at the end
+ try {
+ JsonNode outputJsonNode = doDG(event.getRpcName(), event.getBody());
+ DmaapOutgoingMessage dmaapOutgoingMessage= Converter.convJsonNodeToDmaapOutgoingMessage(event, outputJsonNode);
+ postMessageToDMaaP(dmaapOutgoingMessage,requestIdWithSubId);
+ Integer statusCode = extractStatusCode(dmaapOutgoingMessage.getBody());
+ if (ProviderOperations.isSucceeded(statusCode)) {
+ LOG.debug(String.format("Event %s finished successfully", requestIdWithSubId));
+ } else {
+ LOG.warn(String.format("Event %s failed", requestIdWithSubId));
+ }
+
+ } catch (Exception e) {
+ // Unknown exception from DG method. Fail and pass the exception
+ // along
+ String msg = "Exception: " + e.getMessage();
+ LOG.error(String.format("Event %s finished with failure. %s", requestIdWithSubId, msg));
+ DmaapOutgoingMessage dmaapOutgoingMessage= Converter.buildDmaapOutgoingMessageWithUnexpectedError(event, e);
+ postMessageToDMaaP(dmaapOutgoingMessage,requestIdWithSubId);
+ }
+
+ LOG.debug("Done working on " + requestIdWithSubId);
+ }
+
+
+ private Integer extractStatusCode(JsonNode event) {
+ Integer statusCode = null;
+ try {
+ statusCode = Converter.extractStatusCode(event);
+ } catch (Exception e) {
+ LOG.error("failed to parse statusCode. Json not in expected format", e);
+ }
+ return statusCode;
+ }
+
+
+ private String extractRequestIdWithSubId(JsonNode event){
+ String requestId = "";
+ try {
+ requestId = Converter.extractRequestIdWithSubId(event);
+ } catch (Exception e) {
+ LOG.error("failed to parse request-id and sub-request-id. Json not in expected format", e);
+ }
+ return requestId;
+ }
+
+
+
+ private void postMessageToDMaaP(DmaapOutgoingMessage dmaapOutgoingMessage,String requestIdWithSubId) {
+ String dmaapOutgoingMessageJsonString;
+ try {
+ dmaapOutgoingMessageJsonString = Converter.convDmaapOutgoingMessageToJsonString(dmaapOutgoingMessage);
+ dmaap.postStatus(dmaapOutgoingMessage.getCambriaPartition(),dmaapOutgoingMessageJsonString);
+ } catch (JsonProcessingException e) {
+ LOG.error("failed to postMessageToDMaaP requestIdWithSubId: "+requestIdWithSubId+" dmaapOutgoingMessage: "+dmaapOutgoingMessage, e);
+ }
+ }
+
+ private JsonNode doDG(String rpcName, JsonNode msg) throws APPCException {
+ return providerOperations.topologyDG(rpcName,msg);
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/ActionIdentifiers.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/ActionIdentifiers.java
new file mode 100644
index 000000000..2419bed65
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/ActionIdentifiers.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.LCM.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.io.Serializable;
+
+
+public class ActionIdentifiers implements Serializable {
+
+ @JsonProperty("service-instance-id")
+ private String serviceInstanceId;
+ @JsonProperty("vnf-id")
+ private String vnfID;
+ @JsonProperty("vnfc-name")
+ private String vnfcName;
+ @JsonProperty("vserver-id")
+ private String vserverId;
+
+ public ActionIdentifiers() {
+ }
+
+ public ActionIdentifiers(ActionIdentifiers actionIdentifiers) {
+ this.serviceInstanceId=actionIdentifiers.getServiceInstanceId();
+ this.vnfID=actionIdentifiers.getVnfID();
+ this.vnfcName=actionIdentifiers.getVnfcName();
+ this.vserverId=actionIdentifiers.getVserverId();
+ }
+
+ public String getServiceInstanceId() {
+ return serviceInstanceId;
+ }
+
+ public void setServiceInstanceId(String serviceInstanceId) {
+ this.serviceInstanceId = serviceInstanceId;
+ }
+
+ public String getVnfID() {
+ return vnfID;
+ }
+
+ public void setVnfID(String vnfID) {
+ this.vnfID = vnfID;
+ }
+
+ public String getVnfcName() {
+ return vnfcName;
+ }
+
+ public void setVnfcName(String vnfcName) {
+ this.vnfcName = vnfcName;
+ }
+
+ public String getVserverId() {
+ return vserverId;
+ }
+
+ public void setVserverId(String vserverId) {
+ this.vserverId = vserverId;
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/CommonHeader.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/CommonHeader.java
new file mode 100644
index 000000000..b7dcc1bb7
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/CommonHeader.java
@@ -0,0 +1,115 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.LCM.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.io.Serializable;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Map;
+
+import org.onap.appc.util.Time;
+
+public class CommonHeader implements Serializable {
+ @JsonProperty("timestamp")
+ private String timeStamp;
+ @JsonProperty("api-ver")
+ private String apiVer;
+ @JsonProperty("originator-id")
+ private String originatorId;
+ @JsonProperty("request-id")
+ private String requestID;
+ @JsonProperty("sub-request-id")
+ private String subRequestId;
+ @JsonProperty("flags")
+ private Map flags;
+
+ private static final DateFormat ZULU_FORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'");
+
+ public CommonHeader() {
+ }
+
+ public CommonHeader(CommonHeader commonHeader) {
+ // changed to current system time
+ timeStamp = ZULU_FORMATTER.format(Time.utcDate());
+
+ apiVer = commonHeader.getApiVer();
+ originatorId = commonHeader.getOriginatorId();
+ requestID = commonHeader.getRequestID();
+ subRequestId = commonHeader.getSubRequestId();
+ flags = commonHeader.getFlags();
+ }
+
+
+
+ public String getTimeStamp() {
+ return timeStamp;
+ }
+
+ public void setTimeStamp(String timeStamp) {
+ this.timeStamp = timeStamp;
+ }
+
+ public String getApiVer() {
+ return apiVer;
+ }
+
+ public void setApiVer(String apiVer) {
+ this.apiVer = apiVer;
+ }
+
+ public String getRequestID() {
+ return requestID;
+ }
+
+ public void setRequestID(String requestID) {
+ this.requestID = requestID;
+ }
+
+ public String getOriginatorId() {
+ return originatorId;
+ }
+
+ public void setOriginatorId(String originatorId) {
+ this.originatorId = originatorId;
+ }
+
+ public String getSubRequestId() {
+ return subRequestId;
+ }
+
+ public void setSubRequestId(String subRequestId) {
+ this.subRequestId = subRequestId;
+ }
+
+ public Map getFlags() {
+ return flags;
+ }
+
+ public void setFlags(Map flags) {
+ this.flags = flags;
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/DmaapIncomingMessage.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/DmaapIncomingMessage.java
new file mode 100644
index 000000000..32b70d100
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/DmaapIncomingMessage.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.LCM.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import org.json.JSONObject;
+import org.onap.appc.listener.util.Mapper;
+
+/**
+ * This class represents a message being sent out to DMaaP by APPC to update listeners on the status of a request
+ *
+ */
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class DmaapIncomingMessage extends DmaapMessage{
+ private final static String defaultCambriaPartition = "APP-C";
+
+ public DmaapIncomingMessage() {
+ super();
+ setCambriaPartition(defaultCambriaPartition);
+ }
+
+
+ @Override
+ public String toString() {
+ return "DmaapIncomingMessage{"+super.toString()+"}";
+ }
+}
+
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/DmaapMessage.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/DmaapMessage.java
new file mode 100644
index 000000000..214783d10
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/DmaapMessage.java
@@ -0,0 +1,119 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.LCM.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.JsonNode;
+
+
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class DmaapMessage{
+
+ @JsonProperty("version")
+ private String version;
+
+ @JsonProperty("type")
+ private String type;
+
+ @JsonProperty("correlation-id")
+ private String correlationID;
+
+ @JsonProperty("cambria.partition")
+ private String cambriaPartition;
+
+ @JsonProperty("rpc-name")
+ private String rpcName;
+
+ @JsonProperty("body")
+ private JsonNode body;
+
+ public DmaapMessage() {
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getCorrelationID() {
+ return correlationID;
+ }
+
+ public void setCorrelationID(String correlationID) {
+ this.correlationID = correlationID;
+ }
+
+ public String getCambriaPartition() {
+ return cambriaPartition;
+ }
+
+ public void setCambriaPartition(String cambriaPartition) {
+ this.cambriaPartition = cambriaPartition;
+ }
+
+ public String getRpcName() {
+ return rpcName;
+ }
+
+ public void setRpcName(String rpcName) {
+ this.rpcName = rpcName;
+ }
+
+ public JsonNode getBody() {
+ return body;
+ }
+
+ public void setBody(JsonNode body) {
+ this.body = body;
+ }
+
+ @Override
+ public String toString() {
+ return "DmaapMessage{" +
+ "version='" + version + '\'' +
+ ", type='" + type + '\'' +
+ ", correlationId='" + correlationID + '\'' +
+ ", cambriaPartition='" + cambriaPartition + '\'' +
+ ", rpcName='" + rpcName + '\'' +
+ ", body=" + body +
+ '}';
+ }
+
+}
+
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/DmaapOutgoingMessage.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/DmaapOutgoingMessage.java
new file mode 100644
index 000000000..acf4461aa
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/DmaapOutgoingMessage.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.LCM.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import org.json.JSONObject;
+import org.onap.appc.listener.util.Mapper;
+
+/**
+ * This class represents a message being sent out to DMaaP by APPC to update listeners on the status of a request
+ *
+ */
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class DmaapOutgoingMessage extends DmaapMessage{
+ private final static String defaultCambriaPartition = "MSO";
+
+ public DmaapOutgoingMessage() {
+ super();
+ setCambriaPartition(defaultCambriaPartition);
+ }
+
+
+ @Override
+ public String toString() {
+ return "DmaapOutgoingMessage{"+super.toString()+"}";
+ }
+}
+
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/InputBody.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/InputBody.java
new file mode 100644
index 000000000..85aed42d8
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/InputBody.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.LCM.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class InputBody {
+
+ @JsonProperty("common-header")
+ private CommonHeader commonHeader;
+
+ @JsonProperty("action-identifiers")
+ private ActionIdentifiers actionIdentifiers;
+
+ @JsonProperty("action")
+ private String action;
+
+ @JsonProperty("payload")
+ private Object payload;
+
+
+ public Object getPayload() {
+ return payload;
+ }
+
+ public void setPayload(Object payload) {
+ this.payload = payload;
+ }
+ @JsonIgnore
+ public void setPayloadAsString(String payload) {
+ this.payload = payload;
+ }
+
+ public String getAction() {
+ return action;
+ }
+
+ public void setAction(String action) {
+ this.action = action;
+ }
+
+ public ActionIdentifiers getActionIdentifiers() {
+ return actionIdentifiers;
+ }
+
+ public void setActionIdentifiers(ActionIdentifiers actionIdentifiers) {
+ this.actionIdentifiers = actionIdentifiers;
+ }
+
+ public CommonHeader getCommonHeader() {
+ return commonHeader;
+ }
+
+ public void setCommonHeader(CommonHeader commonHeader) {
+ this.commonHeader = commonHeader;
+ }
+
+ @JsonIgnore
+ public boolean isValid() {
+ return getCommonHeader() != null;
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/OutputBody.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/OutputBody.java
new file mode 100644
index 000000000..11714e8fb
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/OutputBody.java
@@ -0,0 +1,101 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.LCM.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import org.json.JSONObject;
+import org.onap.appc.listener.util.Mapper;
+
+/**
+ * This class represents a message being sent out to DMaaP by APPC to update listeners on the status of a request
+ *
+ */
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class OutputBody {
+
+ @JsonProperty("common-header")
+ private CommonHeader header;
+
+ @JsonProperty("status")
+ private ResponseStatus status;
+
+ @JsonProperty("payload")
+ private String payload;
+
+ @JsonProperty("locked")
+ private String locked;
+
+ public OutputBody() {
+ }
+
+
+ public JSONObject toResponse() {
+ return Mapper.toJsonObject(this);
+ }
+
+ public OutputBody(InputBody msg) {
+ this.header = new CommonHeader(msg.getCommonHeader());
+ }
+
+ public String getLocked() {
+ return locked;
+ }
+
+ public void setLocked(String locked) {
+ this.locked = locked;
+ }
+ public String getPayload() {
+ return payload;
+ }
+
+ public void setPayload(String payload) {
+ this.payload = payload;
+ }
+
+ public CommonHeader getHeader() {
+ return header;
+ }
+
+ public void setHeader(CommonHeader header) {
+ this.header = header;
+ }
+
+ public ResponseStatus getStatus() {
+ return status;
+ }
+
+ public void setStatus(ResponseStatus status) {
+ this.status = status;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s - %s(%s)", getHeader().getRequestID(), getStatus().getCode(), getStatus().getValue());
+ }
+}
+
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/ResponseStatus.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/ResponseStatus.java
new file mode 100644
index 000000000..114b97b35
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/model/ResponseStatus.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.LCM.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ResponseStatus {
+ @JsonProperty("code")
+ private Integer code;
+ @JsonProperty("message")
+ private String value;
+
+ public ResponseStatus() {
+ }
+
+ public ResponseStatus(Integer code, String value) {
+ this.code = code;
+ this.value = value;
+ }
+
+ public Integer getCode() {
+ return code;
+ }
+
+ public void setCode(Integer code) {
+ code = code;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+
+
+ public void setValue(String value) {
+ value = value;
+ }
+
+ @Override
+ public String toString() {
+ return "ResponseStatus{" +
+ "code=" + code +
+ ", value='" + value + '\'' +
+ '}';
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/GenericProviderOperationRequestFormatter.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/GenericProviderOperationRequestFormatter.java
new file mode 100644
index 000000000..8fbe4af24
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/GenericProviderOperationRequestFormatter.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.LCM.operation;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.json.JSONObject;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.listener.LCM.model.InputBody;
+import org.onap.appc.listener.LCM.model.ResponseStatus;
+import org.onap.appc.listener.util.Mapper;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import java.net.URL;
+
+public class GenericProviderOperationRequestFormatter implements ProviderOperationRequestFormatter {
+
+ private final EELFLogger LOG = EELFManager.getInstance().getLogger(GenericProviderOperationRequestFormatter.class);
+
+ //@formatter:off
+ @SuppressWarnings("nls")
+ private final static String TEMPLATE = "{\"input\": %s}";
+ //@formatter:on
+
+ @Override
+ public String buildPath(URL url, String rpcName) {
+ return url.getPath() + ":"+rpcName;
+ }
+
+ @Override
+ public String buildRequest(InputBody msg) {
+ JSONObject jsonObject = Mapper.toJsonObject(msg);
+ return String.format(TEMPLATE, jsonObject.toString());
+ }
+
+ @Override
+ public ResponseStatus getResponseStatus(JsonNode responseBody)throws APPCException{
+ try {
+ JsonNode status = responseBody.get("output").get("status");
+ return new ResponseStatus(status.get("code").asInt(), status.get("message").asText());
+ } catch (Exception e) {
+ LOG.error("Unknown error processing failed response from provider. Json not in expected format", e);
+ throw new APPCException("APPC has an unknown RPC error");
+ }
+ }
+
+ @Override
+ public String getLocked(JSONObject responseBody) throws APPCException {
+ try {
+ JSONObject outputObject=responseBody.getJSONObject("output");
+ if(outputObject.has("locked")){
+ return outputObject.getString("locked");
+ }else{
+ return null;
+ }
+ } catch (Exception e) {
+ LOG.error("Unknown error processing failed response from provider. Json not in expected format", e);
+ throw new APPCException("APPC has an unknown RPC error");
+ }
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/ProviderOperationRequestFormatter.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/ProviderOperationRequestFormatter.java
new file mode 100644
index 000000000..1e9909a1f
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/ProviderOperationRequestFormatter.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.LCM.operation;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.json.JSONObject;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.listener.LCM.model.InputBody;
+import org.onap.appc.listener.LCM.model.ResponseStatus;
+
+import java.net.URL;
+
+
+public interface ProviderOperationRequestFormatter {
+
+ String buildPath(URL url, String rpcName);
+
+ String buildRequest(InputBody msg);
+
+ ResponseStatus getResponseStatus(JsonNode json)throws APPCException;
+
+ String getLocked(JSONObject json)throws APPCException;
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/ProviderOperations.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/ProviderOperations.java
new file mode 100644
index 000000000..d3ac83d1b
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/ProviderOperations.java
@@ -0,0 +1,263 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.LCM.operation;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpHeaders;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.protocol.HTTP;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.listener.LCM.model.ResponseStatus;
+import org.onap.appc.listener.util.Mapper;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.Socket;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.security.*;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+public class ProviderOperations {
+
+ private static final EELFLogger LOG = EELFManager.getInstance().getLogger(ProviderOperations.class);
+
+ private URL url;
+ private String basic_auth;
+
+ private static ProviderOperationRequestFormatter requestFormatter = new GenericProviderOperationRequestFormatter();
+
+ /**
+ * Calls the AppcProvider to run a topology directed graph
+ *
+ * @param msg The incoming message to be run
+ * @return True if the result is success. Never returns false and throws an exception instead.
+ * @throws UnsupportedEncodingException
+ * @throws Exception if there was a failure processing the request. The exception message is the failure reason.
+ */
+ @SuppressWarnings("nls")
+ public JsonNode topologyDG(String rpcName, JsonNode msg) throws APPCException {
+ if (msg == null) {
+ throw new APPCException("Provided message was null");
+ }
+
+ HttpPost post = null;
+ try {
+
+ // Concatenate the "action" on the end of the URL
+ String path = requestFormatter.buildPath(url, rpcName);
+ URL serviceUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
+
+ post = new HttpPost(serviceUrl.toExternalForm());
+ post.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
+ post.setHeader(HttpHeaders.ACCEPT, "application/json");
+
+ // Set Auth
+ if (basic_auth != null) {
+ post.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + basic_auth);
+ }
+
+ String body = Mapper.toJsonString(msg);
+ StringEntity entity = new StringEntity(body);
+ entity.setContentType("application/json");
+ post.setEntity(new StringEntity(body));
+ } catch (UnsupportedEncodingException | MalformedURLException e) {
+ throw new APPCException(e);
+ }
+
+ HttpClient client = getHttpClient();
+
+ int httpCode = 0;
+ String respBody = null;
+ try {
+ HttpResponse response = client.execute(post);
+ httpCode = response.getStatusLine().getStatusCode();
+ respBody = IOUtils.toString(response.getEntity().getContent());
+ } catch (IOException e) {
+ throw new APPCException(e);
+ }
+
+ if (httpCode >= 200 && httpCode < 300 && respBody != null) {
+ JsonNode json;
+ try {
+ json = Mapper.toJsonNodeFromJsonString(respBody);
+ } catch (Exception e) {
+ LOG.error("Error processing response from provider. Could not map response to json", e);
+ throw new APPCException("APPC has an unknown RPC error");
+ }
+
+ ResponseStatus responseStatus = requestFormatter.getResponseStatus(json);
+
+ if (!isSucceeded(responseStatus.getCode())) {
+ LOG.warn(String.format("Operation failed [%s]", msg.toString()));
+ }
+
+ return json;
+ }
+
+ throw new APPCException(String.format("Unexpected response from endpoint: [%d] - %s ", httpCode, respBody));
+ }
+
+ /**
+ * Updates the static var URL and returns the value;
+ *
+ * @return The new value of URL
+ */
+ public String getUrl() {
+ return url.toExternalForm();
+ }
+
+ public void setUrl(String newUrl) {
+ try {
+ url = new URL(newUrl);
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Sets the basic authentication header for the given user and password. If either entry is null then set basic auth
+ * to null
+ *
+ * @param user The user with optional domain name
+ * @param password The password for the user
+ * @return The new value of the basic auth string that will be used in the request headers
+ */
+ public String setAuthentication(String user, String password) {
+ if (user != null && password != null) {
+ String authStr = user + ":" + password;
+ basic_auth = new String(Base64.encodeBase64(authStr.getBytes()));
+ } else {
+ basic_auth = null;
+ }
+ return basic_auth;
+ }
+
+ @SuppressWarnings("deprecation")
+ private HttpClient getHttpClient() throws APPCException {
+ HttpClient client;
+ if (url.getProtocol().equals("https")) {
+ try {
+ KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ trustStore.load(null, null);
+ MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
+ sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+
+ HttpParams params = new BasicHttpParams();
+ HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
+ HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
+
+ SchemeRegistry registry = new SchemeRegistry();
+ registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ registry.register(new Scheme("https", sf, 443));
+ registry.register(new Scheme("https", sf, 8443));
+ registry.register(new Scheme("http", sf, 8181));
+
+ ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
+ client = new DefaultHttpClient(ccm, params);
+ } catch (Exception e) {
+ client = new DefaultHttpClient();
+ }
+ } else if (url.getProtocol().equals("http")) {
+ client = new DefaultHttpClient();
+ } else {
+ throw new APPCException(
+ "The provider.topology.url property is invalid. The url did not start with http[s]");
+ }
+ return client;
+ }
+
+ @SuppressWarnings("deprecation")
+ public static class MySSLSocketFactory extends SSLSocketFactory {
+ private SSLContext sslContext = SSLContext.getInstance("TLS");
+
+ public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException,
+ KeyStoreException, UnrecoverableKeyException {
+ super(truststore);
+
+ TrustManager tm = new X509TrustManager() {
+ @Override
+ public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ }
+
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
+ };
+
+ sslContext.init(null, new TrustManager[]{
+ tm
+ }, null);
+ }
+
+ @Override
+ public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
+ throws IOException, UnknownHostException {
+ return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
+ }
+
+ @Override
+ public Socket createSocket() throws IOException {
+ return sslContext.getSocketFactory().createSocket();
+ }
+ }
+
+ public static boolean isSucceeded(Integer code) {
+ if (code == null) {
+ return false;
+ }
+ return ((code == 100) || (code == 400)); // only 100 & 400 statuses are success
+ }
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/Listener.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/Listener.java
new file mode 100644
index 000000000..50589c89d
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/Listener.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener;
+
+/**
+ * This interface defines a listener that subscribes to a DMaaP topic and continually polls for messages. The
+ * listener does all operations in the run() method and long running operations should be created in a separate worker
+ * thread.
+ *
+ */
+public interface Listener extends Runnable {
+
+ /**
+ * Should start a continuous poll to get messages from the message bus only ending when stop() or stopNow() are
+ * called.
+ *
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run();
+
+ /**
+ * Signals the listener to stop accepting new messages to the queue and to cleanly finish processing all remaining
+ * messages in the queue. This can take a significant amount of time to complete depending on the thread pool
+ * characteristics. Similar to {@link #stopNow()}
+ */
+ public void stop();
+
+ /**
+ * Signals the listener to stop accepting new messages to the queue and to destroy all remaining messages in the
+ * queue. This will complete quicker than {@link #stop()} at the cost of discarded requests. Recovery of these
+ * requests would have to be caught downstream. Similar to {@link #stop()}
+ */
+ public void stopNow();
+
+ /**
+ * @return A string that shows various benchmarking data. Can be used by humans to tune the thread pool.
+ */
+ public String getBenchmark();
+
+ /**
+ * @return The listener's id when requesting messages from DMaaP. Also known as the group id.
+ */
+ public String getListenerId();
+
+ /**
+ * Sets the listener's id to use when requesting messages from DMaaP. Also known as the group id.
+ *
+ * @param idString
+ * The new listener id
+ */
+ public void setListenerId(String idString);
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/ListenerProperties.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/ListenerProperties.java
new file mode 100644
index 000000000..7908d3a1b
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/ListenerProperties.java
@@ -0,0 +1,285 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener;
+
+import java.util.Properties;
+
+/**
+ * A class for instantiating Listener objects. It is primarily used to hold properties that start with the given prefix.
+ * It also holds a class that implements {@see Listener} and will be used by the controller to spawn a new listener
+ * object.
+ *
+ * @since Apr 25, 2016
+ * @version $Id$
+ */
+public class ListenerProperties {
+
+ private String prefix;
+
+ private Class extends Listener> listenerClass;
+
+ private Properties props;
+
+ /**
+ * Creates a new listener object with the given prefix and properties. Any property starting with the prefix is
+ * added to the internal properties object with the prefix removed. All other properties are ignored.
+ * ListenerProperties constructor
+ *
+ * @param prefix
+ * The prefix of the properties to load
+ * @param allProps
+ * The properties object to load from.
+ */
+ public ListenerProperties(String prefix, Properties allProps) {
+ this.prefix = prefix;
+ props = new Properties();
+
+ String dottedPrefix = String.format("%s.", prefix);
+ for (String key : allProps.stringPropertyNames()) {
+ if (key.startsWith(dottedPrefix) && key.length() > dottedPrefix.length()) {
+ props.put(key.substring(dottedPrefix.length()), allProps.get(key));
+ }
+ }
+ }
+
+ /**
+ * @return The prefix of these properties
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * Sets the listener class. Will be used by {@see Controller} to instantiate the Listener thread for this object
+ *
+ * @param cls
+ * The class to be created. Implements {@see Listener}
+ */
+ public void setListenerClass(Class extends Listener> cls) {
+ this.listenerClass = cls;
+ }
+
+ /**
+ * @return The class that will be used by {@see Controller} to instantiate the Listener thread for this object
+ */
+ public Class extends Listener> getListenerClass() {
+ return listenerClass;
+ }
+
+ /**
+ * Returns a property matching a given KEYS
+ *
+ * @param key
+ * The KEYS object who's value to return.
+ * @return The value of the property or null if none exists
+ */
+ public String getProperty(KEYS key) {
+ return getProperty(key, null);
+ }
+
+ /**
+ * Returns a property matching a given string.
+ *
+ * @param key
+ * The key who's value to return.
+ * @return The value of the property or null if none exists
+ */
+ public String getProperty(String key) {
+ return getProperty(key, null);
+ }
+
+ /**
+ * Returns a property matching a given KEYS
+ *
+ * @param key
+ * The KEYS object who's value to return.
+ * @param defaultValue
+ * The value to return if the property is not found
+ * @return The value of the property or null if none exists
+ */
+ public String getProperty(KEYS key, String defaultValue) {
+ return getProperty(key.getPropertySuffix(), defaultValue);
+ }
+
+ /**
+ * Returns a property matching a given string.
+ *
+ * @param key
+ * The key who's value to return.
+ * @param defaultValue
+ * The value to return if the property is not found
+ * @return The value of the property or null if none exists
+ */
+ public String getProperty(String key, String defaultValue) {
+ return props.getProperty(key, defaultValue);
+ }
+
+ /**
+ * @return The properties object containing all properties
+ */
+ public Properties getProperties() {
+ return props;
+ }
+
+ /**
+ * Reads the prefix.disabled property to determine if the listener is disabled and should not be run by the
+ * controller. Defaults to false if property not set or value cannot be parsed.
+ *
+ * @return true if the listener is disabled and should not be started. false if the listener should be start
+ * normally (default).
+ */
+ public boolean isDisabled() {
+ return Boolean.valueOf(getProperty(KEYS.DISABLED, "false"));
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s", prefix);
+ }
+
+
+ /**
+ * Set of common properties that will be used by most systems. Primarily relating to DMaaP and ThreadPools
+ *
+ * @since Apr 25, 2016
+ * @version $Id$
+ */
+ public enum KEYS {
+ /**
+ * Property to determine if the listener should be disabled. If not set, defaults to false
+ */
+ DISABLED("disabled"),
+
+ /**
+ * Property for the message service type. Should be a lower case string. See MessageService.
+ */
+ MESSAGE_SERVICE("service"),
+
+ /**
+ * A hostname or comma separated list (no spaces) of hostnames of servers in a cluster. Can have ports included
+ * as well.
+ * Examples:
+ *
+ * - server1.appc.openecomp.org
+ * - server1.appc.openecomp.org:3904
+ * - server1.appc.openecomp.org,server2.appc.openecomp.org
+ *
+ */
+ HOSTS("poolMembers"),
+
+ /**
+ * The topic that will be used for DMaaP read operations. Can only support a single topic.
+ */
+ TOPIC_READ("topic.read"),
+
+ /**
+ * The topic or topics that will be used to write to. If multiple topics are provided, should be in a comma
+ * seperated list with no spaces.
+ * Examples:
+ *
+ * - TOPIC-1
+ * - TOPIC-1,TOPIC-2,ANOTHER-TOPIC
+ *
+ */
+ TOPIC_WRITE("topic.write"),
+
+ /**
+ * The highland park filter to use on read requests. If you are reading and writing to the same topic this must
+ * be provided. Filter should be in JSON format (not url escaped).
+ */
+ TOPIC_READ_FILTER("topic.read.filter"),
+
+ /**
+ * The amount of time in seconds that the DMaaP polling connection should stay open for. Recommended to be set
+ * high (around 60 seconds) as most clients will return immediately and not wait until the timeout is up to
+ * return if they have data.
+ */
+ TOPIC_READ_TIMEOUT("topic.read.timeout"),
+
+ /**
+ * The name of the client to use. Should be unique to the application.
+ */
+ CLIENT_NAME("client.name"),
+
+ /**
+ * The id of the client to use. Should be unique for each instance of the application in an environment.
+ */
+ CLIENT_ID("client.name.id"),
+
+ /**
+ * The User (DMaaP) to use for authentication. If a user is provided, you must include the
+ * domain name (e.g. example@example.com).
+ */
+ AUTH_USER_KEY("client.key"),
+
+ /**
+ * The password (DMaaP) to use for authentication.
+ */
+ AUTH_SECRET_KEY("client.secret"),
+
+ /**
+ * The minimum amount of size of the queue. A client should request new messages once the queue has dropped
+ * below this size.
+ */
+ THREADS_MIN_QUEUE("threads.queuesize.min"),
+
+ /**
+ * The maximum size of the queue. A client will request no new messages once this maximum size has been reached.
+ */
+ THREADS_MAX_QUEUE("threads.queuesize.max"),
+
+ /**
+ * The minimum size of the worker threads pool. This is the pool each listener will use to launch longer running
+ * operations.
+ */
+ THREADS_MIN_POOL("threads.poolsize.min"),
+
+ /**
+ * The maximum size of the worker threads pool. This is the pool each listener will use to launch longer running
+ * operations.
+ */
+ THREADS_MAX_POOL("threads.poolsize.max");
+
+ private String suffix;
+
+ private KEYS(String val) {
+ this.suffix = val;
+ }
+
+ /**
+ * @param prefix
+ * The prefix to prepend
+ * @return a fully property name that corroponds to what is used in the properties file. Format is PREFIX.KEY
+ */
+ public String getFullProp(String prefix) {
+ return String.format("%s.%s", prefix, suffix);
+ }
+
+ public String getPropertySuffix() {
+ return suffix;
+ }
+ }
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/impl/ListenerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/impl/ListenerImpl.java
new file mode 100644
index 000000000..c7599dd1a
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/impl/ListenerImpl.java
@@ -0,0 +1,132 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.demo.impl;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+import java.util.concurrent.RejectedExecutionException;
+
+import org.onap.appc.listener.AbstractListener;
+import org.onap.appc.listener.ListenerProperties;
+import org.onap.appc.listener.demo.model.IncomingMessage;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResourceManager;
+
+public class ListenerImpl extends AbstractListener {
+
+ private final EELFLogger LOG = EELFManager.getInstance().getLogger(ListenerImpl.class);
+
+ private long startTime = 0;
+
+ public ListenerImpl(ListenerProperties props) {
+ super(props);
+ String url = props.getProperty("provider.url");
+ LOG.info("DMaaP Provider Endpoint: " + url);
+ ProviderOperations.setUrl(url);
+
+ // Set Basic Auth
+ String user = props.getProperty("provider.user");
+ String pass = props.getProperty("provider.pass");
+ ProviderOperations.setAuthentication(user, pass);
+ }
+
+ @Override
+ public void run() {
+ // Some vars for benchmarking
+ startTime = System.currentTimeMillis();
+
+ LOG.info("Running DMaaP Listener");
+
+ while (run.get()) {
+ // Only update if the queue is low. otherwise we read in more
+ // messages than we need
+ try {
+ if (executor.getQueue().size() <= QUEUED_MIN) {
+ LOG.debug("DMaaP queue running low. Querying for more jobs");
+ List messages = dmaap.getIncomingEvents(IncomingMessage.class, QUEUED_MAX);
+ LOG.debug(String.format("Read %d messages from dmaap", messages.size()));
+ for (IncomingMessage incoming : messages) {
+ // Acknowledge that we read the event
+ LOG.info("Acknowledging Message: " + incoming.getHeader().getRequestID());
+
+ //TODO: Should we post a pending status for 1607
+ //dmaap.postStatus(incoming.toOutgoing(Status.PENDING, null).toString());
+ }
+ for (IncomingMessage incoming : messages) {
+ // Add to pool if still running
+ if (run.get()) {
+ LOG.info(String.format("Adding DMaaP message to pool queue [%s]", incoming.getHeader().getRequestID()));
+ if (incoming.isValid()) {
+ try {
+ executor.execute(new WorkerImpl(incoming, dmaap));
+ } catch (RejectedExecutionException rejectEx) {
+ LOG.error("Task Rejected: ", rejectEx);
+ }
+ } else {
+ // Badly formed message
+ LOG.error("Message was not valid. Rejecting");
+ }
+ } else {
+ LOG.info("Run stopped. Orphaning Message: " + incoming.getHeader().getRequestID());
+ }
+ }
+ }
+ } catch (Exception e) {
+ LOG.error("Exception " + e.getClass().getSimpleName() + " caught in DMaaP listener");
+ LOG.error(EELFResourceManager.format(e));
+ LOG.error("DMaaP Listener logging and ignoring the exception, continue...");
+ }
+ }
+
+ LOG.info("Stopping DMaaP Listener thread");
+
+ // We've told the listener to stop
+ // TODO - Should we:
+ // 1) Put a message back on the queue indicating that APP-C never got to
+ // the message
+ // or
+ // 2) Let downstream figure it out after timeout between PENDING and
+ // ACTIVE messages
+ }
+
+ @Override
+ public String getBenchmark() {
+ long time = System.currentTimeMillis();
+ DateFormat df = new SimpleDateFormat("HH:mm:ss");
+ df.setTimeZone(TimeZone.getTimeZone("UTC"));
+ String runningTime = df.format(new Date(time - startTime));
+
+ String out = String.format("Running for %s and completed %d jobs using %d threads.", runningTime,
+ executor.getCompletedTaskCount(), executor.getPoolSize());
+ LOG.info("***BENCHMARK*** " + out);
+ return out;
+ }
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/impl/ProviderOperations.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/impl/ProviderOperations.java
new file mode 100644
index 000000000..9337edfbf
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/impl/ProviderOperations.java
@@ -0,0 +1,294 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.demo.impl;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.Socket;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.security.KeyManagementException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.protocol.HTTP;
+import org.json.JSONObject;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.listener.demo.model.IncomingMessage;
+import org.onap.appc.listener.util.Mapper;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class ProviderOperations {
+
+ private static final EELFLogger LOG = EELFManager.getInstance().getLogger(ProviderOperations.class);
+
+ private static URL url;
+
+ private static String basic_auth;
+
+ //@formatter:off
+ @SuppressWarnings("nls")
+ private final static String TEMPLATE = "{\"input\": {\"common-request-header\": {\"service-request-id\": \"%s\"},\"config-payload\": {\"config-url\": \"%s\",\"config-json\":\"%s\"}}}";
+ //@formatter:on
+
+ /**
+ * Calls the AppcProvider to run a topology directed graph
+ *
+ * @param msg
+ * The incoming message to be run
+ * @return True if the result is success. Never returns false and throws an exception instead.
+ * @throws UnsupportedEncodingException
+ * @throws Exception
+ * if there was a failure processing the request. The exception message is the failure reason.
+ */
+ @SuppressWarnings("nls")
+ public static boolean topologyDG(IncomingMessage msg) throws APPCException {
+ if (msg == null) {
+ throw new APPCException("Provided message was null");
+ }
+
+ HttpPost post = null;
+ try {
+ // Concatenate the "action" on the end of the URL
+ String path = url.getPath() + ":" + msg.getAction().getValue();
+ URL serviceUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
+
+ post = new HttpPost(serviceUrl.toExternalForm());
+ post.setHeader("Content-Type", "application/json");
+ post.setHeader("Accept", "application/json");
+
+ // Set Auth
+ if (basic_auth != null) {
+ post.setHeader("Authorization", "Basic " + basic_auth);
+ }
+
+ //String body = buildReqest(msg.getId(), msg.getUrl(), msg.getIdentityUrl());
+ String body = buildReqest(msg.getHeader().getRequestID(), msg.getPayload().getGenericVnfId(), msg.getPayload().getPgStreams());
+ StringEntity entity = new StringEntity(body);
+ entity.setContentType("application/json");
+ post.setEntity(new StringEntity(body));
+ } catch (UnsupportedEncodingException | MalformedURLException e) {
+ throw new APPCException(e);
+ }
+
+ HttpClient client = getHttpClient();
+
+ int httpCode = 0;
+ String respBody = null;
+ try {
+ HttpResponse response = client.execute(post);
+ httpCode = response.getStatusLine().getStatusCode();
+ respBody = IOUtils.toString(response.getEntity().getContent());
+ } catch (IOException e) {
+ throw new APPCException(e);
+ }
+
+ if (httpCode == 200 && respBody != null) {
+ JSONObject json;
+ try {
+ json = Mapper.toJsonObject(respBody);
+ } catch (Exception e) {
+ LOG.error("Error prcoessing response from provider. Could not map response to json", e);
+ throw new APPCException("APPC has an unknown RPC error");
+ }
+ boolean success;
+ String reason;
+ try {
+ JSONObject header = json.getJSONObject("output").getJSONObject("common-response-header");
+ success = header.getBoolean("success");
+ reason = header.getString("reason");
+ } catch (Exception e) {
+ LOG.error("Unknown error prcoessing failed response from provider. Json not in expected format", e);
+ throw new APPCException("APPC has an unknown RPC error");
+ }
+ if (success) {
+ return true;
+ }
+ String reasonStr = reason == null ? "Unknown" : reason;
+ LOG.warn(String.format("Topology Operation [%s] failed. Reason: %s", msg.getHeader().getRequestID(), reasonStr));
+ throw new APPCException(reasonStr);
+
+ }
+ throw new APPCException(String.format("Unexpected response from endpoint: [%d] - %s ", httpCode, respBody));
+ }
+
+ /**
+ * Updates the static var URL and returns the value;
+ *
+ * @return The new value of URL
+ */
+ public static String getUrl() {
+ return url.toExternalForm();
+ }
+
+ public static void setUrl(String newUrl) {
+ try {
+ url = new URL(newUrl);
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Sets the basic authentication header for the given user and password. If either entry is null then set basic auth
+ * to null
+ *
+ * @param user
+ * The user with optional domain name
+ * @param password
+ * The password for the user
+ * @return The new value of the basic auth string that will be used in the request headers
+ */
+ public static String setAuthentication(String user, String password) {
+ if (user != null && password != null) {
+ String authStr = user + ":" + password;
+ basic_auth = new String(Base64.encodeBase64(authStr.getBytes()));
+ } else {
+ basic_auth = null;
+ }
+ return basic_auth;
+ }
+
+ /**
+ * Builds the request body for a topology operation
+ *
+ * @param id
+ * The request id
+ * @param url
+ * The vm's url
+ *
+ * @param pgstreams
+ * The streams to send to the traffic generator
+ *
+ * @return A String containing the request body
+ */
+ private static String buildReqest(String id, String url, String pgstreams) {
+
+ return String.format(TEMPLATE, id, url, pgstreams);
+ }
+
+ @SuppressWarnings("deprecation")
+ private static HttpClient getHttpClient() throws APPCException {
+ HttpClient client;
+ if (url.getProtocol().equals("https")) {
+ try {
+ KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ trustStore.load(null, null);
+ MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
+ sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+
+ HttpParams params = new BasicHttpParams();
+ HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
+ HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
+
+ SchemeRegistry registry = new SchemeRegistry();
+ registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ registry.register(new Scheme("https", sf, 443));
+ registry.register(new Scheme("https", sf, 8443));
+ registry.register(new Scheme("http", sf, 8181));
+
+ ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
+ client = new DefaultHttpClient(ccm, params);
+ } catch (Exception e) {
+ client = new DefaultHttpClient();
+ }
+ } else if (url.getProtocol().equals("http")) {
+ client = new DefaultHttpClient();
+ } else {
+ throw new APPCException(
+ "The provider.topology.url property is invalid. The url did not start with http[s]");
+ }
+ return client;
+ }
+
+ @SuppressWarnings("deprecation")
+ public static class MySSLSocketFactory extends SSLSocketFactory {
+ private SSLContext sslContext = SSLContext.getInstance("TLS");
+
+ public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException,
+ KeyStoreException, UnrecoverableKeyException {
+ super(truststore);
+
+ TrustManager tm = new X509TrustManager() {
+ @Override
+ public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ }
+
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
+ };
+
+ sslContext.init(null, new TrustManager[] {
+ tm
+ }, null);
+ }
+
+ @Override
+ public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
+ throws IOException, UnknownHostException {
+ return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
+ }
+
+ @Override
+ public Socket createSocket() throws IOException {
+ return sslContext.getSocketFactory().createSocket();
+ }
+ }
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/impl/WorkerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/impl/WorkerImpl.java
new file mode 100644
index 000000000..ef72c6e12
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/impl/WorkerImpl.java
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.demo.impl;
+
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.listener.EventHandler;
+import org.onap.appc.listener.demo.model.IncomingMessage;
+import org.onap.appc.listener.demo.model.Status;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class WorkerImpl implements Runnable {
+
+ private final EELFLogger LOG = EELFManager.getInstance().getLogger(WorkerImpl.class);
+
+ // Should have all of the data we need for processing
+ private IncomingMessage event;
+
+ // So we can post messages from inside the worker.
+ private EventHandler dmaap;
+
+ public WorkerImpl(IncomingMessage message, EventHandler dmaap) {
+ this.event = message;
+ this.dmaap = dmaap;
+ }
+
+ @Override
+ public void run() {
+ LOG.debug(String.format("Started working on %s", event.getHeader().getRequestID()));
+
+ dmaap.postStatus(event.toOutgoing(Status.ACCEPTED));
+ // Run the dg in a try catch to handle all exceptions and update the
+ // message at the end
+ try {
+ if (doDG(event)) {
+ dmaap.postStatus(event.toOutgoing(Status.SUCCESS));
+ LOG.debug(String.format("Event %s finished successfully", event.getHeader().getRequestID()));
+ } else {
+ // Should never happen. Exception with message should be thrown instead.
+ LOG.error(String.format(
+ "We somehow returned false from doDG() instead of throwing exception. Incoming event [%s]",
+ event.toJson().toString()));
+ dmaap.postStatus(event.toOutgoing(Status.FAILURE));
+ }
+
+ } catch (Exception e) {
+ // Unknown exception from DG method. Fail and pass the exception
+ // along
+ String msg = "Exception: " + e.getMessage();
+ LOG.warn(String.format("Event %s finished with failure. %s", event.getHeader().getRequestID(), msg));
+ //TODO: should a message be included? there is nothing in the API spec for a msg?
+ //dmaap.postStatus(event.toOutgoing(Status.FAILURE, msg));
+ dmaap.postStatus(event.toOutgoing(Status.FAILURE));
+ }
+
+ LOG.debug("Done working on " + event.getHeader().getRequestID());
+ }
+
+ private boolean doDG(IncomingMessage msg) throws APPCException {
+ return ProviderOperations.topologyDG(msg);
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/Action.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/Action.java
new file mode 100644
index 000000000..eecc99b4c
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/Action.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.demo.model;
+
+public enum Action {
+ Restart("Restart"), Rebuild("Rebuild"), Migrate("Migrate"), Evacuate("Evacuate"), Snapshot("Snapshot"),modifyconfig("ModifyConfig");
+
+ /**
+ * Converts the string to an Action
+ *
+ * @param value
+ * The string to try and convert. Is case insensitive
+ * @return The action matching the string or null if no match was found.
+ */
+ public static Action toAction(String value) {
+ if (value != null) {
+ for (Action e : values()) {
+ if (e.getValue().toUpperCase().equals(value.toUpperCase())) {
+ return e;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private String value;
+
+ private Action(String valueToUse) {
+ value = valueToUse;
+ }
+
+ public final String getValue() {
+ return value;
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/CommonMessage.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/CommonMessage.java
new file mode 100644
index 000000000..75a618754
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/CommonMessage.java
@@ -0,0 +1,343 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.demo.model;
+
+import java.io.Serializable;
+import java.util.Collection;
+
+import org.json.JSONObject;
+import org.onap.appc.listener.util.Mapper;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+/**
+ * This class holds attributes that are common to DMaaP messages both coming in from DCAE and being sent out by APPC
+ *
+ */
+@JsonSerialize(include = Inclusion.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class CommonMessage implements Serializable {
+ /*
+ * { "CommonHeader": { "TimeStamp": "0000-00-00T00:00:00.000Z", "APIver": "1.01", "OriginatorID": "policy.pdp01",
+ * "RequestID": "b74d13c5-bb26-4b04-992c-4679dfc8280e", "SubrequestID": "1" }, "Action": "RESTART", "Payload": {
+ * "VServerSelfLink":
+ * "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345",
+ * "VNF_NAME": "test", "VMID": "abc12345-1234-5678-890a-abcdefg12345", "TenantID":
+ * "abcde12345fghijk6789lmnopq123rst", "LOC_ID": "Test", "in-maint": "false", "Identity":
+ * "http://example.com:5000/v2.0", "Prov_status": "ACTIVE", "OAM_IPV4": "192.168.1.2",
+ * "is-closed-loop-disabled": "false", "VM_NAME": "basx0001vm034", "OAM_IPV6": "aaaa::bbbb:cccc:dddd:eeee/64" } }
+ */
+
+ private static final long serialVersionUID = 1L;
+
+ /*
+ * The common header
+ */
+ @JsonProperty("CommonHeader")
+ private CommonHeader header;
+
+ /*
+ * The payload
+ */
+ @JsonProperty("Payload")
+ private Payload payload;
+
+ @JsonIgnore
+ private long startTime = System.currentTimeMillis();
+
+ /*
+ * Getters and Setters
+ */
+
+ public long getStartTime() {
+ return startTime;
+ }
+
+ public void setStartTime(long startTime) {
+ this.startTime = startTime;
+ }
+
+ /**
+ * @return the header
+ */
+ public CommonHeader getHeader() {
+ return header;
+ }
+
+ /**
+ * @param header
+ * the header to set
+ */
+ public void setHeader(CommonHeader header) {
+ this.header = header;
+ }
+
+ /**
+ * @return the payload
+ */
+ public Payload getPayload() {
+ return payload;
+ }
+
+ /**
+ * @param payload
+ * the payload to set
+ */
+ public void setPayload(Payload payload) {
+ this.payload = payload;
+ }
+
+ /**
+ * Convenience method to return a json representation of this object.
+ *
+ * @return The json representation of this object
+ */
+ public JSONObject toJson() {
+ return Mapper.toJsonObject(this);
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ public static class CommonHeader {
+ /*
+ * "CommonHeader": { "TimeStamp": "2016-05-11T13:53:53.146Z", "APIver": "1.01", "OriginatorID": "policy.pdp01",
+ * "RequestID": "b74d13c5-bb26-4b04-992c-4679dfc8280e", "SubrequestID": "1" }
+ */
+
+ /*
+ * The timestamp of the message
+ */
+ @JsonProperty("TimeStamp")
+ private String timeStamp;
+
+ /*
+ * The API version of the message
+ */
+ @JsonProperty("APIver")
+ private String apiVer;
+
+ /*
+ * The Originator ID of the message
+ */
+ @JsonProperty("OriginatorID")
+ private String originatorId;
+
+ /*
+ * The Request Id of the message
+ */
+ @JsonProperty("RequestID")
+ private String requestID;
+
+ /*
+ * The Subrequest Id of the message
+ */
+ @JsonProperty("SubrequestID")
+ private String subRequestId;
+
+ /**
+ * @return the timeStamp
+ */
+ public String getTimeStamp() {
+ return timeStamp;
+ }
+
+ /**
+ * @param timeStamp
+ * the timeStamp to set
+ */
+ public void setTimeStamp(String timeStamp) {
+ this.timeStamp = timeStamp;
+ }
+
+ /**
+ * @return the apiVer
+ */
+ public String getApiVer() {
+ return apiVer;
+ }
+
+ /**
+ * @param apiVer
+ * the apiVer to set
+ */
+ public void setApiVer(String apiVer) {
+ this.apiVer = apiVer;
+ }
+
+ /**
+ * @return the originatorId
+ */
+ public String getOriginatorId() {
+ return originatorId;
+ }
+
+ /**
+ * @param originatorId
+ * the originatorId to set
+ */
+ public void setOriginatorId(String originatorId) {
+ this.originatorId = originatorId;
+ }
+
+ /**
+ * @return the requestID
+ */
+ public String getRequestID() {
+ return requestID;
+ }
+
+ /**
+ * @param requestID
+ * the requestID to set
+ */
+ public void setRequestID(String requestID) {
+ this.requestID = requestID;
+ }
+
+ /**
+ * @return the subRequestId
+ */
+ public String getSubRequestId() {
+ return subRequestId;
+ }
+
+ /**
+ * @param subRequestId
+ * the subRequestId to set
+ */
+ public void setSubRequestId(String subRequestId) {
+ this.subRequestId = subRequestId;
+ }
+ };
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ public static class Payload {
+ /*
+ * "Payload": { "VServerSelfLink":
+ * "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345",
+ * "VNF_NAME": "test", "VMID": "abc12345-1234-5678-890a-abcdefg12345", "TenantID":
+ * "abcde12345fghijk6789lmnopq123rst", "LOC_ID": "Test", "in-maint": "false", "Identity":
+ * "http://example.com:5000/v2.0", "Prov_status": "ACTIVE", "OAM_IPV4": "192.168.1.2",
+ * "is-closed-loop-disabled": "false", "VM_NAME": "test", "OAM_IPV6": "aaaa::bbbb:cccc:dddd:eeee/64" }
+ */
+
+ /*
+ * The TenantID of the message
+ */
+ @JsonProperty("generic-vnf.vnf-id")
+ private String genericVnfId;
+
+ /**
+ * @return the TenantID
+ */
+ public String getGenericVnfId() {
+ return genericVnfId;
+ }
+
+ /**
+ * @param TenantID
+ * the TenantID to set
+ */
+ public void setGenericVnfId(String genericVnfId) {
+ this.genericVnfId = genericVnfId;
+ }
+
+ @JsonProperty("pg-streams")
+ private pgStreams pgStreams;
+
+ /**
+ * @return the TenantID
+ */
+
+ public String getPgStreams() {
+ String r = "{\\\"pg-streams\\\": {\\\"pg-stream\\\":[";
+ boolean first = true;
+ for(pgStream p : this.pgStreams.streams){
+ String n = "{\\\"id\\\":\\\""+p.getId()+"\\\", \\\"is-enabled\\\":\\\""+p.getIsEnabled()+"\\\"}";
+ if(!first){
+ r = r.concat(",");
+ }
+ first = false;
+ r = r.concat(n);
+ }
+ r= r.concat("]}}");
+ return r;
+ }
+
+ /**
+ * @param TenantID
+ * the TenantID to set
+ */
+ public void setPgStreams(pgStreams pgStreams) {
+ this.pgStreams = pgStreams;
+ }
+
+
+
+
+
+ };
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ public static class pgStreams {
+ @JsonProperty("pg-stream")
+ private Collection streams;
+
+ public Collection getStreams() {
+ return streams;
+ }
+
+ public void setStreams(Collection streams) {
+ this.streams = streams;
+ }
+
+
+ };
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ public static class pgStream{
+ public String getId() {
+ return id;
+ }
+ public void setId(String id) {
+ this.id = id;
+ }
+ public String getIsEnabled() {
+ return isEnabled;
+ }
+ public void setIsEnabled(String isEnabled) {
+ this.isEnabled = isEnabled;
+ }
+ @JsonProperty("id")
+ private String id;
+ @JsonProperty("is-enabled")
+ private String isEnabled;
+ };
+
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/IncomingMessage.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/IncomingMessage.java
new file mode 100644
index 000000000..555329106
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/IncomingMessage.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.demo.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
+
+/**
+ * This class represents a message coming in from DCAE.
+ *
+ */
+@JsonSerialize(include = Inclusion.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class IncomingMessage extends CommonMessage {
+
+ private static final long serialVersionUID = 1L;
+
+ /*
+ * The action being requested. Its presence signals that it is an incoming message and it is not present on outgoing
+ * messages
+ */
+ //TODO; use enum
+ @JsonProperty("Action")
+ private String action;
+
+
+ public String getRequest() {
+ return action;
+ }
+
+ @JsonIgnore
+ public Action getAction() {
+ return Action.toAction(action);
+ }
+
+ public void setRequest(String request) {
+ this.action = request;
+ }
+
+// @Override
+// public String toString() {
+// String time = getRequestTime() != null ? getRequestTime() : "N/A";
+// // String req = request != null ? request : "N/A";
+// return String.format("[%s - %s]", time, getId());
+// }
+
+// public String toOutgoing(Status status) {
+// return toOutgoing(status);
+// }
+
+ public String toOutgoing(Status status) {
+ OutgoingMessage out = new OutgoingMessage(this);
+ out.setResponse(status);
+ return out.toResponse().toString();
+ }
+
+ /**
+ * Determines if this message should be parsed parsed. Will eventually check that the message is well formed, has
+ * all required fields, and had not exceeded any timing restrictions.
+ *
+ * @return True if the message should be parsed. False otherwise
+ */
+ public boolean isValid() {
+ return true;
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/OutgoingMessage.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/OutgoingMessage.java
new file mode 100644
index 000000000..a3294dd8c
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/OutgoingMessage.java
@@ -0,0 +1,195 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.demo.model;
+
+import java.net.InetAddress;
+import java.security.SecureRandom;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.json.JSONObject;
+import org.onap.appc.listener.util.Mapper;
+import org.onap.appc.util.Time;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
+
+/**
+ * This class represents a message being sent out to DMaaP by APPC to update listeners on the status of a request
+ *
+ */
+@JsonSerialize(include = Inclusion.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class OutgoingMessage extends CommonMessage {
+
+ public OutgoingMessage() {
+
+ }
+
+ public OutgoingMessage(IncomingMessage msg) {
+ setHeader(msg.getHeader());
+ setPayload(msg.getPayload());
+// setId(msg.getId());
+// setOriginalRequest(msg.getRequest());
+// setRequestClient(msg.getRequestClient());
+// setRequestTime(msg.getRequestTime());
+// setVmName(msg.getVmName());
+// setFromSystem(generateFrom());
+// setResponse(Status.PENDING);
+// setPolicyName(msg.getPolicyName());
+// setPolicyVersion(msg.getPolicyVersion());
+// setStartTime(msg.getStartTime());
+ }
+
+ private static final long serialVersionUID = -5447940920271469613L;
+ /*
+ * The status of the response
+ */
+ @JsonProperty("Status")
+ private OutStatus status;
+
+ /**
+ * @return the status
+ */
+ public OutStatus getStatus() {
+ return status;
+ }
+
+ /**
+ * @param status the status to set
+ */
+ public void setStatus(OutStatus status) {
+ this.status = status;
+ }
+
+ public void updateResponseTime() {
+ SecureRandom rand = new SecureRandom();
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss.SSS");
+ df.setTimeZone(TimeZone.getTimeZone("UTC"));
+ String date = df.format(new Date(Time.utcTime()));
+ //this.responseTime = String.format("%s%03d", date, rand.nextInt(1000));
+ }
+
+ public String generateFrom() {
+ String name;
+ try {
+ InetAddress iAddress = InetAddress.getLocalHost();
+ name = iAddress.getCanonicalHostName();
+ } catch (Exception e) {
+ // Could not get anything from the InetAddress
+ name = "UnknownHost";
+ }
+ return "appc@" + name;
+ }
+
+ public JSONObject toResponse() {
+ updateResponseTime();
+ JSONObject json = Mapper.toJsonObject(this);
+
+ if (!json.has("message")) {
+ // If there is no message, parrot the status (response field)
+ // TODO - Can this be removed for 1602 making message truely optional?
+ //json.put("message", this.getResponse().toString());
+ }
+
+ // Removed duplication of status from message for 1602
+ // json.put("message", String.format("%s: %s", request, json.get("message")));
+
+ return json;
+ }
+
+// @Override
+// public String toString() {
+// return String.format("%s - %s", getId(), getResponse());
+// }
+
+ public static class OutStatus{
+ @JsonProperty("Code")
+ private String code;
+
+ @JsonProperty("Value")
+ private String value;
+
+ /**
+ * @return the code
+ */
+ public String getCode() {
+ return code;
+ }
+
+ /**
+ * @param code the code to set
+ */
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ /**
+ * @return the value
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * @param value the value to set
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ }
+
+ public void setResponse(Status newStatus) {
+ if(this.status == null){
+ this.status = new OutStatus();
+ }
+
+ switch (newStatus){
+ case ACCEPTED:
+ this.status.setValue(newStatus.getValue());
+ this.status.setCode("100");
+ break;
+
+ case FAILURE:
+ this.status.setValue(newStatus.getValue());
+ this.status.setCode("500");
+ break;
+
+ case SUCCESS:
+ this.status.setValue(newStatus.getValue());
+ this.status.setCode("400");
+ break;
+ default:
+ break;
+
+ }
+
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/Status.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/Status.java
new file mode 100644
index 000000000..09db11402
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/Status.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.demo.model;
+
+public enum Status {
+ /*
+ * APP-C acknowledges that it has read the event off of the wire. This is the initial status of an OutgoingEvent
+ */
+ ACCEPTED("ACCEPTED"),
+
+ /*
+ * APP-C has finished processing the event without errors
+ */
+ SUCCESS("SUCCESS"),
+
+ /*
+ * APP-C has finished processing the event with errors
+ */
+ FAILURE("FAILURE");
+
+ /**
+ * Converts the string to an Status
+ *
+ * @param value
+ * The string to try and convert. Is case insensitive
+ * @return The status matching the string or null if no match was found.
+ */
+ public static Status toStatus(String value) {
+ if (value != null) {
+ for (Status e : values()) {
+ if (e.getValue().toUpperCase().equals(value.toUpperCase())) {
+ return e;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private String value;
+
+ private Status(String valueToUse) {
+ value = valueToUse;
+ }
+
+ public final String getValue() {
+ return value;
+ }
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/ControllerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/ControllerImpl.java
new file mode 100644
index 000000000..b830b6fc7
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/ControllerImpl.java
@@ -0,0 +1,129 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.lang3.concurrent.BasicThreadFactory;
+import org.onap.appc.listener.Controller;
+import org.onap.appc.listener.Listener;
+import org.onap.appc.listener.ListenerProperties;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+
+/**
+ * A common implementation of a controller. This controller should not need to be modified to implement new listeners
+ *
+ */
+public class ControllerImpl implements Controller {
+
+ private final EELFLogger LOG = EELFManager.getInstance().getLogger(ControllerImpl.class);
+
+ private int LISTENER_COUNT = 1;
+
+ private Map listeners = null;
+
+ private ThreadPoolExecutor executor;
+
+ /**
+ * Creates a Controller with the set of listener properties which will be used to start listener threads.
+ *
+ * @param properties
+ * A non null Set of ListenerProperties
+ */
+ public ControllerImpl(Set properties) {
+ listeners = new HashMap();
+ for (ListenerProperties props : properties) {
+ if (props.getClass() != null) {
+ listeners.put(props, null);
+ } else {
+ LOG.error(String.format(
+ "The ListenerProperties %s has no Listener class associated with it and will not run.", props));
+ }
+ }
+
+ LISTENER_COUNT = properties.size();
+
+ executor = new ThreadPoolExecutor(LISTENER_COUNT, LISTENER_COUNT, 1, TimeUnit.SECONDS,
+ new ArrayBlockingQueue(LISTENER_COUNT));
+
+ // Custom Named thread factory
+ BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("Appc-Listener-%d").build();
+ executor.setThreadFactory(threadFactory);
+ }
+
+ @Override
+ public void start() {
+ LOG.info("Starting DMaaP Controller.");
+ for (ListenerProperties props : listeners.keySet()) {
+ try {
+ if (props.isDisabled()) {
+ LOG.warn(String.format("The listener %s is disabled and will not be run", props.getPrefix()));
+ } else {
+ Listener l = props.getListenerClass().getConstructor(ListenerProperties.class).newInstance(props);
+ l.setListenerId(props.getPrefix());
+ listeners.put(props, l);
+ executor.execute(l);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ LOG.error(String.format("Exception while starting listener %s.", props), e);
+ }
+ }
+ }
+
+ @Override
+ public void stop(boolean stopNow) {
+ LOG.info("Stopping DMaaP Controller.");
+ Iterator itr = listeners.values().iterator();
+ while (itr.hasNext()) {
+ Listener l = itr.next();
+ if (stopNow) {
+ l.stopNow();
+ } else {
+ l.stop();
+ }
+ itr.remove();
+ }
+ executor.shutdown();
+ try {
+ executor.awaitTermination(10, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ }
+ }
+
+ @Override
+ public Map getListeners() {
+ return listeners;
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java
new file mode 100644
index 000000000..85ce93001
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java
@@ -0,0 +1,337 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.impl;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.onap.appc.adapter.factory.MessageService;
+import org.onap.appc.adapter.message.Consumer;
+import org.onap.appc.adapter.message.MessageAdapterFactory;
+import org.onap.appc.adapter.message.Producer;
+import org.onap.appc.listener.EventHandler;
+import org.onap.appc.listener.ListenerProperties;
+import org.onap.appc.listener.util.Mapper;
+import org.onap.appc.logging.LoggingConstants;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.MDC;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * This class is a wrapper for the DMaaP client provided in appc-dmaap-adapter. Its aim is to ensure
+ * that only well formed messages are sent and received on DMaaP.
+ */
+public class EventHandlerImpl implements EventHandler {
+
+ private final EELFLogger LOG = EELFManager.getInstance().getLogger(EventHandlerImpl.class);
+
+ /*
+ * The amount of time in seconds to keep a connection to a topic open while waiting for data
+ */
+ private int READ_TIMEOUT = 60;
+
+ /*
+ * The pool of hosts to query against
+ */
+ private Collection pool;
+
+ /*
+ * The topic to read messages from
+ */
+ private String readTopic;
+
+ /*
+ * The topic to write messages to
+ */
+ private Set writeTopics;
+
+ /*
+ * The client (group) name to use for reading messages
+ */
+ private String clientName;
+
+ /*
+ * The id of the client (group) that is reading messages
+ */
+ private String clientId;
+
+ /*
+ * The api public key to use for authentication
+ */
+ private String apiKey;
+
+ /*
+ * The api secret key to use for authentication
+ */
+ private String apiSecret;
+
+ /*
+ * A json object containing filter arguments.
+ */
+ private String filter_json;
+
+ private MessageService messageService;
+
+ private Consumer reader = null;
+ private Producer producer = null;
+
+ public EventHandlerImpl(ListenerProperties props) {
+ pool = new HashSet<>();
+ writeTopics = new HashSet<>();
+
+ if (props != null) {
+ readTopic = props.getProperty(ListenerProperties.KEYS.TOPIC_READ);
+ clientName = props.getProperty(ListenerProperties.KEYS.CLIENT_NAME, "APP-C");
+ clientId = props.getProperty(ListenerProperties.KEYS.CLIENT_ID, "0");
+ apiKey = props.getProperty(ListenerProperties.KEYS.AUTH_USER_KEY);
+ apiSecret = props.getProperty(ListenerProperties.KEYS.AUTH_SECRET_KEY);
+
+ filter_json = props.getProperty(ListenerProperties.KEYS.TOPIC_READ_FILTER);
+
+ READ_TIMEOUT = Integer
+ .valueOf(props.getProperty(ListenerProperties.KEYS.TOPIC_READ_TIMEOUT, String.valueOf(READ_TIMEOUT)));
+
+ String hostnames = props.getProperty(ListenerProperties.KEYS.HOSTS);
+ if (hostnames != null && !hostnames.isEmpty()) {
+ for (String name : hostnames.split(",")) {
+ pool.add(name);
+ }
+ }
+
+ String writeTopicStr = props.getProperty(ListenerProperties.KEYS.TOPIC_WRITE);
+ if (writeTopicStr != null) {
+ for (String topic : writeTopicStr.split(",")) {
+ writeTopics.add(topic);
+ }
+ }
+
+ messageService = MessageService.parse(props.getProperty(ListenerProperties.KEYS.MESSAGE_SERVICE));
+
+ LOG.info(String.format(
+ "Configured to use %s client on host pool [%s]. Reading from [%s] filtered by %s. Wriring to [%s]. Authenticated using %s",
+ messageService, hostnames, readTopic, filter_json, writeTopics, apiKey));
+ }
+ }
+
+ @Override
+ public List getIncomingEvents() {
+ return getIncomingEvents(1000);
+ }
+
+ @Override
+ public List getIncomingEvents(int limit) {
+ List out = new ArrayList<>();
+ LOG.info(String.format("Getting up to %d incoming events", limit));
+ // reuse the consumer object instead of creating a new one every time
+ if (reader == null) {
+ LOG.info("Getting Consumer...");
+ reader = getConsumer();
+ }
+ if (reader != null) {
+ List items = reader.fetch(READ_TIMEOUT * 1000, limit);
+ for (String item : items) {
+ out.add(item);
+ }
+ }
+ LOG.info(String.format("Read %d messages from %s as %s/%s.", out.size(), readTopic, clientName, clientId));
+ return out;
+ }
+
+ @Override
+ public List getIncomingEvents(Class cls) {
+ return getIncomingEvents(cls, 1000);
+ }
+
+ @Override
+ public List getIncomingEvents(Class cls, int limit) {
+ List incomingStrings = getIncomingEvents(limit);
+ return Mapper.mapList(incomingStrings, cls);
+ }
+
+ @Override
+ public void postStatus(String event) {
+ postStatus(null, event);
+ }
+
+ @Override
+ public void postStatus(String partition, String event) {
+ LOG.debug(String.format("Posting Message [%s]", event));
+ if (producer == null) {
+ LOG.info("Getting Producer...");
+ producer = getProducer();
+ }
+ producer.post(partition, event);
+ }
+
+ /**
+ * Returns a consumer object for direct access to our Cambria consumer interface
+ *
+ * @return An instance of the consumer interface
+ */
+ protected Consumer getConsumer() {
+ LOG.debug(String.format("Getting Consumer: %s %s/%s/%s", pool, readTopic, clientName, clientId));
+ if (filter_json == null && writeTopics.contains(readTopic)) {
+ LOG.error(
+ "*****We will be writing and reading to the same topic without a filter. This will cause an infinite loop.*****");
+ }
+
+ Consumer out = null;
+ BundleContext ctx = FrameworkUtil.getBundle(EventHandlerImpl.class).getBundleContext();
+ if (ctx != null) {
+ ServiceReference svcRef = ctx.getServiceReference(MessageAdapterFactory.class.getName());
+ if (svcRef != null) {
+ try {
+ out = ((MessageAdapterFactory) ctx.getService(svcRef))
+ .createConsumer(pool, readTopic, clientName, clientId, filter_json, apiKey, apiSecret);
+ } catch (Exception e) {
+ //TODO:create eelf message
+ LOG.error("EvenHandlerImp.getConsumer calling MessageAdapterFactor.createConsumer", e);
+ }
+ if (out != null) {
+ for (String url : pool) {
+ if (url.contains("3905") || url.contains("https")) {
+ out.useHttps(true);
+ break;
+ }
+ }
+ }
+ }
+ }
+ return out;
+ }
+
+ /**
+ * Returns a consumer object for direct access to our Cambria producer interface
+ *
+ * @return An instance of the producer interface
+ */
+ protected Producer getProducer() {
+ LOG.debug(String.format("Getting Producer: %s %s", pool, readTopic));
+
+ Producer out = null;
+ BundleContext ctx = FrameworkUtil.getBundle(EventHandlerImpl.class).getBundleContext();
+ if (ctx != null) {
+ ServiceReference svcRef = ctx.getServiceReference(MessageAdapterFactory.class.getName());
+ if (svcRef != null) {
+ out = ((MessageAdapterFactory) ctx.getService(svcRef))
+ .createProducer(pool, writeTopics, apiKey, apiSecret);
+ if (out != null) {
+ for (String url : pool) {
+ if (url.contains("3905") || url.contains("https")) {
+ out.useHttps(true);
+ break;
+ }
+ }
+ }
+ }
+ }
+ return out;
+ }
+
+ @Override
+ public void closeClients() {
+ LOG.debug("Closing Consumer and Producer DMaaP clients");
+ if (reader != null) {
+ reader.close();
+ }
+ if (producer != null) {
+ producer.close();
+ }
+ }
+
+ @Override
+ public String getClientId() {
+ return clientId;
+ }
+
+ @Override
+ public void setClientId(String clientId) {
+ this.clientId = clientId;
+ }
+
+ @Override
+ public String getClientName() {
+ return clientName;
+ }
+
+ @Override
+ public void setClientName(String clientName) {
+ this.clientName = clientName;
+ MDC.put(LoggingConstants.MDCKeys.PARTNER_NAME, clientName);
+ }
+
+ @Override
+ public void addToPool(String hostname) {
+ pool.add(hostname);
+ }
+
+ @Override
+ public Collection getPool() {
+ return pool;
+ }
+
+ @Override
+ public void removeFromPool(String hostname) {
+ pool.remove(hostname);
+ }
+
+ @Override
+ public String getReadTopic() {
+ return readTopic;
+ }
+
+ @Override
+ public void setReadTopic(String readTopic) {
+ this.readTopic = readTopic;
+ }
+
+ @Override
+ public Set getWriteTopics() {
+ return writeTopics;
+ }
+
+ @Override
+ public void setWriteTopics(Set writeTopics) {
+ this.writeTopics = writeTopics;
+ }
+
+ @Override
+ public void clearCredentials() {
+ apiKey = null;
+ apiSecret = null;
+ }
+
+ @Override
+ public void setCredentials(String key, String secret) {
+ apiKey = key;
+ apiSecret = secret;
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/util/Mapper.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/util/Mapper.java
new file mode 100644
index 000000000..bd77041ec
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/util/Mapper.java
@@ -0,0 +1,137 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.listener.util;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.json.JSONObject;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class Mapper {
+
+ private static final EELFLogger LOG = EELFManager.getInstance().getLogger(Mapper.class);
+
+ private static ObjectMapper mapper = new ObjectMapper();
+
+ /**
+ * @return The object mapper that we are using.
+ */
+ public static ObjectMapper getMapper() {
+ return mapper;
+ }
+
+ /**
+ * Convert a String to a DcaeMessage
+ *
+ * @param data
+ * The json string to try and parse
+ * @return A DcaeMessage from the json string or null if it could not
+ */
+ public static T mapOne(String data, Class cls) {
+ try {
+ return mapper.readValue(data, cls);
+ } catch (Exception e) {
+ LOG.warn(String.format("Could not map [ %s ] to %s", data, cls.getName()), e);
+ return null;
+ }
+ }
+
+ public static List mapList(List data, Class cls) {
+ List out = new ArrayList();
+ for (String s : data) {
+ T tmp = Mapper.mapOne(s, cls);
+ if (tmp != null) {
+ out.add(tmp);
+ }
+ }
+ return out;
+ }
+
+ /**
+ * Convenience method to try and convert objects to json String
+ *
+ * @param obj
+ * The object to try and convert
+ * @return A json string representing the object or null if it could not be converted
+ */
+ public static String toJsonString(Object obj) {
+ String jsonStr;
+ try {
+ if (obj instanceof JSONObject) {
+ jsonStr = obj.toString();
+ }else {
+ jsonStr = mapper.writeValueAsString(obj);
+ }
+ return jsonStr;
+ } catch (Exception e) {
+ LOG.warn(String.format("Could not map %s to JSONObject.", obj), e);
+ return null;
+ }
+ }
+
+ public static JSONObject toJsonObject(Object obj) {
+ String jsonStr;
+ try {
+ if (obj.getClass().equals(String.class)) {
+ jsonStr = (String) obj;
+ } else {
+ jsonStr = mapper.writeValueAsString(obj);
+ }
+ return new JSONObject(jsonStr);
+ } catch (Exception e) {
+ LOG.warn(String.format("Could not map %s to JSONObject.", obj), e);
+ return null;
+ }
+ }
+ public static JsonNode toJsonNodeFromJsonString(String jsonStr) {
+ JsonNode jsonNode = null;
+ if(jsonStr != null) {
+ try {
+ jsonNode = mapper.readTree(jsonStr);
+ } catch (IOException e) {
+ LOG.warn(String.format("Could not map %s to jsonNode.", jsonStr), e);
+ }
+ }
+ return jsonNode;
+ }
+ public static JsonNode toJsonNode(Object obj) {
+ JsonNode jsonNode = null;
+ String jsonStr = toJsonString(obj);
+ if(jsonStr != null) {
+ try {
+ jsonNode = mapper.readTree(jsonStr);
+ } catch (IOException e) {
+ LOG.warn(String.format("Could not map %s to JSONObject.", obj), e);
+ }
+ }
+ return jsonNode;
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/AbstractListener.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/AbstractListener.java
deleted file mode 100644
index 89c75a357..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/AbstractListener.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener;
-
-import java.security.SecureRandom;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.RejectedExecutionHandler;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.apache.commons.lang3.concurrent.BasicThreadFactory;
-import org.onap.appc.listener.impl.EventHandlerImpl;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
-public abstract class AbstractListener implements Listener {
-
- private final EELFLogger LOG = EELFManager.getInstance().getLogger(AbstractListener.class);
-
- protected AtomicBoolean run = new AtomicBoolean(false);
-
- protected int QUEUED_MIN = 1;
- protected int QUEUED_MAX = 10;
-
- protected int THREAD_MIN = 4;
- protected int THREAD_MAX = THREAD_MIN; // Fixed thread pool
- protected int THREAD_SCALE_DOWN_SEC = 10; // Number of seconds to wait until we remove idle threads
-
- protected ThreadPoolExecutor executor;
-
- protected EventHandler dmaap;
-
- protected ListenerProperties props;
-
- private String listenerId;
-
- public AbstractListener(ListenerProperties props) {
- updateProperties(props);
-
- dmaap = new EventHandlerImpl(props);
- if (dmaap.getClientId().equals("0")) {
- dmaap.setClientId(String.valueOf(new SecureRandom().nextInt(1000)));
- }
-
- BlockingQueue threadQueue = new ArrayBlockingQueue(QUEUED_MAX + QUEUED_MIN + 1);
- executor = new ThreadPoolExecutor(THREAD_MIN, THREAD_MAX, THREAD_SCALE_DOWN_SEC, TimeUnit.SECONDS, threadQueue,
- new JobRejectionHandler());
-
- // Custom Named thread factory
- BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("DMaaP-Worker-%d").build();
- executor.setThreadFactory(threadFactory);
-
- run.set(true);
- }
-
- /**
- * Starts a loop that will only end after stop() or stopNow() are called. The loop will read messages off the DMaaP
- * topic and perform some action on them while writing messages back to DMaaP at critical points in the execution.
- * Inherited from Runnable.
- *
- * @see java.lang.Runnable#run()
- */
- @Override
- public void run() {
- LOG.error("Listener.run() has not been implemented");
- }
-
- @Override
- public void stop() {
- run.set(false);
- LOG.info(String.format("Stopping with %d messages in queue", executor.getQueue().size()));
- executor.shutdown();
- try {
- executor.awaitTermination(10, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- LOG.error("Listener graceful stop() failed", e);
- }
-
- // close DMaaP clients
- if (dmaap != null) {
- dmaap.closeClients();
- }
- LOG.info("Listener Thread Pool Finished");
- }
-
- @Override
- public void stopNow() {
- run.set(false);
- LOG.info(String.format("StopNow called. Orphaning %d messages in the queue", executor.getQueue().size()));
- executor.getQueue().clear();
- stop();
- }
-
- @Override
- public String getBenchmark() {
- return String.format("%s - No benchmarking implemented.", getListenerId());
- }
-
- @Override
- public String getListenerId() {
- return listenerId;
- }
-
- // Sets the id of the listener in
- @Override
- public void setListenerId(String id) {
- listenerId = id;
- }
-
- private void updateProperties(ListenerProperties properties) {
- this.props = properties;
- QUEUED_MIN =
- Integer.valueOf(props.getProperty(ListenerProperties.KEYS.THREADS_MIN_QUEUE, String.valueOf(QUEUED_MIN)));
- QUEUED_MAX =
- Integer.valueOf(props.getProperty(ListenerProperties.KEYS.THREADS_MAX_QUEUE, String.valueOf(QUEUED_MAX)));
- THREAD_MIN =
- Integer.valueOf(props.getProperty(ListenerProperties.KEYS.THREADS_MIN_POOL, String.valueOf(THREAD_MIN)));
- THREAD_MAX =
- Integer.valueOf(props.getProperty(ListenerProperties.KEYS.THREADS_MAX_POOL, String.valueOf(THREAD_MAX)));
-
- listenerId = props.getPrefix();
- }
-
- /**
- * This class will be used to handle what happens when we cannot add a job because of a ThreadPool issue. It does
- * not get invoked if there is any fault with the job. NOTE: So far, this has only been seen when doing a
- * {@link Listener#stopNow}
- *
- */
- class JobRejectionHandler implements RejectedExecutionHandler {
- @Override
- public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
- LOG.error(String.format("A job was rejected. [%s]", r));
- }
-
- }
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/AppcEventListenerActivator.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/AppcEventListenerActivator.java
deleted file mode 100644
index 0b1eb5328..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/AppcEventListenerActivator.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener;
-
-import org.onap.appc.configuration.Configuration;
-import org.onap.appc.configuration.ConfigurationFactory;
-import org.onap.appc.listener.impl.ControllerImpl;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-
-import java.util.HashSet;
-import java.util.Properties;
-import java.util.Set;
-
-/**
- * This activator is used to initialize and terminate the dmaap listener controller and pool(s)
- *
- * The DMaaP listener is responsible for listening to a topic on the Universal Event Bus and reading in messages that
- * conform to the DCAE message format for APPC. These messages will then be parsed and passed along to the APPC Provider
- * to take action on. The listener will also send messages out on DMaaP during critical phases. The messages sent out
- * will have a status of:
- *
- * - PENDING - The listener has read the message off of DMaaP and has put it in the queue to be processed
- * - ACTIVE - The listener has begun actually processing the request and is waiting on the appc provider to
- * complete the request
- * - SUCCESS or FAILURE - The listener has gotten a response back from the appc provider. If it is a
- * FAILURE, a message should also be included
- *
- *
- *
- * Activation of the bundle will provision 1 controller that in turn will provision 1 (or in the future more) listener
- * to interact with DMaaP. Each listener will have a queue of messages read off of DMaaP and a thread pool of workers to
- * process them. This worker is responsible for contacting appc provider to perform the action
- *
- *
- * When the bundle is deactivated, the stopNow() method is called and the thread pool is emptied and all remaining jobs
- * are orphaned. Alternatively stop() could be called which would allow all remaining jobs in the queue to complete at
- * the cost of longer run time.
- *
- *
- * @since Aug 30, 2015
- * @version $Id$
- */
-public class AppcEventListenerActivator implements BundleActivator {
-
- /**
- * The bundle registration
- */
- private ServiceRegistration registration = null;
-
- /**
- * The configuration object
- */
- private Configuration configuration;
-
- /**
- * The bundle context
- */
- private static BundleContext context;
-
- /**
- * The reference to the actual implementation object that implements the services
- */
- private Controller adapter;
-
- /**
- * The logger to be used
- */
- private final EELFLogger LOG = EELFManager.getInstance().getLogger(AppcEventListenerActivator.class);
-
- /**
- * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
- * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
- *
- * This method must complete and return to its caller in a timely manner.
- *
- *
- * @param ctx
- * The execution context of the bundle being started.
- * @throws java.lang.Exception
- * If this method throws an exception, this bundle is marked as stopped and the Framework will remove
- * this bundle's listeners, unregister all services registered by this bundle, and release all services
- * used by this bundle.
- * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
- */
- @Override
- public void start(BundleContext ctx) throws Exception {
- LOG.info("Starting Bundle " + getName());
-
- context = ctx;
-
- configuration = ConfigurationFactory.getConfiguration();
-
- Properties props = configuration.getProperties();
-
- Set listeners = new HashSet<>();
-
- // Configure event listener for the demo use case
- ListenerProperties demoProps = new ListenerProperties("appc.demo", props);
- demoProps.setListenerClass(org.onap.appc.listener.demo.impl.ListenerImpl.class);
- listeners.add(demoProps);
-
- // ===========================================================================
-
- ListenerProperties clLCMProps = new ListenerProperties("appc.LCM", props);
- clLCMProps.setListenerClass(org.onap.appc.listener.LCM.impl.ListenerImpl.class);
- listeners.add(clLCMProps);
-
- // Configure the OAM properties
- String oamPropKeyPrefix = "appc.OAM";
- ListenerProperties oamProps = new ListenerProperties(oamPropKeyPrefix, props);
- if (isAppcOamPropsListenerEnabled(oamProps)) {
- oamProps.setListenerClass(org.onap.appc.listener.LCM.impl.ListenerImpl.class);
- listeners.add(oamProps);
- } else {
- LOG.warn(String.format("The listener %s is disabled and will not be run", oamPropKeyPrefix));
- }
-
- adapter = new ControllerImpl(listeners);
- if (ctx != null && registration == null) {
- LOG.info("Registering service DMaaP Controller");
- registration = ctx.registerService(Controller.class, adapter, null);
- }
- adapter.start();
-
- LOG.info("DMaaP Listener started successfully");
- }
-
- /**
- * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
- * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
- * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
- * call any Framework objects.
- *
- * This method must complete and return to its caller in a timely manner.
- *
- *
- * @param ctx
- * The execution context of the bundle being stopped.
- * @throws java.lang.Exception
- * If this method throws an exception, the bundle is still marked as stopped, and the Framework will
- * remove the bundle's listeners, unregister all services registered by the bundle, and release all
- * services used by the bundle. *
- * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- @Override
- public void stop(BundleContext ctx) throws Exception {
- boolean stopNow = true;
- LOG.info("Stopping DMaaP Listener. StopNow=" + stopNow);
- adapter.stop(stopNow);
- if (registration != null) {
- registration.unregister();
- registration = null;
- }
- LOG.info("DMaaP Listener stopped successfully");
- }
-
- public String getName() {
- return "DMaaP Listener";
- }
-
- /**
- * Check if AppcOam props disable listener or not
- *
- * @param listenerProperties of ListenerProperties objext
- * @return false only if AppcOam disabled key is defined and equal to true. Otherwise, return true.
- */
- private boolean isAppcOamPropsListenerEnabled(ListenerProperties listenerProperties) {
- final Properties appcOamProperties = listenerProperties.getProperties();
-
- return appcOamProperties == null
- || !Boolean.parseBoolean(appcOamProperties.getProperty(
- ListenerProperties.KEYS.DISABLED.getPropertySuffix()));
- }
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/Controller.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/Controller.java
deleted file mode 100644
index 4fce8972b..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/Controller.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener;
-
-import java.util.Map;
-
-/**
- * A controller is responsible for creating a listener for each ListenerProperties object that is passed in to it on
- * instantiation. The controller will create a thread pool that will contain all of the listener threads so no listener
- * can crash the controller.
- *
- */
-public interface Controller {
-
- /**
- * Creates a new thread in the thread pool for an implementation of the {@see #Listener} class set in the
- * ListenerProperties. This thread is run immediately after it is created.
- */
- public void start();
-
- /**
- * Stops each of the listeners known by this controller. Takes an optional parameter that indicates the the listener
- * should stop immediately rather than waiting for all threads to complete.
- *
- * @param stopNow
- * Determines what method the listeners should use to shutdown. If true, listeners will use the stopNow()
- * method. Otherwise they will use the stop() method.
- */
- public void stop(boolean stopNow);
-
- /**
- * @return A Map of ListenerProperties and the Listener object that is running in the controllers thread pool.
- */
- public Map getListeners();
-
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/EventHandler.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/EventHandler.java
deleted file mode 100644
index 9ec81b831..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/EventHandler.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
-/**
- * EventHandler defines a class that wraps DMaaP operations (most notably Get Message and Post Message) to make them
- * easier to use.
- *
- */
-public interface EventHandler {
-
- /**
- * Gets a list of messages as Strings on the read topic.
- *
- * @return A list of String messages. Never returns null.
- */
- public List getIncomingEvents();
-
- /**
- * Gets a list of messages as String on the read topic.
- *
- * @param limit
- * The maximum amount of entries to return
- * @return A list of String messages. Never returns null.
- */
- public List getIncomingEvents(int limit);
-
- /**
- * Gets a list of messages Mapped to the given Class. If a message cannot be mapped to that class, it is discarded.
- *
- * @param cls
- * The class to map the message to.
- * @return A list of objects of the provided class. Never returns null.
- */
- public List getIncomingEvents(Class cls);
-
- /**
- * Gets a list of messages Mapped to the given Class. If a message cannot be mapped to that class, it is discarded.
- *
- * @param cls
- * The class to map the message to.
- * @param limit
- * The maximum amount of entries to return
- * @return A list of objects of the provided class. Never returns null.
- */
- public List getIncomingEvents(Class cls, int limit);
-
- /**
- * Posts the String message to the write topic(s).
- *
- * @param event
- * The String to post.
- */
- public void postStatus(String event);
-
- /**
- * Posts the String message to the write topic(s) on the specified partition. Partitions are only used to guarantee
- * ordering and do not impact if data is retreived.
- *
- * @param partition
- * The partition to post to or null if no partition should be used.
- * @param event
- * The String to post.
- */
- public void postStatus(String partition, String event);
-
- /**
- * @return The client/group id used to read messages
- */
- public String getClientId();
-
- /**
- * Set the client/group id used to read messages
- *
- * @param clientId
- * The new clientId to use
- */
- public void setClientId(String clientId);
-
- /**
- * @return The client/group name to use.
- */
- public String getClientName();
-
- /**
- * Set the client/group name used to read messages.
- *
- * @param clientName
- * The new clientName to use
- */
- public void setClientName(String clientName);
-
- /**
- * @return The name of the topic to read from
- */
- public String getReadTopic();
-
- /**
- * Set the name of the topic to read from.
- *
- * @param topic
- * The new topic to read from
- */
- public void setReadTopic(String topic);
-
- /**
- * @return The name of the topic to write to
- */
- public Set getWriteTopics();
-
- /**
- * Set the name of the topic to write to
- *
- * @param topic
- * The new topic to write to
- */
- public void setWriteTopics(Set topic);
-
- /**
- * Adds a DMaaP host to the host pool
- *
- * @param host
- * The host to add to the pool in <host>:<port> format
- */
- public void addToPool(String host);
-
- /**
- * Remove the host name from the pool if it exists
- *
- * @param host
- * The host to add to the pool in <host>:<port> format
- */
- public void removeFromPool(String host);
-
- /**
- * Get all of the hosts in the DMaaP pool
- *
- * @return A collection of host in <host>:<port> format
- */
- public Collection getPool();
-
- /**
- * Clear any provided api credentials and make future requests as an unauthenticated user
- */
- public void clearCredentials();
-
- /**
- * Set the api credentials and make future requests as an authenticated user
- *
- * @param access
- * The access portion of the credentials (either user name or api key)
- * @param secret
- * The secret portion of the credentials (either password or api secret)
- */
- public void setCredentials(String access, String secret);
-
- /**
- * Close consumer/producer DMaaP clients
- */
- public void closeClients();
-
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/conv/Converter.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/conv/Converter.java
deleted file mode 100644
index 4cef18c87..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/conv/Converter.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.LCM.conv;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.*;
-import org.apache.commons.lang3.StringUtils;
-import org.json.JSONObject;
-import org.onap.appc.listener.LCM.model.DmaapMessage;
-import org.onap.appc.listener.LCM.model.DmaapOutgoingMessage;
-import org.onap.appc.listener.util.Mapper;
-
-public class Converter {
-
- public static DmaapOutgoingMessage convJsonNodeToDmaapOutgoingMessage(DmaapMessage event, JsonNode inObj) {
- DmaapOutgoingMessage outObj = new DmaapOutgoingMessage();
- outObj.setBody(inObj);
- outObj.setRpcName(event.getRpcName());
- outObj.setVersion(event.getVersion());
- outObj.setType("response");
- outObj.setCorrelationID(event.getCorrelationID());
- return outObj;
- }
-
- public static String convDmaapOutgoingMessageToJsonString(DmaapMessage inObj) throws JsonProcessingException {
-// return Mapper.toJsonString(inObj);
- ObjectMapper objectMapper = new ObjectMapper();
- ObjectWriter writer = objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL).configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY,true)
- .writer().withFeatures(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
- return writer.writeValueAsString(inObj);
-
- }
-
- public static DmaapOutgoingMessage buildDmaapOutgoingMessageWithUnexpectedError(DmaapMessage event,Exception inputException) {
- DmaapOutgoingMessage dmaapOutgoingMessage = null;
- String errMsg = StringUtils.isEmpty(inputException.getMessage())? inputException.toString() : inputException.getMessage();
- JSONObject commonHeaderJsonObject = Mapper.toJsonObject(event.getBody().get("input").get("common-header"));
- JSONObject jsonObjectOutput = new JSONObject().accumulate("common-header", commonHeaderJsonObject).accumulate("status", new JSONObject().accumulate("code",200).accumulate("value",errMsg));
- dmaapOutgoingMessage = new DmaapOutgoingMessage();
- dmaapOutgoingMessage.setRpcName(event.getRpcName());
- dmaapOutgoingMessage.setCorrelationID(event.getCorrelationID());
- dmaapOutgoingMessage.setType("error");
- dmaapOutgoingMessage.setVersion(event.getVersion());
- JSONObject jsonObjectBody = new JSONObject().accumulate("output",jsonObjectOutput);
- JsonNode jsonNodeBody = Mapper.toJsonNodeFromJsonString(jsonObjectBody.toString());
- dmaapOutgoingMessage.setBody(jsonNodeBody);
- return dmaapOutgoingMessage;
- }
-
- public static String extractRequestIdWithSubId(JsonNode dmaapBody) {
- //TODO: null pointer exception if dmaapBody is null, check if null or ensure is not null before calling
- JsonNode commonHeaderJsonNode = dmaapBody.get("input").get("common-header");
- String requestId = getValue(commonHeaderJsonNode,"request-id","");
- String subRequestId = getValue(commonHeaderJsonNode,"sub-request-id","");
- if(!StringUtils.isEmpty(subRequestId)){
- requestId = requestId +"-"+subRequestId;
- }
- return requestId;
- }
-
- public static Integer extractStatusCode(JsonNode event) {
- Integer statusCode;
- statusCode = event.get("output").get("status").get("code").asInt();
- return statusCode;
- }
-
- private static String getValue(JsonNode jsonNode,String name,String defaultValue){
- if(jsonNode == null){
- return defaultValue;
- }
- JsonNode childJsonNode = jsonNode.get(name);
- if(childJsonNode == null){
- return defaultValue;
- }
- String value = childJsonNode.asText();
- if(value == null){
- return defaultValue;
- }
- return value;
- }
-
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/impl/ListenerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/impl/ListenerImpl.java
deleted file mode 100644
index 41a6f92ee..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/impl/ListenerImpl.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.LCM.impl;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.appc.listener.AbstractListener;
-import org.onap.appc.listener.ListenerProperties;
-import org.onap.appc.listener.LCM.conv.Converter;
-import org.onap.appc.listener.LCM.model.DmaapIncomingMessage;
-import org.onap.appc.listener.LCM.operation.ProviderOperations;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.att.eelf.i18n.EELFResourceManager;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.TimeZone;
-import java.util.concurrent.RejectedExecutionException;
-
-public class ListenerImpl extends AbstractListener {
-
- private final EELFLogger LOG = EELFManager.getInstance().getLogger(ListenerImpl.class);
-
- private long startTime = 0;
-
- private final ProviderOperations providerOperations;
-
- public ListenerImpl(ListenerProperties props) {
- super(props);
-
- String url = props.getProperty("provider.url");
- LOG.info("DMaaP Provider Endpoint: " + url);
- providerOperations = new ProviderOperations();
- providerOperations.setUrl(url);
-
- // Set Basic Auth
- String user = props.getProperty("provider.user");
- String pass = props.getProperty("provider.pass");
- providerOperations.setAuthentication(user, pass);
- }
-
- @Override
- public void run() {
- // Some vars for benchmarking
- startTime = System.currentTimeMillis();
-
- LOG.info("Running DMaaP Listener");
-
- while (run.get()) {
- // Only update if the queue is low. otherwise we read in more
- // messages than we need
- try {
- if (executor.getQueue().size() <= QUEUED_MIN) {
- LOG.debug("DMaaP queue running low. Querying for more jobs");
-
-
- List messages = dmaap.getIncomingEvents(DmaapIncomingMessage.class, QUEUED_MAX);
- LOG.debug(String.format("Read %d messages from dmaap", messages.size()));
- for (DmaapIncomingMessage incoming : messages) {
- // Acknowledge that we read the event
- if (isValid(incoming)) {
- String requestIdWithSubId = getRequestIdWithSubId(incoming.getBody());
- LOG.info("Acknowledging Message: " + requestIdWithSubId);
- }
- }
- for (DmaapIncomingMessage incoming : messages) {
- String requestIdWithSubId = getRequestIdWithSubId(incoming.getBody());
- // Add to pool if still running
- if (run.get()) {
- if (isValid(incoming)) {
- LOG.info(String.format("Adding DMaaP message to pool queue [%s]", requestIdWithSubId));
- try {
- executor.execute(new WorkerImpl(incoming, dmaap, providerOperations));
- } catch (RejectedExecutionException rejectEx) {
- LOG.error("Task Rejected: ", rejectEx);
- }
- } else {
- // Badly formed message
- LOG.error("Message was not valid. Rejecting message: "+incoming);
- }
- } else {
- if (isValid(incoming)) {
- LOG.info("Run stopped. Orphaning Message: " + requestIdWithSubId);
- }
- else {
- // Badly formed message
- LOG.error("Message was not valid. Rejecting message: "+incoming);
- }
- }
- }
- }
- } catch (Exception e) {
- LOG.error("Exception " + e.getClass().getSimpleName() + " caught in DMaaP listener");
- LOG.error(EELFResourceManager.format(e));
- LOG.error("DMaaP Listener logging and ignoring the exception, continue...");
- }
- }
-
- LOG.info("Stopping DMaaP Listener thread");
-
- // We've told the listener to stop
- // TODO - Should we:
- // 1) Put a message back on the queue indicating that APP-C never got to
- // the message
- // or
- // 2) Let downstream figure it out after timeout between PENDING and
- // ACTIVE messages
- }
-
- private boolean isValid(DmaapIncomingMessage incoming) {
- return ((incoming != null) &&
- incoming.getBody() != null
- && !StringUtils.isEmpty(incoming.getRpcName()));
- }
-
- @Override
- public String getBenchmark() {
- long time = System.currentTimeMillis();
- DateFormat df = new SimpleDateFormat("HH:mm:ss");
- df.setTimeZone(TimeZone.getTimeZone("UTC"));
- String runningTime = df.format(new Date(time - startTime));
-
- String out = String.format("Running for %s and completed %d jobs using %d threads.", runningTime,
- executor.getCompletedTaskCount(), executor.getPoolSize());
- LOG.info("***BENCHMARK*** " + out);
- return out;
- }
-
- private String getRequestIdWithSubId(JsonNode event){
- String requestId = "";
- try {
- requestId = Converter.extractRequestIdWithSubId(event);
- } catch (Exception e) {
- LOG.error("failed to parse request-id and sub-request-id. Json not in expected format", e);
- }
- return requestId;
- }
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/impl/WorkerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/impl/WorkerImpl.java
deleted file mode 100644
index 9334a8fad..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/impl/WorkerImpl.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.LCM.impl;
-
-import org.onap.appc.exceptions.APPCException;
-import org.onap.appc.listener.EventHandler;
-import org.onap.appc.listener.LCM.conv.Converter;
-import org.onap.appc.listener.LCM.model.DmaapMessage;
-import org.onap.appc.listener.LCM.model.DmaapOutgoingMessage;
-import org.onap.appc.listener.LCM.operation.ProviderOperations;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-
-public class WorkerImpl implements Runnable {
-
- private final EELFLogger LOG = EELFManager.getInstance().getLogger(WorkerImpl.class);
-
- // Should have all of the data we need for processing
- private DmaapMessage event;
-
- // So we can post messages from inside the worker.
- private EventHandler dmaap;
-
- //so we know were to post the messages
- private final ProviderOperations providerOperations;
-
-
- public WorkerImpl(DmaapMessage message, EventHandler dmaap, ProviderOperations providerOperations) {
- this.event = message;
- this.dmaap = dmaap;
- this.providerOperations = providerOperations;
- }
-
- @Override
- public void run() {
- String requestIdWithSubId = extractRequestIdWithSubId(event.getBody());
- LOG.debug(String.format("Started working on %s", requestIdWithSubId));
-
- // Run the dg in a try catch to handle all exceptions and update the
- // message at the end
- try {
- JsonNode outputJsonNode = doDG(event.getRpcName(), event.getBody());
- DmaapOutgoingMessage dmaapOutgoingMessage= Converter.convJsonNodeToDmaapOutgoingMessage(event, outputJsonNode);
- postMessageToDMaaP(dmaapOutgoingMessage,requestIdWithSubId);
- Integer statusCode = extractStatusCode(dmaapOutgoingMessage.getBody());
- if (ProviderOperations.isSucceeded(statusCode)) {
- LOG.debug(String.format("Event %s finished successfully", requestIdWithSubId));
- } else {
- LOG.warn(String.format("Event %s failed", requestIdWithSubId));
- }
-
- } catch (Exception e) {
- // Unknown exception from DG method. Fail and pass the exception
- // along
- String msg = "Exception: " + e.getMessage();
- LOG.error(String.format("Event %s finished with failure. %s", requestIdWithSubId, msg));
- DmaapOutgoingMessage dmaapOutgoingMessage= Converter.buildDmaapOutgoingMessageWithUnexpectedError(event, e);
- postMessageToDMaaP(dmaapOutgoingMessage,requestIdWithSubId);
- }
-
- LOG.debug("Done working on " + requestIdWithSubId);
- }
-
-
- private Integer extractStatusCode(JsonNode event) {
- Integer statusCode = null;
- try {
- statusCode = Converter.extractStatusCode(event);
- } catch (Exception e) {
- LOG.error("failed to parse statusCode. Json not in expected format", e);
- }
- return statusCode;
- }
-
-
- private String extractRequestIdWithSubId(JsonNode event){
- String requestId = "";
- try {
- requestId = Converter.extractRequestIdWithSubId(event);
- } catch (Exception e) {
- LOG.error("failed to parse request-id and sub-request-id. Json not in expected format", e);
- }
- return requestId;
- }
-
-
-
- private void postMessageToDMaaP(DmaapOutgoingMessage dmaapOutgoingMessage,String requestIdWithSubId) {
- String dmaapOutgoingMessageJsonString;
- try {
- dmaapOutgoingMessageJsonString = Converter.convDmaapOutgoingMessageToJsonString(dmaapOutgoingMessage);
- dmaap.postStatus(dmaapOutgoingMessage.getCambriaPartition(),dmaapOutgoingMessageJsonString);
- } catch (JsonProcessingException e) {
- LOG.error("failed to postMessageToDMaaP requestIdWithSubId: "+requestIdWithSubId+" dmaapOutgoingMessage: "+dmaapOutgoingMessage, e);
- }
- }
-
- private JsonNode doDG(String rpcName, JsonNode msg) throws APPCException {
- return providerOperations.topologyDG(rpcName,msg);
- }
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/ActionIdentifiers.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/ActionIdentifiers.java
deleted file mode 100644
index 2419bed65..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/ActionIdentifiers.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.LCM.model;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import java.io.Serializable;
-
-
-public class ActionIdentifiers implements Serializable {
-
- @JsonProperty("service-instance-id")
- private String serviceInstanceId;
- @JsonProperty("vnf-id")
- private String vnfID;
- @JsonProperty("vnfc-name")
- private String vnfcName;
- @JsonProperty("vserver-id")
- private String vserverId;
-
- public ActionIdentifiers() {
- }
-
- public ActionIdentifiers(ActionIdentifiers actionIdentifiers) {
- this.serviceInstanceId=actionIdentifiers.getServiceInstanceId();
- this.vnfID=actionIdentifiers.getVnfID();
- this.vnfcName=actionIdentifiers.getVnfcName();
- this.vserverId=actionIdentifiers.getVserverId();
- }
-
- public String getServiceInstanceId() {
- return serviceInstanceId;
- }
-
- public void setServiceInstanceId(String serviceInstanceId) {
- this.serviceInstanceId = serviceInstanceId;
- }
-
- public String getVnfID() {
- return vnfID;
- }
-
- public void setVnfID(String vnfID) {
- this.vnfID = vnfID;
- }
-
- public String getVnfcName() {
- return vnfcName;
- }
-
- public void setVnfcName(String vnfcName) {
- this.vnfcName = vnfcName;
- }
-
- public String getVserverId() {
- return vserverId;
- }
-
- public void setVserverId(String vserverId) {
- this.vserverId = vserverId;
- }
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/CommonHeader.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/CommonHeader.java
deleted file mode 100644
index b7dcc1bb7..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/CommonHeader.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.LCM.model;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import java.io.Serializable;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Map;
-
-import org.onap.appc.util.Time;
-
-public class CommonHeader implements Serializable {
- @JsonProperty("timestamp")
- private String timeStamp;
- @JsonProperty("api-ver")
- private String apiVer;
- @JsonProperty("originator-id")
- private String originatorId;
- @JsonProperty("request-id")
- private String requestID;
- @JsonProperty("sub-request-id")
- private String subRequestId;
- @JsonProperty("flags")
- private Map flags;
-
- private static final DateFormat ZULU_FORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'");
-
- public CommonHeader() {
- }
-
- public CommonHeader(CommonHeader commonHeader) {
- // changed to current system time
- timeStamp = ZULU_FORMATTER.format(Time.utcDate());
-
- apiVer = commonHeader.getApiVer();
- originatorId = commonHeader.getOriginatorId();
- requestID = commonHeader.getRequestID();
- subRequestId = commonHeader.getSubRequestId();
- flags = commonHeader.getFlags();
- }
-
-
-
- public String getTimeStamp() {
- return timeStamp;
- }
-
- public void setTimeStamp(String timeStamp) {
- this.timeStamp = timeStamp;
- }
-
- public String getApiVer() {
- return apiVer;
- }
-
- public void setApiVer(String apiVer) {
- this.apiVer = apiVer;
- }
-
- public String getRequestID() {
- return requestID;
- }
-
- public void setRequestID(String requestID) {
- this.requestID = requestID;
- }
-
- public String getOriginatorId() {
- return originatorId;
- }
-
- public void setOriginatorId(String originatorId) {
- this.originatorId = originatorId;
- }
-
- public String getSubRequestId() {
- return subRequestId;
- }
-
- public void setSubRequestId(String subRequestId) {
- this.subRequestId = subRequestId;
- }
-
- public Map getFlags() {
- return flags;
- }
-
- public void setFlags(Map flags) {
- this.flags = flags;
- }
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/DmaapIncomingMessage.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/DmaapIncomingMessage.java
deleted file mode 100644
index 32b70d100..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/DmaapIncomingMessage.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.LCM.model;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import org.json.JSONObject;
-import org.onap.appc.listener.util.Mapper;
-
-/**
- * This class represents a message being sent out to DMaaP by APPC to update listeners on the status of a request
- *
- */
-@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class DmaapIncomingMessage extends DmaapMessage{
- private final static String defaultCambriaPartition = "APP-C";
-
- public DmaapIncomingMessage() {
- super();
- setCambriaPartition(defaultCambriaPartition);
- }
-
-
- @Override
- public String toString() {
- return "DmaapIncomingMessage{"+super.toString()+"}";
- }
-}
-
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/DmaapMessage.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/DmaapMessage.java
deleted file mode 100644
index 214783d10..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/DmaapMessage.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.LCM.model;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.databind.JsonNode;
-
-
-@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class DmaapMessage{
-
- @JsonProperty("version")
- private String version;
-
- @JsonProperty("type")
- private String type;
-
- @JsonProperty("correlation-id")
- private String correlationID;
-
- @JsonProperty("cambria.partition")
- private String cambriaPartition;
-
- @JsonProperty("rpc-name")
- private String rpcName;
-
- @JsonProperty("body")
- private JsonNode body;
-
- public DmaapMessage() {
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getCorrelationID() {
- return correlationID;
- }
-
- public void setCorrelationID(String correlationID) {
- this.correlationID = correlationID;
- }
-
- public String getCambriaPartition() {
- return cambriaPartition;
- }
-
- public void setCambriaPartition(String cambriaPartition) {
- this.cambriaPartition = cambriaPartition;
- }
-
- public String getRpcName() {
- return rpcName;
- }
-
- public void setRpcName(String rpcName) {
- this.rpcName = rpcName;
- }
-
- public JsonNode getBody() {
- return body;
- }
-
- public void setBody(JsonNode body) {
- this.body = body;
- }
-
- @Override
- public String toString() {
- return "DmaapMessage{" +
- "version='" + version + '\'' +
- ", type='" + type + '\'' +
- ", correlationId='" + correlationID + '\'' +
- ", cambriaPartition='" + cambriaPartition + '\'' +
- ", rpcName='" + rpcName + '\'' +
- ", body=" + body +
- '}';
- }
-
-}
-
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/DmaapOutgoingMessage.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/DmaapOutgoingMessage.java
deleted file mode 100644
index acf4461aa..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/DmaapOutgoingMessage.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.LCM.model;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import org.json.JSONObject;
-import org.onap.appc.listener.util.Mapper;
-
-/**
- * This class represents a message being sent out to DMaaP by APPC to update listeners on the status of a request
- *
- */
-@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class DmaapOutgoingMessage extends DmaapMessage{
- private final static String defaultCambriaPartition = "MSO";
-
- public DmaapOutgoingMessage() {
- super();
- setCambriaPartition(defaultCambriaPartition);
- }
-
-
- @Override
- public String toString() {
- return "DmaapOutgoingMessage{"+super.toString()+"}";
- }
-}
-
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/InputBody.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/InputBody.java
deleted file mode 100644
index 85aed42d8..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/InputBody.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.LCM.model;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
-@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class InputBody {
-
- @JsonProperty("common-header")
- private CommonHeader commonHeader;
-
- @JsonProperty("action-identifiers")
- private ActionIdentifiers actionIdentifiers;
-
- @JsonProperty("action")
- private String action;
-
- @JsonProperty("payload")
- private Object payload;
-
-
- public Object getPayload() {
- return payload;
- }
-
- public void setPayload(Object payload) {
- this.payload = payload;
- }
- @JsonIgnore
- public void setPayloadAsString(String payload) {
- this.payload = payload;
- }
-
- public String getAction() {
- return action;
- }
-
- public void setAction(String action) {
- this.action = action;
- }
-
- public ActionIdentifiers getActionIdentifiers() {
- return actionIdentifiers;
- }
-
- public void setActionIdentifiers(ActionIdentifiers actionIdentifiers) {
- this.actionIdentifiers = actionIdentifiers;
- }
-
- public CommonHeader getCommonHeader() {
- return commonHeader;
- }
-
- public void setCommonHeader(CommonHeader commonHeader) {
- this.commonHeader = commonHeader;
- }
-
- @JsonIgnore
- public boolean isValid() {
- return getCommonHeader() != null;
- }
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/OutputBody.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/OutputBody.java
deleted file mode 100644
index 11714e8fb..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/OutputBody.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.LCM.model;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import org.json.JSONObject;
-import org.onap.appc.listener.util.Mapper;
-
-/**
- * This class represents a message being sent out to DMaaP by APPC to update listeners on the status of a request
- *
- */
-@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class OutputBody {
-
- @JsonProperty("common-header")
- private CommonHeader header;
-
- @JsonProperty("status")
- private ResponseStatus status;
-
- @JsonProperty("payload")
- private String payload;
-
- @JsonProperty("locked")
- private String locked;
-
- public OutputBody() {
- }
-
-
- public JSONObject toResponse() {
- return Mapper.toJsonObject(this);
- }
-
- public OutputBody(InputBody msg) {
- this.header = new CommonHeader(msg.getCommonHeader());
- }
-
- public String getLocked() {
- return locked;
- }
-
- public void setLocked(String locked) {
- this.locked = locked;
- }
- public String getPayload() {
- return payload;
- }
-
- public void setPayload(String payload) {
- this.payload = payload;
- }
-
- public CommonHeader getHeader() {
- return header;
- }
-
- public void setHeader(CommonHeader header) {
- this.header = header;
- }
-
- public ResponseStatus getStatus() {
- return status;
- }
-
- public void setStatus(ResponseStatus status) {
- this.status = status;
- }
-
- @Override
- public String toString() {
- return String.format("%s - %s(%s)", getHeader().getRequestID(), getStatus().getCode(), getStatus().getValue());
- }
-}
-
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/ResponseStatus.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/ResponseStatus.java
deleted file mode 100644
index 114b97b35..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/model/ResponseStatus.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.LCM.model;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
-
-@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class ResponseStatus {
- @JsonProperty("code")
- private Integer code;
- @JsonProperty("message")
- private String value;
-
- public ResponseStatus() {
- }
-
- public ResponseStatus(Integer code, String value) {
- this.code = code;
- this.value = value;
- }
-
- public Integer getCode() {
- return code;
- }
-
- public void setCode(Integer code) {
- code = code;
- }
-
- public String getValue() {
- return value;
- }
-
-
-
- public void setValue(String value) {
- value = value;
- }
-
- @Override
- public String toString() {
- return "ResponseStatus{" +
- "code=" + code +
- ", value='" + value + '\'' +
- '}';
- }
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/operation/GenericProviderOperationRequestFormatter.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/operation/GenericProviderOperationRequestFormatter.java
deleted file mode 100644
index 8fbe4af24..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/operation/GenericProviderOperationRequestFormatter.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.LCM.operation;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import org.json.JSONObject;
-import org.onap.appc.exceptions.APPCException;
-import org.onap.appc.listener.LCM.model.InputBody;
-import org.onap.appc.listener.LCM.model.ResponseStatus;
-import org.onap.appc.listener.util.Mapper;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
-import java.net.URL;
-
-public class GenericProviderOperationRequestFormatter implements ProviderOperationRequestFormatter {
-
- private final EELFLogger LOG = EELFManager.getInstance().getLogger(GenericProviderOperationRequestFormatter.class);
-
- //@formatter:off
- @SuppressWarnings("nls")
- private final static String TEMPLATE = "{\"input\": %s}";
- //@formatter:on
-
- @Override
- public String buildPath(URL url, String rpcName) {
- return url.getPath() + ":"+rpcName;
- }
-
- @Override
- public String buildRequest(InputBody msg) {
- JSONObject jsonObject = Mapper.toJsonObject(msg);
- return String.format(TEMPLATE, jsonObject.toString());
- }
-
- @Override
- public ResponseStatus getResponseStatus(JsonNode responseBody)throws APPCException{
- try {
- JsonNode status = responseBody.get("output").get("status");
- return new ResponseStatus(status.get("code").asInt(), status.get("message").asText());
- } catch (Exception e) {
- LOG.error("Unknown error processing failed response from provider. Json not in expected format", e);
- throw new APPCException("APPC has an unknown RPC error");
- }
- }
-
- @Override
- public String getLocked(JSONObject responseBody) throws APPCException {
- try {
- JSONObject outputObject=responseBody.getJSONObject("output");
- if(outputObject.has("locked")){
- return outputObject.getString("locked");
- }else{
- return null;
- }
- } catch (Exception e) {
- LOG.error("Unknown error processing failed response from provider. Json not in expected format", e);
- throw new APPCException("APPC has an unknown RPC error");
- }
- }
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/operation/ProviderOperationRequestFormatter.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/operation/ProviderOperationRequestFormatter.java
deleted file mode 100644
index 1e9909a1f..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/operation/ProviderOperationRequestFormatter.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.LCM.operation;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import org.json.JSONObject;
-import org.onap.appc.exceptions.APPCException;
-import org.onap.appc.listener.LCM.model.InputBody;
-import org.onap.appc.listener.LCM.model.ResponseStatus;
-
-import java.net.URL;
-
-
-public interface ProviderOperationRequestFormatter {
-
- String buildPath(URL url, String rpcName);
-
- String buildRequest(InputBody msg);
-
- ResponseStatus getResponseStatus(JsonNode json)throws APPCException;
-
- String getLocked(JSONObject json)throws APPCException;
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/operation/ProviderOperations.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/operation/ProviderOperations.java
deleted file mode 100644
index d3ac83d1b..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/LCM/operation/ProviderOperations.java
+++ /dev/null
@@ -1,263 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.LCM.operation;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.IOUtils;
-import org.apache.http.HttpHeaders;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpVersion;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.scheme.PlainSocketFactory;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.ssl.SSLSocketFactory;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpProtocolParams;
-import org.apache.http.protocol.HTTP;
-import org.onap.appc.exceptions.APPCException;
-import org.onap.appc.listener.LCM.model.ResponseStatus;
-import org.onap.appc.listener.util.Mapper;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.Socket;
-import java.net.URL;
-import java.net.UnknownHostException;
-import java.security.*;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-
-public class ProviderOperations {
-
- private static final EELFLogger LOG = EELFManager.getInstance().getLogger(ProviderOperations.class);
-
- private URL url;
- private String basic_auth;
-
- private static ProviderOperationRequestFormatter requestFormatter = new GenericProviderOperationRequestFormatter();
-
- /**
- * Calls the AppcProvider to run a topology directed graph
- *
- * @param msg The incoming message to be run
- * @return True if the result is success. Never returns false and throws an exception instead.
- * @throws UnsupportedEncodingException
- * @throws Exception if there was a failure processing the request. The exception message is the failure reason.
- */
- @SuppressWarnings("nls")
- public JsonNode topologyDG(String rpcName, JsonNode msg) throws APPCException {
- if (msg == null) {
- throw new APPCException("Provided message was null");
- }
-
- HttpPost post = null;
- try {
-
- // Concatenate the "action" on the end of the URL
- String path = requestFormatter.buildPath(url, rpcName);
- URL serviceUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
-
- post = new HttpPost(serviceUrl.toExternalForm());
- post.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
- post.setHeader(HttpHeaders.ACCEPT, "application/json");
-
- // Set Auth
- if (basic_auth != null) {
- post.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + basic_auth);
- }
-
- String body = Mapper.toJsonString(msg);
- StringEntity entity = new StringEntity(body);
- entity.setContentType("application/json");
- post.setEntity(new StringEntity(body));
- } catch (UnsupportedEncodingException | MalformedURLException e) {
- throw new APPCException(e);
- }
-
- HttpClient client = getHttpClient();
-
- int httpCode = 0;
- String respBody = null;
- try {
- HttpResponse response = client.execute(post);
- httpCode = response.getStatusLine().getStatusCode();
- respBody = IOUtils.toString(response.getEntity().getContent());
- } catch (IOException e) {
- throw new APPCException(e);
- }
-
- if (httpCode >= 200 && httpCode < 300 && respBody != null) {
- JsonNode json;
- try {
- json = Mapper.toJsonNodeFromJsonString(respBody);
- } catch (Exception e) {
- LOG.error("Error processing response from provider. Could not map response to json", e);
- throw new APPCException("APPC has an unknown RPC error");
- }
-
- ResponseStatus responseStatus = requestFormatter.getResponseStatus(json);
-
- if (!isSucceeded(responseStatus.getCode())) {
- LOG.warn(String.format("Operation failed [%s]", msg.toString()));
- }
-
- return json;
- }
-
- throw new APPCException(String.format("Unexpected response from endpoint: [%d] - %s ", httpCode, respBody));
- }
-
- /**
- * Updates the static var URL and returns the value;
- *
- * @return The new value of URL
- */
- public String getUrl() {
- return url.toExternalForm();
- }
-
- public void setUrl(String newUrl) {
- try {
- url = new URL(newUrl);
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Sets the basic authentication header for the given user and password. If either entry is null then set basic auth
- * to null
- *
- * @param user The user with optional domain name
- * @param password The password for the user
- * @return The new value of the basic auth string that will be used in the request headers
- */
- public String setAuthentication(String user, String password) {
- if (user != null && password != null) {
- String authStr = user + ":" + password;
- basic_auth = new String(Base64.encodeBase64(authStr.getBytes()));
- } else {
- basic_auth = null;
- }
- return basic_auth;
- }
-
- @SuppressWarnings("deprecation")
- private HttpClient getHttpClient() throws APPCException {
- HttpClient client;
- if (url.getProtocol().equals("https")) {
- try {
- KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
- trustStore.load(null, null);
- MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
- sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
-
- HttpParams params = new BasicHttpParams();
- HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
- HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
-
- SchemeRegistry registry = new SchemeRegistry();
- registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
- registry.register(new Scheme("https", sf, 443));
- registry.register(new Scheme("https", sf, 8443));
- registry.register(new Scheme("http", sf, 8181));
-
- ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
- client = new DefaultHttpClient(ccm, params);
- } catch (Exception e) {
- client = new DefaultHttpClient();
- }
- } else if (url.getProtocol().equals("http")) {
- client = new DefaultHttpClient();
- } else {
- throw new APPCException(
- "The provider.topology.url property is invalid. The url did not start with http[s]");
- }
- return client;
- }
-
- @SuppressWarnings("deprecation")
- public static class MySSLSocketFactory extends SSLSocketFactory {
- private SSLContext sslContext = SSLContext.getInstance("TLS");
-
- public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException,
- KeyStoreException, UnrecoverableKeyException {
- super(truststore);
-
- TrustManager tm = new X509TrustManager() {
- @Override
- public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- }
-
- @Override
- public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- }
-
- @Override
- public X509Certificate[] getAcceptedIssuers() {
- return null;
- }
- };
-
- sslContext.init(null, new TrustManager[]{
- tm
- }, null);
- }
-
- @Override
- public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
- throws IOException, UnknownHostException {
- return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
- }
-
- @Override
- public Socket createSocket() throws IOException {
- return sslContext.getSocketFactory().createSocket();
- }
- }
-
- public static boolean isSucceeded(Integer code) {
- if (code == null) {
- return false;
- }
- return ((code == 100) || (code == 400)); // only 100 & 400 statuses are success
- }
-
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/Listener.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/Listener.java
deleted file mode 100644
index 50589c89d..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/Listener.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener;
-
-/**
- * This interface defines a listener that subscribes to a DMaaP topic and continually polls for messages. The
- * listener does all operations in the run() method and long running operations should be created in a separate worker
- * thread.
- *
- */
-public interface Listener extends Runnable {
-
- /**
- * Should start a continuous poll to get messages from the message bus only ending when stop() or stopNow() are
- * called.
- *
- * @see java.lang.Runnable#run()
- */
- @Override
- public void run();
-
- /**
- * Signals the listener to stop accepting new messages to the queue and to cleanly finish processing all remaining
- * messages in the queue. This can take a significant amount of time to complete depending on the thread pool
- * characteristics. Similar to {@link #stopNow()}
- */
- public void stop();
-
- /**
- * Signals the listener to stop accepting new messages to the queue and to destroy all remaining messages in the
- * queue. This will complete quicker than {@link #stop()} at the cost of discarded requests. Recovery of these
- * requests would have to be caught downstream. Similar to {@link #stop()}
- */
- public void stopNow();
-
- /**
- * @return A string that shows various benchmarking data. Can be used by humans to tune the thread pool.
- */
- public String getBenchmark();
-
- /**
- * @return The listener's id when requesting messages from DMaaP. Also known as the group id.
- */
- public String getListenerId();
-
- /**
- * Sets the listener's id to use when requesting messages from DMaaP. Also known as the group id.
- *
- * @param idString
- * The new listener id
- */
- public void setListenerId(String idString);
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/ListenerProperties.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/ListenerProperties.java
deleted file mode 100644
index 7908d3a1b..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/ListenerProperties.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener;
-
-import java.util.Properties;
-
-/**
- * A class for instantiating Listener objects. It is primarily used to hold properties that start with the given prefix.
- * It also holds a class that implements {@see Listener} and will be used by the controller to spawn a new listener
- * object.
- *
- * @since Apr 25, 2016
- * @version $Id$
- */
-public class ListenerProperties {
-
- private String prefix;
-
- private Class extends Listener> listenerClass;
-
- private Properties props;
-
- /**
- * Creates a new listener object with the given prefix and properties. Any property starting with the prefix is
- * added to the internal properties object with the prefix removed. All other properties are ignored.
- * ListenerProperties constructor
- *
- * @param prefix
- * The prefix of the properties to load
- * @param allProps
- * The properties object to load from.
- */
- public ListenerProperties(String prefix, Properties allProps) {
- this.prefix = prefix;
- props = new Properties();
-
- String dottedPrefix = String.format("%s.", prefix);
- for (String key : allProps.stringPropertyNames()) {
- if (key.startsWith(dottedPrefix) && key.length() > dottedPrefix.length()) {
- props.put(key.substring(dottedPrefix.length()), allProps.get(key));
- }
- }
- }
-
- /**
- * @return The prefix of these properties
- */
- public String getPrefix() {
- return prefix;
- }
-
- /**
- * Sets the listener class. Will be used by {@see Controller} to instantiate the Listener thread for this object
- *
- * @param cls
- * The class to be created. Implements {@see Listener}
- */
- public void setListenerClass(Class extends Listener> cls) {
- this.listenerClass = cls;
- }
-
- /**
- * @return The class that will be used by {@see Controller} to instantiate the Listener thread for this object
- */
- public Class extends Listener> getListenerClass() {
- return listenerClass;
- }
-
- /**
- * Returns a property matching a given KEYS
- *
- * @param key
- * The KEYS object who's value to return.
- * @return The value of the property or null if none exists
- */
- public String getProperty(KEYS key) {
- return getProperty(key, null);
- }
-
- /**
- * Returns a property matching a given string.
- *
- * @param key
- * The key who's value to return.
- * @return The value of the property or null if none exists
- */
- public String getProperty(String key) {
- return getProperty(key, null);
- }
-
- /**
- * Returns a property matching a given KEYS
- *
- * @param key
- * The KEYS object who's value to return.
- * @param defaultValue
- * The value to return if the property is not found
- * @return The value of the property or null if none exists
- */
- public String getProperty(KEYS key, String defaultValue) {
- return getProperty(key.getPropertySuffix(), defaultValue);
- }
-
- /**
- * Returns a property matching a given string.
- *
- * @param key
- * The key who's value to return.
- * @param defaultValue
- * The value to return if the property is not found
- * @return The value of the property or null if none exists
- */
- public String getProperty(String key, String defaultValue) {
- return props.getProperty(key, defaultValue);
- }
-
- /**
- * @return The properties object containing all properties
- */
- public Properties getProperties() {
- return props;
- }
-
- /**
- * Reads the prefix.disabled property to determine if the listener is disabled and should not be run by the
- * controller. Defaults to false if property not set or value cannot be parsed.
- *
- * @return true if the listener is disabled and should not be started. false if the listener should be start
- * normally (default).
- */
- public boolean isDisabled() {
- return Boolean.valueOf(getProperty(KEYS.DISABLED, "false"));
- }
-
- @Override
- public String toString() {
- return String.format("%s", prefix);
- }
-
-
- /**
- * Set of common properties that will be used by most systems. Primarily relating to DMaaP and ThreadPools
- *
- * @since Apr 25, 2016
- * @version $Id$
- */
- public enum KEYS {
- /**
- * Property to determine if the listener should be disabled. If not set, defaults to false
- */
- DISABLED("disabled"),
-
- /**
- * Property for the message service type. Should be a lower case string. See MessageService.
- */
- MESSAGE_SERVICE("service"),
-
- /**
- * A hostname or comma separated list (no spaces) of hostnames of servers in a cluster. Can have ports included
- * as well.
- * Examples:
- *
- * - server1.appc.openecomp.org
- * - server1.appc.openecomp.org:3904
- * - server1.appc.openecomp.org,server2.appc.openecomp.org
- *
- */
- HOSTS("poolMembers"),
-
- /**
- * The topic that will be used for DMaaP read operations. Can only support a single topic.
- */
- TOPIC_READ("topic.read"),
-
- /**
- * The topic or topics that will be used to write to. If multiple topics are provided, should be in a comma
- * seperated list with no spaces.
- * Examples:
- *
- * - TOPIC-1
- * - TOPIC-1,TOPIC-2,ANOTHER-TOPIC
- *
- */
- TOPIC_WRITE("topic.write"),
-
- /**
- * The highland park filter to use on read requests. If you are reading and writing to the same topic this must
- * be provided. Filter should be in JSON format (not url escaped).
- */
- TOPIC_READ_FILTER("topic.read.filter"),
-
- /**
- * The amount of time in seconds that the DMaaP polling connection should stay open for. Recommended to be set
- * high (around 60 seconds) as most clients will return immediately and not wait until the timeout is up to
- * return if they have data.
- */
- TOPIC_READ_TIMEOUT("topic.read.timeout"),
-
- /**
- * The name of the client to use. Should be unique to the application.
- */
- CLIENT_NAME("client.name"),
-
- /**
- * The id of the client to use. Should be unique for each instance of the application in an environment.
- */
- CLIENT_ID("client.name.id"),
-
- /**
- * The User (DMaaP) to use for authentication. If a user is provided, you must include the
- * domain name (e.g. example@example.com).
- */
- AUTH_USER_KEY("client.key"),
-
- /**
- * The password (DMaaP) to use for authentication.
- */
- AUTH_SECRET_KEY("client.secret"),
-
- /**
- * The minimum amount of size of the queue. A client should request new messages once the queue has dropped
- * below this size.
- */
- THREADS_MIN_QUEUE("threads.queuesize.min"),
-
- /**
- * The maximum size of the queue. A client will request no new messages once this maximum size has been reached.
- */
- THREADS_MAX_QUEUE("threads.queuesize.max"),
-
- /**
- * The minimum size of the worker threads pool. This is the pool each listener will use to launch longer running
- * operations.
- */
- THREADS_MIN_POOL("threads.poolsize.min"),
-
- /**
- * The maximum size of the worker threads pool. This is the pool each listener will use to launch longer running
- * operations.
- */
- THREADS_MAX_POOL("threads.poolsize.max");
-
- private String suffix;
-
- private KEYS(String val) {
- this.suffix = val;
- }
-
- /**
- * @param prefix
- * The prefix to prepend
- * @return a fully property name that corroponds to what is used in the properties file. Format is PREFIX.KEY
- */
- public String getFullProp(String prefix) {
- return String.format("%s.%s", prefix, suffix);
- }
-
- public String getPropertySuffix() {
- return suffix;
- }
- }
-
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/impl/ListenerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/impl/ListenerImpl.java
deleted file mode 100644
index c7599dd1a..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/impl/ListenerImpl.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.demo.impl;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.TimeZone;
-import java.util.concurrent.RejectedExecutionException;
-
-import org.onap.appc.listener.AbstractListener;
-import org.onap.appc.listener.ListenerProperties;
-import org.onap.appc.listener.demo.model.IncomingMessage;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.att.eelf.i18n.EELFResourceManager;
-
-public class ListenerImpl extends AbstractListener {
-
- private final EELFLogger LOG = EELFManager.getInstance().getLogger(ListenerImpl.class);
-
- private long startTime = 0;
-
- public ListenerImpl(ListenerProperties props) {
- super(props);
- String url = props.getProperty("provider.url");
- LOG.info("DMaaP Provider Endpoint: " + url);
- ProviderOperations.setUrl(url);
-
- // Set Basic Auth
- String user = props.getProperty("provider.user");
- String pass = props.getProperty("provider.pass");
- ProviderOperations.setAuthentication(user, pass);
- }
-
- @Override
- public void run() {
- // Some vars for benchmarking
- startTime = System.currentTimeMillis();
-
- LOG.info("Running DMaaP Listener");
-
- while (run.get()) {
- // Only update if the queue is low. otherwise we read in more
- // messages than we need
- try {
- if (executor.getQueue().size() <= QUEUED_MIN) {
- LOG.debug("DMaaP queue running low. Querying for more jobs");
- List messages = dmaap.getIncomingEvents(IncomingMessage.class, QUEUED_MAX);
- LOG.debug(String.format("Read %d messages from dmaap", messages.size()));
- for (IncomingMessage incoming : messages) {
- // Acknowledge that we read the event
- LOG.info("Acknowledging Message: " + incoming.getHeader().getRequestID());
-
- //TODO: Should we post a pending status for 1607
- //dmaap.postStatus(incoming.toOutgoing(Status.PENDING, null).toString());
- }
- for (IncomingMessage incoming : messages) {
- // Add to pool if still running
- if (run.get()) {
- LOG.info(String.format("Adding DMaaP message to pool queue [%s]", incoming.getHeader().getRequestID()));
- if (incoming.isValid()) {
- try {
- executor.execute(new WorkerImpl(incoming, dmaap));
- } catch (RejectedExecutionException rejectEx) {
- LOG.error("Task Rejected: ", rejectEx);
- }
- } else {
- // Badly formed message
- LOG.error("Message was not valid. Rejecting");
- }
- } else {
- LOG.info("Run stopped. Orphaning Message: " + incoming.getHeader().getRequestID());
- }
- }
- }
- } catch (Exception e) {
- LOG.error("Exception " + e.getClass().getSimpleName() + " caught in DMaaP listener");
- LOG.error(EELFResourceManager.format(e));
- LOG.error("DMaaP Listener logging and ignoring the exception, continue...");
- }
- }
-
- LOG.info("Stopping DMaaP Listener thread");
-
- // We've told the listener to stop
- // TODO - Should we:
- // 1) Put a message back on the queue indicating that APP-C never got to
- // the message
- // or
- // 2) Let downstream figure it out after timeout between PENDING and
- // ACTIVE messages
- }
-
- @Override
- public String getBenchmark() {
- long time = System.currentTimeMillis();
- DateFormat df = new SimpleDateFormat("HH:mm:ss");
- df.setTimeZone(TimeZone.getTimeZone("UTC"));
- String runningTime = df.format(new Date(time - startTime));
-
- String out = String.format("Running for %s and completed %d jobs using %d threads.", runningTime,
- executor.getCompletedTaskCount(), executor.getPoolSize());
- LOG.info("***BENCHMARK*** " + out);
- return out;
- }
-
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/impl/ProviderOperations.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/impl/ProviderOperations.java
deleted file mode 100644
index 9337edfbf..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/impl/ProviderOperations.java
+++ /dev/null
@@ -1,294 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.demo.impl;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.Socket;
-import java.net.URL;
-import java.net.UnknownHostException;
-import java.security.KeyManagementException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.IOUtils;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpVersion;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.scheme.PlainSocketFactory;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.ssl.SSLSocketFactory;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpProtocolParams;
-import org.apache.http.protocol.HTTP;
-import org.json.JSONObject;
-import org.onap.appc.exceptions.APPCException;
-import org.onap.appc.listener.demo.model.IncomingMessage;
-import org.onap.appc.listener.util.Mapper;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
-public class ProviderOperations {
-
- private static final EELFLogger LOG = EELFManager.getInstance().getLogger(ProviderOperations.class);
-
- private static URL url;
-
- private static String basic_auth;
-
- //@formatter:off
- @SuppressWarnings("nls")
- private final static String TEMPLATE = "{\"input\": {\"common-request-header\": {\"service-request-id\": \"%s\"},\"config-payload\": {\"config-url\": \"%s\",\"config-json\":\"%s\"}}}";
- //@formatter:on
-
- /**
- * Calls the AppcProvider to run a topology directed graph
- *
- * @param msg
- * The incoming message to be run
- * @return True if the result is success. Never returns false and throws an exception instead.
- * @throws UnsupportedEncodingException
- * @throws Exception
- * if there was a failure processing the request. The exception message is the failure reason.
- */
- @SuppressWarnings("nls")
- public static boolean topologyDG(IncomingMessage msg) throws APPCException {
- if (msg == null) {
- throw new APPCException("Provided message was null");
- }
-
- HttpPost post = null;
- try {
- // Concatenate the "action" on the end of the URL
- String path = url.getPath() + ":" + msg.getAction().getValue();
- URL serviceUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
-
- post = new HttpPost(serviceUrl.toExternalForm());
- post.setHeader("Content-Type", "application/json");
- post.setHeader("Accept", "application/json");
-
- // Set Auth
- if (basic_auth != null) {
- post.setHeader("Authorization", "Basic " + basic_auth);
- }
-
- //String body = buildReqest(msg.getId(), msg.getUrl(), msg.getIdentityUrl());
- String body = buildReqest(msg.getHeader().getRequestID(), msg.getPayload().getGenericVnfId(), msg.getPayload().getPgStreams());
- StringEntity entity = new StringEntity(body);
- entity.setContentType("application/json");
- post.setEntity(new StringEntity(body));
- } catch (UnsupportedEncodingException | MalformedURLException e) {
- throw new APPCException(e);
- }
-
- HttpClient client = getHttpClient();
-
- int httpCode = 0;
- String respBody = null;
- try {
- HttpResponse response = client.execute(post);
- httpCode = response.getStatusLine().getStatusCode();
- respBody = IOUtils.toString(response.getEntity().getContent());
- } catch (IOException e) {
- throw new APPCException(e);
- }
-
- if (httpCode == 200 && respBody != null) {
- JSONObject json;
- try {
- json = Mapper.toJsonObject(respBody);
- } catch (Exception e) {
- LOG.error("Error prcoessing response from provider. Could not map response to json", e);
- throw new APPCException("APPC has an unknown RPC error");
- }
- boolean success;
- String reason;
- try {
- JSONObject header = json.getJSONObject("output").getJSONObject("common-response-header");
- success = header.getBoolean("success");
- reason = header.getString("reason");
- } catch (Exception e) {
- LOG.error("Unknown error prcoessing failed response from provider. Json not in expected format", e);
- throw new APPCException("APPC has an unknown RPC error");
- }
- if (success) {
- return true;
- }
- String reasonStr = reason == null ? "Unknown" : reason;
- LOG.warn(String.format("Topology Operation [%s] failed. Reason: %s", msg.getHeader().getRequestID(), reasonStr));
- throw new APPCException(reasonStr);
-
- }
- throw new APPCException(String.format("Unexpected response from endpoint: [%d] - %s ", httpCode, respBody));
- }
-
- /**
- * Updates the static var URL and returns the value;
- *
- * @return The new value of URL
- */
- public static String getUrl() {
- return url.toExternalForm();
- }
-
- public static void setUrl(String newUrl) {
- try {
- url = new URL(newUrl);
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Sets the basic authentication header for the given user and password. If either entry is null then set basic auth
- * to null
- *
- * @param user
- * The user with optional domain name
- * @param password
- * The password for the user
- * @return The new value of the basic auth string that will be used in the request headers
- */
- public static String setAuthentication(String user, String password) {
- if (user != null && password != null) {
- String authStr = user + ":" + password;
- basic_auth = new String(Base64.encodeBase64(authStr.getBytes()));
- } else {
- basic_auth = null;
- }
- return basic_auth;
- }
-
- /**
- * Builds the request body for a topology operation
- *
- * @param id
- * The request id
- * @param url
- * The vm's url
- *
- * @param pgstreams
- * The streams to send to the traffic generator
- *
- * @return A String containing the request body
- */
- private static String buildReqest(String id, String url, String pgstreams) {
-
- return String.format(TEMPLATE, id, url, pgstreams);
- }
-
- @SuppressWarnings("deprecation")
- private static HttpClient getHttpClient() throws APPCException {
- HttpClient client;
- if (url.getProtocol().equals("https")) {
- try {
- KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
- trustStore.load(null, null);
- MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
- sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
-
- HttpParams params = new BasicHttpParams();
- HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
- HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
-
- SchemeRegistry registry = new SchemeRegistry();
- registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
- registry.register(new Scheme("https", sf, 443));
- registry.register(new Scheme("https", sf, 8443));
- registry.register(new Scheme("http", sf, 8181));
-
- ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
- client = new DefaultHttpClient(ccm, params);
- } catch (Exception e) {
- client = new DefaultHttpClient();
- }
- } else if (url.getProtocol().equals("http")) {
- client = new DefaultHttpClient();
- } else {
- throw new APPCException(
- "The provider.topology.url property is invalid. The url did not start with http[s]");
- }
- return client;
- }
-
- @SuppressWarnings("deprecation")
- public static class MySSLSocketFactory extends SSLSocketFactory {
- private SSLContext sslContext = SSLContext.getInstance("TLS");
-
- public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException,
- KeyStoreException, UnrecoverableKeyException {
- super(truststore);
-
- TrustManager tm = new X509TrustManager() {
- @Override
- public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- }
-
- @Override
- public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- }
-
- @Override
- public X509Certificate[] getAcceptedIssuers() {
- return null;
- }
- };
-
- sslContext.init(null, new TrustManager[] {
- tm
- }, null);
- }
-
- @Override
- public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
- throws IOException, UnknownHostException {
- return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
- }
-
- @Override
- public Socket createSocket() throws IOException {
- return sslContext.getSocketFactory().createSocket();
- }
- }
-
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/impl/WorkerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/impl/WorkerImpl.java
deleted file mode 100644
index ef72c6e12..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/impl/WorkerImpl.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.demo.impl;
-
-import org.onap.appc.exceptions.APPCException;
-import org.onap.appc.listener.EventHandler;
-import org.onap.appc.listener.demo.model.IncomingMessage;
-import org.onap.appc.listener.demo.model.Status;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
-public class WorkerImpl implements Runnable {
-
- private final EELFLogger LOG = EELFManager.getInstance().getLogger(WorkerImpl.class);
-
- // Should have all of the data we need for processing
- private IncomingMessage event;
-
- // So we can post messages from inside the worker.
- private EventHandler dmaap;
-
- public WorkerImpl(IncomingMessage message, EventHandler dmaap) {
- this.event = message;
- this.dmaap = dmaap;
- }
-
- @Override
- public void run() {
- LOG.debug(String.format("Started working on %s", event.getHeader().getRequestID()));
-
- dmaap.postStatus(event.toOutgoing(Status.ACCEPTED));
- // Run the dg in a try catch to handle all exceptions and update the
- // message at the end
- try {
- if (doDG(event)) {
- dmaap.postStatus(event.toOutgoing(Status.SUCCESS));
- LOG.debug(String.format("Event %s finished successfully", event.getHeader().getRequestID()));
- } else {
- // Should never happen. Exception with message should be thrown instead.
- LOG.error(String.format(
- "We somehow returned false from doDG() instead of throwing exception. Incoming event [%s]",
- event.toJson().toString()));
- dmaap.postStatus(event.toOutgoing(Status.FAILURE));
- }
-
- } catch (Exception e) {
- // Unknown exception from DG method. Fail and pass the exception
- // along
- String msg = "Exception: " + e.getMessage();
- LOG.warn(String.format("Event %s finished with failure. %s", event.getHeader().getRequestID(), msg));
- //TODO: should a message be included? there is nothing in the API spec for a msg?
- //dmaap.postStatus(event.toOutgoing(Status.FAILURE, msg));
- dmaap.postStatus(event.toOutgoing(Status.FAILURE));
- }
-
- LOG.debug("Done working on " + event.getHeader().getRequestID());
- }
-
- private boolean doDG(IncomingMessage msg) throws APPCException {
- return ProviderOperations.topologyDG(msg);
- }
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/Action.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/Action.java
deleted file mode 100644
index eecc99b4c..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/Action.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.demo.model;
-
-public enum Action {
- Restart("Restart"), Rebuild("Rebuild"), Migrate("Migrate"), Evacuate("Evacuate"), Snapshot("Snapshot"),modifyconfig("ModifyConfig");
-
- /**
- * Converts the string to an Action
- *
- * @param value
- * The string to try and convert. Is case insensitive
- * @return The action matching the string or null if no match was found.
- */
- public static Action toAction(String value) {
- if (value != null) {
- for (Action e : values()) {
- if (e.getValue().toUpperCase().equals(value.toUpperCase())) {
- return e;
- }
- }
- }
-
- return null;
- }
-
- private String value;
-
- private Action(String valueToUse) {
- value = valueToUse;
- }
-
- public final String getValue() {
- return value;
- }
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/CommonMessage.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/CommonMessage.java
deleted file mode 100644
index 75a618754..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/CommonMessage.java
+++ /dev/null
@@ -1,343 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.demo.model;
-
-import java.io.Serializable;
-import java.util.Collection;
-
-import org.json.JSONObject;
-import org.onap.appc.listener.util.Mapper;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-/**
- * This class holds attributes that are common to DMaaP messages both coming in from DCAE and being sent out by APPC
- *
- */
-@JsonSerialize(include = Inclusion.NON_NULL)
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class CommonMessage implements Serializable {
- /*
- * { "CommonHeader": { "TimeStamp": "0000-00-00T00:00:00.000Z", "APIver": "1.01", "OriginatorID": "policy.pdp01",
- * "RequestID": "b74d13c5-bb26-4b04-992c-4679dfc8280e", "SubrequestID": "1" }, "Action": "RESTART", "Payload": {
- * "VServerSelfLink":
- * "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345",
- * "VNF_NAME": "test", "VMID": "abc12345-1234-5678-890a-abcdefg12345", "TenantID":
- * "abcde12345fghijk6789lmnopq123rst", "LOC_ID": "Test", "in-maint": "false", "Identity":
- * "http://example.com:5000/v2.0", "Prov_status": "ACTIVE", "OAM_IPV4": "192.168.1.2",
- * "is-closed-loop-disabled": "false", "VM_NAME": "basx0001vm034", "OAM_IPV6": "aaaa::bbbb:cccc:dddd:eeee/64" } }
- */
-
- private static final long serialVersionUID = 1L;
-
- /*
- * The common header
- */
- @JsonProperty("CommonHeader")
- private CommonHeader header;
-
- /*
- * The payload
- */
- @JsonProperty("Payload")
- private Payload payload;
-
- @JsonIgnore
- private long startTime = System.currentTimeMillis();
-
- /*
- * Getters and Setters
- */
-
- public long getStartTime() {
- return startTime;
- }
-
- public void setStartTime(long startTime) {
- this.startTime = startTime;
- }
-
- /**
- * @return the header
- */
- public CommonHeader getHeader() {
- return header;
- }
-
- /**
- * @param header
- * the header to set
- */
- public void setHeader(CommonHeader header) {
- this.header = header;
- }
-
- /**
- * @return the payload
- */
- public Payload getPayload() {
- return payload;
- }
-
- /**
- * @param payload
- * the payload to set
- */
- public void setPayload(Payload payload) {
- this.payload = payload;
- }
-
- /**
- * Convenience method to return a json representation of this object.
- *
- * @return The json representation of this object
- */
- public JSONObject toJson() {
- return Mapper.toJsonObject(this);
- }
-
- @JsonIgnoreProperties(ignoreUnknown = true)
- public static class CommonHeader {
- /*
- * "CommonHeader": { "TimeStamp": "2016-05-11T13:53:53.146Z", "APIver": "1.01", "OriginatorID": "policy.pdp01",
- * "RequestID": "b74d13c5-bb26-4b04-992c-4679dfc8280e", "SubrequestID": "1" }
- */
-
- /*
- * The timestamp of the message
- */
- @JsonProperty("TimeStamp")
- private String timeStamp;
-
- /*
- * The API version of the message
- */
- @JsonProperty("APIver")
- private String apiVer;
-
- /*
- * The Originator ID of the message
- */
- @JsonProperty("OriginatorID")
- private String originatorId;
-
- /*
- * The Request Id of the message
- */
- @JsonProperty("RequestID")
- private String requestID;
-
- /*
- * The Subrequest Id of the message
- */
- @JsonProperty("SubrequestID")
- private String subRequestId;
-
- /**
- * @return the timeStamp
- */
- public String getTimeStamp() {
- return timeStamp;
- }
-
- /**
- * @param timeStamp
- * the timeStamp to set
- */
- public void setTimeStamp(String timeStamp) {
- this.timeStamp = timeStamp;
- }
-
- /**
- * @return the apiVer
- */
- public String getApiVer() {
- return apiVer;
- }
-
- /**
- * @param apiVer
- * the apiVer to set
- */
- public void setApiVer(String apiVer) {
- this.apiVer = apiVer;
- }
-
- /**
- * @return the originatorId
- */
- public String getOriginatorId() {
- return originatorId;
- }
-
- /**
- * @param originatorId
- * the originatorId to set
- */
- public void setOriginatorId(String originatorId) {
- this.originatorId = originatorId;
- }
-
- /**
- * @return the requestID
- */
- public String getRequestID() {
- return requestID;
- }
-
- /**
- * @param requestID
- * the requestID to set
- */
- public void setRequestID(String requestID) {
- this.requestID = requestID;
- }
-
- /**
- * @return the subRequestId
- */
- public String getSubRequestId() {
- return subRequestId;
- }
-
- /**
- * @param subRequestId
- * the subRequestId to set
- */
- public void setSubRequestId(String subRequestId) {
- this.subRequestId = subRequestId;
- }
- };
-
- @JsonIgnoreProperties(ignoreUnknown = true)
- public static class Payload {
- /*
- * "Payload": { "VServerSelfLink":
- * "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345",
- * "VNF_NAME": "test", "VMID": "abc12345-1234-5678-890a-abcdefg12345", "TenantID":
- * "abcde12345fghijk6789lmnopq123rst", "LOC_ID": "Test", "in-maint": "false", "Identity":
- * "http://example.com:5000/v2.0", "Prov_status": "ACTIVE", "OAM_IPV4": "192.168.1.2",
- * "is-closed-loop-disabled": "false", "VM_NAME": "test", "OAM_IPV6": "aaaa::bbbb:cccc:dddd:eeee/64" }
- */
-
- /*
- * The TenantID of the message
- */
- @JsonProperty("generic-vnf.vnf-id")
- private String genericVnfId;
-
- /**
- * @return the TenantID
- */
- public String getGenericVnfId() {
- return genericVnfId;
- }
-
- /**
- * @param TenantID
- * the TenantID to set
- */
- public void setGenericVnfId(String genericVnfId) {
- this.genericVnfId = genericVnfId;
- }
-
- @JsonProperty("pg-streams")
- private pgStreams pgStreams;
-
- /**
- * @return the TenantID
- */
-
- public String getPgStreams() {
- String r = "{\\\"pg-streams\\\": {\\\"pg-stream\\\":[";
- boolean first = true;
- for(pgStream p : this.pgStreams.streams){
- String n = "{\\\"id\\\":\\\""+p.getId()+"\\\", \\\"is-enabled\\\":\\\""+p.getIsEnabled()+"\\\"}";
- if(!first){
- r = r.concat(",");
- }
- first = false;
- r = r.concat(n);
- }
- r= r.concat("]}}");
- return r;
- }
-
- /**
- * @param TenantID
- * the TenantID to set
- */
- public void setPgStreams(pgStreams pgStreams) {
- this.pgStreams = pgStreams;
- }
-
-
-
-
-
- };
- @JsonIgnoreProperties(ignoreUnknown = true)
- public static class pgStreams {
- @JsonProperty("pg-stream")
- private Collection streams;
-
- public Collection getStreams() {
- return streams;
- }
-
- public void setStreams(Collection streams) {
- this.streams = streams;
- }
-
-
- };
- @JsonIgnoreProperties(ignoreUnknown = true)
- public static class pgStream{
- public String getId() {
- return id;
- }
- public void setId(String id) {
- this.id = id;
- }
- public String getIsEnabled() {
- return isEnabled;
- }
- public void setIsEnabled(String isEnabled) {
- this.isEnabled = isEnabled;
- }
- @JsonProperty("id")
- private String id;
- @JsonProperty("is-enabled")
- private String isEnabled;
- };
-
-
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/IncomingMessage.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/IncomingMessage.java
deleted file mode 100644
index 555329106..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/IncomingMessage.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.demo.model;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
-
-/**
- * This class represents a message coming in from DCAE.
- *
- */
-@JsonSerialize(include = Inclusion.NON_NULL)
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class IncomingMessage extends CommonMessage {
-
- private static final long serialVersionUID = 1L;
-
- /*
- * The action being requested. Its presence signals that it is an incoming message and it is not present on outgoing
- * messages
- */
- //TODO; use enum
- @JsonProperty("Action")
- private String action;
-
-
- public String getRequest() {
- return action;
- }
-
- @JsonIgnore
- public Action getAction() {
- return Action.toAction(action);
- }
-
- public void setRequest(String request) {
- this.action = request;
- }
-
-// @Override
-// public String toString() {
-// String time = getRequestTime() != null ? getRequestTime() : "N/A";
-// // String req = request != null ? request : "N/A";
-// return String.format("[%s - %s]", time, getId());
-// }
-
-// public String toOutgoing(Status status) {
-// return toOutgoing(status);
-// }
-
- public String toOutgoing(Status status) {
- OutgoingMessage out = new OutgoingMessage(this);
- out.setResponse(status);
- return out.toResponse().toString();
- }
-
- /**
- * Determines if this message should be parsed parsed. Will eventually check that the message is well formed, has
- * all required fields, and had not exceeded any timing restrictions.
- *
- * @return True if the message should be parsed. False otherwise
- */
- public boolean isValid() {
- return true;
- }
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/OutgoingMessage.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/OutgoingMessage.java
deleted file mode 100644
index a3294dd8c..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/OutgoingMessage.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.demo.model;
-
-import java.net.InetAddress;
-import java.security.SecureRandom;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.TimeZone;
-
-import org.json.JSONObject;
-import org.onap.appc.listener.util.Mapper;
-import org.onap.appc.util.Time;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
-
-/**
- * This class represents a message being sent out to DMaaP by APPC to update listeners on the status of a request
- *
- */
-@JsonSerialize(include = Inclusion.NON_NULL)
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class OutgoingMessage extends CommonMessage {
-
- public OutgoingMessage() {
-
- }
-
- public OutgoingMessage(IncomingMessage msg) {
- setHeader(msg.getHeader());
- setPayload(msg.getPayload());
-// setId(msg.getId());
-// setOriginalRequest(msg.getRequest());
-// setRequestClient(msg.getRequestClient());
-// setRequestTime(msg.getRequestTime());
-// setVmName(msg.getVmName());
-// setFromSystem(generateFrom());
-// setResponse(Status.PENDING);
-// setPolicyName(msg.getPolicyName());
-// setPolicyVersion(msg.getPolicyVersion());
-// setStartTime(msg.getStartTime());
- }
-
- private static final long serialVersionUID = -5447940920271469613L;
- /*
- * The status of the response
- */
- @JsonProperty("Status")
- private OutStatus status;
-
- /**
- * @return the status
- */
- public OutStatus getStatus() {
- return status;
- }
-
- /**
- * @param status the status to set
- */
- public void setStatus(OutStatus status) {
- this.status = status;
- }
-
- public void updateResponseTime() {
- SecureRandom rand = new SecureRandom();
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss.SSS");
- df.setTimeZone(TimeZone.getTimeZone("UTC"));
- String date = df.format(new Date(Time.utcTime()));
- //this.responseTime = String.format("%s%03d", date, rand.nextInt(1000));
- }
-
- public String generateFrom() {
- String name;
- try {
- InetAddress iAddress = InetAddress.getLocalHost();
- name = iAddress.getCanonicalHostName();
- } catch (Exception e) {
- // Could not get anything from the InetAddress
- name = "UnknownHost";
- }
- return "appc@" + name;
- }
-
- public JSONObject toResponse() {
- updateResponseTime();
- JSONObject json = Mapper.toJsonObject(this);
-
- if (!json.has("message")) {
- // If there is no message, parrot the status (response field)
- // TODO - Can this be removed for 1602 making message truely optional?
- //json.put("message", this.getResponse().toString());
- }
-
- // Removed duplication of status from message for 1602
- // json.put("message", String.format("%s: %s", request, json.get("message")));
-
- return json;
- }
-
-// @Override
-// public String toString() {
-// return String.format("%s - %s", getId(), getResponse());
-// }
-
- public static class OutStatus{
- @JsonProperty("Code")
- private String code;
-
- @JsonProperty("Value")
- private String value;
-
- /**
- * @return the code
- */
- public String getCode() {
- return code;
- }
-
- /**
- * @param code the code to set
- */
- public void setCode(String code) {
- this.code = code;
- }
-
- /**
- * @return the value
- */
- public String getValue() {
- return value;
- }
-
- /**
- * @param value the value to set
- */
- public void setValue(String value) {
- this.value = value;
- }
-
- }
-
- public void setResponse(Status newStatus) {
- if(this.status == null){
- this.status = new OutStatus();
- }
-
- switch (newStatus){
- case ACCEPTED:
- this.status.setValue(newStatus.getValue());
- this.status.setCode("100");
- break;
-
- case FAILURE:
- this.status.setValue(newStatus.getValue());
- this.status.setCode("500");
- break;
-
- case SUCCESS:
- this.status.setValue(newStatus.getValue());
- this.status.setCode("400");
- break;
- default:
- break;
-
- }
-
- }
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/Status.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/Status.java
deleted file mode 100644
index 09db11402..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/demo/model/Status.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.demo.model;
-
-public enum Status {
- /*
- * APP-C acknowledges that it has read the event off of the wire. This is the initial status of an OutgoingEvent
- */
- ACCEPTED("ACCEPTED"),
-
- /*
- * APP-C has finished processing the event without errors
- */
- SUCCESS("SUCCESS"),
-
- /*
- * APP-C has finished processing the event with errors
- */
- FAILURE("FAILURE");
-
- /**
- * Converts the string to an Status
- *
- * @param value
- * The string to try and convert. Is case insensitive
- * @return The status matching the string or null if no match was found.
- */
- public static Status toStatus(String value) {
- if (value != null) {
- for (Status e : values()) {
- if (e.getValue().toUpperCase().equals(value.toUpperCase())) {
- return e;
- }
- }
- }
-
- return null;
- }
-
- private String value;
-
- private Status(String valueToUse) {
- value = valueToUse;
- }
-
- public final String getValue() {
- return value;
- }
-
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/impl/ControllerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/impl/ControllerImpl.java
deleted file mode 100644
index b830b6fc7..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/impl/ControllerImpl.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.impl;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.commons.lang3.concurrent.BasicThreadFactory;
-import org.onap.appc.listener.Controller;
-import org.onap.appc.listener.Listener;
-import org.onap.appc.listener.ListenerProperties;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
-
-/**
- * A common implementation of a controller. This controller should not need to be modified to implement new listeners
- *
- */
-public class ControllerImpl implements Controller {
-
- private final EELFLogger LOG = EELFManager.getInstance().getLogger(ControllerImpl.class);
-
- private int LISTENER_COUNT = 1;
-
- private Map listeners = null;
-
- private ThreadPoolExecutor executor;
-
- /**
- * Creates a Controller with the set of listener properties which will be used to start listener threads.
- *
- * @param properties
- * A non null Set of ListenerProperties
- */
- public ControllerImpl(Set properties) {
- listeners = new HashMap();
- for (ListenerProperties props : properties) {
- if (props.getClass() != null) {
- listeners.put(props, null);
- } else {
- LOG.error(String.format(
- "The ListenerProperties %s has no Listener class associated with it and will not run.", props));
- }
- }
-
- LISTENER_COUNT = properties.size();
-
- executor = new ThreadPoolExecutor(LISTENER_COUNT, LISTENER_COUNT, 1, TimeUnit.SECONDS,
- new ArrayBlockingQueue(LISTENER_COUNT));
-
- // Custom Named thread factory
- BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("Appc-Listener-%d").build();
- executor.setThreadFactory(threadFactory);
- }
-
- @Override
- public void start() {
- LOG.info("Starting DMaaP Controller.");
- for (ListenerProperties props : listeners.keySet()) {
- try {
- if (props.isDisabled()) {
- LOG.warn(String.format("The listener %s is disabled and will not be run", props.getPrefix()));
- } else {
- Listener l = props.getListenerClass().getConstructor(ListenerProperties.class).newInstance(props);
- l.setListenerId(props.getPrefix());
- listeners.put(props, l);
- executor.execute(l);
- }
- } catch (Exception e) {
- e.printStackTrace();
- LOG.error(String.format("Exception while starting listener %s.", props), e);
- }
- }
- }
-
- @Override
- public void stop(boolean stopNow) {
- LOG.info("Stopping DMaaP Controller.");
- Iterator itr = listeners.values().iterator();
- while (itr.hasNext()) {
- Listener l = itr.next();
- if (stopNow) {
- l.stopNow();
- } else {
- l.stop();
- }
- itr.remove();
- }
- executor.shutdown();
- try {
- executor.awaitTermination(10, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- }
- }
-
- @Override
- public Map getListeners() {
- return listeners;
- }
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/impl/EventHandlerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/impl/EventHandlerImpl.java
deleted file mode 100644
index 85ce93001..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/impl/EventHandlerImpl.java
+++ /dev/null
@@ -1,337 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.impl;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import org.onap.appc.adapter.factory.MessageService;
-import org.onap.appc.adapter.message.Consumer;
-import org.onap.appc.adapter.message.MessageAdapterFactory;
-import org.onap.appc.adapter.message.Producer;
-import org.onap.appc.listener.EventHandler;
-import org.onap.appc.listener.ListenerProperties;
-import org.onap.appc.listener.util.Mapper;
-import org.onap.appc.logging.LoggingConstants;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
-import org.slf4j.MDC;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * This class is a wrapper for the DMaaP client provided in appc-dmaap-adapter. Its aim is to ensure
- * that only well formed messages are sent and received on DMaaP.
- */
-public class EventHandlerImpl implements EventHandler {
-
- private final EELFLogger LOG = EELFManager.getInstance().getLogger(EventHandlerImpl.class);
-
- /*
- * The amount of time in seconds to keep a connection to a topic open while waiting for data
- */
- private int READ_TIMEOUT = 60;
-
- /*
- * The pool of hosts to query against
- */
- private Collection pool;
-
- /*
- * The topic to read messages from
- */
- private String readTopic;
-
- /*
- * The topic to write messages to
- */
- private Set writeTopics;
-
- /*
- * The client (group) name to use for reading messages
- */
- private String clientName;
-
- /*
- * The id of the client (group) that is reading messages
- */
- private String clientId;
-
- /*
- * The api public key to use for authentication
- */
- private String apiKey;
-
- /*
- * The api secret key to use for authentication
- */
- private String apiSecret;
-
- /*
- * A json object containing filter arguments.
- */
- private String filter_json;
-
- private MessageService messageService;
-
- private Consumer reader = null;
- private Producer producer = null;
-
- public EventHandlerImpl(ListenerProperties props) {
- pool = new HashSet<>();
- writeTopics = new HashSet<>();
-
- if (props != null) {
- readTopic = props.getProperty(ListenerProperties.KEYS.TOPIC_READ);
- clientName = props.getProperty(ListenerProperties.KEYS.CLIENT_NAME, "APP-C");
- clientId = props.getProperty(ListenerProperties.KEYS.CLIENT_ID, "0");
- apiKey = props.getProperty(ListenerProperties.KEYS.AUTH_USER_KEY);
- apiSecret = props.getProperty(ListenerProperties.KEYS.AUTH_SECRET_KEY);
-
- filter_json = props.getProperty(ListenerProperties.KEYS.TOPIC_READ_FILTER);
-
- READ_TIMEOUT = Integer
- .valueOf(props.getProperty(ListenerProperties.KEYS.TOPIC_READ_TIMEOUT, String.valueOf(READ_TIMEOUT)));
-
- String hostnames = props.getProperty(ListenerProperties.KEYS.HOSTS);
- if (hostnames != null && !hostnames.isEmpty()) {
- for (String name : hostnames.split(",")) {
- pool.add(name);
- }
- }
-
- String writeTopicStr = props.getProperty(ListenerProperties.KEYS.TOPIC_WRITE);
- if (writeTopicStr != null) {
- for (String topic : writeTopicStr.split(",")) {
- writeTopics.add(topic);
- }
- }
-
- messageService = MessageService.parse(props.getProperty(ListenerProperties.KEYS.MESSAGE_SERVICE));
-
- LOG.info(String.format(
- "Configured to use %s client on host pool [%s]. Reading from [%s] filtered by %s. Wriring to [%s]. Authenticated using %s",
- messageService, hostnames, readTopic, filter_json, writeTopics, apiKey));
- }
- }
-
- @Override
- public List getIncomingEvents() {
- return getIncomingEvents(1000);
- }
-
- @Override
- public List getIncomingEvents(int limit) {
- List out = new ArrayList<>();
- LOG.info(String.format("Getting up to %d incoming events", limit));
- // reuse the consumer object instead of creating a new one every time
- if (reader == null) {
- LOG.info("Getting Consumer...");
- reader = getConsumer();
- }
- if (reader != null) {
- List items = reader.fetch(READ_TIMEOUT * 1000, limit);
- for (String item : items) {
- out.add(item);
- }
- }
- LOG.info(String.format("Read %d messages from %s as %s/%s.", out.size(), readTopic, clientName, clientId));
- return out;
- }
-
- @Override
- public List getIncomingEvents(Class cls) {
- return getIncomingEvents(cls, 1000);
- }
-
- @Override
- public List getIncomingEvents(Class cls, int limit) {
- List incomingStrings = getIncomingEvents(limit);
- return Mapper.mapList(incomingStrings, cls);
- }
-
- @Override
- public void postStatus(String event) {
- postStatus(null, event);
- }
-
- @Override
- public void postStatus(String partition, String event) {
- LOG.debug(String.format("Posting Message [%s]", event));
- if (producer == null) {
- LOG.info("Getting Producer...");
- producer = getProducer();
- }
- producer.post(partition, event);
- }
-
- /**
- * Returns a consumer object for direct access to our Cambria consumer interface
- *
- * @return An instance of the consumer interface
- */
- protected Consumer getConsumer() {
- LOG.debug(String.format("Getting Consumer: %s %s/%s/%s", pool, readTopic, clientName, clientId));
- if (filter_json == null && writeTopics.contains(readTopic)) {
- LOG.error(
- "*****We will be writing and reading to the same topic without a filter. This will cause an infinite loop.*****");
- }
-
- Consumer out = null;
- BundleContext ctx = FrameworkUtil.getBundle(EventHandlerImpl.class).getBundleContext();
- if (ctx != null) {
- ServiceReference svcRef = ctx.getServiceReference(MessageAdapterFactory.class.getName());
- if (svcRef != null) {
- try {
- out = ((MessageAdapterFactory) ctx.getService(svcRef))
- .createConsumer(pool, readTopic, clientName, clientId, filter_json, apiKey, apiSecret);
- } catch (Exception e) {
- //TODO:create eelf message
- LOG.error("EvenHandlerImp.getConsumer calling MessageAdapterFactor.createConsumer", e);
- }
- if (out != null) {
- for (String url : pool) {
- if (url.contains("3905") || url.contains("https")) {
- out.useHttps(true);
- break;
- }
- }
- }
- }
- }
- return out;
- }
-
- /**
- * Returns a consumer object for direct access to our Cambria producer interface
- *
- * @return An instance of the producer interface
- */
- protected Producer getProducer() {
- LOG.debug(String.format("Getting Producer: %s %s", pool, readTopic));
-
- Producer out = null;
- BundleContext ctx = FrameworkUtil.getBundle(EventHandlerImpl.class).getBundleContext();
- if (ctx != null) {
- ServiceReference svcRef = ctx.getServiceReference(MessageAdapterFactory.class.getName());
- if (svcRef != null) {
- out = ((MessageAdapterFactory) ctx.getService(svcRef))
- .createProducer(pool, writeTopics, apiKey, apiSecret);
- if (out != null) {
- for (String url : pool) {
- if (url.contains("3905") || url.contains("https")) {
- out.useHttps(true);
- break;
- }
- }
- }
- }
- }
- return out;
- }
-
- @Override
- public void closeClients() {
- LOG.debug("Closing Consumer and Producer DMaaP clients");
- if (reader != null) {
- reader.close();
- }
- if (producer != null) {
- producer.close();
- }
- }
-
- @Override
- public String getClientId() {
- return clientId;
- }
-
- @Override
- public void setClientId(String clientId) {
- this.clientId = clientId;
- }
-
- @Override
- public String getClientName() {
- return clientName;
- }
-
- @Override
- public void setClientName(String clientName) {
- this.clientName = clientName;
- MDC.put(LoggingConstants.MDCKeys.PARTNER_NAME, clientName);
- }
-
- @Override
- public void addToPool(String hostname) {
- pool.add(hostname);
- }
-
- @Override
- public Collection getPool() {
- return pool;
- }
-
- @Override
- public void removeFromPool(String hostname) {
- pool.remove(hostname);
- }
-
- @Override
- public String getReadTopic() {
- return readTopic;
- }
-
- @Override
- public void setReadTopic(String readTopic) {
- this.readTopic = readTopic;
- }
-
- @Override
- public Set getWriteTopics() {
- return writeTopics;
- }
-
- @Override
- public void setWriteTopics(Set writeTopics) {
- this.writeTopics = writeTopics;
- }
-
- @Override
- public void clearCredentials() {
- apiKey = null;
- apiSecret = null;
- }
-
- @Override
- public void setCredentials(String key, String secret) {
- apiKey = key;
- apiSecret = secret;
- }
-}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/util/Mapper.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/util/Mapper.java
deleted file mode 100644
index bd77041ec..000000000
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/openecomp/appc/listener/util/Mapper.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.listener.util;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import org.json.JSONObject;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-public class Mapper {
-
- private static final EELFLogger LOG = EELFManager.getInstance().getLogger(Mapper.class);
-
- private static ObjectMapper mapper = new ObjectMapper();
-
- /**
- * @return The object mapper that we are using.
- */
- public static ObjectMapper getMapper() {
- return mapper;
- }
-
- /**
- * Convert a String to a DcaeMessage
- *
- * @param data
- * The json string to try and parse
- * @return A DcaeMessage from the json string or null if it could not
- */
- public static T mapOne(String data, Class cls) {
- try {
- return mapper.readValue(data, cls);
- } catch (Exception e) {
- LOG.warn(String.format("Could not map [ %s ] to %s", data, cls.getName()), e);
- return null;
- }
- }
-
- public static List mapList(List data, Class cls) {
- List out = new ArrayList();
- for (String s : data) {
- T tmp = Mapper.mapOne(s, cls);
- if (tmp != null) {
- out.add(tmp);
- }
- }
- return out;
- }
-
- /**
- * Convenience method to try and convert objects to json String
- *
- * @param obj
- * The object to try and convert
- * @return A json string representing the object or null if it could not be converted
- */
- public static String toJsonString(Object obj) {
- String jsonStr;
- try {
- if (obj instanceof JSONObject) {
- jsonStr = obj.toString();
- }else {
- jsonStr = mapper.writeValueAsString(obj);
- }
- return jsonStr;
- } catch (Exception e) {
- LOG.warn(String.format("Could not map %s to JSONObject.", obj), e);
- return null;
- }
- }
-
- public static JSONObject toJsonObject(Object obj) {
- String jsonStr;
- try {
- if (obj.getClass().equals(String.class)) {
- jsonStr = (String) obj;
- } else {
- jsonStr = mapper.writeValueAsString(obj);
- }
- return new JSONObject(jsonStr);
- } catch (Exception e) {
- LOG.warn(String.format("Could not map %s to JSONObject.", obj), e);
- return null;
- }
- }
- public static JsonNode toJsonNodeFromJsonString(String jsonStr) {
- JsonNode jsonNode = null;
- if(jsonStr != null) {
- try {
- jsonNode = mapper.readTree(jsonStr);
- } catch (IOException e) {
- LOG.warn(String.format("Could not map %s to jsonNode.", jsonStr), e);
- }
- }
- return jsonNode;
- }
- public static JsonNode toJsonNode(Object obj) {
- JsonNode jsonNode = null;
- String jsonStr = toJsonString(obj);
- if(jsonStr != null) {
- try {
- jsonNode = mapper.readTree(jsonStr);
- } catch (IOException e) {
- LOG.warn(String.format("Could not map %s to JSONObject.", obj), e);
- }
- }
- return jsonNode;
- }
-}
--
cgit 1.2.3-korg