Search in sources :

Example 11 with ResourceTagJoinVO

use of com.cloud.api.query.vo.ResourceTagJoinVO 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;
}
Also used : Account(com.cloud.user.Account) TemplateResponse(com.cloud.api.response.TemplateResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO)

Example 12 with ResourceTagJoinVO

use of com.cloud.api.query.vo.ResourceTagJoinVO in project cosmic by MissionCriticalCloud.

the class TemplateJoinDaoImpl method newUpdateResponse.

// TODO: This is to keep compatibility with 4.1 API, where updateTemplateCmd and updateIsoCmd will return a simpler TemplateResponse
// compared to listTemplates and listIsos.
@Override
public TemplateResponse newUpdateResponse(final TemplateJoinVO result) {
    final TemplateResponse response = new TemplateResponse();
    response.setId(result.getUuid());
    response.setName(result.getName());
    response.setDisplayText(result.getDisplayText());
    response.setPublic(result.isPublicTemplate());
    response.setCreated(result.getCreated());
    response.setFormat(result.getFormat());
    response.setOsTypeId(result.getGuestOSUuid());
    response.setOsTypeName(result.getGuestOSName());
    response.setBootable(result.isBootable());
    response.setHypervisor(result.getHypervisorType().toString());
    // populate owner.
    ApiResponseHelper.populateOwner(response, result);
    // populate domain
    response.setDomainId(result.getDomainUuid());
    response.setDomainName(result.getDomainName());
    // set details map
    if (result.getDetailName() != null) {
        final Map<String, String> details = new HashMap<>();
        details.put(result.getDetailName(), result.getDetailValue());
        response.setDetails(details);
    }
    // update tag information
    final long tag_id = result.getTagId();
    if (tag_id > 0) {
        final ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
        if (vtag != null) {
            response.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
        }
    }
    response.setObjectName("iso");
    return response;
}
Also used : HashMap(java.util.HashMap) TemplateResponse(com.cloud.api.response.TemplateResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO)

Example 13 with ResourceTagJoinVO

use of com.cloud.api.query.vo.ResourceTagJoinVO in project cosmic by MissionCriticalCloud.

the class ProjectJoinDaoImpl method newProjectResponse.

@Override
public ProjectResponse newProjectResponse(final ProjectJoinVO proj) {
    final ProjectResponse response = new ProjectResponse();
    response.setId(proj.getUuid());
    response.setName(proj.getName());
    response.setDisplaytext(proj.getDisplayText());
    if (proj.getState() != null) {
        response.setState(proj.getState().toString());
    }
    response.setDomainId(proj.getDomainUuid());
    response.setDomain(proj.getDomainName());
    response.setOwner(proj.getOwner());
    // update tag information
    final Long tag_id = proj.getTagId();
    if (tag_id != null && tag_id.longValue() > 0) {
        final ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
        if (vtag != null) {
            response.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
        }
    }
    // set resource limit/count information for the project (by getting the info of the project's account)
    final Account account = _accountDao.findByIdIncludingRemoved(proj.getProjectAccountId());
    final AccountJoinVO accountJn = ApiDBUtils.newAccountView(account);
    _accountJoinDao.setResourceLimits(accountJn, false, response);
    response.setObjectName("project");
    return response;
}
Also used : Account(com.cloud.user.Account) ProjectResponse(com.cloud.api.response.ProjectResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO) AccountJoinVO(com.cloud.api.query.vo.AccountJoinVO)

Example 14 with ResourceTagJoinVO

use of com.cloud.api.query.vo.ResourceTagJoinVO in project cloudstack by apache.

the class TemplateJoinDaoImpl method newUpdateResponse.

