Search in sources :

Example 96 with InvalidParameterValueException

use of com.cloud.exception.InvalidParameterValueException in project cloudstack by apache.

the class ListNuageVspDevicesCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        List<NuageVspDeviceVO> nuageDevices = _nuageVspManager.listNuageVspDevices(this);
        ListResponse<NuageVspDeviceResponse> response = new ListResponse<NuageVspDeviceResponse>();
        List<NuageVspDeviceResponse> nuageDevicesResponse = new ArrayList<NuageVspDeviceResponse>();
        if (nuageDevices != null && !nuageDevices.isEmpty()) {
            for (NuageVspDeviceVO nuageDeviceVO : nuageDevices) {
                NuageVspDeviceResponse nuageDeviceResponse = _nuageVspManager.createNuageVspDeviceResponse(nuageDeviceVO);
                nuageDevicesResponse.add(nuageDeviceResponse);
            }
        }
        response.setResponses(nuageDevicesResponse);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) NuageVspDeviceResponse(com.cloud.api.response.NuageVspDeviceResponse)

Example 97 with InvalidParameterValueException

use of com.cloud.exception.InvalidParameterValueException in project cloudstack by apache.

the class NetworkServiceImpl method getNetworkOfferingServiceCapabilities.

@Override
public Map<Capability, String> getNetworkOfferingServiceCapabilities(NetworkOffering offering, Service service) {
    if (!areServicesSupportedByNetworkOffering(offering.getId(), service)) {
        // TBD: We should be sending networkOfferingId and not the offering object itself.
        throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the network offering " + offering);
    }
    Map<Capability, String> serviceCapabilities = new HashMap<Capability, String>();
    // get the Provider for this Service for this offering
    List<String> providers = _ntwkOfferingSrvcDao.listProvidersForServiceForNetworkOffering(offering.getId(), service);
    if (providers.isEmpty()) {
        // TBD: We should be sending networkOfferingId and not the offering object itself.
        throw new InvalidParameterValueException("Service " + service.getName() + " is not supported by the network offering " + offering);
    }
    // FIXME - in post 3.0 we are going to support multiple providers for the same service per network offering, so
    // we have to calculate capabilities for all of them
    String provider = providers.get(0);
    // FIXME we return the capabilities of the first provider of the service - what if we have multiple providers
    // for same Service?
    NetworkElement element = _networkModel.getElementImplementingProvider(provider);
    if (element != null) {
        Map<Service, Map<Capability, String>> elementCapabilities = element.getCapabilities();
        ;
        if (elementCapabilities == null || !elementCapabilities.containsKey(service)) {
            // TBD: We should be sending providerId and not the offering object itself.
            throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the element=" + element.getName() + " implementing Provider=" + provider);
        }
        serviceCapabilities = elementCapabilities.get(service);
    }
    return serviceCapabilities;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.network.Network.Capability) HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) 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) Map(java.util.Map) HashMap(java.util.HashMap)

Example 98 with InvalidParameterValueException

use of com.cloud.exception.InvalidParameterValueException in project cloudstack by apache.

the class NetworkServiceImpl method canUpgrade.

