use of org.jbpm.services.api.model.DeployedUnit 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);
}
}
}
use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.
the class EDeploymentTest method testDeploy.
@Test
public void testDeploy() throws Exception {
DeploymentUnit basicKieJar = archive.deployBasicKieJar();
DeployedUnit deployed = deploymentService.getDeployedUnit(basicKieJar.getIdentifier());
Assertions.assertThat(deployed).isNotNull();
Assertions.assertThat(deployed.getDeploymentUnit()).isNotNull();
Assertions.assertThat(deployed.getDeploymentUnit()).isEqualTo(basicKieJar);
Assertions.assertThat(deployed.getRuntimeManager()).isNotNull();
Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
Assertions.assertThat(processes).isNotNull().isNotEmpty();
}
use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.
the class TaskVariablesQueryServiceTest method prepare.
@Before
public void prepare() {
configureServices();
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
File kjar = new File("src/test/resources/kjar-task-vars/task-vars-1.0.jar");
File pom = new File("src/test/resources/kjar-task-vars/pom.xml");
KieMavenRepository repository = getKieMavenRepository();
repository.installArtifact(releaseId, kjar, pom);
ReleaseId releaseIdSales = ks.newReleaseId("org.jbpm.test", "product-sale", "1.0");
File kjarSales = new File("src/test/resources/kjar-sales/product-sale-1.0.jar");
File pomSales = new File("src/test/resources/kjar-sales/pom.xml");
repository.installArtifact(releaseIdSales, kjarSales, pomSales);
assertNotNull(deploymentService);
KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(deploymentUnit);
KModuleDeploymentUnit deploymentUnitSales = new KModuleDeploymentUnit(SALES_GROUP_ID, SALES_ARTIFACT_ID, SALES_VERSION);
DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
customDescriptor.getBuilder().addMarshalingStrategy(new ObjectModel("mvel", "new org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy(\"org.jbpm.test:product-sale:1.0\", classLoader)"));
// disable below line to avoid jpa marshaling of ProductSale variable
deploymentUnitSales.setDeploymentDescriptor(customDescriptor);
deploymentService.deploy(deploymentUnitSales);
deploymentUnitSalesId = deploymentUnitSales.getIdentifier();
DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
assertNotNull(deployed);
assertNotNull(deployed.getDeploymentUnit());
assertNotNull(runtimeDataService);
Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
assertNotNull(processes);
assertEquals(2, processes.size());
deploymentUnitId = deploymentUnit.getIdentifier();
}
use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.
the class DeploymentServiceWithSyncTest method testDeploymentOfProcessesBySyncWithDisabledAttribute.
@Test
public void testDeploymentOfProcessesBySyncWithDisabledAttribute() throws Exception {
CoundDownDeploymentListener countDownListener = configureListener(1, true, false, false, false);
Collection<DeployedUnit> deployed = deploymentService.getDeployedUnits();
assertNotNull(deployed);
assertEquals(0, deployed.size());
KModuleDeploymentUnit unit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
unit.addAttribute("sync", "false");
store.enableDeploymentUnit(unit);
units.add(unit);
countDownListener.waitTillCompleted(4000);
deployed = deploymentService.getDeployedUnits();
assertNotNull(deployed);
assertEquals(0, deployed.size());
}
use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.
the class FilteredKModuleDeploymentServiceTest method testMultipleRemotableInPojoJar.
@Test
public void testMultipleRemotableInPojoJar() {
String groupId = "org.test";
String pojoArtifactId = "jbpm-kie-services-filter-test-pojo";
String projectArtifactId = "jbpm-kie-services-filter-test-project";
String version = VERSION;
KieServices ks = KieServices.Factory.get();
ReleaseId pojoReleaseId = ks.newReleaseId(groupId, pojoArtifactId, VERSION);
// contains two @Remotable classes MyPojo, MyPojo2
File pojojar = new File("src/test/resources/multi-remotable/pojo.jar");
File pojopom = new File(this.getClass().getResource("/multi-remotable/pojo-pom.xml").getFile());
KieMavenRepository.getKieMavenRepository().installArtifact(pojoReleaseId, pojojar, pojopom);
FluentKieModuleDeploymentHelper.newFluentInstance().setGroupId(groupId).setArtifactId(projectArtifactId).setVersion(version).addDependencies(groupId + ":" + pojoArtifactId + ":" + version).createKieJarAndDeployToMaven();
configureServices();
KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(groupId, projectArtifactId, version);
DeploymentDescriptor depDesc = new DeploymentDescriptorImpl().getBuilder().setLimitSerializationClasses(true).get();
deploymentUnit.setDeploymentDescriptor(depDesc);
deploymentService.deploy(deploymentUnit);
DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
Collection<Class<?>> deployedClasses = deployedUnit.getDeployedClasses();
ClassLoader classLoader = deploymentUnit.getKieContainer().getClassLoader();
try {
assertTrue("MyPojo is not added", deployedClasses.contains(classLoader.loadClass("com.sample.MyPojo")));
assertTrue("MyPojo2 is not added", deployedClasses.contains(classLoader.loadClass("com.sample.MyPojo2")));
} catch (ClassNotFoundException e) {
fail(e.getMessage());
}
}
Aggregations