Merged V2.2 to HEAD

7389: Added Deploy action to user sandboxes
             Renamed DeploySnapshotDialog to DeployWebsiteDialog and AVMDeploySnapshotAction to AVMDeployWebsiteAction
             Updated UIDeployWebsite component to list unallocated test or live servers
             Updated DeployWebsiteDialog to update allocatedto property on server config when necessary
  7392: Incorporated panel graphics from Linton for deploy server configuration
             Applied feedback from Linton on add, edit, remove deploy server config
  7412: Added ability to re-deploy to test servers
             Added ability to view deployment reports for test servers
             Added ability to preview test servers

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8353 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2008-02-21 15:24:41 +00:00
parent 11d4e64539
commit 90eff8cbf0
28 changed files with 787 additions and 330 deletions

View File

@@ -895,16 +895,17 @@ public class AVMBrowseBean implements IContextListener
// expression in a 'rendered' attribute, we therefore cache the result
// on a per request basis
List<ChildAssociationRef> deployAttempts = null;
List<NodeRef> deployAttempts = null;
FacesContext context = FacesContext.getCurrentInstance();
Map request = context.getExternalContext().getRequestMap();
if (request.get(REQUEST_BEEN_DEPLOYED_KEY) == null)
{
// see if there are any deployment attempts for the site
// see if there are any deployment attempts for the staging area
NodeRef webProjectRef = this.getWebsite().getNodeRef();
deployAttempts = getNodeService().getChildAssocs(webProjectRef,
WCMAppModel.ASSOC_DEPLOYMENTATTEMPT, RegexQNamePattern.MATCH_ALL);
String store = (String)nodeService.getProperty(webProjectRef,
WCMAppModel.PROP_AVMSTORE);
deployAttempts = DeploymentUtil.findDeploymentAttempts(store);
// add a placeholder object in the request so we don't evaluate this again for this request
request.put(REQUEST_BEEN_DEPLOYED_KEY, Boolean.TRUE);
@@ -912,7 +913,7 @@ public class AVMBrowseBean implements IContextListener
}
else
{
deployAttempts = (List<ChildAssociationRef>)request.get(REQUEST_BEEN_DEPLOYED_RESULT);
deployAttempts = (List<NodeRef>)request.get(REQUEST_BEEN_DEPLOYED_RESULT);
}
return (deployAttempts != null && deployAttempts.size() > 0);

View File

