Deepa vaddireddy | 386f38b | 2017-08-02 06:24:01 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.opencord.sadis.rest; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 19 | import org.onosproject.rest.AbstractWebResource; |
| 20 | import com.fasterxml.jackson.databind.node.ArrayNode; |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 21 | import org.opencord.sadis.BandwidthProfileInformation; |
| 22 | import org.opencord.sadis.BaseInformationService; |
| 23 | import org.opencord.sadis.SadisService; |
Deepa vaddireddy | 386f38b | 2017-08-02 06:24:01 +0000 | [diff] [blame] | 24 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
| 25 | import org.onlab.util.ItemNotFoundException; |
| 26 | |
Deepa vaddireddy | 386f38b | 2017-08-02 06:24:01 +0000 | [diff] [blame] | 27 | import javax.ws.rs.GET; |
Deepa vaddireddy | 386f38b | 2017-08-02 06:24:01 +0000 | [diff] [blame] | 28 | import javax.ws.rs.DELETE; |
| 29 | import javax.ws.rs.Path; |
| 30 | import javax.ws.rs.PathParam; |
| 31 | import javax.ws.rs.Produces; |
Deepa vaddireddy | 386f38b | 2017-08-02 06:24:01 +0000 | [diff] [blame] | 32 | import javax.ws.rs.core.MediaType; |
| 33 | import javax.ws.rs.core.Response; |
| 34 | |
| 35 | /** |
| 36 | * Subscriber And Device Information Service web resource. |
| 37 | */ |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 38 | @Path("sadis") |
Deepa vaddireddy | 386f38b | 2017-08-02 06:24:01 +0000 | [diff] [blame] | 39 | public 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 Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 43 | private static final String BP_NOT_FOUND = "Bandwidth Profile not found"; |
Deepa vaddireddy | 386f38b | 2017-08-02 06:24:01 +0000 | [diff] [blame] | 44 | |
| 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 Moro | 82d9a36 | 2019-11-06 23:51:20 +0000 | [diff] [blame] | 57 | SadisService sadisService = get(SadisService.class); |
| 58 | BaseInformationService<SubscriberAndDeviceInformation> subService = |
| 59 | sadisService.getSubscriberInfoService(); |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 60 | final SubscriberAndDeviceInformation entry = subService.get(id); |
Deepa vaddireddy | 386f38b | 2017-08-02 06:24:01 +0000 | [diff] [blame] | 61 | 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 Moro | 82d9a36 | 2019-11-06 23:51:20 +0000 | [diff] [blame] | 80 | SadisService sadisService = get(SadisService.class); |
| 81 | BaseInformationService<SubscriberAndDeviceInformation> subService = |
| 82 | sadisService.getSubscriberInfoService(); |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 83 | final SubscriberAndDeviceInformation entry = subService.getfromCache(id); |
Deepa vaddireddy | 386f38b | 2017-08-02 06:24:01 +0000 | [diff] [blame] | 84 | 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 vaddireddy | 386f38b | 2017-08-02 06:24:01 +0000 | [diff] [blame] | 92 | * 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 Moro | 82d9a36 | 2019-11-06 23:51:20 +0000 | [diff] [blame] | 101 | SadisService sadisService = get(SadisService.class); |
| 102 | BaseInformationService<SubscriberAndDeviceInformation> subService = |
| 103 | sadisService.getSubscriberInfoService(); |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 104 | subService.invalidateId(id); |
Deepa vaddireddy | 386f38b | 2017-08-02 06:24:01 +0000 | [diff] [blame] | 105 | 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 Moro | 82d9a36 | 2019-11-06 23:51:20 +0000 | [diff] [blame] | 116 | SadisService sadisService = get(SadisService.class); |
| 117 | BaseInformationService<SubscriberAndDeviceInformation> subService = |
| 118 | sadisService.getSubscriberInfoService(); |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 119 | 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 Moro | 82d9a36 | 2019-11-06 23:51:20 +0000 | [diff] [blame] | 127 | SadisService sadisService = get(SadisService.class); |
| 128 | BaseInformationService<BandwidthProfileInformation> bpService = |
| 129 | sadisService.getBandwidthProfileService(); |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 130 | 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 Moro | 82d9a36 | 2019-11-06 23:51:20 +0000 | [diff] [blame] | 142 | SadisService sadisService = get(SadisService.class); |
| 143 | BaseInformationService<BandwidthProfileInformation> bpService = |
| 144 | sadisService.getBandwidthProfileService(); |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 145 | 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 Moro | 82d9a36 | 2019-11-06 23:51:20 +0000 | [diff] [blame] | 156 | SadisService sadisService = get(SadisService.class); |
| 157 | BaseInformationService<BandwidthProfileInformation> bpService = |
| 158 | sadisService.getBandwidthProfileService(); |
| 159 | bpService.invalidateId(id); |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 160 | return Response.noContent().build(); |
| 161 | } |
| 162 | |
| 163 | @DELETE |
| 164 | @Path("/cache/bandwidthprofile/") |
| 165 | public Response deleteAllBandwidthProfiles() { |
Daniele Moro | 82d9a36 | 2019-11-06 23:51:20 +0000 | [diff] [blame] | 166 | SadisService sadisService = get(SadisService.class); |
| 167 | BaseInformationService<BandwidthProfileInformation> bpService = |
| 168 | sadisService.getBandwidthProfileService(); |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 169 | bpService.invalidateAll(); |
Deepa vaddireddy | 386f38b | 2017-08-02 06:24:01 +0000 | [diff] [blame] | 170 | return Response.noContent().build(); |
| 171 | } |
| 172 | } |