You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by dg...@apache.org on 2024/04/22 06:04:20 UTC
(unomi) 01/01: UNOMI-810 : add karaf logs on metadata items operations
This is an automated email from the ASF dual-hosted git repository.
dgriffon pushed a commit to branch UNOMI-810-metadataitem-es-logs-1-x
in repository https://gitbox.apache.org/repos/asf/unomi.git
commit b00b2ae66d093ebb5a8e974ea0ba92968baf6e03
Author: david.griffon <dg...@jahia.com>
AuthorDate: Mon Apr 22 08:04:08 2024 +0200
UNOMI-810 : add karaf logs on metadata items operations
---
.github/workflows/unomi-ci-build-tests.yml | 60 +++++++++++++++++-----
.../ElasticSearchPersistenceServiceImpl.java | 16 +++++-
2 files changed, 63 insertions(+), 13 deletions(-)
diff --git a/.github/workflows/unomi-ci-build-tests.yml b/.github/workflows/unomi-ci-build-tests.yml
index 05f512410..2875646a2 100644
--- a/.github/workflows/unomi-ci-build-tests.yml
+++ b/.github/workflows/unomi-ci-build-tests.yml
@@ -1,7 +1,7 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
-name: Unomi CI - Build and tests
+name: Build and run tests
on:
push:
@@ -10,20 +10,56 @@ on:
branches: [ master, unomi-1.x, unomi-1.7.x ]
jobs:
- build-and-tests:
+ unit-tests:
+ name: Execute unit tests
runs-on: ubuntu-latest
strategy:
+ fail-fast: false
matrix:
java: [ 1.8, 11]
steps:
- - uses: actions/checkout@v2
- - name: Set up JDK ${{ matrix.java }}
- uses: actions/setup-java@v1
- with:
- java-version: ${{ matrix.java }}
+ - uses: actions/checkout@v2
+ - name: Set up JDK ${{ matrix.java }}
+ uses: actions/setup-java@v1
+ with:
+ java-version: ${{ matrix.java }}
+ cache: maven
+ - name: Build and Unit tests
+ run: mvn -U -ntp -e clean install
- - name: Build and Unit tests
- run: mvn -U -B -e clean install
-
- - name: Integration tests
- run: mvn -pl itests clean install -Pintegration-tests
+ integration-tests:
+ name: Execute integration tests
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ java: [ 1.8, 11]
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up JDK ${{ matrix.java }}
+ uses: actions/setup-java@v1
+ with:
+ java-version: ${{ matrix.java }}
+ cache: maven
+ - name: Integration tests
+ run: mvn -ntp clean install -Pintegration-tests
+ - name: Archive code coverage logs
+ uses: actions/upload-artifact@v3
+ if: false # UNOMI-746 Reactivate if necessary
+ with:
+ name: unomi-code-coverage-jdk${{ matrix.java }}-${{ github.run_number }}
+ path: itests/target/site/jacoco
+ - name: Archive unomi logs
+ uses: actions/upload-artifact@v3
+ if: failure()
+ with:
+ name: unomi-log-jdk${{ matrix.java }}-${{ github.run_number }}
+ path: |
+ itests/target/exam/**/data/log
+ itests/target/elasticsearch0/data
+ itests/target/elasticsearch0/logs
+ - name: Publish Test Report
+ uses: mikepenz/action-junit-report@v3
+ if: failure()
+ with:
+ report_paths: 'itests/target/failsafe-reports/TEST-*.xml'
\ No newline at end of file
diff --git a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
index 589bca1b1..42ff5ad0c 100644
--- a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
+++ b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
@@ -31,6 +31,7 @@ import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.log4j.Level;
import org.apache.lucene.search.TotalHits;
import org.apache.unomi.api.Item;
+import org.apache.unomi.api.MetadataItem;
import org.apache.unomi.api.PartialList;
import org.apache.unomi.api.TimestampedItem;
import org.apache.unomi.api.conditions.Condition;
@@ -877,6 +878,7 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
} else {
bulkProcessor.add(indexRequest);
}
+ logMetadataItemOperation("saved", item);
} catch (IndexNotFoundException e) {
logger.error("Could not find index {}, could not register item type {} with id {} ",
index, itemType, itemId, e);
@@ -918,6 +920,7 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
} else {
bulkProcessor.add(updateRequest);
}
+ logMetadataItemOperation("update", item);
return true;
} catch (IndexNotFoundException e) {
throw new Exception("No index found for itemType=" + clazz.getName() + "itemId=" + item.getItemId(), e);
@@ -1185,6 +1188,9 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
DeleteRequest deleteRequest = new DeleteRequest(getIndexNameForQuery(itemType), itemId);
client.delete(deleteRequest, RequestOptions.DEFAULT);
+ if (MetadataItem.class.isAssignableFrom(clazz)) {
+ logger.info("Item of type {} with ID {} has been removed", clazz.getSimpleName(), itemId);
+ }
return true;
} catch (Exception e) {
throw new Exception("Cannot remove", e);
@@ -1203,6 +1209,7 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
protected Boolean execute(Object... args) throws Exception {
try {
String itemType = Item.getItemType(clazz);
+ logger.debug("Remove item of type {} using a query", itemType);
QueryBuilder queryBuilder = conditionESQueryBuilderDispatcher.getQueryBuilder(query);
final DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(getIndexNameForQuery(itemType))
.setQuery(queryBuilder)
@@ -1311,7 +1318,7 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
public boolean createIndex(final String itemType) {
String index = getIndex(itemType);
-
+ logger.debug("Create index {}", itemType);
Boolean result = new InClassLoaderExecute<Boolean>(metricsService, this.getClass().getName() + ".createIndex", this.bundleContext, this.fatalIllegalStateErrors, throwExceptions) {
protected Boolean execute(Object... args) throws IOException {
GetIndexRequest getIndexRequest = new GetIndexRequest(index);
@@ -2132,6 +2139,7 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
@Override
public void purge(final String scope) {
+ logger.debug("Purge scope {}", scope);
new InClassLoaderExecute<Void>(metricsService, this.getClass().getName() + ".purgeWithScope", this.bundleContext, this.fatalIllegalStateErrors, throwExceptions) {
@Override
protected Void execute(Object... args) throws IOException {
@@ -2353,4 +2361,10 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
return WriteRequest.RefreshPolicy.NONE;
}
+ private void logMetadataItemOperation (String operation, Item item) {
+ if (item instanceof MetadataItem) {
+ logger.info("Item of type {} with ID {} has been {}", item.getItemType(), item.getItemId(), operation);
+ }
+ }
+
}