@@ -809,44 +809,6 @@ public final class AVMUtil
return webProjectNode;
}
/**
* Retrieves the NodeRef of the deploymentattempt node with the given id
*
* @param attemptId The deployattemptid of the node to be found
* @return The NodeRef of the deploymentattempt node or null if not found
*/
public static NodeRef findDeploymentAttempt(String attemptId)
{
FacesContext fc = FacesContext.getCurrentInstance();
SearchService searchService = Repository.getServiceRegistry(fc).getSearchService();
// construct the query
String query = "@wca\\:deployattemptid:\"" + attemptId + "\"";
NodeRef attempt = null;
ResultSet results = null;
try
{
// execute the query
results = searchService.query(Repository.getStoreRef(),
SearchService.LANGUAGE_LUCENE, query);
if (results.length() == 1)
{
attempt = results.getNodeRef(0);
}
}
finally
{
if (results != null)
{
results.close();
}
}
return attempt;
}
/**
* Creates all directories for a path if they do not already exist.

View File

@@ -1175,7 +1175,7 @@ public class CreateWebsiteWizard extends BaseWizardBean
this.currentDeployServer.setProperties(this.editedDeployServerProps);
if (logger.isDebugEnabled())
logger.debug("Updated deploy server config: " + this.currentDeployServer);
logger.debug("Saved transient deploy server config: " + this.currentDeployServer);
// reset state
this.currentDeployServer = null;

View File

@@ -33,9 +33,10 @@ import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.WCMAppModel;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.avm.actions.AVMDeploySnapshotAction;
import org.alfresco.repo.avm.actions.AVMDeployWebsiteAction;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.sandbox.SandboxConstants;
import org.alfresco.service.cmr.action.Action;
@@ -51,25 +52,27 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Deploys a web project snapshot to one or more remote servers.
* Deploys a website to one or more remote servers.
*
* @author gavinc
*/
public class DeploySnapshotDialog extends BaseDialogBean
public class DeployWebsiteDialog extends BaseDialogBean
{
private static final long serialVersionUID = 62702082716235924L;
protected int versionToDeploy;
protected String[] deployTo;
protected String stagingStore;
protected String store;
protected String deployMode;
protected NodeRef websiteRef;
protected NodeRef webProjectRef;
protected boolean updateTestServer;
protected AVMBrowseBean avmBrowseBean;
transient private AVMService avmService;
transient private ActionService actionService;
private static final Log logger = LogFactory.getLog(DeploySnapshotDialog.class);
private static final Log logger = LogFactory.getLog(DeployWebsiteDialog.class);
// ------------------------------------------------------------------------------
// Dialog implementation
@@ -81,16 +84,35 @@ public class DeploySnapshotDialog extends BaseDialogBean
// setup context for dialog
this.deployTo = null;
this.versionToDeploy = Integer.parseInt(parameters.get("version"));
this.avmBrowseBean.getDeploymentMonitorIds().clear();
this.webProjectRef = this.avmBrowseBean.getWebsite().getNodeRef();
this.stagingStore = this.avmBrowseBean.getStagingStore();
String storeRoot = AVMUtil.buildSandboxRootPath(this.stagingStore);
String ver = parameters.get("version");
if (ver != null && ver.length() > 0)
{
this.versionToDeploy = Integer.parseInt(ver);
}
else
{
this.versionToDeploy = -1;
}
this.store = parameters.get("store");
String storeRoot = AVMUtil.buildSandboxRootPath(this.store);
this.websiteRef = AVMNodeConverter.ToNodeRef(this.versionToDeploy, storeRoot);
this.deployMode = (this.versionToDeploy == -1) ?
WCMAppModel.CONSTRAINT_TESTSERVER : WCMAppModel.CONSTRAINT_LIVESERVER;
this.updateTestServer = false;
String updateTestServerParam = parameters.get("updateTestServer");
if (updateTestServerParam != null)
{
this.updateTestServer = Boolean.parseBoolean(updateTestServerParam);
}
this.avmBrowseBean.getDeploymentMonitorIds().clear();
this.webProjectRef = this.avmBrowseBean.getWebsite().getNodeRef();
if (logger.isDebugEnabled())
logger.debug("Initialising dialog to deploy version " + this.versionToDeploy +
" of " + this.websiteRef.toString());
logger.debug("Initialising dialog to deploy: " + this.websiteRef.toString());
}
@SuppressWarnings("unchecked")
@@ -102,18 +124,17 @@ public class DeploySnapshotDialog extends BaseDialogBean
if (this.deployTo != null && this.deployTo.length > 0)
{
NodeRef webProjectRef = this.avmBrowseBean.getWebsite().getNodeRef();
List<String> selectedDeployToNames = new ArrayList<String>();
// create a deploymentattempt node to represent this deployment
String attemptId = GUID.generate();
Map<QName, Serializable> props = new HashMap<QName, Serializable>(8, 1.0f);
props.put(WCMAppModel.PROP_DEPLOYATTEMPTID, attemptId);
props.put(WCMAppModel.PROP_DEPLOYATTEMPTTYPE, WCMAppModel.CONSTRAINT_LIVESERVER);
props.put(WCMAppModel.PROP_DEPLOYATTEMPTSTORE, this.stagingStore);
props.put(WCMAppModel.PROP_DEPLOYATTEMPTTYPE, this.deployMode);
props.put(WCMAppModel.PROP_DEPLOYATTEMPTSTORE, this.store);
props.put(WCMAppModel.PROP_DEPLOYATTEMPTVERSION, this.versionToDeploy);
props.put(WCMAppModel.PROP_DEPLOYATTEMPTTIME, new Date());
NodeRef attempt = getNodeService().createNode(webProjectRef,
NodeRef attempt = getNodeService().createNode(this.webProjectRef,
WCMAppModel.ASSOC_DEPLOYMENTATTEMPT, WCMAppModel.ASSOC_DEPLOYMENTATTEMPT,
WCMAppModel.TYPE_DEPLOYMENTATTEMPT, props).getChildRef();
@@ -128,13 +149,33 @@ public class DeploySnapshotDialog extends BaseDialogBean
// get all properties of the target server
Map<QName, Serializable> serverProps = getNodeService().getProperties(serverRef);
String serverUri = AVMDeploySnapshotAction.calculateServerUri(serverProps);
String serverUri = AVMDeployWebsiteAction.calculateServerUri(serverProps);
String serverName = (String)serverProps.get(WCMAppModel.PROP_DEPLOYSERVERNAME);
if (serverName == null || serverName.length() == 0)
{
serverName = serverUri;
}
// if this is a test server deployment we need to allocate the
// test server to the current sandbox so it can re-use it and
// more importantly, no one else can. Before doing that however,
// we need to make sure no one else has taken the server since
// we selected it.
if (WCMAppModel.CONSTRAINT_TESTSERVER.equals(this.deployMode) &&
this.updateTestServer == false)
{
String allocatedTo = (String)serverProps.get(WCMAppModel.PROP_DEPLOYSERVERALLOCATEDTO);
if (allocatedTo != null)
{
throw new AlfrescoRuntimeException("testserver.taken", new Object[] {serverName});
}
else
{
getNodeService().setProperty(serverRef, WCMAppModel.PROP_DEPLOYSERVERALLOCATEDTO,
this.store);
}
}
if (logger.isDebugEnabled())
logger.debug("Issuing deployment request for: " + serverName);
@@ -150,11 +191,11 @@ public class DeploySnapshotDialog extends BaseDialogBean
// create and execute the action asynchronously
Map<String, Serializable> args = new HashMap<String, Serializable>(1, 1.0f);
args.put(AVMDeploySnapshotAction.PARAM_WEBSITE, webProjectRef);
args.put(AVMDeploySnapshotAction.PARAM_SERVER, serverRef);
args.put(AVMDeploySnapshotAction.PARAM_ATTEMPT, attempt);
args.put(AVMDeploySnapshotAction.PARAM_CALLBACK, monitor);
Action action = getActionService().createAction(AVMDeploySnapshotAction.NAME, args);
args.put(AVMDeployWebsiteAction.PARAM_WEBSITE, webProjectRef);
args.put(AVMDeployWebsiteAction.PARAM_SERVER, serverRef);
args.put(AVMDeployWebsiteAction.PARAM_ATTEMPT, attempt);
args.put(AVMDeployWebsiteAction.PARAM_CALLBACK, monitor);
Action action = getActionService().createAction(AVMDeployWebsiteAction.NAME, args);
getActionService().executeAction(action, this.websiteRef, false, true);
}
else if (logger.isWarnEnabled())
@@ -169,8 +210,8 @@ public class DeploySnapshotDialog extends BaseDialogBean
(Serializable)selectedDeployToNames);
// set the deploymentattempid property on the store this deployment was for
getAvmService().deleteStoreProperty(this.stagingStore, SandboxConstants.PROP_LAST_DEPLOYMENT_ID);
getAvmService().setStoreProperty(this.stagingStore, SandboxConstants.PROP_LAST_DEPLOYMENT_ID,
getAvmService().deleteStoreProperty(this.store, SandboxConstants.PROP_LAST_DEPLOYMENT_ID);
getAvmService().setStoreProperty(this.store, SandboxConstants.PROP_LAST_DEPLOYMENT_ID,
new PropertyValue(DataTypeDefinition.TEXT, attemptId));
// close this dialog and immediately open the monitorDeployment dialog
@@ -178,6 +219,9 @@ public class DeploySnapshotDialog extends BaseDialogBean
}
else
{
if (logger.isWarnEnabled())
logger.warn("Deployment of '" + this.websiteRef.toString() + "' skipped as no servers were selected");
return outcome;
}
}
@@ -260,6 +304,16 @@ public class DeploySnapshotDialog extends BaseDialogBean
return this.deployTo;
}
/**
* Returns the type of server to deploy to, either 'live' or 'test'.
*
* @return The type of server to deploy to
*/
public String getDeployMode()
{
return this.deployMode;
}
/**
* @return The NodeRef of the web project the deployment reports are being shown for
*/
@@ -268,6 +322,14 @@ public class DeploySnapshotDialog extends BaseDialogBean
return this.webProjectRef;
}
/**
* @return The store being deployed
*/
public String getStore()
{
return this.store;
}
/**
* @return The version of the snapshot to deploy
*/

