diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/postregistration/SimpleShareFinder.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/postregistration/SimpleShareFinder.java index fc60a606bc86059920c7d4edbf3be6f361da8d26..170fa113b1ee396bf3b23055e2801e6eaeeb508f 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/postregistration/SimpleShareFinder.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/postregistration/SimpleShareFinder.java @@ -16,80 +16,19 @@ package ch.systemsx.cisd.etlserver.postregistration; -import java.util.List; import java.util.Properties; -import ch.systemsx.cisd.openbis.dss.generic.shared.IShareFinder; -import ch.systemsx.cisd.openbis.dss.generic.shared.utils.Share; -import ch.systemsx.cisd.openbis.generic.shared.dto.SimpleDataSetInformationDTO; - /** - * Simple share finder tries to find the external share with maximum free space larger than the size - * of the data set to be moved. If no such external share can be found it tries to find the incoming - * share with maximum free space larger than the size of the data set to be moved and which is not - * the share of the data set. + * The class is only here for backward compatibility with older configurations. * - * @author Franz-Josef Elmer + * @author Kaloyan Enimanev */ -public class SimpleShareFinder implements IShareFinder +public class SimpleShareFinder extends + ch.systemsx.cisd.openbis.dss.generic.shared.SimpleShareFinder { public SimpleShareFinder(Properties properties) { - - } - - public Share tryToFindShare(SimpleDataSetInformationDTO dataSet, List<Share> shares) - { - Long dataSetSize = dataSet.getDataSetSize(); - String dataSetShareId = dataSet.getDataSetShareId(); - long dataSetShareFreeSpace = 0; - boolean dataSetShareIncoming = false; - Share incomingShareWithMostFree = null; - long incomingMaxFreeSpace = dataSetSize; - Share extensionShareWithMostFree = null; - long extensionsMaxFreeSpace = dataSetSize; - for (Share share : shares) - { - long freeSpace = share.calculateFreeSpace(); - String shareId = share.getShareId(); - if (dataSetShareId.equals(shareId)) - { - dataSetShareFreeSpace = freeSpace; - dataSetShareIncoming = share.isIncoming(); - continue; - } - if (share.isIncoming()) - { - if (freeSpace > incomingMaxFreeSpace) - { - incomingMaxFreeSpace = freeSpace; - incomingShareWithMostFree = share; - } - } else - { - if (freeSpace > extensionsMaxFreeSpace) - { - extensionsMaxFreeSpace = freeSpace; - extensionShareWithMostFree = share; - } - } - } - if (extensionShareWithMostFree != null) - { - if (dataSetShareIncoming - || extensionsMaxFreeSpace - dataSetSize > dataSetShareFreeSpace) - { - return extensionShareWithMostFree; - } - } else if (incomingShareWithMostFree != null) - { - if (dataSetShareIncoming == false - || incomingMaxFreeSpace - dataSetSize > dataSetShareFreeSpace) - { - return incomingShareWithMostFree; - } - } - return null; + super(properties); } } diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/AbstractArchiverProcessingPlugin.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/AbstractArchiverProcessingPlugin.java index 7bba8c0cd415b2614262f8ade1d87eb941ab3c11..c6e86bbf0d2cfeba7568c36179937062e7a2eca5 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/AbstractArchiverProcessingPlugin.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/AbstractArchiverProcessingPlugin.java @@ -29,6 +29,7 @@ import java.util.Properties; import java.util.Set; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; import ch.rinn.restrictions.Private; import ch.systemsx.cisd.common.collections.CollectionUtils; @@ -51,6 +52,7 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.IncomingShareIdProvider; import ch.systemsx.cisd.openbis.dss.generic.shared.ProcessingStatus; import ch.systemsx.cisd.openbis.dss.generic.shared.QueueingDataSetStatusUpdaterService; import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider; +import ch.systemsx.cisd.openbis.dss.generic.shared.SimpleShareFinder; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetCodesWithStatus; import ch.systemsx.cisd.openbis.dss.generic.shared.utils.SegmentedStoreUtils; import ch.systemsx.cisd.openbis.dss.generic.shared.utils.Share; @@ -277,23 +279,13 @@ public abstract class AbstractArchiverProcessingPlugin extends AbstractDatastore private void setUpUnarchivingPreparation(ArchiverTaskContext context) { - Properties props = - PropertyParametersUtil.extractSingleSectionProperties(properties, SHARE_FINDER_KEY, - false).getProperties(); - if (props.isEmpty()) - { - return; - } - String dataStoreCode = ServiceProvider.getConfigProvider().getDataStoreCode(); Set<String> incomingShares = IncomingShareIdProvider.getIdsOfIncomingShares(); IFreeSpaceProvider freeSpaceProvider = new SimpleFreeSpaceProvider(); List<Share> shares = SegmentedStoreUtils.getDataSetsPerShare(storeRoot, dataStoreCode, incomingShares, freeSpaceProvider, getService(), new Log4jSimpleLogger(operationLog)); - IShareFinder shareFinder = - ClassUtils.create(IShareFinder.class, props.getProperty("class"), props); - context.setUnarchivingPreparation(new UnarchivingPreparation(shareFinder, + context.setUnarchivingPreparation(new UnarchivingPreparation(getShareFinder(), getShareIdManager(), getService(), shares)); } @@ -536,6 +528,25 @@ public abstract class AbstractArchiverProcessingPlugin extends AbstractDatastore return shareIdManager; } + private IShareFinder getShareFinder() + { + Properties props = + PropertyParametersUtil.extractSingleSectionProperties(properties, SHARE_FINDER_KEY, + false).getProperties(); + + String className = props.getProperty("class"); + if (StringUtils.isEmpty(className)) + { + // use simple share finder by default when no share finder is configured + className = SimpleShareFinder.class.getName(); + } + + IShareFinder shareFinder = ClassUtils.create(IShareFinder.class, className, props); + + return shareFinder; + } + + private IEncapsulatedOpenBISService getService() { if (service == null) diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/SimpleShareFinder.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/SimpleShareFinder.java new file mode 100644 index 0000000000000000000000000000000000000000..12680609b8b8fd56941f6d9e66eed738b355fa65 --- /dev/null +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/SimpleShareFinder.java @@ -0,0 +1,94 @@ +/* + * Copyright 2011 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.shared; + +import java.util.List; +import java.util.Properties; + +import ch.systemsx.cisd.openbis.dss.generic.shared.utils.Share; +import ch.systemsx.cisd.openbis.generic.shared.dto.SimpleDataSetInformationDTO; + +/** + * Simple share finder tries to find the external share with maximum free space larger than the size + * of the data set to be moved. If no such external share can be found it tries to find the incoming + * share with maximum free space larger than the size of the data set to be moved and which is not + * the share of the data set. + * + * @author Franz-Josef Elmer + */ +public class SimpleShareFinder implements IShareFinder +{ + public SimpleShareFinder(Properties properties) + { + + } + + public Share tryToFindShare(SimpleDataSetInformationDTO dataSet, List<Share> shares) + { + Long dataSetSize = dataSet.getDataSetSize(); + String dataSetShareId = dataSet.getDataSetShareId(); + long dataSetShareFreeSpace = 0; + boolean dataSetShareIncoming = false; + Share incomingShareWithMostFree = null; + long incomingMaxFreeSpace = dataSetSize; + Share extensionShareWithMostFree = null; + long extensionsMaxFreeSpace = dataSetSize; + for (Share share : shares) + { + long freeSpace = share.calculateFreeSpace(); + String shareId = share.getShareId(); + if (dataSetShareId.equals(shareId)) + { + dataSetShareFreeSpace = freeSpace; + dataSetShareIncoming = share.isIncoming(); + continue; + } + if (share.isIncoming()) + { + if (freeSpace > incomingMaxFreeSpace) + { + incomingMaxFreeSpace = freeSpace; + incomingShareWithMostFree = share; + } + } else + { + if (freeSpace > extensionsMaxFreeSpace) + { + extensionsMaxFreeSpace = freeSpace; + extensionShareWithMostFree = share; + } + } + } + if (extensionShareWithMostFree != null) + { + if (dataSetShareIncoming + || extensionsMaxFreeSpace - dataSetSize > dataSetShareFreeSpace) + { + return extensionShareWithMostFree; + } + } else if (incomingShareWithMostFree != null) + { + if (dataSetShareIncoming == false + || incomingMaxFreeSpace - dataSetSize > dataSetShareFreeSpace) + { + return incomingShareWithMostFree; + } + } + return null; + } + +} diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/postregistration/SimpleShareFinderTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/shared/SimpleShareFinderTest.java similarity index 96% rename from datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/postregistration/SimpleShareFinderTest.java rename to datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/shared/SimpleShareFinderTest.java index 585f12e4c03c313d56fb02de06b12dfe4cb49655..52741f689ac96da9dcde701f91cd12c9292b80ea 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/postregistration/SimpleShareFinderTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/shared/SimpleShareFinderTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package ch.systemsx.cisd.etlserver.postregistration; +package ch.systemsx.cisd.openbis.dss.generic.shared; import java.io.File; import java.io.IOException; @@ -27,6 +27,7 @@ import org.testng.annotations.Test; import ch.systemsx.cisd.common.filesystem.HostAwareFile; import ch.systemsx.cisd.common.filesystem.IFreeSpaceProvider; +import ch.systemsx.cisd.etlserver.postregistration.SimpleShareFinder; import ch.systemsx.cisd.openbis.dss.generic.shared.utils.Share; import ch.systemsx.cisd.openbis.generic.shared.dto.SimpleDataSetInformationDTO;