Author: ips
Date: 2009-04-04 12:58:23 -0400 (Sat, 04 Apr 2009)
New Revision: 276
Added:
trunk/core/src/main/java/org/jboss/on/embedded/ui/ApplicationInfoAction.java
Modified:
trunk/core/src/main/java/org/jboss/on/embedded/BootstrapAction.java
trunk/core/src/main/java/org/jboss/on/embedded/manager/pc/PluginContainerResourceManager.java
trunk/core/src/main/java/org/jboss/on/embedded/ui/DiscoveryAction.java
trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java
trunk/core/src/main/java/org/jboss/on/embedded/ui/content/AbstractFileUploadAction.java
trunk/core/src/main/java/org/jboss/on/embedded/ui/content/UpdateBackingContentAction.java
trunk/core/src/main/webapp/errorLayout.xhtml
trunk/core/src/main/webapp/layout.xhtml
trunk/core/src/main/webapp/login.xhtml
trunk/core/src/main/webapp/secure/resourceInstanceContent.xhtml
Log:
do bootstrap after first successful login, rather than at webapp startup time
(
https://jira.jboss.org/jira/browse/EMBJOPR-85)
Modified: trunk/core/src/main/java/org/jboss/on/embedded/BootstrapAction.java
===================================================================
--- trunk/core/src/main/java/org/jboss/on/embedded/BootstrapAction.java 2009-04-03
15:41:45 UTC (rev 275)
+++ trunk/core/src/main/java/org/jboss/on/embedded/BootstrapAction.java 2009-04-04
16:58:23 UTC (rev 276)
@@ -24,16 +24,17 @@
import org.jboss.on.embedded.bean.history.content.ContentServerServiceImpl;
import org.jboss.on.embedded.bean.history.content.ContentHistoryManagerBean;
import org.jboss.on.embedded.bean.history.operation.OperationServerServiceImpl;
-import org.jboss.on.embedded.manager.ResourceManager;
+import org.jboss.on.embedded.manager.history.operation.OperationHistoryManager;
import org.jboss.on.embedded.manager.ResourceManagerFactory;
-import org.jboss.on.embedded.manager.history.operation.OperationHistoryManager;
+
import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Create;
+import org.jboss.seam.security.Identity;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Startup;
import org.jboss.seam.annotations.Destroy;
+import org.jboss.seam.annotations.Observer;
import org.jboss.seam.contexts.ServletLifecycle;
import org.jetbrains.annotations.Nullable;
import org.rhq.core.pc.PluginContainer;
@@ -43,7 +44,6 @@
import org.rhq.core.pc.plugin.SimplePluginFinder;
import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
import java.io.File;
import java.io.FileInputStream;
@@ -57,7 +57,9 @@
import java.util.logging.Level;
/**
- * A Seam managed bean that bootstraps the admin console immediately after the admin
console WAR is deployed.
+ * A Seam component that is in charge of initializing and shutting down the Admin
Console.
+ *
+ * @author Ian Springer
*/
@Name("bootstrapAction")
@Scope(ScopeType.APPLICATION)
@@ -79,53 +81,75 @@
@In(value = "inventoryEventListener", create = true)
private EmbeddedInventoryEventListener inventoryEventListener;
+ private boolean initialized;
+
private File tempDir;
- @Create
- public void init() throws ServletException
+ /**
+ * Initializes the Admin Console after the first user logs in.
+ */
+ @Observer(Identity.EVENT_LOGIN_SUCCESSFUL)
+ public void init()
{
- try
- {
- bootstrap();
+ if (!this.initialized) {
+ try
+ {
+ String version = getVersion();
+ LOG.info("Bootstrapping Administration Console" + ((version !=
null) ? (" v" + version) : "") + "...");
+ long startTime = System.currentTimeMillis();
+ reconfigureJdkLogging();
+ initPluginContainer();
+ ResourceManagerFactory.resourceManager().discoverResources();
+ long elapsedTime = System.currentTimeMillis() - startTime;
+ LOG.info("Done bootstrapping Administration Console (" +
elapsedTime + " ms elapsed).");
+ this.initialized = true;
+ }
+ catch (Exception e)
+ {
+ LOG.error("*** Failed to initialize Administration Console.
***", e);
+ }
}
- catch (Exception e)
- {
- LOG.error("Error bootstrapping Administration Console", e);
- }
}
/**
- * Shutdown the plugin container when the webapp gets undeployed.
+ * Shuts down the Admin Console when the webapp is stopped.
*/
@Destroy
public void shutdown()
{
- PluginContainer.getInstance().shutdown();
+ if (this.initialized) {
+ try
+ {
+ PluginContainer.getInstance().shutdown();
+ }
+ catch (RuntimeException e)
+ {
+ LOG.error("*** Failed to shutdown Administration Console. ***",
e);
+ }
+ }
}
+ public boolean isInitialized()
+ {
+ return this.initialized;
+ }
+
public File getTempDir()
{
return this.tempDir;
}
- private void bootstrap()
- throws Exception
+ private void initPluginContainer()
+ throws MalformedURLException
{
- String version = getVersion();
- LOG.info("Bootstrapping Administration Console" + ((version != null) ?
(" v" + version) : "") + "...");
- reconfigureJdkLogging();
PluginContainerConfiguration pluginContainerConfig =
createPluginContainerConfiguration();
PluginContainer pluginContainer = PluginContainer.getInstance();
pluginContainer.setConfiguration(pluginContainerConfig);
configureMockScenarioLoader();
pluginContainer.initialize();
logLoadedPlugins(pluginContainer);
- // Add our inventory listener BEFORE initiating Resource discovery.
pluginContainer.getInventoryManager().addInventoryEventListener(this.inventoryEventListener);
pluginContainer.getInventoryManager().addInventoryEventListener(new
LoggingInventoryEventListener());
- ResourceManager resourceManager = ResourceManagerFactory.resourceManager();
- resourceManager.discoverResources();
- LOG.info("Done bootstrapping Administration Console.");
}
@Nullable
@@ -233,6 +257,7 @@
if (baseTempDir == null)
baseTempDir = File.separatorChar == '/' ? "/tmp" :
"C:/tmp";
this.tempDir = new File(baseTempDir, "embjopr");
+ //noinspection ResultOfMethodCallIgnored
this.tempDir.mkdirs();
if (!this.tempDir.exists())
throw new IllegalStateException("Failed to initialize temporary
directory: " + this.tempDir);
@@ -245,9 +270,7 @@
File directory = null;
String directoryPath = System.getProperty(systemProperty);
if (directoryPath != null)
- {
directory = new File(directoryPath);
- }
return directory;
}
}
Modified:
trunk/core/src/main/java/org/jboss/on/embedded/manager/pc/PluginContainerResourceManager.java
===================================================================
---
trunk/core/src/main/java/org/jboss/on/embedded/manager/pc/PluginContainerResourceManager.java 2009-04-03
15:41:45 UTC (rev 275)
+++
trunk/core/src/main/java/org/jboss/on/embedded/manager/pc/PluginContainerResourceManager.java 2009-04-04
16:58:23 UTC (rev 276)
@@ -329,7 +329,7 @@
public Availability getAvailability(Resource resource)
{
- return getInventoryService().getAvailability(resource);
+ return getInventoryService().getCurrentAvailability(resource);
}
public List<OperationDefinition> getOperationsForResource(Resource resource)
Added: trunk/core/src/main/java/org/jboss/on/embedded/ui/ApplicationInfoAction.java
===================================================================
--- trunk/core/src/main/java/org/jboss/on/embedded/ui/ApplicationInfoAction.java
(rev 0)
+++
trunk/core/src/main/java/org/jboss/on/embedded/ui/ApplicationInfoAction.java 2009-04-04
16:58:23 UTC (rev 276)
@@ -0,0 +1,54 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.jboss.on.embedded.ui;
+
+import javax.faces.context.FacesContext;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Startup;
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Factory;
+import org.jboss.seam.ScopeType;
+
+/**
+ * @author Ian Springer
+ */
+@Name("applicationInfoAction")
+(a)Scope(ScopeType.APPLICATION)
+@Startup
+public class ApplicationInfoAction
+{
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ @Factory(value = "baseUrl")
+ public String getBaseUrl()
+ {
+ FacesContext context = FacesContext.getCurrentInstance();
+ HttpServletRequest request = (HttpServletRequest)
context.getExternalContext().getRequest();
+ int indexAfterContextRoot =
request.getRequestURL().indexOf(request.getServletPath());
+ String baseUrl = request.getRequestURL().substring(0, indexAfterContextRoot) +
"/";
+ log.debug("Base URL: " + baseUrl);
+ return baseUrl;
+ }
+}
Property changes on:
trunk/core/src/main/java/org/jboss/on/embedded/ui/ApplicationInfoAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Author Id Revision HeadURL
Name: svn:eol-style
+ LF
Modified: trunk/core/src/main/java/org/jboss/on/embedded/ui/DiscoveryAction.java
===================================================================
--- trunk/core/src/main/java/org/jboss/on/embedded/ui/DiscoveryAction.java 2009-04-03
15:41:45 UTC (rev 275)
+++ trunk/core/src/main/java/org/jboss/on/embedded/ui/DiscoveryAction.java 2009-04-04
16:58:23 UTC (rev 276)
@@ -22,24 +22,29 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.on.embedded.manager.ResourceManagerFactory;
+import org.jboss.on.embedded.BootstrapAction;
+
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.In;
/**
- * A managed bean that periodically asynchronously executes runtime discovery scans.
+ * A managed bean that periodically asynchronously executes service discovery scans.
* The {@link #checkAutodiscovery()} action will get triggered every time the user
- * hits any page, but it will only kick off a scan if the last scan was more than
- * one minute ago.
+ * hits any page (configured in pages.xml), but it will only kick off a scan if the
+ * last scan was more than one minute ago.
*
* @author Charles Crouch
*/
-// Make this application-scoped so each user doesn't trigger their own discovery.
@Scope(ScopeType.APPLICATION)
@Name("discoveryAction")
public class DiscoveryAction {
- private static final Log log = LogFactory.getLog(DiscoveryAction.class);
-
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ @In
+ private BootstrapAction bootstrapAction;
+
private volatile long lastDiscoveryTime;
// the minimum length of time (in milliseconds) between consecutive discoveries
@@ -54,25 +59,20 @@
}
public void checkAutodiscovery() {
- if (System.currentTimeMillis() - lastDiscoveryTime > scanPeriod) {
+ if (this.bootstrapAction.isInitialized() && (System.currentTimeMillis() -
lastDiscoveryTime) > scanPeriod) {
// try the timestamp check in a synchronized block
tryAutodiscovery();
}
}
synchronized private void tryAutodiscovery() {
- log.debug("DiscoveryFilter tryAutodiscovery");
- if (System.currentTimeMillis() - lastDiscoveryTime > scanPeriod) {
- // put the timestamp updating above doAutodiscovery() so we don't continuously
- // retry on failure, and that we don't block subsequent requests
- // waiting to get into tryAutodiscovery()
+ log.trace("Checking if service discovery scan is needed...");
+ if ((System.currentTimeMillis() - lastDiscoveryTime) > scanPeriod) {
+ // Put the timestamp updating above the call to discoverServicesAsync(), so we
don't continuously
+ // retry on failure, and so we don't block subsequent requests waiting to get into
tryAutodiscovery().
lastDiscoveryTime = System.currentTimeMillis();
- doAutodiscovery();
+ log.debug("Performing service discovery scan...");
+ ResourceManagerFactory.resourceManager().discoverServicesAsync();
}
}
-
- private void doAutodiscovery() {
- log.debug("DiscoveryAction doAutodiscovery");
- ResourceManagerFactory.resourceManager().discoverServicesAsync();
- }
}
Modified: trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java
===================================================================
--- trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java 2009-04-03
15:41:45 UTC (rev 275)
+++ trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java 2009-04-04
16:58:23 UTC (rev 276)
@@ -26,8 +26,6 @@
import java.io.Serializable;
import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -82,8 +80,6 @@
this.openDepth = n;
}
- private String baseUrl;
-
private static final Log log = LogFactory.getLog(NavigationAction.class);
private Object navigationState;
@@ -103,24 +99,7 @@
return ResourceManagerFactory.resourceManager();
}
- public String getBaseUrl()
- {
- // TODO consider moving this initialization code into @Create method
- if (baseUrl == null)
- {
- StringBuilder url = new StringBuilder();
- FacesContext context = FacesContext.getCurrentInstance();
- HttpServletRequest request = (HttpServletRequest)
context.getExternalContext().getRequest();
- int indexAfterContextRoot =
request.getRequestURL().indexOf(request.getServletPath());
- baseUrl = request.getRequestURL().substring(0, indexAfterContextRoot) +
"/";
-
- log.debug("Base URL: " + url);
- }
-
- return baseUrl;
- }
-
@In(value = "rootNode", create=true)
private JONTreeNode rootNode;
Modified:
trunk/core/src/main/java/org/jboss/on/embedded/ui/content/AbstractFileUploadAction.java
===================================================================
---
trunk/core/src/main/java/org/jboss/on/embedded/ui/content/AbstractFileUploadAction.java 2009-04-03
15:41:45 UTC (rev 275)
+++
trunk/core/src/main/java/org/jboss/on/embedded/ui/content/AbstractFileUploadAction.java 2009-04-04
16:58:23 UTC (rev 276)
@@ -65,15 +65,14 @@
{
File tempFile;
File tempDir = this.bootstrapAction.getTempDir();
+ File uploadsDir = new File(tempDir, "uploads");
try {
-
- tempDir.mkdirs(); // just in case the temp dir got deleted since this webapp
was last deployed
- tempFile = new File(tempDir, this.fileName);
- log.debug("Writing temp file to " + tempFile + "...");
- if (tempFile.exists())
- tempFile.delete();
+ uploadsDir.mkdirs();
+ tempFile = new File(uploadsDir, this.fileName);
+ log.debug("Writing uploaded file to '" + tempFile +
"'...");
FileOutputStream fos = new FileOutputStream(tempFile);
fos.write(this.file);
+ log.debug("Wrote " + this.file.length + " bytes to '"
+ tempFile + "'.");
fos.close();
}
catch (IOException e) {
Modified:
trunk/core/src/main/java/org/jboss/on/embedded/ui/content/UpdateBackingContentAction.java
===================================================================
---
trunk/core/src/main/java/org/jboss/on/embedded/ui/content/UpdateBackingContentAction.java 2009-04-03
15:41:45 UTC (rev 275)
+++
trunk/core/src/main/java/org/jboss/on/embedded/ui/content/UpdateBackingContentAction.java 2009-04-04
16:58:23 UTC (rev 276)
@@ -179,8 +179,12 @@
try {
report =
PluginContainer.getInstance().getContentManager().executeResourcePackageDiscoveryImmediately(
this.resource.getId(), this.packageType.getName());
- if (report.getDeployedPackages().size() != 1)
- throw new
IllegalStateException("ContentManager.executeResourcePackageDiscoveryImmediately()
returned more than one package.");
+ if (report.getDeployedPackages().isEmpty())
+ throw new IllegalStateException("Backing " +
this.packageType.getName() + " package not found for "
+ + this.resource + ".");
+ if (report.getDeployedPackages().size() > 1)
+ throw new IllegalStateException("More than one " +
this.packageType.getName() + " package found for "
+ + this.resource + ".");
}
catch (PluginContainerException e) {
throw new Exception("Failed to discover underlying " +
this.packageType.getName() + " package for "
Modified: trunk/core/src/main/webapp/errorLayout.xhtml
===================================================================
--- trunk/core/src/main/webapp/errorLayout.xhtml 2009-04-03 15:41:45 UTC (rev 275)
+++ trunk/core/src/main/webapp/errorLayout.xhtml 2009-04-04 16:58:23 UTC (rev 276)
@@ -35,7 +35,7 @@
<f:view contentType="text/html; charset=UTF-8">
<head>
- <base href="#{navigationAction.baseUrl}" />
+ <base href="#{baseUrl}" />
<title>
<ui:insert
name="title">#{messages['default.windowTitle']}</ui:insert>
</title>
Modified: trunk/core/src/main/webapp/layout.xhtml
===================================================================
--- trunk/core/src/main/webapp/layout.xhtml 2009-04-03 15:41:45 UTC (rev 275)
+++ trunk/core/src/main/webapp/layout.xhtml 2009-04-04 16:58:23 UTC (rev 276)
@@ -33,7 +33,7 @@
</ui:remove>
<f:view contentType="text/html; charset=UTF-8">
<head>
- <base href="#{navigationAction.baseUrl}"/>
+ <base href="#{baseUrl}"/>
<title>
<ui:insert
name="title">#{messages['default.windowTitle']}</ui:insert>
</title>
Modified: trunk/core/src/main/webapp/login.xhtml
===================================================================
--- trunk/core/src/main/webapp/login.xhtml 2009-04-03 15:41:45 UTC (rev 275)
+++ trunk/core/src/main/webapp/login.xhtml 2009-04-04 16:58:23 UTC (rev 276)
@@ -34,7 +34,7 @@
</ui:remove>
<f:view contentType="text/html; charset=UTF-8">
<head>
- <base href="#{navigationAction.baseUrl}"/>
+ <base href="#{baseUrl}"/>
<title><ui:insert
name="title">#{messages['default.windowTitle']}</ui:insert></title>
<link href="css/console-style.css" rel="stylesheet"
type="text/css"/>
@@ -56,7 +56,7 @@
<h:messages layout="table"
styleClass="loginerror-msg"/>
<h:form id="login_form">
<div>
- <h2>Welcome to the JBoss administration console.</h2>
+ <h2>Welcome to the JBoss Administration Console.</h2>
<h2>Please login to proceed.</h2>
<p/>
<h:outputLabel for="name"
value="#{messages['security.username']}"/><br/>
Modified: trunk/core/src/main/webapp/secure/resourceInstanceContent.xhtml
===================================================================
--- trunk/core/src/main/webapp/secure/resourceInstanceContent.xhtml 2009-04-03 15:41:45
UTC (rev 275)
+++ trunk/core/src/main/webapp/secure/resourceInstanceContent.xhtml 2009-04-04 16:58:23
UTC (rev 276)
@@ -46,11 +46,13 @@
<ui:include
src="../include/displayGlobalMessages.xhtml"/>
<h:panelGroup layout="block" rendered="#{not empty
packageDetails.location}"
styleClass="instructionalText">
- <b>File Path:</b> #{packageDetails.location}
+ <b>File Path: </b> #{packageDetails.location}
</h:panelGroup>
<h:panelGroup layout="block" rendered="#{not empty
packageDetails.fileSize}"
styleClass="instructionalText">
- <b>File Size:</b> #{packageDetails.fileSize} bytes
+ <b>File Size: </b>
+ <h:outputText value=" "/>
+ <h:outputText
value="#{packageDetails.fileSize}"><f:convertNumber/></h:outputText>
bytes
</h:panelGroup>
<hr/>
<div class="instructionalText">