View File

@@ -0,0 +1,275 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* 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; either version 2
* of the License, or (at your option) any later version.
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.web.bean.wcm;
import java.util.ArrayList;
import java.util.List;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.model.WCMAppModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.util.ISO9075;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Repository;
/**
* Helper methods for deployment
*
* @author Gavin Cornwell
*/
public final class DeploymentUtil
{
public static List<NodeRef> findDeploymentAttempts(String store)
{
FacesContext fc = FacesContext.getCurrentInstance();
SearchService searchService = Repository.getServiceRegistry(fc).getSearchService();
// query for all deploymentattempt nodes with the deploymentattemptstore
// set to the given store id
StringBuilder query = new StringBuilder("@");
query.append(NamespaceService.WCMAPP_MODEL_PREFIX);
query.append("\\:");
query.append(WCMAppModel.PROP_DEPLOYATTEMPTSTORE.getLocalName());
query.append(":\"");
query.append(store);
query.append("\"");
ResultSet results = null;
List<NodeRef> attempts = new ArrayList<NodeRef>();
try
{
// execute the query
results = searchService.query(Repository.getStoreRef(),
SearchService.LANGUAGE_LUCENE, query.toString());
for (NodeRef attempt : results.getNodeRefs())
{
attempts.add(attempt);
}
}
finally
{
if (results != null)
{
results.close();
}
}
return attempts;
}
/**
* Retrieves the NodeRef of the deploymentattempt node with the given id
*
* @param attemptId The deployattemptid of the node to be found
* @return The NodeRef of the deploymentattempt node or null if not found
*/
public static NodeRef findDeploymentAttempt(String attemptId)
{
FacesContext fc = FacesContext.getCurrentInstance();
SearchService searchService = Repository.getServiceRegistry(fc).getSearchService();
// construct the query
StringBuilder query = new StringBuilder("@");
query.append(NamespaceService.WCMAPP_MODEL_PREFIX);
query.append("\\:");
query.append(WCMAppModel.PROP_DEPLOYATTEMPTID.getLocalName());
query.append(":\"");
query.append(attemptId);
query.append("\"");
ResultSet results = null;
NodeRef attempt = null;
try
{
// execute the query
results = searchService.query(Repository.getStoreRef(),
SearchService.LANGUAGE_LUCENE, query.toString());
if (results.length() == 1)
{
attempt = results.getNodeRef(0);
}
else if (results.length() > 1)
{
throw new IllegalStateException(
"More than one deployment attempt node was found, there should only be one!");
}
}
finally
{
if (results != null)
{
results.close();
}
}
return attempt;
}
/**
* Returns the test server allocated to the given store.
*
* @param store The store to get the test server for
* @return The allocated server or null if there isn't one
*/
public static NodeRef findAllocatedTestServer(String store)
{
FacesContext fc = FacesContext.getCurrentInstance();
SearchService searchService = Repository.getServiceRegistry(fc).getSearchService();
// construct the query
StringBuilder query = new StringBuilder("@");
query.append(NamespaceService.WCMAPP_MODEL_PREFIX);
query.append("\\:");
query.append(WCMAppModel.PROP_DEPLOYSERVERALLOCATEDTO.getLocalName());
query.append(":\"");
query.append(store);
query.append("\"");
ResultSet results = null;
NodeRef testServer = null;
try
{
// execute the query
results = searchService.query(Repository.getStoreRef(),
SearchService.LANGUAGE_LUCENE, query.toString());
if (results.length() == 1)
{
testServer = results.getNodeRef(0);
}
else if (results.length() > 1)
{
throw new IllegalStateException("More than one allocated test server for store '" +
store + "' was found, should only be one!");
}
}
finally
{
if (results != null)
{
results.close();
}
}
return testServer;
}
/**
* Returns a list of NodeRefs representing the 'live' servers configured
* for the given web project.
*
* @param webProject Web project to get live servers for
* @return List of live servers
*/
public static List<NodeRef> findLiveServers(NodeRef webProject)
{
return findServers(webProject, true, false);
}
/**
* Returns a list of NodeRefs representing the 'test' servers configured
* for the given web project.
*
* @param webProject Web project to get test servers for
* @param allocated true only returns those servers already allocated
* @return List of test servers
*/
public static List<NodeRef> findTestServers(NodeRef webProject, boolean allocated)
{
return findServers(webProject, false, allocated);
}
private static List<NodeRef> findServers(NodeRef webProject, boolean live, boolean allocated)
{
FacesContext context = FacesContext.getCurrentInstance();
NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();
SearchService searchService = Repository.getServiceRegistry(context).getSearchService();
// build the query
String webProjectName = (String)nodeService.getProperty(webProject, ContentModel.PROP_NAME);
String safeProjectName = ISO9075.encode(webProjectName);
StringBuilder query = new StringBuilder("PATH:\"/");
query.append(Application.getRootPath(context));
query.append("/");
query.append(Application.getWebsitesFolderName(context));
query.append("/cm:");
query.append(safeProjectName);
query.append("/*\" AND @");
query.append(NamespaceService.WCMAPP_MODEL_PREFIX);
query.append("\\:");
query.append(WCMAppModel.PROP_DEPLOYSERVERTYPE.getLocalName());
query.append(":\"");
if (live)
{
query.append(WCMAppModel.CONSTRAINT_LIVESERVER);
}
else
{
query.append(WCMAppModel.CONSTRAINT_TESTSERVER);
}
query.append("\"");
// if required filter the test servers
if (live == false && allocated == false)
{
query.append(" AND ISNULL:\"");
query.append(WCMAppModel.PROP_DEPLOYSERVERALLOCATEDTO.toString());
query.append("\"");
}
// execute the query
ResultSet results = null;
List<NodeRef> servers = new ArrayList<NodeRef>();
try
{
results = searchService.query(Repository.getStoreRef(),
SearchService.LANGUAGE_LUCENE, query.toString());
for (NodeRef server : results.getNodeRefs())
{
servers.add(server);
}
}
finally
{
if (results != null)
{
results.close();
}
}
return servers;
}
}

