don't delete template if template check fail, give user a chance to check the template manually

use can delete the template though UI
This commit is contained in:
anthony 2010-11-08 21:02:20 -08:00
parent 8835c94311
commit 8df96da0a5
6 changed files with 56 additions and 36 deletions

View File

@ -3872,7 +3872,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
VDI pvISO = vids.iterator().next();
String uuid = pvISO.getUuid(conn);
Map<String, TemplateInfo> pvISOtmlt = new HashMap<String, TemplateInfo>();
TemplateInfo tmplt = new TemplateInfo("xs-tools.iso", uuid, pvISO.getVirtualSize(conn), true);
TemplateInfo tmplt = new TemplateInfo("xs-tools.iso", uuid, pvISO.getVirtualSize(conn), true, false);
pvISOtmlt.put("xs-tools", tmplt);
sscmd.setTemplateInfo(pvISOtmlt);
} catch (XenAPIException e) {

View File

@ -177,7 +177,7 @@ public class DummySecondaryStorageResource extends ServerResourceBase implements
Map<String, TemplateInfo> tmpltInfo = new HashMap<String, TemplateInfo>();
if (tmplts != null) {
for (VMTemplateVO tmplt : tmplts) {
TemplateInfo routingInfo = new TemplateInfo(tmplt.getUniqueName(), TemplateConstants.DEFAULT_SYSTEM_VM_TEMPLATE_PATH + tmplt.getId() + File.separator, false);
TemplateInfo routingInfo = new TemplateInfo(tmplt.getUniqueName(), TemplateConstants.DEFAULT_SYSTEM_VM_TEMPLATE_PATH + tmplt.getId() + File.separator, false, false);
tmpltInfo.put(tmplt.getUniqueName(), routingInfo);
}
}

View File

@ -47,5 +47,6 @@ public interface Processor extends Adapter {
public long size;
public long virtualSize;
public String filename;
public boolean isCorrupted;
}
}

View File

