5e3426c3b65c5860cb68229daa7a13237789b61c
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / netconf / sal / restconf / api / JSONRestconfService.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.sal.restconf.api;
9
10 import java.util.Optional;
11 import javax.ws.rs.core.MultivaluedMap;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
14 import org.opendaylight.yangtools.yang.common.OperationFailedException;
15
16 /**
17  * Provides restconf CRUD operations via code with input/output data in JSON format.
18  *
19  * @author Thomas Pantelis.
20  */
21 public interface JSONRestconfService {
22     /**
23      * The data tree root path.
24      */
25     String ROOT_PATH = null;
26
27     /**
28      * Issues a restconf PUT request to the configuration data store.
29      *
30      * @param uriPath the yang instance identifier path, eg "opendaylight-inventory:nodes/node/device-id".
31      *       To specify the root, use {@link ROOT_PATH}.
32      * @param payload the payload data in JSON format.
33      * @throws OperationFailedException if the request fails.
34      */
35     void put(String uriPath, @NonNull String payload) throws OperationFailedException;
36
37     /**
38      * Issues a restconf POST request to the configuration data store.
39      *
40      * @param uriPath the yang instance identifier path, eg "opendaylight-inventory:nodes/node/device-id".
41      *       To specify the root, use {@link ROOT_PATH}.
42      * @param payload the payload data in JSON format.
43      * @throws OperationFailedException if the request fails.
44      */
45     void post(String uriPath, @NonNull String payload) throws OperationFailedException;
46
47     /**
48      * Issues a restconf DELETE request to the configuration data store.
49      *
50      * @param uriPath the yang instance identifier path, eg "opendaylight-inventory:nodes/node/device-id".
51      *       To specify the root, use {@link ROOT_PATH}.
52      * @throws OperationFailedException if the request fails.
53      */
54     void delete(String uriPath) throws OperationFailedException;
55
56     /**
57      * Issues a restconf GET request to the given data store.
58      *
59      * @param uriPath the yang instance identifier path, eg "opendaylight-inventory:nodes/node/device-id".
60      *       To specify the root, use {@link ROOT_PATH}.
61      * @param datastoreType the data store type to read from.
62      * @return an Optional containing the data in JSON format if present.
63      * @throws OperationFailedException if the request fails.
64      */
65     Optional<String> get(String uriPath, LogicalDatastoreType datastoreType)
66             throws OperationFailedException;
67
68     /**
69      * Invokes a yang-defined RPC.
70      *
71      * @param uriPath the path representing the RPC to invoke, eg "toaster:make-toast".
72      * @param input the input in JSON format if the RPC takes input.
73      * @return an Optional containing the output in JSON format if the RPC returns output.
74      * @throws OperationFailedException if the request fails.
75      */
76     Optional<String> invokeRpc(@NonNull String uriPath, Optional<String> input) throws OperationFailedException;
77
78     /**
79      * Issues a restconf PATCH request to the configuration data store.
80      *
81      * @param uriPath the yang instance identifier path, eg "opendaylight-inventory:nodes/node/device-id".
82      *       To specify the root, use {@link ROOT_PATH}.
83      * @param payload the payload data in JSON format.
84      * @return an Optional containing the patch response data in JSON format.
85      * @throws OperationFailedException if the request fails.
86      */
87     Optional<String> patch(@NonNull String uriPath, @NonNull String payload) throws OperationFailedException;
88
89     /**
90      * Subscribe to a stream.
91      * @param identifier the identifier of the stream, e.g., "data-change-event-subscription/neutron:neutron/...
92      *                   ...neutron:ports/datastore=OPERATIONAL/scope=SUBTREE".
93      * @param params HTTP query parameters or null.
94      * @return On optional containing the JSON response.
95      * @throws OperationFailedException if the requests fails.
96      */
97     Optional<String> subscribeToStream(@NonNull String identifier, MultivaluedMap<String, String> params)
98                                                                                     throws OperationFailedException;
99 }