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