Search in sources :

Example 1 with ResourceIconVO

use of com.cloud.resource.icon.ResourceIconVO in project cloudstack by apache.

the class ResourceIconDaoImpl method listResourceIcons.

@Override
public List<ResourceIconResponse> listResourceIcons(List<String> resourceUuids, ResourceTag.ResourceObjectType resourceType) {
    SearchCriteria<ResourceIconVO> sc = AllFieldsSearch.create();
    sc.setParameters("uuid", resourceUuids.toArray());
    sc.setParameters("resourceType", resourceType);
    List<ResourceIconVO> resourceIcons = listBy(sc);
    List<ResourceIconResponse> iconResponses = new ArrayList<>();
    for (ResourceIconVO resourceIcon : resourceIcons) {
        ResourceIconResponse response = new ResourceIconResponse();
        response.setResourceId(resourceIcon.getResourceUuid());
        response.setResourceType(resourceIcon.getResourceType());
        response.setImage(resourceIcon.getIcon());
        response.setObjectName(ApiConstants.RESOURCE_ICON);
        iconResponses.add(response);
    }
    return iconResponses;
}
Also used : ResourceIconResponse(org.apache.cloudstack.api.response.ResourceIconResponse) ArrayList(java.util.ArrayList) ResourceIconVO(com.cloud.resource.icon.ResourceIconVO)

Example 2 with ResourceIconVO

use of com.cloud.resource.icon.ResourceIconVO in project cloudstack by apache.

the class DataCenterJoinDaoImpl method newDataCenterResponse.

@Override
public ZoneResponse newDataCenterResponse(ResponseView view, DataCenterJoinVO dataCenter, Boolean showCapacities, Boolean showResourceImage) {
    ZoneResponse zoneResponse = new ZoneResponse();
    zoneResponse.setId(dataCenter.getUuid());
    zoneResponse.setName(dataCenter.getName());
    zoneResponse.setSecurityGroupsEnabled(ApiDBUtils.isSecurityGroupEnabledInZone(dataCenter.getId()));
    zoneResponse.setLocalStorageEnabled(dataCenter.isLocalStorageEnabled());
    if ((dataCenter.getDescription() != null) && !dataCenter.getDescription().equalsIgnoreCase("null")) {
        zoneResponse.setDescription(dataCenter.getDescription());
    }
    if (view == ResponseView.Full) {
        zoneResponse.setDns1(dataCenter.getDns1());
        zoneResponse.setDns2(dataCenter.getDns2());
        zoneResponse.setIp6Dns1(dataCenter.getIp6Dns1());
        zoneResponse.setIp6Dns2(dataCenter.getIp6Dns2());
        zoneResponse.setInternalDns1(dataCenter.getInternalDns1());
        zoneResponse.setInternalDns2(dataCenter.getInternalDns2());
        // FIXME zoneResponse.setVlan(dataCenter.get.getVnet());
        zoneResponse.setGuestCidrAddress(dataCenter.getGuestNetworkCidr());
        if (showCapacities != null && showCapacities) {
            zoneResponse.setCapacitites(ApiResponseHelper.getDataCenterCapacityResponse(dataCenter.getId()));
        }
    }
    // set network domain info
    zoneResponse.setDomain(dataCenter.getDomain());
    // set domain info
    zoneResponse.setDomainId(dataCenter.getDomainUuid());
    zoneResponse.setDomainName(dataCenter.getDomainName());
    zoneResponse.setNetworkType(dataCenter.getNetworkType().toString());
    zoneResponse.setAllocationState(dataCenter.getAllocationState().toString());
    zoneResponse.setZoneToken(dataCenter.getZoneToken());
    zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider());
    // update tag information
    List<ResourceTagJoinVO> resourceTags = ApiDBUtils.listResourceTagViewByResourceUUID(dataCenter.getUuid(), ResourceObjectType.Zone);
    for (ResourceTagJoinVO resourceTag : resourceTags) {
        ResourceTagResponse tagResponse = ApiDBUtils.newResourceTagResponse(resourceTag, false);
        zoneResponse.addTag(tagResponse);
    }
    if (showResourceImage) {
        ResourceIconVO resourceIcon = ApiDBUtils.getResourceIconByResourceUUID(dataCenter.getUuid(), ResourceObjectType.Zone);
        if (resourceIcon != null) {
            ResourceIconResponse iconResponse = ApiDBUtils.newResourceIconResponse(resourceIcon);
            zoneResponse.setResourceIconResponse(iconResponse);
        }
    }
    zoneResponse.setResourceDetails(ApiDBUtils.getResourceDetails(dataCenter.getId(), ResourceObjectType.Zone));
    zoneResponse.setHasAnnotation(annotationDao.hasAnnotations(dataCenter.getUuid(), AnnotationService.EntityType.ZONE.name(), _accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
    zoneResponse.setObjectName("zone");
    return zoneResponse;
}
Also used : ZoneResponse(org.apache.cloudstack.api.response.ZoneResponse) ResourceIconResponse(org.apache.cloudstack.api.response.ResourceIconResponse) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO) ResourceIconVO(com.cloud.resource.icon.ResourceIconVO)

