ALF-2025: where noderefs are cached in the transfer service (both transmitter and receiver) have made them multi-tenant aware.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19631 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Brian Remmington
2010-03-29 11:12:04 +00:00
parent 280c41ae60
commit aa056f0268
5 changed files with 76 additions and 56 deletions

View File

@@ -16,6 +16,9 @@
<property name="transactionService">
<ref bean="TransactionService" />
</property>
<property name="tenantService">
<ref bean="tenantService" />
</property>
<property name="transferSpaceQuery">
<value>/${spaces.company_home.childname}/${spaces.dictionary.childname}/${spaces.transfers.childname}/${spaces.transfer_groups.childname}</value>
</property>
@@ -54,6 +57,7 @@
<property name="searchService" ref="SearchService" />
<property name="transactionService" ref="TransactionService" />
<property name="actionService" ref="ActionService" />
<property name="tenantService" ref="tenantService" />
<property name="transferLockFolderPath">
<value>/${spaces.company_home.childname}/${spaces.dictionary.childname}/${spaces.transfers.childname}</value>

View File

@@ -29,6 +29,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
@@ -37,6 +38,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
@@ -59,9 +61,9 @@ import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.PropertyCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.alfresco.util.PropertyCheck;
import org.springframework.util.FileCopyUtils;
/**
@@ -139,10 +141,11 @@ public class RepoTransferReceiverImpl implements TransferReceiver
private BehaviourFilter behaviourFilter;
private TransferProgressMonitor progressMonitor;
private ActionService actionService;
private TenantService tenantService;
private NodeRef transferLockFolder;
private NodeRef transferTempFolder;
private NodeRef inboundTransferRecordsFolder;
private Map<String,NodeRef> transferLockFolderMap = new ConcurrentHashMap<String, NodeRef>();
private Map<String,NodeRef> transferTempFolderMap = new ConcurrentHashMap<String, NodeRef>();
private Map<String,NodeRef> inboundTransferRecordsFolderMap = new ConcurrentHashMap<String, NodeRef>();
public void init()
{
@@ -185,26 +188,23 @@ public class RepoTransferReceiverImpl implements TransferReceiver
private NodeRef getLockFolder()
{
String tenantDomain = tenantService.getUserDomain(AuthenticationUtil.getRunAsUser());
NodeRef transferLockFolder = transferLockFolderMap.get(tenantDomain);
// Have we already resolved the node that is the parent of the lock node?
// If not then do so.
if (transferLockFolder == null)
{
synchronized (this)
{
if (transferLockFolder == null)
{
ResultSet rs = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
SearchService.LANGUAGE_XPATH, transferLockFolderPath);
ResultSet rs = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH,
transferLockFolderPath);
if (rs.length() > 0)
{
transferLockFolder = rs.getNodeRef(0);
transferLockFolderMap.put(tenantDomain, transferLockFolder);
}
else
{
throw new TransferException(MSG_TRANSFER_LOCK_FOLDER_NOT_FOUND,
new Object[] { transferLockFolderPath });
}
}
throw new TransferException(MSG_TRANSFER_LOCK_FOLDER_NOT_FOUND, new Object[] { transferLockFolderPath });
}
}
return transferLockFolder;
@@ -213,19 +213,19 @@ public class RepoTransferReceiverImpl implements TransferReceiver
public NodeRef getTempFolder(String transferId)
{
String tenantDomain = tenantService.getUserDomain(AuthenticationUtil.getRunAsUser());
NodeRef transferTempFolder = transferTempFolderMap.get(tenantDomain);
// Have we already resolved the node that is the temp folder?
// If not then do so.
if (transferTempFolder == null)
{
synchronized (this)
{
if (transferTempFolder == null)
{
ResultSet rs = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
SearchService.LANGUAGE_XPATH, transferTempFolderPath);
ResultSet rs = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH,
transferTempFolderPath);
if (rs.length() > 0)
{
transferTempFolder = rs.getNodeRef(0);
transferTempFolderMap.put(tenantDomain, transferTempFolder);
}
else
{
@@ -233,8 +233,6 @@ public class RepoTransferReceiverImpl implements TransferReceiver
transferTempFolderPath });
}
}
}
}
NodeRef transferNodeRef = new NodeRef(transferId);
String tempTransferFolderName = transferNodeRef.getId();
@@ -319,19 +317,18 @@ public class RepoTransferReceiverImpl implements TransferReceiver
*/
private NodeRef createTransferRecord()
{
log.debug("->createTransferRecord");
if (inboundTransferRecordsFolder == null)
{
synchronized (this)
{
String tenantDomain = tenantService.getUserDomain(AuthenticationUtil.getRunAsUser());
NodeRef inboundTransferRecordsFolder = inboundTransferRecordsFolderMap.get(tenantDomain);
if (inboundTransferRecordsFolder == null)
{
log.debug("Trying to find transfer records folder: " + inboundTransferRecordsPath);
ResultSet rs = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
SearchService.LANGUAGE_XPATH, inboundTransferRecordsPath);
ResultSet rs = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH,
inboundTransferRecordsPath);
if (rs.length() > 0)
{
inboundTransferRecordsFolder = rs.getNodeRef(0);
inboundTransferRecordsFolderMap.put(tenantDomain, inboundTransferRecordsFolder);
log.debug("Found inbound transfer records folder: " + inboundTransferRecordsFolder);
}
else
@@ -340,8 +337,7 @@ public class RepoTransferReceiverImpl implements TransferReceiver
new Object[] { inboundTransferRecordsPath });
}
}
}
}
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSSZ");
String timeNow = format.format(new Date());
QName recordName = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, timeNow);
@@ -720,6 +716,11 @@ public class RepoTransferReceiverImpl implements TransferReceiver
this.transactionService = transactionService;
}
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
/**
* @param transferLockFolderPath
* the transferLockFolderPath to set

View File

@@ -34,6 +34,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import javax.transaction.UserTransaction;
import javax.xml.parsers.SAXParser;
@@ -41,6 +43,8 @@ import javax.xml.parsers.SAXParserFactory;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transfer.manifest.TransferManifestDeletedNode;
import org.alfresco.repo.transfer.manifest.TransferManifestHeader;
@@ -91,7 +95,7 @@ public class TransferServiceImpl implements TransferService
/**
* The synchronised list of transfers in progress.
*/
private Map<String, TransferStatus> transferMonitoring = Collections.synchronizedMap(new HashMap<String,TransferStatus>());
private Map<String, TransferStatus> transferMonitoring = Collections.synchronizedMap(new TreeMap<String,TransferStatus>());
private static Log logger = LogFactory.getLog(TransferServiceImpl.class);
@@ -116,6 +120,7 @@ public class TransferServiceImpl implements TransferService
private ActionService actionService;
private TransferManifestNodeFactory transferManifestNodeFactory;
private TransferReporter transferReporter;
private TenantService tenantService;
/**
* How long to delay while polling for commit status.
@@ -861,6 +866,11 @@ public class TransferServiceImpl implements TransferService
return searchService;
}
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
public void setTransferSpaceQuery(String transferSpaceQuery)
{
this.transferSpaceQuery = transferSpaceQuery;
@@ -891,9 +901,11 @@ public class TransferServiceImpl implements TransferService
this.transmitter = transmitter;
}
private NodeRef transferHome;
private Map<String,NodeRef> transferHomeMap = new ConcurrentHashMap<String, NodeRef>();
protected NodeRef getTransferHome()
{
String tenantDomain = tenantService.getUserDomain(AuthenticationUtil.getRunAsUser());
NodeRef transferHome = transferHomeMap.get(tenantDomain);
if(transferHome == null)
{
String query = transferSpaceQuery;
@@ -909,6 +921,7 @@ public class TransferServiceImpl implements TransferService
if (result.getNodeRefs().size() != 0)
{
transferHome = result.getNodeRef(0);
transferHomeMap.put(tenantDomain, transferHome);
}
}
return transferHome;

View File

@@ -34,7 +34,7 @@ public class TransferTargetImpl implements TransferTarget
private String endpointProtocol;
private String endpointHost;
private int endpointPort;
private String endpointPath;
private String endpointPath = "/alfresco/service/api/transfer";
private String username;
private char[] password;
private boolean enabled;

View File

@@ -124,12 +124,14 @@ public interface TransferTarget
/**
* The location of the transfer service on the target endpoint host
* Defaults to "/alfresco/service/api/transfer", and this shouldn't typically need to change
* @return
*/
String getEndpointPath();
/**
* The location of the transfer service on the target endpoint host
* Defaults to "/alfresco/service/api/transfer", and this shouldn't typically need to change
*/
void setEndpointPath(String path);