Search in sources :

Example 11 with ImageStoreVO

use of com.cloud.storage.datastore.db.ImageStoreVO in project cosmic by MissionCriticalCloud.

the class ImageStoreProviderManagerImpl method listImageCacheStores.

@Override
public List<DataStore> listImageCacheStores(final Scope scope) {
    if (scope.getScopeType() != ScopeType.ZONE) {
        s_logger.debug("only support zone wide image cache stores");
        return null;
    }
    final List<ImageStoreVO> stores = dataStoreDao.findImageCacheByScope(new ZoneScope(scope.getScopeId()));
    final List<DataStore> imageStores = new ArrayList<>();
    for (final ImageStoreVO store : stores) {
        imageStores.add(getImageStore(store.getId()));
    }
    return imageStores;
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 12 with ImageStoreVO

use of com.cloud.storage.datastore.db.ImageStoreVO in project cosmic by MissionCriticalCloud.

the class ImageStoreProviderManagerImpl method getImageStore.

@Override
public ImageStoreEntity getImageStore(final long dataStoreId) {
    final ImageStoreVO dataStore = dataStoreDao.findById(dataStoreId);
    final String providerName = dataStore.getProviderName();
    final ImageStoreProvider provider = (ImageStoreProvider) providerManager.getDataStoreProvider(providerName);
    final ImageStoreEntity imgStore = ImageStoreImpl.getDataStore(dataStore, driverMaps.get(provider.getName()), provider);
    return imgStore;
}
Also used : ImageStoreProvider(com.cloud.engine.subsystem.api.storage.ImageStoreProvider) ImageStoreEntity(com.cloud.storage.image.datastore.ImageStoreEntity) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 13 with ImageStoreVO

use of com.cloud.storage.datastore.db.ImageStoreVO in project cosmic by MissionCriticalCloud.

the class ImageStoreProviderManagerImpl method listImageStores.

@Override
public List<DataStore> listImageStores() {
    final List<ImageStoreVO> stores = dataStoreDao.listImageStores();
    final List<DataStore> imageStores = new ArrayList<>();
    for (final ImageStoreVO store : stores) {
        imageStores.add(getImageStore(store.getId()));
    }
    return imageStores;
}
Also used : DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 14 with ImageStoreVO

use of com.cloud.storage.datastore.db.ImageStoreVO in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method discoverImageStore.

@Override
public ImageStore discoverImageStore(String name, final String url, String providerName, final Long zoneId, final Map details) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
    DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(providerName);
    if (storeProvider == null) {
        storeProvider = _dataStoreProviderMgr.getDefaultImageDataStoreProvider();
        if (storeProvider == null) {
            throw new InvalidParameterValueException("can't find image store provider: " + providerName);
        }
        // ignored passed provider name and use default image store provider name
        providerName = storeProvider.getName();
    }
    ScopeType scopeType = ScopeType.ZONE;
    if (zoneId == null) {
        scopeType = ScopeType.REGION;
    }
    if (name == null) {
        name = url;
    }
    final ImageStoreVO imageStore = _imageStoreDao.findByName(name);
    if (imageStore != null) {
        throw new InvalidParameterValueException("The image store with name " + name + " already exists, try creating with another name");
    }
    // check if scope is supported by store provider
    if (!((ImageStoreProvider) storeProvider).isScopeSupported(scopeType)) {
        throw new InvalidParameterValueException("Image store provider " + providerName + " does not support scope " + scopeType);
    }
    // check if we have already image stores from other different providers,
    // we currently are not supporting image stores from different
    // providers co-existing
    final List<ImageStoreVO> imageStores = _imageStoreDao.listImageStores();
    for (final ImageStoreVO store : imageStores) {
        if (!store.getProviderName().equalsIgnoreCase(providerName)) {
            throw new InvalidParameterValueException("You can only add new image stores from the same provider " + store.getProviderName() + " already added");
        }
    }
    if (zoneId != null) {
        // Check if the zone exists in the system
        final DataCenterVO zone = _dcDao.findById(zoneId);
        if (zone == null) {
            throw new InvalidParameterValueException("Can't find zone by id " + zoneId);
        }
        final Account account = CallContext.current().getCallingAccount();
        if (AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getId())) {
            final PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, Zone with specified id is currently disabled");
            ex.addProxyObject(zone.getUuid(), "dcId");
            throw ex;
        }
    }
    final Map<String, Object> params = new HashMap();
    params.put("zoneId", zoneId);
    params.put("url", url);
    params.put("name", name);
    params.put("details", details);
    params.put("scope", scopeType);
    params.put("providerName", storeProvider.getName());
    params.put("role", DataStoreRole.Image);
    final DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
    final DataStore store;
    try {
        store = lifeCycle.initialize(params);
    } catch (final Exception e) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Failed to add data store: " + e.getMessage(), e);
        }
        throw new CloudRuntimeException("Failed to add data store: " + e.getMessage(), e);
    }
    if (((ImageStoreProvider) storeProvider).needDownloadSysTemplate()) {
        // trigger system vm template download
        _imageSrv.downloadBootstrapSysTemplate(store);
    } else {
        // populate template_store_ref table
        _imageSrv.addSystemVMTemplatesToSecondary(store);
    }
    // associate builtin template with zones associated with this image store
    associateCrosszoneTemplatesToZone(zoneId);
    // duplicate cache store records to region wide storage
    if (scopeType == ScopeType.REGION) {
        duplicateCacheStoreRecordsToRegionStore(store.getId());
    }
    return (ImageStore) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Image);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) HashMap(java.util.HashMap) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) ImageStoreProvider(com.cloud.engine.subsystem.api.storage.ImageStoreProvider) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) StorageConflictException(com.cloud.exception.StorageConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) DataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 15 with ImageStoreVO

