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.openecomp.policy.std;
23 import java.io.IOException;
24 import java.net.MalformedURLException;
26 import java.security.GeneralSecurityException;
27 import java.util.List;
29 import org.json.JSONObject;
30 import org.openecomp.policy.api.NotificationScheme;
31 import org.openecomp.policy.api.NotificationType;
32 import org.openecomp.policy.api.PDPNotification;
33 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
34 import org.openecomp.policy.common.logging.flexlogger.Logger;
36 import com.att.nsa.cambria.client.CambriaClientFactory;
37 import com.att.nsa.cambria.client.CambriaConsumer;
38 import com.att.nsa.cambria.client.CambriaPublisher;
41 @SuppressWarnings("deprecation")
42 public class ManualClientEndUEB {
43 private static StdPDPNotification notification = null;
44 private static String resultJson = null;
45 private static Logger logger = FlexLogger.getLogger(ManualClientEndUEB.class.getName());
46 private static CambriaConsumer CConsumer = null;
47 @SuppressWarnings("unused")
48 private static List<String> uebURLList = null;
49 @SuppressWarnings("unused")
50 private static boolean messageNotReceived = false;
51 @SuppressWarnings("unused")
52 private static String url = null;
53 private static String uniquID = null;
54 private static String topic = null;
57 public static PDPNotification result(NotificationScheme scheme) {
58 if (resultJson == null || notification == null) {
59 logger.debug("No Result" );
62 if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) {
63 boolean removed = false, updated = false;
64 if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){
67 if(notification.getLoadedPolicies()!=null && !notification.getLoadedPolicies().isEmpty()){
70 if(removed && updated) {
71 notification.setNotificationType(NotificationType.BOTH);
73 notification.setNotificationType(NotificationType.REMOVE);
75 notification.setNotificationType(NotificationType.UPDATE);
78 }else if(scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) {
79 return MatchStore.checkMatch(notification);
86 private static void publishMessage(String pubTopic, String uniqueID , List<String> uebURLList) {
88 String UEBlist = uebURLList.toString();
89 UEBlist = UEBlist.substring(1,UEBlist.length()-1);
90 CambriaPublisher pub = null;
92 pub = CambriaClientFactory.createSimplePublisher(null, UEBlist, pubTopic);
93 } catch (MalformedURLException e1) {
95 } catch (GeneralSecurityException e1) {
98 final JSONObject msg1 = new JSONObject ();
100 msg1.put ( "JSON", "UEB Update Ruest UID=" + uniqueID);
103 pub.send ( "MyPartitionKey", msg1.toString () );
104 } catch (IOException e) {
105 logger.error("Exception Occured"+e);
111 public static void createTopic (String url, String uniquID, List<String> uebURLList){
115 topic = aURL.getHost() + aURL.getPort();
116 } catch (MalformedURLException e) {
117 topic = url.replace("[:/]", "");
120 publishMessage(topic+ uniquID , uniquID, uebURLList);
123 public static void start(String url, List<String> uebURLList,
125 ManualClientEndUEB.uebURLList = uebURLList;
126 ManualClientEndUEB.url = url;
127 ManualClientEndUEB.uniquID = uniqueID;
131 ManualClientEndUEB.topic = aURL.getHost() + aURL.getPort();
132 } catch (MalformedURLException e) {
133 ManualClientEndUEB.topic = url.replace("[:/]", "");
137 CConsumer = CambriaClientFactory.createConsumer ( null, uebURLList, topic + uniquID, "clientGroup", id, 15*1000, 1000 );
138 } catch (MalformedURLException e1) {
139 e1.printStackTrace();
140 } catch (GeneralSecurityException e1) {
141 e1.printStackTrace();
145 publishMessage(topic + "UpdateRequest", uniquID, uebURLList);
147 for ( String msg : CConsumer.fetch () )
150 logger.debug("Manual Notification Recieved Message " + msg + " from UEB cluster : " + uebURLList.toString());
152 if (!msg.contains("UEB Update")){
153 // System.out.println("Manual Notification Recieved Message " + msg + " from UEB cluster : " + uebURLList.toString());
154 notification = NotificationUnMarshal.notificationJSON(msg);
158 }catch (Exception e) {