Return-Path: X-Original-To: apmail-karaf-commits-archive@minotaur.apache.org Delivered-To: apmail-karaf-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9F2B53FDE for ; Fri, 6 May 2011 17:56:20 +0000 (UTC) Received: (qmail 52303 invoked by uid 500); 6 May 2011 17:56:20 -0000 Delivered-To: apmail-karaf-commits-archive@karaf.apache.org Received: (qmail 52277 invoked by uid 500); 6 May 2011 17:56:20 -0000 Mailing-List: contact commits-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list commits@karaf.apache.org Received: (qmail 52270 invoked by uid 99); 6 May 2011 17:56:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 May 2011 17:56:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 May 2011 17:56:07 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A2FD32388B3A; Fri, 6 May 2011 17:55:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1100302 [5/5] - in /karaf/cellar: ./ branches/ tags/ trunk/ trunk/config/ trunk/config/src/ trunk/config/src/main/ trunk/config/src/main/java/ trunk/config/src/main/java/org/ trunk/config/src/main/java/org/apache/ trunk/config/src/main/jav... Date: Fri, 06 May 2011 17:55:42 -0000 To: commits@karaf.apache.org From: iocanel@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110506175544.A2FD32388B3A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupDeleteCommand.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupDeleteCommand.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupDeleteCommand.java (added) +++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupDeleteCommand.java Fri May 6 17:55:35 2011 @@ -0,0 +1,63 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.shell.group; + +import org.apache.karaf.cellar.core.Group; +import org.apache.karaf.cellar.core.Node; +import org.apache.karaf.cellar.core.control.ManageGroupAction; +import org.apache.felix.gogo.commands.Argument; +import org.apache.felix.gogo.commands.Command; + +import java.util.LinkedList; +import java.util.List; + +/** + * @author iocanel + */ +@Command(scope = "cluster", name = "group-delete", description = "Deletes a group") +public class GroupDeleteCommand extends GroupSupport { + + + @Argument(index = 0, name = "group", description = "The name of the group to delete", required = false, multiValued = false) + String group; + + /** + * Execute the command. + * + * @return + * @throws Exception + */ + @Override + protected Object doExecute() throws Exception { + ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); + Group g = groupManager.findGroupByName(group); + List nodes = new LinkedList(); + + if (g.getMembers() != null && !g.getMembers().isEmpty()) { + for (Node n : g.getMembers()) { + nodes.add(n.getId()); + } + doExecute(ManageGroupAction.QUIT, group, nodes); + } + + groupManager.deleteGroup(group); + } finally { + Thread.currentThread().setContextClassLoader(originalClassLoader); + } + return null; + } +} Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupJoinCommand.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupJoinCommand.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupJoinCommand.java (added) +++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupJoinCommand.java Fri May 6 17:55:35 2011 @@ -0,0 +1,46 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.shell.group; + +import org.apache.karaf.cellar.core.control.ManageGroupAction; +import org.apache.felix.gogo.commands.Argument; +import org.apache.felix.gogo.commands.Command; + +import java.util.List; + +/** + * @author iocanel + */ +@Command(scope = "cluster", name = "group-join", description = "Manages nodes and groups") +public class GroupJoinCommand extends GroupSupport { + + + @Argument(index = 0, name = "group", description = "The name of the group to join", required = false, multiValued = false) + String group; + + @Argument(index = 1, name = "node", description = "The id of the node(s) to turn on/off event producer. If none specified current is assumed", required = false, multiValued = true) + List nodes; + + /** + * Execute the command. + * + * @return + * @throws Exception + */ + @Override + protected Object doExecute() throws Exception { + return doExecute(ManageGroupAction.JOIN, group, nodes); + } +} Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupListCommand.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupListCommand.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupListCommand.java (added) +++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupListCommand.java Fri May 6 17:55:35 2011 @@ -0,0 +1,42 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.shell.group; + +import org.apache.karaf.cellar.core.control.ManageGroupAction; +import org.apache.felix.gogo.commands.Argument; +import org.apache.felix.gogo.commands.Command; + +import java.util.List; + +/** + * @author iocanel + */ +@Command(scope = "cluster", name = "group-list", description = "Manages nodes and groups") +public class GroupListCommand extends GroupSupport { + + @Argument(index = 0, name = "node", description = "The id of the node(s) to turn on/off event producer", required = false, multiValued = true) + List nodes; + + /** + * Execute the command. + * + * @return + * @throws Exception + */ + @Override + protected Object doExecute() throws Exception { + return doExecute(ManageGroupAction.LIST, null, nodes); + } +} Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupQuitCommand.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupQuitCommand.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupQuitCommand.java (added) +++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupQuitCommand.java Fri May 6 17:55:35 2011 @@ -0,0 +1,46 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.shell.group; + +import org.apache.karaf.cellar.core.control.ManageGroupAction; +import org.apache.felix.gogo.commands.Argument; +import org.apache.felix.gogo.commands.Command; + +import java.util.List; + +/** + * @author iocanel + */ +@Command(scope = "cluster", name = "group-quit", description = "Manages nodes and groups") +public class GroupQuitCommand extends GroupSupport { + + + @Argument(index = 0, name = "group", description = "The name of the group to join", required = false, multiValued = false) + String group; + + @Argument(index = 1, name = "node", description = "The id of the node(s) to turn on/off event producer", required = false, multiValued = true) + List nodes; + + /** + * Execute the command. + * + * @return + * @throws Exception + */ + @Override + protected Object doExecute() throws Exception { + return doExecute(ManageGroupAction.QUIT, group, nodes); + } +} Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSetCommand.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSetCommand.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSetCommand.java (added) +++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSetCommand.java Fri May 6 17:55:35 2011 @@ -0,0 +1,46 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.shell.group; + +import org.apache.karaf.cellar.core.control.ManageGroupAction; +import org.apache.felix.gogo.commands.Argument; +import org.apache.felix.gogo.commands.Command; + +import java.util.List; + +/** + * @author: iocanel + */ +@Command(scope = "cluster", name = "group-set", description = "Set the target nodes to a specific group") +public class GroupSetCommand extends GroupSupport { + + + @Argument(index = 0, name = "group", description = "The name of the group to join", required = false, multiValued = false) + String group; + + @Argument(index = 1, name = "node", description = "The id of the node(s) to turn on/off event producer. If none specified current is assumed", required = false, multiValued = true) + List nodes; + + /** + * Execute the command. + * + * @return + * @throws Exception + */ + @Override + protected Object doExecute() throws Exception { + return doExecute(ManageGroupAction.SET, group, nodes); + } +} Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java (added) +++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java Fri May 6 17:55:35 2011 @@ -0,0 +1,86 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.shell.group; + +import org.apache.karaf.cellar.core.Group; +import org.apache.karaf.cellar.core.Node; +import org.apache.karaf.cellar.core.control.ManageGroupAction; +import org.apache.karaf.cellar.core.control.ManageGroupCommand; +import org.apache.karaf.cellar.core.control.ManageGroupResult; +import org.apache.karaf.cellar.shell.ClusterCommandSuppot; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * @author iocanel + */ +public abstract class GroupSupport extends ClusterCommandSuppot { + + protected static final String OUTPUT_FORMAT = "%1s %-20s %s"; + + /** + * Execut the command. + * + * @return + * @throws Exception + */ + protected Object doExecute(ManageGroupAction action, String group, Collection nodes) throws Exception { + ManageGroupCommand command = new ManageGroupCommand(clusterManager.generateId()); + Set recipientList = clusterManager.listNodes(nodes); + + //Set the recipient list + if (recipientList != null && !recipientList.isEmpty()) { + command.setDestination(recipientList); + } else { + Set recipients = new HashSet(); + recipients.add(clusterManager.getNode()); + command.setDestination(recipients); + } + + command.setAction(action); + + + if (group != null) { + command.setGroupName(group); + } + + Map results = executionContext.execute(command); + if (results == null || results.isEmpty()) { + System.out.println("No result received within given timeout"); + } else { + System.out.println(String.format(OUTPUT_FORMAT, " ", "Node", "Group")); + for (Node node : results.keySet()) { + ManageGroupResult result = results.get(node); + if (result != null && result.getGroups() != null) { + for (Group g : result.getGroups()) { + if (g.getMembers() != null && !g.getMembers().isEmpty()) { + for (Node memeber : g.getMembers()) { + String name = g.getName(); + String mark = " "; + if (memeber.equals(clusterManager.getNode())) + mark = "*"; + System.out.println(String.format(OUTPUT_FORMAT, mark, memeber.getId(), name)); + } + } else System.out.println(String.format(OUTPUT_FORMAT, "", "", g.getName())); + } + } + } + } + return null; + } +} Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersStartCommand.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersStartCommand.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersStartCommand.java (added) +++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersStartCommand.java Fri May 6 17:55:35 2011 @@ -0,0 +1,68 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.shell.handler; + +import org.apache.karaf.cellar.core.ClusterManager; +import org.apache.karaf.cellar.core.command.ExecutionContext; +import org.apache.felix.gogo.commands.Argument; +import org.apache.felix.gogo.commands.Command; + +import java.util.List; + +/** + * @author iocanel + */ +@Command(scope = "cluster", name = "handlers", description = "Starts the handler of the specified nodes.") +public class HandlersStartCommand extends HandlersSupport { + + private static final String OUTPUT_FORMAT = "%-20s %-7s %s"; + + private ClusterManager clusterManager; + private ExecutionContext executionContext; + + @Argument(index = 0, name = "handler-start", description = "The id of the event handler", required = false, multiValued = false) + String handler; + + @Argument(index = 1, name = "node", description = "The id of the node(s)", required = false, multiValued = true) + List nodes; + + + /** + * Execute the command. + * + * @return + * @throws Exception + */ + @Override + protected Object doExecute() throws Exception { + return doExecute(handler, nodes, Boolean.TRUE); + } + + public ExecutionContext getExecutionContext() { + return executionContext; + } + + public void setExecutionContext(ExecutionContext executionContext) { + this.executionContext = executionContext; + } + + public ClusterManager getClusterManager() { + return clusterManager; + } + + public void setClusterManager(ClusterManager clusterManager) { + this.clusterManager = clusterManager; + } +} Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersStatusCommand.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersStatusCommand.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersStatusCommand.java (added) +++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersStatusCommand.java Fri May 6 17:55:35 2011 @@ -0,0 +1,68 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.shell.handler; + +import org.apache.karaf.cellar.core.ClusterManager; +import org.apache.karaf.cellar.core.command.ExecutionContext; +import org.apache.felix.gogo.commands.Argument; +import org.apache.felix.gogo.commands.Command; + +import java.util.List; + +/** + * @author iocanel + */ +@Command(scope = "cluster", name = "handler-status", description = "Lists the handlers of the specified nodes.") +public class HandlersStatusCommand extends HandlersSupport { + + private static final String OUTPUT_FORMAT = "%-20s %-7s %s"; + + private ClusterManager clusterManager; + private ExecutionContext executionContext; + + @Argument(index = 0, name = "handler-start", description = "The id of the event handler", required = false, multiValued = false) + String handler; + + @Argument(index = 1, name = "node", description = "The id of the node(s)", required = false, multiValued = true) + List nodes; + + + /** + * Execute the command. + * + * @return + * @throws Exception + */ + @Override + protected Object doExecute() throws Exception { + return doExecute(handler, nodes, null); + } + + public ExecutionContext getExecutionContext() { + return executionContext; + } + + public void setExecutionContext(ExecutionContext executionContext) { + this.executionContext = executionContext; + } + + public ClusterManager getClusterManager() { + return clusterManager; + } + + public void setClusterManager(ClusterManager clusterManager) { + this.clusterManager = clusterManager; + } +} Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersStopCommand.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersStopCommand.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersStopCommand.java (added) +++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersStopCommand.java Fri May 6 17:55:35 2011 @@ -0,0 +1,68 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.shell.handler; + +import org.apache.karaf.cellar.core.ClusterManager; +import org.apache.karaf.cellar.core.command.ExecutionContext; +import org.apache.felix.gogo.commands.Argument; +import org.apache.felix.gogo.commands.Command; + +import java.util.List; + +/** + * @author iocanel + */ +@Command(scope = "cluster", name = "handler-stop", description = "Stops the handler of the specified nodes.") +public class HandlersStopCommand extends HandlersSupport { + + private static final String OUTPUT_FORMAT = "%-20s %-7s %s"; + + private ClusterManager clusterManager; + private ExecutionContext executionContext; + + @Argument(index = 0, name = "handler", description = "The id of the event handler", required = false, multiValued = false) + String handler; + + @Argument(index = 1, name = "node", description = "The id of the node(s)", required = false, multiValued = true) + List nodes; + + + /** + * Execute the command. + * + * @return + * @throws Exception + */ + @Override + protected Object doExecute() throws Exception { + return doExecute(handler, nodes, Boolean.FALSE); + } + + public ExecutionContext getExecutionContext() { + return executionContext; + } + + public void setExecutionContext(ExecutionContext executionContext) { + this.executionContext = executionContext; + } + + public ClusterManager getClusterManager() { + return clusterManager; + } + + public void setClusterManager(ClusterManager clusterManager) { + this.clusterManager = clusterManager; + } +} Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java (added) +++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java Fri May 6 17:55:35 2011 @@ -0,0 +1,75 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.shell.handler; + +import org.apache.karaf.cellar.core.Node; +import org.apache.karaf.cellar.core.control.ManageHandlersCommand; +import org.apache.karaf.cellar.core.control.ManageHandlersResult; +import org.apache.karaf.cellar.shell.ClusterCommandSuppot; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author iocanel + */ +public abstract class HandlersSupport extends ClusterCommandSuppot { + + protected static final String OUTPUT_FORMAT = "%-20s %-7s %s"; + + /** + * Execute the command. + * + * @return + * @throws Exception + */ + protected Object doExecute(String handler, List nodes, Boolean status) throws Exception { + ManageHandlersCommand command = new ManageHandlersCommand(clusterManager.generateId()); + Set recipientList = clusterManager.listNodes(nodes); + + //Set the recipient list + if (recipientList != null && !recipientList.isEmpty()) { + command.setDestination(recipientList); + } + + //Set the name of the handler. + if (handler != null && handler.length() > 2) { + handler = handler.substring(1); + handler = handler.substring(0, handler.length() - 1); + command.setHandlesName(handler); + } + + command.setStatus(status); + + + Map results = executionContext.execute(command); + if (results == null || results.isEmpty()) { + System.out.println("No result received within given timeout"); + } else { + System.out.println(String.format(OUTPUT_FORMAT, "Node", "Status", "Event Handler")); + for (Node node : results.keySet()) { + ManageHandlersResult result = results.get(node); + if (result != null && result.getHandlers() != null) { + for (String h : result.getHandlers().keySet()) { + String s = result.getHandlers().get(h); + System.out.println(String.format(OUTPUT_FORMAT, node.getId(), s, handler)); + } + } + } + } + return null; + } +} Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerStartCommand.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerStartCommand.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerStartCommand.java (added) +++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerStartCommand.java Fri May 6 17:55:35 2011 @@ -0,0 +1,43 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.shell.producer; + +import org.apache.karaf.cellar.core.control.SwitchStatus; +import org.apache.felix.gogo.commands.Argument; +import org.apache.felix.gogo.commands.Command; + +import java.util.List; + +/** + * @author iocanel + */ +@Command(scope = "cluster", name = "producer-start", description = "Turns on the producer capabilities of a node.") +public class ProducerStartCommand extends ProducerSupport { + + @Argument(index = 0, name = "node", description = "The id of the node(s) to turn on/off event producer", required = false, multiValued = true) + List nodes; + + + /** + * Execute the command. + * + * @return + * @throws Exception + */ + @Override + protected Object doExecute() throws Exception { + return doExecute(nodes, SwitchStatus.ON); + } +} Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerStatusCommand.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerStatusCommand.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerStatusCommand.java (added) +++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerStatusCommand.java Fri May 6 17:55:35 2011 @@ -0,0 +1,42 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.shell.producer; + +import org.apache.felix.gogo.commands.Argument; +import org.apache.felix.gogo.commands.Command; + +import java.util.List; + +/** + * @author iocanel + */ +@Command(scope = "cluster", name = "producer-start", description = "Displays the producer capabilities of a node.") +public class ProducerStatusCommand extends ProducerSupport { + + @Argument(index = 0, name = "node", description = "The id of the node(s) to turn on/off event producer", required = false, multiValued = true) + List nodes; + + + /** + * Execute the command. + * + * @return + * @throws Exception + */ + @Override + protected Object doExecute() throws Exception { + return doExecute(nodes, null); + } +} Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerStopCommand.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerStopCommand.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerStopCommand.java (added) +++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerStopCommand.java Fri May 6 17:55:35 2011 @@ -0,0 +1,43 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.shell.producer; + +import org.apache.karaf.cellar.core.control.SwitchStatus; +import org.apache.felix.gogo.commands.Argument; +import org.apache.felix.gogo.commands.Command; + +import java.util.List; + +/** + * @author iocanel + */ +@Command(scope = "cluster", name = "producer-stop", description = "Turns off the producer capabilities of a node.") +public class ProducerStopCommand extends ProducerSupport { + + @Argument(index = 0, name = "node", description = "The id of the node(s) to turn on/off event producer", required = false, multiValued = true) + List nodes; + + + /** + * Execute the command. + * + * @return + * @throws Exception + */ + @Override + protected Object doExecute() throws Exception { + return doExecute(nodes, SwitchStatus.OFF); + } +} Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java (added) +++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java Fri May 6 17:55:35 2011 @@ -0,0 +1,65 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.shell.producer; + +import org.apache.karaf.cellar.core.Node; +import org.apache.karaf.cellar.core.control.ProducerSwitchCommand; +import org.apache.karaf.cellar.core.control.ProducerSwitchResult; +import org.apache.karaf.cellar.core.control.SwitchStatus; +import org.apache.karaf.cellar.shell.ClusterCommandSuppot; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author iocanel + */ + +public abstract class ProducerSupport extends ClusterCommandSuppot { + + protected static final String OUTPUT_FORMAT = "%-20s %s"; + + /** + * Execut the command. + * + * @return + * @throws Exception + */ + protected Object doExecute(List nodes, SwitchStatus status) throws Exception { + ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId()); + Set recipientList = clusterManager.listNodes(nodes); + + //Set the recipient list + if (recipientList != null && !recipientList.isEmpty()) { + command.setDestination(recipientList); + } + + command.setStatus(status); + + + Map results = executionContext.execute(command); + if (results == null || results.isEmpty()) { + System.out.println("No result received within given timeout"); + } else { + System.out.println(String.format(OUTPUT_FORMAT, "Node", "Status")); + for (Node node : results.keySet()) { + ProducerSwitchResult result = results.get(node); + System.out.println(String.format(OUTPUT_FORMAT, node.getId(), result.getStatus())); + } + } + return null; + } +} Added: karaf/cellar/trunk/shell/src/main/resources/OSGI-INF/blueprint/shell-cluster.xml URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/resources/OSGI-INF/blueprint/shell-cluster.xml?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/shell/src/main/resources/OSGI-INF/blueprint/shell-cluster.xml (added) +++ karaf/cellar/trunk/shell/src/main/resources/OSGI-INF/blueprint/shell-cluster.xml Fri May 6 17:55:35 2011 @@ -0,0 +1,209 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: karaf/cellar/trunk/src/main/resources/feature.xml URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/src/main/resources/feature.xml?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/src/main/resources/feature.xml (added) +++ karaf/cellar/trunk/src/main/resources/feature.xml Fri May 6 17:55:35 2011 @@ -0,0 +1,43 @@ + + + + + mvn:org.apache.karaf.assemblies.features/standard/${karaf.version}/xml/features + + + mvn:com.hazelcast/hazelcast/${hazelcast.version} + + + + hazelcast + war + mvn:com.hazelcast/hazelcast-monitor/${hazelcast.version}/war + + + + hazelcast + spring-dm + mvn:org.apache.karaf.cellar/core/${project.version} + mvn:org.apache.karaf.cellar/config/${project.version} + mvn:org.apache.karaf.cellar/features/${project.version} + mvn:org.apache.karaf.cellar/utils/${project.version} + mvn:org.apache.karaf.cellar/shell/${project.version} + mvn:org.apache.karaf.cellar/hazelcast/${project.version} + mvn:org.apache.karaf.cellar/cellar/${project.version}/cfg/groups + + mvn:org.apache.karaf.cellar/cellar/${project.version}/cfg/node + + + \ No newline at end of file Added: karaf/cellar/trunk/src/main/resources/groups.cfg URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/src/main/resources/groups.cfg?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/src/main/resources/groups.cfg (added) +++ karaf/cellar/trunk/src/main/resources/groups.cfg Fri May 6 17:55:35 2011 @@ -0,0 +1,11 @@ +default.config.whitelist.inbound=* +default.config.whitelist.outbound=* +default.config.blacklist.inbound=org.apache.karaf.cellar.node,org.apache.karaf.management +default.config.blacklist.outbound=org.apache.karaf.cellar.node,org.apache.karaf.management +default.config.sync=true +default.features.whitelist.inbound=* +default.features.whitelist.outbound=* +default.features.blacklist.inbound=cellar +default.features.blacklist.outbound=cellar +default.features.sync=true +default.repositories.sync=true \ No newline at end of file Added: karaf/cellar/trunk/src/main/resources/node.cfg URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/src/main/resources/node.cfg?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/src/main/resources/node.cfg (added) +++ karaf/cellar/trunk/src/main/resources/node.cfg Fri May 6 17:55:35 2011 @@ -0,0 +1 @@ +groups=default \ No newline at end of file Added: karaf/cellar/trunk/utils/pom.xml URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/utils/pom.xml?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/utils/pom.xml (added) +++ karaf/cellar/trunk/utils/pom.xml Fri May 6 17:55:35 2011 @@ -0,0 +1,64 @@ + + + + + + org.apache.karaf.cellar + karaf-cellar + 1.0.0-SNAPSHOT + + 4.0.0 + + org.apache.karaf.cellar + utils + bundle + Apache Karaf :: Cellar :: Utils + + + + UTF-8 + + !org.apache.karaf.cellar.utils*;version=${project.version}, + org.apache.karaf.cellar.core*;version=${project.version}, + * + + javax.*,org.w3c.*,org.xml.* + + org.apache.karaf.cellar.utils*;version=${project.version} + + + + + + + org.apache.karaf.cellar + core + ${project.version} + + + + org.apache.felix + org.apache.felix.configadmin + + + + org.slf4j + slf4j-api + + + + \ No newline at end of file Added: karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/Ping.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/Ping.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/Ping.java (added) +++ karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/Ping.java Fri May 6 17:55:35 2011 @@ -0,0 +1,28 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.utils.ping; + +import org.apache.karaf.cellar.core.command.Command; + +/** + * @author iocanel + */ +public class Ping extends Command { + + public Ping(String id) { + super(id); + } + +} Added: karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/PingHandler.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/PingHandler.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/PingHandler.java (added) +++ karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/PingHandler.java Fri May 6 17:55:35 2011 @@ -0,0 +1,44 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.utils.ping; + +import org.apache.karaf.cellar.core.command.CommandHandler; +import org.apache.karaf.cellar.core.control.BasicSwitch; +import org.apache.karaf.cellar.core.control.Switch; + +/** + * @author iocanel + */ +public class PingHandler extends CommandHandler { + + public static final String SWITCH_ID = "org.apache.karaf.cellar.command.ping.switch"; + + private final Switch commandSwitch = new BasicSwitch(SWITCH_ID); + + @Override + public Pong execute(Ping command) { + return new Pong(command.getId()); + } + + @Override + public Class getType() { + return Ping.class; + } + + @Override + public Switch getSwitch() { + return commandSwitch; + } +} Added: karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/Pong.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/Pong.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/Pong.java (added) +++ karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/Pong.java Fri May 6 17:55:35 2011 @@ -0,0 +1,27 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.utils.ping; + +import org.apache.karaf.cellar.core.command.Result; + +/** + * @author iocanel + */ +public class Pong extends Result { + + public Pong(String id) { + super(id); + } +} Added: karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/PongHandler.java URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/PongHandler.java?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/PongHandler.java (added) +++ karaf/cellar/trunk/utils/src/main/java/org/apache/karaf/cellar/utils/ping/PongHandler.java Fri May 6 17:55:35 2011 @@ -0,0 +1,28 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.karaf.cellar.utils.ping; + +import org.apache.karaf.cellar.core.command.ResultHandler; + +/** + * @author iocanel + */ +public class PongHandler extends ResultHandler { + + @Override + public Class getType() { + return Pong.class; + } +} Added: karaf/cellar/trunk/utils/src/main/resources/OSGI-INF/blueprint/blueprint.xml URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/utils/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1100302&view=auto ============================================================================== --- karaf/cellar/trunk/utils/src/main/resources/OSGI-INF/blueprint/blueprint.xml (added) +++ karaf/cellar/trunk/utils/src/main/resources/OSGI-INF/blueprint/blueprint.xml Fri May 6 17:55:35 2011 @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + +