geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r388832 - in /geronimo/trunk: applications/console-core/src/java/org/apache/geronimo/console/util/ applications/console-standard/src/java/org/apache/geronimo/console/car/ applications/console-standard/src/java/org/apache/geronimo/console/ut...
Date Sat, 25 Mar 2006 21:11:57 GMT
Author: ammulder
Date: Sat Mar 25 13:11:55 2006
New Revision: 388832

URL: http://svn.apache.org/viewcvs?rev=388832&view=rev
Log:
Move the configuration download and install logic from the console
  into a GBean

Added:
    geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigInstallerGBean.java
  (with props)
    geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationInstaller.java
  (with props)
    geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationMetadata.java
  (with props)
    geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/DownloadResults.java
  (with props)
Modified:
    geronimo/trunk/applications/console-core/src/java/org/apache/geronimo/console/util/KernelManagementHelper.java
    geronimo/trunk/applications/console-core/src/java/org/apache/geronimo/console/util/ManagementHelper.java
    geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/car/DownloadCARHandler.java
    geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/car/ListHandler.java
    geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/util/PortletManager.java
    geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/car/list.jsp
    geronimo/trunk/configs/j2ee-system/src/plan/plan.xml
    geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/management/impl/J2EEServerImpl.java
    geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/repository/WriteableRepository.java
    geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/J2EEServer.java

Modified: geronimo/trunk/applications/console-core/src/java/org/apache/geronimo/console/util/KernelManagementHelper.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-core/src/java/org/apache/geronimo/console/util/KernelManagementHelper.java?rev=388832&r1=388831&r2=388832&view=diff
==============================================================================
--- geronimo/trunk/applications/console-core/src/java/org/apache/geronimo/console/util/KernelManagementHelper.java
(original)
+++ geronimo/trunk/applications/console-core/src/java/org/apache/geronimo/console/util/KernelManagementHelper.java
Sat Mar 25 13:11:55 2006
@@ -91,6 +91,7 @@
 import org.apache.geronimo.security.keystore.KeystoreManager;
 import org.apache.geronimo.system.logging.SystemLog;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
+import org.apache.geronimo.system.configuration.ConfigurationInstaller;
 
 /**
  * An implementation of the ManagementHelper interface that uses a Geronimo
@@ -549,6 +550,16 @@
             return (KeystoreManager) pm.createProxy(ObjectName.getInstance(name), KernelManagementHelper.class.getClassLoader());
         } catch (Exception e) {
             log.error("Unable to look up KeystoreManager for J2EEServer", e);
+            return null;
+        }
+    }
+
+    public ConfigurationInstaller getConfigurationInstaller(J2EEServer server) {
+        try {
+            String name = server.getConfigurationInstaller();
+            return (ConfigurationInstaller) pm.createProxy(ObjectName.getInstance(name),
KernelManagementHelper.class.getClassLoader());
+        } catch (Exception e) {
+            log.error("Unable to look up ConfigurationInstaller for J2EEServer", e);
             return null;
         }
     }

Modified: geronimo/trunk/applications/console-core/src/java/org/apache/geronimo/console/util/ManagementHelper.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-core/src/java/org/apache/geronimo/console/util/ManagementHelper.java?rev=388832&r1=388831&r2=388832&view=diff
==============================================================================
--- geronimo/trunk/applications/console-core/src/java/org/apache/geronimo/console/util/ManagementHelper.java
(original)
+++ geronimo/trunk/applications/console-core/src/java/org/apache/geronimo/console/util/ManagementHelper.java
Sat Mar 25 13:11:55 2006
@@ -61,6 +61,7 @@
 import org.apache.geronimo.security.keystore.KeystoreManager;
 import org.apache.geronimo.system.logging.SystemLog;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
+import org.apache.geronimo.system.configuration.ConfigurationInstaller;
 
 /**
  * A helper interface to navigate between management objects.  This is not
@@ -97,6 +98,7 @@
     ServerInfo getServerInfo(J2EEServer server);
     JaasLoginServiceMBean getLoginService(J2EEServer server);
     KeystoreManager getKeystoreManager(J2EEServer server);
+    ConfigurationInstaller getConfigurationInstaller(J2EEServer server);
     WebManager[] getWebManagers(J2EEServer server);
     WebAccessLog getWebAccessLog(WebManager manager, WebContainer container);
     WebAccessLog getWebAccessLog(WebManager manager, String containerObjectName);

Modified: geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/car/DownloadCARHandler.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/car/DownloadCARHandler.java?rev=388832&r1=388831&r2=388832&view=diff
==============================================================================
--- geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/car/DownloadCARHandler.java
(original)
+++ geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/car/DownloadCARHandler.java
Sat Mar 25 13:11:55 2006
@@ -20,36 +20,21 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.console.MultiPageModel;
 import org.apache.geronimo.console.util.PortletManager;
-import org.apache.geronimo.gbean.GBeanData;
-import org.apache.geronimo.gbean.GBeanQuery;
-import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
-import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.KernelRegistry;
-import org.apache.geronimo.kernel.config.ConfigurationStore;
-import org.apache.geronimo.kernel.repository.Repository;
-import org.apache.geronimo.kernel.repository.WriteableRepository;
+import org.apache.geronimo.system.configuration.ConfigurationMetadata;
+import org.apache.geronimo.system.configuration.DownloadResults;
 
-import javax.management.ObjectName;
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.PortletException;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
-import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
 import java.io.Serializable;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
 
 /**
  * Handler for the initial download screen.
@@ -66,15 +51,7 @@
     public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel
model) throws PortletException, IOException {
         String configId = request.getParameter("configId");
         String repo = request.getParameter("repository");
-        if(!repo.endsWith("/")) {
-            repo += "/";
-        }
-        String url = getURL(configId, repo);
-        File file = File.createTempFile("geronimo-download", "." + configId.substring(configId.lastIndexOf("/")+1));
-        file.deleteOnExit();
-        downloadFile(url, file);
         response.setRenderParameter("configId", configId);
-        response.setRenderParameter("file", file.getAbsolutePath());
         response.setRenderParameter("repository", repo);
 
         return getMode();
@@ -83,25 +60,16 @@
     public void renderView(RenderRequest request, RenderResponse response, MultiPageModel
model) throws PortletException, IOException {
         String configId = request.getParameter("configId");
         String repo = request.getParameter("repository");
-        File file = new File(request.getParameter("file"));
-        ZipFile zip = new ZipFile(file);
+        ConfigurationMetadata config;
         try {
-            ZipEntry entry = zip.getEntry("META-INF/config.ser");
-            ObjectInputStream serIn = new ObjectInputStream(zip.getInputStream(entry));
-            GBeanData config = new GBeanData();
-            config.readExternal(serIn);
-            URI[] parentIds = (URI[]) config.getAttribute("parentId");
-            List dependencies = (List) config.getAttribute("dependencies");
-            request.setAttribute("file", file.getAbsolutePath());
-            request.setAttribute("configId", configId);
-            request.setAttribute("parents", parentIds);
-            request.setAttribute("dependencies", dependencies);
-            request.setAttribute("repository", repo);
-        } catch (ClassNotFoundException e) {
-            throw new PortletException("Unable to deserialize GBeanData", e);
-        } finally {
-            zip.close();
+            config = PortletManager.getConfigurationInstaller(request).loadDependencies(new
URL(repo), new ConfigurationMetadata(new URI(configId), null, null, false));
+        } catch (URISyntaxException e) {
+            throw new PortletException("Unable to format URI", e);
         }
+        request.setAttribute("configId", configId);
+        request.setAttribute("parents", config.getParents());
+        request.setAttribute("dependencies", config.getDependencies());
+        request.setAttribute("repository", repo);
     }
 
     public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel
model) throws PortletException, IOException {
@@ -109,15 +77,30 @@
         boolean proceed = Boolean.valueOf(request.getParameter("proceed")).booleanValue();
         if(proceed) {
             String configId = request.getParameter("configId");
-            File file = new File(request.getParameter("file"));
-
-            WriteableRepository[] repos = PortletManager.getWritableRepositories(request);
-            if(repos.length < 1) {
-                throw new PortletException("No writeable repository available in kernel");
+            DownloadResults results;
+            try {
+                results = PortletManager.getConfigurationInstaller(request).install(new URL(repo),
new URI(configId));
+            } catch (URISyntaxException e) {
+                throw new PortletException("Unable to format URI", e);
             }
             List configs = new ArrayList();
+            for (int i = 0; i < results.getConfigurationsInstalled().length; i++) {
+                URI uri = results.getConfigurationsInstalled()[i];
+                configs.add(new InstallResults(uri.toString(), "installed"));
+            }
+            for (int i = 0; i < results.getConfigurationsPresent().length; i++) {
+                URI uri = results.getConfigurationsPresent()[i];
+                configs.add(new InstallResults(uri.toString(), "already present"));
+            }
             List deps = new ArrayList();
-            downloadConfiguration(file, repos[0], repo, configs, deps);
+            for (int i = 0; i < results.getDependenciesInstalled().length; i++) {
+                URI uri = results.getDependenciesInstalled()[i];
+                deps.add(new InstallResults(uri.toString(), "installed"));
+            }
+            for (int i = 0; i < results.getDependenciesPresent().length; i++) {
+                URI uri = results.getDependenciesPresent()[i];
+                deps.add(new InstallResults(uri.toString(), "already present"));
+            }
             request.getPortletSession(true).setAttribute("car.install.configurations", configs);
             request.getPortletSession(true).setAttribute("car.install.dependencies", deps);
             response.setRenderParameter("configId", configId);
@@ -125,97 +108,11 @@
         return RESULTS_MODE+BEFORE_ACTION;
     }
 
-    private void downloadConfiguration(File file, WriteableRepository repo, String repoURL,
List configResults, List dependencyResults) throws IOException, PortletException {
-        Kernel kernel = KernelRegistry.getSingleKernel();
-        Set set = kernel.listGBeans(new GBeanQuery(null, ConfigurationStore.class.getName()));
-        ConfigurationStore stores[] = new ConfigurationStore[set.size()];
-        int index = 0;
-        for (Iterator it = set.iterator(); it.hasNext(); ++index) {
-            ObjectName name = (ObjectName) it.next();
-            stores[index] = (ConfigurationStore) kernel.getProxyManager().createProxy(name,
ConfigurationStore.class);
-        }
-        ZipFile zip = new ZipFile(file);
-        try {
-            ZipEntry entry = zip.getEntry("META-INF/config.ser");
-            ObjectInputStream serIn = new ObjectInputStream(zip.getInputStream(entry));
-            GBeanData config = new GBeanData();
-            config.readExternal(serIn);
-            URI[] parentIds = (URI[]) config.getAttribute("parentId");
-            List dependencies = (List) config.getAttribute("dependencies");
-            // Download the dependencies
-            for (int i = 0; i < dependencies.size(); i++) {
-                URI dep = (URI) dependencies.get(i);
-                if(((Repository)repo).hasURI(dep)) {
-                    dependencyResults.add(new DownloadResults(dep.toString(), "already present"));
-                    continue;
-                }
-                String url = getURL(dep.toString(), repoURL);
-                log.info("Downloading "+url+" to local repository");
-                repo.copyToRepository(new URL(url).openStream(), dep, null);
-                dependencyResults.add(new DownloadResults(dep.toString(), "downloaded and
installed"));
-            }
-            // Download the parents
-            parents:
-            for (int i = 0; i < parentIds.length; i++) {
-                String id = parentIds[i].toString();
-                URI uri = new URI(id);
-                for (int j = 0; j < stores.length; j++) {
-                    ConfigurationStore store = stores[j];
-                    if(store.containsConfiguration(uri)) {
-                        configResults.add(new DownloadResults(uri.toString(), "already present"));
-                        continue parents;
-                    }
-                }
-                File next = File.createTempFile("geronimo-download", "." + id.substring(id.lastIndexOf("/")+1));
-                file.deleteOnExit();
-                String url = getURL(id, repoURL);
-                downloadFile(url, next);
-                downloadConfiguration(next, repo, repoURL, configResults, dependencyResults);
-            }
-            // Install the configuration
-            for (Iterator it = set.iterator(); it.hasNext();) {
-                ObjectName name = (ObjectName) it.next();
-                if(name.getKeyProperty(NameFactory.J2EE_NAME).equals("Local")) {
-                    try {
-                        URI uri = (URI)kernel.invoke(name, "install", new Object[]{file.toURL()},
new String[]{URL.class.getName()});
-                        configResults.add(new DownloadResults(uri.toString(), "downloaded
and installed"));
-                    } catch (Exception e) {
-                        throw new IOException("Unable to write ZIP file: "+e.getMessage());
-                    }
-                }
-            }
-        } catch (URISyntaxException e) {
-            throw new PortletException("Unable to process parent configurations", e);
-        } catch (ClassNotFoundException e) {
-            throw new PortletException("Unable to deserialize GBeanData", e);
-        } finally {
-            zip.close();
-        }
-    }
-
-    private String getURL(String configId, String baseRepositoryURL) {
-        String[] parts = configId.split("/");
-        return baseRepositoryURL+parts[0]+"/"+parts[3]+"s/"+parts[1]+"-"+parts[2]+"."+parts[3];
-    }
-
-    private void downloadFile(String url, File target) throws IOException {
-        log.info("Downloading "+url+" to "+target.getAbsolutePath());
-        byte[] buf = new byte[10240];
-        InputStream in = new URL(url).openStream();
-        FileOutputStream out = new FileOutputStream(target);
-        int count;
-        while((count = in.read(buf)) > -1) {
-            out.write(buf, 0, count);
-        }
-        in.close();
-        out.close();
-    }
-
-    public static class DownloadResults implements Serializable {
+    public static class InstallResults implements Serializable {
         private String name;
         private String action;
 
-        public DownloadResults(String name, String action) {
+        public InstallResults(String name, String action) {
             this.name = name;
             this.action = action;
         }

Modified: geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/car/ListHandler.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/car/ListHandler.java?rev=388832&r1=388831&r2=388832&view=diff
==============================================================================
--- geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/car/ListHandler.java
(original)
+++ geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/car/ListHandler.java
Sat Mar 25 13:11:55 2006
@@ -16,32 +16,23 @@
  */
 package org.apache.geronimo.console.car;
 
