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