blob: 0f5b32b574adc507bd6ac56e3ce19e5f5b952bfa [file] [log] [blame]
Hesam Rahimi4a409b42016-08-12 18:37:33 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Hesam Rahimi4a409b42016-08-12 18:37:33 -04003 *
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.http;
18
Matteo Gerola7e180c22017-03-30 11:57:58 +020019import java.io.InputStream;
20import java.util.Map;
Sean Condon5548ce62018-07-30 16:00:10 +010021import java.util.function.Consumer;
Matteo Gerola7e180c22017-03-30 11:57:58 +020022
23import javax.ws.rs.core.MediaType;
Sean Condon5548ce62018-07-30 16:00:10 +010024import javax.ws.rs.sse.InboundSseEvent;
Matteo Gerola7e180c22017-03-30 11:57:58 +020025
Hesam Rahimi4a409b42016-08-12 18:37:33 -040026import org.onlab.packet.IpAddress;
27import org.onosproject.net.DeviceId;
28import org.onosproject.protocol.rest.RestSBDevice;
29
Hesam Rahimi4a409b42016-08-12 18:37:33 -040030/**
31 * Abstraction of an HTTP controller. Serves as a one stop shop for obtaining
32 * HTTP southbound devices and (un)register listeners.
33 */
34public interface HttpSBController {
35
36 /**
37 * Returns all the devices known to this controller.
38 *
39 * @return map of devices
40 */
41 Map<DeviceId, RestSBDevice> getDevices();
42
43 /**
44 * Returns a device by node identifier.
45 *
46 * @param deviceInfo node identifier
47 * @return RestSBDevice rest device
48 */
49 RestSBDevice getDevice(DeviceId deviceInfo);
50
51 /**
52 * Returns a device by Ip and Port.
53 *
Matteo Gerola7e180c22017-03-30 11:57:58 +020054 * @param ip device ip
Hesam Rahimi4a409b42016-08-12 18:37:33 -040055 * @param port device port
56 * @return RestSBDevice rest device
57 */
58 RestSBDevice getDevice(IpAddress ip, int port);
59
60 /**
61 * Adds a device to the device map.
62 *
63 * @param device to be added
64 */
65 void addDevice(RestSBDevice device);
66
67 /**
68 * Removes the device from the devices map.
69 *
70 * @param deviceId to be removed
71 */
72 void removeDevice(DeviceId deviceId);
73
74 /**
75 * Does a HTTP POST request with specified parameters to the device.
76 *
Matteo Gerola7e180c22017-03-30 11:57:58 +020077 * @param device device to make the request to
78 * @param request url of the request
79 * @param payload payload of the request as an InputStream
Hesam Rahimi4a409b42016-08-12 18:37:33 -040080 * @param mediaType type of content in the payload i.e. application/json
Matteo Gerola7e180c22017-03-30 11:57:58 +020081 * @return status Commonly used status codes defined by HTTP
82 */
83 int post(DeviceId device, String request, InputStream payload, MediaType mediaType);
84
85 /**
86 * Does a HTTP PUT request with specified parameters to the device.
87 *
88 * @param device device to make the request to
89 * @param request resource path of the request
90 * @param payload payload of the request as an InputStream
91 * @param mediaType type of content in the payload i.e. application/json
92 * @return status Commonly used status codes defined by HTTP
93 */
94 int put(DeviceId device, String request, InputStream payload, MediaType mediaType);
95
96 /**
97 * Does a HTTP PATCH request with specified parameters to the device.
98 *
99 * @param device device to make the request to
100 * @param request url of the request
101 * @param payload payload of the request as an InputStream
102 * @param mediaType format to retrieve the content in
103 * @return status Commonly used status codes defined by HTTP
104 */
105 int patch(DeviceId device, String request, InputStream payload, MediaType mediaType);
106
107 /**
108 * Does a HTTP DELETE request with specified parameters to the device.
109 *
110 * @param device device to make the request to
111 * @param request url of the request
112 * @param payload payload of the request as an InputStream
113 * @param mediaType type of content in the payload i.e. application/json
114 * @return status Commonly used status codes defined by HTTP
115 */
116 int delete(DeviceId device, String request, InputStream payload, MediaType mediaType);
117
118 /**
119 *
120 * Does a HTTP GET request with specified parameters to the device.
121 *
122 * @param device device to make the request to
123 * @param request url of the request
124 * @param mediaType format to retrieve the content in
125 * @return an inputstream of data from the reply.
126 */
127 InputStream get(DeviceId device, String request, MediaType mediaType);
128
129 /**
Sean Condon5548ce62018-07-30 16:00:10 +0100130 * Does a HTTP POST request with specified parameters to the device and
131 * extracts an object of type T from the response entity field.
Matteo Gerola7e180c22017-03-30 11:57:58 +0200132 *
133 * @param <T> post return type
134 * @param device device to make the request to
135 * @param request url of the request
136 * @param payload payload of the request as an InputStream
137 * @param mediaType type of content in the payload i.e. application/json
138 * @param responseClass the type of response object we are interested in,
139 * such as String, InputStream.
140 * @return Object of type requested via responseClass.
141 */
142 <T> T post(DeviceId device, String request, InputStream payload, MediaType mediaType, Class<T> responseClass);
143
Sean Condon5548ce62018-07-30 16:00:10 +0100144 /**
145 * Does a HTTP GET against a Server Sent Events (SSE_INBOUND) resource on the device.
146 *
147 * This is a low level function that can take callbacks.
148 * For a higher level function that emits events based on this callback
149 * see startServerSentEvents() in the RestSBController
150 *
151 * @param deviceId device to make the request to
152 * @param request url of the request
153 * @param onEvent A consumer of inbound SSE_INBOUND events
154 * @param onError A consumer of inbound SSE_INBOUND errors
155 * @return status Commonly used status codes defined by HTTP
156 */
157 int getServerSentEvents(DeviceId deviceId, String request,
158 Consumer<InboundSseEvent> onEvent, Consumer<Throwable> onError);
Matteo Gerola7e180c22017-03-30 11:57:58 +0200159
Sean Condon5548ce62018-07-30 16:00:10 +0100160 /**
161 * Cancels a Server Sent Events listener to a device.
162 *
163 * @param deviceId device to cancel the listener for
164 * @return status Commonly used status codes defined by HTTP
165 */
166 int cancelServerSentEvents(DeviceId deviceId);
Hesam Rahimi4a409b42016-08-12 18:37:33 -0400167}