Search in sources :

Example 1 with ReleaseIdImpl

use of org.kie.util.maven.support.ReleaseIdImpl in project drools by kiegroup.

the class KieModuleRepoTest method newerVersionDeployOverwritesTest.

// 2. simultaneous deploy requests
// - multitenant UI
// - duplicate REST requests
@Test(timeout = 5000)
public void newerVersionDeployOverwritesTest() throws Exception {
    // setup
    final ReleaseIdImpl releaseId = new ReleaseIdImpl("org", "deployTwiceAfterUpdateDependency", "1.0");
    final InternalKieModule originalOldKieModule = new InternalKieModuleStub();
    final ReleaseId dependentReleaseid = new ReleaseIdImpl("org", "deployTwiceAfterUpdate", "1.0");
    final KieContainerImpl kieContainer = createMockKieContainer(dependentReleaseid, kieModuleRepo);
    // 1. deploy
    kieModuleRepo.store(originalOldKieModule);
    // 2. another project is dependent on this project
    kieContainer.updateDependencyToVersion(releaseId, releaseId);
    final InternalKieModule newKieModule = mock(InternalKieModule.class);
    when(newKieModule.getReleaseId()).thenReturn(releaseId);
    when(newKieModule.getCreationTimestamp()).thenReturn(10l);
    final CyclicBarrier storeOperationBarrier = new CyclicBarrier(2);
    final CyclicBarrier storeSerializationBarrier = new CyclicBarrier(2);
    final CyclicBarrier threadsFinishedBarrier = new CyclicBarrier(3);
    final Runnable deployRunnable = () -> {
        waitFor(storeOperationBarrier);
        // Second thread waits with store until the first one finishes with it.
        if (Thread.currentThread().getName().equals("two")) {
            waitFor(storeSerializationBarrier);
        }
        kieModuleRepo.store(newKieModule);
        if (Thread.currentThread().getName().equals("one")) {
            waitFor(storeSerializationBarrier);
        }
        waitFor(threadsFinishedBarrier);
    };
    final ExecutorService executor = Executors.newFixedThreadPool(2);
    try {
        // 2. remove and redploy
        final Thread deployThread = new Thread(deployRunnable);
        deployThread.setName("one");
        executor.submit(deployThread);
        final Thread secondDeployThread = new Thread(deployRunnable);
        secondDeployThread.setName("two");
        executor.submit(secondDeployThread);
        waitFor(threadsFinishedBarrier);
    } finally {
        executor.shutdownNow();
    }
    // never gets this far, but this is a good check
    final KieModule oldKieModule = kieModuleRepo.oldKieModules.get(releaseId);
    final long oldKieModuleTimeStamp = ((InternalKieModule) oldKieModule).getCreationTimestamp();
    final long originalKieModuleTimestamp = originalOldKieModule.getCreationTimestamp();
    assertEquals("The old kie module in the repo is not the originally deployed module!", originalKieModuleTimestamp, oldKieModuleTimeStamp);
}
Also used : ReleaseIdImpl(org.kie.util.maven.support.ReleaseIdImpl) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) ExecutorService(java.util.concurrent.ExecutorService) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test)

Example 2 with ReleaseIdImpl

use of org.kie.util.maven.support.ReleaseIdImpl in project drools by kiegroup.

the class KieModuleDeploymentHelperImpl method createKieJarAndDeployToMaven.

@Override
public void createKieJarAndDeployToMaven(String groupId, String artifactId, String version, String kbaseName, String ksessionName, List<String> resourceFilePaths) {
    ReleaseId releaseId = new ReleaseIdImpl(groupId, artifactId, version);
    internalCreateAndDeployKjarToMaven(releaseId, kbaseName, ksessionName, resourceFilePaths, null, null);
}
Also used : ReleaseIdImpl(org.kie.util.maven.support.ReleaseIdImpl) ReleaseId(org.kie.api.builder.ReleaseId)

Example 3 with ReleaseIdImpl

use of org.kie.util.maven.support.ReleaseIdImpl in project drools by kiegroup.

the class KieModuleDeploymentHelperImpl method internalCreateKieJar.

/**
 * Create a KJar for deployment;
 *
 * @param releaseId Release (deployment) id.
 * @param resourceFilePaths List of resource file paths
 * @param kbaseName The name of the {@link KieBase}
 * @param ksessionName The name of the {@link KieSession}.
 * @param dependencies List of dependencies to add
 *
 * @return The {@link InternalKieModule} which represents the KJar.
 */
