Search in sources :

Example 1 with DeploymentService

use of org.jbpm.services.api.DeploymentService in project droolsjbpm-integration by kiegroup.

the class JBPMApplication method deployAndValidate.

@Bean
CommandLineRunner deployAndValidate() {
    return new CommandLineRunner() {

        @Autowired
        private DeploymentService deploymentService;

        @Autowired
        private RuntimeDataService runtimeDataService;

        @Autowired
        private ProcessService processService;

        @Override
        public void run(String... strings) throws Exception {
            KModuleDeploymentUnit unit = null;
            if (strings.length > 0) {
                String arg = strings[0];
                LOGGER.info("About to deploy : {}", arg);
                String[] gav = arg.split(":");
                unit = new KModuleDeploymentUnit(gav[0], gav[1], gav[2]);
                deploymentService.deploy(unit);
                LOGGER.info("{} successfully deployed", arg);
            }
            LOGGER.info("Available processes:");
            Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
            for (ProcessDefinition def : processes) {
                LOGGER.info("\t{} (with id '{})", def.getName(), def.getId());
            }
            if (unit != null && !processes.isEmpty()) {
                String processId = processes.iterator().next().getId();
                LOGGER.info("About to start process with id {}", processId);
                long processInstanceId = processService.startProcess(unit.getIdentifier(), processId);
                LOGGER.info("Started instance of {} process with id {}", processId, processInstanceId);
                processService.abortProcessInstance(processInstanceId);
                LOGGER.info("Aborted instance with id {}", processInstanceId);
            }
            LOGGER.info("========= Verification completed successfully =========");
        }
    };
}
Also used : RuntimeDataService(org.jbpm.services.api.RuntimeDataService) CommandLineRunner(org.springframework.boot.CommandLineRunner) DeploymentService(org.jbpm.services.api.DeploymentService) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) QueryContext(org.kie.api.runtime.query.QueryContext) ProcessService(org.jbpm.services.api.ProcessService) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) Bean(org.springframework.context.annotation.Bean)

Example 2 with DeploymentService

use of org.jbpm.services.api.DeploymentService in project droolsjbpm-integration by kiegroup.

the class JbpmKieServerExtension method configureServices.

