summaryrefslogtreecommitdiffstats
path: root/actn-interface-tools/restconf-client/api/src/main/java/org/onap/integration/actninterfacetools/protocol/restconf/RestConfSBController.java
blob: 86cfbc65be9ea080e16e3a57fe040b8c547b211b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
 *   ============LICENSE_START=======================================================
 *   Actn Interface Tools
 *   ================================================================================
 *   Copyright (C) 2023 Huawei Canada Limited.
 *   ================================================================================
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *   ============LICENSE_END=========================================================
 */
package org.onap.integration.actninterfacetools.protocol.restconf;

import com.fasterxml.jackson.databind.node.ObjectNode;

import javax.ws.rs.core.MediaType;
import java.net.InetAddress;
import java.util.Map;
import java.util.UUID;

/**
 * Abstraction of a RESTCONF controller. Serves as a one-stop shop for obtaining
 * RESTCONF southbound devices and (un)register listeners.
 */
public interface RestConfSBController {
    /**
     * Returns all the devices known to this controller.
     *
     * @return map of devices
     */
    Map<UUID, PncInstance> getPncInstances();

    /**
     * Returns a device by node identifier.
     *
     * @param deviceInfo node identifier
     * @return RestSBDevice rest device
     */
    PncInstance getPncInstance(UUID deviceInfo);

    /**
     * Returns a device by Ip and Port.
     *
     * @param ip device ip
     * @param port device port
     * @return RestSBDevice rest device
     */
    PncInstance getPncInstance(InetAddress ip, int port);

    /**
     * Adds a device to the device map.
     *
     * @param pncInstance to be added
     */
    void addPncInstance(PncInstance pncInstance);

    /**
     * Removes the device from the devices map.
     *
     * @param pncId to be removed
     */
    void removeDevice(UUID pncId);
    /**
     * This method is to be called by whoever is interested to receive
     * Notifications from a specific device. It does a REST GET request
     * with specified parameters to the device, and calls the provided
     * callBackListener upon receiving notifications to notify the requester
     * about notifications.
     *
     * @param pncId           pnc to make the request to
     * @param request          url of the request
     * @param mediaType        format to retrieve the content in
     * @param callBackListener method to call when notifications arrives
     */
    void enableNotifications(UUID pncId, String request, String mediaType,
                             RestconfNotificationEventListener callBackListener);

    /**
     * Registers a listener for notification events that occur to restconf
     * devices.
     *
     * @param pncId identifier of the pnc to which the listener is attached
     * @param listener the listener to notify
     */
    void addNotificationListener(UUID pncId,
                                 RestconfNotificationEventListener listener);

    /**
     * Unregisters the listener for the device.
     *
     * @param pncId identifier of the pnc for which the listener
     *                 is to be removed
     * @param listener listener to be removed
     */
    void removeNotificationListener(UUID pncId,
                                    RestconfNotificationEventListener listener);

    /**
     * Returns true if a listener has been installed to listen to RESTCONF
     * notifications sent from a particular device.
     *
     * @param pncId identifier of the pnc from which the notifications
     *                 are generated
     * @return true if listener is installed; false otherwise
     */
    boolean isNotificationEnabled(UUID pncId);

    /**
     * HTTP POST request with specified parameters to the pnc.
     *
     * @param pncId pnc to make the request to
     * @param request url of the request
     * @param payload payload of the request as an ObjectNode
     * @param mediaType type of content in the payload i.e. application/json
     * @return status Commonly used status codes defined by HTTP
     */
    int post(UUID pncId, String request, ObjectNode payload, MediaType mediaType);
    /**
     * HTTP POST request with specified parameters to the pnc.
     *
     * @param pncId pnc to make the request to
     * @param request url of the request
     * @param payload payload of the request as an ObjectNode
     * @param mediaType type of content in the payload in the form of string i.e. "application/json"
     * @return true if status defined by HTTP is OK, CREATED, ACCEPTED or PARTIAL-CONTEND, otherwise return false
     */
    boolean post(UUID pncId, String request, ObjectNode payload, String mediaType);

    <T> T post(UUID pncId, String request, ObjectNode payload, String mediaType, Class<T> responseClass);

    <T> T post(UUID pncId, String request, ObjectNode payload, MediaType mediaType, Class<T> responseClass);

    /**
     * HTTP PUT request with specified parameters to the device.
     *
     * @param pncId pnc to make the request to
     * @param request resource path of the request
     * @param payload payload of the request as an ObjectNode
     * @param mediaType type of content in the payload i.e. application/json
     * @return status Commonly used status codes defined by HTTP
     */
    int put(UUID pncId, String request, ObjectNode payload, MediaType mediaType);

    /**
     * HTTP PUT request with specified parameters to the pnc.
     *
     * @param pncId pnc to make the request to
     * @param request url of the request
     * @param payload payload of the request as an ObjectNode
     * @param mediaType type of content in the payload in the form of string i.e. "application/json"
     * @return true if status defined by HTTP is OK, CREATED, ACCEPTED or PARTIAL-CONTEND, otherwise return false
     */
    boolean put(UUID pncId, String request, ObjectNode payload, String mediaType);

    /**
     * HTTP PATCH request with specified parameters to the device.
     *
     * @param pncId pnc to make the request to
     * @param request url of the request
     * @param payload payload of the request as an ObjectNode
     * @param mediaType format to retrieve the content in
     * @return status Commonly used status codes defined by HTTP
     */
    int patch(UUID pncId, String request, ObjectNode payload, MediaType mediaType);

    /**
     * HTTP PATCH request with specified parameters to the pnc.
     *
     * @param pncId pnc to make the request to
     * @param request url of the request
     * @param payload payload of the request as an ObjectNode
     * @param mediaType type of content in the payload i.e. application/json
     * @return status Commonly used status codes defined by HTTP
     */
    boolean patch(UUID pncId, String request, ObjectNode payload, String mediaType);

    /**
     * HTTP DELETE request with specified parameters to the device.
     *
     * @param pncId pnc to make the request to
     * @param request url of the request
     * @param mediaType type of content in the payload i.e. application/json
     * @return status Commonly used status codes defined by HTTP
     */
    int delete(UUID pncId, String request,  MediaType mediaType);

    /**
     * HTTP DELETE request with specified parameters to the pnc.
     *
     * @param pncId pnc to make the request to
     * @param request url of the request
     * @param mediaType type of content in the payload i.e. application/json
     * @return status Commonly used status codes defined by HTTP
     */
    boolean delete(UUID pncId, String request,  String mediaType);

    /**
     *
     * HTTP GET request with specified parameters to the device.
     *
     * @param pncId pnc to make the request to
     * @param request url of the request
     * @param mediaType format to retrieve the content in
     * @return an ObjectNode of data from the reply.
     */
    ObjectNode get(UUID pncId, String request, String mediaType);

}