Search in sources :

Example 31 with KieMavenRepository

use of org.kie.scanner.KieMavenRepository in project drools by kiegroup.

the class KieScannerMemoryTest method testScannerMemoryFootprint.

@Test
public void testScannerMemoryFootprint() throws IOException {
    final KieServices kieServices = KieServices.Factory.get();
    final KieMavenRepository repository = KieMavenRepository.getKieMavenRepository();
    final KieModule kieModule = KieUtil.getKieModuleFromDrls(TestConstants.PACKAGE_FUNCTIONAL, KieBaseTestConfiguration.CLOUD_IDENTITY, "rule R when then end");
    final ReleaseId releaseId = kieModule.getReleaseId();
    repository.installArtifact(releaseId, (InternalKieModule) kieModule, MavenUtil.createPomXml(fileManager, releaseId));
    final KieContainer kieContainer = kieServices.newKieContainer(releaseId);
    final KieScanner kieScanner = kieServices.newKieScanner(kieContainer);
    kieScanner.start(20);
    try {
        measureMemoryFootprint(1000, 100, 6, 30);
    } finally {
        kieScanner.stop();
    }
}
Also used : KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 32 with KieMavenRepository

use of org.kie.scanner.KieMavenRepository in project drools by kiegroup.

the class KieScannerMBeanTest method testKScannerMBean.

@Test
public void testKScannerMBean() throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-mbean-test", "1.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kJar1, createKPom(fileManager, releaseId));
    // create a ksesion and check it works as expected
    KieSession ksession = kieContainer.newKieSession("KSession1");
    checkKSession(ksession, "rule1", "rule2");
    KieRepositoryScannerImpl scanner = (KieRepositoryScannerImpl) ks.newKieScanner(kieContainer);
    KieScannerMBeanImpl mBean = (KieScannerMBeanImpl) scanner.getMBean();
    ObjectName mbeanName = mBean.getMBeanName();
    // we want to check that the mbean is register in the server and exposing the correct attribute values
    // so we fetch the attributes from the server
    Assert.assertEquals(releaseId.toExternalForm(), MBeanUtils.getAttribute(mbeanName, "ScannerReleaseId"));
    Assert.assertEquals(releaseId.toExternalForm(), MBeanUtils.getAttribute(mbeanName, "CurrentReleaseId"));
    Assert.assertEquals(InternalKieScanner.Status.STOPPED.toString(), MBeanUtils.getAttribute(mbeanName, "Status"));
    MBeanUtils.invoke(mbeanName, "start", new Object[] { Long.valueOf(10000) }, new String[] { "long" });
    Assert.assertEquals(InternalKieScanner.Status.RUNNING.toString(), MBeanUtils.getAttribute(mbeanName, "Status"));
    MBeanUtils.invoke(mbeanName, "stop", new Object[] {}, new String[] {});
    Assert.assertEquals(InternalKieScanner.Status.STOPPED.toString(), MBeanUtils.getAttribute(mbeanName, "Status"));
    // create a new kjar
    InternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3");
    // deploy it on maven
    repository.installArtifact(releaseId, kJar2, createKPom(fileManager, releaseId));
    MBeanUtils.invoke(mbeanName, "scanNow", new Object[] {}, new String[] {});
    // create a ksesion and check it works as expected
    KieSession ksession2 = kieContainer.newKieSession("KSession1");
    checkKSession(ksession2, "rule2", "rule3");
    MBeanUtils.invoke(mbeanName, "shutdown", new Object[] {}, new String[] {});
    Assert.assertEquals(InternalKieScanner.Status.SHUTDOWN.toString(), MBeanUtils.getAttribute(mbeanName, "Status"));
    ks.getRepository().removeKieModule(releaseId);
}
Also used : KieRepositoryScannerImpl(org.kie.scanner.KieRepositoryScannerImpl) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) ObjectName(javax.management.ObjectName) Test(org.junit.Test) AbstractKieCiTest(org.kie.scanner.AbstractKieCiTest)

Example 33 with KieMavenRepository

use of org.kie.scanner.KieMavenRepository in project drools by kiegroup.

the class MavenDeployTest method testKScannerWithDeployUsingDistributionManagement.

