2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.admin;
23 import org.onap.policy.common.logging.flexlogger.FlexLogger;
24 import org.onap.policy.common.logging.flexlogger.Logger;
25 import org.onap.policy.controller.ActionPolicyController;
26 import org.onap.policy.controller.CreateBRMSParamController;
27 import org.onap.policy.controller.CreateBRMSRawController;
28 import org.onap.policy.controller.CreateClosedLoopFaultController;
29 import org.onap.policy.controller.CreateClosedLoopPMController;
30 import org.onap.policy.controller.CreateDcaeMicroServiceController;
31 import org.onap.policy.controller.CreateFirewallController;
32 import org.onap.policy.controller.CreateOptimizationController;
33 import org.onap.policy.controller.CreatePolicyController;
34 import org.onap.policy.controller.DecisionPolicyController;
35 import org.onap.policy.rest.adapter.PolicyRestAdapter;
36 import org.onap.policy.rest.jpa.PolicyEntity;
38 import com.att.research.xacml.util.XACMLProperties;
40 public class PolicyAdapter {
42 private static final Logger LOGGER = FlexLogger.getLogger(PolicyAdapter.class);
44 public void configure(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
45 if(extendedOptions(policyAdapter, entity)){
48 String policyNameValue = policyAdapter.getPolicyName().substring(0, policyAdapter.getPolicyName().indexOf('_'));
49 String configPolicyName = null ;
50 if(policyAdapter.getPolicyName().startsWith("Config_PM")){
51 configPolicyName = "ClosedLoop_PM";
52 }else if(policyAdapter.getPolicyName().startsWith("Config_Fault")){
53 configPolicyName = "ClosedLoop_Fault";
54 }else if(policyAdapter.getPolicyName().startsWith("Config_FW")){
55 configPolicyName = "Firewall Config";
56 }else if(policyAdapter.getPolicyName().startsWith("Config_BRMS_Raw")){
57 configPolicyName = "BRMS_Raw";
58 }else if(policyAdapter.getPolicyName().startsWith("Config_BRMS_Param")){
59 configPolicyName = "BRMS_Param";
60 }else if(policyAdapter.getPolicyName().startsWith("Config_MS")){
61 configPolicyName = "Micro Service";
62 }else if(policyAdapter.getPolicyName().startsWith("Config_OOF")){
63 configPolicyName = "Optimization";
64 }else if(policyAdapter.getPolicyName().startsWith("Action") || policyAdapter.getPolicyName().startsWith("Decision") ){
65 // No configPolicyName is applicable
67 configPolicyName = "Base";
69 if (policyNameValue != null) {
70 policyAdapter.setPolicyType(policyNameValue);
72 if (configPolicyName != null) {
73 policyAdapter.setConfigPolicyType(configPolicyName);
76 if("Action".equalsIgnoreCase(policyAdapter.getPolicyType())){
77 new ActionPolicyController().prePopulateActionPolicyData(policyAdapter, entity);
79 if("Decision".equalsIgnoreCase(policyAdapter.getPolicyType())){
80 new DecisionPolicyController().prePopulateDecisionPolicyData(policyAdapter, entity);
82 if("Config".equalsIgnoreCase(policyAdapter.getPolicyType())){
83 if("Base".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){
84 new CreatePolicyController().prePopulateBaseConfigPolicyData(policyAdapter, entity);
86 else if("BRMS_Raw".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){
87 new CreateBRMSRawController().prePopulateBRMSRawPolicyData(policyAdapter, entity);
89 else if("BRMS_Param".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){
90 new CreateBRMSParamController().prePopulateBRMSParamPolicyData(policyAdapter, entity);
92 else if("ClosedLoop_Fault".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){
93 new CreateClosedLoopFaultController().prePopulateClosedLoopFaultPolicyData(policyAdapter, entity);
95 else if("ClosedLoop_PM".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){
96 new CreateClosedLoopPMController().prePopulateClosedLoopPMPolicyData(policyAdapter, entity);
98 else if("Micro Service".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){
99 new CreateDcaeMicroServiceController().prePopulateDCAEMSPolicyData(policyAdapter, entity);
101 else if("Optimization".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){
102 new CreateOptimizationController().prePopulatePolicyData(policyAdapter, entity);
104 else if("Firewall Config".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){
105 new CreateFirewallController().prePopulateFWPolicyData(policyAdapter, entity);
110 public boolean extendedOptions(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
114 public static PolicyAdapter getInstance() {
116 Class<?> policyAdapter = Class.forName(XACMLProperties.getProperty("policyAdapter.impl.className", PolicyAdapter.class.getName()));
117 return (PolicyAdapter) policyAdapter.newInstance();
118 } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException e) {
119 LOGGER.error("Exception Occured"+e);