use of org.alfresco.service.cmr.transfer.TransferDefinition in project alfresco-repository by Alfresco.
the class TransferServiceCallbackTest method testTargetAlreadyLocked.
public void testTargetAlreadyLocked() {
configureBasicMockTransmitter(null);
when(mockedTransferTransmitter.begin(target, "localRepositoryId", version)).thenThrow(new TransferException("Simulate lock unavailable"));
TransferDefinition transferDef = new TransferDefinition();
transferDef.setNodes(folder1, file1, file2, file3);
try {
transferService.transfer(TRANSFER_TARGET_NAME, transferDef, mockedCallback);
fail("Transfer expected to throw an exception, but it didn't.");
} catch (TransferFailureException ex) {
List<TransferEvent> expectedEvents = new ArrayList<TransferEvent>();
TransferEventImpl event;
event = new TransferEventEnterState();
event.setTransferState(TransferState.START);
expectedEvents.add(event);
event = new TransferEventEndState();
event.setTransferState(TransferState.START);
expectedEvents.add(event);
event = new TransferEventEnterState();
event.setTransferState(TransferState.ERROR);
expectedEvents.add(event);
event = new TransferEventReport();
event.setTransferState(TransferState.ERROR);
expectedEvents.add(event);
event = new TransferEventError();
event.setTransferState(TransferState.ERROR);
((TransferEventError) event).setException((Exception) ex.getCause());
expectedEvents.add(event);
verifyCallback(expectedEvents);
}
}
use of org.alfresco.service.cmr.transfer.TransferDefinition in project alfresco-repository by Alfresco.
the class ReplicationActionExecutor method buildTransferDefinition.
/**
* Takes a {@link ReplicationDefinition} and a list of
* {@link NodeRef}s, and returns the
* {@link TransferDefinition} which will allow the
* replication to be run.
*/
protected TransferDefinition buildTransferDefinition(ReplicationDefinition replicationDef, Set<NodeRef> toTransfer) {
TransferDefinition transferDefinition = new TransferDefinition();
transferDefinition.setNodes(toTransfer);
transferDefinition.setSync(true);
transferDefinition.setReadOnly(replicationParams.getTransferReadOnly());
// Exclude aspects from transfer
// NOTE: this list of aspects should be synced up with the NodeCrawler in expandPayload to
// ensure a coherent set of nodes are transferred
transferDefinition.setExcludedAspects(excludedAspects);
return transferDefinition;
}
use of org.alfresco.service.cmr.transfer.TransferDefinition in project alfresco-repository by Alfresco.
the class ReplicationActionExecutor method executeImpl.
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
if (action instanceof ReplicationDefinition) {
// Already of the correct type
} else if (action.getActionDefinitionName().equals(ReplicationDefinitionImpl.EXECUTOR_NAME)) {
// Specialise the action if needed, eg when loaded directly from
// the NodeRef without going via the replication service
action = new ReplicationDefinitionImpl(action);
}
// Off we go
final ReplicationDefinition replicationDef = (ReplicationDefinition) action;
if (replicationDef.getTargetName() == null || replicationDef.getTargetName().equals("")) {
throw new ReplicationServiceException(I18NUtil.getMessage(MSG_ERR_TARGET_NOT_GIVEN));
}
if (replicationDef.getPayload().size() == 0) {
throw new ReplicationServiceException(I18NUtil.getMessage(MSG_ERR_NO_PAYLOADS_SPECIFIED));
}
if (!replicationDef.isEnabled()) {
throw new DisabledReplicationJobException(I18NUtil.getMessage(MSG_ERR_REPLICATION_DEF_DISABLED));
}
if (!replicationParams.isEnabled()) {
throw new ReplicationServiceException(I18NUtil.getMessage(MSG_ERR_UNABLE_TO_REPLICATE));
}
// Lock the service - only one instance of the replication
// should occur at a time
ReplicationDefinitionLockExtender lock = new ReplicationDefinitionLockExtender(replicationDef);
// Turn our payload list of root nodes into something that
// the transfer service can work with
Set<NodeRef> toTransfer;
try {
toTransfer = expandPayload(replicationDef);
} catch (Exception e) {
lock.close();
throw new ReplicationServiceException(I18NUtil.getMessage(MSG_ERR_PROCESSING_PAYLOAD, e.getMessage()), e);
}
// Ask the transfer service to do the replication
// work for us
TransferEndEvent endEvent = null;
try {
// Build the definition
TransferDefinition transferDefinition = buildTransferDefinition(replicationDef, toTransfer);
// Off we go
endEvent = transferService.transfer(replicationDef.getTargetName(), transferDefinition, lock);
if (endEvent instanceof TransferEventCancelled) {
if (logger.isDebugEnabled())
logger.debug("Cancelling replication job");
// that this is correctly recorded
throw new ActionCancelledException(replicationDef);
}
// Record details of the transfer reports (in success case)
replicationDef.setLocalTransferReport(endEvent.getSourceReport());
replicationDef.setRemoteTransferReport(endEvent.getDestinationReport());
replicationDefinitionPersister.saveReplicationDefinition(replicationDef);
} catch (Exception e) {
if (e instanceof ActionCancelledException) {
writeDefinitionReports(replicationDef, endEvent.getSourceReport(), endEvent.getDestinationReport());
throw (ActionCancelledException) e;
}
if (e instanceof TransferFailureException) {
TransferEventError failureEndEvent = ((TransferFailureException) e).getErrorEvent();
writeDefinitionReports(replicationDef, failureEndEvent.getSourceReport(), failureEndEvent.getDestinationReport());
Throwable cause = (e.getCause() == null) ? e : e.getCause();
throw new ReplicationServiceException(I18NUtil.getMessage(MSG_ERR_EXECUTING_TRANSFER, cause.getMessage()), cause);
}
writeDefinitionReports(replicationDef, null, null);
throw new ReplicationServiceException(I18NUtil.getMessage(MSG_ERR_EXECUTING_TRANSFER, e.getMessage()), e);
} finally {
lock.close();
}
}
use of org.alfresco.service.cmr.transfer.TransferDefinition in project alfresco-repository by Alfresco.
the class TransferOneNodeActionExecuter method executeImpl.
/* (non-Javadoc)
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
TransferTarget target = TransferTestUtil.getTestTarget(transferService);
TransferDefinition td = new TransferDefinition();
td.setNodes(actionedUponNodeRef);
transferService.transfer(target.getName(), td);
}
use of org.alfresco.service.cmr.transfer.TransferDefinition in project alfresco-repository by Alfresco.
the class TransferTreeActionExecuter method executeImpl.
/* (non-Javadoc)
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
TransferTarget target = TransferTestUtil.getTestTarget(transferService);
NodeCrawler crawler = new StandardNodeCrawlerImpl(serviceRegistry);
crawler.setNodeFinders(new ChildAssociatedNodeFinder(ContentModel.ASSOC_CONTAINS));
Set<NodeRef> nodes = crawler.crawl(actionedUponNodeRef);
TransferDefinition td = new TransferDefinition();
td.setNodes(nodes);
transferService.transfer(target.getName(), td);
}
Aggregations