if (!RuntimeManagerRegistry.get().isRegistered(migrationSpec.getDeploymentId())) { report.addEntry(Type.ERROR, "No deployment found for " + migrationSpec.getDeploymentId()); if (!RuntimeManagerRegistry.get().isRegistered(migrationSpec.getToDeploymentId())) { report.addEntry(Type.ERROR, "No target deployment found for " + migrationSpec.getToDeploymentId()); InternalRuntimeManager manager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(migrationSpec.getToDeploymentId()); if (manager.getEnvironment().getKieBase().getProcess(migrationSpec.getToProcessId()) == null) { report.addEntry(Type.ERROR, "No process found for " + migrationSpec.getToProcessId() + " in deployment " + migrationSpec.getToDeploymentId()); InternalRuntimeManager sourceManager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(migrationSpec.getDeploymentId()); if (!sourceManager.getClass().isAssignableFrom(manager.getClass())) { report.addEntry(Type.ERROR, "Source (" + sourceManager.getClass().getName() + ") and target (" + manager.getClass().getName() + ") deployments are of different type (they represent different runtime strategies)"); EntityManager em = emf.createEntityManager(); try {
public List<String> getDeployments() { List<String> deploymentIds = new ArrayList<>(RuntimeManagerRegistry.get().getRegisteredIdentifiers()); // add jbpm as trigger group for backward compatibility deploymentIds.add("jbpm"); return deploymentIds; }
public PerCaseRuntimeManager(RuntimeEnvironment environment, SessionFactory factory, TaskServiceFactory taskServiceFactory, String identifier) { super(environment, identifier); this.factory = factory; this.taskServiceFactory = taskServiceFactory; this.mapper = ((org.kie.internal.runtime.manager.RuntimeEnvironment) environment).getMapper(); this.registry.register(this); }
@Override public void execute(JobContext ctx) { RuntimeManager runtimeManager = null; RuntimeEngine engine = null; CommandExecutor executor = null; if (deploymentId != null && processInstanceId != null) { runtimeManager = RuntimeManagerRegistry.get().getManager(deploymentId); engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId)); executor = engine.getTaskService(); } else { executor = TaskDeadlinesServiceImpl.getInstance(); } try { executor.execute(new ExecuteDeadlinesCommand(taskId, deadlineId, type)); } catch (NullPointerException e) { logger.error("TaskDeadlineService instance is not available, most likely was not properly initialized - Job did not run!"); } finally { if (runtimeManager != null && engine != null) { runtimeManager.disposeRuntimeEngine(engine); } } }
RuntimeManager runtimeManager = RuntimeManagerRegistry.get().getManager(deploymentId); if (runtimeManager == null) { throw new IllegalArgumentException("No runtime manager found for deployment id " + deploymentId); RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get()); try { if (correlationKey == null || correlationKey.isEmpty()) { engine.getKieSession().startProcess(processId, variables); } else { String[] correlationKeyProperties = correlationKey.split(","); ((CorrelationAwareProcessRuntime) engine.getKieSession()).startProcess(processId, ck, variables); runtimeManager.disposeRuntimeEngine(engine);
@After public void teardown() { executorService.destroy(); if (manager != null) { RuntimeManagerRegistry.get().remove(manager.getIdentifier()); manager.close(); } if (emf != null) { emf.close(); } pds.close(); }
TransactionManager txm = null; boolean transactionOwner = false; InternalRuntimeManager currentManager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(migrationSpec.getDeploymentId()); InternalRuntimeManager toBeManager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(migrationSpec.getToDeploymentId()); txm = TransactionManagerFactory.get().newTransactionManager(currentManager.getEnvironment().getEnvironment()); transactionOwner = txm.begin(); org.kie.api.definition.process.Process toBeProcess = toBeManager.getEnvironment().getKieBase().getProcess(migrationSpec.getToProcessId()); EntityManager em = emf.createEntityManager(); report.addEntry(Type.INFO, "Executor Jobs updated = " + executorRequestsUpdated + " for process instance id " + migrationSpec.getProcessInstanceId()); current = JPAKnowledgeService.newStatefulKnowledgeSession(currentManager.getEnvironment().getKieBase(), null, currentManager.getEnvironment().getEnvironment()); tobe = toBeManager.getEnvironment().getKieBase().newKieSession(); upgradeProcessInstance(current, tobe, migrationSpec.getProcessInstanceId(), migrationSpec.getToProcessId(), nodeMapping, em, toBeManager.getIdentifier());
EntityManager em = emf.createEntityManager(); try { AbstractRuntimeManager manager = (AbstractRuntimeManager) RuntimeManagerRegistry.get().getManager(error.getDeploymentId()); if (manager != null) { ExecutionErrorManager errorManager = manager.getExecutionErrorManager();
@Override public CommandExecutor lookupKieSession(String kieSessionId, KieContainerInstance containerInstance, KieServerRegistry registry) { String managerId = kieSessionId; Long processInstanceId = null; if (kieSessionId.indexOf("#") != -1) { String[] managerAndInstanceIds = kieSessionId.split("#"); managerId = managerAndInstanceIds[0]; processInstanceId = Long.parseLong(managerAndInstanceIds[1]); } if (RuntimeManagerRegistry.get().isRegistered(managerId)) { RuntimeManager runtimeManager = RuntimeManagerRegistry.get().getManager(managerId); Context ctx = EmptyContext.get(); if (processInstanceId != null) { ctx = ProcessInstanceIdContext.get(processInstanceId); } RuntimeEngine engine = runtimeManager.getRuntimeEngine(ctx); return new RuntimeEngineDisposableCommandExecutor(runtimeManager, engine); } return null; }
protected RuntimeEngine getRuntimeEngine(String releaseId, Long processInstanceId) { RuntimeManager manager = RuntimeManagerRegistry.get().getManager(releaseId); Context<?> context = EmptyContext.get(); if (processInstanceId != null && manager instanceof PerProcessInstanceRuntimeManager) { context = ProcessInstanceIdContext.get(processInstanceId); } if (manager != null) { RuntimeEngine engine = manager.getRuntimeEngine(context); return engine; } return null; }
persistSessionId(location, identifier, singleton.getKieSession().getIdentifier()); registerItems(this.singleton); attachManager(this.singleton); this.registry.register(this); if (tm != null) { tm.commit(owner);
protected ClassLoader getClassLoader(String deploymentId) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (deploymentId == null) { return cl; } InternalRuntimeManager manager = ((InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(deploymentId)); if (manager != null && manager.getEnvironment().getClassLoader() != null) { cl = manager.getEnvironment().getClassLoader(); } return cl; }
@Override public Object getObject() throws Exception { if(RuntimeManagerRegistry.get().isRegistered(getIdentifier())) { // get the runtime manager from the registry return RuntimeManagerRegistry.get().getManager(getIdentifier()); } else { TransactionManagerFactory transactionManagerFactory = TransactionManagerFactory.get(); if (transactionManagerFactory instanceof KieSpringTransactionManagerFactory) { ((KieSpringTransactionManagerFactory) transactionManagerFactory).setGlobalTransactionManager(applicationContext.getBean(AbstractPlatformTransactionManager.class)); } RuntimeManager manager = null; if ("PER_REQUEST".equalsIgnoreCase(type)) { disallowSharedTaskService(runtimeEnvironment); manager = factory.newPerRequestRuntimeManager(runtimeEnvironment, identifier); } else if ("PER_PROCESS_INSTANCE".equalsIgnoreCase(type)) { disallowSharedTaskService(runtimeEnvironment); manager = factory.newPerProcessInstanceRuntimeManager(runtimeEnvironment, identifier); } else { manager = factory.newSingletonRuntimeManager(runtimeEnvironment, identifier); } runtimeManagerSet.add(manager); return manager; } }
protected RuntimeManager getRuntimeManager(CommandContext ctx) { String deploymentId = (String) ctx.getData("deploymentId"); RuntimeManager runtimeManager = RuntimeManagerRegistry.get().getManager(deploymentId); if (runtimeManager == null) { throw new IllegalStateException("There is no runtime manager for deployment " + deploymentId); } return runtimeManager; }
public RuntimeManager getManager(Task task) { return registry.getManager(task.getTaskData().getDeploymentId()); }
public AbstractRuntimeManager(RuntimeEnvironment environment, String identifier) { this.environment = environment; this.identifier = identifier; if (registry.isRegistered(identifier)) { throw new IllegalStateException("RuntimeManager with id " + identifier + " is already active"); } ((SimpleRuntimeEnvironment)environment).getEnvironmentTemplate().set(EnvironmentName.DEPLOYMENT_ID, this.getIdentifier()); internalSetDeploymentDescriptor(); internalSetKieContainer(); ((InternalRegisterableItemsFactory)environment.getRegisterableItemsFactory()).setRuntimeManager(this); String eagerInit = (String)((SimpleRuntimeEnvironment)environment).getEnvironmentTemplate().get("RuntimeEngineEagerInit"); if (eagerInit != null) { engineInitEager = Boolean.parseBoolean(eagerInit); } ExecutionErrorStorage storage = (ExecutionErrorStorage) ((SimpleRuntimeEnvironment)environment).getEnvironmentTemplate().get("ExecutionErrorStorage"); if (storage == null) { storage = new DefaultExecutionErrorStorage(environment.getEnvironment()); } this.executionErrorManager = new ExecutionErrorManagerImpl(storage); ((SimpleRuntimeEnvironment)environment).getEnvironmentTemplate().set(EnvironmentName.EXEC_ERROR_MANAGER, executionErrorManager); }
public PerRequestRuntimeManager(RuntimeEnvironment environment, SessionFactory factory, TaskServiceFactory taskServiceFactory, String identifier) { super(environment, identifier); this.factory = factory; this.taskServiceFactory = taskServiceFactory; this.registry.register(this); }
@After public void teardown() { executorService.destroy(); if (manager != null) { RuntimeManagerRegistry.get().remove(manager.getIdentifier()); manager.close(); } if (emf != null) { emf.close(); } pds.close(); }
TransactionManager txm = null; boolean transactionOwner = false; InternalRuntimeManager currentManager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(migrationSpec.getDeploymentId()); InternalRuntimeManager toBeManager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(migrationSpec.getToDeploymentId()); txm = TransactionManagerFactory.get().newTransactionManager(currentManager.getEnvironment().getEnvironment()); transactionOwner = txm.begin(); org.kie.api.definition.process.Process toBeProcess = toBeManager.getEnvironment().getKieBase().getProcess(migrationSpec.getToProcessId()); EntityManager em = emf.createEntityManager(); report.addEntry(Type.INFO, "Executor Jobs updated = " + executorRequestsUpdated + " for process instance id " + migrationSpec.getProcessInstanceId()); current = JPAKnowledgeService.newStatefulKnowledgeSession(currentManager.getEnvironment().getKieBase(), null, currentManager.getEnvironment().getEnvironment()); tobe = toBeManager.getEnvironment().getKieBase().newKieSession(); upgradeProcessInstance(current, tobe, migrationSpec.getProcessInstanceId(), migrationSpec.getToProcessId(), nodeMapping, em, toBeManager.getIdentifier());
@Override public ExecutionResults execute(CommandContext ctx) throws Exception { String deploymentId = (String) ctx.getData("deploymentId"); if (deploymentId == null) { deploymentId = (String) ctx.getData("DeploymentId"); } Long processInstanceId = (Long) ctx.getData("processInstanceId"); if (processInstanceId == null) { processInstanceId = (Long) ctx.getData("ProcessInstanceId"); } String signal = (String) ctx.getData("Signal"); Object event = ctx.getData("Event"); if (deploymentId == null || signal == null) { throw new IllegalArgumentException("Deployment id and signal name is required"); } RuntimeManager runtimeManager = RuntimeManagerRegistry.get().getManager(deploymentId); if (runtimeManager == null) { throw new IllegalArgumentException("No runtime manager found for deployment id " + deploymentId); } RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId)); try { engine.getKieSession().signalEvent(signal, event, processInstanceId); return new ExecutionResults(); } finally { runtimeManager.disposeRuntimeEngine(engine); } }