aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java250
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnector.java12
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImpl.java132
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/Pair.java30
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticData.java179
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java389
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyLocator.java19
7 files changed, 567 insertions, 444 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java
index f04be861b..cfae68091 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java
@@ -21,6 +21,7 @@
package org.onap.policy.pap.xacml.rest.elk.client;
import com.google.gson.Gson;
+
import io.searchbox.client.JestClientFactory;
import io.searchbox.client.config.HttpClientConfig;
import io.searchbox.client.http.JestHttpClient;
@@ -28,6 +29,7 @@ import io.searchbox.core.Bulk;
import io.searchbox.core.Bulk.Builder;
import io.searchbox.core.BulkResult;
import io.searchbox.core.Index;
+
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
@@ -43,6 +45,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
+
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
@@ -50,13 +53,12 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
+
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.utils.PeCryptoUtils;
import org.onap.policy.xacml.util.XACMLPolicyScanner;
-
-
/**
* This code will deals with parsing the XACML content on reading from
* database(PolicyEntity, ConfigurationDataEntity and ActionBodyEntity tables)
@@ -126,54 +128,53 @@ public class ElasticSearchPolicyUpdate {
String policyEntityQuery = "Select * from PolicyEntity";
result = stmt.executeQuery(policyEntityQuery);
- while(result.next()){
+ while (result.next()) {
StringBuilder policyDataString = new StringBuilder("{");
String scope = result.getString("scope");
String policyName = result.getString("policyName");
- if(policyName != null){
- policyDataString.append("\"policyName\":\""+scope+"."+policyName+"\",");
+ if (policyName != null) {
+ policyDataString.append("\"policyName\":\"" + scope + "." + policyName + "\",");
}
String description = result.getString("description");
- if(description != null){
- policyDataString.append("\"policyDescription\":\""+description+"\",");
+ if (description != null) {
+ policyDataString.append("\"policyDescription\":\"" + description + "\",");
}
Object policyData = result.getString("policydata");
- if(scope != null){
- policyDataString.append("\"scope\":\""+scope+"\",");
+ if (scope != null) {
+ policyDataString.append("\"scope\":\"" + scope + "\",");
}
String actionbodyid = result.getString("actionbodyid");
String configurationdataid = result.getString("configurationdataid");
-
String policyWithScopeName = scope + "." + policyName;
String _type = null;
- if(policyWithScopeName.contains(".Config_")){
+ if (policyWithScopeName.contains(".Config_")) {
policyDataString.append("\"policyType\":\"Config\",");
- if(policyWithScopeName.contains(".Config_Fault_")){
+ if (policyWithScopeName.contains(".Config_Fault_")) {
_type = "closedloop";
policyDataString.append("\"configPolicyType\":\"ClosedLoop_Fault\",");
- }else if(policyWithScopeName.contains(".Config_PM_")){
+ } else if (policyWithScopeName.contains(".Config_PM_")) {
_type = "closedloop";
policyDataString.append("\"configPolicyType\":\"ClosedLoop_PM\",");
- }else{
+ } else {
_type = "config";
policyDataString.append("\"configPolicyType\":\"Base\",");
}
- }else if(policyWithScopeName.contains(".Action_")){
+ } else if (policyWithScopeName.contains(".Action_")) {
_type = "action";
policyDataString.append("\"policyType\":\"Action\",");
- }else if(policyWithScopeName.contains(".Decision_")){
+ } else if (policyWithScopeName.contains(".Decision_")) {
_type = "decision";
policyDataString.append("\"policyType\":\"Decision\",");
}
- if(!"decision".equals(_type)){
- if(configurationdataid != null){
+ if (!"decision".equals(_type)) {
+ if (configurationdataid != null) {
updateConfigData(conn, configurationdataid, policyDataString);
}
- if(actionbodyid != null){
+ if (actionbodyid != null) {
updateActionData(conn, actionbodyid, policyDataString);
}
}
@@ -181,72 +182,72 @@ public class ElasticSearchPolicyUpdate {
String _id = policyWithScopeName;
String dataString = constructPolicyData(policyData, policyDataString);
- dataString = dataString.substring(0, dataString.length()-1);
+ dataString = dataString.substring(0, dataString.length() - 1);
dataString = dataString.trim().replace(System.getProperty("line.separator"), "") + "}";
dataString = dataString.replace("null", "\"\"");
dataString = dataString.replaceAll("\n", "");
- try{
+ try {
Gson gson = new Gson();
gson.fromJson(dataString, Object.class);
- }catch(Exception e){
+ } catch (Exception e) {
LOGGER.error(e);
continue;
}
- if("config".equals(_type)){
+ if ("config".equals(_type)) {
listIndex.add(new Index.Builder(dataString).index("policy").type("config").id(_id).build());
- }else if("closedloop".equals(_type)){
+ } else if ("closedloop".equals(_type)) {
listIndex.add(new Index.Builder(dataString).index("policy").type("closedloop").id(_id).build());
- }else if("action".equals(_type)){
+ } else if ("action".equals(_type)) {
listIndex.add(new Index.Builder(dataString).index("policy").type("action").id(_id).build());
- }else if("decision".equals(_type)){
+ } else if ("decision".equals(_type)) {
listIndex.add(new Index.Builder(dataString).index("policy").type("decision").id(_id).build());
}
}
result.close();
bulk = new Bulk.Builder();
- for(int i =0; i < listIndex.size(); i++){
+ for (int i = 0; i < listIndex.size(); i++) {
bulk.addAction(listIndex.get(i));
}
BulkResult searchResult = client.execute(bulk.build());
- if(searchResult.isSucceeded()){
+ if (searchResult.isSucceeded()) {
LOGGER.debug("Success");
- }else{
+ } else {
LOGGER.error("Failure");
}
} catch (Exception e) {
- LOGGER.error("Exception Occured while performing database Operation for Elastic Search Policy Upgrade"+e);
- }finally{
- if(result != null){
- try {
- result.close();
- } catch (Exception e) {
- LOGGER.error("Exception Occured while closing the resultset"+e);
- }
+ LOGGER.error("Exception Occured while performing database Operation for Elastic Search Policy Upgrade" + e);
+ } finally {
+ if (result != null) {
+ try {
+ result.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the resultset" + e);
}
- if(stmt != null){
- try {
- stmt.close();
- } catch (Exception e) {
- LOGGER.error("Exception Occured while closing the statement"+e);
- }
+ }
+ if (stmt != null) {
+ try {
+ stmt.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the statement" + e);
}
- if(conn != null){
+ }
+ if (conn != null) {
try {
conn.close();
} catch (Exception e) {
- LOGGER.error("Exception Occured while closing the connection"+e);
+ LOGGER.error("Exception Occured while closing the connection" + e);
}
}
}
}
- public static String constructPolicyData(Object policyContent, StringBuilder policyDataString){
+ public static String constructPolicyData(Object policyContent, StringBuilder policyDataString) {
InputStream stream = new ByteArrayInputStream(policyContent.toString().getBytes(StandardCharsets.UTF_8));
Object policyData = XACMLPolicyScanner.readPolicy(stream);
- if(policyData instanceof PolicyType){
+ if (policyData instanceof PolicyType) {
PolicyType policy = (PolicyType) policyData;
TargetType target = policy.getTarget();
if (target != null) {
@@ -278,19 +279,19 @@ public class ElasticSearchPolicyUpdate {
String attributeId = designator.getAttributeId();
// First match in the target is OnapName, so set that value.
if ("ONAPName".equals(attributeId)) {
- policyDataString.append("\"onapName\":\""+value+"\",");
+ policyDataString.append("\"onapName\":\"" + value + "\",");
}
- if ("RiskType".equals(attributeId)){
- policyDataString.append("\"riskType\":\""+value+"\",");
+ if ("RiskType".equals(attributeId)) {
+ policyDataString.append("\"riskType\":\"" + value + "\",");
}
- if ("RiskLevel".equals(attributeId)){
- policyDataString.append("\"riskLevel\":\""+value+"\",");
+ if ("RiskLevel".equals(attributeId)) {
+ policyDataString.append("\"riskLevel\":\"" + value + "\",");
}
- if ("guard".equals(attributeId)){
- policyDataString.append("\"guard\":\""+value+"\",");
+ if ("guard".equals(attributeId)) {
+ policyDataString.append("\"guard\":\"" + value + "\",");
}
- if ("ConfigName".equals(attributeId)){
- policyDataString.append("\"configName\":\""+value+"\",");
+ if ("ConfigName".equals(attributeId)) {
+ policyDataString.append("\"configName\":\"" + value + "\",");
}
}
}
@@ -303,79 +304,82 @@ public class ElasticSearchPolicyUpdate {
return policyDataString.toString();
}
- private static void updateConfigData(Connection conn, String configurationdataid, StringBuilder policyDataString) throws Exception {
-
- PreparedStatement pstmt = null;
- ResultSet configResult = null;
- try {
- String configEntityQuery = "Select * from ConfigurationDataEntity where configurationDataId = ?";
- pstmt = null;
- pstmt = conn.prepareStatement(configEntityQuery);
- pstmt.setString(1, configurationdataid);
- configResult = pstmt.executeQuery();
- while(configResult.next()){
- String configBody = configResult.getString("configbody");
- String configType = configResult.getString("configtype");
- if(configBody!=null){
- configBody = configBody.replace("null", "\"\"");
- configBody= configBody.replace("\"", "\\\"");
- policyDataString.append("\"jsonBodyData\":\""+configBody+"\",\"configType\":\""+configType+"\",");
- }
+ private static void updateConfigData(Connection conn, String configurationdataid, StringBuilder policyDataString)
+ throws Exception {
+
+ PreparedStatement pstmt = null;
+ ResultSet configResult = null;
+ try {
+ String configEntityQuery = "Select * from ConfigurationDataEntity where configurationDataId = ?";
+ pstmt = null;
+ pstmt = conn.prepareStatement(configEntityQuery);
+ pstmt.setString(1, configurationdataid);
+ configResult = pstmt.executeQuery();
+ while (configResult.next()) {
+ String configBody = configResult.getString("configbody");
+ String configType = configResult.getString("configtype");
+ if (configBody != null) {
+ configBody = configBody.replace("null", "\"\"");
+ configBody = configBody.replace("\"", "\\\"");
+ policyDataString
+ .append("\"jsonBodyData\":\"" + configBody + "\",\"configType\":\"" + configType + "\",");
}
- } catch(Exception e) {
- LOGGER.error("Exception Occured while updating configData"+e);
- throw(e);
- } finally {
- if(configResult != null){
- try {
- configResult.close();
- } catch (Exception e) {
- LOGGER.error("Exception Occured while closing the ResultSet"+e);
- }
+ }
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while updating configData" + e);
+ throw (e);
+ } finally {
+ if (configResult != null) {
+ try {
+ configResult.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the ResultSet" + e);
}
- if(pstmt != null){
- try {
- pstmt.close();
- } catch (Exception e) {
- LOGGER.error("Exception Occured while closing the PreparedStatement"+e);
- }
+ }
+ if (pstmt != null) {
+ try {
+ pstmt.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the PreparedStatement" + e);
}
- }
+ }
+ }
}
- private static void updateActionData(Connection conn, String actionbodyid, StringBuilder policyDataString) throws Exception {
-
- PreparedStatement pstmt = null;
- ResultSet actionResult = null;
- try {
- String actionEntityQuery = "Select * from ActionBodyEntity where actionBodyId = ?";
- pstmt = conn.prepareStatement(actionEntityQuery);
- pstmt.setString(1, actionbodyid);
- actionResult = pstmt.executeQuery();
- while(actionResult.next()){
- String actionBody = actionResult.getString("actionbody");
- actionBody = actionBody.replace("null", "\"\"");
- actionBody = actionBody.replace("\"", "\\\"");
- policyDataString.append("\"jsonBodyData\":\""+actionBody+"\",");
- }
- } catch(Exception e) {
- LOGGER.error("Exception Occured while updating actionData"+e);
- throw(e);
- } finally {
- if(actionResult != null){
- try {
- actionResult.close();
- } catch (Exception e) {
- LOGGER.error("Exception Occured while closing the ResultSet"+e);
- }
+ private static void updateActionData(Connection conn, String actionbodyid, StringBuilder policyDataString)
+ throws Exception {
+
+ PreparedStatement pstmt = null;
+ ResultSet actionResult = null;
+ try {
+ String actionEntityQuery = "Select * from ActionBodyEntity where actionBodyId = ?";
+ pstmt = conn.prepareStatement(actionEntityQuery);
+ pstmt.setString(1, actionbodyid);
+ actionResult = pstmt.executeQuery();
+ while (actionResult.next()) {
+ String actionBody = actionResult.getString("actionbody");
+ actionBody = actionBody.replace("null", "\"\"");
+ actionBody = actionBody.replace("\"", "\\\"");
+ policyDataString.append("\"jsonBodyData\":\"" + actionBody + "\",");
+ }
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while updating actionData" + e);
+ throw (e);
+ } finally {
+ if (actionResult != null) {
+ try {
+ actionResult.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the ResultSet" + e);
}
- if(pstmt != null){
- try {
- pstmt.close();
- } catch (Exception e) {
- LOGGER.error("Exception Occured while closing the PreparedStatement"+e);
- }
+ }
+ if (pstmt != null) {
+ try {
+ pstmt.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the PreparedStatement" + e);
}
- }
+ }
+ }
}
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnector.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnector.java
index d64b71763..d3f7f4dea 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnector.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnector.java
@@ -20,9 +20,10 @@
package org.onap.policy.pap.xacml.rest.elk.client;
-
import io.searchbox.client.JestResult;
+
import java.util.Map;
+
import org.onap.policy.rest.adapter.PolicyRestAdapter;
public interface ElkConnector {
@@ -44,8 +45,7 @@ public interface ElkConnector {
public boolean delete(PolicyRestAdapter policyData) throws IllegalStateException;
- public JestResult search(PolicyIndexType type, String text)
- throws IllegalStateException, IllegalArgumentException;
+ public JestResult search(PolicyIndexType type, String text) throws IllegalStateException, IllegalArgumentException;
public JestResult search(PolicyIndexType type, String text, Map<String, String> searchKeyValue)
throws IllegalStateException, IllegalArgumentException;
@@ -54,8 +54,7 @@ public interface ElkConnector {
public ElkConnector singleton = new ElkConnectorImpl();
- public static PolicyIndexType toPolicyIndexType(String policyName)
- throws IllegalArgumentException {
+ public static PolicyIndexType toPolicyIndexType(String policyName) throws IllegalArgumentException {
if (policyName == null)
throw new IllegalArgumentException("Unsupported NULL policy name conversion");
@@ -76,8 +75,7 @@ public interface ElkConnector {
} else if (policyName.startsWith("Config")) {
return PolicyIndexType.config;
} else {
- throw new IllegalArgumentException(
- "Unsupported policy name conversion to index: " + policyName);
+ throw new IllegalArgumentException("Unsupported policy name conversion to index: " + policyName);
}
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImpl.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImpl.java
index 6bbe033a3..4d84526a5 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImpl.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImpl.java
@@ -32,9 +32,11 @@ import io.searchbox.core.Search.Builder;
import io.searchbox.indices.IndicesExists;
import io.searchbox.indices.type.TypeExist;
import io.searchbox.params.Parameters;
+
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
+
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
@@ -56,8 +58,7 @@ public class ElkConnectorImpl implements ElkConnector {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("ENTER: -");
}
- HttpClientConfig jestClientConfig =
- new HttpClientConfig.Builder(ELK_URL).multiThreaded(true).build();
+ HttpClientConfig jestClientConfig = new HttpClientConfig.Builder(ELK_URL).multiThreaded(true).build();
jestFactory.setHttpClientConfig(jestClientConfig);
jestClient = jestFactory.getObject();
}
@@ -68,8 +69,7 @@ public class ElkConnectorImpl implements ElkConnector {
}
try {
- Action<JestResult> typeQuery =
- new TypeExist.Builder(ELK_INDEX_POLICY).addType(type.toString()).build();
+ Action<JestResult> typeQuery = new TypeExist.Builder(ELK_INDEX_POLICY).addType(type.toString()).build();
JestResult result = jestClient.execute(typeQuery);
if (LOGGER.isInfoEnabled()) {
@@ -80,9 +80,7 @@ public class ElkConnectorImpl implements ElkConnector {
}
return result.isSucceeded();
} catch (IOException e) {
- LOGGER.warn(
- "Error checking type existance of " + type.toString() + ": " + e.getMessage(),
- e);
+ LOGGER.warn("Error checking type existance of " + type.toString() + ": " + e.getMessage(), e);
throw e;
}
}
@@ -100,9 +98,7 @@ public class ElkConnectorImpl implements ElkConnector {
}
return result.isSucceeded();
} catch (IOException e) {
- LOGGER.warn(
- "Error checking index existance of " + ELK_INDEX_POLICY + ": " + e.getMessage(),
- e);
+ LOGGER.warn("Error checking index existance of " + ELK_INDEX_POLICY + ": " + e.getMessage(), e);
throw e;
}
}
@@ -112,8 +108,7 @@ public class ElkConnectorImpl implements ElkConnector {
}
@Override
- public JestResult search(PolicyIndexType type, String text)
- throws IllegalStateException, IllegalArgumentException {
+ public JestResult search(PolicyIndexType type, String text) throws IllegalStateException, IllegalArgumentException {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("ENTER: " + text);
}
@@ -129,9 +124,8 @@ public class ElkConnectorImpl implements ElkConnector {
QueryStringQueryBuilder mQ = QueryBuilders.queryStringQuery("*" + text + "*");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(mQ);
- Builder searchBuilder =
- new Search.Builder(searchSourceBuilder.toString()).addIndex(ELK_INDEX_POLICY)
- .setParameter(Parameters.SIZE, ElkConnectorImpl.QUERY_MAXRECORDS);
+ Builder searchBuilder = new Search.Builder(searchSourceBuilder.toString()).addIndex(ELK_INDEX_POLICY)
+ .setParameter(Parameters.SIZE, ElkConnectorImpl.QUERY_MAXRECORDS);
if (type == null || type == PolicyIndexType.all) {
for (PolicyIndexType pT : PolicyIndexType.values()) {
@@ -148,24 +142,21 @@ public class ElkConnectorImpl implements ElkConnector {
try {
result = jestClient.execute(search);
} catch (IOException ioe) {
- LOGGER.warn(
- XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + search + ": " + ioe.getMessage(),
- ioe);
+ LOGGER.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + search + ": " + ioe.getMessage(), ioe);
throw new IllegalStateException(ioe);
}
if (result.isSucceeded()) {
if (LOGGER.isInfoEnabled()) {
- LOGGER.info("OK:" + result.getResponseCode() + ":" + search + ": "
- + result.getPathToResult() + ":" + System.lineSeparator()
- + result.getJsonString());
+ LOGGER.info("OK:" + result.getResponseCode() + ":" + search + ": " + result.getPathToResult() + ":"
+ + System.lineSeparator() + result.getJsonString());
}
} else {
/* Unsuccessful search */
if (LOGGER.isWarnEnabled()) {
- LOGGER.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + result.getResponseCode()
- + ": " + search.getURI() + ":" + result.getPathToResult() + ":"
- + result.getJsonString() + ":" + result.getErrorMessage());
+ LOGGER.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + result.getResponseCode() + ": "
+ + search.getURI() + ":" + result.getPathToResult() + ":" + result.getJsonString() + ":"
+ + result.getErrorMessage());
}
String errorMessage = result.getErrorMessage();
@@ -173,24 +164,19 @@ public class ElkConnectorImpl implements ElkConnector {
String xMessage;
if (errorMessage.contains("TokenMgrError")) {
int indexError = errorMessage.lastIndexOf("TokenMgrError");
- xMessage = "Invalid Search Expression. Details: "
- + errorMessage.substring(indexError);
+ xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError);
} else if (errorMessage.contains("QueryParsingException")) {
int indexError = errorMessage.lastIndexOf("QueryParsingException");
- xMessage = "Invalid Search Expression. Details: "
- + errorMessage.substring(indexError);
+ xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError);
} else if (errorMessage.contains("JsonParseException")) {
int indexError = errorMessage.lastIndexOf("JsonParseException");
- xMessage = "Invalid Search Expression. Details: "
- + errorMessage.substring(indexError);
+ xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError);
} else if (errorMessage.contains("Parse Failure")) {
int indexError = errorMessage.lastIndexOf("Parse Failure");
- xMessage = "Invalid Search Expression. Details: "
- + errorMessage.substring(indexError);
+ xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError);
} else if (errorMessage.contains("SearchParseException")) {
int indexError = errorMessage.lastIndexOf("SearchParseException");
- xMessage = "Invalid Search Expression. Details: "
- + errorMessage.substring(indexError);
+ xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError);
} else {
xMessage = result.getErrorMessage();
}
@@ -201,7 +187,6 @@ public class ElkConnectorImpl implements ElkConnector {
return result;
}
-
@Override
public JestResult search(PolicyIndexType type, String text, Map<String, String> filter_s)
throws IllegalStateException, IllegalArgumentException {
@@ -218,8 +203,8 @@ public class ElkConnectorImpl implements ElkConnector {
}
String matches_s = "";
- matches_s = "{\n" + " \"size\" : " + ElkConnectorImpl.QUERY_MAXRECORDS + ",\n"
- + " \"query\": {\n" + " \"bool\" : {\n" + " \"must\" : [";
+ matches_s = "{\n" + " \"size\" : " + ElkConnectorImpl.QUERY_MAXRECORDS + ",\n" + " \"query\": {\n"
+ + " \"bool\" : {\n" + " \"must\" : [";
String match_params = "";
boolean first = true;
@@ -230,8 +215,7 @@ public class ElkConnectorImpl implements ElkConnector {
match_params = "\"match\" : {\"" + key + "\" : \"" + value + "\" }},";
first = false;
} else {
- match_params =
- match_params + "{\"match\" : { \"" + key + "\" : \"" + value + "\" } },";
+ match_params = match_params + "{\"match\" : { \"" + key + "\" : \"" + value + "\" } },";
}
}
if (match_params.endsWith(",")) {
@@ -271,24 +255,21 @@ public class ElkConnectorImpl implements ElkConnector {
try {
result = jestClient.execute(search);
} catch (IOException ioe) {
- LOGGER.warn(
- XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + search + ": " + ioe.getMessage(),
- ioe);
+ LOGGER.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + search + ": " + ioe.getMessage(), ioe);
throw new IllegalStateException(ioe);
}
if (result.isSucceeded()) {
if (LOGGER.isInfoEnabled()) {
- LOGGER.info("OK:" + result.getResponseCode() + ":" + search + ": "
- + result.getPathToResult() + ":" + System.lineSeparator()
- + result.getJsonString());
+ LOGGER.info("OK:" + result.getResponseCode() + ":" + search + ": " + result.getPathToResult() + ":"
+ + System.lineSeparator() + result.getJsonString());
}
} else {
/* Unsuccessful search */
if (LOGGER.isWarnEnabled()) {
- LOGGER.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + result.getResponseCode()
- + ": " + search.getURI() + ":" + result.getPathToResult() + ":"
- + result.getJsonString() + ":" + result.getErrorMessage());
+ LOGGER.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + result.getResponseCode() + ": "
+ + search.getURI() + ":" + result.getPathToResult() + ":" + result.getJsonString() + ":"
+ + result.getErrorMessage());
}
String errorMessage = result.getErrorMessage();
@@ -296,24 +277,19 @@ public class ElkConnectorImpl implements ElkConnector {
String xMessage = errorMessage;
if (errorMessage.contains("TokenMgrError")) {
int indexError = errorMessage.lastIndexOf("TokenMgrError");
- xMessage = "Invalid Search Expression. Details: "
- + errorMessage.substring(indexError);
+ xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError);
} else if (errorMessage.contains("QueryParsingException")) {
int indexError = errorMessage.lastIndexOf("QueryParsingException");
- xMessage = "Invalid Search Expression. Details: "
- + errorMessage.substring(indexError);
+ xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError);
} else if (errorMessage.contains("JsonParseException")) {
int indexError = errorMessage.lastIndexOf("JsonParseException");
- xMessage = "Invalid Search Expression. Details: "
- + errorMessage.substring(indexError);
+ xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError);
} else if (errorMessage.contains("Parse Failure")) {
int indexError = errorMessage.lastIndexOf("Parse Failure");
- xMessage = "Invalid Search Expression. Details: "
- + errorMessage.substring(indexError);
+ xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError);
} else if (errorMessage.contains("SearchParseException")) {
int indexError = errorMessage.lastIndexOf("SearchParseException");
- xMessage = "Invalid Search Expression. Details: "
- + errorMessage.substring(indexError);
+ xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError);
} else {
xMessage = result.getErrorMessage();
}
@@ -347,22 +323,20 @@ public class ElkConnectorImpl implements ElkConnector {
}
PolicyElasticData elasticData = new PolicyElasticData(policyData);
JSONObject jsonObj = new JSONObject(elasticData);
- Index elkPut = new Index.Builder(jsonObj.toString()).index(ELK_INDEX_POLICY)
- .type(indexType.name()).id(elasticData.getPolicyName()).refresh(true).build();
+ Index elkPut = new Index.Builder(jsonObj.toString()).index(ELK_INDEX_POLICY).type(indexType.name())
+ .id(elasticData.getPolicyName()).refresh(true).build();
JestResult result = jestClient.execute(elkPut);
if (result.isSucceeded()) {
if (LOGGER.isInfoEnabled())
- LOGGER.info("ElkConnector: OK: PUT operation of " + "->" + ": " + "success="
- + result.isSucceeded() + "[" + result.getResponseCode() + ":"
- + result.getPathToResult() + "]" + System.lineSeparator()
+ LOGGER.info("ElkConnector: OK: PUT operation of " + "->" + ": " + "success=" + result.isSucceeded()
+ + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]" + System.lineSeparator()
+ result.getJsonString());
} else {
if (LOGGER.isWarnEnabled())
- LOGGER.warn("ElkConnector: FAILURE: PUT operation of " + "->" + ": " + "success="
- + result.isSucceeded() + "[" + result.getResponseCode() + ":"
- + result.getPathToResult() + "]" + System.lineSeparator()
+ LOGGER.warn("ElkConnector: FAILURE: PUT operation of " + "->" + ": " + "success=" + result.isSucceeded()
+ + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]" + System.lineSeparator()
+ result.getJsonString());
}
@@ -387,31 +361,29 @@ public class ElkConnectorImpl implements ElkConnector {
String[] splitPolicyName = policyName.split(":");
indexType = ElkConnector.toPolicyIndexType(splitPolicyName[1]);
if (!isType(indexType)) {
- throw new IllegalStateException("ELK: Index: " + ELK_INDEX_POLICY + " Type: "
- + indexType + " is not configured");
+ throw new IllegalStateException(
+ "ELK: Index: " + ELK_INDEX_POLICY + " Type: " + indexType + " is not configured");
}
PolicyElasticData elasticData = new PolicyElasticData(policyData);
- Delete deleteRequest = new Delete.Builder(elasticData.getPolicyName())
- .index(ELK_INDEX_POLICY).type(indexType.name()).build();
+ Delete deleteRequest = new Delete.Builder(elasticData.getPolicyName()).index(ELK_INDEX_POLICY)
+ .type(indexType.name()).build();
result = jestClient.execute(deleteRequest);
} catch (IllegalArgumentException | IOException e) {
- LOGGER.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ": delete:" + indexType + ": null"
- + ":" + policyData.getNewFileName() + ": " + e.getMessage(), e);
+ LOGGER.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ": delete:" + indexType + ": null" + ":"
+ + policyData.getNewFileName() + ": " + e.getMessage(), e);
throw new IllegalStateException(e);
}
if (result.isSucceeded()) {
if (LOGGER.isInfoEnabled())
- LOGGER.info("OK: DELETE operation of " + indexType + ":"
- + policyData.getNewFileName() + ": " + "success=" + result.isSucceeded()
- + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]"
- + System.lineSeparator() + result.getJsonString());
+ LOGGER.info("OK: DELETE operation of " + indexType + ":" + policyData.getNewFileName() + ": "
+ + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":"
+ + result.getPathToResult() + "]" + System.lineSeparator() + result.getJsonString());
} else {
if (LOGGER.isWarnEnabled())
- LOGGER.warn("FAILURE: DELETE operation of " + indexType + ":"
- + policyData.getNewFileName() + ": " + "success=" + result.isSucceeded()
- + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]"
- + System.lineSeparator() + result.getJsonString());
+ LOGGER.warn("FAILURE: DELETE operation of " + indexType + ":" + policyData.getNewFileName() + ": "
+ + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":"
+ + result.getPathToResult() + "]" + System.lineSeparator() + result.getJsonString());
}
return result.isSucceeded();
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/Pair.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/Pair.java
index 2b0c94bf3..cd3fc4f0c 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/Pair.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/Pair.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,17 +17,31 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.pap.xacml.rest.elk.client;
-public class Pair<L,R> {
+public class Pair<L, R> {
private L left;
private R right;
- public Pair(L l, R r){
+
+ public Pair(L l, R r) {
+ this.left = l;
+ this.right = r;
+ }
+
+ public L left() {
+ return left;
+ }
+
+ public R right() {
+ return right;
+ }
+
+ public void left(L l) {
this.left = l;
+ }
+
+ public void right(R r) {
this.right = r;
}
- public L left(){ return left; }
- public R right(){ return right; }
- public void left(L l){ this.left = l; }
- public void right(R r){ this.right = r; }
-} \ No newline at end of file
+}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticData.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticData.java
index 988640ca6..70964c487 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticData.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticData.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.pap.xacml.rest.elk.client;
import java.util.ArrayList;
@@ -46,14 +47,14 @@ public class PolicyElasticData {
private Map<?, ?> description;
private Map<?, ?> attributeFields;
- //Safe Policy
+ // Safe Policy
private String policyScope;
private String providerComboBox;
private String riskType;
private String riskLevel;
private String guard;
private String ttlDate;
- private Map<String,String> matching;
+ private Map<String, String> matching;
private List<Object> triggerSignatures;
private List<Object> symptomSignatures;
@@ -62,39 +63,39 @@ public class PolicyElasticData {
public String gocServerScope;
private String supressionType;
- //MicroSerice
+ // MicroSerice
private String serviceType;
private String uuid;
private String location;
private String priority;
private String msLocation;
- //BRMS Policies
+ // BRMS Policies
private String ruleName;
- private Map<String,String> brmsParamBody;
+ private Map<String, String> brmsParamBody;
private String brmsController;
private List<String> brmsDependency;
- private LinkedHashMap<?, ?> ruleData;
- private LinkedHashMap<?,?> ruleListData;
- private Map<String,String> drlRuleAndUIParams;
+ private LinkedHashMap<?, ?> ruleData;
+ private LinkedHashMap<?, ?> ruleListData;
+ private Map<String, String> drlRuleAndUIParams;
- //ClosedLoop
+ // ClosedLoop
private String clearTimeOut;
private String trapMaxAge;
private String verificationclearTimeOut;
- public Map<String , String> dynamicLayoutMap;
+ public Map<String, String> dynamicLayoutMap;
- //FireWall
+ // FireWall
private String fwPolicyType;
private List<Object> fwattributes;
private String parentForChild;
private String securityZone;
- //Action & Decision
+ // Action & Decision
private String ruleCombiningAlgId;
- private Map<String,String> dynamicFieldConfigAttributes;
- private Map<String,String> dynamicSettingsMap;
- private Map<String,String> dropDownMap;
+ private Map<String, String> dynamicFieldConfigAttributes;
+ private Map<String, String> dynamicSettingsMap;
+ private Map<String, String> dropDownMap;
private String actionPerformer;
private String actionAttribute;
private List<String> dynamicRuleAlgorithmLabels;
@@ -117,15 +118,15 @@ public class PolicyElasticData {
this.policyType = policyData.getPolicyType();
this.configPolicyType = policyData.getConfigPolicyType();
this.configBodyData = policyData.getConfigBodyData();
- this.policyName = policyData.getNewFileName();
- this.policyDescription = policyData.getPolicyDescription();
+ this.policyName = policyData.getNewFileName();
+ this.policyDescription = policyData.getPolicyDescription();
this.onapName = policyData.getOnapName();
this.configName = policyData.getConfigName();
this.configType = policyData.getConfigType();
this.jsonBody = policyData.getJsonBody();
- if(configPolicyType.startsWith("ClosedLoop")){
+ if (configPolicyType.startsWith("ClosedLoop")) {
this.jsonBodyData = jsonBody;
- }else{
+ } else {
this.jsonBodyData = policyData.getJsonBodyData();
}
@@ -134,12 +135,12 @@ public class PolicyElasticData {
this.description = policyData.getDescription();
this.attributeFields = policyData.getAttributeFields();
- //Safe Policy
+ // Safe Policy
this.policyScope = policyData.getPolicyScope();
this.providerComboBox = policyData.getProviderComboBox();
this.riskType = policyData.getRiskType();
this.riskLevel = policyData.getRiskLevel();
- this.guard = policyData.getGuard();
+ this.guard = policyData.getGuard();
this.ttlDate = policyData.getTtlDate();
this.matching = policyData.getMatching();
@@ -150,14 +151,14 @@ public class PolicyElasticData {
this.gocServerScope = policyData.getGocServerScope();
this.supressionType = policyData.getSupressionType();
- //MicroSerice
+ // MicroSerice
this.serviceType = policyData.getServiceType();
this.uuid = policyData.getUuid();
this.location = policyData.getLocation();
this.priority = policyData.getPriority();
this.msLocation = policyData.getMsLocation();
- //BRMS Policies
+ // BRMS Policies
this.ruleName = policyData.getRuleName();
this.brmsParamBody = policyData.getBrmsParamBody();
this.brmsController = policyData.getBrmsController();
@@ -166,19 +167,19 @@ public class PolicyElasticData {
this.ruleListData = policyData.getRuleListData();
this.drlRuleAndUIParams = policyData.getDrlRuleAndUIParams();
- //ClosedLoop
+ // ClosedLoop
this.clearTimeOut = policyData.getClearTimeOut();
this.trapMaxAge = policyData.getTrapMaxAge();
this.verificationclearTimeOut = policyData.getVerificationclearTimeOut();
this.dynamicLayoutMap = policyData.getDynamicLayoutMap();
- //FireWall
+ // FireWall
this.fwPolicyType = policyData.getFwPolicyType();
this.fwattributes = policyData.getFwattributes();
this.parentForChild = policyData.getParentForChild();
this.securityZone = policyData.getSecurityZone();
- //Action & Decision
+ // Action & Decision
this.ruleCombiningAlgId = policyData.getRuleCombiningAlgId();
this.dynamicFieldConfigAttributes = policyData.getDynamicFieldConfigAttributes();
this.dynamicSettingsMap = policyData.getDynamicSettingsMap();
@@ -204,21 +205,27 @@ public class PolicyElasticData {
public String getScope() {
return scope;
}
+
public void setScope(String scope) {
this.scope = scope;
}
+
public String getPolicyType() {
return policyType;
}
+
public void setPolicyType(String policyType) {
this.policyType = policyType;
}
+
public String getConfigPolicyType() {
return configPolicyType;
}
+
public void setConfigPolicyType(String configPolicyType) {
this.configPolicyType = configPolicyType;
}
+
public String getConfigBodyData() {
return configBodyData;
}
@@ -226,42 +233,55 @@ public class PolicyElasticData {
public void setConfigBodyData(String configBodyData) {
this.configBodyData = configBodyData;
}
+
public String getPolicyName() {
return policyName;
}
+
public void setPolicyName(String policyName) {
this.policyName = policyName;
}
+
public String getPolicyDescription() {
return policyDescription;
}
+
public void setPolicyDescription(String policyDescription) {
this.policyDescription = policyDescription;
}
+
public String getOnapName() {
return onapName;
}
+
public void setOnapName(String onapName) {
this.onapName = onapName;
}
+
public String getConfigName() {
return configName;
}
+
public void setConfigName(String configName) {
this.configName = configName;
}
+
public String getConfigType() {
return configType;
}
+
public void setConfigType(String configType) {
this.configType = configType;
}
+
public String getJsonBody() {
return jsonBody;
}
+
public void setJsonBody(String jsonBody) {
this.jsonBody = jsonBody;
}
+
public Map<?, ?> getServiceTypePolicyName() {
return serviceTypePolicyName;
}
@@ -293,318 +313,423 @@ public class PolicyElasticData {
public void setAttributeFields(LinkedHashMap<?, ?> attributeFields) {
this.attributeFields = attributeFields;
}
+
public String getPolicyScope() {
return policyScope;
}
+
public void setPolicyScope(String policyScope) {
this.policyScope = policyScope;
}
+
public String getProviderComboBox() {
return providerComboBox;
}
+
public void setProviderComboBox(String providerComboBox) {
this.providerComboBox = providerComboBox;
}
+
public String getRiskType() {
return riskType;
}
+
public void setRiskType(String riskType) {
this.riskType = riskType;
}
+
public String getRiskLevel() {
return riskLevel;
}
+
public void setRiskLevel(String riskLevel) {
this.riskLevel = riskLevel;
}
+
public String getGuard() {
return guard;
}
+
public void setGuard(String guard) {
this.guard = guard;
}
+
public String getTtlDate() {
return ttlDate;
}
+
public void setTtlDate(String ttlDate) {
this.ttlDate = ttlDate;
}
+
public Map<String, String> getMatching() {
return matching;
}
+
public void setMatching(Map<String, String> matching) {
this.matching = matching;
}
+
public List<Object> getTriggerSignatures() {
return triggerSignatures;
}
+
public void setTriggerSignatures(ArrayList<Object> triggerSignatures) {
this.triggerSignatures = triggerSignatures;
}
+
public List<Object> getSymptomSignatures() {
return symptomSignatures;
}
+
public void setSymptomSignatures(ArrayList<Object> symptomSignatures) {
this.symptomSignatures = symptomSignatures;
}
+
public String getLogicalConnector() {
return logicalConnector;
}
+
public void setLogicalConnector(String logicalConnector) {
this.logicalConnector = logicalConnector;
}
+
public String getPolicyStatus() {
return policyStatus;
}
+
public void setPolicyStatus(String policyStatus) {
this.policyStatus = policyStatus;
}
+
public String getGocServerScope() {
return gocServerScope;
}
+
public void setGocServerScope(String gocServerScope) {
this.gocServerScope = gocServerScope;
}
+
public String getSupressionType() {
return supressionType;
}
+
public void setSupressionType(String supressionType) {
this.supressionType = supressionType;
}
+
public String getServiceType() {
return serviceType;
}
+
public void setServiceType(String serviceType) {
this.serviceType = serviceType;
}
+
public String getUuid() {
return uuid;
}
+
public void setUuid(String uuid) {
this.uuid = uuid;
}
+
public String getLocation() {
return location;
}
+
public void setLocation(String location) {
this.location = location;
}
+
public String getPriority() {
return priority;
}
+
public void setPriority(String priority) {
this.priority = priority;
}
+
public String getMsLocation() {
return msLocation;
}
+
public void setMsLocation(String msLocation) {
this.msLocation = msLocation;
}
+
public String getRuleName() {
return ruleName;
}
+
public void setRuleName(String ruleName) {
this.ruleName = ruleName;
}
+
public Map<String, String> getBrmsParamBody() {
return brmsParamBody;
}
+
public void setBrmsParamBody(Map<String, String> brmsParamBody) {
this.brmsParamBody = brmsParamBody;
}
+
public String getBrmsController() {
return brmsController;
}
+
public void setBrmsController(String brmsController) {
this.brmsController = brmsController;
}
+
public List<String> getBrmsDependency() {
return brmsDependency;
}
+
public void setBrmsDependency(List<String> brmsDependency) {
this.brmsDependency = brmsDependency;
}
+
public Map<?, ?> getRuleData() {
return ruleData;
}
+
public void setRuleData(LinkedHashMap<?, ?> ruleData) {
this.ruleData = ruleData;
}
+
public Map<?, ?> getRuleListData() {
return ruleListData;
}
+
public void setRuleListData(LinkedHashMap<?, ?> ruleListData) {
this.ruleListData = ruleListData;
}
+
public Map<String, String> getDrlRuleAndUIParams() {
return drlRuleAndUIParams;
}
+
public void setDrlRuleAndUIParams(Map<String, String> drlRuleAndUIParams) {
this.drlRuleAndUIParams = drlRuleAndUIParams;
}
+
public String getClearTimeOut() {
return clearTimeOut;
}
+
public void setClearTimeOut(String clearTimeOut) {
this.clearTimeOut = clearTimeOut;
}
+
public String getTrapMaxAge() {
return trapMaxAge;
}
+
public void setTrapMaxAge(String trapMaxAge) {
this.trapMaxAge = trapMaxAge;
}
+
public String getVerificationclearTimeOut() {
return verificationclearTimeOut;
}
+
public void setVerificationclearTimeOut(String verificationclearTimeOut) {
this.verificationclearTimeOut = verificationclearTimeOut;
}
+
public Map<String, String> getDynamicLayoutMap() {
return dynamicLayoutMap;
}
+
public void setDynamicLayoutMap(Map<String, String> dynamicLayoutMap) {
this.dynamicLayoutMap = dynamicLayoutMap;
}
+
public String getFwPolicyType() {
return fwPolicyType;
}
+
public void setFwPolicyType(String fwPolicyType) {
this.fwPolicyType = fwPolicyType;
}
+
public List<Object> getFwattributes() {
return fwattributes;
}
+
public void setFwattributes(ArrayList<Object> fwattributes) {
this.fwattributes = fwattributes;
}
+
public String getParentForChild() {
return parentForChild;
}
+
public void setParentForChild(String parentForChild) {
this.parentForChild = parentForChild;
}
+
public String getSecurityZone() {
return securityZone;
}
+
public void setSecurityZone(String securityZone) {
this.securityZone = securityZone;
}
+
public String getRuleCombiningAlgId() {
return ruleCombiningAlgId;
}
+
public void setRuleCombiningAlgId(String ruleCombiningAlgId) {
this.ruleCombiningAlgId = ruleCombiningAlgId;
}
+
public Map<String, String> getDynamicFieldConfigAttributes() {
return dynamicFieldConfigAttributes;
}
+
public void setDynamicFieldConfigAttributes(Map<String, String> dynamicFieldConfigAttributes) {
this.dynamicFieldConfigAttributes = dynamicFieldConfigAttributes;
}
+
public Map<String, String> getDynamicSettingsMap() {
return dynamicSettingsMap;
}
+
public void setDynamicSettingsMap(Map<String, String> dynamicSettingsMap) {
this.dynamicSettingsMap = dynamicSettingsMap;
}
+
public Map<String, String> getDropDownMap() {
return dropDownMap;
}
+
public void setDropDownMap(Map<String, String> dropDownMap) {
this.dropDownMap = dropDownMap;
}
+
public String getActionPerformer() {
return actionPerformer;
}
+
public void setActionPerformer(String actionPerformer) {
this.actionPerformer = actionPerformer;
}
+
public String getActionAttribute() {
return actionAttribute;
}
+
public void setActionAttribute(String actionAttribute) {
this.actionAttribute = actionAttribute;
}
+
public List<String> getDynamicRuleAlgorithmLabels() {
return dynamicRuleAlgorithmLabels;
}
+
public void setDynamicRuleAlgorithmLabels(List<String> dynamicRuleAlgorithmLabels) {
this.dynamicRuleAlgorithmLabels = dynamicRuleAlgorithmLabels;
}
+
public List<String> getDynamicRuleAlgorithmCombo() {
return dynamicRuleAlgorithmCombo;
}
+
public void setDynamicRuleAlgorithmCombo(List<String> dynamicRuleAlgorithmCombo) {
this.dynamicRuleAlgorithmCombo = dynamicRuleAlgorithmCombo;
}
+
public List<String> getDynamicRuleAlgorithmField1() {
return dynamicRuleAlgorithmField1;
}
+
public void setDynamicRuleAlgorithmField1(List<String> dynamicRuleAlgorithmField1) {
this.dynamicRuleAlgorithmField1 = dynamicRuleAlgorithmField1;
}
+
public List<String> getDynamicRuleAlgorithmField2() {
return dynamicRuleAlgorithmField2;
}
+
public void setDynamicRuleAlgorithmField2(List<String> dynamicRuleAlgorithmField2) {
this.dynamicRuleAlgorithmField2 = dynamicRuleAlgorithmField2;
}
+
public List<Object> getDynamicVariableList() {
return dynamicVariableList;
}
+
public void setDynamicVariableList(List<Object> dynamicVariableList) {
this.dynamicVariableList = dynamicVariableList;
}
+
public List<String> getDataTypeList() {
return dataTypeList;
}
+
public void setDataTypeList(List<String> dataTypeList) {
this.dataTypeList = dataTypeList;
}
+
public String getActionAttributeValue() {
return actionAttributeValue;
}
+
public void setActionAttributeValue(String actionAttributeValue) {
this.actionAttributeValue = actionAttributeValue;
}
+
public String getRuleProvider() {
return ruleProvider;
}
+
public void setRuleProvider(String ruleProvider) {
this.ruleProvider = ruleProvider;
}
+
public String getActionBody() {
return actionBody;
}
+
public void setActionBody(String actionBody) {
this.actionBody = actionBody;
}
+
public String getActionDictHeader() {
return actionDictHeader;
}
+
public void setActionDictHeader(String actionDictHeader) {
this.actionDictHeader = actionDictHeader;
}
+
public String getActionDictType() {
return actionDictType;
}
+
public void setActionDictType(String actionDictType) {
this.actionDictType = actionDictType;
}
+
public String getActionDictUrl() {
return actionDictUrl;
}
+
public void setActionDictUrl(String actionDictUrl) {
this.actionDictUrl = actionDictUrl;
}
+
public String getActionDictMethod() {
return actionDictMethod;
}
+
public void setActionDictMethod(String actionDictMethod) {
this.actionDictMethod = actionDictMethod;
}
+
public YAMLParams getYamlparams() {
return yamlparams;
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java
index 50965bd2b..48dc46c1b 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,15 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.pap.xacml.rest.elk.client;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.JsonArray;
+
+import io.searchbox.client.JestResult;
import java.io.IOException;
import java.io.PrintWriter;
@@ -41,22 +48,22 @@ import org.onap.policy.rest.adapter.PolicyRestAdapter;
import org.onap.policy.rest.dao.CommonClassDao;
import org.onap.policy.rest.jpa.ActionPolicyDict;
import org.onap.policy.rest.jpa.Attribute;
-import org.onap.policy.rest.jpa.BRMSParamTemplate;
+import org.onap.policy.rest.jpa.BrmsParamTemplate;
import org.onap.policy.rest.jpa.ClosedLoopD2Services;
import org.onap.policy.rest.jpa.ClosedLoopSite;
-import org.onap.policy.rest.jpa.DCAEuuid;
+import org.onap.policy.rest.jpa.DcaeUuid;
import org.onap.policy.rest.jpa.DecisionSettings;
import org.onap.policy.rest.jpa.DescriptiveScope;
import org.onap.policy.rest.jpa.GroupPolicyScopeList;
import org.onap.policy.rest.jpa.MicroServiceLocation;
import org.onap.policy.rest.jpa.MicroServiceModels;
import org.onap.policy.rest.jpa.OnapName;
-import org.onap.policy.rest.jpa.PEPOptions;
+import org.onap.policy.rest.jpa.PepOptions;
import org.onap.policy.rest.jpa.RiskType;
import org.onap.policy.rest.jpa.SafePolicyWarning;
import org.onap.policy.rest.jpa.TermList;
-import org.onap.policy.rest.jpa.VNFType;
-import org.onap.policy.rest.jpa.VSCLAction;
+import org.onap.policy.rest.jpa.VnfType;
+import org.onap.policy.rest.jpa.VsclAction;
import org.onap.policy.rest.jpa.VarbindDictionary;
import org.onap.policy.utils.PolicyUtils;
import org.onap.policy.xacml.api.XACMLErrorConstants;
@@ -66,24 +73,14 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.gson.JsonArray;
-
-import io.searchbox.client.JestResult;
-
@Controller
@RequestMapping({"/"})
-public class PolicyElasticSearchController{
+public class PolicyElasticSearchController {
private static final Logger LOGGER = FlexLogger.getLogger(PolicyElasticSearchController.class);
- enum Mode{
- attribute, onapName, actionPolicy, brmsParam, pepOptions,
- clSite, clService, clVarbind, clVnf, clVSCL, decision,
- fwTerm, msDCAEUUID, msConfigName, msLocation, msModels,
- psGroupPolicy, safeRisk, safePolicyWarning
+ enum Mode {
+ attribute, onapName, actionPolicy, brmsParam, pepOptions, clSite, clService, clVarbind, clVnf, clVSCL, decision, fwTerm, msDCAEUUID, msConfigName, msLocation, msModels, psGroupPolicy, safeRisk, safePolicyWarning
}
protected static final HashMap<String, String> name2jsonPath = new HashMap<String, String>() {
@@ -108,7 +105,7 @@ public class PolicyElasticSearchController{
}
public ElkConnector.PolicyIndexType toPolicyIndexType(String type) throws IllegalArgumentException {
- if (type == null || type.isEmpty()){
+ if (type == null || type.isEmpty()) {
return PolicyIndexType.all;
}
return PolicyIndexType.valueOf(type);
@@ -154,11 +151,10 @@ public class PolicyElasticSearchController{
return success;
}
-
- @RequestMapping(value="/searchPolicy", method= RequestMethod.POST)
+ @RequestMapping(value = "/searchPolicy", method = RequestMethod.POST)
public void searchPolicy(HttpServletRequest request, HttpServletResponse response) {
- try{
- String message="";
+ try {
+ String message = "";
boolean result = false;
boolean policyResult = false;
boolean validationCheck = true;
@@ -168,16 +164,16 @@ public class PolicyElasticSearchController{
PolicyElasticSearchController controller = new PolicyElasticSearchController();
Map<String, String> searchKeyValue = new HashMap<>();
List<String> policyList = new ArrayList<>();
- if(request.getParameter("policyName") != null){
+ if (request.getParameter("policyName") != null) {
String policyName = request.getParameter("policyName");
policyData.setNewFileName(policyName);
- if("delete".equalsIgnoreCase(request.getParameter(action))){
+ if ("delete".equalsIgnoreCase(request.getParameter(action))) {
result = controller.deleteElk(policyData);
- }else{
+ } else {
result = controller.updateElk(policyData);
}
}
- if("search".equalsIgnoreCase(request.getParameter(action))){
+ if ("search".equalsIgnoreCase(request.getParameter(action))) {
try {
JsonNode root = mapper.readTree(request.getReader());
SearchData searchData = mapper.readValue(root.get("searchdata").toString(), SearchData.class);
@@ -186,111 +182,117 @@ public class PolicyElasticSearchController{
String searchText = searchData.getQuery();
String descriptivevalue = searchData.getDescriptiveScope();
- if(descriptivevalue != null){
- DescriptiveScope dsSearch = (DescriptiveScope) commonClassDao.getEntityItem(DescriptiveScope.class, "descriptiveScopeName", descriptivevalue);
- if(dsSearch != null){
- String[] descriptiveList = dsSearch.getSearch().split("AND");
- for(String keyValue : descriptiveList){
+ if (descriptivevalue != null) {
+ DescriptiveScope dsSearch = (DescriptiveScope) commonClassDao
+ .getEntityItem(DescriptiveScope.class, "descriptiveScopeName", descriptivevalue);
+ if (dsSearch != null) {
+ String[] descriptiveList = dsSearch.getSearch().split("AND");
+ for (String keyValue : descriptiveList) {
String[] entry = keyValue.split(":");
- if(searchData.getPolicyType() != null && "closedLoop".equals(searchData.getPolicyType())){
- if(!PolicyUtils.policySpecialCharValidator(entry[1]).contains(success)){
- message = "The Descriptive Scope Dictionary value contains space and it is invalid for Search : "+entry[1];
+ if (searchData.getPolicyType() != null
+ && "closedLoop".equals(searchData.getPolicyType())) {
+ if (!PolicyUtils.policySpecialCharValidator(entry[1]).contains(success)) {
+ message =
+ "The Descriptive Scope Dictionary value contains space and it is invalid for Search : "
+ + entry[1];
validationCheck = false;
}
- searchKeyValue.put(jsonBodyData, "*" +entry[1] +"*");
- }else{
+ searchKeyValue.put(jsonBodyData, "*" + entry[1] + "*");
+ } else {
searchText = entry[1];
}
}
}
}
- if(!PolicyUtils.policySpecialCharValidator(searchText).contains(success)){
- message = "The Search value contains space and it is invalid for Search : "+searchText;
+ if (!PolicyUtils.policySpecialCharValidator(searchText).contains(success)) {
+ message = "The Search value contains space and it is invalid for Search : " + searchText;
validationCheck = false;
}
- if(searchData.getClosedLooppolicyType() != null){
+ if (searchData.getClosedLooppolicyType() != null) {
String closedLoopType;
- if("Config_Fault".equalsIgnoreCase(searchData.getClosedLooppolicyType())){
- closedLoopType = "ClosedLoop_Fault";
- }else{
- closedLoopType = "ClosedLoop_PM";
+ if ("Config_Fault".equalsIgnoreCase(searchData.getClosedLooppolicyType())) {
+ closedLoopType = "ClosedLoop_Fault";
+ } else {
+ closedLoopType = "ClosedLoop_PM";
}
searchKeyValue.put("configPolicyType", closedLoopType);
}
- if(searchData.getOnapName() != null){
+ if (searchData.getOnapName() != null) {
searchKeyValue.put("onapName", searchData.getOnapName());
}
- if(searchData.getD2Service() != null){
+ if (searchData.getD2Service() != null) {
String d2Service = searchData.getD2Service().trim();
- if("Hosted Voice (Trinity)".equalsIgnoreCase(d2Service)){
+ if ("Hosted Voice (Trinity)".equalsIgnoreCase(d2Service)) {
d2Service = "trinity";
- }else if("vUSP".equalsIgnoreCase(d2Service)){
+ } else if ("vUSP".equalsIgnoreCase(d2Service)) {
d2Service = "vUSP";
- }else if("MCR".equalsIgnoreCase(d2Service)){
+ } else if ("MCR".equalsIgnoreCase(d2Service)) {
d2Service = "mcr";
- }else if("Gamma".equalsIgnoreCase(d2Service)){
+ } else if ("Gamma".equalsIgnoreCase(d2Service)) {
d2Service = "gamma";
- }else if("vDNS".equalsIgnoreCase(d2Service)){
+ } else if ("vDNS".equalsIgnoreCase(d2Service)) {
d2Service = "vDNS";
}
- searchKeyValue.put("jsonBodyData."+d2Service+"", "true");
+ searchKeyValue.put("jsonBodyData." + d2Service + "", "true");
}
- if(searchData.getVnfType() != null){
- searchKeyValue.put(jsonBodyData, "*"+searchData.getVnfType()+"*");
+ if (searchData.getVnfType() != null) {
+ searchKeyValue.put(jsonBodyData, "*" + searchData.getVnfType() + "*");
}
- if(searchData.getPolicyStatus() != null){
- searchKeyValue.put(jsonBodyData, "*"+searchData.getPolicyStatus()+"*");
+ if (searchData.getPolicyStatus() != null) {
+ searchKeyValue.put(jsonBodyData, "*" + searchData.getPolicyStatus() + "*");
}
- if(searchData.getVproAction() != null){
- searchKeyValue.put(jsonBodyData, "*"+searchData.getVproAction()+"*");
+ if (searchData.getVproAction() != null) {
+ searchKeyValue.put(jsonBodyData, "*" + searchData.getVproAction() + "*");
}
- if(searchData.getServiceType() != null){
+ if (searchData.getServiceType() != null) {
searchKeyValue.put("serviceType", searchData.getServiceType());
}
- if(searchData.getBindTextSearch() != null){
+ if (searchData.getBindTextSearch() != null) {
searchKeyValue.put(searchData.getBindTextSearch(), searchText);
searchText = null;
}
PolicyIndexType type = null;
- if(policyType != null){
- if(action.equalsIgnoreCase(policyType)){
+ if (policyType != null) {
+ if (action.equalsIgnoreCase(policyType)) {
type = ElkConnector.PolicyIndexType.action;
- }else if(decision.equalsIgnoreCase(policyType)){
+ } else if (decision.equalsIgnoreCase(policyType)) {
type = ElkConnector.PolicyIndexType.decision;
- }else if(config.equalsIgnoreCase(policyType)){
+ } else if (config.equalsIgnoreCase(policyType)) {
type = ElkConnector.PolicyIndexType.config;
- }else if("closedloop".equalsIgnoreCase(policyType)){
+ } else if ("closedloop".equalsIgnoreCase(policyType)) {
type = ElkConnector.PolicyIndexType.closedloop;
- }else{
+ } else {
type = ElkConnector.PolicyIndexType.all;
}
- }else{
+ } else {
type = ElkConnector.PolicyIndexType.all;
}
- if(validationCheck){
+ if (validationCheck) {
JestResult policyResultList = controller.search(type, searchText, searchKeyValue);
- if(policyResultList.isSucceeded()){
+ if (policyResultList.isSucceeded()) {
result = true;
policyResult = true;
- JsonArray resultObject = policyResultList.getJsonObject().get("hits").getAsJsonObject().get("hits").getAsJsonArray();
- for(int i =0; i < resultObject.size(); i++){
+ JsonArray resultObject = policyResultList.getJsonObject().get("hits").getAsJsonObject()
+ .get("hits").getAsJsonArray();
+ for (int i = 0; i < resultObject.size(); i++) {
String policyName = resultObject.get(i).getAsJsonObject().get("_id").toString();
policyList.add(policyName);
}
- }else{
- LOGGER.error("Exception Occured While Searching for Data in Elastic Search Server, Check the Logs");
+ } else {
+ LOGGER.error(
+ "Exception Occured While Searching for Data in Elastic Search Server, Check the Logs");
}
}
- }catch(Exception e){
+ } catch (Exception e) {
LOGGER.error("Exception Occured While Searching for Data in Elastic Search Server" + e);
}
}
- if(validationCheck){
- if(result){
+ if (validationCheck) {
+ if (result) {
message = "Elastic Server Transaction is success";
- }else{
+ } else {
message = "Elastic Server Transaction is failed, please check the logs";
}
}
@@ -298,22 +300,25 @@ public class PolicyElasticSearchController{
JSONObject j = new JSONObject(msg);
response.setStatus(HttpServletResponse.SC_OK);
response.addHeader(success, success);
- if(policyResult){
+ if (policyResult) {
JSONObject k = new JSONObject("{policyresult: " + policyList + "}");
response.getWriter().write(k.toString());
- }else{
+ } else {
response.getWriter().write(j.toString());
}
- }catch(Exception e){
+ } catch (Exception e) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.addHeader("error", "Exception Occured While Performing Elastic Transaction");
- LOGGER.error("Exception Occured While Performing Elastic Transaction"+e.getMessage(),e);
+ LOGGER.error("Exception Occured While Performing Elastic Transaction" + e.getMessage(), e);
}
}
- @RequestMapping(value={"/searchDictionary"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView searchDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
- try{
+ @RequestMapping(
+ value = {"/searchDictionary"},
+ method = {org.springframework.web.bind.annotation.RequestMethod.POST})
+ public ModelAndView searchDictionary(HttpServletRequest request, HttpServletResponse response)
+ throws UnsupportedEncodingException, IOException {
+ try {
PolicyIndexType config = PolicyIndexType.config;
PolicyIndexType closedloop = PolicyIndexType.closedloop;
PolicyIndexType action = PolicyIndexType.action;
@@ -327,105 +332,114 @@ public class PolicyElasticSearchController{
Mode mode = Mode.valueOf(dictionaryType);
String value;
List<String> policyList = new ArrayList<>();
- switch (mode){
- case attribute :
- Attribute attributedata = mapper.readValue(root.get("data").toString(), Attribute.class);
- value = attributedata.getXacmlId();
- policyList = searchElkDatabase(all, pholder,value);
- break;
- case onapName :
- OnapName onapName = mapper.readValue(root.get("data").toString(), OnapName.class);
- value = onapName.getOnapName();
- policyList = searchElkDatabase(all, "onapName",value);
- break;
- case actionPolicy :
- ActionPolicyDict actionPolicyDict = mapper.readValue(root.get("data").toString(), ActionPolicyDict.class);
- value = actionPolicyDict.getAttributeName();
- policyList = searchElkDatabase(action, "actionAttributeValue",value);
- break;
- case brmsParam :
- BRMSParamTemplate bRMSParamTemplate = mapper.readValue(root.get("data").toString(), BRMSParamTemplate.class);
- value = bRMSParamTemplate.getRuleName();
- policyList = searchElkDatabase(config, "ruleName",value);
- break;
- case pepOptions :
- PEPOptions pEPOptions = mapper.readValue(root.get("data").toString(), PEPOptions.class);
- value = pEPOptions.getPepName();
- policyList = searchElkDatabase(closedloop,"jsonBodyData.pepName",value);
- break;
- case clSite :
- ClosedLoopSite closedLoopSite = mapper.readValue(root.get("data").toString(), ClosedLoopSite.class);
- value = closedLoopSite.getSiteName();
- policyList = searchElkDatabase(closedloop,"siteNames",value);
- break;
- case clService :
- ClosedLoopD2Services closedLoopD2Services = mapper.readValue(root.get("data").toString(), ClosedLoopD2Services.class);
- value = closedLoopD2Services.getServiceName();
- policyList = searchElkDatabase(closedloop, pholder,value);
- break;
- case clVarbind :
- VarbindDictionary varbindDictionary = mapper.readValue(root.get("data").toString(), VarbindDictionary.class);
- value = varbindDictionary.getVarbindName();
- policyList = searchElkDatabase(closedloop, jsonBodyData,"*"+value+"*");
- break;
- case clVnf :
- VNFType vNFType = mapper.readValue(root.get("data").toString(), VNFType.class);
- value = vNFType.getVnftype();
- policyList = searchElkDatabase(closedloop, jsonBodyData,"*"+value+"*");
- break;
- case clVSCL :
- VSCLAction vsclAction = mapper.readValue(root.get("data").toString(), VSCLAction.class);
- value = vsclAction.getVsclaction();
- policyList = searchElkDatabase(closedloop, jsonBodyData,"*"+value+"*");
- break;
- case decision :
- DecisionSettings decisionSettings = mapper.readValue(root.get("data").toString(), DecisionSettings.class);
- value = decisionSettings.getXacmlId();
- policyList = searchElkDatabase(decision,pholder,value);
- break;
- case fwTerm :
- TermList term = mapper.readValue(root.get("data").toString(), TermList.class);
- value = term.getTermName();
- policyList = searchElkDatabase(config, pholder,value);
- break;
- case msDCAEUUID :
- DCAEuuid dcaeUUID = mapper.readValue(root.get("data").toString(), DCAEuuid.class);
- value = dcaeUUID.getName();
- policyList = searchElkDatabase(config, "uuid",value);
- break;
- case msLocation :
- MicroServiceLocation mslocation = mapper.readValue(root.get("data").toString(), MicroServiceLocation.class);
- value = mslocation.getName();
- policyList = searchElkDatabase(config, "location",value);
- break;
- case msModels :
- MicroServiceModels msModels = mapper.readValue(root.get("data").toString(), MicroServiceModels.class);
- value = msModels.getModelName();
- policyList = searchElkDatabase(config, "serviceType",value);
- break;
- case psGroupPolicy :
- GroupPolicyScopeList groupPoilicy = mapper.readValue(root.get("data").toString(), GroupPolicyScopeList.class);
- value = groupPoilicy.getGroupName();
- policyList = searchElkDatabase(config, pholder,value);
- break;
- case safeRisk :
- RiskType riskType= mapper.readValue(root.get("data").toString(), RiskType.class);
- value = riskType.getRiskName();
- policyList = searchElkDatabase(config, "riskType",value);
- break;
- case safePolicyWarning :
- SafePolicyWarning safePolicy = mapper.readValue(root.get("data").toString(), SafePolicyWarning.class);
- value = safePolicy.getName();
- policyList = searchElkDatabase(config, pholder,value);
- break;
- default:
+ switch (mode) {
+ case attribute:
+ Attribute attributedata = mapper.readValue(root.get("data").toString(), Attribute.class);
+ value = attributedata.getXacmlId();
+ policyList = searchElkDatabase(all, pholder, value);
+ break;
+ case onapName:
+ OnapName onapName = mapper.readValue(root.get("data").toString(), OnapName.class);
+ value = onapName.getName();
+ policyList = searchElkDatabase(all, "onapName", value);
+ break;
+ case actionPolicy:
+ ActionPolicyDict actionPolicyDict =
+ mapper.readValue(root.get("data").toString(), ActionPolicyDict.class);
+ value = actionPolicyDict.getAttributeName();
+ policyList = searchElkDatabase(action, "actionAttributeValue", value);
+ break;
+ case brmsParam:
+ BrmsParamTemplate bRMSParamTemplate =
+ mapper.readValue(root.get("data").toString(), BrmsParamTemplate.class);
+ value = bRMSParamTemplate.getRuleName();
+ policyList = searchElkDatabase(config, "ruleName", value);
+ break;
+ case pepOptions:
+ PepOptions pEPOptions = mapper.readValue(root.get("data").toString(), PepOptions.class);
+ value = pEPOptions.getPepName();
+ policyList = searchElkDatabase(closedloop, "jsonBodyData.pepName", value);
+ break;
+ case clSite:
+ ClosedLoopSite closedLoopSite = mapper.readValue(root.get("data").toString(), ClosedLoopSite.class);
+ value = closedLoopSite.getSiteName();
+ policyList = searchElkDatabase(closedloop, "siteNames", value);
+ break;
+ case clService:
+ ClosedLoopD2Services closedLoopD2Services =
+ mapper.readValue(root.get("data").toString(), ClosedLoopD2Services.class);
+ value = closedLoopD2Services.getServiceName();
+ policyList = searchElkDatabase(closedloop, pholder, value);
+ break;
+ case clVarbind:
+ VarbindDictionary varbindDictionary =
+ mapper.readValue(root.get("data").toString(), VarbindDictionary.class);
+ value = varbindDictionary.getVarbindName();
+ policyList = searchElkDatabase(closedloop, jsonBodyData, "*" + value + "*");
+ break;
+ case clVnf:
+ VnfType vNFType = mapper.readValue(root.get("data").toString(), VnfType.class);
+ value = vNFType.getType();
+ policyList = searchElkDatabase(closedloop, jsonBodyData, "*" + value + "*");
+ break;
+ case clVSCL:
+ VsclAction vsclAction = mapper.readValue(root.get("data").toString(), VsclAction.class);
+ value = vsclAction.getAction();
+ policyList = searchElkDatabase(closedloop, jsonBodyData, "*" + value + "*");
+ break;
+ case decision:
+ DecisionSettings decisionSettings =
+ mapper.readValue(root.get("data").toString(), DecisionSettings.class);
+ value = decisionSettings.getXacmlId();
+ policyList = searchElkDatabase(decision, pholder, value);
+ break;
+ case fwTerm:
+ TermList term = mapper.readValue(root.get("data").toString(), TermList.class);
+ value = term.getTermName();
+ policyList = searchElkDatabase(config, pholder, value);
+ break;
+ case msDCAEUUID:
+ DcaeUuid dcaeUUID = mapper.readValue(root.get("data").toString(), DcaeUuid.class);
+ value = dcaeUUID.getName();
+ policyList = searchElkDatabase(config, "uuid", value);
+ break;
+ case msLocation:
+ MicroServiceLocation mslocation =
+ mapper.readValue(root.get("data").toString(), MicroServiceLocation.class);
+ value = mslocation.getName();
+ policyList = searchElkDatabase(config, "location", value);
+ break;
+ case msModels:
+ MicroServiceModels msModels =
+ mapper.readValue(root.get("data").toString(), MicroServiceModels.class);
+ value = msModels.getModelName();
+ policyList = searchElkDatabase(config, "serviceType", value);
+ break;
+ case psGroupPolicy:
+ GroupPolicyScopeList groupPoilicy =
+ mapper.readValue(root.get("data").toString(), GroupPolicyScopeList.class);
+ value = groupPoilicy.getGroupName();
+ policyList = searchElkDatabase(config, pholder, value);
+ break;
+ case safeRisk:
+ RiskType riskType = mapper.readValue(root.get("data").toString(), RiskType.class);
+ value = riskType.getName();
+ policyList = searchElkDatabase(config, "riskType", value);
+ break;
+ case safePolicyWarning:
+ SafePolicyWarning safePolicy =
+ mapper.readValue(root.get("data").toString(), SafePolicyWarning.class);
+ value = safePolicy.getName();
+ policyList = searchElkDatabase(config, pholder, value);
+ break;
+ default:
}
response.setStatus(HttpServletResponse.SC_OK);
response.addHeader(success, success);
JSONObject k = new JSONObject("{policyresult: " + policyList + "}");
response.getWriter().write(k.toString());
- }catch(Exception e){
+ } catch (Exception e) {
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
@@ -435,30 +449,31 @@ public class PolicyElasticSearchController{
return null;
}
- //Search the Elk database
- public List<String> searchElkDatabase(PolicyIndexType type, String key, String value){
+ // Search the Elk database
+ public List<String> searchElkDatabase(PolicyIndexType type, String key, String value) {
PolicyElasticSearchController controller = new PolicyElasticSearchController();
Map<String, String> searchKeyValue = new HashMap<>();
- if(!pholder.equals(key)){
+ if (!pholder.equals(key)) {
searchKeyValue.put(key, value);
}
List<String> policyList = new ArrayList<>();
JestResult policyResultList = controller.search(type, value, searchKeyValue);
- if(policyResultList.isSucceeded()){
- JsonArray resultObject = policyResultList.getJsonObject().get("hits").getAsJsonObject().get("hits").getAsJsonArray();
- for(int i =0; i < resultObject.size(); i++){
+ if (policyResultList.isSucceeded()) {
+ JsonArray resultObject =
+ policyResultList.getJsonObject().get("hits").getAsJsonObject().get("hits").getAsJsonArray();
+ for (int i = 0; i < resultObject.size(); i++) {
String policyName = resultObject.get(i).getAsJsonObject().get("_id").toString();
policyList.add(policyName);
}
- }else{
+ } else {
LOGGER.error("Exception Occured While Searching for Data in Elastic Search Server, Check the Logs");
}
return policyList;
}
public JestResult search(PolicyIndexType type, String text, Map<String, String> searchKeyValue) {
- return ElkConnector.singleton.search(type, text, searchKeyValue);
+ return ElkConnector.singleton.search(type, text, searchKeyValue);
}
-} \ No newline at end of file
+}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyLocator.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyLocator.java
index 9338cdbbd..95930ede8 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyLocator.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyLocator.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.pap.xacml.rest.elk.client;
public class PolicyLocator {
@@ -27,11 +28,10 @@ public class PolicyLocator {
public final String policyId;
public final String version;
- public PolicyLocator(String policyType, String policyName,
- String owner, String scope, String policyId,
- String version) {
+ public PolicyLocator(String policyType, String policyName, String owner, String scope, String policyId,
+ String version) {
this.policyType = policyType;
- this.policyName= policyName;
+ this.policyName = policyName;
this.owner = owner;
this.scope = scope;
this.policyId = policyId;
@@ -39,13 +39,8 @@ public class PolicyLocator {
}
public String toString() {
- return "[" +
- this.owner + "|" +
- this.scope + "|" +
- this.policyType + "|" +
- this.policyName + "|" +
- this.policyId + "|" +
- "v" + this.version + "|" + "]";
+ return "[" + this.owner + "|" + this.scope + "|" + this.policyType + "|" + this.policyName + "|" + this.policyId
+ + "|" + "v" + this.version + "|" + "]";
}
}