You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2013/02/21 16:40:23 UTC
svn commit: r1448685 - in
/karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features:
FeaturesEventHandler.java FeaturesSupport.java FeaturesSynchronizer.java
RepositoryEventHandler.java
Author: jbonofre
Date: Thu Feb 21 15:40:22 2013
New Revision: 1448685
URL: http://svn.apache.org/r1448685
Log:
[KARAF-2113] In the RepositoryEventHandler, check the local status of a features repository before modifying the features service
Modified:
karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/FeaturesEventHandler.java
karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSupport.java
karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSynchronizer.java
karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/RepositoryEventHandler.java
Modified: karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/FeaturesEventHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/FeaturesEventHandler.java?rev=1448685&r1=1448684&r2=1448685&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/FeaturesEventHandler.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/FeaturesEventHandler.java Thu Feb 21 15:40:22 2013
@@ -71,7 +71,7 @@ public class FeaturesEventHandler extend
String version = event.getVersion();
if (isAllowed(event.getSourceGroup(), Constants.FEATURES_CATEGORY, name, EventType.INBOUND) || event.getForce()) {
FeatureEvent.EventType type = event.getType();
- Boolean isInstalled = isInstalled(name, version);
+ Boolean isInstalled = isFeatureInstalledLocally(name, version);
try {
if (FeatureEvent.EventType.FeatureInstalled.equals(type) && !isInstalled) {
boolean noClean = event.getNoClean();
Modified: karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSupport.java?rev=1448685&r1=1448684&r2=1448685&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSupport.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSupport.java Thu Feb 21 15:40:22 2013
@@ -36,33 +36,29 @@ public class FeaturesSupport extends Cel
protected FeaturesService featuresService;
- /**
- * Initialization method
- */
public void init() {
+
}
- /**
- * Destruction method
- */
public void destroy() {
+
}
/**
- * Returns true if the specified feature is installed.
+ * Check if a feature is already installed locally.
*
- * @param name
- * @param version
- * @return
+ * @param name the feature name.
+ * @param version the feature version.
+ * @return true if the feature is already installed locally, false else.
*/
- public Boolean isInstalled(String name, String version) {
+ public Boolean isFeatureInstalledLocally(String name, String version) {
if (featuresService != null) {
- Feature[] features = featuresService.listInstalledFeatures();
+ Feature[] localFeatures = featuresService.listInstalledFeatures();
- if (features != null && features.length > 0) {
- for (Feature feature : features) {
- if (feature.getName().equals(name) && (feature.getVersion().equals(version) || version == null))
+ if (localFeatures != null && localFeatures.length > 0) {
+ for (Feature localFeature : localFeatures) {
+ if (localFeature.getName().equals(name) && (localFeature.getVersion().equals(version) || version == null))
return true;
}
}
@@ -71,6 +67,22 @@ public class FeaturesSupport extends Cel
}
/**
+ * Check if a features repository is already registered locally.
+ *
+ * @param uri the features repository URI.
+ * @return true if the features repository is already registered locally, false else.
+ */
+ public Boolean isRepositoryRegisteredLocally(String uri) {
+ Repository[] localRepositories = featuresService.listRepositories();
+ for (Repository localRepository : localRepositories) {
+ if (localRepository.getURI().toString().equals(uri)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Pushes a {@code Feature} and its status to the distributed list of features.
*
* @param feature
@@ -78,13 +90,13 @@ public class FeaturesSupport extends Cel
public void pushFeature(Feature feature, Group group) {
if (feature != null) {
String groupName = group.getName();
- Map<FeatureInfo, Boolean> features = clusterManager.getMap(Constants.FEATURES + Configurations.SEPARATOR + groupName);
+ Map<FeatureInfo, Boolean> clusterFeatures = clusterManager.getMap(Constants.FEATURES + Configurations.SEPARATOR + groupName);
if (isAllowed(group, Constants.FEATURES_CATEGORY, feature.getName(), EventType.OUTBOUND)) {
- if (featuresService != null && features != null) {
+ if (featuresService != null && clusterFeatures != null) {
FeatureInfo info = new FeatureInfo(feature.getName(), feature.getVersion());
Boolean installed = featuresService.isInstalled(feature);
- features.put(info, installed);
+ clusterFeatures.put(info, installed);
}
} else LOGGER.warn("CELLAR FEATURES: feature {} is marked as BLOCKED OUTBOUND", feature.getName());
} else LOGGER.warn("CELLAR FEATURES: feature is null");
@@ -99,12 +111,12 @@ public class FeaturesSupport extends Cel
public void pushFeature(Feature feature, Group group, Boolean force) {
if (feature != null) {
String groupName = group.getName();
- Map<FeatureInfo, Boolean> features = clusterManager.getMap(Constants.FEATURES + Configurations.SEPARATOR + groupName);
+ Map<FeatureInfo, Boolean> clusterFeatures = clusterManager.getMap(Constants.FEATURES + Configurations.SEPARATOR + groupName);
if (isAllowed(group, Constants.FEATURES_CATEGORY, feature.getName(), EventType.OUTBOUND)) {
- if (featuresService != null && features != null) {
+ if (featuresService != null && clusterFeatures != null) {
FeatureInfo info = new FeatureInfo(feature.getName(), feature.getVersion());
- features.put(info, force);
+ clusterFeatures.put(info, force);
}
} else LOGGER.warn("CELLAR FEATURES: feature {} is marked as BLOCKED OUTBOUND", feature.getName());
} else LOGGER.warn("CELLAR FEATURES: feature is null");
@@ -117,18 +129,18 @@ public class FeaturesSupport extends Cel
*/
public void pushRepository(Repository repository, Group group) {
String groupName = group.getName();
- List<String> repositories = clusterManager.getList(Constants.REPOSITORIES + Configurations.SEPARATOR + groupName);
+ List<String> clusterRepositories = clusterManager.getList(Constants.REPOSITORIES + Configurations.SEPARATOR + groupName);
boolean found = false;
- for (String registeredRepository : repositories) {
- if (registeredRepository.equals(repository.getURI().toString())) {
+ for (String clusterRepository : clusterRepositories) {
+ if (clusterRepository.equals(repository.getURI().toString())) {
found = true;
break;
}
}
if (!found) {
- repositories.add(repository.getURI().toString());
+ clusterRepositories.add(repository.getURI().toString());
}
}
@@ -139,13 +151,14 @@ public class FeaturesSupport extends Cel
*/
public void removeRepository(Repository repository, Group group) {
String groupName = group.getName();
- List<String> repositories = clusterManager.getList(Constants.REPOSITORIES + Configurations.SEPARATOR + groupName);
+ List<String> clusterRepositories = clusterManager.getList(Constants.REPOSITORIES + Configurations.SEPARATOR + groupName);
- if (featuresService != null && repositories != null) {
+ if (featuresService != null && clusterRepositories != null) {
URI uri = repository.getURI();
- repositories.remove(uri.toString());
+ clusterRepositories.remove(uri.toString());
}
}
+
public FeaturesService getFeaturesService() {
return featuresService;
}
Modified: karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSynchronizer.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSynchronizer.java?rev=1448685&r1=1448684&r2=1448685&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSynchronizer.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSynchronizer.java Thu Feb 21 15:40:22 2013
@@ -17,7 +17,6 @@ import org.apache.karaf.cellar.core.Clus
import org.apache.karaf.cellar.core.Configurations;
import org.apache.karaf.cellar.core.Group;
import org.apache.karaf.cellar.core.Synchronizer;
-import org.apache.karaf.cellar.core.event.EventProducer;
import org.apache.karaf.cellar.core.event.EventType;
import org.apache.karaf.features.Feature;
import org.apache.karaf.features.FeaturesService;
@@ -97,7 +96,7 @@ public class FeaturesSynchronizer extend
//Check if feature is blocked.
if (isAllowed(group, Constants.FEATURES_CATEGORY, name, EventType.INBOUND)) {
Boolean remotelyInstalled = features.get(info);
- Boolean locallyInstalled = isInstalled(info.getName(), info.getVersion());
+ Boolean locallyInstalled = isFeatureInstalledLocally(info.getName(), info.getVersion());
// prevent NPE
if (remotelyInstalled == null) {
Modified: karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/RepositoryEventHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/RepositoryEventHandler.java?rev=1448685&r1=1448684&r2=1448685&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/RepositoryEventHandler.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/RepositoryEventHandler.java Thu Feb 21 15:40:22 2013
@@ -63,11 +63,19 @@ public class RepositoryEventHandler exte
try {
// TODO check if isAllowed
if (RepositoryEvent.EventType.RepositoryAdded.equals(type)) {
- LOGGER.debug("CELLAR FEATURES: adding repository URI {}", uri);
- featuresService.addRepository(new URI(uri));
+ if (!isRepositoryRegisteredLocally(uri)) {
+ LOGGER.debug("CELLAR FEATURES: adding repository URI {}", uri);
+ featuresService.addRepository(new URI(uri));
+ } else {
+ LOGGER.debug("CELLAR FEATURES: repository URI {} is already registered locally");
+ }
} else {
- LOGGER.debug("CELLAR FEATURES: removing repository URI {}", uri);
- featuresService.removeRepository(new URI(uri));
+ if (isRepositoryRegisteredLocally(uri)) {
+ LOGGER.debug("CELLAR FEATURES: removing repository URI {}", uri);
+ featuresService.removeRepository(new URI(uri));
+ } else {
+ LOGGER.debug("CELLAR FEATURES: repository URI {} is not registered locally");
+ }
}
} catch (Exception e) {
LOGGER.error("CELLAR FEATURES: failed to add/remove repository URI {}", uri, e);