Skip to content

Commit 4ba24fd

Browse files
winterhazelLocharla, Sandeep
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 2eb53a4 commit 4ba24fd

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
@@ -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.logging.log4j.Logger;
@@ -112,6 +114,9 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
112114
@Inject
113115
SnapshotDao snapshotDao;
114116

117+
@Inject
118+
HeuristicRuleHelper heuristicRuleHelper;
119+
115120
@Override
116121
public StrategyPriority canHandle(DataObject srcData, DataObject destData) {
117122
return StrategyPriority.DEFAULT;
@@ -379,7 +384,13 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData)
379384
}
380385
// need to find a nfs or cifs image store, assuming that can't copy volume
381386
// directly to s3
382-
ImageStoreEntity imageStore = (ImageStoreEntity)dataStoreMgr.getImageStoreWithFreeCapacity(destScope.getScopeId());
387+
Long zoneId = destScope.getScopeId();
388+
ImageStoreEntity imageStore = (ImageStoreEntity) heuristicRuleHelper.getImageStoreIfThereIsHeuristicRule(zoneId, HeuristicType.VOLUME, destData);
389+
if (imageStore == null) {
390+
logger.debug("Secondary storage selector did not direct volume migration to a specific secondary storage; using secondary storage with the most free capacity.");
391+
imageStore = (ImageStoreEntity) dataStoreMgr.getImageStoreWithFreeCapacity(zoneId);
392+
}
393+
383394
if (imageStore == null || !imageStore.getProtocol().equalsIgnoreCase("nfs") && !imageStore.getProtocol().equalsIgnoreCase("cifs")) {
384395
String errMsg = "can't find a nfs (or cifs) image store to satisfy the need for a staging store";
385396
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)