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.net.URISyntaxException;
28 import java.security.GeneralSecurityException;
29 import java.util.List;
30 import java.util.UUID;
31 import java.util.concurrent.CountDownLatch;
33 //import org.apache.log4j.Logger;
34 import org.json.JSONObject;
35 import org.openecomp.policy.api.NotificationScheme;
36 import org.openecomp.policy.api.NotificationType;
37 import org.openecomp.policy.api.PDPNotification;
38 import org.openecomp.policy.std.StdPDPNotification;
40 import com.att.nsa.cambria.client.CambriaClientFactory;
41 import com.att.nsa.cambria.client.CambriaConsumer;
42 import com.att.nsa.cambria.client.CambriaPublisher;
43 import com.fasterxml.jackson.core.JsonParseException;
44 import com.fasterxml.jackson.databind.JsonMappingException;
45 import org.openecomp.policy.common.logging.flexlogger.*;
48 public class ManualClientEndUEB {
49 private static StdPDPNotification notification = null;
50 private static String resultJson = null;
51 private static Logger logger = FlexLogger.getLogger(ManualClientEndUEB.class.getName());
52 private static CambriaConsumer CConsumer = null;
53 private static List<String> uebURLList = null;
54 private static boolean messageNotReceived = false;
55 private static String url = null;
56 private static String uniquID = null;
57 private static String topic = null;
60 public static PDPNotification result(NotificationScheme scheme) {
61 if (resultJson == null || notification == null) {
62 logger.debug("No Result" );
65 if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) {
66 boolean removed = false, 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);
89 private static void publishMessage(String pubTopic, String uniqueID , List<String> uebURLList) {
91 String UEBlist = uebURLList.toString();
92 UEBlist = UEBlist.substring(1,UEBlist.length()-1);
93 CambriaPublisher pub = null;
95 pub = CambriaClientFactory.createSimplePublisher(null, UEBlist, pubTopic);
96 } catch (MalformedURLException e1) {
97 // TODO Auto-generated catch block
99 } catch (GeneralSecurityException e1) {
100 // TODO Auto-generated catch block
101 e1.printStackTrace();
103 final JSONObject msg1 = new JSONObject ();
105 msg1.put ( "JSON", "UEB Update Ruest UID=" + uniqueID);
108 pub.send ( "MyPartitionKey", msg1.toString () );
109 } catch (IOException e) {
110 // TODO Auto-generated catch block
117 public static void createTopic (String url, String uniquID, List<String> uebURLList){
121 topic = aURL.getHost() + aURL.getPort();
122 } catch (MalformedURLException e) {
123 topic = url.replace("[:/]", "");
126 publishMessage(topic+ uniquID , uniquID, uebURLList);
129 public static void start(String url, List<String> uebURLList,
131 ManualClientEndUEB.uebURLList = uebURLList;
132 ManualClientEndUEB.url = url;
133 ManualClientEndUEB.uniquID = uniqueID;
137 ManualClientEndUEB.topic = aURL.getHost() + aURL.getPort();
138 } catch (MalformedURLException e) {
139 ManualClientEndUEB.topic = url.replace("[:/]", "");
143 CConsumer = CambriaClientFactory.createConsumer ( null, uebURLList, topic + uniquID, "clientGroup", id, 15*1000, 1000 );
144 } catch (MalformedURLException e1) {
145 // TODO Auto-generated catch block
146 e1.printStackTrace();
147 } catch (GeneralSecurityException e1) {
148 // TODO Auto-generated catch block
149 e1.printStackTrace();
153 publishMessage(topic + "UpdateRequest", uniquID, uebURLList);
155 for ( String msg : CConsumer.fetch () )
158 logger.debug("Manual Notification Recieved Message " + msg + " from UEB cluster : " + uebURLList.toString());
160 if (!msg.contains("UEB Update")){
161 // System.out.println("Manual Notification Recieved Message " + msg + " from UEB cluster : " + uebURLList.toString());
162 notification = NotificationUnMarshal.notificationJSON(msg);
166 }catch (Exception e) {