*/
package org.opendaylight.controller.configpusherfeature.internal;
+import com.google.common.base.Optional;
+import com.google.common.collect.Sets;
+
+import java.util.Set;
+
+import org.apache.karaf.features.Feature;
import org.apache.karaf.features.FeaturesListener;
import org.apache.karaf.features.FeaturesService;
import org.opendaylight.controller.config.persist.api.ConfigPusher;
+import org.opendaylight.controller.config.persist.storage.file.xml.XmlFileStorageAdapter;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-public class FeatureServiceCustomizer implements ServiceTrackerCustomizer<FeaturesService, FeaturesService>, AutoCloseable {
+public class FeatureServiceCustomizer implements ServiceTrackerCustomizer<FeaturesService, FeaturesService>,
+ AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(FeatureServiceCustomizer.class);
private ConfigPusher configPusher = null;
- private ConfigFeaturesListener configFeaturesListener = null;
private ServiceRegistration<?> registration;
- FeatureServiceCustomizer(ConfigPusher c) {
- configPusher = c;
+ FeatureServiceCustomizer(final ConfigPusher configPusher) {
+ this.configPusher = configPusher;
}
-
@Override
- public FeaturesService addingService(ServiceReference<FeaturesService> reference) {
+ @SuppressWarnings("IllegalCatch")
+ public FeaturesService addingService(final ServiceReference<FeaturesService> reference) {
BundleContext bc = reference.getBundle().getBundleContext();
- FeaturesService featureService = bc.getService(reference);
- configFeaturesListener = new ConfigFeaturesListener(configPusher,featureService);
+ final FeaturesService featureService = bc.getService(reference);
+ final Optional<XmlFileStorageAdapter> currentPersister = XmlFileStorageAdapter.getInstance();
+
+ if (XmlFileStorageAdapter.getInstance().isPresent()) {
+ final Set<String> installedFeatureIds = Sets.newHashSet();
+ try {
+ for (final Feature installedFeature : featureService.listInstalledFeatures()) {
+ installedFeatureIds.add(installedFeature.getId());
+ }
+ } catch (final Exception e) {
+ LOG.error("Error listing installed features", e);
+ }
+
+ currentPersister.get().setFeaturesService(() -> installedFeatureIds);
+ }
+ ConfigFeaturesListener configFeaturesListener = new ConfigFeaturesListener(configPusher, featureService);
registration = bc.registerService(FeaturesListener.class.getCanonicalName(), configFeaturesListener, null);
return featureService;
}
@Override
- public void modifiedService(ServiceReference<FeaturesService> reference,
- FeaturesService service) {
+ public void modifiedService(final ServiceReference<FeaturesService> reference, final FeaturesService service) {
// we don't care if the properties change
-
}
@Override
- public void removedService(ServiceReference<FeaturesService> reference,
- FeaturesService service) {
+ public void removedService(final ServiceReference<FeaturesService> reference, final FeaturesService service) {
close();
}
@Override
public void close() {
- if(registration != null) {
+ if (registration != null) {
registration.unregister();
registration = null;
}
}
-
}