예제 #1
0
 private void postDataWithinTransaction(
     final DOMDataReadWriteTransaction rWTransaction,
     final LogicalDatastoreType datastore,
     final YangInstanceIdentifier path,
     final NormalizedNode<?, ?> payload,
     final SchemaContext schemaContext) {
   // FIXME: This is doing correct post for container and list children
   //        not sure if this will work for choice case
   if (payload instanceof MapNode) {
     LOG.trace(
         "POST {} within Restconf PATCH: {} with payload {}", datastore.name(), path, payload);
     final NormalizedNode<?, ?> emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path);
     rWTransaction.merge(
         datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
     ensureParentsByMerge(datastore, path, rWTransaction, schemaContext);
     for (final MapEntryNode child : ((MapNode) payload).getValue()) {
       final YangInstanceIdentifier childPath = path.node(child.getIdentifier());
       checkItemDoesNotExists(rWTransaction, datastore, childPath);
       rWTransaction.put(datastore, childPath, child);
     }
   } else {
     checkItemDoesNotExists(rWTransaction, datastore, path);
     ensureParentsByMerge(datastore, path, rWTransaction, schemaContext);
     rWTransaction.put(datastore, path, payload);
   }
 }
  @Override
  protected CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(
      final NormalizedNode<?, ?> input) {
    final Optional<NormalizedNode<?, ?>> maybeKey = NormalizedNodes.findNode(input, keyId);

    // Routing key is present, attempt to deliver as a routed RPC
    if (maybeKey.isPresent()) {
      final NormalizedNode<?, ?> key = maybeKey.get();
      final Object value = key.getValue();
      if (value instanceof YangInstanceIdentifier) {
        final YangInstanceIdentifier iid = (YangInstanceIdentifier) value;

        // Find a DOMRpcImplementation for a specific iid
        final List<DOMRpcImplementation> specificImpls = getImplementations(iid);
        if (specificImpls != null) {
          return specificImpls
              .get(0)
              .invokeRpc(DOMRpcIdentifier.create(getSchemaPath(), iid), input);
        }

        LOG.debug("No implementation for context {} found will now look for wildcard id", iid);

        // Find a DOMRpcImplementation for a wild card. Usually remote-rpc-connector would register
        // an
        // implementation this way
        final List<DOMRpcImplementation> mayBeRemoteImpls =
            getImplementations(YangInstanceIdentifier.EMPTY);

        if (mayBeRemoteImpls != null) {
          return mayBeRemoteImpls
              .get(0)
              .invokeRpc(DOMRpcIdentifier.create(getSchemaPath(), iid), input);
        }

      } else {
        LOG.warn("Ignoring wrong context value {}", value);
      }
    }

    final List<DOMRpcImplementation> impls = getImplementations(null);
    if (impls != null) {
      return impls.get(0).invokeRpc(globalRpcId, input);
    } else {
      return Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(
          new DOMRpcImplementationNotAvailableException(
              "No implementation of RPC %s available", getSchemaPath()));
    }
  }
예제 #3
0
  private <T> Optional<T> getArgumentOpt(
      final Input inputArgs, final String argName, final Class<T> type) {
    final QName argQName = QName.create(getCommandId(), argName);
    final NormalizedNode<?, ?> argumentNode = inputArgs.getArg(argName);
    if (argumentNode == null) {
      return Optional.absent();
    }
    Preconditions.checkArgument(
        argumentNode instanceof LeafNode, "Only simple type argument supported, %s", argQName);

    final Object value = argumentNode.getValue();
    Preconditions.checkArgument(
        type.isInstance(value),
        "Unexpected instance type: %s for argument: %s",
        value.getClass(),
        argQName);
    return Optional.of(type.cast(value));
  }
  /** Test case: NodeId translation */
  @Test
  public void testNodeId() {
    String logicalName = "node:1";
    UnderlayItem physicalNode =
        new UnderlayItem(
            mockNormalizedNode, null, TOPOLOGY_NAME, "node:1", CorrelationItemEnum.Node);
    OverlayItem logicalNode =
        new OverlayItem(Collections.singletonList(physicalNode), CorrelationItemEnum.Node);
    OverlayItemWrapper wrapper = new OverlayItemWrapper(logicalName, logicalNode);
    NormalizedNode<?, ?> normalizedNode = translator.translate(wrapper);

    NormalizedNode<?, ?> nodeId =
        NormalizedNodes.findNode(
                normalizedNode, YangInstanceIdentifier.of(TopologyQNames.NETWORK_NODE_ID_QNAME))
            .get();
    Assert.assertEquals(
        "NormalizedNode ID should be the same as the LogicalNodeWrapper ID",
        logicalName,
        nodeId.getValue());
  }