Bug 3999: Create internal service to access restconf
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / 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.controller.restconf.api;
9
10 import com.google.common.base.Optional;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.yangtools.yang.common.OperationFailedException;
14
15 /**
16  * @author Thomas Pantelis
17  */
18 public interface JSONRestconfService {
19     /**
20      * The data tree root path.
21      */
22     String ROOT_PATH = null;
23
24     /**
25      * Issues a restconf PUT request to the configuration data store.
26      *
27      * @param uriPath the yang instance identifier path, eg "opendaylight-inventory:nodes/node/device-id".
28      *       To specify the root, use {@link ROOT_PATH}.
29      * @param payload the payload data in JSON format.
30      * @throws OperationFailedException if the request fails.
31      */
32     void put(String uriPath, @Nonnull String payload) throws OperationFailedException;
33
34     /**
35      * Issues a restconf POST request to the configuration data store.
36      *
37      * @param uriPath the yang instance identifier path, eg "opendaylight-inventory:nodes/node/device-id".
38      *       To specify the root, use {@link ROOT_PATH}.
39      * @param payload the payload data in JSON format.
40      * @throws OperationFailedException if the request fails.
41      */
42     void post(String uriPath, @Nonnull String payload) throws OperationFailedException;
43
44     /**
45      * Issues a restconf DELETE request to the configuration data store.
46      *
47      * @param uriPath the yang instance identifier path, eg "opendaylight-inventory:nodes/node/device-id".
48      *       To specify the root, use {@link ROOT_PATH}.
49      * @throws OperationFailedException if the request fails.
50      */
51     void delete(String uriPath) throws OperationFailedException;
52
53     /**
54      * Issues a restconf GET request to the given data store.
55      *
56      * @param uriPath the yang instance identifier path, eg "opendaylight-inventory:nodes/node/device-id".
57      *       To specify the root, use {@link ROOT_PATH}.
58      * @param datastoreType the data store type to read from.
59      * @return an Optional containing the data in JSON format if present.
60      * @throws OperationFailedException if the request fails.
61      */
62     Optional<String> get(String uriPath, LogicalDatastoreType datastoreType) throws OperationFailedException;
63
64     /**
65      * Invokes a yang-defined RPC.
66      *
67      * @param uriPath the path representing the RPC to invoke, eg "toaster:make-toast".
68      * @param input the input in JSON format if the RPC takes input.
69      * @return an Optional containing the output in JSON format if the RPC returns output.
70      * @throws OperationFailedException if the request fails.
71      */
72     Optional<String> invokeRpc(@Nonnull String uriPath, Optional<String> input) throws OperationFailedException;
73 }