public String marshal(String containerId, String marshallingFormat, Object entity, ContainerLocator locator) { MarshallingFormat format = getFormat(marshallingFormat); if (format == null) { throw new IllegalArgumentException("Unknown marshalling format " + marshallingFormat); } KieContainerInstance containerInstance = registry.getContainer(containerId, locator); if (containerInstance == null) { throw new IllegalArgumentException("No container found for id " + containerId + " ."); } Marshaller marshaller = containerInstance.getMarshaller(format); if (marshaller == null) { throw new IllegalArgumentException("No marshaller found for format " + format); } return marshaller.marshall(entity); }
/** * Looks up container id for given alias that is associated with task instance * @param alias container alias * @param taskId unique task instance id * @return * @throws IllegalArgumentException in case there are no containers for given alias */ public String forTaskInstance(String alias, long taskId) { return registry.getContainerId(alias, new ByTaskIdContainerLocator(taskId)); } }
@Override public void init(KieServerImpl kieServer, KieServerRegistry registry) { this.registry = registry; KieServerExtension jbpmExtension = registry.getServerExtension("jBPM"); if (jbpmExtension == null) { initialized = false; logger.warn("jBPM extension not found, Case Management cannot work without jBPM extension, disabling itself"); return; } configureServices(kieServer, registry); this.services.add(this.caseManagementServiceBase); this.services.add(this.caseManagementRuntimeDataService); this.services.add(this.caseRuntimeDataService); this.kieContainerCommandService = new CaseKieContainerCommandServiceImpl(registry, caseManagementServiceBase, caseManagementRuntimeDataService, caseAdminServiceBase); initialized = true; }
public CaseManagementRuntimeDataServiceBase(CaseRuntimeDataService caseRuntimeDataService, KieServerRegistry context) { this.caseRuntimeDataService = caseRuntimeDataService; this.identityProvider = context.getIdentityProvider(); this.context = context; this.bypassAuthUser = Boolean.parseBoolean(context.getConfig().getConfigItemValue(KieServerConstants.CFG_BYPASS_AUTH_USER, "false")); }
private void verifyContainerId(String containerId, String caseId) { String caseContainerId; try { caseContainerId = (new ByCaseIdContainerLocator(caseId)).locateContainer(containerId, null); } catch (IllegalArgumentException e) { throw new CaseNotFoundException(e.getMessage()); } KieContainerInstanceImpl taskContainer = context.getContainer(caseContainerId); List<KieContainerInstanceImpl> containersByAlias = context.getContainersForAlias(containerId); // The container id is either a non-existent one or is not a valid alias for the container id the task is associated with. Both scenarios should raise an exception. if (context.getContainer(containerId) == null && !containersByAlias.contains(taskContainer)) { throw new DeploymentNotFoundException("CaseId: " + caseId + " is not associated with the provided container id: " + containerId + " or its alias."); } }
KieContainerInstanceImpl kci = context.getContainer(containerId); if (kci != null && kci.getStatus().equals(KieContainerStatus.STARTED)) { List<KieServerExtension> extensions = context.getServerExtensions(); for (KieServerExtension extension : extensions) { extension.deactivateContainer(containerId, kci, parameters);
if (command instanceof CreateSolverCommand) { CreateSolverCommand createSolverCommand = (CreateSolverCommand) command; String containerId = context.getContainerId(createSolverCommand.getContainerId(), ContainerLocatorProvider.get().getLocator()); SolverInstance instance = new SolverInstance(); } else if (command instanceof GetSolversCommand) { GetSolversCommand getSolversCommand = (GetSolversCommand) command; String containerId = context.getContainerId(getSolversCommand.getContainerId(), ContainerLocatorProvider.get().getLocator()); response = solverService.getSolvers(containerId); } else if (command instanceof GetSolverCommand) { GetSolverCommand getSolverCommand = (GetSolverCommand) command; String containerId = context.getContainerId(getSolverCommand.getContainerId(), ContainerLocatorProvider.get().getLocator()); response = solverService.getSolver(containerId, GetSolverWithBestSolutionCommand getSolverWithBestSolutionCommand = (GetSolverWithBestSolutionCommand) command; String containerId = context.getContainerId(getSolverWithBestSolutionCommand.getContainerId(), ContainerLocatorProvider.get().getLocator()); response = solverService.getSolverWithBestSolution(containerId, } else if (command instanceof SolvePlanningProblemCommand) { SolvePlanningProblemCommand solvePlanningProblemCommand = (SolvePlanningProblemCommand) command; String containerId = context.getContainerId(solvePlanningProblemCommand.getContainerId(), ContainerLocatorProvider.get().getLocator()); KieContainerInstanceImpl kc = context.getContainer(containerId); Marshaller marshaller = kc.getMarshaller(marshallingFormat);
KieContainerInstanceImpl kci = (KieContainerInstanceImpl) context.getContainer( containerId, ContainerLocatorProvider.get().getLocator() ); ks = context.getKieSessionLookupManager().lookup(sessionId, kci, context); } else {
String formType) { containerId = registry.getContainerId(containerId, new ByTaskIdContainerLocator(taskId)); Task task = userTaskService.execute(containerId, new GetUserTaskCommand(registry.getIdentityProvider().getName(), taskId)); if (task == null) { throw new IllegalStateException("No task with id " + taskId + " found");
protected void configureServices(KieServerImpl kieServer, KieServerRegistry registry) { KieServerConfig config = registry.getConfig(); ((KModuleDeploymentService) deploymentService).setBpmn2Service(definitionService); ((KModuleDeploymentService) deploymentService).setEmf(emf); ((KModuleDeploymentService) deploymentService).setIdentityProvider(registry.getIdentityProvider()); ((KModuleDeploymentService) deploymentService).setManagerFactory(new RuntimeManagerFactoryImpl()); ((KModuleDeploymentService) deploymentService).setFormManagerService(formManagerService); ((RuntimeDataServiceImpl) runtimeDataService).setIdentityProvider(registry.getIdentityProvider()); ((RuntimeDataServiceImpl) runtimeDataService).setTaskService(taskService); ((RuntimeDataServiceImpl) runtimeDataService).setTaskAuditService(TaskAuditServiceFactory.newTaskAuditServiceConfigurator() ((QueryServiceImpl)queryService).setIdentityProvider(registry.getIdentityProvider()); ((QueryServiceImpl)queryService).setCommandService(new TransactionalCommandService(emf)); Function<String, String> kieServerDataSourceResolver = input -> { while (matcher.find()) { String paramName = matcher.group(1); KieServerConfig configuration = context.getStateRepository().load(KieServerEnvironment.getServerId()).getConfiguration(); dataSource = configuration.getConfigItemValue(paramName, "java:jboss/datasources/ExampleDS"); logger.info("Data source expression {} resolved to {}", input, dataSource); ((ProcessInstanceAdminServiceImpl) this.processInstanceAdminService).setRuntimeDataService(runtimeDataService); ((ProcessInstanceAdminServiceImpl) this.processInstanceAdminService).setCommandService(new TransactionalCommandService(emf)); ((ProcessInstanceAdminServiceImpl) this.processInstanceAdminService).setIdentityProvider(registry.getIdentityProvider()); ((UserTaskAdminServiceImpl) this.userTaskAdminService).setIdentityProvider(context.getIdentityProvider()); ((UserTaskAdminServiceImpl) this.userTaskAdminService).setCommandService(new TransactionalCommandService(emf));
protected void configureServices(KieServerImpl kieServer, KieServerRegistry registry) { KieServerExtension jbpmExtension = registry.getServerExtension("jBPM"); List<Object> jbpmServices = jbpmExtension.getServices(); RuntimeDataService runtimeDataService = null; ((CaseRuntimeDataServiceImpl) caseRuntimeDataService).setRuntimeDataService(runtimeDataService); ((CaseRuntimeDataServiceImpl) caseRuntimeDataService).setCommandService(new TransactionalCommandService(EntityManagerFactoryManager.get().getOrCreate(persistenceUnitName))); ((CaseRuntimeDataServiceImpl) caseRuntimeDataService).setIdentityProvider(registry.getIdentityProvider()); ((CaseServiceImpl) caseService).setRuntimeDataService(runtimeDataService); ((CaseServiceImpl) caseService).setCommandService(new TransactionalCommandService(EntityManagerFactoryManager.get().getOrCreate(persistenceUnitName))); ((CaseServiceImpl) caseService).setAuthorizationManager(new AuthorizationManagerImpl(registry.getIdentityProvider(), new TransactionalCommandService(EntityManagerFactoryManager.get().getOrCreate(persistenceUnitName)))); ((CaseServiceImpl) caseService).setIdentityProvider(registry.getIdentityProvider()); CaseConfigurationDeploymentListener configurationListener = new CaseConfigurationDeploymentListener(registry.getIdentityProvider());
public void startContainer(String containerId) { KieServerState currentState = context.getStateRepository().load(KieServerEnvironment.getServerId()); Set<String> controllers = currentState.getControllers(); KieServerConfig config = currentState.getConfiguration(); if (controllers != null && !controllers.isEmpty()) { for (String controllerUrl : controllers) { if (controllerUrl != null && !controllerUrl.isEmpty()) { String connectAndSyncUrl = controllerUrl + "/management/servers/" + KieServerEnvironment.getServerId() + "/containers/" + containerId + "/status/started"; String userName = config.getConfigItemValue(KieServerConstants.CFG_KIE_CONTROLLER_USER, "kieserver"); String password = loadControllerPassword(config); String token = config.getConfigItemValue(KieServerConstants.CFG_KIE_CONTROLLER_TOKEN); try { makeHttpPostRequestAndCreateCustomResponse(connectAndSyncUrl, "", null, userName, password, token); break; } catch (Exception e) { // let's check all other controllers in case of running in cluster of controllers logger.warn("Exception encountered while syncing with controller at {} error {}", connectAndSyncUrl, e.getCause() == null ? e.getMessage() : e.getCause().getMessage()); logger.debug("Exception encountered while syncing with controller at {} error {}", connectAndSyncUrl, e.getMessage(), e); } } } } }
public ImageServiceBase(RuntimeDataService dataService, Map<String, ImageReference> imageReferenceMap, KieServerRegistry registry) { this.dataService = dataService; this.imageReferenceMap = imageReferenceMap; this.registry = registry; this.kieServerLocation = this.registry.getConfig().getConfigItemValue(KieServerConstants.KIE_SERVER_LOCATION, System.getProperty(KieServerConstants.KIE_SERVER_LOCATION, "unknown")); if (!this.kieServerLocation.endsWith("/")) { this.kieServerLocation = kieServerLocation + "/"; } }
@Override public void init(KieServerImpl kieServer, KieServerRegistry registry) { this.rulesExecutionService = new RulesExecutionService(registry); this.batchCommandService = new DroolsKieContainerCommandServiceImpl(kieServer, registry, this.rulesExecutionService); this.registry = registry; if (registry.getKieSessionLookupManager() != null) { registry.getKieSessionLookupManager().addHandler(new DroolsKieSessionLookupHandler()); } services.add(batchCommandService); services.add(rulesExecutionService); initialized = true; }
KieContainerInstanceImpl kci = context.getContainer(containerId); if (kci != null && kci.getStatus().equals(KieContainerStatus.DEACTIVATED)) { List<KieServerExtension> extensions = context.getServerExtensions(); for (KieServerExtension extension : extensions) { extension.activateContainer(containerId, kci, parameters);
public RuntimeDataServiceBase(RuntimeDataService delegate, KieServerRegistry context) { this.runtimeDataService = delegate; this.identityProvider = context.getIdentityProvider(); this.context = context; this.bypassAuthUser = Boolean.parseBoolean(context.getConfig().getConfigItemValue(KieServerConstants.CFG_BYPASS_AUTH_USER, "false")); }
public String getTaskRenderedForm(String renderer, String containerId, long taskId) { String resolvedContainerId = registry.getContainerId(containerId, new ByTaskIdContainerLocator(taskId)); Task task = userTaskService.execute(resolvedContainerId, new GetUserTaskCommand(registry.getIdentityProvider().getName(), taskId)); if (task == null) { throw new TaskNotFoundException("No task with id " + taskId + " found");
public void stopContainer(String containerId) { KieServerState currentState = context.getStateRepository().load(KieServerEnvironment.getServerId()); Set<String> controllers = currentState.getControllers(); KieServerConfig config = currentState.getConfiguration(); if (controllers != null && !controllers.isEmpty()) { for (String controllerUrl : controllers) { if (controllerUrl != null && !controllerUrl.isEmpty()) { String connectAndSyncUrl = controllerUrl + "/management/servers/" + KieServerEnvironment.getServerId() + "/containers/" + containerId + "/status/stopped"; String userName = config.getConfigItemValue(KieServerConstants.CFG_KIE_CONTROLLER_USER, "kieserver"); String password = loadControllerPassword(config); String token = config.getConfigItemValue(KieServerConstants.CFG_KIE_CONTROLLER_TOKEN); try { makeHttpPostRequestAndCreateCustomResponse(connectAndSyncUrl, "", null, userName, password, token); break; } catch (Exception e) { // let's check all other controllers in case of running in cluster of controllers logger.warn("Exception encountered while syncing with controller at {} error {}", connectAndSyncUrl, e.getCause() == null ? e.getMessage() : e.getCause().getMessage()); logger.debug("Exception encountered while syncing with controller at {} error {}", connectAndSyncUrl, e.getMessage(), e); } } } } } }
String processInstanceQuerySource = context.getConfig().getConfigItemValue(KieServerConstants.CFG_PERSISTANCE_DS, "java:jboss/datasources/ExampleDS");
@Override public void init(KieServerImpl kieServer, KieServerRegistry registry) { this.kieServer = kieServer; this.context = registry; configureServices(kieServer, registry); if (registry.getKieSessionLookupManager() != null) { registry.getKieSessionLookupManager().addHandler(new JBPMKieSessionLookupHandler()); } services.add(formManagerService); services.add(deploymentService); services.add(definitionService); services.add(processService); services.add(userTaskService); services.add(runtimeDataService); services.add(executorService); services.add(queryService); services.add(processInstanceMigrationService); services.add(processInstanceAdminService); services.add(userTaskAdminService); registerDefaultQueryDefinitions(); initialized = true; }