Search in sources :

Example 46 with StoragePoolVO

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

the class VolumeOrchestrator method recreateVolume.

private Pair<VolumeVO, DataStore> recreateVolume(final VolumeVO vol, final VirtualMachineProfile vm, final DeployDestination dest) throws StorageUnavailableException {
    VolumeVO newVol;
    final boolean recreate = RecreatableSystemVmEnabled.value();
    DataStore destPool = null;
    if (recreate && (dest.getStorageForDisks() == null || dest.getStorageForDisks().get(vol) == null)) {
        destPool = dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
        s_logger.debug("existing pool: " + destPool.getId());
    } else {
        final StoragePool pool = dest.getStorageForDisks().get(vol);
        destPool = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
    }
    if (vol.getState() == Volume.State.Allocated || vol.getState() == Volume.State.Creating) {
        newVol = vol;
    } else {
        newVol = switchVolume(vol, vm);
        // changed
        if (dest.getStorageForDisks() != null && dest.getStorageForDisks().containsKey(vol)) {
            final StoragePool poolWithOldVol = dest.getStorageForDisks().get(vol);
            dest.getStorageForDisks().put(newVol, poolWithOldVol);
            dest.getStorageForDisks().remove(vol);
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Created new volume " + newVol + " for old volume " + vol);
        }
    }
    VolumeInfo volume = volFactory.getVolume(newVol.getId(), destPool);
    final Long templateId = newVol.getTemplateId();
    for (int i = 0; i < 2; i++) {
        // retry one more time in case of template reload is required for Vmware case
        AsyncCallFuture<VolumeService.VolumeApiResult> future = null;
        if (templateId == null) {
            final DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
            final HypervisorType hyperType = vm.getVirtualMachine().getHypervisorType();
            // update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
            volService.updateHypervisorSnapshotReserveForVolume(diskOffering, volume.getId(), hyperType);
            volume = volFactory.getVolume(newVol.getId(), destPool);
            future = volService.createVolumeAsync(volume, destPool);
        } else {
            final TemplateInfo templ = tmplFactory.getReadyTemplateOnImageStore(templateId, dest.getZone().getId());
            if (templ == null) {
                s_logger.debug("can't find ready template: " + templateId + " for data center " + dest.getZone().getId());
                throw new CloudRuntimeException("can't find ready template: " + templateId + " for data center " + dest.getZone().getId());
            }
            final PrimaryDataStore primaryDataStore = (PrimaryDataStore) destPool;
            if (primaryDataStore.isManaged()) {
                final DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
                final HypervisorType hyperType = vm.getVirtualMachine().getHypervisorType();
                // update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
                volService.updateHypervisorSnapshotReserveForVolume(diskOffering, volume.getId(), hyperType);
                final long hostId = vm.getVirtualMachine().getHostId();
                future = volService.createManagedStorageAndVolumeFromTemplateAsync(volume, destPool.getId(), templ, hostId);
            } else {
                future = volService.createVolumeFromTemplateAsync(volume, destPool.getId(), templ);
            }
        }
        VolumeService.VolumeApiResult result = null;
        try {
            result = future.get();
            if (result.isFailed()) {
                if (result.getResult().contains("request template reload") && (i == 0)) {
                    s_logger.debug("Retry template re-deploy for vmware");
                    continue;
                } else {
                    s_logger.debug("Unable to create " + newVol + ":" + result.getResult());
                    throw new StorageUnavailableException("Unable to create " + newVol + ":" + result.getResult(), destPool.getId());
                }
            }
            final StoragePoolVO storagePool = _storagePoolDao.findById(destPool.getId());
            if (storagePool.isManaged()) {
                final long hostId = vm.getVirtualMachine().getHostId();
                final Host host = _hostDao.findById(hostId);
                volService.grantAccess(volFactory.getVolume(newVol.getId()), host, destPool);
            }
            newVol = _volsDao.findById(newVol.getId());
            // break out of template-redeploy retry loop
            break;
        } catch (final InterruptedException e) {
            s_logger.error("Unable to create " + newVol, e);
            throw new StorageUnavailableException("Unable to create " + newVol + ":" + e.toString(), destPool.getId());
        } catch (final ExecutionException e) {
            s_logger.error("Unable to create " + newVol, e);
            throw new StorageUnavailableException("Unable to create " + newVol + ":" + e.toString(), destPool.getId());
        }
    }
    return new Pair<>(newVol, destPool);
}
Also used : StoragePool(com.cloud.storage.StoragePool) DiskOffering(com.cloud.offering.DiskOffering) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) Host(com.cloud.host.Host) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) VolumeVO(com.cloud.storage.VolumeVO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeService(com.cloud.engine.subsystem.api.storage.VolumeService) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ExecutionException(java.util.concurrent.ExecutionException) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) Pair(com.cloud.utils.Pair)

