*/\r
package org.onap.holmes.rulemgt.bolt.enginebolt;\r
\r
-import com.fasterxml.jackson.databind.ObjectMapper;\r
-import java.io.IOException;\r
-import javax.ws.rs.client.Client;\r
-import javax.ws.rs.client.ClientBuilder;\r
-import javax.ws.rs.client.Entity;\r
-import javax.ws.rs.client.WebTarget;\r
+import java.util.HashMap;\r
import javax.ws.rs.core.MediaType;\r
-import javax.ws.rs.core.Response;\r
import lombok.extern.slf4j.Slf4j;\r
-import org.glassfish.jersey.client.ClientConfig;\r
+import org.apache.http.HttpResponse;\r
+import org.apache.http.entity.StringEntity;\r
import org.jvnet.hk2.annotations.Service;\r
+import org.onap.holmes.common.utils.GsonUtil;\r
+import org.onap.holmes.common.utils.HttpsUtils;\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
@Service\r
public class EngineService {\r
\r
- protected Response delete(String packageName) throws IOException {\r
- Client client = createClient();\r
- WebTarget webTarget = client\r
- .target(MicroServiceConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH + "/" + packageName);\r
- return webTarget.request(MediaType.APPLICATION_JSON).delete();\r
+ private static final String PREFIX = "https://";\r
+ private static final String PORT = ":9102";\r
+\r
+ protected HttpResponse delete(String packageName, String ip) throws Exception {\r
+ HashMap headers = createHeaders();\r
+ String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH + "/" + packageName;\r
+ return HttpsUtils.delete(url, headers);\r
}\r
\r
- private Client createClient() {\r
- ClientConfig clientConfig = new ClientConfig();\r
- return ClientBuilder.newClient(clientConfig);\r
+ protected HttpResponse check(CorrelationCheckRule4Engine correlationCheckRule4Engine, String ip)\r
+ throws Exception {\r
+ String content = GsonUtil.beanToJson(correlationCheckRule4Engine);\r
+ HashMap headers = createHeaders();\r
+ String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH;\r
+ return HttpsUtils.post(url, headers, new HashMap<>(), new StringEntity(content));\r
}\r
\r
- protected Response check(CorrelationCheckRule4Engine correlationCheckRule4Engine)\r
- throws IOException {\r
- Client client = createClient();\r
- ObjectMapper mapper = new ObjectMapper();\r
- String content = mapper.writeValueAsString(correlationCheckRule4Engine);\r
- WebTarget webTarget = client.target(MicroServiceConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH);\r
- return webTarget.request(MediaType.APPLICATION_JSON).post(Entity.entity(content, MediaType.APPLICATION_JSON));\r
+ protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine, String ip) throws Exception {\r
+ String content = GsonUtil.beanToJson(correlationDeployRule4Engine);\r
+ HashMap headers = createHeaders();\r
+ String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH;\r
+ return HttpsUtils.put(url, headers, new HashMap<>(), new StringEntity(content));\r
}\r
\r
- protected Response deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine) throws IOException {\r
- Client client = createClient();\r
- ObjectMapper mapper = new ObjectMapper();\r
- String content = mapper.writeValueAsString(correlationDeployRule4Engine);\r
- WebTarget webTarget = client.target(MicroServiceConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH);\r
- return webTarget.request(MediaType.APPLICATION_JSON).put(Entity.entity(content, MediaType.APPLICATION_JSON));\r
+ private HashMap<String, String> createHeaders() {\r
+ HashMap<String, String> headers = new HashMap<>();\r
+ headers.put("Content-Type", MediaType.APPLICATION_JSON);\r
+ headers.put("Accept", MediaType.APPLICATION_JSON);\r
+ return headers;\r
}\r
}\r