Search in sources :

Example 11 with DeleteStoragePoolCommand

use of com.cloud.agent.api.DeleteStoragePoolCommand in project cloudstack by apache.

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(citrixResourceBase.getHost()).thenReturn(xsHost);
    final Answer answer = wrapper.execute(deleteStorageCommand, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) Test(org.junit.Test)

Example 12 with DeleteStoragePoolCommand

use of com.cloud.agent.api.DeleteStoragePoolCommand in project cloudstack by apache.

the class CloudStackPrimaryDataStoreLifeCycleImpl method deleteDataStore.

@DB
@Override
public boolean deleteDataStore(DataStore store) {
    List<StoragePoolHostVO> hostPoolRecords = _storagePoolHostDao.listByPoolId(store.getId());
    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 (StoragePoolHostVO host : hostPoolRecords) {
        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.hypervisor.Hypervisor.HypervisorType) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) DB(com.cloud.utils.db.DB)

Example 13 with DeleteStoragePoolCommand

use of com.cloud.agent.api.DeleteStoragePoolCommand in project cloudstack by apache.

the class ElastistorPrimaryDataStoreLifeCycle method deleteDataStore.

@SuppressWarnings("finally")
@Override
public boolean deleteDataStore(DataStore store) {
    List<StoragePoolHostVO> hostPoolRecords = _storagePoolHostDao.listByPoolId(store.getId());
    StoragePool pool = (StoragePool) store;
    // find the hypervisor where the storage is attached to.
    HypervisorType hType = null;
    if (hostPoolRecords.size() > 0) {
        hType = getHypervisorType(hostPoolRecords.get(0).getHostId());
    }
    StoragePoolVO storagePoolVO = _storagePoolDao.findById(store.getId());
    if (!(storagePoolVO.isManaged())) {
        // Remove the SR associated with the Xenserver
        for (StoragePoolHostVO host : hostPoolRecords) {
            DeleteStoragePoolCommand deleteCmd = new DeleteStoragePoolCommand(pool);
            final Answer answer = agentMgr.easySend(host.getHostId(), deleteCmd);
            if (answer != null && answer.getResult()) {
                // to all the kvm hosts.
                if (HypervisorType.KVM != hType) {
                    break;
                }
            } else {
                if (answer != null) {
                    s_logger.error("Failed to delete storage pool: " + answer.getResult());
                }
            }
        }
    }
    // delete the Elastistor volume at backend
    deleteElastistorVolume(pool, storagePoolVO.isManaged());
    return _dataStoreHelper.deletePrimaryDataStore(store);
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand)

Aggregations

Answer (com.cloud.agent.api.Answer)13 DeleteStoragePoolCommand (com.cloud.agent.api.DeleteStoragePoolCommand)13 StoragePool (com.cloud.storage.StoragePool)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)5 Test (org.junit.Test)5 ModifyStoragePoolCommand (com.cloud.agent.api.ModifyStoragePoolCommand)4 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)3 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)3 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)3 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)3 CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)3 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)3 CreateStoragePoolCommand (com.cloud.agent.api.CreateStoragePoolCommand)3 CreateVolumeFromSnapshotCommand (com.cloud.agent.api.CreateVolumeFromSnapshotCommand)3 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)3 GetHostStatsCommand (com.cloud.agent.api.GetHostStatsCommand)3 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)3 GetStorageStatsCommand (com.cloud.agent.api.GetStorageStatsCommand)3 GetVmStatsAnswer (com.cloud.agent.api.GetVmStatsAnswer)3