Skip to content

Commit 7071461

Browse files
committed
Consider secondary storage selectors during cold volume migration
1 parent 823080c commit 7071461

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@
4545
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
4646
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
4747
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
48+
import org.apache.cloudstack.secstorage.heuristics.HeuristicType;
4849
import org.apache.cloudstack.storage.RemoteHostEndPoint;
4950
import org.apache.cloudstack.storage.command.CopyCommand;
5051
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
5152
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
53+
import org.apache.cloudstack.storage.heuristics.HeuristicRuleHelper;
5254
import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
5355
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
5456
import org.apache.logging.log4j.Logger;
@@ -104,6 +106,9 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
104106
@Inject
105107
SnapshotDao snapshotDao;
106108

109+
@Inject
110+
HeuristicRuleHelper heuristicRuleHelper;
111+
107112
@Override
108113
public StrategyPriority canHandle(DataObject srcData, DataObject destData) {
109114
return StrategyPriority.DEFAULT;
@@ -374,7 +379,13 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData)
374379
}
375380
// need to find a nfs or cifs image store, assuming that can't copy volume
376381
// directly to s3
377-
ImageStoreEntity imageStore = (ImageStoreEntity)dataStoreMgr.getImageStoreWithFreeCapacity(destScope.getScopeId());
382+
Long zoneId = destScope.getScopeId();
383+
ImageStoreEntity imageStore = (ImageStoreEntity) heuristicRuleHelper.getImageStoreIfThereIsHeuristicRule(zoneId, HeuristicType.VOLUME, destData);
384+
if (imageStore == null) {
385+
logger.debug("Secondary storage selector did not direct volume migration to a specific secondary storage; using secondary storage with the most free capacity.");
386+
imageStore = (ImageStoreEntity) dataStoreMgr.getImageStoreWithFreeCapacity(zoneId);
387+
}
388+
378389
if (imageStore == null || !imageStore.getProtocol().equalsIgnoreCase("nfs") && !imageStore.getProtocol().equalsIgnoreCase("cifs")) {
379390
String errMsg = "can't find a nfs (or cifs) image store to satisfy the need for a staging store";
380391
Answer answer = new Answer(null, false, errMsg);

server/src/main/java/org/apache/cloudstack/storage/heuristics/HeuristicRuleHelper.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ protected void buildPresetVariables(JsInterpreter jsInterpreter, HeuristicType h
117117
accountId = ((SnapshotInfo) obj).getAccountId();
118118
break;
119119
case VOLUME:
120-
presetVariables.setVolume(setVolumePresetVariable((VolumeVO) obj));
121-
accountId = ((VolumeVO) obj).getAccountId();
120+
presetVariables.setVolume(setVolumePresetVariable((com.cloud.storage.Volume) obj));
121+
accountId = ((com.cloud.storage.Volume) obj).getAccountId();
122122
break;
123123
}
124124
presetVariables.setAccount(setAccountPresetVariable(accountId));
@@ -191,14 +191,14 @@ protected Template setTemplatePresetVariable(VMTemplateVO templateVO) {
191191
return template;
192192
}
193193

194-
protected Volume setVolumePresetVariable(VolumeVO volumeVO) {
195-
Volume volume = new Volume();
194+
protected Volume setVolumePresetVariable(com.cloud.storage.Volume volumeVO) {
195+
Volume volumePresetVariable = new Volume();
196196

197-
volume.setName(volumeVO.getName());
198-
volume.setFormat(volumeVO.getFormat());
199-
volume.setSize(volumeVO.getSize());
197+
volumePresetVariable.setName(volumeVO.getName());
198+
volumePresetVariable.setFormat(volumeVO.getFormat());
199+
volumePresetVariable.setSize(volumeVO.getSize());
200200

201-
return volume;
201+
return volumePresetVariable;
202202
}
203203

204204
protected Snapshot setSnapshotPresetVariable(SnapshotInfo snapshotInfo) {

0 commit comments

Comments
 (0)