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.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.messageadapter.impl;
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import com.fasterxml.jackson.core.JsonProcessingException;
31 import org.apache.commons.lang.ObjectUtils;
32 import org.onap.appc.domainmodel.lcm.ResponseContext;
33 import org.onap.appc.domainmodel.lcm.VNFOperation;
34 import org.onap.appc.messageadapter.MessageAdapter;
35 import org.onap.appc.requesthandler.conv.Converter;
36 import org.onap.appc.srvcomm.messaging.MessagingConnector;
38 public class MessageAdapterImpl implements MessageAdapter{
40 private MessagingConnector messageService;
41 private String partition ;
43 private static final EELFLogger logger = EELFManager.getInstance().getLogger(MessageAdapterImpl.class);
46 * Initialize producer client to post messages using configuration properties
50 logger.debug("MessageAdapterImpl - init");
51 this.messageService = new MessagingConnector();
54 public void init(MessagingConnector connector) {
55 logger.debug("MessageAdapterImpl - init");
56 this.messageService = connector;
60 * Posts message to DMaaP. As DMaaP accepts only json messages this method first convert dmaapMessage to json format and post it to DMaaP.
61 * @param asyncResponse response data that based on it a message will be send to DMaaP (the format of the message that will be sent to DMaaP based on the action and its YANG domainmodel).
62 * @return True if message is postes successfully else False
65 public boolean post(VNFOperation operation, String rpcName, ResponseContext asyncResponse){
67 if (logger.isTraceEnabled()) {
68 logger.trace("Entering to post with AsyncResponse = " + ObjectUtils.toString(asyncResponse));
70 logger.debug("Entered MessageAdapterImpl.post()");
73 logger.debug("Before converting Async Response");
74 jsonMessage = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(operation, rpcName, asyncResponse);
75 if (logger.isDebugEnabled()) {
76 logger.debug("DMaaP Response = " + jsonMessage);
78 logger.debug("Before Invoking producer.post(): jsonMessage is::" + jsonMessage);
79 success = messageService.publishMessage("appc.LCM", this.partition, jsonMessage);
80 logger.debug("After Invoking producer.post()");
81 } catch (JsonProcessingException e1) {
82 logger.error("Error generating Json from DMaaP message " + e1.getMessage());
85 logger.error("Error sending message to DMaaP " + e.getMessage());
88 logger.debug("Exiting MesageAdapterImpl.post()");
89 if (logger.isTraceEnabled()) {
90 logger.trace("Exiting from post with (success = " + ObjectUtils.toString(success) + ")");