private synchronized KieModule internalCreateKieJar(ReleaseId releaseId, String kbaseName, String ksessionName, List<String> resourceFilePaths, List<Class<?>> classes, List<String> dependencies) {
    ReleaseId[] releaseIds = {};
    if (dependencies != null && dependencies.size() > 0) {
        List<ReleaseId> depReleaseIds = new ArrayList<>();
        for (String dep : dependencies) {
            String[] gav = dep.split(":");
            if (gav.length != 3) {
                throw new IllegalArgumentException("Dependendency id '" + dep + "' does not conform to the format <groupId>:<artifactId>:<version> (Classifiers are not accepted).");
            }
            depReleaseIds.add(new ReleaseIdImpl(gav[0], gav[1], gav[2]));
        }
        releaseIds = depReleaseIds.toArray(new ReleaseId[depReleaseIds.size()]);
    }
    config.pomText = getPomText(releaseId, releaseIds);
    KieFileSystem kfs = createKieFileSystemWithKProject();
    kfs.writePomXML(this.config.pomText);
    List<KJarResource> resourceFiles = loadResources(resourceFilePaths);
    for (KJarResource resource : resourceFiles) {
        kfs.write("src/main/resources/" + kbaseName + "/" + resource.name, resource.content);
    }
    if (classes != null) {
        for (Class<?> userClass : classes) {
            addClass(userClass, kfs);
        }
    }
    KieBuilder kieBuilder = config.getKieServicesInstance().newKieBuilder(kfs);
    int buildMsgs = 0;
    for (Message buildMsg : kieBuilder.buildAll().getResults().getMessages()) {
        System.out.println(buildMsg.getPath() + " : " + buildMsg.getText());
        ++buildMsgs;
    }
    if (buildMsgs > 0) {
        throw new RuntimeException("Unable to build KieModule, see the " + buildMsgs + " messages above.");
    }
    return kieBuilder.getKieModule();
}
Also used : ReleaseIdImpl(org.kie.util.maven.support.ReleaseIdImpl) KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) ArrayList(java.util.ArrayList) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder)

Example 4 with ReleaseIdImpl

use of org.kie.util.maven.support.ReleaseIdImpl in project drools by kiegroup.

the class AccumulateTest method testImportAccumulateFunction.

private void testImportAccumulateFunction(final String drl) {
    final ReleaseId releaseId = new ReleaseIdImpl("foo", "bar", "1.0");
    KieUtil.getKieModuleFromDrls(releaseId, kieBaseTestConfiguration, drl);
    final KieContainer kc = KieServices.get().newKieContainer(releaseId);
    final KieSession ksession = kc.newKieSession();
    try {
        final AgendaEventListener ael = mock(AgendaEventListener.class);
        ksession.addEventListener(ael);
        ksession.insert("x");
        ksession.fireAllRules();
        final ArgumentCaptor<AfterMatchFiredEvent> ac = ArgumentCaptor.forClass(AfterMatchFiredEvent.class);
        verify(ael).afterMatchFired(ac.capture());
        assertThat(ac.getValue().getMatch().getDeclarationValue("$v"), is(1));
    } finally {
        ksession.dispose();
    }
}
Also used : ReleaseIdImpl(org.kie.util.maven.support.ReleaseIdImpl) AgendaEventListener(org.kie.api.event.rule.AgendaEventListener) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) AfterMatchFiredEvent(org.kie.api.event.rule.AfterMatchFiredEvent) KieContainer(org.kie.api.runtime.KieContainer)

Example 5 with ReleaseIdImpl

use of org.kie.util.maven.support.ReleaseIdImpl in project drools by kiegroup.

the class PMMLRuntimeFactoryInternalTest method testGetPMMLRuntimeFromFileAndReleaseId.

@Test
public void testGetPMMLRuntimeFromFileAndReleaseId() {
    File pmmlFile = getFile("MiningModel_Mixed.pmml");
    ReleaseId releaseId = new ReleaseIdImpl("org.dummy:dummy-artifact:1-0");
    PMMLRuntime retrieved = PMMLRuntimeFactoryInternal.getPMMLRuntime(pmmlFile, releaseId);
    commonValidatePMMLRuntime(retrieved);
}
Also used : ReleaseIdImpl(org.kie.util.maven.support.ReleaseIdImpl) ReleaseId(org.kie.api.builder.ReleaseId) PMMLRuntime(org.kie.pmml.api.runtime.PMMLRuntime) File(java.io.File) FileUtils.getFile(org.kie.test.util.filesystem.FileUtils.getFile) Test(org.junit.Test)

Aggregations

ReleaseIdImpl (org.kie.util.maven.support.ReleaseIdImpl)16 Test (org.junit.Test)9 ReleaseId (org.kie.api.builder.ReleaseId)8 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)5 KieModule (org.kie.api.builder.KieModule)3 ArrayList (java.util.ArrayList)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 ExecutorService (java.util.concurrent.ExecutorService)2 KieBuilder (org.kie.api.builder.KieBuilder)2 KieFileSystem (org.kie.api.builder.KieFileSystem)2 ComparableVersion (org.kie.api.builder.ReleaseIdComparator.ComparableVersion)2 File (java.io.File)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Field (org.dmg.pmml.Field)1