private Element getResponseInternal( final Document document, final ConfigRegistryClient configRegistryClient, final Datastore source) { final ConfigTransactionClient registryClient; // Read current state from a transaction, if running is source, then start new transaction just // for reading // in case of candidate, get current transaction representing candidate if (source == Datastore.running) { final ObjectName readTx = transactionProvider.getOrCreateReadTransaction(); registryClient = getConfigRegistryClient().getConfigTransactionClient(readTx); } else { registryClient = getConfigRegistryClient() .getConfigTransactionClient(transactionProvider.getOrCreateTransaction()); } try { Element dataElement = XmlUtil.createElement(document, XmlNetconfConstants.DATA_KEY, Optional.<String>absent()); final Set<ObjectName> instances = Datastore.getInstanceQueryStrategy(source, this.transactionProvider) .queryInstances(configRegistryClient); final Config configMapping = new Config( EditConfig.transformMbeToModuleConfigs( registryClient, yangStoreSnapshot.getModuleMXBeanEntryMap()), yangStoreSnapshot.getEnumResolver()); ServiceRegistryWrapper serviceTracker = new ServiceRegistryWrapper(registryClient); dataElement = configMapping.toXml( instances, this.maybeNamespace, document, dataElement, serviceTracker); LOG.trace("{} operation successful", GET_CONFIG); return dataElement; } finally { if (source == Datastore.running) { transactionProvider.closeReadTransaction(); } } }
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); }