blob: b2bfad2da53dcd40668c8f2a33e9684186a76f62 [file] [log] [blame]
Deepa vaddireddy386f38b2017-08-02 06:24:01 +00001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.opencord.sadis.rest;
17
18import com.fasterxml.jackson.databind.node.ObjectNode;
19import org.onosproject.rest.AbstractWebResource;
20import com.fasterxml.jackson.databind.node.ArrayNode;
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000021import org.opencord.sadis.BandwidthProfileInformation;
22import org.opencord.sadis.BaseInformationService;
23import org.opencord.sadis.SadisService;
Deepa vaddireddy386f38b2017-08-02 06:24:01 +000024import org.opencord.sadis.SubscriberAndDeviceInformation;
25import org.onlab.util.ItemNotFoundException;
26
Deepa vaddireddy386f38b2017-08-02 06:24:01 +000027import javax.ws.rs.GET;
Deepa vaddireddy386f38b2017-08-02 06:24:01 +000028import javax.ws.rs.DELETE;
29import javax.ws.rs.Path;
30import javax.ws.rs.PathParam;
31import javax.ws.rs.Produces;
Deepa vaddireddy386f38b2017-08-02 06:24:01 +000032import javax.ws.rs.core.MediaType;
33import javax.ws.rs.core.Response;
34
35/**
36 * Subscriber And Device Information Service web resource.
37 */
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000038@Path("sadis")
Deepa vaddireddy386f38b2017-08-02 06:24:01 +000039public class SadisWebResource extends AbstractWebResource {
40 private final ObjectNode root = mapper().createObjectNode();
41 private final ArrayNode node = root.putArray("entry");
42 private static final String SUBSCRIBER_NOT_FOUND = "Subscriber not found";
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000043 private static final String BP_NOT_FOUND = "Bandwidth Profile not found";
Deepa vaddireddy386f38b2017-08-02 06:24:01 +000044
45 /**
46 * Get subscriber object.
47 *
48 * @param id
49 * ID of the subscriber
50 *
51 * @return 200 OK
52 */
53 @GET
54 @Path("/subscriber/{id}")
55 @Produces(MediaType.APPLICATION_JSON)
56 public Response getSubscriber(@PathParam("id") String id) {
Daniele Moro82d9a362019-11-06 23:51:20 +000057 SadisService sadisService = get(SadisService.class);
58 BaseInformationService<SubscriberAndDeviceInformation> subService =
59 sadisService.getSubscriberInfoService();
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000060 final SubscriberAndDeviceInformation entry = subService.get(id);
Deepa vaddireddy386f38b2017-08-02 06:24:01 +000061 if (entry == null) {
62 throw new ItemNotFoundException(SUBSCRIBER_NOT_FOUND);
63 }
64 node.add(codec(SubscriberAndDeviceInformation.class).encode(entry, this));
65 return ok(root).build();
66 }
67
68 /**
69 * Get subscriber object from the cache.
70 *
71 * @param id
72 * ID of the subscriber
73 *
74 * @return 200 OK
75 */
76 @GET
77 @Path("/cache/subscriber/{id}")
78 @Produces(MediaType.APPLICATION_JSON)
79 public Response getSubscriberCache(@PathParam("id") String id) {
Daniele Moro82d9a362019-11-06 23:51:20 +000080 SadisService sadisService = get(SadisService.class);
81 BaseInformationService<SubscriberAndDeviceInformation> subService =
82 sadisService.getSubscriberInfoService();
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000083 final SubscriberAndDeviceInformation entry = subService.getfromCache(id);
Deepa vaddireddy386f38b2017-08-02 06:24:01 +000084 if (entry == null) {
85 throw new ItemNotFoundException(SUBSCRIBER_NOT_FOUND);
86 }
87 node.add(codec(SubscriberAndDeviceInformation.class).encode(entry, this));
88 return ok(root).build();
89 }
90
91 /**
Deepa vaddireddy386f38b2017-08-02 06:24:01 +000092 * Delete subscriber object.
93 *
94 * @param id
95 * ID of the subscriber
96 * @return 204 NoContent
97 */
98 @DELETE
99 @Path("/cache/subscriber/{id}")
100 public Response deleteSubscriber(@PathParam("id") String id) {
Daniele Moro82d9a362019-11-06 23:51:20 +0000101 SadisService sadisService = get(SadisService.class);
102 BaseInformationService<SubscriberAndDeviceInformation> subService =
103 sadisService.getSubscriberInfoService();
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000104 subService.invalidateId(id);
Deepa vaddireddy386f38b2017-08-02 06:24:01 +0000105 return Response.noContent().build();
106 }
107
108 /**
109 * Delete all the subscriber objects.
110 *
111 * @return 204 NoContent
112 */
113 @DELETE
114 @Path("/cache/subscriber/")
115 public Response deleteAllSubscribers() {
Daniele Moro82d9a362019-11-06 23:51:20 +0000116 SadisService sadisService = get(SadisService.class);
117 BaseInformationService<SubscriberAndDeviceInformation> subService =
118 sadisService.getSubscriberInfoService();
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000119 subService.invalidateAll();
120 return Response.noContent().build();
121 }
122
123 @GET
124 @Path("/bandwidthprofile/{id}")
125 @Produces(MediaType.APPLICATION_JSON)
126 public Response getBandwidthProfile(@PathParam("id") String id) {
Daniele Moro82d9a362019-11-06 23:51:20 +0000127 SadisService sadisService = get(SadisService.class);
128 BaseInformationService<BandwidthProfileInformation> bpService =
129 sadisService.getBandwidthProfileService();
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000130 final BandwidthProfileInformation entry = bpService.get(id);
131 if (entry == null) {
132 throw new ItemNotFoundException(BP_NOT_FOUND);
133 }
134 node.add(codec(BandwidthProfileInformation.class).encode(entry, this));
135 return ok(root).build();
136 }
137
138 @GET
139 @Path("/cache/bandwidthprofile/{id}")
140 @Produces(MediaType.APPLICATION_JSON)
141 public Response getBandwidthProfileCache(@PathParam("id") String id) {
Daniele Moro82d9a362019-11-06 23:51:20 +0000142 SadisService sadisService = get(SadisService.class);
143 BaseInformationService<BandwidthProfileInformation> bpService =
144 sadisService.getBandwidthProfileService();
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000145 final BandwidthProfileInformation entry = bpService.getfromCache(id);
146 if (entry == null) {
147 throw new ItemNotFoundException(BP_NOT_FOUND);
148 }
149 node.add(codec(BandwidthProfileInformation.class).encode(entry, this));
150 return ok(root).build();
151 }
152
153 @DELETE
154 @Path("/cache/bandwidthprofile/{id}")
155 public Response deleteBandwidthProfile(@PathParam("id") String id) {
Daniele Moro82d9a362019-11-06 23:51:20 +0000156 SadisService sadisService = get(SadisService.class);
157 BaseInformationService<BandwidthProfileInformation> bpService =
158 sadisService.getBandwidthProfileService();
159 bpService.invalidateId(id);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000160 return Response.noContent().build();
161 }
162
163 @DELETE
164 @Path("/cache/bandwidthprofile/")
165 public Response deleteAllBandwidthProfiles() {
Daniele Moro82d9a362019-11-06 23:51:20 +0000166 SadisService sadisService = get(SadisService.class);
167 BaseInformationService<BandwidthProfileInformation> bpService =
168 sadisService.getBandwidthProfileService();
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000169 bpService.invalidateAll();
Deepa vaddireddy386f38b2017-08-02 06:24:01 +0000170 return Response.noContent().build();
171 }
172}