Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.protocol.http; |
| 18 | |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 19 | import java.io.InputStream; |
| 20 | import java.util.Map; |
| 21 | |
| 22 | import javax.ws.rs.core.MediaType; |
| 23 | |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 24 | import org.onlab.packet.IpAddress; |
| 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.protocol.rest.RestSBDevice; |
| 27 | |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 28 | /** |
| 29 | * Abstraction of an HTTP controller. Serves as a one stop shop for obtaining |
| 30 | * HTTP southbound devices and (un)register listeners. |
| 31 | */ |
| 32 | public interface HttpSBController { |
| 33 | |
| 34 | /** |
| 35 | * Returns all the devices known to this controller. |
| 36 | * |
| 37 | * @return map of devices |
| 38 | */ |
| 39 | Map<DeviceId, RestSBDevice> getDevices(); |
| 40 | |
| 41 | /** |
| 42 | * Returns a device by node identifier. |
| 43 | * |
| 44 | * @param deviceInfo node identifier |
| 45 | * @return RestSBDevice rest device |
| 46 | */ |
| 47 | RestSBDevice getDevice(DeviceId deviceInfo); |
| 48 | |
| 49 | /** |
| 50 | * Returns a device by Ip and Port. |
| 51 | * |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 52 | * @param ip device ip |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 53 | * @param port device port |
| 54 | * @return RestSBDevice rest device |
| 55 | */ |
| 56 | RestSBDevice getDevice(IpAddress ip, int port); |
| 57 | |
| 58 | /** |
| 59 | * Adds a device to the device map. |
| 60 | * |
| 61 | * @param device to be added |
| 62 | */ |
| 63 | void addDevice(RestSBDevice device); |
| 64 | |
| 65 | /** |
| 66 | * Removes the device from the devices map. |
| 67 | * |
| 68 | * @param deviceId to be removed |
| 69 | */ |
| 70 | void removeDevice(DeviceId deviceId); |
| 71 | |
| 72 | /** |
| 73 | * Does a HTTP POST request with specified parameters to the device. |
| 74 | * |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 75 | * @param device device to make the request to |
| 76 | * @param request url of the request |
| 77 | * @param payload payload of the request as an InputStream |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 78 | * @param mediaType type of content in the payload i.e. application/json |
| 79 | * @return true if operation returned 200, 201, 202, false otherwise |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 80 | * |
| 81 | * @deprecated in Kingfisher (1.10.0) |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 82 | */ |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 83 | @Deprecated |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 84 | boolean post(DeviceId device, String request, InputStream payload, String mediaType); |
| 85 | |
| 86 | /** |
| 87 | * Does a HTTP POST request with specified parameters to the device. |
| 88 | * |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 89 | * @param <T> post return type |
| 90 | * @param device device to make the request to |
| 91 | * @param request url of the request |
| 92 | * @param payload payload of the request as an InputStream |
| 93 | * @param mediaType type of content in the payload i.e. application/json |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 94 | * @param responseClass the type of response object we are interested in, |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 95 | * such as String, InputStream. |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 96 | * @return Object of type requested via responseClass. |
| 97 | */ |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 98 | @Deprecated |
| 99 | <T> T post(DeviceId device, String request, InputStream payload, String mediaType, Class<T> responseClass); |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * Does a HTTP PUT request with specified parameters to the device. |
| 103 | * |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 104 | * @param device device to make the request to |
| 105 | * @param request resource path of the request |
| 106 | * @param payload payload of the request as an InputStream |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 107 | * @param mediaType type of content in the payload i.e. application/json |
| 108 | * @return true if operation returned 200, 201, 202, false otherwise |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 109 | * |
| 110 | * @deprecated in Kingfisher (1.10.0) |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 111 | */ |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 112 | @Deprecated |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 113 | boolean put(DeviceId device, String request, InputStream payload, String mediaType); |
| 114 | |
| 115 | /** |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 116 | * |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 117 | * Does a HTTP GET request with specified parameters to the device. |
| 118 | * |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 119 | * @param device device to make the request to |
| 120 | * @param request url of the request |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 121 | * @param mediaType format to retrieve the content in |
| 122 | * @return an inputstream of data from the reply. |
| 123 | */ |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 124 | @Deprecated |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 125 | InputStream get(DeviceId device, String request, String mediaType); |
| 126 | |
| 127 | /** |
| 128 | * Does a HTTP PATCH request with specified parameters to the device. |
| 129 | * |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 130 | * @param device device to make the request to |
| 131 | * @param request url of the request |
| 132 | * @param payload payload of the request as an InputStream |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 133 | * @param mediaType format to retrieve the content in |
| 134 | * @return true if operation returned 200, 201, 202, false otherwise |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 135 | * |
| 136 | * @deprecated in Kingfisher (1.10.0) |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 137 | */ |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 138 | @Deprecated |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 139 | boolean patch(DeviceId device, String request, InputStream payload, String mediaType); |
| 140 | |
| 141 | /** |
| 142 | * Does a HTTP DELETE request with specified parameters to the device. |
| 143 | * |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 144 | * @param device device to make the request to |
| 145 | * @param request url of the request |
| 146 | * @param payload payload of the request as an InputStream |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 147 | * @param mediaType type of content in the payload i.e. application/json |
| 148 | * @return true if operation returned 200 false otherwise |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 149 | * |
| 150 | * @deprecated in Kingfisher (1.10.0) |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 151 | */ |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 152 | @Deprecated |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 153 | boolean delete(DeviceId device, String request, InputStream payload, String mediaType); |
| 154 | |
Matteo Gerola | 7e180c2 | 2017-03-30 11:57:58 +0200 | [diff] [blame] | 155 | /** |
| 156 | * Does a HTTP POST request with specified parameters to the device. |
| 157 | * |
| 158 | * @param device device to make the request to |
| 159 | * @param request url of the request |
| 160 | * @param payload payload of the request as an InputStream |
| 161 | * @param mediaType type of content in the payload i.e. application/json |
| 162 | * @return status Commonly used status codes defined by HTTP |
| 163 | */ |
| 164 | int post(DeviceId device, String request, InputStream payload, MediaType mediaType); |
| 165 | |
| 166 | /** |
| 167 | * Does a HTTP PUT request with specified parameters to the device. |
| 168 | * |
| 169 | * @param device device to make the request to |
| 170 | * @param request resource path of the request |
| 171 | * @param payload payload of the request as an InputStream |
| 172 | * @param mediaType type of content in the payload i.e. application/json |
| 173 | * @return status Commonly used status codes defined by HTTP |
| 174 | */ |
| 175 | int put(DeviceId device, String request, InputStream payload, MediaType mediaType); |
| 176 | |
| 177 | /** |
| 178 | * Does a HTTP PATCH request with specified parameters to the device. |
| 179 | * |
| 180 | * @param device device to make the request to |
| 181 | * @param request url of the request |
| 182 | * @param payload payload of the request as an InputStream |
| 183 | * @param mediaType format to retrieve the content in |
| 184 | * @return status Commonly used status codes defined by HTTP |
| 185 | */ |
| 186 | int patch(DeviceId device, String request, InputStream payload, MediaType mediaType); |
| 187 | |
| 188 | /** |
| 189 | * Does a HTTP DELETE request with specified parameters to the device. |
| 190 | * |
| 191 | * @param device device to make the request to |
| 192 | * @param request url of the request |
| 193 | * @param payload payload of the request as an InputStream |
| 194 | * @param mediaType type of content in the payload i.e. application/json |
| 195 | * @return status Commonly used status codes defined by HTTP |
| 196 | */ |
| 197 | int delete(DeviceId device, String request, InputStream payload, MediaType mediaType); |
| 198 | |
| 199 | /** |
| 200 | * |
| 201 | * Does a HTTP GET request with specified parameters to the device. |
| 202 | * |
| 203 | * @param device device to make the request to |
| 204 | * @param request url of the request |
| 205 | * @param mediaType format to retrieve the content in |
| 206 | * @return an inputstream of data from the reply. |
| 207 | */ |
| 208 | InputStream get(DeviceId device, String request, MediaType mediaType); |
| 209 | |
| 210 | /** |
| 211 | * Does a HTTP POST request with specified parameters to the device. |
| 212 | * |
| 213 | * @param <T> post return type |
| 214 | * @param device device to make the request to |
| 215 | * @param request url of the request |
| 216 | * @param payload payload of the request as an InputStream |
| 217 | * @param mediaType type of content in the payload i.e. application/json |
| 218 | * @param responseClass the type of response object we are interested in, |
| 219 | * such as String, InputStream. |
| 220 | * @return Object of type requested via responseClass. |
| 221 | */ |
| 222 | <T> T post(DeviceId device, String request, InputStream payload, MediaType mediaType, Class<T> responseClass); |
| 223 | |
| 224 | |
Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame] | 225 | } |