aboutsummaryrefslogtreecommitdiffstats
path: root/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DashboardController.java
blob: 891398aef363c4eef51400bcb0c01b4fa968ad9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
/*-
 * ============LICENSE_START=======================================================
 * ONAP Policy Engine
 * ================================================================================
 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.controller;

import com.att.research.xacml.api.pap.PAPException;
import com.att.research.xacml.api.pap.PDP;
import com.att.research.xacml.api.pap.PDPGroup;
import com.att.research.xacml.api.pap.PDPPolicy;
import com.att.research.xacml.util.XACMLProperties;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.script.SimpleBindings;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.dao.SystemLogDbDao;
import org.onap.policy.model.PDPGroupContainer;
import org.onap.policy.rest.XACMLRestProperties;
import org.onap.policy.rest.dao.CommonClassDao;
import org.onap.policy.rest.jpa.PolicyEntity;
import org.onap.policy.utils.PolicyUtils;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import org.onap.policy.xacml.api.pap.OnapPDP;
import org.onap.policy.xacml.api.pap.OnapPDPGroup;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
import org.onap.portalsdk.core.web.support.JsonMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping({"/"})
public class DashboardController extends RestrictedBaseController {
    private static final Logger policyLogger = FlexLogger.getLogger(DashboardController.class);
    @Autowired
    CommonClassDao commonClassDao;

    @Autowired
    SystemLogDbDao systemDAO;

    public void setCommonClassDao(CommonClassDao commonClassDao) {
        this.commonClassDao = commonClassDao;
    }

    public void setSystemLogDbDao(SystemLogDbDao systemDAO) {
        this.systemDAO = systemDAO;
    }

    private int pdpCount;
    private PDPGroupContainer pdpConatiner;
    private ArrayList<Object> pdpStatusData;
    private ArrayList<Object> papStatusData;
    private ArrayList<Object> policyStatusCrudData;
    private ArrayList<Object> pdpStatusCrudData;
    private ArrayList<Object> policyActivityData;
    private PolicyController policyController;
    private static String defaultTime = "0000-00-00";
    private static String createDate = "createdDate";
    private static String modifiedDate = "modifiedDate";
    private static String scope = "scope";
    private static String stage = "stage";
    private static String exceptionOccured = "Exception Occured";

    public PolicyController getPolicyController() {
        return policyController;
    }

    public void setPolicyController(PolicyController policyController) {
        this.policyController = policyController;
    }

    private PolicyController getPolicyControllerInstance() {
        return policyController != null ? getPolicyController() : new PolicyController();
    }

    /**
     * This method is to retrieve all the data of last 30 days from PolicyEntity table as default.
     *
     * @param request object
     * @param response object contains retrieved data
     */
    @RequestMapping(
            value = {"/get_DashboardPolicyCRUDData"},
            method = {org.springframework.web.bind.annotation.RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void get_DashboardPolicyCrudData(HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> model = new HashMap<>();
            ObjectMapper mapper = new ObjectMapper();
            mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
            addPolicyCrudInfoToTable();
            model.put("papStatusCRUDData", mapper.writeValueAsString(policyStatusCrudData));
            response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(model))).toString());
        } catch (Exception e) {
            policyLogger.error(exceptionOccured, e);
        }
    }

    /**
     * This method retrieves data based on input criteria.
     *
     * @param request object
     * @param response object contains retrieved data
     */
    @RequestMapping(
            value = {"/dashboardController/dashboardAdvancedSearch.htm"},
            method = {org.springframework.web.bind.annotation.RequestMethod.POST})
    public void dashboardAdvancedSearch(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String lscope = null;
        String lstage = "both";
        String isDelected = "both";
        String ttlDateAfter = null;
        String ttlDateBefore = null;
        try {
            ObjectMapper mapper = new ObjectMapper();
            mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
            JsonNode root = mapper.readTree(request.getReader());
            JsonNode inputData = root.get("policyData");
            JsonNode jscope = inputData.path(scope);
            if (jscope != null) {
                lscope = jscope.textValue();
            }
            JsonNode jstage = inputData.path(stage);
            if (jstage != null) {
                lstage = jstage.textValue();
            }
            JsonNode jisDelected = inputData.path("isDelected");
            if (jisDelected != null) {
                isDelected = jisDelected.textValue();
            }
            JsonNode jttlDateAfter = inputData.path("ttlDate_after");
            if (jttlDateAfter != null) {
                ttlDateAfter = jttlDateAfter.textValue();
            }
            JsonNode jttlDateBefore = inputData.path("ttlDate_before");
            if (jttlDateBefore != null) {
                ttlDateBefore = jttlDateBefore.textValue();
            }
            getPolicyData(lscope, lstage, isDelected, ttlDateAfter, ttlDateBefore);
            Map<String, Object> model = new HashMap<>();
            model.put("policyStatusCRUDData", mapper.writeValueAsString(policyStatusCrudData));
            response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(model))).toString());
        } catch (Exception e) {
            response.setCharacterEncoding("UTF-8");
            PrintWriter out = response.getWriter();
            out.write(PolicyUtils.CATCH_EXCEPTION);
        }

    }

    /**
     * This method is to retrieve data from PolicyEntity table.
     *
     * @param request object
     * @param response object contains retrieved data
     */
    @RequestMapping(
            value = {"/get_DashboardPdpPolicyCRUDData"},
            method = {org.springframework.web.bind.annotation.RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void get_DashboardPdpPolicyCrudData(HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> model = new HashMap<>();
            ObjectMapper mapper = new ObjectMapper();
            mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
            model.put("pdpStatusCRUDData", mapper.writeValueAsString(pdpStatusCrudData));
            response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(model))).toString());
        } catch (Exception e) {
            policyLogger.error(exceptionOccured, e);
        }
    }

    /**
     * getData.
     *
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     */
    @RequestMapping(
            value = {"/get_DashboardLoggingData"},
            method = {org.springframework.web.bind.annotation.RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getData(HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> model = new HashMap<>();
            ObjectMapper mapper = new ObjectMapper();
            model.put("availableLoggingDatas", mapper.writeValueAsString(systemDAO.getLoggingData()));
            response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(model))).toString());
        } catch (Exception e) {
            policyLogger.error(exceptionOccured + e);
        }
    }

    /**
     * getSystemAlertData.
     *
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     */
    @RequestMapping(
            value = {"/get_DashboardSystemAlertData"},
            method = {org.springframework.web.bind.annotation.RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getSystemAlertData(HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> model = new HashMap<>();
            ObjectMapper mapper = new ObjectMapper();
            model.put("systemAlertsTableDatas", mapper.writeValueAsString(systemDAO.getSystemAlertData()));
            response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(model))).toString());
        } catch (Exception e) {
            policyLogger.error(exceptionOccured + e);
        }
    }

    /**
     * getPAPStatusData.
     *
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     */
    @RequestMapping(
            value = {"/get_DashboardPAPStatusData"},
            method = {org.springframework.web.bind.annotation.RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getPAPStatusData(HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> model = new HashMap<>();
            ObjectMapper mapper = new ObjectMapper();
            mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
            addPAPToTable();
            model.put("papTableDatas", mapper.writeValueAsString(papStatusData));
            response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(model))).toString());
        } catch (Exception e) {
            policyLogger.error(exceptionOccured + e);
        }
    }

    /**
     * getPDPStatusData.
     *
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     */
    @RequestMapping(
            value = {"/get_DashboardPDPStatusData"},
            method = {org.springframework.web.bind.annotation.RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getPDPStatusData(HttpServletRequest request, HttpServletResponse response) {
        try {
            final Map<String, Object> model = new HashMap<>();
            ObjectMapper mapper = new ObjectMapper();
            mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
            PolicyController controller = getPolicyControllerInstance();
            this.pdpConatiner = new PDPGroupContainer(controller.getPapEngine());
            addPDPToTable();
            model.put("pdpTableDatas", mapper.writeValueAsString(pdpStatusData));
            JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
            response.getWriter().write(new JSONObject(msg).toString());
        } catch (Exception e) {
            policyLogger.error(exceptionOccured + e);
        }
    }

    /**
     * getPolicyActivityData.
     *
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     */
    @RequestMapping(
            value = {"/get_DashboardPolicyActivityData"},
            method = {org.springframework.web.bind.annotation.RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getPolicyActivityData(HttpServletRequest request, HttpServletResponse response) {
        try {
            final Map<String, Object> model = new HashMap<>();
            ObjectMapper mapper = new ObjectMapper();
            mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
            PolicyController controller = getPolicyControllerInstance();
            this.pdpConatiner = new PDPGroupContainer(controller.getPapEngine());
            addPolicyToTable();
            model.put("policyActivityTableDatas", mapper.writeValueAsString(policyActivityData));
            response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(model))).toString());
        } catch (Exception e) {
            policyLogger.error(exceptionOccured + e);
        }
    }

    /*
     * Add the PAP information to the PAP Table
     */
    public void addPAPToTable() {
        papStatusData = new ArrayList<>();
        String papStatus = null;
        try {
            PolicyController controller = getPolicyControllerInstance();
            Set<OnapPDPGroup> groups = controller.getPapEngine().getOnapPDPGroups();
            if (groups == null) {
                throw new PAPException("PAP not running");
            } else {
                papStatus = "IS_OK";
            }
        } catch (PAPException | NullPointerException e1) {
            papStatus = "CANNOT_CONNECT";
            policyLogger.error("Error getting PAP status, PAP not responding to requests", e1);
        }
        String papUrl = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL);
        JSONObject object = new JSONObject();
        object.put("system", papUrl);
        object.put("status", papStatus);
        List<Object> data = commonClassDao.getDataByQuery("from PolicyEntity", new SimpleBindings());
        object.put("noOfPolicy", data.size());
        object.put("noOfConnectedTrap", pdpCount);
        papStatusData.add(0, object);
    }

    /**
     * Add the PAP Policy information to the PAP Table.
     */
    public void addPolicyCrudInfoToTable() {
        policyStatusCrudData = new ArrayList<>();
        LocalDate now = LocalDate.now();
        LocalDate lastThirtyDate = now.minusDays(30);
        policyLogger.info("now: " + now);
        policyLogger.info("thirty: " + lastThirtyDate);
        String entityquery = "from PolicyEntity where created_date >= :createdDate";
        SimpleBindings geParams = new SimpleBindings();
        geParams.put(createDate, lastThirtyDate.toString());
        List<Object> datas = commonClassDao.getDataByQuery(entityquery, geParams);

        if (datas == null) {
            return;
        }

        datas.stream().forEach((data) -> {
            JSONObject object = new JSONObject();
            object.put("id", ((PolicyEntity) data).getPolicyId());
            object.put(scope, ((PolicyEntity) data).getScope());
            object.put("policyName", ((PolicyEntity) data).getPolicyName());
            object.put("version", ((PolicyEntity) data).getVersion());
            if (isPushedToPdp(((PolicyEntity) data).getPolicyId())) {
                object.put(stage, "PDP");
            } else {
                object.put(stage, "PAP");
            }
            object.put("createdBy", ((PolicyEntity) data).getCreatedBy());
            object.put("deleted", ((PolicyEntity) data).isDeleted());
            object.put("deleteReasonCode", ((PolicyEntity) data).getDeleteReasonCode());
            object.put("deletedBy", ((PolicyEntity) data).getDeletedBy());
            object.put("modifiedBy", ((PolicyEntity) data).getModifiedBy());
            if (((PolicyEntity) data).getModifiedDate() != null) {
                Timestamp ts = new Timestamp(((PolicyEntity) data).getModifiedDate().getTime());
                Timestamp cts = new Timestamp(((PolicyEntity) data).getCreatedDate().getTime());
                object.put(modifiedDate, ts.toString());
                object.put(createDate, cts.toString());
            } else {
                object.put(modifiedDate, defaultTime);
                object.put(createDate, defaultTime);
            }
            policyStatusCrudData.add(object);
        });
    }

    /*
     * Add the PDP Policy information to the PDP Table
     */
    private boolean isPushedToPdp(long policyId) {
        try {
            String groupEntityquery = "from PolicyGroupEntity where policyid = :policyEntityId";
            SimpleBindings geParams = new SimpleBindings();
            geParams.put("policyEntityId", policyId);
            List<Object> groupobject = commonClassDao.getDataByQuery(groupEntityquery, geParams);
            if (groupobject != null && ! groupobject.isEmpty()) {
                return true;
            }
        } catch (Exception e) {
            policyLogger.error(exceptionOccured + e);
        }

        return false;
    }

    /*
     * Add the Policy information to the policyStatusCRUDDataTable
     */
    private void getPolicyData(String inputScope, String inputStage, String isDeleted, String createdAfter,
            String createdBefore) {
        policyStatusCrudData = new ArrayList<>();
        List<Object> policyData = null;
        SimpleBindings geParams = new SimpleBindings();
        try {
            StringBuilder entityquery = buildSqlQuery(inputScope, isDeleted, createdAfter, createdBefore);
            if (entityquery == null) {
                return;
            }
            policyLogger.info("entityquery: " + entityquery.toString());
            policyLogger.info("geParams: " + geParams.toString());

            policyData = commonClassDao.getDataByQuery(entityquery.toString(), geParams);
            if (policyData == null) {
                return;
            }
            policyData.stream().forEach((data) -> {
                JSONObject object = populatePolicyData((PolicyEntity) data);

                if (object.get(stage).equals("PDP") && "PDP".equalsIgnoreCase(inputStage)) {
                    policyStatusCrudData.add(object);
                }
                if (object.get(stage).equals("PAP") && "PAP".equalsIgnoreCase(inputStage)) {
                    policyStatusCrudData.add(object);
                }
                if ("both".equalsIgnoreCase(inputStage)) {
                    policyStatusCrudData.add(object);
                }
            });
        } catch (Exception e) {
            policyLogger.error(exceptionOccured, e);
        }
    }

    /*
     * Build SQL query
     */
    private StringBuilder buildSqlQuery(String scope, String isDeleted, String createdAfter, String createdBefore) {
        SimpleBindings geParams = new SimpleBindings();

        // since scope is required
        if (scope == null || scope.isEmpty()) {
            return null;
        } else {
            geParams.put(scope, "%" + scope + "%");
        }
        StringBuilder entityquery = new StringBuilder("from PolicyEntity where scope like :scope ");
        if (!"both".equalsIgnoreCase(isDeleted)) {
            entityquery.append(" and deleted = :isDeleted");
            if ("Yes".equalsIgnoreCase(isDeleted)) {
                geParams.put("isDeleted", true);
            } else {
                geParams.put("isDeleted", false);
            }
        }
        if (createdAfter != null && !createdAfter.isEmpty()) {
            entityquery.append(" and created_date >= :createdAfter");
            geParams.put("createdAfter", createdAfter);
        }
        if (createdBefore != null && !createdBefore.isEmpty()) {
            entityquery.append(" and created_date <= :createdBefore");
            geParams.put("createdBefore", createdBefore);
        }
        return entityquery;
    }

    private JSONObject populatePolicyData(PolicyEntity data) {
        JSONObject object = new JSONObject();
        object.put("id", data.getPolicyId());
        object.put(scope, data.getScope());
        object.put("policyName", data.getPolicyName());
        object.put("version", data.getVersion());
        if (isPushedToPdp(data.getPolicyId())) {
            object.put(stage, "PDP");
        } else {
            object.put(stage, "PAP");
        }
        object.put("createdBy", data.getCreatedBy());
        object.put("deleted", data.isDeleted());
        object.put("deleteReasonCode", data.getDeleteReasonCode());
        object.put("deletedBy", data.getDeletedBy());
        object.put("modifiedBy", data.getModifiedBy());
        if (data.getModifiedDate() != null) {
            Timestamp ts = new Timestamp(data.getModifiedDate().getTime());
            Timestamp cts = new Timestamp(data.getCreatedDate().getTime());
            object.put(modifiedDate, ts.toString());
            object.put(createDate, cts.toString());
        } else {
            object.put(modifiedDate, defaultTime);
            object.put(createDate, defaultTime);
        }

        return object;
    }

    /**
     * Add PDP Information to the PDP Table.
     *
     */
    public void addPDPToTable() {
        pdpCount = 0;
        pdpStatusData = new ArrayList<>();
        long naCount;
        long denyCount = 0;
        long permitCount = 0;
        for (PDPGroup group : this.pdpConatiner.getGroups()) {
            for (PDP pdp : group.getPdps()) {
                naCount = -1;
                if ("UP_TO_DATE".equals(pdp.getStatus().getStatus().toString()) && ((OnapPDP) pdp).getJmxPort() != 0) {
                    String pdpIpAddress = parseIpSystem(pdp.getId());
                    int port = ((OnapPDP) pdp).getJmxPort();
                    if (port != 0) {
                        policyLogger.debug("Getting JMX Response Counts from " + pdpIpAddress + " at JMX port " + port);
                        naCount = getRequestCounts(pdpIpAddress, port, "pdpEvaluationNA");
                        permitCount = getRequestCounts(pdpIpAddress, port, "PdpEvaluationPermit");
                        denyCount = getRequestCounts(pdpIpAddress, port, "PdpEvaluationDeny");
                    }
                }
                if (naCount == -1) {
                    JSONObject object = new JSONObject();
                    object.put("id", pdp.getId());
                    object.put("name", pdp.getName());
                    object.put("groupname", group.getName());
                    object.put("status", pdp.getStatus().getStatus().toString());
                    object.put("description", pdp.getDescription());
                    object.put("permitCount", "NA");
                    object.put("denyCount", "NA");
                    object.put("naCount", "NA");
                    pdpStatusData.add(object);
                } else {
                    JSONObject object = new JSONObject();
                    object.put("id", pdp.getId());
                    object.put("name", pdp.getName());
                    object.put("groupname", group.getName());
                    object.put("status", pdp.getStatus().getStatus().toString());
                    object.put("description", pdp.getDescription());
                    object.put("permitCount", permitCount);
                    object.put("denyCount", denyCount);
                    object.put("naCount", naCount);
                    pdpStatusData.add(object);
                }
                pdpCount++;
            }
        }
    }

    private static String parseIpSystem(String line) {
        Pattern pattern = Pattern.compile("://(.+?):");
        Matcher ip = pattern.matcher(line);
        if (ip.find()) {
            return ip.group(1);
        }
        return null;
    }

    /*
     * Contact JMX Connector Sever and return the value of the given jmxAttribute
     */
    @SuppressWarnings({"rawtypes", "unchecked"})
    private long getRequestCounts(String host, int port, String jmxAttribute) {

        policyLogger.debug("Create an RMI connector client and connect it to the JMX connector server");
        HashMap map = null;
        try (JMXConnector jmxConnection = JMXConnectorFactory.newJMXConnector(createConnectionUrl(host, port), map)) {
            jmxConnection.connect();
            Object obj = jmxConnection.getMBeanServerConnection()
                    .getAttribute(new ObjectName("PdpRest:type=PdpRestMonitor"), jmxAttribute);
            policyLogger.debug("pdpEvaluationNA value retreived: " + obj);
            return (long) obj;
        } catch (MalformedURLException e) {
            policyLogger.error("MalformedURLException for JMX connection", e);
        } catch (IOException e) {
            policyLogger.error("Error in reteriving" + jmxAttribute + " from JMX connection", e);
        } catch (AttributeNotFoundException e) {
            policyLogger.error("AttributeNotFoundException  " + jmxAttribute + " for JMX connection", e);
        } catch (InstanceNotFoundException e) {
            policyLogger.error("InstanceNotFoundException " + host + " for JMX connection", e);
        } catch (MalformedObjectNameException e) {
            policyLogger.error("MalformedObjectNameException for JMX connection", e);
        } catch (MBeanException e) {
            policyLogger.error("MBeanException for JMX connection");
            policyLogger.error(exceptionOccured + e);
        } catch (ReflectionException e) {
            policyLogger.error("ReflectionException for JMX connection", e);
        }

        return -1;
    }

    private static JMXServiceURL createConnectionUrl(String host, int port) throws MalformedURLException {
        return new JMXServiceURL("rmi", "", 0, "/jndi/rmi://" + host + ":" + port + "/jmxrmi");
    }

    /*
     * Add the information to the Policy Table
     */
    private void addPolicyToTable() {
        policyActivityData = new ArrayList<>();
        String policyID;
        int policyFireCount;
        Map<String, String> policyMap = new HashMap<>();
        Object policyList;
        // get list of policy

        for (PDPGroup group : this.pdpConatiner.getGroups()) {
            for (PDPPolicy policy : group.getPolicies()) {
                try {
                    policyMap.put(policy.getPolicyId().replace(" ", ""), policy.getId());
                } catch (Exception e) {
                    policyLogger.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + policy.getName() + e);
                }
            }

            for (PDP pdp : group.getPdps()) {
                // Add rows to the Policy Table
                policyList = null;
                if ("UP_TO_DATE".equals(pdp.getStatus().getStatus().toString()) && ((OnapPDP) pdp).getJmxPort() != 0) {
                    String pdpIpAddress = parseIpSystem(pdp.getId());
                    policyList = getPolicy(pdpIpAddress, ((OnapPDP) pdp).getJmxPort());
                }
                if (policyList != null && policyList.toString().length() > 3) {
                    String[] splitPolicy = policyList.toString().split(",");
                    for (String policyKeyValue : splitPolicy) {
                        policyID = urnPolicyID(policyKeyValue);
                        policyFireCount = countPolicyID(policyKeyValue);
                        if (policyID != null && policyMap.containsKey(policyID)) {
                            JSONObject object = new JSONObject();
                            object.put("policyId", policyMap.get(policyID));
                            object.put("fireCount", policyFireCount);
                            object.put("system", pdp.getId());
                            policyActivityData.add(object);
                        }
                    }
                } else {
                    JSONObject object = new JSONObject();
                    if (policyList != null) {
                        object.put("policyId", "Unable to retrieve policy information");
                    } else {
                        object.put("policyId", "Unable to access PDP JMX Server");
                    }
                    object.put("fireCount", "NA");
                    object.put("system", pdp.getId());
                    policyActivityData.add(object);
                }
            }
        }
    }

    /*
     * Contact JMX Connector Sever and return the list of {policy id , count}
     */
    @SuppressWarnings({"rawtypes", "unchecked"})
    private Object getPolicy(String host, int port) {
        policyLogger
                .debug("Create an RMI connector client and connect it to the JMX connector server for Policy: " + host);
        HashMap map = null;
        try (JMXConnector jmxConnection = JMXConnectorFactory.newJMXConnector(createConnectionUrl(host, port), map)) {
            jmxConnection.connect();
            Object obj = jmxConnection.getMBeanServerConnection()
                    .getAttribute(new ObjectName("PdpRest:type=PdpRestMonitor"), "policyMap");
            policyLogger.debug("policyMap value retreived: " + obj);
            return obj;
        } catch (MalformedURLException e) {
            policyLogger.error("MalformedURLException for JMX connection", e);
        } catch (IOException e) {
            policyLogger.error("AttributeNotFoundException for policyMap", e);
        } catch (AttributeNotFoundException e) {
            policyLogger.error("AttributeNotFoundException for JMX connection", e);
        } catch (InstanceNotFoundException e) {
            policyLogger.error("InstanceNotFoundException " + host + " for JMX connection", e);
        } catch (MalformedObjectNameException e) {
            policyLogger.error("MalformedObjectNameException for JMX connection", e);
        } catch (MBeanException e) {
            policyLogger.error("MBeanException for JMX connection", e);
            policyLogger.error(exceptionOccured + e);
        } catch (ReflectionException e) {
            policyLogger.error("ReflectionException for JMX connection", e);
        }

        return null;

    }

    private static String urnPolicyID(String line) {
        String[] splitLine = line.split("=");
        String removeSpaces = splitLine[0].replaceAll("\\s+", "");
        return removeSpaces.replace("{", "");
    }

    private static Integer countPolicyID(String line) {
        String[] splitLine = line.split("=");
        return Integer.parseInt(splitLine[1].replace("}", ""));
    }

}