Example 3 with ResourceIconVO

use of com.cloud.resource.icon.ResourceIconVO in project cloudstack by apache.

the class ResourceIconManagerImpl method uploadResourceIcon.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_RESOURCE_ICON_UPLOAD, eventDescription = "uploading resource icon")
public boolean uploadResourceIcon(List<String> resourceIds, ResourceTag.ResourceObjectType resourceType, String base64Image) {
    final Account caller = CallContext.current().getCallingAccount();
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            for (String resourceId : resourceIds) {
                if (!resourceType.resourceIconSupport()) {
                    throw new InvalidParameterValueException("The resource type " + resourceType + " doesn't support resource icons");
                }
                if (base64Image == null) {
                    throw new InvalidParameterValueException("No icon provided to be uploaded for resource: " + resourceId);
                }
                long id = resourceManagerUtil.getResourceId(resourceId, resourceType);
                String resourceUuid = resourceManagerUtil.getUuid(resourceId, resourceType);
                ResourceIconVO existingResourceIcon = resourceIconDao.findByResourceUuid(resourceUuid, resourceType);
                ResourceIconVO resourceIcon = null;
                Pair<Long, Long> accountDomainPair = getAccountDomain(id, resourceType);
                Long domainId = accountDomainPair.second();
                Long accountId = accountDomainPair.first();
                resourceManagerUtil.checkResourceAccessible(accountId, domainId, String.format("Account ' %s ' doesn't have permissions to upload icon for resource ' %s ", caller, id));
                if (existingResourceIcon == null) {
                    resourceIcon = new ResourceIconVO(id, resourceType, resourceUuid, base64Image);
                } else {
                    resourceIcon = existingResourceIcon;
                    resourceIcon.setIcon(base64Image);
                    resourceIcon.setUpdated(new Date());
                }
                try {
                    resourceIconDao.persist(resourceIcon);
                } catch (EntityExistsException e) {
                    throw new CloudRuntimeException(String.format("Image already uploaded for resource type: %s with id %s", resourceType.toString(), resourceId), e);
                }
            }
        }
    });
    return true;
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) Date(java.util.Date) EntityExistsException(javax.persistence.EntityExistsException) ResourceIconVO(com.cloud.resource.icon.ResourceIconVO) Pair(com.cloud.utils.Pair) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Aggregations

ResourceIconVO (com.cloud.resource.icon.ResourceIconVO)3 ResourceIconResponse (org.apache.cloudstack.api.response.ResourceIconResponse)2 ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)1 ActionEvent (com.cloud.event.ActionEvent)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 Account (com.cloud.user.Account)1 Pair (com.cloud.utils.Pair)1 DB (com.cloud.utils.db.DB)1 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)1 TransactionStatus (com.cloud.utils.db.TransactionStatus)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 EntityExistsException (javax.persistence.EntityExistsException)1 ResourceTagResponse (org.apache.cloudstack.api.response.ResourceTagResponse)1 ZoneResponse (org.apache.cloudstack.api.response.ZoneResponse)1