2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.netconf.confignetconfconnector.osgi;
11 import java.lang.management.ManagementFactory;
12 import java.util.HashSet;
14 import javax.management.MBeanServer;
15 import org.opendaylight.controller.config.util.ConfigRegistryJMXClient;
16 import org.opendaylight.controller.netconf.api.Capability;
17 import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener;
18 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
19 import org.opendaylight.controller.netconf.util.capability.BasicCapability;
20 import org.opendaylight.controller.netconf.util.capability.YangModuleCapability;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class NetconfOperationServiceFactoryImpl implements NetconfOperationServiceFactory {
27 public static final int ATTEMPT_TIMEOUT_MS = 1000;
28 private static final int SILENT_ATTEMPTS = 30;
30 private final YangStoreService yangStoreService;
31 private final ConfigRegistryJMXClient jmxClient;
33 private static final Logger LOG = LoggerFactory.getLogger(NetconfOperationServiceFactoryImpl.class);
35 public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService) {
36 this(yangStoreService, ManagementFactory.getPlatformMBeanServer());
39 public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService, MBeanServer mBeanServer) {
40 this.yangStoreService = yangStoreService;
42 ConfigRegistryJMXClient configRegistryJMXClient;
44 // Config registry might not be present yet, but will be eventually
48 configRegistryJMXClient = new ConfigRegistryJMXClient(mBeanServer);
50 } catch (IllegalStateException e) {
52 if (i > SILENT_ATTEMPTS) {
53 LOG.info("JMX client not created after {} attempts, still trying", i, e);
55 LOG.debug("JMX client could not be created, reattempting, try {}", i, e);
58 Thread.sleep(ATTEMPT_TIMEOUT_MS);
59 } catch (InterruptedException e1) {
60 Thread.currentThread().interrupt();
61 throw new IllegalStateException("Interrupted while reattempting connection", e1);
66 jmxClient = configRegistryJMXClient;
67 if (i > SILENT_ATTEMPTS) {
68 LOG.info("Created JMX client after {} attempts", i);
70 LOG.debug("Created JMX client after {} attempts", i);
75 public NetconfOperationServiceImpl createService(String netconfSessionIdForReporting) {
76 return new NetconfOperationServiceImpl(yangStoreService, jmxClient, netconfSessionIdForReporting);
81 public Set<Capability> getCapabilities() {
82 return setupCapabilities(yangStoreService);
86 public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
87 return yangStoreService.registerCapabilityListener(listener);
90 public static Set<Capability> setupCapabilities(final YangStoreContext yangStoreSnapshot) {
91 Set<Capability> capabilities = new HashSet<>();
92 // [RFC6241] 8.3. Candidate Configuration Capability
93 capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:candidate:1.0"));
95 // TODO rollback on error not supported EditConfigXmlParser:100
96 // [RFC6241] 8.5. Rollback-on-Error Capability
97 // capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:rollback-on-error:1.0"));
99 Set<Module> modules = yangStoreSnapshot.getModules();
100 for (Module module : modules) {
101 capabilities.add(new YangModuleCapability(module, yangStoreSnapshot.getModuleSource(module)));