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.onap.appc.listener.LCM.impl;
27 import org.onap.appc.exceptions.APPCException;
28 import org.onap.appc.listener.EventHandler;
29 import org.onap.appc.listener.LCM.conv.Converter;
30 import org.onap.appc.listener.LCM.model.DmaapMessage;
31 import org.onap.appc.listener.LCM.model.DmaapOutgoingMessage;
32 import org.onap.appc.listener.LCM.operation.ProviderOperations;
34 import com.att.eelf.configuration.EELFLogger;
35 import com.att.eelf.configuration.EELFManager;
37 import com.fasterxml.jackson.core.JsonProcessingException;
38 import com.fasterxml.jackson.databind.JsonNode;
40 public class WorkerImpl implements Runnable {
42 private final EELFLogger LOG = EELFManager.getInstance().getLogger(WorkerImpl.class);
44 // Should have all of the data we need for processing
45 private DmaapMessage event;
47 // So we can post messages from inside the worker.
48 private EventHandler dmaap;
50 //so we know were to post the messages
51 private final ProviderOperations providerOperations;
54 public WorkerImpl(DmaapMessage message, EventHandler dmaap, ProviderOperations providerOperations) {
57 this.providerOperations = providerOperations;
62 String requestIdWithSubId = extractRequestIdWithSubId(event.getBody());
63 LOG.debug(String.format("Started working on %s", requestIdWithSubId));
65 // Run the dg in a try catch to handle all exceptions and update the
68 JsonNode outputJsonNode = doDG(event.getRpcName(), event.getBody());
69 DmaapOutgoingMessage dmaapOutgoingMessage= Converter.convJsonNodeToDmaapOutgoingMessage(event, outputJsonNode);
70 postMessageToDMaaP(dmaapOutgoingMessage,requestIdWithSubId);
71 Integer statusCode = extractStatusCode(dmaapOutgoingMessage.getBody());
72 if (ProviderOperations.isSucceeded(statusCode)) {
73 LOG.debug(String.format("Event %s finished successfully", requestIdWithSubId));
75 LOG.warn(String.format("Event %s failed", requestIdWithSubId));
78 } catch (Exception e) {
79 // Unknown exception from DG method. Fail and pass the exception
81 String msg = "Exception: " + e.getMessage();
82 LOG.error(String.format("Event %s finished with failure. %s", requestIdWithSubId, msg));
83 DmaapOutgoingMessage dmaapOutgoingMessage= Converter.buildDmaapOutgoingMessageWithUnexpectedError(event, e);
84 postMessageToDMaaP(dmaapOutgoingMessage,requestIdWithSubId);
87 LOG.debug("Done working on " + requestIdWithSubId);
91 private Integer extractStatusCode(JsonNode event) {
92 Integer statusCode = null;
94 statusCode = Converter.extractStatusCode(event);
95 } catch (Exception e) {
96 LOG.error("failed to parse statusCode. Json not in expected format", e);
102 private String extractRequestIdWithSubId(JsonNode event){
103 String requestId = "";
105 requestId = Converter.extractRequestIdWithSubId(event);
106 } catch (Exception e) {
107 LOG.error("failed to parse request-id and sub-request-id. Json not in expected format", e);
114 private void postMessageToDMaaP(DmaapOutgoingMessage dmaapOutgoingMessage,String requestIdWithSubId) {
115 String dmaapOutgoingMessageJsonString;
117 dmaapOutgoingMessageJsonString = Converter.convDmaapOutgoingMessageToJsonString(dmaapOutgoingMessage);
118 dmaap.postStatus(dmaapOutgoingMessage.getCambriaPartition(),dmaapOutgoingMessageJsonString);
119 } catch (JsonProcessingException e) {
120 LOG.error("failed to postMessageToDMaaP requestIdWithSubId: "+requestIdWithSubId+" dmaapOutgoingMessage: "+dmaapOutgoingMessage, e);
124 private JsonNode doDG(String rpcName, JsonNode msg) throws APPCException {
125 return providerOperations.topologyDG(rpcName,msg);