2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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 * ============LICENSE_END=========================================================
24 package org.onap.appc.oam.messageadapter;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.fasterxml.jackson.core.JsonProcessingException;
29 import org.apache.commons.lang.ObjectUtils;
30 import org.onap.appc.srvcomm.messaging.MessagingConnector;
32 public class MessageAdapter {
34 private final EELFLogger logger = EELFManager.getInstance().getLogger(MessageAdapter.class);
36 private static final String PROPERTIES_PREFIX = "appc.OAM";
38 private MessagingConnector messagingConnector;
39 private String partition;
40 private boolean isDisabled;
43 * Initialize producer client to post messages using configuration properties.
47 if (isAppcOamPropsListenerEnabled()) {
48 messagingConnector = new MessagingConnector();
50 logger.warn(String.format("The listener %s is disabled and will not be run", "appc.OAM"));
54 public void init(MessagingConnector connector) {
56 if (isAppcOamPropsListenerEnabled()) {
57 messagingConnector = connector;
59 logger.warn(String.format("The listener %s is disabled and will not be run", "appc.OAM"));
65 * Get producer. If it is null, call createProducer to create it again.
69 MessagingConnector getMessagingConnector() {
70 if (messagingConnector == null) {
71 messagingConnector = new MessagingConnector();
74 return messagingConnector;
78 * Posts message to UEB. As UEB accepts only json messages this method first convert uebMessage to json format
81 * @param oamContext response data that based on it a message will be send to UEB (the format of the message that
82 * will be sent to UEB based on the action and its YANG domainmodel).
84 public void post(OAMContext oamContext) {
85 if (logger.isTraceEnabled()) {
86 logger.trace("Entering to post with AsyncResponse = " + ObjectUtils.toString(oamContext));
92 jsonMessage = Converter.convAsyncResponseToUebOutgoingMessageJsonString(oamContext);
93 if (logger.isDebugEnabled()) {
94 logger.debug("UEB Response = " + jsonMessage);
97 MessagingConnector connector = getMessagingConnector();
98 success = connector != null && connector.publishMessage(PROPERTIES_PREFIX, this.partition, jsonMessage);
99 } catch (JsonProcessingException e1) {
100 logger.error("Error generating Json from UEB message " + e1.getMessage());
102 } catch (Exception e) {
103 logger.error("Error sending message to UEB " + e.getMessage(), e);
107 if (logger.isTraceEnabled()) {
108 logger.trace("Exiting from post with (success = " + ObjectUtils.toString(success) + ")");
112 private boolean isAppcOamPropsListenerEnabled() {