d64b717630e37e25f211b740def0a8f3f86a7b92
[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
24 import io.searchbox.client.JestResult;
25 import java.util.Map;
26 import org.onap.policy.rest.adapter.PolicyRestAdapter;
27
28 public interface ElkConnector {
29
30     public static final String ELK_URL = "http://localhost:9200";
31     public static final String ELK_INDEX_POLICY = "policy";
32
33     public enum PolicyIndexType {
34         config, action, decision, closedloop, all,
35     }
36
37     public enum PolicyType {
38         Config, Action, Decision, Config_Fault, Config_PM, Config_FW, Config_MS, Config_OOF, none,
39     }
40
41     public enum PolicyBodyType {
42         json, xml, properties, txt, none,
43     }
44
45     public boolean delete(PolicyRestAdapter policyData) throws IllegalStateException;
46
47     public JestResult search(PolicyIndexType type, String text)
48             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)
58             throws IllegalArgumentException {
59         if (policyName == null)
60             throw new IllegalArgumentException("Unsupported NULL policy name conversion");
61
62         if (policyName.startsWith("Config_Fault")) {
63             return PolicyIndexType.closedloop;
64         } else if (policyName.startsWith("Config_PM")) {
65             return PolicyIndexType.closedloop;
66         } else if (policyName.startsWith("Config_FW")) {
67             return PolicyIndexType.config;
68         } else if (policyName.startsWith("Config_MS")) {
69             return PolicyIndexType.config;
70         } else if (policyName.startsWith("Config_OOF")) {
71             return PolicyIndexType.config;
72         } else if (policyName.startsWith("Action")) {
73             return PolicyIndexType.action;
74         } else if (policyName.startsWith("Decision")) {
75             return PolicyIndexType.decision;
76         } else if (policyName.startsWith("Config")) {
77             return PolicyIndexType.config;
78         } else {
79             throw new IllegalArgumentException(
80                     "Unsupported policy name conversion to index: " + policyName);
81         }
82     }
83
84 }