X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Fosgi%2FNetconfOperationServiceFactoryImpl.java;h=6ea628d0190e8a531166c823efa4eff8bf6e5173;hp=590f4c4ceb038b2a70f72c2379d5e759bc285db6;hb=23fe9ca678ada6263fec5dd996f4025e4a32fcf5;hpb=ba9a8dbd5baf3c1a235fb42489dbf9c9ba100043 diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java index 590f4c4ceb..6ea628d019 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java @@ -8,186 +8,56 @@ package org.opendaylight.controller.netconf.confignetconfconnector.osgi; -import com.google.common.base.Optional; -import java.lang.management.ManagementFactory; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; +import com.google.common.base.Function; +import com.google.common.collect.Collections2; +import com.google.common.collect.Sets; import java.util.Set; -import javax.management.MBeanServer; -import org.opendaylight.controller.config.util.ConfigRegistryJMXClient; -import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacadeFactory; +import org.opendaylight.controller.config.util.capability.Capability; +import org.opendaylight.controller.config.util.capability.ModuleListener; +import org.opendaylight.controller.config.util.capability.YangModuleCapability; import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; -import org.opendaylight.controller.netconf.confignetconfconnector.util.Util; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; import org.opendaylight.yangtools.yang.model.api.Module; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class NetconfOperationServiceFactoryImpl implements NetconfOperationServiceFactory { - public static final int ATTEMPT_TIMEOUT_MS = 1000; - private static final int SILENT_ATTEMPTS = 30; + private final ConfigSubsystemFacadeFactory configFacadeFactory; - private final YangStoreService yangStoreService; - private final ConfigRegistryJMXClient jmxClient; - - private static final Logger LOG = LoggerFactory.getLogger(NetconfOperationServiceFactoryImpl.class); - - public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService) { - this(yangStoreService, ManagementFactory.getPlatformMBeanServer()); - } - - public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService, MBeanServer mBeanServer) { - this.yangStoreService = yangStoreService; - - ConfigRegistryJMXClient configRegistryJMXClient; - int i = 0; - // Config registry might not be present yet, but will be eventually - while(true) { - - try { - configRegistryJMXClient = new ConfigRegistryJMXClient(mBeanServer); - break; - } catch (IllegalStateException e) { - ++i; - if (i > SILENT_ATTEMPTS) { - LOG.info("JMX client not created after {} attempts, still trying", i, e); - } else { - LOG.debug("JMX client could not be created, reattempting, try {}", i, e); - } - try { - Thread.sleep(ATTEMPT_TIMEOUT_MS); - } catch (InterruptedException e1) { - Thread.currentThread().interrupt(); - throw new IllegalStateException("Interrupted while reattempting connection", e1); - } - } - } - - jmxClient = configRegistryJMXClient; - if (i > SILENT_ATTEMPTS) { - LOG.info("Created JMX client after {} attempts", i); - } else { - LOG.debug("Created JMX client after {} attempts", i); - } + public NetconfOperationServiceFactoryImpl(ConfigSubsystemFacadeFactory configFacadeFactory) { + this.configFacadeFactory = configFacadeFactory; } @Override public NetconfOperationServiceImpl createService(String netconfSessionIdForReporting) { - return new NetconfOperationServiceImpl(yangStoreService, jmxClient, netconfSessionIdForReporting); + return new NetconfOperationServiceImpl(configFacadeFactory.createFacade(netconfSessionIdForReporting), netconfSessionIdForReporting); } - @Override public Set getCapabilities() { - return setupCapabilities(yangStoreService); + return configFacadeFactory.getCurrentCapabilities(); } @Override public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { - return yangStoreService.registerCapabilityListener(listener); - } - - public static Set setupCapabilities(final YangStoreContext yangStoreSnapshot) { - Set capabilities = new HashSet<>(); - // [RFC6241] 8.3. Candidate Configuration Capability - capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:candidate:1.0")); - - // TODO rollback on error not supported EditConfigXmlParser:100 - // [RFC6241] 8.5. Rollback-on-Error Capability - // capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:rollback-on-error:1.0")); - - Set modules = yangStoreSnapshot.getModules(); - for (Module module : modules) { - capabilities.add(new YangStoreCapability(module, yangStoreSnapshot.getModuleSource(module))); - } - - return capabilities; + return configFacadeFactory.getYangStoreService().registerModuleListener(new ModuleListener() { + @Override + public void onCapabilitiesChanged(Set added, Set removed) { + listener.onCapabilitiesChanged( + transformModulesToCapabilities(added), transformModulesToCapabilities(removed)); + } + }); } - private static class BasicCapability implements Capability { - - private final String capability; - - private BasicCapability(final String capability) { - this.capability = capability; - } - + private static final Function MODULE_TO_CAPABILITY = new Function() { @Override - public String getCapabilityUri() { - return capability; + public Capability apply(final Module module) { + return new YangModuleCapability(module, module.getSource()); } + }; - @Override - public Optional getModuleNamespace() { - return Optional.absent(); - } - - @Override - public Optional getModuleName() { - return Optional.absent(); - } - - @Override - public Optional getRevision() { - return Optional.absent(); - } - - @Override - public Optional getCapabilitySchema() { - return Optional.absent(); - } - - @Override - public Collection getLocation() { - return Collections.emptyList(); - } - - @Override - public String toString() { - return capability; - } + public static Set transformModulesToCapabilities(Set modules) { + return Sets.newHashSet(Collections2.transform(modules, MODULE_TO_CAPABILITY)); } - static final class YangStoreCapability extends BasicCapability { - - private final String content; - private final String revision; - private final String moduleName; - private final String moduleNamespace; - - public YangStoreCapability(final Module module, final String moduleContent) { - super(toCapabilityURI(module)); - this.content = moduleContent; - this.moduleName = module.getName(); - this.moduleNamespace = module.getNamespace().toString(); - this.revision = Util.writeDate(module.getRevision()); - } - - @Override - public Optional getCapabilitySchema() { - return Optional.of(content); - } - - private static String toCapabilityURI(final Module module) { - return String.valueOf(module.getNamespace()) + "?module=" - + module.getName() + "&revision=" + Util.writeDate(module.getRevision()); - } - - @Override - public Optional getModuleName() { - return Optional.of(moduleName); - } - - @Override - public Optional getModuleNamespace() { - return Optional.of(moduleNamespace); - } - - @Override - public Optional getRevision() { - return Optional.of(revision); - } - } }