Allocate Rule
[holmes/rule-management.git] / rulemgt / src / main / java / org / onap / holmes / rulemgt / bolt / enginebolt / EngineService.java
1 /**\r
2  * Copyright 2017 ZTE Corporation.\r
3  *\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
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\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
15  */\r
16 package org.onap.holmes.rulemgt.bolt.enginebolt;\r
17 \r
18 import java.util.HashMap;\r
19 import javax.ws.rs.core.MediaType;\r
20 import lombok.extern.slf4j.Slf4j;\r
21 import org.apache.http.HttpResponse;\r
22 import org.apache.http.entity.StringEntity;\r
23 import org.jvnet.hk2.annotations.Service;\r
24 import org.onap.holmes.common.utils.GsonUtil;\r
25 import org.onap.holmes.common.utils.HttpsUtils;\r
26 import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
27 import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
28 import org.onap.holmes.rulemgt.constant.RuleMgtConstant;\r
29 import org.onap.holmes.common.config.MicroServiceConfig;\r
30 \r
31 @Slf4j\r
32 @Service\r
33 public class EngineService {\r
34 \r
35     private static final String PREFIX = "https://";\r
36     private static final String PORT = ":9102";\r
37 \r
38     protected HttpResponse delete(String packageName, String ip) throws Exception {\r
39         HashMap headers = createHeaders();\r
40         String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH + "/" + packageName;\r
41         return HttpsUtils.delete(url, headers);\r
42     }\r
43 \r
44     protected HttpResponse check(CorrelationCheckRule4Engine correlationCheckRule4Engine, String ip)\r
45             throws Exception {\r
46         String content = GsonUtil.beanToJson(correlationCheckRule4Engine);\r
47         HashMap headers = createHeaders();\r
48         String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH;\r
49         return HttpsUtils.post(url, headers, new HashMap<>(), new StringEntity(content));\r
50     }\r
51 \r
52     protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine, String ip) throws Exception {\r
53         String content = GsonUtil.beanToJson(correlationDeployRule4Engine);\r
54         HashMap headers = createHeaders();\r
55         String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH;\r
56         return HttpsUtils.put(url, headers, new HashMap<>(), new StringEntity(content));\r
57     }\r
58 \r
59     private HashMap<String, String> createHeaders() {\r
60         HashMap<String, String> headers = new HashMap<>();\r
61         headers.put("Content-Type", MediaType.APPLICATION_JSON);\r
62         headers.put("Accept", MediaType.APPLICATION_JSON);\r
63         return headers;\r
64     }\r
65 }\r