use of com.cloud.storage.datastore.db.ImageStoreVO in project cosmic by MissionCriticalCloud.

the class TemplateAdapterBase method prepare.

@Override
public TemplateProfile prepare(final boolean isIso, final long userId, final String name, final String displayText, Integer bits, Boolean passwordEnabled, Boolean requiresHVM, final String url, Boolean isPublic, Boolean featured, Boolean isExtractable, final String format, Long guestOSId, Long zoneId, final HypervisorType hypervisorType, final String chksum, Boolean bootable, final String templateTag, final Account templateOwner, Map details, Boolean sshkeyEnabled, final String imageStoreUuid, final Boolean isDynamicallyScalable, final TemplateType templateType) throws ResourceAllocationException {
    if (isPublic == null) {
        isPublic = Boolean.FALSE;
    }
    if (zoneId.longValue() == -1) {
        zoneId = null;
    }
    if (isIso) {
        if (bootable == null) {
            bootable = Boolean.TRUE;
        }
        final GuestOS noneGuestOs = ApiDBUtils.findGuestOSByDisplayName(ApiConstants.ISO_GUEST_OS_NONE);
        if ((guestOSId == null || guestOSId == noneGuestOs.getId()) && bootable == true) {
            throw new InvalidParameterValueException("Please pass a valid GuestOS Id");
        }
        if (bootable == false) {
            // Guest os id of None.
            guestOSId = noneGuestOs.getId();
        }
    } else {
        if (bits == null) {
            bits = Integer.valueOf(64);
        }
        if (passwordEnabled == null) {
            passwordEnabled = false;
        }
        if (requiresHVM == null) {
            requiresHVM = true;
        }
    }
    if (isExtractable == null) {
        isExtractable = Boolean.FALSE;
    }
    if (sshkeyEnabled == null) {
        sshkeyEnabled = Boolean.FALSE;
    }
    final boolean isAdmin = _accountMgr.isRootAdmin(templateOwner.getId());
    boolean isRegionStore = false;
    final List<ImageStoreVO> stores = _imgStoreDao.findRegionImageStores();
    if (stores != null && stores.size() > 0) {
        isRegionStore = true;
    }
    if (!isAdmin && zoneId == null && !isRegionStore) {
        // domain admin and user should also be able to register template on a region store
        throw new InvalidParameterValueException("Please specify a valid zone Id. Only admins can create templates in all zones.");
    }
    // check for the url format only when url is not null. url can be null incase of form based upload
    if (url != null && url.toLowerCase().contains("file://")) {
        throw new InvalidParameterValueException("File:// type urls are currently unsupported");
    }
    // check whether owner can create public templates
    final boolean allowPublicUserTemplates = TemplateManager.AllowPublicUserTemplates.valueIn(templateOwner.getId());
    if (!isAdmin && !allowPublicUserTemplates && isPublic) {
        throw new InvalidParameterValueException("Only private templates/ISO can be created.");
    }
    if (!isAdmin || featured == null) {
        featured = Boolean.FALSE;
    }
    final ImageFormat imgfmt;
    try {
        imgfmt = 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 resource limit for templates/ISOs won't be exceeded
    final UserVO user = _userDao.findById(userId);
    if (user == null) {
        throw new IllegalArgumentException("Unable to find user with id " + userId);
    }
    _resourceLimitMgr.checkResourceLimit(templateOwner, ResourceType.template);
    // If a zoneId is specified, make sure it is valid
    if (zoneId != null) {
        final DataCenterVO zone = _dcDao.findById(zoneId);
        if (zone == null) {
            throw new IllegalArgumentException("Please specify a valid zone.");
        }
        final Account caller = CallContext.current().getCallingAccount();
        if (AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getId())) {
            throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId);
        }
    }
    final List<VMTemplateVO> systemvmTmplts = _tmpltDao.listAllSystemVMTemplates();
    for (final VMTemplateVO template : systemvmTmplts) {
        if (template.getName().equalsIgnoreCase(name) || template.getDisplayText().equalsIgnoreCase(displayText)) {
            throw new IllegalArgumentException("Cannot use reserved names for templates");
        }
    }
    if (hypervisorType.equals(Hypervisor.HypervisorType.XenServer)) {
        if (details == null || !details.containsKey("hypervisortoolsversion") || details.get("hypervisortoolsversion") == null || ((String) details.get("hypervisortoolsversion")).equalsIgnoreCase("none")) {
            final String hpvs = _configDao.getValue(Config.XenServerPVdriverVersion.key());
            if (hpvs != null) {
                if (details == null) {
                    details = new HashMap<String, String>();
                }
                details.put("hypervisortoolsversion", hpvs);
            }
        }
    }
    final Long id = _tmpltDao.getNextInSequence(Long.class, "id");
    CallContext.current().setEventDetails("Id: " + id + " name: " + name);
    return new TemplateProfile(id, userId, name, displayText, bits, passwordEnabled, requiresHVM, url, isPublic, featured, isExtractable, imgfmt, guestOSId, zoneId, hypervisorType, templateOwner.getAccountName(), templateOwner.getDomainId(), templateOwner.getAccountId(), chksum, bootable, templateTag, details, sshkeyEnabled, null, isDynamicallyScalable, templateType);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) VMTemplateVO(com.cloud.storage.VMTemplateVO) ImageFormat(com.cloud.storage.Storage.ImageFormat) UserVO(com.cloud.user.UserVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) GuestOS(com.cloud.storage.GuestOS) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO) TemplateProfile(com.cloud.storage.TemplateProfile)

Aggregations

ImageStoreVO (com.cloud.storage.datastore.db.ImageStoreVO)19 Account (com.cloud.user.Account)8 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)7 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)4 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)3 VMTemplateVO (com.cloud.storage.VMTemplateVO)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 DataCenterVO (com.cloud.dc.DataCenterVO)2 ImageStoreProvider (com.cloud.engine.subsystem.api.storage.ImageStoreProvider)2 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)2 GuestOSVO (com.cloud.storage.GuestOSVO)2 SnapshotVO (com.cloud.storage.SnapshotVO)2 SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)2 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)2 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)2 TransactionStatus (com.cloud.utils.db.TransactionStatus)2 Answer (com.cloud.agent.api.Answer)1 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)1