You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by am...@apache.org on 2006/04/21 05:50:03 UTC

svn commit: r395769 - in /geronimo/branches/1.1/applications/console-standard/src: java/org/apache/geronimo/console/ajax/ java/org/apache/geronimo/console/car/ java/org/apache/geronimo/console/databasemanager/wizard/ webapp/WEB-INF/ webapp/WEB-INF/view...

Author: ammulder
Date: Thu Apr 20 20:50:01 2006
New Revision: 395769

URL: http://svn.apache.org/viewcvs?rev=395769&view=rev
Log:
Add download progress bar to 1.1 (GERONIMO-1876)

Added:
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/ajax/
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/ajax/ProgressInfo.java
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/ajax/ProgressMonitor.java
    geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/ajax/
    geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/ajax/progressbar.jsp   (with props)
Modified:
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/car/DownloadCARHandler.java
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/DriverDownloader.java
    geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/dwr.xml
    geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/car/download.jsp
    geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/selectDownload.jsp

Added: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/ajax/ProgressInfo.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/ajax/ProgressInfo.java?rev=395769&view=auto
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/ajax/ProgressInfo.java (added)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/ajax/ProgressInfo.java Thu Apr 20 20:50:01 2006
@@ -0,0 +1,51 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  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.geronimo.console.ajax;
+
+public class ProgressInfo
+{
+    public static final String PROGRESS_INFO_KEY = "progressinfokey";
+    private int progressPercent = -1;
+    private String mainMessage;
+    private String subMessage;
+
+	public int getProgressPercent() {
+		return progressPercent;
+	}
+
+	public void setProgressPercent(int progressPercent) {
+		this.progressPercent = progressPercent;
+	}
+
+	public String getMainMessage() {
+		return mainMessage;
+	}
+
+	public void setMainMessage(String mainMessage) {
+		this.mainMessage = mainMessage;
+	}
+
+	public String getSubMessage() {
+		return subMessage;
+	}
+
+	public void setSubMessage(String subMessage) {
+		this.subMessage = subMessage;
+	}
+    
+}

Added: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/ajax/ProgressMonitor.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/ajax/ProgressMonitor.java?rev=395769&view=auto
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/ajax/ProgressMonitor.java (added)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/ajax/ProgressMonitor.java Thu Apr 20 20:50:01 2006
@@ -0,0 +1,40 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  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.geronimo.console.ajax;
+
+import javax.servlet.http.HttpSession;
+
+import uk.ltd.getahead.dwr.ExecutionContext;
+
+/**
+ * Provides information to an AJAX client during server side
+ * activities.
+ */
+public class ProgressMonitor
+{
+    public ProgressInfo getProgressInfo()
+    {
+        HttpSession session = ExecutionContext.get().getSession();
+        
+        if (session.getAttribute(ProgressInfo.PROGRESS_INFO_KEY) != null) {
+            return (ProgressInfo) session.getAttribute(ProgressInfo.PROGRESS_INFO_KEY);
+        } else {
+            return new ProgressInfo();
+        }
+    }
+}

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/car/DownloadCARHandler.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/car/DownloadCARHandler.java?rev=395769&r1=395768&r2=395769&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/car/DownloadCARHandler.java (original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/car/DownloadCARHandler.java Thu Apr 20 20:50:01 2006
@@ -24,15 +24,19 @@
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.PortletException;
+import javax.portlet.PortletSession;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 import javax.security.auth.login.FailedLoginException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.console.MultiPageModel;
+import org.apache.geronimo.console.ajax.ProgressInfo;
+import org.apache.geronimo.console.ajax.ProgressMonitor;
 import org.apache.geronimo.console.util.PortletManager;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.MissingDependencyException;
+import org.apache.geronimo.system.configuration.ConfigurationInstaller;
 import org.apache.geronimo.system.configuration.ConfigurationMetadata;
 import org.apache.geronimo.system.configuration.DownloadResults;
 import org.apache.geronimo.system.configuration.ConfigurationList;
@@ -117,8 +121,23 @@
                 throw new PortletException("No configuration found for '"+configId+"'");
             }
 