View File

@@ -28,7 +28,6 @@ import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.apache.commons.logging.Log;
@@ -43,10 +42,7 @@ public class ViewDeploymentReportDialog extends BaseDialogBean
{
private static final long serialVersionUID = -8054466371051782132L;
protected NodeRef webProjectRef;
protected Integer deployedVersion;
protected AVMBrowseBean avmBrowseBean;
protected String store;
private static final Log logger = LogFactory.getLog(ViewDeploymentReportDialog.class);
@@ -58,11 +54,16 @@ public class ViewDeploymentReportDialog extends BaseDialogBean
{
super.init(parameters);
this.webProjectRef = this.avmBrowseBean.getWebsite().getNodeRef();
this.store = parameters.get("store");
if (this.store == null || this.store.length() == 0)
{
throw new IllegalArgumentException("store parameter is mandatory");
}
if (logger.isDebugEnabled())
logger.debug("Initialising dialog to view deployment report for " +
this.avmBrowseBean.getStagingStore());
logger.debug("Initialising dialog to view deployment report for: " +
this.store);
}
@Override
@@ -81,18 +82,10 @@ public class ViewDeploymentReportDialog extends BaseDialogBean
// Bean getters and setters
/**
* @return The NodeRef of the web project the deployment reports are being shown for
* @return The store to show deployment reports for
*/
public NodeRef getWebProjectRef()
public String getStore()
{
return this.webProjectRef;
return this.store;
}
/**
* @param avmBrowseBean The AVM BrowseBean instance to use
*/
public void setAvmBrowseBean(AVMBrowseBean avmBrowseBean)
{
this.avmBrowseBean = avmBrowseBean;
}
}
}