-import org.apache.geronimo.console.keystores.BaseKeystoreHandler;
-import org.apache.geronimo.console.MultiPageModel;
-import org.apache.geronimo.console.util.PortletManager;
-import org.apache.geronimo.security.keystore.KeystoreManager;
-import org.apache.geronimo.kernel.config.ConfigurationInfo;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.console.MultiPageModel;
+import org.apache.geronimo.console.util.PortletManager;
+import org.apache.geronimo.system.configuration.ConfigurationMetadata;
 
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.PortletException;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
-import javax.portlet.PortletSession;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.Serializable;
 import java.net.URL;
-import java.util.Properties;
-import java.util.Map;
+import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
-import java.util.ArrayList;
-import java.util.Set;
-import java.util.HashSet;
+import java.util.Map;
 
 /**
  * Handler for the import export list screen.
@@ -75,64 +66,18 @@
     }
 
     private void loadFromRepository(RenderRequest request, String repository) throws IOException
{
-        if(!repository.endsWith("/")) {
-            repository = repository+"/";
-        }
-        URL url = new URL(repository+"geronimo-configurations.properties");
-        Set set = new HashSet();
-        ConfigurationInfo[] installed = PortletManager.getConfigurations(request, null, false);
-        for (int i = 0; i < installed.length; i++) {
-            ConfigurationInfo info = installed[i];
-            set.add(info.getConfigID().toString());
-        }
-        InputStream in = url.openStream();
-        Properties props = new Properties();
-        props.load(in);
-        in.close();
+        ConfigurationMetadata[] data = PortletManager.getConfigurationInstaller(request).listConfigurations(new
URL(repository));
+
         Map results = new HashMap();
-        for (Iterator it = props.keySet().iterator(); it.hasNext();) {
-            String key = (String) it.next();
-            int pos = key.indexOf('.');
-            String type = key.substring(0, pos);
-            List values = (List) results.get(type);
+        for (int i = 0; i < data.length; i++) {
+            ConfigurationMetadata metadata = data[i];
+            List values = (List) results.get(metadata.getCategory());
             if(values == null) {
                 values = new ArrayList();
-                results.put(type, values);
+                results.put(metadata.getCategory(), values);
             }
-            String configId = key.substring(pos + 1);
-            values.add(new RepositoryEntry(configId, props.getProperty(key), set.contains(configId)));
+            values.add(metadata);
         }
         request.setAttribute("categories", results);
-    }
-
-    public static class RepositoryEntry implements Serializable {
-        private String configId;
-        private String name;
-        private boolean installed;
-        private String version;
-
-        public RepositoryEntry(String configId, String name, boolean installed) {
-            this.configId = configId;
-            this.name = name;
-            this.installed = installed;
-            String[] parts = configId.split("/");
-            version = parts[2];
-        }
-
-        public String getConfigId() {
-            return configId;
-        }
-
-        public String getName() {
-            return name;
-        }
-
-        public boolean isInstalled() {
-            return installed;
-        }
-
-        public String getVersion() {
-            return version;
-        }
     }
 }

Modified: geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/util/PortletManager.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/util/PortletManager.java?rev=388832&r1=388831&r2=388832&view=diff
==============================================================================
--- geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/util/PortletManager.java
(original)
+++ geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/util/PortletManager.java
Sat Mar 25 13:11:55 2006
@@ -36,6 +36,7 @@
 import org.apache.geronimo.security.keystore.KeystoreManager;
 import org.apache.geronimo.system.logging.SystemLog;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
+import org.apache.geronimo.system.configuration.ConfigurationInstaller;
 
 import javax.enterprise.deploy.spi.DeploymentManager;
 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
@@ -170,6 +171,11 @@
     public static KeystoreManager getKeystoreManager(PortletRequest request) {
         ManagementHelper helper = getManagementHelper(request);
         return helper.getKeystoreManager(getCurrentServer(request));
+    }
+
+    public static ConfigurationInstaller getConfigurationInstaller(PortletRequest request)
{
+        ManagementHelper helper = getManagementHelper(request);
+        return helper.getConfigurationInstaller(getCurrentServer(request));
     }
 
     public static void testLoginModule(PortletRequest request, LoginModule module, Map options)
{

Modified: geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/car/list.jsp
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/car/list.jsp?rev=388832&r1=388831&r2=388832&view=diff
==============================================================================
--- geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/car/list.jsp (original)
+++ geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/car/list.jsp Sat
Mar 25 13:11:55 2006
@@ -15,10 +15,10 @@
     <c:forEach var="entry" items="${category.value}">
       <c:choose>
         <c:when test="${entry.installed}">
-          <li>${entry.name}</li>
+          <li>${entry.description}</li>
         </c:when>
         <c:otherwise>
-          <li><a href="<portlet:actionURL><portlet:param name="configId"
value="${entry.configId}"/><portlet:param name="repository" value="${repository}"/><portlet:param
name="mode" value="download-before"/></portlet:actionURL>">${entry.name} (${entry.version})</a></li>
+          <li><a href="<portlet:actionURL><portlet:param name="configId"
value="${entry.configId}"/><portlet:param name="repository" value="${repository}"/><portlet:param
name="mode" value="download-before"/></portlet:actionURL>">${entry.description}
(${entry.version})</a></li>
         </c:otherwise>
       </c:choose>
     </c:forEach>

Modified: geronimo/trunk/configs/j2ee-system/src/plan/plan.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/configs/j2ee-system/src/plan/plan.xml?rev=388832&r1=388831&r2=388832&view=diff
==============================================================================
--- geronimo/trunk/configs/j2ee-system/src/plan/plan.xml (original)
+++ geronimo/trunk/configs/j2ee-system/src/plan/plan.xml Sat Mar 25 13:11:55 2006
@@ -74,6 +74,21 @@
         </reference>
     </gbean>
 
+    <!-- Configuration Installer -->
+    <gbean name="ConfigurationInstaller" class="org.apache.geronimo.system.configuration.ConfigInstallerGBean">
+        <reference name="DependencyInstallTarget">
+            <name>Repository</name>
+        </reference>
+        <reference name="ConfigurationInstallTarget">
+            <name>Local</name>
+        </reference>
+        <references name="AllConfigurations">
+          <pattern>
+            <gbean-name>geronimo.config:*</gbean-name>
+          </pattern>
+        </references>
+    </gbean>
+
     <!-- Logging service -->
     <gbean name="Logger" class="org.apache.geronimo.system.logging.log4j.Log4jService">
         <attribute name="configFileName">var/log/server-log4j.properties</attribute>

Modified: geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/management/impl/J2EEServerImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/management/impl/J2EEServerImpl.java?rev=388832&r1=388831&r2=388832&view=diff
==============================================================================
--- geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/management/impl/J2EEServerImpl.java
(original)
+++ geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/management/impl/J2EEServerImpl.java
Sat Mar 25 13:11:55 2006
@@ -225,6 +225,16 @@
         return null;
     }
 
+    public String getConfigurationInstaller() {
+        GBeanQuery query = new GBeanQuery(null, "org.apache.geronimo.system.configuration.ConfigurationInstaller");
+        Set set = kernel.listGBeans(query);
+        for (Iterator it = set.iterator(); it.hasNext();) {
+            ObjectName name = (ObjectName) it.next();
+            return name.getCanonicalName();
+        }
+        return null;
+    }
+
     public String getServerVendor() {
         return SERVER_VENDOR;
     }

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/repository/WriteableRepository.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/repository/WriteableRepository.java?rev=388832&r1=388831&r2=388832&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/repository/WriteableRepository.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/repository/WriteableRepository.java
Sat Mar 25 13:11:55 2006
@@ -26,7 +26,7 @@
  *
  * @version $Rev$ $Date$
  */
