Change nexus values to properties
[appc.git] / appc-event-listener / appc-event-listener-bundle / src / main / java / org / openecomp / appc / listener / CL / impl / WorkerImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.appc.listener.CL.impl;
23
24 import org.openecomp.appc.exceptions.APPCException;
25 import org.openecomp.appc.listener.EventHandler;
26 import org.openecomp.appc.listener.CL.model.IncomingMessage;
27 import org.openecomp.appc.listener.CL.model.Status;
28
29 import com.att.eelf.configuration.EELFLogger;
30 import com.att.eelf.configuration.EELFManager;
31
32 public class WorkerImpl implements Runnable {
33
34     private final EELFLogger LOG = EELFManager.getInstance().getLogger(WorkerImpl.class);
35
36     // Should have all of the data we need for processing
37     private IncomingMessage event;
38
39     // So we can post messages from inside the worker.
40     private EventHandler dmaap;
41
42     public WorkerImpl(IncomingMessage message, EventHandler dmaap) {
43         this.event = message;
44         this.dmaap = dmaap;
45     }
46
47     @Override
48     public void run() {
49         LOG.debug(String.format("Started working on %s", event.getId()));
50         dmaap.postStatus(event.toOutgoing(Status.ACTIVE, null));
51         // Run the dg in a try catch to handle all exceptions and update the
52         // message at the end
53         try {
54             if (doDG(event)) {
55                 dmaap.postStatus(event.toOutgoing(Status.SUCCESS, null));
56                 LOG.debug(String.format("Event %s finished successfully", event.getId()));
57             } else {
58                 // Should never happen. Exception with message should be thrown instead.
59                 LOG.error(String.format(
60                     "We somehow returned false from doDG() instead of throwing exception. Incoming event [%s]",
61                     event.toJson().toString()));
62                 dmaap.postStatus(event.toOutgoing(Status.FAILURE));
63             }
64
65         } catch (Exception e) {
66             // Unknown exception from DG method. Fail and pass the exception
67             // along
68             String msg = "Exception: " + e.getMessage();
69             LOG.warn(String.format("Event %s finished with failure. %s", event.getId(), msg));
70             dmaap.postStatus(event.toOutgoing(Status.FAILURE, msg));
71         }
72
73         LOG.debug("Done working on " + event.getId());
74     }
75
76     private boolean doDG(IncomingMessage msg) throws APPCException {
77         return ProviderOperations.topologyDG(msg);
78     }
79 }