aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PDP-REST/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-PDP-REST/src/main/java')
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpLoader.java18
-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/PAPServices.java24
-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
9 files changed, 151 insertions, 24 deletions
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpLoader.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpLoader.java
index 5c9f8602f..102d43f0c 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpLoader.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpLoader.java
@@ -550,20 +550,14 @@ public class XACMLPdpLoader {
// properties
//
changed = true;
+ } catch (MalformedURLException e) {
+ papUrls.failed();
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Policy '" + policy
+ + "' had bad URL in new configuration, URL='" + propLocation + "'");
} catch (Exception e) {
papUrls.failed();
- if (e instanceof MalformedURLException) {
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Policy '"
- + policy
- + "' had bad URL in new configuration, URL='"
- + propLocation + "'");
-
- } else {
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while retrieving policy "
- + policy
- + " from URL "
- + url + ", e=" + e);
- }
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while retrieving policy "
+ + policy + " from URL " + url + ", e=" + e);
}
papUrls.getNext();
}
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/PAPServices.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java
index 59194841f..3c0ea3894 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java
@@ -54,12 +54,16 @@ public class PAPServices {
private int responseCode = 0;
private static String environment = "DEVL";
- public static Boolean junit = false;
+ private static Boolean isJunit = false;
private static List<String> paps = null;
private static final Object papResourceLock = new Object();
private String operation = null;
private String requestMethod = null;
- private String encoding = null;
+ private String encoding = null;
+
+ public static void setJunit(boolean isJunit) {
+ PAPServices.isJunit = isJunit;
+ }
public PAPServices() {
environment = PDPApiAuth.getEnvironment();
@@ -164,7 +168,7 @@ public class PAPServices {
} else if(content != null){
// the content is an object to be encoded in JSON
ObjectMapper mapper = new ObjectMapper();
- if (!junit) {
+ if (!isJunit) {
mapper.writeValue(connection.getOutputStream(),
content);
}
@@ -174,7 +178,7 @@ public class PAPServices {
responseCode = connection.getResponseCode();
// If Connected to PAP then break from the loop and continue
// with the Request
- if (connection.getResponseCode() > 0 || junit) {
+ if (connection.getResponseCode() > 0 || isJunit) {
connected = true;
break;
} else {
@@ -183,7 +187,7 @@ public class PAPServices {
}
} catch (Exception e) {
// This means that the PAP is not working
- if (junit) {
+ if (isJunit) {
connected = true;
break;
}
@@ -212,7 +216,7 @@ public class PAPServices {
XACMLErrorConstants.ERROR_SYSTEM_ERROR
+ "Decoding the result ", e);
}
- if (junit) {
+ if (isJunit) {
response = SUCCESS;
}
}else{
@@ -326,10 +330,10 @@ public class PAPServices {
private String checkResponse(HttpURLConnection connection, UUID requestID) throws IOException {
String response = null;
- if (responseCode == 200 || junit) {
+ if (responseCode == 200 || isJunit) {
// Check for successful creation of policy
String isSuccess = null;
- if (!junit) { // is this a junit test?
+ if (!isJunit) { // is this a junit test?
isSuccess = connection.getHeaderField("successMapKey");
operation = connection.getHeaderField("operation");
} else {
@@ -603,7 +607,7 @@ public class PAPServices {
responseCode = connection.getResponseCode();
// If Connected to PAP then break from the loop and continue
// with the Request
- if (connection.getResponseCode() > 0 || junit) {
+ if (connection.getResponseCode() > 0 || isJunit) {
connected = true;
break;
} else {
@@ -612,7 +616,7 @@ public class PAPServices {
}
} catch (Exception e) {
// This means that the PAP is not working
- if (junit) {
+ if (isJunit) {
connected = true;
break;
}
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_";