コード例 #1
0
 private static boolean isHelloMessage(final Document document) {
   XmlElement element = XmlElement.fromDomElement(document.getDocumentElement());
   try {
     return element.getName().equals(HELLO_TAG)
         && element.hasNamespace()
         && element
             .getNamespace()
             .equals(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
   } catch (MissingNameSpaceException e) {
     // Cannot happen, since we check for hasNamespace
     throw new IllegalStateException(e);
   }
 }
コード例 #2
0
ファイル: GetConfig.java プロジェクト: willtmwu/controller
  public static Datastore fromXml(XmlElement xml)
      throws UnexpectedNamespaceException, UnexpectedElementException, MissingNameSpaceException,
          NetconfDocumentedException {

    xml.checkName(GET_CONFIG);
    xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);

    XmlElement sourceElement =
        xml.getOnlyChildElement(
            XmlNetconfConstants.SOURCE_KEY,
            XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
    XmlElement sourceNode = sourceElement.getOnlyChildElement();
    String sourceParsed = sourceNode.getName();
    LOG.debug("Setting source datastore to '{}'", sourceParsed);
    Datastore sourceDatastore = Datastore.valueOf(sourceParsed);

    // Filter option: ignore for now, TODO only load modules specified by the filter

    return sourceDatastore;
  }
コード例 #3
0
  EditConfigXmlParser.EditConfigExecution fromXml(
      final XmlElement xml,
      final Config cfgMapping,
      TransactionProvider transactionProvider,
      ConfigRegistryClient configRegistryClient)
      throws NetconfDocumentedException {

    EditStrategyType editStrategyType = EditStrategyType.getDefaultStrategy();

    xml.checkName(EditConfigXmlParser.EDIT_CONFIG);
    xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);

    XmlElement targetElement =
        xml.getOnlyChildElementWithSameNamespace(EditConfigXmlParser.TARGET_KEY);
    XmlElement targetChildNode = targetElement.getOnlyChildElementWithSameNamespace();
    String datastoreValue = targetChildNode.getName();
    Datastore targetDatastore = Datastore.valueOf(datastoreValue);
    logger.debug("Setting {} to '{}'", EditConfigXmlParser.TARGET_KEY, targetDatastore);

    // check target
    Preconditions.checkArgument(
        targetDatastore == Datastore.candidate,
        "Only %s datastore supported for edit config but was: %s",
        Datastore.candidate,
        targetDatastore);

    // Test option
    TestOption testOption;
    Optional<XmlElement> testOptionElementOpt =
        xml.getOnlyChildElementWithSameNamespaceOptionally(EditConfigXmlParser.TEST_OPTION_KEY);
    if (testOptionElementOpt.isPresent()) {
      String testOptionValue = testOptionElementOpt.get().getTextContent();
      testOption = EditConfigXmlParser.TestOption.getFromXmlName(testOptionValue);
    } else {
      testOption = EditConfigXmlParser.TestOption.getDefault();
    }
    logger.debug("Setting {} to '{}'", EditConfigXmlParser.TEST_OPTION_KEY, testOption);

    // Error option
    Optional<XmlElement> errorOptionElement =
        xml.getOnlyChildElementWithSameNamespaceOptionally(EditConfigXmlParser.ERROR_OPTION_KEY);
    if (errorOptionElement.isPresent()) {
      String errorOptionParsed = errorOptionElement.get().getTextContent();
      if (false == errorOptionParsed.equals(EditConfigXmlParser.DEFAULT_ERROR_OPTION))
        throw new UnsupportedOperationException(
            "Only "
                + EditConfigXmlParser.DEFAULT_ERROR_OPTION
                + " supported for "
                + EditConfigXmlParser.ERROR_OPTION_KEY
                + ", was "
                + errorOptionParsed);
    }

    // Default op
    Optional<XmlElement> defaultContent =
        xml.getOnlyChildElementWithSameNamespaceOptionally(
            EditConfigXmlParser.DEFAULT_OPERATION_KEY);
    if (defaultContent.isPresent()) {
      String mergeStrategyString = defaultContent.get().getTextContent();
      logger.trace("Setting merge strategy to {}", mergeStrategyString);
      editStrategyType = EditStrategyType.valueOf(mergeStrategyString);
    }
    Set<ObjectName> instancesForFillingServiceRefMapping = Collections.emptySet();
    if (editStrategyType == EditStrategyType.merge) {
      instancesForFillingServiceRefMapping =
          Datastore.getInstanceQueryStrategy(targetDatastore, transactionProvider)
              .queryInstances(configRegistryClient);
      logger.trace(
          "Pre-filling services from following instances: {}",
          instancesForFillingServiceRefMapping);
    }

    XmlElement configElement =
        xml.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.CONFIG_KEY);

    return new EditConfigXmlParser.EditConfigExecution(
        xml,
        cfgMapping,
        configElement,
        testOption,
        instancesForFillingServiceRefMapping,
        editStrategyType);
  }
コード例 #4
0
 private static boolean isNotification(final NetconfMessage message) {
   final XmlElement xmle = XmlElement.fromDomDocument(message.getDocument());
   return XmlNetconfConstants.NOTIFICATION_ELEMENT_NAME.equals(xmle.getName());
 }