use of com.cloud.api.response.TemplateResponse in project CloudStack-archive by CloudStack-extras.
the class RegisterIsoCmd method execute.
@Override
public void execute() throws ResourceAllocationException {
VirtualMachineTemplate template = _templateService.registerIso(this);
if (template != null) {
ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(template.getId(), zoneId, false);
response.setResponses(templateResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to register iso");
}
}
use of com.cloud.api.response.TemplateResponse in project CloudStack-archive by CloudStack-extras.
the class CopyTemplateCmd method execute.
@Override
public void execute() throws ResourceAllocationException {
try {
UserContext.current().setEventDetails(getEventDescription());
VirtualMachineTemplate template = _templateService.copyTemplate(this);
if (template != null) {
List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(template.getId(), getDestinationZoneId(), false);
TemplateResponse response = new TemplateResponse();
if (listResponse != null && !listResponse.isEmpty()) {
response = listResponse.get(0);
}
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to copy template");
}
} catch (StorageUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
}
}
use of com.cloud.api.response.TemplateResponse in project cosmic by MissionCriticalCloud.
the class ViewResponseHelper method createTemplateUpdateResponse.
public static List<TemplateResponse> createTemplateUpdateResponse(final ResponseView view, final TemplateJoinVO... templates) {
final Hashtable<Long, TemplateResponse> vrDataList = new Hashtable<>();
for (final TemplateJoinVO vr : templates) {
TemplateResponse vrData = vrDataList.get(vr.getId());
if (vrData == null) {
// first time encountering this volume
vrData = ApiDBUtils.newTemplateUpdateResponse(vr);
} else {
// update tags
vrData = ApiDBUtils.fillTemplateDetails(view, vrData, vr);
}
vrDataList.put(vr.getId(), vrData);
}
return new ArrayList<>(vrDataList.values());
}
use of com.cloud.api.response.TemplateResponse in project cosmic by MissionCriticalCloud.
the class ViewResponseHelper method createTemplateResponse.
public static List<TemplateResponse> createTemplateResponse(final ResponseView view, final TemplateJoinVO... templates) {
final LinkedHashMap<String, TemplateResponse> vrDataList = new LinkedHashMap<>();
for (final TemplateJoinVO vr : templates) {
TemplateResponse vrData = vrDataList.get(vr.getTempZonePair());
if (vrData == null) {
// first time encountering this volume
vrData = ApiDBUtils.newTemplateResponse(view, vr);
} else {
// update tags
vrData = ApiDBUtils.fillTemplateDetails(view, vrData, vr);
}
vrDataList.put(vr.getTempZonePair(), vrData);
}
return new ArrayList<>(vrDataList.values());
}
use of com.cloud.api.response.TemplateResponse in project cosmic by MissionCriticalCloud.
the class TemplateJoinDaoImpl method newIsoResponse.
@Override
public TemplateResponse newIsoResponse(final TemplateJoinVO iso) {
final TemplateResponse isoResponse = new TemplateResponse();
isoResponse.setId(iso.getUuid());
isoResponse.setName(iso.getName());
isoResponse.setDisplayText(iso.getDisplayText());
isoResponse.setPublic(iso.isPublicTemplate());
isoResponse.setExtractable(iso.isExtractable() && !(iso.getTemplateType() == TemplateType.PERHOST));
isoResponse.setCreated(iso.getCreatedOnStore());
isoResponse.setDynamicallyScalable(iso.isDynamicallyScalable());
if (iso.getTemplateType() == TemplateType.PERHOST) {
// for xs-tools.iso, we didn't download, but is ready to use.
isoResponse.setReady(true);
} else {
isoResponse.setReady(iso.getState() == ObjectInDataStoreStateMachine.State.Ready);
}
isoResponse.setBootable(iso.isBootable());
isoResponse.setFeatured(iso.isFeatured());
isoResponse.setCrossZones(iso.isCrossZones());
isoResponse.setPublic(iso.isPublicTemplate());
isoResponse.setChecksum(iso.getChecksum());
isoResponse.setOsTypeId(iso.getGuestOSUuid());
isoResponse.setOsTypeName(iso.getGuestOSName());
// populate owner.
ApiResponseHelper.populateOwner(isoResponse, iso);
// populate domain
isoResponse.setDomainId(iso.getDomainUuid());
isoResponse.setDomainName(iso.getDomainName());
final Account caller = CallContext.current().getCallingAccount();
boolean isAdmin = false;
if (caller == null || _accountService.isAdmin(caller.getId())) {
isAdmin = true;
}
// 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() == VMTemplateHostVO.Status.DOWNLOADED) {
isoStatus = "Download Complete";
} else if (iso.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) {
if (iso.getDownloadPercent() == 100) {
isoStatus = "Installing ISO";
} else {
isoStatus = iso.getDownloadPercent() + "% Downloaded";
}
} else {
isoStatus = iso.getErrorString();
}
isoResponse.setStatus(isoStatus);
} else {
isoResponse.setStatus("Successfully Installed");
}
}
if (iso.getDataCenterId() > 0) {
isoResponse.setZoneId(iso.getDataCenterUuid());
isoResponse.setZoneName(iso.getDataCenterName());
}
final Long isoSize = iso.getSize();
if (isoSize > 0) {
isoResponse.setSize(isoSize);
}
// update tag information
final long tag_id = iso.getTagId();
if (tag_id > 0) {
final ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
if (vtag != null) {
isoResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
}
}
isoResponse.setObjectName("iso");
return isoResponse;
}
Aggregations