- public void start(BundleContext context) throws Exception {
- logger.debug("ConfigPersister activator started");
-
- Optional<PersisterImpl> maybePersister = PersisterImpl.createFromProperties(context);
- if (maybePersister.isPresent() == false) {
- throw new IllegalStateException("No persister is defined in " + PersisterImpl.STORAGE_ADAPTER_CLASS_PROP
- + " property. For noop persister use " + NoOpStorageAdapter.class.getCanonicalName()
- + " . Persister is not operational");
+ public void start(final BundleContext context) throws Exception {
+ logger.debug("ConfigPersister starting");
+ autoCloseables = new ArrayList<>();
+ PropertiesProviderBaseImpl propertiesProvider = new PropertiesProviderBaseImpl(context);
+
+ final PersisterAggregator persisterAggregator = PersisterAggregator.createFromProperties(propertiesProvider);
+ autoCloseables.add(persisterAggregator);
+ long maxWaitForCapabilitiesMillis = getMaxWaitForCapabilitiesMillis(propertiesProvider);
+ List<ConfigSnapshotHolder> configs = persisterAggregator.loadLastConfigs();
+ long conflictingVersionTimeoutMillis = getConflictingVersionTimeoutMillis(propertiesProvider);
+ logger.trace("Following configs will be pushed: {}", configs);
+
+ InnerCustomizer innerCustomizer = new InnerCustomizer(configs, maxWaitForCapabilitiesMillis,
+ conflictingVersionTimeoutMillis, persisterAggregator);
+ OuterCustomizer outerCustomizer = new OuterCustomizer(context, innerCustomizer);
+ new ServiceTracker<>(context, NetconfOperationProvider.class, outerCustomizer).open();
+ }
+
+ private long getConflictingVersionTimeoutMillis(PropertiesProviderBaseImpl propertiesProvider) {
+ String timeoutProperty = propertiesProvider.getProperty(CONFLICTING_VERSION_TIMEOUT_MILLIS_PROPERTY);
+ return timeoutProperty == null ? CONFLICTING_VERSION_TIMEOUT_MILLIS_DEFAULT : Long.valueOf(timeoutProperty);
+ }
+
+ private long getMaxWaitForCapabilitiesMillis(PropertiesProviderBaseImpl propertiesProvider) {
+ String timeoutProperty = propertiesProvider.getProperty(MAX_WAIT_FOR_CAPABILITIES_MILLIS_PROPERTY);
+ return timeoutProperty == null ? MAX_WAIT_FOR_CAPABILITIES_MILLIS_DEFAULT : Long.valueOf(timeoutProperty);
+ }
+
+ @Override
+ public synchronized void stop(BundleContext context) throws Exception {
+ CloseableUtil.closeAll(autoCloseables);
+ }
+
+
+ @VisibleForTesting
+ public static String getFilterString() {
+ return "(&" +
+ "(" + Constants.OBJECTCLASS + "=" + NetconfOperationServiceFactory.class.getName() + ")" +
+ "(name" + "=" + "config-netconf-connector" + ")" +
+ ")";
+ }
+
+ class OuterCustomizer implements ServiceTrackerCustomizer<NetconfOperationProvider, NetconfOperationProvider> {
+ private final BundleContext context;
+ private final InnerCustomizer innerCustomizer;
+
+ OuterCustomizer(BundleContext context, InnerCustomizer innerCustomizer) {
+ this.context = context;
+ this.innerCustomizer = innerCustomizer;