Search in sources :

Example 6 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.

the class SnapshotTestWithFakeData method createDataStore.

private DataStore createDataStore() throws URISyntaxException {
    StoragePoolVO pool = new StoragePoolVO();
    pool.setClusterId(clusterId);
    pool.setDataCenterId(dcId);
    URI uri = new URI("nfs://jfkdkf/fjdkfj");
    pool.setHostAddress(uri.getHost());
    pool.setPath(uri.getPath());
    pool.setPort(0);
    pool.setName(UUID.randomUUID().toString());
    pool.setUuid(UUID.randomUUID().toString());
    pool.setStatus(StoragePoolStatus.Up);
    pool.setPoolType(Storage.StoragePoolType.NetworkFilesystem);
    pool.setPodId(podId);
    pool.setScope(ScopeType.CLUSTER);
    pool.setStorageProviderName(DataStoreProvider.DEFAULT_PRIMARY);
    pool = primaryDataStoreDao.persist(pool);
    DataStore store = dataStoreManager.getPrimaryDataStore(pool.getId());
    return store;
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) URI(java.net.URI)

Example 7 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.

the class SnapshotTestWithFakeData method testTakeSnapshotWithFailed.

// @Test
public void testTakeSnapshotWithFailed() throws URISyntaxException {
    SnapshotVO snapshotVO = createSnapshotInDb();
    DataStore store = null;
    try {
        store = createDataStore();
        FakePrimaryDataStoreDriver dataStoreDriver = (FakePrimaryDataStoreDriver) store.getDriver();
        dataStoreDriver.makeTakeSnapshotSucceed(false);
        SnapshotInfo snapshotInfo = snapshotDataFactory.getSnapshot(snapshotVO.getId(), store);
        SnapshotResult result = snapshotService.takeSnapshot(snapshotInfo);
        Assert.assertFalse(result.isSuccess());
        SnapshotDataStoreVO storeRef = snapshotDataStoreDao.findByStoreSnapshot(store.getRole(), store.getId(), snapshotVO.getId());
        Assert.assertTrue(storeRef == null);
    } finally {
        snapshotDao.expunge(snapshotVO.getId());
        if (store != null) {
            primaryDataStoreDao.remove(store.getId());
        }
    }
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

Example 8 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.

the class SnapshotTestWithFakeData method testTakeSnapshot.

// @Test
public void testTakeSnapshot() throws URISyntaxException {
    SnapshotVO snapshotVO = createSnapshotInDb();
    DataStore store = createDataStore();
    try {
        SnapshotInfo snapshotInfo = snapshotDataFactory.getSnapshot(snapshotVO.getId(), store);
        SnapshotResult result = snapshotService.takeSnapshot(snapshotInfo);
        Assert.assertTrue(result.isSuccess());
        SnapshotDataStoreVO storeRef = snapshotDataStoreDao.findByStoreSnapshot(store.getRole(), store.getId(), snapshotVO.getId());
        Assert.assertTrue(storeRef != null);
        Assert.assertTrue(storeRef.getState() == ObjectInDataStoreStateMachine.State.Ready);
        snapshotInfo = result.getSnapshot();
        boolean deletResult = snapshotService.deleteSnapshot(snapshotInfo);
        Assert.assertTrue(deletResult);
        snapshotDataStoreDao.expunge(storeRef.getId());
    } finally {
        snapshotDao.expunge(snapshotVO.getId());
        primaryDataStoreDao.remove(store.getId());
    }
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

Example 9 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.

the class EndpointSelectorTest method testMixZonePrimaryStorages.

@Test
public void testMixZonePrimaryStorages() {
    Long srcStoreId = null;
    Long destStoreId = imageStore.getId();
    DataStore store = createPrimaryDataStore(ScopeType.ZONE);
    srcStoreId = store.getId();
    HostVO host = createHost(Hypervisor.HypervisorType.VMware);
    addStorageToHost(store, host);
    store = createPrimaryDataStore(ScopeType.ZONE);
    host = createHost(Hypervisor.HypervisorType.VMware);
    addStorageToHost(store, host);
    Long xenStoreId = null;
    store = createPrimaryDataStore(ScopeType.CLUSTER);
    xenStoreId = store.getId();
    host = createHost(Hypervisor.HypervisorType.XenServer);
    addStorageToHost(store, host);
    store = createPrimaryDataStore(ScopeType.CLUSTER);
    host = createHost(Hypervisor.HypervisorType.XenServer);
    addStorageToHost(store, host);
    ZoneScope srcScope = new ZoneScope(dcId);
    DataStore srcStore = mock(DataStore.class);
    DataStore destStore = mock(DataStore.class);
    when(srcStore.getScope()).thenReturn(srcScope);
    when(srcStore.getRole()).thenReturn(DataStoreRole.Primary);
    when(srcStore.getId()).thenReturn(srcStoreId);
    when(destStore.getScope()).thenReturn(srcScope);
    when(destStore.getRole()).thenReturn(DataStoreRole.Image);
    when(destStore.getId()).thenReturn(destStoreId);
    DataObject srcObj = mock(DataObject.class);
    DataObject destObj = mock(DataObject.class);
    when(srcObj.getDataStore()).thenReturn(srcStore);
    when(destObj.getDataStore()).thenReturn(destStore);
    EndPoint ep = endPointSelector.select(srcObj, destObj);
    Assert.assertTrue(ep != null);
    Long hostId = ep.getId();
    HostVO newHost = hostDao.findById(hostId);
    Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.VMware);
    when(srcStore.getRole()).thenReturn(DataStoreRole.Image);
    when(srcStore.getId()).thenReturn(destStoreId);
    when(destStore.getId()).thenReturn(srcStoreId);
    when(destStore.getRole()).thenReturn(DataStoreRole.Primary);
    ep = endPointSelector.select(srcObj, destObj);
    Assert.assertTrue(ep != null);
    hostId = ep.getId();
    newHost = hostDao.findById(hostId);
    Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.VMware);
    ClusterScope clusterScope = new ClusterScope(clusterId, podId, dcId);
    when(srcStore.getRole()).thenReturn(DataStoreRole.Primary);
    when(srcStore.getScope()).thenReturn(clusterScope);
    when(srcStore.getId()).thenReturn(xenStoreId);
    ep = endPointSelector.select(srcStore);
    Assert.assertTrue(ep != null);
    newHost = hostDao.findById(ep.getId());
    Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.XenServer);
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) Test(org.junit.Test)

