From cfc1fb398065e78beb14ee4a50cbf7cc222fd918 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 22 Sep 2017 13:07:54 +0000 Subject: [PATCH] Allowing elaborate only when last update is before last 8 hours. This avoid to start two recovery/elaboration while the previous is not terminated. git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-aggregator-se-plugin@154426 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../aggregator/elaboration/Elaborator.java | 12 +++++++++++- .../aggregator/elaboration/RecoveryManager.java | 11 ----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/gcube/accounting/aggregator/elaboration/Elaborator.java b/src/main/java/org/gcube/accounting/aggregator/elaboration/Elaborator.java index fa15a20..13a1b7d 100644 --- a/src/main/java/org/gcube/accounting/aggregator/elaboration/Elaborator.java +++ b/src/main/java/org/gcube/accounting/aggregator/elaboration/Elaborator.java @@ -15,6 +15,7 @@ import org.gcube.accounting.aggregator.persistence.CouchBaseConnector.SUFFIX; import org.gcube.accounting.aggregator.plugin.AccountingAggregatorPlugin; import org.gcube.accounting.aggregator.status.AggregationState; import org.gcube.accounting.aggregator.status.AggregationStatus; +import org.gcube.accounting.aggregator.utility.Constant; import org.gcube.accounting.aggregator.utility.Utility; import org.gcube.documentstore.records.DSMapper; import org.slf4j.Logger; @@ -110,7 +111,16 @@ public class Elaborator { aggregationStatus.getAggregationState(), DSMapper.getObjectMapper().writeValueAsString(aggregationStatus)); return; - }else{ + } + + Calendar now = Utility.getUTCCalendarInstance(); + now.add(Constant.CALENDAR_FIELD_TO_SUBSTRACT_TO_CONSIDER_UNTERMINATED, -Constant.UNIT_TO_SUBSTRACT_TO_CONSIDER_UNTERMINATED); + if(aggregationStatus.getLastUpdateTime().after(now)){ + logger.info("Cannot elaborate of {} because has been modified in the last {} ", + DSMapper.getObjectMapper().writeValueAsString(aggregationStatus), + Constant.UNIT_TO_SUBSTRACT_TO_CONSIDER_UNTERMINATED, Constant.CALENDAR_FIELD_TO_SUBSTRACT_TO_CONSIDER_UNTERMINATED==Calendar.HOUR_OF_DAY? "hours" : "unit"); + return; + }else { aggregationStatus.updateLastUpdateTime(true); } } diff --git a/src/main/java/org/gcube/accounting/aggregator/elaboration/RecoveryManager.java b/src/main/java/org/gcube/accounting/aggregator/elaboration/RecoveryManager.java index 32d4fb0..a738003 100644 --- a/src/main/java/org/gcube/accounting/aggregator/elaboration/RecoveryManager.java +++ b/src/main/java/org/gcube/accounting/aggregator/elaboration/RecoveryManager.java @@ -1,14 +1,11 @@ package org.gcube.accounting.aggregator.elaboration; -import java.util.Calendar; import java.util.Date; import java.util.List; import org.gcube.accounting.aggregator.aggregation.AggregationInfo; import org.gcube.accounting.aggregator.persistence.CouchBaseConnector; import org.gcube.accounting.aggregator.status.AggregationStatus; -import org.gcube.accounting.aggregator.utility.Constant; -import org.gcube.accounting.aggregator.utility.Utility; import org.gcube.documentstore.records.DSMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,14 +39,6 @@ public class RecoveryManager { aggregationInfo.getAggregationStartDate()); logger.info("Going to Recover unterminated elaboration {}", DSMapper.getObjectMapper().writeValueAsString(aggregationStatus)); - Calendar now = Utility.getUTCCalendarInstance(); - now.add(Constant.CALENDAR_FIELD_TO_SUBSTRACT_TO_CONSIDER_UNTERMINATED, -Constant.UNIT_TO_SUBSTRACT_TO_CONSIDER_UNTERMINATED); - if(aggregationStatus.getLastUpdateTime().after(now)){ - logger.info("Cannot start recovery of {} because has been modified in the last {} ", - DSMapper.getObjectMapper().writeValueAsString(aggregationStatus), - Constant.UNIT_TO_SUBSTRACT_TO_CONSIDER_UNTERMINATED, Constant.CALENDAR_FIELD_TO_SUBSTRACT_TO_CONSIDER_UNTERMINATED==Calendar.HOUR_OF_DAY? "hours" : "unit"); - return; - } Elaborator elaborator = new Elaborator(aggregationStatus, persistStartTime, persistEndTime); elaborator.elaborate(); }