protected void configureServices(KieServerImpl kieServer, KieServerRegistry registry) {
    KieServerConfig config = registry.getConfig();
    // loaded from system property as callback info isn't stored as configuration in kie server repository
    String callbackConfig = System.getProperty(KieServerConstants.CFG_HT_CALLBACK);
    // if no other callback set, use Elytron or jaas by default
    if (callbackConfig == null || callbackConfig.isEmpty()) {
        if (ElytronIdentityProvider.available()) {
            System.setProperty(KieServerConstants.CFG_HT_CALLBACK, "custom");
            String name = ElytronUserGroupCallbackImpl.class.getName();
            ElytronUserGroupCallbackImpl.addExternalUserGroupAdapter(new JMSUserGroupAdapter());
            System.setProperty(KieServerConstants.CFG_HT_CALLBACK_CLASS, name);
        } else {
            System.setProperty(KieServerConstants.CFG_HT_CALLBACK, "jaas");
            JAASUserGroupCallbackImpl.addExternalUserGroupAdapter(new JMSUserGroupAdapter());
        }
    }
    this.isExecutorAvailable = isExecutorOnClasspath();
    EntityManagerFactory emf = build(getPersistenceProperties(config));
    EntityManagerFactoryManager.get().addEntityManagerFactory(persistenceUnitName, emf);
    formManagerService = new FormManagerServiceImpl();
    // build definition service
    definitionService = new BPMN2DataServiceImpl();
    // build deployment service
    deploymentService = new KModuleDeploymentService();
    ((KModuleDeploymentService) deploymentService).setBpmn2Service(definitionService);
    ((KModuleDeploymentService) deploymentService).setEmf(emf);
    ((KModuleDeploymentService) deploymentService).setIdentityProvider(registry.getIdentityProvider());
    ((KModuleDeploymentService) deploymentService).setManagerFactory(new RuntimeManagerFactoryImpl());
    ((KModuleDeploymentService) deploymentService).setFormManagerService(formManagerService);
    // configure user group callback
    UserGroupCallback userGroupCallback = UserDataServiceProvider.getUserGroupCallback();
    UserInfo userInfo = UserDataServiceProvider.getUserInfo();
    TaskService taskService = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).userGroupCallback(userGroupCallback).userInfo(userInfo).getTaskService();
    // build runtime data service
    runtimeDataService = new RuntimeDataServiceImpl();
    ((RuntimeDataServiceImpl) runtimeDataService).setCommandService(new TransactionalCommandService(emf));
    ((RuntimeDataServiceImpl) runtimeDataService).setIdentityProvider(registry.getIdentityProvider());
    ((RuntimeDataServiceImpl) runtimeDataService).setTaskService(taskService);
    ((RuntimeDataServiceImpl) runtimeDataService).setTaskAuditService(TaskAuditServiceFactory.newTaskAuditServiceConfigurator().setTaskService(taskService).getTaskAuditService());
    ((KModuleDeploymentService) deploymentService).setRuntimeDataService(runtimeDataService);
    // build process service
    processService = new ProcessServiceImpl();
    ((ProcessServiceImpl) processService).setDataService(runtimeDataService);
    ((ProcessServiceImpl) processService).setDeploymentService(deploymentService);
    // build user task service
    userTaskService = new UserTaskServiceImpl();
    ((UserTaskServiceImpl) userTaskService).setDataService(runtimeDataService);
    ((UserTaskServiceImpl) userTaskService).setDeploymentService(deploymentService);
    // build query service
    queryService = new QueryServiceImpl();
    ((QueryServiceImpl) queryService).setIdentityProvider(registry.getIdentityProvider());
    ((QueryServiceImpl) queryService).setCommandService(new TransactionalCommandService(emf));
    Function<String, String> kieServerDataSourceResolver = input -> {
        String dataSource = input;
        Matcher matcher = PARAMETER_MATCHER.matcher(dataSource);
        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);
        }
        return dataSource;
    };
    ((QueryServiceImpl) queryService).setDataSourceResolver(kieServerDataSourceResolver);
    ((QueryServiceImpl) queryService).init();
    // set runtime data service as listener on deployment service
    ((KModuleDeploymentService) deploymentService).addListener(((RuntimeDataServiceImpl) runtimeDataService));
    ((KModuleDeploymentService) deploymentService).addListener(((BPMN2DataServiceImpl) definitionService));
    ((KModuleDeploymentService) deploymentService).addListener(((QueryServiceImpl) queryService));
    if (config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_DISABLED, "false").equalsIgnoreCase("false")) {
        String executorQueueName = config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_JMS_QUEUE, "queue/KIE.SERVER.EXECUTOR");
        // build executor service
        executorService = ExecutorServiceFactory.newExecutorService(emf);
        executorService.setInterval(Integer.parseInt(config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_INTERVAL, "0")));
        executorService.setRetries(Integer.parseInt(config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_RETRIES, "3")));
        executorService.setThreadPoolSize(Integer.parseInt(config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_POOL, "1")));
        executorService.setTimeunit(TimeUnit.valueOf(config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_TIME_UNIT, "SECONDS")));
        ((ExecutorImpl) ((ExecutorServiceImpl) executorService).getExecutor()).setQueueName(executorQueueName);
        ((KModuleDeploymentService) deploymentService).setExecutorService(executorService);
    }
    // admin services
    this.processInstanceMigrationService = new ProcessInstanceMigrationServiceImpl();
    this.processInstanceAdminService = new ProcessInstanceAdminServiceImpl();
    ((ProcessInstanceAdminServiceImpl) this.processInstanceAdminService).setProcessService(processService);
    ((ProcessInstanceAdminServiceImpl) this.processInstanceAdminService).setRuntimeDataService(runtimeDataService);
    ((ProcessInstanceAdminServiceImpl) this.processInstanceAdminService).setCommandService(new TransactionalCommandService(emf));
    ((ProcessInstanceAdminServiceImpl) this.processInstanceAdminService).setIdentityProvider(registry.getIdentityProvider());
    this.userTaskAdminService = new UserTaskAdminServiceImpl();
    ((UserTaskAdminServiceImpl) this.userTaskAdminService).setRuntimeDataService(runtimeDataService);
    ((UserTaskAdminServiceImpl) this.userTaskAdminService).setUserTaskService(userTaskService);
    ((UserTaskAdminServiceImpl) this.userTaskAdminService).setIdentityProvider(context.getIdentityProvider());
    ((UserTaskAdminServiceImpl) this.userTaskAdminService).setCommandService(new TransactionalCommandService(emf));
    this.advanceRuntimeDataService = new AdvanceRuntimeDataServiceImpl();
    ((AdvanceRuntimeDataServiceImpl) this.advanceRuntimeDataService).setEmf(emf);
    ((AdvanceRuntimeDataServiceImpl) this.advanceRuntimeDataService).setCommandService(new TransactionalCommandService(emf));
    this.kieContainerCommandService = new JBPMKieContainerCommandServiceImpl(context, deploymentService, new DefinitionServiceBase(definitionService, context), new ProcessServiceBase(processService, definitionService, runtimeDataService, context), new UserTaskServiceBase(userTaskService, context), new RuntimeDataServiceBase(runtimeDataService, advanceRuntimeDataService, context), new ExecutorServiceBase(executorService, context), new QueryDataServiceBase(queryService, context), new DocumentServiceBase(context), new ProcessAdminServiceBase(processInstanceMigrationService, processInstanceAdminService, runtimeDataService, context), new UserTaskAdminServiceBase(userTaskAdminService, context));
}
Also used : FormManagerServiceImpl(org.jbpm.kie.services.impl.FormManagerServiceImpl) Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) QueryService(org.jbpm.services.api.query.QueryService) AuditMode(org.kie.internal.runtime.conf.AuditMode) KieServerConstants(org.kie.server.api.KieServerConstants) KieServerMode(org.kie.server.api.model.KieServerMode) UserGroupCallback(org.kie.api.task.UserGroupCallback) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) Matcher(java.util.regex.Matcher) QueryServiceImpl(org.jbpm.kie.services.impl.query.QueryServiceImpl) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) Message(org.kie.server.api.model.Message) InitialContext(javax.naming.InitialContext) PersistenceProviderResolverHolder(javax.persistence.spi.PersistenceProviderResolverHolder) UserTaskServiceImpl(org.jbpm.kie.services.impl.UserTaskServiceImpl) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) PersistenceUnitInfoImpl(org.kie.server.services.jbpm.jpa.PersistenceUnitInfoImpl) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) Set(java.util.Set) QueryContext(org.kie.api.runtime.query.QueryContext) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) IOUtils(org.apache.commons.io.IOUtils) EntityManagerFactory(javax.persistence.EntityManagerFactory) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) DeploymentDescriptorMerger(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorMerger) RuntimeManagerFactoryImpl(org.jbpm.runtime.manager.impl.RuntimeManagerFactoryImpl) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) SupportedTransports(org.kie.server.services.api.SupportedTransports) ObjectModel(org.kie.internal.runtime.conf.ObjectModel) FormManagerServiceImpl(org.jbpm.kie.services.impl.FormManagerServiceImpl) ProcessInstanceAdminService(org.jbpm.services.api.admin.ProcessInstanceAdminService) ArrayList(java.util.ArrayList) ProcessInstanceAdminServiceImpl(org.jbpm.kie.services.impl.admin.ProcessInstanceAdminServiceImpl) DeploymentService(org.jbpm.services.api.DeploymentService) QueryNotFoundException(org.jbpm.services.api.query.QueryNotFoundException) JAASUserGroupCallbackImpl(org.jbpm.services.task.identity.JAASUserGroupCallbackImpl) TaskAuditServiceFactory(org.jbpm.services.task.audit.TaskAuditServiceFactory) ExecutorImpl(org.jbpm.executor.impl.ExecutorImpl) TaskService(org.kie.api.task.TaskService) MarshallingException(org.kie.server.api.marshalling.MarshallingException) InternalKieContainer(org.drools.core.impl.InternalKieContainer) AbstractDeploymentService(org.jbpm.kie.services.impl.AbstractDeploymentService) UserDataServiceProvider(org.jbpm.runtime.manager.impl.identity.UserDataServiceProvider) PersistenceUnitExtensionsLoader(org.kie.server.services.jbpm.jpa.PersistenceUnitExtensionsLoader) IOException(java.io.IOException) ProcessInstanceMigrationService(org.jbpm.services.api.admin.ProcessInstanceMigrationService) QueryMapperRegistry(org.jbpm.services.api.query.QueryMapperRegistry) PersistenceProvider(javax.persistence.spi.PersistenceProvider) HumanTaskServiceFactory(org.jbpm.services.task.HumanTaskServiceFactory) AdvanceRuntimeDataService(org.jbpm.services.api.AdvanceRuntimeDataService) KieServerApplicationComponentsService(org.kie.server.services.api.KieServerApplicationComponentsService) FormManagerService(org.jbpm.kie.services.impl.FormManagerService) UserTaskAdminServiceBase(org.kie.server.services.jbpm.admin.UserTaskAdminServiceBase) DeploymentDescriptorManager(org.kie.internal.runtime.manager.deploy.DeploymentDescriptorManager) UserInfo(org.kie.internal.task.api.UserInfo) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) DeploymentDescriptorManagerUtil(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorManagerUtil) AdvanceRuntimeDataServiceImpl(org.jbpm.kie.services.impl.AdvanceRuntimeDataServiceImpl) ReleaseId(org.kie.api.builder.ReleaseId) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) ProcessInstanceMigrationServiceImpl(org.jbpm.kie.services.impl.admin.ProcessInstanceMigrationServiceImpl) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) RuntimeDataServiceImpl(org.jbpm.kie.services.impl.RuntimeDataServiceImpl) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ExecutorServiceFactory(org.jbpm.executor.ExecutorServiceFactory) ElytronIdentityProvider(org.kie.server.services.impl.security.ElytronIdentityProvider) ServiceLoader(java.util.ServiceLoader) JMSUserGroupAdapter(org.kie.server.services.jbpm.security.JMSUserGroupAdapter) MergeMode(org.kie.internal.runtime.conf.MergeMode) ElytronUserGroupCallbackImpl(org.kie.server.services.jbpm.security.ElytronUserGroupCallbackImpl) FileNotFoundException(java.io.FileNotFoundException) KieContainerInstance(org.kie.server.services.api.KieContainerInstance) PersistenceUnitInfoLoader(org.kie.server.services.jbpm.jpa.PersistenceUnitInfoLoader) List(java.util.List) UserTaskAdminService(org.jbpm.services.api.admin.UserTaskAdminService) KieSessionModel(org.kie.api.builder.model.KieSessionModel) RuntimeStrategy(org.kie.internal.runtime.conf.RuntimeStrategy) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) KModuleDeploymentService(org.jbpm.kie.services.impl.KModuleDeploymentService) Pattern(java.util.regex.Pattern) ProcessServiceImpl(org.jbpm.kie.services.impl.ProcessServiceImpl) ProcessService(org.jbpm.services.api.ProcessService) PreUndeployOperations(org.jbpm.kie.services.impl.utils.PreUndeployOperations) KieServerConfig(org.kie.server.api.model.KieServerConfig) HashMap(java.util.HashMap) Function(java.util.function.Function) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) HashSet(java.util.HashSet) KieServerExtension(org.kie.server.services.api.KieServerExtension) ExecutorService(org.kie.api.executor.ExecutorService) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) Charset(java.nio.charset.Charset) ProcessAdminServiceBase(org.kie.server.services.jbpm.admin.ProcessAdminServiceBase) Severity(org.kie.server.api.model.Severity) UserTaskService(org.jbpm.services.api.UserTaskService) EntityManagerFactoryManager(org.jbpm.runtime.manager.impl.jpa.EntityManagerFactoryManager) MarshallerFactory(org.kie.server.api.marshalling.MarshallerFactory) Logger(org.slf4j.Logger) UserTaskAdminServiceImpl(org.jbpm.kie.services.impl.admin.UserTaskAdminServiceImpl) KieServerEnvironment(org.kie.server.api.KieServerEnvironment) FileInputStream(java.io.FileInputStream) DefinitionService(org.jbpm.services.api.DefinitionService) TimeUnit(java.util.concurrent.TimeUnit) RuntimeDataService(org.jbpm.services.api.RuntimeDataService) KieContainerCommandService(org.kie.server.services.api.KieContainerCommandService) BPMN2DataServiceImpl(org.jbpm.kie.services.impl.bpmn2.BPMN2DataServiceImpl) KieServerImpl(org.kie.server.services.impl.KieServerImpl) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) InputStream(java.io.InputStream) BPMN2DataServiceImpl(org.jbpm.kie.services.impl.bpmn2.BPMN2DataServiceImpl) UserTaskAdminServiceImpl(org.jbpm.kie.services.impl.admin.UserTaskAdminServiceImpl) Matcher(java.util.regex.Matcher) UserTaskAdminServiceBase(org.kie.server.services.jbpm.admin.UserTaskAdminServiceBase) UserInfo(org.kie.internal.task.api.UserInfo) UserGroupCallback(org.kie.api.task.UserGroupCallback) AdvanceRuntimeDataServiceImpl(org.jbpm.kie.services.impl.AdvanceRuntimeDataServiceImpl) KModuleDeploymentService(org.jbpm.kie.services.impl.KModuleDeploymentService) ProcessServiceImpl(org.jbpm.kie.services.impl.ProcessServiceImpl) ProcessInstanceMigrationServiceImpl(org.jbpm.kie.services.impl.admin.ProcessInstanceMigrationServiceImpl) QueryServiceImpl(org.jbpm.kie.services.impl.query.QueryServiceImpl) RuntimeManagerFactoryImpl(org.jbpm.runtime.manager.impl.RuntimeManagerFactoryImpl) TaskService(org.kie.api.task.TaskService) UserTaskService(org.jbpm.services.api.UserTaskService) ExecutorImpl(org.jbpm.executor.impl.ExecutorImpl) KieServerConfig(org.kie.server.api.model.KieServerConfig) UserTaskServiceImpl(org.jbpm.kie.services.impl.UserTaskServiceImpl) ProcessInstanceAdminServiceImpl(org.jbpm.kie.services.impl.admin.ProcessInstanceAdminServiceImpl) ProcessAdminServiceBase(org.kie.server.services.jbpm.admin.ProcessAdminServiceBase) AdvanceRuntimeDataServiceImpl(org.jbpm.kie.services.impl.AdvanceRuntimeDataServiceImpl) RuntimeDataServiceImpl(org.jbpm.kie.services.impl.RuntimeDataServiceImpl) EntityManagerFactory(javax.persistence.EntityManagerFactory) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) JMSUserGroupAdapter(org.kie.server.services.jbpm.security.JMSUserGroupAdapter)

