Updated holmes-actions to 1.3.5
[holmes/rule-management.git] / rulemgt / src / main / java / org / onap / holmes / rulemgt / bolt / enginebolt / EngineService.java
1 /**\r
2  * Copyright 2017-2021 ZTE Corporation.\r
3  * <p>\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  * <p>\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  * <p>\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 org.jvnet.hk2.annotations.Service;\r
19 import org.onap.holmes.common.utils.CommonUtils;\r
20 import org.onap.holmes.common.utils.JerseyClient;\r
21 import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
22 import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
23 \r
24 import javax.ws.rs.client.Entity;\r
25 import javax.ws.rs.core.MediaType;\r
26 \r
27 import static org.onap.holmes.rulemgt.constant.RuleMgtConstant.ENGINE_PATH;\r
28 \r
29 @Service\r
30 public class EngineService {\r
31 \r
32     private static final String PORT = "9102";\r
33     private static final String SEP = "//";\r
34     private static final String COLON = ":";\r
35 \r
36     protected boolean delete(String packageName, String ip) {\r
37         return JerseyClient.newInstance()\r
38                 .path(packageName)\r
39                 .delete(getUrl(ip)) != null;\r
40     }\r
41 \r
42     protected boolean check(CorrelationCheckRule4Engine correlationCheckRule4Engine, String ip) {\r
43         return JerseyClient.newInstance()\r
44                 .header("Accept", MediaType.APPLICATION_JSON)\r
45                 .post(getUrl(ip), Entity.json(correlationCheckRule4Engine)) != null;\r
46     }\r
47 \r
48     protected String deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine, String ip) {\r
49         return JerseyClient.newInstance()\r
50                 .header("Accept", MediaType.APPLICATION_JSON)\r
51                 .put(getUrl(ip), Entity.json(correlationDeployRule4Engine));\r
52     }\r
53 \r
54     private String getRequestPref() {\r
55         return CommonUtils.isHttpsEnabled() ? JerseyClient.PROTOCOL_HTTPS : JerseyClient.PROTOCOL_HTTP;\r
56     }\r
57 \r
58     private String getUrl(String ip) {\r
59         return new StringBuilder(getRequestPref())\r
60                 .append(COLON)\r
61                 .append(SEP)\r
62                 .append(ip)\r
63                 .append(COLON)\r
64                 .append(PORT)\r
65                 .append(ENGINE_PATH)\r
66                 .toString();\r
67     }\r
68 }\r