Search in sources :

Example 6 with PhysicalNetworkServiceProviderVO

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

the class InternalLbElementTest method setUp.

@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    VirtualRouterProviderVO validElement = new VirtualRouterProviderVO(1, Type.InternalLbVm);
    validElement.setEnabled(true);
    VirtualRouterProviderVO invalidElement = new VirtualRouterProviderVO(1, Type.VirtualRouter);
    VirtualRouterProviderVO notEnabledElement = new VirtualRouterProviderVO(1, Type.InternalLbVm);
    Mockito.when(_vrProviderDao.findByNspIdAndType(validElId, Type.InternalLbVm)).thenReturn(validElement);
    Mockito.when(_vrProviderDao.findByNspIdAndType(invalidElId, Type.InternalLbVm)).thenReturn(invalidElement);
    Mockito.when(_vrProviderDao.findByNspIdAndType(notEnabledElId, Type.InternalLbVm)).thenReturn(notEnabledElement);
    Mockito.when(_vrProviderDao.persist(validElement)).thenReturn(validElement);
    Mockito.when(_vrProviderDao.findByNspIdAndType(validProviderId, Type.InternalLbVm)).thenReturn(validElement);
    PhysicalNetworkServiceProviderVO validProvider = new PhysicalNetworkServiceProviderVO(1, "InternalLoadBalancerElement");
    PhysicalNetworkServiceProviderVO invalidProvider = new PhysicalNetworkServiceProviderVO(1, "Invalid name!");
    Mockito.when(_pNtwkProviderDao.findById(validProviderId)).thenReturn(validProvider);
    Mockito.when(_pNtwkProviderDao.findById(invalidProviderId)).thenReturn(invalidProvider);
    Mockito.when(_vrProviderDao.persist(Matchers.any(VirtualRouterProviderVO.class))).thenReturn(validElement);
    DataCenterVO dc = new DataCenterVO(1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null);
    Mockito.when(_entityMgr.findById(Matchers.eq(DataCenter.class), Matchers.anyLong())).thenReturn(dc);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) DataCenter(com.cloud.dc.DataCenter) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) VirtualRouterProviderVO(com.cloud.network.element.VirtualRouterProviderVO) Before(org.junit.Before)

Example 7 with PhysicalNetworkServiceProviderVO

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

the class NuageVspManagerImpl method addNuageVspDevice.

