The publish_web_content_processdefinition now always runs the PublishEventAction asynchronously. Added ScriptAction.executeAsynchronously(ScriptNode) method.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28975 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
N Smith
2011-07-13 11:45:51 +00:00
parent 17a5ae11ff
commit 9534fcf21e
6 changed files with 84 additions and 186 deletions

View File

@@ -73,12 +73,6 @@
<property name="workflowEngineId" value="jbpm" /> <property name="workflowEngineId" value="jbpm" />
</bean> </bean>
<!-- Check Publishing Dependencies Action -->
<bean id="pub_checkPublishingDependencies"
class="org.alfresco.repo.publishing.CheckPublishingDependenciesAction" >
<property name="nodeService" ref="NodeService" />
</bean>
<!-- Publish Event Action --> <!-- Publish Event Action -->
<bean id="pub_publishEvent" class="org.alfresco.repo.publishing.PublishEventAction" > <bean id="pub_publishEvent" class="org.alfresco.repo.publishing.PublishEventAction" >

View File

@@ -10,7 +10,7 @@
</start-state> </start-state>
<decision name="checkForScheduledTime" > <decision name="checkForScheduledTime" >
<transition name="toCheckDependencies" to="checkDependencies"> <transition name="toPublish" to="publish">
<condition>#{pubwf_scheduledPublishDate == null}</condition> <condition>#{pubwf_scheduledPublishDate == null}</condition>
</transition> </transition>
<transition name="toWaitForScheduledTime" to="waitForScheduledTime" /> <transition name="toWaitForScheduledTime" to="waitForScheduledTime" />
@@ -18,7 +18,7 @@
<task-node name="waitForScheduledTime" end-tasks="true" > <task-node name="waitForScheduledTime" end-tasks="true" >
<task name="pubwf:wait" > <task name="pubwf:wait" >
<timer duedate="#{pubwf_scheduledPublishDate}" transition="toCheckDependencies" > <timer duedate="#{pubwf_scheduledPublishDate}" transition="toPublish" >
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript"> <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script> <script>
logger.log("Checking dependencies for PUblishing Event: "+ pubwf_publishingEvent); logger.log("Checking dependencies for PUblishing Event: "+ pubwf_publishingEvent);
@@ -26,50 +26,7 @@
</action> </action>
</timer> </timer>
</task> </task>
<transition name="toCheckDependencies" to="checkDependencies" /> <transition name="toPublish" to="publish" />
</task-node>
<decision name="checkDependencies">
<event type="node-enter">
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script>
<variable name="pubwf_eventStatus" access="write" />
<expression>
var publishingDependenciesAction = actions.create("pub_checkPublishingDependencies");
publishingDependenciesAction.execute(pubwf_publishingEvent);
pubwf_publishingEvent.properties["pub:publishingEventStatus"];
</expression>
</script>
</action>
</event>
<transition name="retry" to="waitAndRetry" />
<transition name="publish" to="publish">
<condition>#{pubwf_eventStatus == "IN_PROGRESS"}</condition>
</transition>
<transition name="fail" to="end">
<condition>#{pubwf_eventStatus== "FAILED"}</condition>
</transition>
<transition name="alreadyCompleted" to="end">
<condition>#{pubwf_eventStatus== "COMPLETED"}</condition>
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script>
logger.log("PUblishing Event already completed! Event: "+ pubwf_publishingEvent);
</script>
</action>
</transition>
</decision>
<task-node name="waitAndRetry" end-tasks="true" >
<task name="pubwf:wait" >
<timer duedate="1 minute" transition="toCheckDependencies" >
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script>
logger.log("Checking dependencies for PUblishing Event: "+ pubwf_publishingEvent);
</script>
</action>
</timer>
</task>
<transition name="toCheckDependencies" to="checkDependencies" />
</task-node> </task-node>
<node name="publish" > <node name="publish" >
@@ -77,7 +34,7 @@
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript"> <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script> <script>
var publishEventAction = actions.create("pub_publishEvent"); var publishEventAction = actions.create("pub_publishEvent");
publishEventAction.execute(pubwf_publishingEvent); publishEventAction.executeAsynchronously(pubwf_publishingEvent);
</script> </script>
</action> </action>
</event> </event>

View File

@@ -8,9 +8,4 @@
<constructor-arg value="org.alfresco.repo.action.executer.ActionExecuter" /> <constructor-arg value="org.alfresco.repo.action.executer.ActionExecuter" />
</bean> </bean>
<!-- Mock Check Publishing Dependencies -->
<bean id="pub_checkPublishingDependencies" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.alfresco.repo.action.executer.ActionExecuter" />
</bean>
</beans> </beans>

