Skip to content

Commit 30fa653

Browse files
committed
bug 6088: track template physical size in template_host_ref table
add migration from 21 to 22 after migration , SSVM needs to stop/start status 6088: resolved fixed
1 parent bdb1f31 commit 30fa653

14 files changed

Lines changed: 166 additions & 120 deletions

File tree

‎agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java‎

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@
147147
import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
148148
import com.cloud.agent.api.storage.CreatePrivateTemplateCommand;
149149
import com.cloud.agent.api.storage.DestroyCommand;
150-
import com.cloud.agent.api.storage.DownloadAnswer;
151150
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
151+
import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
152152
import com.cloud.agent.api.to.NicTO;
153153
import com.cloud.agent.api.to.StorageFilerTO;
154154
import com.cloud.agent.api.to.VirtualMachineTO;
@@ -1765,7 +1765,7 @@ private StoragePool getNfsSPbyURI(Connect conn, URI uri) throws LibvirtException
17651765
return sp;
17661766
}
17671767
}
1768-
protected Answer execute(final PrimaryStorageDownloadCommand cmd) {
1768+
protected PrimaryStorageDownloadAnswer execute(final PrimaryStorageDownloadCommand cmd) {
17691769
String tmplturl = cmd.getUrl();
17701770
int index = tmplturl.lastIndexOf("/");
17711771
String mountpoint = tmplturl.substring(0, index);
@@ -1781,7 +1781,7 @@ protected Answer execute(final PrimaryStorageDownloadCommand cmd) {
17811781
try {
17821782
secondaryPool = getNfsSPbyURI(_conn, new URI(mountpoint));
17831783
if (secondaryPool == null) {
1784-
return new Answer(cmd, false, " Failed to create storage pool");
1784+
return new PrimaryStorageDownloadAnswer(" Failed to create storage pool");
17851785
}
17861786
if (tmpltname == null) {
17871787
/*Hack: server just pass the directory of system vm template, need to scan the folder */
@@ -1790,7 +1790,7 @@ protected Answer execute(final PrimaryStorageDownloadCommand cmd) {
17901790
}
17911791
String[] volumes = secondaryPool.listVolumes();
17921792
if (volumes == null) {
1793-
return new Answer(cmd, false, "Failed to get volumes from pool: " + secondaryPool.getName());
1793+
return new PrimaryStorageDownloadAnswer("Failed to get volumes from pool: " + secondaryPool.getName());
17941794
}
17951795
for (String volumeName : volumes) {
17961796
if (volumeName.endsWith("qcow2")) {
@@ -1799,40 +1799,32 @@ protected Answer execute(final PrimaryStorageDownloadCommand cmd) {
17991799
}
18001800
}
18011801
if (tmpltname == null) {
1802-
return new Answer(cmd, false, "Failed to get template from pool: " + secondaryPool.getName());
1802+
return new PrimaryStorageDownloadAnswer("Failed to get template from pool: " + secondaryPool.getName());
18031803
}
18041804
}
18051805
tmplVol = getVolume(secondaryPool, getPathOfStoragePool(secondaryPool) + tmpltname);
18061806
if (tmplVol == null) {
1807-
return new Answer(cmd, false, " Can't find volume");
1807+
return new PrimaryStorageDownloadAnswer(" Can't find volume");
18081808
}
18091809
primaryPool = _conn.storagePoolLookupByUUIDString(cmd.getPoolUuid());
18101810
if (primaryPool == null) {
1811-
return new Answer(cmd, false, " Can't find primary storage pool");
1811+
return new PrimaryStorageDownloadAnswer(" Can't find primary storage pool");
18121812
}
18131813
LibvirtStorageVolumeDef vol = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), tmplVol.getInfo().capacity, volFormat.QCOW2, null, null);
18141814
s_logger.debug(vol.toString());
18151815
primaryVol = copyVolume(primaryPool, vol, tmplVol);
18161816
if (primaryVol == null) {
1817-
return new Answer(cmd, false, " Can't create storage volume on storage pool");
1817+
return new PrimaryStorageDownloadAnswer(" Can't create storage volume on storage pool");
18181818
}
1819-
18201819
StorageVolInfo priVolInfo = primaryVol.getInfo();
1821-
DownloadAnswer answer = new DownloadAnswer(null,
1822-
100,
1823-
cmd,
1824-
com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
1825-
primaryVol.getKey(),
1826-
primaryVol.getKey());
1827-
answer.setTemplateSize(priVolInfo.allocation);
1828-
return answer;
1820+
return new PrimaryStorageDownloadAnswer(primaryVol.getKey(), priVolInfo.allocation);
18291821
} catch (LibvirtException e) {
18301822
result = "Failed to download template: " + e.toString();
18311823
s_logger.debug(result);
1832-
return new Answer(cmd, false, result);
1824+
return new PrimaryStorageDownloadAnswer(result);
18331825
} catch (URISyntaxException e) {
18341826
// TODO Auto-generated catch block
1835-
return new Answer(cmd, false, e.toString());
1827+
return new PrimaryStorageDownloadAnswer(e.toString());
18361828
} finally {
18371829
try {
18381830
if (primaryVol != null) {

‎core/src/com/cloud/agent/api/storage/DownloadAnswer.java‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public class DownloadAnswer extends Answer {
3131
private VMTemplateHostVO.Status downloadStatus;
3232
private String downloadPath;
3333
private String installPath;
34-
public Long templateSize = 0L;
34+
private long templateSize = 0L;
35+
private long templatePhySicalSize = 0L;
3536

3637
public int getDownloadPct() {
3738
return downloadPct;
@@ -62,8 +63,15 @@ public void setJobId(String jobId) {
6263
this.jobId = jobId;
6364
}
6465

66+
public DownloadAnswer(String errorString, Status status) {
67+
super();
68+
this.downloadPct = 0;
69+
this.errorString = errorString;
70+
this.downloadStatus = status;
71+
}
72+
6573
public DownloadAnswer(String jobId, int downloadPct, String errorString,
66-
Status downloadStatus, String fileSystemPath, String installPath, long templateSize) {
74+
Status downloadStatus, String fileSystemPath, String installPath, long templateSize, long templatePhySicalSize ) {
6775
super();
6876
this.jobId = jobId;
6977
this.downloadPct = downloadPct;
@@ -72,6 +80,7 @@ public DownloadAnswer(String jobId, int downloadPct, String errorString,
7280
this.downloadPath = fileSystemPath;
7381
this.installPath = fixPath(installPath);
7482
this.templateSize = templateSize;
83+
this.templatePhySicalSize = templatePhySicalSize;
7584
}
7685

7786
public DownloadAnswer(String jobId, int downloadPct, Command command,
@@ -114,5 +123,11 @@ public void setTemplateSize(long templateSize) {
114123
public Long getTemplateSize() {
115124
return templateSize;
116125
}
126+
public void setTemplatePhySicalSize(long templatePhySicalSize) {
127+
this.templatePhySicalSize = templatePhySicalSize;
128+
}
129+
public long getTemplatePhySicalSize() {
130+
return templatePhySicalSize;
131+
}
117132

118133
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
package com.cloud.agent.api.storage;
19+
20+
import com.cloud.agent.api.Answer;
21+
22+
public class PrimaryStorageDownloadAnswer extends Answer {
23+
private String installPath;
24+
private long templateSize = 0L;
25+
26+
protected PrimaryStorageDownloadAnswer() {
27+
}
28+
29+
public PrimaryStorageDownloadAnswer(String detail) {
30+
super(null, false, detail);
31+
}
32+
33+
public PrimaryStorageDownloadAnswer(String installPath, long templateSize ) {
34+
super(null);
35+
this.installPath = installPath;
36+
this.templateSize = templateSize;
37+
}
38+
39+
public String getInstallPath() {
40+
return installPath;
41+
}
42+
43+
public void setInstallPath(String installPath) {
44+
this.installPath = installPath;
45+
}
46+
47+
public void setTemplateSize(long templateSize) {
48+
this.templateSize = templateSize;
49+
}
50+
51+
public Long getTemplateSize() {
52+
return templateSize;
53+
}
54+
55+
}

‎core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@
142142
import com.cloud.agent.api.storage.CreateCommand;
143143
import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
144144
import com.cloud.agent.api.storage.DestroyCommand;
145-
import com.cloud.agent.api.storage.DownloadAnswer;
146145
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
146+
import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
147147
import com.cloud.agent.api.storage.ShareAnswer;
148148
import com.cloud.agent.api.storage.ShareCommand;
149149
import com.cloud.agent.api.to.NicTO;
@@ -2066,7 +2066,7 @@ protected PrepareForMigrationAnswer execute(final PrepareForMigrationCommand cmd
20662066
}
20672067

20682068
@Override
2069-
public DownloadAnswer execute(final PrimaryStorageDownloadCommand cmd) {
2069+
public PrimaryStorageDownloadAnswer execute(final PrimaryStorageDownloadCommand cmd) {
20702070
SR tmpltsr = null;
20712071
String tmplturl = cmd.getUrl();
20722072
int index = tmplturl.lastIndexOf("/");
@@ -2082,7 +2082,7 @@ public DownloadAnswer execute(final PrimaryStorageDownloadCommand cmd) {
20822082
if (srs.size() != 1) {
20832083
String msg = "There are " + srs.size() + " SRs with same name: " + pUuid;
20842084
s_logger.warn(msg);
2085-
return new DownloadAnswer(null, 0, msg, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR, "", "", 0);
2085+
return new PrimaryStorageDownloadAnswer(msg);
20862086
} else {
20872087
poolsr = srs.iterator().next();
20882088
}
@@ -2119,7 +2119,7 @@ public DownloadAnswer execute(final PrimaryStorageDownloadCommand cmd) {
21192119
if (tmpltvdi == null) {
21202120
String msg = "Unable to find template vdi on secondary storage" + "host:" + _host.uuid + "pool: " + tmplturl;
21212121
s_logger.warn(msg);
2122-
return new DownloadAnswer(null, 0, msg, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR, "", "", 0);
2122+
return new PrimaryStorageDownloadAnswer(msg);
21232123
}
21242124
vmtmpltvdi = cloudVDIcopy(tmpltvdi, poolsr);
21252125
snapshotvdi = vmtmpltvdi.snapshot(conn, new HashMap<String, String>());
@@ -2138,20 +2138,16 @@ public DownloadAnswer execute(final PrimaryStorageDownloadCommand cmd) {
21382138

21392139
// Determine the size of the template
21402140
long phySize = vmtmpltvdi.getPhysicalUtilisation(conn);
2141-
2142-
DownloadAnswer answer = new DownloadAnswer(null, 100, cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, uuid, uuid);
2143-
answer.setTemplateSize(phySize);
2144-
2145-
return answer;
2141+
return new PrimaryStorageDownloadAnswer(uuid, phySize);
21462142

21472143
} catch (XenAPIException e) {
21482144
String msg = "XenAPIException:" + e.toString() + "host:" + _host.uuid + "pool: " + tmplturl;
21492145
s_logger.warn(msg, e);
2150-
return new DownloadAnswer(null, 0, msg, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR, "", "", 0);
2146+
return new PrimaryStorageDownloadAnswer(msg);
21512147
} catch (Exception e) {
21522148
String msg = "XenAPIException:" + e.getMessage() + "host:" + _host.uuid + "pool: " + tmplturl;
21532149
s_logger.warn(msg, e);
2154-
return new DownloadAnswer(null, 0, msg, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR, "", "", 0);
2150+
return new PrimaryStorageDownloadAnswer(msg);
21552151
} finally {
21562152
removeSR(tmpltsr);
21572153
}
@@ -3901,7 +3897,7 @@ protected void getPVISO(StartupStorageCommand sscmd) {
39013897
VDI pvISO = vids.iterator().next();
39023898
String uuid = pvISO.getUuid(conn);
39033899
Map<String, TemplateInfo> pvISOtmlt = new HashMap<String, TemplateInfo>();
3904-
TemplateInfo tmplt = new TemplateInfo("xs-tools.iso", uuid, pvISO.getVirtualSize(conn), true, false);
3900+
TemplateInfo tmplt = new TemplateInfo("xs-tools.iso", uuid, pvISO.getVirtualSize(conn), pvISO.getVirtualSize(conn), true, false);
39053901
pvISOtmlt.put("xs-tools", tmplt);
39063902
sscmd.setTemplateInfo(pvISOtmlt);
39073903
} catch (XenAPIException e) {

‎core/src/com/cloud/storage/VMTemplateHostVO.java‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ public class VMTemplateHostVO implements VMTemplateStorageResourceAssoc {
6262
private int downloadPercent;
6363

6464
@Column (name="size")
65-
private long size;
65+
private long size;
66+
67+
@Column (name="physicalSize")
68+
private long physicalSize;
6669

6770
@Column (name="download_state")
6871
@Enumerated(EnumType.STRING)
@@ -240,6 +243,14 @@ public long getSize() {
240243
}
241244

242245

246+
public void setPhysicalSize(long physicalSize) {
247+
this.physicalSize = physicalSize;
248+
}
249+
250+
public long getPhysicalSize() {
251+
return physicalSize;
252+
}
253+
243254
public void setDestroyed(boolean destroyed) {
244255
this.destroyed = destroyed;
245256
}

‎core/src/com/cloud/storage/resource/StoragePoolResource.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
import com.cloud.agent.api.storage.CreateAnswer;
2424
import com.cloud.agent.api.storage.CreateCommand;
2525
import com.cloud.agent.api.storage.DestroyCommand;
26-
import com.cloud.agent.api.storage.DownloadAnswer;
2726
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
27+
import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
2828
import com.cloud.agent.api.storage.ShareAnswer;
2929
import com.cloud.agent.api.storage.ShareCommand;
3030

3131
public interface StoragePoolResource {
3232
// FIXME: Should have a PrimaryStorageDownloadAnswer
33-
DownloadAnswer execute(PrimaryStorageDownloadCommand cmd);
33+
PrimaryStorageDownloadAnswer execute(PrimaryStorageDownloadCommand cmd);
3434

3535
// FIXME: Should have an DestroyAnswer
3636
Answer execute(DestroyCommand cmd);

0 commit comments

Comments
 (0)