Search in sources :

Example 56 with PhysicalNetworkVO

use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.

the class ConfigurationManagerTest method checkIfZoneIsDeletableFailureOnVolumeTest.

@Test(expected = CloudRuntimeException.class)
public void checkIfZoneIsDeletableFailureOnVolumeTest() {
    VolumeVO volumeVO = Mockito.mock(VolumeVO.class);
    ArrayList<VolumeVO> arrayList = new ArrayList<VolumeVO>();
    arrayList.add(volumeVO);
    Mockito.when(_hostDao.listByDataCenterId(anyLong())).thenReturn(new ArrayList<HostVO>());
    Mockito.when(_podDao.listByDataCenterId(anyLong())).thenReturn(new ArrayList<HostPodVO>());
    Mockito.when(_privateIpAddressDao.countIPs(anyLong(), anyBoolean())).thenReturn(0);
    Mockito.when(_publicIpAddressDao.countIPs(anyLong(), anyBoolean())).thenReturn(0);
    Mockito.when(_vmInstanceDao.listByZoneId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
    Mockito.when(_volumeDao.findByDc(anyLong())).thenReturn(arrayList);
    Mockito.when(_physicalNetworkDao.listByZone(anyLong())).thenReturn(new ArrayList<PhysicalNetworkVO>());
    configurationMgr.checkIfZoneIsDeletable(new Random().nextLong());
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) Random(java.util.Random) ArrayList(java.util.ArrayList) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) Test(org.junit.Test)

Example 57 with PhysicalNetworkVO

use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.

the class DedicateGuestVlanRangesTest method runDedicateGuestVlanRangePostiveTest.

