Search in sources :

Example 96 with StoragePool

use of com.cloud.storage.StoragePool in project cosmic by MissionCriticalCloud.

the class ZoneWideStoragePoolAllocator method select.

@Override
protected List<StoragePool> select(final DiskProfile dskCh, final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoid, final int returnUpTo) {
    s_logger.debug("ZoneWideStoragePoolAllocator to find storage pool");
    if (dskCh.useLocalStorage()) {
        return null;
    }
    if (s_logger.isTraceEnabled()) {
        // Log the pools details that are ignored because they are in disabled state
        final List<StoragePoolVO> disabledPools = _storagePoolDao.findDisabledPoolsByScope(plan.getDataCenterId(), null, null, ScopeType.ZONE);
        if (disabledPools != null && !disabledPools.isEmpty()) {
            for (final StoragePoolVO pool : disabledPools) {
                s_logger.trace("Ignoring pool " + pool + " as it is in disabled state.");
            }
        }
    }
    final List<StoragePool> suitablePools = new ArrayList<>();
    List<StoragePoolVO> storagePools = _storagePoolDao.findZoneWideStoragePoolsByTags(plan.getDataCenterId(), dskCh.getTags());
    if (storagePools == null) {
        storagePools = new ArrayList<>();
    }
    final List<StoragePoolVO> anyHypervisorStoragePools = new ArrayList<>();
    for (final StoragePoolVO storagePool : storagePools) {
        if (HypervisorType.Any.equals(storagePool.getHypervisor())) {
            anyHypervisorStoragePools.add(storagePool);
        }
    }
    final 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
    final List<StoragePoolVO> allPools = _storagePoolDao.findZoneWideStoragePoolsByTags(plan.getDataCenterId(), null);
    allPools.removeAll(storagePools);
    for (final StoragePoolVO pool : allPools) {
        avoid.addPool(pool.getId());
    }
    detectSuitableOrToAvoidPools(dskCh, plan, avoid, returnUpTo, suitablePools, storagePools);
    return suitablePools;
}
Also used : StoragePool(com.cloud.storage.StoragePool) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList)

Example 97 with StoragePool

use of com.cloud.storage.StoragePool in project cosmic by MissionCriticalCloud.

the class AbstractHyperVisorStorageMotionStrategy method updateVolumePathsAfterMigration.

protected void updateVolumePathsAfterMigration(final Map<VolumeInfo, DataStore> volumeToPool, final List<VolumeObjectTO> volumeTos) {
    for (final Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
        boolean updated = false;
        final VolumeInfo volume = entry.getKey();
        final StoragePool pool = (StoragePool) entry.getValue();
        for (final VolumeObjectTO volumeTo : volumeTos) {
            if (volume.getId() == volumeTo.getId()) {
                final VolumeVO volumeVO = volDao.findById(volume.getId());
                final Long oldPoolId = volumeVO.getPoolId();
                volumeVO.setPath(volumeTo.getPath());
                volumeVO.setFolder(pool.getPath());
                volumeVO.setPodId(pool.getPodId());
                volumeVO.setPoolId(pool.getId());
                volumeVO.setLastPoolId(oldPoolId);
                volDao.update(volume.getId(), volumeVO);
                updated = true;
                break;
            }
        }
        if (!updated) {
            s_logger.error("Volume path wasn't updated for volume " + volume + " after it was migrated.");
        }
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VolumeObjectTO(com.cloud.storage.to.VolumeObjectTO) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) Map(java.util.Map)

Example 98 with StoragePool

use of com.cloud.storage.StoragePool in project cosmic by MissionCriticalCloud.

the class DefaultHostListener method hostConnect.

@Override
public boolean hostConnect(final long hostId, final long poolId) throws StorageConflictException {
    final StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
    final ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool);
    final Answer answer = agentMgr.easySend(hostId, cmd);
    if (answer == null) {
        throw new CloudRuntimeException("Unable to get an answer to the modify storage pool command" + pool.getId());
    }
    if (!answer.getResult()) {
        final String msg = "Unable to attach storage pool" + poolId + " to the host" + hostId;
        alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, pool.getDataCenterId(), pool.getPodId(), msg, msg);
        throw new CloudRuntimeException("Unable establish connection from storage head to storage pool " + pool.getId() + " due to " + answer.getDetails() + pool.getId());
    }
    assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" + pool.getId() + "Host=" + hostId;
    final ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) answer;
    if (mspAnswer.getLocalDatastoreName() != null && pool.isShared()) {
        final String datastoreName = mspAnswer.getLocalDatastoreName();
        final List<StoragePoolVO> localStoragePools = this.primaryStoreDao.listLocalStoragePoolByPath(pool.getDataCenterId(), datastoreName);
        for (final StoragePoolVO localStoragePool : localStoragePools) {
            if (datastoreName.equals(localStoragePool.getPath())) {
                s_logger.warn("Storage pool: " + pool.getId() + " has already been added as local storage: " + localStoragePool.getName());
                throw new StorageConflictException("Cannot add shared storage pool: " + pool.getId() + " because it has already been added as local storage:" + localStoragePool.getName());
            }
        }
    }
    StoragePoolHostVO poolHost = storagePoolHostDao.findByPoolHost(pool.getId(), hostId);
    if (poolHost == null) {
        poolHost = new StoragePoolHostVO(pool.getId(), hostId, mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
        storagePoolHostDao.persist(poolHost);
    } else {
        poolHost.setLocalPath(mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
    }
    final StoragePoolVO poolVO = this.primaryStoreDao.findById(poolId);
    poolVO.setUsedBytes(mspAnswer.getPoolInfo().getCapacityBytes() - mspAnswer.getPoolInfo().getAvailableBytes());
    poolVO.setCapacityBytes(mspAnswer.getPoolInfo().getCapacityBytes());
    primaryStoreDao.update(pool.getId(), poolVO);
    s_logger.info("Connection established between storage pool " + pool + " and host " + hostId);
    return true;
}
Also used : ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) StorageConflictException(com.cloud.exception.StorageConflictException) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand)

