2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ============LICENSE_END=========================================================
22 package org.onap.policy.simulators;
24 import java.io.IOException;
25 import java.nio.charset.StandardCharsets;
26 import java.util.UUID;
27 import javax.ws.rs.Consumes;
28 import javax.ws.rs.GET;
29 import javax.ws.rs.PUT;
30 import javax.ws.rs.Path;
31 import javax.ws.rs.PathParam;
32 import javax.ws.rs.Produces;
33 import javax.ws.rs.QueryParam;
34 import javax.ws.rs.core.MediaType;
35 import org.apache.commons.io.IOUtils;
38 public class AaiSimulatorJaxRs {
40 private static final String DISABLE_CLOSEDLOOP = "disableClosedLoop";
41 private static final String ERROR = "error";
42 private static final String GETFAIL = "getFail";
47 * @param vnfId the VNF Id
51 @Path("/v8/network/generic-vnfs/generic-vnf/{vnfId}")
52 @Consumes(MediaType.APPLICATION_JSON)
53 @Produces("application/json")
54 public String aaiGetQuery(@PathParam("vnfID") final String vnfId) {
55 return "{\"relationship-list\": {\"relationship\":[{\"related-to-property\": [{\"property-key\": "
56 + "\"service-instance.service-instance-name\"}]},{\"related-to-property\": [ {\"property-key\": "
57 + "\"vserver.vserver-name\",\"property-value\": \"USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}";
66 @Path("/v16/search/nodes-query")
67 @Consumes(MediaType.APPLICATION_JSON)
68 @Produces("application/json")
69 public String aaiGetVserverQuery(@QueryParam("filter") final String filter) {
70 if (filter.equals("vserver-name:EQUALS:f953c499-4b1e-426b-8c6d-e9e9f1fc730f")
71 || filter.equals("vserver-name:EQUALS:OzVServer")
72 || filter.equals("vserver-name:EQUALS:testVserverName")) {
73 return "{\"result-data\":[{\"resource-type\": \"vserver\",\"resource-link\":\"/aai/v15/"
74 + "cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/tenants"
75 + "/tenant/3f2aaef74ecb4b19b35e26d0849fe9a2/vservers/vserver/"
76 + "6c3b3714-e36c-45af-9f16-7d3a73d99497\"}]}";
85 * @param req the request
86 * @return the response
87 * @throws IOException if a response file cannot be read
91 @Consumes(MediaType.APPLICATION_JSON)
92 @Produces("application/json")
93 public String aaiPutQuery(final String req) throws IOException {
94 return IOUtils.toString(getClass().getResource("aai/AaiCqResponse.json"),
95 StandardCharsets.UTF_8);
101 * @param vnfName the VNF name
102 * @return the response
105 @Path("/v11/network/generic-vnfs/generic-vnf")
106 @Consumes(MediaType.APPLICATION_JSON)
107 @Produces("application/json")
108 public String getByVnfName(@QueryParam("vnf-name") final String vnfName) {
109 if (GETFAIL.equals(vnfName)) {
110 return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not"
111 + " found for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/"
112 + "generic-vnf\",\"Node Not Found:No Node of type generic-vnf found at network/generic-vnfs"
113 + "/generic-vnf\",\"ERR.5.4.6114\"]}}}";
115 final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vnfName);
116 if (ERROR.equals(vnfName)) {
117 return "{ \"vnf-id\": \"error\", \"vnf-name\": \"" + vnfName
118 + "\", \"vnf-type\": \"RT\", \"service-id\": \"d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \""
119 + "equipment-role\": \"UCPE\", \"orchestration-status\": \"created\", \"management-option\": \""
120 + "ATT\", \"ipv4-oam-address\": \"32.40.68.35\", \"ipv4-loopback0-address\": \"32.40.64.57\", \""
121 + "nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345\", \"management-v6-address\": \""
122 + "2001:1890:e00e:fffd::36\", \"in-maint\": false, \"prov-status\":\"ACTIVE\", "
123 + "\"is-closed-loop-disabled\": " + isDisabled
124 + ", \"resource-version\": \"1493389458092\", \"relationship-list\": {\"relationship\":[{ \""
125 + "related-to\": \"service-instance\", \"related-link\": \"/aai/v11/business/customers/customer/"
126 + "1610_Func_Global_20160817084727/service-subscriptions/service-subscription/uCPE-VMS/"
127 + "service-instances/service-instance/USUCP0PCOIL0110UJZZ01\", \"relationship-data\":[{ \""
128 + "relationship-key\": \"customer.global-customer-id\", \"relationship-value\": \""
129 + "1610_Func_Global_20160817084727\"},{ \"relationship-key\": \"service-subscription.service-type"
130 + "\", \"relationship-value\": \"uCPE-VMS\"},{ \"relationship-key\": \""
131 + "service-instance.service-instance-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01"
132 + "\"} ], \"related-to-property\": [{\"property-key\": \"service-instance.service-instance-name"
133 + "\"}]},{ \"related-to\": \"vserver\", \"related-link\": \"/aai/v11/cloud-infrastructure/"
134 + "cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/"
135 + "USUCP0PCOIL0110UJZZ01%3A%3AuCPE-VMS/vservers/vserver/3b2558f4-39d8-40e7-bfc7-30660fb52c45"
136 + "\", \"relationship-data\":[{ \"relationship-key\": \"cloud-region.cloud-owner\", \""
137 + "relationship-value\": \"att-aic\"},{ \"relationship-key\": \"cloud-region.cloud-region-id"
138 + "\", \"relationship-value\": \"AAIAIC25\"},{ \"relationship-key\": \"tenant.tenant-id"
139 + "\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01::uCPE-VMS\"},{ \"relationship-key\": \""
140 + "vserver.vserver-id\", \"relationship-value\": \"3b2558f4-39d8-40e7-bfc7-30660fb52c45\"} ], \""
141 + "related-to-property\": [ {\"property-key\": \"vserver.vserver-name\",\"property-value\": \""
142 + "USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}";
145 final String vnfId = getUuidValue(vnfName, "5e49ca06-2972-4532-9ed4-6d071588d792");
146 return "{ \"vnf-id\": \"" + vnfId + "\", \"vnf-name\": \"" + vnfName
147 + "\", \"vnf-type\": \"RT\", \"service-id\": \"d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \""
148 + "equipment-role\": \"UCPE\", \"orchestration-status\": \"created\", \"management-option\": \"ATT"
149 + "\", \"ipv4-oam-address\": \"32.40.68.35\", \"ipv4-loopback0-address\": \"32.40.64.57\", \""
150 + "nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345\", \"management-v6-address\": \""
151 + "2001:1890:e00e:fffd::36\", \"in-maint\": false, \"prov-status\":\"ACTIVE\", "
152 + "\"is-closed-loop-disabled\": " + isDisabled
153 + ", \"resource-version\": \"1493389458092\", \"relationship-list\": {\"relationship\":[{ \""
154 + "related-to\": \"service-instance\", \"related-link\": \"/aai/v11/business/customers/customer"
155 + "/1610_Func_Global_20160817084727/service-subscriptions/service-subscription/uCPE-VMS/"
156 + "service-instances/service-instance/USUCP0PCOIL0110UJZZ01\", \"relationship-data\":[{ \""
157 + "relationship-key\": \"customer.global-customer-id\", \"relationship-value\": \""
158 + "1610_Func_Global_20160817084727\"},{ \"relationship-key\": \"service-subscription.service-type"
159 + "\", \"relationship-value\": \"uCPE-VMS\"},{ \"relationship-key\": \""
160 + "service-instance.service-instance-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01\"} ], \""
161 + "related-to-property\": [{\"property-key\": \"service-instance.service-instance-name\"}]},{ \""
162 + "related-to\": \"vserver\", \"related-link\": \"/aai/v11/cloud-infrastructure/cloud-regions/"
163 + "cloud-region/att-aic/AAIAIC25/tenants/tenant/USUCP0PCOIL0110UJZZ01%3A%3AuCPE-VMS/vservers/vserver"
164 + "/3b2558f4-39d8-40e7-bfc7-30660fb52c45\", \"relationship-data\":[{ \"relationship-key\": \""
165 + "cloud-region.cloud-owner\", \"relationship-value\": \"att-aic\"},{ \"relationship-key\": \""
166 + "cloud-region.cloud-region-id\", \"relationship-value\": \"AAIAIC25\"},{ \"relationship-key\": \""
167 + "tenant.tenant-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01::uCPE-VMS\"},{ \""
168 + "relationship-key\": \"vserver.vserver-id\", \"relationship-value\": \""
169 + "3b2558f4-39d8-40e7-bfc7-30660fb52c45\"} ], \"related-to-property\": [ {\"property-key\": \""
170 + "vserver.vserver-name\",\"property-value\": \"USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}";
176 * @param vnfId the VNF Id
177 * @return the response
180 @Path("/v11/network/generic-vnfs/generic-vnf/{vnfId}")
181 @Consumes(MediaType.APPLICATION_JSON)
182 @Produces("application/json")
183 public String getByVnfId(@PathParam("vnfId") final String vnfId) {
184 if (GETFAIL.equals(vnfId)) {
185 return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found"
186 + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/"
187 + "generic-vnf/getFail\",\"Node Not Found:No Node of type generic-vnf found at network/"
188 + "generic-vnfs/generic-vnf/getFail\",\"ERR.5.4.6114\"]}}}";
190 final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vnfId);
191 final String vnfName = getUuidValue(vnfId, "USUCP0PCOIL0110UJRT01");
192 return "{ \"vnf-id\": \"" + vnfId + "\", \"vnf-name\": \"" + vnfName
193 + "\", \"vnf-type\": \"RT\", \"service-id\": \""
194 + "d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \"equipment-role\": \"UCPE\", \"orchestration-status"
195 + "\": \"created\", \"management-option\": \"ATT\", \"ipv4-oam-address\": \"32.40.68.35\", \""
196 + "ipv4-loopback0-address\": \"32.40.64.57\", \"nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345"
197 + "\", \"management-v6-address\": \"2001:1890:e00e:fffd::36\", \"in-maint\": false, "
198 + "\"prov-status\":\"ACTIVE\", \"" + "" + "is-closed-loop-disabled\": " + isDisabled
199 + ", \"resource-version\": \"1493389458092\", \""
200 + "relationship-list\": {\"relationship\":[{ \"related-to\": \"service-instance\", \"related-link"
201 + "\": \"/aai/v11/business/customers/customer/1610_Func_Global_20160817084727/service-subscriptions"
202 + "/service-subscription/uCPE-VMS/service-instances/service-instance/USUCP0PCOIL0110UJZZ01\", \""
203 + "relationship-data\":[{ \"relationship-key\": \"customer.global-customer-id\", \""
204 + "relationship-value\": \"1610_Func_Global_20160817084727\"},{ \"relationship-key\": \""
205 + "service-subscription.service-type\", \"relationship-value\": \"uCPE-VMS\"},{ \"relationship-key"
206 + "\": \"service-instance.service-instance-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01\"} "
207 + "], \"related-to-property\": [{\"property-key\": \"service-instance.service-instance-name\"}]},"
208 + "{ \"related-to\": \"vserver\", \"related-link\": \"/aai/v11/cloud-infrastructure/cloud-regions/"
209 + "cloud-region/att-aic/AAIAIC25/tenants/tenant/USUCP0PCOIL0110UJZZ01%3A%3AuCPE-VMS/vservers/vserver"
210 + "/3b2558f4-39d8-40e7-bfc7-30660fb52c45\", \"relationship-data\":[{ \"relationship-key\": \""
211 + "cloud-region.cloud-owner\", \"relationship-value\": \"att-aic\"},{ \"relationship-key\": \""
212 + "cloud-region.cloud-region-id\", \"relationship-value\": \"AAIAIC25\"},{ \"relationship-key\": \""
213 + "tenant.tenant-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01::uCPE-VMS\"},{ \""
214 + "relationship-key\": \"vserver.vserver-id\", \"relationship-value\": \""
215 + "3b2558f4-39d8-40e7-bfc7-30660fb52c45\"} ], \"related-to-property\": [ {\"property-key\": \""
216 + "vserver.vserver-name\",\"property-value\": \"USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}";
220 * Get by VServer name.
222 * @param vserverName the VServer name
223 * @return the response
226 @Path("/v11/nodes/vservers")
227 @Consumes(MediaType.APPLICATION_JSON)
228 @Produces("application/json")
229 public String getByVserverName(@QueryParam("vserver-name") final String vserverName) {
230 if (GETFAIL.equals(vserverName)) {
231 return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found"
232 + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"nodes/vservers\",\"Node Not"
233 + " Found:No Node of type generic-vnf found at nodes/vservers\",\"ERR.5.4.6114\"]}}}";
235 final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vserverName);
236 final String vserverId = getUuidValue(vserverName, "d0668d4f-c25e-4a1b-87c4-83845c01efd8");
237 return "{\"vserver\": [{ \"vserver-id\": \"" + vserverId + "\", \"vserver-name\": \""
239 + "\", \"vserver-name2\": \"vjunos0\", \"vserver-selflink\": \"https://aai-ext1.test.att.com:8443/aai/v7/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/USMSO1SX7NJ0103UJZZ01%3A%3AuCPE-VMS/vservers/vserver/d0668d4f-c25e-4a1b-87c4-83845c01efd8\", \"in-maint\": false, \"is-closed-loop-disabled\": "
240 + isDisabled + ", \"prov-status\":\"ACTIVE\", \"resource-version\": \"1494001931513\", "
241 + "\"relationship-list\": {\"relationship\":[{ \"related-to"
242 + "\": \"generic-vnf\", \"related-link\": \"/aai/v11/network/generic-vnfs/generic-vnf/"
243 + "e1a41e99-4ede-409a-8f9d-b5e12984203a\", \"relationship-data\": [ {\"relationship-key\": \""
244 + "generic-vnf.vnf-id\",\"relationship-value\": \"e1a41e99-4ede-409a-8f9d-b5e12984203a\" }], \""
245 + "related-to-property\": [ {\"property-key\": \"generic-vnf.vnf-name\",\"property-value\": \""
246 + "USMSO1SX7NJ0103UJSW01\" }]},{ \"related-to\": \"pserver\", \"related-link\": \"/aai/v11/"
247 + "cloud-infrastructure/pservers/pserver/USMSO1SX7NJ0103UJZZ01\", \"relationship-data\": [ {\""
248 + "relationship-key\": \"pserver.hostname\",\"relationship-value\": \"USMSO1SX7NJ0103UJZZ01\" }], \""
249 + "related-to-property\": [{\"property-key\": \"pserver.pserver-name2\"}]} ]}}]}";
252 private String getUuidValue(final String value, final String defaultValue) {
253 return value != null ? UUID.nameUUIDFromBytes(value.getBytes()).toString() : defaultValue;