Removed Dependency: httpclient
[holmes/rule-management.git] / rulemgt / src / main / java / org / onap / holmes / rulemgt / bolt / enginebolt / EngineWrapper.java
index 183e52f..7c927c0 100644 (file)
@@ -1,12 +1,12 @@
 /**\r
- * Copyright 2017 ZTE Corporation.\r
- *\r
+ * Copyright 2017-2021 ZTE Corporation.\r
+ * <p>\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
+ * <p>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p>\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
  */\r
 package org.onap.holmes.rulemgt.bolt.enginebolt;\r
 \r
-import javax.inject.Inject;\r
+import com.google.gson.JsonObject;\r
+import com.google.gson.JsonParser;\r
 import lombok.extern.slf4j.Slf4j;\r
-import net.sf.json.JSONObject;\r
-import org.apache.http.HttpResponse;\r
 import org.jvnet.hk2.annotations.Service;\r
-import org.onap.holmes.common.utils.HttpsUtils;\r
+import org.onap.holmes.common.exception.CorrelationException;\r
 import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
 import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
 import org.onap.holmes.rulemgt.constant.RuleMgtConstant;\r
-import org.onap.holmes.common.exception.CorrelationException;\r
+\r
+import javax.inject.Inject;\r
 \r
 @Service\r
 @Slf4j\r
@@ -33,18 +33,12 @@ public class EngineWrapper {
     @Inject\r
     private EngineService engineService;\r
 \r
-    public String deployEngine(CorrelationDeployRule4Engine correlationRule) throws CorrelationException {\r
-        HttpResponse response;\r
-        try {\r
-            response = engineService.deploy(correlationRule);\r
-        } catch (Exception e) {\r
-            throw new CorrelationException("Failed to call the rule deployment RESTful API.", e);\r
-        }\r
-        if (response.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
-            log.info("Succeeded in calling the rule deployment RESTful API from the engine management service.");\r
+    public String deployEngine(CorrelationDeployRule4Engine correlationRule, String ip) throws CorrelationException {\r
+        String response = engineService.deploy(correlationRule, ip);\r
+        if (response != null) {\r
             try {\r
-                JSONObject json = JSONObject.fromObject(HttpsUtils.extractResponseEntity(response));\r
-                return json.get(RuleMgtConstant.PACKAGE).toString();\r
+                JsonObject json = JsonParser.parseString(response).getAsJsonObject();\r
+                return json.get(RuleMgtConstant.PACKAGE).getAsString();\r
             } catch (Exception e) {\r
                 throw new CorrelationException("Failed to parse the value returned by the engine management service.", e);\r
             }\r
@@ -53,36 +47,20 @@ public class EngineWrapper {
         }\r
     }\r
 \r
-    public boolean deleteRuleFromEngine(String packageName) throws CorrelationException {\r
-        HttpResponse response;\r
-        try {\r
-            response = engineService.delete(packageName);\r
-        } catch (Exception e) {\r
-            throw new CorrelationException("Failed to call the rule deleting RESTful API.", e);\r
-        }\r
-        if (response.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
-            log.info("Succeeded in calling the rule deleting RESTful API from the engine management service.");\r
+    public boolean deleteRuleFromEngine(String packageName, String ip) throws CorrelationException {\r
+        if (engineService.delete(packageName, ip)) {\r
             return true;\r
         } else {\r
             throw new CorrelationException("Failed to delete the rule!");\r
         }\r
     }\r
 \r
-    public boolean checkRuleFromEngine(CorrelationCheckRule4Engine correlationCheckRule4Engine)\r
+    public boolean checkRuleFromEngine(CorrelationCheckRule4Engine correlationCheckRule4Engine, String ip)\r
             throws CorrelationException {\r
         log.info("Rule Contents: " + correlationCheckRule4Engine.getContent());\r
-        HttpResponse response;\r
-        try {\r
-            response = engineService.check(correlationCheckRule4Engine);\r
-        } catch (Exception e) {\r
-            throw new CorrelationException("Failed to call the rule verification RESTful API.", e);\r
-        }\r
-        if (response.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
-            log.info("Succeeded in calling the rule verification RESTful API from the engine management service.");\r
-            return true;\r
-        } else {\r
-            log.info(response.getStatusLine().getStatusCode() + " " + response.getEntity());\r
+        if (!engineService.check(correlationCheckRule4Engine, ip)) {\r
             throw new CorrelationException("Failed to verify the rule. The contents of the rule are invalid.");\r
         }\r
+        return true;\r
     }\r
 }\r