Bump models to 2.3.6 snapshot
[policy/models.git] / models-interactions / model-simulators / src / main / java / org / onap / policy / simulators / AaiSimulatorJaxRs.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * simulators
4  * ================================================================================
5  * Copyright (C) 2017-2018, 2020 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
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  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.simulators;
23
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;
36
37 @Path("/aai")
38 public class AaiSimulatorJaxRs {
39
40     private static final String DISABLE_CLOSEDLOOP = "disableClosedLoop";
41     private static final String ERROR = "error";
42     private static final String GETFAIL = "getFail";
43
44     /**
45      * A&AI get query.
46      *
47      * @param vnfId the VNF Id
48      * @return the result
49      */
50     @GET
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\" }]} ]}}";
58     }
59
60     /**
61      * A&AI get query.
62      *
63      * @return the result
64      */
65     @GET
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:Ete_vFWCLvFWSNK_7ba1fbde_0")
72             || filter.equals("vserver-name:EQUALS:OzVServer")
73             || filter.equals("vserver-name:EQUALS:testVserverName")) {
74             return "{\"result-data\":[{\"resource-type\": \"vserver\",\"resource-link\":\"/aai/v15/"
75                 + "cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/tenants"
76                 + "/tenant/3f2aaef74ecb4b19b35e26d0849fe9a2/vservers/vserver/"
77                 + "6c3b3714-e36c-45af-9f16-7d3a73d99497\"}]}";
78         } else {
79             return null;
80         }
81     }
82
83     /**
84      * A&AI put query.
85      *
86      * @param req the request
87      * @return the response
88      * @throws IOException if a response file cannot be read
89      */
90     @PUT
91     @Path("/v16/query")
92     @Consumes(MediaType.APPLICATION_JSON)
93     @Produces("application/json")
94     public String aaiPutQuery(final String req) throws IOException {
95         return IOUtils.toString(getClass().getResource("aai/AaiCqResponse.json"),
96             StandardCharsets.UTF_8);
97     }
98
99     /**
100      * A&AI get PNF query.
101      *
102      * @return the result
103      * @throws IOException if a response file cannot be read
104      */
105     @GET
106     @Path("/v16/network/pnfs/pnf/{pnfName}")
107     @Consumes(MediaType.APPLICATION_JSON)
108     @Produces("application/json")
109     public String aaiGetPnfQuery(@PathParam("pnfName") final String pnfName) throws IOException {
110         if (GETFAIL.equals(pnfName)) {
111             throw new IllegalArgumentException("query failed, as requested");
112         }
113
114         return IOUtils.toString(getClass().getResource("aai/AaiGetPnfResponse.json"),
115                         StandardCharsets.UTF_8);
116     }
117
118     /**
119      * Get by VNF name.
120      *
121      * @param vnfName the VNF name
122      * @return the response
123      */
124     @GET
125     @Path("/v11/network/generic-vnfs/generic-vnf")
126     @Consumes(MediaType.APPLICATION_JSON)
127     @Produces("application/json")
128     public String getByVnfName(@QueryParam("vnf-name") final String vnfName) {
129         if (GETFAIL.equals(vnfName)) {
130             return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not"
131                 + " found for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/"
132                 + "generic-vnf\",\"Node Not Found:No Node of type generic-vnf found at network/generic-vnfs"
133                 + "/generic-vnf\",\"ERR.5.4.6114\"]}}}";
134         }
135         final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vnfName);
136         if (ERROR.equals(vnfName)) {
137             return "{ \"vnf-id\": \"error\", \"vnf-name\": \"" + vnfName
138                 + "\", \"vnf-type\": \"RT\", \"service-id\": \"d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \""
139                 + "equipment-role\": \"UCPE\", \"orchestration-status\": \"created\", \"management-option\": \""
140                 + "ATT\", \"ipv4-oam-address\": \"32.40.68.35\", \"ipv4-loopback0-address\": \"32.40.64.57\", \""
141                 + "nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345\", \"management-v6-address\": \""
142                 + "2001:1890:e00e:fffd::36\", \"in-maint\": false, \"prov-status\":\"ACTIVE\", "
143                 + "\"is-closed-loop-disabled\": " + isDisabled
144                 + ", \"resource-version\": \"1493389458092\", \"relationship-list\": {\"relationship\":[{ \""
145                 + "related-to\": \"service-instance\", \"related-link\": \"/aai/v11/business/customers/customer/"
146                 + "1610_Func_Global_20160817084727/service-subscriptions/service-subscription/uCPE-VMS/"
147                 + "service-instances/service-instance/USUCP0PCOIL0110UJZZ01\", \"relationship-data\":[{ \""
148                 + "relationship-key\": \"customer.global-customer-id\", \"relationship-value\": \""
149                 + "1610_Func_Global_20160817084727\"},{ \"relationship-key\": \"service-subscription.service-type"
150                 + "\", \"relationship-value\": \"uCPE-VMS\"},{ \"relationship-key\": \""
151                 + "service-instance.service-instance-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01"
152                 + "\"} ], \"related-to-property\": [{\"property-key\": \"service-instance.service-instance-name"
153                 + "\"}]},{ \"related-to\": \"vserver\", \"related-link\": \"/aai/v11/cloud-infrastructure/"
154                 + "cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/"
155                 + "USUCP0PCOIL0110UJZZ01%3A%3AuCPE-VMS/vservers/vserver/3b2558f4-39d8-40e7-bfc7-30660fb52c45"
156                 + "\", \"relationship-data\":[{ \"relationship-key\": \"cloud-region.cloud-owner\", \""
157                 + "relationship-value\": \"att-aic\"},{ \"relationship-key\": \"cloud-region.cloud-region-id"
158                 + "\", \"relationship-value\": \"AAIAIC25\"},{ \"relationship-key\": \"tenant.tenant-id"
159                 + "\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01::uCPE-VMS\"},{ \"relationship-key\": \""
160                 + "vserver.vserver-id\", \"relationship-value\": \"3b2558f4-39d8-40e7-bfc7-30660fb52c45\"} ], \""
161                 + "related-to-property\": [ {\"property-key\": \"vserver.vserver-name\",\"property-value\": \""
162                 + "USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}";
163
164         }
165         final String vnfId = getUuidValue(vnfName, "5e49ca06-2972-4532-9ed4-6d071588d792");
166         return "{ \"vnf-id\": \"" + vnfId + "\", \"vnf-name\": \"" + vnfName
167             + "\", \"vnf-type\": \"RT\", \"service-id\": \"d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \""
168             + "equipment-role\": \"UCPE\", \"orchestration-status\": \"created\", \"management-option\": \"ATT"
169             + "\", \"ipv4-oam-address\": \"32.40.68.35\", \"ipv4-loopback0-address\": \"32.40.64.57\", \""
170             + "nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345\", \"management-v6-address\": \""
171             + "2001:1890:e00e:fffd::36\", \"in-maint\": false, \"prov-status\":\"ACTIVE\", "
172             + "\"is-closed-loop-disabled\": " + isDisabled
173             + ", \"resource-version\": \"1493389458092\", \"relationship-list\": {\"relationship\":[{ \""
174             + "related-to\": \"service-instance\", \"related-link\": \"/aai/v11/business/customers/customer"
175             + "/1610_Func_Global_20160817084727/service-subscriptions/service-subscription/uCPE-VMS/"
176             + "service-instances/service-instance/USUCP0PCOIL0110UJZZ01\", \"relationship-data\":[{ \""
177             + "relationship-key\": \"customer.global-customer-id\", \"relationship-value\": \""
178             + "1610_Func_Global_20160817084727\"},{ \"relationship-key\": \"service-subscription.service-type"
179             + "\", \"relationship-value\": \"uCPE-VMS\"},{ \"relationship-key\": \""
180             + "service-instance.service-instance-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01\"} ], \""
181             + "related-to-property\": [{\"property-key\": \"service-instance.service-instance-name\"}]},{ \""
182             + "related-to\": \"vserver\", \"related-link\": \"/aai/v11/cloud-infrastructure/cloud-regions/"
183             + "cloud-region/att-aic/AAIAIC25/tenants/tenant/USUCP0PCOIL0110UJZZ01%3A%3AuCPE-VMS/vservers/vserver"
184             + "/3b2558f4-39d8-40e7-bfc7-30660fb52c45\", \"relationship-data\":[{ \"relationship-key\": \""
185             + "cloud-region.cloud-owner\", \"relationship-value\": \"att-aic\"},{ \"relationship-key\": \""
186             + "cloud-region.cloud-region-id\", \"relationship-value\": \"AAIAIC25\"},{ \"relationship-key\": \""
187             + "tenant.tenant-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01::uCPE-VMS\"},{ \""
188             + "relationship-key\": \"vserver.vserver-id\", \"relationship-value\": \""
189             + "3b2558f4-39d8-40e7-bfc7-30660fb52c45\"} ], \"related-to-property\": [ {\"property-key\": \""
190             + "vserver.vserver-name\",\"property-value\": \"USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}";
191     }
192
193     /**
194      * Get by VNF Id.
195      *
196      * @param vnfId the VNF Id
197      * @return the response
198      */
199     @GET
200     @Path("/v11/network/generic-vnfs/generic-vnf/{vnfId}")
201     @Consumes(MediaType.APPLICATION_JSON)
202     @Produces("application/json")
203     public String getByVnfId(@PathParam("vnfId") final String vnfId) {
204         if (GETFAIL.equals(vnfId)) {
205             return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found"
206                 + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/"
207                 + "generic-vnf/getFail\",\"Node Not Found:No Node of type generic-vnf found at network/"
208                 + "generic-vnfs/generic-vnf/getFail\",\"ERR.5.4.6114\"]}}}";
209         }
210         final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vnfId);
211         final String vnfName = getUuidValue(vnfId, "USUCP0PCOIL0110UJRT01");
212         return "{ \"vnf-id\": \"" + vnfId + "\", \"vnf-name\": \"" + vnfName
213             + "\", \"vnf-type\": \"RT\", \"service-id\": \""
214             + "d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \"equipment-role\": \"UCPE\", \"orchestration-status"
215             + "\": \"created\", \"management-option\": \"ATT\", \"ipv4-oam-address\": \"32.40.68.35\", \""
216             + "ipv4-loopback0-address\": \"32.40.64.57\", \"nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345"
217             + "\", \"management-v6-address\": \"2001:1890:e00e:fffd::36\", \"in-maint\": false, "
218             + "\"prov-status\":\"ACTIVE\", \"" + "" + "is-closed-loop-disabled\": " + isDisabled
219             + ", \"resource-version\": \"1493389458092\", \""
220             + "relationship-list\": {\"relationship\":[{ \"related-to\": \"service-instance\", \"related-link"
221             + "\": \"/aai/v11/business/customers/customer/1610_Func_Global_20160817084727/service-subscriptions"
222             + "/service-subscription/uCPE-VMS/service-instances/service-instance/USUCP0PCOIL0110UJZZ01\", \""
223             + "relationship-data\":[{ \"relationship-key\": \"customer.global-customer-id\", \""
224             + "relationship-value\": \"1610_Func_Global_20160817084727\"},{ \"relationship-key\": \""
225             + "service-subscription.service-type\", \"relationship-value\": \"uCPE-VMS\"},{ \"relationship-key"
226             + "\": \"service-instance.service-instance-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01\"} "
227             + "], \"related-to-property\": [{\"property-key\": \"service-instance.service-instance-name\"}]},"
228             + "{ \"related-to\": \"vserver\", \"related-link\": \"/aai/v11/cloud-infrastructure/cloud-regions/"
229             + "cloud-region/att-aic/AAIAIC25/tenants/tenant/USUCP0PCOIL0110UJZZ01%3A%3AuCPE-VMS/vservers/vserver"
230             + "/3b2558f4-39d8-40e7-bfc7-30660fb52c45\", \"relationship-data\":[{ \"relationship-key\": \""
231             + "cloud-region.cloud-owner\", \"relationship-value\": \"att-aic\"},{ \"relationship-key\": \""
232             + "cloud-region.cloud-region-id\", \"relationship-value\": \"AAIAIC25\"},{ \"relationship-key\": \""
233             + "tenant.tenant-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01::uCPE-VMS\"},{ \""
234             + "relationship-key\": \"vserver.vserver-id\", \"relationship-value\": \""
235             + "3b2558f4-39d8-40e7-bfc7-30660fb52c45\"} ], \"related-to-property\": [ {\"property-key\": \""
236             + "vserver.vserver-name\",\"property-value\": \"USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}";
237     }
238
239     /**
240      * Get by VServer name.
241      *
242      * @param vserverName the VServer name
243      * @return the response
244      */
245     @GET
246     @Path("/v11/nodes/vservers")
247     @Consumes(MediaType.APPLICATION_JSON)
248     @Produces("application/json")
249     public String getByVserverName(@QueryParam("vserver-name") final String vserverName) {
250         if (GETFAIL.equals(vserverName)) {
251             return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found"
252                 + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"nodes/vservers\",\"Node Not"
253                 + " Found:No Node of type generic-vnf found at nodes/vservers\",\"ERR.5.4.6114\"]}}}";
254         }
255         final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vserverName);
256         final String vserverId = getUuidValue(vserverName, "d0668d4f-c25e-4a1b-87c4-83845c01efd8");
257         return "{\"vserver\": [{ \"vserver-id\": \"" + vserverId + "\", \"vserver-name\": \""
258             + vserverName
259             + "\", \"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\": "
260             + isDisabled + ", \"prov-status\":\"ACTIVE\", \"resource-version\": \"1494001931513\", "
261             + "\"relationship-list\": {\"relationship\":[{ \"related-to"
262             + "\": \"generic-vnf\", \"related-link\": \"/aai/v11/network/generic-vnfs/generic-vnf/"
263             + "e1a41e99-4ede-409a-8f9d-b5e12984203a\", \"relationship-data\": [ {\"relationship-key\": \""
264             + "generic-vnf.vnf-id\",\"relationship-value\": \"e1a41e99-4ede-409a-8f9d-b5e12984203a\" }], \""
265             + "related-to-property\": [ {\"property-key\": \"generic-vnf.vnf-name\",\"property-value\": \""
266             + "USMSO1SX7NJ0103UJSW01\" }]},{ \"related-to\": \"pserver\", \"related-link\": \"/aai/v11/"
267             + "cloud-infrastructure/pservers/pserver/USMSO1SX7NJ0103UJZZ01\", \"relationship-data\": [ {\""
268             + "relationship-key\": \"pserver.hostname\",\"relationship-value\": \"USMSO1SX7NJ0103UJZZ01\" }], \""
269             + "related-to-property\": [{\"property-key\": \"pserver.pserver-name2\"}]} ]}}]}";
270     }
271
272     private String getUuidValue(final String value, final String defaultValue) {
273         return value != null ? UUID.nameUUIDFromBytes(value.getBytes()).toString() : defaultValue;
274     }
275
276 }

© 2017 ONAP. Copyright © The Linux Foundation ®. All Rights Reserved.
The Linux Foundation has registered trademarks and uses trademarks.
For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.
Linux is a registered trademark of Linus Torvalds.
Privacy Policy and Terms of Use