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