mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Replication - record target transfer report in replication definition
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21880 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -44,6 +44,7 @@ import org.alfresco.service.cmr.transfer.TransferDefinition;
|
|||||||
import org.alfresco.service.cmr.transfer.TransferEvent;
|
import org.alfresco.service.cmr.transfer.TransferEvent;
|
||||||
import org.alfresco.service.cmr.transfer.TransferEventBegin;
|
import org.alfresco.service.cmr.transfer.TransferEventBegin;
|
||||||
import org.alfresco.service.cmr.transfer.TransferEventEnterState;
|
import org.alfresco.service.cmr.transfer.TransferEventEnterState;
|
||||||
|
import org.alfresco.service.cmr.transfer.TransferEventReport;
|
||||||
import org.alfresco.service.cmr.transfer.TransferService;
|
import org.alfresco.service.cmr.transfer.TransferService;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@@ -182,8 +183,9 @@ public class ReplicationActionExecutor extends ActionExecuterAbstractBase {
|
|||||||
throw new ReplicationServiceException("Unable to execute a disabled replication definition");
|
throw new ReplicationServiceException("Unable to execute a disabled replication definition");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the previous transfer report reference
|
// Clear the previous transfer report references
|
||||||
replicationDef.setLocalTransferReport(null);
|
replicationDef.setLocalTransferReport(null);
|
||||||
|
replicationDef.setRemoteTransferReport(null);
|
||||||
|
|
||||||
// Lock the service - only one instance of the replication
|
// Lock the service - only one instance of the replication
|
||||||
// should occur at a time
|
// should occur at a time
|
||||||
@@ -199,6 +201,9 @@ public class ReplicationActionExecutor extends ActionExecuterAbstractBase {
|
|||||||
lock.close();
|
lock.close();
|
||||||
throw new ReplicationServiceException("Error processing payload list - " + e.getMessage(), e);
|
throw new ReplicationServiceException("Error processing payload list - " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Holder for reports generated by the transfer
|
||||||
|
ReplicationReportCollector reports = new ReplicationReportCollector();
|
||||||
|
|
||||||
// Ask the transfer service to do the replication
|
// Ask the transfer service to do the replication
|
||||||
// work for us
|
// work for us
|
||||||
@@ -208,14 +213,15 @@ public class ReplicationActionExecutor extends ActionExecuterAbstractBase {
|
|||||||
buildTransferDefinition(replicationDef, toTransfer);
|
buildTransferDefinition(replicationDef, toTransfer);
|
||||||
|
|
||||||
// Off we go
|
// Off we go
|
||||||
NodeRef transferReport = transferService.transfer(
|
transferService.transfer(
|
||||||
replicationDef.getTargetName(),
|
replicationDef.getTargetName(),
|
||||||
transferDefinition,
|
transferDefinition,
|
||||||
lock
|
lock, reports
|
||||||
);
|
);
|
||||||
|
|
||||||
// Record the details of the transfer report
|
// Record the details of the transfer reports
|
||||||
replicationDef.setLocalTransferReport(transferReport);
|
replicationDef.setLocalTransferReport(reports.getLocalReport());
|
||||||
|
replicationDef.setRemoteTransferReport(reports.getRemoteReport());
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
if(! (e instanceof TransferCancelledException))
|
if(! (e instanceof TransferCancelledException))
|
||||||
{
|
{
|
||||||
@@ -341,4 +347,53 @@ public class ReplicationActionExecutor extends ActionExecuterAbstractBase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link TransferCallback} which collects the various reports generated by
|
||||||
|
* the transfer.
|
||||||
|
*/
|
||||||
|
protected class ReplicationReportCollector implements TransferCallback
|
||||||
|
{
|
||||||
|
private NodeRef localReport;
|
||||||
|
private NodeRef remoteReport;
|
||||||
|
|
||||||
|
protected ReplicationReportCollector()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collect source and destination repository target reports
|
||||||
|
*/
|
||||||
|
public void processEvent(TransferEvent event)
|
||||||
|
{
|
||||||
|
if(event instanceof TransferEventReport)
|
||||||
|
{
|
||||||
|
TransferEventReport reportEvent = (TransferEventReport)event;
|
||||||
|
if (reportEvent.getReportType().equals(TransferEventReport.ReportType.SOURCE))
|
||||||
|
{
|
||||||
|
localReport = reportEvent.getNodeRef();
|
||||||
|
}
|
||||||
|
else if (reportEvent.getReportType().equals(TransferEventReport.ReportType.DESTINATION))
|
||||||
|
{
|
||||||
|
remoteReport = reportEvent.getNodeRef();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return local transfer report
|
||||||
|
*/
|
||||||
|
public NodeRef getLocalReport()
|
||||||
|
{
|
||||||
|
return localReport;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return target transfer report
|
||||||
|
*/
|
||||||
|
public NodeRef getRemoteReport()
|
||||||
|
{
|
||||||
|
return remoteReport;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -65,6 +65,7 @@ public class ReplicationServiceImplTest extends TestCase
|
|||||||
assertEquals(0, replicationAction.getPayload().size());
|
assertEquals(0, replicationAction.getPayload().size());
|
||||||
|
|
||||||
assertNull(replicationAction.getLocalTransferReport());
|
assertNull(replicationAction.getLocalTransferReport());
|
||||||
|
assertNull(replicationAction.getRemoteTransferReport());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -207,6 +207,7 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
|||||||
assertEquals(0, replicationAction.getPayload().size());
|
assertEquals(0, replicationAction.getPayload().size());
|
||||||
|
|
||||||
assertNull(replicationAction.getLocalTransferReport());
|
assertNull(replicationAction.getLocalTransferReport());
|
||||||
|
assertNull(replicationAction.getRemoteTransferReport());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateSaveLoad() throws Exception
|
public void testCreateSaveLoad() throws Exception
|
||||||
@@ -672,6 +673,7 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
|||||||
rd.getPayload().add(folder2a);
|
rd.getPayload().add(folder2a);
|
||||||
|
|
||||||
assertEquals(null, rd.getLocalTransferReport());
|
assertEquals(null, rd.getLocalTransferReport());
|
||||||
|
assertEquals(null, rd.getRemoteTransferReport());
|
||||||
|
|
||||||
txn = transactionService.getUserTransaction();
|
txn = transactionService.getUserTransaction();
|
||||||
txn.begin();
|
txn.begin();
|
||||||
@@ -744,20 +746,30 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check we got a transfer report, and it looks sensible
|
// Check we got transfer reports, and they look sensible
|
||||||
NodeRef transferReport = rd.getLocalTransferReport();
|
NodeRef localReport = rd.getLocalTransferReport();
|
||||||
assertNotNull(transferReport);
|
assertNotNull(localReport);
|
||||||
|
NodeRef remoteReport = rd.getRemoteTransferReport();
|
||||||
|
assertNotNull(remoteReport);
|
||||||
|
|
||||||
txn = transactionService.getUserTransaction();
|
txn = transactionService.getUserTransaction();
|
||||||
txn.begin();
|
txn.begin();
|
||||||
|
|
||||||
ContentReader transferReader =
|
ContentReader localReader =
|
||||||
contentService.getReader(transferReport, ContentModel.PROP_CONTENT);
|
contentService.getReader(localReport, ContentModel.PROP_CONTENT);
|
||||||
String report = transferReader.getContentString();
|
String localReportContent = localReader.getContentString();
|
||||||
|
|
||||||
assertTrue("XML not found in:\n" + report, report.contains("<?xml"));
|
assertTrue("XML not found in:\n" + localReportContent, localReportContent.contains("<?xml"));
|
||||||
assertTrue("Report XML not found in:\n" + report, report.contains("<report:transferReport"));
|
assertTrue("Report XML not found in:\n" + localReportContent, localReportContent.contains("<report:transferReport"));
|
||||||
|
|
||||||
|
ContentReader remoteReader =
|
||||||
|
contentService.getReader(remoteReport, ContentModel.PROP_CONTENT);
|
||||||
|
String remoteReportContent = remoteReader.getContentString();
|
||||||
|
|
||||||
|
// TODO: update these tests when transfer report is converted to XML
|
||||||
|
assertFalse("XML found in:\n" + remoteReportContent, remoteReportContent.contains("<?xml"));
|
||||||
|
assertTrue("Report Status not found in:\n" + remoteReportContent, remoteReportContent.contains("Status update: COMPLETE"));
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user