[
https://jira.jboss.org/jira/browse/JBAS-6879?page=com.atlassian.jira.plug...
]
sachin mishra commented on JBAS-6879:
-------------------------------------
Hi Brian,
Yes, its similar to the discussion we had on the forum. Here is the complete java code
that i wrote to fix this issue for my cluster. I will be using this in the production
system soon so if you see anything that looks incorrect please let me know.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package xxx;
import java.io.File;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.log4j.Logger;
import org.jboss.ha.framework.interfaces.HAPartition;
import org.jboss.ha.framework.server.ClusterFileTransfer;
import org.jboss.ha.framework.server.ClusterFileTransfer.ClusterFileTransferException;
import org.jboss.ha.framework.server.FarmMemberService;
import org.jboss.system.ServiceMBean;
public class ClusterMemberService extends FarmMemberService {
private Logger logger = Logger.getLogger(getClass());
private ClusterFileTransfer mFileTransfer;
private boolean doInit = true;
@Override
protected void pullNewDeployments(HAPartition partition, HashMap farmed) {
if (ServiceMBean.STARTING == getState()) {
if (doInit) {
init();
doInit = false;
}
} else {
logger.info("using pullNewDeployments on FarmMemberService as we are not
in starting state... ");
super.pullNewDeployments(partition, farmed);
return;
}
Iterator it = farmed.keySet().iterator();
String parentName = null;
File destFile = null;
while (it.hasNext()) {
String depName = (String) it.next();
Date last = (Date) farmed.get(depName);
DeployedURL du = (DeployedURL) parentDUMap.get(depName);
int indexofParentName = depName.indexOf('/');
parentName = depName.substring(0, indexofParentName);
String child = depName.substring(indexofParentName + 1, depName.length());
File parentFolder = findParent(parentName);
if (parentFolder == null) {
IllegalStateException stateException = new
IllegalStateException("Can't find the farmed folder " + parentName);
logger.error(stateException, stateException);
throw stateException;
}
destFile = new File(parentFolder, child);
Date localDeployedDate = new Date(destFile.lastModified());
logger.info("parentname=" + parentName + " destfile= " +
destFile.getAbsolutePath() + " isexist=" + destFile.exists() + " local mode
date=" + localDeployedDate + " remote deploy date=" + last);
if (destFile.exists() && !localDeployedDate.before(last)) {
logger.info(" no need to pull " + depName + " from remote
server as the timestamps are same");
} else {
logger.info(" going to pull " + depName + " from remote
server.....");
pullRemoteFile(new File(depName), parentName);
}
}
}
private void init() {
try {
HAPartition lHAPartition = null;
if (mClusterPartition != null) {
lHAPartition = mClusterPartition.getHAPartition();
}
if (lHAPartition == null) {
// Old style config with PartitionName was used -- have to
// look up the partition in JMX
lHAPartition = (HAPartition) getServer().getAttribute(
mClusterPartitionName,
"HAPartition");
}
mFileTransfer = new ClusterFileTransfer(lHAPartition,
buildParentFolderMapping());
logger.info("Created mFileTransfer successfully");
} catch (Exception e) {
logger.error("Error Starting ClusterMemberService ", e);
}
}
private void pullRemoteFile(File destFile, String parentName) {
try {
mFileTransfer.pull(destFile, parentName);
synchronized (remotelyDeployed) {
remotelyDeployed.add(destFile.getName());
}
} catch (ClusterFileTransferException e) {
// log the exception and continue with the next deployment
log.error(e, e);
}
}
// return mapping of Farming folder names to the File
private Map buildParentFolderMapping() {
Map map = new HashMap();
URL[] urls = (URL[]) urlList.toArray(new URL[]{});
for (int i = 0; i < urlList.size(); i++) {
if (urls[i].getProtocol().equals("file")) {
File file = new File(urls[i].getFile());
if (file.isDirectory()) {
map.put(file.getName(), file);
}
}
}
return map;
}
}
pullNewDeployments in FarmMemberService is buggy
------------------------------------------------
Key: JBAS-6879
URL:
https://jira.jboss.org/jira/browse/JBAS-6879
Project: JBoss Application Server
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: Clustering
Affects Versions: JBossAS-4.0.0 Final, JBossAS-4.0.1 Final, JBossAS-4.0.1 SP1,
JBossAS-4.0.2 Final, JBossAS-4.0.3 Final, JBossAS-4.0.3 SP1, JBossAS-4.0.4.GA,
JBossAS-4.0.5.GA, JBossAS-4.2.0.GA, JBossAS-4.2.1.GA, JBossAS-4.2.2.GA, JBossAS-4.2.3.GA
Environment: jboss 4.2.2 onwards
Reporter: sachin mishra
Assignee: Brian Stansberry
Fix For: JBossAS-Branch_4_2
pullNewDeployments method in FarmMemberService is not working correctly during startup
where there are more than 1 nodes in the cluster. Currently newly started cluster will
always pull the files from the coordinator node as the call to DeployedURL du =
(DeployedURL)parentDUMap.get(depName); will always return null on startup.
Steps to reproduce:
1. create 2 or more nodes in 1 cluster
2. deploy app Test.war in the cluster
3. restart 1 of the nodes and you will see that this node is pulling the Test.war.
Test.war hasn't changed therefore no need to pull it.
This is currently causing a lot of issues in our server as we have lots of apps ( over
100) deployed and are quite big in size , therefore pull all the files at startup causes
the server to become available after a very long time.
Possible Fix;
@Override
protected void pullNewDeployments(HAPartition partition, HashMap farmed)
{
if(ServiceMBean.STARTING == getState()){
if(doInit){
init();
doInit = false;
}
}else{
logger.info("using pullNewDeployments on FarmMemberService as we are not
in starting state... " );
super.pullNewDeployments(partition, farmed);
return;
}
Iterator it = farmed.keySet().iterator();
String parentName= null;
File destFile = null;
while (it.hasNext())
{
String depName = (String)it.next();
Date last = (Date)farmed.get(depName);
DeployedURL du = (DeployedURL)parentDUMap.get(depName);
int indexofParentName = depName.indexOf('/');
parentName= depName.substring(0, indexofParentName);
String child = depName.substring(indexofParentName+1, depName.length());
File parentFolder = findParent(parentName);
if(parentFolder == null){
IllegalStateException stateException = new
IllegalStateException("Can't find the farmed folder " + parentName);
logger.error(stateException,stateException);
throw stateException;
}
destFile = new File(parentFolder,child);
Date localDeployedDate = new Date(destFile.lastModified());
logger.info("parentname=" + parentName + " destfile= "
+destFile.getAbsolutePath() + " isexist=" + destFile.exists() + " local
mode date=" + localDeployedDate + " remote deploy date=" + last);
if(destFile.exists() && !localDeployedDate.before(last)){
logger.info(" no need to pull " + depName + " from remote
server as the timestamps are same");
}else{
logger.info(" going to pull " +depName + " from remote
server.....");
pullRemoteFile(new File(depName), parentName);
}
}
}
private void init() {
try{
HAPartition lHAPartition = null;
if (mClusterPartition != null)
{
lHAPartition = mClusterPartition.getHAPartition();
}
if (lHAPartition == null)
{
// Old style config with PartitionName was used -- have to
// look up the partition in JMX
lHAPartition = (HAPartition) getServer().getAttribute(
mClusterPartitionName,
"HAPartition"
);
}
mFileTransfer = new ClusterFileTransfer(lHAPartition,
buildParentFolderMapping());
logger.warn("Created mFileTransfer successfully");
}catch(Exception e){
logger.error("Error Starting ClusterMemberService ",e);
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira