Search in sources :

Example 56 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class LocalStoragePoolAllocator method select.

@Override
protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) {
    s_logger.debug("LocalStoragePoolAllocator trying to find storage pool to fit the vm");
    if (!bypassStorageTypeCheck && !dskCh.useLocalStorage()) {
        return null;
    }
    if (s_logger.isTraceEnabled()) {
        // Log the pools details that are ignored because they are in disabled state
        List<StoragePoolVO> disabledPools = storagePoolDao.findDisabledPoolsByScope(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), ScopeType.HOST);
        if (disabledPools != null && !disabledPools.isEmpty()) {
            for (StoragePoolVO pool : disabledPools) {
                s_logger.trace("Ignoring pool " + pool + " as it is in disabled state.");
            }
        }
    }
    List<StoragePool> suitablePools = new ArrayList<StoragePool>();
    // data disk and host identified from deploying vm (attach volume case)
    if (plan.getHostId() != null) {
        List<StoragePoolVO> hostTagsPools = storagePoolDao.findLocalStoragePoolsByHostAndTags(plan.getHostId(), dskCh.getTags());
        for (StoragePoolVO pool : hostTagsPools) {
            if (pool != null && pool.isLocal()) {
                StoragePool storagePool = (StoragePool) this.dataStoreMgr.getPrimaryDataStore(pool.getId());
                if (filter(avoid, storagePool, dskCh, plan)) {
                    s_logger.debug("Found suitable local storage pool " + pool.getId() + ", adding to list");
                    suitablePools.add(storagePool);
                } else {
                    avoid.addPool(pool.getId());
                }
            }
            if (suitablePools.size() == returnUpTo) {
                break;
            }
        }
    } else {
        if (plan.getPodId() == null) {
            // zone wide primary storage deployment
            return null;
        }
        List<StoragePoolVO> availablePools = storagePoolDao.findLocalStoragePoolsByTags(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), dskCh.getTags());
        for (StoragePoolVO pool : availablePools) {
            if (suitablePools.size() == returnUpTo) {
                break;
            }
            StoragePool storagePool = (StoragePool) this.dataStoreMgr.getPrimaryDataStore(pool.getId());
            if (filter(avoid, storagePool, dskCh, plan)) {
                suitablePools.add(storagePool);
            } else {
                avoid.addPool(pool.getId());
            }
        }
        // add remaining pools in cluster, that did not match tags, to avoid
        // set
        List<StoragePoolVO> allPools = storagePoolDao.findLocalStoragePoolsByTags(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), null);
        allPools.removeAll(availablePools);
        for (StoragePoolVO pool : allPools) {
            avoid.addPool(pool.getId());
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("LocalStoragePoolAllocator returning " + suitablePools.size() + " suitable storage pools");
    }
    return suitablePools;
}
Also used : StoragePool(com.cloud.storage.StoragePool) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList)

Example 57 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class ZoneWideStoragePoolAllocator method select.

@Override
protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) {
    LOGGER.debug("ZoneWideStoragePoolAllocator to find storage pool");
    if (!bypassStorageTypeCheck && dskCh.useLocalStorage()) {
        return null;
    }
    if (LOGGER.isTraceEnabled()) {
        // Log the pools details that are ignored because they are in disabled state
        List<StoragePoolVO> disabledPools = storagePoolDao.findDisabledPoolsByScope(plan.getDataCenterId(), null, null, ScopeType.ZONE);
        if (disabledPools != null && !disabledPools.isEmpty()) {
            for (StoragePoolVO pool : disabledPools) {
                LOGGER.trace("Ignoring pool " + pool + " as it is in disabled state.");
            }
        }
    }
    List<StoragePool> suitablePools = new ArrayList<>();
    List<StoragePoolVO> storagePools = storagePoolDao.findZoneWideStoragePoolsByTags(plan.getDataCenterId(), dskCh.getTags());
    if (storagePools == null) {
        storagePools = new ArrayList<>();
    }
    List<StoragePoolVO> anyHypervisorStoragePools = new ArrayList<>();
    for (StoragePoolVO storagePool : storagePools) {
        if (HypervisorType.Any.equals(storagePool.getHypervisor())) {
            anyHypervisorStoragePools.add(storagePool);
        }
    }
    List<StoragePoolVO> storagePoolsByHypervisor = storagePoolDao.findZoneWideStoragePoolsByHypervisor(plan.getDataCenterId(), dskCh.getHypervisorType());
    storagePools.retainAll(storagePoolsByHypervisor);
    storagePools.addAll(anyHypervisorStoragePools);
    // add remaining pools in zone, that did not match tags, to avoid set
    List<StoragePoolVO> allPools = storagePoolDao.findZoneWideStoragePoolsByTags(plan.getDataCenterId(), null);
    allPools.removeAll(storagePools);
    for (StoragePoolVO pool : allPools) {
        avoid.addPool(pool.getId());
    }
    for (StoragePoolVO storage : storagePools) {
        if (suitablePools.size() == returnUpTo) {
            break;
        }
        StoragePool storagePool = (StoragePool) this.dataStoreMgr.getPrimaryDataStore(storage.getId());
        if (filter(avoid, storagePool, dskCh, plan)) {
            suitablePools.add(storagePool);
        } else {
            if (canAddStoragePoolToAvoidSet(storage)) {
                avoid.addPool(storagePool.getId());
            }
        }
    }
    return suitablePools;
}
Also used : StoragePool(com.cloud.storage.StoragePool) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList)