Example 99 with StoragePool

use of com.cloud.storage.StoragePool in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testManageSnapshotCommandLibvirt.

@Test
public void testManageSnapshotCommandLibvirt() {
    final StoragePool storagePool = Mockito.mock(StoragePool.class);
    final String volumePath = "/123/vol";
    final String vmName = "Test";
    final long snapshotId = 1l;
    final String preSnapshotPath = "/snapshot/path";
    final String snapshotName = "snap";
    final ManageSnapshotCommand command = new ManageSnapshotCommand(snapshotId, volumePath, storagePool, preSnapshotPath, snapshotName, vmName);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final Connect conn = Mockito.mock(Connect.class);
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool primaryPool = Mockito.mock(KvmStoragePool.class);
    final Domain vm = Mockito.mock(Domain.class);
    final DomainInfo info = Mockito.mock(DomainInfo.class);
    final DomainState state = DomainInfo.DomainState.VIR_DOMAIN_RUNNING;
    info.state = state;
    final KvmPhysicalDisk disk = Mockito.mock(KvmPhysicalDisk.class);
    final StorageFilerTO pool = command.getPool();
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
        when(libvirtComputingResource.getDomain(conn, command.getVmName())).thenReturn(vm);
        when(vm.getInfo()).thenReturn(info);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primaryPool);
    when(primaryPool.getPhysicalDisk(command.getVolumePath())).thenReturn(disk);
    when(primaryPool.isExternalSnapshot()).thenReturn(false);
    try {
        when(vm.getUUIDString()).thenReturn("cdb18980-546d-4153-b916-70ee9edf0908");
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : NfsStoragePool(com.cloud.hypervisor.kvm.resource.KvmHaBase.NfsStoragePool) StoragePool(com.cloud.storage.StoragePool) KvmStoragePool(com.cloud.hypervisor.kvm.storage.KvmStoragePool) KvmStoragePool(com.cloud.hypervisor.kvm.storage.KvmStoragePool) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) ManageSnapshotCommand(com.cloud.agent.api.ManageSnapshotCommand) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AttachAnswer(com.cloud.storage.command.AttachAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) DomainState(org.libvirt.DomainInfo.DomainState) KvmStoragePoolManager(com.cloud.hypervisor.kvm.storage.KvmStoragePoolManager) DomainInfo(org.libvirt.DomainInfo) Domain(org.libvirt.Domain) KvmPhysicalDisk(com.cloud.hypervisor.kvm.storage.KvmPhysicalDisk) Test(org.junit.Test)

Example 100 with StoragePool

use of com.cloud.storage.StoragePool in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromVolumeCommand.

@Test
public void testCreatePrivateTemplateFromVolumeCommand() {
    // Simple test used to make sure the flow (LibvirtComputingResource => Request => CommandWrapper) is working.
    // The code is way to big and complex. Will finish the refactor and come back to this to add more cases.
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final String secondaryStorageUrl = "nfs:/127.0.0.1/storage/secondary";
    final long templateId = 1l;
    final long accountId = 1l;
    final String userSpecifiedName = "User";
    final String uniqueName = "Unique";
    final String volumePath = "/123/vol";
    final String vmName = "Test";
    final int wait = 0;
    final CreatePrivateTemplateFromVolumeCommand command = new CreatePrivateTemplateFromVolumeCommand(pool, secondaryStorageUrl, templateId, accountId, userSpecifiedName, uniqueName, volumePath, vmName, wait);
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool secondaryStorage = Mockito.mock(KvmStoragePool.class);
    // final KVMStoragePool primary = Mockito.mock(KVMStoragePool.class);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePoolByUri(secondaryStorageUrl)).thenReturn(secondaryStorage);
    when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPrimaryStoragePoolNameLabel())).thenThrow(new CloudRuntimeException("error"));
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).getStoragePoolByUri(secondaryStorageUrl);
    verify(storagePoolMgr, times(1)).getStoragePool(command.getPool().getType(), command.getPrimaryStoragePoolNameLabel());
}
Also used : Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AttachAnswer(com.cloud.storage.command.AttachAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KvmHaBase.NfsStoragePool) StoragePool(com.cloud.storage.StoragePool) KvmStoragePool(com.cloud.hypervisor.kvm.storage.KvmStoragePool) KvmStoragePool(com.cloud.hypervisor.kvm.storage.KvmStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) KvmStoragePoolManager(com.cloud.hypervisor.kvm.storage.KvmStoragePoolManager) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand) Test(org.junit.Test)

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