2 * Copyright 2017 ZTE Corporation.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
16 package org.onap.holmes.rulemgt.bolt.enginebolt;
\r
18 import java.io.IOException;
\r
19 import java.util.HashMap;
\r
20 import javax.ws.rs.core.MediaType;
\r
21 import lombok.extern.slf4j.Slf4j;
\r
22 import org.apache.http.HttpResponse;
\r
23 import org.apache.http.entity.StringEntity;
\r
24 import org.apache.http.impl.client.CloseableHttpClient;
\r
25 import org.jvnet.hk2.annotations.Service;
\r
26 import org.onap.holmes.common.utils.GsonUtil;
\r
27 import org.onap.holmes.common.utils.HttpsUtils;
\r
28 import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
\r
29 import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
\r
30 import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
\r
31 import org.onap.holmes.common.config.MicroServiceConfig;
\r
35 public class EngineService {
\r
37 private static final String PREFIX = "https://";
\r
38 private static final String PORT = ":9102";
\r
40 protected HttpResponse delete(String packageName, String ip) throws Exception {
\r
41 HashMap headers = createHeaders();
\r
42 String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH + "/" + packageName;
\r
43 CloseableHttpClient httpClient = null;
\r
45 httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);
\r
46 return HttpsUtils.delete(url, headers, httpClient);
\r
48 closeHttpClient(httpClient);
\r
52 protected HttpResponse check(CorrelationCheckRule4Engine correlationCheckRule4Engine, String ip)
\r
54 String content = GsonUtil.beanToJson(correlationCheckRule4Engine);
\r
55 HashMap headers = createHeaders();
\r
56 String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH;
\r
57 CloseableHttpClient httpClient = null;
\r
59 httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);
\r
60 return HttpsUtils.post(url, headers, new HashMap<>(), new StringEntity(content), httpClient);
\r
62 closeHttpClient(httpClient);
\r
66 protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine, String ip) throws Exception {
\r
67 String content = GsonUtil.beanToJson(correlationDeployRule4Engine);
\r
68 HashMap headers = createHeaders();
\r
69 String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH;
\r
70 CloseableHttpClient httpClient = null;
\r
72 httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);
\r
73 return HttpsUtils.put(url, headers, new HashMap<>(), new StringEntity(content),httpClient);
\r
75 closeHttpClient(httpClient);
\r
79 private void closeHttpClient(CloseableHttpClient httpClient) {
\r
80 if (httpClient != null) {
\r
83 } catch (IOException e) {
\r
84 log.warn("Failed to close http client!");
\r
89 private HashMap<String, String> createHeaders() {
\r
90 HashMap<String, String> headers = new HashMap<>();
\r
91 headers.put("Content-Type", MediaType.APPLICATION_JSON);
\r
92 headers.put("Accept", MediaType.APPLICATION_JSON);
\r