Skip to content

Commit af9d686

Browse files
authored
Initialize template status='Processing' (#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 ca52327 commit af9d686

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
@@ -77,6 +77,7 @@
7777
import com.cloud.user.Account;
7878
import com.cloud.user.AccountService;
7979
import com.cloud.utils.Pair;
80+
import com.cloud.utils.StringUtils;
8081
import com.cloud.utils.db.Filter;
8182
import com.cloud.utils.db.SearchBuilder;
8283
import com.cloud.utils.db.SearchCriteria;
@@ -161,29 +162,50 @@ protected TemplateJoinDaoImpl() {
161162
_count = "select count(distinct temp_zone_pair) from template_view WHERE ";
162163
}
163164

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

189211
@Override
@@ -511,24 +533,9 @@ public TemplateResponse newIsoResponse(TemplateJoinVO iso, ResponseView view) {
511533
// If the user is an admin, add the template download status
512534
if (isAdmin || caller.getId() == iso.getAccountId()) {
513535
// add download status
514-
if (iso.getDownloadState() != Status.DOWNLOADED) {
515-
String isoStatus = "Processing";
516-
if (iso.getDownloadState() == Status.DOWNLOADED) {
517-
isoStatus = "Download Complete";
518-
} else if (iso.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
519-
if (iso.getDownloadPercent() == 100) {
520-
isoStatus = "Installing ISO";
521-
} else {
522-
isoStatus = iso.getDownloadPercent() + "% Downloaded";
523-
}
524-
} else if (iso.getDownloadState() == Status.BYPASSED) {
525-
isoStatus = "Bypassed Secondary Storage";
526-
} else {
527-
isoStatus = iso.getErrorString();
528-
}
529-
isoResponse.setStatus(isoStatus);
530-
} else {
531-
isoResponse.setStatus("Successfully Installed");
536+
String templateStatus = getTemplateStatus(iso);
537+
if (templateStatus != null) {
538+
isoResponse.setStatus(templateStatus);
532539
}
533540
isoResponse.setUrl(iso.getUrl());
534541
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
@@ -1658,11 +1658,12 @@ def download(self, apiclient, retries=300, interval=5):
16581658
# If template is ready,
16591659
# template.status = Download Complete
16601660
# Downloading - x% Downloaded
1661+
# Processing - Initial status
16611662
# Error - Any other string
16621663
if template.status == 'Download Complete' and template.isready:
16631664
return
16641665

1665-
elif 'Downloaded' in template.status:
1666+
elif 'Downloaded' in template.status or template.status == 'Processing':
16661667
retries = retries - 1
16671668
continue
16681669

0 commit comments

Comments
 (0)