2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.std;
23 import java.io.IOException;
24 import java.net.MalformedURLException;
26 import java.util.List;
28 import org.json.JSONObject;
29 import org.onap.policy.api.NotificationScheme;
30 import org.onap.policy.api.NotificationType;
31 import org.onap.policy.api.PDPNotification;
32 import org.onap.policy.common.logging.flexlogger.FlexLogger;
33 import org.onap.policy.common.logging.flexlogger.Logger;
35 import com.att.nsa.cambria.client.CambriaClientFactory;
36 import com.att.nsa.cambria.client.CambriaConsumer;
37 import com.att.nsa.cambria.client.CambriaPublisher;
40 @SuppressWarnings("deprecation")
41 public class ManualClientEndUEB {
42 private static StdPDPNotification notification = null;
43 private static String resultJson = null;
44 private static Logger logger = FlexLogger.getLogger(ManualClientEndUEB.class.getName());
45 private static CambriaConsumer CConsumer = null;
46 @SuppressWarnings("unused")
47 private static List<String> uebURLList = null;
48 @SuppressWarnings("unused")
49 private static boolean messageNotReceived = false;
50 @SuppressWarnings("unused")
51 private static String url = null;
52 private static String uniquID = null;
53 private static String topic = null;
56 public static PDPNotification result(NotificationScheme scheme) {
57 if (resultJson == null || notification == null) {
58 logger.debug("No Result" );
61 if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) {
62 boolean removed = false, updated = false;
63 if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){
66 if(notification.getLoadedPolicies()!=null && !notification.getLoadedPolicies().isEmpty()){
69 if(removed && updated) {
70 notification.setNotificationType(NotificationType.BOTH);
72 notification.setNotificationType(NotificationType.REMOVE);
74 notification.setNotificationType(NotificationType.UPDATE);
77 }else if(scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) {
78 return MatchStore.checkMatch(notification);
85 private static void publishMessage(String pubTopic, String uniqueID , List<String> uebURLList) {
87 String UEBlist = uebURLList.toString();
88 UEBlist = UEBlist.substring(1,UEBlist.length()-1);
89 CambriaPublisher pub = null;
91 pub = CambriaClientFactory.createSimplePublisher(null, UEBlist, pubTopic);
92 } catch (Exception e1) {
93 logger.error("Exception Occured"+e1);
95 final JSONObject msg1 = new JSONObject ();
97 msg1.put ( "JSON", "UEB Update Ruest UID=" + uniqueID);
100 pub.send ( "MyPartitionKey", msg1.toString () );
102 } catch (IOException e) {
103 logger.error("Exception Occured"+e);
108 public static void createTopic (String url, String uniquID, List<String> uebURLList){
112 topic = aURL.getHost() + aURL.getPort();
113 } catch (MalformedURLException e) {
114 topic = url.replace("[:/]", "");
117 publishMessage(topic+ uniquID , uniquID, uebURLList);
120 public static void start(String url, List<String> uebURLList,
122 ManualClientEndUEB.uebURLList = uebURLList;
123 ManualClientEndUEB.url = url;
124 ManualClientEndUEB.uniquID = uniqueID;
128 ManualClientEndUEB.topic = aURL.getHost() + aURL.getPort();
129 } catch (MalformedURLException e) {
130 ManualClientEndUEB.topic = url.replace("[:/]", "");
134 CConsumer = CambriaClientFactory.createConsumer ( null, uebURLList, topic + uniquID, "clientGroup", id, 15*1000, 1000 );
135 } catch (Exception e1) {
136 logger.error("Exception Occured"+e1);
140 publishMessage(topic + "UpdateRequest", uniquID, uebURLList);
142 for ( String msg : CConsumer.fetch () )
145 logger.debug("Manual Notification Recieved Message " + msg + " from UEB cluster : " + uebURLList.toString());
147 if (!msg.contains("UEB Update")){
148 notification = NotificationUnMarshal.notificationJSON(msg);
152 }catch (Exception e) {
153 logger.error("Error in Manual CLient UEB notification ", e);