mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merged V2.2 to HEAD
7307: Re-enabled ability to perform deployments against new model 7278: Added friendly server name property to model and refactored view deployment report dialog 7272: Patch for new deployment features git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8245 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -67,14 +67,16 @@ public class AVMDeploySnapshotAction extends ActionExecuterAbstractBase
|
||||
public static final String NAME = "avm-deploy-snapshot";
|
||||
|
||||
public static final String PARAM_WEBSITE = "website";
|
||||
public static final String PARAM_TARGET_SERVER = "target-server";
|
||||
public static final String PARAM_DEFAULT_RMI_PORT = "default-rmi-port";
|
||||
public static final String PARAM_DEFAULT_RECEIVER_RMI_PORT = "default-receiver-rmi-port";
|
||||
public static final String PARAM_REMOTE_USERNAME = "remote-username";
|
||||
public static final String PARAM_REMOTE_PASSWORD = "remote-password";
|
||||
public static final String PARAM_CALLBACK = "deploy-callback";
|
||||
public static final String PARAM_DELAY = "delay";
|
||||
public static final String PARAM_SERVER = "server";
|
||||
public static final String PARAM_ATTEMPT = "attempt";
|
||||
public static final String PARAM_CALLBACK = "callback";
|
||||
|
||||
private int delay = -1;
|
||||
private int defaultAlfRmiPort = 50500;
|
||||
private int defaultReceiverRmiPort = 44100;
|
||||
private String defaultRemoteUsername = "admin";
|
||||
private String defaultRemotePassword = "admin";
|
||||
private String defaultTargetName = "default";
|
||||
private DeploymentService deployService;
|
||||
private ContentService contentService;
|
||||
private NodeService nodeService;
|
||||
@@ -83,6 +85,96 @@ public class AVMDeploySnapshotAction extends ActionExecuterAbstractBase
|
||||
private static Log delayDeploymentLogger = LogFactory.getLog("alfresco.deployment.delay");
|
||||
private static final String FILE_SERVER_PREFIX = "\\\\";
|
||||
|
||||
/**
|
||||
* Calculate the URI representation of a server from the given set of properties
|
||||
*
|
||||
* @param props Set of properties to calculate URI from
|
||||
*/
|
||||
public static String calculateServerUri(Map<QName, Serializable> props)
|
||||
{
|
||||
StringBuilder uri = new StringBuilder();
|
||||
|
||||
// prefix the uri if necessary
|
||||
String type = (String)props.get(WCMAppModel.PROP_DEPLOYTYPE);
|
||||
if (WCMAppModel.CONSTRAINT_FILEDEPLOY.equals(type))
|
||||
{
|
||||
uri.append(FILE_SERVER_PREFIX);
|
||||
}
|
||||
|
||||
// append server name
|
||||
uri.append((String)props.get(WCMAppModel.PROP_DEPLOYSERVERHOST));
|
||||
|
||||
// append port (if present)
|
||||
Integer port = (Integer)props.get(WCMAppModel.PROP_DEPLOYSERVERPORT);
|
||||
if (port != null)
|
||||
{
|
||||
uri.append(":");
|
||||
uri.append(port.toString());
|
||||
}
|
||||
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the delay to use before starting the deployment
|
||||
*
|
||||
* @param delay The delay in seconds
|
||||
*/
|
||||
public void setDelay(int delay)
|
||||
{
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default RMI port for Alfresco server deployments
|
||||
*
|
||||
* @param defaultAlfrescoRmiPort port number
|
||||
*/
|
||||
public void setDefaultAlfrescoRmiPort(int defaultAlfrescoRmiPort)
|
||||
{
|
||||
this.defaultAlfRmiPort = defaultAlfrescoRmiPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default RMI port for File system deployments
|
||||
*
|
||||
* @param defaultReceiverRmiPort port number
|
||||
*/
|
||||
public void setDefaultReceiverRmiPort(int defaultReceiverRmiPort)
|
||||
{
|
||||
this.defaultReceiverRmiPort = defaultReceiverRmiPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default remote username to use for deployments
|
||||
*
|
||||
* @param defaultRemoteUsername Default remote username
|
||||
*/
|
||||
public void setDefaultRemoteUsername(String defaultRemoteUsername)
|
||||
{
|
||||
this.defaultRemoteUsername = defaultRemoteUsername;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default remote password to use for deployments
|
||||
*
|
||||
* @param defaultRemotePassword Default remote password
|
||||
*/
|
||||
public void setDefaultRemotePassword(String defaultRemotePassword)
|
||||
{
|
||||
this.defaultRemotePassword = defaultRemotePassword;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default target name to use on file system receivers
|
||||
*
|
||||
* @param defaultTargetName Default target name
|
||||
*/
|
||||
public void setDefaultTargetName(String defaultTargetName)
|
||||
{
|
||||
this.defaultTargetName = defaultTargetName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param service The NodeService instance
|
||||
*/
|
||||
@@ -112,20 +204,12 @@ public class AVMDeploySnapshotAction extends ActionExecuterAbstractBase
|
||||
{
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_WEBSITE, DataTypeDefinition.NODE_REF, true,
|
||||
getParamDisplayLabel(PARAM_WEBSITE)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_TARGET_SERVER, DataTypeDefinition.TEXT, true,
|
||||
getParamDisplayLabel(PARAM_TARGET_SERVER)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_DEFAULT_RMI_PORT, DataTypeDefinition.INT, true,
|
||||
getParamDisplayLabel(PARAM_DEFAULT_RMI_PORT)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_DEFAULT_RECEIVER_RMI_PORT, DataTypeDefinition.INT, true,
|
||||
getParamDisplayLabel(PARAM_DEFAULT_RECEIVER_RMI_PORT)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_REMOTE_USERNAME, DataTypeDefinition.TEXT, true,
|
||||
getParamDisplayLabel(PARAM_REMOTE_USERNAME)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_REMOTE_PASSWORD, DataTypeDefinition.TEXT, true,
|
||||
getParamDisplayLabel(PARAM_REMOTE_PASSWORD)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_SERVER, DataTypeDefinition.NODE_REF, true,
|
||||
getParamDisplayLabel(PARAM_SERVER)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_ATTEMPT, DataTypeDefinition.NODE_REF, false,
|
||||
getParamDisplayLabel(PARAM_ATTEMPT)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_CALLBACK, DataTypeDefinition.ANY, false,
|
||||
getParamDisplayLabel(PARAM_CALLBACK)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_DELAY, DataTypeDefinition.INT, false,
|
||||
getParamDisplayLabel(PARAM_DELAY)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,40 +235,81 @@ public class AVMDeploySnapshotAction extends ActionExecuterAbstractBase
|
||||
") provided does not exist!");
|
||||
}
|
||||
|
||||
// get the NodeRef representing the server to deploy to
|
||||
NodeRef serverRef = (NodeRef)action.getParameterValue(PARAM_SERVER);
|
||||
if (this.nodeService.exists(serverRef) == false)
|
||||
{
|
||||
throw new IllegalStateException("The server NodeRef (" + serverRef +
|
||||
") provided does not exist!");
|
||||
}
|
||||
|
||||
// get the NodeRef representing the deployment attempt this one is part of
|
||||
NodeRef attemptRef = (NodeRef)action.getParameterValue(PARAM_ATTEMPT);
|
||||
|
||||
// TODO: if attempt reference is null create one now for this deployment, for now throw error
|
||||
if (this.nodeService.exists(attemptRef) == false)
|
||||
{
|
||||
throw new IllegalStateException("The attempt NodeRef (" + serverRef +
|
||||
") provided does not exist!");
|
||||
}
|
||||
|
||||
// get the callback object
|
||||
DeploymentCallback callback = (DeploymentCallback)action.getParameterValue(PARAM_CALLBACK);
|
||||
|
||||
// get the remote machine
|
||||
String targetServer = (String)action.getParameterValue(PARAM_TARGET_SERVER);
|
||||
String remoteUsername = (String)action.getParameterValue(PARAM_REMOTE_USERNAME);
|
||||
String remotePassword = (String)action.getParameterValue(PARAM_REMOTE_PASSWORD);
|
||||
int defaultAlfRmiPort = (Integer)action.getParameterValue(PARAM_DEFAULT_RMI_PORT);
|
||||
int defaultReceiverRmiPort = (Integer)action.getParameterValue(PARAM_DEFAULT_RECEIVER_RMI_PORT);
|
||||
int delay = -1;
|
||||
if (action.getParameterValue(PARAM_DELAY) != null)
|
||||
{
|
||||
delay = (Integer)action.getParameterValue(PARAM_DELAY);
|
||||
}
|
||||
// get the other data from the deploymentserver object
|
||||
Map<QName, Serializable> serverProps = nodeService.getProperties(serverRef);
|
||||
String serverUri = calculateServerUri(serverProps);
|
||||
String host = (String)serverProps.get(WCMAppModel.PROP_DEPLOYSERVERHOST);
|
||||
Integer port = (Integer)serverProps.get(WCMAppModel.PROP_DEPLOYSERVERPORT);
|
||||
String remoteUsername = (String)serverProps.get(WCMAppModel.PROP_DEPLOYSERVERUSERNAME);
|
||||
String remotePassword = (String)serverProps.get(WCMAppModel.PROP_DEPLOYSERVERPASSWORD);
|
||||
boolean fileServerDeployment = WCMAppModel.CONSTRAINT_FILEDEPLOY.equals(
|
||||
serverProps.get(WCMAppModel.PROP_DEPLOYTYPE));
|
||||
String sourcePath = (String)serverProps.get(WCMAppModel.PROP_DEPLOYSOURCEPATH);
|
||||
String targetName = (String)serverProps.get(WCMAppModel.PROP_DEPLOYSERVERTARGET);
|
||||
String targetPath = path;
|
||||
|
||||
// determine whether this is a file server or Alfresco server deployment
|
||||
boolean fileServerDeployment = false;
|
||||
if (targetServer.startsWith(FILE_SERVER_PREFIX))
|
||||
{
|
||||
fileServerDeployment = true;
|
||||
}
|
||||
// TODO: determine if we need to deploy a subfolder of the website
|
||||
|
||||
// if "localhost" is passed as the target server add "live" to the end of the
|
||||
// store name, this store will then get created automatically.
|
||||
String targetPath = null;
|
||||
if (targetServer.equalsIgnoreCase("localhost") || targetServer.equalsIgnoreCase("127.0.0.1"))
|
||||
if (fileServerDeployment == false)
|
||||
{
|
||||
targetPath = storePath[0] + "live:" + storePath[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Check that the actual host name of the machine hasn't been passed
|
||||
// if "localhost" is passed as the target server add "live" to the end of the
|
||||
// store name, this store will then get created automatically.
|
||||
|
||||
targetPath = path;
|
||||
// TODO: Check that the actual host name of the machine hasn't been passed
|
||||
|
||||
if (port == null && (host.equalsIgnoreCase("localhost") || host.equalsIgnoreCase("127.0.0.1")))
|
||||
{
|
||||
targetPath = storePath[0] + "live:" + storePath[1];
|
||||
}
|
||||
}
|
||||
|
||||
// get defaults for data not provided in server node
|
||||
if (port == null)
|
||||
{
|
||||
if (fileServerDeployment)
|
||||
{
|
||||
port = this.defaultReceiverRmiPort;
|
||||
}
|
||||
else
|
||||
{
|
||||
port = this.defaultAlfRmiPort;
|
||||
}
|
||||
}
|
||||
|
||||
if (remoteUsername == null || remoteUsername.length() == 0)
|
||||
{
|
||||
remoteUsername = this.defaultRemoteUsername;
|
||||
}
|
||||
|
||||
if (remotePassword == null || remotePassword.length() == 0)
|
||||
{
|
||||
remotePassword = this.defaultRemotePassword;
|
||||
}
|
||||
|
||||
if (targetName == null || targetName.length() == 0)
|
||||
{
|
||||
targetName = this.defaultTargetName;
|
||||
}
|
||||
|
||||
// take a note of the current date/time
|
||||
@@ -192,7 +317,7 @@ public class AVMDeploySnapshotAction extends ActionExecuterAbstractBase
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Starting deployment of " + actionedUponNodeRef.toString() +
|
||||
" to " + targetServer + " at " + startDate);
|
||||
" to " + serverUri + " at " + startDate);
|
||||
|
||||
if (delayDeploymentLogger.isDebugEnabled() && delay > 0)
|
||||
{
|
||||
@@ -207,46 +332,24 @@ public class AVMDeploySnapshotAction extends ActionExecuterAbstractBase
|
||||
DeploymentReport report = null;
|
||||
try
|
||||
{
|
||||
String host = targetServer;
|
||||
int port = defaultAlfRmiPort;
|
||||
if (fileServerDeployment)
|
||||
{
|
||||
port = defaultReceiverRmiPort;
|
||||
}
|
||||
|
||||
// check whether there is a port number present, if so, use it
|
||||
int idx = targetServer.indexOf(":");
|
||||
if (idx != -1)
|
||||
{
|
||||
host = targetServer.substring(0, idx);
|
||||
String strPort = targetServer.substring(idx+1);
|
||||
port = Integer.parseInt(strPort);
|
||||
}
|
||||
|
||||
// TODO: we need to capture username/password for the remote server at some
|
||||
// point, for now we use the configured username/password for all servers
|
||||
|
||||
// call the appropriate method to deploy
|
||||
if (fileServerDeployment)
|
||||
{
|
||||
// remove the prefixed \\
|
||||
host = host.substring(FILE_SERVER_PREFIX.length());
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Performing file server deployment to " + host + ":" + port);
|
||||
|
||||
// TODO Added new NameMatcher parameter to deploy methods. It acts as a filter.
|
||||
// Any matching path names are ignored for deployment purposes.
|
||||
// TODO: Added new NameMatcher parameter to deploy methods. It acts as a filter.
|
||||
// Any matching path names are ignored for deployment purposes.
|
||||
report = this.deployService.deployDifferenceFS(version, path, host, port,
|
||||
remoteUsername, remotePassword, "default", null, true, false, false, callback);
|
||||
remoteUsername, remotePassword, targetName, null, true, false, false, callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Performing Alfresco deployment to " + host + ":" + port);
|
||||
|
||||
// TODO Added new NameMatcher parameter to deploy methods. It acts as a filter.
|
||||
// Any matching path names are ignored for deployment purposes.
|
||||
// TODO: Added new NameMatcher parameter to deploy methods. It acts as a filter.
|
||||
// Any matching path names are ignored for deployment purposes.
|
||||
report = this.deployService.deployDifference(version, path, host, port,
|
||||
remoteUsername, remotePassword, targetPath, null, true, false, false, callback);
|
||||
}
|
||||
@@ -279,16 +382,17 @@ public class AVMDeploySnapshotAction extends ActionExecuterAbstractBase
|
||||
if (report != null)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Differences successfully applied to " + targetServer);
|
||||
logger.debug("Differences successfully applied to " + serverUri);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Failed to apply differences to " + targetServer);
|
||||
logger.debug("Failed to apply differences to " + serverUri);
|
||||
}
|
||||
|
||||
// create the deployment report node
|
||||
createDeploymentReportNode(report, targetServer, version, websiteRef, startDate, deployError);
|
||||
createDeploymentReportNode(report, attemptRef, serverProps, version,
|
||||
websiteRef, startDate, deployError);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -296,7 +400,8 @@ public class AVMDeploySnapshotAction extends ActionExecuterAbstractBase
|
||||
*
|
||||
* @param report The DeploymentReport result from the deploy,
|
||||
* will be null if the deploy failed
|
||||
* @param targetServer The server the deploy was going to
|
||||
* @param attempt NodeRef of the attempt the deploy was part of
|
||||
* @param serverProps The properties of the server the deploy was going to
|
||||
* @param version The version of the site bebing deployed (the snapshot)
|
||||
* @param websiteRef The NodeRef of the folder representing the website
|
||||
* @param startDate The date/time the deployment started
|
||||
@@ -304,30 +409,38 @@ public class AVMDeploySnapshotAction extends ActionExecuterAbstractBase
|
||||
* deployment was successful
|
||||
* @return The created deployment report NodeRef
|
||||
*/
|
||||
private NodeRef createDeploymentReportNode(DeploymentReport report, String targetServer,
|
||||
int version, NodeRef websiteRef, Date startDate, Throwable error)
|
||||
private NodeRef createDeploymentReportNode(DeploymentReport report, NodeRef attempt,
|
||||
Map<QName, Serializable> serverProps, int version, NodeRef websiteRef,
|
||||
Date startDate, Throwable error)
|
||||
{
|
||||
NodeRef reportRef = null;
|
||||
|
||||
// remove illegal chars from the target server name to create the report name
|
||||
String reportName = targetServer.replace(':', '_').replace('\\', '_') +
|
||||
" deployment report.txt";
|
||||
String serverUri = calculateServerUri(serverProps);
|
||||
Map<QName, Serializable> reportProps = new HashMap<QName, Serializable>(4, 1.0f);
|
||||
reportProps.put(WCMAppModel.PROP_DEPLOYSERVER, serverUri);
|
||||
reportProps.put(WCMAppModel.PROP_DEPLOYVERSION, version);
|
||||
reportProps.put(WCMAppModel.PROP_DEPLOYSTARTTIME, startDate);
|
||||
reportProps.put(WCMAppModel.PROP_DEPLOYENDTIME, new Date());
|
||||
reportProps.put(WCMAppModel.PROP_DEPLOYSERVERNAMEUSED,
|
||||
serverProps.get(WCMAppModel.PROP_DEPLOYSERVERNAME));
|
||||
reportProps.put(WCMAppModel.PROP_DEPLOYSERVERUSERNAMEUSED,
|
||||
serverProps.get(WCMAppModel.PROP_DEPLOYSERVERUSERNAME));
|
||||
reportProps.put(WCMAppModel.PROP_DEPLOYSERVERTARGETUSED,
|
||||
serverProps.get(WCMAppModel.PROP_DEPLOYSERVERTARGET));
|
||||
reportProps.put(WCMAppModel.PROP_DEPLOYSOURCEPATHUSED,
|
||||
serverProps.get(WCMAppModel.PROP_DEPLOYSOURCEPATH));
|
||||
reportProps.put(WCMAppModel.PROP_DEPLOYSERVERURLUSED,
|
||||
serverProps.get(WCMAppModel.PROP_DEPLOYSERVERURL));
|
||||
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(4, 1.0f);
|
||||
props.put(ContentModel.PROP_NAME, reportName);
|
||||
props.put(WCMAppModel.PROP_DEPLOYSERVER, targetServer);
|
||||
props.put(WCMAppModel.PROP_DEPLOYVERSION, version);
|
||||
props.put(WCMAppModel.PROP_DEPLOYSTARTTIME, startDate);
|
||||
props.put(WCMAppModel.PROP_DEPLOYENDTIME, new Date());
|
||||
props.put(WCMAppModel.PROP_DEPLOYSUCCESSFUL, (report != null));
|
||||
reportProps.put(WCMAppModel.PROP_DEPLOYSUCCESSFUL, (report != null));
|
||||
if (report == null && error != null)
|
||||
{
|
||||
// add error message as fail reason if appropriate
|
||||
props.put(WCMAppModel.PROP_DEPLOYFAILEDREASON, error.getMessage());
|
||||
reportProps.put(WCMAppModel.PROP_DEPLOYFAILEDREASON, error.getMessage());
|
||||
}
|
||||
reportRef = this.nodeService.createNode(websiteRef,
|
||||
WCMAppModel.ASSOC_DEPLOYMENTREPORT, WCMAppModel.ASSOC_DEPLOYMENTREPORT,
|
||||
WCMAppModel.TYPE_DEPLOYMENTREPORT, props).getChildRef();
|
||||
reportRef = this.nodeService.createNode(attempt,
|
||||
WCMAppModel.ASSOC_DEPLOYMENTREPORTS, WCMAppModel.ASSOC_DEPLOYMENTREPORT,
|
||||
WCMAppModel.TYPE_DEPLOYMENTREPORT, reportProps).getChildRef();
|
||||
ContentWriter writer = contentService.getWriter(reportRef, ContentModel.PROP_CONTENT, true);
|
||||
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
writer.setEncoding("UTF-8");
|
||||
@@ -363,8 +476,8 @@ public class AVMDeploySnapshotAction extends ActionExecuterAbstractBase
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Created deplyoment report node (" + reportRef + ") for targetServer " +
|
||||
targetServer);
|
||||
logger.debug("Created deplyoment report node (" + reportRef + ") for server " +
|
||||
serverUri);
|
||||
|
||||
return reportRef;
|
||||
}
|
||||
|
Reference in New Issue
Block a user