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;
55 private ManualClientEndUEB() {
59 public static PDPNotification result(NotificationScheme scheme) {
60 if (resultJson == null || notification == null) {
61 logger.debug("No Result" );
64 if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) {
65 boolean removed = false;
66 boolean updated = false;
67 if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){
70 if(notification.getLoadedPolicies()!=null && !notification.getLoadedPolicies().isEmpty()){
73 if(removed && updated) {
74 notification.setNotificationType(NotificationType.BOTH);
76 notification.setNotificationType(NotificationType.REMOVE);
78 notification.setNotificationType(NotificationType.UPDATE);
81 }else if(scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) {
82 return MatchStore.checkMatch(notification);
87 private static void publishMessage(String pubTopic, String uniqueID , List<String> uebURLList) {
89 String UEBlist = uebURLList.toString();
90 UEBlist = UEBlist.substring(1,UEBlist.length()-1);
91 CambriaPublisher pub = null;
93 pub = CambriaClientFactory.createSimplePublisher(null, UEBlist, pubTopic);
94 } catch (Exception e1) {
95 logger.error("Exception Occured"+e1);
97 final JSONObject msg1 = new JSONObject ();
99 msg1.put ( "JSON", "UEB Update Ruest UID=" + uniqueID);
102 pub.send ( "MyPartitionKey", msg1.toString () );
104 } catch (IOException e) {
105 logger.error("Exception Occured"+e);
110 public static void createTopic (String url, String uniquID, List<String> uebURLList){
114 topic = aURL.getHost() + aURL.getPort();
115 } catch (MalformedURLException e) {
116 topic = url.replace("[:/]", "");
119 publishMessage(topic+ uniquID , uniquID, uebURLList);
122 public static void start(String url, List<String> uebURLList,
124 ManualClientEndUEB.uebURLList = uebURLList;
125 ManualClientEndUEB.url = url;
126 ManualClientEndUEB.uniquID = uniqueID;
130 ManualClientEndUEB.topic = aURL.getHost() + aURL.getPort();
131 } catch (MalformedURLException e) {
132 ManualClientEndUEB.topic = url.replace("[:/]", "");
136 CConsumer = CambriaClientFactory.createConsumer ( null, uebURLList, topic + uniquID, "clientGroup", id, 15*1000, 1000 );
137 } catch (Exception e1) {
138 logger.error("Exception Occured"+e1);
142 publishMessage(topic + "UpdateRequest", uniquID, uebURLList);
144 for ( String msg : CConsumer.fetch () )
147 logger.debug("Manual Notification Recieved Message " + msg + " from UEB cluster : " + uebURLList.toString());
149 if (!msg.contains("UEB Update")){
150 notification = NotificationUnMarshal.notificationJSON(msg);
154 }catch (Exception e) {
155 logger.error("Error in Manual CLient UEB notification ", e);