mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
Add template zone related information into TemplateZoneResponse.
This commit is contained in:
parent
c8692f2e4a
commit
3160a0c2da
@ -16,6 +16,8 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.response;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseResponse;
|
||||
|
||||
@ -29,6 +31,15 @@ public class TemplateZoneResponse extends BaseResponse {
|
||||
@SerializedName(ApiConstants.ZONE_NAME) @Param(description="the name of the zone for the template")
|
||||
private String zoneName;
|
||||
|
||||
@SerializedName(ApiConstants.STATUS) @Param(description="the status of the template")
|
||||
private String status;
|
||||
|
||||
@SerializedName(ApiConstants.IS_READY) // propName="ready" (FIXME: this used to be part of Param annotation, do we need it?)
|
||||
@Param(description="true if the template is ready to be deployed from, false otherwise.")
|
||||
private boolean isReady;
|
||||
|
||||
@SerializedName(ApiConstants.CREATED) @Param(description="the date this template was created")
|
||||
private Date created;
|
||||
|
||||
public TemplateZoneResponse(){
|
||||
super();
|
||||
@ -58,6 +69,31 @@ public class TemplateZoneResponse extends BaseResponse {
|
||||
this.zoneName = zoneName;
|
||||
}
|
||||
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public boolean isReady() {
|
||||
return isReady;
|
||||
}
|
||||
|
||||
public void setReady(boolean isReady) {
|
||||
this.isReady = isReady;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
@ -69,21 +105,26 @@ public class TemplateZoneResponse extends BaseResponse {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
if (this == obj) {
|
||||
return true;
|
||||
if (obj == null)
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
TemplateZoneResponse other = (TemplateZoneResponse) obj;
|
||||
String oid = this.getZoneId();
|
||||
if (oid == null) {
|
||||
if (other.getZoneId() != null)
|
||||
if (other.getZoneId() != null) {
|
||||
return false;
|
||||
} else if (!oid.equals(other.getZoneId()))
|
||||
}
|
||||
} else if (!oid.equals(other.getZoneId())) {
|
||||
return false;
|
||||
else if ( this.getZoneName().equals(other.getZoneName()))
|
||||
} else if ( this.getZoneName().equals(other.getZoneName())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -38,8 +38,8 @@ import com.cloud.api.query.vo.ResourceTagJoinVO;
|
||||
import com.cloud.api.query.vo.TemplateJoinVO;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.user.Account;
|
||||
@ -96,6 +96,36 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO, Long> im
|
||||
|
||||
|
||||
|
||||
private String getTemplateStatus(TemplateJoinVO template){
|
||||
boolean isAdmin = false;
|
||||
Account caller = UserContext.current().getCaller();
|
||||
if ((caller == null) || BaseCmd.isAdmin(caller.getType())) {
|
||||
isAdmin = true;
|
||||
}
|
||||
|
||||
// If the user is an Admin, add the template download status
|
||||
String templateStatus = null;
|
||||
if (isAdmin || caller.getId() == template.getAccountId()) {
|
||||
// add download status
|
||||
if (template.getDownloadState() != Status.DOWNLOADED) {
|
||||
templateStatus = "Processing";
|
||||
if (template.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) {
|
||||
if (template.getDownloadPercent() == 100) {
|
||||
templateStatus = "Installing Template";
|
||||
} else {
|
||||
templateStatus = template.getDownloadPercent() + "% Downloaded";
|
||||
}
|
||||
} else {
|
||||
templateStatus = template.getErrorString();
|
||||
}
|
||||
} else if (template.getDownloadState() == VMTemplateHostVO.Status.DOWNLOADED) {
|
||||
templateStatus = "Download Complete";
|
||||
} else {
|
||||
templateStatus = "Successfully Installed";
|
||||
}
|
||||
}
|
||||
return templateStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateResponse newTemplateResponse(TemplateJoinVO template) {
|
||||
@ -136,33 +166,10 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO, Long> im
|
||||
templateResponse.setDomainName(template.getDomainName());
|
||||
|
||||
|
||||
|
||||
boolean isAdmin = false;
|
||||
Account caller = UserContext.current().getCaller();
|
||||
if ((caller == null) || BaseCmd.isAdmin(caller.getType())) {
|
||||
isAdmin = true;
|
||||
}
|
||||
|
||||
// If the user is an Admin, add the template download status
|
||||
if (isAdmin || caller.getId() == template.getAccountId()) {
|
||||
// add download status
|
||||
if (template.getDownloadState() != Status.DOWNLOADED) {
|
||||
String templateStatus = "Processing";
|
||||
if (template.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) {
|
||||
if (template.getDownloadPercent() == 100) {
|
||||
templateStatus = "Installing Template";
|
||||
} else {
|
||||
templateStatus = template.getDownloadPercent() + "% Downloaded";
|
||||
}
|
||||
} else {
|
||||
templateStatus = template.getErrorString();
|
||||
}
|
||||
templateResponse.setStatus(templateStatus);
|
||||
} else if (template.getDownloadState() == VMTemplateHostVO.Status.DOWNLOADED) {
|
||||
templateResponse.setStatus("Download Complete");
|
||||
} else {
|
||||
templateResponse.setStatus("Successfully Installed");
|
||||
}
|
||||
String templateStatus = getTemplateStatus(template);
|
||||
if ( templateStatus != null ){
|
||||
templateResponse.setStatus(templateStatus);
|
||||
}
|
||||
|
||||
Long templateSize = template.getSize();
|
||||
@ -179,6 +186,17 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO, Long> im
|
||||
// set template zone information
|
||||
if (template.getDataCenterId() > 0 ){
|
||||
TemplateZoneResponse tmplZoneResp = new TemplateZoneResponse(template.getDataCenterUuid(), template.getDataCenterName());
|
||||
tmplZoneResp.setCreated(template.getCreatedOnStore());
|
||||
if ( template.getFormat() == Storage.ImageFormat.BAREMETAL ){
|
||||
// for baremetal template, we didn't download, but is ready to use.
|
||||
tmplZoneResp.setReady(true);
|
||||
}
|
||||
else{
|
||||
tmplZoneResp.setReady(template.getState() == ObjectInDataStoreStateMachine.State.Ready);
|
||||
}
|
||||
if ( templateStatus != null ){
|
||||
tmplZoneResp.setStatus(templateStatus);
|
||||
}
|
||||
templateResponse.addZone(tmplZoneResp);
|
||||
// set the first found associated zone directly in TemplateResponse
|
||||
templateResponse.setZoneId(template.getDataCenterUuid());
|
||||
@ -259,6 +277,18 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO, Long> im
|
||||
// update template zone information
|
||||
if (template.getDataCenterId() > 0 ){
|
||||
TemplateZoneResponse tmplZoneResp = new TemplateZoneResponse(template.getDataCenterUuid(), template.getDataCenterName());
|
||||
tmplZoneResp.setCreated(template.getCreatedOnStore());
|
||||
if ( template.getFormat() == Storage.ImageFormat.BAREMETAL ){
|
||||
// for baremetal template, we didn't download, but is ready to use.
|
||||
tmplZoneResp.setReady(true);
|
||||
}
|
||||
else{
|
||||
tmplZoneResp.setReady(template.getState() == ObjectInDataStoreStateMachine.State.Ready);
|
||||
}
|
||||
String templateStatus = getTemplateStatus(template);
|
||||
if ( templateStatus != null ){
|
||||
tmplZoneResp.setStatus(templateStatus);
|
||||
}
|
||||
templateResponse.addZone(tmplZoneResp);
|
||||
if (templateResponse.getZoneId() == null) {
|
||||
// set the first found associated zone directly in
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user