Search in sources :

Example 21 with TransferDefinition

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);
    }
}
Also used : TransferDefinition(org.alfresco.service.cmr.transfer.TransferDefinition) TransferException(org.alfresco.service.cmr.transfer.TransferException) TransferEventEnterState(org.alfresco.service.cmr.transfer.TransferEventEnterState) TransferEvent(org.alfresco.service.cmr.transfer.TransferEvent) List(java.util.List) ArrayList(java.util.ArrayList) TransferEventReport(org.alfresco.service.cmr.transfer.TransferEventReport) TransferEventError(org.alfresco.service.cmr.transfer.TransferEventError) TransferEventEndState(org.alfresco.service.cmr.transfer.TransferEventEndState) TransferFailureException(org.alfresco.service.cmr.transfer.TransferFailureException) TransferException(org.alfresco.service.cmr.transfer.TransferException) TransferFailureException(org.alfresco.service.cmr.transfer.TransferFailureException)

Example 22 with TransferDefinition

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;
}
Also used : TransferDefinition(org.alfresco.service.cmr.transfer.TransferDefinition)

Example 23 with 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();
    }
}
Also used : ReplicationServiceException(org.alfresco.service.cmr.replication.ReplicationServiceException) TransferEndEvent(org.alfresco.service.cmr.transfer.TransferEndEvent) TransferEventCancelled(org.alfresco.service.cmr.transfer.TransferEventCancelled) DisabledReplicationJobException(org.alfresco.service.cmr.replication.DisabledReplicationJobException) ActionCancelledException(org.alfresco.repo.action.ActionCancelledException) TransferFailureException(org.alfresco.service.cmr.transfer.TransferFailureException) LockAcquisitionException(org.alfresco.repo.lock.LockAcquisitionException) ReplicationServiceException(org.alfresco.service.cmr.replication.ReplicationServiceException) DisabledReplicationJobException(org.alfresco.service.cmr.replication.DisabledReplicationJobException) TransferDefinition(org.alfresco.service.cmr.transfer.TransferDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ReplicationDefinition(org.alfresco.service.cmr.replication.ReplicationDefinition) ActionCancelledException(org.alfresco.repo.action.ActionCancelledException) TransferEventError(org.alfresco.service.cmr.transfer.TransferEventError) TransferFailureException(org.alfresco.service.cmr.transfer.TransferFailureException)

Example 24 with TransferDefinition

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);
}
Also used : TransferDefinition(org.alfresco.service.cmr.transfer.TransferDefinition) TransferTarget(org.alfresco.service.cmr.transfer.TransferTarget)

Example 25 with TransferDefinition

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);
}
Also used : TransferDefinition(org.alfresco.service.cmr.transfer.TransferDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeCrawler(org.alfresco.service.cmr.transfer.NodeCrawler) TransferTarget(org.alfresco.service.cmr.transfer.TransferTarget)

Aggregations

TransferDefinition (org.alfresco.service.cmr.transfer.TransferDefinition)38 NodeRef (org.alfresco.service.cmr.repository.NodeRef)31 TransferTarget (org.alfresco.service.cmr.transfer.TransferTarget)25 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)24 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)24 Test (org.junit.Test)24 HashSet (java.util.HashSet)21 Locale (java.util.Locale)19 DescriptorService (org.alfresco.service.descriptor.DescriptorService)18 ArrayList (java.util.ArrayList)17 Pair (org.alfresco.util.Pair)16 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)14 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)13 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)11 List (java.util.List)10 Path (org.alfresco.service.cmr.repository.Path)10 TransferEvent (org.alfresco.service.cmr.transfer.TransferEvent)8 Collection (java.util.Collection)7 QName (org.alfresco.service.namespace.QName)7 ContentReader (org.alfresco.service.cmr.repository.ContentReader)5