Example 47 with StoragePoolVO

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

the class VolumeOrchestrator method getDetails.

private Map<String, String> getDetails(final VolumeInfo volumeInfo, final DataStore dataStore) {
    final Map<String, String> details = new HashMap<>();
    final StoragePoolVO storagePool = _storagePoolDao.findById(dataStore.getId());
    details.put(DiskTO.MANAGED, String.valueOf(storagePool.isManaged()));
    details.put(DiskTO.STORAGE_HOST, storagePool.getHostAddress());
    details.put(DiskTO.STORAGE_PORT, String.valueOf(storagePool.getPort()));
    details.put(DiskTO.VOLUME_SIZE, String.valueOf(volumeInfo.getSize()));
    details.put(DiskTO.IQN, volumeInfo.get_iScsiName());
    details.put(DiskTO.MOUNT_POINT, volumeInfo.get_iScsiName());
    final VolumeVO volume = _volumeDao.findById(volumeInfo.getId());
    details.put(DiskTO.PROTOCOL_TYPE, (volume.getPoolType() != null) ? volume.getPoolType().toString() : null);
    final ChapInfo chapInfo = volService.getChapInfo(volumeInfo, dataStore);
    if (chapInfo != null) {
        details.put(DiskTO.CHAP_INITIATOR_USERNAME, chapInfo.getInitiatorUsername());
        details.put(DiskTO.CHAP_INITIATOR_SECRET, chapInfo.getInitiatorSecret());
        details.put(DiskTO.CHAP_TARGET_USERNAME, chapInfo.getTargetUsername());
        details.put(DiskTO.CHAP_TARGET_SECRET, chapInfo.getTargetSecret());
    }
    return details;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) HashMap(java.util.HashMap) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ChapInfo(com.cloud.engine.subsystem.api.storage.ChapInfo)

Example 48 with StoragePoolVO

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

the class VirtualMachineManagerImpl method orchestrateMigrateAway.

private void orchestrateMigrateAway(final String vmUuid, final long srcHostId, final DeploymentPlanner planner) throws InsufficientServerCapacityException {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    if (vm == null) {
        s_logger.debug("Unable to find a VM for " + vmUuid);
        throw new CloudRuntimeException("Unable to find " + vmUuid);
    }
    final ServiceOfferingVO offeringVO = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, offeringVO, null, null);
    final Long hostId = vm.getHostId();
    if (hostId == null) {
        s_logger.debug("Unable to migrate because the VM doesn't have a host id: " + vm);
        throw new CloudRuntimeException("Unable to migrate " + vmUuid);
    }
    final Host host = _hostDao.findById(hostId);
    Long poolId = null;
    final List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
    for (final VolumeVO rootVolumeOfVm : vols) {
        final StoragePoolVO rootDiskPool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId());
        if (rootDiskPool != null) {
            poolId = rootDiskPool.getId();
        }
    }
    final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), null, poolId, null);
    final ExcludeList excludes = new ExcludeList();
    excludes.addHost(hostId);
    DeployDestination dest = null;
    while (true) {
        try {
            dest = _dpMgr.planDeployment(profile, plan, excludes, planner);
        } catch (final AffinityConflictException e2) {
            s_logger.warn("Unable to create deployment, affinity rules associted to the VM conflict", e2);
            throw new CloudRuntimeException("Unable to create deployment, affinity rules associted to the VM conflict");
        }
        if (dest != null) {
            s_logger.debug("Found destination " + dest + " for migrating to.");
        } else {
            s_logger.debug("Unable to find destination for migrating the vm " + profile);
            throw new InsufficientServerCapacityException("Unable to find a server to migrate to.", host.getClusterId());
        }
        excludes.addHost(dest.getHost().getId());
        try {
            migrate(vm, srcHostId, dest);
            return;
        } catch (final ResourceUnavailableException e) {
            s_logger.debug("Unable to migrate to unavailable " + dest);
        } catch (final ConcurrentOperationException e) {
            s_logger.debug("Unable to migrate VM due to: " + e.getMessage());
        }
        try {
            advanceStop(vmUuid, true);
            throw new CloudRuntimeException("Unable to migrate " + vm);
        } catch (final ResourceUnavailableException e) {
            s_logger.debug("Unable to stop VM due to " + e.getMessage());
            throw new CloudRuntimeException("Unable to migrate " + vm);
        } catch (final ConcurrentOperationException e) {
            s_logger.debug("Unable to stop VM due to " + e.getMessage());
            throw new CloudRuntimeException("Unable to migrate " + vm);
        } catch (final OperationTimedoutException e) {
            s_logger.debug("Unable to stop VM due to " + e.getMessage());
            throw new CloudRuntimeException("Unable to migrate " + vm);
        }
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) Host(com.cloud.host.Host) AffinityConflictException(com.cloud.exception.AffinityConflictException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DeployDestination(com.cloud.deploy.DeployDestination) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 49 with StoragePoolVO

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

the class XenServerGuru method finalizeExpungeVolumes.

@Override
public List<Command> finalizeExpungeVolumes(final VirtualMachine vm) {
    final List<Command> commands = new ArrayList<>();
    final List<VolumeVO> volumes = _volumeDao.findByInstance(vm.getId());
    // will simply lead to the SR that supports the root volume being removed
    if (volumes != null) {
        for (final VolumeVO volume : volumes) {
            final StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
            // so the volume was never assigned to a storage pool)
            if (storagePool != null && storagePool.isManaged()) {
                final DataTO volTO = _volFactory.getVolume(volume.getId()).getTO();
                final DiskTO disk = new DiskTO(volTO, volume.getDeviceId(), volume.getPath(), volume.getVolumeType());
                final DettachCommand cmd = new DettachCommand(disk, vm.getInstanceName());
                cmd.setManaged(true);
                cmd.setStorageHost(storagePool.getHostAddress());
                cmd.setStoragePort(storagePool.getPort());
                cmd.set_iScsiName(volume.get_iScsiName());
                commands.add(cmd);
            }
        }
    }
    return commands;
}
Also used : DataTO(com.cloud.agent.api.to.DataTO) VolumeVO(com.cloud.storage.VolumeVO) StorageSubSystemCommand(com.cloud.storage.command.StorageSubSystemCommand) DettachCommand(com.cloud.storage.command.DettachCommand) CopyCommand(com.cloud.storage.command.CopyCommand) Command(com.cloud.agent.api.Command) ArrayList(java.util.ArrayList) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) DettachCommand(com.cloud.storage.command.DettachCommand) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 50 with StoragePoolVO

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

