Search in sources :

Example 61 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class CloudStackPrimaryDataStoreDriverImpl method createAsync.

@Override
public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
    String errMsg = null;
    Answer answer = null;
    CreateCmdResult result = new CreateCmdResult(null, null);
    if (data.getType() == DataObjectType.VOLUME) {
        try {
            answer = createVolume((VolumeInfo) data);
            if ((answer == null) || (!answer.getResult())) {
                result.setSuccess(false);
                if (answer != null) {
                    result.setResult(answer.getDetails());
                }
            } else {
                result.setAnswer(answer);
            }
        } catch (StorageUnavailableException e) {
            s_logger.debug("failed to create volume", e);
            errMsg = e.toString();
        } catch (Exception e) {
            s_logger.debug("failed to create volume", e);
            errMsg = e.toString();
        }
    }
    if (errMsg != null) {
        result.setResult(errMsg);
    }
    callback.complete(result);
}
Also used : ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) StorageUnavailableException(com.cloud.exception.StorageUnavailableException)

Example 62 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class ElastistorPrimaryDataStoreDriver method createAsync.

@Override
public void createAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CreateCmdResult> callback) {
    String iqn = null;
    String errMsg = null;
    CreateCmdResult result = new CreateCmdResult(iqn, new Answer(null, errMsg == null, errMsg));
    if (dataObject.getType() == DataObjectType.VOLUME) {
        VolumeInfo volumeInfo = (VolumeInfo) dataObject;
        long storagePoolId = dataStore.getId();
        String volumeName = volumeInfo.getName();
        Long Iops = volumeInfo.getMaxIops();
        // quota size of the cloudbyte volume will be increased with the given HypervisorSnapshotReserve
        Long quotaSize = getDataObjectSizeIncludingHypervisorSnapshotReserve(volumeInfo, _storagePoolDao.findById(storagePoolId));
        StoragePoolVO storagePool = _storagePoolDao.findById(dataStore.getId());
        VolumeVO volume = _volumeDao.findById(volumeInfo.getId());
        // calling super(default) that creates a vdi(disk) only.
        if (!(storagePool.isManaged())) {
            super.createAsync(dataStore, dataObject, callback);
            // update the volume property
            volume.setPoolType(storagePool.getPoolType());
            _volumeDao.update(volume.getId(), volume);
            return;
        }
        DiskOfferingVO diskOffering = _diskOfferingDao.findById(volumeInfo.getDiskOfferingId());
        long capacityIops = storagePool.getCapacityIops();
        capacityIops = capacityIops - Iops;
        if (capacityIops < 0) {
            throw new CloudRuntimeException("IOPS not available. [pool:" + storagePool.getName() + "] [availiops:" + capacityIops + "] [requirediops:" + Iops + "]");
        }
        String protocoltype = null;
        StoragePoolVO dataStoreVO = _storagePoolDao.findById(storagePoolId);
        String desc = diskOffering.getDisplayText();
        if (desc.toLowerCase().contains("iscsi")) {
            protocoltype = "iscsi";
        } else if (dataStoreVO.getPoolType().equals(StoragePoolType.NetworkFilesystem) || dataStoreVO.getPoolType().equals(StoragePoolType.Filesystem)) {
            protocoltype = "nfs";
        } else {
            protocoltype = "iscsi";
        }
        FileSystem esvolume = null;
        try {
            esvolume = ElastistorUtil.createElastistorVolume(volumeName, dataStoreVO.getUuid(), quotaSize, Iops, protocoltype, volumeName);
        } catch (Throwable e) {
            s_logger.error(e.toString(), e);
            result.setResult(e.toString());
            callback.complete(result);
            throw new CloudRuntimeException(e.getMessage());
        }
        if (esvolume.getNfsenabled().equalsIgnoreCase("true")) {
            volume.set_iScsiName(esvolume.getPath());
            volume.setPoolType(StoragePoolType.NetworkFilesystem);
        } else {
            iqn = esvolume.getIqn();
            String modifiediqn = "/" + iqn + "/0";
            volume.set_iScsiName(modifiediqn);
            volume.setPoolType(StoragePoolType.IscsiLUN);
        }
        volume.setFolder(String.valueOf(esvolume.getUuid()));
        volume.setPoolId(storagePoolId);
        volume.setUuid(esvolume.getUuid());
        volume.setPath(null);
        _volumeDao.update(volume.getId(), volume);
        // create new volume details for the volume
        //updateVolumeDetails(volume, esvolume);
        long capacityBytes = storagePool.getCapacityBytes();
        long usedBytes = storagePool.getUsedBytes();
        Long inbytes = volume.getSize();
        usedBytes += inbytes;
        storagePool.setCapacityIops(capacityIops);
        storagePool.setUsedBytes(usedBytes > capacityBytes ? capacityBytes : usedBytes);
        _storagePoolDao.update(storagePoolId, storagePool);
        s_logger.info("Elastistor volume creation complete.");
    } else {
        errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to createAsync";
        s_logger.error(errMsg);
    }
    result.setResult(errMsg);
    callback.complete(result);
}
Also used : CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) Answer(com.cloud.agent.api.Answer) VolumeVO(com.cloud.storage.VolumeVO) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) FileSystem(org.apache.cloudstack.storage.datastore.util.ElastistorUtil.FileSystem) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)