protected boolean canUpgrade(Network network, long oldNetworkOfferingId, long newNetworkOfferingId) {
    NetworkOffering oldNetworkOffering = _networkOfferingDao.findByIdIncludingRemoved(oldNetworkOfferingId);
    NetworkOffering newNetworkOffering = _networkOfferingDao.findById(newNetworkOfferingId);
    // can upgrade only Isolated networks
    if (oldNetworkOffering.getGuestType() != GuestType.Isolated) {
        throw new InvalidParameterValueException("NetworkOfferingId can be upgraded only for the network of type " + GuestType.Isolated);
    }
    // security group service should be the same
    if (areServicesSupportedByNetworkOffering(oldNetworkOfferingId, Service.SecurityGroup) != areServicesSupportedByNetworkOffering(newNetworkOfferingId, Service.SecurityGroup)) {
        s_logger.debug("Offerings " + newNetworkOfferingId + " and " + oldNetworkOfferingId + " have different securityGroupProperty, can't upgrade");
        return false;
    }
    // Type of the network should be the same
    if (oldNetworkOffering.getGuestType() != newNetworkOffering.getGuestType()) {
        s_logger.debug("Network offerings " + newNetworkOfferingId + " and " + oldNetworkOfferingId + " are of different types, can't upgrade");
        return false;
    }
    // tags should be the same
    if (newNetworkOffering.getTags() != null) {
        if (oldNetworkOffering.getTags() == null) {
            s_logger.debug("New network offering id=" + newNetworkOfferingId + " has tags and old network offering id=" + oldNetworkOfferingId + " doesn't, can't upgrade");
            return false;
        }
        if (!StringUtils.areTagsEqual(oldNetworkOffering.getTags(), newNetworkOffering.getTags())) {
            s_logger.debug("Network offerings " + newNetworkOffering.getUuid() + " and " + oldNetworkOffering.getUuid() + " have different tags, can't upgrade");
            return false;
        }
    }
    // Traffic types should be the same
    if (oldNetworkOffering.getTrafficType() != newNetworkOffering.getTrafficType()) {
        s_logger.debug("Network offerings " + newNetworkOfferingId + " and " + oldNetworkOfferingId + " have different traffic types, can't upgrade");
        return false;
    }
    // specify vlan should be the same
    if (oldNetworkOffering.getSpecifyVlan() != newNetworkOffering.getSpecifyVlan()) {
        s_logger.debug("Network offerings " + newNetworkOfferingId + " and " + oldNetworkOfferingId + " have different values for specifyVlan, can't upgrade");
        return false;
    }
    // specify ipRanges should be the same
    if (oldNetworkOffering.getSpecifyIpRanges() != newNetworkOffering.getSpecifyIpRanges()) {
        s_logger.debug("Network offerings " + newNetworkOfferingId + " and " + oldNetworkOfferingId + " have different values for specifyIpRangess, can't upgrade");
        return false;
    }
    // Check all ips
    List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null);
    List<PublicIp> publicIps = new ArrayList<PublicIp>();
    if (userIps != null && !userIps.isEmpty()) {
        for (IPAddressVO userIp : userIps) {
            PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
            publicIps.add(publicIp);
        }
    }
    if (oldNetworkOffering.isConserveMode() && !newNetworkOffering.isConserveMode()) {
        if (!canIpsUsedForNonConserve(publicIps)) {
            return false;
        }
    }
    //can't update from internal LB to public LB
    if (areServicesSupportedByNetworkOffering(oldNetworkOfferingId, Service.Lb) && areServicesSupportedByNetworkOffering(newNetworkOfferingId, Service.Lb)) {
        if (oldNetworkOffering.getPublicLb() != newNetworkOffering.getPublicLb() || oldNetworkOffering.getInternalLb() != newNetworkOffering.getInternalLb()) {
            throw new InvalidParameterValueException("Original and new offerings support different types of LB - Internal vs Public," + " can't upgrade");
        }
    }
    return canIpsUseOffering(publicIps, newNetworkOfferingId);
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PublicIp(com.cloud.network.addr.PublicIp) ArrayList(java.util.ArrayList) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 99 with InvalidParameterValueException

use of com.cloud.exception.InvalidParameterValueException 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 100 with InvalidParameterValueException

use of com.cloud.exception.InvalidParameterValueException in project cloudstack by apache.

the class IpAddressManagerImpl method isPortableIpTransferableFromNetwork.

@Override
public boolean isPortableIpTransferableFromNetwork(long ipAddrId, long networkId) {
    Network network = _networksDao.findById(networkId);
    if (network == null) {
        throw new InvalidParameterValueException("Invalid network id is given");
    }
    IPAddressVO ip = _ipAddressDao.findById(ipAddrId);
    if (ip == null) {
        throw new InvalidParameterValueException("Invalid network id is given");
    }
    // Check if IP has any services (rules) associated in the network
    List<PublicIpAddress> ipList = new ArrayList<PublicIpAddress>();
    PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
    ipList.add(publicIp);
    Map<PublicIpAddress, Set<Service>> ipToServices = _networkModel.getIpToServices(ipList, false, true);
    if (!ipToServices.isEmpty()) {
        Set<Service> ipServices = ipToServices.get(publicIp);
        if (ipServices != null && !ipServices.isEmpty()) {
            return false;
        }
    }
    return true;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PublicIp(com.cloud.network.addr.PublicIp) ArrayList(java.util.ArrayList) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) RemoteAccessVpnService(com.cloud.network.vpn.RemoteAccessVpnService) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Aggregations

InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)725 Account (com.cloud.user.Account)242 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)229 ArrayList (java.util.ArrayList)186 ActionEvent (com.cloud.event.ActionEvent)171 DB (com.cloud.utils.db.DB)139 ServerApiException (org.apache.cloudstack.api.ServerApiException)110 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)94 TransactionStatus (com.cloud.utils.db.TransactionStatus)88 List (java.util.List)80 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)69 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)63 Network (com.cloud.network.Network)58 HashMap (java.util.HashMap)58 ConfigurationException (javax.naming.ConfigurationException)53 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)52 Pair (com.cloud.utils.Pair)50 HostVO (com.cloud.host.HostVO)46 NetworkVO (com.cloud.network.dao.NetworkVO)46 DataCenterVO (com.cloud.dc.DataCenterVO)44