@ -17,29 +17,30 @@
*/
package com.cloud.storage.template;
public class TemplateInfo {
String templateName;
String installPath;
long size;
long id;
boolean isPublic;
boolean isCorrupted;
protected TemplateInfo() {
}
public TemplateInfo(String templateName, String installPath, long size, boolean isPublic) {
public TemplateInfo(String templateName, String installPath, long size, boolean isPublic, boolean isCorrupted) {
this.templateName = templateName;
this.installPath = installPath;
this.size = size;
this.isPublic = isPublic;
this.isCorrupted = isCorrupted;
}
public TemplateInfo(String templateName, String installPath, boolean isPublic) {
this.templateName = templateName;
this.installPath = installPath;
this.size = 0;
this.isPublic = isPublic;
public TemplateInfo(String templateName, String installPath, boolean isPublic, boolean isCorrupted) {
this(templateName, installPath, 0, isPublic, isCorrupted);
}
public long getId() {
@ -58,6 +59,10 @@ public class TemplateInfo {
return isPublic;
}
public boolean isCorrupted() {
return isCorrupted;
}
public void setInstallPath(String installPath) {
this.installPath = installPath;
}

View File

@ -38,6 +38,7 @@ public class TemplateLocation {
StorageLayer _storage;
String _templatePath;
boolean _isCorrupted;
File _file;
Properties _props;
@ -53,6 +54,7 @@ public class TemplateLocation {
_formats = new ArrayList<FormatInfo>(5);
_props = new Properties();
_file = _storage.getFile(_templatePath + Filename);
_isCorrupted = false;
}
public boolean create(long id, boolean isPublic, String uniqueName) throws IOException {
@ -100,15 +102,18 @@ public class TemplateLocation {
FormatInfo info = new FormatInfo();
info.format = format;
info.filename = _props.getProperty(format.getFileExtension() + ".filename");
if( info.filename == null ) {
continue;
}
info.size = NumbersUtil.parseLong(_props.getProperty(format.getFileExtension() + ".size"), -1);
info.virtualSize = NumbersUtil.parseLong(_props.getProperty(format.getFileExtension() + ".virtualsize"), -1);
_formats.add(info);
_formats.add(info);
if (!checkFormatValidity(info)) {
_isCorrupted = true;
s_logger.warn("Cleaning up inconsistent information for " + format);
cleanup(format);
}
}
}
}
@ -116,7 +121,7 @@ public class TemplateLocation {
return false;
}
return _formats.size() > 0;
return (_formats.size() > 0);
}
public boolean save() {
@ -148,10 +153,10 @@ public class TemplateLocation {
public TemplateInfo getTemplateInfo() {
TemplateInfo tmplInfo = new TemplateInfo();
String[] tokens = _templatePath.split(File.separator);
tmplInfo.id = Long.parseLong(_props.getProperty("id"));
tmplInfo.installPath = _templatePath + File.separator + _props.getProperty("filename");
tmplInfo.installPath = tmplInfo.installPath.substring(tmplInfo.installPath.indexOf("template"));
tmplInfo.isCorrupted = _isCorrupted;
tmplInfo.isPublic = Boolean.parseBoolean(_props.getProperty("public"));
tmplInfo.templateName = _props.getProperty("uniquename");
tmplInfo.size = Long.parseLong(_props.getProperty("virtualsize"));
@ -159,16 +164,7 @@ public class TemplateLocation {
return tmplInfo;
}
protected void cleanup(ImageFormat format) {
FormatInfo info = deleteFormat(format);
if (info != null && info.filename != null) {
boolean r = _storage.delete(_templatePath + info.filename);
if (s_logger.isDebugEnabled()) {
s_logger.debug((r ? "R" : "Unable to r") + "emove " + _templatePath + info.filename);
}
}
}
public FormatInfo getFormat(ImageFormat format) {
for (FormatInfo info : _formats) {
if (info.format == format) {

View File

@ -38,6 +38,7 @@ import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand.RequestType;
import com.cloud.agent.AgentManager;
import com.cloud.alert.AlertManager;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
@ -88,7 +89,8 @@ public class DownloadMonitorImpl implements DownloadMonitor {
StoragePoolHostDao _poolHostDao;
@Inject
SecondaryStorageVmDao _secStorageVmDao;
@Inject
AlertManager _alertMgr;
@Inject
HostDao _serverDao = null;
@ -408,7 +410,7 @@ public class DownloadMonitorImpl implements DownloadMonitor {
}
@Override
public void handleTemplateSync(long sserverId, Map<String, TemplateInfo> templateInfo) {
public void handleTemplateSync(long sserverId, Map<String, TemplateInfo> templateInfos) {
HostVO storageHost = _serverDao.findById(sserverId);
if (storageHost == null) {
s_logger.warn("Huh? Agent id " + sserverId + " does not correspond to a row in hosts table?");
@ -446,25 +448,41 @@ public class DownloadMonitorImpl implements DownloadMonitor {
for (VMTemplateVO tmplt: allTemplates) {
String uniqueName = tmplt.getUniqueName();
VMTemplateHostVO tmpltHost = _vmTemplateHostDao.findByHostTemplate(sserverId, tmplt.getId());
if (templateInfo.containsKey(uniqueName)) {
if (templateInfos.containsKey(uniqueName)) {
TemplateInfo tmpltInfo = templateInfos.remove(uniqueName);
toBeDownloaded.remove(tmplt);
if (tmpltHost != null) {
s_logger.info("Template Sync found " + uniqueName + " already in the template host table");
if (tmpltHost.getDownloadState() != Status.DOWNLOADED) {
tmpltHost.setErrorString("");
}
tmpltHost.setDownloadPercent(100);
tmpltHost.setDownloadState(Status.DOWNLOADED);
tmpltHost.setInstallPath(templateInfo.get(uniqueName).getInstallPath());
tmpltHost.setSize(templateInfo.get(uniqueName).getSize());
tmpltHost.setLastUpdated(new Date());
if( tmpltInfo.isCorrupted() ) {
tmpltHost.setDownloadState(Status.DOWNLOAD_ERROR);
tmpltHost.setErrorString("This template is corrupted");
toBeDownloaded.add(tmplt);
s_logger.info("Template (" + tmplt +") is corrupted");
if( tmplt.getUrl() == null) {
String msg = "Private Template (" + tmplt +") with install path " + tmpltInfo.getInstallPath() +
"is corrupted, please check in secondary storage: " + tmpltHost.getHostId();
s_logger.warn(msg);
} else {
toBeDownloaded.add(tmplt);
}
} else {
tmpltHost.setDownloadPercent(100);
tmpltHost.setDownloadState(Status.DOWNLOADED);
tmpltHost.setInstallPath(tmpltInfo.getInstallPath());
tmpltHost.setSize(tmpltInfo.getSize());
tmpltHost.setLastUpdated(new Date());
}
_vmTemplateHostDao.update(tmpltHost.getId(), tmpltHost);
} else {
tmpltHost = new VMTemplateHostVO(sserverId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null, templateInfo.get(uniqueName).getInstallPath(), tmplt.getUrl());
tmpltHost.setSize(templateInfo.get(uniqueName).getSize());
tmpltHost = new VMTemplateHostVO(sserverId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null, tmpltInfo.getInstallPath(), tmplt.getUrl());
tmpltHost.setSize(tmpltInfo.getSize());
_vmTemplateHostDao.persist(tmpltHost);
}
templateInfo.remove(uniqueName);
continue;
}
if (tmpltHost != null && tmpltHost.getDownloadState() != Status.DOWNLOADED) {
@ -489,8 +507,8 @@ public class DownloadMonitorImpl implements DownloadMonitor {
}
}
for (String uniqueName: templateInfo.keySet()) {
TemplateInfo tInfo = templateInfo.get(uniqueName);
for (String uniqueName: templateInfos.keySet()) {
TemplateInfo tInfo = templateInfos.get(uniqueName);
DeleteTemplateCommand dtCommand = new DeleteTemplateCommand(tInfo.getInstallPath());
long result = send(sserverId, dtCommand, null);
if (result == -1 ){