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=5dc97b4f2cb19ca12c0fbf580c6273c7817e2973;hpb=3893b89844f0e76d1a80c578216c4320fac65ed9;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 5dc97b4..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,52 +15,54 @@ */ package org.onap.holmes.rulemgt.bolt.enginebolt; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.IOException; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import lombok.extern.slf4j.Slf4j; -import org.glassfish.jersey.client.ClientConfig; import org.jvnet.hk2.annotations.Service; +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 { - protected Response delete(String packageName) throws IOException { - Client client = createClient(); - WebTarget webTarget = client - .target(MicroServiceConfig.getMsbServerAddrWithHttpPrefix() + RuleMgtConstant.ENGINE_PATH + "/" + packageName); - return webTarget.request(MediaType.APPLICATION_JSON).delete(); + 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 boolean check(CorrelationCheckRule4Engine correlationCheckRule4Engine, String ip) { + return JerseyClient.newInstance() + .header("Accept", MediaType.APPLICATION_JSON) + .post(getUrl(ip), Entity.json(correlationCheckRule4Engine)) != null; } - private Client createClient() { - ClientConfig clientConfig = new ClientConfig(); - return ClientBuilder.newClient(clientConfig); + protected String deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine, String ip) { + return JerseyClient.newInstance() + .header("Accept", MediaType.APPLICATION_JSON) + .put(getUrl(ip), Entity.json(correlationDeployRule4Engine)); } - protected Response check(CorrelationCheckRule4Engine correlationCheckRule4Engine) - throws IOException { - Client client = createClient(); - ObjectMapper mapper = new ObjectMapper(); - String content = mapper.writeValueAsString(correlationCheckRule4Engine); - WebTarget webTarget = client.target(MicroServiceConfig.getMsbServerAddrWithHttpPrefix() + RuleMgtConstant.ENGINE_PATH); - return webTarget.request(MediaType.APPLICATION_JSON).post(Entity.entity(content, MediaType.APPLICATION_JSON)); + private String getRequestPref() { + return CommonUtils.isHttpsEnabled() ? JerseyClient.PROTOCOL_HTTPS : JerseyClient.PROTOCOL_HTTP; } - protected Response deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine) throws IOException { - Client client = createClient(); - ObjectMapper mapper = new ObjectMapper(); - String content = mapper.writeValueAsString(correlationDeployRule4Engine); - WebTarget webTarget = client.target(MicroServiceConfig.getMsbServerAddrWithHttpPrefix() + RuleMgtConstant.ENGINE_PATH); - return webTarget.request(MediaType.APPLICATION_JSON).put(Entity.entity(content, MediaType.APPLICATION_JSON)); + private String getUrl(String ip) { + return new StringBuilder(getRequestPref()) + .append(COLON) + .append(SEP) + .append(ip) + .append(COLON) + .append(PORT) + .append(ENGINE_PATH) + .toString(); } }