X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Fosgi%2FNetconfOperationServiceFactoryImpl.java;h=cb9c956b90c8e10bba8283bd75eabe979cb9d068;hb=8485b8c8ca9481cc8797b08d56930bbf67c7653d;hp=35695f75102870a00c31f631ca6f26a3b7e5320f;hpb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9;p=controller.git 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 35695f7510..cb9c956b90 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,24 +8,29 @@ package org.opendaylight.controller.netconf.confignetconfconnector.osgi; +import java.lang.management.ManagementFactory; +import java.util.HashSet; +import java.util.Set; +import javax.management.MBeanServer; import org.opendaylight.controller.config.util.ConfigRegistryJMXClient; -import org.opendaylight.controller.config.yang.store.api.YangStoreException; -import org.opendaylight.controller.config.yang.store.api.YangStoreService; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.controller.netconf.util.capability.BasicCapability; +import org.opendaylight.controller.netconf.util.capability.YangModuleCapability; +import org.opendaylight.yangtools.yang.model.api.Module; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.management.MBeanServer; -import java.lang.management.ManagementFactory; - public class NetconfOperationServiceFactoryImpl implements NetconfOperationServiceFactory { public static final int ATTEMPT_TIMEOUT_MS = 1000; + private static final int SILENT_ATTEMPTS = 30; private final YangStoreService yangStoreService; private final ConfigRegistryJMXClient jmxClient; - private static final Logger logger = LoggerFactory.getLogger(NetconfOperationServiceFactoryImpl.class); + private static final Logger LOG = LoggerFactory.getLogger(NetconfOperationServiceFactoryImpl.class); public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService) { this(yangStoreService, ManagementFactory.getPlatformMBeanServer()); @@ -34,33 +39,69 @@ public class NetconfOperationServiceFactoryImpl implements NetconfOperationServi 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) { - final ConfigRegistryJMXClient configRegistryJMXClient; try { configRegistryJMXClient = new ConfigRegistryJMXClient(mBeanServer); + break; } catch (IllegalStateException e) { - logger.debug("Jmx client could not be created, reattempting"); + ++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) { - throw new RuntimeException(e1); + Thread.currentThread().interrupt(); + throw new IllegalStateException("Interrupted while reattempting connection", e1); } - continue; } + } - jmxClient = configRegistryJMXClient; - break; + jmxClient = configRegistryJMXClient; + if (i > SILENT_ATTEMPTS) { + LOG.info("Created JMX client after {} attempts", i); + } else { + LOG.debug("Created JMX client after {} attempts", i); } } @Override - public NetconfOperationServiceImpl createService(long netconfSessionId, String netconfSessionIdForReporting) { - try { - return new NetconfOperationServiceImpl(yangStoreService, jmxClient, netconfSessionIdForReporting); - } catch (YangStoreException e) { - throw new IllegalStateException(e); + public NetconfOperationServiceImpl createService(String netconfSessionIdForReporting) { + return new NetconfOperationServiceImpl(yangStoreService, jmxClient, netconfSessionIdForReporting); + } + + + @Override + public Set getCapabilities() { + return setupCapabilities(yangStoreService); + } + + @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 YangModuleCapability(module, yangStoreSnapshot.getModuleSource(module))); } + + return capabilities; } + }