// TODO: This is to keep compatibility with 4.1 API, where updateTemplateCmd and updateIsoCmd will return a simpler TemplateResponse
// compared to listTemplates and listIsos.
@Override
public TemplateResponse newUpdateResponse(TemplateJoinVO result) {
    TemplateResponse response = new TemplateResponse();
    response.setId(result.getUuid());
    response.setName(result.getName());
    response.setDisplayText(result.getDisplayText());
    response.setPublic(result.isPublicTemplate());
    response.setCreated(result.getCreated());
    response.setFormat(result.getFormat());
    response.setOsTypeId(result.getGuestOSUuid());
    response.setOsTypeName(result.getGuestOSName());
    response.setBootable(result.isBootable());
    response.setHypervisor(result.getHypervisorType().toString());
    response.setDynamicallyScalable(result.isDynamicallyScalable());
    // populate owner.
    ApiResponseHelper.populateOwner(response, result);
    // populate domain
    response.setDomainId(result.getDomainUuid());
    response.setDomainName(result.getDomainName());
    // set details map
    if (result.getDetailName() != null) {
        Map<String, String> details = new HashMap<>();
        details.put(result.getDetailName(), result.getDetailValue());
        response.setDetails(details);
    }
    // update tag information
    long tag_id = result.getTagId();
    if (tag_id > 0) {
        ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
        if (vtag != null) {
            response.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
        }
    }
    response.setObjectName("iso");
    return response;
}
Also used : HashMap(java.util.HashMap) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse) ChildTemplateResponse(org.apache.cloudstack.api.response.ChildTemplateResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO)

Example 15 with ResourceTagJoinVO

use of com.cloud.api.query.vo.ResourceTagJoinVO in project cloudstack by apache.

the class TemplateJoinDaoImpl method newIsoResponse.

@Override
public TemplateResponse newIsoResponse(TemplateJoinVO iso) {
    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 TemplateManager.XS_TOOLS_ISO and TemplateManager.VMWARE_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(DigestHelper.getHashValueFromChecksumValue(iso.getChecksum()));
    isoResponse.setOsTypeId(iso.getGuestOSUuid());
    isoResponse.setOsTypeName(iso.getGuestOSName());
    isoResponse.setBits(iso.getBits());
    isoResponse.setPasswordEnabled(iso.isEnablePassword());
    // populate owner.
    ApiResponseHelper.populateOwner(isoResponse, iso);
    // populate domain
    isoResponse.setDomainId(iso.getDomainUuid());
    isoResponse.setDomainName(iso.getDomainName());
    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() == 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");
        }
        isoResponse.setUrl(iso.getUrl());
    }
    if (iso.getDataCenterId() > 0) {
        isoResponse.setZoneId(iso.getDataCenterUuid());
        isoResponse.setZoneName(iso.getDataCenterName());
    }
    Long isoSize = iso.getSize();
    if (isoSize > 0) {
        isoResponse.setSize(isoSize);
    }
    // update tag information
    long tag_id = iso.getTagId();
    if (tag_id > 0) {
        ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
        if (vtag != null) {
            isoResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
        }
    }
    isoResponse.setHasAnnotation(annotationDao.hasAnnotations(iso.getUuid(), AnnotationService.EntityType.ISO.name(), _accountService.isRootAdmin(CallContext.current().getCallingAccount().getId())));
    isoResponse.setDirectDownload(iso.isDirectDownload());
    isoResponse.setObjectName("iso");
    return isoResponse;
}
Also used : Account(com.cloud.user.Account) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse) ChildTemplateResponse(org.apache.cloudstack.api.response.ChildTemplateResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO)

Aggregations

ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)19 Account (com.cloud.user.Account)9 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 AccountJoinVO (com.cloud.api.query.vo.AccountJoinVO)3 TemplateResponse (com.cloud.api.response.TemplateResponse)3 ResourceTagResponse (org.apache.cloudstack.api.response.ResourceTagResponse)3 AffinityGroupResponse (com.cloud.affinity.AffinityGroupResponse)2 SecurityGroupJoinVO (com.cloud.api.query.vo.SecurityGroupJoinVO)2 NicResponse (com.cloud.api.response.NicResponse)2 NicSecondaryIpResponse (com.cloud.api.response.NicSecondaryIpResponse)2 ListProjectResourcesCriteria (com.cloud.projects.Project.ListProjectResourcesCriteria)2 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)2 User (com.cloud.user.User)2 Ternary (com.cloud.utils.Ternary)2 Filter (com.cloud.utils.db.Filter)2 NicSecondaryIpVO (com.cloud.vm.dao.NicSecondaryIpVO)2 HashSet (java.util.HashSet)2 List (java.util.List)2 ChildTemplateResponse (org.apache.cloudstack.api.response.ChildTemplateResponse)2