Split Restconf implementations (draft02 and RFC) - Application
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / services / 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.restconf.nb.rfc8040.rests.services.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  * Provides restconf CRUD operations via code with input/output data in JSON format.
17  *
18  * @author Thomas Pantelis.
19  */
20 public interface JSONRestconfService {
21     /**
22      * The data tree root path.
23      */
24     String ROOT_PATH = null;
25
26     /**
27      * Issues a restconf PUT request to the configuration data store.
28      *
29      * @param uriPath the yang instance identifier path, eg "opendaylight-inventory:nodes/node/device-id".
30      *       To specify the root, use {@link ROOT_PATH}.
31      * @param payload the payload data in JSON format.
32      * @throws OperationFailedException if the request fails.
33      */
34     void put(String uriPath, @Nonnull String payload) throws OperationFailedException;
35
36     /**
37      * Issues a restconf POST request to the configuration data store.
38      *
39      * @param uriPath the yang instance identifier path, eg "opendaylight-inventory:nodes/node/device-id".
40      *       To specify the root, use {@link ROOT_PATH}.
41      * @param payload the payload data in JSON format.
42      * @throws OperationFailedException if the request fails.
43      */
44     void post(String uriPath, @Nonnull String payload) throws OperationFailedException;
45
46     /**
47      * Issues a restconf DELETE request to the configuration data store.
48      *
49      * @param uriPath the yang instance identifier path, eg "opendaylight-inventory:nodes/node/device-id".
50      *       To specify the root, use {@link ROOT_PATH}.
51      * @throws OperationFailedException if the request fails.
52      */
53     void delete(String uriPath) throws OperationFailedException;
54
55     /**
56      * Issues a restconf GET request to the given data store.
57      *
58      * @param uriPath the yang instance identifier path, eg "opendaylight-inventory:nodes/node/device-id".
59      *       To specify the root, use {@link ROOT_PATH}.
60      * @param datastoreType the data store type to read from.
61      * @return an Optional containing the data in JSON format if present.
62      * @throws OperationFailedException if the request fails.
63      */
64     Optional<String> get(String uriPath, LogicalDatastoreType datastoreType)
65             throws OperationFailedException;
66
67     /**
68      * Invokes a yang-defined RPC.
69      *
70      * @param uriPath the path representing the RPC to invoke, eg "toaster:make-toast".
71      * @param input the input in JSON format if the RPC takes input.
72      * @return an Optional containing the output in JSON format if the RPC returns output.
73      * @throws OperationFailedException if the request fails.
74      */
75     Optional<String> invokeRpc(@Nonnull String uriPath, Optional<String> input) throws OperationFailedException;
76 }