Skip to content
Snippets Groups Projects
Commit 0420fc1e authored by jakubs's avatar jakubs
Browse files

SSDM-2197: data set type based share finder

SVN: 34511
parent 751b46ef
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2015 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.dss.generic.shared.utils.ShareFactory;
import ch.systemsx.cisd.openbis.generic.shared.dto.SimpleDataSetInformationDTO;
/**
* Share finder for shares associated to certain data set types as specified in the property {@link ShareFactory#DATA_SET_TYPES_PROP} of
* {@link ShareFactory#SHARE_PROPS_FILE} file.
* <p>
* Returns the first share which has enough space and where the data set type of the data set to be shuffled matches one of the data set types
* associated with the share.
*
* @author Jakub Straszewski
*/
public class DataSetTypeBasedShareFinder implements IShareFinder
{
public DataSetTypeBasedShareFinder(Properties properties)
{
}
@Override
public Share tryToFindShare(SimpleDataSetInformationDTO dataSet, List<Share> shares)
{
for (Share share : shares)
{
if (share.getDataSetTypes().contains(dataSet.getDataSetType())
&& share.calculateFreeSpace() > dataSet.getDataSetSize())
{
return share;
}
}
return null;
}
}
......@@ -95,6 +95,8 @@ public final class Share
private Set<String> experimentIdentifiers;
private Set<String> dataSetTypes;
public Share(File share, int speed,
IFreeSpaceProvider freeSpaceProvider)
{
......@@ -124,6 +126,19 @@ public final class Share
this.experimentIdentifiers = experimentIdentifiers;
}
/**
* Returns the set of data set types or an empty set if undefined
*/
public Set<String> getDataSetTypes()
{
return dataSetTypes;
}
public void setDataSetTypes(Set<String> dataSetTypes)
{
this.dataSetTypes = dataSetTypes;
}
/**
* Returns the share Id of this share.
*/
......
......@@ -64,6 +64,8 @@ public class ShareFactory
public static final String EXPERIMENTS_PROP = "experiments";
public static final String DATA_SET_TYPES_PROP = "data_set_types";
private int speed = Math.abs(Constants.DEFAULT_SPEED_HINT);
private ShufflePriority shufflePriority = ShufflePriority.SPEED;
......@@ -76,6 +78,8 @@ public class ShareFactory
private Set<String> experimentIdentifiers = Collections.emptySet();
private Set<String> dataSetTypes = Collections.emptySet();
Share createShare(final SharesHolder sharesHolder, File shareRoot,
IFreeSpaceProvider freeSpaceProvider, ISimpleLogger log)
{
......@@ -87,6 +91,7 @@ public class ShareFactory
share.setUnarchivingScratchShare(unarchivingScratchShare);
share.setIgnoredForShuffling(ignoredForShuffling);
share.setExperimentIdentifiers(experimentIdentifiers);
share.setDataSetTypes(dataSetTypes);
return share;
}
......@@ -143,6 +148,9 @@ public class ShareFactory
experimentIdentifiers =
new HashSet<String>(Arrays.asList(PropertyParametersUtil.parseItemisedProperty(
props.getProperty(EXPERIMENTS_PROP, ""), EXPERIMENTS_PROP)));
dataSetTypes =
new HashSet<String>(Arrays.asList(PropertyParametersUtil.parseItemisedProperty(
props.getProperty(DATA_SET_TYPES_PROP, ""), DATA_SET_TYPES_PROP)));
}
}
......
/*
* 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.openbis.dss.generic.shared;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.dss.generic.shared.utils.Share;
import ch.systemsx.cisd.openbis.generic.shared.dto.SimpleDataSetInformationDTO;
/**
* @author Franz-Josef Elmer
*/
public class DataSetTypeBasedShareFinderTest extends AbstractIShareFinderTestCase
{
private IShareFinder finder = new DataSetTypeBasedShareFinder(new Properties());
private List<Share> shares;
@BeforeMethod
public void setUp()
{
Share share1 = extensionShare("1", 100 * FileUtils.ONE_KB);
share1.setDataSetTypes(new HashSet<String>(Arrays.asList("TYPE_A")));
Share share2 = extensionShare("2", 200 * FileUtils.ONE_KB);
share2.setDataSetTypes(new HashSet<String>(Arrays.asList("TYPE_B")));
Share share3 = extensionShare("3", 300 * FileUtils.ONE_KB);
share3.setDataSetTypes(new HashSet<String>());
shares = Arrays.asList(share1, share2, share3);
}
@Test
public void testMatchingDataSetType()
{
SimpleDataSetInformationDTO dataSet = new SimpleDataSetInformationDTO();
dataSet.setSpaceCode("S1");
dataSet.setProjectCode("P1");
dataSet.setExperimentCode("EXP3");
dataSet.setDataSetSize(42 * FileUtils.ONE_KB);
dataSet.setDataSetType("TYPE_A");
Share share = finder.tryToFindShare(dataSet, shares);
assertEquals("1", share.getShareId());
}
@Test
public void testNoMatchingDataSetTypes()
{
SimpleDataSetInformationDTO dataSet = new SimpleDataSetInformationDTO();
dataSet.setSpaceCode("S1");
dataSet.setProjectCode("P1");
dataSet.setExperimentCode("EXP3");
dataSet.setDataSetSize(42 * FileUtils.ONE_KB);
dataSet.setDataSetType("TYPE_C");
Share share = finder.tryToFindShare(dataSet, shares);
assertEquals(null, share);
}
@Test
public void testMatchingDataSetTypeButNotEnoughSpace()
{
SimpleDataSetInformationDTO dataSet = new SimpleDataSetInformationDTO();
dataSet.setSpaceCode("S1");
dataSet.setProjectCode("P1");
dataSet.setExperimentCode("EXP3");
dataSet.setDataSetSize(142 * FileUtils.ONE_KB);
dataSet.setDataSetType("TYPE_A");
Share share = finder.tryToFindShare(dataSet, shares);
assertEquals(null, share);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment