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.srvcomm.messaging.event;
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
31 import org.onap.appc.configuration.Configuration;
32 import org.onap.appc.configuration.ConfigurationFactory;
33 import org.onap.appc.exceptions.APPCException;
34 import org.onap.appc.srvcomm.messaging.MessageDestination;
35 import org.onap.appc.srvcomm.messaging.MessagingConnector;
36 import java.util.Date;
40 public class EventSender implements EventSenderInterface
42 private final EELFLogger LOG = EELFManager.getInstance().getLogger(EventSender.class);
43 public static final String PROPERTY_PREFIX = "dmaap.event";
45 private static Configuration configuration = ConfigurationFactory.getConfiguration();
47 private MessagingConnector messagingConnector;
50 messagingConnector = new MessagingConnector();
54 public boolean sendEvent(MessageDestination destination, EventMessage msg) {
55 String jsonStr = msg.toJson();
56 String id = msg.getEventHeader().getEventId();
57 LOG.info(String.format("Posting Message [%s - %s]", id, jsonStr));
58 String propertyPrefix = destination.toString() + "." + PROPERTY_PREFIX;
59 return messagingConnector.publishMessage(propertyPrefix, id, jsonStr);
63 public boolean sendEvent(MessageDestination destination, EventMessage msg, String eventTopicName) {
64 String jsonStr = msg.toJson();
65 String id = msg.getEventHeader().getEventId();
66 LOG.info(String.format("Posting Message [%s - %s]", id, jsonStr));
67 String propertyPrefix = destination.toString() + "." + PROPERTY_PREFIX;
68 return messagingConnector.publishMessage(propertyPrefix, id, eventTopicName, jsonStr);
72 public boolean sendEvent(MessageDestination destination, Map<String, String> params, SvcLogicContext ctx) throws APPCException {
75 String message = "Parameters map is empty (null)";
77 throw new APPCException(message);
79 String eventTime = new Date(System.currentTimeMillis()).toString();
80 String apiVer = params.get("apiVer");
81 String eventId = params.get("eventId");
82 String reason = params.get("reason");
83 String entityId = params.get("entityId");
85 reason += "(" + entityId + ")";
87 Integer code = Integer.getInteger(params.get("code"), 500);
89 if (eventTime == null || apiVer == null || eventId == null || reason == null) {
90 String message = String.format("Missing input parameters: %s", params);
92 throw new APPCException(message);
94 EventMessage eventMessage = new EventMessage(
95 new EventHeader(eventTime, apiVer, eventId),
96 new EventStatus(code, reason));
98 return sendEvent(destination, eventMessage);