Example 3 with DeploymentService

use of org.jbpm.services.api.DeploymentService in project droolsjbpm-integration by kiegroup.

the class JbpmKieServerExtensionTest method init.

@Before
public void init() {
    KieServerEnvironment.setServerId(UUID.randomUUID().toString());
    context = new KieServerRegistryImpl();
    context.registerStateRepository(new KieServerStateFileRepository(new File("target")));
    kieServices = (KieServicesImpl) KieServices.Factory.get();
    when(kieServerInfo.getMode()).thenAnswer(invocationOnMock -> mode);
    when(kieServer.getInfo()).thenReturn(new ServiceResponse<KieServerInfo>(KieServiceResponse.ResponseType.SUCCESS, "", kieServerInfo));
    extension = spy(new JbpmKieServerExtension() {

        {
            this.deploymentService = JbpmKieServerExtensionTest.this.deploymentService;
            this.runtimeDataService = JbpmKieServerExtensionTest.this.runtimeDataService;
            this.kieServer = JbpmKieServerExtensionTest.this.kieServer;
        }
    });
    when(deploymentService.isDeployed(anyString())).thenAnswer((Answer<Boolean>) invocation -> deployed);
    doAnswer(invocation -> {
        deployed = false;
        return null;
    }).when(deploymentService).undeploy(any(), any());
    doAnswer(invocation -> {
        deployed = false;
        return null;
    }).when(deploymentService).undeploy(any());
    doAnswer((Answer<Void>) invocation -> {
        deploymentUnit = (DeploymentUnit) invocation.getArguments()[0];
        deployed = true;
        return null;
    }).when(deploymentService).deploy(any());
    when(deploymentService.getDeployedUnit(anyString())).thenAnswer((Answer<DeployedUnit>) invocation -> {
        deployedUnit = new DeployedUnitImpl(deploymentUnit);
        runimeManager = mock(RuntimeManager.class);
        engine = mock(RuntimeEngine.class);
        when(runimeManager.getRuntimeEngine(any())).thenReturn(engine);
        session = mock(KieSession.class);
        when(engine.getKieSession()).thenReturn(session);
        deployedUnit.setRuntimeManager(runimeManager);
        return deployedUnit;
    });
    extension.setQueryService(queryService);
    extension.setContext(context);
    when(runtimeDataService.getProcessInstancesByDeploymentId(anyString(), anyList(), any())).thenReturn(activeProcessInstances);
}
Also used : InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) QueryService(org.jbpm.services.api.query.QueryService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) KieServerConstants(org.kie.server.api.KieServerConstants) KieServerMode(org.kie.server.api.model.KieServerMode) DeployedUnitImpl(org.jbpm.kie.services.impl.DeployedUnitImpl) ServiceResponse(org.kie.server.api.model.ServiceResponse) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) After(org.junit.After) Mockito.doAnswer(org.mockito.Mockito.doAnswer) KieSession(org.kie.api.runtime.KieSession) Mockito.doReturn(org.mockito.Mockito.doReturn) Message(org.kie.server.api.model.Message) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) UUID(java.util.UUID) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) KieServerRegistryImpl(org.kie.server.services.impl.KieServerRegistryImpl) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) KieModule(org.kie.api.builder.KieModule) DependencyFilter(org.appformer.maven.support.DependencyFilter) KieServerInfo(org.kie.server.api.model.KieServerInfo) EntityManagerFactory(javax.persistence.EntityManagerFactory) Assert.assertFalse(org.junit.Assert.assertFalse) KieServerStateFileRepository(org.kie.server.services.impl.storage.file.KieServerStateFileRepository) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) KieServicesImpl(org.drools.compiler.kie.builder.impl.KieServicesImpl) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Function(java.util.function.Function) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) Captor(org.mockito.Captor) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) ArrayList(java.util.ArrayList) DeploymentService(org.jbpm.services.api.DeploymentService) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) Charset(java.nio.charset.Charset) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) KieContainerStatus(org.kie.server.api.model.KieContainerStatus) Before(org.junit.Before) KieFileSystem(org.kie.api.builder.KieFileSystem) InternalKieContainer(org.drools.core.impl.InternalKieContainer) KieServiceResponse(org.kie.server.api.model.KieServiceResponse) Assert.assertNotNull(org.junit.Assert.assertNotNull) KieServerEnvironment(org.kie.server.api.KieServerEnvironment) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) RuntimeDataService(org.jbpm.services.api.RuntimeDataService) PersistenceUnitExtensionsLoaderMock(org.kie.server.services.jbpm.jpa.PersistenceUnitExtensionsLoaderMock) ReleaseId(org.kie.server.api.model.ReleaseId) Assert(org.junit.Assert) KieServerImpl(org.kie.server.services.impl.KieServerImpl) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KieServerStateFileRepository(org.kie.server.services.impl.storage.file.KieServerStateFileRepository) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) KieServerInfo(org.kie.server.api.model.KieServerInfo) DeployedUnitImpl(org.jbpm.kie.services.impl.DeployedUnitImpl) File(java.io.File) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KieServerRegistryImpl(org.kie.server.services.impl.KieServerRegistryImpl) Before(org.junit.Before)

