You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by js...@apache.org on 2023/03/02 13:18:55 UTC
[unomi] 04/05: UNOMI-739 : remove useless code and fix test
This is an automated email from the ASF dual-hosted git repository.
jsinovassinnaik pushed a commit to branch UNOMI-739-update-purge-system
in repository https://gitbox.apache.org/repos/asf/unomi.git
commit 7416d321ee96615a4b7753c2492e5afb008323d6
Author: jsinovassin <js...@jahia.com>
AuthorDate: Wed Feb 22 16:51:27 2023 +0100
UNOMI-739 : remove useless code and fix test
---
.../apache/unomi/api/services/ClusterService.java | 1 +
.../org/apache/unomi/itests/ProfileServiceIT.java | 18 ++++++++----
.../ElasticSearchPersistenceServiceImpl.java | 34 ----------------------
.../unomi/persistence/spi/PersistenceService.java | 1 +
.../rest/endpoints/ClusterServiceEndPoint.java | 1 +
.../services/impl/profiles/ProfileServiceImpl.java | 6 ----
6 files changed, 15 insertions(+), 46 deletions(-)
diff --git a/api/src/main/java/org/apache/unomi/api/services/ClusterService.java b/api/src/main/java/org/apache/unomi/api/services/ClusterService.java
index 4c89ba94b..299ac9098 100644
--- a/api/src/main/java/org/apache/unomi/api/services/ClusterService.java
+++ b/api/src/main/java/org/apache/unomi/api/services/ClusterService.java
@@ -41,6 +41,7 @@ public interface ClusterService {
*
* @param date the Date before which all data needs to be removed
*/
+ @Deprecated
void purge(final Date date);
/**
diff --git a/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java b/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
index 79a3bf843..bda614d81 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
@@ -372,30 +372,36 @@ public class ProfileServiceIT extends BaseIT {
(count) -> count == (450 + originalEventsCount), 1000, 100);
// Should have no effect
- profileService.purgeMonthlyItems(0);
+ profileService.purgeSessionItems(0);
keepTrying("Sessions number should be 450", () -> persistenceService.getAllItemsCount(Session.ITEM_TYPE),
(count) -> count == (450 + originalSessionsCount), 1000, 100);
+ profileService.purgeEventItems(0);
keepTrying("Events number should be 450", () -> persistenceService.getAllItemsCount(Event.ITEM_TYPE),
(count) -> count == (450 + originalEventsCount), 1000, 100);
// Should have no effect there is no monthly items older than 40 months
- profileService.purgeMonthlyItems(40);
+ profileService.purgeSessionItems(40);
keepTrying("Sessions number should be 450", () -> persistenceService.getAllItemsCount(Session.ITEM_TYPE),
(count) -> count == (450 + originalSessionsCount), 1000, 100);
+ profileService.purgeEventItems(40);
keepTrying("Events number should be 450", () -> persistenceService.getAllItemsCount(Event.ITEM_TYPE),
(count) -> count == (450 + originalEventsCount), 1000, 100);
- // Should purge monthly items older than 25 days
- profileService.purgeMonthlyItems(25);
+ // Should purge sessions older than 25 days
+ profileService.purgeSessionItems(25);
keepTrying("Sessions number should be 300", () -> persistenceService.getAllItemsCount(Session.ITEM_TYPE),
(count) -> count == (300 + originalSessionsCount), 1000, 100);
+ // Should purge events older than 25 days
+ profileService.purgeEventItems(25);
keepTrying("Events number should be 300", () -> persistenceService.getAllItemsCount(Event.ITEM_TYPE),
(count) -> count == (300 + originalEventsCount), 1000, 100);
- // Should purge monthly items older than 5 days
- profileService.purgeMonthlyItems(5);
+ // Should purge sessions older than 5 days
+ profileService.purgeSessionItems(5);
keepTrying("Sessions number should be 150", () -> persistenceService.getAllItemsCount(Session.ITEM_TYPE),
(count) -> count == (150 + originalSessionsCount), 1000, 100);
+ // Should purge events older than 5 days
+ profileService.purgeEventItems(5);
keepTrying("Events number should be 150", () -> persistenceService.getAllItemsCount(Event.ITEM_TYPE),
(count) -> count == (150 + originalEventsCount), 1000, 100);
}
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 f1ec3e7fe..d14d284d9 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
@@ -148,8 +148,6 @@ import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -2422,38 +2420,6 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
@Override
public void purge(final Date date) {
- new InClassLoaderExecute<Object>(metricsService, this.getClass().getName() + ".purgeWithDate", this.bundleContext, this.fatalIllegalStateErrors, throwExceptions) {
- @Override
- protected Object execute(Object... args) throws Exception {
-
- GetIndexRequest getIndexRequest = new GetIndexRequest(getAllIndexForQuery());
- GetIndexResponse getIndexResponse = client.indices().get(getIndexRequest, RequestOptions.DEFAULT);
- String[] indices = getIndexResponse.getIndices();
-
- SimpleDateFormat d = new SimpleDateFormat("yyyy-MM");
-
- List<String> toDelete = new ArrayList<>();
- for (String currentIndexName : indices) {
- int indexDatePrefixPos = currentIndexName.indexOf(INDEX_DATE_PREFIX);
- if (indexDatePrefixPos > -1) {
- try {
- Date indexDate = d.parse(currentIndexName.substring(indexDatePrefixPos + INDEX_DATE_PREFIX.length()));
-
- if (indexDate.before(date)) {
- toDelete.add(currentIndexName);
- }
- } catch (ParseException e) {
- throw new Exception("Cannot parse index name " + currentIndexName, e);
- }
- }
- }
- if (!toDelete.isEmpty()) {
- DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(toDelete.toArray(new String[toDelete.size()]));
- client.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);
- }
- return null;
- }
- }.catchingExecuteInClassLoader(true);
}
@Override
diff --git a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
index 7ed85e767..751a34c85 100644
--- a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
+++ b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
@@ -680,6 +680,7 @@ public interface PersistenceService {
*
* @param date the date (not included) before which we want to erase all data
*/
+ @Deprecated
void purge(Date date);
/**
diff --git a/rest/src/main/java/org/apache/unomi/rest/endpoints/ClusterServiceEndPoint.java b/rest/src/main/java/org/apache/unomi/rest/endpoints/ClusterServiceEndPoint.java
index 9cfeae9a2..d0c7cf29b 100644
--- a/rest/src/main/java/org/apache/unomi/rest/endpoints/ClusterServiceEndPoint.java
+++ b/rest/src/main/java/org/apache/unomi/rest/endpoints/ClusterServiceEndPoint.java
@@ -87,6 +87,7 @@ public class ClusterServiceEndPoint {
*/
@GET
@Path("/purge/{date}")
+ @Deprecated
public void purge(@PathParam("date") String date) {
try {
clusterService.purge(new SimpleDateFormat("yyyy-MM-dd").parse(date));
diff --git a/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java b/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
index 399c3e3b9..05ffb72fd 100644
--- a/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
@@ -471,12 +471,6 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
}
}
- private GregorianCalendar getMonth(int offset) {
- GregorianCalendar gc = new GregorianCalendar();
- gc = new GregorianCalendar(gc.get(Calendar.YEAR), gc.get(Calendar.MONTH), 1);
- gc.add(Calendar.MONTH, offset);
- return gc;
- }
public long getAllProfilesCount() {
return persistenceService.getAllItemsCount(Profile.ITEM_TYPE);