@Override
public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
    final NuageVspResource resource = new NuageVspResource();
    final String deviceName = Network.Provider.NuageVsp.getName();
    ExternalNetworkDeviceManager.NetworkDevice networkDevice = ExternalNetworkDeviceManager.NetworkDevice.getNetworkDevice(deviceName);
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    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 (_nuageVspDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
        throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network");
    }
    // While the default VSD port is 8443, clustering via HAProxy will go over port 443 (CLOUD-58)
    int port = cmd.getPort() > 0 ? cmd.getPort() : 443;
    try {
        String apiVersion = null;
        String cmsUserPasswordBase64 = NuageVspUtil.encodePassword(cmd.getPassword());
        NuageVspResourceConfiguration resourceConfiguration = new NuageVspResourceConfiguration().guid(UUID.randomUUID().toString()).zoneId(String.valueOf(physicalNetwork.getDataCenterId())).hostName(cmd.getHostName()).cmsUser(cmd.getUserName()).cmsUserPassword(cmsUserPasswordBase64).port(String.valueOf(port)).apiVersion(NuageVspApiVersion.CURRENT.toString()).retryCount(NuageVspConstants.DEFAULT_API_RETRY_COUNT.toString()).retryInterval(NuageVspConstants.DEFAULT_API_RETRY_INTERVAL.toString()).apiRelativePath("/nuage");
        VspHost vspHost = resourceConfiguration.buildVspHost();
        NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(vspHost);
        VspApiDefaults apiDefaults = clientLoader.getNuageVspManagerClient().getApiDefaults();
        if (StringUtils.isNotBlank(cmd.getApiVersion())) {
            if (!clientLoader.getNuageVspManagerClient().isSupportedApiVersion(cmd.getApiVersion())) {
                throw new CloudRuntimeException("Unsupported API version : " + cmd.getApiVersion());
            }
            apiVersion = cmd.getApiVersion();
        } else {
            boolean apiVersionFound = false;
            Map<NuageVspApiVersion, NuageVspApiVersion.Status> supportedVersions = clientLoader.getNuageVspManagerClient().getSupportedVersions();
            for (NuageVspApiVersion selectedVersion : supportedVersions.keySet()) {
                if (supportedVersions.get(selectedVersion) == NuageVspApiVersion.Status.CURRENT) {
                    apiVersion = selectedVersion.toString();
                    apiVersionFound = true;
                    break;
                }
            }
            if (!apiVersionFound) {
                throw new CloudRuntimeException("No supported API version found!");
            }
        }
        String retryCount = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryCount(), apiDefaults.getRetryCount()));
        String retryInterval = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryInterval(), apiDefaults.getRetryInterval()));
        resourceConfiguration.apiVersion(apiVersion).apiRelativePath("/nuage/api/" + apiVersion).retryCount(retryCount).retryInterval(retryInterval);
        Map<String, String> hostDetails = resourceConfiguration.build();
        resource.configure("Nuage VSD - " + cmd.getHostName(), Maps.<String, Object>newHashMap(hostDetails));
        Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, hostDetails);
        if (host == null) {
            throw new CloudRuntimeException("Failed to add Nuage Vsp Device due to internal error.");
        }
        NuageVspDeviceVO nuageVspDevice = new NuageVspDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
        _nuageVspDao.persist(nuageVspDevice);
        DetailVO detail = new DetailVO(host.getId(), "nuagevspdeviceid", String.valueOf(nuageVspDevice.getId()));
        _hostDetailsDao.persist(detail);
        NuageVspDeviceVO matchingNuageVspDevice = findMatchingNuageVspDevice(nuageVspDevice);
        String cmsId;
        if (matchingNuageVspDevice != null) {
            cmsId = findNuageVspCmsIdForDeviceOrHost(matchingNuageVspDevice.getId(), matchingNuageVspDevice.getHostId());
        } else {
            SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.REGISTER, null);
            SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
            if (answer != null && answer.getSuccess()) {
                cmsId = answer.getNuageVspCmsId();
            } else {
                throw new CloudRuntimeException("Failed to register CMS ID");
            }
        }
        host = findNuageVspHost(nuageVspDevice.getHostId());
        registerNewNuageVspDevice(host.getId(), cmsId);
        resourceConfiguration.nuageVspCmsId(cmsId);
        resource.configure(cmd.getHostName(), Maps.<String, Object>newHashMap(resourceConfiguration.build()));
        if (matchingNuageVspDevice == null) {
            auditDomainsOnVsp((HostVO) host, true);
        }
        return nuageVspDevice;
    } catch (ConfigurationException e) {
        s_logger.error("Failed to configure Nuage VSD resource " + cmd.getHostName(), e);
        throw new CloudRuntimeException("Failed to configure Nuage VSD resource " + cmd.getHostName(), e);
    } catch (ExecutionException ee) {
        s_logger.error("Failed to add Nuage VSP device " + cmd.getHostName(), ee);
        throw new CloudRuntimeException("Failed to add Nuage VSP device " + cmd.getHostName(), ee);
    }
}
Also used : NuageVspResourceConfiguration(com.cloud.network.resource.NuageVspResourceConfiguration) VspApiDefaults(net.nuage.vsp.acs.client.api.model.VspApiDefaults) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NuageVspApiVersion(net.nuage.vsp.acs.client.common.NuageVspApiVersion) SyncNuageVspCmsIdAnswer(com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer) VspHost(net.nuage.vsp.acs.client.api.model.VspHost) ExecutionException(java.util.concurrent.ExecutionException) TransactionStatus(com.cloud.utils.db.TransactionStatus) Status(com.cloud.host.Status) NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) ExternalNetworkDeviceManager(org.apache.cloudstack.network.ExternalNetworkDeviceManager) VspHost(net.nuage.vsp.acs.client.api.model.VspHost) Host(com.cloud.host.Host) NuageVspResource(com.cloud.network.resource.NuageVspResource) DetailVO(com.cloud.host.DetailVO) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) SyncNuageVspCmsIdCommand(com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand) NuageVspPluginClientLoader(net.nuage.vsp.acs.client.api.NuageVspPluginClientLoader)

Example 8 with PhysicalNetworkServiceProviderVO

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

the class ExternalLoadBalancerDeviceManagerImpl method listExternalLoadBalancers.

