use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method checkIfSubsetOrSuperset.
public NetUtils.SupersetOrSubset checkIfSubsetOrSuperset(String newVlanGateway, String newVlanNetmask, final VlanVO vlan, final String startIP, final String endIP) {
if (newVlanGateway == null && newVlanNetmask == null) {
newVlanGateway = vlan.getVlanGateway();
newVlanNetmask = vlan.getVlanNetmask();
// this means he is trying to add to the existing subnet.
if (NetUtils.sameSubnet(startIP, newVlanGateway, newVlanNetmask)) {
if (NetUtils.sameSubnet(endIP, newVlanGateway, newVlanNetmask)) {
return NetUtils.SupersetOrSubset.sameSubnet;
}
}
return NetUtils.SupersetOrSubset.neitherSubetNorSuperset;
} else if (newVlanGateway == null || newVlanNetmask == null) {
throw new InvalidParameterValueException("either both netmask and gateway should be passed or both should me omited.");
} else {
if (!NetUtils.sameSubnet(startIP, newVlanGateway, newVlanNetmask)) {
throw new InvalidParameterValueException("The start ip and gateway do not belong to the same subnet");
}
if (!NetUtils.sameSubnet(endIP, newVlanGateway, newVlanNetmask)) {
throw new InvalidParameterValueException("The end ip and gateway do not belong to the same subnet");
}
}
final String cidrnew = NetUtils.getCidrFromGatewayAndNetmask(newVlanGateway, newVlanNetmask);
final String existing_cidr = NetUtils.getCidrFromGatewayAndNetmask(vlan.getVlanGateway(), vlan.getVlanNetmask());
return NetUtils.isNetworkASubsetOrSupersetOfNetworkB(cidrnew, existing_cidr);
}
use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method createServiceOffering.
protected ServiceOfferingVO createServiceOffering(final long userId, final boolean isSystem, final VirtualMachineType vmType, final String name, final Integer cpu, final Integer ramSize, final String displayText, final String provisioningType, final boolean localStorageRequired, final boolean offerHA, final boolean limitResourceUse, final boolean volatileVm, String tags, final Long domainId, final String hostTag, final Integer networkRate, final String deploymentPlanner, final Map<String, String> details, final Boolean isCustomizedIops, Long minIops, Long maxIops, Long bytesReadRate, Long bytesWriteRate, Long iopsReadRate, Long iopsWriteRate, Long iopsTotalRate, final boolean iopsRatePerGb, final Integer hypervisorSnapshotReserve) {
// Check if user exists in the system
final User user = _userDao.findById(userId);
if (user == null || user.getRemoved() != null) {
throw new InvalidParameterValueException("Unable to find active user by id " + userId);
}
final Account account = _accountDao.findById(user.getAccountId());
if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
if (domainId == null) {
throw new InvalidParameterValueException("Unable to create public service offering by id " + userId + " because it is domain-admin");
}
if (tags != null || hostTag != null) {
throw new InvalidParameterValueException("Unable to create service offering with storage tags or host tags by id " + userId + " because it is domain-admin");
}
if (!_domainDao.isChildDomain(account.getDomainId(), domainId)) {
throw new InvalidParameterValueException("Unable to create service offering by another domain admin with id " + userId);
}
} else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
throw new InvalidParameterValueException("Unable to create service offering by id " + userId + " because it is not root-admin or domain-admin");
}
final StorageProvisioningType typedProvisioningType = StorageProvisioningType.valueOf(provisioningType);
tags = StringUtils.cleanupTags(tags);
ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, networkRate, null, offerHA, limitResourceUse, volatileVm, displayText, typedProvisioningType, localStorageRequired, false, tags, isSystem, vmType, domainId, hostTag, deploymentPlanner);
if (isCustomizedIops != null) {
bytesReadRate = null;
bytesWriteRate = null;
iopsReadRate = null;
iopsWriteRate = null;
if (isCustomizedIops) {
minIops = null;
maxIops = null;
} else {
if (minIops == null && maxIops == null) {
minIops = 0L;
maxIops = 0L;
} else {
if (minIops == null || minIops <= 0) {
throw new InvalidParameterValueException("The min IOPS must be greater than 0.");
}
if (maxIops == null) {
maxIops = 0L;
}
if (minIops > maxIops) {
throw new InvalidParameterValueException("The min IOPS must be less than or equal to the max IOPS.");
}
}
}
} else {
minIops = null;
maxIops = null;
}
offering.setCustomizedIops(isCustomizedIops);
offering.setMinIops(minIops);
offering.setMaxIops(maxIops);
if (bytesReadRate != null && bytesReadRate > 0) {
offering.setBytesReadRate(bytesReadRate);
}
if (bytesWriteRate != null && bytesWriteRate > 0) {
offering.setBytesWriteRate(bytesWriteRate);
}
if (iopsReadRate != null && iopsReadRate > 0) {
offering.setIopsReadRate(iopsReadRate);
}
if (iopsWriteRate != null && iopsWriteRate > 0) {
offering.setIopsWriteRate(iopsWriteRate);
}
if (iopsTotalRate != null && iopsTotalRate > 0) {
if (iopsWriteRate != null && iopsWriteRate > 0 || iopsReadRate != null && iopsReadRate > 0) {
throw new InvalidParameterValueException("Total IOPS rate cannot be used together with IOPS read rate or IOPS write rate");
}
offering.setIopsTotalRate(iopsTotalRate);
}
if (iopsRatePerGb) {
offering.setIopsRatePerGb(iopsRatePerGb);
}
if (hypervisorSnapshotReserve != null && hypervisorSnapshotReserve < 0) {
throw new InvalidParameterValueException("If provided, Hypervisor Snapshot Reserve must be greater than or equal to 0.");
}
offering.setHypervisorSnapshotReserve(hypervisorSnapshotReserve);
List<ServiceOfferingDetailsVO> detailsVO = null;
if (details != null) {
// To have correct input, either both gpu card name and VGPU type should be passed or nothing should be passed.
// Use XOR condition to verify that.
final boolean entry1 = details.containsKey(GPU.Keys.pciDevice.toString());
final boolean entry2 = details.containsKey(GPU.Keys.vgpuType.toString());
if ((entry1 || entry2) && !(entry1 && entry2)) {
throw new InvalidParameterValueException("Please specify the pciDevice and vgpuType correctly.");
}
detailsVO = new ArrayList<>();
for (final Entry<String, String> detailEntry : details.entrySet()) {
if (detailEntry.getKey().equals(GPU.Keys.pciDevice.toString())) {
if (detailEntry.getValue() == null) {
throw new InvalidParameterValueException("Please specify a GPU Card.");
}
}
if (detailEntry.getKey().equals(GPU.Keys.vgpuType.toString())) {
if (detailEntry.getValue() == null) {
throw new InvalidParameterValueException("vGPUType value cannot be null");
}
}
detailsVO.add(new ServiceOfferingDetailsVO(offering.getId(), detailEntry.getKey(), detailEntry.getValue(), true));
}
}
if ((offering = _serviceOfferingDao.persist(offering)) != null) {
if (detailsVO != null && !detailsVO.isEmpty()) {
for (int index = 0; index < detailsVO.size(); index++) {
detailsVO.get(index).setResourceId(offering.getId());
}
_serviceOfferingDetailsDao.saveDetails(detailsVO);
}
CallContext.current().setEventDetails("Service offering id=" + offering.getId());
return offering;
} else {
return null;
}
}
use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method createNetworkOffering.
@Override
@DB
public NetworkOfferingVO createNetworkOffering(final String name, final String displayText, final TrafficType trafficType, String tags, final boolean specifyVlan, final Availability availability, final Integer networkRate, final Map<Service, Set<Provider>> serviceProviderMap, final boolean isDefault, final GuestType type, final boolean systemOnly, final Long serviceOfferingId, final Long secondaryServiceOfferingId, final boolean conserveMode, final Map<Service, Map<Capability, String>> serviceCapabilityMap, final boolean specifyIpRanges, final boolean isPersistent, final Map<NetworkOffering.Detail, String> details, final boolean egressDefaultPolicy, final Integer maxconn, final boolean enableKeepAlive) {
final String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
final int multicastRate = multicastRateStr == null ? 10 : Integer.parseInt(multicastRateStr);
tags = StringUtils.cleanupTags(tags);
// specifyVlan should always be true for Shared network offerings
if (!specifyVlan && type == GuestType.Shared) {
throw new InvalidParameterValueException("SpecifyVlan should be true if network offering's type is " + type);
}
// Nat service
if (specifyIpRanges) {
if (type == GuestType.Isolated) {
if (serviceProviderMap.containsKey(Service.SourceNat)) {
throw new InvalidParameterValueException("SpecifyIpRanges can only be true for Shared network offerings and Isolated with no SourceNat service");
}
}
} else {
if (type == GuestType.Shared) {
throw new InvalidParameterValueException("SpecifyIpRanges should always be true for Shared network offerings");
}
}
// isPersistent should always be false for Shared network Offerings
if (isPersistent && type == GuestType.Shared) {
throw new InvalidParameterValueException("isPersistent should be false if network offering's type is " + type);
}
// validate availability value
if (availability == NetworkOffering.Availability.Required) {
final boolean canOffBeRequired = type == GuestType.Isolated && serviceProviderMap.containsKey(Service.SourceNat);
if (!canOffBeRequired) {
throw new InvalidParameterValueException("Availability can be " + NetworkOffering.Availability.Required + " only for networkOfferings of type " + GuestType.Isolated + " and with " + Service.SourceNat.getName() + " enabled");
}
// only one network offering in the system can be Required
final List<NetworkOfferingVO> offerings = _networkOfferingDao.listByAvailability(Availability.Required, false);
if (!offerings.isEmpty()) {
throw new InvalidParameterValueException("System already has network offering id=" + offerings.get(0).getId() + " with availability " + Availability.Required);
}
}
boolean dedicatedLb = false;
boolean elasticLb = false;
boolean sharedSourceNat = false;
boolean redundantRouter = false;
boolean elasticIp = false;
boolean associatePublicIp = false;
boolean inline = false;
boolean publicLb = false;
boolean strechedL2Subnet = false;
if (serviceCapabilityMap != null && !serviceCapabilityMap.isEmpty()) {
final Map<Capability, String> lbServiceCapabilityMap = serviceCapabilityMap.get(Service.Lb);
if (lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) {
final String isolationCapability = lbServiceCapabilityMap.get(Capability.SupportedLBIsolation);
if (isolationCapability != null) {
_networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.SupportedLBIsolation, isolationCapability);
dedicatedLb = isolationCapability.contains("dedicated");
} else {
dedicatedLb = true;
}
final String param = lbServiceCapabilityMap.get(Capability.ElasticLb);
if (param != null) {
elasticLb = param.contains("true");
}
final String inlineMode = lbServiceCapabilityMap.get(Capability.InlineMode);
if (inlineMode != null) {
_networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.InlineMode, inlineMode);
inline = inlineMode.contains("true");
} else {
inline = false;
}
final String publicLbStr = lbServiceCapabilityMap.get(Capability.LbSchemes);
if (serviceProviderMap.containsKey(Service.Lb)) {
if (publicLbStr != null) {
_networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.LbSchemes, publicLbStr);
publicLb = publicLbStr.contains("public");
}
}
}
final Map<Capability, String> sourceNatServiceCapabilityMap = serviceCapabilityMap.get(Service.SourceNat);
if (sourceNatServiceCapabilityMap != null && !sourceNatServiceCapabilityMap.isEmpty()) {
final String sourceNatType = sourceNatServiceCapabilityMap.get(Capability.SupportedSourceNatTypes);
if (sourceNatType != null) {
_networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, Capability.SupportedSourceNatTypes, sourceNatType);
sharedSourceNat = sourceNatType.contains("perzone");
}
final String param = sourceNatServiceCapabilityMap.get(Capability.RedundantRouter);
if (param != null) {
_networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, Capability.RedundantRouter, param);
redundantRouter = param.contains("true");
}
}
final Map<Capability, String> staticNatServiceCapabilityMap = serviceCapabilityMap.get(Service.StaticNat);
if (staticNatServiceCapabilityMap != null && !staticNatServiceCapabilityMap.isEmpty()) {
final String param = staticNatServiceCapabilityMap.get(Capability.ElasticIp);
if (param != null) {
elasticIp = param.contains("true");
final String associatePublicIP = staticNatServiceCapabilityMap.get(Capability.AssociatePublicIP);
if (associatePublicIP != null) {
associatePublicIp = associatePublicIP.contains("true");
}
}
}
final Map<Capability, String> connectivityServiceCapabilityMap = serviceCapabilityMap.get(Service.Connectivity);
if (connectivityServiceCapabilityMap != null && !connectivityServiceCapabilityMap.isEmpty()) {
final String value = connectivityServiceCapabilityMap.get(Capability.StretchedL2Subnet);
if ("true".equalsIgnoreCase(value)) {
strechedL2Subnet = true;
}
}
}
if (serviceProviderMap != null && serviceProviderMap.containsKey(Service.Lb) && !publicLb) {
// if not specified, default public lb to true
publicLb = true;
}
final NetworkOfferingVO offeringFinal = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb, sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges, inline, isPersistent, associatePublicIp, publicLb, egressDefaultPolicy, strechedL2Subnet);
if (serviceOfferingId != null) {
offeringFinal.setServiceOfferingId(serviceOfferingId);
}
if (secondaryServiceOfferingId != null) {
offeringFinal.setSecondaryServiceOfferingId(secondaryServiceOfferingId);
}
// validate the details
if (details != null) {
validateNtwkOffDetails(details, serviceProviderMap);
}
return Transaction.execute(new TransactionCallback<NetworkOfferingVO>() {
@Override
public NetworkOfferingVO doInTransaction(final TransactionStatus status) {
NetworkOfferingVO offering = offeringFinal;
// 1) create network offering object
s_logger.debug("Adding network offering " + offering);
offering.setConcurrentConnections(maxconn);
offering.setKeepAliveEnabled(enableKeepAlive);
offering = _networkOfferingDao.persist(offering, details);
// 2) populate services and providers
if (serviceProviderMap != null) {
for (final Network.Service service : serviceProviderMap.keySet()) {
final Set<Provider> providers = serviceProviderMap.get(service);
if (providers != null && !providers.isEmpty()) {
boolean vpcOff = false;
for (final Network.Provider provider : providers) {
if (provider == Provider.VPCVirtualRouter) {
vpcOff = true;
}
final NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(offering.getId(), service, provider);
_ntwkOffServiceMapDao.persist(offService);
s_logger.trace("Added service for the network offering: " + offService + " with provider " + provider.getName());
}
if (vpcOff) {
final List<Service> supportedSvcs = new ArrayList<>();
supportedSvcs.addAll(serviceProviderMap.keySet());
_vpcMgr.validateNtwkOffForVpc(offering, supportedSvcs);
}
} else {
final NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(offering.getId(), service, null);
_ntwkOffServiceMapDao.persist(offService);
s_logger.trace("Added service for the network offering: " + offService + " with null provider");
}
}
}
return offering;
}
});
}
use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class DedicatedResourceManagerImpl method dedicateZone.
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_DEDICATE_RESOURCE, eventDescription = "dedicating a Zone")
public List<DedicatedResourceVO> dedicateZone(final Long zoneId, final Long domainId, final String accountName) {
Long accountId = null;
List<HostVO> hosts = null;
if (accountName != null) {
final Account caller = CallContext.current().getCallingAccount();
final Account owner = _accountMgr.finalizeOwner(caller, accountName, domainId, null);
accountId = owner.getId();
}
final List<Long> childDomainIds = getDomainChildIds(domainId);
childDomainIds.add(domainId);
checkAccountAndDomain(accountId, domainId);
final Zone zone = zoneRepository.findById(zoneId).orElse(null);
if (zone == null) {
throw new InvalidParameterValueException("Unable to find zone by id " + zoneId);
} else {
final DedicatedResourceVO dedicatedZone = _dedicatedDao.findByZoneId(zoneId);
// check if zone is dedicated
if (dedicatedZone != null) {
s_logger.error("Zone " + zone.getName() + " is already dedicated");
throw new CloudRuntimeException("Zone " + zone.getName() + " is already dedicated");
}
// check if any resource under this zone is dedicated to different account or sub-domain
final List<HostPodVO> pods = _podDao.listByDataCenterId(zone.getId());
final List<DedicatedResourceVO> podsToRelease = new ArrayList<>();
final List<DedicatedResourceVO> clustersToRelease = new ArrayList<>();
final List<DedicatedResourceVO> hostsToRelease = new ArrayList<>();
for (final HostPodVO pod : pods) {
final DedicatedResourceVO dPod = _dedicatedDao.findByPodId(pod.getId());
if (dPod != null) {
if (!(childDomainIds.contains(dPod.getDomainId()))) {
throw new CloudRuntimeException("Pod " + pod.getName() + " under this Zone " + zone.getName() + " is dedicated to different account/domain");
}
if (accountId != null) {
if (dPod.getAccountId().equals(accountId)) {
podsToRelease.add(dPod);
} else {
s_logger.error("Pod " + pod.getName() + " under this Zone " + zone.getName() + " is dedicated to different account/domain");
throw new CloudRuntimeException("Pod " + pod.getName() + " under this Zone " + zone.getName() + " is dedicated to different account/domain");
}
} else {
if (dPod.getAccountId() == null && dPod.getDomainId().equals(domainId)) {
podsToRelease.add(dPod);
}
}
}
}
for (final DedicatedResourceVO dr : podsToRelease) {
releaseDedicatedResource(null, dr.getPodId(), null, null);
}
final List<ClusterVO> clusters = _clusterDao.listClustersByDcId(zone.getId());
for (final ClusterVO cluster : clusters) {
final DedicatedResourceVO dCluster = _dedicatedDao.findByClusterId(cluster.getId());
if (dCluster != null) {
if (!(childDomainIds.contains(dCluster.getDomainId()))) {
throw new CloudRuntimeException("Cluster " + cluster.getName() + " under this Zone " + zone.getName() + " is dedicated to different account/domain");
}
if (accountId != null) {
if (dCluster.getAccountId().equals(accountId)) {
clustersToRelease.add(dCluster);
} else {
s_logger.error("Cluster " + cluster.getName() + " under this Zone " + zone.getName() + " is dedicated to different account/domain");
throw new CloudRuntimeException("Cluster " + cluster.getName() + " under this Zone " + zone.getName() + " is dedicated to different account/domain");
}
} else {
if (dCluster.getAccountId() == null && dCluster.getDomainId().equals(domainId)) {
clustersToRelease.add(dCluster);
}
}
}
}
for (final DedicatedResourceVO dr : clustersToRelease) {
releaseDedicatedResource(null, null, dr.getClusterId(), null);
}
hosts = _hostDao.listByDataCenterId(zone.getId());
for (final HostVO host : hosts) {
final DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
if (dHost != null) {
if (!(childDomainIds.contains(dHost.getDomainId()))) {
throw new CloudRuntimeException("Host " + host.getName() + " under this Zone " + zone.getName() + " is dedicated to different account/domain");
}
if (accountId != null) {
if (dHost.getAccountId().equals(accountId)) {
hostsToRelease.add(dHost);
} else {
s_logger.error("Host " + host.getName() + " under this Zone " + zone.getName() + " is dedicated to different account/domain");
throw new CloudRuntimeException("Host " + host.getName() + " under this Zone " + zone.getName() + " is dedicated to different account/domain");
}
} else {
if (dHost.getAccountId() == null && dHost.getDomainId().equals(domainId)) {
hostsToRelease.add(dHost);
}
}
}
}
for (final DedicatedResourceVO dr : hostsToRelease) {
releaseDedicatedResource(null, null, null, dr.getHostId());
}
}
checkHostsSuitabilityForExplicitDedication(accountId, childDomainIds, hosts);
final Long accountIdFinal = accountId;
return Transaction.execute(new TransactionCallback<List<DedicatedResourceVO>>() {
@Override
public List<DedicatedResourceVO> doInTransaction(final TransactionStatus status) {
// find or create the affinity group by name under this account/domain
final AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal);
if (group == null) {
s_logger.error("Unable to dedicate zone due to, failed to create dedication affinity group");
throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support.");
}
DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(zoneId, null, null, null, null, null, group.getId());
try {
dedicatedResource.setDomainId(domainId);
if (accountIdFinal != null) {
dedicatedResource.setAccountId(accountIdFinal);
}
dedicatedResource = _dedicatedDao.persist(dedicatedResource);
// save the domainId in the zone
zone.setDomainId(domainId);
zoneRepository.save(zone);
} catch (final Exception e) {
s_logger.error("Unable to dedicate zone due to " + e.getMessage(), e);
throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support.");
}
final List<DedicatedResourceVO> result = new ArrayList<>();
result.add(dedicatedResource);
return result;
}
});
}
use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class DedicatedResourceManagerImpl method listDedicatedClusters.
@Override
public Pair<List<? extends DedicatedResourceVO>, Integer> listDedicatedClusters(final ListDedicatedClustersCmd cmd) {
final Long clusterId = cmd.getClusterId();
final Long domainId = cmd.getDomainId();
final String accountName = cmd.getAccountName();
Long accountId = null;
final Long affinityGroupId = cmd.getAffinityGroupId();
if (accountName != null) {
if (domainId != null) {
final Account account = _accountDao.findActiveAccount(accountName, domainId);
if (account != null) {
accountId = account.getId();
}
} else {
throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName);
}
}
final Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedClusters(clusterId, domainId, accountId, affinityGroupId);
return new Pair<>(result.first(), result.second());
}
Aggregations