[Policy-52, Policy-92, Policy-93] Policy Enhancements and bugfixes
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / openecomp / policy / controller / DashboardController.java
index 707a65d..0894706 100644 (file)
@@ -73,7 +73,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 @Controller
 @RequestMapping({"/"})
 public class DashboardController  extends RestrictedBaseController{
-       private static final Logger logger = FlexLogger.getLogger(DashboardController.class);
+       private static final Logger policyLogger = FlexLogger.getLogger(DashboardController.class);
        @Autowired
        SystemLogDbDao systemDAO;
        
@@ -86,7 +86,18 @@ public class DashboardController  extends RestrictedBaseController{
        private ArrayList<Object> papStatusData;
        private ArrayList<Object> policyActivityData;
        
+       private PolicyController policyController;
+       public PolicyController getPolicyController() {
+               return policyController;
+       }
 
+       public void setPolicyController(PolicyController policyController) {
+               this.policyController = policyController;
+       }
+       
+       private PolicyController getPolicyControllerInstance(){
+               return policyController != null ? getPolicyController() : new PolicyController();
+       }
        
        @RequestMapping(value={"/get_DashboardLoggingData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
        public void getData(HttpServletRequest request, HttpServletResponse response){
@@ -99,7 +110,7 @@ public class DashboardController  extends RestrictedBaseController{
                        response.getWriter().write(j.toString());
                }
                catch (Exception e){
-                       logger.error("Exception Occured"+e);
+                       policyLogger.error("Exception Occured"+e);
                }
        }
        
@@ -114,7 +125,7 @@ public class DashboardController  extends RestrictedBaseController{
                        response.getWriter().write(j.toString());
                }
                catch (Exception e){
-                       logger.error("Exception Occured"+e);
+                       policyLogger.error("Exception Occured"+e);
                }
        }
        
@@ -131,7 +142,7 @@ public class DashboardController  extends RestrictedBaseController{
                        response.getWriter().write(j.toString());
                }
                catch (Exception e){
-                       logger.error("Exception Occured"+e);
+                       policyLogger.error("Exception Occured"+e);
                }
        }
        
@@ -141,7 +152,8 @@ public class DashboardController  extends RestrictedBaseController{
                        Map<String, Object> model = new HashMap<>();
                        ObjectMapper mapper = new ObjectMapper();
                        mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
-                       this.pdpConatiner = new PDPGroupContainer(PolicyController.getPapEngine());
+                       PolicyController controller = getPolicyControllerInstance();
+                       this.pdpConatiner = new PDPGroupContainer(controller.getPapEngine());
                        addPDPToTable();
                        model.put("pdpTableDatas", mapper.writeValueAsString(pdpStatusData));
                        JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
@@ -149,7 +161,7 @@ public class DashboardController  extends RestrictedBaseController{
                        response.getWriter().write(j.toString());
                }
                catch (Exception e){
-                       logger.error("Exception Occured"+e);
+                       policyLogger.error("Exception Occured"+e);
                }
        }
        
@@ -159,7 +171,8 @@ public class DashboardController  extends RestrictedBaseController{
                        Map<String, Object> model = new HashMap<>();
                        ObjectMapper mapper = new ObjectMapper();
                        mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
-                       this.pdpConatiner = new PDPGroupContainer(PolicyController.getPapEngine());
+                       PolicyController controller = getPolicyControllerInstance();
+                       this.pdpConatiner = new PDPGroupContainer(controller.getPapEngine());
                        addPolicyToTable();
                        model.put("policyActivityTableDatas", mapper.writeValueAsString(policyActivityData));
                        JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
@@ -167,7 +180,7 @@ public class DashboardController  extends RestrictedBaseController{
                        response.getWriter().write(j.toString());
                }
                catch (Exception e){
-                       logger.error("Exception Occured"+e);
+                       policyLogger.error("Exception Occured"+e);
                }
        }
        
@@ -178,7 +191,8 @@ public class DashboardController  extends RestrictedBaseController{
                papStatusData = new ArrayList<>();
                String papStatus = null;
                try {
-                       Set<EcompPDPGroup> groups = PolicyController.getPapEngine().getEcompPDPGroups();
+                       PolicyController controller = getPolicyControllerInstance();
+                       Set<EcompPDPGroup> groups = controller.getPapEngine().getEcompPDPGroups();
                        if (groups == null) {
                                papStatus = "UNKNOWN";
                                throw new PAPException("PAP not running");              
@@ -187,7 +201,7 @@ public class DashboardController  extends RestrictedBaseController{
                        }
                } catch (PAPException | NullPointerException e1) {
                        papStatus = "CANNOT_CONNECT";
-                       logger.error("Error getting PAP status, PAP not responding to requests");
+                       policyLogger.error("Error getting PAP status, PAP not responding to requests", e1);
                }
                String papURL = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL);
                JSONObject object = new JSONObject();
@@ -215,11 +229,12 @@ public class DashboardController  extends RestrictedBaseController{
                                if (pdp.getStatus().getStatus().toString() == "UP_TO_DATE" && ((EcompPDP) pdp).getJmxPort() != 0){
                                        String pdpIpAddress = parseIPSystem(pdp.getId());
                                        int port = ((EcompPDP) pdp).getJmxPort();
-                                       if (port != 0)
-                                       logger.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 (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();
@@ -265,7 +280,7 @@ public class DashboardController  extends RestrictedBaseController{
        @SuppressWarnings({ "rawtypes", "unchecked" })
        private long getRequestCounts(String host, int port, String jmxAttribute) {
                
-               logger.debug("Create an RMI connector client and connect it to the JMX connector server");
+               policyLogger.debug("Create an RMI connector client and connect it to the JMX connector server");
                HashMap map = new HashMap();
                map = null;
                JMXConnector jmxConnection;
@@ -274,23 +289,23 @@ public class DashboardController  extends RestrictedBaseController{
                        jmxConnection.connect();
                        Object o = jmxConnection.getMBeanServerConnection().getAttribute(new ObjectName("PdpRest:type=PdpRestMonitor"), jmxAttribute);
                        jmxConnection.close();
-                       logger.debug("pdpEvaluationNA value retreived: " + o);
+                       policyLogger.debug("pdpEvaluationNA value retreived: " + o);
                        return (long) o;
                } catch (MalformedURLException e) {
-                       logger.error("MalformedURLException for JMX connection");
+                       policyLogger.error("MalformedURLException for JMX connection" , e);
                } catch (IOException e) {
-                       logger.error("Error in reteriving" + jmxAttribute + " from JMX connection");
+                       policyLogger.error("Error in reteriving" + jmxAttribute + " from JMX connection", e);
                } catch (AttributeNotFoundException e) {                
-                       logger.error("AttributeNotFoundException  " + jmxAttribute +  " for JMX connection");
+                       policyLogger.error("AttributeNotFoundException  " + jmxAttribute +  " for JMX connection", e);
                } catch (InstanceNotFoundException e) {
-                       logger.error("InstanceNotFoundException " + host + " for JMX connection");
+                       policyLogger.error("InstanceNotFoundException " + host + " for JMX connection", e);
                } catch (MalformedObjectNameException e) {
-                       logger.error("MalformedObjectNameException for JMX connection");
+                       policyLogger.error("MalformedObjectNameException for JMX connection", e);
                } catch (MBeanException e) {
-                       logger.error("MBeanException for JMX connection");
-                       logger.error("Exception Occured"+e);
+                       policyLogger.error("MBeanException for JMX connection");
+                       policyLogger.error("Exception Occured"+e);
                } catch (ReflectionException e) {
-                       logger.error("ReflectionException for JMX connection");
+                       policyLogger.error("ReflectionException for JMX connection", e);
                }
                
                return -1;
@@ -318,7 +333,7 @@ public class DashboardController  extends RestrictedBaseController{
                                try{
                                        policyMap.put(policy.getPolicyId().replace(" ", ""), policy.getId());
                                }catch(Exception e){
-                                       logger.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID+policy.getName() +e);
+                                       policyLogger.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID+policy.getName() +e);
                                }
                        }
                        
@@ -372,7 +387,7 @@ public class DashboardController  extends RestrictedBaseController{
         */
        @SuppressWarnings({ "rawtypes", "unchecked" })
        private Object getPolicy(String host, int port, String jmxAttribute){
-               logger.debug("Create an RMI connector client and connect it to the JMX connector server for Policy: " + host);
+               policyLogger.debug("Create an RMI connector client and connect it to the JMX connector server for Policy: " + host);
                HashMap map = new HashMap();
                map = null;
                JMXConnector jmxConnection;
@@ -381,23 +396,23 @@ public class DashboardController  extends RestrictedBaseController{
                        jmxConnection.connect();
                        Object o = jmxConnection.getMBeanServerConnection().getAttribute(new ObjectName("PdpRest:type=PdpRestMonitor"), "policyMap");
                        jmxConnection.close();
-                       logger.debug("policyMap value retreived: " + o);
+                       policyLogger.debug("policyMap value retreived: " + o);
                        return  o;
                } catch (MalformedURLException e) {
-                       logger.error("MalformedURLException for JMX connection");
+                       policyLogger.error("MalformedURLException for JMX connection");
                } catch (IOException e) {
-                       logger.error("AttributeNotFoundException for policyMap" );
+                       policyLogger.error("AttributeNotFoundException for policyMap" );
                } catch (AttributeNotFoundException e) {                
-                       logger.error("AttributeNotFoundException for JMX connection");
+                       policyLogger.error("AttributeNotFoundException for JMX connection");
                } catch (InstanceNotFoundException e) {
-                       logger.error("InstanceNotFoundException " + host + " for JMX connection");
+                       policyLogger.error("InstanceNotFoundException " + host + " for JMX connection");
                } catch (MalformedObjectNameException e) {
-                       logger.error("MalformedObjectNameException for JMX connection");
+                       policyLogger.error("MalformedObjectNameException for JMX connection");
                } catch (MBeanException e) {
-                       logger.error("MBeanException for JMX connection");
-                       logger.error("Exception Occured"+e);
+                       policyLogger.error("MBeanException for JMX connection");
+                       policyLogger.error("Exception Occured"+e);
                } catch (ReflectionException e) {
-                       logger.error("ReflectionException for JMX connection");
+                       policyLogger.error("ReflectionException for JMX connection");
                }
                
                return null;