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 2012/05/04 14:52:46 UTC
svn commit: r1333918 - in
/karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal:
CellarFeaturesMBeanImpl.java CellarGroupMBeanImpl.java CellarMBeanImpl.java
CellarNodeMBeanImpl.java
Author: jbonofre
Date: Fri May 4 12:52:46 2012
New Revision: 1333918
URL: http://svn.apache.org/viewvc?rev=1333918&view=rev
Log:
[KARAF-1316] Apply the same checks in the MBeans
Modified:
karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java
karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarGroupMBeanImpl.java
karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java
karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarNodeMBeanImpl.java
Modified: karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java?rev=1333918&r1=1333917&r2=1333918&view=diff
==============================================================================
--- karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java (original)
+++ karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java Fri May 4 12:52:46 2012
@@ -80,6 +80,10 @@ public class CellarFeaturesMBeanImpl ext
throw new IllegalStateException("Cluster event producer is OFF for this node");
}
+ // TODO check if the feature exist on the group
+ // TODO update the distributed resource
+
+ // broadcast the cluster event
RemoteFeaturesEvent event = new RemoteFeaturesEvent(name, version, FeatureEvent.EventType.FeatureInstalled);
event.setSourceGroup(group);
eventProducer.produce(event);
@@ -101,6 +105,9 @@ public class CellarFeaturesMBeanImpl ext
throw new IllegalStateException("Cluster event producer is OFF for this node");
}
+ // TODO check if the feature exist on the group
+ // TODO update the distributed resource
+
RemoteFeaturesEvent event = new RemoteFeaturesEvent(name, version, FeatureEvent.EventType.FeatureUninstalled);
event.setSourceGroup(group);
eventProducer.produce(event);
Modified: karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarGroupMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarGroupMBeanImpl.java?rev=1333918&r1=1333917&r2=1333918&view=diff
==============================================================================
--- karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarGroupMBeanImpl.java (original)
+++ karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarGroupMBeanImpl.java Fri May 4 12:52:46 2012
@@ -26,6 +26,9 @@ import javax.management.NotCompliantMBea
import javax.management.StandardMBean;
import javax.management.openmbean.*;
import java.util.*;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
/**
* Implementation of the Cellar Group MBean;
@@ -93,25 +96,46 @@ public class CellarGroupMBeanImpl extend
}
}
- public void join(String group, String nodeId) throws Exception {
- List<String> nodes = new ArrayList<String>();
- nodes.add(nodeId);
+ public void join(String groupName, String nodeId) throws Exception {
+ Group group = groupManager.findGroupByName(groupName);
+ if (group == null) {
+ throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist");
+ }
+
+ Node node = clusterManager.findNodeById(nodeId);
+ if (node == null) {
+ throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+ }
+
+ Set<Node> nodes = new HashSet<Node>();
+ nodes.add(node);
+
ManageGroupCommand command = new ManageGroupCommand(clusterManager.generateId());
command.setAction(ManageGroupAction.JOIN);
- command.setGroupName(group);
- Set<Node> recipientList = clusterManager.listNodes(nodes);
- command.setDestination(recipientList);
+ command.setGroupName(groupName);
+ command.setDestination(nodes);
+
executionContext.execute(command);
}
- public void quit(String group, String nodeId) throws Exception {
- List<String> nodes = new ArrayList<String>();
- nodes.add(nodeId);
+ public void quit(String groupName, String nodeId) throws Exception {
+ Group group = groupManager.findGroupByName(groupName);
+ if (group == null) {
+ throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist");
+ }
+
+ Node node = clusterManager.findNodeById(nodeId);
+ if (node == null) {
+ throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+ }
+
+ Set<Node> nodes = new HashSet<Node>();
+ nodes.add(node);
+
ManageGroupCommand command = new ManageGroupCommand(clusterManager.generateId());
command.setAction(ManageGroupAction.QUIT);
- command.setGroupName(group);
- Set<Node> recipientList = clusterManager.listNodes(nodes);
- command.setDestination(recipientList);
+ command.setGroupName(groupName);
+ command.setDestination(nodes);
executionContext.execute(command);
}
Modified: karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java?rev=1333918&r1=1333917&r2=1333918&view=diff
==============================================================================
--- karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java (original)
+++ karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java Fri May 4 12:52:46 2012
@@ -103,9 +103,15 @@ public class CellarMBeanImpl extends Sta
public void handlerStart(String handlerId, String nodeId) throws Exception {
ManageHandlersCommand command = new ManageHandlersCommand(clusterManager.generateId());
- List<String> nodeIds = new ArrayList<String>();
- nodeIds.add(nodeId);
- Set<Node> nodes = clusterManager.listNodes(nodeIds);
+
+ Node node = clusterManager.findNodeById(nodeId);
+ if (node == null) {
+ throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+ }
+
+ Set<Node> nodes = new HashSet<Node>();
+ nodes.add(node);
+
command.setHandlerName(handlerId);
command.setDestination(nodes);
command.setStatus(Boolean.TRUE);
@@ -113,9 +119,15 @@ public class CellarMBeanImpl extends Sta
public void handlerStop(String handlerId, String nodeId) throws Exception {
ManageHandlersCommand command = new ManageHandlersCommand(clusterManager.generateId());
- List<String> nodeIds = new ArrayList<String>();
- nodeIds.add(nodeId);
- Set<Node> nodes = clusterManager.listNodes(nodeIds);
+
+ Node node = clusterManager.findNodeById(nodeId);
+ if (node == null) {
+ throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+ }
+
+ Set<Node> nodes = new HashSet<Node>();
+ nodes.add(node);
+
command.setHandlerName(handlerId);
command.setDestination(nodes);
command.setStatus(Boolean.FALSE);
@@ -146,21 +158,33 @@ public class CellarMBeanImpl extends Sta
return table;
}
- public void consumerStart(String node) throws Exception {
+ public void consumerStart(String nodeId) throws Exception {
ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId());
- List<String> ids = new ArrayList<String>();
- ids.add(node);
- Set<Node> nodes = clusterManager.listNodes(ids);
+
+ Node node = clusterManager.findNodeById(nodeId);
+ if (node == null) {
+ throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+ }
+
+ Set<Node> nodes = new HashSet<Node>();
+ nodes.add(node);
+
command.setDestination(nodes);
command.setStatus(SwitchStatus.ON);
executionContext.execute(command);
}
- public void consumerStop(String node) throws Exception {
+ public void consumerStop(String nodeId) throws Exception {
ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId());
- List<String> ids = new ArrayList<String>();
- ids.add(node);
- Set<Node> nodes = clusterManager.listNodes(ids);
+
+ Node node = clusterManager.findNodeById(nodeId);
+ if (node == null) {
+ throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+ }
+
+ Set<Node> nodes = new HashSet<Node>();
+ nodes.add(node);
+
command.setDestination(nodes);
command.setStatus(SwitchStatus.OFF);
executionContext.execute(command);
@@ -191,21 +215,33 @@ public class CellarMBeanImpl extends Sta
return table;
}
- public void producerStop(String node) throws Exception {
+ public void producerStop(String nodeId) throws Exception {
ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId());
- List<String> ids = new ArrayList<String>();
- ids.add(node);
- Set<Node> nodes = clusterManager.listNodes(ids);
+
+ Node node = clusterManager.findNodeById(nodeId);
+ if (node == null) {
+ throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+ }
+
+ Set<Node> nodes = new HashSet<Node>();
+ nodes.add(node);
+
command.setDestination(nodes);
command.setStatus(SwitchStatus.OFF);
executionContext.execute(command);
}
- public void producerStart(String node) throws Exception {
+ public void producerStart(String nodeId) throws Exception {
ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId());
- List<String> ids = new ArrayList<String>();
- ids.add(node);
- Set<Node> nodes = clusterManager.listNodes(ids);
+
+ Node node = clusterManager.findNodeById(nodeId);
+ if (node == null) {
+ throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist)");
+ }
+
+ Set<Node> nodes = new HashSet<Node>();
+ nodes.add(node);
+
command.setDestination(nodes);
command.setStatus(SwitchStatus.ON);
executionContext.execute(command);
Modified: karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarNodeMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarNodeMBeanImpl.java?rev=1333918&r1=1333917&r2=1333918&view=diff
==============================================================================
--- karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarNodeMBeanImpl.java (original)
+++ karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarNodeMBeanImpl.java Fri May 4 12:52:46 2012
@@ -57,6 +57,9 @@ public class CellarNodeMBeanImpl extends
public long pingNode(String nodeId) throws Exception {
Node node = clusterManager.findNodeById(nodeId);
+ if (node == null) {
+ throw new IllegalArgumentException("Cluster group " + nodeId + " doesn't exist");
+ }
Long start = System.currentTimeMillis();
Ping ping = new Ping(clusterManager.generateId());
ping.setDestination(new HashSet(Arrays.asList(node)));