bug 11096: ExtractTemplate - For private template choose the correct sec storage host id since its not present in all the sec storage now.

This commit is contained in:
Nitin 2011-08-12 12:21:02 +05:30
parent 12a49668d7
commit f1d13729af
3 changed files with 23 additions and 25 deletions

View File

@ -25,12 +25,14 @@ public class DeleteEntityDownloadURLCommand extends AbstractDownloadCommand {
private String path; private String path;
private String extractUrl; private String extractUrl;
private Upload.Type type; private Upload.Type type;
private String parentPath;
public DeleteEntityDownloadURLCommand(String path, Upload.Type type, String url) { public DeleteEntityDownloadURLCommand(String path, Upload.Type type, String url, String parentPath) {
super(); super();
this.path = path; this.path = path;
this.type = type; this.type = type;
this.extractUrl = url; this.extractUrl = url;
this.parentPath = parentPath;
} }
public DeleteEntityDownloadURLCommand() { public DeleteEntityDownloadURLCommand() {
@ -61,4 +63,12 @@ public class DeleteEntityDownloadURLCommand extends AbstractDownloadCommand {
this.extractUrl = extractUrl; this.extractUrl = extractUrl;
} }
public String getParentPath() {
return parentPath;
}
public void setParentPath(String parentPath) {
this.parentPath = parentPath;
}
} }

View File

@ -411,7 +411,7 @@ public class UploadManagerImpl implements UploadManager {
if(cmd.getType() == Upload.Type.VOLUME){ if(cmd.getType() == Upload.Type.VOLUME){
command = new Script("/bin/bash", s_logger); command = new Script("/bin/bash", s_logger);
command.add("-c"); command.add("-c");
command.add("rm -f " + parentDir +File.separator+ path); command.add("rm -f /mnt/SecStorage/" + cmd.getParentPath() +File.separator+ path);
s_logger.warn(" " +parentDir +File.separator+ path); s_logger.warn(" " +parentDir +File.separator+ path);
result = command.execute(); result = command.execute();
if (result != null) { if (result != null) {

View File

@ -194,26 +194,13 @@ public class UploadMonitorImpl implements UploadMonitor {
String errorString = ""; String errorString = "";
boolean success = false; boolean success = false;
List<HostVO> storageServers = _serverDao.listByTypeDataCenter(Host.Type.SecondaryStorage, dataCenterId); Host secStorage = ApiDBUtils.findHostById(vmTemplateHost.getHostId());
if(storageServers == null || storageServers.size() == 0) {
throw new CloudRuntimeException("No Storage Server found at the datacenter - " +dataCenterId);
}
Type type = (template.getFormat() == ImageFormat.ISO) ? Type.ISO : Type.TEMPLATE ; Type type = (template.getFormat() == ImageFormat.ISO) ? Type.ISO : Type.TEMPLATE ;
List<HostVO> storageServerVMs = _serverDao.listByTypeDataCenter(Host.Type.SecondaryStorageVM, dataCenterId); //Check if ssvm is up
//Check if one ssvm is up HostVO ssvm = _agentMgr.getSSAgent(ApiDBUtils.findHostById(vmTemplateHost.getHostId()));
boolean no_vm_up = true; if( ssvm == null ) {
HostVO use_ssvm = null; throw new CloudRuntimeException("There is no secondary storage VM for secondary storage host " + secStorage.getId());
for (HostVO ssvm: storageServerVMs){
if(ssvm.getStatus() == com.cloud.host.Status.Up){
no_vm_up = false;
use_ssvm = ssvm;
break;
}
}
if(no_vm_up){
throw new CloudRuntimeException("Couldnt create extract link - Secondary Storage Vm is not up");
} }
//Check if it already exists. //Check if it already exists.
@ -223,7 +210,7 @@ public class UploadMonitorImpl implements UploadMonitor {
} }
// It doesn't exist so create a DB entry. // It doesn't exist so create a DB entry.
UploadVO uploadTemplateObj = new UploadVO(use_ssvm.getId(), template.getId(), new Date(), UploadVO uploadTemplateObj = new UploadVO(vmTemplateHost.getHostId(), template.getId(), new Date(),
Status.DOWNLOAD_URL_NOT_CREATED, 0, type, Mode.HTTP_DOWNLOAD); Status.DOWNLOAD_URL_NOT_CREATED, 0, type, Mode.HTTP_DOWNLOAD);
uploadTemplateObj.setInstallPath(vmTemplateHost.getInstallPath()); uploadTemplateObj.setInstallPath(vmTemplateHost.getInstallPath());
_uploadDao.persist(uploadTemplateObj); _uploadDao.persist(uploadTemplateObj);
@ -231,8 +218,8 @@ public class UploadMonitorImpl implements UploadMonitor {
// Create Symlink at ssvm // Create Symlink at ssvm
String path = vmTemplateHost.getInstallPath(); String path = vmTemplateHost.getInstallPath();
String uuid = UUID.randomUUID().toString() + path.substring(path.length() - 4) ; // last 4 characters of the path specify the format like .vhd String uuid = UUID.randomUUID().toString() + path.substring(path.length() - 4) ; // last 4 characters of the path specify the format like .vhd
CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(storageServers.get(0).getParent(), path, uuid); CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(secStorage.getParent(), path, uuid);
long result = send(use_ssvm.getId(), cmd, null); long result = send(ssvm.getId(), cmd, null);
if (result == -1){ if (result == -1){
errorString = "Unable to create a link for " +type+ " id:"+template.getId(); errorString = "Unable to create a link for " +type+ " id:"+template.getId();
s_logger.error(errorString); s_logger.error(errorString);
@ -474,10 +461,11 @@ public class UploadMonitorImpl implements UploadMonitor {
for (UploadVO extractJob : extractJobs){ for (UploadVO extractJob : extractJobs){
if( getTimeDiff(extractJob.getLastUpdated()) > EXTRACT_URL_LIFE_LIMIT_IN_SECONDS ){ if( getTimeDiff(extractJob.getLastUpdated()) > EXTRACT_URL_LIFE_LIMIT_IN_SECONDS ){
String path = extractJob.getInstallPath(); String path = extractJob.getInstallPath();
HostVO secStorage = ApiDBUtils.findHostById(extractJob.getHostId());
s_logger.debug("Sending deletion of extract URL "+extractJob.getUploadUrl()); s_logger.debug("Sending deletion of extract URL "+extractJob.getUploadUrl());
// Would delete the symlink for the Type and if Type == VOLUME then also the volume // Would delete the symlink for the Type and if Type == VOLUME then also the volume
DeleteEntityDownloadURLCommand cmd = new DeleteEntityDownloadURLCommand(path, extractJob.getType(),extractJob.getUploadUrl()); DeleteEntityDownloadURLCommand cmd = new DeleteEntityDownloadURLCommand(path, extractJob.getType(),extractJob.getUploadUrl(), secStorage.getParent());
HostVO ssvm = _agentMgr.getSSAgent(ApiDBUtils.findHostById(extractJob.getHostId())); HostVO ssvm = _agentMgr.getSSAgent(secStorage);
if( ssvm == null ) { if( ssvm == null ) {
s_logger.warn("There is no secondary storage VM for secondary storage host " + extractJob.getHostId()); s_logger.warn("There is no secondary storage VM for secondary storage host " + extractJob.getHostId());
continue; continue;