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=4b6e2485afeff88fb8f768d7c497e0295bfaa989;hb=af62330fbd26c576564a4170b2ff271ca606ee93;hp=13507d67731e6c5287b9c1e7985acd3eaa7f4b9e;hpb=580d4ce637b1c09b3bd2258b0b9c8332b8789bad;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 13507d6..4b6e248 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-2021 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,51 +15,54 @@ */ package org.onap.holmes.rulemgt.bolt.enginebolt; -import java.util.HashMap; -import javax.ws.rs.core.MediaType; -import lombok.extern.slf4j.Slf4j; -import org.apache.http.HttpResponse; -import org.apache.http.entity.StringEntity; import org.jvnet.hk2.annotations.Service; -import org.onap.holmes.common.utils.GsonUtil; -import org.onap.holmes.common.utils.HttpsUtils; +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.onap.holmes.common.config.MicroServiceConfig; -@Slf4j +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.MediaType; + +import static org.onap.holmes.rulemgt.constant.RuleMgtConstant.ENGINE_PATH; + @Service public class EngineService { - private static final String PREFIX = "https://"; - private static final String PORT = ":9102"; + private static final String PORT = "9102"; + private static final String SEP = "//"; + private static final String COLON = ":"; + + protected boolean delete(String packageName, String ip) { + return JerseyClient.newInstance() + .path(packageName) + .delete(getUrl(ip)) != null; + } - protected HttpResponse delete(String packageName, String ip) throws Exception { - HashMap headers = createHeaders(); - String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH + "/" + packageName; - return HttpsUtils.delete(url, headers); + protected boolean check(CorrelationCheckRule4Engine correlationCheckRule4Engine, String ip) { + return JerseyClient.newInstance() + .header("Accept", MediaType.APPLICATION_JSON) + .post(getUrl(ip), Entity.json(correlationCheckRule4Engine)) != null; } - protected HttpResponse check(CorrelationCheckRule4Engine correlationCheckRule4Engine, String ip) - throws Exception { - String content = GsonUtil.beanToJson(correlationCheckRule4Engine); - HashMap headers = createHeaders(); - String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH; - return HttpsUtils.post(url, headers, new HashMap<>(), new StringEntity(content)); + protected String deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine, String ip) { + return JerseyClient.newInstance() + .header("Accept", MediaType.APPLICATION_JSON) + .put(getUrl(ip), Entity.json(correlationDeployRule4Engine)); } - protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine, String ip) throws Exception { - String content = GsonUtil.beanToJson(correlationDeployRule4Engine); - HashMap headers = createHeaders(); - String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH; - return HttpsUtils.put(url, headers, new HashMap<>(), new StringEntity(content)); + private String getRequestPref() { + return CommonUtils.isHttpsEnabled() ? JerseyClient.PROTOCOL_HTTPS : JerseyClient.PROTOCOL_HTTP; } - private HashMap createHeaders() { - HashMap headers = new HashMap<>(); - headers.put("Content-Type", MediaType.APPLICATION_JSON); - headers.put("Accept", MediaType.APPLICATION_JSON); - return headers; + private String getUrl(String ip) { + return new StringBuilder(getRequestPref()) + .append(COLON) + .append(SEP) + .append(ip) + .append(COLON) + .append(PORT) + .append(ENGINE_PATH) + .toString(); } }