1832945ca04337213d627bb1da47f5948d9f6700
[policy/xacml-pdp.git] / applications / guard / src / main / java / org / onap / policy / xacml / pdp / application / guard / GuardPdpApplication.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2021 Nordix Foundation.
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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  *
20  * SPDX-License-Identifier: Apache-2.0
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.policy.xacml.pdp.application.guard;
25
26 import java.util.Arrays;
27 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
28 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslator;
29 import org.onap.policy.pdp.xacml.application.common.std.StdXacmlApplicationServiceProvider;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 /**
34  * This class implements the onap.policies.controlloop.Guard policy implementations.
35  *
36  * @author pameladragosh
37  *
38  */
39 public class GuardPdpApplication extends StdXacmlApplicationServiceProvider {
40     private static final Logger LOGGER = LoggerFactory.getLogger(GuardPdpApplication.class);
41     private static final String STRING_VERSION100 = "1.0.0";
42
43     private GuardTranslator guardTranslator = new GuardTranslator();
44     private CoordinationGuardTranslator coordinationTranslator = new CoordinationGuardTranslator();
45
46     /**
47      * Constructor.
48      *
49      */
50     public GuardPdpApplication() {
51         super();
52
53         applicationName = "guard";
54         actions = Arrays.asList("guard");
55
56         this.supportedPolicyTypes.add(new ToscaConceptIdentifier(
57                 GuardTranslator.POLICYTYPE_FREQUENCY,
58                 STRING_VERSION100));
59         this.supportedPolicyTypes.add(new ToscaConceptIdentifier(
60                 GuardTranslator.POLICYTYPE_MINMAX,
61                 STRING_VERSION100));
62         this.supportedPolicyTypes.add(new ToscaConceptIdentifier(
63                 GuardTranslator.POLICYTYPE_BLACKLIST,
64                 STRING_VERSION100));
65         this.supportedPolicyTypes.add(new ToscaConceptIdentifier(
66                 GuardTranslator.POLICYTYPE_FILTER,
67                 STRING_VERSION100));
68         this.supportedPolicyTypes.add(new ToscaConceptIdentifier(
69                 "onap.policies.controlloop.guard.coordination.FirstBlocksSecond",
70                 STRING_VERSION100));
71     }
72
73     @Override
74     public boolean canSupportPolicyType(ToscaConceptIdentifier policyTypeId) {
75         //
76         // For the time being, restrict this if the version isn't known.
77         // Could be too difficult to support changing of versions dynamically.
78         //
79         for (ToscaConceptIdentifier supported : this.supportedPolicyTypes) {
80             if (policyTypeId.equals(supported)) {
81                 return true;
82             }
83         }
84         return false;
85     }
86
87     @Override
88     protected ToscaPolicyTranslator getTranslator(String type) {
89         LOGGER.debug("Policy type {}", type);
90         if (type.contains("coordination")) {
91             LOGGER.debug("returning coordinationTranslator");
92             return coordinationTranslator;
93         } else {
94             LOGGER.debug("returning guardTranslator");
95             return guardTranslator;
96         }
97     }
98
99 }