blob: b51b12f86c20311ed3f08ce05bd8ca1dc9491ff3 [file] [log] [blame]
Andrea Campanella945ded22016-01-07 13:17:43 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Andrea Campanella945ded22016-01-07 13:17:43 -08003 *
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
17package org.onosproject.protocol.rest;
18
19import org.onlab.packet.IpAddress;
20import org.onosproject.net.DeviceId;
21
22import java.io.InputStream;
23import 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 */
29public 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 Campanella86294db2016-03-07 11:42:49 -080065 * @param deviceId to be removed
Andrea Campanella945ded22016-01-07 13:17:43 -080066 */
Andrea Campanella86294db2016-03-07 11:42:49 -080067 void removeDevice(DeviceId deviceId);
Andrea Campanella945ded22016-01-07 13:17:43 -080068
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 Campanellac3851262016-06-08 12:27:11 +020081 * Does a REST POST request with specified parameters to the device.
82 *
Ray Milkeybb23e0b2016-08-02 17:00:21 -070083 * @param <T> post return type
Andrea Campanellac3851262016-06-08 12:27:11 +020084 * @param device device to make the request to
85 * @param request url of the request
86 * @param payload payload of the request as an InputStream
87 * @param mediaType type of content in the payload i.e. application/json
88 * @param responseClass the type of response object we are interested in,
89 * such as String, InputStream.
90 * @return Object of type requested via responseClass.
91 */
92 <T> T post(DeviceId device, String request, InputStream payload,
93 String mediaType, Class<T> responseClass);
94
95 /**
Andrea Campanella945ded22016-01-07 13:17:43 -080096 * Does a REST PUT request with specified parameters to the device.
97 *
98 * @param device device to make the request to
99 * @param request resource path of the request
100 * @param payload payload of the request as an InputStream
101 * @param mediaType type of content in the payload i.e. application/json
102 * @return true if operation returned 200, 201, 202, false otherwise
103 */
104 boolean put(DeviceId device, String request, InputStream payload, String mediaType);
105
106 /**
107 * Does a REST GET request with specified parameters to the device.
108 *
Andrea Campanella86294db2016-03-07 11:42:49 -0800109 * @param device device to make the request to
110 * @param request url of the request
Andrea Campanella945ded22016-01-07 13:17:43 -0800111 * @param mediaType format to retrieve the content in
112 * @return an inputstream of data from the reply.
113 */
114 InputStream get(DeviceId device, String request, String mediaType);
115
116 /**
Andrea Campanellace279ee2016-01-25 10:21:45 -0800117 * Does a REST PATCH request with specified parameters to the device.
118 *
Andrea Campanella86294db2016-03-07 11:42:49 -0800119 * @param device device to make the request to
120 * @param request url of the request
Andrea Campanellace279ee2016-01-25 10:21:45 -0800121 * @param payload payload of the request as an InputStream
122 * @param mediaType format to retrieve the content in
123 * @return true if operation returned 200, 201, 202, false otherwise
124 */
125 boolean patch(DeviceId device, String request, InputStream payload, String mediaType);
126
127 /**
Andrea Campanella945ded22016-01-07 13:17:43 -0800128 * Does a REST DELETE request with specified parameters to the device.
129 *
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
133 * @param mediaType type of content in the payload i.e. application/json
134 * @return true if operation returned 200 false otherwise
135 */
136 boolean delete(DeviceId device, String request, InputStream payload, String mediaType);
137
138}