use of com.cloud.dc.DataCenterVO in project cloudstack by apache.
the class SecondaryStorageManagerTest method getDefaultNetworkForAdvancedWrongZoneType.
@Test(expected = CloudRuntimeException.class)
public void getDefaultNetworkForAdvancedWrongZoneType() {
DataCenterVO dc = Mockito.mock(DataCenterVO.class);
when(dc.getNetworkType()).thenReturn(NetworkType.Basic);
when(dc.isSecurityGroupEnabled()).thenReturn(true);
when(_dcDao.findById(Mockito.anyLong())).thenReturn(dc);
NetworkVO network = Mockito.mock(NetworkVO.class);
NetworkVO badNetwork = Mockito.mock(NetworkVO.class);
when(_networkDao.listByZoneAndTrafficType(anyLong(), any(TrafficType.class))).thenReturn(Collections.singletonList(badNetwork));
when(_networkDao.listByZoneSecurityGroup(anyLong())).thenReturn(Collections.singletonList(network));
_ssMgr.getDefaultNetworkForAdvancedZone(dc);
}
use of com.cloud.dc.DataCenterVO in project cloudstack by apache.
the class SecondaryStorageManagerTest method getDefaultNetworkForAdvancedSG.
@Test
public void getDefaultNetworkForAdvancedSG() {
DataCenterVO dc = Mockito.mock(DataCenterVO.class);
when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
when(dc.isSecurityGroupEnabled()).thenReturn(true);
when(_dcDao.findById(Mockito.anyLong())).thenReturn(dc);
NetworkVO network = Mockito.mock(NetworkVO.class);
NetworkVO badNetwork = Mockito.mock(NetworkVO.class);
when(_networkDao.listByZoneAndTrafficType(anyLong(), any(TrafficType.class))).thenReturn(Collections.singletonList(badNetwork));
when(_networkDao.listByZoneSecurityGroup(anyLong())).thenReturn(Collections.singletonList(network));
NetworkVO returnedNetwork = _ssMgr.getDefaultNetworkForAdvancedZone(dc);
Assert.assertEquals(network, returnedNetwork);
Assert.assertNotEquals(badNetwork, returnedNetwork);
}
use of com.cloud.dc.DataCenterVO in project cloudstack by apache.
the class SecondaryStorageManagerTest method getDefaultNetworkForBasicSG.
@Test
public void getDefaultNetworkForBasicSG() {
DataCenterVO dc = Mockito.mock(DataCenterVO.class);
when(dc.getNetworkType()).thenReturn(NetworkType.Basic);
when(dc.isSecurityGroupEnabled()).thenReturn(true);
when(_dcDao.findById(Mockito.anyLong())).thenReturn(dc);
NetworkVO network = Mockito.mock(NetworkVO.class);
NetworkVO badNetwork = Mockito.mock(NetworkVO.class);
when(_networkDao.listByZoneAndTrafficType(anyLong(), eq(TrafficType.Guest))).thenReturn(Collections.singletonList(network));
when(_networkDao.listByZoneAndTrafficType(anyLong(), not(eq(TrafficType.Guest)))).thenReturn(Collections.singletonList(badNetwork));
NetworkVO returnedNetwork = _ssMgr.getDefaultNetworkForBasicZone(dc);
Assert.assertNotNull(returnedNetwork);
Assert.assertEquals(network, returnedNetwork);
Assert.assertNotEquals(badNetwork, returnedNetwork);
}
use of com.cloud.dc.DataCenterVO in project cloudstack by apache.
the class SecondaryStorageManagerTest method getDefaultNetworkForBasicSGWrongZoneType.
//also test invalid input
@Test(expected = CloudRuntimeException.class)
public void getDefaultNetworkForBasicSGWrongZoneType() {
DataCenterVO dc = Mockito.mock(DataCenterVO.class);
when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
when(dc.isSecurityGroupEnabled()).thenReturn(true);
when(_dcDao.findById(Mockito.anyLong())).thenReturn(dc);
NetworkVO network = Mockito.mock(NetworkVO.class);
NetworkVO badNetwork = Mockito.mock(NetworkVO.class);
when(_networkDao.listByZoneAndTrafficType(anyLong(), eq(TrafficType.Guest))).thenReturn(Collections.singletonList(network));
when(_networkDao.listByZoneAndTrafficType(anyLong(), not(eq(TrafficType.Guest)))).thenReturn(Collections.singletonList(badNetwork));
_ssMgr.getDefaultNetworkForBasicZone(dc);
}
use of com.cloud.dc.DataCenterVO in project cloudstack by apache.
the class HypervisorTemplateAdapter method create.
@Override
public VMTemplateVO create(TemplateProfile profile) {
// persist entry in vm_template, vm_template_details and template_zone_ref tables, not that entry at template_store_ref is not created here, and created in createTemplateAsync.
VMTemplateVO template = persistTemplate(profile, State.Active);
if (template == null) {
throw new CloudRuntimeException("Unable to persist the template " + profile.getTemplate());
}
// find all eligible image stores for this zone scope
List<DataStore> imageStores = storeMgr.getImageStoresByScope(new ZoneScope(profile.getZoneId()));
if (imageStores == null || imageStores.size() == 0) {
throw new CloudRuntimeException("Unable to find image store to download template " + profile.getTemplate());
}
Set<Long> zoneSet = new HashSet<Long>();
// For private templates choose a random store. TODO - Have a better algorithm based on size, no. of objects, load etc.
Collections.shuffle(imageStores);
for (DataStore imageStore : imageStores) {
// skip data stores for a disabled zone
Long zoneId = imageStore.getScope().getScopeId();
if (zoneId != null) {
DataCenterVO zone = _dcDao.findById(zoneId);
if (zone == null) {
s_logger.warn("Unable to find zone by id " + zoneId + ", so skip downloading template to its image store " + imageStore.getId());
continue;
}
// Check if zone is disabled
if (Grouping.AllocationState.Disabled == zone.getAllocationState()) {
s_logger.info("Zone " + zoneId + " is disabled, so skip downloading template to its image store " + imageStore.getId());
continue;
}
// Check if image store has enough capacity for template
if (!_statsCollector.imageStoreHasEnoughCapacity(imageStore)) {
s_logger.info("Image store doesn't has enough capacity, so skip downloading template to this image store " + imageStore.getId());
continue;
}
// We want to download private template to one of the image store in a zone
if (isPrivateTemplate(template) && zoneSet.contains(zoneId)) {
continue;
} else {
zoneSet.add(zoneId);
}
}
TemplateInfo tmpl = imageFactory.getTemplate(template.getId(), imageStore);
CreateTemplateContext<TemplateApiResult> context = new CreateTemplateContext<TemplateApiResult>(null, tmpl);
AsyncCallbackDispatcher<HypervisorTemplateAdapter, TemplateApiResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createTemplateAsyncCallBack(null, null));
caller.setContext(context);
imageService.createTemplateAsync(tmpl, imageStore, caller);
}
_resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template);
return template;
}
Aggregations