Search in sources :

Example 1 with DeleteStoragePoolCommand

use of com.cloud.legacymodel.communication.command.DeleteStoragePoolCommand in project cosmic by MissionCriticalCloud.

the class CloudStackPrimaryDataStoreLifeCycleImpl method deleteDataStore.

@DB
@Override
public boolean deleteDataStore(final DataStore store) {
    final List<StoragePoolHostVO> hostPoolRecords = _storagePoolHostDao.listByPoolId(store.getId());
    final StoragePool pool = (StoragePool) store;
    boolean deleteFlag = false;
    // find the hypervisor where the storage is attached to.
    HypervisorType hType = null;
    if (hostPoolRecords.size() > 0) {
        hType = getHypervisorType(hostPoolRecords.get(0).getHostId());
    }
    // Remove the SR associated with the Xenserver
    for (final StoragePoolHostVO host : hostPoolRecords) {
        final DeleteStoragePoolCommand deleteCmd = new DeleteStoragePoolCommand(pool);
        final Answer answer = agentMgr.easySend(host.getHostId(), deleteCmd);
        if (answer != null && answer.getResult()) {
            deleteFlag = true;
            // if host is KVM hypervisor then send deleteStoragepoolcmd to all the kvm hosts.
            if (HypervisorType.KVM != hType) {
                break;
            }
        } else {
            if (answer != null) {
                s_logger.debug("Failed to delete storage pool: " + answer.getResult());
            }
        }
    }
    if (!hostPoolRecords.isEmpty() && !deleteFlag) {
        throw new CloudRuntimeException("Failed to delete storage pool on host");
    }
    return dataStoreHelper.deletePrimaryDataStore(store);
}
Also used : HypervisorType(com.cloud.model.enumeration.HypervisorType) Answer(com.cloud.legacymodel.communication.answer.Answer) StoragePool(com.cloud.legacymodel.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DeleteStoragePoolCommand(com.cloud.legacymodel.communication.command.DeleteStoragePoolCommand) DB(com.cloud.utils.db.DB)

Example 2 with DeleteStoragePoolCommand

use of com.cloud.legacymodel.communication.command.DeleteStoragePoolCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testDeleteStoragePoolCommandException.

@Test
public void testDeleteStoragePoolCommandException() {
    final StoragePool storagePool = Mockito.mock(StoragePool.class);
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final DeleteStoragePoolCommand command = new DeleteStoragePoolCommand(storagePool);
    final StorageFilerTO pool = command.getPool();
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.deleteStoragePool(pool.getType(), pool.getUuid())).thenThrow(CloudRuntimeException.class);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).deleteStoragePool(pool.getType(), pool.getUuid());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) DeleteStoragePoolCommand(com.cloud.legacymodel.communication.command.DeleteStoragePoolCommand) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) Test(org.junit.Test)

Example 3 with DeleteStoragePoolCommand

use of com.cloud.legacymodel.communication.command.DeleteStoragePoolCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testDeleteStoragePoolCommand.

@Test
public void testDeleteStoragePoolCommand() {
    final StoragePool storagePool = Mockito.mock(StoragePool.class);
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final DeleteStoragePoolCommand command = new DeleteStoragePoolCommand(storagePool);
    final StorageFilerTO pool = command.getPool();
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.deleteStoragePool(pool.getType(), pool.getUuid())).thenReturn(true);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).deleteStoragePool(pool.getType(), pool.getUuid());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) DeleteStoragePoolCommand(com.cloud.legacymodel.communication.command.DeleteStoragePoolCommand) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) Test(org.junit.Test)

Example 4 with DeleteStoragePoolCommand

use of com.cloud.legacymodel.communication.command.DeleteStoragePoolCommand in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testDeleteStoragePoolCommand.

@Test
public void testDeleteStoragePoolCommand() {
    final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final DeleteStoragePoolCommand deleteStorageCommand = new DeleteStoragePoolCommand(poolVO);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(this.citrixResourceBase.getHost()).thenReturn(xsHost);
    final Answer answer = wrapper.execute(deleteStorageCommand, this.citrixResourceBase);
    verify(this.citrixResourceBase, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) DeleteStoragePoolCommand(com.cloud.legacymodel.communication.command.DeleteStoragePoolCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)4 DeleteStoragePoolCommand (com.cloud.legacymodel.communication.command.DeleteStoragePoolCommand)4 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)3 StoragePool (com.cloud.legacymodel.storage.StoragePool)3 Test (org.junit.Test)3 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)2 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)2 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)2 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)2 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)2 StorageFilerTO (com.cloud.legacymodel.to.StorageFilerTO)2 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)1 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)1 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 HypervisorType (com.cloud.model.enumeration.HypervisorType)1 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)1 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)1 DB (com.cloud.utils.db.DB)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1