Example 4 with DeploymentService

use of org.jbpm.services.api.DeploymentService in project jbpm-work-items by kiegroup.

the class JBPMApplication method deployAndValidate.

@Bean
CommandLineRunner deployAndValidate() {
    return new CommandLineRunner() {

        @Autowired
        private DeploymentService deploymentService;

        @Autowired
        private RuntimeDataService runtimeDataService;

        @Autowired
        private ProcessService processService;

        @Override
        public void run(String... strings) throws Exception {
            KModuleDeploymentUnit unit = null;
            if (strings.length > 0) {
                String arg = strings[0];
                LOGGER.info("About to deploy : {}", arg);
                String[] gav = arg.split(":");
                unit = new KModuleDeploymentUnit(gav[0], gav[1], gav[2]);
                deploymentService.deploy(unit);
                LOGGER.info("{} successfully deployed", arg);
            }
            LOGGER.info("Available processes:");
            Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
            for (ProcessDefinition def : processes) {
                LOGGER.info("\t{} (with id '{})", def.getName(), def.getId());
            }
            if (unit != null && !processes.isEmpty()) {
                String processId = processes.iterator().next().getId();
                LOGGER.info("About to start process with id {}", processId);
                long processInstanceId = processService.startProcess(unit.getIdentifier(), processId);
                LOGGER.info("Started instance of {} process with id {}", processId, processInstanceId);
                processService.abortProcessInstance(processInstanceId);
                LOGGER.info("Aborted instance with id {}", processInstanceId);
            }
            LOGGER.info("========= Verification completed successfully =========");
        }
    };
}
Also used : RuntimeDataService(org.jbpm.services.api.RuntimeDataService) CommandLineRunner(org.springframework.boot.CommandLineRunner) DeploymentService(org.jbpm.services.api.DeploymentService) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) QueryContext(org.kie.api.runtime.query.QueryContext) ProcessService(org.jbpm.services.api.ProcessService) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) Bean(org.springframework.context.annotation.Bean)

