incubator-ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ange...@apache.org
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 GMT
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.ace</groupId>
+        <artifactId>ace-pom</artifactId>
+        <version>0.8.0-SNAPSHOT</version>
+        <relativePath>../pom/pom.xml</relativePath>
+    </parent>
+
+    <artifactId>org.apache.ace.nodelauncher.ui</artifactId>
+    <packaging>bundle</packaging>
+
+    <name>Apache ACE :: NodeLauncher :: UI</name>
+    <description></description>
+
+    <properties>
+        <private.package>
+            org.apache.ace.nodelauncher.ui
+        </private.package>
+        <bundle.activator>
+            org.apache.ace.nodelauncher.ui.Activator
+        </bundle.activator>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.dependencymanager</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.nodelauncher.api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.webui.vaadin</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.client.repository.api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.vaadin</groupId>
+            <artifactId>vaadin</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>
\ 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<String, Object> 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<Action, Runnable> m_runners = new HashMap<Action, Runnable>();
+    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<Object> 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<NodeStatusListener> m_listeners = new CopyOnWriteArrayList<NodeStatusListener>();
+
+        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 @@
 
         <module>ace-webui-vaadin</module>
 
+        <module>ace-nodelauncher-api</module>
+        <module>ace-nodelauncher-amazon</module>
+        <module>ace-nodelauncher-ui</module>
+
         <module>ace-managementagent</module>
         <module>ace-launcher</module>
 
@@ -114,9 +118,6 @@
         <module>ace-target-devgateway</module>
         <module>ace-target-devserver</module>
 
-        <module>ace-nodelauncher-api</module>
-        <module>ace-nodelauncher-amazon</module>
-
         <!-- not ready yet
         <module>ace-distribution-servlet</module>
         -->

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 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.ace</groupId>
+                <artifactId>org.apache.ace.nodelauncher.ui</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.ace</groupId>
                 <artifactId>org.apache.ace.webui</artifactId>
                 <version>${project.version}</version>
                 <type>war</type>



Mime
View raw message