Policy 1707 commit to LF
[policy/engine.git] / ECOMP-PAP-REST / src / main / java / org / openecomp / policy / pap / xacml / rest / elk / client / ElkConnector.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP-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.openecomp.policy.pap.xacml.rest.elk.client;
21
22
23 import java.util.ArrayList;
24
25 import org.openecomp.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 JestResult policy(String policyId) 
62                    throws IllegalStateException, IllegalArgumentException;
63         
64         public boolean delete(PolicyRestAdapter policyData)
65                         throws IllegalStateException;
66
67         public ArrayList<PolicyLocator> policyLocators(PolicyIndexType type, String text,int connector)
68                    throws IllegalStateException, IllegalArgumentException;
69         
70         public ArrayList<PolicyLocator> policyLocators(PolicyIndexType type, String text, 
71                                                                ArrayList<Pair<ArrayList<String>,ArrayList<String>>> filter_s,int connector)
72                    throws IllegalStateException, IllegalArgumentException;
73
74         public JestResult search(PolicyIndexType type, String text) 
75                    throws IllegalStateException, IllegalArgumentException;
76         
77         public JestResult search(PolicyIndexType type, String text, 
78                                          ArrayList<Pair<ArrayList<String>,ArrayList<String>>> filter_s) 
79                            throws IllegalStateException, IllegalArgumentException;
80         
81         public boolean update(PolicyRestAdapter policyData) throws IllegalStateException;
82         
83         public ElkConnector singleton = new ElkConnectorImpl();
84         
85         public static PolicyIndexType toPolicyIndexType(PolicyType type) 
86                throws IllegalArgumentException {
87                 if (type == null)
88                         throw new IllegalArgumentException("Unsupported NULL type conversion");
89                 
90                 switch(type) {
91                 case Config:
92                         return PolicyIndexType.config;
93                 case Action:
94                         return PolicyIndexType.action;
95                 case Decision:
96                         return PolicyIndexType.decision;
97                 case Config_Fault:
98                         return PolicyIndexType.closedloop;
99                 case Config_PM:
100                         return PolicyIndexType.closedloop;
101                 case Config_FW:
102                         return PolicyIndexType.config;
103                 case Config_MS:
104                         return PolicyIndexType.config;
105                 case none:
106                         return PolicyIndexType.all;
107                 default:
108                         throw new IllegalArgumentException("Unsupported type conversion to index: " + type.name());
109                 }
110         }
111         
112         public static PolicyIndexType toPolicyIndexType(String policyName) 
113                        throws IllegalArgumentException {
114                         if (policyName == null)
115                                 throw new IllegalArgumentException("Unsupported NULL policy name conversion");
116                         
117                         if (policyName.startsWith("Config_Fault")) {
118                                 return PolicyIndexType.closedloop;
119                         } else if (policyName.startsWith("Config_PM")) {
120                                 return PolicyIndexType.closedloop;
121                         } else if (policyName.startsWith("Config_FW")) {
122                                 return PolicyIndexType.config;
123                         } else if (policyName.startsWith("Config_MS")) {
124                                 return PolicyIndexType.config;
125                         }else if (policyName.startsWith("Action")) {
126                                 return PolicyIndexType.action;
127                         } else if (policyName.startsWith("Decision")) {
128                                 return PolicyIndexType.decision;
129                         } else if (policyName.startsWith("Config")) {
130                                 return PolicyIndexType.config;
131                         } else {
132                                 throw new IllegalArgumentException
133                                                         ("Unsupported policy name conversion to index: " + 
134                                              policyName);
135                         }
136         }
137         
138         public static PolicyType toPolicyType(String policyName) 
139                        throws IllegalArgumentException {
140                 if (policyName == null)
141                         throw new IllegalArgumentException("Unsupported NULL policy name conversion to Policy Type");
142                 
143                 if (policyName.startsWith("Config_Fault")) {
144                         return PolicyType.Config_Fault;
145                 } else if (policyName.startsWith("Config_PM")) {
146                         return PolicyType.Config_PM;
147                 } else if (policyName.startsWith("Config_FW")) {
148                         return PolicyType.Config_FW;
149                 } else if (policyName.startsWith("Config_MS")) {
150                         return PolicyType.Config_MS;
151                 }else if (policyName.startsWith("Action")) {
152                         return PolicyType.Action;
153                 } else if (policyName.startsWith("Decision")) {
154                         return PolicyType.Decision;
155                 } else if (policyName.startsWith("Config")) {
156                         return PolicyType.Config;
157                 } else {
158                         throw new IllegalArgumentException
159                                                 ("Unsupported policy name conversion to index: " + 
160                                      policyName);
161                 }
162         }
163         
164 }