Merge "fixed restconf notification subscription parsing."
authorTony Tkacik <ttkacik@cisco.com>
Thu, 19 Mar 2015 08:16:32 +0000 (08:16 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 19 Mar 2015 08:16:33 +0000 (08:16 +0000)
1  2 
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java

index 75c61d1c196d720401236dba043ec518d38b7fc4,e2e3db052fa085381f1490f54523fb017b4af4d4..814273ebc0dc6ba1205fa3a7c93dd97152e38034
@@@ -18,6 -18,7 +18,7 @@@ import com.google.common.base.Throwable
  import com.google.common.collect.ImmutableList;
  import com.google.common.collect.Iterables;
  import com.google.common.collect.Lists;
+ import com.google.common.collect.Sets;
  import com.google.common.util.concurrent.CheckedFuture;
  import com.google.common.util.concurrent.Futures;
  import java.math.BigInteger;
@@@ -74,6 -75,7 +75,7 @@@ import org.opendaylight.yangtools.yang.
  import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
  import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
  import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+ import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
  import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
  import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
  import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
@@@ -168,8 -170,6 +170,6 @@@ public class RestconfImpl implements Re
  
      private static final URI NAMESPACE_EVENT_SUBSCRIPTION_AUGMENT = URI.create("urn:sal:restconf:event:subscription");
  
-     private static final Date EVENT_SUBSCRIPTION_AUGMENT_REVISION;
      private static final String DATASTORE_PARAM_NAME = "datastore";
  
      private static final String SCOPE_PARAM_NAME = "scope";
  
      private static final QName NETCONF_BASE_QNAME;
  
+     private static final QNameModule SAL_REMOTE_AUGMENT;
+     private static final YangInstanceIdentifier.AugmentationIdentifier SAL_REMOTE_AUG_IDENTIFIER;
      static {
          try {
-             EVENT_SUBSCRIPTION_AUGMENT_REVISION = new SimpleDateFormat("yyyy-MM-dd").parse("2014-07-08");
+             final Date eventSubscriptionAugRevision = new SimpleDateFormat("yyyy-MM-dd").parse("2014-07-08");
              NETCONF_BASE_QNAME = QName.create(QNameModule.create(new URI(NETCONF_BASE), null), NETCONF_BASE_PAYLOAD_NAME );
+             SAL_REMOTE_AUGMENT = QNameModule.create(NAMESPACE_EVENT_SUBSCRIPTION_AUGMENT,
+                     eventSubscriptionAugRevision);
+             SAL_REMOTE_AUG_IDENTIFIER = new YangInstanceIdentifier.AugmentationIdentifier(Sets.newHashSet(QName.create(SAL_REMOTE_AUGMENT, "scope"),
+                     QName.create(SAL_REMOTE_AUGMENT, "datastore")));
          } catch (final ParseException e) {
              throw new RestconfDocumentedException(
                      "It wasn't possible to convert revision date of sal-remote-augment to date", ErrorType.APPLICATION,
  
          final DOMRpcResult result = checkRpcResponse(response);
  
 -        DataSchemaNode resultNodeSchema = null;
 +        RpcDefinition resultNodeSchema = null;
          final NormalizedNode<?, ?> resultData = result.getResult();
          if (result != null && result.getResult() != null) {
 -            final RpcDefinition rpcDef = (RpcDefinition) payload.getInstanceIdentifierContext().getSchemaNode();
 -            resultNodeSchema = rpcDef.getOutput();
 +            resultNodeSchema = (RpcDefinition) payload.getInstanceIdentifierContext().getSchemaNode();
          }
  
 -        return new NormalizedNodeContext(new InstanceIdentifierContext(null, resultNodeSchema, mountPoint,
 -                schemaContext), resultData);
 +        return new NormalizedNodeContext(new InstanceIdentifierContext<RpcDefinition>(null,
 +                resultNodeSchema, mountPoint, schemaContext), resultData);
      }
  
      private DOMRpcResult checkRpcResponse(final CheckedFuture<DOMRpcResult, DOMRpcException> response) {
  
          if (rpc.getInput() != null) {
              // FIXME : find a correct Error from specification
 -            throw new IllegalStateException("RPC " + rpc + " needs input value!");
 +            throw new IllegalStateException("RPC " + rpc + " does'n need input value!");
          }
  
          final CheckedFuture<DOMRpcResult, DOMRpcException> response;
          final YangInstanceIdentifier resultII;
          try {
              if (mountPoint != null) {
 -                broker.commitConfigurationDataPost(mountPoint, normalizedII, payload.getData());
 -
 +                broker.commitConfigurationDataPost(mountPoint, normalizedII, payload.getData()).checkedGet();
              } else {
 -                broker.commitConfigurationDataPost(normalizedII, payload.getData());
 +                broker.commitConfigurationDataPost(normalizedII, payload.getData()).checkedGet();
              }
          } catch(final RestconfDocumentedException e) {
              throw e;
       */
      private <T> T parseEnumTypeParameter(final ContainerNode value, final Class<T> classDescriptor,
              final String paramName) {
-         final QNameModule salRemoteAugment = QNameModule.create(NAMESPACE_EVENT_SUBSCRIPTION_AUGMENT,
-                 EVENT_SUBSCRIPTION_AUGMENT_REVISION);
-         final Optional<DataContainerChild<? extends PathArgument, ?>> enumNode = value.getChild(new NodeIdentifier(
-                 QName.create(salRemoteAugment, paramName)));
+         final Optional<DataContainerChild<? extends PathArgument, ?>> augNode = value.getChild(SAL_REMOTE_AUG_IDENTIFIER);
+         if (!augNode.isPresent() && !(augNode instanceof AugmentationNode)) {
+             return null;
+         }
+         final Optional<DataContainerChild<? extends PathArgument, ?>> enumNode =
+                 ((AugmentationNode) augNode.get()).getChild(new NodeIdentifier(QName.create(SAL_REMOTE_AUGMENT, paramName)));
          if (!enumNode.isPresent()) {
              return null;
          }