diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/DssRegistrationLogDirectoryHelper.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/DssRegistrationLogDirectoryHelper.java index d0afffead17c874b746c510ace96d3652d88a3f0..783ef45bb32fdca49f74e2bae6b834a1045713c9 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/DssRegistrationLogDirectoryHelper.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/DssRegistrationLogDirectoryHelper.java @@ -18,9 +18,6 @@ package ch.systemsx.cisd.etlserver; import java.io.File; import java.io.IOException; -import java.util.GregorianCalendar; - -import org.apache.commons.lang.time.DateFormatUtils; import ch.systemsx.cisd.base.exceptions.IOExceptionUnchecked; import ch.systemsx.cisd.common.filesystem.IFileOperations; @@ -102,27 +99,7 @@ public class DssRegistrationLogDirectoryHelper */ String generateLogFileName(String name, String threadName) { - String sectionSeparator = "_"; - - // The log file name is YYYY-MM-DD_HH-mm-ss-SSS_threadName_name.log - StringBuilder logFilename = new StringBuilder(); - GregorianCalendar calendar = new GregorianCalendar(); - - String dateSection = DateFormatUtils.ISO_DATE_FORMAT.format(calendar); - logFilename.append(dateSection); - logFilename.append(sectionSeparator); - - String timeSection = DateFormatUtils.format(calendar, "HH-mm-ss-SSS"); - logFilename.append(timeSection); - logFilename.append(sectionSeparator); - - logFilename.append(threadName); - logFilename.append(sectionSeparator); - - logFilename.append(name); - logFilename.append(".log"); - - return logFilename.toString(); + return new DssUniqueFilenameGenerator(threadName, name, ".log").generateFilename(); } private void createDirectoryIfNecessary(File dir) diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/DssUniqueFilenameGenerator.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/DssUniqueFilenameGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..d8a982d56d84ca33df35ab865424f98813a5b8b5 --- /dev/null +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/DssUniqueFilenameGenerator.java @@ -0,0 +1,79 @@ +/* + * Copyright 2012 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.etlserver; + +import java.util.GregorianCalendar; + +import org.apache.commons.lang.time.DateFormatUtils; + +/** + * Generate a filename comprised of a timestamp and the information specified in the constructor. + * + * @author Chandrasekhar Ramakrishnan + */ +public class DssUniqueFilenameGenerator +{ + private final String sectionSeparator = "_"; + + private final String threadName; + + private final String name; + + private final String extensionOrNull; + + /** + * Specify the information used to generate the filename + * + * @param threadName + * @param name + * @param extensionOrNull + */ + public DssUniqueFilenameGenerator(String threadName, String name, String extensionOrNull) + { + super(); + this.threadName = threadName; + this.name = name; + this.extensionOrNull = extensionOrNull; + } + + public String generateFilename() + { + + // The log file name is YYYY-MM-DD_HH-mm-ss-SSS_threadName_name.log + StringBuilder filename = new StringBuilder(); + GregorianCalendar calendar = new GregorianCalendar(); + + String dateSection = DateFormatUtils.ISO_DATE_FORMAT.format(calendar); + filename.append(dateSection); + filename.append(sectionSeparator); + + String timeSection = DateFormatUtils.format(calendar, "HH-mm-ss-SSS"); + filename.append(timeSection); + filename.append(sectionSeparator); + + filename.append(threadName); + filename.append(sectionSeparator); + + filename.append(name); + if (null != extensionOrNull) + { + filename.append(extensionOrNull); + } + return filename.toString(); + } + +} diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/AbstractOmniscientTopLevelDataSetRegistrator.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/AbstractOmniscientTopLevelDataSetRegistrator.java index 765be5f9dc61447bcd2cfe51f7c0699ca101d231..71970e67d5970c8658cbdeacd24a6e1bd88662a8 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/AbstractOmniscientTopLevelDataSetRegistrator.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/AbstractOmniscientTopLevelDataSetRegistrator.java @@ -45,6 +45,7 @@ import ch.systemsx.cisd.common.utilities.ExtendedProperties; import ch.systemsx.cisd.common.utilities.IDelegatedActionWithResult; import ch.systemsx.cisd.etlserver.AbstractTopLevelDataSetRegistrator; import ch.systemsx.cisd.etlserver.DataStrategyStore; +import ch.systemsx.cisd.etlserver.DssUniqueFilenameGenerator; import ch.systemsx.cisd.etlserver.IDataStrategyStore; import ch.systemsx.cisd.etlserver.IPostRegistrationAction; import ch.systemsx.cisd.etlserver.IPreRegistrationAction; @@ -348,7 +349,12 @@ public abstract class AbstractOmniscientTopLevelDataSetRegistrator<T extends Dat private File copyIncomingFileToPreStaging(File incomingDataSetFile) { - File preStagingDir = state.getGlobalState().getPreStagingDir(); + TopLevelDataSetRegistratorGlobalState globalState = state.getGlobalState(); + File preStagingRootDir = globalState.getPreStagingDir(); + String incomingDirName = new DssUniqueFilenameGenerator(globalState.getThreadParameters().getThreadName(), incomingDataSetFile.getName(), null).generateFilename(); + File preStagingDir = new File(preStagingRootDir, incomingDirName); + preStagingDir.mkdir(); + // Try to find a hardlink maker IImmutableCopier hardlinkMaker = FastRecursiveHardLinkMaker.tryCreate(); boolean linkWasMade = false; diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/DssComponentTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/DssComponentTest.java index 1a2f7e4df8a41f690bc04db274bcc7236d37dc0e..3e0855da5308d2be170d6543bee2bb160b5fcd4a 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/DssComponentTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/DssComponentTest.java @@ -139,7 +139,7 @@ public class DssComponentTest extends SystemTestCase "^\\t\\d+-\\d+$", "^\\d{2}:\\d{2}:\\d{2} Data has been moved to the store.$", "^\\d{2}:\\d{2}:\\d{2} Data has been registered with the openBIS Application Server.$", - "^\\d{2}:\\d{2}:\\d{2} Storage processors have committed.$" + "^\\d{2}:\\d{2}:\\d{2} Storage processors have been committed.$" }; checkLogFileContents(logFile, expectedContents); @@ -158,7 +158,7 @@ public class DssComponentTest extends SystemTestCase int i = 0; for (String expected : expectedContents) { - assertTrue(logFileContents.get(i), Pattern.matches(expected, logFileContents.get(i++))); + assertTrue(expected + ".matches(" + logFileContents.get(i) + ")", Pattern.matches(expected, logFileContents.get(i++))); } }