-            // todo: switch to asynchronous AJAX-based download monitor
-            DownloadResults results = PortletManager.getCurrentServer(request).getConfigurationInstaller().install(installList, user, pass);
+            ConfigurationInstaller configInstaller = PortletManager.getCurrentServer(request).getConfigurationInstaller(); 
+            Object downloadKey = configInstaller.startInstall(installList, user, pass);
+            ProgressInfo progressInfo = new ProgressInfo();
+            request.getPortletSession().setAttribute(ProgressInfo.PROGRESS_INFO_KEY, progressInfo, PortletSession.APPLICATION_SCOPE);
+            DownloadResults results;
+            while (true) {
+            	results = configInstaller.checkOnInstall(downloadKey);
+            	progressInfo.setMainMessage(results.getCurrentMessage());
+            	progressInfo.setProgressPercent(results.getCurrentFilePercent());
+            	if (results.isFinished() || results.isFailed()) {
+                	break;
+            	} else {
+            		try { Thread.sleep(1000); } catch (InterruptedException e) {
+                        log.error("Download monitor thread interrupted", e);
+					}
+            	}
+            }
             if(results.isFailed()) {
                 throw new PortletException("Unable to install configuration", results.getFailure());
             }

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java?rev=395769&r1=395768&r2=395769&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java (original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java Thu Apr 20 20:50:01 2006
@@ -31,6 +31,7 @@
 import org.apache.geronimo.connector.deployment.jsr88.SinglePool;
 import org.apache.geronimo.connector.outbound.PoolingAttributes;
 import org.apache.geronimo.console.BasePortlet;
+import org.apache.geronimo.console.ajax.ProgressInfo;
 import org.apache.geronimo.console.util.PortletManager;
 import org.apache.geronimo.converter.DatabaseConversionStatus;
 import org.apache.geronimo.converter.JDBCPool;
@@ -47,6 +48,7 @@
 import org.apache.geronimo.kernel.repository.WriteableRepository;
 import org.apache.geronimo.management.geronimo.JCAManagedConnectionFactory;
 import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
+import org.apache.geronimo.system.configuration.DownloadResults;
 import org.apache.geronimo.gbean.AbstractName;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -277,7 +279,13 @@
                 DriverDownloader downloader = new DriverDownloader();
                 WriteableRepository repo = PortletManager.getWritableRepositories(actionRequest)[0];
                 try {
-                    downloader.loadDriver(repo, found, new FileWriteMonitor() {
+                    final PortletSession session = actionRequest.getPortletSession();
+                    ProgressInfo progressInfo = new ProgressInfo();
+                    progressInfo.setMainMessage("Downloading " + found.getName());
+                    session.setAttribute(ProgressInfo.PROGRESS_INFO_KEY, progressInfo, PortletSession.APPLICATION_SCOPE);
+                    final DownloadResults downloadResults = new DownloadResults(); 
+                    downloader.loadDriver(repo, found, downloadResults, new FileWriteMonitor() {
+                    	
                         public void writeStarted(String fileDescription) {
                             System.out.println("Downloading "+fileDescription);
                         }
@@ -285,6 +293,16 @@
                         public void writeProgress(int bytes) {
                             System.out.print("\rDownload progress: "+(bytes/1024)+"kB");
                             System.out.flush();
+                            ProgressInfo progressInfo = (ProgressInfo)session.getAttribute(ProgressInfo.PROGRESS_INFO_KEY);
+                            int totalBytes = (int)downloadResults.getTotalDownloadBytes();
+                            int kbDownloaded = (int)Math.floor(bytes/1024);
+                            if (totalBytes > 0) {
+                            	int percent = (bytes*100)/totalBytes;
+                            	progressInfo.setProgressPercent(percent);
+                                progressInfo.setSubMessage(kbDownloaded + " / " + totalBytes/1024 + " Kb downloaded");
+                            } else {
+                                progressInfo.setSubMessage(kbDownloaded + " Kb downloaded");
+                            }
                         }
 
                         public void writeComplete(int bytes) {

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/DriverDownloader.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/DriverDownloader.java?rev=395769&r1=395768&r2=395769&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/DriverDownloader.java (original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/DriverDownloader.java Thu Apr 20 20:50:01 2006
@@ -21,6 +21,7 @@
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.FileWriteMonitor;
 import org.apache.geronimo.kernel.repository.WriteableRepository;
+import org.apache.geronimo.system.configuration.DownloadResults;
 
 import java.io.BufferedOutputStream;
 import java.io.File;
@@ -30,6 +31,7 @@
 import java.io.OutputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
@@ -116,7 +118,7 @@
     /**
      * Downloads a driver and loads it into the local repository.
      */
-    public void loadDriver(WriteableRepository repo, DriverInfo driver, FileWriteMonitor monitor) throws IOException {
+    public void loadDriver(WriteableRepository repo, DriverInfo driver, DownloadResults downloadResults, FileWriteMonitor monitor) throws IOException {
         int urlIndex = 0;
         if (driver.urls.length > 1) {
             if (random == null) {
@@ -132,7 +134,9 @@
             int size;
             int total = 0;
             int threshold = 10240;
-            InputStream net = url.openStream();
+            URLConnection uc = url.openConnection();
+            downloadResults.addDownloadBytes(uc.getContentLength());
+            InputStream net = uc.getInputStream();
             JarFile jar = null;
             File download = null;
             try {

Modified: geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/dwr.xml
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/dwr.xml?rev=395769&r1=395768&r2=395769&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/dwr.xml (original)
+++ geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/dwr.xml Thu Apr 20 20:50:01 2006
@@ -8,5 +8,9 @@
     <create creator="new" javascript="Jsr77Stats">
       <param name="class" value="org.apache.geronimo.console.jsr77.Jsr77Lookup"/>
     </create>
+    <convert converter="bean" match="org.apache.geronimo.console.ajax.ProgressInfo"/>
+    <create creator="new" javascript="ProgressMonitor">
+      <param name="class" value="org.apache.geronimo.console.ajax.ProgressMonitor"/>
+    </create>
   </allow>
 </dwr>

Added: geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/ajax/progressbar.jsp
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/ajax/progressbar.jsp?rev=395769&view=auto
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/ajax/progressbar.jsp (added)
+++ geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/ajax/progressbar.jsp Thu Apr 20 20:50:01 2006
@@ -0,0 +1,52 @@
+<% String dwrForwarderServlet = org.apache.geronimo.console.util.PortletManager.getConsoleFrameworkServletPath(request) + "/../dwr"; %>
+<script type='text/javascript' src='<%= dwrForwarderServlet %>/interface/ProgressMonitor.js'></script>
+<script type='text/javascript' src='<%= dwrForwarderServlet %>/engine.js'></script>
+<script type='text/javascript' src='<%= dwrForwarderServlet %>/util.js'></script>
+
+<script>
+function refreshProgress()
+{
+    ProgressMonitor.getProgressInfo(updateProgress);
+}
+
+function updateProgress(progressInfo)
+{
+    // get the bean values from DWR
+    var progressPercent = progressInfo.progressPercent;
+    var mainMessage = progressInfo.mainMessage;
+    var subMessage = progressInfo.subMessage;
+
+    // set the bean values in the HTML document
+    if (mainMessage != null) {
+	    document.getElementById('progressMeterMainMessage').innerHTML = mainMessage;
+    }
+    if (subMessage != null) {
+	    document.getElementById('progressMeterSubMessage').innerHTML = subMessage;
+    }
+    if (progressPercent > -1) {
+       document.getElementById('progressMeterShell').style.display = 'block';
+       document.getElementById('progressMeterBar').style.width = parseInt(progressPercent * 3.5) + 'px';
+    }
+    window.setTimeout('refreshProgress()', 1000);
+    return true;
+}
+
+function startProgress()
+{
+    document.getElementById('progressMeter').style.display = 'block';
+    document.getElementById('progressMeterMainMessage').innerHTML = 'Processing...';
+    window.setTimeout("refreshProgress()", 1000);
+    return true;
+}
+</script>
+
+<div id="progressMeter" style="display: none; padding-top: 5px;">
+    <br/>
+    <div>
+        <div id="progressMeterMainMessage"></div>
+        <div id="progressMeterSubMessage"></div>
+        <div id="progressMeterShell" style="display: none; width: 350px; height: 20px; border: 1px inset; background: #eee;">
+            <div id="progressMeterBar" style="width: 0; height: 20px; border-right: 1px solid #444; background: #9ACB34;"></div>
+        </div>
+    </div>
+</div>

Propchange: geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/ajax/progressbar.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/car/download.jsp
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/car/download.jsp?rev=395769&r1=395768&r2=395769&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/car/download.jsp (original)
+++ geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/car/download.jsp Thu Apr 20 20:50:01 2006
@@ -14,7 +14,7 @@
 </c:forEach>
 </ul>
 
-<form name="<portlet:namespace/>PluginForm" action="<portlet:actionURL/>">
+<form name="<portlet:namespace/>PluginForm" action="<portlet:actionURL/>" onsubmit="startProgress()">
     <input type="hidden" name="file" value="${file}" />
     <input type="hidden" name="configId" value="${configId}" />
     <input type="hidden" name="mode" value="download-after" />
@@ -24,5 +24,7 @@
     <input type="hidden" name="proceed" value="true" />
     <input type="submit" value="Install Plugin" />
 </form>
+
+<jsp:include flush="true" page="../ajax/progressbar.jsp"/>
 
 <p><a href="<portlet:actionURL portletMode="view"><portlet:param name="mode" value="index-before" /></portlet:actionURL>">Cancel</a></p>

Modified: geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/selectDownload.jsp
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/selectDownload.jsp?rev=395769&r1=395768&r2=395769&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/selectDownload.jsp (original)
+++ geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/selectDownload.jsp Thu Apr 20 20:50:01 2006
@@ -13,7 +13,7 @@
 install the driver by hand (copy it to a directory under geronimo/repository/)</i></p>
 
 <!--   FORM TO COLLECT DATA FOR THIS PAGE   -->
-<form name="<portlet:namespace/>DatabaseForm" action="<portlet:actionURL/>" method="POST">
+<form name="<portlet:namespace/>DatabaseForm" action="<portlet:actionURL/>" method="POST" onSubmit="startProgress()">
     <input type="hidden" name="mode" value="process-download" />
     <input type="hidden" name="name" value="${pool.name}" />
     <input type="hidden" name="dbtype" value="${pool.dbtype}" />
@@ -63,6 +63,9 @@
       </tr>
     </table>
 </form>
+
+<jsp:include flush="true" page="../ajax/progressbar.jsp"/>
+
 <!--   END OF FORM TO COLLECT DATA FOR THIS PAGE   -->
 
 <%--