blob: ed79fd9dfcce58e5d65e66fb3260c5faec3a24fd [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 *
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 Campanella945ded22016-01-07 13:17:43 -080095 * 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 Campanella86294db2016-03-07 11:42:49 -0800108 * @param device device to make the request to
109 * @param request url of the request
Andrea Campanella945ded22016-01-07 13:17:43 -0800110 * @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 Campanellace279ee2016-01-25 10:21:45 -0800116 * Does a REST PATCH request with specified parameters to the device.
117 *
Andrea Campanella86294db2016-03-07 11:42:49 -0800118 * @param device device to make the request to
119 * @param request url of the request
Andrea Campanellace279ee2016-01-25 10:21:45 -0800120 * @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 Campanella945ded22016-01-07 13:17:43 -0800127 * 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}