aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PDP-REST/src/main/java/org/onap
diff options
context:
space:
mode:
authorMichael Mokry <mm117s@att.com>2018-03-16 20:50:41 -0500
committerMichael Mokry <mm117s@att.com>2018-03-26 09:43:24 -0500
commitb6d9063e06ab8cdf2d97fc75810792659344e4a8 (patch)
tree189c47e59cef6650ba0d39bbee31dcdaaa3ddbc7 /ONAP-PDP-REST/src/main/java/org/onap
parentc8bed1e392b935ec50aaeeb5fb82d25a9568b790 (diff)
New Optimization Policy
This is the new Optimization Policy to support the Integration of the OOF Policy Model into the Policy Platform. Added changes from Frank Wang to fix the following issues with existing Model Parser: 1. TOSCA Rendering issues 2. Matching Attributes support 3. ImportModelAPI to support TOSCA model upload via REST API Running local Sonar tonight to start fixing Sonar issues Added changes per review comments and fixed Sonar issues Change-Id: Ia8ce09c28a718ce4460475e76a750caef774bd6b Issue-ID: POLICY-622 Signed-off-by: Michael Mokry <mm117s@att.com>
Diffstat (limited to 'ONAP-PDP-REST/src/main/java/org/onap')
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java6
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java3
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetConfigService.java2
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java3
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyService.java110
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PolicyEngineImportService.java6
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PushPolicyService.java3
7 files changed, 131 insertions, 2 deletions
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java
index 62b850370..f2cc16b1f 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java
@@ -176,6 +176,12 @@ public class CreateUpdatePolicyServiceImpl implements CreateUpdatePolicyService
// Get Result.
response = microServicesPolicyService.getResult(updateFlag);
break;
+ case Optimization:
+ OptimizationPolicyService optimizationPolicyService = new OptimizationPolicyService(policyName, policyScope, policyParameters, date);
+
+ // Get Result
+ response = optimizationPolicyService.getResult(updateFlag);
+ break;
default:
message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " Invalid Config Type Present";
LOGGER.error(message);
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java
index 144d3a48d..c9ecee86b 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java
@@ -236,6 +236,9 @@ public class DeletePolicyService {
} else if ("MicroService".equalsIgnoreCase(policyType)) {
clientScope = "ConfigMS";
filePrefix = "Config_MS_";
+ } else if ("Optimization".equalsIgnoreCase(policyType)) {
+ clientScope = "ConfigOptimization";
+ filePrefix = "Config_OOF_";
}else if ("BRMS_RAW".equalsIgnoreCase(policyType)) {
clientScope = "ConfigBrmsRaw";
filePrefix = "Config_BRMS_Raw_";
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetConfigService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetConfigService.java
index 6e6badf6a..1744aa8ae 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetConfigService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetConfigService.java
@@ -173,6 +173,8 @@ public class GetConfigService {
return PolicyConfigType.ClosedLoop_PM;
} else if(name.startsWith("Config_MS_")) {
return PolicyConfigType.MicroService;
+ } else if(name.startsWith("Config_OOF_")) {
+ return PolicyConfigType.Optimization;
} else if(name.startsWith("Config_")) {
return PolicyConfigType.Base;
}
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java
index 9b86204e0..152e84ccf 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java
@@ -222,6 +222,9 @@ public class GetDictionaryService {
case "MicroServiceModels":
jsonString = jsonString.replace("microServiceModelsDictionaryDatas", "DictionaryDatas");
break;
+ case "OptimizationModels":
+ jsonString = jsonString.replace("optmizationModelsDictionaryDatas", "DictionaryDatas");
+ break;
case "PolicyScopeService":
jsonString = jsonString.replace("psServiceDictionaryDatas", "DictionaryDatas");
break;
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyService.java
new file mode 100644
index 000000000..61038d955
--- /dev/null
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyService.java
@@ -0,0 +1,110 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PDP-REST
+ * ================================================================================
+ * Copyright (C) 2018 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.pdp.rest.api.services;
+
+import javax.json.JsonException;
+import javax.json.JsonObject;
+import org.onap.policy.api.PolicyException;
+import org.onap.policy.api.PolicyParameters;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+import org.onap.policy.pdp.rest.api.utils.PolicyApiUtils;
+import org.onap.policy.xacml.api.XACMLErrorConstants;
+import org.onap.policy.xacml.std.pap.StdPAPPolicy;
+
+/**
+ * Optimization Policy implementation.
+ *
+ * @version 0.1
+ */
+public class OptimizationPolicyService{
+ private static final Logger LOGGER = FlexLogger.getLogger(OptimizationPolicyService.class.getName());
+
+ private PAPServices papServices = null;
+ private PolicyParameters policyParameters = null;
+ private String message = null;
+ private String policyName = null;
+ private String policyScope = null;
+ private String date = null;
+
+ public OptimizationPolicyService(String policyName, String policyScope, PolicyParameters policyParameters, String date) {
+ this.policyParameters = policyParameters;
+ this.policyName = policyName;
+ this.policyScope = policyScope;
+ this.date = date;
+ papServices = new PAPServices();
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public String getResult(boolean updateFlag) throws PolicyException{
+ String response = null;
+ String operation = null;
+
+ if (updateFlag){
+ operation = "update";
+ } else {
+ operation = "create";
+ }
+
+ // get values and attributes from the JsonObject
+ String servicModel = null;
+ String policyDescription=null;
+ String priority=null;
+ String version=null;
+
+ String onapName = policyParameters.getOnapName();
+ JsonObject optimizationAttributes = null;
+ try{
+ optimizationAttributes = PolicyApiUtils.stringToJsonObject(policyParameters.getConfigBody());
+ } catch(JsonException| IllegalStateException e){
+ message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody();
+ LOGGER.error("Error while parsing JSON body for MicroService Policy creation. ", e);
+ return null;
+ }
+
+ if (optimizationAttributes.get("service")!=null){
+ servicModel = optimizationAttributes.get("service").toString().replace("\"", "");
+ }
+ if(optimizationAttributes.containsKey("description")){
+ policyDescription = optimizationAttributes.get("description").toString().replace("\"", "");
+ }
+ if(optimizationAttributes.containsKey("priority")){
+ priority = optimizationAttributes.get("priority").toString().replace("\"", "");
+ }
+ if(optimizationAttributes.containsKey("version")){
+ version = optimizationAttributes.get("version").toString().replace("\"", "");
+ }
+
+ // Create Policy Object
+ StdPAPPolicy newPAPPolicy = new StdPAPPolicy("Optimization", policyName, policyDescription, onapName,
+ null, servicModel, null, null, optimizationAttributes.toString(), priority,
+ version, updateFlag, policyScope, 0, policyParameters.getRiskLevel(),
+ policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date);
+
+ // Send JSON Object to PAP
+ response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"},
+ policyParameters.getRequestID(), "ConfigOptimization");
+ LOGGER.info("Response: " + response);
+ return response;
+ }
+}
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PolicyEngineImportService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PolicyEngineImportService.java
index d0649d78a..f7c1cc578 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PolicyEngineImportService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PolicyEngineImportService.java
@@ -110,7 +110,8 @@ public class PolicyEngineImportService {
String fileName = file.getOriginalFilename();
switch (importParameters.getServiceType()){
case MICROSERVICE:
- if (fileName.endsWith(".xmi") || fileName.endsWith(".zip")){
+ case OPTIMIZATION:
+ if (fileName.endsWith(".yml") || fileName.endsWith(".xmi") || fileName.endsWith(".zip")){
try {
targetStream = new BufferedInputStream(file.getInputStream());
} catch (IOException e) {
@@ -164,7 +165,8 @@ public class PolicyEngineImportService {
message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Missing service Type value.";
return false;
}
- if(importParameters.getServiceType().equals(IMPORT_TYPE.MICROSERVICE) && (importParameters.getVersion()==null || importParameters.getVersion().trim().isEmpty())){
+ if((IMPORT_TYPE.MICROSERVICE.equals(importParameters.getServiceType()) || IMPORT_TYPE.OPTIMIZATION.equals(importParameters.getServiceType()))
+ && (importParameters.getVersion()==null || importParameters.getVersion().trim().isEmpty())){
message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Missing version value.";
return false;
}
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PushPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PushPolicyService.java
index a3d18b3e6..7ab17e0d0 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PushPolicyService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PushPolicyService.java
@@ -176,6 +176,9 @@ public class PushPolicyService {
} else if ("MicroService".equalsIgnoreCase(policyType)) {
clientScope = "ConfigMS";
filePrefix = "Config_MS_";
+ } else if ("Optimization".equalsIgnoreCase(policyType)) {
+ clientScope = "ConfigOptimization";
+ filePrefix = "Config_OOF_";
} else if ("BRMS_RAW".equalsIgnoreCase(policyType)) {
clientScope = "ConfigBrmsRaw";
filePrefix = "Config_BRMS_Raw_";