Search in sources :

Example 1 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.

the class AbstractDeploymentService method commonDeploy.

public void commonDeploy(DeploymentUnit unit, DeployedUnitImpl deployedUnit, RuntimeEnvironment environemnt, KieContainer kieContainer) {
    synchronized (this) {
        if (deploymentsMap.containsKey(unit.getIdentifier())) {
            DeployedUnit deployed = deploymentsMap.remove(unit.getIdentifier());
            RuntimeManager manager = deployed.getRuntimeManager();
            manager.close();
        }
        RuntimeManager manager = null;
        deploymentsMap.put(unit.getIdentifier(), deployedUnit);
        ((SimpleRuntimeEnvironment) environemnt).addToEnvironment("IdentityProvider", identityProvider);
        ((SimpleRuntimeEnvironment) environemnt).addToEnvironment("Active", deployedUnit.isActive());
        try {
            switch(unit.getStrategy()) {
                case SINGLETON:
                    manager = managerFactory.newSingletonRuntimeManager(environemnt, unit.getIdentifier());
                    break;
                case PER_REQUEST:
                    manager = managerFactory.newPerRequestRuntimeManager(environemnt, unit.getIdentifier());
                    break;
                case PER_PROCESS_INSTANCE:
                    manager = managerFactory.newPerProcessInstanceRuntimeManager(environemnt, unit.getIdentifier());
                    break;
                case PER_CASE:
                    manager = managerFactory.newPerCaseRuntimeManager(environemnt, unit.getIdentifier());
                    break;
                default:
                    throw new IllegalArgumentException("Invalid strategy " + unit.getStrategy());
            }
            if (!deployedUnit.isActive()) {
                ((InternalRuntimeManager) manager).deactivate();
            }
            ((InternalRuntimeManager) manager).setKieContainer(kieContainer);
            deployedUnit.setRuntimeManager(manager);
            DeploymentDescriptor descriptor = ((InternalRuntimeManager) manager).getDeploymentDescriptor();
            List<String> requiredRoles = descriptor.getRequiredRoles(DeploymentDescriptor.TYPE_EXECUTE);
            if (requiredRoles != null && !requiredRoles.isEmpty()) {
                ((InternalRuntimeManager) manager).setSecurityManager(new IdentityRolesSecurityManager(identityProvider, requiredRoles));
            }
            notifyOnDeploy(unit, deployedUnit);
        } catch (Throwable e) {
            deploymentsMap.remove(unit.getIdentifier());
            if (manager != null) {
                manager.close();
            }
            notifyOnUnDeploy(unit, deployedUnit);
            throw new RuntimeException(e);
        }
    }
}
Also used : SimpleRuntimeEnvironment(org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment) IdentityRolesSecurityManager(org.jbpm.kie.services.impl.security.IdentityRolesSecurityManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager)

Example 2 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.

the class KModuleDeploymentService method addClassToDeployedUnit.

protected void addClassToDeployedUnit(Class deploymentClass, DeployedUnitImpl deployedUnit) {
    if (deploymentClass != null) {
        DeploymentUnit unit = deployedUnit.getDeploymentUnit();
        Boolean limitClasses = false;
        if (unit != null) {
            DeploymentDescriptor depDesc = ((KModuleDeploymentUnit) unit).getDeploymentDescriptor();
            if (depDesc != null) {
                limitClasses = depDesc.getLimitSerializationClasses();
            }
        }
        if (limitClasses != null && limitClasses) {
            filterClassesAddedToDeployedUnit(deployedUnit, deploymentClass);
        } else {
            logger.debug("Loaded {} onto the classpath from deployment {}", deploymentClass.getName(), unit.getIdentifier());
            deployedUnit.addClass(deploymentClass);
        }
    }
}
Also used : DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit)

Example 3 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.

the class AbstractCaseServicesBaseTest method createKieJar.

