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();
}
}
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();
}
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;
}
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;
}
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;
}
Aggregations