diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTask.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTask.java index 4e8206ce55de9389d109d82daf993c3517c2ad49..b84ccdf88e9a4fc714308b8e04725b4d07747ce1 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTask.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTask.java @@ -32,6 +32,7 @@ import ch.systemsx.cisd.common.utilities.ITimeProvider; import ch.systemsx.cisd.common.utilities.SystemTimeProvider; import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider; +import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider; import ch.systemsx.cisd.openbis.dss.generic.shared.utils.DataSetAndPathInfoDBConsistencyChecker; import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; import ch.systemsx.cisd.openbis.generic.shared.dto.SimpleDataSetInformationDTO; @@ -46,10 +47,13 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat( BasicConstant.DATE_WITHOUT_TIMEZONE_PATTERN); + private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, + DataSetAndPathInfoDBConsistencyCheckTask.class); + private static final Logger notificationLog = LogFactory.getLogger(LogCategory.NOTIFY, DataSetAndPathInfoDBConsistencyCheckTask.class); - private final IEncapsulatedOpenBISService service; + private IEncapsulatedOpenBISService service; private IHierarchicalContentProvider fileProvider; @@ -58,11 +62,9 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas private long timeInterval; private ITimeProvider timeProvider; - - public DataSetAndPathInfoDBConsistencyCheckTask(Properties properties, - IEncapsulatedOpenBISService service) + + public DataSetAndPathInfoDBConsistencyCheckTask() { - this.service = service; } DataSetAndPathInfoDBConsistencyCheckTask(IHierarchicalContentProvider fileProvider, @@ -88,7 +90,9 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas { Date youngerThanDate = new Date(getTimeProvider().getTimeInMilliseconds() - timeInterval); List<SimpleDataSetInformationDTO> dataSets = - service.listOldestPhysicalDataSets(youngerThanDate, Integer.MAX_VALUE); + getService().listOldestPhysicalDataSets(youngerThanDate, Integer.MAX_VALUE); + operationLog.info("Check " + dataSets.size() + " registered since " + + DATE_FORMAT.format(youngerThanDate)); DataSetAndPathInfoDBConsistencyChecker checker = new DataSetAndPathInfoDBConsistencyChecker(fileProvider, pathInfoProvider); checker.check(dataSets); @@ -102,6 +106,15 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas } } + private IEncapsulatedOpenBISService getService() + { + if (service == null) + { + service = ServiceProvider.getOpenBISService(); + } + return service; + } + private ITimeProvider getTimeProvider() { if (timeProvider == null) diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/DataSetAndPathInfoDBConsistencyCheckTask.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/DataSetAndPathInfoDBConsistencyCheckTask.java deleted file mode 100644 index 5dea0ac2880ce97afef5234ea0a226fa429b958b..0000000000000000000000000000000000000000 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/DataSetAndPathInfoDBConsistencyCheckTask.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2013 ETH Zuerich, CISD - * - * Licensed 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 ch.systemsx.cisd.openbis.dss.generic.server.plugins.standard; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import java.util.Properties; - -import org.apache.commons.lang.time.DateUtils; -import org.apache.log4j.Logger; - -import ch.systemsx.cisd.common.logging.LogCategory; -import ch.systemsx.cisd.common.logging.LogFactory; -import ch.systemsx.cisd.common.maintenance.IMaintenanceTask; -import ch.systemsx.cisd.common.time.DateTimeUtils; -import ch.systemsx.cisd.common.utilities.ITimeProvider; -import ch.systemsx.cisd.common.utilities.SystemTimeProvider; -import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; -import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider; -import ch.systemsx.cisd.openbis.dss.generic.shared.utils.DataSetAndPathInfoDBConsistencyChecker; -import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; -import ch.systemsx.cisd.openbis.generic.shared.dto.SimpleDataSetInformationDTO; - -/** - * @author Franz-Josef Elmer - */ -public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTask -{ - static final String CHECKING_TIME_INTERVAL_KEY = "checking-time-interval"; - - private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat( - BasicConstant.DATE_WITHOUT_TIMEZONE_PATTERN); - - private static final Logger notificationLog = LogFactory.getLogger(LogCategory.NOTIFY, - DataSetAndPathInfoDBConsistencyCheckTask.class); - - private final IEncapsulatedOpenBISService service; - - private IHierarchicalContentProvider fileProvider; - - private IHierarchicalContentProvider pathInfoProvider; - - private long timeInterval; - - private ITimeProvider timeProvider; - - public DataSetAndPathInfoDBConsistencyCheckTask(Properties properties, - IEncapsulatedOpenBISService service) - { - this.service = service; - } - - DataSetAndPathInfoDBConsistencyCheckTask(IHierarchicalContentProvider fileProvider, - IHierarchicalContentProvider pathInfoProvider, IEncapsulatedOpenBISService service, - ITimeProvider timeProvider) - { - this.fileProvider = fileProvider; - this.pathInfoProvider = pathInfoProvider; - this.service = service; - this.timeProvider = timeProvider; - } - - @Override - public void setUp(String pluginName, Properties properties) - { - timeInterval = - DateTimeUtils.getDurationInMillis(properties, CHECKING_TIME_INTERVAL_KEY, - DateUtils.MILLIS_PER_DAY); - } - - @Override - public void execute() - { - Date youngerThanDate = new Date(getTimeProvider().getTimeInMilliseconds() - timeInterval); - List<SimpleDataSetInformationDTO> dataSets = - service.listOldestPhysicalDataSets(youngerThanDate, Integer.MAX_VALUE); - DataSetAndPathInfoDBConsistencyChecker checker = - new DataSetAndPathInfoDBConsistencyChecker(fileProvider, pathInfoProvider); - checker.check(dataSets); - if (checker.noErrorAndInconsitencyFound() == false) - { - StringBuilder builder = new StringBuilder(); - builder.append("File system and path info DB consistency check report for all data sets since "); - builder.append(DATE_FORMAT.format(youngerThanDate)).append("\n\n"); - builder.append(checker.createReport()); - notificationLog.error(builder.toString()); - } - } - - private ITimeProvider getTimeProvider() - { - if (timeProvider == null) - { - timeProvider = SystemTimeProvider.SYSTEM_TIME_PROVIDER; - } - return timeProvider; - } - -} diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTaskTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTaskTest.java index 435a4dfe9b2b910fd60a39e685ec180b50f82bcc..d748f715ee9f805f5402fb23a27530ef5222c33d 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTaskTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTaskTest.java @@ -97,7 +97,8 @@ public class DataSetAndPathInfoDBConsistencyCheckTaskTest extends AssertJUnit task.execute(); - assertEquals("", logRecorder.getLogContent()); + assertEquals("INFO OPERATION.DataSetAndPathInfoDBConsistencyCheckTask - " + + "Check 1 registered since 1970-01-01 01:00:00", logRecorder.getLogContent()); assertEquals(true, fileContent.isClosed()); assertEquals(true, pathInfoContent.isClosed()); context.assertIsSatisfied(); @@ -114,7 +115,9 @@ public class DataSetAndPathInfoDBConsistencyCheckTaskTest extends AssertJUnit task.execute(); - assertEquals("ERROR OPERATION.DataSetAndPathInfoDBConsistencyChecker - " + assertEquals("INFO OPERATION.DataSetAndPathInfoDBConsistencyCheckTask - " + + "Check 1 registered since 1970-01-01 01:00:00\n" + + "ERROR OPERATION.DataSetAndPathInfoDBConsistencyChecker - " + "Couldn't check consistency of the file system and " + "the path info database for a data set: ds1\n" + "java.lang.RuntimeException: Oohps!\n" @@ -158,7 +161,9 @@ public class DataSetAndPathInfoDBConsistencyCheckTaskTest extends AssertJUnit task.execute(); assertEquals( - "ERROR NOTIFY.DataSetAndPathInfoDBConsistencyCheckTask - " + "INFO OPERATION.DataSetAndPathInfoDBConsistencyCheckTask - " + + "Check 4 registered since 1970-01-01 01:00:00\n" + + "ERROR NOTIFY.DataSetAndPathInfoDBConsistencyCheckTask - " + "File system and path info DB consistency check report " + "for all data sets since 1970-01-01 01:00:00\n\n" + "Data sets checked:\n\nds1, ds2, ds3, ds4\n\n"