319347e02cb1580bff82cf078a647a7ea16613a5
[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     protected HttpResponse delete(String packageName) throws Exception {\r
36         HashMap headers = createHeaders();\r
37         String url = MicroServiceConfig.getMsbServerAddrWithHttpPrefix() + RuleMgtConstant.ENGINE_PATH + "/" + packageName;\r
38         return HttpsUtils.delete(url, headers);\r
39     }\r
40 \r
41     protected HttpResponse check(CorrelationCheckRule4Engine correlationCheckRule4Engine)\r
42             throws Exception {\r
43         String content = GsonUtil.beanToJson(correlationCheckRule4Engine);\r
44         HashMap headers = createHeaders();\r
45         String url = MicroServiceConfig.getMsbServerAddrWithHttpPrefix() + RuleMgtConstant.ENGINE_PATH;\r
46         return HttpsUtils.post(url, headers, new HashMap<>(), new StringEntity(content));\r
47     }\r
48 \r
49     protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine) throws Exception {\r
50         String content = GsonUtil.beanToJson(correlationDeployRule4Engine);\r
51         HashMap headers = createHeaders();\r
52         String url = MicroServiceConfig.getMsbServerAddrWithHttpPrefix() + RuleMgtConstant.ENGINE_PATH;\r
53         return HttpsUtils.put(url, headers, new HashMap<>(), new StringEntity(content));\r
54     }\r
55 \r
56     private HashMap<String, String> createHeaders() {\r
57         HashMap<String, String> headers = new HashMap<>();\r
58         headers.put("Content-Type", MediaType.APPLICATION_JSON);\r
59         headers.put("Accept", MediaType.APPLICATION_JSON);\r
60         return headers;\r
61     }\r
62 }\r