Consolidate PolicyRestAdapter setup
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / elk / client / ElkConnector.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.pap.xacml.rest.elk.client;
22
23 import io.searchbox.client.JestResult;
24
25 import java.util.Map;
26
27 import org.onap.policy.rest.adapter.PolicyRestAdapter;
28
29 public interface ElkConnector {
30
31     public static final String ELK_URL = "http://localhost:9200";
32     public static final String ELK_INDEX_POLICY = "policy";
33
34     public enum PolicyIndexType {
35         config, action, decision, closedloop, all,
36     }
37
38     public enum PolicyType {
39         Config, Action, Decision, Config_Fault, Config_PM, Config_FW, Config_MS, Config_OOF, none,
40     }
41
42     public enum PolicyBodyType {
43         json, xml, properties, txt, none,
44     }
45
46     public boolean delete(PolicyRestAdapter policyData) throws IllegalStateException;
47
48     public JestResult search(PolicyIndexType type, String text) throws IllegalStateException, IllegalArgumentException;
49
50     public JestResult search(PolicyIndexType type, String text, Map<String, String> searchKeyValue)
51             throws IllegalStateException, IllegalArgumentException;
52
53     public boolean update(PolicyRestAdapter policyData) throws IllegalStateException;
54
55     public ElkConnector singleton = new ElkConnectorImpl();
56
57     public static PolicyIndexType toPolicyIndexType(String policyName) throws IllegalArgumentException {
58         if (policyName == null)
59             throw new IllegalArgumentException("Unsupported NULL policy name conversion");
60
61         if (policyName.startsWith("Config_Fault")) {
62             return PolicyIndexType.closedloop;
63         } else if (policyName.startsWith("Config_PM")) {
64             return PolicyIndexType.closedloop;
65         } else if (policyName.startsWith("Config_FW")) {
66             return PolicyIndexType.config;
67         } else if (policyName.startsWith("Config_MS")) {
68             return PolicyIndexType.config;
69         } else if (policyName.startsWith("Config_OOF")) {
70             return PolicyIndexType.config;
71         } else if (policyName.startsWith("Action")) {
72             return PolicyIndexType.action;
73         } else if (policyName.startsWith("Decision")) {
74             return PolicyIndexType.decision;
75         } else if (policyName.startsWith("Config")) {
76             return PolicyIndexType.config;
77         } else {
78             throw new IllegalArgumentException("Unsupported policy name conversion to index: " + policyName);
79         }
80     }
81
82 }