Example 63 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class ElastistorPrimaryDataStoreDriver method getDataObjectSizeIncludingHypervisorSnapshotReserve.

@Override
public long getDataObjectSizeIncludingHypervisorSnapshotReserve(DataObject dataObject, StoragePool pool) {
    VolumeInfo volume = (VolumeInfo) dataObject;
    long volumeSize = volume.getSize();
    Integer hypervisorSnapshotReserve = volume.getHypervisorSnapshotReserve();
    if (hypervisorSnapshotReserve != null) {
        if (hypervisorSnapshotReserve < 25) {
            hypervisorSnapshotReserve = 25;
        }
        volumeSize += volumeSize * (hypervisorSnapshotReserve / 100f);
    }
    return volumeSize;
}
Also used : VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Example 64 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class VolumeApiServiceImplTest method testResourceLimitCheckForUploadedVolume.

/**
     * The resource limit check for primary storage should not be skipped for Volume in 'Uploaded' state.
     * @throws NoSuchFieldException
     * @throws IllegalAccessException
     * @throws ResourceAllocationException
     */
@Test
public void testResourceLimitCheckForUploadedVolume() throws NoSuchFieldException, IllegalAccessException, ResourceAllocationException {
    doThrow(new ResourceAllocationException("primary storage resource limit check failed", Resource.ResourceType.primary_storage)).when(_svc._resourceLimitMgr).checkResourceLimit(any(AccountVO.class), any(Resource.ResourceType.class), any(Long.class));
    UserVmVO vm = Mockito.mock(UserVmVO.class);
    VolumeInfo volumeToAttach = Mockito.mock(VolumeInfo.class);
    when(volumeToAttach.getId()).thenReturn(9L);
    when(volumeToAttach.getDataCenterId()).thenReturn(34L);
    when(volumeToAttach.getVolumeType()).thenReturn(Volume.Type.DATADISK);
    when(volumeToAttach.getInstanceId()).thenReturn(null);
    when(_userVmDao.findById(anyLong())).thenReturn(vm);
    when(vm.getType()).thenReturn(VirtualMachine.Type.User);
    when(vm.getState()).thenReturn(State.Running);
    when(vm.getDataCenterId()).thenReturn(34L);
    when(_svc._volsDao.findByInstanceAndType(anyLong(), any(Volume.Type.class))).thenReturn(new ArrayList(10));
    when(_svc.volFactory.getVolume(9L)).thenReturn(volumeToAttach);
    when(volumeToAttach.getState()).thenReturn(Volume.State.Uploaded);
    DataCenterVO zoneWithDisabledLocalStorage = Mockito.mock(DataCenterVO.class);
    when(_svc._dcDao.findById(anyLong())).thenReturn(zoneWithDisabledLocalStorage);
    when(zoneWithDisabledLocalStorage.isLocalStorageEnabled()).thenReturn(true);
    try {
        _svc.attachVolumeToVM(2L, 9L, null);
    } catch (InvalidParameterValueException e) {
        Assert.assertEquals(e.getMessage(), ("primary storage resource limit check failed"));
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) UserVmVO(com.cloud.vm.UserVmVO) AccessType(org.apache.cloudstack.acl.SecurityChecker.AccessType) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Matchers.anyLong(org.mockito.Matchers.anyLong) ArrayList(java.util.ArrayList) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 65 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class VolumeApiServiceImpl method uploadVolume.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_UPLOAD, eventDescription = "uploading volume for post upload", async = true)
public GetUploadParamsResponse uploadVolume(final GetUploadParamsForVolumeCmd cmd) throws ResourceAllocationException, MalformedURLException {
    Account caller = CallContext.current().getCallingAccount();
    long ownerId = cmd.getEntityOwnerId();
    final Account owner = _entityMgr.findById(Account.class, ownerId);
    final Long zoneId = cmd.getZoneId();
    final String volumeName = cmd.getName();
    String format = cmd.getFormat();
    final Long diskOfferingId = cmd.getDiskOfferingId();
    String imageStoreUuid = cmd.getImageStoreUuid();
    final DataStore store = _tmpltMgr.getImageStore(imageStoreUuid, zoneId);
    validateVolume(caller, ownerId, zoneId, volumeName, null, format, diskOfferingId);
    return Transaction.execute(new TransactionCallbackWithException<GetUploadParamsResponse, MalformedURLException>() {

        @Override
        public GetUploadParamsResponse doInTransaction(TransactionStatus status) throws MalformedURLException {
            VolumeVO volume = persistVolume(owner, zoneId, volumeName, null, cmd.getFormat(), diskOfferingId, Volume.State.NotUploaded);
            VolumeInfo vol = volFactory.getVolume(volume.getId());
            RegisterVolumePayload payload = new RegisterVolumePayload(null, cmd.getChecksum(), cmd.getFormat());
            vol.addPayload(payload);
            Pair<EndPoint, DataObject> pair = volService.registerVolumeForPostUpload(vol, store);
            EndPoint ep = pair.first();
            DataObject dataObject = pair.second();
            GetUploadParamsResponse response = new GetUploadParamsResponse();
            String ssvmUrlDomain = _configDao.getValue(Config.SecStorageSecureCopyCert.key());
            String url = ImageStoreUtil.generatePostUploadUrl(ssvmUrlDomain, ep.getPublicAddr(), vol.getUuid());
            response.setPostURL(new URL(url));
            // set the post url, this is used in the monitoring thread to determine the SSVM
            VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(vol.getId());
            assert (volumeStore != null) : "sincle volume is registered, volumestore cannot be null at this stage";
            volumeStore.setExtractUrl(url);
            _volumeStoreDao.persist(volumeStore);
            response.setId(UUID.fromString(vol.getUuid()));
            int timeout = ImageStoreUploadMonitorImpl.getUploadOperationTimeout();
            DateTime currentDateTime = new DateTime(DateTimeZone.UTC);
            String expires = currentDateTime.plusMinutes(timeout).toString();
            response.setTimeout(expires);
            String key = _configDao.getValue(Config.SSVMPSK.key());
            /*
                  * encoded metadata using the post upload config key
                  */
            TemplateOrVolumePostUploadCommand command = new TemplateOrVolumePostUploadCommand(vol.getId(), vol.getUuid(), volumeStore.getInstallPath(), cmd.getChecksum(), vol.getType().toString(), vol.getName(), vol.getFormat().toString(), dataObject.getDataStore().getUri(), dataObject.getDataStore().getRole().toString());
            command.setLocalPath(volumeStore.getLocalDownloadPath());
            //using the existing max upload size configuration
            command.setMaxUploadSize(_configDao.getValue(Config.MaxUploadVolumeSize.key()));
            command.setDefaultMaxAccountSecondaryStorage(_configDao.getValue(Config.DefaultMaxAccountSecondaryStorage.key()));
            command.setAccountId(vol.getAccountId());
            Gson gson = new GsonBuilder().create();
            String metadata = EncryptionUtil.encodeData(gson.toJson(command), key);
            response.setMetadata(metadata);
            /*
                 * signature calculated on the url, expiry, metadata.
                 */
            response.setSignature(EncryptionUtil.generateSignature(metadata + url + expires, key));
            return response;
        }
    });
}
Also used : Account(com.cloud.user.Account) MalformedURLException(java.net.MalformedURLException) GsonBuilder(com.google.gson.GsonBuilder) TransactionStatus(com.cloud.utils.db.TransactionStatus) Gson(com.google.gson.Gson) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) GetUploadParamsResponse(org.apache.cloudstack.api.response.GetUploadParamsResponse) URL(java.net.URL) DateTime(org.joda.time.DateTime) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) TemplateOrVolumePostUploadCommand(org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommand) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) Pair(com.cloud.utils.Pair) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)112 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)51 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)50 VolumeVO (com.cloud.storage.VolumeVO)36 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)23 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)22 ExecutionException (java.util.concurrent.ExecutionException)22 VolumeApiResult (org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult)22 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)19 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)19 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)18 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)17 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)15 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)13 Map (java.util.Map)13 SnapshotVO (com.cloud.storage.SnapshotVO)12 DB (com.cloud.utils.db.DB)12 Test (org.testng.annotations.Test)12 Account (com.cloud.user.Account)11