2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.listener.demo.impl;
27 import org.openecomp.appc.exceptions.APPCException;
28 import org.openecomp.appc.listener.EventHandler;
29 import org.openecomp.appc.listener.demo.model.IncomingMessage;
30 import org.openecomp.appc.listener.demo.model.Status;
32 import com.att.eelf.configuration.EELFLogger;
33 import com.att.eelf.configuration.EELFManager;
35 public class WorkerImpl implements Runnable {
37 private final EELFLogger LOG = EELFManager.getInstance().getLogger(WorkerImpl.class);
39 // Should have all of the data we need for processing
40 private IncomingMessage event;
42 // So we can post messages from inside the worker.
43 private EventHandler dmaap;
45 public WorkerImpl(IncomingMessage message, EventHandler dmaap) {
52 LOG.debug(String.format("Started working on %s", event.getHeader().getRequestID()));
54 dmaap.postStatus(event.toOutgoing(Status.ACCEPTED));
55 // Run the dg in a try catch to handle all exceptions and update the
59 dmaap.postStatus(event.toOutgoing(Status.SUCCESS));
60 LOG.debug(String.format("Event %s finished successfully", event.getHeader().getRequestID()));
62 // Should never happen. Exception with message should be thrown instead.
63 LOG.error(String.format(
64 "We somehow returned false from doDG() instead of throwing exception. Incoming event [%s]",
65 event.toJson().toString()));
66 dmaap.postStatus(event.toOutgoing(Status.FAILURE));
69 } catch (Exception e) {
70 // Unknown exception from DG method. Fail and pass the exception
72 String msg = "Exception: " + e.getMessage();
73 LOG.warn(String.format("Event %s finished with failure. %s", event.getHeader().getRequestID(), msg));
74 //TODO: should a message be included? there is nothing in the API spec for a msg?
75 //dmaap.postStatus(event.toOutgoing(Status.FAILURE, msg));
76 dmaap.postStatus(event.toOutgoing(Status.FAILURE));
79 LOG.debug("Done working on " + event.getHeader().getRequestID());
82 private boolean doDG(IncomingMessage msg) throws APPCException {
83 return ProviderOperations.topologyDG(msg);