Skip to content

Commit f4bb6d1

Browse files
sudo87dhslove
authored andcommitted
Initialize template status='Processing' (apache#11970)
* Initialize template status='Processing' * remove else block and fix the error string * restructure if-else * standardize register ISO response * use enum instead of string * fix smoke test failures * Add Download Complete status for template
1 parent eb7d54c commit f4bb6d1

2 files changed

Lines changed: 45 additions & 37 deletions

File tree

server/src/main/java/com/cloud/api/query/dao/TemplateJoinDaoImpl.java

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import com.cloud.user.AccountService;
7777
import com.cloud.user.dao.UserDataDao;
7878
import com.cloud.utils.Pair;
79+
import com.cloud.utils.StringUtils;
7980
import com.cloud.utils.db.Filter;
8081
import com.cloud.utils.db.SearchBuilder;
8182
import com.cloud.utils.db.SearchCriteria;
@@ -160,29 +161,50 @@ protected TemplateJoinDaoImpl() {
160161
_count = "select count(distinct temp_zone_pair) from template_view WHERE ";
161162
}
162163

164+
private enum TemplateStatus {
165+
SUCCESSFULLY_INSTALLED("Successfully Installed"),
166+
INSTALLING_TEMPLATE("Installing Template"),
167+
INSTALLING_ISO("Installing ISO"),
168+
BYPASSED_SECONDARY_STORAGE("Bypassed Secondary Storage"),
169+
PROCESSING("Processing"),
170+
DOWNLOADING("%d%% Downloaded"),
171+
DOWNLOAD_COMPLETE("Download Complete");
172+
173+
private final String status;
174+
TemplateStatus(String status) {
175+
this.status = status;
176+
}
177+
public String getStatus() {
178+
return status;
179+
}
180+
// For statuses that have dynamic details (e.g. "75% Downloaded").
181+
public String format(int percent) {
182+
return String.format(status, percent);
183+
}
184+
}
185+
163186
private String getTemplateStatus(TemplateJoinVO template) {
164-
String templateStatus = null;
165-
if (template.getDownloadState() != Status.DOWNLOADED) {
166-
templateStatus = "Processing";
167-
if (template.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
168-
if (template.getDownloadPercent() == 100) {
169-
templateStatus = "Installing Template";
170-
} else {
171-
templateStatus = template.getDownloadPercent() + "% Downloaded";
172-
}
173-
} else if (template.getDownloadState() == Status.BYPASSED) {
174-
templateStatus = "Bypassed Secondary Storage";
175-
} else if (template.getErrorString() == null) {
176-
templateStatus = template.getTemplateState().toString();
187+
if (template == null) {
188+
return null;
189+
}
190+
boolean isIso = Storage.ImageFormat.ISO == template.getFormat();
191+
TemplateStatus templateStatus;
192+
if (template.getDownloadState() == Status.DOWNLOADED) {
193+
templateStatus = isIso ? TemplateStatus.SUCCESSFULLY_INSTALLED : TemplateStatus.DOWNLOAD_COMPLETE;
194+
} else if (template.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
195+
if (template.getDownloadPercent() == 100) {
196+
templateStatus = isIso ? TemplateStatus.INSTALLING_ISO : TemplateStatus.INSTALLING_TEMPLATE;
177197
} else {
178-
templateStatus = template.getErrorString().trim();
198+
return TemplateStatus.DOWNLOADING.format(template.getDownloadPercent());
179199
}
180-
} else if (template.getDownloadState() == Status.DOWNLOADED) {
181-
templateStatus = "Download Complete";
200+
} else if (template.getDownloadState() == Status.BYPASSED) {
201+
templateStatus = TemplateStatus.BYPASSED_SECONDARY_STORAGE;
202+
} else if (StringUtils.isNotBlank(template.getErrorString())) {
203+
return template.getErrorString().trim();
182204
} else {
183-
templateStatus = "Successfully Installed";
205+
templateStatus = TemplateStatus.PROCESSING;
184206
}
185-
return templateStatus;
207+
return templateStatus.getStatus();
186208
}
187209

188210
@Override
@@ -504,24 +526,9 @@ public TemplateResponse newIsoResponse(TemplateJoinVO iso, ResponseView view) {
504526
// If the user is an admin, add the template download status
505527
if (isAdmin || caller.getId() == iso.getAccountId()) {
506528
// add download status
507-
if (iso.getDownloadState() != Status.DOWNLOADED) {
508-
String isoStatus = "Processing";
509-
if (iso.getDownloadState() == Status.DOWNLOADED) {
510-
isoStatus = "Download Complete";
511-
} else if (iso.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
512-
if (iso.getDownloadPercent() == 100) {
513-
isoStatus = "Installing ISO";
514-
} else {
515-
isoStatus = iso.getDownloadPercent() + "% Downloaded";
516-
}
517-
} else if (iso.getDownloadState() == Status.BYPASSED) {
518-
isoStatus = "Bypassed Secondary Storage";
519-
} else {
520-
isoStatus = iso.getErrorString();
521-
}
522-
isoResponse.setStatus(isoStatus);
523-
} else {
524-
isoResponse.setStatus("Successfully Installed");
529+
String templateStatus = getTemplateStatus(iso);
530+
if (templateStatus != null) {
531+
isoResponse.setStatus(templateStatus);
525532
}
526533
isoResponse.setUrl(iso.getUrl());
527534
List<TemplateDataStoreVO> isosInStore = _templateStoreDao.listByTemplateNotBypassed(iso.getId());

tools/marvin/marvin/lib/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,11 +1740,12 @@ def download(self, apiclient, retries=300, interval=5):
17401740
# If template is ready,
17411741
# template.status = Download Complete
17421742
# Downloading - x% Downloaded
1743+
# Processing - Initial status
17431744
# Error - Any other string
17441745
if template.status == 'Download Complete' and template.isready:
17451746
return
17461747

1747-
elif 'Downloaded' in template.status:
1748+
elif 'Downloaded' in template.status or template.status == 'Processing':
17481749
retries = retries - 1
17491750
continue
17501751

0 commit comments

Comments
 (0)