diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2018-03-26 21:39:45 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-26 21:39:45 +0000 |
commit | a65d684a684105c39a64181bbd44f1debb80fb06 (patch) | |
tree | 57311bb28988a777b990fc2776bfc5dc53a0fc35 /ONAP-PDP-REST/src/main/java | |
parent | cc7dca9a21765dca0ba336f27659a3852f6a15d9 (diff) | |
parent | b6d9063e06ab8cdf2d97fc75810792659344e4a8 (diff) |
Merge "New Optimization Policy"
Diffstat (limited to 'ONAP-PDP-REST/src/main/java')
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_"; |