Search in sources :

Example 16 with PhysicalNetworkServiceProviderVO

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

the class VirtualRouterElementTest method mockDAOs.

/**
     * @param network
     */
private void mockDAOs(final NetworkVO network, final NetworkOfferingVO offering) {
    when(_networkDao.acquireInLockTable(network.getId(), NetworkOrchestrationService.NetworkLockTimeout.value())).thenReturn(network);
    when(_networksDao.acquireInLockTable(network.getId(), NetworkOrchestrationService.NetworkLockTimeout.value())).thenReturn(network);
    when(_physicalProviderDao.findByServiceProvider(0L, "VirtualRouter")).thenReturn(new PhysicalNetworkServiceProviderVO());
    when(_vrProviderDao.findByNspIdAndType(0L, Type.VirtualRouter)).thenReturn(new VirtualRouterProviderVO());
    when(_networkOfferingDao.findById(0L)).thenReturn(offering);
    // watchit: (in this test) there can be only one
    when(_routerDao.getNextInSequence(Long.class, "id")).thenReturn(0L);
    final ServiceOfferingVO svcoff = new ServiceOfferingVO("name", /* cpu */
    1, /* ramsize */
    1024 * 1024, /* (clock?)speed */
    1024 * 1024 * 1024, /* rateMbps */
    1, /* multicastRateMbps */
    0, /* offerHA */
    false, "displayText", ProvisioningType.THIN, /* useLocalStorage */
    false, /* recreatable */
    false, "tags", /* systemUse */
    false, VirtualMachine.Type.DomainRouter, /* defaultUse */
    false);
    when(_serviceOfferingDao.findById(0L)).thenReturn(svcoff);
    when(_serviceOfferingDao.findByName(Matchers.anyString())).thenReturn(svcoff);
    final DomainRouterVO router = new DomainRouterVO(/* id */
    1L, /* serviceOfferingId */
    1L, /* elementId */
    0L, "name", /* templateId */
    0L, HypervisorType.XenServer, /* guestOSId */
    0L, /* domainId */
    0L, /* accountId */
    1L, /* userId */
    1L, /* isRedundantRouter */
    false, RedundantState.UNKNOWN, /* haEnabled */
    false, /* stopPending */
    false, /* vpcId */
    null);
    final DomainRouterVO routerNeedUpdateBackup = new DomainRouterVO(/* id */
    2L, /* serviceOfferingId */
    1L, /* elementId */
    0L, "name", /* templateId */
    0L, HypervisorType.XenServer, /* guestOSId */
    0L, /* domainId */
    0L, /* accountId */
    1L, /* userId */
    1L, /* isRedundantRouter */
    false, RedundantState.BACKUP, /* haEnabled */
    false, /* stopPending */
    false, /* vpcId */
    null);
    routerNeedUpdateBackup.setUpdateState(VirtualRouter.UpdateState.UPDATE_NEEDED);
    final DomainRouterVO routerNeedUpdateMaster = new DomainRouterVO(/* id */
    3L, /* serviceOfferingId */
    1L, /* elementId */
    0L, "name", /* templateId */
    0L, HypervisorType.XenServer, /* guestOSId */
    0L, /* domainId */
    0L, /* accountId */
    1L, /* userId */
    1L, /* isRedundantRouter */
    false, RedundantState.MASTER, /* haEnabled */
    false, /* stopPending */
    false, /* vpcId */
    null);
    routerNeedUpdateMaster.setUpdateState(VirtualRouter.UpdateState.UPDATE_NEEDED);
    final DomainRouterVO routerUpdateComplete = new DomainRouterVO(/* id */
    4L, /* serviceOfferingId */
    1L, /* elementId */
    0L, "name", /* templateId */
    0L, HypervisorType.XenServer, /* guestOSId */
    0L, /* domainId */
    0L, /* accountId */
    1L, /* userId */
    1L, /* isRedundantRouter */
    false, RedundantState.UNKNOWN, /* haEnabled */
    false, /* stopPending */
    false, /* vpcId */
    null);
    routerUpdateComplete.setUpdateState(VirtualRouter.UpdateState.UPDATE_COMPLETE);
    final DomainRouterVO routerUpdateInProgress = new DomainRouterVO(/* id */
    5L, /* serviceOfferingId */
    1L, /* elementId */
    0L, "name", /* templateId */
    0L, HypervisorType.XenServer, /* guestOSId */
    0L, /* domainId */
    0L, /* accountId */
    1L, /* userId */
    1L, /* isRedundantRouter */
    false, RedundantState.UNKNOWN, /* haEnabled */
    false, /* stopPending */
    false, /* vpcId */
    null);
    routerUpdateInProgress.setUpdateState(VirtualRouter.UpdateState.UPDATE_IN_PROGRESS);
    List<DomainRouterVO> routerList1 = new ArrayList<>();
    routerList1.add(routerUpdateComplete);
    routerList1.add(routerNeedUpdateBackup);
    routerList1.add(routerNeedUpdateMaster);
    routerList1.add(routerUpdateInProgress);
    List<DomainRouterVO> routerList2 = new ArrayList<>();
    routerList2.add(routerUpdateComplete);
    routerList2.add(routerNeedUpdateBackup);
    routerList2.add(routerNeedUpdateMaster);
    List<DomainRouterVO> routerList3 = new ArrayList<>();
    routerList3.add(routerUpdateComplete);
    routerList3.add(routerUpdateInProgress);
    when(_routerDao.getNextInSequence(Long.class, "id")).thenReturn(1L);
    when(_templateDao.findRoutingTemplate(HypervisorType.XenServer, "SystemVM Template (XenServer)")).thenReturn(new VMTemplateVO());
    when(_routerDao.persist(any(DomainRouterVO.class))).thenReturn(router);
    when(_routerDao.findById(router.getId())).thenReturn(router);
    when(_routerDao.listByNetworkAndRole(1l, VirtualRouter.Role.VIRTUAL_ROUTER)).thenReturn(routerList1);
    when(_routerDao.listByNetworkAndRole(2l, VirtualRouter.Role.VIRTUAL_ROUTER)).thenReturn(routerList2);
    when(_routerDao.listByNetworkAndRole(3l, VirtualRouter.Role.VIRTUAL_ROUTER)).thenReturn(routerList1);
    when(_routerDao.listByNetworkAndRole(6l, VirtualRouter.Role.VIRTUAL_ROUTER)).thenReturn(routerList3);
    when(_networkDetailsDao.findDetail(1l, Network.updatingInSequence)).thenReturn(new NetworkDetailVO(1l, Network.updatingInSequence, "true", true));
    when(_networkDetailsDao.findDetail(2l, Network.updatingInSequence)).thenReturn(new NetworkDetailVO(2l, Network.updatingInSequence, "true", true));
    when(_networkDetailsDao.findDetail(6l, Network.updatingInSequence)).thenReturn(new NetworkDetailVO(2l, Network.updatingInSequence, "true", true));
    when(_routerDao.persist(any(DomainRouterVO.class))).thenReturn(router);
}
Also used : PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) ArrayList(java.util.ArrayList) VMTemplateVO(com.cloud.storage.VMTemplateVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) NetworkDetailVO(com.cloud.network.dao.NetworkDetailVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 17 with PhysicalNetworkServiceProviderVO

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

the class InternalLbElementTest method verifyValidProviderState.

//TEST FOR isReady() METHOD
@Test
public void verifyValidProviderState() {
    PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO();
    provider = setId(provider, validElId);
    boolean isReady = _lbEl.isReady(provider);
    assertTrue("Valid provider is returned as not ready", isReady);
}
Also used : PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) Test(org.junit.Test)

