当前位置: 首页>>代码示例>>Java>>正文


Java ImageFormat.valueOf方法代码示例

本文整理汇总了Java中com.cloud.storage.Storage.ImageFormat.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Java ImageFormat.valueOf方法的具体用法?Java ImageFormat.valueOf怎么用?Java ImageFormat.valueOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.cloud.storage.Storage.ImageFormat的用法示例。


在下文中一共展示了ImageFormat.valueOf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: listPermittedTemplates

import com.cloud.storage.Storage.ImageFormat; //导入方法依赖的package包/类
@Override
public List<VMTemplateVO> listPermittedTemplates(final long accountId) {
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    final List<VMTemplateVO> permittedTemplates = new ArrayList<>();
    PreparedStatement pstmt = null;
    try {
        final String sql = LIST_PERMITTED_TEMPLATES;
        pstmt = txn.prepareAutoCloseStatement(sql);
        pstmt.setLong(1, accountId);
        final ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            final long id = rs.getLong(1);
            final String uniqueName = rs.getString(2);
            final String name = rs.getString(3);
            final boolean isPublic = rs.getBoolean(4);
            final String value = rs.getString(5);
            final ImageFormat format = ImageFormat.valueOf(value);
            final String tmpltType = rs.getString(6);
            final boolean requiresHVM = rs.getBoolean(7);
            final int bits = rs.getInt(8);
            final String url = rs.getString(9);
            final String createdTS = rs.getString(10);
            final long templateAccountId = rs.getLong(11);
            final String checksum = rs.getString(12);
            final String displayText = rs.getString(13);
            final boolean enablePassword = rs.getBoolean(14);
            final long guestOSId = rs.getLong(15);
            final boolean featured = rs.getBoolean(16);
            Date createdDate = null;

            if (createdTS != null) {
                createdDate = DateUtil.parseDateString(s_gmtTimeZone, createdTS);
            }

            if (isPublic) {
                continue; // if it's public already, skip adding it to
                // permitted templates as this for private
                // templates only
            }
            final VMTemplateVO template =
                    new VMTemplateVO(id, uniqueName, name, format, isPublic, featured, TemplateType.valueOf(tmpltType), url, createdDate, requiresHVM, bits,
                            templateAccountId, checksum, displayText, enablePassword, guestOSId, true, null);
            permittedTemplates.add(template);
        }
    } catch (final Exception e) {
        s_logger.warn("Error listing permitted templates", e);
    }
    return permittedTemplates;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:50,代码来源:LaunchPermissionDaoImpl.java

示例2: validateVolume

import com.cloud.storage.Storage.ImageFormat; //导入方法依赖的package包/类
private boolean validateVolume(final Account caller, final long ownerId, final Long zoneId, final String volumeName, final String url,
                               final String format, final Long diskOfferingId) throws ResourceAllocationException {

    // permission check
    final Account volumeOwner = _accountMgr.getActiveAccountById(ownerId);
    _accountMgr.checkAccess(caller, null, true, volumeOwner);

    // Check that the resource limit for volumes won't be exceeded
    _resourceLimitMgr.checkResourceLimit(volumeOwner, ResourceType.volume);

    // Verify that zone exists
    final DataCenterVO zone = _dcDao.findById(zoneId);
    if (zone == null) {
        throw new InvalidParameterValueException("Unable to find zone by id " + zoneId);
    }

    // Check if zone is disabled
    if (AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getId())) {
        throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId);
    }

    //validating the url only when url is not null. url can be null incase of form based post upload
    if (url != null) {
        if (url.toLowerCase().contains("file://")) {
            throw new InvalidParameterValueException("File:// type urls are currently unsupported");
        }
        UriUtils.validateUrl(format, url);
        // check URL existence
        UriUtils.checkUrlExistence(url);
        // Check that the resource limit for secondary storage won't be exceeded
        _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(ownerId), ResourceType.secondary_storage, UriUtils.getRemoteSize(url));
    } else {
        _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(ownerId), ResourceType.secondary_storage);
    }

    try {
        ImageFormat.valueOf(format.toUpperCase());
    } catch (final IllegalArgumentException e) {
        s_logger.debug("ImageFormat IllegalArgumentException: " + e.getMessage());
        throw new IllegalArgumentException("Image format: " + format + " is incorrect. Supported formats are " + EnumUtils.listValues(ImageFormat.values()));
    }

    // Check that the the disk offering specified is valid
    if (diskOfferingId != null) {
        final DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
        if (diskOffering == null || diskOffering.getRemoved() != null
                || !DiskOfferingVO.Type.Disk.equals(diskOffering.getType())) {
            throw new InvalidParameterValueException("Please specify a valid disk offering.");
        }
        if (!diskOffering.isCustomized()) {
            throw new InvalidParameterValueException("Please specify a custom sized disk offering.");
        }

        if (diskOffering.getDomainId() == null) {
            // do nothing as offering is public
        } else {
            _configMgr.checkDiskOfferingAccess(volumeOwner, diskOffering);
        }
    }

    return false;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:63,代码来源:VolumeApiServiceImpl.java

