2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018, 2020-2021 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 javax.ws.rs.Consumes;
27 import javax.ws.rs.GET;
28 import javax.ws.rs.PUT;
29 import javax.ws.rs.Path;
30 import javax.ws.rs.PathParam;
31 import javax.ws.rs.Produces;
32 import javax.ws.rs.QueryParam;
33 import javax.ws.rs.core.MediaType;
34 import org.apache.commons.io.IOUtils;
37 public class AaiSimulatorJaxRs {
39 private static final String GETFAIL = "getFail";
47 @Path("/{version:v16|v21}/search/nodes-query")
48 @Consumes(MediaType.APPLICATION_JSON)
49 @Produces("application/json")
50 public String aaiGetVserverQuery(@QueryParam("filter") final String filter) {
51 if (filter.equals("vserver-name:EQUALS:f953c499-4b1e-426b-8c6d-e9e9f1fc730f")
52 || filter.equals("vserver-name:EQUALS:Ete_vFWCLvFWSNK_7ba1fbde_0")
53 || filter.equals("vserver-name:EQUALS:OzVServer")
54 || filter.equals("vserver-name:EQUALS:testVserverName")) {
55 return "{\"result-data\":[{\"resource-type\": \"vserver\",\"resource-link\":\"/aai/v15/"
56 + "cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/tenants"
57 + "/tenant/3f2aaef74ecb4b19b35e26d0849fe9a2/vservers/vserver/"
58 + "6c3b3714-e36c-45af-9f16-7d3a73d99497\"}]}";
67 * @param req the request
68 * @return the response
69 * @throws IOException if a response file cannot be read
72 @Path("/{version:v16|v21}/query")
73 @Consumes(MediaType.APPLICATION_JSON)
74 @Produces("application/json")
75 public String aaiPutQuery(final String req) throws IOException {
76 return IOUtils.toString(getClass().getResource("aai/AaiCqResponse.json"),
77 StandardCharsets.UTF_8);
84 * @throws IOException if a response file cannot be read
87 @Path("/{version:v16|v21}/network/pnfs/pnf/{pnfName}")
88 @Consumes(MediaType.APPLICATION_JSON)
89 @Produces("application/json")
90 public String aaiGetPnfQuery(@PathParam("pnfName") final String pnfName) throws IOException {
91 if (GETFAIL.equals(pnfName)) {
92 throw new IllegalArgumentException("query failed, as requested");
95 return IOUtils.toString(getClass().getResource("aai/AaiGetPnfResponse.json"),
96 StandardCharsets.UTF_8);