Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import com.cloud.user.Account;
import com.cloud.user.AccountService;
import com.cloud.utils.Pair;
import com.cloud.utils.StringUtils;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
Expand Down Expand Up @@ -161,29 +162,52 @@ protected TemplateJoinDaoImpl() {
_count = "select count(distinct temp_zone_pair) from template_view WHERE ";
}

private enum TemplateStatus {
SUCCESSFULLY_INSTALLED("Successfully Installed"),
INSTALLING_TEMPLATE("Installing Template"),
INSTALLING_ISO("Installing ISO"),
BYPASSED_SECONDARY_STORAGE("Bypassed Secondary Storage"),
PROCESSING("Processing"),
DOWNLOADING("%d%% Downloaded");

private final String status;
TemplateStatus(String status) {
this.status = status;
}
public String getStatus() {
return status;
}
// For statuses that have dynamic details (e.g. "75% Downloaded").
public String format(int percent) {
return String.format(status, percent);
}
}

private String getTemplateStatus(TemplateJoinVO template) {
String templateStatus = null;
if (template.getDownloadState() != Status.DOWNLOADED) {
templateStatus = "Processing";
if (template.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
if (template.getDownloadPercent() == 100) {
templateStatus = "Installing Template";
} else {
templateStatus = template.getDownloadPercent() + "% Downloaded";
if (template == null) {
return null;
}

TemplateStatus templateStatus;
if (template.getDownloadState() == Status.DOWNLOADED) {
templateStatus = TemplateStatus.SUCCESSFULLY_INSTALLED;
} else if (template.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
if (template.getDownloadPercent() == 100) {
templateStatus = TemplateStatus.INSTALLING_TEMPLATE;
if (Storage.ImageFormat.ISO == template.getFormat()) {
templateStatus = TemplateStatus.INSTALLING_ISO;
}
} else if (template.getDownloadState() == Status.BYPASSED) {
templateStatus = "Bypassed Secondary Storage";
} else if (template.getErrorString() == null) {
templateStatus = template.getTemplateState().toString();
} else {
templateStatus = template.getErrorString().trim();
return TemplateStatus.DOWNLOADING.format(template.getDownloadPercent());
}
} else if (template.getDownloadState() == Status.DOWNLOADED) {
templateStatus = "Download Complete";
} else if (template.getDownloadState() == Status.BYPASSED) {
templateStatus = TemplateStatus.BYPASSED_SECONDARY_STORAGE;
} else if (StringUtils.isNotBlank(template.getErrorString())) {
return template.getErrorString().trim();
} else {
templateStatus = "Successfully Installed";
templateStatus = TemplateStatus.PROCESSING;
}
return templateStatus;
return templateStatus.getStatus();
}

@Override
Expand Down Expand Up @@ -511,24 +535,9 @@ public TemplateResponse newIsoResponse(TemplateJoinVO iso, ResponseView view) {
// If the user is an admin, add the template download status
if (isAdmin || caller.getId() == iso.getAccountId()) {
// add download status
if (iso.getDownloadState() != Status.DOWNLOADED) {
String isoStatus = "Processing";
if (iso.getDownloadState() == Status.DOWNLOADED) {
isoStatus = "Download Complete";
} else if (iso.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
if (iso.getDownloadPercent() == 100) {
isoStatus = "Installing ISO";
} else {
isoStatus = iso.getDownloadPercent() + "% Downloaded";
}
} else if (iso.getDownloadState() == Status.BYPASSED) {
isoStatus = "Bypassed Secondary Storage";
} else {
isoStatus = iso.getErrorString();
}
isoResponse.setStatus(isoStatus);
} else {
isoResponse.setStatus("Successfully Installed");
String templateStatus = getTemplateStatus(iso);
if (templateStatus != null) {
isoResponse.setStatus(templateStatus);
}
isoResponse.setUrl(iso.getUrl());
List<TemplateDataStoreVO> isosInStore = _templateStoreDao.listByTemplateNotBypassed(iso.getId());
Expand Down
Loading