Bug 5528 - Connecting RESTful part to restconf + fix bugs 46/40246/10
authorJakub Toth <jatoth@cisco.com>
Mon, 13 Jun 2016 16:05:13 +0000 (18:05 +0200)
committerJakub Toth <jatoth@cisco.com>
Tue, 28 Jun 2016 12:24:39 +0000 (12:24 +0000)
  *new wrapper for transaction services
  *wrapper for transaction and base services
  *fix bugs
    *fix serializer of YII for create right prefix of namespace

Change-Id: I847eb536d94ff0e1b0c1e34cbb8d7c110b744ac4
Signed-off-by: Jakub Toth <jatoth@cisco.com>
13 files changed:
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonNormalizedNodeBodyReader.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/XmlNormalizedNodeBodyReader.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/RestConnectorProvider.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/RestconfApplication.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/common/wrapper/services/Draft11ServicesWrapperImpl.java [new file with mode: 0644]
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierSerializer.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/services/api/Draft11BaseServicesWrapper.java [moved from restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/services/api/Draft11ServicesWrapper.java with 86% similarity]
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/services/impl/Draft11ServicesWrapperImpl.java [deleted file]
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/Draft11TransactionServicesWrapper.java [new file with mode: 0644]
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/impl/RestconfDataServiceImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/impl/RestconfInvokeOperationsServiceImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/impl/RestconfStreamsSubscriptionServiceImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/utils/FutureCallbackTx.java

