Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync main branch with Apache main branch #56

Merged
merged 17 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
ab1e671
[Fix #3605] Use concurrent hash map (#3606)
fjtirado Aug 7, 2024
9c24acf
NO-ISSUE: Updating Maven to 3.9.6 (#3479)
yesamer Aug 8, 2024
5dbabe6
[incubator-kie-issues-1131] v7 migration to code generation (#3608)
Abhitocode Aug 8, 2024
be75431
[incubator-kie-issues-1131] v7 migration to code generation (#3601)
Abhitocode Aug 9, 2024
13a966a
[incubator-kie-issues-1131] v7 migration to code generation (#3597)
Abhitocode Aug 9, 2024
aa0247b
[incubator-kie-issues-1131] v7 migration to code generation (#3596)
Abhitocode Aug 9, 2024
6652a1e
[incubator-kie-issues-1131] v7 migration to code generation (#3593)
Abhitocode Aug 13, 2024
ef03b17
Adding new dynamic addon (#3611)
fjtirado Aug 14, 2024
ae2446d
Add edge tests (#3619)
gmunozfe Aug 14, 2024
f708e1a
[incubator-kie-issues#1412] Refactor springboot/integration-tests (#3…
gitgabrio Aug 16, 2024
9fac60e
Add correlation persistence for MongoDB (#3612)
mcruzdev Aug 16, 2024
8f5432f
[Fix #3602] Adding jq extra functions (#3616)
fjtirado Aug 16, 2024
33e6d7f
[Fix 3624] Removing rest-easy-client from sonataflow extension (#3625)
fjtirado Aug 22, 2024
dca53f0
[Fix #3628] Avoiding concurrency issues with Instance and ServiceLoad…
fjtirado Aug 22, 2024
18aef89
[incubator-kie-issues-1131] v7 migration to code generation (#3623)
Abhitocode Aug 23, 2024
1007ae2
[incubator-kie-issues-1131] v7 migration to code generation (#3618)
Abhitocode Aug 23, 2024
33a735f
[incubator-kie-issues#1441] Clean kogito-pmml-dependencies (#3630)
gitgabrio Aug 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr-downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
job_name: [ kogito-apps, kogito-quarkus-examples, kogito-springboot-examples, serverless-workflow-examples ]
os: [ubuntu-latest]
java-version: [17]
maven-version: ['3.9.3']
maven-version: ['3.9.6']
include:
- job_name: kogito-apps
repository: kogito-apps
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-kogito-runtimes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
matrix:
os: [ubuntu-latest]
java-version: [17]
maven-version: ['3.9.3']
maven-version: ['3.9.6']
fail-fast: false
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} / Java-${{ matrix.java-version }} / Maven-${{ matrix.maven-version }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
package org.kie.kogito.monitoring.core.common.process;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -49,7 +49,7 @@
public class MetricsProcessEventListener extends DefaultKogitoProcessEventListener {

private static final Logger LOGGER = LoggerFactory.getLogger(MetricsProcessEventListener.class);
private static Map<String, AtomicInteger> gaugeMap = new HashMap<>();
private static Map<String, AtomicInteger> gaugeMap = new ConcurrentHashMap<>();
private final String identifier;
private final KogitoGAV gav;
private final MeterRegistry meterRegistry;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.kogito.mongodb.correlation;

import java.io.UncheckedIOException;
import java.util.Map;

import org.bson.Document;
import org.bson.codecs.configuration.CodecRegistries;
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.conversions.Bson;
import org.kie.kogito.correlation.CompositeCorrelation;
import org.kie.kogito.correlation.Correlation;
import org.kie.kogito.correlation.CorrelationInstance;
import org.kie.kogito.correlation.SimpleCorrelation;
import org.kie.kogito.jackson.utils.ObjectMapperFactory;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Filters;
import com.mongodb.client.result.InsertOneResult;

public class MongoDBCorrelationRepository {

private final MongoCollection<Document> collection;
private final ObjectMapper objectMapper;

private static final String ENCODED_CORRELATION_ID_FIELD = "encodedCorrelationId";
private static final String CORRELATED_ID_FIELD = "correlatedId";
private static final String CORRELATION_FIELD = "correlation";
private static final String CORRELATION_COLLECTION_NAME = "correlations";

public MongoDBCorrelationRepository(MongoClient mongoClient, String dbName) {
CodecRegistry registry = CodecRegistries.fromRegistries(MongoClientSettings.getDefaultCodecRegistry());
this.collection = mongoClient.getDatabase(dbName).getCollection(CORRELATION_COLLECTION_NAME).withCodecRegistry(registry);
SimpleModule simpleModule = new SimpleModule();
simpleModule.addAbstractTypeMapping(Correlation.class, SimpleCorrelation.class);
this.objectMapper = ObjectMapperFactory.get().copy().registerModule(simpleModule);
}

public CorrelationInstance insert(final String encodedCorrelationId, final String correlatedId, final Correlation correlation) {

CorrelationInstance correlationInstance = new CorrelationInstance(encodedCorrelationId, correlatedId, correlation);
try {
Map<String, Object> object = Map.of(
ENCODED_CORRELATION_ID_FIELD, encodedCorrelationId,
CORRELATED_ID_FIELD, correlatedId,
CORRELATION_FIELD, correlation);
String json = this.objectMapper.writeValueAsString(object);
InsertOneResult insertOneResult = this.collection.insertOne(Document.parse(json));
return insertOneResult.getInsertedId() != null ? correlationInstance : null;
} catch (JsonProcessingException e) {
throw new UncheckedIOException(e);
}
}

public CorrelationInstance findByEncodedCorrelationId(String encoded) {
Bson eq = Filters.eq(ENCODED_CORRELATION_ID_FIELD, encoded);
return getCorrelationInstanceByFilter(eq);
}

public CorrelationInstance findByCorrelatedId(String correlatedId) {
Bson eq = Filters.eq(CORRELATED_ID_FIELD, correlatedId);
return getCorrelationInstanceByFilter(eq);
}

private CorrelationInstance getCorrelationInstanceByFilter(Bson eq) {
Document first = this.collection.find(eq).first();
if (first == null) {
return null;
} else {
Document document = first.get(CORRELATION_FIELD, Document.class);
try {
CompositeCorrelation compositeCorrelation = this.objectMapper.readValue(document.toJson(), CompositeCorrelation.class);
return new CorrelationInstance(
first.getString(ENCODED_CORRELATION_ID_FIELD),
first.getString(CORRELATED_ID_FIELD),
compositeCorrelation);
} catch (JsonProcessingException e) {
throw new UncheckedIOException(e);
}
}
}

public void delete(String encoded) {
Bson eq = Filters.eq(ENCODED_CORRELATION_ID_FIELD, encoded);
this.collection.deleteOne(eq);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.kogito.mongodb.correlation;

import java.util.Optional;

import org.kie.kogito.correlation.Correlation;
import org.kie.kogito.correlation.CorrelationEncoder;
import org.kie.kogito.correlation.CorrelationInstance;
import org.kie.kogito.correlation.CorrelationService;
import org.kie.kogito.event.correlation.MD5CorrelationEncoder;

public class MongoDBCorrelationService implements CorrelationService {

private final MongoDBCorrelationRepository correlationRepository;
private final CorrelationEncoder correlationEncoder;

public MongoDBCorrelationService(MongoDBCorrelationRepository correlationRepository) {
this.correlationRepository = correlationRepository;
this.correlationEncoder = new MD5CorrelationEncoder();
}

@Override
public CorrelationInstance create(Correlation correlation, String correlatedId) {
String encodedCorrelationId = this.correlationEncoder.encode(correlation);
return this.correlationRepository.insert(encodedCorrelationId, correlatedId, correlation);
}

@Override
public Optional<CorrelationInstance> find(Correlation correlation) {
String encodedCorrelationId = correlationEncoder.encode(correlation);
return Optional.ofNullable(this.correlationRepository.findByEncodedCorrelationId(encodedCorrelationId));
}

@Override
public Optional<CorrelationInstance> findByCorrelatedId(String correlatedId) {
return Optional.ofNullable(this.correlationRepository.findByCorrelatedId(correlatedId));
}

@Override
public void delete(Correlation correlation) {
String encodedCorrelationId = correlationEncoder.encode(correlation);
this.correlationRepository.delete(encodedCorrelationId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.kogito.mongodb.correlation;

import java.util.Collections;
import java.util.Optional;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.kie.kogito.correlation.CompositeCorrelation;
import org.kie.kogito.correlation.CorrelationInstance;
import org.kie.kogito.correlation.SimpleCorrelation;
import org.kie.kogito.testcontainers.KogitoMongoDBContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;

import static org.assertj.core.api.Assertions.assertThat;

@Testcontainers
class MongoDBCorrelationServiceIT {

@Container
final static KogitoMongoDBContainer mongoDBContainer = new KogitoMongoDBContainer();
private static MongoDBCorrelationService correlationService;
private static MongoClient mongoClient;
private static final String DB_NAME = "test";
private static final String COLLECTION_NAME = "correlations";

@BeforeAll
static void setUp() {
mongoDBContainer.start();
mongoClient = MongoClients.create(mongoDBContainer.getReplicaSetUrl());
correlationService = new MongoDBCorrelationService(new MongoDBCorrelationRepository(
mongoClient, DB_NAME));
}

@BeforeEach
void beforeEach() {
mongoClient.getDatabase(DB_NAME).getCollection(COLLECTION_NAME).drop();
}

@Test
void shouldSaveCorrelation() {
// arrange
String correlatedId = "id";
CompositeCorrelation correlation = new CompositeCorrelation(Collections.singleton(new SimpleCorrelation<>("city", "Rio de Janeiro")));

// act
correlationService.create(correlation, correlatedId);

// assert
Optional<CorrelationInstance> byCorrelatedId = correlationService.findByCorrelatedId(correlatedId);
assertThat(byCorrelatedId).isNotEmpty();
}

@Test
void shouldDeleteCorrelation() {
// arrange
String correlatedId = "id";
CompositeCorrelation correlation = new CompositeCorrelation(Collections.singleton(new SimpleCorrelation<>("city", "São Paulo")));
correlationService.create(correlation, correlatedId);

// act
correlationService.delete(correlation);

// assert
assertThat(correlationService.findByCorrelatedId(correlatedId)).isEmpty();
}

@Test
void shouldFindByCorrelatedId() {
// arrange
String correlatedId = "id";
CompositeCorrelation correlation = new CompositeCorrelation(Collections.singleton(new SimpleCorrelation<>("city", "Goiânia")));
correlationService.create(correlation, correlatedId);

// act
Optional<CorrelationInstance> byCorrelatedId = correlationService.findByCorrelatedId(correlatedId);

// assert
assertThat(byCorrelatedId).isNotEmpty();
}

@Test
void shouldFindByCorrelation() {
// arrange
CompositeCorrelation correlation = new CompositeCorrelation(Collections.singleton(new SimpleCorrelation<>("city", "Osasco")));
String correlatedId = "id";

correlationService.create(correlation, correlatedId);

// act
Optional<CorrelationInstance> correlationInstance = correlationService.find(correlation);

// assert
assertThat(correlationInstance).isNotEmpty();
}

}
1 change: 1 addition & 0 deletions addons/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<module>rest-exception-handler</module>
<module>process-svg</module>
<module>process-management</module>
<module>process-dynamic</module>
<module>knative</module>
<module>kubernetes</module>
<module>kubernetes-service-catalog</module>
Expand Down
43 changes: 43 additions & 0 deletions addons/common/process-dynamic/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!--

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.kie</groupId>
<artifactId>kogito-addons-common-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<artifactId>kie-addons-process-dynamic</artifactId>
<name>KIE Add-On Process Instance Dynamic Calls</name>
<description>Allow performing dynamic calls for existing process instances</description>
<properties>
<java.module.name>org.kie.process.dynamic</java.module.name>
</properties>
<dependencies>

<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-rest-workitem</artifactId>
</dependency>
</dependencies>
</project>
Loading
Loading