@Override
public List<Host> listExternalLoadBalancers(long physicalNetworkId, String deviceName) {
    List<Host> lbHosts = new ArrayList<Host>();
    NetworkDevice lbNetworkDevice = NetworkDevice.getNetworkDevice(deviceName);
    PhysicalNetworkVO pNetwork = null;
    pNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if ((pNetwork == null) || (lbNetworkDevice == null)) {
        throw new InvalidParameterValueException("Atleast one of the required parameter physical networkId, device name is invalid.");
    }
    PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(pNetwork.getId(), lbNetworkDevice.getNetworkServiceProvder());
    // if provider not configured in to physical network, then there can be no instances
    if (ntwkSvcProvider == null) {
        return null;
    }
    List<ExternalLoadBalancerDeviceVO> lbDevices = _externalLoadBalancerDeviceDao.listByPhysicalNetworkAndProvider(physicalNetworkId, ntwkSvcProvider.getProviderName());
    for (ExternalLoadBalancerDeviceVO provderInstance : lbDevices) {
        lbHosts.add(_hostDao.findById(provderInstance.getHostId()));
    }
    return lbHosts;
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) NetworkDevice(org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice) ArrayList(java.util.ArrayList) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Host(com.cloud.host.Host)

Example 9 with PhysicalNetworkServiceProviderVO

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

the class NetworkServiceImpl method updateNetworkServiceProvider.

@Override
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_PROVIDER_UPDATE, eventDescription = "Updating physical network ServiceProvider", async = true)
public PhysicalNetworkServiceProvider updateNetworkServiceProvider(Long id, String stateStr, List<String> enabledServices) {
    PhysicalNetworkServiceProviderVO provider = _pNSPDao.findById(id);
    if (provider == null) {
        throw new InvalidParameterValueException("Network Service Provider id=" + id + "doesn't exist in the system");
    }
    NetworkElement element = _networkModel.getElementImplementingProvider(provider.getProviderName());
    if (element == null) {
        throw new InvalidParameterValueException("Unable to find the Network Element implementing the Service Provider '" + provider.getProviderName() + "'");
    }
    PhysicalNetworkServiceProvider.State state = null;
    if (stateStr != null && !stateStr.isEmpty()) {
        try {
            state = PhysicalNetworkServiceProvider.State.valueOf(stateStr);
        } catch (IllegalArgumentException ex) {
            throw new InvalidParameterValueException("Unable to resolve state '" + stateStr + "' to a supported value {Enabled or Disabled}");
        }
    }
    boolean update = false;
    if (state != null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("trying to update the state of the service provider id=" + id + " on physical network: " + provider.getPhysicalNetworkId() + " to state: " + stateStr);
        }
        switch(state) {
            case Enabled:
                if (element != null && element.isReady(provider)) {
                    provider.setState(PhysicalNetworkServiceProvider.State.Enabled);
                    update = true;
                } else {
                    throw new CloudRuntimeException("Provider is not ready, cannot Enable the provider, please configure the provider first");
                }
                break;
            case Disabled:
                // do we need to do anything for the provider instances before disabling?
                provider.setState(PhysicalNetworkServiceProvider.State.Disabled);
                update = true;
                break;
            case Shutdown:
                throw new InvalidParameterValueException("Updating the provider state to 'Shutdown' is not supported");
        }
    }
    if (enabledServices != null) {
        // check if services can be turned of
        if (!element.canEnableIndividualServices()) {
            throw new InvalidParameterValueException("Cannot update set of Services for this Service Provider '" + provider.getProviderName() + "'");
        }
        // validate Services
        List<Service> services = new ArrayList<Service>();
        for (String serviceName : enabledServices) {
            Network.Service service = Network.Service.getService(serviceName);
            if (service == null) {
                throw new InvalidParameterValueException("Invalid Network Service specified=" + serviceName);
            }
            services.add(service);
        }
        // set enabled services
        provider.setEnabledServices(services);
        update = true;
    }
    if (update) {
        _pNSPDao.update(id, provider);
    }
    return provider;
}
Also used : ArrayList(java.util.ArrayList) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) LoadBalancingRulesService(com.cloud.network.lb.LoadBalancingRulesService) SecurityGroupService(com.cloud.network.security.SecurityGroupService) ResourceLimitService(com.cloud.user.ResourceLimitService) InternalLoadBalancerElementService(org.apache.cloudstack.network.element.InternalLoadBalancerElementService) Service(com.cloud.network.Network.Service) NetworkElement(com.cloud.network.element.NetworkElement) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ActionEvent(com.cloud.event.ActionEvent)

