Search in sources :

Example 6 with ImageStoreVO

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

the class ManagementServerImpl method listCapabilities.

@Override
public Map<String, Object> listCapabilities(final ListCapabilitiesCmd cmd) {
    final Map<String, Object> capabilities = new HashMap<>();
    final Account caller = getCaller();
    final boolean elasticLoadBalancerEnabled;
    final boolean KVMSnapshotEnabled;
    String supportELB = "false";
    final long diskOffMinSize = VolumeOrchestrationService.CustomDiskOfferingMinSize.value();
    final long diskOffMaxSize = VolumeOrchestrationService.CustomDiskOfferingMaxSize.value();
    KVMSnapshotEnabled = Boolean.parseBoolean(_configDao.getValue("KVM.snapshot.enabled"));
    final boolean userPublicTemplateEnabled = TemplateManager.AllowPublicUserTemplates.valueIn(caller.getId());
    // add some parameters UI needs to handle API throttling
    final boolean apiLimitEnabled = Boolean.parseBoolean(_configDao.getValue(Config.ApiLimitEnabled.key()));
    final Integer apiLimitInterval = Integer.valueOf(_configDao.getValue(Config.ApiLimitInterval.key()));
    final Integer apiLimitMax = Integer.valueOf(_configDao.getValue(Config.ApiLimitMax.key()));
    final boolean allowUserViewDestroyedVM = QueryService.AllowUserViewDestroyedVM.valueIn(caller.getId()) | _accountService.isAdmin(caller.getId());
    final boolean allowUserExpungeRecoverVM = UserVmManager.AllowUserExpungeRecoverVm.valueIn(caller.getId()) | _accountService.isAdmin(caller.getId());
    final boolean XenServerDeploymentsEnabled = xenserverDeploymentsEnabled.value();
    final boolean KvmDeploymentsEnabled = kvmDeploymentsEnabled.value();
    // check if region-wide secondary storage is used
    boolean regionSecondaryEnabled = false;
    final List<ImageStoreVO> imgStores = _imgStoreDao.findRegionImageStores();
    if (imgStores != null && imgStores.size() > 0) {
        regionSecondaryEnabled = true;
    }
    capabilities.put("userPublicTemplateEnabled", userPublicTemplateEnabled);
    capabilities.put("cloudStackVersion", getVersion());
    capabilities.put("supportELB", supportELB);
    capabilities.put("projectInviteRequired", _projectMgr.projectInviteRequired());
    capabilities.put("allowusercreateprojects", _projectMgr.allowUserToCreateProject());
    capabilities.put("customDiskOffMinSize", diskOffMinSize);
    capabilities.put("customDiskOffMaxSize", diskOffMaxSize);
    capabilities.put("regionSecondaryEnabled", regionSecondaryEnabled);
    capabilities.put("KVMSnapshotEnabled", KVMSnapshotEnabled);
    capabilities.put("allowUserViewDestroyedVM", allowUserViewDestroyedVM);
    capabilities.put("allowUserExpungeRecoverVM", allowUserExpungeRecoverVM);
    capabilities.put("xenserverDeploymentsEnabled", XenServerDeploymentsEnabled);
    capabilities.put("KVMDeploymentsEnabled", KvmDeploymentsEnabled);
    if (apiLimitEnabled) {
        capabilities.put("apiLimitInterval", apiLimitInterval);
        capabilities.put("apiLimitMax", apiLimitMax);
    }
    return capabilities;
}
Also used : Account(com.cloud.user.Account) HashMap(java.util.HashMap) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 7 with ImageStoreVO

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

the class StorageManagerImpl method deleteImageStore.

