use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.
the class KModuleDeploymentService method deactivate.
@Override
public void deactivate(String deploymentId) {
DeployedUnit deployed = getDeployedUnit(deploymentId);
if (deployed != null && deployed.isActive()) {
((DeployedUnitImpl) deployed).setActive(false);
((InternalRuntimeManager) deployed.getRuntimeManager()).deactivate();
notifyOnDeactivate(deployed.getDeploymentUnit(), deployed);
}
}
use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.
the class UserTaskServiceImpl method fail.
@Override
public void fail(String deploymentId, Long taskId, String userId, Map<String, Object> faultData) {
UserTaskInstanceDesc task = dataService.getTaskById(taskId);
validateTask(deploymentId, taskId, task);
RuntimeManager manager = getRuntimeManager(task);
if (manager == null) {
logger.warn("Cannot find runtime manager for task {}", taskId);
return;
}
if (manager instanceof InternalRuntimeManager) {
faultData = process(faultData, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
}
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
try {
TaskService taskService = engine.getTaskService();
// perform actual operation
taskService.fail(taskId, userId, faultData);
} catch (PermissionDeniedException e) {
throw new TaskNotFoundException(e.getMessage());
} finally {
disposeRuntimeEngine(manager, engine);
}
}
use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.
the class UserTaskServiceImpl method completeAutoProgress.
@Override
public void completeAutoProgress(String deploymentId, Long taskId, String userId, Map<String, Object> params) {
UserTaskInstanceDesc task = dataService.getTaskById(taskId);
validateTask(deploymentId, taskId, task);
RuntimeManager manager = getRuntimeManager(task);
if (manager == null) {
logger.warn("Cannot find runtime manager for task {}", taskId);
return;
}
if (manager instanceof InternalRuntimeManager) {
params = process(params, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
}
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
try {
TaskService taskService = engine.getTaskService();
// auto progress if needed
if (task.getStatus().equals(Status.Ready.name())) {
taskService.claim(taskId.longValue(), userId);
taskService.start(taskId.longValue(), userId);
} else if (task.getStatus().equals(Status.Reserved.name())) {
taskService.start(taskId.longValue(), userId);
}
// perform actual operation
taskService.complete(taskId, userId, params);
} catch (PermissionDeniedException e) {
throw new TaskNotFoundException(e.getMessage());
} finally {
disposeRuntimeEngine(manager, engine);
}
}
use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.
the class AsyncWorkItemHandlerTest method testRunProcessWithAsyncHandlerWthSecurityManager.
@Test(timeout = 10000)
public void testRunProcessWithAsyncHandlerWthSecurityManager() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Task 1", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("async", new AsyncWorkItemHandler(executorService, "org.jbpm.executor.commands.PrintOutCommand"));
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
assertNotNull(manager);
final AtomicBoolean active = new AtomicBoolean(false);
((InternalRuntimeManager) manager).setSecurityManager(new org.kie.internal.runtime.manager.SecurityManager() {
@Override
public void checkPermission() throws SecurityException {
if (active.get() && !AsyncExecutionMarker.isAsync()) {
throw new SecurityException("Only async allowed");
}
}
});
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance processInstance = ksession.startProcess("ScriptTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
manager.disposeRuntimeEngine(runtime);
// activate security manager to enforce checks for async only
active.set(true);
countDownListener.waitTillCompleted();
// reset the security manager again...
active.set(false);
runtime = manager.getRuntimeEngine(EmptyContext.get());
ksession = runtime.getKieSession();
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
manager.disposeRuntimeEngine(runtime);
}
use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.
the class AbstractDeploymentService method commonDeploy.
public void commonDeploy(DeploymentUnit unit, DeployedUnitImpl deployedUnit, RuntimeEnvironment environemnt, KieContainer kieContainer) {
synchronized (this) {
if (deploymentsMap.containsKey(unit.getIdentifier())) {
DeployedUnit deployed = deploymentsMap.remove(unit.getIdentifier());
RuntimeManager manager = deployed.getRuntimeManager();
manager.close();
}
RuntimeManager manager = null;
deploymentsMap.put(unit.getIdentifier(), deployedUnit);
((SimpleRuntimeEnvironment) environemnt).addToEnvironment("IdentityProvider", identityProvider);
((SimpleRuntimeEnvironment) environemnt).addToEnvironment("Active", deployedUnit.isActive());
try {
switch(unit.getStrategy()) {
case SINGLETON:
manager = managerFactory.newSingletonRuntimeManager(environemnt, unit.getIdentifier());
break;
case PER_REQUEST:
manager = managerFactory.newPerRequestRuntimeManager(environemnt, unit.getIdentifier());
break;
case PER_PROCESS_INSTANCE:
manager = managerFactory.newPerProcessInstanceRuntimeManager(environemnt, unit.getIdentifier());
break;
case PER_CASE:
manager = managerFactory.newPerCaseRuntimeManager(environemnt, unit.getIdentifier());
break;
default:
throw new IllegalArgumentException("Invalid strategy " + unit.getStrategy());
}
if (!deployedUnit.isActive()) {
((InternalRuntimeManager) manager).deactivate();
}
((InternalRuntimeManager) manager).setKieContainer(kieContainer);
deployedUnit.setRuntimeManager(manager);
DeploymentDescriptor descriptor = ((InternalRuntimeManager) manager).getDeploymentDescriptor();
List<String> requiredRoles = descriptor.getRequiredRoles(DeploymentDescriptor.TYPE_EXECUTE);
if (requiredRoles != null && !requiredRoles.isEmpty()) {
((InternalRuntimeManager) manager).setSecurityManager(new IdentityRolesSecurityManager(identityProvider, requiredRoles));
}
notifyOnDeploy(unit, deployedUnit);
} catch (Throwable e) {
deploymentsMap.remove(unit.getIdentifier());
if (manager != null) {
manager.close();
}
notifyOnUnDeploy(unit, deployedUnit);
throw new RuntimeException(e);
}
}
}
Aggregations