Skip to content

Commit 86754b3

Browse files
winterhazeldhslove
authored andcommitted
Consider secondary storage selectors during cold volume migration (apache#10957)
The secondary storage selectors allow operators to specify, for instance, that volumes should go to a specific secondary storage A. Thus, when uploading a volume, it will always be downloaded to secondary storage A. The cold volume migration moves volumes to a secondary storage before moving them to the destination primary storage. This process does not consider the secondary storage selectors. However, some companies want to dedicate specific secondary storages for cold migration. To address this, this PR makes the cold volume migration process consider the secondary storage selectors.
1 parent da79725 commit 86754b3

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

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
@@ -47,10 +47,12 @@
4747
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
4848
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
4949
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
50+
import org.apache.cloudstack.secstorage.heuristics.HeuristicType;
5051
import org.apache.cloudstack.storage.RemoteHostEndPoint;
5152
import org.apache.cloudstack.storage.command.CopyCommand;
5253
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
5354
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
55+
import org.apache.cloudstack.storage.heuristics.HeuristicRuleHelper;
5456
import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
5557
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
5658
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
@@ -117,6 +119,9 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
117119
@Inject
118120
SnapshotDao snapshotDao;
119121

122+
@Inject
123+
HeuristicRuleHelper heuristicRuleHelper;
124+
120125
@Override
121126
public StrategyPriority canHandle(DataObject srcData, DataObject destData) {
122127
return StrategyPriority.DEFAULT;
@@ -392,7 +397,13 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData)
392397
}
393398
// need to find a nfs or cifs image store, assuming that can't copy volume
394399
// directly to s3
395-
ImageStoreEntity imageStore = (ImageStoreEntity)dataStoreMgr.getImageStoreWithFreeCapacity(destScope.getScopeId());
400+
Long zoneId = destScope.getScopeId();
401+
ImageStoreEntity imageStore = (ImageStoreEntity) heuristicRuleHelper.getImageStoreIfThereIsHeuristicRule(zoneId, HeuristicType.VOLUME, destData);
402+
if (imageStore == null) {
403+
logger.debug("Secondary storage selector did not direct volume migration to a specific secondary storage; using secondary storage with the most free capacity.");
404+
imageStore = (ImageStoreEntity) dataStoreMgr.getImageStoreWithFreeCapacity(zoneId);
405+
}
406+
396407
if (imageStore == null || !imageStore.getProtocol().equalsIgnoreCase("nfs") && !imageStore.getProtocol().equalsIgnoreCase("cifs")) {
397408
String errMsg = "can't find a nfs (or cifs) image store to satisfy the need for a staging store";
398409
Answer answer = new Answer(null, false, errMsg);

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

Lines changed: 6 additions & 6 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

197197
volumePresetVariable.setName(volumeVO.getName());
198-
volumePresetVariable.setFormat(volumeVO.getFormat().toString());
198+
volumePresetVariable.setFormat(volumeVO.getFormat());
199199
volumePresetVariable.setSize(volumeVO.getSize());
200200

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

204204
protected Snapshot setSnapshotPresetVariable(SnapshotInfo snapshotInfo) {

0 commit comments

Comments
 (0)