ONOS-5755: RESTCONF App: App Skeleton creation
pom file will stay the same as before, while testing, please add <module>restconf</module> at apps/pom.xml
modified by Henry's comments.
Change-Id: I55d6bd4de07f03dcad77dfa575cb54c5563c937c
diff --git a/apps/restconf/api/src/main/java/org/onosproject/restconf/api/Patch.java b/apps/restconf/api/src/main/java/org/onosproject/restconf/api/Patch.java
new file mode 100644
index 0000000..4af1c42
--- /dev/null
+++ b/apps/restconf/api/src/main/java/org/onosproject/restconf/api/Patch.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.
+ */
+
+package org.onosproject.restconf.api;
+
+import javax.ws.rs.HttpMethod;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Indicates that the annotated method responds to HTTP PATCH requests.
+ */
+@Target({ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@HttpMethod("PATCH")
+public @interface Patch {
+}
\ No newline at end of file
diff --git a/apps/restconf/api/src/main/java/org/onosproject/restconf/api/RestconfException.java b/apps/restconf/api/src/main/java/org/onosproject/restconf/api/RestconfException.java
new file mode 100644
index 0000000..523c57e
--- /dev/null
+++ b/apps/restconf/api/src/main/java/org/onosproject/restconf/api/RestconfException.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.
+ */
+package org.onosproject.restconf.api;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+import static javax.ws.rs.core.Response.Status;
+
+/**
+ * Exceptions raised during RESTCONF operations. This class extends
+ * WebApplicationException. The design intention is to create a place holder
+ * for RESTCONF specific errors and to be able to add more functions as the
+ * subsystem grows.
+ */
+public class RestconfException extends WebApplicationException {
+
+ // This is a randomly generated value. A WebApplicationException class is required to define it.
+ private static final long SERIAL_VERSION_UID = 3275970397584007046L;
+
+ /**
+ * Constructs a new RESTCONF server error exception. The caller raising this
+ * exception may pass in a HTTP error status code and an error message. The
+ * error code will be displayed to the RESTCONF client as part of the
+ * response from the RESTCONF server. The error message is a string which
+ * may be saved in a log file and may be later retrieved by the
+ * getMessage() method.
+ *
+ * @param message the detailed error message
+ * @param status HTTP error status
+ * @throws IllegalArgumentException in case the status code is null or is not from
+ * javax.ws.rs.core.Response.Status.Family
+ * status code family
+ */
+ public RestconfException(String message, Status status) {
+ super(message, null, Response.status(status).build());
+ }
+
+ /**
+ * Constructs a new RESTCONF server error exception. The caller raising
+ * this exception may pass in the numerical value of a HTTP error
+ * status code, The error code will be displayed to the RESTCONF client
+ * as a response from the RESTCONF server.
+ *
+ * @param status HTTP error status
+ * @throws IllegalArgumentException in case the status code is not a valid
+ * HTTP status code or if it is not from the
+ * javax.ws.rs.core.Response.Status.Family
+ * status code family
+ */
+ public RestconfException(int status) {
+ super((Throwable) null, Response.status(status).build());
+ }
+}
diff --git a/apps/restconf/api/src/main/java/org/onosproject/restconf/api/RestconfService.java b/apps/restconf/api/src/main/java/org/onosproject/restconf/api/RestconfService.java
new file mode 100644
index 0000000..f44ed99
--- /dev/null
+++ b/apps/restconf/api/src/main/java/org/onosproject/restconf/api/RestconfService.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.
+ */
+package org.onosproject.restconf.api;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.glassfish.jersey.server.ChunkedOutput;
+
+/**
+ * Abstraction of RESTCONF Server functionality according to the
+ * RESTCONF RFC (no official RFC number yet).
+ */
+public interface RestconfService {
+ /**
+ * Processes a GET request against a data resource. The
+ * target data resource is identified by its URI. If the
+ * GET operation cannot be fulfilled due to reasons such
+ * as the nonexistence of the target resource, then a
+ * RestconfException exception is raised. The proper
+ * HTTP error status code is enclosed in the exception, so
+ * that the caller may return it to the RESTCONF client to
+ * display.
+ *
+ * @param uri URI of the target data resource
+ * @return JSON representation of the data resource
+ * @throws RestconfException if the GET operation cannot be fulfilled
+ */
+ ObjectNode runGetOperationOnDataResource(String uri)
+ throws RestconfException;
+
+ /**
+ * Processes a POST request against a data resource. The location of
+ * the target resource is passed in as a URI. And the resource's
+ * content is passed in as a JSON ObjectNode. If the POST operation
+ * cannot be fulfilled due to reasons such as wrong input URIs or
+ * syntax errors in the JSON payloads, a RestconfException exception
+ * is raised. The proper HTTP error status code is enclosed in the
+ * exception.
+ *
+ * @param uri URI of the data resource to be created
+ * @param rootNode JSON representation of the data resource
+ * @throws RestconfException if the POST operation cannot be fulfilled
+ */
+ void runPostOperationOnDataResource(String uri, ObjectNode rootNode)
+ throws RestconfException;
+
+ /**
+ * Processes a PUT request against a data resource. The location of
+ * the target resource is passed in as a URI. And the resource's
+ * content is passed in as a JSON ObjectNode. If the PUT operation
+ * cannot be fulfilled due to reasons such as wrong input URIs or
+ * syntax errors in the JSON payloads, a RestconfException exception
+ * is raised. The proper HTTP error status code is enclosed in the
+ * exception.
+ *
+ * @param uri URI of the data resource to be created or updated
+ * @param rootNode JSON representation of the data resource
+ * @throws RestconfException if the PUT operation cannot be fulfilled
+ */
+ void runPutOperationOnDataResource(String uri, ObjectNode rootNode)
+ throws RestconfException;
+
+ /**
+ * Processes the DELETE operation against a data resource. The target
+ * data resource is identified by its URI. If the DELETE operation
+ * cannot be fulfilled due reasons such as the nonexistence of the
+ * target resource, a RestconfException exception is raised. The
+ * proper HTTP error status code is enclosed in the exception.
+ *
+ * @param uri URI of the data resource to be deleted
+ * @throws RestconfException if the DELETE operation cannot be fulfilled
+ */
+ void runDeleteOperationOnDataResource(String uri) throws RestconfException;
+
+ /**
+ * Processes a PATCH operation on a data resource. The target data
+ * resource is identified by its URI passed in by the caller.
+ * And the content of the data resource is passed in as a JSON ObjectNode.
+ * If the PATCH operation cannot be fulfilled due reasons such as
+ * the nonexistence of the target resource, a RestconfException
+ * exception is raised. The proper HTTP error status code is
+ * enclosed in the exception.
+ *
+ * @param uri URI of the data resource to be patched
+ * @param rootNode JSON representation of the data resource
+ * @throws RestconfException if the PATCH operation cannot be fulfilled
+ */
+ void runPatchOperationOnDataResource(String uri, ObjectNode rootNode)
+ throws RestconfException;
+
+ /**
+ * Retrieves the RESTCONF Root directory.
+ *
+ * @return the RESTCONF Root directory
+ */
+ String getRestconfRootPath();
+
+ /**
+ * Handles an Event Stream subscription request. This function creates
+ * a worker thread to listen to events and writes to a ChunkedOutput,
+ * which is passed in from the caller. (The worker thread blocks if
+ * no events arrive.) The ChuckedOutput is a pipe to which this
+ * function acts as the writer and the caller the reader.
+ * <p>
+ * If the Event Stream cannot be subscribed due to reasons such as
+ * the nonexistence of the target stream or failure to allocate
+ * worker thread to handle the request, a RestconfException exception
+ * is raised. The proper HTTP error status code is enclosed in the
+ * exception, so that the caller may return it to the RESTCONF client
+ * to display.
+ *
+ * @param streamId ID of the RESTCONF stream to subscribe
+ * @param output A string data stream
+ * @throws RestconfException if the Event Stream cannot be subscribed
+ */
+ void subscribeEventStream(String streamId, ChunkedOutput<String> output)
+ throws RestconfException;
+}
diff --git a/apps/restconf/api/src/main/java/org/onosproject/restconf/api/package-info.java b/apps/restconf/api/src/main/java/org/onosproject/restconf/api/package-info.java
new file mode 100644
index 0000000..273e398
--- /dev/null
+++ b/apps/restconf/api/src/main/java/org/onosproject/restconf/api/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.
+ */
+
+/**
+ * RESTCONF Server Public Interface. All public interfaces/APIs that might be used by
+ * external applications should be packaged here.
+ */
+package org.onosproject.restconf.api;