Search in sources :

Example 66 with InvalidParameterValueException

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

the class UpdateSnapshotPolicyCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    SnapshotPolicy policy = _entityMgr.findById(SnapshotPolicy.class, getId());
    if (policy == null) {
        throw new InvalidParameterValueException("Invalid snapshot policy id was provided");
    }
    Volume volume = _responseGenerator.findVolumeById(policy.getVolumeId());
    if (volume == null) {
        throw new InvalidParameterValueException("Snapshot policy's volume id doesnt exist");
    } else {
        return volume.getAccountId();
    }
}
Also used : SnapshotPolicy(com.cloud.storage.snapshot.SnapshotPolicy) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Volume(com.cloud.storage.Volume)

Example 67 with InvalidParameterValueException

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

the class CreateTemplateCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    Long volumeId = getVolumeId();
    Long snapshotId = getSnapshotId();
    Account callingAccount = CallContext.current().getCallingAccount();
    if (volumeId != null) {
        Volume volume = _entityMgr.findById(Volume.class, volumeId);
        if (volume != null) {
            _accountService.checkAccess(callingAccount, SecurityChecker.AccessType.UseEntry, false, volume);
        } else {
            throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
        }
    } else {
        Snapshot snapshot = _entityMgr.findById(Snapshot.class, snapshotId);
        if (snapshot != null) {
            _accountService.checkAccess(callingAccount, SecurityChecker.AccessType.UseEntry, false, snapshot);
        } else {
            throw new InvalidParameterValueException("Unable to find snapshot by id=" + snapshotId);
        }
    }
    if (projectId != null) {
        final Project project = _projectService.getProject(projectId);
        if (project != null) {
            if (project.getState() == Project.State.Active) {
                Account projectAccount = _accountService.getAccount(project.getProjectAccountId());
                _accountService.checkAccess(callingAccount, SecurityChecker.AccessType.UseEntry, false, projectAccount);
                return project.getProjectAccountId();
            } else {
                final PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active");
                ex.addProxyObject(project.getUuid(), "projectId");
                throw ex;
            }
        } else {
            throw new InvalidParameterValueException("Unable to find project by id");
        }
    }
    return callingAccount.getId();
}
Also used : Account(com.cloud.user.Account) Snapshot(com.cloud.storage.Snapshot) Project(com.cloud.projects.Project) Volume(com.cloud.storage.Volume) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Example 68 with InvalidParameterValueException

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

the class F5ExternalLoadBalancerElement method listF5LoadBalancers.

@Override
public List<ExternalLoadBalancerDeviceVO> listF5LoadBalancers(ListF5LoadBalancersCmd cmd) {
    Long physcialNetworkId = cmd.getPhysicalNetworkId();
    Long lbDeviceId = cmd.getLoadBalancerDeviceId();
    PhysicalNetworkVO pNetwork = null;
    List<ExternalLoadBalancerDeviceVO> lbDevices = new ArrayList<ExternalLoadBalancerDeviceVO>();
    if (physcialNetworkId == null && lbDeviceId == null) {
        throw new InvalidParameterValueException("Either physical network Id or load balancer device Id must be specified");
    }
    if (lbDeviceId != null) {
        ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
        if (lbDeviceVo == null || !lbDeviceVo.getDeviceName().equalsIgnoreCase(NetworkDevice.F5BigIpLoadBalancer.getName())) {
            throw new InvalidParameterValueException("Could not find F5 load balancer device with ID: " + lbDeviceId);
        }
        lbDevices.add(lbDeviceVo);
        return lbDevices;
    }
    if (physcialNetworkId != null) {
        pNetwork = _physicalNetworkDao.findById(physcialNetworkId);
        if (pNetwork == null) {
            throw new InvalidParameterValueException("Could not find phyical network with ID: " + physcialNetworkId);
        }
        lbDevices = _lbDeviceDao.listByPhysicalNetworkAndProvider(physcialNetworkId, Provider.F5BigIp.getName());
        return lbDevices;
    }
    return null;
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList)

