Search in sources :

Example 16 with DataCenterVO

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);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkVO(com.cloud.network.dao.NetworkVO) TrafficType(com.cloud.network.Networks.TrafficType) Test(org.junit.Test)

Example 17 with DataCenterVO

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);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkVO(com.cloud.network.dao.NetworkVO) TrafficType(com.cloud.network.Networks.TrafficType) Test(org.junit.Test)

Example 18 with DataCenterVO

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);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkVO(com.cloud.network.dao.NetworkVO) Test(org.junit.Test)

Example 19 with DataCenterVO

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);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkVO(com.cloud.network.dao.NetworkVO) Test(org.junit.Test)

Example 20 with DataCenterVO

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;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateApiResult(org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) HashSet(java.util.HashSet)

Aggregations

DataCenterVO (com.cloud.dc.DataCenterVO)214 ArrayList (java.util.ArrayList)60 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)54 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)53 HostVO (com.cloud.host.HostVO)42 Account (com.cloud.user.Account)37 NetworkVO (com.cloud.network.dao.NetworkVO)35 DomainRouterVO (com.cloud.vm.DomainRouterVO)33 HostPodVO (com.cloud.dc.HostPodVO)32 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)30 ClusterVO (com.cloud.dc.ClusterVO)27 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)27 DB (com.cloud.utils.db.DB)26 Network (com.cloud.network.Network)25 HashMap (java.util.HashMap)25 ConfigurationException (javax.naming.ConfigurationException)25 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)20 Test (org.junit.Test)20 NicProfile (com.cloud.vm.NicProfile)19 ActionEvent (com.cloud.event.ActionEvent)18