Skip to content

Commit

Permalink
Merge branch 'main' into d7382_multipleKieSessionTests
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco authored Jun 29, 2023
2 parents 140bfc3 + 6fc371a commit 520cdd1
Show file tree
Hide file tree
Showing 14 changed files with 800 additions and 83 deletions.
3 changes: 3 additions & 0 deletions .ci/jenkins/config/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ git:
- name: 8.40.x
seed:
branch: seed-drools-8.40.x
- name: 8.40.x-prod
seed:
branch: seed-drools-8.40.x
seed:
config_file:
git:
Expand Down
1 change: 1 addition & 0 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void createProjectSetupBranchJob() {
KogitoJobTemplate.createPipelineJob(this, jobParams)?.with {
parameters {
stringParam('DROOLS_VERSION', '', 'Drools version')
booleanParam('DEPLOY_ARTIFACTS', true, 'Deploy artifacts')
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions .ci/jenkins/project/Jenkinsfile.setup-branch
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ pipeline {

// Launch the nightly to deploy all artifacts from the branch
stage('Launch the nightly') {
when {
expression { return params.DEPLOY_ARTIFACTS }
}
steps {
script {
def buildParams = getDefaultBuildParams()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@

package org.drools.compiler.kie.builder.impl;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicReference;

import org.drools.compiler.compiler.io.memory.MemoryFileSystem;
import org.drools.compiler.kproject.models.KieModuleModelImpl;
import org.drools.io.InternalResource;
Expand All @@ -33,20 +46,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicReference;

import static org.drools.compiler.kie.builder.impl.KieBuilderImpl.setDefaultsforEmptyKieModule;
import static org.kie.util.maven.support.ReleaseIdImpl.fromPropertiesStream;

Expand All @@ -66,7 +65,7 @@ public class KieRepositoryImpl

public static final KieRepository INSTANCE = new KieRepositoryImpl();

private final KieModuleRepo kieModuleRepo = new KieModuleRepo();
private final KieModuleRepo kieModuleRepo;

public static void setInternalKieScanner(InternalKieScanner scanner) {
synchronized (KieScannerHolder.class) {
Expand Down Expand Up @@ -95,6 +94,10 @@ private static InternalKieScanner getInternalKieScanner() {
}
}

public KieRepositoryImpl() {
kieModuleRepo = new KieModuleRepo();
}

public void setDefaultGAV(ReleaseId releaseId) {
this.defaultGAV.set(releaseId);
}
Expand Down Expand Up @@ -122,26 +125,20 @@ KieModule getOldKieModule(ReleaseId releaseId) {
}

public KieModule getKieModule(ReleaseId releaseId, PomModel pomModel) {
if (kieModuleRepo.isKnownNotKieModule(releaseId)) {
return null;
}

KieModule kieModule = kieModuleRepo.load( KieScannerHolder.kieScanner, releaseId );
if (kieModule != null) {
return kieModule;
if (kieModule == null) {
log.debug("KieModule Lookup. ReleaseId {} was not in cache, checking classpath",
releaseId.toExternalForm());
kieModule = checkClasspathForKieModule(releaseId);
}

log.debug("KieModule Lookup. ReleaseId {} was not in cache, checking classpath",
releaseId.toExternalForm());
kieModule = checkClasspathForKieModule(releaseId);

if (kieModule == null) {
log.debug("KieModule Lookup. ReleaseId {} was not in cache, checking maven repository",
releaseId.toExternalForm());
kieModule = loadKieModuleFromMavenRepo(releaseId, pomModel);
}

return kieModuleRepo.storeKieModule(releaseId, kieModule);
return kieModule;
}

private KieModule checkClasspathForKieModule(ReleaseId releaseId) {
Expand Down Expand Up @@ -259,7 +256,7 @@ public Collection<KieScannerEventListener> getListeners() {
public KieModule addKieModule(Resource resource, Resource... dependencies) {
log.info("Adding KieModule from resource: " + resource);
KieModule kModule = getKieModule(resource);
if (dependencies != null) {
if (dependencies != null && dependencies.length > 0) {
for (Resource depRes : dependencies) {
InternalKieModule depKModule = (InternalKieModule) getKieModule(depRes);
((InternalKieModule) kModule).addKieDependency(depKModule);
Expand Down Expand Up @@ -328,35 +325,30 @@ public static class KieModuleRepo {
public static int MAX_SIZE_GA_VERSIONS_CACHE // made changeable for test purposes
= Integer.parseInt(System.getProperty(CACHE_VERSIONS_MAX_PROPERTY, "10"));

private final Set<ReleaseId> notKieModules = Collections.newSetFromMap(new LinkedHashMap<>(){
@Override
protected boolean removeEldestEntry(Map.Entry<ReleaseId, Boolean> eldest) {
return size() > 1_000;
}
});

// FIELDS -----------------------------------------------------------------------------------------------------------------

// kieModules evicts based on access-time, not on insertion-time
public final Map<String, NavigableMap<ComparableVersion, KieModule>> kieModules = new LinkedHashMap<>(16, 0.75f, true) {
public final Map<String, NavigableMap<ComparableVersion, KieModule>> kieModules
= new LinkedHashMap<String, NavigableMap<ComparableVersion, KieModule>>(16, 0.75f, true) {
@Override
protected boolean removeEldestEntry( Map.Entry<String, NavigableMap<ComparableVersion, KieModule>> eldest) {
return (size() > MAX_SIZE_GA_CACHE);
}
};

public final LinkedHashMap<ReleaseId, KieModule> oldKieModules = new LinkedHashMap<>() {
public final LinkedHashMap<ReleaseId, KieModule> oldKieModules = new LinkedHashMap<ReleaseId, KieModule>() {
@Override
protected boolean removeEldestEntry( Map.Entry<ReleaseId, KieModule> eldest ) {
return size() > (MAX_SIZE_GA_CACHE*MAX_SIZE_GA_VERSIONS_CACHE);
}
};

};

// METHODS ----------------------------------------------------------------------------------------------------------------

public synchronized KieModule remove(ReleaseId releaseId) {
KieModule removedKieModule = null;
String ga = toArtifactId(releaseId);
String ga = releaseId.getGroupId() + ":" + releaseId.getArtifactId();
ComparableVersion comparableVersion = new ComparableVersion(releaseId.getVersion());

NavigableMap<ComparableVersion, KieModule> artifactMap = kieModules.get(ga);
Expand All @@ -371,24 +363,9 @@ public synchronized KieModule remove(ReleaseId releaseId) {
return removedKieModule;
}

private KieModule storeKieModule(ReleaseId releaseId, KieModule kieModule) {
if (kieModule != null) {
store(kieModule);
} else {
notKieModules.add(releaseId);
}
return kieModule;
}

private boolean isKnownNotKieModule(ReleaseId releaseId) {
return notKieModules.contains(releaseId);
}

public synchronized void store(KieModule kieModule) {
ReleaseId releaseId = kieModule.getReleaseId();
notKieModules.remove(releaseId);

String ga = toArtifactId(releaseId);
String ga = releaseId.getGroupId() + ":" + releaseId.getArtifactId();
ComparableVersion comparableVersion = new ComparableVersion(releaseId.getVersion());

NavigableMap<ComparableVersion, KieModule> artifactMap = kieModules.get(ga);
Expand Down Expand Up @@ -416,11 +393,11 @@ public synchronized void store(KieModule kieModule) {
* @return a {@link NavigableMap} that is "backed" by a {@link LinkedHashMap} to enforce a LRU cache
*/
private NavigableMap<ComparableVersion, KieModule> createNewArtifactMap() {
return new TreeMap<>() {
NavigableMap<ComparableVersion, KieModule> newArtifactMap = new TreeMap<ComparableVersion, KieModule>() {

private final Map<ComparableVersion, KieModule> artifactMap = this;

final LinkedHashMap<ComparableVersion, Object> backingLRUMap = new LinkedHashMap<>(16, 0.75f, true) {
LinkedHashMap<ComparableVersion, Object> backingLRUMap = new LinkedHashMap<ComparableVersion, Object>(16, 0.75f, true) {
@Override
protected boolean removeEldestEntry( Map.Entry<ComparableVersion, Object> eldest ) {
boolean remove = (size() > MAX_SIZE_GA_VERSIONS_CACHE);
Expand All @@ -438,6 +415,7 @@ public KieModule put( ComparableVersion key, KieModule value ) {
}

};
return newArtifactMap;
}

synchronized KieModule loadOldAndRemove(ReleaseId releaseId) {
Expand All @@ -449,7 +427,9 @@ synchronized KieModule load(InternalKieScanner kieScanner, ReleaseId releaseId)
}

synchronized KieModule load(InternalKieScanner kieScanner, ReleaseId releaseId, VersionRange versionRange) {
NavigableMap<ComparableVersion, KieModule> artifactMap = kieModules.get( toArtifactId(releaseId) );
String ga = releaseId.getGroupId() + ":" + releaseId.getArtifactId();

NavigableMap<ComparableVersion, KieModule> artifactMap = kieModules.get(ga);
if ( artifactMap == null || artifactMap.isEmpty() ) {
return null;
}
Expand Down Expand Up @@ -492,10 +472,6 @@ synchronized KieModule load(InternalKieScanner kieScanner, ReleaseId releaseId,

}

private static String toArtifactId(ReleaseId releaseId) {
return releaseId.getGroupId() + ":" + releaseId.getArtifactId();
}

private static class VersionRange {

private String lowerBound;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.drools.base.facttemplates.Fact;
import org.drools.base.facttemplates.FactTemplate;
import org.drools.model.PrototypeFact;

public class HashMapFactImpl implements Fact, PrototypeFact, Serializable {

protected final UUID uuid;

protected final FactTemplate factTemplate;

protected final Map<String, Object> valuesMap;
Expand All @@ -35,6 +38,7 @@ public HashMapFactImpl( FactTemplate factTemplate ) {
}

public HashMapFactImpl( FactTemplate factTemplate, Map<String, Object> valuesMap ) {
this.uuid = UUID.randomUUID();
this.factTemplate = factTemplate;
this.valuesMap = valuesMap;
}
Expand Down Expand Up @@ -68,4 +72,30 @@ public Map<String, Object> asMap() {
public String toString() {
return "Fact " + factTemplate.getName() + " with values = " + valuesMap;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
HashMapFactImpl other = (HashMapFactImpl) obj;
if (uuid == null) {
if (other.uuid != null)
return false;
} else if (!uuid.equals(other.uuid))
return false;
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.stream.Collectors;

import org.drools.core.common.Storage;
import org.drools.core.phreak.PhreakTimerNode.TimerNodeJob;
import org.drools.core.reteoo.ObjectTypeNode.ExpireJob;
import org.drools.core.time.impl.PseudoClockScheduler;
import org.drools.core.time.impl.TimerJobInstance;
Expand Down Expand Up @@ -65,11 +66,11 @@ private void updateStorage() {
}

/**
* ExpireJob is recreated by repropagate, so doesn't need to persist
* ExpireJob and TimerNodeJob are recreated by repropagate, so we don't need to persist
*/
public List<TimerJobInstance> createFilteredInternalQueueForPersistence(PriorityQueue<TimerJobInstance> queue) {
return queue.stream()
.filter(job -> !(job.getJob() instanceof ExpireJob))
.filter(job -> !(job.getJob() instanceof ExpireJob || job.getJob() instanceof TimerNodeJob))
.collect(Collectors.toList());
}
}
Loading

0 comments on commit 520cdd1

Please sign in to comment.