Example 5 with DeploymentService

use of org.jbpm.services.api.DeploymentService in project droolsjbpm-integration by kiegroup.

the class KafkaServerExtension method init.

@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
    if (initialized.get()) {
        logger.warn("Kafka extension already initialized");
        return;
    }
    initProperties();
    factory = buildEventProcessorFactory();
    KafkaServerProducer.init(factory, this::getKafkaProducer);
    DeploymentDescriptorManager.addDescriptorLocation("classpath:/META-INF/kafka-deployment-descriptor-defaults.xml");
    KieServerExtension jbpmExt = registry.getServerExtension(JbpmKieServerExtension.EXTENSION_NAME);
    if (jbpmExt == null) {
        logger.warn("Extension " + JbpmKieServerExtension.EXTENSION_NAME + " is required");
        return;
    }
    ProcessService processService = null;
    for (Object service : jbpmExt.getServices()) {
        if (deploymentService == null && DeploymentService.class.isAssignableFrom(service.getClass())) {
            deploymentService = (ListenerSupport) service;
        } else if (processService == null && ProcessService.class.isAssignableFrom(service.getClass())) {
            processService = (ProcessService) service;
        }
        if (deploymentService != null && processService != null) {
            break;
        }
    }
    if (deploymentService == null) {
        throw new IllegalStateException("Cannot find deployment service");
    }
    if (processService == null) {
        throw new IllegalStateException("Cannot find process service");
    }
    kafkaServerConsumer = new KafkaServerConsumer(factory, this::getKafkaConsumer, processService);
    deploymentService.addListener(this);
    initialized.set(true);
}
Also used : JbpmKieServerExtension(org.kie.server.services.jbpm.JbpmKieServerExtension) KieServerExtension(org.kie.server.services.api.KieServerExtension) DeploymentService(org.jbpm.services.api.DeploymentService) ProcessService(org.jbpm.services.api.ProcessService)

Aggregations

DeploymentService (org.jbpm.services.api.DeploymentService)6 ProcessService (org.jbpm.services.api.ProcessService)5 RuntimeDataService (org.jbpm.services.api.RuntimeDataService)5 EntityManagerFactory (javax.persistence.EntityManagerFactory)3 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)3 QueryContext (org.kie.api.runtime.query.QueryContext)3 IOException (java.io.IOException)2 Charset (java.nio.charset.Charset)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Function (java.util.function.Function)2 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)2 IOUtils (org.apache.commons.io.IOUtils)2 InternalKieContainer (org.drools.core.impl.InternalKieContainer)2 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)2 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)2 QueryService (org.jbpm.services.api.query.QueryService)2 KieModuleMetaData (org.kie.scanner.KieModuleMetaData)2