0 Replies Latest reply on Aug 29, 2013 4:52 AM by bhillou

    jBPM6 and OSGi deployment/undeployment

      Hello,

       

      I'm trying to understand how to properly setup my RuntimeManager when using OSGi bundle that contain KIE modules. We are actually in the process of upgrading our jBPM 4.4 integration to jBPM 6 so you can imagine we face some interesting challenges We also use Drools quite heavily and love both projects.

       

      From my previous question I got the following answer:

      Serge Huber wrote:

       

      Thanks a lot for your answer, it helps clarify things a bit. Now I have a few more questions. You talk about setting up a module that aggregates all dependencies, but as I'm dealing with OSGi modules, I cannot know in advance which modules will be deployed or not. Isn't there a way to do this dynamically ?

      >What I meant is if you have dependent modules they should be aggregated into single one that will have all those modules defined as dependencies so there will be single unit of deployment that will have access to all required classes and assets. And yes, you can do it dynamically where you'll get >one to one relationship between RuntimeManager and KieContainer. You can create RuntimeManagers (and then close) them on demand - meaning it is completely dynamic. That's the same way jbpm console does it, allows you at any time to deploy or undeploy units (kjars).

       

      I'm wondering if it's necessary to recreate a RuntimeManager on each bundle deployment / undeployment, or can I just change the KieBuilder's dependencies and trigger a buildAll() ? I'm just trying to make sure the minimal amount of work is needed when deploying/undeploying.

       

      Also, how do I add a bundle as a dependency. Do I manually create an OsgiKieModule using something like this ?

       

      OsgiKieModule.create(module.getBundle().getEntry("META-INF/kmodule.xml"));

       

      or is there a service to do this ?

       

      Any examples would be great of course. Currently this is how I setup my environment :

       

              kieFileSystem = kieServices.newKieFileSystem();

              for (org.kie.api.io.Resource kieResource : fileSystemResources) {

                  kieFileSystem.write(kieResource);

              }

       

              kieBuilder = kieServices.newKieBuilder(kieFileSystem);

              kieBuilder.buildAll();

              kieContainer = kieServices.newKieContainer(kieRepository.getDefaultReleaseId());

       

       

              TransactionManager transactionManager = new DroolsSpringTransactionManager(platformTransactionManager);

              Environment env = EnvironmentFactory.newEnvironment();

              env.set(EnvironmentName.APP_SCOPED_ENTITY_MANAGER, em);

              env.set(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER, em);

              env.set("IS_JTA_TRANSACTION", false);

              env.set("IS_SHARED_ENTITY_MANAGER", true);

       

       

              env.set(EnvironmentName.TRANSACTION_MANAGER, transactionManager);

              PersistenceContextManager persistenceContextManager = new DroolsSpringJpaManager(env);

              env.set(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, persistenceContextManager);

              RuntimeEnvironment runtimeEnvironment = RuntimeEnvironmentBuilder.getDefault()

                      .entityManagerFactory(emf)

                      .addEnvironmentEntry(EnvironmentName.TRANSACTION_MANAGER, transactionManager)

                      .addEnvironmentEntry(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, persistenceContextManager)

                      .knowledgeBase(kieContainer.getKieBase())

                      .classLoader(kieContainer.getClassLoader())

                      .registerableItemsFactory(new JahiaKModuleRegisterableItemsFactory(kieContainer, null, peopleAssignmentPipeline))

                      .userGroupCallback(jahiaUserGroupCallback)

                      .get();

              // runtimeManager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);

              runtimeManager = JahiaRuntimeManagerFactoryImpl.getInstance().newSingletonRuntimeManager(runtimeEnvironment);

              runtimeEngine = runtimeManager.getRuntimeEngine(EmptyContext.get());

              taskService = runtimeEngine.getTaskService();

       

      I really appreciate the help I've gotten so far, it has been great

       

      Best regards,

      Serge Huber.