View File

@@ -142,11 +142,35 @@ public class ScriptAction implements Serializable, Scopeable
node.reset(); node.reset();
} }
/**
* Execute action. The existing transaction will be joined.
*
* @param node
* the node to execute action upon
*/
@SuppressWarnings("synthetic-access")
public void executeAsynchronously(ScriptNode node)
{
performParamConversionForRepo();
executeAsynchronouslyImpl(node);
// Parameters may have been updated by action execution, so reset cache
this.parameters = null;
// Reset the actioned upon node
node.reset();
}
protected void executeImpl(ScriptNode node) protected void executeImpl(ScriptNode node)
{ {
actionService.executeAction(action, node.getNodeRef()); actionService.executeAction(action, node.getNodeRef());
} }
protected void executeAsynchronouslyImpl(ScriptNode node)
{
actionService.executeAction(action, node.getNodeRef(), true, true);
}
/** /**
* Execute action, optionally starting a new, potentially read-only transaction. * Execute action, optionally starting a new, potentially read-only transaction.
* *

View File

@@ -1,77 +0,0 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.publishing;
import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_STATUS;
import static org.alfresco.repo.publishing.PublishingModel.TYPE_PUBLISHING_EVENT;
import java.util.List;
import org.alfresco.repo.action.executer.ActionExecuter;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.publishing.PublishingEvent.Status;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* This {@link ActionExecuter} checks the status of the publishing event
* dependencies and sets the pub:publishingEventStatus property accordingly.
*
* @author Nick Smith
* @since 4.0
*
*/
public class CheckPublishingDependenciesAction extends ActionExecuterAbstractBase
{
private NodeService nodeService;
/**
* {@inheritDoc}
*/
@Override
protected void executeImpl(Action action, NodeRef node)
{
QName nodeType = nodeService.getType(node);
if(TYPE_PUBLISHING_EVENT.equals(nodeType))
{
nodeService.setProperty(node, PROP_PUBLISHING_EVENT_STATUS, Status.IN_PROGRESS);
}
}
/**
* {@inheritDoc}
*/
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
{
//NOOP
}
/**
* @param nodeService the nodeService to set
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
}

View File

@@ -62,6 +62,9 @@ import org.alfresco.util.GUID;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
/** /**
* @author Nick Smith * @author Nick Smith
@@ -75,22 +78,13 @@ public class PublishWebContentJbpmTest extends BaseSpringTest
private ServiceRegistry serviceRegistry; private ServiceRegistry serviceRegistry;
private Repository repositoryHelper; private Repository repositoryHelper;
private ActionExecuter publishEventAction; private ActionExecuter publishEventAction;
private ActionExecuter checkPublishingDependenciesAction;
private NodeService nodeService; private NodeService nodeService;
private WorkflowService workflowService; private WorkflowService workflowService;
private RetryingTransactionHelper transactionHelper; private RetryingTransactionHelper transactionHelper;
private NodeRef event; private NodeRef event;
private String instanceId; private String instanceId;
private long threadId;
@Override
protected String[] getConfigLocations()
{
return new String[]
{
ApplicationContextHelper.CONFIG_LOCATIONS[0], "classpath:test/alfresco/test-web-publishing--workflow-context.xml"
};
}
@Test @Test
public void testProcessTimers() throws Exception public void testProcessTimers() throws Exception
@@ -106,41 +100,40 @@ public class PublishWebContentJbpmTest extends BaseSpringTest
// Wait for scheduled time to elapse. // Wait for scheduled time to elapse.
Thread.sleep(10000); Thread.sleep(10000);
// Check the Publish Event Action was called
verify(checkPublishingDependenciesAction).execute(any(Action.class), any(NodeRef.class));
// Should now be waiting to retry
checkNode("waitAndRetry");
// Set Status to IN_PROGRESS
nodeService.setProperty(event, PROP_PUBLISHING_EVENT_STATUS, Status.IN_PROGRESS.name());
// Wait for retry
Thread.sleep(65000);
// Should have ended // Should have ended
WorkflowInstance instance = workflowService.getWorkflowById(instanceId); checkEnded(instanceId);
assertFalse("Workflow should have ended!", instance.isActive());
}
@Test
public void testProcessPublishPath() throws Exception
{
// Set Status to IN_PROGRESS
nodeService.setProperty(event, PROP_PUBLISHING_EVENT_STATUS, Status.IN_PROGRESS.name());
Calendar schedule = Calendar.getInstance();
schedule.add(Calendar.SECOND, 1);
startWorkflowAndCommit(schedule);
Thread.sleep(2000);
// Should have ended
WorkflowInstance instance = workflowService.getWorkflowById(instanceId);
assertFalse("Workflow should have ended!", instance.isActive());
// Check the Publish Event Action was called // Check the Publish Event Action was called
verify(publishEventAction).execute(any(Action.class), any(NodeRef.class)); verify(publishEventAction).execute(any(Action.class), any(NodeRef.class));
assertFalse("The action should be run from a different Thread!", Thread.currentThread().getId()==threadId);
}
public void testProcessNoSchedule() throws Exception
{
startWorkflowAndCommit(null);
// Wait for async action to execute
Thread.sleep(500);
// Should have ended
checkEnded(instanceId);
// Check the Publish Event Action was called
verify(publishEventAction).execute(any(Action.class), any(NodeRef.class));
assertFalse("The action should be run from a different Thread!", Thread.currentThread().getId()==threadId);
}
private void checkEnded(String instanceId2)
{
WorkflowInstance instance = workflowService.getWorkflowById(instanceId2);
if(instance.isActive())
{
List<WorkflowPath> paths = workflowService.getWorkflowPaths(instance.getId());
String nodeName = paths.get(0).getNode().getName();
fail("Workflow should have ended! At node: " +nodeName);
}
} }
private void startWorkflowAndCommit(final Calendar scheduledTime) private void startWorkflowAndCommit(final Calendar scheduledTime)
@@ -152,10 +145,7 @@ public class PublishWebContentJbpmTest extends BaseSpringTest
WorkflowPath path = startWorkflow(scheduledTime); WorkflowPath path = startWorkflow(scheduledTime);
// End the Start task. // End the Start task.
List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId()); WorkflowTask startTask = workflowService.getStartTask(path.getInstance().getId());
assertNotNull(tasks);
assertEquals(1, tasks.size());
WorkflowTask startTask = tasks.get(0);
workflowService.endTask(startTask.getId(), null); workflowService.endTask(startTask.getId(), null);
return null; return null;
} }
@@ -196,13 +186,19 @@ public class PublishWebContentJbpmTest extends BaseSpringTest
serviceRegistry = (ServiceRegistry)getApplicationContext().getBean("ServiceRegistry"); serviceRegistry = (ServiceRegistry)getApplicationContext().getBean("ServiceRegistry");
repositoryHelper = (Repository) getApplicationContext().getBean("repositoryHelper"); repositoryHelper = (Repository) getApplicationContext().getBean("repositoryHelper");
publishEventAction = (ActionExecuter) getApplicationContext().getBean("pub_publishEvent"); publishEventAction = (ActionExecuter) getApplicationContext().getBean("pub_publishEvent");
checkPublishingDependenciesAction = (ActionExecuter) getApplicationContext().getBean("pub_checkPublishingDependencies");
reset(checkPublishingDependenciesAction);
reset(publishEventAction); reset(publishEventAction);
ActionDefinition actionDef = mock(ActionDefinition.class); ActionDefinition actionDef = mock(ActionDefinition.class);
when(publishEventAction.getActionDefinition()).thenReturn(actionDef); when(publishEventAction.getActionDefinition()).thenReturn(actionDef);
when(checkPublishingDependenciesAction.getActionDefinition()).thenReturn(actionDef); // Record thread action is run in.
Mockito.doAnswer(new Answer<Void>()
{
public Void answer(InvocationOnMock invocation) throws Throwable
{
threadId = Thread.currentThread().getId();
return null;
}
}).when(publishEventAction).execute(any(Action.class), any(NodeRef.class));
this.workflowService = serviceRegistry.getWorkflowService(); this.workflowService = serviceRegistry.getWorkflowService();
this.nodeService = serviceRegistry.getNodeService(); this.nodeService = serviceRegistry.getNodeService();
@@ -219,6 +215,15 @@ public class PublishWebContentJbpmTest extends BaseSpringTest
this.event = eventAssoc.getChildRef(); this.event = eventAssoc.getChildRef();
} }
@Override
protected String[] getConfigLocations()
{
return new String[]
{
ApplicationContextHelper.CONFIG_LOCATIONS[0], "classpath:test/alfresco/test-web-publishing--workflow-context.xml"
};
}
@After @After
public void onTearDown() public void onTearDown()
{ {