protected InternalKieModule createKieJar(KieServices ks, ReleaseId releaseId, List<String> resources, Map<String, String> extraResources) {
    KieFileSystem kfs = createKieFileSystemWithKProject(ks);
    kfs.writePomXML(getPom(releaseId));
    DeploymentDescriptor customDescriptor = createDeploymentDescriptor();
    if (extraResources == null) {
        extraResources = new HashMap<String, String>();
    }
    extraResources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
    for (String resource : resources) {
        kfs.write("src/main/resources/KBase-test/" + resource, ResourceFactory.newClassPathResource(resource));
    }
    if (extraResources != null) {
        for (Map.Entry<String, String> entry : extraResources.entrySet()) {
            kfs.write(entry.getKey(), ResourceFactory.newByteArrayResource(entry.getValue().getBytes()));
        }
    }
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    if (!kieBuilder.buildAll().getResults().getMessages().isEmpty()) {
        for (Message message : kieBuilder.buildAll().getResults().getMessages()) {
            logger.error("Error Message: ({}) {}", message.getPath(), message.getText());
        }
        throw new RuntimeException("There are errors builing the package, please check your knowledge assets!");
    }
    return (InternalKieModule) kieBuilder.getKieModule();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) KieBuilder(org.kie.api.builder.KieBuilder) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) HashMap(java.util.HashMap) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 4 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.

the class AbstractCaseServicesBaseTest method prepareDeploymentUnit.

protected DeploymentUnit prepareDeploymentUnit() {
    assertThat(deploymentService).isNotNull();
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    final DeploymentDescriptor descriptor = new DeploymentDescriptorImpl();
    descriptor.getBuilder().addEventListener(new NamedObjectModel("mvel", "processIdentity", "new org.jbpm.kie.services.impl.IdentityProviderAwareProcessListener(ksession)"));
    deploymentUnit.setDeploymentDescriptor(descriptor);
    deploymentUnit.setStrategy(RuntimeStrategy.PER_CASE);
    deploymentService.deploy(deploymentUnit);
    return deploymentUnit;
}
Also used : NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentDescriptorImpl(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit)

Example 5 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.

the class AbstractCaseServicesBaseTest method createDeploymentDescriptor.

protected DeploymentDescriptor createDeploymentDescriptor() {
    // add this listener by default
    listenerMvelDefinitions.add("new org.jbpm.casemgmt.impl.util.TrackingCaseEventListener()");
    DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
    DeploymentDescriptorBuilder ddBuilder = customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_CASE).addMarshalingStrategy(new ObjectModel("mvel", CaseMarshallerFactory.builder().withDoc().toString())).addWorkItemHandler(new NamedObjectModel("mvel", "StartCaseInstance", "new org.jbpm.casemgmt.impl.wih.StartCaseWorkItemHandler(ksession)"));
    listenerMvelDefinitions.forEach(listenerDefinition -> ddBuilder.addEventListener(new ObjectModel("mvel", listenerDefinition)));
    getProcessListeners().forEach(listener -> ddBuilder.addEventListener(listener));
    getWorkItemHandlers().forEach(listener -> ddBuilder.addWorkItemHandler(listener));
    return customDescriptor;
}
Also used : NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentDescriptorImpl(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl) DeploymentDescriptorBuilder(org.kie.internal.runtime.conf.DeploymentDescriptorBuilder)

Aggregations

DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)98 Test (org.junit.Test)55 NamedObjectModel (org.kie.internal.runtime.conf.NamedObjectModel)43 ObjectModel (org.kie.internal.runtime.conf.ObjectModel)34 HashMap (java.util.HashMap)27 DeploymentDescriptorImpl (org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl)26 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)23 KieServices (org.kie.api.KieServices)22 ArrayList (java.util.ArrayList)21 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)21 ReleaseId (org.kie.api.builder.ReleaseId)21 ByteArrayInputStream (java.io.ByteArrayInputStream)16 File (java.io.File)13 KieMavenRepository (org.kie.scanner.KieMavenRepository)12 FileOutputStream (java.io.FileOutputStream)11 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)11 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)10 InputStream (java.io.InputStream)9 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)9 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)8