CLOUDSTACK-4190:[Object_store_refactor] volume should be deleted from

staging storage after successfule volume migration .
This commit is contained in:
Min Chen 2013-08-08 16:16:36 -07:00
parent dfe99a5b15
commit bf6961255a
3 changed files with 89 additions and 67 deletions

View File

@ -329,6 +329,10 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
CopyCommand cmd = new CopyCommand(cacheData.getTO(), destData.getTO(), _copyvolumewait, _mgmtServer.getExecuteInSequence());
EndPoint ep = selector.select(cacheData, destData);
Answer answer = ep.sendMessage(cmd);
// delete volume on cache store
if (cacheData != null) {
cacheMgr.deleteCacheObject(cacheData);
}
return answer;
}

View File

@ -876,7 +876,7 @@ public class VolumeServiceImpl implements VolumeService {
future.complete(res);
}
} catch (Exception e) {
s_logger.error("Failed to process copy volume callback", e);
s_logger.error("Failed to process migrate volume callback", e);
res.setResult(e.toString());
future.complete(res);
}

View File

@ -27,6 +27,21 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import com.google.gson.Gson;
import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.VirtualDeviceConfigSpec;
import com.vmware.vim25.VirtualDeviceConfigSpecOperation;
import com.vmware.vim25.VirtualDisk;
import com.vmware.vim25.VirtualEthernetCard;
import com.vmware.vim25.VirtualLsiLogicController;
import com.vmware.vim25.VirtualMachineConfigSpec;
import com.vmware.vim25.VirtualMachineFileInfo;
import com.vmware.vim25.VirtualMachineGuestOsIdentifier;
import com.vmware.vim25.VirtualSCSISharing;
import org.apache.cloudstack.storage.command.AttachAnswer;
import org.apache.cloudstack.storage.command.AttachCommand;
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
@ -39,8 +54,6 @@ import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
import org.apache.cloudstack.storage.to.TemplateObjectTO;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
@ -73,17 +86,6 @@ import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
import com.cloud.utils.script.Script;
import com.cloud.vm.VirtualMachine.State;
import com.google.gson.Gson;
import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.VirtualDeviceConfigSpec;
import com.vmware.vim25.VirtualDeviceConfigSpecOperation;
import com.vmware.vim25.VirtualDisk;
import com.vmware.vim25.VirtualEthernetCard;
import com.vmware.vim25.VirtualLsiLogicController;
import com.vmware.vim25.VirtualMachineConfigSpec;
import com.vmware.vim25.VirtualMachineFileInfo;
import com.vmware.vim25.VirtualMachineGuestOsIdentifier;
import com.vmware.vim25.VirtualSCSISharing;
public class VmwareStorageProcessor implements StorageProcessor {
private static final Logger s_logger = Logger.getLogger(VmwareStorageProcessor.class);
@ -236,8 +238,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
VirtualMachineMO templateMo = VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templateUuidName), true);
if (templateMo == null) {
if(s_logger.isInfoEnabled())
if(s_logger.isInfoEnabled()) {
s_logger.info("Template " + templateName + " is not setup yet, setup template from secondary storage with uuid name: " + templateUuidName);
}
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, primaryStore.getUuid());
assert (morDs != null);
DatastoreMO primaryStorageDatastoreMo = new DatastoreMO(context, morDs);
@ -272,8 +275,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
throw new Exception(msg);
}
if(dsMo.folderExists(String.format("[%s]", dsMo.getName()), vmdkName))
if(dsMo.folderExists(String.format("[%s]", dsMo.getName()), vmdkName)) {
dsMo.deleteFile(String.format("[%s] %s/", dsMo.getName(), vmdkName), dcMo.getMor(), false);
}
s_logger.info("creating linked clone from template");
if (!vmTemplate.createLinkedClone(vmdkName, morBaseSnapshot, dcMo.getVmFolder(), morPool, morDatastore)) {
@ -299,8 +303,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
private boolean createVMFullClone(VirtualMachineMO vmTemplate, DatacenterMO dcMo, DatastoreMO dsMo,
String vmdkName, ManagedObjectReference morDatastore, ManagedObjectReference morPool) throws Exception {
if(dsMo.folderExists(String.format("[%s]", dsMo.getName()), vmdkName))
if(dsMo.folderExists(String.format("[%s]", dsMo.getName()), vmdkName)) {
dsMo.deleteFile(String.format("[%s] %s/", dsMo.getName(), vmdkName), dcMo.getMor(), false);
}
s_logger.info("creating full clone from template");
if (!vmTemplate.createFullClone(vmdkName, dcMo.getVmFolder(), morPool, morDatastore)) {
@ -339,8 +344,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter());
VirtualMachineMO vmMo = null;
ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, primaryStore.getUuid());
if (morDatastore == null)
if (morDatastore == null) {
throw new Exception("Unable to find datastore in vSphere");
}
DatastoreMO dsMo = new DatastoreMO(context, morDatastore);
@ -414,7 +420,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
this.hostService.invalidateServiceContext(null);
}
String msg = "CreateCommand failed due to " + VmwareHelper.getExceptionMessage(e);
String msg = "CopyCommand failed due to " + VmwareHelper.getExceptionMessage(e);
s_logger.error(msg, e);
return new CopyCmdAnswer(e.toString());
}
@ -644,10 +650,11 @@ public class VmwareStorageProcessor implements StorageProcessor {
out.write("ova.size=" + size);
out.newLine();
} finally {
if(out != null)
if(out != null) {
out.close();
}
}
}
private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vmMo, String installPath, long templateId, String templateUniqueName,
String secStorageUrl, String volumePath, String workerVmName) throws Exception {
@ -736,8 +743,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(volume.getVmName());
if (vmMo == null) {
if(s_logger.isDebugEnabled())
if(s_logger.isDebugEnabled()) {
s_logger.debug("Unable to find the owner VM for CreatePrivateTemplateFromVolumeCommand on host " + hyperHost.getHyperHostName() + ", try within datacenter");
}
vmMo = hyperHost.findVmOnPeerHyperHost(volume.getVmName());
if (vmMo == null) {
@ -798,10 +806,11 @@ public class VmwareStorageProcessor implements StorageProcessor {
out.write("disk1.size=" + diskSize);
out.newLine();
} finally {
if(out != null)
if(out != null) {
out.close();
}
}
}
private Ternary<String, Long, Long> createTemplateFromSnapshot(String installPath, String templateUniqueName,
String secStorageUrl, String snapshotPath, Long templateId) throws Exception {
@ -986,10 +995,11 @@ public class VmwareStorageProcessor implements StorageProcessor {
Script command = new Script(false, "mkdir", _timeout, s_logger);
command.add("-p");
command.add(exportPath);
if(command.execute() != null)
if(command.execute() != null) {
throw new Exception("unable to prepare snapshot backup directory");
}
}
}
VirtualMachineMO clonedVm = null;
try {
@ -1068,8 +1078,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
try {
vmMo = hyperHost.findVmOnHyperHost(vmName);
if (vmMo == null) {
if(s_logger.isDebugEnabled())
if(s_logger.isDebugEnabled()) {
s_logger.debug("Unable to find owner VM for BackupSnapshotCommand on host " + hyperHost.getHyperHostName() + ", will try within datacenter");
}
vmMo = hyperHost.findVmOnPeerHyperHost(vmName);
if(vmMo == null) {
@ -1231,8 +1242,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
VmwareHypervisorHost hyperHost = this.hostService.getHyperHost(this.hostService.getServiceContext(null), null);
ManagedObjectReference morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), storeName.replace("-", ""));
if (morDatastore == null)
if (morDatastore == null) {
throw new Exception("Unable to mount secondary storage on host. storeUrl: " + storeUrl);
}
return morDatastore;
}
@ -1250,8 +1262,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
TemplateObjectTO iso = (TemplateObjectTO)disk.getData();
NfsTO nfsImageStore = (NfsTO)iso.getDataStore();
String storeUrl = null;
if (nfsImageStore != null)
if (nfsImageStore != null) {
storeUrl = nfsImageStore.getUrl();
}
if (storeUrl == null) {
if (!iso.getName().equalsIgnoreCase("vmware-tools.iso")) {
String msg = "ISO store root url is not found in AttachIsoCommand";
@ -1364,8 +1377,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter());
ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, primaryStore.getUuid());
if (morDatastore == null)
if (morDatastore == null) {
throw new Exception("Unable to find datastore in vSphere");
}
DatastoreMO dsMo = new DatastoreMO(context, morDatastore);
// create data volume
@ -1469,8 +1483,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
List<NetworkDetails> networks = vmMo.getNetworksWithDetails();
// tear down all devices first before we destroy the VM to avoid accidently delete disk backing files
if (this.resource.getVmState(vmMo) != State.Stopped)
if (this.resource.getVmState(vmMo) != State.Stopped) {
vmMo.safePowerOff(_shutdown_waitMs);
}
vmMo.tearDownDevices(new Class<?>[] { VirtualDisk.class, VirtualEthernetCard.class });
vmMo.destroy();
@ -1483,8 +1498,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
}
}
if (s_logger.isInfoEnabled())
if (s_logger.isInfoEnabled()) {
s_logger.info("Destroy volume by original name: " + vol.getPath() + ".vmdk");
}
dsMo.deleteFile(vol.getPath() + ".vmdk", morDc, true);
// root volume may be created via linked-clone, delete the delta disk as well
@ -1509,8 +1525,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
// evitTemplate will be converted into DestroyCommand, test if we are running in this case
VirtualMachineMO vmMo = clusterMo.findVmOnHyperHost(vol.getPath());
if (vmMo != null) {
if (s_logger.isInfoEnabled())
if (s_logger.isInfoEnabled()) {
s_logger.info("Destroy template volume " + vol.getPath());
}
vmMo.destroy();
return new Answer(cmd, true, "Success");
@ -1617,8 +1634,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
try {
hyperHost.importVmFromOVF(srcOVFFileName, newVolumeName, primaryDsMo, "thin");
clonedVm = hyperHost.findVmOnHyperHost(newVolumeName);
if(clonedVm == null)
if(clonedVm == null) {
throw new Exception("Unable to create container VM for volume creation");
}
clonedVm.moveAllVmDiskFiles(primaryDsMo, "", false);
clonedVm.detachAllDisks();