X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=rulemgt%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fholmes%2Frulemgt%2Fbolt%2Fenginebolt%2FEngineService.java;h=0d1dd0562068e9e6254f949789d8a353670f2b57;hb=a796bda2f8e2db093ce9f528f6e5960e4aa1b22c;hp=cc20caba84b9bdc165161e1804e6755863d4a4db;hpb=6e783fe6e2b456486af69bd334aa167409b29fd7;p=holmes%2Frule-management.git diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java index cc20cab..0d1dd05 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java @@ -1,12 +1,12 @@ /** - * Copyright 2017 ZTE Corporation. - * + * Copyright 2017-2022 ZTE Corporation. + *
* 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 - * + *
+ * 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.
@@ -15,93 +15,53 @@
*/
package org.onap.holmes.rulemgt.bolt.enginebolt;
-import java.io.IOException;
-import java.util.HashMap;
-import javax.ws.rs.core.MediaType;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.common.utils.GsonUtil;
-import org.onap.holmes.common.utils.HttpsUtils;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.core.MediaType;
+import org.onap.holmes.common.utils.CommonUtils;
+import org.onap.holmes.common.utils.JerseyClient;
import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
-import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
+import org.springframework.stereotype.Service;
+
+import static org.onap.holmes.rulemgt.constant.RuleMgtConstant.ENGINE_PATH;
-@Slf4j
@Service
public class EngineService {
- private static final String HTTPS = "https://";
- private static final String HTTP = "http://";
- private static final String PORT = ":9102";
-
- protected HttpResponse delete(String packageName, String ip) throws Exception {
- HashMap headers = createHeaders();
- String url = getRequestPref() + ip + PORT + RuleMgtConstant.ENGINE_PATH + "/" + packageName;
- CloseableHttpClient httpClient = null;
- HttpDelete httpDelete = new HttpDelete(url);
- try {
- httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);
- return HttpsUtils.delete(httpDelete, headers, httpClient);
- } finally {
- httpDelete.releaseConnection();
- closeHttpClient(httpClient);
- }
- }
+ private static final String PORT = "9102";
+ private static final String SEP = "//";
+ private static final String COLON = ":";
- protected HttpResponse check(CorrelationCheckRule4Engine correlationCheckRule4Engine, String ip)
- throws Exception {
- String content = GsonUtil.beanToJson(correlationCheckRule4Engine);
- HashMap headers = createHeaders();
- String url = getRequestPref() + ip + PORT + RuleMgtConstant.ENGINE_PATH;
- CloseableHttpClient httpClient = null;
- HttpPost httpPost = new HttpPost(url);
- try {
- httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);
- return HttpsUtils.post(httpPost, headers, new HashMap<>(), new StringEntity(content), httpClient);
- } finally {
- httpPost.releaseConnection();
- closeHttpClient(httpClient);
- }
+ protected boolean delete(String packageName, String ip) {
+ return JerseyClient.newInstance()
+ .path(packageName)
+ .delete(getUrl(ip)) != null;
}
- protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine, String ip) throws Exception {
- String content = GsonUtil.beanToJson(correlationDeployRule4Engine);
- HashMap headers = createHeaders();
- String url = getRequestPref() + ip + PORT + RuleMgtConstant.ENGINE_PATH;
- CloseableHttpClient httpClient = null;
- HttpPut httpPut = new HttpPut(url);
- try {
- httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);
- return HttpsUtils.put(httpPut, headers, new HashMap<>(), new StringEntity(content),httpClient);
- } finally {
- closeHttpClient(httpClient);
- }
+ protected boolean check(CorrelationCheckRule4Engine correlationCheckRule4Engine, String ip) {
+ return JerseyClient.newInstance()
+ .header("Accept", MediaType.APPLICATION_JSON)
+ .post(getUrl(ip), Entity.json(correlationCheckRule4Engine)) != null;
}
- private void closeHttpClient(CloseableHttpClient httpClient) {
- if (httpClient != null) {
- try {
- httpClient.close();
- } catch (IOException e) {
- log.warn("Failed to close http client!");
- }
- }
+ protected String deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine, String ip) {
+ return JerseyClient.newInstance()
+ .header("Accept", MediaType.APPLICATION_JSON)
+ .put(getUrl(ip), Entity.json(correlationDeployRule4Engine));
}
- private HashMap