Monitoring policy creation foundation
[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 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.xacml.pdp.application.guard;
24
25 import com.google.common.collect.Lists;
26
27 import java.nio.file.Path;
28 import java.util.Arrays;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32
33 import org.json.JSONObject;
34 import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 /**
39  * This class implements the onap.policies.controlloop.Guard policy implementations.
40  *
41  * @author pameladragosh
42  *
43  */
44 public class GuardPdpApplication implements XacmlApplicationServiceProvider {
45
46     private static final Logger LOGGER = LoggerFactory.getLogger(GuardPdpApplication.class);
47     private static final String STRING_VERSION100 = "1.0.0";
48     private Map<String, String> supportedPolicyTypes = new HashMap<>();
49     private Path pathForData;
50
51     /** Constructor.
52      *
53      */
54     public GuardPdpApplication() {
55         this.supportedPolicyTypes.put("onap.policies.controlloop.guard.FrequencyLimiter", STRING_VERSION100);
56         this.supportedPolicyTypes.put("onap.policies.controlloop.guard.MinMax", STRING_VERSION100);
57     }
58
59     @Override
60     public String applicationName() {
61         return "Guard Application";
62     }
63
64     @Override
65     public List<String> actionDecisionsSupported() {
66         return Arrays.asList("guard");
67     }
68
69     @Override
70     public void initialize(Path pathForData) {
71         //
72         // Save the path
73         //
74         this.pathForData = pathForData;
75         LOGGER.debug("New Path is {}", this.pathForData.toAbsolutePath());
76     }
77
78     @Override
79     public List<String> supportedPolicyTypes() {
80         return Lists.newArrayList(supportedPolicyTypes.keySet());
81     }
82
83     @Override
84     public boolean canSupportPolicyType(String policyType, String policyTypeVersion) {
85         //
86         // For the time being, restrict this if the version isn't known.
87         // Could be too difficult to support changing of versions dynamically.
88         //
89         if (! this.supportedPolicyTypes.containsKey(policyType)) {
90             return false;
91         }
92         //
93         // Must match version exactly
94         //
95         return this.supportedPolicyTypes.get(policyType).equals(policyTypeVersion);
96     }
97
98     @Override
99     public void loadPolicies(Map<String, Object> toscaPolicies) {
100     }
101
102     @Override
103     public JSONObject makeDecision(JSONObject jsonSchema) {
104         return null;
105     }
106
107 }