Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [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.rest; |
| 18 | |
| 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | |
| 22 | import java.io.InputStream; |
| 23 | import java.util.Map; |
| 24 | |
| 25 | /** |
| 26 | * Abstraction of an REST controller. Serves as a one stop shop for obtaining |
| 27 | * Rest southbound devices and (un)register listeners. |
| 28 | */ |
| 29 | public interface RestSBController { |
| 30 | |
| 31 | /** |
| 32 | * Returns all the devices known to this controller. |
| 33 | * |
| 34 | * @return map of devices |
| 35 | */ |
| 36 | Map<DeviceId, RestSBDevice> getDevices(); |
| 37 | |
| 38 | /** |
| 39 | * Returns a device by node identifier. |
| 40 | * |
| 41 | * @param deviceInfo node identifier |
| 42 | * @return RestSBDevice rest device |
| 43 | */ |
| 44 | RestSBDevice getDevice(DeviceId deviceInfo); |
| 45 | |
| 46 | /** |
| 47 | * Returns a device by Ip and Port. |
| 48 | * |
| 49 | * @param ip device ip |
| 50 | * @param port device port |
| 51 | * @return RestSBDevice rest device |
| 52 | */ |
| 53 | RestSBDevice getDevice(IpAddress ip, int port); |
| 54 | |
| 55 | /** |
| 56 | * Adds a device to the device map. |
| 57 | * |
| 58 | * @param device to be added |
| 59 | */ |
| 60 | void addDevice(RestSBDevice device); |
| 61 | |
| 62 | /** |
| 63 | * Removes the device from the devices map. |
| 64 | * |
Andrea Campanella | 86294db | 2016-03-07 11:42:49 -0800 | [diff] [blame] | 65 | * @param deviceId to be removed |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 66 | */ |
Andrea Campanella | 86294db | 2016-03-07 11:42:49 -0800 | [diff] [blame] | 67 | void removeDevice(DeviceId deviceId); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * Does a REST POST request with specified parameters to the device. |
| 71 | * |
| 72 | * @param device device to make the request to |
| 73 | * @param request url of the request |
| 74 | * @param payload payload of the request as an InputStream |
| 75 | * @param mediaType type of content in the payload i.e. application/json |
| 76 | * @return true if operation returned 200, 201, 202, false otherwise |
| 77 | */ |
| 78 | boolean post(DeviceId device, String request, InputStream payload, String mediaType); |
| 79 | |
| 80 | /** |
Andrea Campanella | c385126 | 2016-06-08 12:27:11 +0200 | [diff] [blame] | 81 | * Does a REST POST request with specified parameters to the device. |
| 82 | * |
| 83 | * @param device device to make the request to |
| 84 | * @param request url of the request |
| 85 | * @param payload payload of the request as an InputStream |
| 86 | * @param mediaType type of content in the payload i.e. application/json |
| 87 | * @param responseClass the type of response object we are interested in, |
| 88 | * such as String, InputStream. |
| 89 | * @return Object of type requested via responseClass. |
| 90 | */ |
| 91 | <T> T post(DeviceId device, String request, InputStream payload, |
| 92 | String mediaType, Class<T> responseClass); |
| 93 | |
| 94 | /** |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 95 | * Does a REST PUT request with specified parameters to the device. |
| 96 | * |
| 97 | * @param device device to make the request to |
| 98 | * @param request resource path of the request |
| 99 | * @param payload payload of the request as an InputStream |
| 100 | * @param mediaType type of content in the payload i.e. application/json |
| 101 | * @return true if operation returned 200, 201, 202, false otherwise |
| 102 | */ |
| 103 | boolean put(DeviceId device, String request, InputStream payload, String mediaType); |
| 104 | |
| 105 | /** |
| 106 | * Does a REST GET request with specified parameters to the device. |
| 107 | * |
Andrea Campanella | 86294db | 2016-03-07 11:42:49 -0800 | [diff] [blame] | 108 | * @param device device to make the request to |
| 109 | * @param request url of the request |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 110 | * @param mediaType format to retrieve the content in |
| 111 | * @return an inputstream of data from the reply. |
| 112 | */ |
| 113 | InputStream get(DeviceId device, String request, String mediaType); |
| 114 | |
| 115 | /** |
Andrea Campanella | ce279ee | 2016-01-25 10:21:45 -0800 | [diff] [blame] | 116 | * Does a REST PATCH request with specified parameters to the device. |
| 117 | * |
Andrea Campanella | 86294db | 2016-03-07 11:42:49 -0800 | [diff] [blame] | 118 | * @param device device to make the request to |
| 119 | * @param request url of the request |
Andrea Campanella | ce279ee | 2016-01-25 10:21:45 -0800 | [diff] [blame] | 120 | * @param payload payload of the request as an InputStream |
| 121 | * @param mediaType format to retrieve the content in |
| 122 | * @return true if operation returned 200, 201, 202, false otherwise |
| 123 | */ |
| 124 | boolean patch(DeviceId device, String request, InputStream payload, String mediaType); |
| 125 | |
| 126 | /** |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 127 | * Does a REST DELETE request with specified parameters to the device. |
| 128 | * |
| 129 | * @param device device to make the request to |
| 130 | * @param request url of the request |
| 131 | * @param payload payload of the request as an InputStream |
| 132 | * @param mediaType type of content in the payload i.e. application/json |
| 133 | * @return true if operation returned 200 false otherwise |
| 134 | */ |
| 135 | boolean delete(DeviceId device, String request, InputStream payload, String mediaType); |
| 136 | |
| 137 | } |