Example 58 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class DefaultSnapshotStrategy method revertSnapshot.

@Override
public boolean revertSnapshot(SnapshotInfo snapshot) {
    if (canHandle(snapshot, SnapshotOperation.REVERT) == StrategyPriority.CANT_HANDLE) {
        throw new CloudRuntimeException("Reverting not supported. Create a template or volume based on the snapshot instead.");
    }
    SnapshotVO snapshotVO = snapshotDao.acquireInLockTable(snapshot.getId());
    if (snapshotVO == null) {
        throw new CloudRuntimeException("Failed to get lock on snapshot:" + snapshot.getId());
    }
    try {
        VolumeInfo volumeInfo = snapshot.getBaseVolume();
        StoragePool store = (StoragePool) volumeInfo.getDataStore();
        if (store != null && store.getStatus() != StoragePoolStatus.Up) {
            snapshot.processEvent(Event.OperationFailed);
            throw new CloudRuntimeException("store is not in up state");
        }
        volumeInfo.stateTransit(Volume.Event.RevertSnapshotRequested);
        boolean result = false;
        try {
            result = snapshotSvr.revertSnapshot(snapshot);
            if (!result) {
                s_logger.debug("Failed to revert snapshot: " + snapshot.getId());
                throw new CloudRuntimeException("Failed to revert snapshot: " + snapshot.getId());
            }
        } finally {
            if (result) {
                volumeInfo.stateTransit(Volume.Event.OperationSucceeded);
            } else {
                volumeInfo.stateTransit(Volume.Event.OperationFailed);
            }
        }
        return result;
    } finally {
        if (snapshotVO != null) {
            snapshotDao.releaseFromLockTable(snapshot.getId());
        }
    }
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) StoragePool(com.cloud.storage.StoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Example 59 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class LibvirtComputingResourceTest method testPrimaryStorageDownloadCommandNOTemplateDisk.

@Test(expected = NullPointerException.class)
public void testPrimaryStorageDownloadCommandNOTemplateDisk() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final List<KVMPhysicalDisk> disks = new ArrayList<KVMPhysicalDisk>();
    final String name = "Test";
    final String url = "http://template/";
    final ImageFormat format = ImageFormat.QCOW2;
    final long accountId = 1l;
    final int wait = 0;
    final PrimaryStorageDownloadCommand command = new PrimaryStorageDownloadCommand(name, url, format, accountId, pool, wait);
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    final KVMStoragePool primaryPool = Mockito.mock(KVMStoragePool.class);
    final KVMStoragePool secondaryPool = Mockito.mock(KVMStoragePool.class);
    final KVMPhysicalDisk tmplVol = Mockito.mock(KVMPhysicalDisk.class);
    final KVMPhysicalDisk primaryVol = Mockito.mock(KVMPhysicalDisk.class);
    final KVMPhysicalDisk disk = new KVMPhysicalDisk("/path", "disk.qcow2", primaryPool);
    disks.add(disk);
    final int index = url.lastIndexOf("/");
    final String mountpoint = url.substring(0, index);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePoolByURI(mountpoint)).thenReturn(secondaryPool);
    when(secondaryPool.listPhysicalDisks()).thenReturn(disks);
    when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPoolUuid())).thenReturn(primaryPool);
    when(storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(), primaryPool, 0)).thenReturn(primaryVol);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) ArrayList(java.util.ArrayList) ImageFormat(com.cloud.storage.Storage.ImageFormat) UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 60 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class KVMHostActivityChecker method isVMActivtyOnHost.

private boolean isVMActivtyOnHost(Host agent, DateTime suspectTime) throws HACheckerException {
    if (agent.getHypervisorType() != Hypervisor.HypervisorType.KVM && agent.getHypervisorType() != Hypervisor.HypervisorType.LXC) {
        throw new IllegalStateException(String.format("Calling KVM investigator for non KVM Host of type [%s].", agent.getHypervisorType()));
    }
    boolean activityStatus = true;
    HashMap<StoragePool, List<Volume>> poolVolMap = getVolumeUuidOnHost(agent);
    for (StoragePool pool : poolVolMap.keySet()) {
        activityStatus = verifyActivityOfStorageOnHost(poolVolMap, pool, agent, suspectTime, activityStatus);
        if (!activityStatus) {
            LOG.warn(String.format("It seems that the storage pool [%s] does not have activity on %s.", pool.getId(), agent.toString()));
            break;
        }
    }
    return activityStatus;
}
Also used : StoragePool(com.cloud.storage.StoragePool) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

StoragePool (com.cloud.storage.StoragePool)234 Answer (com.cloud.agent.api.Answer)81 Test (org.junit.Test)70 ArrayList (java.util.ArrayList)69 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)63 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)56 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)56 Volume (com.cloud.storage.Volume)55 HashMap (java.util.HashMap)47 VolumeVO (com.cloud.storage.VolumeVO)37 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)36 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)35 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)29 DiskProfile (com.cloud.vm.DiskProfile)29 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)28 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool)28 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KvmHaBase.NfsStoragePool)28 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)28 KvmStoragePool (com.cloud.hypervisor.kvm.storage.KvmStoragePool)28 AttachAnswer (com.cloud.storage.command.AttachAnswer)28