void runDedicateGuestVlanRangePostiveTest() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runDedicateGuestVlanRangePostiveTest");
    Field dedicateVlanField = _dedicateGuestVlanRangeClass.getDeclaredField("vlan");
    dedicateVlanField.setAccessible(true);
    dedicateVlanField.set(dedicateGuestVlanRangesCmd, "2-5");
    PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L, "2-5", "200", 1L, null, "testphysicalnetwork");
    physicalNetwork.addIsolationMethod("VLAN");
    AccountGuestVlanMapVO accountGuestVlanMapVO = new AccountGuestVlanMapVO(1L, 1L);
    when(networkService._physicalNetworkDao.findById(anyLong())).thenReturn(physicalNetwork);
    when(networkService._datacneterVnet.listAllocatedVnetsInRange(anyLong(), anyLong(), anyInt(), anyInt())).thenReturn(null);
    when(networkService._accountGuestVlanMapDao.listAccountGuestVlanMapsByPhysicalNetwork(anyLong())).thenReturn(null);
    when(networkService._accountGuestVlanMapDao.persist(any(AccountGuestVlanMapVO.class))).thenReturn(accountGuestVlanMapVO);
    when(networkService._datacneterVnet.update(anyLong(), any(DataCenterVnetVO.class))).thenReturn(true);
    List<DataCenterVnetVO> dataCenterVnetList = new ArrayList<DataCenterVnetVO>();
    DataCenterVnetVO dataCenterVnetVO = new DataCenterVnetVO("2-5", 1L, 1L);
    dataCenterVnetList.add(dataCenterVnetVO);
    when(networkService._datacneterVnet.findVnet(anyLong(), anyString())).thenReturn(dataCenterVnetList);
    try {
        GuestVlan result = networkService.dedicateGuestVlanRange(dedicateGuestVlanRangesCmd);
        Assert.assertNotNull(result);
    } catch (Exception e) {
        s_logger.info("exception in testing runDedicateGuestVlanRangePostiveTest message: " + e.toString());
    } finally {
        txn.close("runDedicateGuestRangePostiveTest");
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Field(java.lang.reflect.Field) AccountGuestVlanMapVO(com.cloud.network.dao.AccountGuestVlanMapVO) DataCenterVnetVO(com.cloud.dc.DataCenterVnetVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList)

Example 58 with PhysicalNetworkVO

use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.

the class DedicateGuestVlanRangesTest method runDedicateGuestVlanRangePartiallyDedicated.

void runDedicateGuestVlanRangePartiallyDedicated() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runDedicateGuestVlanRangePartiallyDedicated");
    Field dedicateVlanField = _dedicateGuestVlanRangeClass.getDeclaredField("vlan");
    dedicateVlanField.setAccessible(true);
    dedicateVlanField.set(dedicateGuestVlanRangesCmd, "2-5");
    PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L, "2-5", "200", 1L, null, "testphysicalnetwork");
    physicalNetwork.addIsolationMethod("VLAN");
    when(networkService._physicalNetworkDao.findById(anyLong())).thenReturn(physicalNetwork);
    when(networkService._datacneterVnet.listAllocatedVnetsInRange(anyLong(), anyLong(), anyInt(), anyInt())).thenReturn(null);
    List<AccountGuestVlanMapVO> guestVlanMaps = new ArrayList<AccountGuestVlanMapVO>();
    AccountGuestVlanMapVO accountGuestVlanMap = new AccountGuestVlanMapVO(2L, 1L);
    accountGuestVlanMap.setGuestVlanRange("4-8");
    guestVlanMaps.add(accountGuestVlanMap);
    when(networkService._accountGuestVlanMapDao.listAccountGuestVlanMapsByPhysicalNetwork(anyLong())).thenReturn(guestVlanMaps);
    try {
        networkService.dedicateGuestVlanRange(dedicateGuestVlanRangesCmd);
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage().contains("Vlan range is already dedicated"));
    } finally {
        txn.close("runDedicateGuestVlanRangePartiallyDedicated");
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Field(java.lang.reflect.Field) AccountGuestVlanMapVO(com.cloud.network.dao.AccountGuestVlanMapVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList)

Example 59 with PhysicalNetworkVO

use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.

the class ConfigurationManagerTest method checkIfZoneIsDeletableFailureOnPhysicalNetworkTest.

@Test(expected = CloudRuntimeException.class)
public void checkIfZoneIsDeletableFailureOnPhysicalNetworkTest() {
    PhysicalNetworkVO physicalNetworkVO = Mockito.mock(PhysicalNetworkVO.class);
    ArrayList<PhysicalNetworkVO> arrayList = new ArrayList<PhysicalNetworkVO>();
    arrayList.add(physicalNetworkVO);
    Mockito.when(_hostDao.listByDataCenterId(anyLong())).thenReturn(new ArrayList<HostVO>());
    Mockito.when(_podDao.listByDataCenterId(anyLong())).thenReturn(new ArrayList<HostPodVO>());
    Mockito.when(_privateIpAddressDao.countIPs(anyLong(), anyBoolean())).thenReturn(0);
    Mockito.when(_publicIpAddressDao.countIPs(anyLong(), anyBoolean())).thenReturn(0);
    Mockito.when(_vmInstanceDao.listByZoneId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
    Mockito.when(_volumeDao.findByDc(anyLong())).thenReturn(new ArrayList<VolumeVO>());
    Mockito.when(_physicalNetworkDao.listByZone(anyLong())).thenReturn(arrayList);
    configurationMgr.checkIfZoneIsDeletable(new Random().nextLong());
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) Random(java.util.Random) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) Test(org.junit.Test)

Example 60 with PhysicalNetworkVO

use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.

the class NuageVspManagerImpl method updateNuageVspDevice.

@Override
public NuageVspDeviceVO updateNuageVspDevice(UpdateNuageVspDeviceCmd command) {
    NuageVspResource resource = new NuageVspResource();
    final String deviceName = Network.Provider.NuageVsp.getName();
    ExternalNetworkDeviceManager.NetworkDevice networkDevice = ExternalNetworkDeviceManager.NetworkDevice.getNetworkDevice(deviceName);
    final Long physicalNetworkId = command.getPhysicalNetworkId();
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }
    final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
    if (ntwkSvcProvider == null) {
        throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " + physicalNetworkId + "to add this device");
    }
    if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
        throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " + physicalNetworkId + "to add this device");
    }
    HostVO nuageVspHost = null;
    NuageVspDeviceVO nuageVspDevice = null;
    List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
    if (nuageVspDevices == null || nuageVspDevices.isEmpty()) {
        throw new CloudRuntimeException("Nuage VSD is not configured on physical network " + physicalNetworkId);
    } else {
        nuageVspDevice = nuageVspDevices.iterator().next();
        nuageVspHost = _hostDao.findById(nuageVspDevice.getHostId());
        _hostDao.loadDetails(nuageVspHost);
    }
    boolean resourceConfigurationChanged = false;
    NuageVspResourceConfiguration resourceConfiguration = NuageVspResourceConfiguration.fromConfiguration(nuageVspHost.getDetails());
    if (!Strings.isNullOrEmpty(command.getHostName()) && !command.getHostName().equals(resourceConfiguration.hostName())) {
        resourceConfiguration.hostName(command.getHostName());
        resourceConfigurationChanged = true;
    }
    if (!Strings.isNullOrEmpty(command.getUserName()) && !command.getUserName().equals(resourceConfiguration.cmsUser())) {
        resourceConfiguration.cmsUser(command.getUserName());
        resourceConfigurationChanged = true;
    }
    if (!Strings.isNullOrEmpty(command.getPassword())) {
        String encodedNewPassword = NuageVspUtil.encodePassword(command.getPassword());
        if (!encodedNewPassword.equals(resourceConfiguration.cmsUserPassword())) {
            resourceConfiguration.cmsUserPassword(encodedNewPassword);
            resourceConfigurationChanged = true;
        }
    }
    if (command.getPort() != null && command.getPort() != Integer.parseInt(resourceConfiguration.port())) {
        resourceConfiguration.port(String.valueOf(command.getPort()));
        resourceConfigurationChanged = true;
    }
    String apiVersion = MoreObjects.firstNonNull(command.getApiVersion(), resourceConfiguration.apiVersion());
    NuageVspApiVersion apiVersionObj = NuageVspApiVersion.fromString(apiVersion);
    NuageVspApiVersion apiVersionCurrent = null;
    try {
        apiVersionCurrent = resourceConfiguration.getApiVersion();
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException("Current version is not configured correctly");
    }
    if (command.getApiVersion() != null) {
        if (apiVersionObj.compareTo(apiVersionCurrent) < 0) {
            throw new CloudRuntimeException("Downgrading is not supported");
        }
        GetApiDefaultsCommand apiDefaultsCmd = new GetApiDefaultsCommand();
        GetApiDefaultsAnswer apiDefaultsAnswer = (GetApiDefaultsAnswer) _agentMgr.easySend(nuageVspHost.getId(), apiDefaultsCmd);
        SupportedApiVersionCommand supportedApiVersionCmd = new SupportedApiVersionCommand(apiVersion);
        Answer supportedApiVersionAnswer = _agentMgr.easySend(nuageVspHost.getId(), supportedApiVersionCmd);
        if (!supportedApiVersionAnswer.getResult()) {
            throw new CloudRuntimeException("Incorrect API version: Nuage plugin only supports " + apiDefaultsAnswer.getApiDefaults().getVersion());
        }
        String apiRelativePath = "/nuage/api/" + apiVersion;
        if (!apiRelativePath.equals(resourceConfiguration.apiRelativePath())) {
            resourceConfiguration.apiVersion(apiVersion);
            resourceConfiguration.apiRelativePath(apiRelativePath);
            resourceConfigurationChanged = true;
        }
    }
    if (command.getApiRetryCount() != null && resourceConfiguration.retryCount() != null) {
        final int retryCount = Integer.parseInt(resourceConfiguration.retryCount());
        if (command.getApiRetryCount() != retryCount) {
            resourceConfiguration.retryCount(String.valueOf(command.getApiRetryCount()));
            resourceConfigurationChanged = true;
        }
    }
    if (command.getApiRetryInterval() != null && resourceConfiguration.retryInterval() != null) {
        final int apiRetryInterval = Integer.parseInt(resourceConfiguration.retryInterval());
        if (command.getApiRetryInterval() != apiRetryInterval) {
            resourceConfiguration.retryInterval(String.valueOf(command.getApiRetryInterval()));
            resourceConfigurationChanged = true;
        }
    }
    if (!resourceConfigurationChanged) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("No change in the NuageVsp device parameters. None of the NuageVsp device parameters are modified");
        }
        return nuageVspDevice;
    }
    Map<String, String> config = resourceConfiguration.build();
    try {
        resource.validate(config);
        UpdateNuageVspDeviceCommand cmd = new UpdateNuageVspDeviceCommand(resourceConfiguration);
        Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("UpdateNuageVspDeviceCommand failed");
            if ((null != answer) && (null != answer.getDetails())) {
                throw new CloudRuntimeException(answer.getDetails());
            }
        }
        _hostDetailsDao.persist(nuageVspDevice.getHostId(), config);
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException("Failed to update Nuage VSP device " + nuageVspDevice.getId() + " with parameters " + resourceConfiguration, e);
    }
    return nuageVspDevice;
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) NuageVspResourceConfiguration(com.cloud.network.resource.NuageVspResourceConfiguration) ExternalNetworkDeviceManager(org.apache.cloudstack.network.ExternalNetworkDeviceManager) GetApiDefaultsCommand(com.cloud.agent.api.manager.GetApiDefaultsCommand) SupportedApiVersionCommand(com.cloud.agent.api.manager.SupportedApiVersionCommand) UpdateNuageVspDeviceCommand(com.cloud.agent.api.manager.UpdateNuageVspDeviceCommand) HostVO(com.cloud.host.HostVO) NuageVspResource(com.cloud.network.resource.NuageVspResource) GetApiDefaultsAnswer(com.cloud.agent.api.manager.GetApiDefaultsAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) GetApiDefaultsAnswer(com.cloud.agent.api.manager.GetApiDefaultsAnswer) SyncNuageVspCmsIdAnswer(com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NuageVspApiVersion(net.nuage.vsp.acs.client.common.NuageVspApiVersion)

Aggregations

PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)112 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)50 ArrayList (java.util.ArrayList)40 NetworkVO (com.cloud.network.dao.NetworkVO)35 HostVO (com.cloud.host.HostVO)28 Test (org.junit.Test)28 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)26 Account (com.cloud.user.Account)25 DataCenter (com.cloud.dc.DataCenter)22 NetworkOffering (com.cloud.offering.NetworkOffering)22 Network (com.cloud.network.Network)18 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)18 Host (com.cloud.host.Host)15 DB (com.cloud.utils.db.DB)15 ConfigurationException (javax.naming.ConfigurationException)14 HashMap (java.util.HashMap)12 DataCenterVO (com.cloud.dc.DataCenterVO)11 Domain (com.cloud.domain.Domain)11 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)11 TransactionStatus (com.cloud.utils.db.TransactionStatus)10