Return-Path: Delivered-To: apmail-incubator-ace-commits-archive@minotaur.apache.org Received: (qmail 7096 invoked from network); 21 Mar 2011 00:11:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Mar 2011 00:11:42 -0000 Received: (qmail 95561 invoked by uid 500); 21 Mar 2011 00:11:42 -0000 Delivered-To: apmail-incubator-ace-commits-archive@incubator.apache.org Received: (qmail 95538 invoked by uid 500); 21 Mar 2011 00:11:42 -0000 Mailing-List: contact ace-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ace-dev@incubator.apache.org Delivered-To: mailing list ace-commits@incubator.apache.org Received: (qmail 95530 invoked by uid 99); 21 Mar 2011 00:11:42 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Mar 2011 00:11:42 +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; Mon, 21 Mar 2011 00:11:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D29F523889EB; Mon, 21 Mar 2011 00:11:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1083621 - in /incubator/ace/trunk: ./ ace-nodelauncher-ui/ ace-nodelauncher-ui/src/ ace-nodelauncher-ui/src/main/ ace-nodelauncher-ui/src/main/java/ ace-nodelauncher-ui/src/main/java/org/ ace-nodelauncher-ui/src/main/java/org/apache/ ace-n... Date: Mon, 21 Mar 2011 00:11:13 -0000 To: ace-commits@incubator.apache.org From: angelos@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110321001113.D29F523889EB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: angelos Date: Mon Mar 21 00:11:13 2011 New Revision: 1083621 URL: http://svn.apache.org/viewvc?rev=1083621&view=rev Log: Added a web ui extension for controller the node launcher. Added: incubator/ace/trunk/ace-nodelauncher-ui/ incubator/ace/trunk/ace-nodelauncher-ui/pom.xml incubator/ace/trunk/ace-nodelauncher-ui/src/ incubator/ace/trunk/ace-nodelauncher-ui/src/main/ incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/ incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/ incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/ incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/ incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/Activator.java incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/NodeLauncherPanelFactory.java incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/NodePanel.java Modified: incubator/ace/trunk/pom.xml incubator/ace/trunk/pom/pom.xml Added: incubator/ace/trunk/ace-nodelauncher-ui/pom.xml URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-nodelauncher-ui/pom.xml?rev=1083621&view=auto ============================================================================== --- incubator/ace/trunk/ace-nodelauncher-ui/pom.xml (added) +++ incubator/ace/trunk/ace-nodelauncher-ui/pom.xml Mon Mar 21 00:11:13 2011 @@ -0,0 +1,77 @@ + + + + + + 4.0.0 + + + org.apache.ace + ace-pom + 0.8.0-SNAPSHOT + ../pom/pom.xml + + + org.apache.ace.nodelauncher.ui + bundle + + Apache ACE :: NodeLauncher :: UI + + + + + org.apache.ace.nodelauncher.ui + + + org.apache.ace.nodelauncher.ui.Activator + + + + + + org.osgi + org.osgi.core + + + org.osgi + org.osgi.compendium + + + org.apache.felix + org.apache.felix.dependencymanager + + + org.apache.ace + org.apache.ace.nodelauncher.api + + + org.apache.ace + org.apache.ace.webui.vaadin + + + org.apache.ace + org.apache.ace.client.repository.api + + + com.vaadin + vaadin + + + + \ No newline at end of file Added: incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/Activator.java URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/Activator.java?rev=1083621&view=auto ============================================================================== --- incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/Activator.java (added) +++ incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/Activator.java Mon Mar 21 00:11:13 2011 @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.ace.nodelauncher.ui; + +import org.apache.ace.nodelauncher.NodeLauncher; +import org.apache.ace.webui.UIExtensionFactory; +import org.apache.felix.dm.DependencyActivatorBase; +import org.apache.felix.dm.DependencyManager; +import org.osgi.framework.BundleContext; +import org.osgi.service.log.LogService; + +import java.util.Properties; + +public class Activator extends DependencyActivatorBase { + @Override + public void init(BundleContext context, DependencyManager manager) throws Exception { + Properties props = new Properties(); + props.put(UIExtensionFactory.EXTENSION_POINT_KEY, UIExtensionFactory.EXTENSION_POINT_VALUE_TARGET); + + manager.add(createComponent() + .setInterface(UIExtensionFactory.class.getName(), props) + .setImplementation(NodeLauncherPanelFactory.class) + .add(createServiceDependency() + .setService(NodeLauncher.class) + .setRequired(true)) + .add(createServiceDependency() + .setService(LogService.class) + .setRequired(false))); + } + + @Override + public void destroy(BundleContext context, DependencyManager manager) throws Exception { + + } +} Added: incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/NodeLauncherPanelFactory.java URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/NodeLauncherPanelFactory.java?rev=1083621&view=auto ============================================================================== --- incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/NodeLauncherPanelFactory.java (added) +++ incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/NodeLauncherPanelFactory.java Mon Mar 21 00:11:13 2011 @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.ace.nodelauncher.ui; + +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.apache.ace.client.repository.stateful.StatefulGatewayObject; +import org.apache.ace.nodelauncher.NodeLauncher; +import org.apache.ace.webui.NamedObject; +import org.apache.ace.webui.UIExtensionFactory; +import org.osgi.service.log.LogService; + +import com.vaadin.ui.Panel; + +public class NodeLauncherPanelFactory implements UIExtensionFactory { + private volatile NodeLauncher m_nodeLauncher; + private volatile LogService m_log; + + private final ExecutorService m_executor = Executors.newCachedThreadPool(); + + public Panel create(Map context) { + NamedObject namedObject = (NamedObject) context.get("object"); + StatefulGatewayObject target = (StatefulGatewayObject) namedObject.getObject(); + return new NodePanel(this, target.getID()); + } + + NodeLauncher getCloudService() { + return m_nodeLauncher; + } + + LogService getLogService() { + return m_log; + } + + Future submit(Runnable runnable) { + return m_executor.submit(runnable); + } +} Added: incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/NodePanel.java URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/NodePanel.java?rev=1083621&view=auto ============================================================================== --- incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/NodePanel.java (added) +++ incubator/ace/trunk/ace-nodelauncher-ui/src/main/java/org/apache/ace/nodelauncher/ui/NodePanel.java Mon Mar 21 00:11:13 2011 @@ -0,0 +1,256 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.ace.nodelauncher.ui; + +import java.util.*; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import com.vaadin.ui.*; +import org.osgi.service.log.LogService; + +import com.vaadin.ui.Button.ClickListener; + +@SuppressWarnings("serial") +public class NodePanel extends Panel { + private final String m_targetId; + private final Lock m_targetLock = new ReentrantLock(); + private final NodeStatusHandler m_handler = new NodeStatusHandler(); + private final NodeLauncherPanelFactory m_factory; + private final Map m_runners = new HashMap(); + private final Runnable m_statusGetter = new StatusGetter(); + + { + m_runners.put(Action.Start, new StartRunner()); + m_runners.put(Action.Stop, new StopRunner()); + } + + public NodePanel(NodeLauncherPanelFactory factory, String target) { + m_factory = factory; + m_targetId = target; + setContent(); + setCaption(m_targetId); + } + + private void setContent() { + VerticalLayout panel = new VerticalLayout(); + setContent(panel); + panel.setMargin(true); + panel.setSpacing(true); + setWidth("100%"); + + Label status = new NodeLabel(m_handler); + + Button startButton = new ActionButton(m_handler, Action.Start); + Button stopButton = new ActionButton(m_handler, Action.Stop); + HorizontalLayout buttonPanel = new HorizontalLayout(); + buttonPanel.addComponent(startButton); + buttonPanel.addComponent(stopButton); + buttonPanel.setSpacing(true); + + Table propertiesTable = new PropertiesTable(m_handler); + propertiesTable.setWidth("100%"); + + panel.addComponent(status); + panel.addComponent(buttonPanel); + panel.addComponent(propertiesTable); + + m_factory.submit(m_statusGetter); + } + + @SuppressWarnings("serial") + private class ActionButton extends Button implements NodeStatusHandler.NodeStatusListener, ClickListener { + private final Action m_action; + + public ActionButton(NodeStatusHandler handler, Action action) { + m_action = action; + handler.addListener(this); + addListener((ClickListener) this); + nodeStatusChanged(NodeStatus.UNKNOWN, null); + setCaption(m_action.toString()); + } + + public void nodeStatusChanged(NodeStatus status, Properties info) { + setEnabled(status.getNextAction().equals(m_action)); + } + + public void buttonClick(ClickEvent event) { + Runnable runner = m_runners.get(m_action); + if (runner != null) { + m_factory.submit(runner); + } + } + } + + @SuppressWarnings("serial") + private static class NodeLabel extends Label implements NodeStatusHandler.NodeStatusListener { + public NodeLabel(NodeStatusHandler handler) { + handler.addListener(this); + nodeStatusChanged(NodeStatus.UNKNOWN, null); + } + + public void nodeStatusChanged(NodeStatus status, Properties info) { + setValue(status.toString()); + } + } + + private static class PropertiesTable extends Table implements NodeStatusHandler.NodeStatusListener { + public PropertiesTable(NodeStatusHandler handler) { + super("Properties"); + handler.addListener(this); + nodeStatusChanged(NodeStatus.UNKNOWN, null); + addContainerProperty("Key", String.class, null); + addContainerProperty("Value", String.class, null); + setPageLength(0); + } + + public void nodeStatusChanged(NodeStatus status, Properties info) { + removeAllItems(); + int index = 0; + if (info != null) { + Enumeration keys = info.keys(); + while (keys.hasMoreElements()) { + Object key = keys.nextElement(); + addItem(new Object[] {key.toString(), info.get(key).toString()}, index++); + } + } + } + } + + private class StatusGetter extends LockedRunner { + public void run() { + try { + Properties properties = m_factory.getCloudService().getProperties(m_targetId); + if (properties != null) { + m_handler.setStatus(NodeStatus.RUNNING, properties); + } + else { + m_handler.setStatus(NodeStatus.STOPPED); + } + } + catch (Exception e) { + m_handler.setStatus(NodeStatus.UNKNOWN); + m_factory.getLogService().log(LogService.LOG_ERROR, + "Error getting status for node with ID " + m_targetId ,e); + } + } + } + + private class StartRunner extends LockedRunner { + @Override + protected void doRun() { + try { + m_handler.setStatus(NodeStatus.STARTING); + m_factory.getCloudService().start(m_targetId); + m_handler.setStatus(NodeStatus.INITIALIZING); + } + catch (Exception e) { + m_handler.setStatus(NodeStatus.ERROR); + m_factory.getLogService().log(LogService.LOG_ERROR, "Error starting node with ID " + m_targetId, e); + } + m_factory.submit(m_statusGetter); + } + } + + private class StopRunner extends LockedRunner { + @Override + protected void doRun() { + try { + m_handler.setStatus(NodeStatus.STOPPING); + m_factory.getCloudService().stop(m_targetId); + } + catch (Exception e) { + m_handler.setStatus(NodeStatus.ERROR); + m_factory.getLogService().log(LogService.LOG_ERROR, "Error stopping node with ID " + m_targetId, e); + } + m_factory.submit(m_statusGetter); + } + } + + private abstract class LockedRunner implements Runnable { + public final void run() { + if (m_targetLock.tryLock()) { + try { + doRun(); + } + finally { + m_targetLock.unlock(); + } + } + } + + protected abstract void doRun(); + } + + private static class NodeStatusHandler { + private final List m_listeners = new CopyOnWriteArrayList(); + + public interface NodeStatusListener { + void nodeStatusChanged(NodeStatus status, Properties info); + } + + private void addListener(NodeStatusListener listener) { + m_listeners.add(listener); + } + + public void setStatus(NodeStatus status) { + setStatus(status, null); + } + + public void setStatus(NodeStatus status, Properties info) { + for (NodeStatusListener listener : m_listeners) { + listener.nodeStatusChanged(status, info); + } + } + } + + private enum NodeStatus { + UNKNOWN("Getting status...", Action.None), + ERROR("Error", Action.Start), + STOPPED("Stopped", Action.Start), + STARTING("Starting...", Action.None), + INITIALIZING("Initializing...", Action.None), + RUNNING("Running", Action.Stop), + STOPPING("Stopping...", Action.None); + + private final String m_label; + private final Action m_nextAction; + + NodeStatus(String label, Action nextAction) { + m_label = label; + m_nextAction = nextAction; + } + + public String toString() { + return m_label; + } + + public Action getNextAction() { + return m_nextAction; + } + } + + private enum Action { + Start, + Stop, + None; + } + +} Modified: incubator/ace/trunk/pom.xml URL: http://svn.apache.org/viewvc/incubator/ace/trunk/pom.xml?rev=1083621&r1=1083620&r2=1083621&view=diff ============================================================================== --- incubator/ace/trunk/pom.xml (original) +++ incubator/ace/trunk/pom.xml Mon Mar 21 00:11:13 2011 @@ -107,6 +107,10 @@ ace-webui-vaadin + ace-nodelauncher-api + ace-nodelauncher-amazon + ace-nodelauncher-ui + ace-managementagent ace-launcher @@ -114,9 +118,6 @@ ace-target-devgateway ace-target-devserver - ace-nodelauncher-api - ace-nodelauncher-amazon - Modified: incubator/ace/trunk/pom/pom.xml URL: http://svn.apache.org/viewvc/incubator/ace/trunk/pom/pom.xml?rev=1083621&r1=1083620&r2=1083621&view=diff ============================================================================== --- incubator/ace/trunk/pom/pom.xml (original) +++ incubator/ace/trunk/pom/pom.xml Mon Mar 21 00:11:13 2011 @@ -580,6 +580,11 @@ org.apache.ace + org.apache.ace.nodelauncher.ui + ${project.version} + + + org.apache.ace org.apache.ace.webui ${project.version} war