diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
index 30e7ec3a0a2..50c4aa7b319 100644
--- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
+++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
@@ -147,8 +147,8 @@ import com.cloud.agent.api.storage.CreateCommand;
import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
import com.cloud.agent.api.storage.CreatePrivateTemplateCommand;
import com.cloud.agent.api.storage.DestroyCommand;
-import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
+import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.StorageFilerTO;
import com.cloud.agent.api.to.VirtualMachineTO;
@@ -1765,7 +1765,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
return sp;
}
}
- protected Answer execute(final PrimaryStorageDownloadCommand cmd) {
+ protected PrimaryStorageDownloadAnswer execute(final PrimaryStorageDownloadCommand cmd) {
String tmplturl = cmd.getUrl();
int index = tmplturl.lastIndexOf("/");
String mountpoint = tmplturl.substring(0, index);
@@ -1781,7 +1781,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
try {
secondaryPool = getNfsSPbyURI(_conn, new URI(mountpoint));
if (secondaryPool == null) {
- return new Answer(cmd, false, " Failed to create storage pool");
+ return new PrimaryStorageDownloadAnswer(" Failed to create storage pool");
}
if (tmpltname == null) {
/*Hack: server just pass the directory of system vm template, need to scan the folder */
@@ -1790,7 +1790,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
String[] volumes = secondaryPool.listVolumes();
if (volumes == null) {
- return new Answer(cmd, false, "Failed to get volumes from pool: " + secondaryPool.getName());
+ return new PrimaryStorageDownloadAnswer("Failed to get volumes from pool: " + secondaryPool.getName());
}
for (String volumeName : volumes) {
if (volumeName.endsWith("qcow2")) {
@@ -1799,40 +1799,32 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
}
if (tmpltname == null) {
- return new Answer(cmd, false, "Failed to get template from pool: " + secondaryPool.getName());
+ return new PrimaryStorageDownloadAnswer("Failed to get template from pool: " + secondaryPool.getName());
}
}
tmplVol = getVolume(secondaryPool, getPathOfStoragePool(secondaryPool) + tmpltname);
if (tmplVol == null) {
- return new Answer(cmd, false, " Can't find volume");
+ return new PrimaryStorageDownloadAnswer(" Can't find volume");
}
primaryPool = _conn.storagePoolLookupByUUIDString(cmd.getPoolUuid());
if (primaryPool == null) {
- return new Answer(cmd, false, " Can't find primary storage pool");
+ return new PrimaryStorageDownloadAnswer(" Can't find primary storage pool");
}
LibvirtStorageVolumeDef vol = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), tmplVol.getInfo().capacity, volFormat.QCOW2, null, null);
s_logger.debug(vol.toString());
primaryVol = copyVolume(primaryPool, vol, tmplVol);
if (primaryVol == null) {
- return new Answer(cmd, false, " Can't create storage volume on storage pool");
+ return new PrimaryStorageDownloadAnswer(" Can't create storage volume on storage pool");
}
-
StorageVolInfo priVolInfo = primaryVol.getInfo();
- DownloadAnswer answer = new DownloadAnswer(null,
- 100,
- cmd,
- com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
- primaryVol.getKey(),
- primaryVol.getKey());
- answer.setTemplateSize(priVolInfo.allocation);
- return answer;
+ return new PrimaryStorageDownloadAnswer(primaryVol.getKey(), priVolInfo.allocation);
} catch (LibvirtException e) {
result = "Failed to download template: " + e.toString();
s_logger.debug(result);
- return new Answer(cmd, false, result);
+ return new PrimaryStorageDownloadAnswer(result);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
- return new Answer(cmd, false, e.toString());
+ return new PrimaryStorageDownloadAnswer(e.toString());
} finally {
try {
if (primaryVol != null) {
diff --git a/core/src/com/cloud/agent/api/storage/DownloadAnswer.java b/core/src/com/cloud/agent/api/storage/DownloadAnswer.java
index d542b14f9df..6fc8599374d 100644
--- a/core/src/com/cloud/agent/api/storage/DownloadAnswer.java
+++ b/core/src/com/cloud/agent/api/storage/DownloadAnswer.java
@@ -31,7 +31,8 @@ public class DownloadAnswer extends Answer {
private VMTemplateHostVO.Status downloadStatus;
private String downloadPath;
private String installPath;
- public Long templateSize = 0L;
+ private long templateSize = 0L;
+ private long templatePhySicalSize = 0L;
public int getDownloadPct() {
return downloadPct;
@@ -62,8 +63,15 @@ public class DownloadAnswer extends Answer {
this.jobId = jobId;
}
+ public DownloadAnswer(String errorString, Status status) {
+ super();
+ this.downloadPct = 0;
+ this.errorString = errorString;
+ this.downloadStatus = status;
+ }
+
public DownloadAnswer(String jobId, int downloadPct, String errorString,
- Status downloadStatus, String fileSystemPath, String installPath, long templateSize) {
+ Status downloadStatus, String fileSystemPath, String installPath, long templateSize, long templatePhySicalSize ) {
super();
this.jobId = jobId;
this.downloadPct = downloadPct;
@@ -72,6 +80,7 @@ public class DownloadAnswer extends Answer {
this.downloadPath = fileSystemPath;
this.installPath = fixPath(installPath);
this.templateSize = templateSize;
+ this.templatePhySicalSize = templatePhySicalSize;
}
public DownloadAnswer(String jobId, int downloadPct, Command command,
@@ -114,5 +123,11 @@ public class DownloadAnswer extends Answer {
public Long getTemplateSize() {
return templateSize;
}
+ public void setTemplatePhySicalSize(long templatePhySicalSize) {
+ this.templatePhySicalSize = templatePhySicalSize;
+ }
+ public long getTemplatePhySicalSize() {
+ return templatePhySicalSize;
+ }
}
diff --git a/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadAnswer.java b/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadAnswer.java
new file mode 100644
index 00000000000..da67572069d
--- /dev/null
+++ b/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadAnswer.java
@@ -0,0 +1,55 @@
+/**
+ * Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
+ *
+ * This software is licensed under the GNU General Public License v3 or later.
+ *
+ * It is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+package com.cloud.agent.api.storage;
+
+import com.cloud.agent.api.Answer;
+
+public class PrimaryStorageDownloadAnswer extends Answer {
+ private String installPath;
+ private long templateSize = 0L;
+
+ protected PrimaryStorageDownloadAnswer() {
+ }
+
+ public PrimaryStorageDownloadAnswer(String detail) {
+ super(null, false, detail);
+ }
+
+ public PrimaryStorageDownloadAnswer(String installPath, long templateSize ) {
+ super(null);
+ this.installPath = installPath;
+ this.templateSize = templateSize;
+ }
+
+ public String getInstallPath() {
+ return installPath;
+ }
+
+ public void setInstallPath(String installPath) {
+ this.installPath = installPath;
+ }
+
+ public void setTemplateSize(long templateSize) {
+ this.templateSize = templateSize;
+ }
+
+ public Long getTemplateSize() {
+ return templateSize;
+ }
+
+}
diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
index ffca282dd1b..292404ca341 100644
--- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
+++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
@@ -142,8 +142,8 @@ import com.cloud.agent.api.storage.CreateAnswer;
import com.cloud.agent.api.storage.CreateCommand;
import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
import com.cloud.agent.api.storage.DestroyCommand;
-import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
+import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
import com.cloud.agent.api.storage.ShareAnswer;
import com.cloud.agent.api.storage.ShareCommand;
import com.cloud.agent.api.to.NicTO;
@@ -2066,7 +2066,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
}
@Override
- public DownloadAnswer execute(final PrimaryStorageDownloadCommand cmd) {
+ public PrimaryStorageDownloadAnswer execute(final PrimaryStorageDownloadCommand cmd) {
SR tmpltsr = null;
String tmplturl = cmd.getUrl();
int index = tmplturl.lastIndexOf("/");
@@ -2082,7 +2082,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
if (srs.size() != 1) {
String msg = "There are " + srs.size() + " SRs with same name: " + pUuid;
s_logger.warn(msg);
- return new DownloadAnswer(null, 0, msg, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR, "", "", 0);
+ return new PrimaryStorageDownloadAnswer(msg);
} else {
poolsr = srs.iterator().next();
}
@@ -2119,7 +2119,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
if (tmpltvdi == null) {
String msg = "Unable to find template vdi on secondary storage" + "host:" + _host.uuid + "pool: " + tmplturl;
s_logger.warn(msg);
- return new DownloadAnswer(null, 0, msg, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR, "", "", 0);
+ return new PrimaryStorageDownloadAnswer(msg);
}
vmtmpltvdi = cloudVDIcopy(tmpltvdi, poolsr);
snapshotvdi = vmtmpltvdi.snapshot(conn, new HashMap());
@@ -2138,20 +2138,16 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
// Determine the size of the template
long phySize = vmtmpltvdi.getPhysicalUtilisation(conn);
-
- DownloadAnswer answer = new DownloadAnswer(null, 100, cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, uuid, uuid);
- answer.setTemplateSize(phySize);
-
- return answer;
+ return new PrimaryStorageDownloadAnswer(uuid, phySize);
} catch (XenAPIException e) {
String msg = "XenAPIException:" + e.toString() + "host:" + _host.uuid + "pool: " + tmplturl;
s_logger.warn(msg, e);
- return new DownloadAnswer(null, 0, msg, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR, "", "", 0);
+ return new PrimaryStorageDownloadAnswer(msg);
} catch (Exception e) {
String msg = "XenAPIException:" + e.getMessage() + "host:" + _host.uuid + "pool: " + tmplturl;
s_logger.warn(msg, e);
- return new DownloadAnswer(null, 0, msg, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR, "", "", 0);
+ return new PrimaryStorageDownloadAnswer(msg);
} finally {
removeSR(tmpltsr);
}
@@ -3901,7 +3897,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
VDI pvISO = vids.iterator().next();
String uuid = pvISO.getUuid(conn);
Map pvISOtmlt = new HashMap();
- TemplateInfo tmplt = new TemplateInfo("xs-tools.iso", uuid, pvISO.getVirtualSize(conn), true, false);
+ TemplateInfo tmplt = new TemplateInfo("xs-tools.iso", uuid, pvISO.getVirtualSize(conn), pvISO.getVirtualSize(conn), true, false);
pvISOtmlt.put("xs-tools", tmplt);
sscmd.setTemplateInfo(pvISOtmlt);
} catch (XenAPIException e) {
diff --git a/core/src/com/cloud/storage/VMTemplateHostVO.java b/core/src/com/cloud/storage/VMTemplateHostVO.java
index 9e6c1e7b2cb..4c06593dfea 100755
--- a/core/src/com/cloud/storage/VMTemplateHostVO.java
+++ b/core/src/com/cloud/storage/VMTemplateHostVO.java
@@ -62,7 +62,10 @@ public class VMTemplateHostVO implements VMTemplateStorageResourceAssoc {
private int downloadPercent;
@Column (name="size")
- private long size;
+ private long size;
+
+ @Column (name="physicalSize")
+ private long physicalSize;
@Column (name="download_state")
@Enumerated(EnumType.STRING)
@@ -240,6 +243,14 @@ public class VMTemplateHostVO implements VMTemplateStorageResourceAssoc {
}
+ public void setPhysicalSize(long physicalSize) {
+ this.physicalSize = physicalSize;
+ }
+
+ public long getPhysicalSize() {
+ return physicalSize;
+ }
+
public void setDestroyed(boolean destroyed) {
this.destroyed = destroyed;
}
diff --git a/core/src/com/cloud/storage/resource/StoragePoolResource.java b/core/src/com/cloud/storage/resource/StoragePoolResource.java
index 4207f8b6273..7178607b113 100644
--- a/core/src/com/cloud/storage/resource/StoragePoolResource.java
+++ b/core/src/com/cloud/storage/resource/StoragePoolResource.java
@@ -23,14 +23,14 @@ import com.cloud.agent.api.storage.CopyVolumeCommand;
import com.cloud.agent.api.storage.CreateAnswer;
import com.cloud.agent.api.storage.CreateCommand;
import com.cloud.agent.api.storage.DestroyCommand;
-import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
+import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
import com.cloud.agent.api.storage.ShareAnswer;
import com.cloud.agent.api.storage.ShareCommand;
public interface StoragePoolResource {
// FIXME: Should have a PrimaryStorageDownloadAnswer
- DownloadAnswer execute(PrimaryStorageDownloadCommand cmd);
+ PrimaryStorageDownloadAnswer execute(PrimaryStorageDownloadCommand cmd);
// FIXME: Should have an DestroyAnswer
Answer execute(DestroyCommand cmd);
diff --git a/core/src/com/cloud/storage/template/DownloadManagerImpl.java b/core/src/com/cloud/storage/template/DownloadManagerImpl.java
index 5e78a53c071..be24a04edf5 100644
--- a/core/src/com/cloud/storage/template/DownloadManagerImpl.java
+++ b/core/src/com/cloud/storage/template/DownloadManagerImpl.java
@@ -58,6 +58,7 @@ import com.cloud.utils.component.ComponentLocator.ComponentInfo;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.OutputInterpreter;
import com.cloud.utils.script.Script;
+import com.cloud.storage.VMTemplateStorageResourceAssoc;
/**
* @author chiradeep
@@ -94,6 +95,7 @@ public class DownloadManagerImpl implements DownloadManager {
private Long accountId;
private String installPathPrefix;
private long templatesize;
+ private long templatePhysicalSize;
private long id;
public DownloadJob(TemplateDownloader td, String jobId, long id, String tmpltName, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum, String installPathPrefix) {
@@ -192,6 +194,14 @@ public class DownloadManagerImpl implements DownloadManager {
public long getTemplatesize() {
return templatesize;
}
+
+ public void setTemplatePhysicalSize(long templatePhysicalSize) {
+ this.templatePhysicalSize = templatePhysicalSize;
+ }
+
+ public long getTemplatePhysicalSize() {
+ return templatePhysicalSize;
+ }
}
public static final Logger s_logger = Logger.getLogger(DownloadManagerImpl.class);
@@ -348,6 +358,7 @@ public class DownloadManagerImpl implements DownloadManager {
if (info != null) {
loc.addFormat(info);
dnld.setTemplatesize(info.virtualSize);
+ dnld.setTemplatePhysicalSize(info.size);
break;
}
}
@@ -448,6 +459,14 @@ public class DownloadManagerImpl implements DownloadManager {
}
return 0;
}
+
+ public long getDownloadTemplatePhysicalSize(String jobId) {
+ DownloadJob dj = jobs.get(jobId);
+ if (dj != null) {
+ return dj.getTemplatePhysicalSize();
+ }
+ return 0;
+ }
// @Override
public String getDownloadLocalPath(String jobId) {
@@ -502,11 +521,11 @@ public class DownloadManagerImpl implements DownloadManager {
}
if (cmd.getUrl() == null) {
- return new DownloadAnswer(null, 0, "Template is corrupted on storage due to an invalid url , cannot download", com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR, "", "", 0);
+ return new DownloadAnswer("Template is corrupted on storage due to an invalid url , cannot download", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
}
if (cmd.getName() == null) {
- return new DownloadAnswer(null, 0, "Invalid Name", com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR, "", "", 0);
+ return new DownloadAnswer("Invalid Name", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
}
String installPathPrefix = null;
@@ -523,10 +542,10 @@ public class DownloadManagerImpl implements DownloadManager {
String jobId = downloadPublicTemplate(cmd.getId(), cmd.getUrl(), cmd.getName(), cmd.getFormat(), cmd.isHvm(), cmd.getAccountId(), cmd.getDescription(), cmd.getChecksum(), installPathPrefix, user, password, maxDownloadSizeInBytes);
sleep();
if (jobId == null) {
- return new DownloadAnswer(null, 0, "Internal Error", com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR, "", "", 0);
+ return new DownloadAnswer("Internal Error", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
}
return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId),
- getDownloadTemplateSize(jobId));
+ getDownloadTemplateSize(jobId), getDownloadTemplateSize(jobId));
}
private void sleep() {
@@ -548,7 +567,7 @@ public class DownloadManagerImpl implements DownloadManager {
DownloadCommand dcmd = new DownloadCommand(cmd);
return handleDownloadCommand(dcmd);
} else {
- return new DownloadAnswer(null, 0, "Cannot find job", com.cloud.storage.VMTemplateHostVO.Status.UNKNOWN, "", "", 0);
+ return new DownloadAnswer("Cannot find job", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR.UNKNOWN);
}
}
TemplateDownloader td = dj.getTemplateDownloader();
@@ -566,14 +585,15 @@ public class DownloadManagerImpl implements DownloadManager {
break;
case PURGE:
td.stopDownload();
- answer = new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId), getDownloadTemplateSize(jobId));
+ answer = new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId),
+ getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplatePhysicalSize(jobId));
jobs.remove(jobId);
return answer;
default:
break; // TODO
}
- return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId),
- getDownloadTemplateSize(jobId));
+ return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId),
+ getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplatePhysicalSize(jobId));
}
private String getInstallPath(String jobId) {
diff --git a/core/src/com/cloud/storage/template/TemplateInfo.java b/core/src/com/cloud/storage/template/TemplateInfo.java
index c6625678621..ec09eb8eb4c 100644
--- a/core/src/com/cloud/storage/template/TemplateInfo.java
+++ b/core/src/com/cloud/storage/template/TemplateInfo.java
@@ -23,6 +23,7 @@ public class TemplateInfo {
String templateName;
String installPath;
long size;
+ long physicalSize;
long id;
boolean isPublic;
boolean isCorrupted;
@@ -31,16 +32,17 @@ public class TemplateInfo {
}
- public TemplateInfo(String templateName, String installPath, long size, boolean isPublic, boolean isCorrupted) {
+ public TemplateInfo(String templateName, String installPath, long size, long physicalSize, boolean isPublic, boolean isCorrupted) {
this.templateName = templateName;
this.installPath = installPath;
this.size = size;
+ this.physicalSize = physicalSize;
this.isPublic = isPublic;
this.isCorrupted = isCorrupted;
}
public TemplateInfo(String templateName, String installPath, boolean isPublic, boolean isCorrupted) {
- this(templateName, installPath, 0, isPublic, isCorrupted);
+ this(templateName, installPath, 0, 0, isPublic, isCorrupted);
}
public long getId() {
@@ -71,6 +73,10 @@ public class TemplateInfo {
return size;
}
+ public long getPhysicalSize() {
+ return physicalSize;
+ }
+
public void setSize(long size) {
this.size = size;
}
diff --git a/core/src/com/cloud/storage/template/TemplateLocation.java b/core/src/com/cloud/storage/template/TemplateLocation.java
index 70c9a094878..abe0d78525b 100644
--- a/core/src/com/cloud/storage/template/TemplateLocation.java
+++ b/core/src/com/cloud/storage/template/TemplateLocation.java
@@ -106,8 +106,8 @@ public class TemplateLocation {
continue;
}
info.size = NumbersUtil.parseLong(_props.getProperty(format.getFileExtension() + ".size"), -1);
+ _props.setProperty("physicalSize", Long.toString(info.size));
info.virtualSize = NumbersUtil.parseLong(_props.getProperty(format.getFileExtension() + ".virtualsize"), -1);
-
_formats.add(info);
if (!checkFormatValidity(info)) {
@@ -145,14 +145,12 @@ public class TemplateLocation {
} catch (IOException e) {
}
}
- }
-
+ }
return true;
}
public TemplateInfo getTemplateInfo() {
- TemplateInfo tmplInfo = new TemplateInfo();
-
+ TemplateInfo tmplInfo = new TemplateInfo();
tmplInfo.id = Long.parseLong(_props.getProperty("id"));
tmplInfo.installPath = _templatePath + File.separator + _props.getProperty("filename");
tmplInfo.installPath = tmplInfo.installPath.substring(tmplInfo.installPath.indexOf("template"));
@@ -160,6 +158,7 @@ public class TemplateLocation {
tmplInfo.isPublic = Boolean.parseBoolean(_props.getProperty("public"));
tmplInfo.templateName = _props.getProperty("uniquename");
tmplInfo.size = Long.parseLong(_props.getProperty("virtualsize"));
+ tmplInfo.physicalSize = Long.parseLong(_props.getProperty("physicalSize"));
return tmplInfo;
}
diff --git a/server/src/com/cloud/storage/allocator/AbstractStoragePoolAllocator.java b/server/src/com/cloud/storage/allocator/AbstractStoragePoolAllocator.java
index 49cb5d717b8..e116be2a947 100644
--- a/server/src/com/cloud/storage/allocator/AbstractStoragePoolAllocator.java
+++ b/server/src/com/cloud/storage/allocator/AbstractStoragePoolAllocator.java
@@ -187,16 +187,13 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement
for (VMTemplateStoragePoolVO templatePoolVO : templatePoolVOs) {
VMTemplateVO templateInPool = _templateDao.findById(templatePoolVO.getTemplateId());
- int templateSizeMultiplier = pool.getPoolType() == StoragePoolType.NetworkFilesystem ? 1 : 2;
if ((template != null) && !tmpinstalled && (templateInPool.getId() == template.getId())) {
tmpinstalled = true;
}
- s_logger.debug("For template: " + templateInPool.getName() + ", using template size multiplier: " + templateSizeMultiplier);
-
long templateSize = templatePoolVO.getTemplateSize();
- totalAllocatedSize += templateSizeMultiplier * (templateSize + _extraBytesPerVolume);
+ totalAllocatedSize += templateSize + _extraBytesPerVolume;
}
if ((template != null) && !tmpinstalled) {
@@ -212,7 +209,8 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement
} else {
s_logger.debug("For template: " + template.getName() + ", using template size multiplier: " + 2);
long templateSize = templateHostVO.getSize();
- totalAllocatedSize += 2 * (templateSize + _extraBytesPerVolume);
+ long templatePhysicalSize = templateHostVO.getPhysicalSize();
+ totalAllocatedSize += (templateSize + _extraBytesPerVolume) + (templatePhysicalSize + _extraBytesPerVolume);
}
}
}
diff --git a/server/src/com/cloud/storage/download/DownloadMonitorImpl.java b/server/src/com/cloud/storage/download/DownloadMonitorImpl.java
index d2c267ad80e..f1ebe51e6fd 100755
--- a/server/src/com/cloud/storage/download/DownloadMonitorImpl.java
+++ b/server/src/com/cloud/storage/download/DownloadMonitorImpl.java
@@ -474,12 +474,14 @@ public class DownloadMonitorImpl implements DownloadMonitor {
tmpltHost.setDownloadState(Status.DOWNLOADED);
tmpltHost.setInstallPath(tmpltInfo.getInstallPath());
tmpltHost.setSize(tmpltInfo.getSize());
+ tmpltHost.setPhysicalSize(tmpltInfo.getPhysicalSize());
tmpltHost.setLastUpdated(new Date());
}
_vmTemplateHostDao.update(tmpltHost.getId(), tmpltHost);
} else {
tmpltHost = new VMTemplateHostVO(sserverId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null, tmpltInfo.getInstallPath(), tmplt.getUrl());
tmpltHost.setSize(tmpltInfo.getSize());
+ tmpltHost.setPhysicalSize(tmpltInfo.getPhysicalSize());
_vmTemplateHostDao.persist(tmpltHost);
}
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index 55af2930360..7b9423c3175 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -35,6 +35,7 @@ import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.storage.DestroyCommand;
import com.cloud.agent.api.storage.DownloadAnswer;
+import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
import com.cloud.api.BaseCmd;
import com.cloud.api.ServerApiException;
@@ -687,11 +688,11 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
}
dcmd.setLocalPath(vo.getLocalPath());
// set 120 min timeout for this command
- DownloadAnswer answer = (DownloadAnswer)_agentMgr.easySend(vo.getHostId(), dcmd, 120*60*1000);
- if (answer != null) {
- templateStoragePoolRef.setDownloadPercent(templateStoragePoolRef.getDownloadPercent());
- templateStoragePoolRef.setDownloadState(answer.getDownloadStatus());
- templateStoragePoolRef.setLocalDownloadPath(answer.getDownloadPath());
+ PrimaryStorageDownloadAnswer answer = (PrimaryStorageDownloadAnswer)_agentMgr.easySend(vo.getHostId(), dcmd, 120*60*1000);
+ if (answer != null && answer.getResult() ) {
+ templateStoragePoolRef.setDownloadPercent(100);
+ templateStoragePoolRef.setDownloadState(Status.DOWNLOADED);
+ templateStoragePoolRef.setLocalDownloadPath(answer.getInstallPath());
templateStoragePoolRef.setInstallPath(answer.getInstallPath());
templateStoragePoolRef.setTemplateSize(answer.getTemplateSize());
_tmpltPoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef);
@@ -699,6 +700,9 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
s_logger.debug("Template " + templateId + " is downloaded via " + vo.getHostId());
}
return templateStoragePoolRef;
+ } else {
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Template " + templateId + " download to pool " + vo.getPoolId() + " failed due to " + (answer!=null?answer.getDetails():"return null")); }
}
}
} finally {
diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql
index 16e849826c8..3cfa04e9ce2 100755
--- a/setup/db/create-schema.sql
+++ b/setup/db/create-schema.sql
@@ -683,6 +683,7 @@ CREATE TABLE `cloud`.`template_host_ref` (
`job_id` varchar(255),
`download_pct` int(10) unsigned,
`size` bigint unsigned,
+ `physicalSize` bigint unsigned DEFAULT 0,
`download_state` varchar(255),
`error_str` varchar(255),
`local_path` varchar(255),
diff --git a/setup/db/schema-21to22.sql b/setup/db/schema-21to22.sql
index 4531dc85700..7bf8e1339cd 100644
--- a/setup/db/schema-21to22.sql
+++ b/setup/db/schema-21to22.sql
@@ -1,59 +1,6 @@
---
--- Schema upgrade from 2.1 to 2.2
---
-
-
-CREATE TABLE `cloud`.`instance_group` (
- `id` bigint unsigned NOT NULL UNIQUE auto_increment,
- `account_id` bigint unsigned NOT NULL COMMENT 'owner. foreign key to account table',
- `name` varchar(255) NOT NULL,
- `removed` datetime COMMENT 'date the group was removed',
- `created` datetime COMMENT 'date the group was created',
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
-
-CREATE TABLE `cloud`.`instance_group_vm_map` (
- `id` bigint unsigned NOT NULL auto_increment,
- `group_id` bigint unsigned NOT NULL,
- `instance_id` bigint unsigned NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
-CREATE TABLE `cloud`.`certificate` (
- `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
- `certificate` text COMMENT 'the actual custom certificate being stored in the db',
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
-CREATE TABLE `cloud`.`remote_access_vpn` (
- `id` bigint unsigned NOT NULL auto_increment,
- `account_id` bigint unsigned NOT NULL,
- `zone_id` bigint unsigned NOT NULL,
- `vpn_server_addr` varchar(15) UNIQUE NOT NULL,
- `local_ip` varchar(15) NOT NULL,
- `ip_range` varchar(32) NOT NULL,
- `ipsec_psk` varchar(256) NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
-CREATE TABLE `cloud`.`vpn_users` (
- `id` bigint unsigned NOT NULL auto_increment,
- `account_id` bigint unsigned NOT NULL,
- `username` varchar(255) NOT NULL,
- `password` varchar(255) NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
-ALTER TABLE `cloud`.`data_center` MODIFY COLUMN `guest_network_cidr` varchar(18); -- modify column width to 18 from 15
-
-ALTER TABLE `cloud`.`resource_count` ADD COLUMN `domain_id` bigint unsigned; -- add the new column
-ALTER TABLE `cloud`.`resource_count` MODIFY COLUMN `account_id` bigint unsigned; -- modify the column to allow NULL values
-ALTER TABLE `cloud`.`storage_pool` add COLUMN STATUS varchar(32) not null; -- new status column for maintenance mode support for primary storage
-ALTER TABLE `cloud`.`volumes` ADD COLUMN `source_id` bigint unsigned; -- id for the source
-ALTER TABLE `cloud`.`volumes` ADD COLUMN `source_type` varchar(32); --source from which the volume is created i.e. snapshot, diskoffering, template, blank
-ALTER TABLE `cloud`.`volumes` ADD COLUMN 'attached' datetime; --date and time the volume was attached
-ALTER TABLE `cloud`.`disk_offering` ADD COLUMN `customized` tinyint(1) unsigned NOT NULL DEFAULT 0;-- 0 implies not customized by default
-ALTER TABLE `cloud`.`user_ip_address` ADD COLUMN `one_to_one_nat` int(1) unsigned NOT NULL default '0'; -- new column for NAT ip
-
-
-
+SET foreign_key_checks = 0;
+
+--
+-- Schema upgrade from 2.1 to 2.2
+--
+ALTER TABLE `cloud`.`template_host_ref` ADD COLUMN `physicalSize` bigint unsigned NOT NULL DEFAULT 0;