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 com.att.research.xacml.std.annotations.XACMLAction;
26 import com.att.research.xacml.std.annotations.XACMLRequest;
27 import com.att.research.xacml.std.annotations.XACMLResource;
28 import com.att.research.xacml.std.annotations.XACMLSubject;
32 import lombok.ToString;
33 import org.onap.policy.models.decisions.concepts.DecisionRequest;
34 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
39 @XACMLRequest(ReturnPolicyIdList = true)
40 public class GuardPolicyRequest {
41 private static final String STR_GUARD = "guard";
43 @XACMLSubject(includeInResults = true)
44 private String onapName;
46 @XACMLSubject(includeInResults = true, attributeId = "urn:org:onap:onap-component")
47 private String onapComponent;
49 @XACMLSubject(includeInResults = true, attributeId = "urn:org:onap:onap-instance")
50 private String onapInstance;
52 @XACMLSubject(includeInResults = true, attributeId = "urn:org:onap:guard:request:request-id")
53 private String requestId;
56 private String action = STR_GUARD;
58 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:clname:clname-id")
59 private String clnameId;
61 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:actor:actor-id")
62 private String actorId;
64 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:operation:operation-id")
65 private String operationId;
67 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:target-id")
68 private String targetId;
70 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:vf-count")
71 private Integer vfCount;
73 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:generic-vnf.vnf-name")
74 private String vnfName;
76 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:generic-vnf.vnf-id")
79 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:generic-vnf.vnf-type")
80 private String vnfType;
82 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:generic-vnf.nf-naming-code")
83 private String vnfNfNamingCode;
85 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:vserver.vserver-id")
86 private String vserverId;
88 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:cloud-region.cloud-region-id")
89 private String cloudRegionId;
91 public static final String PREFIX_RESOURCE_ATTRIBUTE_ID = "urn:org:onap:guard:target:";
93 public GuardPolicyRequest() {
98 * Parses the DecisionRequest into a StdMetadataPolicyRequest.
100 * @param decisionRequest Input DecisionRequest
101 * @return StdMetadataPolicyRequest
102 * @throws ToscaPolicyConversionException If we cannot parse the request
104 @SuppressWarnings("unchecked")
105 public static GuardPolicyRequest createInstance(DecisionRequest decisionRequest)
106 throws ToscaPolicyConversionException {
108 // Create our return object
110 GuardPolicyRequest request = new GuardPolicyRequest();
112 // Add the subject attributes
114 request.onapName = decisionRequest.getOnapName();
115 request.onapComponent = decisionRequest.getOnapComponent();
116 request.onapInstance = decisionRequest.getOnapInstance();
117 request.requestId = decisionRequest.getRequestId();
119 // Now pull from the resources
121 Map<String, Object> resources = decisionRequest.getResource();
123 // Just in case nothing is in there
125 if (resources == null || resources.isEmpty() || !resources.containsKey(STR_GUARD)) {
127 // Perhaps we throw an exception and then caller
128 // can put together a response
132 Map<String, Object> guard = (Map<String, Object>) resources.get(STR_GUARD);
133 if (guard == null || guard.isEmpty()) {
135 // again, same problem throw an exception?
142 if (guard.containsKey("actor")) {
143 request.actorId = guard.get("actor").toString();
145 if (guard.containsKey("operation")) {
146 request.operationId = guard.get("operation").toString();
148 if (guard.containsKey("clname")) {
149 request.clnameId = guard.get("clname").toString();
151 if (guard.containsKey("target")) {
152 request.targetId = guard.get("target").toString();
154 if (guard.containsKey("vfCount")) {
156 request.vfCount = Integer.decode(guard.get("vfCount").toString());
157 } catch (NumberFormatException e) {
158 throw new ToscaPolicyConversionException("Failed to decode vfCount", e);
161 if (guard.containsKey("generic-vnf.vnf-name")) {
162 request.vnfName = guard.get("generic-vnf.vnf-name").toString();
164 if (guard.containsKey("generic-vnf.vnf-id")) {
165 request.vnfId = guard.get("generic-vnf.vnf-id").toString();
167 if (guard.containsKey("generic-vnf.vnf-type")) {
168 request.vnfType = guard.get("generic-vnf.vnf-type").toString();
170 if (guard.containsKey("generic-vnf.nf-naming-code")) {
171 request.vnfNfNamingCode = guard.get("generic-vnf.nf-naming-code").toString();
173 if (guard.containsKey("vserver.vserver-id")) {
174 request.vserverId = guard.get("vserver.vserver-id").toString();
176 if (guard.containsKey("cloud-region.cloud-region-id")) {
177 request.cloudRegionId = guard.get("cloud-region.cloud-region-id").toString();