Example 18 with PhysicalNetworkServiceProviderVO

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

the class InternalLbElementTest method verifyNonExistingProviderState.

@Test
public void verifyNonExistingProviderState() {
    PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO();
    provider = setId(provider, nonExistingElId);
    boolean isReady = _lbEl.isReady(provider);
    assertFalse("Non existing provider is returned as ready", isReady);
}
Also used : PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) Test(org.junit.Test)

Example 19 with PhysicalNetworkServiceProviderVO

use of com.cloud.network.dao.PhysicalNetworkServiceProviderVO 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)

Example 20 with PhysicalNetworkServiceProviderVO

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

the class CiscoVnmcElement method addCiscoVnmcResource.

@Override
public CiscoVnmcController addCiscoVnmcResource(AddCiscoVnmcResourceCmd cmd) {
    final String deviceName = Provider.CiscoVnmc.getName();
    NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    CiscoVnmcController ciscoVnmcResource = null;
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }
    long zoneId = physicalNetwork.getDataCenterId();
    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");
    } else 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");
    }
    if (_ciscoVnmcDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
        throw new CloudRuntimeException("A Cisco Vnmc device is already configured on this physical network");
    }
    Map<String, String> params = new HashMap<String, String>();
    params.put("guid", UUID.randomUUID().toString());
    params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
    params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
    params.put("name", "Cisco VNMC Controller - " + cmd.getHost());
    params.put("ip", cmd.getHost());
    params.put("username", cmd.getUsername());
    params.put("password", cmd.getPassword());
    Map<String, Object> hostdetails = new HashMap<String, Object>();
    hostdetails.putAll(params);
    ServerResource resource = new CiscoVnmcResource();
    try {
        resource.configure(cmd.getHost(), hostdetails);
        final Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.ExternalFirewall, params);
        if (host != null) {
            return Transaction.execute(new TransactionCallback<CiscoVnmcController>() {

                @Override
                public CiscoVnmcController doInTransaction(TransactionStatus status) {
                    CiscoVnmcController ciscoVnmcResource = new CiscoVnmcControllerVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
                    _ciscoVnmcDao.persist((CiscoVnmcControllerVO) ciscoVnmcResource);
                    DetailVO detail = new DetailVO(host.getId(), "deviceid", String.valueOf(ciscoVnmcResource.getId()));
                    _hostDetailsDao.persist(detail);
                    return ciscoVnmcResource;
                }
            });
        } else {
            throw new CloudRuntimeException("Failed to add Cisco Vnmc device due to internal error.");
        }
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) NetworkDevice(org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice) ServerResource(com.cloud.resource.ServerResource) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) ConfigurationException(javax.naming.ConfigurationException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CiscoVnmcResource(com.cloud.network.resource.CiscoVnmcResource) CiscoVnmcController(com.cloud.network.cisco.CiscoVnmcController) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO)

Aggregations

PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)33 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)19 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)15 Host (com.cloud.host.Host)13 ConfigurationException (javax.naming.ConfigurationException)11 DB (com.cloud.utils.db.DB)10 HashMap (java.util.HashMap)10 TransactionStatus (com.cloud.utils.db.TransactionStatus)9 NetworkDevice (org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice)9 HostVO (com.cloud.host.HostVO)8 ServerResource (com.cloud.resource.ServerResource)8 ArrayList (java.util.ArrayList)8 DetailVO (com.cloud.host.DetailVO)7 Test (org.junit.Test)6 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)5 URI (java.net.URI)5 Map (java.util.Map)5 ActionEvent (com.cloud.event.ActionEvent)4 DataCenterVO (com.cloud.dc.DataCenterVO)3