X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Foperations%2Feditconfig%2FEditConfig.java;h=3ea26055f33c79212debc907caa259109f7101a2;hp=0cc9d1153f7711ec0aa3c8320b32cc45cd7d67ae;hb=386d8f0ac5fa09ee5514d48284f1a4012f408b52;hpb=72a2f458d328d443e2a5479ac147c1242a41a70f diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/editconfig/EditConfig.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/editconfig/EditConfig.java index 0cc9d1153f..3ea26055f3 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/editconfig/EditConfig.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/editconfig/EditConfig.java @@ -8,15 +8,11 @@ package org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import javax.management.InstanceNotFoundException; -import javax.management.ObjectName; - +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; +import com.google.common.collect.Multimap; import org.opendaylight.controller.config.api.ValidationException; import org.opendaylight.controller.config.util.ConfigRegistryClient; import org.opendaylight.controller.config.util.ConfigTransactionClient; @@ -25,6 +21,7 @@ import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity; import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag; import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorType; +import org.opendaylight.controller.netconf.confignetconfconnector.exception.NetconfConfigHandlingException; import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Config; import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.InstanceConfig; import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.InstanceConfigElementResolved; @@ -46,11 +43,12 @@ import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; +import javax.management.InstanceNotFoundException; +import javax.management.ObjectName; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; public class EditConfig extends AbstractConfigNetconfOperation { @@ -71,14 +69,14 @@ public class EditConfig extends AbstractConfigNetconfOperation { @VisibleForTesting Element getResponseInternal(final Document document, - final EditConfigXmlParser.EditConfigExecution editConfigExecution) throws NetconfDocumentedException { + final EditConfigXmlParser.EditConfigExecution editConfigExecution) throws NetconfDocumentedException, NetconfConfigHandlingException { if (editConfigExecution.shouldTest()) { - executeTests(configRegistryClient, editConfigExecution); + executeTests(getConfigRegistryClient(), editConfigExecution); } if (editConfigExecution.shouldSet()) { - executeSet(configRegistryClient, editConfigExecution); + executeSet(getConfigRegistryClient(), editConfigExecution); } logger.trace("Operation {} successful", EditConfigXmlParser.EDIT_CONFIG); @@ -88,19 +86,7 @@ public class EditConfig extends AbstractConfigNetconfOperation { private void executeSet(ConfigRegistryClient configRegistryClient, EditConfigXmlParser.EditConfigExecution editConfigExecution) throws NetconfDocumentedException { - try { - set(configRegistryClient, editConfigExecution); - - } catch (IllegalStateException e) { - //FIXME: when can IllegalStateException be thrown? - // JmxAttributeValidationException is wrapped in DynamicWritableWrapper with ValidationException - // ValidationException is not thrown until validate or commit is issued - logger.warn("Set phase for {} failed", EditConfigXmlParser.EDIT_CONFIG, e); - final Map errorInfo = new HashMap<>(); - errorInfo.put(ErrorTag.operation_failed.name(), e.getMessage()); - throw new NetconfDocumentedException("Test phase: " + e.getMessage(), e, ErrorType.application, - ErrorTag.operation_failed, ErrorSeverity.error, errorInfo); - } + set(configRegistryClient, editConfigExecution); logger.debug("Set phase for {} operation successful", EditConfigXmlParser.EDIT_CONFIG); } @@ -108,8 +94,7 @@ public class EditConfig extends AbstractConfigNetconfOperation { EditConfigExecution editConfigExecution) throws NetconfDocumentedException { try { test(configRegistryClient, editConfigExecution, editConfigExecution.getDefaultStrategy()); - } catch (IllegalStateException | ValidationException e) { - //FIXME: when can IllegalStateException be thrown? + } catch (final ValidationException e) { logger.warn("Test phase for {} failed", EditConfigXmlParser.EDIT_CONFIG, e); final Map errorInfo = new HashMap<>(); errorInfo.put(ErrorTag.operation_failed.name(), e.getMessage()); @@ -120,10 +105,9 @@ public class EditConfig extends AbstractConfigNetconfOperation { } private void test(ConfigRegistryClient configRegistryClient, EditConfigExecution execution, - EditStrategyType editStrategyType) throws ValidationException { + EditStrategyType editStrategyType) throws ValidationException, NetconfDocumentedException { ObjectName taON = transactionProvider.getTestTransaction(); try { - // default strategy = replace wipes config if (editStrategyType == EditStrategyType.replace) { transactionProvider.wipeTestTransaction(taON); @@ -141,7 +125,7 @@ public class EditConfig extends AbstractConfigNetconfOperation { } private void set(ConfigRegistryClient configRegistryClient, - EditConfigXmlParser.EditConfigExecution editConfigExecution) { + EditConfigXmlParser.EditConfigExecution editConfigExecution) throws NetconfDocumentedException { ObjectName taON = transactionProvider.getOrCreateTransaction(); // default strategy = replace wipes config @@ -156,7 +140,7 @@ public class EditConfig extends AbstractConfigNetconfOperation { setOnTransaction(ta, editConfigExecution); } - private void setServicesOnTransaction(ConfigTransactionClient ta, EditConfigExecution execution) { + private void setServicesOnTransaction(ConfigTransactionClient ta, EditConfigExecution execution) throws NetconfDocumentedException { Services services = execution.getServices(); @@ -177,7 +161,10 @@ public class EditConfig extends AbstractConfigNetconfOperation { logger.debug("Saving service {} with on {} under name {} with service on {}", qnameOfService, on, refName, saved); } catch (InstanceNotFoundException e) { - throw new IllegalStateException("Unable to save ref name " + refName + " for instance " + on, e); + throw new NetconfDocumentedException(String.format("Unable to save ref name " + refName + " for instance " + on, e), + ErrorType.application, + ErrorTag.operation_failed, + ErrorSeverity.error); } } } @@ -188,11 +175,11 @@ public class EditConfig extends AbstractConfigNetconfOperation { return ta.getServiceInterfaceName(namespace, serviceName); } - private void setOnTransaction(ConfigTransactionClient ta, EditConfigExecution execution) { + private void setOnTransaction(ConfigTransactionClient ta, EditConfigExecution execution) throws NetconfDocumentedException { for (Multimap modulesToResolved : execution.getResolvedXmlElements(ta).values()) { - for (Entry moduleToResolved : modulesToResolved.entries()) { + for (Map.Entry moduleToResolved : modulesToResolved.entries()) { String moduleName = moduleToResolved.getKey(); ModuleElementResolved moduleElementResolved = moduleToResolved.getValue(); @@ -206,10 +193,10 @@ public class EditConfig extends AbstractConfigNetconfOperation { } private void handleMisssingInstancesOnTransaction(ConfigTransactionClient ta, - EditConfigExecution execution) { + EditConfigExecution execution) throws NetconfDocumentedException { for (Multimap modulesToResolved : execution.getModulesDefinition(ta).values()) { - for (Entry moduleToResolved : modulesToResolved.entries()) { + for (Map.Entry moduleToResolved : modulesToResolved.entries()) { String moduleName = moduleToResolved.getKey(); ModuleElementDefinition moduleElementDefinition = moduleToResolved.getValue(); @@ -237,7 +224,7 @@ public class EditConfig extends AbstractConfigNetconfOperation { void addIdSchemaNode(IdentitySchemaNode node) { String name = node.getQName().getLocalName(); - Preconditions.checkState(identityNameToSchemaNode.containsKey(name) == false); + Preconditions.checkState(!identityNameToSchemaNode.containsKey(name)); identityNameToSchemaNode.put(name, node); } @@ -263,7 +250,7 @@ public class EditConfig extends AbstractConfigNetconfOperation { } Date revision = module.getRevision(); - Preconditions.checkState(revisionsByNamespace.containsKey(revision) == false, + Preconditions.checkState(!revisionsByNamespace.containsKey(revision), "Duplicate revision %s for namespace %s", revision, namespace); IdentityMapping identityMapping = revisionsByNamespace.get(revision); @@ -289,7 +276,7 @@ public class EditConfig extends AbstractConfigNetconfOperation { Map> namespaceToModuleNameToModuleConfig = Maps.newHashMap(); for (String namespace : mBeanEntries.keySet()) { - for (Entry moduleNameToMbe : mBeanEntries.get(namespace).entrySet()) { + for (Map.Entry moduleNameToMbe : mBeanEntries.get(namespace).entrySet()) { String moduleName = moduleNameToMbe.getKey(); ModuleMXBeanEntry moduleMXBeanEntry = moduleNameToMbe.getValue(); @@ -319,30 +306,12 @@ public class EditConfig extends AbstractConfigNetconfOperation { protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException { EditConfigXmlParser.EditConfigExecution editConfigExecution; - Config cfg = getConfigMapping(configRegistryClient, yangStoreSnapshot); - try { - editConfigExecution = editConfigXmlParser.fromXml(xml, cfg, transactionProvider, configRegistryClient); - } catch (IllegalStateException e) { - logger.warn("Error parsing xml", e); - final Map errorInfo = new HashMap<>(); - errorInfo.put(ErrorTag.missing_attribute.name(), "Error parsing xml: " + e.getMessage()); - throw new NetconfDocumentedException(e.getMessage(), ErrorType.rpc, ErrorTag.missing_attribute, - ErrorSeverity.error, errorInfo); - } catch (final IllegalArgumentException e) { - logger.warn("Error parsing xml", e); - final Map errorInfo = new HashMap<>(); - errorInfo.put(ErrorTag.bad_attribute.name(), e.getMessage()); - throw new NetconfDocumentedException(e.getMessage(), ErrorType.rpc, ErrorTag.bad_attribute, - ErrorSeverity.error, errorInfo); - } catch (final UnsupportedOperationException e) { - logger.warn("Unsupported", e); - final Map errorInfo = new HashMap<>(); - errorInfo.put(ErrorTag.operation_not_supported.name(), "Unsupported option for 'edit-config'"); - throw new NetconfDocumentedException(e.getMessage(), ErrorType.application, - ErrorTag.operation_not_supported, ErrorSeverity.error, errorInfo); - } + Config cfg = getConfigMapping(getConfigRegistryClient(), yangStoreSnapshot); + editConfigExecution = editConfigXmlParser.fromXml(xml, cfg, transactionProvider, getConfigRegistryClient()); - return getResponseInternal(document, editConfigExecution); + Element responseInternal; + responseInternal = getResponseInternal(document, editConfigExecution); + return responseInternal; } }