Example 69 with InvalidParameterValueException

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

the class InternalLoadBalancerElement method addInternalLoadBalancerElement.

@Override
public VirtualRouterProvider addInternalLoadBalancerElement(long ntwkSvcProviderId) {
    VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(ntwkSvcProviderId, Type.InternalLbVm);
    if (element != null) {
        s_logger.debug("There is already an " + getName() + " with service provider id " + ntwkSvcProviderId);
        return null;
    }
    PhysicalNetworkServiceProvider provider = _pNtwkSvcProviderDao.findById(ntwkSvcProviderId);
    if (provider == null || !provider.getProviderName().equalsIgnoreCase(getName())) {
        throw new InvalidParameterValueException("Invalid network service provider is specified");
    }
    element = new VirtualRouterProviderVO(ntwkSvcProviderId, Type.InternalLbVm);
    element = _vrProviderDao.persist(element);
    return element;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) VirtualRouterProviderVO(com.cloud.network.element.VirtualRouterProviderVO) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider)

Example 70 with InvalidParameterValueException

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

the class GloboDnsElement method addGloboDnsHost.

@Override
@DB
public Host addGloboDnsHost(Long physicalNetworkId, final String username, final String password, String url) {
    if (username == null || username.trim().isEmpty()) {
        throw new InvalidParameterValueException("Invalid username: " + username);
    }
    if (password == null || password.trim().isEmpty()) {
        throw new InvalidParameterValueException("Invalid password: " + password);
    }
    if (url == null || url.trim().isEmpty()) {
        throw new InvalidParameterValueException("Invalid url: " + url);
    }
    // validate physical network and zone
    // Check if physical network exists
    PhysicalNetwork pNtwk = null;
    if (physicalNetworkId != null) {
        pNtwk = _physicalNetworkDao.findById(physicalNetworkId);
        if (pNtwk == null) {
            throw new InvalidParameterValueException("Unable to find a physical network having the specified physical network id");
        }
    } else {
        throw new InvalidParameterValueException("Invalid physicalNetworkId: " + physicalNetworkId);
    }
    final Long zoneId = pNtwk.getDataCenterId();
    final Map<String, String> params = new HashMap<String, String>();
    params.put("guid", "globodns-" + String.valueOf(zoneId));
    params.put("zoneId", String.valueOf(zoneId));
    params.put("name", Provider.GloboDns.getName());
    params.put("url", url);
    params.put("username", username);
    params.put("password", password);
    final Map<String, Object> hostDetails = new HashMap<String, Object>();
    hostDetails.putAll(params);
    Host host = Transaction.execute(new TransactionCallbackWithException<Host, CloudRuntimeException>() {

        @Override
        public Host doInTransaction(TransactionStatus status) throws CloudRuntimeException {
            try {
                GloboDnsResource resource = new GloboDnsResource();
                resource.configure(Provider.GloboDns.getName(), hostDetails);
                Host host = _resourceMgr.addHost(zoneId, resource, resource.getType(), params);
                if (host == null) {
                    throw new CloudRuntimeException("Failed to add GloboDNS host");
                }
                // Validate username and password by logging in
                SignInCommand cmd = new SignInCommand(username, password);
                Answer answer = callCommand(cmd, zoneId);
                if (answer == null || !answer.getResult()) {
                    // Could not sign in on GloboDNS
                    throw new ConfigurationException("Could not sign in on GloboDNS. Please verify URL, username and password.");
                }
                return host;
            } catch (ConfigurationException e) {
                throw new CloudRuntimeException(e);
            }
        }
    });
    return host;
}
Also used : SignInCommand(com.globo.globodns.cloudstack.commands.SignInCommand) HashMap(java.util.HashMap) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) GloboDnsResource(com.globo.globodns.cloudstack.resource.GloboDnsResource) Answer(com.cloud.agent.api.Answer) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PhysicalNetwork(com.cloud.network.PhysicalNetwork) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DB(com.cloud.utils.db.DB)

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