91c46746fd032ba909f55578a03612c984e68f1d
[policy/xacml-pdp.git] / applications / optimization / src / main / java / org / onap / policy / xacml / pdp / application / optimization / OptimizationPdpApplication.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.optimization;
24
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.List;
29
30 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
31 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslator;
32 import org.onap.policy.pdp.xacml.application.common.std.StdMatchableTranslator;
33 import org.onap.policy.pdp.xacml.application.common.std.StdXacmlApplicationServiceProvider;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 public class OptimizationPdpApplication extends StdXacmlApplicationServiceProvider {
38
39     private static final Logger LOGGER = LoggerFactory.getLogger(OptimizationPdpApplication.class);
40     private static final String STRING_VERSION100 = "1.0.0";
41
42     private StdMatchableTranslator translator = new StdMatchableTranslator();
43     private List<ToscaPolicyTypeIdentifier> supportedPolicyTypes = new ArrayList<>();
44
45     /**
46      * Constructor.
47      */
48     public OptimizationPdpApplication() {
49         this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
50                 "onap.policies.optimization.AffinityPolicy", STRING_VERSION100));
51         this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
52                 "onap.policies.optimization.DistancePolicy", STRING_VERSION100));
53         this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
54                 "onap.policies.optimization.HpaPolicy", STRING_VERSION100));
55         this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
56                 "onap.policies.optimization.OptimizationPolicy", STRING_VERSION100));
57         this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
58                 "onap.policies.optimization.PciPolicy", STRING_VERSION100));
59         this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
60                 "onap.policies.optimization.QueryPolicy", STRING_VERSION100));
61         this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
62                 "onap.policies.optimization.SubscriberPolicy", STRING_VERSION100));
63         this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
64                 "onap.policies.optimization.Vim_fit", STRING_VERSION100));
65         this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
66                 "onap.policies.optimization.VnfPolicy", STRING_VERSION100));
67     }
68
69     @Override
70     public String applicationName() {
71         return "optimization";
72     }
73
74     @Override
75     public List<String> actionDecisionsSupported() {
76         return Arrays.asList("optimize");
77     }
78
79     @Override
80     public synchronized List<ToscaPolicyTypeIdentifier> supportedPolicyTypes() {
81         return Collections.unmodifiableList(supportedPolicyTypes);
82     }
83
84     @Override
85     public boolean canSupportPolicyType(ToscaPolicyTypeIdentifier policyTypeId) {
86         //
87         // For the time being, restrict this if the version isn't known.
88         // Could be too difficult to support changing of versions dynamically.
89         //
90         //
91         // For the time being, restrict this if the version isn't known.
92         // Could be too difficult to support changing of versions dynamically.
93         //
94         for (ToscaPolicyTypeIdentifier supported : this.supportedPolicyTypes) {
95             if (policyTypeId.equals(supported)) {
96                 LOGGER.info("optimization can support {}", supported);
97                 return true;
98             }
99         }
100         return false;
101     }
102
103     @Override
104     protected ToscaPolicyTranslator getTranslator(String type) {
105         return translator;
106     }
107
108 }