2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2020 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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.xacml.pdp.application.guard;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.List;
28 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
29 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslator;
30 import org.onap.policy.pdp.xacml.application.common.std.StdXacmlApplicationServiceProvider;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 * This class implements the onap.policies.controlloop.Guard policy implementations.
37 * @author pameladragosh
40 public class GuardPdpApplication extends StdXacmlApplicationServiceProvider {
41 private static final Logger LOGGER = LoggerFactory.getLogger(GuardPdpApplication.class);
42 private static final String STRING_VERSION100 = "1.0.0";
43 private List<ToscaPolicyTypeIdentifier> supportedPolicyTypes = new ArrayList<>();
44 private GuardTranslator guardTranslator = new GuardTranslator();
45 private CoordinationGuardTranslator coordinationTranslator = new CoordinationGuardTranslator();
51 public GuardPdpApplication() {
52 this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
53 GuardTranslator.POLICYTYPE_FREQUENCY,
55 this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
56 GuardTranslator.POLICYTYPE_MINMAX,
58 this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
59 GuardTranslator.POLICYTYPE_BLACKLIST,
61 this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
62 "onap.policies.controlloop.guard.coordination.FirstBlocksSecond",
67 public String applicationName() {
72 public List<String> actionDecisionsSupported() {
73 return Arrays.asList("guard");
77 public List<ToscaPolicyTypeIdentifier> supportedPolicyTypes() {
78 return supportedPolicyTypes;
82 public boolean canSupportPolicyType(ToscaPolicyTypeIdentifier policyTypeId) {
84 // For the time being, restrict this if the version isn't known.
85 // Could be too difficult to support changing of versions dynamically.
87 for (ToscaPolicyTypeIdentifier supported : this.supportedPolicyTypes) {
88 if (policyTypeId.equals(supported)) {
96 protected ToscaPolicyTranslator getTranslator(String type) {
97 LOGGER.debug("Policy type {}", type);
98 if (type.contains("coordination")) {
99 LOGGER.debug("returning coordinationTranslator");
100 return coordinationTranslator;
102 LOGGER.debug("returning guardTranslator");
103 return guardTranslator;