Search in sources :

Example 1 with InternalRuntimeManager

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);
    }
}
Also used : InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) DeployedUnit(org.jbpm.services.api.model.DeployedUnit)

Example 2 with InternalRuntimeManager

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);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Example 3 with InternalRuntimeManager

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);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Example 4 with InternalRuntimeManager

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);
}
Also used : DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest) Test(org.junit.Test)

Example 5 with InternalRuntimeManager

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);
        }
    }
}
Also used : SimpleRuntimeEnvironment(org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment) IdentityRolesSecurityManager(org.jbpm.kie.services.impl.security.IdentityRolesSecurityManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager)

Aggregations

InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)51 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)29 Test (org.junit.Test)23 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)23 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)17 HashMap (java.util.HashMap)14 KieSession (org.kie.api.runtime.KieSession)14 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)14 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)12 ArrayList (java.util.ArrayList)9 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)9 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)9 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)8 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)7 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)7 KieServices (org.kie.api.KieServices)7 ReleaseId (org.kie.api.builder.ReleaseId)7 TaskService (org.kie.api.task.TaskService)7 InternalTaskService (org.kie.internal.task.api.InternalTaskService)7 NamedObjectModel (org.kie.internal.runtime.conf.NamedObjectModel)6