From: David Suarez Date: Sat, 9 Sep 2017 18:27:18 +0000 (+0200) Subject: Fix checkstyle issues to enforce it X-Git-Tag: release/oxygen~95 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=d266f4384d4850af9049d7cddd2bbac8f75ba61e Fix checkstyle issues to enforce it Fix checkstyle issues to enforce it. Change-Id: I8ea15ab059b1ffa3de79737cf2ca0763f2455139 Signed-off-by: David Suarez --- diff --git a/opendaylight/config/config-manager-facade-xml/pom.xml b/opendaylight/config/config-manager-facade-xml/pom.xml index 39310ba887..47fe18cc18 100644 --- a/opendaylight/config/config-manager-facade-xml/pom.xml +++ b/opendaylight/config/config-manager-facade-xml/pom.xml @@ -1,58 +1,64 @@ - - 4.0.0 - - config-subsystem - org.opendaylight.controller - 0.8.0-SNAPSHOT - - config-manager-facade-xml - ${project.artifactId} - bundle + + 4.0.0 + + config-subsystem + org.opendaylight.controller + 0.8.0-SNAPSHOT + + config-manager-facade-xml + ${project.artifactId} + bundle - - - org.opendaylight.controller - config-util - - - org.opendaylight.controller - yang-jmx-generator - - - org.opendaylight.yangtools - yang-data-api - - - org.opendaylight.mdsal - mdsal-binding-generator-impl - - - org.slf4j - slf4j-api - - - junit - junit - test - - + + + org.opendaylight.controller + config-util + + + org.opendaylight.controller + yang-jmx-generator + + + org.opendaylight.yangtools + yang-data-api + + + org.opendaylight.mdsal + mdsal-binding-generator-impl + + + org.slf4j + slf4j-api + + + junit + junit + test + + - - - - org.apache.felix - maven-bundle-plugin - true - - - org.opendaylight.controller.config.facade.xml.osgi.YangStoreActivator - - - - - + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + checkstyle.violationSeverity=error + + + + org.apache.felix + maven-bundle-plugin + true + + + org.opendaylight.controller.config.facade.xml.osgi.YangStoreActivator + + + + + diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigExecution.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigExecution.java index 26ba0eafc4..d6179c793b 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigExecution.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigExecution.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -28,7 +28,8 @@ public class ConfigExecution { private final Config configResolver; private final XmlElement configElement; - public ConfigExecution(final Config configResolver, final XmlElement configElement, final TestOption testOption, final EditStrategyType defaultStrategy) throws DocumentedException { + public ConfigExecution(final Config configResolver, final XmlElement configElement, final TestOption testOption, + final EditStrategyType defaultStrategy) throws DocumentedException { Config.checkUnrecognisedChildren(configElement); this.configResolver = configResolver; this.configElement = configElement; @@ -47,7 +48,8 @@ public class ConfigExecution { public Map> getResolvedXmlElements( final ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException { - return configResolver.fromXmlModulesResolved(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry)); + return configResolver.fromXmlModulesResolved(configElement, defaultEditStrategyType, + getServiceRegistryWrapper(serviceRegistry)); } public ServiceRegistryWrapper getServiceRegistryWrapper(final ServiceReferenceReadableRegistry serviceRegistry) { @@ -55,9 +57,10 @@ public class ConfigExecution { return new ServiceRegistryWrapper(serviceRegistry); } - public Map> getModulesDefinition( + public Map> getModulesDefinition( final ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException { - return configResolver.fromXmlModulesMap(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry)); + return configResolver.fromXmlModulesMap(configElement, defaultEditStrategyType, + getServiceRegistryWrapper(serviceRegistry)); } public EditStrategyType getDefaultStrategy() { diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigSubsystemFacade.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigSubsystemFacade.java index 2b4e633646..c535b2184c 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigSubsystemFacade.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigSubsystemFacade.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -10,14 +10,17 @@ package org.opendaylight.controller.config.facade.xml; import com.google.common.base.Optional; import com.google.common.collect.Multimap; + import java.io.Closeable; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; + import javax.management.InstanceNotFoundException; import javax.management.ObjectName; + import org.opendaylight.controller.config.api.ConflictingVersionException; import org.opendaylight.controller.config.api.ValidationException; import org.opendaylight.controller.config.api.jmx.CommitStatus; @@ -58,7 +61,8 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; /** - * Config subsystem facade for xml format + * Config subsystem facade for xml format. + * *

* TODO extract generic interface for config subsystem facades */ @@ -71,7 +75,10 @@ public class ConfigSubsystemFacade implements Closeable { private final ConfigRegistryClient configRegistryClientNoNotifications; private final RpcFacade rpcFacade; - public ConfigSubsystemFacade(final ConfigRegistryClient configRegistryClient, final ConfigRegistryClient configRegistryClientNoNotifications, final YangStoreService yangStoreService, final String id) { + public ConfigSubsystemFacade(final ConfigRegistryClient configRegistryClient, + final ConfigRegistryClient configRegistryClientNoNotifications, + final YangStoreService yangStoreService, + final String id) { this.configRegistryClient = configRegistryClient; this.configRegistryClientNoNotifications = configRegistryClientNoNotifications; this.yangStoreService = yangStoreService; @@ -79,7 +86,10 @@ public class ConfigSubsystemFacade implements Closeable { rpcFacade = new RpcFacade(yangStoreService, configRegistryClient); } - public ConfigSubsystemFacade(final ConfigRegistryClient configRegistryClient, final ConfigRegistryClient configRegistryClientNoNotifications, final YangStoreService yangStoreService, final TransactionProvider txProvider) { + public ConfigSubsystemFacade(final ConfigRegistryClient configRegistryClient, + final ConfigRegistryClient configRegistryClientNoNotifications, + final YangStoreService yangStoreService, + final TransactionProvider txProvider) { this.configRegistryClient = configRegistryClient; this.configRegistryClientNoNotifications = configRegistryClientNoNotifications; this.yangStoreService = yangStoreService; @@ -87,25 +97,30 @@ public class ConfigSubsystemFacade implements Closeable { rpcFacade = new RpcFacade(yangStoreService, configRegistryClient); } - public Element getConfiguration(final Document document, final Datastore source, final Optional maybeNamespace) { + public Element getConfiguration(final Document document, final Datastore source, + final Optional maybeNamespace) { final ConfigTransactionClient registryClient; - // Read current state from a transaction, if running is source, then start new transaction just for reading + // 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 = configRegistryClient.getConfigTransactionClient(readTx); } else { - registryClient = configRegistryClient.getConfigTransactionClient(transactionProvider.getOrCreateTransaction()); + registryClient = configRegistryClient + .getConfigTransactionClient(transactionProvider.getOrCreateTransaction()); } try { - Element dataElement = XmlUtil.createElement(document, XmlMappingConstants.DATA_KEY, Optional.absent()); + Element dataElement = XmlUtil.createElement(document, XmlMappingConstants.DATA_KEY, + Optional.absent()); final Set instances = Datastore.getInstanceQueryStrategy(source, this.transactionProvider) .queryInstances(configRegistryClient); - final Config configMapping = - new Config(transformMbeToModuleConfigs(yangStoreService.getModuleMXBeanEntryMap()), yangStoreService.getEnumResolver()); + final Config configMapping = new Config( + transformMbeToModuleConfigs(yangStoreService.getModuleMXBeanEntryMap()), + yangStoreService.getEnumResolver()); ServiceRegistryWrapper serviceTracker = new ServiceRegistryWrapper(registryClient); dataElement = configMapping.toXml(instances, maybeNamespace, document, dataElement, serviceTracker); @@ -118,7 +133,8 @@ public class ConfigSubsystemFacade implements Closeable { } } - public void executeConfigExecution(final ConfigExecution configExecution) throws DocumentedException, ValidationException { + public void executeConfigExecution(final ConfigExecution configExecution) + throws DocumentedException, ValidationException { if (configExecution.shouldTest()) { executeTests(configExecution); } @@ -128,13 +144,15 @@ public class ConfigSubsystemFacade implements Closeable { } } - public CommitStatus commitTransaction() throws DocumentedException, ValidationException, ConflictingVersionException { + public CommitStatus commitTransaction() + throws DocumentedException, ValidationException, ConflictingVersionException { final CommitStatus status = this.transactionProvider.commitTransaction(); LOG.trace("Transaction committed successfully: {}", status); return status; } - public CommitStatus commitSilentTransaction() throws DocumentedException, ValidationException, ConflictingVersionException { + public CommitStatus commitSilentTransaction() + throws DocumentedException, ValidationException, ConflictingVersionException { final CommitStatus status = this.transactionProvider.commitTransaction(configRegistryClientNoNotifications); LOG.trace("Transaction committed successfully: {}", status); return status; @@ -142,15 +160,18 @@ public class ConfigSubsystemFacade implements Closeable { private void executeSet(final ConfigExecution configExecution) throws DocumentedException { set(configExecution); - LOG.debug("Set phase for {} operation successful, element: ", configExecution.getDefaultStrategy(), configExecution.getConfigElement()); + LOG.debug("Set phase for {} operation successful, element: ", configExecution.getDefaultStrategy(), + configExecution.getConfigElement()); } private void executeTests(final ConfigExecution configExecution) throws DocumentedException, ValidationException { test(configExecution, configExecution.getDefaultStrategy()); - LOG.debug("Test phase for {} operation successful, element: ", configExecution.getDefaultStrategy(), configExecution.getConfigElement()); + LOG.debug("Test phase for {} operation successful, element: ", configExecution.getDefaultStrategy(), + configExecution.getConfigElement()); } - private void test(final ConfigExecution execution, final EditStrategyType editStrategyType) throws ValidationException, DocumentedException { + private void test(final ConfigExecution execution, final EditStrategyType editStrategyType) + throws ValidationException, DocumentedException { ObjectName taON = transactionProvider.getTestTransaction(); try { // default strategy = replace wipes config @@ -169,31 +190,33 @@ public class ConfigSubsystemFacade implements Closeable { } } - private void set(final ConfigExecution ConfigExecution) throws DocumentedException { + private void set(final ConfigExecution configExecution) throws DocumentedException { ObjectName taON = transactionProvider.getOrCreateTransaction(); // default strategy = replace wipes config - if (ConfigExecution.getDefaultStrategy() == EditStrategyType.replace) { + if (configExecution.getDefaultStrategy() == EditStrategyType.replace) { transactionProvider.wipeTransaction(); } ConfigTransactionClient ta = configRegistryClient.getConfigTransactionClient(taON); - handleMisssingInstancesOnTransaction(ta, ConfigExecution); - setServicesOnTransaction(ta, ConfigExecution); - setOnTransaction(ta, ConfigExecution); + handleMisssingInstancesOnTransaction(ta, configExecution); + setServicesOnTransaction(ta, configExecution); + setOnTransaction(ta, configExecution); } - private void setServicesOnTransaction(final ConfigTransactionClient ta, final ConfigExecution execution) throws DocumentedException { - + private void setServicesOnTransaction(final ConfigTransactionClient ta, final ConfigExecution execution) + throws DocumentedException { Services services = execution.getServices(); - Map>> namespaceToServiceNameToRefNameToInstance = services - .getNamespaceToServiceNameToRefNameToInstance(); - - for (Map.Entry>> namespaceToServiceToRefEntry : namespaceToServiceNameToRefNameToInstance.entrySet()) { - for (Map.Entry> serviceToRefEntry : namespaceToServiceToRefEntry.getValue().entrySet()) { + Map>> namespaceToServiceNameToRefNameToInstance = + services.getNamespaceToServiceNameToRefNameToInstance(); + for (Map.Entry>> + namespaceToServiceToRefEntry : namespaceToServiceNameToRefNameToInstance + .entrySet()) { + for (Map.Entry> serviceToRefEntry + : namespaceToServiceToRefEntry.getValue().entrySet()) { String qnameOfService = getQname(ta, namespaceToServiceToRefEntry.getKey(), serviceToRefEntry.getKey()); Map refNameToInstance = serviceToRefEntry.getValue(); @@ -202,17 +225,19 @@ public class ConfigSubsystemFacade implements Closeable { try { if (Services.ServiceInstance.EMPTY_SERVICE_INSTANCE == refNameToServiceEntry.getValue()) { ta.removeServiceReference(qnameOfService, refNameToServiceEntry.getKey()); - LOG.debug("Removing service {} with name {}", qnameOfService, refNameToServiceEntry.getKey()); + LOG.debug("Removing service {} with name {}", qnameOfService, + refNameToServiceEntry.getKey()); } else { - ObjectName saved = ta.saveServiceReference(qnameOfService, refNameToServiceEntry.getKey(), on); + ObjectName saved = ta.saveServiceReference(qnameOfService, refNameToServiceEntry.getKey(), + on); LOG.debug("Saving service {} with on {} under name {} with service on {}", qnameOfService, on, refNameToServiceEntry.getKey(), saved); } } catch (final InstanceNotFoundException e) { - throw new DocumentedException(String.format("Unable to edit ref name " + refNameToServiceEntry.getKey() + " for instance " + on, e), - ErrorType.APPLICATION, - ErrorTag.OPERATION_FAILED, - ErrorSeverity.ERROR); + throw new DocumentedException( + String.format("Unable to edit ref name " + refNameToServiceEntry.getKey() + + " for instance " + on, e), + ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR); } } } @@ -223,9 +248,11 @@ public class ConfigSubsystemFacade implements Closeable { return ta.getServiceInterfaceName(namespace, serviceName); } - private void setOnTransaction(final ConfigTransactionClient ta, final ConfigExecution execution) throws DocumentedException { + private void setOnTransaction(final ConfigTransactionClient ta, final ConfigExecution execution) + throws DocumentedException { - for (Multimap modulesToResolved : execution.getResolvedXmlElements(ta).values()) { + for (Multimap modulesToResolved : execution.getResolvedXmlElements(ta) + .values()) { for (Map.Entry moduleToResolved : modulesToResolved.entries()) { String moduleName = moduleToResolved.getKey(); @@ -235,29 +262,33 @@ public class ConfigSubsystemFacade implements Closeable { InstanceConfigElementResolved ice = moduleElementResolved.getInstanceConfigElementResolved(); EditConfigStrategy strategy = ice.getEditStrategy(); - strategy.executeConfiguration(moduleName, instanceName, ice.getConfiguration(), ta, execution.getServiceRegistryWrapper(ta)); + strategy.executeConfiguration(moduleName, instanceName, ice.getConfiguration(), ta, + execution.getServiceRegistryWrapper(ta)); } } } - private void handleMisssingInstancesOnTransaction(final ConfigTransactionClient ta, - final ConfigExecution execution) throws DocumentedException { + private void handleMisssingInstancesOnTransaction(final ConfigTransactionClient ta, final ConfigExecution execution) + throws DocumentedException { - for (Multimap modulesToResolved : execution.getModulesDefinition(ta).values()) { + for (Multimap modulesToResolved : execution.getModulesDefinition(ta) + .values()) { for (Map.Entry moduleToResolved : modulesToResolved.entries()) { String moduleName = moduleToResolved.getKey(); ModuleElementDefinition moduleElementDefinition = moduleToResolved.getValue(); EditConfigStrategy strategy = moduleElementDefinition.getEditStrategy(); - strategy.executeConfiguration(moduleName, moduleElementDefinition.getInstanceName(), null, ta, execution.getServiceRegistryWrapper(ta)); + strategy.executeConfiguration(moduleName, moduleElementDefinition.getInstanceName(), null, ta, + execution.getServiceRegistryWrapper(ta)); } } } public Config getConfigMapping() { final YangStoreContext snapshot = yangStoreService.getCurrentSnapshot(); - Map> factories = transformMbeToModuleConfigs(snapshot.getModuleMXBeanEntryMap()); + Map> factories = transformMbeToModuleConfigs( + snapshot.getModuleMXBeanEntryMap()); Map> identitiesMap = transformIdentities(snapshot.getModules()); return new Config(factories, identitiesMap, snapshot.getEnumResolver()); } @@ -266,13 +297,13 @@ public class ConfigSubsystemFacade implements Closeable { Map> mappedIds = new HashMap<>(); for (Module module : modules) { String namespace = module.getNamespace().toString(); - Map revisionsByNamespace = - mappedIds.computeIfAbsent(namespace, k -> new HashMap<>()); + Map revisionsByNamespace = mappedIds.computeIfAbsent(namespace, + k -> new HashMap<>()); Date revision = module.getRevision(); - IdentityMapping identityMapping = - revisionsByNamespace.computeIfAbsent(revision, k -> new IdentityMapping()); + IdentityMapping identityMapping = revisionsByNamespace.computeIfAbsent(revision, + k -> new IdentityMapping()); for (IdentitySchemaNode identitySchemaNode : module.getIdentities()) { identityMapping.addIdSchemaNode(identitySchemaNode); @@ -284,31 +315,32 @@ public class ConfigSubsystemFacade implements Closeable { } public Map> transformMbeToModuleConfigs( + Map> transformMbeToModuleConfigs( final Map> mBeanEntries) { - return transformMbeToModuleConfigs(configRegistryClient, mBeanEntries); + Map> mbeanentries) { + return transformMbeToModuleConfigs(configRegistryClient, mbeanentries); } public Map> transformMbeToModuleConfigs( + Map> transformMbeToModuleConfigs( final BeanReader reader, - final Map> mBeanEntries) { - + final Map> mbeanentries) { Map> namespaceToModuleNameToModuleConfig = new HashMap<>(); - for (Map.Entry> namespaceToModuleToMbe : mBeanEntries.entrySet()) { + for (Map.Entry> namespaceToModuleToMbe : mbeanentries.entrySet()) { for (Map.Entry moduleNameToMbe : namespaceToModuleToMbe.getValue().entrySet()) { String moduleName = moduleNameToMbe.getKey(); ModuleMXBeanEntry moduleMXBeanEntry = moduleNameToMbe.getValue(); - ModuleConfig moduleConfig = new ModuleConfig(moduleName, - new InstanceConfig(reader, moduleMXBeanEntry.getAttributes(), moduleMXBeanEntry.getNullableDummyContainerName())); + ModuleConfig moduleConfig = new ModuleConfig(moduleName, new InstanceConfig(reader, + moduleMXBeanEntry.getAttributes(), moduleMXBeanEntry.getNullableDummyContainerName())); - Map moduleNameToModuleConfig = - namespaceToModuleNameToModuleConfig.computeIfAbsent(namespaceToModuleToMbe.getKey(), - k -> new HashMap<>()); + Map moduleNameToModuleConfig = namespaceToModuleNameToModuleConfig + .computeIfAbsent(namespaceToModuleToMbe.getKey(), k -> new HashMap<>()); moduleNameToModuleConfig.put(moduleName, moduleConfig); } @@ -317,15 +349,18 @@ public class ConfigSubsystemFacade implements Closeable { return namespaceToModuleNameToModuleConfig; } - public ConfigExecution getConfigExecution(final Config configMapping, final Element xmlToBePersisted) throws DocumentedException { - return new ConfigExecution(configMapping, XmlElement.fromDomElement(xmlToBePersisted), TestOption.testThenSet, EditStrategyType.getDefaultStrategy()); + public ConfigExecution getConfigExecution(final Config configMapping, final Element xmlToBePersisted) + throws DocumentedException { + return new ConfigExecution(configMapping, XmlElement.fromDomElement(xmlToBePersisted), TestOption.testThenSet, + EditStrategyType.getDefaultStrategy()); } - private Map> createModuleRuntimes(final ConfigRegistryClient configRegistryClient, - final Map> mBeanEntries) { + private Map> createModuleRuntimes( + final ConfigRegistryClient configRegistryClient, + final Map> mbeanentries) { Map> retVal = new HashMap<>(); - for (Map.Entry> namespaceToModuleEntry : mBeanEntries.entrySet()) { + for (Map.Entry> namespaceToModuleEntry : mbeanentries.entrySet()) { Map innerMap = new HashMap<>(); Map entriesFromNamespace = namespaceToModuleEntry.getValue(); @@ -336,7 +371,8 @@ public class ConfigSubsystemFacade implements Closeable { Map cache = new HashMap<>(); RuntimeBeanEntry root = null; for (RuntimeBeanEntry rbe : mbe.getRuntimeBeans()) { - cache.put(rbe, new InstanceConfig(configRegistryClient, rbe.getYangPropertiesToTypesMap(), mbe.getNullableDummyContainerName())); + cache.put(rbe, new InstanceConfig(configRegistryClient, rbe.getYangPropertiesToTypesMap(), + mbe.getNullableDummyContainerName())); if (rbe.isRoot()) { root = rbe; } @@ -356,7 +392,8 @@ public class ConfigSubsystemFacade implements Closeable { return retVal; } - private InstanceRuntime createInstanceRuntime(final RuntimeBeanEntry root, final Map cache) { + private InstanceRuntime createInstanceRuntime(final RuntimeBeanEntry root, + final Map cache) { Map children = new HashMap<>(); for (RuntimeBeanEntry child : root.getChildren()) { children.put(child.getJavaNamePrefix(), createInstanceRuntime(child, cache)); @@ -378,10 +415,12 @@ public class ConfigSubsystemFacade implements Closeable { final ConfigTransactionClient txClient = configRegistryClient.getConfigTransactionClient(testTransaction); try { - // Runtime beans are not parts of transactions and have to be queried against the central registry + // Runtime beans are not parts of transactions and have to be queried against + // the central registry final Set runtimeBeans = configRegistryClient.lookupRuntimeBeans(); - final Set configBeans = Datastore.getInstanceQueryStrategy(Datastore.running, transactionProvider) + final Set configBeans = Datastore + .getInstanceQueryStrategy(Datastore.running, transactionProvider) .queryInstances(configRegistryClient); final Map> moduleRuntimes = createModuleRuntimes(configRegistryClient, @@ -391,7 +430,8 @@ public class ConfigSubsystemFacade implements Closeable { final Map> moduleConfigs = transformMbeToModuleConfigs(txClient, yangStoreSnapshot.getModuleMXBeanEntryMap()); - final org.opendaylight.controller.config.facade.xml.runtime.Runtime runtime = new Runtime(moduleRuntimes, moduleConfigs); + final org.opendaylight.controller.config.facade.xml.runtime.Runtime runtime = new Runtime(moduleRuntimes, + moduleConfigs); return runtime.toXml(runtimeBeans, configBeans, document, yangStoreSnapshot.getEnumResolver()); } finally { @@ -419,4 +459,3 @@ public class ConfigSubsystemFacade implements Closeable { } } - diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigSubsystemFacadeFactory.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigSubsystemFacadeFactory.java index 02a7914a16..895bcc5a30 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigSubsystemFacadeFactory.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigSubsystemFacadeFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -19,19 +19,21 @@ import org.opendaylight.yangtools.yang.model.api.Module; public class ConfigSubsystemFacadeFactory { - private ConfigRegistryClient cfgRegClient; - private ConfigRegistryJMXClient cfgRegClientNoNotifications; - private YangStoreService yangStoreService; + private final ConfigRegistryClient cfgRegClient; + private final ConfigRegistryJMXClient cfgRegClientNoNotifications; + private final YangStoreService yangStoreService; - public ConfigSubsystemFacadeFactory(final ConfigRegistryClient cfgRegClient, final ConfigRegistryJMXClient jmxClientNoNotifications, final YangStoreService yangStoreService) { + public ConfigSubsystemFacadeFactory(final ConfigRegistryClient cfgRegClient, + final ConfigRegistryJMXClient jmxClientNoNotifications, final YangStoreService yangStoreService) { this.cfgRegClient = cfgRegClient; this.cfgRegClientNoNotifications = jmxClientNoNotifications; this.yangStoreService = yangStoreService; } /** - * Create new instance of ConfigSubsystemFacade. Each instance works with a dedicated transaction provider, making - * the instances suitable for facade-per-client use. + * Create new instance of ConfigSubsystemFacade. Each instance works with a + * dedicated transaction provider, making the instances suitable for + * facade-per-client use. */ public ConfigSubsystemFacade createFacade(final String id) { return new ConfigSubsystemFacade(cfgRegClient, cfgRegClientNoNotifications, yangStoreService, id); @@ -47,9 +49,6 @@ public class ConfigSubsystemFacadeFactory { for (Module module : modules) { capabilities.add(new YangModuleCapability(module, yangStoreService.getModuleSource(module))); } - return capabilities; } - - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/Datastore.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/Datastore.java index 22c97c46dc..93df25ffc6 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/Datastore.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/Datastore.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -14,20 +14,15 @@ public enum Datastore { running, candidate; - /** - * @param source - * @param transactionProvider - * @return - */ public static DatastoreQueryStrategy getInstanceQueryStrategy(final Datastore source, final TransactionProvider transactionProvider) { switch (source) { - case running: - return new RunningDatastoreQueryStrategy(transactionProvider); - case candidate: - return new CandidateDatastoreQueryStrategy(transactionProvider); - default: - throw new UnsupportedOperationException("Unimplemented datastore query strategy for " + source); + case running: + return new RunningDatastoreQueryStrategy(transactionProvider); + case candidate: + return new CandidateDatastoreQueryStrategy(transactionProvider); + default: + throw new UnsupportedOperationException("Unimplemented datastore query strategy for " + source); } } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/DatastoreQueryStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/DatastoreQueryStrategy.java index 6102b587b6..5be09c6598 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/DatastoreQueryStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/DatastoreQueryStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -13,11 +13,5 @@ import javax.management.ObjectName; import org.opendaylight.controller.config.util.ConfigRegistryClient; public interface DatastoreQueryStrategy { - - /** - * @param configRegistryClient - * @return - */ Set queryInstances(ConfigRegistryClient configRegistryClient); - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/RpcFacade.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/RpcFacade.java index 37043eb9ab..aaa773ee51 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/RpcFacade.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/RpcFacade.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -39,8 +39,8 @@ import org.w3c.dom.Element; public class RpcFacade { public static final String CONTEXT_INSTANCE = "context-instance"; - private YangStoreService yangStoreService; - private ConfigRegistryClient configRegistryClient; + private final YangStoreService yangStoreService; + private final ConfigRegistryClient configRegistryClient; public RpcFacade(final YangStoreService yangStoreService, final ConfigRegistryClient configRegistryClient) { this.yangStoreService = yangStoreService; @@ -51,15 +51,17 @@ public class RpcFacade { final Map> map = new HashMap<>(); - for (final Map.Entry> namespaceToModuleEntry : yangStoreService.getModuleMXBeanEntryMap().entrySet()) { + for (final Map.Entry> namespaceToModuleEntry : yangStoreService + .getModuleMXBeanEntryMap().entrySet()) { - Map namespaceToModules = - map.computeIfAbsent(namespaceToModuleEntry.getKey(), k -> new HashMap<>()); + Map namespaceToModules = map.computeIfAbsent(namespaceToModuleEntry.getKey(), + k -> new HashMap<>()); - for (final Map.Entry moduleEntry : namespaceToModuleEntry.getValue().entrySet()) { + for (final Map.Entry moduleEntry : namespaceToModuleEntry.getValue() + .entrySet()) { ModuleRpcs rpcMapping = namespaceToModules.computeIfAbsent(moduleEntry.getKey(), - k -> new ModuleRpcs(yangStoreService.getEnumResolver())); + k -> new ModuleRpcs(yangStoreService.getEnumResolver())); final ModuleMXBeanEntry entry = moduleEntry.getValue(); @@ -75,7 +77,6 @@ public class RpcFacade { return new Rpcs(map); } - public OperationExecution fromXml(final XmlElement xml) throws DocumentedException { final String namespace; namespace = xml.getNamespace(); @@ -83,8 +84,8 @@ public class RpcFacade { final XmlElement contextInstanceElement = xml.getOnlyChildElement(CONTEXT_INSTANCE); final String operationName = xml.getName(); - final RuntimeRpcElementResolved id = RuntimeRpcElementResolved.fromXpath( - contextInstanceElement.getTextContent(), operationName, namespace); + final RuntimeRpcElementResolved id = RuntimeRpcElementResolved + .fromXpath(contextInstanceElement.getTextContent(), operationName, namespace); final Rpcs rpcs = mapRpcs(); @@ -97,12 +98,12 @@ public class RpcFacade { Map attributes = instanceRuntimeRpc.fromXml(xml); attributes = sortAttributes(attributes, xml); - return new OperationExecution(on, instanceRuntimeRpc.getName(), attributes, - instanceRuntimeRpc.getReturnType(), namespace); + return new OperationExecution(on, instanceRuntimeRpc.getName(), attributes, instanceRuntimeRpc.getReturnType(), + namespace); } - private Map sortAttributes( - final Map attributes, final XmlElement xml) { + private Map sortAttributes(final Map attributes, + final XmlElement xml) { final Map sorted = new LinkedHashMap<>(); for (XmlElement xmlElement : xml.getChildElements()) { @@ -127,33 +128,39 @@ public class RpcFacade { final Object[] params = new Object[execution.attributes.size()]; final String[] signature = new String[execution.attributes.size()]; - int i = 0; + int index = 0; for (final AttributeConfigElement attribute : execution.attributes.values()) { final Optional resolvedValueOpt = attribute.getResolvedValue(); - params[i] = resolvedValueOpt.isPresent() ? resolvedValueOpt.get() : attribute.getResolvedDefaultValue(); - signature[i] = resolvedValueOpt.isPresent() ? resolvedValueOpt.get().getClass().getName() : attribute - .getResolvedDefaultValue().getClass().getName(); - i++; + params[index] = resolvedValueOpt.isPresent() ? resolvedValueOpt.get() : attribute.getResolvedDefaultValue(); + signature[index] = resolvedValueOpt.isPresent() ? resolvedValueOpt.get().getClass().getName() + : attribute.getResolvedDefaultValue().getClass().getName(); + index++; } return configRegistryClient.invokeMethod(execution.on, execution.operationName, params, signature); } - public Element toXml(final Document doc, final Object result, final OperationExecution execution) throws DocumentedException { - AttributeMappingStrategy> mappingStrategy = new ObjectMapper().prepareStrategy(execution.getReturnType()); + public Element toXml(final Document doc, final Object result, final OperationExecution execution) + throws DocumentedException { + AttributeMappingStrategy> mappingStrategy = new ObjectMapper() + .prepareStrategy(execution.getReturnType()); Optional mappedAttributeOpt = mappingStrategy.mapAttribute(result); - Preconditions.checkState(mappedAttributeOpt.isPresent(), "Unable to map return value %s as %s", result, execution.getReturnType().getOpenType()); + Preconditions.checkState(mappedAttributeOpt.isPresent(), "Unable to map return value %s as %s", result, + execution.getReturnType().getOpenType()); - // FIXME: multiple return values defined as leaf-list and list in yang should not be wrapped in output xml element, + // FIXME: multiple return values defined as leaf-list and list in yang should + // not be wrapped in output xml element, // they need to be appended directly under rpc-reply element // // Either allow List of Elements to be returned from NetconfOperation or // pass reference to parent output xml element for netconf operations to // append result(s) on their own - Element tempParent = XmlUtil.createElement(doc, "output", Optional.of(XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0)); + Element tempParent = XmlUtil.createElement(doc, "output", + Optional.of(XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0)); new ObjectXmlWriter().prepareWritingStrategy(execution.getReturnType().getAttributeYangName(), - execution.getReturnType(), doc).writeElement(tempParent, execution.getNamespace(), mappedAttributeOpt.get()); + execution.getReturnType(), doc) + .writeElement(tempParent, execution.getNamespace(), mappedAttributeOpt.get()); XmlElement xmlElement = XmlElement.fromDomElement(tempParent); return xmlElement.getChildElements().size() > 1 ? tempParent : xmlElement.getOnlyChildElement().getDomElement(); @@ -168,7 +175,8 @@ public class RpcFacade { private final String namespace; public OperationExecution(final ObjectName on, final String name, - final Map attributes, final AttributeIfc returnType, final String namespace) { + final Map attributes, final AttributeIfc returnType, + final String namespace) { this.on = on; this.operationName = name; this.attributes = attributes; @@ -200,5 +208,4 @@ public class RpcFacade { return namespace; } } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/TestOption.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/TestOption.java index 312717ad90..b5b2960666 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/TestOption.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/TestOption.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -15,20 +15,19 @@ public enum TestOption { public static TestOption getFromXmlName(final String testOptionXmlName) { switch (testOptionXmlName) { - case "test-only": - return testOnly; - case "test-then-set": - return testThenSet; - case "set": - return set; - default: - throw new IllegalArgumentException("Unsupported test option " + testOptionXmlName + " supported: " - + Arrays.toString(TestOption.values())); + case "test-only": + return testOnly; + case "test-then-set": + return testThenSet; + case "set": + return set; + default: + throw new IllegalArgumentException("Unsupported test option " + testOptionXmlName + " supported: " + + Arrays.toString(TestOption.values())); } } public static TestOption getDefault() { return testThenSet; } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/exception/ConfigHandlingException.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/exception/ConfigHandlingException.java index 3874d70c37..2d8bcbb83b 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/exception/ConfigHandlingException.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/exception/ConfigHandlingException.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -15,12 +15,12 @@ public class ConfigHandlingException extends DocumentedException { private static final long serialVersionUID = 1L; public ConfigHandlingException(final String message, final ErrorType errorType, final ErrorTag errorTag, - final ErrorSeverity errorSeverity) { + final ErrorSeverity errorSeverity) { this(message, errorType, errorTag, errorSeverity, Collections.emptyMap()); } public ConfigHandlingException(final String message, final ErrorType errorType, final ErrorTag errorTag, - final ErrorSeverity errorSeverity, final Map errorInfo){ - super(message,errorType,errorTag,errorSeverity,errorInfo); + final ErrorSeverity errorSeverity, final Map errorInfo) { + super(message, errorType, errorTag, errorSeverity, errorInfo); } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/exception/OperationNotPermittedException.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/exception/OperationNotPermittedException.java index 4882b4a6fb..cedb833b12 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/exception/OperationNotPermittedException.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/exception/OperationNotPermittedException.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -15,12 +15,12 @@ public class OperationNotPermittedException extends DocumentedException { private static final long serialVersionUID = 1L; public OperationNotPermittedException(final String message, final ErrorType errorType, final ErrorTag errorTag, - final ErrorSeverity errorSeverity) { - this(message, errorType, errorTag, errorSeverity, Collections. emptyMap()); + final ErrorSeverity errorSeverity) { + this(message, errorType, errorTag, errorSeverity, Collections.emptyMap()); } public OperationNotPermittedException(final String message, final ErrorType errorType, final ErrorTag errorTag, - final ErrorSeverity errorSeverity, final Map errorInfo){ - super(message,errorType,errorTag,errorSeverity,errorInfo); + final ErrorSeverity errorSeverity, final Map errorInfo) { + super(message, errorType, errorTag, errorSeverity, errorInfo); } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/AttributeIfcSwitchStatement.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/AttributeIfcSwitchStatement.java index 9c2aaeda49..f5131c8752 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/AttributeIfcSwitchStatement.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/AttributeIfcSwitchStatement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -32,13 +32,13 @@ public abstract class AttributeIfcSwitchStatement { if (attributeIfc instanceof JavaAttribute) { try { - if(((JavaAttribute)attributeIfc).getTypeDefinition() instanceof BinaryTypeDefinition) { + if (((JavaAttribute) attributeIfc).getTypeDefinition() instanceof BinaryTypeDefinition) { return caseJavaBinaryAttribute(openType); - } else if(((JavaAttribute)attributeIfc).isUnion()) { + } else if (((JavaAttribute) attributeIfc).isUnion()) { return caseJavaUnionAttribute(openType); - } else if(((JavaAttribute)attributeIfc).isIdentityRef()) { + } else if (((JavaAttribute) attributeIfc).isIdentityRef()) { return caseJavaIdentityRefAttribute(openType); - } else if(((JavaAttribute)attributeIfc).isEnum()) { + } else if (((JavaAttribute) attributeIfc).isEnum()) { return caseJavaEnumAttribute(openType); } else { return caseJavaAttribute(openType); @@ -114,7 +114,7 @@ public abstract class AttributeIfcSwitchStatement { private static class UnknownOpenTypeException extends RuntimeException { private static final long serialVersionUID = 1L; - public UnknownOpenTypeException(final String message) { + UnknownOpenTypeException(final String message) { super(message); } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/AbstractAttributeReadingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/AbstractAttributeReadingStrategy.java index d0642944a6..4920cc563a 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/AbstractAttributeReadingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/AbstractAttributeReadingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -26,7 +26,7 @@ public abstract class AbstractAttributeReadingStrategy implements AttributeReadi @Override public AttributeConfigElement readElement(final List configNodes) throws DocumentedException { - if (configNodes.size() == 0){ + if (configNodes.isEmpty()) { return AttributeConfigElement.createNullValue(postprocessNullableDefault(nullableDefault)); } return readElementHook(configNodes); diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/ArrayAttributeReadingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/ArrayAttributeReadingStrategy.java index f2a67cce45..8887fbd088 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/ArrayAttributeReadingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/ArrayAttributeReadingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -26,17 +26,18 @@ public class ArrayAttributeReadingStrategy extends AbstractAttributeReadingStrat @Override AttributeConfigElement readElementHook(final List configNodes) throws DocumentedException { List innerList = Lists.newArrayList(); - EditStrategyType innerEditStrategy= null; + EditStrategyType innerEditStrategy = null; for (XmlElement configNode : configNodes) { - final AttributeConfigElement attributeConfigElement = innerStrategy.readElement(Lists.newArrayList(configNode)); - if(attributeConfigElement.getEditStrategy().isPresent()) { + final AttributeConfigElement attributeConfigElement = innerStrategy + .readElement(Lists.newArrayList(configNode)); + if (attributeConfigElement.getEditStrategy().isPresent()) { // TODO this sets the last operation for the entire array innerEditStrategy = attributeConfigElement.getEditStrategy().get(); } innerList.add(attributeConfigElement.getValue()); } - return innerEditStrategy == null ? AttributeConfigElement.create(getNullableDefault(), innerList) : - AttributeConfigElement.create(getNullableDefault(), innerList, innerEditStrategy); + return innerEditStrategy == null ? AttributeConfigElement.create(getNullableDefault(), innerList) + : AttributeConfigElement.create(getNullableDefault(), innerList, innerEditStrategy); } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/AttributeConfigElement.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/AttributeConfigElement.java index 850d0bea33..ac8380f90b 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/AttributeConfigElement.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/AttributeConfigElement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -27,7 +27,8 @@ public class AttributeConfigElement { private Object resolvedDefaultValue; private String jmxName; - public AttributeConfigElement(final Object defaultValue, final Object value, final EditStrategyType editStrategyType) { + public AttributeConfigElement(final Object defaultValue, final Object value, + final EditStrategyType editStrategyType) { this.defaultValue = defaultValue; this.value = value; this.editStrategy = Optional.fromNullable(editStrategyType); @@ -56,12 +57,13 @@ public class AttributeConfigElement { return new AttributeConfigElement(nullableDefault, value, null); } - public static AttributeConfigElement createNullValue(final Object nullableDefault) { - return new AttributeConfigElement(nullableDefault, null, null); + public static AttributeConfigElement create(final String nullableDefault, final Object value, + final EditStrategyType editStrategyType) { + return new AttributeConfigElement(nullableDefault, value, editStrategyType); } - public static AttributeConfigElement create(final String nullableDefault, final Object value, final EditStrategyType editStrategyType) { - return new AttributeConfigElement(nullableDefault, value, editStrategyType); + public static AttributeConfigElement createNullValue(final Object nullableDefault) { + return new AttributeConfigElement(nullableDefault, null, null); } public Object getValue() { @@ -84,5 +86,4 @@ public class AttributeConfigElement { public String toString() { return "AttributeConfigElement [defaultValue=" + defaultValue + ", value=" + value + "]"; } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/CompositeAttributeReadingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/CompositeAttributeReadingStrategy.java index 461ac339e9..f35281411a 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/CompositeAttributeReadingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/CompositeAttributeReadingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -41,14 +41,13 @@ public class CompositeAttributeReadingStrategy extends AbstractAttributeReadingS List recognisedChildren = Lists.newArrayList(); for (Entry innerAttrEntry : innerStrategies.entrySet()) { - List childItem = complexElement.getChildElementsWithSameNamespace( - innerAttrEntry.getKey()); + List childItem = complexElement.getChildElementsWithSameNamespace(innerAttrEntry.getKey()); recognisedChildren.addAll(childItem); AttributeConfigElement resolvedInner = innerAttrEntry.getValue().readElement(childItem); Object value = resolvedInner.getValue(); - if(value == null) { + if (value == null) { value = resolvedInner.getDefaultValue(); } @@ -60,8 +59,9 @@ public class CompositeAttributeReadingStrategy extends AbstractAttributeReadingS String perInstanceEditStrategy = complexElement.getAttribute(XmlMappingConstants.OPERATION_ATTR_KEY, XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); - return Strings.isNullOrEmpty(perInstanceEditStrategy) ? AttributeConfigElement.create(getNullableDefault(), innerMap) : - AttributeConfigElement.create(getNullableDefault(), innerMap, EditStrategyType.valueOf(perInstanceEditStrategy)); + return Strings.isNullOrEmpty(perInstanceEditStrategy) + ? AttributeConfigElement.create(getNullableDefault(), innerMap) + : AttributeConfigElement.create(getNullableDefault(), innerMap, + EditStrategyType.valueOf(perInstanceEditStrategy)); } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/ObjectNameAttributeReadingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/ObjectNameAttributeReadingStrategy.java index 12d68cefa6..cce74ad6c6 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/ObjectNameAttributeReadingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/ObjectNameAttributeReadingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -27,14 +27,15 @@ public class ObjectNameAttributeReadingStrategy extends AbstractAttributeReading AttributeConfigElement readElementHook(final List configNodes) throws DocumentedException { XmlElement firstChild = configNodes.get(0); - Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + firstChild - + " but was " + configNodes.size()); + Preconditions.checkState(configNodes.size() == 1, + "This element should be present only once " + firstChild + " but was " + configNodes.size()); Preconditions.checkNotNull(firstChild, "Element %s should be present", firstChild); return AttributeConfigElement.create(getNullableDefault(), resolve(firstChild)); } - private ObjectNameAttributeMappingStrategy.MappedDependency resolve(final XmlElement firstChild) throws DocumentedException{ + private ObjectNameAttributeMappingStrategy.MappedDependency resolve(final XmlElement firstChild) + throws DocumentedException { XmlElement typeElement = firstChild.getOnlyChildElementWithSameNamespace(XmlMappingConstants.TYPE_KEY); Map.Entry prefixNamespace = typeElement.findNamespaceOfTextContent(); @@ -47,11 +48,12 @@ public class ObjectNameAttributeReadingStrategy extends AbstractAttributeReading dependencyName); } - public static String checkPrefixAndExtractServiceName(final XmlElement typeElement, final Map.Entry prefixNamespace) throws DocumentedException { + public static String checkPrefixAndExtractServiceName(final XmlElement typeElement, + final Map.Entry prefixNamespace) throws DocumentedException { String serviceName = typeElement.getTextContent(); Preconditions.checkNotNull(prefixNamespace.getKey(), "Service %s value cannot be linked to namespace", XmlMappingConstants.TYPE_KEY); - if(prefixNamespace.getKey().isEmpty()) { + if (prefixNamespace.getKey().isEmpty()) { return serviceName; } else { String prefix = prefixNamespace.getKey() + PREFIX_SEPARATOR; @@ -62,5 +64,4 @@ public class ObjectNameAttributeReadingStrategy extends AbstractAttributeReading return serviceName; } } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/ObjectXmlReader.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/ObjectXmlReader.java index 2fe373475f..1878808f3f 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/ObjectXmlReader.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/ObjectXmlReader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -31,7 +31,8 @@ public class ObjectXmlReader extends AttributeIfcSwitchStatement> identityMap; - public Map prepareReading(final Map yangToAttrConfig, final Map> identityMap) { + public Map prepareReading(final Map yangToAttrConfig, + final Map> identityMap) { Map strategies = Maps.newHashMap(); this.identityMap = identityMap; @@ -65,13 +66,15 @@ public class ObjectXmlReader extends AttributeIfcSwitchStatement openType) { - SimpleAttributeReadingStrategy innerStrategy = new SimpleAttributeReadingStrategy(getLastAttribute().getNullableDefault()); + SimpleAttributeReadingStrategy innerStrategy = new SimpleAttributeReadingStrategy( + getLastAttribute().getNullableDefault()); return new ArrayAttributeReadingStrategy(getLastAttribute().getNullableDefault(), innerStrategy); } @Override public AttributeReadingStrategy caseJavaCompositeAttribute(final CompositeType openType) { - Preconditions.checkState(openType.keySet().size() == 1, "Unexpected number of elements for open type %s, should be 1", openType); + Preconditions.checkState(openType.keySet().size() == 1, + "Unexpected number of elements for open type %s, should be 1", openType); String mappingKey = openType.keySet().iterator().next(); return new SimpleCompositeAttributeReadingStrategy(getLastAttribute().getNullableDefault(), mappingKey); } @@ -80,9 +83,11 @@ public class ObjectXmlReader extends AttributeIfcSwitchStatement openType) { Preconditions.checkState(openType instanceof CompositeType); Set keys = ((CompositeType) openType).keySet(); - Preconditions.checkState(keys.size() == 1, "Unexpected number of elements for open type %s, should be 1", openType); + Preconditions.checkState(keys.size() == 1, "Unexpected number of elements for open type %s, should be 1", + openType); String mappingKey = keys.iterator().next(); - return new SimpleIdentityRefAttributeReadingStrategy(getLastAttribute().getNullableDefault(), mappingKey, identityMap); + return new SimpleIdentityRefAttributeReadingStrategy(getLastAttribute().getNullableDefault(), mappingKey, + identityMap); } @Override @@ -94,7 +99,7 @@ public class ObjectXmlReader extends AttributeIfcSwitchStatement inner = ((TOAttribute)lastAttribute).getYangPropertiesToTypesMap(); + Map inner = ((TOAttribute) lastAttribute).getYangPropertiesToTypesMap(); Map innerStrategies = Maps.newHashMap(); @@ -103,7 +108,6 @@ public class ObjectXmlReader extends AttributeIfcSwitchStatement openType) { AttributeIfc lastAttribute = getLastAttribute(); Preconditions.checkState(lastAttribute instanceof ListAttribute); - AttributeReadingStrategy innerStrategy = prepareReadingStrategy(key, ((ListAttribute) lastAttribute).getInnerAttribute()); + AttributeReadingStrategy innerStrategy = prepareReadingStrategy(key, + ((ListAttribute) lastAttribute).getInnerAttribute()); return new ArrayAttributeReadingStrategy(lastAttribute.getNullableDefault(), innerStrategy); } @@ -122,5 +127,4 @@ public class ObjectXmlReader extends AttributeIfcSwitchStatement> identityMap; - public SimpleIdentityRefAttributeReadingStrategy(final String nullableDefault, final String key, final Map> identityMap) { + public SimpleIdentityRefAttributeReadingStrategy(final String nullableDefault, final String key, + final Map> identityMap) { super(nullableDefault); this.key = key; this.identityMap = identityMap; @@ -38,22 +38,25 @@ public class SimpleIdentityRefAttributeReadingStrategy extends SimpleAttributeRe final String namespace; final String localName; - if(namespaceOfTextContent.getKey().isEmpty()) { + if (namespaceOfTextContent.getKey().isEmpty()) { localName = content; namespace = xmlElement.getNamespace(); } else { String prefix = namespaceOfTextContent.getKey() + ":"; - Preconditions.checkArgument(content.startsWith(prefix), "Identity ref should be prefixed with \"%s\"", prefix); + Preconditions.checkArgument(content.startsWith(prefix), "Identity ref should be prefixed with \"%s\"", + prefix); localName = content.substring(prefix.length()); namespace = namespaceOfTextContent.getValue(); } Date revision = null; Map revisions = identityMap.get(namespace); - if(revisions.keySet().size() > 1) { + if (revisions.keySet().size() > 1) { for (Map.Entry revisionToIdentityEntry : revisions.entrySet()) { - if(revisionToIdentityEntry.getValue().containsIdName(localName)) { - Preconditions.checkState(revision == null, "Duplicate identity %s, in namespace %s, with revisions: %s, %s detected. Cannot map attribute", + if (revisionToIdentityEntry.getValue().containsIdName(localName)) { + Preconditions.checkState(revision == null, + "Duplicate identity %s, in namespace %s, " + + "with revisions: %s, %s detected. Cannot map attribute", localName, namespace, revision, revisionToIdentityEntry.getKey()); revision = revisionToIdentityEntry.getKey(); } @@ -66,7 +69,7 @@ public class SimpleIdentityRefAttributeReadingStrategy extends SimpleAttributeRe @Override protected Object postprocessParsedValue(final String textContent) { - HashMap map = Maps.newHashMap(); + HashMap map = Maps.newHashMap(); map.put(key, textContent); return map; } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/ArrayAttributeMappingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/ArrayAttributeMappingStrategy.java index 0c593ebf3d..9aa5a6a914 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/ArrayAttributeMappingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/ArrayAttributeMappingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -28,7 +28,7 @@ public class ArrayAttributeMappingStrategy extends AbstractAttributeMappingStrat @Override public Optional> mapAttribute(final Object value) { - if (value == null){ + if (value == null) { return Optional.absent(); } @@ -40,12 +40,10 @@ public class ArrayAttributeMappingStrategy extends AbstractAttributeMappingStrat Object innerValue = Array.get(value, i); Optional mapAttribute = innerElementStrategy.mapAttribute(innerValue); - if (mapAttribute.isPresent()){ + if (mapAttribute.isPresent()) { retVal.add(mapAttribute.get()); } } - return Optional.of(retVal); } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/AttributeMappingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/AttributeMappingStrategy.java index b082ddc2f2..33eb64d395 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/AttributeMappingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/AttributeMappingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -15,6 +15,5 @@ public interface AttributeMappingStrategy> { O getOpenType(); - Optional mapAttribute(Object o); - + Optional mapAttribute(Object object); } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/CompositeAttributeMappingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/CompositeAttributeMappingStrategy.java index 7c1357005b..d5c3848e8c 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/CompositeAttributeMappingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/CompositeAttributeMappingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -18,8 +18,8 @@ import javax.management.openmbean.CompositeType; import javax.management.openmbean.OpenType; import org.opendaylight.controller.config.facade.xml.util.Util; -public class CompositeAttributeMappingStrategy extends - AbstractAttributeMappingStrategy, CompositeType> { +public class CompositeAttributeMappingStrategy + extends AbstractAttributeMappingStrategy, CompositeType> { private final Map>> innerStrategies; private final Map jmxToJavaNameMapping; @@ -34,7 +34,7 @@ public class CompositeAttributeMappingStrategy extends @Override public Optional> mapAttribute(final Object value) { - if (value == null){ + if (value == null) { return Optional.absent(); } @@ -54,7 +54,7 @@ public class CompositeAttributeMappingStrategy extends for (String jmxName : jmxToJavaNameMapping.keySet()) { Optional mapped = mapInnerAttribute(compositeData, jmxName, expectedType.getDescription(jmxName)); - if(mapped.isPresent()){ + if (mapped.isPresent()) { retVal.put(jmxToJavaNameMapping.get(jmxName), mapped.get()); } } @@ -62,12 +62,11 @@ public class CompositeAttributeMappingStrategy extends return Optional.of(retVal); } - protected Optional mapInnerAttribute(final CompositeDataSupport compositeData, final String jmxName, final String description) { + protected Optional mapInnerAttribute(final CompositeDataSupport compositeData, final String jmxName, + final String description) { Object innerValue = compositeData.get(jmxName); - AttributeMappingStrategy> attributeMappingStrategy = innerStrategies - .get(jmxName); + AttributeMappingStrategy> attributeMappingStrategy = innerStrategies.get(jmxName); return attributeMappingStrategy.mapAttribute(innerValue); } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/EnumAttributeMappingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/EnumAttributeMappingStrategy.java index 6ff56d0452..c6b20c826f 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/EnumAttributeMappingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/EnumAttributeMappingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -23,12 +23,11 @@ public class EnumAttributeMappingStrategy extends AbstractAttributeMappingStrate @Override public Optional mapAttribute(final Object value) { - if (value == null){ + if (value == null) { return Optional.absent(); } String expectedClass = getOpenType().getTypeName(); return Optional.of(enumResolver.toYang(expectedClass, value.toString())); } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/ObjectMapper.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/ObjectMapper.java index 9e2c69b9f3..0dc03bf402 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/ObjectMapper.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/ObjectMapper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -36,25 +36,25 @@ public class ObjectMapper extends AttributeIfcSwitchStatement attrEntry : configDefinition.entrySet()) { strategies.put(attrEntry.getKey(), prepareStrategy(attrEntry.getValue())); } - return strategies; } public AttributeMappingStrategy> prepareStrategy(final AttributeIfc attributeIfc) { - if(attributeIfc instanceof DependencyAttribute) { - namespaceOfDepAttr = ((DependencyAttribute)attributeIfc).getDependency().getSie().getQName().getNamespace().toString(); + if (attributeIfc instanceof DependencyAttribute) { + namespaceOfDepAttr = ((DependencyAttribute) attributeIfc).getDependency().getSie().getQName().getNamespace() + .toString(); } else if (attributeIfc instanceof ListDependenciesAttribute) { - namespaceOfDepAttr = ((ListDependenciesAttribute)attributeIfc).getDependency().getSie().getQName().getNamespace().toString(); + namespaceOfDepAttr = ((ListDependenciesAttribute) attributeIfc).getDependency().getSie().getQName() + .getNamespace().toString(); } - return switchAttribute(attributeIfc); } private Map createJmxToYangMapping(final TOAttribute attributeIfc) { Map retVal = Maps.newHashMap(); for (Entry entry : attributeIfc.getJmxPropertiesToTypesMap().entrySet()) { - retVal.put(entry.getKey(), (entry.getValue()).getAttributeYangName()); + retVal.put(entry.getKey(), entry.getValue().getAttributeYangName()); } return retVal; } @@ -66,7 +66,7 @@ public class ObjectMapper extends AttributeIfcSwitchStatement> caseJavaEnumAttribute(final OpenType openType) { - return new EnumAttributeMappingStrategy(((CompositeType) openType), enumResolver); + return new EnumAttributeMappingStrategy((CompositeType) openType, enumResolver); } @Override @@ -78,7 +78,8 @@ public class ObjectMapper extends AttributeIfcSwitchStatement> caseJavaCompositeAttribute(final CompositeType openType) { + protected AttributeMappingStrategy> caseJavaCompositeAttribute( + final CompositeType openType) { Map>> innerStrategies = Maps.newHashMap(); Map attributeMapping = Maps.newHashMap(); @@ -88,7 +89,6 @@ public class ObjectMapper extends AttributeIfcSwitchStatement> caseDependencyAttribute( - final SimpleType openType) { + protected AttributeMappingStrategy> caseDependencyAttribute(final SimpleType openType) { return new ObjectNameAttributeMappingStrategy(openType, namespaceOfDepAttr); } @@ -123,12 +121,12 @@ public class ObjectMapper extends AttributeIfcSwitchStatement innerAttrEntry : ((TOAttribute)getLastAttribute()).getJmxPropertiesToTypesMap().entrySet()) { + for (Entry innerAttrEntry : ((TOAttribute) getLastAttribute()) + .getJmxPropertiesToTypesMap().entrySet()) { innerStrategies.put(innerAttrEntry.getKey(), prepareStrategy(innerAttrEntry.getValue())); } - return new CompositeAttributeMappingStrategy(openType, innerStrategies, - createJmxToYangMapping(lastTO)); + return new CompositeAttributeMappingStrategy(openType, innerStrategies, createJmxToYangMapping(lastTO)); } @Override @@ -139,9 +137,9 @@ public class ObjectMapper extends AttributeIfcSwitchStatement> caseListDependeciesAttribute(final ArrayType openType) { + protected AttributeMappingStrategy> caseListDependeciesAttribute( + final ArrayType openType) { Preconditions.checkState(getLastAttribute() instanceof ListDependenciesAttribute); return new ArrayAttributeMappingStrategy(openType, caseDependencyAttribute(SimpleType.OBJECTNAME)); } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/ObjectNameAttributeMappingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/ObjectNameAttributeMappingStrategy.java index b7e6932b6e..4cad4609da 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/ObjectNameAttributeMappingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/ObjectNameAttributeMappingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -16,8 +16,8 @@ import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; import org.opendaylight.controller.config.facade.xml.util.Util; import org.opendaylight.yangtools.yang.common.QName; -public class ObjectNameAttributeMappingStrategy extends - AbstractAttributeMappingStrategy> { +public class ObjectNameAttributeMappingStrategy + extends AbstractAttributeMappingStrategy> { private final String namespace; @@ -28,27 +28,30 @@ public class ObjectNameAttributeMappingStrategy extends @Override public Optional mapAttribute(final Object value) { - if (value == null){ + if (value == null) { return Optional.absent(); } String expectedClass = getOpenType().getClassName(); String realClass = value.getClass().getName(); - Preconditions.checkArgument(realClass.equals(expectedClass), "Type mismatch, expected " + expectedClass - + " but was " + realClass); + Preconditions.checkArgument(realClass.equals(expectedClass), + "Type mismatch, expected " + expectedClass + " but was " + realClass); Util.checkType(value, ObjectName.class); ObjectName on = (ObjectName) value; String refName = ObjectNameUtil.getReferenceName(on); - //we want to use the exact service name that was configured in xml so services that are referencing it can be resolved + // we want to use the exact service name that was configured in xml so services + // that are referencing it can be resolved return Optional.of(new MappedDependency(namespace, QName.create(ObjectNameUtil.getServiceQName(on)).getLocalName(), refName)); } public static class MappedDependency { - private final String namespace, serviceName, refName; + private final String namespace; + private final String serviceName; + private final String refName; public MappedDependency(final String namespace, final String serviceName, final String refName) { this.serviceName = serviceName; @@ -78,5 +81,4 @@ public class ObjectNameAttributeMappingStrategy extends return sb.toString(); } } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/SimpleAttributeMappingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/SimpleAttributeMappingStrategy.java index aacdd93b51..a79e96a23c 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/SimpleAttributeMappingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/SimpleAttributeMappingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -24,25 +24,26 @@ public class SimpleAttributeMappingStrategy extends AbstractAttributeMappingStra @Override public Optional mapAttribute(final Object value) { - if (value == null){ + if (value == null) { return Optional.absent(); } String expectedClass = getOpenType().getClassName(); String realClass = value.getClass().getName(); - Preconditions.checkArgument(realClass.equals(expectedClass), "Type mismatch, expected " + expectedClass - + " but was " + realClass); + Preconditions.checkArgument(realClass.equals(expectedClass), + "Type mismatch, expected " + expectedClass + " but was " + realClass); - WriterPlugin prefferedPlugin = writerPlugins.get(value.getClass().getCanonicalName()); - prefferedPlugin = prefferedPlugin == null ? writerPlugins.get(DEFAULT_WRITER_PLUGIN) : prefferedPlugin; + WriterPlugin prefferedPlugin = WRITER_PLUGINS.get(value.getClass().getCanonicalName()); + prefferedPlugin = prefferedPlugin == null ? WRITER_PLUGINS.get(DEFAULT_WRITER_PLUGIN) : prefferedPlugin; return Optional.of(prefferedPlugin.writeObject(value)); } private static final String DEFAULT_WRITER_PLUGIN = "default"; - private static final Map writerPlugins = Maps.newHashMap(); + private static final Map WRITER_PLUGINS = Maps.newHashMap(); + static { - writerPlugins.put(DEFAULT_WRITER_PLUGIN, new DefaultWriterPlugin()); - writerPlugins.put(Date.class.getCanonicalName(), new DatePlugin()); + WRITER_PLUGINS.put(DEFAULT_WRITER_PLUGIN, new DefaultWriterPlugin()); + WRITER_PLUGINS.put(Date.class.getCanonicalName(), new DatePlugin()); } /** diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/UnionCompositeAttributeMappingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/UnionCompositeAttributeMappingStrategy.java index d15777cb8c..3053964e02 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/UnionCompositeAttributeMappingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/UnionCompositeAttributeMappingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -15,17 +15,18 @@ import javax.management.openmbean.CompositeType; import javax.management.openmbean.OpenType; import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute; -public class UnionCompositeAttributeMappingStrategy extends - CompositeAttributeMappingStrategy { +public class UnionCompositeAttributeMappingStrategy extends CompositeAttributeMappingStrategy { - - public UnionCompositeAttributeMappingStrategy(final CompositeType compositeType, final Map>> innerStrategies, final Map jmxToJavaNameMapping) { + public UnionCompositeAttributeMappingStrategy(final CompositeType compositeType, + final Map>> innerStrategies, + final Map jmxToJavaNameMapping) { super(compositeType, innerStrategies, jmxToJavaNameMapping); } @Override - protected Optional mapInnerAttribute(final CompositeDataSupport compositeData, final String jmxName, final String description) { - if(!description.equals(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION)){ + protected Optional mapInnerAttribute(final CompositeDataSupport compositeData, final String jmxName, + final String description) { + if (!description.equals(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION)) { return Optional.absent(); } return super.mapInnerAttribute(compositeData, jmxName, description); diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/AbstractAttributeResolvingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/AbstractAttributeResolvingStrategy.java index 0443013a3f..4f9cef4179 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/AbstractAttributeResolvingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/AbstractAttributeResolvingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -10,7 +10,8 @@ package org.opendaylight.controller.config.facade.xml.mapping.attributes.resolvi import javax.management.openmbean.OpenType; -abstract class AbstractAttributeResolvingStrategy> implements AttributeResolvingStrategy { +public abstract class AbstractAttributeResolvingStrategy> + implements AttributeResolvingStrategy { private O openType; public AbstractAttributeResolvingStrategy(final O openType) { @@ -23,7 +24,8 @@ abstract class AbstractAttributeResolvingStrategy> impl } /** - * Composite types might change during resolution. Use this setter to update open type + * Composite types might change during resolution. Use this setter to update + * open type */ public void setOpenType(final O openType) { this.openType = openType; diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/ArrayAttributeResolvingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/ArrayAttributeResolvingStrategy.java index 5daf5a42a9..7f085978a0 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/ArrayAttributeResolvingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/ArrayAttributeResolvingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -21,7 +21,7 @@ import org.opendaylight.controller.config.util.xml.DocumentedException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -final class ArrayAttributeResolvingStrategy extends AbstractAttributeResolvingStrategy> { +public final class ArrayAttributeResolvingStrategy extends AbstractAttributeResolvingStrategy> { private final AttributeResolvingStrategy> innerTypeResolvingStrategy; @@ -50,8 +50,8 @@ final class ArrayAttributeResolvingStrategy extends AbstractAttributeResolvingSt try { innerTypeClass = Class.forName(getOpenType().getElementOpenType().getClassName()); } catch (final ClassNotFoundException e) { - throw new IllegalStateException("Unable to locate class for " - + getOpenType().getElementOpenType().getClassName(), e); + throw new IllegalStateException( + "Unable to locate class for " + getOpenType().getElementOpenType().getClassName(), e); } } @@ -64,21 +64,21 @@ final class ArrayAttributeResolvingStrategy extends AbstractAttributeResolvingSt parsedArray = Array.newInstance(innerTypeClass, valueList.size()); } - int i = 0; + int index = 0; for (Object innerValue : valueList) { - Optional parsedElement = innerTypeResolvingStrategy.parseAttribute(attrName + "_" + i, innerValue); - if (!parsedElement.isPresent()){ + Optional parsedElement = innerTypeResolvingStrategy.parseAttribute(attrName + "_" + index, innerValue); + if (!parsedElement.isPresent()) { continue; } - Array.set(parsedArray, i, parsedElement.get()); - i++; + Array.set(parsedArray, index, parsedElement.get()); + index++; } // Rebuild open type. Underlying composite types might have changed if (innerTypeResolvingStrategy.getOpenType() instanceof CompositeType) { try { - final ArrayType openType = - new ArrayType<>(getOpenType().getDimension(), innerTypeResolvingStrategy.getOpenType()); + final ArrayType openType = new ArrayType<>(getOpenType().getDimension(), + innerTypeResolvingStrategy.getOpenType()); setOpenType(openType); } catch (final OpenDataException e) { throw new IllegalStateException("An error occurred during restoration of array type " + this @@ -106,7 +106,7 @@ final class ArrayAttributeResolvingStrategy extends AbstractAttributeResolvingSt private static Class getPrimitiveType(final Class innerTypeClass) { try { return (Class) innerTypeClass.getField("TYPE").get(null); - } catch (final Exception e) { + } catch (final IllegalAccessException | IllegalArgumentException | NoSuchFieldException e) { throw new IllegalStateException("Unable to determine primitive type to " + innerTypeClass); } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/CompositeAttributeResolvingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/CompositeAttributeResolvingStrategy.java index 920b5dcd88..f08233c8ee 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/CompositeAttributeResolvingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/CompositeAttributeResolvingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -22,14 +22,15 @@ import org.opendaylight.controller.config.util.xml.DocumentedException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -class CompositeAttributeResolvingStrategy extends - AbstractAttributeResolvingStrategy { +class CompositeAttributeResolvingStrategy + extends AbstractAttributeResolvingStrategy { private final Map>> innerTypes; private final Map yangToJavaAttrMapping; private static final Logger LOG = LoggerFactory.getLogger(CompositeAttributeResolvingStrategy.class); - CompositeAttributeResolvingStrategy(final Map>> innerTypes, + CompositeAttributeResolvingStrategy( + final Map>> innerTypes, final CompositeType openType, final Map yangToJavaAttrMapping) { super(openType); this.innerTypes = innerTypes; @@ -42,7 +43,8 @@ class CompositeAttributeResolvingStrategy extends } @Override - public Optional parseAttribute(final String attrName, final Object value) throws DocumentedException { + public Optional parseAttribute(final String attrName, final Object value) + throws DocumentedException { if (value == null) { return Optional.absent(); @@ -58,7 +60,7 @@ class CompositeAttributeResolvingStrategy extends final String[] names = new String[getOpenType().keySet().size()]; final String[] descriptions = new String[getOpenType().keySet().size()]; OpenType[] itemTypes = new OpenType[names.length]; - int i = 0; + int index = 0; for (Object innerAttrName : innerTypes.keySet()) { Preconditions.checkState(innerAttrName instanceof String, "Attribute name must be string"); @@ -71,8 +73,9 @@ class CompositeAttributeResolvingStrategy extends Optional parsedInnerValue = attributeResolvingStrategy.parseAttribute(innerAttrNameStr, valueToParse); - if(attributeResolvingStrategy instanceof EnumAttributeResolvingStrategy) { - // Open type for enum contain the class name necessary for its resolution, however in a DTO + if (attributeResolvingStrategy instanceof EnumAttributeResolvingStrategy) { + // Open type for enum contain the class name necessary for its resolution, + // however in a DTO // the open type need to be just SimpleType.STRING so that JMX is happy // After the enum attribute is resolved, change its open type back to STRING openTypes.put(innerAttrNameStr, SimpleType.STRING); @@ -83,17 +86,19 @@ class CompositeAttributeResolvingStrategy extends items.put(yangToJavaAttrMapping.get(innerAttrNameStr), parsedInnerValue.isPresent() ? parsedInnerValue.get() : null); - // fill names + item types in order to reconstruct the open type for current attribute - names[i] = yangToJavaAttrMapping.get(innerAttrNameStr); - descriptions[i] = getOpenType().getDescription(names[i]); - itemTypes[i] = openTypes.get(innerAttrNameStr); - i++; + // fill names + item types in order to reconstruct the open type for current + // attribute + names[index] = yangToJavaAttrMapping.get(innerAttrNameStr); + descriptions[index] = getOpenType().getDescription(names[index]); + itemTypes[index] = openTypes.get(innerAttrNameStr); + index++; } CompositeDataSupport parsedValue; try { LOG.trace("Attribute {} with open type {}. Reconstructing open type.", attrName, getOpenType()); - setOpenType(new CompositeType(getOpenType().getTypeName(), getOpenType().getDescription(), names, descriptions, itemTypes)); + setOpenType(new CompositeType(getOpenType().getTypeName(), getOpenType().getDescription(), names, + descriptions, itemTypes)); LOG.debug("Attribute {}. Open type reconstructed to {}", attrName, getOpenType(), getOpenType()); parsedValue = new CompositeDataSupport(getOpenType(), items); } catch (final OpenDataException e) { @@ -106,10 +111,7 @@ class CompositeAttributeResolvingStrategy extends return Optional.of(parsedValue); } - protected Map preprocessValueMap(final Map valueMap) { return valueMap; } - - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/EnumAttributeResolvingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/EnumAttributeResolvingStrategy.java index 7a66e421cf..4d426b59cc 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/EnumAttributeResolvingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/EnumAttributeResolvingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -38,18 +38,18 @@ final class EnumAttributeResolvingStrategy extends AbstractAttributeResolvingStr if (value == null) { return Optional.absent(); } - Util.checkType(value, Map.class); Map valueMap = (Map) value; - Preconditions.checkArgument(valueMap.size() == 1, "Unexpected value size " + value + " should be just 1 foe enum"); + Preconditions.checkArgument(valueMap.size() == 1, + "Unexpected value size " + value + " should be just 1 foe enum"); final Object innerValue = valueMap.values().iterator().next(); Util.checkType(innerValue, String.class); final String className = getOpenType().getTypeName(); - final Object parsedValue = enumResolver.fromYang(className, ((String) innerValue)); + final Object parsedValue = enumResolver.fromYang(className, (String) innerValue); - LOG.debug("Attribute {} : {} parsed to enum type {} with value {}", attrName, innerValue, getOpenType(), parsedValue); + LOG.debug("Attribute {} : {} parsed to enum type {} with value {}", attrName, innerValue, getOpenType(), + parsedValue); return Optional.of(parsedValue); } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/ObjectNameAttributeResolvingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/ObjectNameAttributeResolvingStrategy.java index 086c18198f..1318bb9d87 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/ObjectNameAttributeResolvingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/ObjectNameAttributeResolvingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -17,7 +17,8 @@ import org.opendaylight.controller.config.facade.xml.util.Util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ObjectNameAttributeResolvingStrategy extends AbstractAttributeResolvingStrategy> { +public class ObjectNameAttributeResolvingStrategy + extends AbstractAttributeResolvingStrategy> { private final ServiceRegistryWrapper serviceTracker; private static final Logger LOG = LoggerFactory.getLogger(ObjectNameAttributeResolvingStrategy.class); @@ -35,7 +36,8 @@ public class ObjectNameAttributeResolvingStrategy extends AbstractAttributeResol Util.checkType(value, ObjectNameAttributeMappingStrategy.MappedDependency.class); - ObjectNameAttributeMappingStrategy.MappedDependency mappedDep = (ObjectNameAttributeMappingStrategy.MappedDependency) value; + ObjectNameAttributeMappingStrategy.MappedDependency mappedDep = + (ObjectNameAttributeMappingStrategy.MappedDependency) value; String serviceName = mappedDep.getServiceName(); String refName = mappedDep.getRefName(); String namespace = mappedDep.getNamespace(); @@ -46,5 +48,4 @@ public class ObjectNameAttributeResolvingStrategy extends AbstractAttributeResol LOG.debug("Attribute {} : {} parsed to type {}", attrName, value, getOpenType()); return Optional.of(on); } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/ObjectResolver.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/ObjectResolver.java index c1eeef5cbf..f1050b9df3 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/ObjectResolver.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/ObjectResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -40,8 +40,7 @@ public class ObjectResolver extends AttributeIfcSwitchStatement>> strategies = Maps.newHashMap(); for (Entry attrEntry : configDefinition.entrySet()) { - strategies.put(attrEntry.getKey(), - prepareStrategy(attrEntry.getValue())); + strategies.put(attrEntry.getKey(), prepareStrategy(attrEntry.getValue())); } return strategies; @@ -54,7 +53,7 @@ public class ObjectResolver extends AttributeIfcSwitchStatement createYangToJmxMapping(final TOAttribute attributeIfc) { Map retVal = Maps.newHashMap(); for (Entry entry : attributeIfc.getYangPropertiesToTypesMap().entrySet()) { - retVal.put(entry.getKey(), (entry.getValue()).getLowerCaseCammelCase()); + retVal.put(entry.getKey(), entry.getValue().getLowerCaseCammelCase()); } return retVal; } @@ -65,12 +64,13 @@ public class ObjectResolver extends AttributeIfcSwitchStatement> caseJavaSimpleAttribute(final SimpleType openType) { + protected AttributeResolvingStrategy> caseJavaSimpleAttribute( + final SimpleType openType) { return new SimpleAttributeResolvingStrategy(openType); } @Override - protected AttributeResolvingStrategy> caseJavaArrayAttribute(final ArrayType openType) { + protected AttributeResolvingStrategy> caseJavaArrayAttribute(final ArrayType openType) { SimpleType innerType = (SimpleType) openType.getElementOpenType(); AttributeResolvingStrategy> strat = new SimpleAttributeResolvingStrategy(innerType); @@ -78,7 +78,8 @@ public class ObjectResolver extends AttributeIfcSwitchStatement> caseJavaCompositeAttribute(final CompositeType openType) { + protected AttributeResolvingStrategy> caseJavaCompositeAttribute( + final CompositeType openType) { Map>> innerMap = Maps.newHashMap(); Map yangToJmxMapping = Maps.newHashMap(); @@ -86,7 +87,9 @@ public class ObjectResolver extends AttributeIfcSwitchStatement>> innerMap, final Map yangToJmxMapping) { + private void fillMappingForComposite(final CompositeType openType, + final Map>> innerMap, + final Map yangToJmxMapping) { for (String innerAttributeKey : openType.keySet()) { innerMap.put(innerAttributeKey, caseJavaAttribute(openType.getType(innerAttributeKey))); yangToJmxMapping.put(innerAttributeKey, innerAttributeKey); @@ -122,8 +125,7 @@ public class ObjectResolver extends AttributeIfcSwitchStatement> caseListDependeciesAttribute(final ArrayType openType) { + protected AttributeResolvingStrategy> caseListDependeciesAttribute( + final ArrayType openType) { Preconditions.checkState(getLastAttribute() instanceof ListDependenciesAttribute); return new ArrayAttributeResolvingStrategy(caseDependencyAttribute(SimpleType.OBJECTNAME), openType); } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/SimpleAttributeResolvingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/SimpleAttributeResolvingStrategy.java index f639ed9cbe..9a42e93d2e 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/SimpleAttributeResolvingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/SimpleAttributeResolvingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -51,8 +51,8 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS Util.checkType(value, String.class); - Resolver prefferedPlugin = resolverPlugins.get(cls.getCanonicalName()); - prefferedPlugin = prefferedPlugin == null ? resolverPlugins.get(DEFAULT_RESOLVERS) : prefferedPlugin; + Resolver prefferedPlugin = RESOLVER_PLUGINS.get(cls.getCanonicalName()); + prefferedPlugin = prefferedPlugin == null ? RESOLVER_PLUGINS.get(DEFAULT_RESOLVERS) : prefferedPlugin; Object parsedValue = prefferedPlugin.resolveObject(cls, attrName, (String) value); LOG.debug("Attribute {} : {} parsed to type {} with value {}", attrName, value, getOpenType(), parsedValue); @@ -60,15 +60,15 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS } private static final String DEFAULT_RESOLVERS = "default"; - private static final Map resolverPlugins = Maps.newHashMap(); + private static final Map RESOLVER_PLUGINS = Maps.newHashMap(); static { - resolverPlugins.put(DEFAULT_RESOLVERS, new DefaultResolver()); - resolverPlugins.put(String.class.getCanonicalName(), new StringResolver()); - resolverPlugins.put(Date.class.getCanonicalName(), new DateResolver()); - resolverPlugins.put(Character.class.getCanonicalName(), new CharResolver()); - resolverPlugins.put(BigInteger.class.getCanonicalName(), new BigIntegerResolver()); - resolverPlugins.put(BigDecimal.class.getCanonicalName(), new BigDecimalResolver()); + RESOLVER_PLUGINS.put(DEFAULT_RESOLVERS, new DefaultResolver()); + RESOLVER_PLUGINS.put(String.class.getCanonicalName(), new StringResolver()); + RESOLVER_PLUGINS.put(Date.class.getCanonicalName(), new DateResolver()); + RESOLVER_PLUGINS.put(Character.class.getCanonicalName(), new CharResolver()); + RESOLVER_PLUGINS.put(BigInteger.class.getCanonicalName(), new BigIntegerResolver()); + RESOLVER_PLUGINS.put(BigDecimal.class.getCanonicalName(), new BigDecimalResolver()); } interface Resolver { @@ -78,13 +78,13 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS static class DefaultResolver implements Resolver { @Override - public Object resolveObject(final Class type, final String attrName, final String value) throws DocumentedException { + public Object resolveObject(final Class type, final String attrName, final String value) + throws DocumentedException { try { return parseObject(type, value); - } catch (final Exception e) { + } catch (final DocumentedException e) { throw new DocumentedException("Unable to resolve attribute " + attrName + " from " + value, - DocumentedException.ErrorType.APPLICATION, - DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, DocumentedException.ErrorSeverity.ERROR); } } @@ -95,11 +95,9 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS method = type.getMethod("valueOf", String.class); return method.invoke(null, value); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { - LOG.trace("Error parsing object ",e); - throw new DocumentedException("Error parsing object.", - DocumentedException.ErrorType.APPLICATION, - DocumentedException.ErrorTag.OPERATION_FAILED, - DocumentedException.ErrorSeverity.ERROR); + LOG.trace("Error parsing object ", e); + throw new DocumentedException("Error parsing object.", DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, DocumentedException.ErrorSeverity.ERROR); } } } @@ -131,7 +129,7 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS static class CharResolver extends DefaultResolver { @Override - protected Object parseObject(final Class type, final String value) { + protected Object parseObject(final Class type, final String value) { return value.charAt(0); } } @@ -142,13 +140,11 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS try { return Util.readDate(value); } catch (final ParseException e) { - LOG.trace("Unable parse value {} due to ",value, e); - throw new DocumentedException("Unable to parse value "+value+" as date.", - DocumentedException.ErrorType.APPLICATION, - DocumentedException.ErrorTag.OPERATION_FAILED, + LOG.trace("Unable parse value {} due to ", value, e); + throw new DocumentedException("Unable to parse value " + value + " as date.", + DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, DocumentedException.ErrorSeverity.ERROR); } } } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/UnionCompositeAttributeResolvingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/UnionCompositeAttributeResolvingStrategy.java index c47087f5b0..ed2e30aaea 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/UnionCompositeAttributeResolvingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/UnionCompositeAttributeResolvingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -17,11 +17,13 @@ import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribu final class UnionCompositeAttributeResolvingStrategy extends CompositeAttributeResolvingStrategy { - UnionCompositeAttributeResolvingStrategy(final Map>> innerTypes, - final CompositeType openType, final Map yangToJavaAttrMapping) { + UnionCompositeAttributeResolvingStrategy( + final Map>> innerTypes, + final CompositeType openType, final Map yangToJavaAttrMapping) { super(innerTypes, openType, yangToJavaAttrMapping); } + @Override protected Map preprocessValueMap(final Map valueMap) { CompositeType openType = getOpenType(); @@ -33,7 +35,7 @@ final class UnionCompositeAttributeResolvingStrategy extends CompositeAttributeR Map newMap = Maps.newHashMap(); for (String key : openType.keySet()) { - if (openType.getDescription(key).equals(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION)){ + if (openType.getDescription(key).equals(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION)) { newMap.put(key, valueMap.get(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION)); } else { newMap.put(key, null); diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/ObjectNameAttributeWritingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/ObjectNameAttributeWritingStrategy.java index 0dc8731d4c..31305af844 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/ObjectNameAttributeWritingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/ObjectNameAttributeWritingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -21,10 +21,6 @@ public class ObjectNameAttributeWritingStrategy implements AttributeWritingStrat private final Document document; private final String key; - /** - * @param document - * @param key - */ public ObjectNameAttributeWritingStrategy(final Document document, final String key) { this.document = document; this.key = key; @@ -39,15 +35,15 @@ public class ObjectNameAttributeWritingStrategy implements AttributeWritingStrat String refName = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getRefName(); String namespaceForType = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getNamespace(); - Element typeElement = XmlUtil.createTextElementWithNamespacedContent(document, XmlMappingConstants.TYPE_KEY, XmlMappingConstants.PREFIX, - namespaceForType, moduleName); + Element typeElement = XmlUtil.createTextElementWithNamespacedContent(document, XmlMappingConstants.TYPE_KEY, + XmlMappingConstants.PREFIX, namespaceForType, moduleName); innerNode.appendChild(typeElement); - final Element nameElement = XmlUtil.createTextElement(document, XmlMappingConstants.NAME_KEY, refName, Optional.absent()); + final Element nameElement = XmlUtil.createTextElement(document, XmlMappingConstants.NAME_KEY, refName, + Optional.absent()); innerNode.appendChild(nameElement); parentElement.appendChild(innerNode); } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/ObjectXmlWriter.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/ObjectXmlWriter.java index d72d65baa8..a62b243eb7 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/ObjectXmlWriter.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/ObjectXmlWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -43,7 +43,8 @@ public class ObjectXmlWriter extends AttributeIfcSwitchStatement innerStrats = Maps.newHashMap(); String currentKey = key; - for (Entry innerAttrEntry : ((TOAttribute) getLastAttribute()).getYangPropertiesToTypesMap().entrySet()) { + for (Entry innerAttrEntry : ((TOAttribute) getLastAttribute()) + .getYangPropertiesToTypesMap().entrySet()) { AttributeWritingStrategy innerStrategy = prepareWritingStrategy(innerAttrEntry.getKey(), innerAttrEntry.getValue(), document); diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleAttributeWritingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleAttributeWritingStrategy.java index c8e218aae8..9847dfb8c2 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleAttributeWritingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleAttributeWritingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -19,10 +19,6 @@ public class SimpleAttributeWritingStrategy implements AttributeWritingStrategy private final Document document; private final String key; - /** - * @param document - * @param key - */ public SimpleAttributeWritingStrategy(final Document document, final String key) { this.document = document; this.key = key; @@ -36,15 +32,15 @@ public class SimpleAttributeWritingStrategy implements AttributeWritingStrategy parentElement.appendChild(innerNode); } - protected Element createElement(final Document document, final String key, final String value, final Optional namespace) { + protected Element createElement(final Document document, final String key, final String value, + final Optional namespace) { Element typeElement = XmlUtil.createElement(document, key, namespace); typeElement.appendChild(document.createTextNode(value)); return typeElement; } + protected Object preprocess(final Object value) { return value; } - - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleBinaryAttributeWritingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleBinaryAttributeWritingStrategy.java index f56ee73703..6c75c9f0df 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleBinaryAttributeWritingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleBinaryAttributeWritingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -16,10 +16,6 @@ import org.w3c.dom.Document; public class SimpleBinaryAttributeWritingStrategy extends SimpleAttributeWritingStrategy { - /** - * @param document - * @param key - */ public SimpleBinaryAttributeWritingStrategy(final Document document, final String key) { super(document, key); } @@ -31,14 +27,12 @@ public class SimpleBinaryAttributeWritingStrategy extends SimpleAttributeWriting List list = (List) value; byte[] decoded = new byte[list.size()]; - int i = 0; - for (Object bAsStr : list) { - Preconditions.checkArgument(bAsStr instanceof String, "Unexpected inner value for %s, expected string", value); - byte b = Byte.parseByte((String) bAsStr); - decoded[i++] = b; + int index = 0; + for (Object basStr : list) { + Preconditions.checkArgument(basStr instanceof String, "Unexpected inner value for %s, expected string", + value); + decoded[index++] = Byte.parseByte((String) basStr); } - return en.encode(decoded); } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleCompositeAttributeWritingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleCompositeAttributeWritingStrategy.java index b67371a927..8c6fd6c54b 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleCompositeAttributeWritingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleCompositeAttributeWritingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -15,18 +15,15 @@ import org.w3c.dom.Document; public class SimpleCompositeAttributeWritingStrategy extends SimpleAttributeWritingStrategy { - /** - * @param document - * @param key - */ public SimpleCompositeAttributeWritingStrategy(final Document document, final String key) { super(document, key); } + @Override protected Object preprocess(final Object value) { Util.checkType(value, Map.class); - Preconditions.checkArgument(((Map)value).size() == 1, "Unexpected number of values in %s, expected 1", value); - return ((Map)value).values().iterator().next(); + Preconditions.checkArgument(((Map) value).size() == 1, "Unexpected number of values in %s, expected 1", + value); + return ((Map) value).values().iterator().next(); } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleIdentityRefAttributeWritingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleIdentityRefAttributeWritingStrategy.java index aba1173921..7fe55b72f8 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleIdentityRefAttributeWritingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleIdentityRefAttributeWritingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -21,17 +21,15 @@ public class SimpleIdentityRefAttributeWritingStrategy extends SimpleAttributeWr private static final String PREFIX = "prefix"; - /** - * @param document - * @param key - */ public SimpleIdentityRefAttributeWritingStrategy(final Document document, final String key) { super(document, key); } + @Override protected Object preprocess(final Object value) { Util.checkType(value, Map.class); - Preconditions.checkArgument(((Map)value).size() == 1, "Unexpected number of values in %s, expected 1", value); + Preconditions.checkArgument(((Map) value).size() == 1, "Unexpected number of values in %s, expected 1", + value); Object stringValue = ((Map) value).values().iterator().next(); Util.checkType(stringValue, String.class); @@ -39,10 +37,12 @@ public class SimpleIdentityRefAttributeWritingStrategy extends SimpleAttributeWr } @Override - protected Element createElement(final Document doc, final String key, final String value, final Optional namespace) { - QName qName = QName.create(value); - String identityValue = qName.getLocalName(); - String identityNamespace = qName.getNamespace().toString(); - return XmlUtil.createTextElementWithNamespacedContent(doc, key, PREFIX, identityNamespace, identityValue, namespace); + protected Element createElement(final Document doc, final String key, final String value, + final Optional namespace) { + QName qualifiedName = QName.create(value); + String identityValue = qualifiedName.getLocalName(); + String identityNamespace = qualifiedName.getNamespace().toString(); + return XmlUtil.createTextElementWithNamespacedContent(doc, key, PREFIX, identityNamespace, identityValue, + namespace); } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleUnionAttributeWritingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleUnionAttributeWritingStrategy.java index d3b0c00114..7aeb76b864 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleUnionAttributeWritingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/toxml/SimpleUnionAttributeWritingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -16,27 +16,23 @@ import org.w3c.dom.Document; public class SimpleUnionAttributeWritingStrategy extends SimpleAttributeWritingStrategy { - /** - * @param document - * @param key - */ public SimpleUnionAttributeWritingStrategy(final Document document, final String key) { super(document, key); } + @Override protected Object preprocess(final Object value) { Util.checkType(value, Map.class); - Preconditions.checkArgument(((Map)value).size() == 1, "Unexpected number of values in %s, expected 1", value); + Preconditions.checkArgument(((Map) value).size() == 1, "Unexpected number of values in %s, expected 1", + value); Object listOfStrings = ((Map) value).values().iterator().next(); Util.checkType(listOfStrings, List.class); - StringBuilder b = new StringBuilder(); - for (Object character: (List)listOfStrings) { + StringBuilder builder = new StringBuilder(); + for (Object character : (List) listOfStrings) { Util.checkType(character, String.class); - b.append(character); + builder.append(character); } - - return b.toString(); + return builder.toString(); } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/Config.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/Config.java index d40bfe1d80..7aec4946e1 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/Config.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/Config.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -9,6 +9,7 @@ package org.opendaylight.controller.config.facade.xml.mapping.config; import static com.google.common.base.Preconditions.checkState; + import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.HashMultimap; @@ -34,11 +35,11 @@ import org.opendaylight.controller.config.util.xml.XmlUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; - public class Config { private final Map> moduleConfigs; + Map> moduleConfigs; private final Map> identityMap; @@ -48,14 +49,15 @@ public class Config { this(moduleConfigs, Collections.>emptyMap(), enumResolver); } - public Config(final Map> moduleConfigs, final Map> identityMap, final EnumResolver enumResolver) { + public Config(final Map> moduleConfigs, + final Map> identityMap, final EnumResolver enumResolver) { this.moduleConfigs = moduleConfigs; this.identityMap = identityMap; this.enumResolver = enumResolver; } - public static Map>> getMappedInstances(final Set instancesToMap, - final Map> configs) { + public static Map>> getMappedInstances( + final Set instancesToMap, final Map> configs) { Multimap moduleToInstances = mapInstancesToModules(instancesToMap); Map>> retVal = Maps.newLinkedHashMap(); @@ -72,14 +74,13 @@ public class Config { // TODO, this code does not support same module names from different namespaces // Namespace should be present in ObjectName - if (instances == null){ + if (instances == null) { continue; } innerRetVal.put(moduleName, instances); } - retVal.put(namespaceToModuleToConfigEntry.getKey(), innerRetVal); } return retVal; @@ -95,8 +96,8 @@ public class Config { return retVal; } - public Element toXml(final Set instancesToMap, final Optional maybeNamespace, final Document document, - final Element dataElement, final ServiceRegistryWrapper serviceTracker) { + public Element toXml(final Set instancesToMap, final Optional maybeNamespace, + final Document document, final Element dataElement, final ServiceRegistryWrapper serviceTracker) { Map>> moduleToInstances = getMappedInstances(instancesToMap, moduleConfigs); @@ -105,20 +106,23 @@ public class Config { dataElement.setAttributeNS(maybeNamespace.get(), dataElement.getNodeName(), "xmlns"); } - Element modulesElement = XmlUtil.createElement(document, XmlMappingConstants.MODULES_KEY, Optional.of(XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG)); + Element modulesElement = XmlUtil.createElement(document, XmlMappingConstants.MODULES_KEY, + Optional.of(XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG)); dataElement.appendChild(modulesElement); for (Entry>> moduleToInstanceEntry : moduleToInstances.entrySet()) { for (Entry> moduleMappingEntry : moduleToInstanceEntry.getValue() .entrySet()) { - ModuleConfig mapping = moduleConfigs.get(moduleToInstanceEntry.getKey()).get(moduleMappingEntry.getKey()); + ModuleConfig mapping = moduleConfigs.get(moduleToInstanceEntry.getKey()) + .get(moduleMappingEntry.getKey()); if (moduleMappingEntry.getValue().isEmpty()) { continue; } for (ObjectName objectName : moduleMappingEntry.getValue()) { - modulesElement.appendChild(mapping.toXml(objectName, document, moduleToInstanceEntry.getKey(), enumResolver)); + modulesElement.appendChild( + mapping.toXml(objectName, document, moduleToInstanceEntry.getKey(), enumResolver)); } } @@ -130,7 +134,7 @@ public class Config { } public Element moduleToXml(final String moduleNamespace, final String factoryName, final String instanceName, - final ObjectName instanceON, final Document document) { + final ObjectName instanceON, final Document document) { ModuleConfig moduleConfig = getModuleMapping(moduleNamespace, instanceName, factoryName); return moduleConfig.toXml(instanceON, document, moduleNamespace, enumResolver); } @@ -139,20 +143,19 @@ public class Config { // TODO refactor, replace Map->Multimap with e.g. ConfigElementResolved // class - public Map> fromXmlModulesResolved(final XmlElement xml, final EditStrategyType defaultEditStrategyType, final ServiceRegistryWrapper serviceTracker) throws DocumentedException { + public Map> fromXmlModulesResolved(final XmlElement xml, + final EditStrategyType defaultEditStrategyType, final ServiceRegistryWrapper serviceTracker) + throws DocumentedException { Optional modulesElement = getModulesElement(xml); List moduleElements = getModulesElementList(modulesElement); Map> retVal = Maps.newHashMap(); for (XmlElement moduleElement : moduleElements) { - ResolvingStrategy resolvingStrategy = new ResolvingStrategy() { - @Override - public ModuleElementResolved resolveElement(final ModuleConfig moduleMapping, final XmlElement moduleElement, final ServiceRegistryWrapper serviceTracker, final String instanceName, final String moduleNamespace, final EditStrategyType defaultStrategy) throws DocumentedException { - return moduleMapping.fromXml(moduleElement, serviceTracker, - instanceName, moduleNamespace, defaultStrategy, identityMap, enumResolver); - } - }; + ResolvingStrategy resolvingStrategy = (moduleMapping, moduleElement1, + serviceTracker1, instanceName, moduleNamespace, + defaultStrategy) -> moduleMapping.fromXml(moduleElement1, serviceTracker1, instanceName, + moduleNamespace, defaultStrategy, identityMap, enumResolver); resolveModule(retVal, serviceTracker, moduleElement, defaultEditStrategyType, resolvingStrategy); } @@ -160,27 +163,25 @@ public class Config { } /** - * return a map containing namespace -> moduleName -> instanceName map. Attribute parsing is omitted. + * return a map containing namespace -> moduleName -> instanceName map. + * Attribute parsing is omitted. */ public Map> fromXmlModulesMap(final XmlElement xml, - final EditStrategyType defaultEditStrategyType, final ServiceRegistryWrapper serviceTracker) throws DocumentedException { + final EditStrategyType defaultEditStrategyType, final ServiceRegistryWrapper serviceTracker) + throws DocumentedException { Optional modulesElement = getModulesElement(xml); List moduleElements = getModulesElementList(modulesElement); Map> retVal = Maps.newHashMap(); for (XmlElement moduleElement : moduleElements) { - ResolvingStrategy resolvingStrategy = new ResolvingStrategy() { - @Override - public ModuleElementDefinition resolveElement(final ModuleConfig moduleMapping, final XmlElement moduleElement, - final ServiceRegistryWrapper serviceTracker, final String instanceName, final String moduleNamespace, - final EditStrategyType defaultStrategy) { - // TODO: add check for conflicts between global and local - // edit strategy - String perInstanceEditStrategy = moduleElement.getAttribute(XmlMappingConstants.OPERATION_ATTR_KEY, - XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); - return new ModuleElementDefinition(instanceName, perInstanceEditStrategy, defaultStrategy); - } + ResolvingStrategy resolvingStrategy = (moduleMapping, moduleElement1, + serviceTracker1, instanceName, moduleNamespace, defaultStrategy) -> { + // TODO: add check for conflicts between global and local + // edit strategy + String perInstanceEditStrategy = moduleElement1.getAttribute(XmlMappingConstants.OPERATION_ATTR_KEY, + XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); + return new ModuleElementDefinition(instanceName, perInstanceEditStrategy, defaultStrategy); }; resolveModule(retVal, serviceTracker, moduleElement, defaultEditStrategyType, resolvingStrategy); @@ -190,10 +191,11 @@ public class Config { private static Optional getModulesElement(final XmlElement xml) { return xml.getOnlyChildElementOptionally(XmlMappingConstants.MODULES_KEY, - XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG); + XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG); } - private List getModulesElementList(final Optional modulesElement) throws DocumentedException { + private List getModulesElementList(final Optional modulesElement) + throws DocumentedException { List moduleElements; if (modulesElement.isPresent()) { @@ -205,8 +207,10 @@ public class Config { return moduleElements; } - private void resolveModule(final Map> retVal, final ServiceRegistryWrapper serviceTracker, - final XmlElement moduleElement, final EditStrategyType defaultStrategy, final ResolvingStrategy resolvingStrategy) throws DocumentedException { + private void resolveModule(final Map> retVal, + final ServiceRegistryWrapper serviceTracker, final XmlElement moduleElement, + final EditStrategyType defaultStrategy, final ResolvingStrategy resolvingStrategy) + throws DocumentedException { XmlElement typeElement = null; typeElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlMappingConstants.TYPE_KEY); Entry prefixToNamespace = typeElement.findNamespaceOfTextContent(); @@ -222,8 +226,8 @@ public class Config { Multimap innerMap = retVal.computeIfAbsent(moduleNamespace, k -> HashMultimap.create()); - T resolvedElement = resolvingStrategy.resolveElement(moduleMapping, moduleElement, serviceTracker, - instanceName, moduleNamespace, defaultStrategy); + T resolvedElement = resolvingStrategy.resolveElement(moduleMapping, moduleElement, serviceTracker, instanceName, + moduleNamespace, defaultStrategy); innerMap.put(factoryName, resolvedElement); } @@ -243,7 +247,7 @@ public class Config { private static Optional getServicesElement(final XmlElement xml) { return xml.getOnlyChildElementOptionally(XmlMappingConstants.SERVICES_KEY, - XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG); + XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG); } public static void checkUnrecognisedChildren(final XmlElement parent) throws DocumentedException { @@ -251,10 +255,10 @@ public class Config { Optional modulesOpt = getModulesElement(parent); List recognised = Lists.newArrayList(); - if(servicesOpt.isPresent()){ + if (servicesOpt.isPresent()) { recognised.add(servicesOpt.get()); } - if(modulesOpt.isPresent()){ + if (modulesOpt.isPresent()) { recognised.add(modulesOpt.get()); } @@ -262,8 +266,7 @@ public class Config { } private String getFactoryName(final String factoryNameWithPrefix, final String prefixOrEmptyString) { - checkState( - factoryNameWithPrefix.startsWith(prefixOrEmptyString), + checkState(factoryNameWithPrefix.startsWith(prefixOrEmptyString), String.format("Internal error: text " + "content '%s' of type node does not start with prefix '%s'", factoryNameWithPrefix, prefixOrEmptyString)); @@ -276,7 +279,8 @@ public class Config { return factoryNameWithPrefix.substring(factoryNameAfterPrefixIndex); } - private ModuleConfig getModuleMapping(final String moduleNamespace, final String instanceName, final String factoryName) { + private ModuleConfig getModuleMapping(final String moduleNamespace, final String instanceName, + final String factoryName) { Map mappingsFromNamespace = moduleConfigs.get(moduleNamespace); Preconditions.checkNotNull(mappingsFromNamespace, @@ -290,6 +294,7 @@ public class Config { private interface ResolvingStrategy { T resolveElement(ModuleConfig moduleMapping, XmlElement moduleElement, ServiceRegistryWrapper serviceTracker, - String instanceName, String moduleNamespace, EditStrategyType defaultStrategy) throws DocumentedException; + String instanceName, String moduleNamespace, EditStrategyType defaultStrategy) + throws DocumentedException; } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/InstanceConfig.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/InstanceConfig.java index b9f4cda834..b9e4bce94d 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/InstanceConfig.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/InstanceConfig.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -11,12 +11,15 @@ package org.opendaylight.controller.config.facade.xml.mapping.config; import com.google.common.base.Optional; import com.google.common.collect.Lists; import com.google.common.collect.Maps; + import java.util.Date; import java.util.List; import java.util.Map; import java.util.Map.Entry; + import javax.management.ObjectName; import javax.management.openmbean.OpenType; + import org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping; import org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement; import org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeReadingStrategy; @@ -58,6 +61,7 @@ public final class InstanceConfig { this.configRegistryClient = configRegistryClient; } + @SuppressWarnings("IllegalCatch") private Map getMappedConfiguration(final ObjectName on, final EnumResolver enumResolver) { // TODO make field, mappingStrategies can be instantiated only once @@ -68,19 +72,19 @@ public final class InstanceConfig { for (Entry configDefEntry : jmxToAttrConfig.entrySet()) { // Skip children runtime beans as they are mapped by InstanceRuntime - if (configDefEntry.getValue() instanceof RuntimeBeanEntry){ + if (configDefEntry.getValue() instanceof RuntimeBeanEntry) { continue; } Object value = configRegistryClient.getAttributeCurrentValue(on, configDefEntry.getKey()); try { AttributeMappingStrategy> attributeMappingStrategy = mappingStrategies .get(configDefEntry.getKey()); - Optional a = attributeMappingStrategy.mapAttribute(value); - if (!a.isPresent()){ + Optional attribute = attributeMappingStrategy.mapAttribute(value); + if (!attribute.isPresent()) { continue; } - toXml.put(configDefEntry.getValue().getAttributeYangName(), a.get()); - } catch (final Exception e) { + toXml.put(configDefEntry.getValue().getAttributeYangName(), attribute.get()); + } catch (final RuntimeException e) { throw new IllegalStateException("Unable to map value " + value + " to attribute " + configDefEntry.getKey(), e); } @@ -88,7 +92,9 @@ public final class InstanceConfig { return toXml; } - public Element toXml(final ObjectName on, final String namespace, final Document document, final Element rootElement, final EnumResolver enumResolver) { + @SuppressWarnings("IllegalCatch") + public Element toXml(final ObjectName on, final String namespace, final Document document, + final Element rootElement, final EnumResolver enumResolver) { Map strats = new ObjectXmlWriter().prepareWriting(yangToAttrConfig, document); Map mappedConfig = getMappedConfiguration(on, enumResolver); Element parentElement; @@ -102,7 +108,7 @@ public final class InstanceConfig { for (Entry mappingEntry : mappedConfig.entrySet()) { try { strats.get(mappingEntry.getKey()).writeElement(parentElement, namespace, mappingEntry.getValue()); - } catch (final Exception e) { + } catch (final RuntimeException e) { throw new IllegalStateException("Unable to write value " + mappingEntry.getValue() + " for attribute " + mappingEntry.getValue(), e); } @@ -110,7 +116,8 @@ public final class InstanceConfig { return rootElement; } - private void resolveConfiguration(final InstanceConfigElementResolved mappedConfig, final ServiceRegistryWrapper depTracker, final EnumResolver enumResolver) { + private void resolveConfiguration(final InstanceConfigElementResolved mappedConfig, + final ServiceRegistryWrapper depTracker, final EnumResolver enumResolver) { // TODO make field, resolvingStrategies can be instantiated only once Map>> resolvingStrategies = new ObjectResolver( @@ -122,24 +129,27 @@ public final class InstanceConfig { try { AttributeResolvingStrategy> attributeResolvingStrategy = resolvingStrategies .get(attributeName); - LOG.trace("Trying to set value {} of attribute {} with {}", value, attributeName, attributeResolvingStrategy); + LOG.trace("Trying to set value {} of attribute {} with {}", value, attributeName, + attributeResolvingStrategy); value.resolveValue(attributeResolvingStrategy, attributeName); - value.setJmxName( - yangToAttrConfig.get(attributeName).getUpperCaseCammelCase()); - } catch (final Exception e) { - throw new IllegalStateException("Unable to resolve value " + value - + " to attribute " + attributeName, e); + value.setJmxName(yangToAttrConfig.get(attributeName).getUpperCaseCammelCase()); + } catch (final DocumentedException e) { + throw new IllegalStateException("Unable to resolve value " + value + " to attribute " + attributeName, + e); } } } - public InstanceConfigElementResolved fromXml(XmlElement moduleElement, final ServiceRegistryWrapper services, final String moduleNamespace, - final EditStrategyType defaultStrategy, - final Map> identityMap, final EnumResolver enumResolver) throws DocumentedException { + public InstanceConfigElementResolved fromXml(XmlElement moduleElement, final ServiceRegistryWrapper services, + final String moduleNamespace, final EditStrategyType defaultStrategy, + final Map> identityMap, + final EnumResolver enumResolver) + throws DocumentedException { Map retVal = Maps.newHashMap(); - Map strats = new ObjectXmlReader().prepareReading(yangToAttrConfig, identityMap); + Map strats = new ObjectXmlReader().prepareReading(yangToAttrConfig, + identityMap); List recognisedChildren = Lists.newArrayList(); XmlElement typeElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlMappingConstants.TYPE_KEY); @@ -151,18 +161,17 @@ public final class InstanceConfig { int size = moduleElement.getChildElements().size(); int expectedChildNodes = 1 + typeAndNameElements.size(); if (size > expectedChildNodes) { - throw new DocumentedException("Error reading module " + typeElement.getTextContent() + " : " + - nameElement.getTextContent() + " - Expected " + expectedChildNodes +" child nodes, " + - "one of them with name " + nullableDummyContainerName + - ", got " + size + " elements."); + throw new DocumentedException("Error reading module " + typeElement.getTextContent() + " : " + + nameElement.getTextContent() + " - Expected " + expectedChildNodes + " child nodes, " + + "one of them with name " + nullableDummyContainerName + ", got " + size + " elements."); } if (size == expectedChildNodes) { try { moduleElement = moduleElement.getOnlyChildElement(nullableDummyContainerName, moduleNamespace); } catch (final DocumentedException e) { - throw new DocumentedException("Error reading module " + typeElement.getTextContent() + " : " + - nameElement.getTextContent() + " - Expected child node with name " + nullableDummyContainerName + - "." + e.getMessage()); + throw new DocumentedException("Error reading module " + typeElement.getTextContent() + " : " + + nameElement.getTextContent() + " - Expected child node with name " + + nullableDummyContainerName + "." + e.getMessage()); } } // else 2 elements, no need to descend } @@ -178,23 +187,27 @@ public final class InstanceConfig { try { moduleElement.checkUnrecognisedElements(recognisedChildren); } catch (final DocumentedException e) { - throw new DocumentedException("Error reading module " + typeElement.getTextContent() + " : " + - nameElement.getTextContent() + " - " + - e.getMessage(), e.getErrorType(), e.getErrorTag(),e.getErrorSeverity(),e.getErrorInfo()); + throw new DocumentedException( + "Error reading module " + typeElement.getTextContent() + " : " + nameElement.getTextContent() + + " - " + e.getMessage(), + e.getErrorType(), e.getErrorTag(), e.getErrorSeverity(), e.getErrorInfo()); } // TODO: add check for conflicts between global and local edit strategy String perInstanceEditStrategy = moduleElement.getAttribute(XmlMappingConstants.OPERATION_ATTR_KEY, XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); - InstanceConfigElementResolved instanceConfigElementResolved = perInstanceEditStrategy.equals("") ? new InstanceConfigElementResolved( - retVal, defaultStrategy) : new InstanceConfigElementResolved(perInstanceEditStrategy, retVal, defaultStrategy); + InstanceConfigElementResolved instanceConfigElementResolved = perInstanceEditStrategy.equals("") + ? new InstanceConfigElementResolved(retVal, defaultStrategy) + : new InstanceConfigElementResolved(perInstanceEditStrategy, retVal, defaultStrategy); resolveConfiguration(instanceConfigElementResolved, services, enumResolver); return instanceConfigElementResolved; } - private List getConfigNodes(final XmlElement moduleElement, final String moduleNamespace, final String name, - final List recognisedChildren, final List typeAndName) throws DocumentedException { + private List getConfigNodes(final XmlElement moduleElement, final String moduleNamespace, + final String name, final List recognisedChildren, + final List typeAndName) + throws DocumentedException { List foundConfigNodes = moduleElement.getChildElementsWithinNamespace(name, moduleNamespace); if (foundConfigNodes.isEmpty()) { LOG.debug("No config nodes {}:{} found in {}", moduleNamespace, name, moduleElement); @@ -212,15 +225,14 @@ public final class InstanceConfig { List foundWithoutNamespaceNodes = moduleElement.getChildElementsWithinNamespace(name, XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG); foundWithoutNamespaceNodes.removeAll(typeAndName); - if (!foundWithoutNamespaceNodes.isEmpty()){ - throw new DocumentedException(String.format("Element %s present multiple times with different namespaces: %s, %s", name, foundConfigNodes, - foundWithoutNamespaceNodes), - DocumentedException.ErrorType.APPLICATION, - DocumentedException.ErrorTag.INVALID_VALUE, + if (!foundWithoutNamespaceNodes.isEmpty()) { + throw new DocumentedException( + String.format("Element %s present multiple times with different namespaces: %s, %s", name, + foundConfigNodes, foundWithoutNamespaceNodes), + DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, DocumentedException.ErrorSeverity.ERROR); } } - recognisedChildren.addAll(foundConfigNodes); return foundConfigNodes; } @@ -231,8 +243,6 @@ public final class InstanceConfig { for (Entry entry : yangNameToAttr.entrySet()) { reversednameToAtr.put(entry.getValue().getUpperCaseCammelCase(), entry.getValue()); } - return reversednameToAtr; } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/InstanceConfigElementResolved.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/InstanceConfigElementResolved.java index 76cf9dbf2a..4c4fb78f45 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/InstanceConfigElementResolved.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/InstanceConfigElementResolved.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -24,26 +24,26 @@ public class InstanceConfigElementResolved { private final EditStrategyType editStrategy; private final Map configuration; - public InstanceConfigElementResolved(final String currentStrategy, final Map configuration, - final EditStrategyType defaultStrategy) + public InstanceConfigElementResolved(final String currentStrategy, + final Map configuration, final EditStrategyType defaultStrategy) throws DocumentedException { this.editStrategy = parseStrategy(currentStrategy, defaultStrategy); this.configuration = configuration; } - public InstanceConfigElementResolved(final Map configuration, final EditStrategyType defaultStrategy) { + public InstanceConfigElementResolved(final Map configuration, + final EditStrategyType defaultStrategy) { editStrategy = defaultStrategy; this.configuration = configuration; } - - static EditStrategyType parseStrategy(final String currentStrategy, final EditStrategyType defaultStrategy) throws OperationNotPermittedException { + static EditStrategyType parseStrategy(final String currentStrategy, final EditStrategyType defaultStrategy) + throws OperationNotPermittedException { EditStrategyType parsedStrategy = EditStrategyType.valueOf(currentStrategy); - EditStrategyType.compareParsedStrategyToDefaultEnforcing(parsedStrategy,defaultStrategy); + EditStrategyType.compareParsedStrategyToDefaultEnforcing(parsedStrategy, defaultStrategy); return parsedStrategy; } - public EditConfigStrategy getEditStrategy() { return editStrategy.getFittingStrategy(); } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ModuleConfig.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ModuleConfig.java index 90108ce72d..ca01f86fec 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ModuleConfig.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ModuleConfig.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -33,12 +33,14 @@ public class ModuleConfig { this.instanceConfig = mbeanMapping; } - public Element toXml(final ObjectName instanceON, final Document document, final String namespace, final EnumResolver enumResolver) { - final Optional configNs = - Optional.of(XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG); + public Element toXml(final ObjectName instanceON, final Document document, final String namespace, + final EnumResolver enumResolver) { + final Optional configNs = Optional + .of(XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG); Element root = XmlUtil.createElement(document, XmlMappingConstants.MODULE_KEY, configNs); - // type belongs to config.yang namespace, but needs to be prefix:moduleName + // type belongs to config.yang namespace, but needs to be prefix:moduleName Element typeElement = XmlUtil.createTextElementWithNamespacedContent(document, XmlMappingConstants.TYPE_KEY, XmlMappingConstants.PREFIX, namespace, moduleName, configNs); @@ -55,10 +57,13 @@ public class ModuleConfig { return root; } - public ModuleElementResolved fromXml(final XmlElement moduleElement, final ServiceRegistryWrapper depTracker, final String instanceName, - final String moduleNamespace, final EditStrategyType defaultStrategy, final Map> identityMap, final EnumResolver enumResolver) throws DocumentedException { + public ModuleElementResolved fromXml(final XmlElement moduleElement, final ServiceRegistryWrapper depTracker, + final String instanceName, final String moduleNamespace, final EditStrategyType defaultStrategy, + final Map> identityMap, final EnumResolver enumResolver) + throws DocumentedException { - InstanceConfigElementResolved ice = instanceConfig.fromXml(moduleElement, depTracker, moduleNamespace, defaultStrategy, identityMap, enumResolver); + InstanceConfigElementResolved ice = instanceConfig.fromXml(moduleElement, depTracker, moduleNamespace, + defaultStrategy, identityMap, enumResolver); return new ModuleElementResolved(instanceName, ice); } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ModuleElementDefinition.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ModuleElementDefinition.java index 15f2b380d3..fc0cd4a52f 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ModuleElementDefinition.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ModuleElementDefinition.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -19,28 +19,30 @@ import org.slf4j.LoggerFactory; public class ModuleElementDefinition { public static final NoneEditConfigStrategy NONE_EDIT_CONFIG_STRATEGY = new NoneEditConfigStrategy(); - public static final MissingInstanceHandlingStrategy MISSING_INSTANCE_HANDLING_STRATEGY = new MissingInstanceHandlingStrategy(); + public static final MissingInstanceHandlingStrategy MISSING_INSTANCE_HANDLING_STRATEGY = + new MissingInstanceHandlingStrategy(); private final String instanceName; private final EditStrategyType editStrategy; private static final Logger LOG = LoggerFactory.getLogger(ModuleElementDefinition.class); - public ModuleElementDefinition(final String instanceName, final String currentStrategy, final EditStrategyType defaultStrategy) { + public ModuleElementDefinition(final String instanceName, final String currentStrategy, + final EditStrategyType defaultStrategy) { this.instanceName = instanceName; if (currentStrategy == null || currentStrategy.isEmpty()) { this.editStrategy = defaultStrategy; } else { - EditStrategyType _edStrategy = null; + EditStrategyType edStrategy = null; try { - _edStrategy = InstanceConfigElementResolved.parseStrategy(currentStrategy, defaultStrategy); + edStrategy = InstanceConfigElementResolved.parseStrategy(currentStrategy, defaultStrategy); } catch (final OperationNotPermittedException e) { - _edStrategy = defaultStrategy; - LOG.warn("Operation not permitted on current strategy {} while default strategy is {}. Element definition strategy set to default.", - currentStrategy, - defaultStrategy, - e); + edStrategy = defaultStrategy; + LOG.warn( + "Operation not permitted on current strategy {} while default strategy " + + "is {}. Element definition strategy set to default.", + currentStrategy, defaultStrategy, e); } - this.editStrategy = _edStrategy; + this.editStrategy = edStrategy; } } @@ -51,12 +53,12 @@ public class ModuleElementDefinition { public EditConfigStrategy getEditStrategy() { switch (editStrategy) { - case delete : - case remove : - case none : - return NONE_EDIT_CONFIG_STRATEGY; - default : - return MISSING_INSTANCE_HANDLING_STRATEGY; + case delete: + case remove: + case none: + return NONE_EDIT_CONFIG_STRATEGY; + default: + return MISSING_INSTANCE_HANDLING_STRATEGY; } } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ModuleElementResolved.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ModuleElementResolved.java index 44418eb981..34e5ebae3e 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ModuleElementResolved.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ModuleElementResolved.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -13,7 +13,8 @@ public class ModuleElementResolved { private final String instanceName; private final InstanceConfigElementResolved instanceConfigElementResolved; - public ModuleElementResolved(final String instanceName, final InstanceConfigElementResolved instanceConfigElementResolved) { + public ModuleElementResolved(final String instanceName, + final InstanceConfigElementResolved instanceConfigElementResolved) { this.instanceName = instanceName; this.instanceConfigElementResolved = instanceConfigElementResolved; } @@ -25,5 +26,4 @@ public class ModuleElementResolved { public InstanceConfigElementResolved getInstanceConfigElementResolved() { return instanceConfigElementResolved; } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ServiceRegistryWrapper.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ServiceRegistryWrapper.java index eab120a3ba..0d04194af6 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ServiceRegistryWrapper.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ServiceRegistryWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -30,35 +30,36 @@ public class ServiceRegistryWrapper { Map> serviceNameToRefNameToInstance = mappedServices.get(namespace); Preconditions.checkArgument(serviceNameToRefNameToInstance != null, - "No service mapped to %s:%s:%s. Wrong namespace, available namespaces: %s", - namespace, serviceType, refName, mappedServices.keySet()); + "No service mapped to %s:%s:%s. Wrong namespace, available namespaces: %s", namespace, serviceType, + refName, mappedServices.keySet()); Map refNameToInstance = serviceNameToRefNameToInstance.get(serviceType); Preconditions.checkArgument(refNameToInstance != null, - "No service mapped to %s:%s:%s. Wrong service type, available service types: %s" - , namespace, serviceType, refName, serviceNameToRefNameToInstance.keySet()); + "No service mapped to %s:%s:%s. Wrong service type, available service types: %s", namespace, + serviceType, refName, serviceNameToRefNameToInstance.keySet()); String instanceId = refNameToInstance.get(refName); Preconditions.checkArgument(instanceId != null, - "No service mapped to %s:%s:%s. Wrong ref name, available ref names: %s" - ,namespace, serviceType, refName, refNameToInstance.keySet()); + "No service mapped to %s:%s:%s. Wrong ref name, available ref names: %s", namespace, serviceType, + refName, refNameToInstance.keySet()); Services.ServiceInstance serviceInstance = Services.ServiceInstance.fromString(instanceId); Preconditions.checkArgument(serviceInstance != null, - "No service mapped to %s:%s:%s. Wrong ref name, available ref names: %s" - ,namespace, serviceType, refName, refNameToInstance.keySet()); + "No service mapped to %s:%s:%s. Wrong ref name, available ref names: %s", namespace, serviceType, + refName, refNameToInstance.keySet()); - String qNameOfService = configServiceRefRegistry.getServiceInterfaceName(namespace, serviceType); + String serviceName = configServiceRefRegistry.getServiceInterfaceName(namespace, serviceType); try { /* - Remove transaction name as this is redundant - will be stripped in DynamicWritableWrapper, - and makes it hard to compare with service references got from MXBean attributes - */ - return ObjectNameUtil.withoutTransactionName( - configServiceRefRegistry.getServiceReference(qNameOfService, refName)); + * Remove transaction name as this is redundant - will be stripped in + * DynamicWritableWrapper, and makes it hard to compare with service references + * got from MXBean attributes + */ + return ObjectNameUtil + .withoutTransactionName(configServiceRefRegistry.getServiceReference(serviceName, refName)); } catch (final InstanceNotFoundException e) { - throw new IllegalArgumentException("No serviceInstance mapped to " + refName - + " under service name " + serviceType + " , " + refNameToInstance.keySet(), e); + throw new IllegalArgumentException("No serviceInstance mapped to " + refName + " under service name " + + serviceType + " , " + refNameToInstance.keySet(), e); } } @@ -67,16 +68,16 @@ public class ServiceRegistryWrapper { Map>> retVal = new HashMap<>(); Map> serviceMapping = configServiceRefRegistry.getServiceMapping(); - for (Map.Entry> qNameToRefNameEntry : serviceMapping.entrySet()){ - for (String refName : qNameToRefNameEntry.getValue().keySet()) { + for (Map.Entry> nameToRefEntry : serviceMapping.entrySet()) { + for (String refName : nameToRefEntry.getValue().keySet()) { - ObjectName on = qNameToRefNameEntry.getValue().get(refName); + ObjectName on = nameToRefEntry.getValue().get(refName); Services.ServiceInstance si = Services.ServiceInstance.fromObjectName(on); - QName qname = QName.create(qNameToRefNameEntry.getKey()); + QName qname = QName.create(nameToRefEntry.getKey()); String namespace = qname.getNamespace().toString(); - Map> serviceToRefs = - retVal.computeIfAbsent(namespace, k -> new HashMap<>()); + Map> serviceToRefs = retVal.computeIfAbsent(namespace, + k -> new HashMap<>()); String localName = qname.getLocalName(); Map refsToSis = serviceToRefs.computeIfAbsent(localName, k -> new HashMap<>()); diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/Services.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/Services.java index 9853bc79a2..b96ba72a07 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/Services.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/Services.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -8,7 +8,6 @@ package org.opendaylight.controller.config.facade.xml.mapping.config; - import com.google.common.base.Optional; import com.google.common.base.Preconditions; import java.util.HashMap; @@ -36,12 +35,12 @@ public final class Services { public static final String TYPE_KEY = "type"; public static final String SERVICE_KEY = "service"; - private final Map>> - namespaceToServiceNameToRefNameToInstance = new HashMap<>(); + private final Map>> namespaceToServiceNameToRefNameToInstance = new HashMap<>(); - /** - * - */ public Map>> getNamespaceToServiceNameToRefNameToInstance() { return namespaceToServiceNameToRefNameToInstance; } @@ -58,16 +57,17 @@ public final class Services { for (Entry refEntry : serviceEntry.getValue().entrySet()) { Map> namespaceToServices = - tracker.namespaceToServiceNameToRefNameToInstance.computeIfAbsent(namespace, - k -> new HashMap<>()); + tracker.namespaceToServiceNameToRefNameToInstance + .computeIfAbsent(namespace, k -> new HashMap<>()); - Map refNameToInstance = namespaceToServices - .computeIfAbsent(serviceName, k -> new HashMap<>()); + Map refNameToInstance = namespaceToServices.computeIfAbsent(serviceName, + k -> new HashMap<>()); String refName = refEntry.getKey(); - //we want to compare reference not value of the provider + // we want to compare reference not value of the provider refNameToInstance.put(refName, refEntry.getValue() == EMPTY_PROVIDER - //provider name cannot be EMPTY_PROVIDER instance unless we are executing delete + // provider name cannot be EMPTY_PROVIDER instance unless we are executing + // delete ? ServiceInstance.EMPTY_SERVICE_INSTANCE : ServiceInstance.fromString(refEntry.getValue())); @@ -90,13 +90,14 @@ public final class Services { XmlElement typeElement = service.getOnlyChildElement(TYPE_KEY); Entry prefixNamespace = typeElement.findNamespaceOfTextContent(); - Preconditions.checkState(prefixNamespace.getKey()!=null && !prefixNamespace.getKey().equals(""), "Type attribute was not prefixed"); + Preconditions.checkState(prefixNamespace.getKey() != null && !prefixNamespace.getKey().equals(""), + "Type attribute was not prefixed"); - Map> namespaceToServices = - retVal.computeIfAbsent(prefixNamespace.getValue(), k -> new HashMap<>()); + Map> namespaceToServices = retVal.computeIfAbsent(prefixNamespace.getValue(), + k -> new HashMap<>()); - String serviceName = ObjectNameAttributeReadingStrategy - .checkPrefixAndExtractServiceName(typeElement, prefixNamespace); + String serviceName = ObjectNameAttributeReadingStrategy.checkPrefixAndExtractServiceName(typeElement, + prefixNamespace); Map innerMap = namespaceToServices.computeIfAbsent(serviceName, k -> new HashMap<>()); @@ -107,11 +108,9 @@ public final class Services { XmlElement nameElement = instance.getOnlyChildElement(NAME_KEY); String refName = nameElement.getTextContent(); - if (!ModifyAction.DELETE.toString().toLowerCase().equals( - instance.getAttribute( - XmlMappingConstants.OPERATION_ATTR_KEY, - XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0))) - { + if (!ModifyAction.DELETE.toString().toLowerCase() + .equals(instance.getAttribute(XmlMappingConstants.OPERATION_ATTR_KEY, + XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0))) { XmlElement providerElement = instance.getOnlyChildElement(PROVIDER_KEY); String providerName = providerElement.getTextContent(); @@ -119,7 +118,8 @@ public final class Services { innerMap.put(refName, providerName); } else { - //since this is a delete we dont have a provider name - we want empty service instance + // since this is a delete we dont have a provider name - we want empty service + // instance innerMap.put(refName, EMPTY_PROVIDER); } } @@ -129,7 +129,8 @@ public final class Services { } public static Element toXml(final ServiceRegistryWrapper serviceRegistryWrapper, final Document document) { - final Optional configNs = Optional.of(XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG); + final Optional configNs = Optional + .of(XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG); Element root = XmlUtil.createElement(document, XmlMappingConstants.SERVICES_KEY, configNs); Map>> mappedServices = serviceRegistryWrapper.getMappedServices(); @@ -142,23 +143,23 @@ public final class Services { // type belongs to config.yang namespace String serviceType = serviceEntry.getKey(); - Element typeElement = XmlUtil.createTextElementWithNamespacedContent( - document, XmlMappingConstants.TYPE_KEY, XmlMappingConstants.PREFIX, - namespaceToRefEntry.getKey(), serviceType, configNs); + Element typeElement = XmlUtil.createTextElementWithNamespacedContent(document, + XmlMappingConstants.TYPE_KEY, XmlMappingConstants.PREFIX, namespaceToRefEntry.getKey(), + serviceType, configNs); serviceElement.appendChild(typeElement); for (Entry instanceEntry : serviceEntry.getValue().entrySet()) { - Element instanceElement = XmlUtil.createElement( - document, XmlMappingConstants.INSTANCE_KEY, configNs); + Element instanceElement = XmlUtil.createElement(document, XmlMappingConstants.INSTANCE_KEY, + configNs); serviceElement.appendChild(instanceElement); - Element nameElement = XmlUtil.createTextElement( - document, NAME_KEY, instanceEntry.getKey(), configNs); + Element nameElement = XmlUtil.createTextElement(document, NAME_KEY, instanceEntry.getKey(), + configNs); instanceElement.appendChild(nameElement); - Element providerElement = XmlUtil.createTextElement( - document, PROVIDER_KEY, instanceEntry.getValue(), configNs); + Element providerElement = XmlUtil.createTextElement(document, PROVIDER_KEY, + instanceEntry.getValue(), configNs); instanceElement.appendChild(providerElement); } } @@ -177,20 +178,23 @@ public final class Services { public static ServiceInstance fromString(String instanceId) { instanceId = instanceId.trim(); - Matcher matcher = p.matcher(instanceId); - if(!matcher.matches()) { - matcher = pDeprecated.matcher(instanceId); + Matcher matcher = PATTERN.matcher(instanceId); + if (!matcher.matches()) { + matcher = PATTERN_DEPRECATED.matcher(instanceId); } - Preconditions.checkArgument(matcher.matches(), "Unexpected format for provider, expected " + p.toString() - + " or " + pDeprecated.toString() + " but was " + instanceId); + Preconditions.checkArgument(matcher.matches(), + "Unexpected format for provider, expected " + PATTERN.toString() + + " or " + PATTERN_DEPRECATED.toString() + " but was " + instanceId); String factoryName = matcher.group(1); String instanceName = matcher.group(2); return new ServiceInstance(factoryName, instanceName); } - private final String moduleName, instanceName; + private final String moduleName; + private final String instanceName; + private String serviceName; public String getServiceName() { @@ -209,65 +213,65 @@ public final class Services { return instanceName; } - private static final String blueprint = "/" - + XmlMappingConstants.MODULES_KEY + "/" + XmlMappingConstants.MODULE_KEY + "[" - + XmlMappingConstants.TYPE_KEY + "='%s'][" + private static final String BLUEPRINT = "/" + XmlMappingConstants.MODULES_KEY + "/" + + XmlMappingConstants.MODULE_KEY + "[" + XmlMappingConstants.TYPE_KEY + "='%s'][" + XmlMappingConstants.NAME_KEY + "='%s']"; // TODO unify with xpath in RuntimeRpc - // Previous version of xpath, needs to be supported for backwards compatibility (persisted configs by config-persister) - private static final String blueprintRDeprecated = "/" + XmlMappingConstants.CONFIG_KEY + "/" + // Previous version of xpath, needs to be supported for backwards compatibility + // (persisted configs by config-persister) + private static final String BLUEPRINTR_DEPRECATED = "/" + XmlMappingConstants.CONFIG_KEY + "/" + XmlMappingConstants.MODULES_KEY + "/" + XmlMappingConstants.MODULE_KEY + "\\[" + XmlMappingConstants.NAME_KEY + "='%s'\\]/" + XmlMappingConstants.INSTANCE_KEY + "\\[" + XmlMappingConstants.NAME_KEY + "='%s'\\]"; - private static final String blueprintR = "/" - + XmlMappingConstants.MODULES_KEY + "/" + XmlMappingConstants.MODULE_KEY + "\\[" - + XmlMappingConstants.TYPE_KEY + "='%s'\\]\\[" + private static final String BLUEPRINTR = "/" + XmlMappingConstants.MODULES_KEY + "/" + + XmlMappingConstants.MODULE_KEY + "\\[" + XmlMappingConstants.TYPE_KEY + "='%s'\\]\\[" + XmlMappingConstants.NAME_KEY + "='%s'\\]"; - private static final Pattern pDeprecated = Pattern.compile(String.format(blueprintRDeprecated, "(.+)", "(.+)")); - private static final Pattern p = Pattern.compile(String.format(blueprintR, "(.+)", "(.+)")); + private static final Pattern PATTERN_DEPRECATED = + Pattern.compile(String.format(BLUEPRINTR_DEPRECATED, "(.+)", "(.+)")); + private static final Pattern PATTERN = Pattern.compile(String.format(BLUEPRINTR, "(.+)", "(.+)")); @Override public String toString() { - return String.format(blueprint, moduleName, instanceName); + return String.format(BLUEPRINT, moduleName, instanceName); } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((instanceName == null) ? 0 : instanceName.hashCode()); - result = prime * result + ((moduleName == null) ? 0 : moduleName.hashCode()); + result = prime * result + (instanceName == null ? 0 : instanceName.hashCode()); + result = prime * result + (moduleName == null ? 0 : moduleName.hashCode()); return result; } @Override public boolean equals(final Object obj) { - if (this == obj){ + if (this == obj) { return true; } - if (obj == null){ + if (obj == null) { return false; } - if (getClass() != obj.getClass()){ + if (getClass() != obj.getClass()) { return false; } ServiceInstance other = (ServiceInstance) obj; if (instanceName == null) { - if (other.instanceName != null){ + if (other.instanceName != null) { return false; } - } else if (!instanceName.equals(other.instanceName)){ + } else if (!instanceName.equals(other.instanceName)) { return false; } if (moduleName == null) { - if (other.moduleName != null){ + if (other.moduleName != null) { return false; } - } else if (!moduleName.equals(other.moduleName)){ + } else if (!moduleName.equals(other.moduleName)) { return false; } return true; @@ -281,5 +285,4 @@ public final class Services { return new ServiceInstance(ObjectNameUtil.getFactoryName(on), ObjectNameUtil.getInstanceName(on)); } } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreActivator.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreActivator.java index 8c95a18383..0578b42701 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreActivator.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreActivator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -29,7 +29,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Start yang store service and the XML config manager facade + * Start yang store service and the XML config manager facade. */ public class YangStoreActivator implements BundleActivator { @@ -47,63 +47,67 @@ public class YangStoreActivator implements BundleActivator { LOG.debug("ConfigPersister starting"); this.context = context; - final ServiceTrackerCustomizer schemaServiceTrackerCustomizer = new ServiceTrackerCustomizer() { + final ServiceTrackerCustomizer schemaServiceTrackerCustomizer = + new ServiceTrackerCustomizer() { private final AtomicBoolean alreadyStarted = new AtomicBoolean(false); @Override public YangStoreService addingService(final ServiceReference reference) { LOG.debug("Got addingService(SchemaContextProvider) event"); - if((reference.getProperty(SchemaSourceProvider.class.getName()) == null) && - (reference.getProperty(BindingRuntimeContext.class.getName()) == null)) { + if (reference.getProperty(SchemaSourceProvider.class.getName()) == null + && reference.getProperty(BindingRuntimeContext.class.getName()) == null) { LOG.debug("SchemaContextProvider not from config-manager. Ignoring"); return null; } // Yang store service should not be registered multiple times - if(!this.alreadyStarted.compareAndSet(false, true)) { + if (!this.alreadyStarted.compareAndSet(false, true)) { LOG.warn("Starting yang store service multiple times. Received new service {}", reference); throw new RuntimeException("Starting yang store service multiple times"); } - final SchemaContextProvider schemaContextProvider = reference.getBundle().getBundleContext().getService(reference); + final SchemaContextProvider schemaContextProvider = reference.getBundle().getBundleContext() + .getService(reference); final Object sourceProvider = Preconditions.checkNotNull( - reference.getProperty(SchemaSourceProvider.class.getName()), "Source provider not found"); + reference.getProperty(SchemaSourceProvider.class.getName()), "Source provider not found"); Preconditions.checkArgument(sourceProvider instanceof SchemaSourceProvider); // TODO avoid cast final YangStoreService yangStoreService = new YangStoreService(schemaContextProvider, - ((SchemaSourceProvider) sourceProvider)); + (SchemaSourceProvider) sourceProvider); final BindingRuntimeContext runtimeContext = (BindingRuntimeContext) reference .getProperty(BindingRuntimeContext.class.getName()); LOG.debug("BindingRuntimeContext retrieved as {}", runtimeContext); - if(runtimeContext != null) { + if (runtimeContext != null) { yangStoreService.refresh(runtimeContext); } - YangStoreActivator.this.yangStoreServiceServiceRegistration = context.registerService(YangStoreService.class, yangStoreService, - new Hashtable<>()); + YangStoreActivator.this.yangStoreServiceServiceRegistration = context + .registerService(YangStoreService.class, yangStoreService, new Hashtable<>()); YangStoreActivator.this.configRegistryLookup = new ConfigRegistryLookupThread(yangStoreService); YangStoreActivator.this.configRegistryLookup.start(); return yangStoreService; } @Override - public void modifiedService(final ServiceReference reference, final YangStoreService service) { + public void modifiedService(final ServiceReference reference, + final YangStoreService service) { if (service == null) { return; } LOG.debug("Got modifiedService(SchemaContextProvider) event"); final BindingRuntimeContext runtimeContext = (BindingRuntimeContext) reference - .getProperty(BindingRuntimeContext.class.getName()); + .getProperty(BindingRuntimeContext.class.getName()); LOG.debug("BindingRuntimeContext retrieved as {}", runtimeContext); service.refresh(runtimeContext); } @Override - public void removedService(final ServiceReference reference, final YangStoreService service) { - if(service == null) { + public void removedService(final ServiceReference reference, + final YangStoreService service) { + if (service == null) { return; } @@ -122,10 +126,10 @@ public class YangStoreActivator implements BundleActivator { @Override public void stop(final BundleContext context) throws Exception { - if(this.configRegistryLookup != null) { + if (this.configRegistryLookup != null) { this.configRegistryLookup.interrupt(); } - if(this.osgiRegistrayion != null) { + if (this.osgiRegistrayion != null) { this.osgiRegistrayion.unregister(); } if (this.yangStoreServiceServiceRegistration != null) { @@ -135,7 +139,7 @@ public class YangStoreActivator implements BundleActivator { } /** - * Find ConfigRegistry from config manager in JMX + * Find ConfigRegistry from config manager in JMX. */ private class ConfigRegistryLookupThread extends Thread { public static final int ATTEMPT_TIMEOUT_MS = 1000; @@ -153,20 +157,21 @@ public class YangStoreActivator implements BundleActivator { ConfigRegistryJMXClient configRegistryJMXClient; ConfigRegistryJMXClient configRegistryJMXClientNoNotifications; - int i = 0; + int index = 0; // Config registry might not be present yet, but will be eventually - while(true) { + while (true) { try { configRegistryJMXClient = new ConfigRegistryJMXClient(YangStoreActivator.this.configMBeanServer); - configRegistryJMXClientNoNotifications = ConfigRegistryJMXClient.createWithoutNotifications(YangStoreActivator.this.configMBeanServer); + configRegistryJMXClientNoNotifications = ConfigRegistryJMXClient + .createWithoutNotifications(YangStoreActivator.this.configMBeanServer); break; } catch (final IllegalStateException e) { - ++i; - if (i > SILENT_ATTEMPTS) { - LOG.info("JMX client not created after {} attempts, still trying", i, e); + ++index; + if (index > SILENT_ATTEMPTS) { + LOG.info("JMX client not created after {} attempts, still trying", index, e); } else { - LOG.debug("JMX client could not be created, reattempting, try {}", i, e); + LOG.debug("JMX client could not be created, reattempting, try {}", index, e); } try { Thread.sleep(ATTEMPT_TIMEOUT_MS); @@ -179,17 +184,16 @@ public class YangStoreActivator implements BundleActivator { final ConfigRegistryJMXClient jmxClient = configRegistryJMXClient; final ConfigRegistryJMXClient jmxClientNoNotifications = configRegistryJMXClientNoNotifications; - if (i > SILENT_ATTEMPTS) { - LOG.info("Created JMX client after {} attempts", i); + if (index > SILENT_ATTEMPTS) { + LOG.info("Created JMX client after {} attempts", index); } else { - LOG.debug("Created JMX client after {} attempts", i); + LOG.debug("Created JMX client after {} attempts", index); } - final ConfigSubsystemFacadeFactory configSubsystemFacade = - new ConfigSubsystemFacadeFactory(jmxClient, jmxClientNoNotifications, this.yangStoreService); - YangStoreActivator.this.osgiRegistrayion = YangStoreActivator.this.context.registerService(ConfigSubsystemFacadeFactory.class, configSubsystemFacade, - new Hashtable<>()); + final ConfigSubsystemFacadeFactory configSubsystemFacade = new ConfigSubsystemFacadeFactory(jmxClient, + jmxClientNoNotifications, this.yangStoreService); + YangStoreActivator.this.osgiRegistrayion = YangStoreActivator.this.context + .registerService(ConfigSubsystemFacadeFactory.class, configSubsystemFacade, new Hashtable<>()); } } } - diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreContext.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreContext.java index 2f316e8780..868a5d8591 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreContext.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -17,24 +17,28 @@ import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; public interface YangStoreContext { /** - * @deprecated Use {@link #getQNamesToIdentitiesToModuleMXBeanEntries()} instead. This method return only one - * module representation even if multiple revisions are available. + * Yang store context. + * + * @deprecated Use {@link #getQNamesToIdentitiesToModuleMXBeanEntries()} + * instead. This method return only one module representation even + * if multiple revisions are available. */ @Deprecated Map> getModuleMXBeanEntryMap(); - + Map> getModuleMXBeanEntryMap(); Map> getQNamesToIdentitiesToModuleMXBeanEntries(); /** * Get all modules discovered when this snapshot was created. - * @return all modules discovered. If one module exists with two different revisions, return both. + * + * @return all modules discovered. If one module exists with two different + * revisions, return both. */ Set getModules(); String getModuleSource(ModuleIdentifier moduleIdentifier); EnumResolver getEnumResolver(); - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreService.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreService.java index cd316611f6..4eef7ee39e 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreService.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -8,7 +8,6 @@ package org.opendaylight.controller.config.facade.xml.osgi; -import com.google.common.base.Function; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; @@ -36,24 +35,25 @@ public class YangStoreService implements YangStoreContext { private final SchemaSourceProvider sourceProvider; private final ExecutorService notificationExecutor = Executors.newSingleThreadExecutor( - new ThreadFactoryBuilder().setDaemon(true).setNameFormat("yangstore-capability-notifications").build()); + new ThreadFactoryBuilder().setDaemon(true).setNameFormat("yangstore-capability-notifications").build()); /** - * Guarded by explicit lock to allow for properly synchronizing the initial notification and modification - * of the listener set. + * Guarded by explicit lock to allow for properly synchronizing the initial + * notification and modification of the listener set. */ @GuardedBy("listeners") private final Set listeners = new HashSet<>(); /** - * This is the latest snapshot. Some of its state is always initialized, but the MXBean maps potentially cause - * recomputation. Accessing those two specific methods needs to re-check whether the snapshot has changed - * asynchronously and retry if it didi. + * This is the latest snapshot. Some of its state is always initialized, but the + * MXBean maps potentially cause recomputation. Accessing those two specific + * methods needs to re-check whether the snapshot has changed asynchronously and + * retry if it didi. */ private volatile YangStoreSnapshot snap; public YangStoreService(final SchemaContextProvider schemaContextProvider, - final SchemaSourceProvider sourceProvider) { + final SchemaSourceProvider sourceProvider) { this.sourceProvider = sourceProvider; } @@ -107,12 +107,7 @@ public class YangStoreService implements YangStoreContext { final YangStoreSnapshot next = new YangStoreSnapshot(runtimeContext, this.sourceProvider); final YangStoreSnapshot previous = this.snap; this.snap = next; - this.notificationExecutor.submit(new Runnable() { - @Override - public void run() { - notifyListeners(previous, next); - } - }); + this.notificationExecutor.submit(() -> notifyListeners(previous, next)); } public AutoCloseable registerModuleListener(final ModuleListener listener) { @@ -120,17 +115,15 @@ public class YangStoreService implements YangStoreContext { synchronized (this.listeners) { if (context != null) { - listener.onCapabilitiesChanged(toCapabilities(context.getModules(), context), Collections.emptySet()); + listener.onCapabilitiesChanged(toCapabilities(context.getModules(), context), + Collections.emptySet()); } this.listeners.add(listener); } - return new AutoCloseable() { - @Override - public void close() { - synchronized (YangStoreService.this.listeners) { - YangStoreService.this.listeners.remove(listener); - } + return () -> { + synchronized (YangStoreService.this.listeners) { + YangStoreService.this.listeners.remove(listener); } }; } @@ -152,11 +145,7 @@ public class YangStoreService implements YangStoreContext { } private static Set toCapabilities(final Set modules, final YangStoreContext current) { - return ImmutableSet.copyOf(Collections2.transform(modules, new Function() { - @Override - public Capability apply(final Module input) { - return new YangModuleCapability(input, current.getModuleSource(input)); - } - })); + return ImmutableSet.copyOf(Collections2.transform(modules, + input -> new YangModuleCapability(input, current.getModuleSource(input)))); } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreSnapshot.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreSnapshot.java index 36f3208710..c4ca3e74db 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreSnapshot.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreSnapshot.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -42,11 +42,11 @@ import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -final class YangStoreSnapshot implements YangStoreContext, EnumResolver { +public final class YangStoreSnapshot implements YangStoreContext, EnumResolver { private static final class MXBeans { private final Map> moduleMXBeanEntryMap; - private final Map> qNamesToIdentitiesToModuleMXBeanEntries; + private final Map> namesToIdentitiesToModuleMXBeanEntries; MXBeans(final SchemaContext schemaContext) { LOG.trace("Resolved modules:{}", schemaContext.getModules()); @@ -63,7 +63,7 @@ final class YangStoreSnapshot implements YangStoreContext, EnumResolver { .create(module, packageName, knownSEITracker); for (final Entry sieEntry : namesToSIEntries.entrySet()) { // merge value into qNamesToSIEs - if (qNamesToSIEs.containsKey(sieEntry.getKey()) == false) { + if (!qNamesToSIEs.containsKey(sieEntry.getKey())) { qNamesToSIEs.put(sieEntry.getKey(), sieEntry.getValue()); } else { throw new IllegalStateException("Cannot add two SIE with same qname " @@ -74,7 +74,8 @@ final class YangStoreSnapshot implements YangStoreContext, EnumResolver { final Map> moduleMXBeanEntryMap = Maps.newHashMap(); - final Map> qNamesToIdentitiesToModuleMXBeanEntries = new HashMap<>(); + final Map> qNamesToIdentitiesToModuleMXBeanEntries = new HashMap<>(); for (final Module module : schemaContext.getModules()) { @@ -92,7 +93,8 @@ final class YangStoreSnapshot implements YangStoreContext, EnumResolver { qNamesToIdentitiesToModuleMXBeanEntries.put(qName, namesToMBEs); } this.moduleMXBeanEntryMap = Collections.unmodifiableMap(moduleMXBeanEntryMap); - this.qNamesToIdentitiesToModuleMXBeanEntries = Collections.unmodifiableMap(qNamesToIdentitiesToModuleMXBeanEntries); + this.namesToIdentitiesToModuleMXBeanEntries = + Collections.unmodifiableMap(qNamesToIdentitiesToModuleMXBeanEntries); } } @@ -136,7 +138,7 @@ final class YangStoreSnapshot implements YangStoreContext, EnumResolver { @Override public Map> getQNamesToIdentitiesToModuleMXBeanEntries() { - return getMXBeans().qNamesToIdentitiesToModuleMXBeanEntries; + return getMXBeans().namesToIdentitiesToModuleMXBeanEntries; } @Override @@ -150,13 +152,13 @@ final class YangStoreSnapshot implements YangStoreContext, EnumResolver { @Override public String getModuleSource(final org.opendaylight.yangtools.yang.model.api.ModuleIdentifier moduleIdentifier) { - final CheckedFuture source = this.sourceProvider.getSource( - SourceIdentifier.create(moduleIdentifier.getName(), Optional.fromNullable( - QName.formattedRevision(moduleIdentifier.getRevision())))); + final CheckedFuture source = this.sourceProvider + .getSource(SourceIdentifier.create(moduleIdentifier.getName(), + Optional.fromNullable(QName.formattedRevision(moduleIdentifier.getRevision())))); try { final YangTextSchemaSource yangTextSchemaSource = source.checkedGet(); - try(InputStream inStream = yangTextSchemaSource.openStream()) { + try (InputStream inStream = yangTextSchemaSource.openStream()) { return new String(ByteStreams.toByteArray(inStream), StandardCharsets.UTF_8); } } catch (SchemaSourceException | IOException e) { @@ -193,7 +195,9 @@ final class YangStoreSnapshot implements YangStoreContext, EnumResolver { Preconditions.checkState(this.bindingContextProvider != null, "Binding context provider was not set yet"); final BiMap enumMapping = this.bindingContextProvider.getEnumMapping(enumClass); final String javaName = enumMapping.get(enumYangValue); - return Preconditions.checkNotNull(javaName, "Unable to resolve enum value %s for enum class %s with assumed enum mapping: %s", enumYangValue, enumClass, enumMapping); + return Preconditions.checkNotNull(javaName, + "Unable to resolve enum value %s for enum class %s with assumed enum mapping: %s", enumYangValue, + enumClass, enumMapping); } @Override diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/rpc/InstanceRuntimeRpc.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/rpc/InstanceRuntimeRpc.java index c513100aea..e0c78f8d48 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/rpc/InstanceRuntimeRpc.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/rpc/InstanceRuntimeRpc.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -61,9 +61,9 @@ public final class InstanceRuntimeRpc { .get(configDefEntry.getKey()); configDefEntry.getValue().resolveValue(attributeResolvingStrategy, configDefEntry.getKey()); - configDefEntry.getValue().setJmxName( - yangToAttrConfig.get(configDefEntry.getKey()).getUpperCaseCammelCase()); - } catch (final Exception e) { + configDefEntry.getValue() + .setJmxName(yangToAttrConfig.get(configDefEntry.getKey()).getUpperCaseCammelCase()); + } catch (final DocumentedException e) { throw new IllegalStateException("Unable to resolve value " + configDefEntry.getValue() + " to attribute " + configDefEntry.getKey(), e); } @@ -75,7 +75,7 @@ public final class InstanceRuntimeRpc { // FIXME add identity map to runtime data Map strats = new ObjectXmlReader().prepareReading(yangToAttrConfig, - Collections.> emptyMap()); + Collections.>emptyMap()); for (Entry readStratEntry : strats.entrySet()) { List configNodes = configRootNode.getChildElements(readStratEntry.getKey()); @@ -94,5 +94,4 @@ public final class InstanceRuntimeRpc { public AttributeIfc getReturnType() { return rpc.getReturnType(); } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/rpc/RuntimeRpcElementResolved.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/rpc/RuntimeRpcElementResolved.java index cd3d72a5c5..a63114c9ad 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/rpc/RuntimeRpcElementResolved.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/rpc/RuntimeRpcElementResolved.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -23,7 +23,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.modules.Module; /** - * Represents parsed xpath to runtime bean instance + * Represents parsed xpath to runtime bean instance. */ public final class RuntimeRpcElementResolved { private final String moduleName; @@ -33,9 +33,9 @@ public final class RuntimeRpcElementResolved { private final Map additionalAttributes; private RuntimeRpcElementResolved(String namespace, String moduleName, String instanceName, String runtimeBeanName, - Map additionalAttributes) { + Map additionalAttributes) { this.moduleName = Preconditions.checkNotNull(moduleName, "Module name"); - this.instanceName = Preconditions.checkNotNull(instanceName, "Instance name"); + this.instanceName = Preconditions.checkNotNull(instanceName, "Instance name"); this.additionalAttributes = additionalAttributes; this.namespace = Preconditions.checkNotNull(namespace, "Namespace"); this.runtimeBeanName = Preconditions.checkNotNull(runtimeBeanName, "Runtime bean name"); @@ -75,52 +75,60 @@ public final class RuntimeRpcElementResolved { } /** - * Pattern for an absolute instance identifier xpath pointing to a runtime bean instance e.g: + * Pattern for an absolute instance identifier xpath pointing to a runtime bean. + * For instance e.g: + * *
      * /modules/module[name=instanceName][type=moduleType]
      * 
+ * + *

* or + * *

      * /a:modules/a:module[a:name=instanceName][a:type=moduleType]
      * 
*/ - private static final String xpathPatternBlueprint = - "/" + getRegExForPrefixedName(Modules.QNAME.getLocalName())+ "/" + getRegExForPrefixedName(Module.QNAME.getLocalName()) + private static final String XPATH_PATTERN_BLUEPRINT = "/" + getRegExForPrefixedName(Modules.QNAME.getLocalName()) + + "/" + getRegExForPrefixedName(Module.QNAME.getLocalName()) - + "\\[" - + "(?" + getRegExForPrefixedName(XmlMappingConstants.TYPE_KEY) + "|" + getRegExForPrefixedName(XmlMappingConstants.NAME_KEY) + ")" - + "=('|\")?(?[^'\"\\]]+)('|\")?" - + "( and |\\]\\[)" - + "(?" + getRegExForPrefixedName(XmlMappingConstants.TYPE_KEY) + "|" + getRegExForPrefixedName(XmlMappingConstants.NAME_KEY) + ")" - + "=('|\")?(?[^'\"\\]]+)('|\")?" - + "\\]" + + "\\[" + "(?" + getRegExForPrefixedName(XmlMappingConstants.TYPE_KEY) + "|" + + getRegExForPrefixedName(XmlMappingConstants.NAME_KEY) + ")" + "=('|\")?(?[^'\"\\]]+)('|\")?" + + "( and |\\]\\[)" + "(?" + getRegExForPrefixedName(XmlMappingConstants.TYPE_KEY) + "|" + + getRegExForPrefixedName(XmlMappingConstants.NAME_KEY) + ")" + "=('|\")?(?[^'\"\\]]+)('|\")?" + + "\\]" - + "(?.*)"; + + "(?.*)"; /** - * Return reg ex that matches either the name with or without a prefix + * Return reg ex that matches either the name with or without a prefix. */ private static String getRegExForPrefixedName(final String name) { return "([^:]+:)?" + name; } - private static final Pattern xpathPattern = Pattern.compile(xpathPatternBlueprint); + private static final Pattern XPATH_PATTERN = Pattern.compile(XPATH_PATTERN_BLUEPRINT); /** - * Pattern for additional path elements inside xpath for instance identifier pointing to an inner runtime bean e.g: + * Pattern for additional path elements inside xpath for instance identifier + * pointing to an inner runtime bean. E.g: + * *
      * /modules/module[name=instanceName and type=moduleType]/inner[key=b]
      * 
*/ - private static final String additionalPatternBlueprint = getRegExForPrefixedName("(?.+)") + "\\[(?" + getRegExForPrefixedName("(.+)") + ")=('|\")?(?[^'\"\\]]+)('|\")?\\]"; - private static final Pattern additionalPattern = Pattern.compile(additionalPatternBlueprint); + private static final String ADDITIONAL_PATTERN_BLUEPRINT = getRegExForPrefixedName("(?.+)") + + "\\[(?" + getRegExForPrefixedName("(.+)") + + ")=('|\")?(?[^'\"\\]]+)('|\")?\\]"; + private static final Pattern ADDITIONAL_PATTERN = Pattern.compile(ADDITIONAL_PATTERN_BLUEPRINT); public static RuntimeRpcElementResolved fromXpath(String xpath, String elementName, String namespace) { - Matcher matcher = xpathPattern.matcher(xpath); + Matcher matcher = XPATH_PATTERN.matcher(xpath); Preconditions.checkState(matcher.matches(), "Node %s with value '%s' not in required form on rpc element %s, required format is %s", - //TODO refactor this string, and/or unify with RPR.CONTEXT_INSTANCE from netconf - "context-instance", xpath, elementName, xpathPatternBlueprint); + // TODO refactor this string, and/or unify with RPR.CONTEXT_INSTANCE from + // netconf + "context-instance", xpath, elementName, XPATH_PATTERN_BLUEPRINT); PatternGroupResolver groups = new PatternGroupResolver(matcher.group("key1"), matcher.group("value1"), matcher.group("value2"), matcher.group("additional")); @@ -136,11 +144,13 @@ public final class RuntimeRpcElementResolved { private static final class PatternGroupResolver { - private final String key1, value1, value2; + private final String key1; + private final String value1; + private final String value2; private final String additional; private String runtimeBeanYangName; - PatternGroupResolver(String key1, String value1, String value2, String additional) { + PatternGroupResolver(String key1, String value1, String value2, String additional) { this.key1 = Preconditions.checkNotNull(key1); this.value1 = Preconditions.checkNotNull(value1); this.value2 = Preconditions.checkNotNull(value2); @@ -155,21 +165,19 @@ public final class RuntimeRpcElementResolved { return key1.contains(XmlMappingConstants.NAME_KEY) ? value1 : value2; } - Map getAdditionalKeys(String elementName, String moduleName) { HashMap additionalAttributes = Maps.newHashMap(); runtimeBeanYangName = moduleName; for (String additionalKeyValue : additional.split("/")) { - if (Strings.isNullOrEmpty(additionalKeyValue)){ + if (Strings.isNullOrEmpty(additionalKeyValue)) { continue; } - Matcher matcher = additionalPattern.matcher(additionalKeyValue); - Preconditions - .checkState( - matcher.matches(), - "Attribute %s not in required form on rpc element %s, required format for additional attributes is: %s", - additionalKeyValue, elementName, additionalPatternBlueprint); + Matcher matcher = ADDITIONAL_PATTERN.matcher(additionalKeyValue); + Preconditions.checkState(matcher.matches(), + "Attribute %s not in required form on rpc element %s," + + " required format for additional attributes is: %s", + additionalKeyValue, elementName, ADDITIONAL_PATTERN_BLUEPRINT); String name = matcher.group("additionalKey"); runtimeBeanYangName = name; additionalAttributes.put(name, matcher.group("additionalValue")); @@ -178,7 +186,7 @@ public final class RuntimeRpcElementResolved { } private String getRuntimeBeanYangName() { - Preconditions.checkState(runtimeBeanYangName!=null); + Preconditions.checkState(runtimeBeanYangName != null); return runtimeBeanYangName; } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/runtime/InstanceRuntime.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/runtime/InstanceRuntime.java index 96287c7d16..c0532317d8 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/runtime/InstanceRuntime.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/runtime/InstanceRuntime.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -9,7 +9,6 @@ package org.opendaylight.controller.config.facade.xml.runtime; import com.google.common.base.Optional; -import com.google.common.base.Predicate; import com.google.common.collect.Collections2; import com.google.common.collect.Sets; import java.util.Map; @@ -24,9 +23,6 @@ import org.w3c.dom.Element; public class InstanceRuntime { - /** - * - */ private static final String KEY_ATTRIBUTE_KEY = "key"; private final InstanceConfig instanceMapping; @@ -41,56 +37,49 @@ public class InstanceRuntime { } /** - * Finds all children runtime beans, same properties and values as current - * root + any number of additional properties + * Finds all children runtime beans, same properties and values as current root + * + any number of additional properties. */ private Set findChildren(ObjectName innerRootBean, Set childRbeOns) { final Map wantedProperties = innerRootBean.getKeyPropertyList(); - return Sets.newHashSet(Collections2.filter(childRbeOns, new Predicate() { - - @Override - public boolean apply(ObjectName on) { - Map localProperties = on.getKeyPropertyList(); - for (Entry propertyEntry : wantedProperties.entrySet()) { - if (!localProperties.containsKey(propertyEntry.getKey())){ - return false; - } - if (!localProperties.get(propertyEntry.getKey()).equals(propertyEntry.getValue())){ - return false; - } - if (localProperties.size() <= wantedProperties.size()){ - return false; - } + return Sets.newHashSet(Collections2.filter(childRbeOns, on -> { + Map localProperties = on.getKeyPropertyList(); + for (Entry propertyEntry : wantedProperties.entrySet()) { + if (!localProperties.containsKey(propertyEntry.getKey())) { + return false; + } + if (!localProperties.get(propertyEntry.getKey()).equals(propertyEntry.getValue())) { + return false; + } + if (localProperties.size() <= wantedProperties.size()) { + return false; } - return true; } + return true; })); } /** - * Finds next level root runtime beans, beans that have the same properties - * as current root + one additional + * Finds next level root runtime beans, beans that have the same properties as + * current root + one additional. */ private Set getRootBeans(Set childRbeOns, final String string, final int keyListSize) { - return Sets.newHashSet(Collections2.filter(childRbeOns, new Predicate() { - - @Override - public boolean apply(ObjectName on) { - if (on.getKeyPropertyList().size() != keyListSize + 1){ - return false; - } - return on.getKeyPropertyList().containsKey(string); + return Sets.newHashSet(Collections2.filter(childRbeOns, on -> { + if (on.getKeyPropertyList().size() != keyListSize + 1) { + return false; } + return on.getKeyPropertyList().containsKey(string); })); } - public Element toXml(ObjectName rootOn, Set childRbeOns, Document document, Element parentElement, String namespace, final EnumResolver enumResolver) { + public Element toXml(ObjectName rootOn, Set childRbeOns, Document document, Element parentElement, + String namespace, final EnumResolver enumResolver) { return toXml(rootOn, childRbeOns, document, null, parentElement, namespace, enumResolver); } public Element toXml(ObjectName rootOn, Set childRbeOns, Document document, String instanceIndex, - Element parentElement, String namespace, final EnumResolver enumResolver) { + Element parentElement, String namespace, final EnumResolver enumResolver) { Element xml = instanceMapping.toXml(rootOn, namespace, document, parentElement, enumResolver); if (instanceIndex != null) { @@ -98,8 +87,8 @@ public class InstanceRuntime { } for (Entry childMappingEntry : childrenMappings.entrySet()) { - Set innerRootBeans = getRootBeans(childRbeOns, childMappingEntry.getKey(), rootOn - .getKeyPropertyList().size()); + Set innerRootBeans = getRootBeans(childRbeOns, childMappingEntry.getKey(), + rootOn.getKeyPropertyList().size()); for (ObjectName objectName : innerRootBeans) { Set innerChildRbeOns = findChildren(objectName, childRbeOns); @@ -108,13 +97,11 @@ public class InstanceRuntime { String elementName = jmxToYangChildRbeMapping.get(childMappingEntry.getKey()); Element innerXml = XmlUtil.createElement(document, elementName, Optional.of(namespace)); - childMappingEntry.getValue().toXml(objectName, innerChildRbeOns, document, - runtimeInstanceIndex, innerXml, namespace, enumResolver); + childMappingEntry.getValue().toXml(objectName, innerChildRbeOns, document, runtimeInstanceIndex, + innerXml, namespace, enumResolver); xml.appendChild(innerXml); } } - return xml; } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/runtime/ModuleRuntime.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/runtime/ModuleRuntime.java index 040950f3c3..67fd458db7 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/runtime/ModuleRuntime.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/runtime/ModuleRuntime.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -27,15 +27,15 @@ public class ModuleRuntime { private ObjectName findRoot(Collection runtimeBeanOns) { for (ObjectName objectName : runtimeBeanOns) { - if (objectName.getKeyPropertyList().size() == 3){ + if (objectName.getKeyPropertyList().size() == 3) { return objectName; } } throw new IllegalStateException("Root runtime bean not found among " + runtimeBeanOns); } - public Element toXml(String namespace, Collection runtimeBeanOns, - Document document, ModuleConfig moduleConfig, ObjectName configBeanON, final EnumResolver enumResolver) { + public Element toXml(String namespace, Collection runtimeBeanOns, Document document, + ModuleConfig moduleConfig, ObjectName configBeanON, final EnumResolver enumResolver) { Element moduleElement = moduleConfig.toXml(configBeanON, document, namespace, enumResolver); @@ -49,5 +49,4 @@ public class ModuleRuntime { return moduleElement; } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/runtime/Runtime.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/runtime/Runtime.java index f58a9d8d37..1a5d105314 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/runtime/Runtime.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/runtime/Runtime.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -52,19 +52,20 @@ public class Runtime { multimap.put(instanceName, objectName); } - return retVal; } - public Element toXml(Set instancesToMap, Set configBeans, Document document, final EnumResolver enumResolver) { + public Element toXml(Set instancesToMap, Set configBeans, Document document, + final EnumResolver enumResolver) { Element root = XmlUtil.createElement(document, XmlMappingConstants.DATA_KEY, Optional.absent()); - Element modulesElement = XmlUtil.createElement(document, XmlMappingConstants.MODULES_KEY, Optional.of(XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG)); + Element modulesElement = XmlUtil.createElement(document, XmlMappingConstants.MODULES_KEY, + Optional.of(XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG)); root.appendChild(modulesElement); Map> moduleToRuntimeInstance = mapInstancesToModules(instancesToMap); - Map>> moduleToConfigInstance = Config - .getMappedInstances(configBeans, moduleConfigs); + Map>> moduleToConfigInstance = Config.getMappedInstances(configBeans, + moduleConfigs); for (String localNamespace : moduleConfigs.keySet()) { @@ -78,7 +79,7 @@ public class Runtime { Element runtimeXml; ModuleConfig moduleConfig = moduleConfigs.get(localNamespace).get(moduleName); - if(instanceToRbe==null || !instanceToRbe.containsKey(instanceName)) { + if (instanceToRbe == null || !instanceToRbe.containsKey(instanceName)) { runtimeXml = moduleConfig.toXml(instanceON, document, localNamespace, enumResolver); } else { ModuleRuntime moduleRuntime = moduleRuntimes.get(localNamespace).get(moduleName); @@ -90,8 +91,6 @@ public class Runtime { } } - return root; } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/DeleteEditConfigStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/DeleteEditConfigStrategy.java index 555af1eb86..08d9d21cdd 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/DeleteEditConfigStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/DeleteEditConfigStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -23,28 +23,25 @@ public class DeleteEditConfigStrategy extends AbstractEditConfigStrategy { private static final Logger LOG = LoggerFactory.getLogger(DeleteEditConfigStrategy.class); - @Override void handleMissingInstance(Map configuration, ConfigTransactionClient ta, - String module, String instance, ServiceRegistryWrapper services) throws - ConfigHandlingException { - throw new ConfigHandlingException(String.format("Unable to delete %s : %s , ServiceInstance not found", module, instance), - DocumentedException.ErrorType.APPLICATION, - DocumentedException.ErrorTag.OPERATION_FAILED, + String module, String instance, ServiceRegistryWrapper services) throws ConfigHandlingException { + throw new ConfigHandlingException( + String.format("Unable to delete %s : %s , ServiceInstance not found", module, instance), + DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, DocumentedException.ErrorSeverity.ERROR); } @Override - void executeStrategy(Map configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) throws - ConfigHandlingException { + void executeStrategy(Map configuration, ConfigTransactionClient ta, ObjectName on, + ServiceRegistryWrapper services) throws ConfigHandlingException { try { ta.destroyModule(on); LOG.debug("ServiceInstance {} deleted successfully", on); } catch (InstanceNotFoundException e) { throw new ConfigHandlingException( String.format("Unable to delete %s because of exception %s" + on, e.getMessage()), - DocumentedException.ErrorType.APPLICATION, - DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, DocumentedException.ErrorSeverity.ERROR); } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/EditStrategyType.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/EditStrategyType.java index 9954592b0a..bf11f2a137 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/EditStrategyType.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/EditStrategyType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -19,7 +19,7 @@ public enum EditStrategyType { // additional per element delete, remove, recreate; - private static final Set defaultStrats = EnumSet.of(merge, replace, none); + private static final Set DEFAULT_STRATS = EnumSet.of(merge, replace, none); public static EditStrategyType getDefaultStrategy() { return merge; @@ -27,50 +27,50 @@ public enum EditStrategyType { public boolean isEnforcing() { switch (this) { - case merge: - case none: - case remove: - case delete: - case recreate: - return false; - case replace: - return true; + case merge: + case none: + case remove: + case delete: + case recreate: + return false; + case replace: + return true; - default: - throw new IllegalStateException("Default edit strategy can be only of value " + defaultStrats + " but was " - + this); + default: + throw new IllegalStateException( + "Default edit strategy can be only of value " + DEFAULT_STRATS + " but was " + this); } } + public static void compareParsedStrategyToDefaultEnforcing(EditStrategyType parsedStrategy, - EditStrategyType defaultStrategy) throws OperationNotPermittedException { + EditStrategyType defaultStrategy) throws OperationNotPermittedException { if (defaultStrategy.isEnforcing()) { - if (parsedStrategy != defaultStrategy){ - throw new OperationNotPermittedException(String.format("With " - + defaultStrategy - + " as default-operation operations on module elements are not permitted since the default option is restrictive"), - DocumentedException.ErrorType.APPLICATION, - DocumentedException.ErrorTag.OPERATION_FAILED, + if (parsedStrategy != defaultStrategy) { + throw new OperationNotPermittedException(String.format("With " + defaultStrategy + + " as default-operation operations on module elements are not permitted" + + "since the default option is restrictive"), + DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, DocumentedException.ErrorSeverity.ERROR); } } - } + public EditConfigStrategy getFittingStrategy() { switch (this) { - case merge: - return new MergeEditConfigStrategy(); - case replace: - return new ReplaceEditConfigStrategy(); - case delete: - return new DeleteEditConfigStrategy(); - case remove: - return new RemoveEditConfigStrategy(); - case recreate: - return new ReCreateEditConfigStrategy(); - case none: - return new NoneEditConfigStrategy(); - default: - throw new UnsupportedOperationException("Unimplemented edit config strategy" + this); + case merge: + return new MergeEditConfigStrategy(); + case replace: + return new ReplaceEditConfigStrategy(); + case delete: + return new DeleteEditConfigStrategy(); + case remove: + return new RemoveEditConfigStrategy(); + case recreate: + return new ReCreateEditConfigStrategy(); + case none: + return new NoneEditConfigStrategy(); + default: + throw new UnsupportedOperationException("Unimplemented edit config strategy" + this); } } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/MergeEditConfigStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/MergeEditConfigStrategy.java index 5f0b23b9ff..ebd98f8c1f 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/MergeEditConfigStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/MergeEditConfigStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -29,25 +29,22 @@ public class MergeEditConfigStrategy extends AbstractEditConfigStrategy { private static final Logger LOG = LoggerFactory.getLogger(MergeEditConfigStrategy.class); public MergeEditConfigStrategy() { - } @Override void handleMissingInstance(Map configuration, ConfigTransactionClient ta, - String module, String instance, ServiceRegistryWrapper services) throws - ConfigHandlingException { - throw new ConfigHandlingException( - String.format("Unable to handle missing instance, no missing instances should appear at this point, missing: %s : %s ", - module, - instance), - DocumentedException.ErrorType.APPLICATION, - DocumentedException.ErrorTag.OPERATION_FAILED, - DocumentedException.ErrorSeverity.ERROR); + String module, String instance, ServiceRegistryWrapper services) throws ConfigHandlingException { + throw new ConfigHandlingException(String.format( + "Unable to handle missing instance, no missing instances should " + + "appear at this point, missing: %s : %s ", + module, instance), DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, DocumentedException.ErrorSeverity.ERROR); } @Override - void executeStrategy(Map configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) throws - ConfigHandlingException { + @SuppressWarnings("IllegalCatch") + void executeStrategy(Map configuration, ConfigTransactionClient ta, ObjectName on, + ServiceRegistryWrapper services) throws ConfigHandlingException { for (Entry configAttributeEntry : configuration.entrySet()) { try { @@ -61,14 +58,15 @@ public class MergeEditConfigStrategy extends AbstractEditConfigStrategy { Object toBeMergedIn = ace.getResolvedValue().get(); // Get the existing values so we can merge the new values with them. Attribute currentAttribute = ta.getAttribute(on, ace.getJmxName()); - Object oldValue = (currentAttribute != null ? currentAttribute.getValue() : null); + Object oldValue = currentAttribute != null ? currentAttribute.getValue() : null; // Merge value with currentValue toBeMergedIn = merge(oldValue, toBeMergedIn); ta.setAttribute(on, ace.getJmxName(), new Attribute(ace.getJmxName(), toBeMergedIn)); LOG.debug("Attribute {} set to {} for {}", configAttributeEntry.getKey(), toBeMergedIn, on); - } catch (Exception e) { - LOG.error("Error while merging objectnames of {}", on, e); - throw new ConfigHandlingException(String.format("Unable to set attributes for %s, Error with attribute %s : %s ", + } catch (RuntimeException e) { + LOG.error("Error while merging object names of {}", on, e); + throw new ConfigHandlingException(String.format("Unable to set attributes for %s, " + + "Error with attribute %s : %s ", on, configAttributeEntry.getKey(), configAttributeEntry.getValue()), @@ -80,9 +78,8 @@ public class MergeEditConfigStrategy extends AbstractEditConfigStrategy { } /** - * Merge value into current value - * Currently, this is only implemented for arrays of ObjectNames, but that is the - * most common case for which it is needed. + * Merge value into current value Currently, this is only implemented for arrays + * of ObjectNames, but that is the most common case for which it is needed. */ protected Object merge(Object oldValue, Object toBeMergedIn) { if (oldValue instanceof ObjectName[] && toBeMergedIn instanceof ObjectName[]) { @@ -92,24 +89,27 @@ public class MergeEditConfigStrategy extends AbstractEditConfigStrategy { } /** - * Merge value into current values - * This implements for arrays of ObjectNames, but that is the - * most common case for which it is needed. + * Merge value into current values This implements for arrays of ObjectNames, + * but that is the most common case for which it is needed. * - * @param oldValue - the new values to be merged into existing values - * @param toBeMergedIn - the existing values + * @param oldValue + * - the new values to be merged into existing values + * @param toBeMergedIn + * - the existing values * - * @return an ObjectName[] consisting the elements of currentValue with an elements from values not already present in currentValue added + * @return an ObjectName[] consisting the elements of currentValue with an + * elements from values not already present in currentValue added * */ protected ObjectName[] mergeObjectNameArrays(ObjectName[] oldValue, ObjectName[] toBeMergedIn) { List newValueList = new ArrayList<>(); newValueList.addAll(asList(oldValue)); /* - It is guaranteed that old values do not contain transaction name. - Since toBeMergedIn is filled using service references translated by ServiceRegistryWrapper, it - is also guaranteed that this list will not contain transaction names. - Run through the list of values to be merged. If we don't have them already, add them to the list. + * It is guaranteed that old values do not contain transaction name. Since + * toBeMergedIn is filled using service references translated by + * ServiceRegistryWrapper, it is also guaranteed that this list will not contain + * transaction names. Run through the list of values to be merged. If we don't + * have them already, add them to the list. */ for (ObjectName objName : toBeMergedIn) { if (!newValueList.contains(objName)) { diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/NoneEditConfigStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/NoneEditConfigStrategy.java index 8e38065944..b2d765d748 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/NoneEditConfigStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/NoneEditConfigStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -23,15 +23,14 @@ public class NoneEditConfigStrategy implements EditConfigStrategy { @Override public void executeConfiguration(String module, String instance, Map configuration, - ConfigTransactionClient ta, ServiceRegistryWrapper services) throws - ConfigHandlingException { - if(configuration != null && !configuration.isEmpty()) { + ConfigTransactionClient ta, ServiceRegistryWrapper services) throws ConfigHandlingException { + if (configuration != null && !configuration.isEmpty()) { for (Map.Entry attrEntry : configuration.entrySet()) { - if(attrEntry.getValue().getEditStrategy().isPresent()) { - final Map partialConfig = - Collections.singletonMap(attrEntry.getKey(), attrEntry.getValue()); - attrEntry.getValue().getEditStrategy().get().getFittingStrategy() - .executeConfiguration(module, instance, partialConfig, ta, services); + if (attrEntry.getValue().getEditStrategy().isPresent()) { + final Map partialConfig = Collections + .singletonMap(attrEntry.getKey(), attrEntry.getValue()); + attrEntry.getValue().getEditStrategy().get().getFittingStrategy().executeConfiguration(module, + instance, partialConfig, ta, services); } else { LOG.debug("Skipping configuration element for {}:{}:{}", module, instance, attrEntry.getKey()); } @@ -40,5 +39,4 @@ public class NoneEditConfigStrategy implements EditConfigStrategy { LOG.debug("Skipping configuration element for {}:{}", module, instance); } } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReCreateEditConfigStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReCreateEditConfigStrategy.java index 8df51a2a8f..4000253e1d 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReCreateEditConfigStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReCreateEditConfigStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Brocade Communications Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016, 2017 Brocade Communications Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -17,7 +17,8 @@ import org.opendaylight.controller.config.util.ConfigTransactionClient; import org.opendaylight.controller.config.util.xml.DocumentedException; /** - * Edit strategy that forces re-creation of a module instance even if the config didn't change. + * Edit strategy that forces re-creation of a module instance even if the config + * didn't change. * * @author Thomas Pantelis */ @@ -28,8 +29,7 @@ public class ReCreateEditConfigStrategy extends AbstractEditConfigStrategy { String module, String instance, ServiceRegistryWrapper services) throws ConfigHandlingException { throw new ConfigHandlingException( String.format("Unable to recreate %s : %s, Existing module instance not found", module, instance), - DocumentedException.ErrorType.APPLICATION, - DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, DocumentedException.ErrorSeverity.ERROR); } @@ -38,10 +38,9 @@ public class ReCreateEditConfigStrategy extends AbstractEditConfigStrategy { ObjectName objectName, ServiceRegistryWrapper services) throws ConfigHandlingException { try { ta.reCreateModule(objectName); - } catch(InstanceNotFoundException e) { + } catch (InstanceNotFoundException e) { throw new ConfigHandlingException(String.format("Unable to recreate instance for %s", objectName), - DocumentedException.ErrorType.APPLICATION, - DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, DocumentedException.ErrorSeverity.ERROR); } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReplaceEditConfigStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReplaceEditConfigStrategy.java index 9821a8b79e..8cc2b9e68d 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReplaceEditConfigStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReplaceEditConfigStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -26,20 +26,18 @@ public class ReplaceEditConfigStrategy extends AbstractEditConfigStrategy { @Override void handleMissingInstance(Map configuration, ConfigTransactionClient ta, - String module, String instance, ServiceRegistryWrapper services) throws - ConfigHandlingException { - throw new ConfigHandlingException( - String.format("Unable to handle missing instance, no missing instances should appear at this point, missing: %s : %s ", - module, - instance), - DocumentedException.ErrorType.APPLICATION, - DocumentedException.ErrorTag.OPERATION_FAILED, - DocumentedException.ErrorSeverity.ERROR); + String module, String instance, ServiceRegistryWrapper services) throws ConfigHandlingException { + throw new ConfigHandlingException(String.format( + "Unable to handle missing instance, no missing instances should appear" + + " at this point, missing: %s : %s ", + module, instance), DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, DocumentedException.ErrorSeverity.ERROR); } @Override - void executeStrategy(Map configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) throws - ConfigHandlingException { + @SuppressWarnings("IllegalCatch") + void executeStrategy(Map configuration, ConfigTransactionClient ta, ObjectName on, + ServiceRegistryWrapper services) throws ConfigHandlingException { for (Entry configAttributeEntry : configuration.entrySet()) { try { AttributeConfigElement ace = configAttributeEntry.getValue(); @@ -47,15 +45,13 @@ public class ReplaceEditConfigStrategy extends AbstractEditConfigStrategy { if (!ace.getResolvedValue().isPresent()) { Object value = ace.getResolvedDefaultValue(); ta.setAttribute(on, ace.getJmxName(), new Attribute(ace.getJmxName(), value)); - LOG.debug("Attribute {} set to default value {} for {}", configAttributeEntry.getKey(), value, - on); + LOG.debug("Attribute {} set to default value {} for {}", configAttributeEntry.getKey(), value, on); } else { Object value = ace.getResolvedValue().get(); ta.setAttribute(on, ace.getJmxName(), new Attribute(ace.getJmxName(), value)); LOG.debug("Attribute {} set to value {} for {}", configAttributeEntry.getKey(), value, on); } - - } catch (Exception e) { + } catch (RuntimeException e) { throw new IllegalStateException("Unable to set attributes for " + on + ", Error with attribute " + configAttributeEntry.getKey() + ":" + configAttributeEntry.getValue(), e); } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/transactions/TransactionProvider.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/transactions/TransactionProvider.java index d742238ba2..a40bac9b05 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/transactions/TransactionProvider.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/transactions/TransactionProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -10,12 +10,15 @@ package org.opendaylight.controller.config.facade.xml.transactions; import com.google.common.base.Optional; import com.google.common.base.Preconditions; + import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; + import javax.management.InstanceNotFoundException; import javax.management.ObjectName; + import org.opendaylight.controller.config.api.ConflictingVersionException; import org.opendaylight.controller.config.api.ValidationException; import org.opendaylight.controller.config.api.jmx.CommitStatus; @@ -41,13 +44,14 @@ public class TransactionProvider implements AutoCloseable { } @Override + @SuppressWarnings("IllegalCatch") public synchronized void close() { for (ObjectName tx : allOpenedTransactions) { try { if (isStillOpenTransaction(tx)) { configRegistryClient.getConfigTransactionClient(tx).abortConfig(); } - } catch (final Exception e) { + } catch (final RuntimeException e) { LOG.debug("Ignoring exception while closing transaction {}", tx, e); } } @@ -56,7 +60,7 @@ public class TransactionProvider implements AutoCloseable { public synchronized Optional getTransaction() { - if (candidateTx == null){ + if (candidateTx == null) { return Optional.absent(); } @@ -71,7 +75,7 @@ public class TransactionProvider implements AutoCloseable { public synchronized Optional getReadTransaction() { - if (readTx == null){ + if (readTx == null) { return Optional.absent(); } @@ -111,7 +115,7 @@ public class TransactionProvider implements AutoCloseable { } /** - * Used for editConfig test option + * Used for editConfig test option. */ public synchronized ObjectName getTestTransaction() { ObjectName testTx = configRegistryClient.beginConfig(); @@ -120,21 +124,22 @@ public class TransactionProvider implements AutoCloseable { } /** - * Commit and notification send must be atomic + * Commit and notification send must be atomic. */ public CommitStatus commitTransaction() throws ValidationException, ConflictingVersionException { return commitTransaction(configRegistryClient); } /** - * Commit and notification send must be atomic - * @param configRegistryClient + * Commit and notification send must be atomic. */ - public synchronized CommitStatus commitTransaction(final ConfigRegistryClient configRegistryClient) throws ValidationException, ConflictingVersionException { - if (!getTransaction().isPresent()){ - //making empty commit without prior opened transaction, just return commit status with empty lists + public synchronized CommitStatus commitTransaction(final ConfigRegistryClient configRegistryClient) + throws ValidationException, ConflictingVersionException { + if (!getTransaction().isPresent()) { + // making empty commit without prior opened transaction, just return commit + // status with empty lists LOG.debug("Making commit without open candidate transaction for session {}", sessionIdForReporting); - return new CommitStatus(Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST); + return new CommitStatus(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); } final Optional maybeTaON = getTransaction(); ObjectName taON = maybeTaON.get(); @@ -203,18 +208,19 @@ public class TransactionProvider implements AutoCloseable { } /** - * Wiping means removing all module instances keeping the transaction open + service references. + * Wiping means removing all module instances keeping the transaction open + + * service references. */ synchronized void wipeInternal(final ObjectName taON, final boolean isTest) { ConfigTransactionClient transactionClient = configRegistryClient.getConfigTransactionClient(taON); Set lookupConfigBeans = transactionClient.lookupConfigBeans(); - int i = lookupConfigBeans.size(); + int index = lookupConfigBeans.size(); for (ObjectName instance : lookupConfigBeans) { try { transactionClient.destroyModule(instance); } catch (final InstanceNotFoundException e) { - if (isTest){ + if (isTest) { LOG.debug("Unable to clean configuration in transactiom {}", taON, e); } else { LOG.warn("Unable to clean configuration in transactiom {}", taON, e); @@ -223,7 +229,7 @@ public class TransactionProvider implements AutoCloseable { throw new IllegalStateException("Unable to clean configuration in transactiom " + taON, e); } } - LOG.debug("Transaction {} wiped clean of {} config beans", taON, i); + LOG.debug("Transaction {} wiped clean of {} config beans", taON, index); transactionClient.removeAllServiceReferences(); LOG.debug("Transaction {} wiped clean of all service references", taON); @@ -234,5 +240,4 @@ public class TransactionProvider implements AutoCloseable { Preconditions.checkState(taON.isPresent(), NO_TRANSACTION_FOUND_FOR_SESSION + sessionIdForReporting); wipeInternal(taON.get(), false); } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/util/Util.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/util/Util.java index deb2ffaa51..18ba37eace 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/util/Util.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/util/Util.java @@ -16,17 +16,19 @@ import java.util.Date; public final class Util { + private Util() { + } + public static String writeDate(final Date date) { return getRevisionFormat().format(date); } - public static Date readDate(final String s) throws ParseException { - return getRevisionFormat().parse(s); + public static Date readDate(final String string) throws ParseException { + return getRevisionFormat().parse(string); } public static void checkType(final Object value, final Class clazz) { - Preconditions.checkArgument(clazz.isAssignableFrom(value.getClass()), "Unexpected type " + value.getClass() - + " should be " + clazz + " of " + value); + Preconditions.checkArgument(clazz.isAssignableFrom(value.getClass()), + "Unexpected type " + value.getClass() + " should be " + clazz + " of " + value); } - } diff --git a/opendaylight/config/config-manager-facade-xml/src/test/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/SimpleIdentityRefAttributeReadingStrategyTest.java b/opendaylight/config/config-manager-facade-xml/src/test/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/SimpleIdentityRefAttributeReadingStrategyTest.java index 398064888e..bf678ffed4 100644 --- a/opendaylight/config/config-manager-facade-xml/src/test/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/SimpleIdentityRefAttributeReadingStrategyTest.java +++ b/opendaylight/config/config-manager-facade-xml/src/test/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/fromxml/SimpleIdentityRefAttributeReadingStrategyTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -28,15 +28,22 @@ public class SimpleIdentityRefAttributeReadingStrategyTest { final Date rev = new Date(); identityMapping.put("namespace", Collections.singletonMap(rev, value)); identityMapping.put("inner", Collections.singletonMap(rev, value)); - final SimpleIdentityRefAttributeReadingStrategy key = new SimpleIdentityRefAttributeReadingStrategy(null, "key", identityMapping); + final SimpleIdentityRefAttributeReadingStrategy key = new SimpleIdentityRefAttributeReadingStrategy(null, "key", + identityMapping); String read = key.readElementContent(XmlElement.fromString("local")); - assertEquals(org.opendaylight.yangtools.yang.common.QName.create(URI.create("namespace"), rev, "local").toString(), read); + assertEquals( + org.opendaylight.yangtools.yang.common.QName.create(URI.create("namespace"), rev, "local").toString(), + read); read = key.readElementContent(XmlElement.fromString("a:local")); - assertEquals(org.opendaylight.yangtools.yang.common.QName.create(URI.create("inner"), rev, "local").toString(), read); - - read = key.readElementContent(XmlElement.fromString("local").getOnlyChildElement()); - assertEquals(org.opendaylight.yangtools.yang.common.QName.create(URI.create("namespace"), rev, "local").toString(), read); + assertEquals(org.opendaylight.yangtools.yang.common.QName.create(URI.create("inner"), rev, "local").toString(), + read); + + read = key.readElementContent( + XmlElement.fromString("local").getOnlyChildElement()); + assertEquals( + org.opendaylight.yangtools.yang.common.QName.create(URI.create("namespace"), rev, "local").toString(), + read); } } diff --git a/opendaylight/config/config-manager-facade-xml/src/test/java/org/opendaylight/controller/config/facade/xml/rpc/RuntimeRpcElementResolvedTest.java b/opendaylight/config/config-manager-facade-xml/src/test/java/org/opendaylight/controller/config/facade/xml/rpc/RuntimeRpcElementResolvedTest.java index 95aff8889d..babd325c1b 100644 --- a/opendaylight/config/config-manager-facade-xml/src/test/java/org/opendaylight/controller/config/facade/xml/rpc/RuntimeRpcElementResolvedTest.java +++ b/opendaylight/config/config-manager-facade-xml/src/test/java/org/opendaylight/controller/config/facade/xml/rpc/RuntimeRpcElementResolvedTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -31,33 +31,35 @@ public class RuntimeRpcElementResolvedTest { public Map additional; @Parameterized.Parameters(name = "{index}: parsed({0}) contains moduleName:{1} and instanceName:{2}") + @SuppressWarnings("linelength") public static Collection data() { - return Arrays.asList(new Object[][]{ + return Arrays.asList(new Object[][] { // With namespaces - {"/a:modules/a:module[a:name='instanceName'][a:type='moduleType']/b:listener-state[b:peer-id='127.0.0.1']", - new HashMap<>(ImmutableMap.of("listener-state", "127.0.0.1"))}, - {"/a:modules/a:module[a:name='instanceName'][a:type='moduleType']", - null}, + { "/a:modules/a:module[a:name='instanceName'][a:type='moduleType']/b:listener-state[b:peer-id='127.0.0.1']", + new HashMap<>(ImmutableMap.of("listener-state", "127.0.0.1")) }, + { "/a:modules/a:module[a:name='instanceName'][a:type='moduleType']", null }, // Without namespaces - {"/modules/module[name=instanceName][type=moduleType]", null}, - {"/modules/module[type=moduleType][name='instanceName']", null}, - {"/modules/module[name=\'instanceName\'][type=\"moduleType\"]", null}, - {"/modules/module[type=moduleType and name=instanceName]", null}, - {"/modules/module[name=\"instanceName\" and type=moduleType]", null}, - {"/modules/module[type=\"moduleType\" and name=instanceName]", null}, - {"/modules/module[name=\'instanceName\' and type=\"moduleType\"]", null}, + { "/modules/module[name=instanceName][type=moduleType]", null }, + { "/modules/module[type=moduleType][name='instanceName']", null }, + { "/modules/module[name=\'instanceName\'][type=\"moduleType\"]", null }, + { "/modules/module[type=moduleType and name=instanceName]", null }, + { "/modules/module[name=\"instanceName\" and type=moduleType]", null }, + { "/modules/module[type=\"moduleType\" and name=instanceName]", null }, + { "/modules/module[name=\'instanceName\' and type=\"moduleType\"]", null }, // With inner beans - {"/modules/module[name=instanceName and type=\"moduleType\"]/inner[key=b]", Collections.singletonMap("inner", "b")}, - {"/modules/module[name=instanceName and type=moduleType]/inner[key=b]", Collections.singletonMap("inner", "b")}, - {"/modules/module[name=instanceName and type=moduleType]/inner[key=\'b\']", Collections.singletonMap("inner", "b")}, - {"/modules/module[name=instanceName and type=moduleType]/inner[key=\"b\"]", Collections.singletonMap("inner", "b")}, + { "/modules/module[name=instanceName and type=\"moduleType\"]/inner[key=b]", + Collections.singletonMap("inner", "b") }, + { "/modules/module[name=instanceName and type=moduleType]/inner[key=b]", + Collections.singletonMap("inner", "b") }, + { "/modules/module[name=instanceName and type=moduleType]/inner[key=\'b\']", + Collections.singletonMap("inner", "b") }, + { "/modules/module[name=instanceName and type=moduleType]/inner[key=\"b\"]", + Collections.singletonMap("inner", "b") }, - {"/modules/module[name=instanceName and type=\"moduleType\"]/inner[key2=a]/inner2[key=b]", - new HashMap<>(ImmutableMap.of("inner", "a", "inner2", "b")) - }, - }); + { "/modules/module[name=instanceName and type=\"moduleType\"]/inner[key2=a]/inner2[key=b]", + new HashMap<>(ImmutableMap.of("inner", "a", "inner2", "b")) }, }); } @Test