@Override
public boolean deleteImageStore(final DeleteImageStoreCmd cmd) {
    final long storeId = cmd.getId();
    // Verify that image store exists
    final ImageStoreVO store = _imageStoreDao.findById(storeId);
    if (store == null) {
        throw new InvalidParameterValueException("Image store with id " + storeId + " doesn't exist");
    }
    _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), store.getDataCenterId());
    // Verify that there are no live snapshot, template, volume on the image
    // store to be deleted
    final List<SnapshotDataStoreVO> snapshots = _snapshotStoreDao.listByStoreId(storeId, DataStoreRole.Image);
    if (snapshots != null && snapshots.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete image store with active snapshots backup!");
    }
    final List<VolumeDataStoreVO> volumes = _volumeStoreDao.listByStoreId(storeId);
    if (volumes != null && volumes.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete image store with active volumes backup!");
    }
    // search if there are user templates stored on this image store, excluding system, builtin templates
    final List<TemplateJoinVO> templates = _templateViewDao.listActiveTemplates(storeId);
    if (templates != null && templates.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete image store with active templates backup!");
    }
    // ready to delete
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            // first delete from image_store_details table, we need to do that since
            // we are not actually deleting record from main
            // image_data_store table, so delete cascade will not work
            _imageStoreDetailsDao.deleteDetails(storeId);
            _snapshotStoreDao.deletePrimaryRecordsForStore(storeId, DataStoreRole.Image);
            _volumeStoreDao.deletePrimaryRecordsForStore(storeId);
            _templateStoreDao.deletePrimaryRecordsForStore(storeId);
            _imageStoreDao.remove(storeId);
        }
    });
    return true;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 8 with ImageStoreVO

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

the class StorageManagerImpl method deleteSecondaryStagingStore.

@Override
public boolean deleteSecondaryStagingStore(final DeleteSecondaryStagingStoreCmd cmd) {
    final long storeId = cmd.getId();
    // Verify that cache store exists
    final ImageStoreVO store = _imageStoreDao.findById(storeId);
    if (store == null) {
        throw new InvalidParameterValueException("Cache store with id " + storeId + " doesn't exist");
    }
    _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), store.getDataCenterId());
    // Verify that there are no live snapshot, template, volume on the cache
    // store that is currently referenced
    final List<SnapshotDataStoreVO> snapshots = _snapshotStoreDao.listActiveOnCache(storeId);
    if (snapshots != null && snapshots.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete cache store with staging snapshots currently in use!");
    }
    final List<VolumeDataStoreVO> volumes = _volumeStoreDao.listActiveOnCache(storeId);
    if (volumes != null && volumes.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete cache store with staging volumes currently in use!");
    }
    final List<TemplateDataStoreVO> templates = _templateStoreDao.listActiveOnCache(storeId);
    if (templates != null && templates.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete cache store with staging templates currently in use!");
    }
    // ready to delete
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            // first delete from image_store_details table, we need to do that since
            // we are not actually deleting record from main
            // image_data_store table, so delete cascade will not work
            _imageStoreDetailsDao.deleteDetails(storeId);
            _snapshotStoreDao.deletePrimaryRecordsForStore(storeId, DataStoreRole.ImageCache);
            _volumeStoreDao.deletePrimaryRecordsForStore(storeId);
            _templateStoreDao.deletePrimaryRecordsForStore(storeId);
            _imageStoreDao.remove(storeId);
        }
    });
    return true;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO)

Example 9 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 GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException {
    // check if the caller can operate with the template owner
    final Account caller = CallContext.current().getCallingAccount();
    final Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
    _accountMgr.checkAccess(caller, null, true, owner);
    final boolean isRouting = (cmd.isRoutingType() == null) ? false : cmd.isRoutingType();
    Long zoneId = cmd.getZoneId();
    // ignore passed zoneId if we are using region wide image store
    final List<ImageStoreVO> stores = _imgStoreDao.findRegionImageStores();
    if (stores != null && stores.size() > 0) {
        zoneId = -1L;
    }
    return prepare(false, CallContext.current().getCallingUserId(), cmd.getName(), cmd.getDisplayText(), cmd.getBits(), cmd.isPasswordEnabled(), cmd.getRequiresHvm(), null, cmd.isPublic(), cmd.isFeatured(), cmd.isExtractable(), cmd.getFormat(), cmd.getOsTypeId(), zoneId, HypervisorType.getType(cmd.getHypervisor()), cmd.getChecksum(), true, cmd.getTemplateTag(), owner, cmd.getDetails(), cmd.isSshKeyEnabled(), null, cmd.isDynamicallyScalable(), isRouting ? TemplateType.ROUTING : TemplateType.USER);
}
Also used : Account(com.cloud.user.Account) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 10 with ImageStoreVO

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