-public interface WriteableRepository {
+public interface WriteableRepository extends Repository {
     /**
      * Copies a file from the server's filesystem into the repository.
      * Obviously to use this remotely, you must have some other way

Modified: geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/J2EEServer.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/J2EEServer.java?rev=388832&r1=388831&r2=388832&view=diff
==============================================================================
--- geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/J2EEServer.java
(original)
+++ geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/J2EEServer.java
Sat Mar 25 13:11:55 2006
@@ -108,4 +108,14 @@
      */
     public String getKeystoreManager();
 
+    /**
+     * Gets the ObjectName of the ConfigurationInstaller associated with this
+     * J2EEServer.
+     *
+     * @see org.apache.geronimo.system.configuration.ConfigurationInstaller
+     *
+     * @return The ObjectName of the ConfigurationInstaller, in String form.
+     */
+    public String getConfigurationInstaller();
+
 }

Added: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigInstallerGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigInstallerGBean.java?rev=388832&view=auto
==============================================================================
--- geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigInstallerGBean.java
(added)
+++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigInstallerGBean.java
Sat Mar 25 13:11:55 2006
@@ -0,0 +1,226 @@
+/**
+ *
+ * Copyright 2005 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.system.configuration;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.kernel.config.Configuration;
+import org.apache.geronimo.kernel.config.ConfigurationStore;
+import org.apache.geronimo.kernel.config.InvalidConfigException;
+import org.apache.geronimo.kernel.repository.WriteableRepository;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+/**
+ * A GBean that knows how to download configurations from a Maven repository.
+ *
+ * @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
+ */
+public class ConfigInstallerGBean implements ConfigurationInstaller {
+    private final static Log log = LogFactory.getLog(ConfigInstallerGBean.class);
+    private Collection configurations;
+    private WriteableRepository writeableRepo;
+    private ConfigurationStore configStore;
+    private Map configIdToFile = new HashMap();
+
+    public ConfigInstallerGBean(Collection configurations, WriteableRepository writeableRepo,
ConfigurationStore configStore) {
+        this.configurations = configurations;
+        this.writeableRepo = writeableRepo;
+        this.configStore = configStore;
+    }
+
+    public ConfigurationMetadata[] listConfigurations(URL mavenRepository) throws IOException
{
+        String repository = mavenRepository.toString();
+        if(!repository.endsWith("/")) {
+            repository = repository+"/";
+        }
+        URL url = new URL(repository+"geronimo-configurations.properties");
+        Set set = new HashSet();
+        for (Iterator it = configurations.iterator(); it.hasNext();) {
+            Configuration config = (Configuration) it.next();
+            set.add(config.getId().toString());
+        }
+        InputStream in = url.openStream();
+        Properties props = new Properties();
+        props.load(in);
+        in.close();
+        List results = new ArrayList();
+        for (Iterator it = props.keySet().iterator(); it.hasNext();) {
+            String key = (String) it.next();
+            int pos = key.indexOf('.');
+            String type = key.substring(0, pos);
+            String configId = key.substring(pos + 1);
+            try {
+                results.add(new ConfigurationMetadata(new URI(configId), props.getProperty(key),
type, set.contains(configId)));
+            } catch (URISyntaxException e) {
+                throw new IOException("Unable to create configID URI: "+e.getMessage());
+            }
+        }
+        return (ConfigurationMetadata[]) results.toArray(new ConfigurationMetadata[results.size()]);
+    }
+
+    public ConfigurationMetadata loadDependencies(URL mavenRepository, ConfigurationMetadata
source) throws IOException {
+        String conf = source.getConfigId().toString();
+        File file = File.createTempFile("geronimo-download", "." + conf.substring(conf.lastIndexOf("/")+1));
+        file.deleteOnExit();
+        String url = getURL(conf, mavenRepository.toString());
+        downloadFile(url, file); //todo: download only SNAPSHOTS if previously available?
+        configIdToFile.put(source.getConfigId(), file);
+        ZipFile zip = new ZipFile(file);
+        try {
+            ZipEntry entry = zip.getEntry("META-INF/config.ser");
+            ObjectInputStream serIn = new ObjectInputStream(zip.getInputStream(entry));
+            GBeanData config = new GBeanData();
+            config.readExternal(serIn);
+            URI[] parentIds = (URI[]) config.getAttribute("parentId");
+            List dependencies = (List) config.getAttribute("dependencies");
+            source.setDependencies((URI[]) dependencies.toArray(new URI[dependencies.size()]));
+            source.setParents(parentIds);
+            return source;
+        } catch (ClassNotFoundException e) {
+            throw new IOException("Unable to deserialize GBeanData (can't load class "+e.getMessage()+")");
+        } finally {
+            zip.close();
+        }
+    }
+
+    public DownloadResults install(URL mavenRepository, URI configId) throws IOException
{
+        Set set = new HashSet();
+        for (Iterator it = configurations.iterator(); it.hasNext();) {
+            Configuration next = (Configuration) it.next();
+            set.add(next.getId());
+        }
+        DownloadResults results = new DownloadResults();
+        processConfiguration(configId,writeableRepo,mavenRepository.toString(),set,results);
+        return results;
+    }
+
+
+
+
+    private String getURL(String configId, String baseRepositoryURL) {
+        String[] parts = configId.split("/");
+        return baseRepositoryURL+parts[0]+"/"+parts[3]+"s/"+parts[1]+"-"+parts[2]+"."+parts[3];
+    }
+
+    private void downloadFile(String url, File target) throws IOException {
+        log.info("Downloading "+url+" to "+target.getAbsolutePath());
+        byte[] buf = new byte[10240];
+        InputStream in = new URL(url).openStream();
+        FileOutputStream out = new FileOutputStream(target);
+        int count;
+        while((count = in.read(buf)) > -1) {
+            out.write(buf, 0, count);
+        }
+        in.close();
+        out.close();
+    }
+
+    private void processConfiguration(URI configId, WriteableRepository repo, String repoURL,
Set configurations, DownloadResults results) throws IOException {
+        // Make sure we have a local copy of the CAR
+        String id = configId.toString();
+        File file;
+        if(configIdToFile.containsKey(configId)) {
+            file = (File) configIdToFile.get(configId);
+        } else {
+            file = File.createTempFile("geronimo-download", "." + id.substring(id.lastIndexOf("/")+1));
+            file.deleteOnExit();
+        }
+        String configUrl = getURL(id, repoURL);
+        downloadFile(configUrl, file);
+        results.addConfigurationInstalled(configId);
+
+        // Process the contents of the CAR
+        ZipFile zip = new ZipFile(file);
+        try {
+            ZipEntry entry = zip.getEntry("META-INF/config.ser");
+            ObjectInputStream serIn = new ObjectInputStream(zip.getInputStream(entry));
+            GBeanData config = new GBeanData();
+            config.readExternal(serIn);
+            URI[] parentIds = (URI[]) config.getAttribute("parentId");
+            List dependencies = (List) config.getAttribute("dependencies");
+            // Download the dependencies
+            for (int i = 0; i < dependencies.size(); i++) {
+                URI dep = (URI) dependencies.get(i);
+                if(repo.hasURI(dep)) {
+                    results.addDependencyPresent(dep);
+                    continue;
+                }
+                String url = getURL(dep.toString(), repoURL);
+                log.info("Downloading "+url+" to local repository");
+                repo.copyToRepository(new URL(url).openStream(), dep, null);
+                results.addDependencyInstalled(dep);
+            }
+            // Download the parents
+            for (int i = 0; i < parentIds.length; i++) {
+                URI uri = parentIds[i];
+                if(configurations.contains(uri)) {
+                    results.addConfigurationPresent(uri);
+                    continue;
+                }
+                processConfiguration(uri, repo, repoURL, configurations, results);
+            }
+            // Install the configuration
+            configStore.install(file.toURL());
+        } catch (ClassNotFoundException e) {
+            throw new IOException("Unable to deserialize GBeanData: "+e.getMessage());
+        } catch (InvalidConfigException e) {
+            throw new IOException("Unable to install configuration: "+e.getMessage());
+        } finally {
+            zip.close();
+        }
+    }
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(ConfigInstallerGBean.class);
+        infoFactory.addReference("AllConfigurations", Configuration.class);
+        infoFactory.addReference("DependencyInstallTarget", WriteableRepository.class, "GBean");
+        infoFactory.addReference("ConfigurationInstallTarget", ConfigurationStore.class,
"ConfigurationStore");
+        infoFactory.addInterface(ConfigurationInstaller.class);
+
+        infoFactory.setConstructor(new String[]{"AllConfigurations", "DependencyInstallTarget",
"ConfigurationInstallTarget"});
+
+        GBEAN_INFO = infoFactory.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+}

Propchange: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigInstallerGBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationInstaller.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationInstaller.java?rev=388832&view=auto
==============================================================================
--- geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationInstaller.java
(added)
+++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationInstaller.java
Sat Mar 25 13:11:55 2006
@@ -0,0 +1,32 @@
+/**
+ *
+ * Copyright 2005 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.system.configuration;
+
+import java.net.URL;
+import java.net.URI;
+import java.io.IOException;
+
+/**
+ * Knows how to import and export configurations
+ *
+ * @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
+ */
+public interface ConfigurationInstaller {
+    public ConfigurationMetadata[] listConfigurations(URL mavenRepository) throws IOException;
+    public ConfigurationMetadata loadDependencies(URL mavenRepository, ConfigurationMetadata
source) throws IOException;
+    public DownloadResults install(URL mavenRepository, URI configId) throws IOException;
+}

Propchange: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationInstaller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationMetadata.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationMetadata.java?rev=388832&view=auto
==============================================================================
--- geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationMetadata.java
(added)
+++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationMetadata.java
Sat Mar 25 13:11:55 2006
@@ -0,0 +1,88 @@
+/**
+ *
+ * Copyright 2005 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.system.configuration;
+
+import java.io.Serializable;
+import java.net.URI;
+
+/**
+ * Various metadata on a configuration that's used when listing, importing,
+ * and exporting configurations.
+ *
+ * @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
+ */
+public class ConfigurationMetadata implements Serializable {
+    private URI configId;
+    private String description;
+    private String category;
+    private boolean installed;
+    private URI[] parents;
+    private URI[] dependencies;
+
+    public ConfigurationMetadata(URI configId, String description, String category, boolean
installed) {
+        this.configId = configId;
+        this.description = description;
+        this.category = category;
+        this.installed = installed;
+    }
+
+    public void setParents(URI[] parents) {
+        this.parents = parents;
+    }
+
+    public void setDependencies(URI[] dependencies) {
+        this.dependencies = dependencies;
+    }
+
+    public URI getConfigId() {
+        return configId;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public String getCategory() {
+        return category;
+    }
+
+    public boolean isInstalled() {
+        return installed;
+    }
+
+    public String getVersion() {
+        String[] parts = configId.toString().split("/");
+        if(parts.length == 4) {
+            return parts[2];
+        }
+        return "unknown version";
+    }
+
+    /**
+     * Note: if null, this information has not yet been loaded from the repository
+     */
+    public URI[] getParents() {
+        return parents;
+    }
+
+    /**
+     * Note: if null, this information has not yet been loaded from the repository
+     */
+    public URI[] getDependencies() {
+        return dependencies;
+    }
+}

Propchange: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationMetadata.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/DownloadResults.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/DownloadResults.java?rev=388832&view=auto
==============================================================================
--- geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/DownloadResults.java
(added)
+++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/DownloadResults.java
Sat Mar 25 13:11:55 2006
@@ -0,0 +1,66 @@
+/**
+ *
+ * Copyright 2005 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.system.configuration;
+
+import java.io.Serializable;
+import java.net.URI;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Lists the results of a configuration download operation.
+ *
+ * @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
+ */
+public class DownloadResults implements Serializable {
+    private List configurationsPresent = new ArrayList();
+    private List configurationsInstalled = new ArrayList();
+    private List dependenciesPresent = new ArrayList();
+    private List dependenciesInstalled = new ArrayList();
+
+    void addConfigurationPresent(URI config) {
+        configurationsPresent.add(config);
+    }
+
+    void addConfigurationInstalled(URI config) {
+        configurationsInstalled.add(config);
+    }
+
+    void addDependencyPresent(URI dep) {
+        dependenciesPresent.add(dep);
+    }
+
+    void addDependencyInstalled(URI dep) {
+        dependenciesInstalled.add(dep);
+    }
+
+    public URI[] getConfigurationsPresent() {
+        return (URI[]) configurationsPresent.toArray(new URI[configurationsPresent.size()]);
+    }
+
+    public URI[] getConfigurationsInstalled() {
+        return (URI[]) configurationsInstalled.toArray(new URI[configurationsInstalled.size()]);
+    }
+
+    public URI[] getDependenciesPresent() {
+        return (URI[]) dependenciesPresent.toArray(new URI[dependenciesPresent.size()]);
+    }
+
+    public URI[] getDependenciesInstalled() {
+        return (URI[]) dependenciesInstalled.toArray(new URI[dependenciesInstalled.size()]);
+    }
+}

Propchange: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/DownloadResults.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message