use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.
the class ProcessServiceImplTest method testStartAndAbortProcessInExternalTransactions.
protected void testStartAndAbortProcessInExternalTransactions(RuntimeStrategy strategy) throws Exception {
assertNotNull(deploymentService);
KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
customDescriptor.getBuilder().runtimeStrategy(strategy);
deploymentUnit.setDeploymentDescriptor(customDescriptor);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
assertNotNull(processService);
boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
assertTrue(isDeployed);
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
ut.begin();
long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
processService.signalEvent(deploymentUnit.getIdentifier(), "test", null);
ut.commit();
// now let's start another transaction
ut.begin();
processService.abortProcessInstance(processInstanceId);
ut.commit();
try {
processService.getProcessInstance(processInstanceId);
} catch (ProcessInstanceNotFoundException e) {
// expected
}
}
use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.
the class ProcessServiceImplTest method testStartAndGetProcessInExternalTransactions.
protected void testStartAndGetProcessInExternalTransactions(RuntimeStrategy strategy) throws Exception {
assertNotNull(deploymentService);
KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
customDescriptor.getBuilder().runtimeStrategy(strategy);
deploymentUnit.setDeploymentDescriptor(customDescriptor);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
assertNotNull(processService);
boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
assertTrue(isDeployed);
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
ut.begin();
long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
ProcessInstance pi = processService.getProcessInstance(processInstanceId);
assertNotNull(pi);
processService.abortProcessInstance(processInstanceId);
ut.commit();
try {
processService.getProcessInstance(processInstanceId);
} catch (ProcessInstanceNotFoundException e) {
// expected
}
}
use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.
the class InjectableRegisterableItemsFactory method getAuditLoggerInstance.
/**
* Provides AuditLogger implementation, JPA or JMS.
* JPA is the default one and JMS requires to have configuration file (.properties)
* to be available on classpath under 'jbpm.audit.jms.properties' name.
* This file must have following properties defined:
* <ul>
* <li>jbpm.audit.jms.connection.factory.jndi - JNDI name of the connection factory to look up - type String</li>
* <li>jbpm.audit.jms.queue.jndi - JNDI name of the queue to look up - type String</li>
* </ul>
* @return instance of the audit logger
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected AbstractAuditLogger getAuditLoggerInstance(RuntimeEngine engine) {
DeploymentDescriptor descriptor = getRuntimeManager().getDeploymentDescriptor();
AbstractAuditLogger auditLogger = null;
if ("true".equals(System.getProperty("jbpm.audit.jms.enabled")) || descriptor.getAuditMode() == AuditMode.JMS) {
try {
Properties properties = new Properties();
properties.load(getRuntimeManager().getEnvironment().getClassLoader().getResourceAsStream("/jbpm.audit.jms.properties"));
auditLogger = AuditLoggerFactory.newJMSInstance((Map) properties);
} catch (IOException e) {
logger.error("Unable to load jms audit properties from {}", "/jbpm.audit.jms.properties", e);
}
auditLogger.setBuilder(getAuditBuilder(engine));
} else if (descriptor.getAuditMode() == AuditMode.JPA) {
if (descriptor.getPersistenceUnit().equals(descriptor.getAuditPersistenceUnit())) {
auditLogger = AuditLoggerFactory.newJPAInstance(engine.getKieSession().getEnvironment());
} else {
auditLogger = new JPAWorkingMemoryDbLogger(EntityManagerFactoryManager.get().getOrCreate(descriptor.getAuditPersistenceUnit()));
}
auditLogger.setBuilder(getAuditBuilder(engine));
}
return auditLogger;
}
use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.
the class KModuleDeploymentService method boostrapRuntimeEnvironmentBuilder.
/**
* This creates and fills a {@link RuntimeEnvironmentBuilder} instance, which is later used when creating services.
* </p>
* A lot of the logic here is used to process the information in the {@link DeploymentDescriptor} instance, which is
* part of the {@link DeploymentUnit}.
*
* @param deploymentUnit The {@link KModuleDeploymentUnit}, which is filled by the method
* @param deployedUnit The {@link DeployedUnit}, which is also filled by the method
* @param kieContainer The {@link KieContainer}, which contains information needed to fill the above two arguments
* @param mode The {@link MergeMode} used to resolve conflicts in the {@link DeploymentDescriptor}.
* @return A {@link RuntimeEnvironmentBuilder} instance ready for use
*/
protected RuntimeEnvironmentBuilder boostrapRuntimeEnvironmentBuilder(KModuleDeploymentUnit deploymentUnit, DeployedUnit deployedUnit, KieContainer kieContainer, MergeMode mode) {
DeploymentDescriptor descriptor = deploymentUnit.getDeploymentDescriptor();
if (descriptor == null || ((DeploymentDescriptorImpl) descriptor).isEmpty()) {
// skip empty descriptors as its default can override settings
DeploymentDescriptorManager descriptorManager = new DeploymentDescriptorManager("org.jbpm.domain");
List<DeploymentDescriptor> descriptorHierarchy = descriptorManager.getDeploymentDescriptorHierarchy(kieContainer);
descriptor = merger.merge(descriptorHierarchy, mode);
deploymentUnit.setDeploymentDescriptor(descriptor);
} else if (descriptor != null && !deploymentUnit.isDeployed()) {
DeploymentDescriptorManager descriptorManager = new DeploymentDescriptorManager("org.jbpm.domain");
List<DeploymentDescriptor> descriptorHierarchy = descriptorManager.getDeploymentDescriptorHierarchy(kieContainer);
descriptorHierarchy.add(0, descriptor);
descriptor = merger.merge(descriptorHierarchy, mode);
deploymentUnit.setDeploymentDescriptor(descriptor);
}
// first set on unit the strategy
deploymentUnit.setStrategy(descriptor.getRuntimeStrategy());
// setting up runtime environment via builder
RuntimeEnvironmentBuilder builder = null;
if (descriptor.getPersistenceMode() == PersistenceMode.NONE) {
builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder();
} else {
builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder();
}
// populate various properties of the builder
EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(descriptor.getPersistenceUnit());
builder.entityManagerFactory(emf);
Map<String, Object> contaxtParams = new HashMap<String, Object>();
contaxtParams.put("entityManagerFactory", emf);
contaxtParams.put("classLoader", kieContainer.getClassLoader());
// process object models that are globally configured (environment entries, session configuration)
for (NamedObjectModel model : descriptor.getEnvironmentEntries()) {
Object entry = getInstanceFromModel(model, kieContainer, contaxtParams);
builder.addEnvironmentEntry(model.getName(), entry);
}
for (NamedObjectModel model : descriptor.getConfiguration()) {
Object entry = getInstanceFromModel(model, kieContainer, contaxtParams);
builder.addConfiguration(model.getName(), (String) entry);
}
ObjectMarshallingStrategy[] mStrategies = new ObjectMarshallingStrategy[descriptor.getMarshallingStrategies().size() + 1];
int index = 0;
for (ObjectModel model : descriptor.getMarshallingStrategies()) {
Object strategy = getInstanceFromModel(model, kieContainer, contaxtParams);
mStrategies[index] = (ObjectMarshallingStrategy) strategy;
index++;
}
// lastly add the main default strategy
mStrategies[index] = new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT);
builder.addEnvironmentEntry(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, mStrategies);
builder.addEnvironmentEntry("KieDeploymentDescriptor", descriptor);
builder.addEnvironmentEntry("KieContainer", kieContainer);
if (executorService != null) {
builder.addEnvironmentEntry("ExecutorService", executorService);
}
if (identityProvider != null) {
builder.addEnvironmentEntry(EnvironmentName.IDENTITY_PROVIDER, identityProvider);
}
// populate all assets with roles for this deployment unit
List<String> requiredRoles = descriptor.getRequiredRoles(DeploymentDescriptor.TYPE_VIEW);
if (requiredRoles != null && !requiredRoles.isEmpty()) {
for (DeployedAsset desc : deployedUnit.getDeployedAssets()) {
if (desc instanceof ProcessAssetDesc) {
((ProcessAssetDesc) desc).setRoles(requiredRoles);
}
}
}
// Classes 3: classes added from descriptor
List<String> remoteableClasses = descriptor.getClasses();
if (remoteableClasses != null && !remoteableClasses.isEmpty()) {
for (String className : remoteableClasses) {
Class descriptorClass = null;
try {
descriptorClass = kieContainer.getClassLoader().loadClass(className);
logger.debug("Loaded {} into the classpath from deployment descriptor {}", className, kieContainer.getReleaseId().toExternalForm());
} catch (ClassNotFoundException cnfe) {
throw new IllegalArgumentException("Class " + className + " not found in the project");
} catch (NoClassDefFoundError e) {
throw new IllegalArgumentException("Class " + className + " not found in the project");
}
addClassToDeployedUnit(descriptorClass, (DeployedUnitImpl) deployedUnit);
}
}
return builder;
}
use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.
the class DefaultRegisterableItemsFactory method getProcessEventListeners.
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> defaultListeners = new ArrayList<ProcessEventListener>();
DeploymentDescriptor descriptor = getRuntimeManager().getDeploymentDescriptor();
if (descriptor == null) {
// register JPAWorkingMemoryDBLogger
AbstractAuditLogger logger = AuditLoggerFactory.newJPAInstance(runtime.getKieSession().getEnvironment());
logger.setBuilder(getAuditBuilder(runtime));
defaultListeners.add(logger);
} else if (descriptor.getAuditMode() == AuditMode.JPA) {
// register JPAWorkingMemoryDBLogger
AbstractAuditLogger logger = null;
if (descriptor.getPersistenceUnit().equals(descriptor.getAuditPersistenceUnit())) {
logger = AuditLoggerFactory.newJPAInstance(runtime.getKieSession().getEnvironment());
} else {
Environment env = EnvironmentFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, EntityManagerFactoryManager.get().getOrCreate(descriptor.getAuditPersistenceUnit()));
logger = AuditLoggerFactory.newJPAInstance(env);
}
logger.setBuilder(getAuditBuilder(runtime));
defaultListeners.add(logger);
} else if (descriptor.getAuditMode() == AuditMode.JMS) {
try {
if (jmsLogger == null) {
Properties properties = new Properties();
InputStream input = getRuntimeManager().getEnvironment().getClassLoader().getResourceAsStream("/jbpm.audit.jms.properties");
// required for junit test
if (input == null) {
input = getRuntimeManager().getEnvironment().getClassLoader().getResourceAsStream("jbpm.audit.jms.properties");
}
properties.load(input);
logger.debug("Creating AsyncAuditLogProducer {}", properties);
jmsLogger = AuditLoggerFactory.newJMSInstance((Map) properties);
jmsLogger.setBuilder(getAuditBuilder(runtime));
}
defaultListeners.add(jmsLogger);
} catch (IOException e) {
logger.error("Unable to load jms audit properties from {}", "/jbpm.audit.jms.properties", e);
}
}
// add any custom listeners
defaultListeners.addAll(super.getProcessEventListeners(runtime));
// add listeners from descriptor
defaultListeners.addAll(getEventListenerFromDescriptor(runtime, ProcessEventListener.class));
return defaultListeners;
}
Aggregations