the class TemplateManagerImplTest method testCreatePrivateTemplateRecordForRegionStore.

@Test
public void testCreatePrivateTemplateRecordForRegionStore() throws ResourceAllocationException {
    final CreateTemplateCmd mockCreateCmd = mock(CreateTemplateCmd.class);
    when(mockCreateCmd.getTemplateName()).thenReturn("test");
    when(mockCreateCmd.getTemplateTag()).thenReturn(null);
    when(mockCreateCmd.getBits()).thenReturn(64);
    when(mockCreateCmd.getRequiresHvm()).thenReturn(true);
    when(mockCreateCmd.isPasswordEnabled()).thenReturn(false);
    when(mockCreateCmd.isPublic()).thenReturn(false);
    when(mockCreateCmd.isFeatured()).thenReturn(false);
    when(mockCreateCmd.isDynamicallyScalable()).thenReturn(false);
    when(mockCreateCmd.getVolumeId()).thenReturn(null);
    when(mockCreateCmd.getSnapshotId()).thenReturn(1L);
    when(mockCreateCmd.getOsTypeId()).thenReturn(1L);
    when(mockCreateCmd.getEventDescription()).thenReturn("test");
    when(mockCreateCmd.getDetails()).thenReturn(null);
    final Account mockTemplateOwner = mock(Account.class);
    final SnapshotVO mockSnapshot = mock(SnapshotVO.class);
    when(snapshotDao.findById(anyLong())).thenReturn(mockSnapshot);
    when(mockSnapshot.getVolumeId()).thenReturn(1L);
    when(mockSnapshot.getState()).thenReturn(Snapshot.State.BackedUp);
    when(mockSnapshot.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.XenServer);
    doNothing().when(resourceLimitMgr).checkResourceLimit(any(Account.class), eq(Resource.ResourceType.template));
    doNothing().when(resourceLimitMgr).checkResourceLimit(any(Account.class), eq(Resource.ResourceType.secondary_storage), anyLong());
    final GuestOSVO mockGuestOS = mock(GuestOSVO.class);
    when(guestOSDao.findById(anyLong())).thenReturn(mockGuestOS);
    when(tmpltDao.getNextInSequence(eq(Long.class), eq("id"))).thenReturn(1L);
    final List<ImageStoreVO> mockRegionStores = new ArrayList<>();
    final ImageStoreVO mockRegionStore = mock(ImageStoreVO.class);
    mockRegionStores.add(mockRegionStore);
    when(imgStoreDao.findRegionImageStores()).thenReturn(mockRegionStores);
    when(tmpltDao.persist(any(VMTemplateVO.class))).thenAnswer(new Answer<VMTemplateVO>() {

        @Override
        public VMTemplateVO answer(final InvocationOnMock invocationOnMock) throws Throwable {
            final Object[] args = invocationOnMock.getArguments();
            return (VMTemplateVO) args[0];
        }
    });
    final VMTemplateVO template = templateManager.createPrivateTemplateRecord(mockCreateCmd, mockTemplateOwner);
    assertTrue("Template in a region store should have cross zones set", template.isCrossZones());
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) VMTemplateVO(com.cloud.storage.VMTemplateVO) GuestOSVO(com.cloud.storage.GuestOSVO) SnapshotVO(com.cloud.storage.SnapshotVO) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyLong(org.mockito.Matchers.anyLong) CreateTemplateCmd(com.cloud.api.command.user.template.CreateTemplateCmd) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO) Test(org.junit.Test)

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