From fc5c07705edc4dcb7083b39116a43844bb6a1490 Mon Sep 17 00:00:00 2001 From: Ravindra Bakkamanthala Date: Mon, 5 Jun 2017 22:42:02 -0400 Subject: Fixed the Policy API issues and Bugfixes Change-Id: I6e8b54442421b6ebd0ff88426fc6e5f3a36b0690 Signed-off-by: Ravindra Bakkamanthala --- .../policyEngine/ClosedLoopPolicyClient.java | 26 ++++++++++++-------- .../ClosedLoopPolicyPerformanceMetricClient.java | 22 ++++++++++------- .../policyEngine/ConfigFirewallPolicyClient.java | 28 ++++++++++++---------- .../policyEngine/MicroServicesPolicyClient.java | 22 ++++++++++------- 4 files changed, 59 insertions(+), 39 deletions(-) (limited to 'PolicyEngineClient') diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyClient.java index 4f0926cca..a54030b94 100644 --- a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyClient.java +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyClient.java @@ -23,6 +23,7 @@ package org.openecomp.policyEngine; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.nio.file.Path; @@ -49,20 +50,26 @@ public class ClosedLoopPolicyClient { //Builds JSONObject from File private static JsonObject buildJSON(File jsonInput, String jsonString) throws FileNotFoundException { JsonObject json = null;; - + JsonReader jsonReader = null; if (jsonString != null && jsonInput == null) { StringReader in = null; in = new StringReader(jsonString); - JsonReader jsonReader = Json.createReader(in); + jsonReader = Json.createReader(in); json = jsonReader.readObject(); - } - else { + in.close(); + }else { InputStream in = null; in = new FileInputStream(jsonInput); - JsonReader jsonReader = Json.createReader(in); + jsonReader = Json.createReader(in); json = jsonReader.readObject(); + try { + in.close(); + } catch (IOException e) { + System.err.println("Exception Occured while closing input stream"+e); + } } - + jsonReader.close(); + return json; } public static void main(String[] args) { @@ -78,10 +85,9 @@ public class ClosedLoopPolicyClient { // Set up Micro Services Attributes File jsonFile = null; String MSjsonString= null; - if (MSjsonString == null) { - Path file = Paths.get("C:\\policyAPI\\ClosedLoopJSON\\faultTestJson.json"); - jsonFile = file.toFile(); - } + Path file = Paths.get("C:\\policyAPI\\ClosedLoopJSON\\faultTestJson.json"); + jsonFile = file.toFile(); + policyParameters.setConfigBody(buildJSON(jsonFile, MSjsonString).toString()); policyParameters.setConfigBodyType(PolicyType.JSON); diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyPerformanceMetricClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyPerformanceMetricClient.java index 6357cea5a..9564cdefe 100644 --- a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyPerformanceMetricClient.java +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyPerformanceMetricClient.java @@ -23,6 +23,7 @@ package org.openecomp.policyEngine; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.nio.file.Path; @@ -50,20 +51,26 @@ public class ClosedLoopPolicyPerformanceMetricClient { //Builds JSONObject from File private static JsonObject buildJSON(File jsonInput, String jsonString) throws FileNotFoundException { JsonObject json = null;; - + JsonReader jsonReader = null; if (jsonString != null && jsonInput == null) { StringReader in = null; in = new StringReader(jsonString); - JsonReader jsonReader = Json.createReader(in); + jsonReader = Json.createReader(in); json = jsonReader.readObject(); + in.close(); } else { InputStream in = null; in = new FileInputStream(jsonInput); - JsonReader jsonReader = Json.createReader(in); + jsonReader = Json.createReader(in); json = jsonReader.readObject(); + try { + in.close(); + } catch (IOException e) { + System.err.println("Exception Occured while closing input stream"+e); + } } - + jsonReader.close(); return json; } @@ -80,10 +87,9 @@ public class ClosedLoopPolicyPerformanceMetricClient { // Set up Micro Services Attributes File jsonFile = null; String MSjsonString= null; - if (MSjsonString == null) { - Path file = Paths.get("C:\\policyAPI\\ClosedLoopJSON\\pmTestJson.json"); - jsonFile = file.toFile(); - } + Path file = Paths.get("C:\\policyAPI\\ClosedLoopJSON\\pmTestJson.json"); + jsonFile = file.toFile(); + policyParameters.setConfigBody(buildJSON(jsonFile, MSjsonString).toString()); policyParameters.setConfigBodyType(PolicyType.JSON); diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ConfigFirewallPolicyClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ConfigFirewallPolicyClient.java index 5c6752bd5..a6b3119f9 100644 --- a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ConfigFirewallPolicyClient.java +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ConfigFirewallPolicyClient.java @@ -23,6 +23,7 @@ package org.openecomp.policyEngine; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.nio.file.Path; @@ -65,10 +66,9 @@ public class ConfigFirewallPolicyClient { policyParameters.setRiskType("PROD"); File jsonFile = null; String jsonRuleList = null; - if (jsonRuleList == null) { - Path file = Paths.get("C:\\policyAPI\\firewallRulesJSON\\Config_FW_1607Rule.json"); - jsonFile = file.toFile(); - } + Path file = Paths.get("C:\\policyAPI\\firewallRulesJSON\\Config_FW_1607Rule.json"); + jsonFile = file.toFile(); + //buildJSON(jsonFile, jsonRuleList); policyParameters.setConfigBody(buildJSON(jsonFile, jsonRuleList).toString()); policyParameters.setConfigBodyType(PolicyType.JSON); @@ -93,24 +93,26 @@ public class ConfigFirewallPolicyClient { } private static JsonObject buildJSON(File jsonInput, String jsonString) throws FileNotFoundException { - JsonObject json = null;; + JsonObject json = null; + JsonReader jsonReader = null; if (jsonString != null && jsonInput == null) { StringReader in = null; - in = new StringReader(jsonString); - - JsonReader jsonReader = Json.createReader(in); + jsonReader = Json.createReader(in); json = jsonReader.readObject(); - - + in.close(); } else { InputStream in = null; in = new FileInputStream(jsonInput); - - JsonReader jsonReader = Json.createReader(in); + jsonReader = Json.createReader(in); json = jsonReader.readObject(); + try { + in.close(); + } catch (IOException e) { + System.err.println("Exception Occured while closing input stream"+e); + } } - + jsonReader.close(); return json; } diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/MicroServicesPolicyClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/MicroServicesPolicyClient.java index 4021c9432..4c6756a5b 100644 --- a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/MicroServicesPolicyClient.java +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/MicroServicesPolicyClient.java @@ -23,6 +23,7 @@ package org.openecomp.policyEngine; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.nio.file.Path; @@ -48,20 +49,26 @@ static Boolean isEdit = false; //Builds JSONObject from File private static JsonObject buildJSON(File jsonInput, String jsonString) throws FileNotFoundException { JsonObject json = null;; - + JsonReader jsonReader = null; if (jsonString != null && jsonInput == null) { StringReader in = null; in = new StringReader(jsonString); - JsonReader jsonReader = Json.createReader(in); + jsonReader = Json.createReader(in); json = jsonReader.readObject(); + in.close(); } else { InputStream in = null; in = new FileInputStream(jsonInput); - JsonReader jsonReader = Json.createReader(in); + jsonReader = Json.createReader(in); json = jsonReader.readObject(); + try { + in.close(); + } catch (IOException e) { + System.err.println("Exception Occured while closing input stream"+e); + } } - + jsonReader.close(); return json; } public static void main(String[] args) { @@ -80,10 +87,9 @@ public static void main(String[] args) { // Set up Micro Services Attributes File jsonFile = null; String MSjsonString= null; - if (MSjsonString == null) { - Path file = Paths.get("C:\\policyAPI\\MicroServicesJSON\\testStringMatching.json"); - jsonFile = file.toFile(); - } + Path file = Paths.get("C:\\policyAPI\\MicroServicesJSON\\testStringMatching.json"); + jsonFile = file.toFile(); + policyParameters.setConfigBody(buildJSON(jsonFile, MSjsonString).toString()); policyParameters.setConfigBodyType(PolicyType.JSON); -- cgit 1.2.3-korg