use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class DeleteAlertsCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
if (ids == null && type == null && endDate == null) {
throw new InvalidParameterValueException("either ids, type or enddate must be specified");
} else if (startDate != null && endDate == null) {
throw new InvalidParameterValueException("enddate must be specified with startdate parameter");
}
final boolean result = _mgr.deleteAlerts(this);
if (result) {
final SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to delete Alerts, one or more parameters has invalid values");
}
}
use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class AssociateIPAddrCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
final Account caller = CallContext.current().getCallingAccount();
if (accountName != null && domainId != null) {
final Account account = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
return account.getId();
} else if (projectId != null) {
final Project project = _projectService.getProject(projectId);
if (project != null) {
if (project.getState() == Project.State.Active) {
return project.getProjectAccountId();
} else {
throw new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active");
}
} else {
throw new InvalidParameterValueException("Unable to find project by ID");
}
} else if (networkId != null) {
final Network network = _networkService.getNetwork(networkId);
if (network == null) {
throw new InvalidParameterValueException("Unable to find network by network id specified");
}
final NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
final DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
if (zone.getNetworkType() == NetworkType.Basic && offering.getElasticIp() && offering.getElasticLb()) {
// shared network with EIP/ELB service.
return caller.getAccountId();
}
return network.getAccountId();
} else if (vpcId != null) {
final Vpc vpc = _entityMgr.findById(Vpc.class, getVpcId());
if (vpc == null) {
throw new InvalidParameterValueException("Can't find enabled VPC by ID specified");
}
return vpc.getAccountId();
}
return caller.getAccountId();
}
use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class AssociateIPAddrCmd method getNetworkId.
public Long getNetworkId() {
if (vpcId != null) {
return null;
}
if (networkId != null) {
return networkId;
}
final Long zoneId = getZoneId();
final DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
if (zone.getNetworkType() == NetworkType.Advanced) {
final List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), _accountService.getAccount(getEntityOwnerId()));
if (networks.size() == 0) {
final String domain = _domainService.getDomain(getDomainId()).getName();
throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain + " doesn't have virtual networks in zone=" + zone.getName());
}
if (networks.size() < 1) {
throw new InvalidParameterValueException("Account doesn't have any isolated networks in the zone");
} else if (networks.size() > 1) {
throw new InvalidParameterValueException("Account has more than one isolated network in the zone");
}
return networks.get(0).getId();
} else {
final Network defaultGuestNetwork = _networkService.getExclusiveGuestNetwork(zoneId);
if (defaultGuestNetwork == null) {
throw new InvalidParameterValueException("Unable to find a default guest network for account " + getAccountName() + " in domain ID=" + getDomainId());
} else {
return defaultGuestNetwork.getId();
}
}
}
use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class DisassociateIPAddrCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
if (ownerId == null) {
final IpAddress ip = getIpAddress(id);
if (ip == null) {
throw new InvalidParameterValueException("Unable to find IP address by ID=" + id);
}
ownerId = ip.getAccountId();
}
if (ownerId == null) {
return Account.ACCOUNT_ID_SYSTEM;
}
return ownerId;
}
use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class UpdateIPAddrCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
if (ownerId == null) {
final IpAddress ip = getIpAddress(id);
if (ip == null) {
throw new InvalidParameterValueException("Unable to find IP address by ID=" + id);
}
ownerId = ip.getAccountId();
}
if (ownerId == null) {
return Account.ACCOUNT_ID_SYSTEM;
}
return ownerId;
}
Aggregations