Example 10 with PhysicalNetworkServiceProviderVO

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

the class NetworkServiceImpl method addProviderToPhysicalNetwork.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_PROVIDER_CREATE, eventDescription = "Creating Physical Network ServiceProvider", create = true)
public PhysicalNetworkServiceProvider addProviderToPhysicalNetwork(Long physicalNetworkId, String providerName, Long destinationPhysicalNetworkId, List<String> enabledServices) {
    // verify input parameters
    PhysicalNetworkVO network = _physicalNetworkDao.findById(physicalNetworkId);
    if (network == null) {
        InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system");
        ex.addProxyObject(physicalNetworkId.toString(), "physicalNetworkId");
        throw ex;
    }
    // verify input parameters
    if (destinationPhysicalNetworkId != null) {
        PhysicalNetworkVO destNetwork = _physicalNetworkDao.findById(destinationPhysicalNetworkId);
        if (destNetwork == null) {
            InvalidParameterValueException ex = new InvalidParameterValueException("Destination Physical Network with specified id doesn't exist in the system");
            ex.addProxyObject(destinationPhysicalNetworkId.toString(), "destinationPhysicalNetworkId");
            throw ex;
        }
    }
    if (providerName != null) {
        Provider provider = Network.Provider.getProvider(providerName);
        if (provider == null) {
            throw new InvalidParameterValueException("Invalid Network Service Provider=" + providerName);
        }
    }
    if (_pNSPDao.findByServiceProvider(physicalNetworkId, providerName) != null) {
        // TBD: send uuid instead of physicalNetworkId.
        throw new CloudRuntimeException("The '" + providerName + "' provider already exists on physical network : " + physicalNetworkId);
    }
    // check if services can be turned off
    NetworkElement element = _networkModel.getElementImplementingProvider(providerName);
    if (element == null) {
        throw new InvalidParameterValueException("Unable to find the Network Element implementing the Service Provider '" + providerName + "'");
    }
    List<Service> services = new ArrayList<Service>();
    if (enabledServices != null) {
        if (!element.canEnableIndividualServices()) {
            if (enabledServices.size() != element.getCapabilities().keySet().size()) {
                throw new InvalidParameterValueException("Cannot enable subset of Services, Please specify the complete list of Services for this Service Provider '" + providerName + "'");
            }
        }
        // validate Services
        boolean addGatewayService = false;
        for (String serviceName : enabledServices) {
            Network.Service service = Network.Service.getService(serviceName);
            if (service == null || service == Service.Gateway) {
                throw new InvalidParameterValueException("Invalid Network Service specified=" + serviceName);
            } else if (service == Service.SourceNat) {
                addGatewayService = true;
            }
            // check if the service is provided by this Provider
            if (!element.getCapabilities().containsKey(service)) {
                throw new InvalidParameterValueException(providerName + " Provider cannot provide this Service specified=" + serviceName);
            }
            services.add(service);
        }
        if (addGatewayService) {
            services.add(Service.Gateway);
        }
    } else {
        // enable all the default services supported by this element.
        services = new ArrayList<Service>(element.getCapabilities().keySet());
    }
    try {
        // Create the new physical network in the database
        PhysicalNetworkServiceProviderVO nsp = new PhysicalNetworkServiceProviderVO(physicalNetworkId, providerName);
        // set enabled services
        nsp.setEnabledServices(services);
        if (destinationPhysicalNetworkId != null) {
            nsp.setDestinationPhysicalNetworkId(destinationPhysicalNetworkId);
        }
        nsp = _pNSPDao.persist(nsp);
        return nsp;
    } catch (Exception ex) {
        s_logger.warn("Exception: ", ex);
        throw new CloudRuntimeException("Fail to add a provider to physical network");
    }
}
Also used : ArrayList(java.util.ArrayList) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) LoadBalancingRulesService(com.cloud.network.lb.LoadBalancingRulesService) SecurityGroupService(com.cloud.network.security.SecurityGroupService) ResourceLimitService(com.cloud.user.ResourceLimitService) InternalLoadBalancerElementService(org.apache.cloudstack.network.element.InternalLoadBalancerElementService) Service(com.cloud.network.Network.Service) InvalidParameterException(java.security.InvalidParameterException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) UnknownHostException(java.net.UnknownHostException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) Provider(com.cloud.network.Network.Provider) NetworkElement(com.cloud.network.element.NetworkElement) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

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