blob: ada5496ba8d92192397d8e5a086c090582275079 [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;
21
22import javax.ws.rs.core.MediaType;
23
Hesam Rahimi4a409b42016-08-12 18:37:33 -040024import org.onlab.packet.IpAddress;
25import org.onosproject.net.DeviceId;
26import org.onosproject.protocol.rest.RestSBDevice;
27
Hesam Rahimi4a409b42016-08-12 18:37:33 -040028/**
29 * Abstraction of an HTTP controller. Serves as a one stop shop for obtaining
30 * HTTP southbound devices and (un)register listeners.
31 */
32public 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 Gerola7e180c22017-03-30 11:57:58 +020052 * @param ip device ip
Hesam Rahimi4a409b42016-08-12 18:37:33 -040053 * @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 Gerola7e180c22017-03-30 11:57:58 +020075 * @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 Rahimi4a409b42016-08-12 18:37:33 -040078 * @param mediaType type of content in the payload i.e. application/json
Matteo Gerola7e180c22017-03-30 11:57:58 +020079 * @return status Commonly used status codes defined by HTTP
80 */
81 int post(DeviceId device, String request, InputStream payload, MediaType mediaType);
82
83 /**
84 * Does a HTTP PUT request with specified parameters to the device.
85 *
86 * @param device device to make the request to
87 * @param request resource path of the request
88 * @param payload payload of the request as an InputStream
89 * @param mediaType type of content in the payload i.e. application/json
90 * @return status Commonly used status codes defined by HTTP
91 */
92 int put(DeviceId device, String request, InputStream payload, MediaType mediaType);
93
94 /**
95 * Does a HTTP PATCH request with specified parameters to the device.
96 *
97 * @param device device to make the request to
98 * @param request url of the request
99 * @param payload payload of the request as an InputStream
100 * @param mediaType format to retrieve the content in
101 * @return status Commonly used status codes defined by HTTP
102 */
103 int patch(DeviceId device, String request, InputStream payload, MediaType mediaType);
104
105 /**
106 * Does a HTTP DELETE request with specified parameters to the device.
107 *
108 * @param device device to make the request to
109 * @param request url of the request
110 * @param payload payload of the request as an InputStream
111 * @param mediaType type of content in the payload i.e. application/json
112 * @return status Commonly used status codes defined by HTTP
113 */
114 int delete(DeviceId device, String request, InputStream payload, MediaType mediaType);
115
116 /**
117 *
118 * Does a HTTP GET request with specified parameters to the device.
119 *
120 * @param device device to make the request to
121 * @param request url of the request
122 * @param mediaType format to retrieve the content in
123 * @return an inputstream of data from the reply.
124 */
125 InputStream get(DeviceId device, String request, MediaType mediaType);
126
127 /**
128 * Does a HTTP POST request with specified parameters to the device.
129 *
130 * @param <T> post return type
131 * @param device device to make the request to
132 * @param request url of the request
133 * @param payload payload of the request as an InputStream
134 * @param mediaType type of content in the payload i.e. application/json
135 * @param responseClass the type of response object we are interested in,
136 * such as String, InputStream.
137 * @return Object of type requested via responseClass.
138 */
139 <T> T post(DeviceId device, String request, InputStream payload, MediaType mediaType, Class<T> responseClass);
140
141
Hesam Rahimi4a409b42016-08-12 18:37:33 -0400142}