use of org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope 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);
}
use of org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope in project cloudstack by apache.
the class ScaleIOPrimaryDataStoreLifeCycleTest method testAttachZone_UnsupportedHypervisor.
@Test(expected = CloudRuntimeException.class)
public void testAttachZone_UnsupportedHypervisor() throws Exception {
final DataStore dataStore = mock(DataStore.class);
final ZoneScope scope = new ZoneScope(1L);
scaleIOPrimaryDataStoreLifeCycleTest.attachZone(dataStore, scope, Hypervisor.HypervisorType.VMware);
}
use of org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope in project cloudstack by apache.
the class TemplateServiceImpl method handleSysTemplateDownload.
@Override
public void handleSysTemplateDownload(HypervisorType hostHyper, Long dcId) {
Set<VMTemplateVO> toBeDownloaded = new HashSet<VMTemplateVO>();
List<DataStore> stores = _storeMgr.getImageStoresByScopeExcludingReadOnly(new ZoneScope(dcId));
if (stores == null || stores.isEmpty()) {
return;
}
/* Download all the templates in zone with the same hypervisortype */
for (DataStore store : stores) {
List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
List<VMTemplateVO> defaultBuiltin = _templateDao.listDefaultBuiltinTemplates();
for (VMTemplateVO rtngTmplt : rtngTmplts) {
if (rtngTmplt.getHypervisorType() == hostHyper && !rtngTmplt.isDirectDownload()) {
toBeDownloaded.add(rtngTmplt);
}
}
for (VMTemplateVO builtinTmplt : defaultBuiltin) {
if (builtinTmplt.getHypervisorType() == hostHyper && !builtinTmplt.isDirectDownload()) {
toBeDownloaded.add(builtinTmplt);
}
}
for (VMTemplateVO template : toBeDownloaded) {
TemplateDataStoreVO tmpltHost = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
if (tmpltHost == null) {
associateTemplateToZone(template.getId(), dcId);
s_logger.info("Downloading builtin template " + template.getUniqueName() + " to data center: " + dcId);
TemplateInfo tmplt = _templateFactory.getTemplate(template.getId(), DataStoreRole.Image);
createTemplateAsync(tmplt, store, null);
}
}
}
}
use of org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope in project cloudstack by apache.
the class AncientDataMotionStrategy method copyVolumeFromSnapshot.
protected Answer copyVolumeFromSnapshot(DataObject snapObj, DataObject volObj) {
SnapshotInfo snapshot = (SnapshotInfo) snapObj;
StoragePool pool = (StoragePool) volObj.getDataStore();
String basicErrMsg = "Failed to create volume from " + snapshot.getName() + " on pool " + pool;
DataStore store = snapObj.getDataStore();
DataStoreTO storTO = store.getTO();
DataObject srcData = snapObj;
try {
if (!(storTO instanceof NfsTO)) {
// cache snapshot to zone-wide staging store for the volume to be created
srcData = cacheSnapshotChain(snapshot, new ZoneScope(pool.getDataCenterId()));
}
String value = configDao.getValue(Config.CreateVolumeFromSnapshotWait.toString());
int _createVolumeFromSnapshotWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreateVolumeFromSnapshotWait.getDefaultValue()));
EndPoint ep = null;
if (srcData.getDataStore().getRole() == DataStoreRole.Primary) {
ep = selector.select(volObj);
} else {
ep = selector.select(srcData, volObj);
}
CopyCommand cmd = new CopyCommand(srcData.getTO(), addFullCloneAndDiskprovisiongStrictnessFlagOnVMwareDest(volObj.getTO()), _createVolumeFromSnapshotWait, VirtualMachineManager.ExecuteInSequence.value());
Answer answer = null;
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
answer = new Answer(cmd, false, errMsg);
} else {
answer = ep.sendMessage(cmd);
}
return answer;
} catch (Exception e) {
s_logger.error(basicErrMsg, e);
throw new CloudRuntimeException(basicErrMsg);
} finally {
if (!(storTO instanceof NfsTO)) {
// still keep snapshot on cache which may be migrated from previous secondary storage
releaseSnapshotCacheChain((SnapshotInfo) srcData);
}
}
}
use of org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope in project cloudstack by apache.
the class ImageStoreProviderManagerImpl method listImageCacheStores.
@Override
public List<DataStore> listImageCacheStores(Scope scope) {
if (scope.getScopeType() != ScopeType.ZONE) {
s_logger.debug("only support zone wide image cache stores");
return null;
}
List<ImageStoreVO> stores = dataStoreDao.findImageCacheByScope(new ZoneScope(scope.getScopeId()));
List<DataStore> imageStores = new ArrayList<DataStore>();
for (ImageStoreVO store : stores) {
imageStores.add(getImageStore(store.getId()));
}
return imageStores;
}
Aggregations