Example 10 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.

the class EndpointSelectorTest method createPrimaryDataStore.

public DataStore createPrimaryDataStore(ScopeType scope) {
    String uuid = UUID.randomUUID().toString();
    List<StoragePoolVO> pools = primaryDataStoreDao.findPoolByName(uuid);
    if (pools.size() > 0) {
        return dataStoreManager.getPrimaryDataStore(pools.get(0).getId());
    }
    StoragePoolVO pool = new StoragePoolVO();
    if (scope != ScopeType.ZONE) {
        pool.setClusterId(clusterId);
    }
    pool.setDataCenterId(dcId);
    pool.setHostAddress(uuid);
    pool.setPath(uuid);
    pool.setPort(0);
    pool.setName(uuid);
    pool.setUuid(uuid);
    pool.setStatus(StoragePoolStatus.Up);
    pool.setPoolType(Storage.StoragePoolType.NetworkFilesystem);
    pool.setPodId(podId);
    pool.setScope(scope);
    pool.setStorageProviderName(DataStoreProvider.DEFAULT_PRIMARY);
    pool = primaryDataStoreDao.persist(pool);
    DataStore store = dataStoreManager.getPrimaryDataStore(pool.getId());
    return store;
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Aggregations

DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)221 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)81 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)71 ExecutionException (java.util.concurrent.ExecutionException)50 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)42 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)38 ArrayList (java.util.ArrayList)37 HashMap (java.util.HashMap)35 VolumeVO (com.cloud.storage.VolumeVO)34 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)30 VMTemplateVO (com.cloud.storage.VMTemplateVO)30 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)29 HostVO (com.cloud.host.HostVO)26 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)26 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)25 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)23 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)23 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)22 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)22 VolumeApiResult (org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult)22