2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.listener.demo.impl;
26 import org.onap.appc.exceptions.APPCException;
27 import org.onap.appc.listener.EventHandler;
28 import org.onap.appc.listener.demo.model.IncomingMessage;
29 import org.onap.appc.listener.demo.model.Status;
31 import com.att.eelf.configuration.EELFLogger;
32 import com.att.eelf.configuration.EELFManager;
34 public class WorkerImpl implements Runnable {
36 private final EELFLogger LOG = EELFManager.getInstance().getLogger(WorkerImpl.class);
38 // Should have all of the data we need for processing
39 private IncomingMessage event;
41 // So we can post messages from inside the worker.
42 private EventHandler dmaap;
44 public WorkerImpl(IncomingMessage message, EventHandler dmaap) {
51 LOG.debug(String.format("Started working on %s", event.getHeader().getRequestID()));
53 dmaap.postStatus(event.toOutgoing(Status.ACCEPTED));
54 // Run the dg in a try catch to handle all exceptions and update the
58 dmaap.postStatus(event.toOutgoing(Status.SUCCESS));
59 LOG.debug(String.format("Event %s finished successfully", event.getHeader().getRequestID()));
61 // Should never happen. Exception with message should be thrown instead.
62 LOG.error(String.format(
63 "We somehow returned false from doDG() instead of throwing exception. Incoming event [%s]",
64 event.toJson().toString()));
65 dmaap.postStatus(event.toOutgoing(Status.FAILURE));
68 } catch (Exception e) {
69 // Unknown exception from DG method. Fail and pass the exception
71 String msg = "Exception: " + e.getMessage();
72 LOG.warn(String.format("Event %s finished with failure. %s", event.getHeader().getRequestID(), msg));
73 //TODO: should a message be included? there is nothing in the API spec for a msg?
74 //dmaap.postStatus(event.toOutgoing(Status.FAILURE, msg));
75 dmaap.postStatus(event.toOutgoing(Status.FAILURE));
78 LOG.debug("Done working on " + event.getHeader().getRequestID());
81 private boolean doDG(IncomingMessage msg) throws APPCException {
82 return ProviderOperations.topologyDG(msg);