Author: jbonofre
Date: Mon Apr 29 07:17:50 2013
New Revision: 1476910
URL: http://svn.apache.org/r1476910
Log:
Code cleanup.
Added:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ClusterObrBundleEvent.java
- copied, changed from r1476312,
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrBundleEvent.java
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ClusterObrUrlEvent.java
- copied, changed from r1476312,
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlEvent.java
Removed:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrBundleEvent.java
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlEvent.java
Modified:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/Constants.java
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrBundleEventHandler.java
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrBundleInfo.java
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrSupport.java
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlEventHandler.java
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlSynchronizer.java
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/management/CellarOBRMBean.java
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/management/internal/CellarOBRMBeanImpl.java
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrAddUrlCommand.java
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrCommandSupport.java
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrDeployCommand.java
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrListCommand.java
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrListUrlCommand.java
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrRemoveUrlCommand.java
Copied:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ClusterObrBundleEvent.java
(from r1476312,
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrBundleEvent.java)
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ClusterObrBundleEvent.java?p2=karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ClusterObrBundleEvent.java&p1=karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrBundleEvent.java&r1=1476312&r2=1476910&rev=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrBundleEvent.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ClusterObrBundleEvent.java
Mon Apr 29 07:17:50 2013
@@ -16,14 +16,14 @@ package org.apache.karaf.cellar.obr;
import org.apache.karaf.cellar.core.event.Event;
/**
- * OBR Bundle cluster event.
+ * Cluster OBR bundle event.
*/
-public class ObrBundleEvent extends Event {
+public class ClusterObrBundleEvent extends Event {
private String bundleId;
private int type;
- public ObrBundleEvent(String bundleId, int type) {
+ public ClusterObrBundleEvent(String bundleId, int type) {
super(bundleId);
this.bundleId = bundleId;
this.type = type;
Copied:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ClusterObrUrlEvent.java
(from r1476312,
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlEvent.java)
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ClusterObrUrlEvent.java?p2=karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ClusterObrUrlEvent.java&p1=karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlEvent.java&r1=1476312&r2=1476910&rev=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlEvent.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ClusterObrUrlEvent.java
Mon Apr 29 07:17:50 2013
@@ -14,17 +14,16 @@
package org.apache.karaf.cellar.obr;
import org.apache.karaf.cellar.core.event.Event;
-import org.apache.karaf.cellar.core.event.EventType;
/**
- * OBR URL Event.
+ * Cluster OBR URL event.
*/
-public class ObrUrlEvent extends Event {
+public class ClusterObrUrlEvent extends Event {
private String url;
private int type;
- public ObrUrlEvent(String url, int type) {
+ public ClusterObrUrlEvent(String url, int type) {
super(url);
this.url = url;
this.type = type;
Modified:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/Constants.java
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/Constants.java?rev=1476910&r1=1476909&r2=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/Constants.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/Constants.java
Mon Apr 29 07:17:50 2013
@@ -14,7 +14,7 @@
package org.apache.karaf.cellar.obr;
/**
- * Cellar OBR constants
+ * Cellar OBR configuration constants.
*/
public class Constants {
Modified:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrBundleEventHandler.java
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrBundleEventHandler.java?rev=1476910&r1=1476909&r2=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrBundleEventHandler.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrBundleEventHandler.java
Mon Apr 29 07:17:50 2013
@@ -30,9 +30,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * OBR bundles event handler.
+ * Handler for cluster OBR bundle event.
*/
-public class ObrBundleEventHandler extends ObrSupport implements
EventHandler<ObrBundleEvent> {
+public class ObrBundleEventHandler extends ObrSupport implements
EventHandler<ClusterObrBundleEvent> {
private static final transient Logger LOGGER =
LoggerFactory.getLogger(ObrBundleEventHandler.class);
@@ -105,22 +105,22 @@ public class ObrBundleEventHandler exten
}
/**
- * Handle an OBR bundle event.
+ * Handle a received cluster OBR bundle event.
*
- * @param event the OBR bundle event.
+ * @param event the cluster OBR bundle event received.
*/
@Override
- public void handle(ObrBundleEvent event) {
+ public void handle(ClusterObrBundleEvent event) {
// check if the handler is ON
if (this.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
- LOGGER.warn("CELLAR OBR: {} switch is OFF, cluster event not
handled", SWITCH_ID);
+ LOGGER.warn("CELLAR OBR: {} switch is OFF", SWITCH_ID);
return;
}
// check if the group is local
if (!groupManager.isLocalGroup(event.getSourceGroup().getName())) {
- LOGGER.debug("CELLAR OBR: node is not part of the event cluster
group");
+ LOGGER.debug("CELLAR OBR: node is not part of the event cluster
group {}", event.getSourceGroup().getName());
return;
}
@@ -152,16 +152,18 @@ public class ObrBundleEventHandler exten
}
} else LOGGER.warn("CELLAR OBR: could not resolve
targets");
}
- } else LOGGER.warn("CELLAR OBR: bundle {} is marked as BLOCKED
INBOUND", bundleId);
+ } else LOGGER.warn("CELLAR OBR: bundle {} is marked BLOCKED
INBOUND for cluster group {}", bundleId, event.getSourceGroup().getName());
} catch (Exception e) {
LOGGER.error("CELLAR OBR: failed to handle bundle event {}",
bundleId, e);
}
}
- public Class<ObrBundleEvent> getType() {
- return ObrBundleEvent.class;
+ @Override
+ public Class<ClusterObrBundleEvent> getType() {
+ return ClusterObrBundleEvent.class;
}
+ @Override
public Switch getSwitch() {
// load the switch status from the config
try {
Modified:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrBundleInfo.java
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrBundleInfo.java?rev=1476910&r1=1476909&r2=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrBundleInfo.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrBundleInfo.java
Mon Apr 29 07:17:50 2013
@@ -16,7 +16,7 @@ package org.apache.karaf.cellar.obr;
import java.io.Serializable;
/**
- * Simple serializable wrapper for OBR bundle.
+ * Serializable wrapper for OBR bundle store in cluster groups.
*/
public class ObrBundleInfo implements Serializable {
Modified:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrSupport.java
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrSupport.java?rev=1476910&r1=1476909&r2=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrSupport.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrSupport.java
Mon Apr 29 07:17:50 2013
@@ -18,16 +18,20 @@ import org.apache.karaf.cellar.core.Cell
import org.osgi.framework.BundleContext;
/**
- * Cellar OBR support.
+ * Generic Cellar OBR support, providing util methods.
*/
public class ObrSupport extends CellarSupport {
protected BundleContext bundleContext;
protected RepositoryAdmin obrService;
- public void init() { }
+ public void init() {
+ // nothing to do
+ }
- public void destroy() { }
+ public void destroy() {
+ // nothing to do
+ }
public BundleContext getBundleContext() {
return this.bundleContext;
Modified:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlEventHandler.java
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlEventHandler.java?rev=1476910&r1=1476909&r2=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlEventHandler.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlEventHandler.java
Mon Apr 29 07:17:50 2013
@@ -24,9 +24,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * OBR URL Event handler.
+ * Handler for cluster OBR URL event.
*/
-public class ObrUrlEventHandler extends ObrSupport implements
EventHandler<ObrUrlEvent> {
+public class ObrUrlEventHandler extends ObrSupport implements
EventHandler<ClusterObrUrlEvent> {
private static final transient Logger LOGGER =
LoggerFactory.getLogger(ObrUrlEventHandler.class);
@@ -45,51 +45,53 @@ public class ObrUrlEventHandler extends
}
/**
- * Process an OBR URL event.
+ * Handle a received cluster OBR URL event.
*
- * @param obrUrlEvent the OBR URL Event.
+ * @param clusterObrUrlEvent the cluster OBR URL event received.
*/
@Override
- public void handle(ObrUrlEvent obrUrlEvent) {
+ public void handle(ClusterObrUrlEvent clusterObrUrlEvent) {
// check if the handler is ON
if (this.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
- LOGGER.warn("CELLAR OBR: {} switch is OFF, cluster event not
handled", SWITCH_ID);
+ LOGGER.warn("CELLAR OBR: {} switch is OFF", SWITCH_ID);
return;
}
// check if the group is local
- if
(!groupManager.isLocalGroup(obrUrlEvent.getSourceGroup().getName())) {
- LOGGER.debug("CELLAR OBR: node is not part of the event cluster
group");
+ if
(!groupManager.isLocalGroup(clusterObrUrlEvent.getSourceGroup().getName())) {
+ LOGGER.debug("CELLAR OBR: node is not part of the event cluster
group {}", clusterObrUrlEvent.getSourceGroup().getName());
return;
}
- String url = obrUrlEvent.getUrl();
- String groupName = obrUrlEvent.getSourceGroup().getName();
+ String url = clusterObrUrlEvent.getUrl();
+ String groupName = clusterObrUrlEvent.getSourceGroup().getName();
try {
- if (isAllowed(obrUrlEvent.getSourceGroup(),
Constants.URLS_CONFIG_CATEGORY, url, EventType.INBOUND) ||
obrUrlEvent.getForce()) {
+ if (isAllowed(clusterObrUrlEvent.getSourceGroup(),
Constants.URLS_CONFIG_CATEGORY, url, EventType.INBOUND) ||
clusterObrUrlEvent.getForce()) {
LOGGER.debug("CELLAR OBR: received OBR URL {}", url);
- if (obrUrlEvent.getType() == Constants.URL_ADD_EVENT_TYPE) {
+ if (clusterObrUrlEvent.getType() ==
Constants.URL_ADD_EVENT_TYPE) {
LOGGER.debug("CELLAR OBR: add OBR URL {}", url);
obrService.addRepository(url);
}
- if (obrUrlEvent.getType() == Constants.URL_REMOVE_EVENT_TYPE) {
+ if (clusterObrUrlEvent.getType() ==
Constants.URL_REMOVE_EVENT_TYPE) {
LOGGER.debug("CELLAR OBR: remove OBR URL {}", url);
boolean removed = obrService.removeRepository(url);
if (!removed) {
LOGGER.warn("CELLAR OBR: the repository URL hasn't
been removed from the OBR service");
}
}
- } else LOGGER.warn("CELLAR OBR: repository URL {} is marked as
BLOCKED INBOUND", url);
+ } else LOGGER.warn("CELLAR OBR: repository URL {} is marked
BLOCKED INBOUND for cluster group {}", url, groupName);
} catch (Exception e) {
LOGGER.error("CELLAR OBR: failed to register URL {}", url, e);
}
}
- public Class<ObrUrlEvent> getType() {
- return ObrUrlEvent.class;
+ @Override
+ public Class<ClusterObrUrlEvent> getType() {
+ return ClusterObrUrlEvent.class;
}
+ @Override
public Switch getSwitch() {
// load the switch status from the config
try {
Modified:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlSynchronizer.java
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlSynchronizer.java?rev=1476910&r1=1476909&r2=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlSynchronizer.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlSynchronizer.java
Mon Apr 29 07:17:50 2013
@@ -18,7 +18,6 @@ import org.apache.felix.bundlerepository
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.osgi.service.cm.Configuration;
import org.slf4j.Logger;
@@ -26,16 +25,16 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Dictionary;
-import java.util.List;
import java.util.Set;
/**
- * Bootstrap synchronizer for the OBR URLs.
+ * OBR URL synchronizer.
*/
public class ObrUrlSynchronizer extends ObrSupport implements Synchronizer {
private static final transient Logger LOGGER =
LoggerFactory.getLogger(ObrUrlSynchronizer.class);
+ @Override
public void init() {
super.init();
Set<Group> groups = groupManager.listLocalGroups();
@@ -49,24 +48,26 @@ public class ObrUrlSynchronizer extends
}
}
+ @Override
public void destroy() {
super.destroy();
}
/**
- * Pull the OBR URL from the cluster.
+ * Pull the OBR URLs from a cluster group to update the local state.
*
* @param group the cluster group.
*/
+ @Override
public void pull(Group group) {
if (group != null) {
String groupName = group.getName();
- Set<String> urls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
+ Set<String> clusterUrls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
ClassLoader originalClassLoader =
Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
- if (urls != null && !urls.isEmpty()) {
- for (String url : urls) {
+ if (clusterUrls != null && !clusterUrls.isEmpty()) {
+ for (String url : clusterUrls) {
try {
obrService.addRepository(url);
LOGGER.debug("CELLAR OBR: add OBR repository URL
{}", url);
@@ -82,14 +83,15 @@ public class ObrUrlSynchronizer extends
}
/**
- * Push the local OBR URLs to the cluster
+ * Push the local OBR URLs to a cluster group.
*
* @param group the cluster group.
*/
+ @Override
public void push(Group group) {
if (group != null) {
String groupName = group.getName();
- Set<String> urls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
+ Set<String> clusterUrls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
ClassLoader originalClassLoader =
Thread.currentThread().getContextClassLoader();
try {
@@ -97,13 +99,13 @@ public class ObrUrlSynchronizer extends
Repository[] repositories = obrService.listRepositories();
for (Repository repository : repositories) {
if (isAllowed(group, Constants.URLS_CONFIG_CATEGORY,
repository.getURI().toString(), EventType.OUTBOUND)) {
- urls.add(repository.getURI().toString());
- // push the bundles in the OBR distributed set
- Set<ObrBundleInfo> bundles =
clusterManager.getSet(Constants.BUNDLES_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
+ clusterUrls.add(repository.getURI().toString());
+ // update the OBR bundles in the cluster group
+ Set<ObrBundleInfo> clusterBundles =
clusterManager.getSet(Constants.BUNDLES_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
Resource[] resources = repository.getResources();
for (Resource resource : resources) {
ObrBundleInfo info = new
ObrBundleInfo(resource.getPresentationName(), resource.getSymbolicName(),
resource.getVersion().toString());
- bundles.add(info);
+ clusterBundles.add(info);
// TODO fire event to the other nodes ?
}
} else {
Modified:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/management/CellarOBRMBean.java
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/management/CellarOBRMBean.java?rev=1476910&r1=1476909&r2=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/management/CellarOBRMBean.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/management/CellarOBRMBean.java
Mon Apr 29 07:17:50 2013
@@ -17,15 +17,53 @@ import javax.management.openmbean.Tabula
import java.util.List;
/**
- * MBean interface describing the operations and attributes on OBR service..
+ * Describe the operations and attributes of the Cellar OBR MBean.
*/
public interface CellarOBRMBean {
+ /**
+ * List the OBR URLs in a cluster group.
+ *
+ * @param groupName the cluster group name.
+ * @return the list of OBR URLs.
+ * @throws Exception in case of retrieval failure.
+ */
List<String> listUrls(String groupName) throws Exception;
+
+ /**
+ * List the OBR bundles in a cluster group.
+ *
+ * @param groupName the cluster group name.
+ * @return the list of OBR bundles.
+ * @throws Exception in case of retrieval failure.
+ */
TabularData listBundles(String groupName) throws Exception;
+ /**
+ * Add an OBR URL in a cluster group.
+ *
+ * @param groupName the cluster group name.
+ * @param url the OBR URL.
+ * @throws Exception in case of add failure.
+ */
void addUrl(String groupName, String url) throws Exception;
+
+ /**
+ * Remove an OBR URL from a cluster group.
+ *
+ * @param groupName the cluster group name.
+ * @param url the OBR URL.
+ * @throws Exception in case of remove failure.
+ */
void removeUrl(String groupName, String url) throws Exception;
+
+ /**
+ * Deploy an OBR bundle in a cluster group.
+ *
+ * @param groupName the cluster group name.
+ * @param bundleId the bundle ID.
+ * @throws Exception in case of deploy failure.
+ */
void deploy(String groupName, String bundleId) throws Exception;
}
Modified:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/management/internal/CellarOBRMBeanImpl.java
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/management/internal/CellarOBRMBeanImpl.java?rev=1476910&r1=1476909&r2=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/management/internal/CellarOBRMBeanImpl.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/management/internal/CellarOBRMBeanImpl.java
Mon Apr 29 07:17:50 2013
@@ -20,10 +20,10 @@ import org.apache.karaf.cellar.core.*;
import org.apache.karaf.cellar.core.control.SwitchStatus;
import org.apache.karaf.cellar.core.event.EventProducer;
import org.apache.karaf.cellar.core.event.EventType;
+import org.apache.karaf.cellar.obr.ClusterObrBundleEvent;
+import org.apache.karaf.cellar.obr.ClusterObrUrlEvent;
import org.apache.karaf.cellar.obr.Constants;
-import org.apache.karaf.cellar.obr.ObrBundleEvent;
import org.apache.karaf.cellar.obr.ObrBundleInfo;
-import org.apache.karaf.cellar.obr.ObrUrlEvent;
import org.apache.karaf.cellar.obr.management.CellarOBRMBean;
import org.osgi.service.cm.ConfigurationAdmin;
@@ -49,6 +49,7 @@ public class CellarOBRMBeanImpl extends
super(CellarOBRMBean.class);
}
+ @Override
public List<String> listUrls(String groupName) throws Exception {
// check if the group exists
Group group = groupManager.findGroupByName(groupName);
@@ -57,13 +58,14 @@ public class CellarOBRMBeanImpl extends
}
List<String> result = new ArrayList<String>();
- Set<String> urls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
- for (String url : urls) {
+ Set<String> clusterUrls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
+ for (String url : clusterUrls) {
result.add(url);
}
return result;
}
+ @Override
public TabularData listBundles(String groupName) throws Exception {
// check if the group exists
Group group = groupManager.findGroupByName(groupName);
@@ -82,8 +84,8 @@ public class CellarOBRMBeanImpl extends
ClassLoader originalClassLoader =
Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
- Set<ObrBundleInfo> bundles =
clusterManager.getSet(Constants.BUNDLES_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
- for (ObrBundleInfo info : bundles) {
+ Set<ObrBundleInfo> clusterBundles =
clusterManager.getSet(Constants.BUNDLES_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
+ for (ObrBundleInfo info : clusterBundles) {
CompositeData data = new CompositeDataSupport(compositeType,
new String[]{ "name", "symbolic", "version" },
new Object[]{ info.getPresentationName(),
info.getSymbolicName(), info.getVersion() });
@@ -96,6 +98,7 @@ public class CellarOBRMBeanImpl extends
return table;
}
+ @Override
public void addUrl(String groupName, String url) throws Exception {
// check if the group exists
Group group = groupManager.findGroupByName(groupName);
@@ -114,13 +117,13 @@ public class CellarOBRMBeanImpl extends
support.setGroupManager(this.groupManager);
support.setConfigurationAdmin(this.configurationAdmin);
if (!support.isAllowed(group, Constants.URLS_CONFIG_CATEGORY, url,
EventType.OUTBOUND)) {
- throw new IllegalArgumentException("OBR URL " + url + " is blocked
outbound");
+ throw new IllegalArgumentException("OBR URL " + url + " is blocked
outbound for cluster group " + groupName);
}
- // push the OBR URL in the distributed set
- Set<String> urls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
- urls.add(url);
- // push the bundles in the OBR distributed set
+ // update the OBR URLs in the cluster group
+ Set<String> clusterUrls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
+ clusterUrls.add(url);
+ // update the OBR bundles in the cluster group
Set<ObrBundleInfo> bundles =
clusterManager.getSet(Constants.BUNDLES_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
synchronized (obrService) {
Repository repository = obrService.addRepository(url);
@@ -132,13 +135,14 @@ public class CellarOBRMBeanImpl extends
obrService.removeRepository(url);
}
- // create an cluster event and produce it
- ObrUrlEvent event = new ObrUrlEvent(url, Constants.URL_ADD_EVENT_TYPE);
+ // broadcast a cluster event
+ ClusterObrUrlEvent event = new ClusterObrUrlEvent(url,
Constants.URL_ADD_EVENT_TYPE);
event.setForce(true);
event.setSourceGroup(group);
eventProducer.produce(event);
}
+ @Override
public void removeUrl(String groupName, String url) throws Exception {
// check if the group exists
Group group = groupManager.findGroupByName(groupName);
@@ -157,13 +161,13 @@ public class CellarOBRMBeanImpl extends
support.setGroupManager(this.groupManager);
support.setConfigurationAdmin(this.configurationAdmin);
if (!support.isAllowed(group, Constants.URLS_CONFIG_CATEGORY, url,
EventType.OUTBOUND)) {
- throw new IllegalArgumentException("OBR URL " + url + " is blocked
outbound");
+ throw new IllegalArgumentException("OBR URL " + url + " is blocked
outbound for cluster group " + groupName);
}
- // remove URL from the distributed map
- Set<String> urls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
- urls.remove(url);
- // remove bundles from the distributed map
+ // update the OBR URLs in the cluster group
+ Set<String> clusterUrls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
+ clusterUrls.remove(url);
+ // update the OBR bundles in the cluster group
Set<ObrBundleInfo> bundles =
clusterManager.getSet(Constants.BUNDLES_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
synchronized (obrService) {
Repository repository = obrService.addRepository(url);
@@ -175,12 +179,13 @@ public class CellarOBRMBeanImpl extends
obrService.removeRepository(url);
}
- // create an event and produce it
- ObrUrlEvent event = new ObrUrlEvent(url,
Constants.URL_REMOVE_EVENT_TYPE);
+ // broadcast the cluster event
+ ClusterObrUrlEvent event = new ClusterObrUrlEvent(url,
Constants.URL_REMOVE_EVENT_TYPE);
event.setSourceGroup(group);
eventProducer.produce(event);
}
+ @Override
public void deploy(String groupName, String bundleId) throws Exception {
// check if the group exists
Group group = groupManager.findGroupByName(groupName);
@@ -199,12 +204,12 @@ public class CellarOBRMBeanImpl extends
support.setGroupManager(this.groupManager);
support.setConfigurationAdmin(this.configurationAdmin);
if (!support.isAllowed(group, Constants.BUNDLES_CONFIG_CATEGORY,
bundleId, EventType.OUTBOUND)) {
- throw new IllegalArgumentException("OBR bundle " + bundleId + " is
blocked outbound");
+ throw new IllegalArgumentException("OBR bundle " + bundleId + " is
blocked outbound for cluster group " + groupName);
}
// create an event and produce it
int type = 0;
- ObrBundleEvent event = new ObrBundleEvent(bundleId, type);
+ ClusterObrBundleEvent event = new ClusterObrBundleEvent(bundleId,
type);
event.setForce(true);
event.setSourceGroup(group);
eventProducer.produce(event);
Modified:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrAddUrlCommand.java
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrAddUrlCommand.java?rev=1476910&r1=1476909&r2=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrAddUrlCommand.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrAddUrlCommand.java
Mon Apr 29 07:17:50 2013
@@ -22,60 +22,61 @@ import org.apache.karaf.cellar.core.Grou
import org.apache.karaf.cellar.core.control.SwitchStatus;
import org.apache.karaf.cellar.core.event.EventProducer;
import org.apache.karaf.cellar.core.event.EventType;
+import org.apache.karaf.cellar.obr.ClusterObrUrlEvent;
import org.apache.karaf.cellar.obr.Constants;
import org.apache.karaf.cellar.obr.ObrBundleInfo;
-import org.apache.karaf.cellar.obr.ObrUrlEvent;
import java.util.Set;
-@Command(scope = "cluster", name = "obr-add-url", description = "Register a
repository URL in the distributed OBR service.")
+@Command(scope = "cluster", name = "obr-add-url", description = "Add an OBR
URL in a cluster group")
public class ObrAddUrlCommand extends ObrCommandSupport {
- @Argument(index = 0, name = "group", description = "The cluster group
name.", required = true, multiValued = false)
+ @Argument(index = 0, name = "group", description = "The cluster group
name", required = true, multiValued = false)
String groupName;
- @Argument(index = 1, name = "url", description = "The repository URL to
register in the OBR service.", required = true, multiValued = false)
+ @Argument(index = 1, name = "url", description = "The repository URL to
register in the OBR service", required = true, multiValued = false)
String url;
private EventProducer eventProducer;
+ @Override
public Object doExecute() throws Exception {
// check if the cluster group exists
Group group = groupManager.findGroupByName(groupName);
if (group == null) {
- System.err.println("Cluster group " + groupName + " doesn't
exist.");
+ System.err.println("Cluster group " + groupName + " doesn't
exist");
return null;
}
// check if the producer is ON
if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
- System.err.println("Cluster event producer is OFF for this node");
+ System.err.println("Cluster event producer is OFF");
return null;
}
// check if the URL is allowed
if (!isAllowed(group, Constants.URLS_CONFIG_CATEGORY, url,
EventType.OUTBOUND)) {
- System.err.println("OBR URL " + url + " is blocked outbound");
+ System.err.println("OBR URL " + url + " is blocked outbound for
cluster group " + groupName);
return null;
}
- // push the OBR URL in the distributed set
- Set<String> urls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
- urls.add(url);
- // push the bundles in the OBR distributed set
- Set<ObrBundleInfo> bundles =
clusterManager.getSet(Constants.BUNDLES_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
+ // update the OBR URLs in the cluster group
+ Set<String> clusterUrls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
+ clusterUrls.add(url);
+ // update the OBR bundles in the cluster group
+ Set<ObrBundleInfo> clusterBundles =
clusterManager.getSet(Constants.BUNDLES_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
synchronized (obrService) {
Repository repository = obrService.addRepository(url);
Resource[] resources = repository.getResources();
for (Resource resource : resources) {
ObrBundleInfo info = new
ObrBundleInfo(resource.getPresentationName(), resource.getSymbolicName(),
resource.getVersion().toString());
- bundles.add(info);
+ clusterBundles.add(info);
}
obrService.removeRepository(url);
}
- // create an cluster event and produce it
- ObrUrlEvent event = new ObrUrlEvent(url, Constants.URL_ADD_EVENT_TYPE);
+ // broadcast a cluster event
+ ClusterObrUrlEvent event = new ClusterObrUrlEvent(url,
Constants.URL_ADD_EVENT_TYPE);
event.setForce(true);
event.setSourceGroup(group);
eventProducer.produce(event);
Modified:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrCommandSupport.java
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrCommandSupport.java?rev=1476910&r1=1476909&r2=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrCommandSupport.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrCommandSupport.java
Mon Apr 29 07:17:50 2013
@@ -19,6 +19,9 @@ import org.apache.karaf.cellar.core.Grou
import org.apache.karaf.cellar.core.event.EventType;
import org.apache.karaf.cellar.core.shell.CellarCommandSupport;
+/**
+ * Generic cluster shell OBR command.
+ */
public abstract class ObrCommandSupport extends CellarCommandSupport {
protected RepositoryAdmin obrService;
@@ -31,6 +34,15 @@ public abstract class ObrCommandSupport
this.obrService = obrService;
}
+ /**
+ * Check if the cluster OBR event is allowed.
+ *
+ * @param group the cluster group name.
+ * @param category the OBR event category name.
+ * @param id the event ID.
+ * @param type the event type (inbound, outbound).
+ * @return true if the OBR event is allowed, false else.
+ */
public boolean isAllowed(Group group, String category, String id,
EventType type) {
CellarSupport support = new CellarSupport();
support.setClusterManager(this.clusterManager);
@@ -39,6 +51,7 @@ public abstract class ObrCommandSupport
return support.isAllowed(group, category, id, type);
}
+ @Override
public abstract Object doExecute() throws Exception;
}
Modified:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrDeployCommand.java
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrDeployCommand.java?rev=1476910&r1=1476909&r2=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrDeployCommand.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrDeployCommand.java
Mon Apr 29 07:17:50 2013
@@ -16,27 +16,23 @@ package org.apache.karaf.cellar.obr.shel
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
import org.apache.felix.gogo.commands.Option;
-import org.apache.karaf.cellar.core.Configurations;
import org.apache.karaf.cellar.core.Group;
import org.apache.karaf.cellar.core.control.SwitchStatus;
import org.apache.karaf.cellar.core.event.EventProducer;
import org.apache.karaf.cellar.core.event.EventType;
-import org.apache.karaf.cellar.core.shell.CellarCommandSupport;
+import org.apache.karaf.cellar.obr.ClusterObrBundleEvent;
import org.apache.karaf.cellar.obr.Constants;
-import org.apache.karaf.cellar.obr.ObrBundleEvent;
-import java.util.Set;
-
-@Command(scope = "cluster", name = "obr-deploy", description = "Deploy a
bundle from the OBR assigned to a cluster group.")
+@Command(scope = "cluster", name = "obr-deploy", description = "Deploy an OBR
bundle in a cluster group")
public class ObrDeployCommand extends ObrCommandSupport {
- @Argument(index = 0, name = "group", description = "The cluster group
name.", required = true, multiValued = false)
+ @Argument(index = 0, name = "group", description = "The cluster group
name", required = true, multiValued = false)
String groupName;
- @Argument(index = 1, name="bundleId", description = "The bundle ID
(symbolicname,version in the OBR) to deploy.", required = true, multiValued =
false)
+ @Argument(index = 1, name="bundleId", description = "The bundle ID
(symbolicname,version in the OBR) to deploy", required = true, multiValued =
false)
String bundleId;
- @Option(name = "-s", aliases = { "--start" }, description = "Start the
deployed bundles.", required = false, multiValued = false)
+ @Option(name = "-s", aliases = { "--start" }, description = "Start the
deployed bundles", required = false, multiValued = false)
boolean start = false;
private EventProducer eventProducer;
@@ -52,20 +48,20 @@ public class ObrDeployCommand extends Ob
// check if the producer is ON
if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
- System.err.println("Cluster event producer is OFF for this node");
+ System.err.println("Cluster event producer is OFF");
return null;
}
// check if the bundle is allowed
if (!isAllowed(group, Constants.BUNDLES_CONFIG_CATEGORY, bundleId,
EventType.OUTBOUND)) {
- System.err.println("OBR bundle " + bundleId + " is blocked
outbound");
+ System.err.println("OBR bundle " + bundleId + " is blocked
outbound for cluster group " + groupName);
return null;
}
- // create an event and produce it
+ // broadcast a cluster event
int type = 0;
if (start) type = Constants.BUNDLE_START_EVENT_TYPE;
- ObrBundleEvent event = new ObrBundleEvent(bundleId, type);
+ ClusterObrBundleEvent event = new ClusterObrBundleEvent(bundleId,
type);
event.setForce(true);
event.setSourceGroup(group);
eventProducer.produce(event);
Modified:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrListCommand.java
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrListCommand.java?rev=1476910&r1=1476909&r2=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrListCommand.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrListCommand.java
Mon Apr 29 07:17:50 2013
@@ -23,15 +23,13 @@ import org.apache.karaf.cellar.obr.ObrBu
import java.util.Set;
-/**
- * cluster:obr-list command.
- */
-@Command(scope = "cluster", name = "obr-list", description = "List available
bundles in the OBR of all nodes assigned to a cluster group")
+@Command(scope = "cluster", name = "obr-list", description = "List the OBR
bundles in a cluster group")
public class ObrListCommand extends CellarCommandSupport {
@Argument(index = 0, name = "group", description = "The cluster group
name", required = true, multiValued = false)
String groupName;
+ @Override
public Object doExecute() {
// check if the group exists
Group group = groupManager.findGroupByName(groupName);
@@ -44,11 +42,11 @@ public class ObrListCommand extends Cell
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
- Set<ObrBundleInfo> bundles =
clusterManager.getSet(Constants.BUNDLES_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
+ Set<ObrBundleInfo> clusterBundles =
clusterManager.getSet(Constants.BUNDLES_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
int maxPName = 4;
int maxSName = 13;
int maxVersion = 7;
- for (ObrBundleInfo bundle : bundles) {
+ for (ObrBundleInfo bundle : clusterBundles) {
maxPName = Math.max(maxPName,
emptyIfNull(bundle.getPresentationName()).length());
maxSName = Math.max(maxSName,
emptyIfNull(bundle.getSymbolicName()).length());
maxVersion = Math.max(maxVersion,
emptyIfNull(bundle.getVersion()).length());
@@ -56,7 +54,7 @@ public class ObrListCommand extends Cell
String formatHeader = " %-" + maxPName + "s %-" + maxSName + "s
%-" + maxVersion + "s";
String formatLine = "[%-" + maxPName + "s] [%-" + maxSName + "s]
[%-" + maxVersion + "s]";
System.out.println(String.format(formatHeader, "NAME", "SYMBOLIC
NAME", "VERSION"));
- for (ObrBundleInfo bundle : bundles) {
+ for (ObrBundleInfo bundle : clusterBundles) {
System.out.println(String.format(formatLine,
emptyIfNull(bundle.getPresentationName()),
emptyIfNull(bundle.getSymbolicName()), emptyIfNull(bundle.getVersion())));
}
} finally {
Modified:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrListUrlCommand.java
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrListUrlCommand.java?rev=1476910&r1=1476909&r2=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrListUrlCommand.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrListUrlCommand.java
Mon Apr 29 07:17:50 2013
@@ -22,15 +22,13 @@ import org.apache.karaf.cellar.obr.Const
import java.util.Set;
-/**
- * cluster:obr-list command
- */
-@Command(scope = "cluster", name = "obr-list-url", description = "List
repository URLs defined in the distributed OBR service assigned to a given
group")
+@Command(scope = "cluster", name = "obr-list-url", description = "List the OBR
URLs in a cluster group")
public class ObrListUrlCommand extends CellarCommandSupport {
@Argument(index = 0, name = "group", description = "The cluster group
name", required = true, multiValued = false)
String groupName;
+ @Override
public Object doExecute() throws Exception {
// check if the group exists
Group group = groupManager.findGroupByName(groupName);
@@ -38,10 +36,10 @@ public class ObrListUrlCommand extends C
System.err.println("Cluster group " + groupName + " doesn't
exist");
return null;
}
- // get the URLs from the distribution set
- Set<String> urls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
- if (urls != null) {
- for (String url : urls) {
+ // get the OBR URLs in the cluster group
+ Set<String> clusterUrls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
+ if (clusterUrls != null) {
+ for (String url : clusterUrls) {
System.out.println(url);
}
}
Modified:
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrRemoveUrlCommand.java
URL:
http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrRemoveUrlCommand.java?rev=1476910&r1=1476909&r2=1476910&view=diff
==============================================================================
---
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrRemoveUrlCommand.java
(original)
+++
karaf/cellar/branches/cellar-2.3.x/obr/src/main/java/org/apache/karaf/cellar/obr/shell/ObrRemoveUrlCommand.java
Mon Apr 29 07:17:50 2013
@@ -22,23 +22,24 @@ import org.apache.karaf.cellar.core.Grou
import org.apache.karaf.cellar.core.control.SwitchStatus;
import org.apache.karaf.cellar.core.event.EventProducer;
import org.apache.karaf.cellar.core.event.EventType;
+import org.apache.karaf.cellar.obr.ClusterObrUrlEvent;
import org.apache.karaf.cellar.obr.Constants;
import org.apache.karaf.cellar.obr.ObrBundleInfo;
-import org.apache.karaf.cellar.obr.ObrUrlEvent;
import java.util.Set;
-@Command(scope = "cluster", name = "obr-remove-url", description = "Remove a
repository URL from the distributed OBR service assigned to a cluster group.")
+@Command(scope = "cluster", name = "obr-remove-url", description = "Remove an
OBR URL from a cluster group")
public class ObrRemoveUrlCommand extends ObrCommandSupport {
- @Argument(index = 0, name = "group", description = "The cluster group
name.", required = true, multiValued = false)
+ @Argument(index = 0, name = "group", description = "The cluster group
name", required = true, multiValued = false)
String groupName;
- @Argument(index = 1, name = "url", description = "The repository URL to
add in the OBR service.", required = true, multiValued = false)
+ @Argument(index = 1, name = "url", description = "The OBR URL", required =
true, multiValued = false)
String url;
private EventProducer eventProducer;
+ @Override
public Object doExecute() throws Exception {
// check if the group exists
Group group = groupManager.findGroupByName(groupName);
@@ -49,33 +50,33 @@ public class ObrRemoveUrlCommand extends
// check if the producer is ON
if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
- System.err.println("Cluster event producer is OFF for this node");
+ System.err.println("Cluster event producer is OFF");
return null;
}
// check if the URL is allowed
if (!isAllowed(group, Constants.URLS_CONFIG_CATEGORY, url,
EventType.OUTBOUND)) {
- System.err.println("OBR URL " + url + " is blocked outbound");
+ System.err.println("OBR URL " + url + " is blocked outbound for
cluster group " + groupName);
return null;
}
- // remove URL from the distributed map
- Set<String> urls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
- urls.remove(url);
- // remove bundles from the distributed map
- Set<ObrBundleInfo> bundles =
clusterManager.getSet(Constants.BUNDLES_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
+ // update the OBR URLs in the cluster group
+ Set<String> clusterUrls =
clusterManager.getSet(Constants.URLS_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
+ clusterUrls.remove(url);
+ // update the OBR bundles in cluster group
+ Set<ObrBundleInfo> clusterBundles =
clusterManager.getSet(Constants.BUNDLES_DISTRIBUTED_SET_NAME +
Configurations.SEPARATOR + groupName);
synchronized (obrService) {
Repository repository = obrService.addRepository(url);
Resource[] resources = repository.getResources();
for (Resource resource : resources) {
ObrBundleInfo info = new
ObrBundleInfo(resource.getPresentationName(), resource.getSymbolicName(),
resource.getVersion().toString());
- bundles.remove(info);
+ clusterBundles.remove(info);
}
obrService.removeRepository(url);
}
- // create an event and produce it
- ObrUrlEvent event = new ObrUrlEvent(url,
Constants.URL_REMOVE_EVENT_TYPE);
+ // broadcast a cluster event
+ ClusterObrUrlEvent event = new ClusterObrUrlEvent(url,
Constants.URL_REMOVE_EVENT_TYPE);
event.setSourceGroup(group);
eventProducer.produce(event);