2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications Copyright (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.messageadapter.impl;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import com.fasterxml.jackson.core.JsonProcessingException;
30 import org.apache.commons.lang.ObjectUtils;
31 import org.onap.appc.domainmodel.lcm.ResponseContext;
32 import org.onap.appc.domainmodel.lcm.VNFOperation;
33 import org.onap.appc.messageadapter.MessageAdapter;
34 import org.onap.appc.requesthandler.conv.Converter;
35 import org.onap.appc.srvcomm.messaging.MessagingConnector;
37 public class MessageAdapterImpl implements MessageAdapter{
39 private MessagingConnector messageService;
40 private String partition;
42 private static final EELFLogger logger = EELFManager.getInstance().getLogger(MessageAdapterImpl.class);
45 * Initialize producer client to post messages using configuration properties
49 logger.debug("MessageAdapterImpl - init");
50 this.messageService = new MessagingConnector();
53 public void init(MessagingConnector connector) {
54 logger.debug("MessageAdapterImpl - init");
55 this.messageService = connector;
59 * Posts message to DMaaP. As DMaaP accepts only json messages this method first converts dmaapMessage
60 * to json format and posts it to DMaaP.
61 * @param asyncResponse response data on which to base a message that will be sent to DMaaP
62 * (the format of the message that will be sent to DMaaP is based on the action and its YANG domainmodel).
63 * @return True if message is posted successfully, else False
66 public boolean post(VNFOperation operation, String rpcName, ResponseContext asyncResponse) {
68 if (logger.isTraceEnabled()) {
69 logger.trace("Entering to post with AsyncResponse = " + ObjectUtils.toString(asyncResponse));
71 logger.debug("Entered MessageAdapterImpl.post()");
74 logger.debug("Before converting Async Response");
76 Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(operation, rpcName, asyncResponse);
77 if (logger.isDebugEnabled()) {
78 logger.debug("DMaaP Response = " + jsonMessage);
80 logger.debug("Before Invoking messageService.publishMessage(): jsonMessage is::" + jsonMessage);
81 success = messageService.publishMessage("appc.LCM", this.partition, jsonMessage);
82 logger.debug("After Invoking messageService.publishMessage()");
83 } catch (JsonProcessingException e1) {
84 logger.error("Error generating Json from DMaaP message " + e1.getMessage());
86 } catch (Exception e) {
87 logger.error("Error sending message to DMaaP " + e.getMessage());
90 logger.debug("Exiting MesageAdapterImpl.post()");
91 if (logger.isTraceEnabled()) {
92 logger.trace("Exiting from post with (success = " + ObjectUtils.toString(success) + ")");