示例3: downloadVolumeToStorage

import com.cloud.storage.Storage.ImageFormat; //导入方法依赖的package包/类
@Override
public void downloadVolumeToStorage(final DataObject volume, final AsyncCompletionCallback<DownloadAnswer> callback) {
    boolean downloadJobExists = false;
    VolumeDataStoreVO volumeHost = null;
    final DataStore store = volume.getDataStore();
    final VolumeInfo volInfo = (VolumeInfo) volume;
    final RegisterVolumePayload payload = (RegisterVolumePayload) volInfo.getpayload();
    final String url = payload.getUrl();
    final String checkSum = payload.getChecksum();
    final ImageFormat format = ImageFormat.valueOf(payload.getFormat());

    volumeHost = _volumeStoreDao.findByStoreVolume(store.getId(), volume.getId());
    if (volumeHost == null) {
        volumeHost = new VolumeDataStoreVO(store.getId(), volume.getId(), new Date(), 0, Status.NOT_DOWNLOADED, null, null, "jobid0000", null, url, checkSum);
        _volumeStoreDao.persist(volumeHost);
    } else if ((volumeHost.getJobId() != null) && (volumeHost.getJobId().length() > 2)) {
        downloadJobExists = true;
    } else {
        // persit url and checksum
        volumeHost.setDownloadUrl(url);
        volumeHost.setChecksum(checkSum);
        _volumeStoreDao.update(volumeHost.getId(), volumeHost);
    }

    final Long maxVolumeSizeInBytes = getMaxVolumeSizeInBytes();
    if (volumeHost != null) {
        start();
        final Volume vol = _volumeDao.findById(volume.getId());
        DownloadCommand dcmd = new DownloadCommand((VolumeObjectTO) (volume.getTO()), maxVolumeSizeInBytes, checkSum, url, format);
        dcmd.setProxy(getHttpProxy());
        if (downloadJobExists) {
            dcmd = new DownloadProgressCommand(dcmd, volumeHost.getJobId(), RequestType.GET_OR_RESTART);
            dcmd.setResourceType(ResourceType.VOLUME);
        }

        final EndPoint ep = _epSelector.select(volume);
        if (ep == null) {
            s_logger.warn("There is no secondary storage VM for image store " + store.getName());
            return;
        }
        final DownloadListener dl = new DownloadListener(ep, store, volume, _timer, this, dcmd, callback);
        ComponentContext.inject(dl); // auto-wired those injected fields in DownloadListener

        if (downloadJobExists) {
            dl.setCurrState(volumeHost.getDownloadState());
        }

        try {
            ep.sendMessageAsync(dcmd, new UploadListener.Callback(ep.getId(), dl));
        } catch (final Exception e) {
            s_logger.warn("Unable to start /resume download of volume " + volume.getId() + " to " + store.getName(), e);
            dl.setDisconnected();
            dl.scheduleStatusCheck(RequestType.GET_OR_RESTART);
        }
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:57,代码来源:DownloadMonitorImpl.java


注:本文中的com.cloud.storage.Storage.ImageFormat.valueOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。