2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.clds.client.req.policy;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
29 import java.util.HashMap;
32 import org.onap.clamp.clds.config.ClampProperties;
33 import org.onap.clamp.clds.model.properties.ModelProperties;
34 import org.onap.clamp.clds.model.properties.PolicyItem;
35 import org.onap.policy.api.AttributeType;
37 public class GuardPolicyAttributesConstructor {
38 private static final EELFLogger logger = EELFManager.getInstance()
39 .getLogger(GuardPolicyAttributesConstructor.class);
41 private GuardPolicyAttributesConstructor() {
44 public static Map<AttributeType, Map<String, String>> formatAttributes(ClampProperties refProp,
45 ModelProperties modelProperties, String modelElementId, PolicyItem policyItem) {
46 Map<String, String> matchingAttributes = prepareMatchingAttributes(refProp, policyItem, modelProperties);
47 return createAttributesMap(matchingAttributes);
50 private static Map<String, String> prepareMatchingAttributes(ClampProperties refProp,
51 PolicyItem policyItem, ModelProperties modelProp) {
52 logger.info("Preparing matching attributes for guard...");
53 Map<String, String> matchingAttributes = new HashMap<>();
54 matchingAttributes.put("actor",policyItem.getActor());
55 matchingAttributes.put("recipe",policyItem.getRecipe());
56 matchingAttributes.put("targets",policyItem.getGuardTargets());
57 matchingAttributes.put("clname",modelProp.getControlNameAndPolicyUniqueId());
58 if ("MinMax".equals(policyItem.getGuardPolicyType())) {
59 matchingAttributes.put("min",policyItem.getMinGuard());
60 matchingAttributes.put("max",policyItem.getMaxGuard());
61 } else if ("FrequencyLimiter".equals(policyItem.getGuardPolicyType())) {
62 matchingAttributes.put("limit",policyItem.getLimitGuard());
63 matchingAttributes.put("timeWindow",policyItem.getTimeWindowGuard());
64 matchingAttributes.put("timeUnits",policyItem.getTimeUnitsGuard());
66 matchingAttributes.put("guardActiveStart",policyItem.getGuardActiveStart());
67 matchingAttributes.put("guardActiveEnd",policyItem.getGuardActiveEnd());
69 logger.info("Prepared: " + matchingAttributes);
70 return matchingAttributes;
73 private static Map<AttributeType, Map<String, String>> createAttributesMap(Map<String, String> matchingAttributes) {
74 Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
75 attributes.put(AttributeType.MATCHING, matchingAttributes);