Skip to content

Commit

Permalink
Merge pull request #56 from rgdoliveira/sync_main
Browse files Browse the repository at this point in the history
Sync main branch with Apache main branch
  • Loading branch information
rgdoliveira authored Aug 26, 2024
2 parents 45af77a + 33a735f commit b138650
Show file tree
Hide file tree
Showing 214 changed files with 3,354 additions and 1,984 deletions.
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

0 comments on commit b138650

Please sign in to comment.