index 83d2449a81a5629f8820287c3839fca5f359cf26..2195dc21ae3f0fe021b2f457854b938daab7e58e 100644 (file)
@@ -30,6 +30,8 @@ import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
+import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.utils.RestconfConstants;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
@@ -50,7 +52,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Provider
-@Consumes({ Draft02.MediaTypes.DATA + RestconfService.JSON, Draft02.MediaTypes.OPERATION + RestconfService.JSON,
+@Consumes({ Draft02.MediaTypes.DATA + RestconfService.JSON, Draft11.MediaTypes.DATA + RestconfConstants.JSON,
+        Draft02.MediaTypes.OPERATION + RestconfService.JSON, Draft11.MediaTypes.OPERATION + RestconfConstants.JSON,
         MediaType.APPLICATION_JSON })
 public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider implements MessageBodyReader<NormalizedNodeContext> {
 
@@ -75,7 +78,7 @@ public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPr
         }
     }
 
-    private static void propagateExceptionAs(Exception e) throws RestconfDocumentedException {
+    private static void propagateExceptionAs(final Exception e) throws RestconfDocumentedException {
         if(e instanceof RestconfDocumentedException) {
             throw (RestconfDocumentedException)e;
         }
@@ -134,7 +137,7 @@ public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPr
         final List<YangInstanceIdentifier.PathArgument> iiToDataList = new ArrayList<>();
         InstanceIdentifierContext<? extends SchemaNode> newIIContext;
 
-        while (result instanceof AugmentationNode || result instanceof ChoiceNode) {
+        while ((result instanceof AugmentationNode) || (result instanceof ChoiceNode)) {
             final Object childNode = ((DataContainerNode) result).getValue().iterator().next();
             if (isPost) {
                 iiToDataList.add(result.getIdentifier());
index 215a29d7aca4b71a99ddc7b431377600ce165747..72ec47d3b9839b505dec5904c35451608081a3ed 100644 (file)
@@ -34,6 +34,8 @@ import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
+import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.utils.RestconfConstants;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlUtils;
@@ -55,7 +57,8 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 @Provider
-@Consumes({ Draft02.MediaTypes.DATA + RestconfService.XML, Draft02.MediaTypes.OPERATION + RestconfService.XML,
+@Consumes({ Draft02.MediaTypes.DATA + RestconfService.XML, Draft11.MediaTypes.DATA + RestconfConstants.XML,
+        Draft02.MediaTypes.OPERATION + RestconfService.XML, Draft11.MediaTypes.OPERATION + RestconfConstants.XML,
     MediaType.APPLICATION_XML, MediaType.TEXT_XML })
 public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider implements MessageBodyReader<NormalizedNodeContext> {
 
@@ -220,7 +223,7 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro
     }
 
     private static AugmentationSchema findCorrespondingAugment(final DataSchemaNode parent, final DataSchemaNode child) {
-        if (parent instanceof AugmentationTarget && !(parent instanceof ChoiceSchemaNode)) {
+        if ((parent instanceof AugmentationTarget) && !(parent instanceof ChoiceSchemaNode)) {
             for (final AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) {
                 final DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName());
                 if (childInAugmentation != null) {
index b6c14eb0f6baa4a9c1a93410d2264f8558961fd5..5ce439ca73ccbd97c4f462bc2c6463c32836d5db 100644 (file)
@@ -15,17 +15,19 @@ import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
 import org.opendaylight.controller.sal.core.api.Provider;
 import org.opendaylight.controller.sal.core.api.model.SchemaService;
 import org.opendaylight.netconf.sal.rest.api.RestConnector;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.restconf.common.wrapper.services.Draft11ServicesWrapperImpl;
 import org.opendaylight.restconf.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.RpcServiceHandler;
 import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.handlers.TransactionChainHandler;
-import org.opendaylight.restconf.rest.services.impl.Draft11ServicesWrapperImpl;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 import org.slf4j.Logger;
@@ -72,12 +74,16 @@ public class RestConnectorProvider implements Provider, RestConnector, AutoClose
                 session.getService(DOMMountPointService.class));
 
         this.dataBroker = session.getService(DOMDataBroker.class);
+        final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(this.dataBroker);
+
         this.transactionChain = this.dataBroker.createTransactionChain(this.transactionListener);
         final TransactionChainHandler transactionChainHandler = new TransactionChainHandler(this.transactionChain);
 
-        final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(this.dataBroker);
+        final DOMRpcService rpcService = session.getService(DOMRpcService.class);
+        final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
 
-        wrapperServices.setHandlers(schemaCtxHandler, domMountPointServiceHandler);
+        wrapperServices.setHandlers(schemaCtxHandler, domMountPointServiceHandler, transactionChainHandler,
+                brokerHandler, rpcServiceHandler);
     }
 
     /**
index 44770388d4b2ba04fb104f8a3bad7c988ca21b4d..8b5d8fd71cb4cb7b3425165ae1289d8741494f40 100644 (file)
@@ -13,16 +13,19 @@ import java.util.Set;
 import javax.ws.rs.core.Application;
 import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContentYangBodyWriter;
 import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContentYinBodyWriter;
+import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
-import org.opendaylight.restconf.rest.services.impl.Draft11ServicesWrapperImpl;
+import org.opendaylight.netconf.sal.rest.impl.XmlNormalizedNodeBodyReader;
+import org.opendaylight.restconf.common.wrapper.services.Draft11ServicesWrapperImpl;
 
 public class RestconfApplication extends Application {
 
     @Override
     public Set<Class<?>> getClasses() {
         return ImmutableSet.<Class<?>> builder().add(NormalizedNodeJsonBodyWriter.class)
-                .add(NormalizedNodeXmlBodyWriter.class).add(SchemaExportContentYinBodyWriter.class)
+                .add(NormalizedNodeXmlBodyWriter.class).add(JsonNormalizedNodeBodyReader.class)
+                .add(XmlNormalizedNodeBodyReader.class).add(SchemaExportContentYinBodyWriter.class)
                 .add(SchemaExportContentYangBodyWriter.class)
                 .build();
     }
diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/common/wrapper/services/Draft11ServicesWrapperImpl.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/common/wrapper/services/Draft11ServicesWrapperImpl.java
new file mode 100644 (file)
index 0000000..bd93fa2
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.restconf.common.wrapper.services;
+
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
+import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
+import org.opendaylight.netconf.sal.restconf.impl.PATCHStatusContext;
+import org.opendaylight.restconf.handlers.DOMDataBrokerHandler;
+import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.RpcServiceHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.handlers.TransactionChainHandler;
+import org.opendaylight.restconf.rest.services.api.Draft11BaseServicesWrapper;
+import org.opendaylight.restconf.rest.services.api.RestconfModulesService;
+import org.opendaylight.restconf.rest.services.api.RestconfOperationsService;
+import org.opendaylight.restconf.rest.services.api.RestconfSchemaService;
+import org.opendaylight.restconf.rest.services.api.RestconfStreamsService;
+import org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceImpl;
+import org.opendaylight.restconf.rest.services.impl.RestconfOperationsServiceImpl;
+import org.opendaylight.restconf.rest.services.impl.RestconfSchemaServiceImpl;
+import org.opendaylight.restconf.rest.services.impl.RestconfStreamsServiceImpl;
+import org.opendaylight.restconf.restful.services.api.Draft11TransactionServicesWrapper;
+import org.opendaylight.restconf.restful.services.api.RestconfDataService;
+import org.opendaylight.restconf.restful.services.api.RestconfInvokeOperationsService;
+import org.opendaylight.restconf.restful.services.api.RestconfStreamsSubscriptionService;
+import org.opendaylight.restconf.restful.services.impl.RestconfDataServiceImpl;
+import org.opendaylight.restconf.restful.services.impl.RestconfInvokeOperationsServiceImpl;
+import org.opendaylight.restconf.restful.services.impl.RestconfStreamsSubscriptionServiceImpl;
+
+/**
+ * Wrapper for services:
+ * <ul>
+ * <li>{@link Draft11BaseServicesWrapper}
+ * <li>{@link Draft11TransactionServicesWrapper}
+ * </ul>
+ *
+ */
+@Path("/")
+public class Draft11ServicesWrapperImpl implements Draft11BaseServicesWrapper, Draft11TransactionServicesWrapper {
+
+    private RestconfDataService delegRestconfDataService;
+    private RestconfInvokeOperationsService delegRestconfInvokeOpsService;
+    private RestconfStreamsSubscriptionService delegRestconfSubscrService;
+    private RestconfModulesService delegRestModService;
+    private RestconfOperationsService delegRestOpsService;
+    private RestconfStreamsService delegRestStrsService;
+    private RestconfSchemaService delegRestSchService;
+
+    private Draft11ServicesWrapperImpl() {
+    }
+
+    private static class InstanceHolder {
+        public static final Draft11ServicesWrapperImpl INSTANCE = new Draft11ServicesWrapperImpl();
+    }
+
+    public static Draft11ServicesWrapperImpl getInstance() {
+        return InstanceHolder.INSTANCE;
+    }
+
+    @Override
+    public NormalizedNodeContext getModules(final UriInfo uriInfo) {
+        return this.delegRestModService.getModules(uriInfo);
+    }
+
+    @Override
+    public NormalizedNodeContext getModules(final String identifier, final UriInfo uriInfo) {
+        return this.delegRestModService.getModules(identifier, uriInfo);
+    }
+
+    @Override
+    public NormalizedNodeContext getModule(final String identifier, final UriInfo uriInfo) {
+        return this.delegRestModService.getModule(identifier, uriInfo);
+    }
+
+    @Override
+    public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
+        return this.delegRestOpsService.getOperations(uriInfo);
+    }
+
+    @Override
+    public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
+        return this.delegRestOpsService.getOperations(identifier, uriInfo);
+    }
+
+    @Override
+    public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
+        return this.delegRestStrsService.getAvailableStreams(uriInfo);
+    }
+
+    @Override
+    public SchemaExportContext getSchema(final String mountAndModuleId) {
+        return this.delegRestSchService.getSchema(mountAndModuleId);
+    }
+
+    @Override
+    public NormalizedNodeContext readData(final String identifier, final UriInfo uriInfo) {
+        return this.delegRestconfDataService.readData(identifier, uriInfo);
+    }
+
+    @Override
+    public Response putData(final String identifier, final NormalizedNodeContext payload) {
+        return this.delegRestconfDataService.putData(identifier, payload);
+    }
+
+    @Override
+    public Response postData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
+        return this.delegRestconfDataService.postData(identifier, payload, uriInfo);
+    }
+
+    @Override
+    public Response postData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
+        return this.delegRestconfDataService.postData(payload, uriInfo);
+    }
+
+    @Override
+    public Response deleteData(final String identifier) {
+        return this.delegRestconfDataService.deleteData(identifier);
+    }
+
+    @Override
+    public PATCHStatusContext patchData(final String identifier, final PATCHContext context, final UriInfo uriInfo) {
+        return this.delegRestconfDataService.patchData(identifier, context, uriInfo);
+    }
+
+    @Override
+    public PATCHStatusContext patchData(final PATCHContext context, final UriInfo uriInfo) {
+        return this.delegRestconfDataService.patchData(context, uriInfo);
+    }
+
+    @Override
+    public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
+            final UriInfo uriInfo) {
+        return this.delegRestconfInvokeOpsService.invokeRpc(identifier, payload, uriInfo);
+    }
+
+    @Override
+    public Response subscribeToStream(final String identifier, final UriInfo uriInfo) {
+        return this.delegRestconfSubscrService.subscribeToStream(identifier, uriInfo);
+    }
+
+    public void setHandlers(final SchemaContextHandler schemaCtxHandler,
+            final DOMMountPointServiceHandler domMountPointServiceHandler,
+            final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
+            final RpcServiceHandler rpcServiceHandler) {
+        this.delegRestModService = new RestconfModulesServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
+        this.delegRestOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
+        this.delegRestSchService = new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
+        this.delegRestStrsService = new RestconfStreamsServiceImpl(schemaCtxHandler);
+        this.delegRestconfDataService = new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler);
+        this.delegRestconfInvokeOpsService = new RestconfInvokeOperationsServiceImpl(rpcServiceHandler,
+                schemaCtxHandler);
+        this.delegRestconfSubscrService = new RestconfStreamsSubscriptionServiceImpl(domDataBrokerHandler);
+    }
+}
index 4e60d4e25ea23b13a1d7d670630938e654df7f76..1384eac69d1d1f906a1cc029bf77866e83b75f1c 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.restconf.parser.builder;
 
-import static org.opendaylight.restconf.utils.parser.builder.ParserBuilderConstants.Serializer;
 
 import com.google.common.base.Preconditions;
 import java.net.URI;
@@ -15,6 +14,7 @@ import java.util.Iterator;
 import java.util.Map.Entry;
 import org.opendaylight.restconf.utils.RestconfConstants;
 import org.opendaylight.restconf.utils.parser.builder.ParserBuilderConstants;
+import org.opendaylight.restconf.utils.parser.builder.ParserBuilderConstants.Serializer;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -23,6 +23,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithV
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
+import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 /**
@@ -74,7 +75,7 @@ public final class YangInstanceIdentifierSerializer {
             // condition is satisfied also for the first path argument
             if (!arg.getNodeType().getModule().equals(parentModule)) {
                 path.append(RestconfConstants.SLASH
-                        + prefixForNamespace(arg.getNodeType())
+                        + prefixForNamespace(arg.getNodeType(), schemaContext)
                         + ParserBuilderConstants.Deserializer.COLON);
             } else {
                 path.append(RestconfConstants.SLASH);
@@ -169,11 +170,11 @@ public final class YangInstanceIdentifierSerializer {
      *            - {@link QName}
      * @return {@link String}
      */
-    private static String prefixForNamespace(final QName qname) {
+    private static String prefixForNamespace(final QName qname, final SchemaContext schemaContext) {
         final URI namespace = qname.getNamespace();
         Preconditions.checkArgument(namespace != null, "Failed to map QName {}", qname);
-        final String prefix = namespace.toString();
-        return prefix.replace(ParserBuilderConstants.Deserializer.COLON, ParserBuilderConstants.Deserializer.HYPHEN);
+        final Module module = schemaContext.findModuleByNamespaceAndRevision(namespace, qname.getRevision());
+        return module.getName();
     }
 
     private static final class MainVarsWrapper {
@@ -7,10 +7,8 @@
  */
 package org.opendaylight.restconf.rest.services.api;
 
-import javax.ws.rs.Path;
-
 /**
- * Wrapper for all services:
+ * Wrapper for all base services:
  * <ul>
  * <li>{@link RestconfModulesService}
  * <li>{@link RestconfOperationsService}
@@ -19,7 +17,6 @@ import javax.ws.rs.Path;
  * </ul>
  *
  */
-@Path("/")
-public interface Draft11ServicesWrapper
+public interface Draft11BaseServicesWrapper
         extends RestconfModulesService, RestconfOperationsService, RestconfStreamsService, RestconfSchemaService {
 }
diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/services/impl/Draft11ServicesWrapperImpl.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/services/impl/Draft11ServicesWrapperImpl.java
deleted file mode 100644 (file)
index 39acd29..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.restconf.rest.services.impl;
-
-import javax.ws.rs.core.UriInfo;
-import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
-import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
-import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
-import org.opendaylight.restconf.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.rest.services.api.Draft11ServicesWrapper;
-import org.opendaylight.restconf.rest.services.api.RestconfModulesService;
-import org.opendaylight.restconf.rest.services.api.RestconfOperationsService;
-import org.opendaylight.restconf.rest.services.api.RestconfSchemaService;
-import org.opendaylight.restconf.rest.services.api.RestconfStreamsService;
-
-/**
- * Implementation of {@link Draft11ServicesWrapper}
- *
- */
-public class Draft11ServicesWrapperImpl implements Draft11ServicesWrapper {
-
-    private RestconfModulesService delegRestModService;
-    private RestconfOperationsService delegRestOpsService;
-    private RestconfStreamsService delegRestStrsService;
-    private RestconfSchemaService delegRestSchService;
-
-    private Draft11ServicesWrapperImpl() {
-    }
-
-    @Override
-    public NormalizedNodeContext getModules(final UriInfo uriInfo) {
-        return this.delegRestModService.getModules(uriInfo);
-    }
-
-    @Override
-    public NormalizedNodeContext getModules(final String identifier, final UriInfo uriInfo) {
-        return this.delegRestModService.getModules(identifier, uriInfo);
-    }
-
-    @Override
-    public NormalizedNodeContext getModule(final String identifier, final UriInfo uriInfo) {
-        return this.delegRestModService.getModule(identifier, uriInfo);
-    }
-
-    @Override
-    public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
-        return this.delegRestOpsService.getOperations(uriInfo);
-    }
-
-    @Override
-    public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
-        return this.delegRestOpsService.getOperations(identifier, uriInfo);
-    }
-
-    @Override
-    public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
-        return this.delegRestStrsService.getAvailableStreams(uriInfo);
-    }
-
-    @Override
-    public SchemaExportContext getSchema(final String mountAndModuleId) {
-        return this.delegRestSchService.getSchema(mountAndModuleId);
-    }
-
-    public static Draft11ServicesWrapperImpl getInstance() {
-        return InstanceHolder.INSTANCE;
-    }
-
-    private static class InstanceHolder {
-        public static final Draft11ServicesWrapperImpl INSTANCE = new Draft11ServicesWrapperImpl();
-    }
-
-    public void setHandlers(final SchemaContextHandler schemaCtxHandler,
-            final DOMMountPointServiceHandler domMountPointServiceHandler) {
-        this.delegRestModService = new RestconfModulesServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
-        this.delegRestOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
-        this.delegRestSchService = new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
-        this.delegRestStrsService = new RestconfStreamsServiceImpl(schemaCtxHandler);
-    }
-
-}
diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/Draft11TransactionServicesWrapper.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/Draft11TransactionServicesWrapper.java
new file mode 100644 (file)
index 0000000..f455411
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.restconf.restful.services.api;
+
+/**
+ * Wrapper for all transaction services:
+ * <ul>
+ * <li>{@link RestconfDataService}
+ * <li>{@link RestconfInvokeOperationsService}
+ * <li>{@link RestconfStreamsSubscriptionService}
+ * </ul>
+ *
+ */
+public interface Draft11TransactionServicesWrapper
+        extends RestconfDataService, RestconfInvokeOperationsService, RestconfStreamsSubscriptionService {
+
+}
index ca412292efdf48c80d639e13c377134afedede13..62021d8aa345dbc7724602bcf27ccc11d1119d1e 100644 (file)
@@ -42,8 +42,14 @@ public class RestconfDataServiceImpl implements RestconfDataService {
 
     private final static Logger LOG = LoggerFactory.getLogger(RestconfDataServiceImpl.class);
 
-    private SchemaContextHandler schemaContextHandler;
-    private TransactionChainHandler transactionChainHandler;
+    private final SchemaContextHandler schemaContextHandler;
+    private final TransactionChainHandler transactionChainHandler;
+
+    public RestconfDataServiceImpl(final SchemaContextHandler schemaContextHandler,
+            final TransactionChainHandler transactionChainHandler) {
+        this.schemaContextHandler = schemaContextHandler;
+        this.transactionChainHandler = transactionChainHandler;
+    }
 
     @Override
     public NormalizedNodeContext readData(final String identifier, final UriInfo uriInfo) {
index 1322e73ea96e09bfc8f9948ea3ea837e14c02e06..222c13902d8c679bcf90c49286a79fed1cee0586 100644 (file)
@@ -30,8 +30,14 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
  */
 public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperationsService {
 
-    private RpcServiceHandler rpcServiceHandler;
-    private SchemaContextHandler schemaContextHandler;
+    private final RpcServiceHandler rpcServiceHandler;
+    private final SchemaContextHandler schemaContextHandler;
+
+    public RestconfInvokeOperationsServiceImpl(final RpcServiceHandler rpcServiceHandler,
+            final SchemaContextHandler schemaContextHandler) {
+        this.rpcServiceHandler = rpcServiceHandler;
+        this.schemaContextHandler = schemaContextHandler;
+    }
 
     @Override
     public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
index 3ff4e837be685f357fd66ca6747e87ea6b740f39..fa77603e694c163140e2bd7b62ed0326f06f7ca8 100644 (file)
@@ -36,7 +36,11 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
 
     private static final Logger LOG = LoggerFactory.getLogger(RestconfStreamsSubscriptionServiceImpl.class);
 
-    private DOMDataBrokerHandler domDataBrokerHandler;
+    private final DOMDataBrokerHandler domDataBrokerHandler;
+
+    public RestconfStreamsSubscriptionServiceImpl(final DOMDataBrokerHandler domDataBrokerHandler) {
+        this.domDataBrokerHandler = domDataBrokerHandler;
+    }
 
     @Override
     public Response subscribeToStream(final String identifier, final UriInfo uriInfo) {
index a3fe0a8a3d78abe27c66ffb8b6e93ee4eb4dd82b..8094087ac2832422b6475e9be978c8c5dd4ccf40 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.restconf.restful.utils;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import java.util.concurrent.CountDownLatch;
 import javax.annotation.Nullable;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.slf4j.Logger;
@@ -39,19 +40,29 @@ final class FutureCallbackTx {
      */
     static <T, X extends Exception> void addCallback(final CheckedFuture<T, X> listenableFuture, final String txType,
             final FutureDataFactory<T> dataFactory) {
+        final CountDownLatch responseWaiter = new CountDownLatch(1);
         Futures.addCallback(listenableFuture, new FutureCallback<T>() {
 
             @Override
             public void onFailure(final Throwable t) {
                 handlingLoggerAndValues(t, txType, null, null);
+                responseWaiter.countDown();
             }
 
             @Override
             public void onSuccess(final T result) {
                 handlingLoggerAndValues(null, txType, result, dataFactory);
+                responseWaiter.countDown();
             }
 
         });
+        try {
+            responseWaiter.await();
+        } catch (final InterruptedException e) {
+            final String msg = "Problem while waiting for response";
+            LOG.warn(msg);
+            throw new RestconfDocumentedException(msg, e);
+        }
     }
 
     /**
@@ -73,7 +84,7 @@ final class FutureCallbackTx {
     protected static <T> void handlingLoggerAndValues(@Nullable final Throwable t, final String txType,
             final T result, final FutureDataFactory<T> dataFactory) {
         if (t != null) {
-            LOG.info("Transaction({}) FAILED!", txType, t);
+            LOG.warn("Transaction({}) FAILED!", txType, t);
             throw new RestconfDocumentedException("  Transaction(" + txType + ") not committed correctly", t);
         } else {
             LOG.trace("Transaction({}) SUCCESSFUL!", txType);