@Test
public void testKScannerWithDeployUsingDistributionManagement() throws IOException {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test-deploy-dist", "1.0-SNAPSHOT");
    Path m2Folder = Files.createTempDirectory("temp-m2-dist");
    Path settingsXmlPath = generateSettingsXml(m2Folder);
    String oldSettingsXmlPath = System.getProperty(CUSTOM_SETTINGS_PROPERTY);
    try {
        System.setProperty(CUSTOM_SETTINGS_PROPERTY, settingsXmlPath.toString());
        MavenSettings.reinitSettings();
        InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
        KieContainer kieContainer = ks.newKieContainer(releaseId);
        KieMavenRepository repository = getKieMavenRepository();
        repository.deployArtifact(releaseId, kJar1, createKPomWithDistributionManagement(m2Folder, releaseId).toFile());
        // create a ksesion and check it works as expected
        KieSession ksession = kieContainer.newKieSession("KSession1");
        checkKSession(ksession, "rule1", "rule2");
        // create a new kjar
        InternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3");
        // deploy it on maven
        repository.deployArtifact(releaseId, kJar2, createKPomWithDistributionManagement(m2Folder, releaseId).toFile());
        // since I am not calling start() on the scanner it means it won't have automatic scheduled scanning
        KieScanner scanner = ks.newKieScanner(kieContainer);
        // scan the maven repo to get the new kjar version and deploy it on the kcontainer
        scanner.scanNow();
        // create a ksesion and check it works as expected
        KieSession ksession2 = kieContainer.newKieSession("KSession1");
        checkKSession(ksession2, "rule2", "rule3");
        ks.getRepository().removeKieModule(releaseId);
    } finally {
        if (oldSettingsXmlPath == null) {
            System.clearProperty(CUSTOM_SETTINGS_PROPERTY);
        } else {
            System.setProperty(CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath);
        }
        MavenSettings.reinitSettings();
    }
}
Also used : Path(java.nio.file.Path) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test) AbstractKieCiTest(org.kie.scanner.AbstractKieCiTest)

Example 34 with KieMavenRepository

use of org.kie.scanner.KieMavenRepository in project drools by kiegroup.

the class MavenDeployTest method testDeploy.

@Test
public void testDeploy() throws IOException {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test-deploy", "1.0-SNAPSHOT");
    Path m2Folder = Files.createTempDirectory("temp-m2");
    Path settingsXmlPath = generateSettingsXml(m2Folder);
    String oldSettingsXmlPath = System.getProperty(CUSTOM_SETTINGS_PROPERTY);
    try {
        System.setProperty(CUSTOM_SETTINGS_PROPERTY, settingsXmlPath.toString());
        MavenSettings.reinitSettings();
        InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
        KieContainer kieContainer = ks.newKieContainer(releaseId);
        KieMavenRepository repository = getKieMavenRepository();
        RemoteRepository remote = createRemoteRepository(m2Folder);
        repository.deployArtifact(remote, releaseId, kJar1, createKPom(m2Folder, releaseId).toFile());
        // create a ksesion and check it works as expected
        KieSession ksession = kieContainer.newKieSession("KSession1");
        checkKSession(ksession, "rule1", "rule2");
        // create a new kjar
        InternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3");
        // deploy it on maven
        repository.deployArtifact(remote, releaseId, kJar2, createKPom(m2Folder, releaseId).toFile());
        // since I am not calling start() on the scanner it means it won't have automatic scheduled scanning
        KieScanner scanner = ks.newKieScanner(kieContainer);
        // scan the maven repo to get the new kjar version and deploy it on the kcontainer
        scanner.scanNow();
        // create a ksesion and check it works as expected
        KieSession ksession2 = kieContainer.newKieSession("KSession1");
        checkKSession(ksession2, "rule2", "rule3");
        ks.getRepository().removeKieModule(releaseId);
    } finally {
        if (oldSettingsXmlPath == null) {
            System.clearProperty(CUSTOM_SETTINGS_PROPERTY);
        } else {
            System.setProperty(CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath);
        }
        MavenSettings.reinitSettings();
    }
}
Also used : Path(java.nio.file.Path) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test) AbstractKieCiTest(org.kie.scanner.AbstractKieCiTest)

Example 35 with KieMavenRepository

use of org.kie.scanner.KieMavenRepository in project jbpm by kiegroup.

the class EJBService method deployKieJar.

private void deployKieJar(KieServices ks, ReleaseId releaseId, List<String> assets, Map<String, String> extraResources) {
    File pom = new File("target/kmodule", "pom.xml");
    pom.getParentFile().mkdirs();
    try {
        FileOutputStream fs = new FileOutputStream(pom);
        fs.write(getPom(releaseId).getBytes());
        fs.close();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    InternalKieModule kJar1 = null;
    if (extraResources == null) {
        kJar1 = createKieJar(ks, releaseId, assets);
    } else {
        kJar1 = createKieJar(ks, releaseId, assets, extraResources);
    }
    KieMavenRepository repository = KieMavenRepository.getKieMavenRepository();
    System.out.println("Local repo is: " + MavenSettings.getSettings().getLocalRepository());
    repository.installArtifact(releaseId, kJar1, pom);
}
Also used : FileOutputStream(java.io.FileOutputStream) KieMavenRepository(org.kie.scanner.KieMavenRepository) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Aggregations

KieMavenRepository (org.kie.scanner.KieMavenRepository)58 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)55 KieServices (org.kie.api.KieServices)54 ReleaseId (org.kie.api.builder.ReleaseId)53 File (java.io.File)51 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)51 FileOutputStream (java.io.FileOutputStream)45 ArrayList (java.util.ArrayList)42 Before (org.junit.Before)32 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)17 HashMap (java.util.HashMap)15 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)15 DeploymentDescriptorImpl (org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl)12 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)12 Test (org.junit.Test)10 KieContainer (org.kie.api.runtime.KieContainer)7 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)5 ObjectModel (org.kie.internal.runtime.conf.ObjectModel)5 IOException (java.io.IOException)4 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)4