the class StorageSystemSnapshotStrategy method getSourceDetails.

private Map<String, String> getSourceDetails(final VolumeInfo volumeInfo) {
    final Map<String, String> sourceDetails = new HashMap<>();
    final VolumeVO volumeVO = _volumeDao.findById(volumeInfo.getId());
    final long storagePoolId = volumeVO.getPoolId();
    final StoragePoolVO storagePoolVO = _storagePoolDao.findById(storagePoolId);
    sourceDetails.put(DiskTO.STORAGE_HOST, storagePoolVO.getHostAddress());
    sourceDetails.put(DiskTO.STORAGE_PORT, String.valueOf(storagePoolVO.getPort()));
    sourceDetails.put(DiskTO.IQN, volumeVO.get_iScsiName());
    final ChapInfo chapInfo = _volService.getChapInfo(volumeInfo, volumeInfo.getDataStore());
    if (chapInfo != null) {
        sourceDetails.put(DiskTO.CHAP_INITIATOR_USERNAME, chapInfo.getInitiatorUsername());
        sourceDetails.put(DiskTO.CHAP_INITIATOR_SECRET, chapInfo.getInitiatorSecret());
        sourceDetails.put(DiskTO.CHAP_TARGET_USERNAME, chapInfo.getTargetUsername());
        sourceDetails.put(DiskTO.CHAP_TARGET_SECRET, chapInfo.getTargetSecret());
    }
    return sourceDetails;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) HashMap(java.util.HashMap) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ChapInfo(com.cloud.engine.subsystem.api.storage.ChapInfo)

Aggregations

StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)86 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)29 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)22 Test (org.junit.Test)18 HostVO (com.cloud.host.HostVO)15 VolumeVO (com.cloud.storage.VolumeVO)15 ArrayList (java.util.ArrayList)15 Answer (com.cloud.agent.api.Answer)14 Account (com.cloud.user.Account)13 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)11 StoragePool (com.cloud.storage.StoragePool)10 AttachAnswer (com.cloud.storage.command.AttachAnswer)10 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)9 VMInstanceVO (com.cloud.vm.VMInstanceVO)9 RebootAnswer (com.cloud.agent.api.RebootAnswer)8 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)8 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)8 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)8 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)8