import java.io.FileInputStream;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Set;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.stream.XMLStreamException;
* Get FeatureConfigSnapshotHolders appropriate to feed to the config subsystem
* from the underlying Feature Config files
*/
- public LinkedHashSet<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
- final LinkedHashSet <FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<>();
+ public Set<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
+ final Set<FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<>();
for(final ConfigFileInfo c: getConfigurationFiles()) {
// Skip non config snapshot XML files
if(isConfigSnapshot(c.getFinalname())) {
import com.google.common.base.Preconditions;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Set;
import org.apache.felix.utils.version.VersionRange;
import org.apache.felix.utils.version.VersionTable;
import org.apache.karaf.features.Dependency;
* Get FeatureConfigSnapshotHolders appropriate to feed to the config subsystem
* from the underlying Feature Config files and those of its children recursively
*/
- public LinkedHashSet <? extends ChildAwareFeatureWrapper> getChildFeatures() throws Exception {
+ public Set<? extends ChildAwareFeatureWrapper> getChildFeatures() throws Exception {
List<Dependency> dependencies = feature.getDependencies();
- LinkedHashSet <ChildAwareFeatureWrapper> childFeatures = new LinkedHashSet<>();
+ Set<ChildAwareFeatureWrapper> childFeatures = new LinkedHashSet<>();
if(dependencies != null) {
for(Dependency dependency: dependencies) {
Feature fi = extractFeatureFromDependency(dependency);
- if(fi != null) {
- if(featuresService.getFeature(fi.getName(), fi.getVersion()) == null) {
+ if (fi != null) {
+ if (featuresService.getFeature(fi.getName(), fi.getVersion()) == null) {
LOG.warn("Feature: {}, {} is missing from features service. Skipping", fi.getName(), fi.getVersion());
} else {
- ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(fi,featuresService);
+ ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(fi, featuresService);
childFeatures.add(wrappedFeature);
}
}
}
@Override
- public LinkedHashSet<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
- LinkedHashSet <FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<>();
+ public Set<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
+ Set<FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<>();
for(ChildAwareFeatureWrapper c: getChildFeatures()) {
for(FeatureConfigSnapshotHolder h: c.getFeatureConfigSnapshotHolders()) {
final Optional<FeatureConfigSnapshotHolder> featureConfigSnapshotHolder = getFeatureConfigSnapshotHolder(h.getFileInfo());
}
}
- protected void processFeatureEvent(FeatureEvent event, List<Feature> toInstall) throws InterruptedException, Exception {
+ protected void processFeatureEvent(FeatureEvent event, List<Feature> toInstall) throws Exception {
if(event.getType() == EventType.FeatureInstalled) {
toInstall.add(event.getFeature());
LinkedHashMultimap<Feature,FeatureConfigSnapshotHolder> result = configPusher.pushConfigs(toInstall);
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Set;
import org.apache.karaf.features.Feature;
import org.apache.karaf.features.FeaturesService;
import org.opendaylight.controller.config.persist.api.ConfigPusher;
* chains. Also, preserves the *original* Feature chain for which we pushed the config.
* (which is handy for logging).
*/
- LinkedHashSet<FeatureConfigSnapshotHolder> pushedConfigs = new LinkedHashSet<>();
+ Set<FeatureConfigSnapshotHolder> pushedConfigs = new LinkedHashSet<>();
/*
* LinkedHashMultimap to track which configs we pushed for each Feature installation
* For future use
for (Feature feature : features) {
- LinkedHashSet<FeatureConfigSnapshotHolder> configSnapShots = pushConfig(feature);
+ Set<FeatureConfigSnapshotHolder> configSnapShots = pushConfig(feature);
if (!configSnapShots.isEmpty()) {
pushedFeatures.putAll(feature, configSnapShots);
}
return pushedFeatures;
}
- private LinkedHashSet<FeatureConfigSnapshotHolder> pushConfig(final Feature feature) throws Exception {
- LinkedHashSet<FeatureConfigSnapshotHolder> configs = new LinkedHashSet<>();
+ private Set<FeatureConfigSnapshotHolder> pushConfig(final Feature feature) throws Exception {
+ Set<FeatureConfigSnapshotHolder> configs = new LinkedHashSet<>();
if(isInstalled(feature)) {
// FIXME Workaround for BUG-2836, features service returns null for feature: standard-condition-webconsole_0_0_0, 3.0.1
if(featuresService.getFeature(feature.getName(), feature.getVersion()) == null) {
}
private boolean isInstalled(final Feature feature) {
- for(int retries=0;retries<MAX_RETRIES;retries++) {
+ for (int retries = 0; retries < MAX_RETRIES; retries++) {
try {
List<Feature> installedFeatures = Arrays.asList(featuresService.listInstalledFeatures());
if(installedFeatures.contains(feature)) {
LOG.warn("Karaf featuresService.listInstalledFeatures() has not yet finished installing feature (retry {}) {} {}",retries,feature.getName(),feature.getVersion());
}
} catch (Exception e) {
- if(retries < MAX_RETRIES) {
- LOG.warn("Karaf featuresService.listInstalledFeatures() has thrown an exception, retry {}", retries, e);
- } else {
- LOG.error("Giving up on Karaf featuresService.listInstalledFeatures() which has thrown an exception, retry {}", retries, e);
- throw e;
- }
+ LOG.warn("Karaf featuresService.listInstalledFeatures() has thrown an exception, retry {}", retries, e);
}
try {
Thread.sleep(RETRY_PAUSE_MILLIS);
return false;
}
- private LinkedHashSet<FeatureConfigSnapshotHolder> pushConfig(final LinkedHashSet<FeatureConfigSnapshotHolder> configs, final Feature feature) throws InterruptedException {
- LinkedHashSet<FeatureConfigSnapshotHolder> configsToPush = new LinkedHashSet<>(configs);
+ private Set<FeatureConfigSnapshotHolder> pushConfig(final Set<FeatureConfigSnapshotHolder> configs, final Feature feature)
+ throws InterruptedException {
+ Set<FeatureConfigSnapshotHolder> configsToPush = new LinkedHashSet<>(configs);
configsToPush.removeAll(pushedConfigs);
if (!configsToPush.isEmpty()) {
pushedConfigs.addAll(configsToPush);
}
- LinkedHashSet<FeatureConfigSnapshotHolder> configsPushed = new LinkedHashSet<>(pushedConfigs);
+ Set<FeatureConfigSnapshotHolder> configsPushed = new LinkedHashSet<>(pushedConfigs);
configsPushed.retainAll(configs);
return configsPushed;
}
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(new File(fileInfo.getFinalname())));
- unmarshalled = ((ConfigSnapshot) um.unmarshal(xsr));
+ unmarshalled = (ConfigSnapshot) um.unmarshal(xsr);
}
/*
* (non-Javadoc)
public class FeatureServiceCustomizer implements ServiceTrackerCustomizer<FeaturesService, FeaturesService>, AutoCloseable {
private ConfigPusher configPusher = null;
- private ConfigFeaturesListener configFeaturesListener = null;
private ServiceRegistration<?> registration;
FeatureServiceCustomizer(ConfigPusher c) {
configPusher = c;
}
-
@Override
public FeaturesService addingService(ServiceReference<FeaturesService> reference) {
BundleContext bc = reference.getBundle().getBundleContext();
}
});
}
- configFeaturesListener = new ConfigFeaturesListener(configPusher,featureService);
+ ConfigFeaturesListener configFeaturesListener = new ConfigFeaturesListener(configPusher, featureService);
registration = bc.registerService(FeaturesListener.class.getCanonicalName(), configFeaturesListener, null);
return featureService;
}
public void modifiedService(ServiceReference<FeaturesService> reference,
FeaturesService service) {
// we don't care if the properties change
-
}
@Override
registration = null;
}
}
-
}