1dea5dd4b024054f148ee440563e708f1c28f12b
[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 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 package org.onap.policy.pap.xacml.rest.elk.client;
21
22
23 import java.util.Map;
24
25 import org.onap.policy.rest.adapter.PolicyRestAdapter;
26
27 import io.searchbox.client.JestResult;
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,
36                 action,
37                 decision,
38                 closedloop,
39                 all,
40         }
41         
42         public enum PolicyType {
43                 Config,
44                 Action,
45                 Decision,
46                 Config_Fault,
47                 Config_PM,
48                 Config_FW,
49                 Config_MS,
50                 none,
51         }
52         
53         public enum PolicyBodyType {
54                 json,
55                 xml,
56                 properties,
57                 txt,
58                 none,
59         }
60
61         public boolean delete(PolicyRestAdapter policyData)
62                         throws IllegalStateException;
63
64         public JestResult search(PolicyIndexType type, String text) 
65                    throws IllegalStateException, IllegalArgumentException;
66         
67         public JestResult search(PolicyIndexType type, String text, 
68                         Map<String, String> searchKeyValue) 
69                            throws IllegalStateException, IllegalArgumentException;
70         
71         public boolean update(PolicyRestAdapter policyData) throws IllegalStateException;
72         
73         public ElkConnector singleton = new ElkConnectorImpl();
74         
75         public static PolicyIndexType toPolicyIndexType(String policyName) 
76                         throws IllegalArgumentException {
77                 if (policyName == null)
78                         throw new IllegalArgumentException("Unsupported NULL policy name conversion");
79
80                 if (policyName.startsWith("Config_Fault")) {
81                         return PolicyIndexType.closedloop;
82                 } else if (policyName.startsWith("Config_PM")) {
83                         return PolicyIndexType.closedloop;
84                 } else if (policyName.startsWith("Config_FW")) {
85                         return PolicyIndexType.config;
86                 } else if (policyName.startsWith("Config_MS")) {
87                         return PolicyIndexType.config;
88                 }else if (policyName.startsWith("Action")) {
89                         return PolicyIndexType.action;
90                 } else if (policyName.startsWith("Decision")) {
91                         return PolicyIndexType.decision;
92                 } else if (policyName.startsWith("Config")) {
93                         return PolicyIndexType.config;
94                 } else {
95                         throw new IllegalArgumentException
96                         ("Unsupported policy name conversion to index: " + 
97                                         policyName);
98                 }
99         }
100         
101 }