Skip to content

Commit 039ab32

Browse files
sudo87Locharla, Sandeep
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 f340e77 commit 039ab32

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed

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
@@ -503,24 +525,9 @@ public TemplateResponse newIsoResponse(TemplateJoinVO iso, ResponseView view) {
503525
// If the user is an admin, add the template download status
504526
if (isAdmin || caller.getId() == iso.getAccountId()) {
505527
// add download status
506-
if (iso.getDownloadState() != Status.DOWNLOADED) {
507-
String isoStatus = "Processing";
508-
if (iso.getDownloadState() == Status.DOWNLOADED) {
509-
isoStatus = "Download Complete";
510-
} else if (iso.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
511-
if (iso.getDownloadPercent() == 100) {
512-
isoStatus = "Installing ISO";
513-
} else {
514-
isoStatus = iso.getDownloadPercent() + "% Downloaded";
515-
}
516-
} else if (iso.getDownloadState() == Status.BYPASSED) {
517-
isoStatus = "Bypassed Secondary Storage";
518-
} else {
519-
isoStatus = iso.getErrorString();
520-
}
521-
isoResponse.setStatus(isoStatus);
522-
} else {
523-
isoResponse.setStatus("Successfully Installed");
528+
String templateStatus = getTemplateStatus(iso);
529+
if (templateStatus != null) {
530+
isoResponse.setStatus(templateStatus);
524531
}
525532
isoResponse.setUrl(iso.getUrl());
526533
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
@@ -1725,11 +1725,12 @@ def download(self, apiclient, retries=300, interval=5):
17251725
# If template is ready,
17261726
# template.status = Download Complete
17271727
# Downloading - x% Downloaded
1728+
# Processing - Initial status
17281729
# Error - Any other string
17291730
if template.status == 'Download Complete' and template.isready:
17301731
return
17311732

1732-
elif 'Downloaded' in template.status:
1733+
elif 'Downloaded' in template.status or template.status == 'Processing':
17331734
retries = retries - 1
17341735
continue
17351736

0 commit comments

Comments
 (0)