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();
}
}
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);
}
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();
}
}
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();
}
}
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);
}
Aggregations