Skip to content

Commit

Permalink
[DROOLS-7066] Replacing FRI with LocalUri (#4635)
Browse files Browse the repository at this point in the history
* [DROOLS-7090] Do not write IndexFile - bring it around with context.
- Experimental draft
- Basically focusing on OnTheFlyDrlTest test case
- Unit tests in efesto and kie-drl passed (with some @disabled)
- Not mind other integrations test errors at the moment

* - Store GeneratedResources map in Context
- RuntimeContext can get GeneratedResources from CompilationContext or scan IndexFile to populate GeneratedResources
- Implement createIndexFiles in CompilationContext
- Add kie-drl-tests-without-index-file for test cases without pre-existing IndexFile

* [DROOLS-7066] Replacing FRI with LocalUri

* [DROOLS-7090] Fix kie-maven-plugin/PMML

* - Add getModelType() for CompilerService/RuntimeService so impl classes need to implement it
- Context automatically detects IndexFile from classpath based on engine models in classpath
- CompilationManager.processResource() return type is void
- EfestoCompilationContextImpl.createIndexFiles merges the content if IndexFile already exists

* [DROOLS-7066] Implementing/using ModelLocalUriID inside efesto

* [DROOLS-7066] Implementing/using ModelLocalUriID inside kie-drl

* [DROOLS-7066] WIP

* [DROOLS-7090] Fixing PMML to work with in memory GeneratedResources

* [DROOLS-7066] Fixing PMML tests/DMN integration

* - Clean up legacy "getIndexFile" dependent codes

* [DROOLS-7066] WIP

* [DROOLS-7066] Merge DROOLS-7090

* - Version bump
- Code smells

* - add EfestoCompilationContext.createIndexFiles overwriting test

* - test fix

* [DROOLS-7090] Add KieRuntimeServiceDrlMapInput native reflection declaration needed by PMML ->  DRL integration (#6)

* [DROOLS-7066] Merging with DROOLS-7090

* [DROOLS-7066] Merging with main

* [DROOLS-7066] Fix sonar code-smells

* [DROOLS-7066] Fix as per PR request

* [DROOLS-7066] Increase test code coverage

* [DROOLS-7066] Fix merge conflict

* [DROOLS-7066] Fix reported bugs

* [DROOLS-7066] Fix code smells

* [DROOLS-7066] Fix tests

* [DROOLS-7066] Testing DMNKiePMMLTrustyInvocationEvaluator

* [DROOLS-7066] Increase test code coverage

* [DROOLS-7066] Declare DTOs inside reflective-config needed for native compilation/execution

Co-authored-by: Toshiya Kobayashi <toshiyakobayashi@gmail.com>
  • Loading branch information
gitgabrio and tkobayas authored Sep 13, 2022
1 parent c56d670 commit 63cda08
Show file tree
Hide file tree
Showing 149 changed files with 3,304 additions and 850 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ public void generateSources( BuildProducer<GeneratedBeanBuildItem> generatedBean

@BuildStep
public List<ReflectiveClassBuildItem> reflectiveEfestoRules() {
LOGGER.info("reflectiveEfestoRules()");
LOGGER.debug("reflectiveEfestoRules()");
final List<ReflectiveClassBuildItem> toReturn = new ArrayList<>();
toReturn.add(new ReflectiveClassBuildItem(true, true, KieRuntimeServiceDrlMapInput.class));
LOGGER.info("toReturn {}", toReturn.size());
LOGGER.debug("toReturn {}", toReturn.size());
return toReturn;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.StringTokenizer;

/**
* A uri of the form: kogito-local:///a/b/c...
* A uri of the form: efesto-local:///a/b/c...
* <p>
* For instance: for "/a/b/c" the {@link LocalUri} is represented as:
*
Expand All @@ -45,17 +45,20 @@
* </pre>
*/
public abstract class LocalUri {
public static final String SCHEME = "kogito-local";

public static final String SCHEME = "efesto-local";
public static final LocalUri Root = new LocalUriRoot();
public static final String SLASH = "/";

public static LocalUri parse(String path) {
if (path.startsWith(SCHEME)) {
URI parsed = URI.create(path);
path = parsed.getPath();
}
if (!path.startsWith("/"))
if (!path.startsWith(SLASH)) {
throw new IllegalArgumentException("Path must start at root /");
StringTokenizer tok = new StringTokenizer(path, "/");
}
StringTokenizer tok = new StringTokenizer(path, SLASH);
LocalUri hpath = Root;
while (tok.hasMoreTokens()) {
hpath = hpath.append(tok.nextToken());
Expand Down Expand Up @@ -108,7 +111,7 @@ public boolean startsWith(String component) {

@Override
public String path() {
return "/";
return SLASH;
}

// it is a singleton: we don't need to override equals, hashCode
Expand All @@ -120,7 +123,7 @@ public String path() {
public static class LocalUriPathComponent extends LocalUri {

private final LocalUri parent;
private final String component;
final String component;

private LocalUriPathComponent(LocalUri parent, String component) {
this.parent = parent;
Expand Down Expand Up @@ -148,7 +151,7 @@ public boolean startsWith(String component) {

@Override
public String path() {
return parent == Root ? ("/" + component) : (parent.path() + "/" + component);
return parent == Root ? (SLASH + component) : (parent.path() + SLASH + component);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
* LocalId.
*/
public abstract class LocalUriId implements LocalId {
private final LocalUri path;
private LocalUri path;

public LocalUriId() {
}

public LocalUriId(LocalUri path) {
this.path = path;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright 2022 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.efesto.common.api.identifiers;

import java.io.Serializable;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.StringTokenizer;

import static org.kie.efesto.common.api.identifiers.LocalUri.SLASH;

public class ModelLocalUriId extends LocalUriId implements Serializable {

private static final long serialVersionUID = 2473381132658366922L;
private final String model;

private final String basePath;

private final String fullPath;


public ModelLocalUriId(LocalUri path) {
super(path);
model = getModel(path);
basePath = getBasePath(path, model);
fullPath = path.path();
}

public String model() {
return model;
}

public String basePath() {
return basePath;
}

public String fullPath() {
return fullPath;
}

public ModelLocalUriId asModelLocalUriId() {
return this.getClass().equals(ModelLocalUriId.class) ? this : new ModelLocalUriId(this.asLocalUri());
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null) {
return false;
}
if (!(o instanceof ModelLocalUriId)) {
return false;
}
ModelLocalUriId that = (ModelLocalUriId) o;
return Objects.equals(model, that.model) && Objects.equals(basePath, that.basePath) && Objects.equals(fullPath, that.fullPath);
}

@Override
public int hashCode() {
return Objects.hash(model, basePath, fullPath);
}
static LocalUri.LocalUriPathComponent getFirstLocalUriPathComponent(LocalUri localUri) {
if (localUri.parent() instanceof LocalUri.LocalUriPathComponent) {
return getFirstLocalUriPathComponent(localUri.parent());
} else {
return localUri instanceof LocalUri.LocalUriPathComponent ? (LocalUri.LocalUriPathComponent) localUri : null;
}
}

static String getModel(LocalUri path) {
LocalUri.LocalUriPathComponent firstLocalUriPathComponent = getFirstLocalUriPathComponent(path);
return firstLocalUriPathComponent != null ? firstLocalUriPathComponent.component : null;
}

static String getBasePath(LocalUri path, String model) {
String uriPath = path.path();
if (model == null || model.isEmpty()) {
return uriPath;
} else {
String start = SLASH + model;
return uriPath.substring(uriPath.indexOf(start) + start.length());
}
}

protected static LocalUri appendBasePath(LocalUri parent, String basePath) {
StringTokenizer tok = new StringTokenizer(basePath, SLASH);
while (tok.hasMoreTokens()) {
parent = parent.append(decodeString(tok.nextToken()));
}
return parent;
}

private static String decodeString(String toDecode) {
return URLDecoder.decode(toDecode, StandardCharsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ReflectiveAppRoot(String name) {
}

public ReflectiveAppRoot() {
super("kogito-app");
super("efesto-app");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;
import java.util.Set;

import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
import org.kie.efesto.common.api.listener.EfestoListener;

/**
Expand Down Expand Up @@ -66,35 +67,35 @@ default void addGeneratedResources(String model, GeneratedResources generatedRes

/**
* Get previously generated classes with the key {@code fri}
* @param fri
* @param modelLocalUriId
* @return generatedClasses
*/
default Map<String, byte[]> getGeneratedClasses(FRI fri) {
return GeneratedClassesRepository.INSTANCE.getGeneratedClasses(fri);
default Map<String, byte[]> getGeneratedClasses(ModelLocalUriId modelLocalUriId) {
return GeneratedClassesRepository.INSTANCE.getGeneratedClasses(modelLocalUriId);
}

/**
* Add generated classes with the key {@code fri}
* @param fri
* @param modelLocalUriId
* @param generatedClasses
*/
default void addGeneratedClasses(FRI fri, Map<String, byte[]> generatedClasses) {
GeneratedClassesRepository.INSTANCE.addGeneratedClasses(fri, generatedClasses);
default void addGeneratedClasses(ModelLocalUriId modelLocalUriId, Map<String, byte[]> generatedClasses) {
GeneratedClassesRepository.INSTANCE.addGeneratedClasses(modelLocalUriId, generatedClasses);
}

/**
* Returns {@code true} if this map contains a mapping for the {@code fri}
* @param fri
* @param localUri
* @return {@code true} if this map contains a mapping for the {@code fri}
*/
default boolean containsKey(FRI fri) {
return GeneratedClassesRepository.INSTANCE.containsKey(fri);
default boolean containsKey(ModelLocalUriId localUri) {
return GeneratedClassesRepository.INSTANCE.containsKey(localUri);
}

/**
* @return {@code Set} of {@code FRI} key in this map
* @return {@code Set} of {@code LocalUri} key in this map
*/
default Set<FRI> friKeySet() {
return GeneratedClassesRepository.INSTANCE.friKeySet();
default Set<ModelLocalUriId> localUriIdKeySet() {
return GeneratedClassesRepository.INSTANCE.localUriIdKeySet();
}
}

This file was deleted.

Loading

0 comments on commit 63cda08

Please sign in to comment.