use of com.cloud.exception.UnsupportedServiceException in project cosmic by MissionCriticalCloud.
the class NetworkModelImpl method canProviderSupportServices.
@Override
public void canProviderSupportServices(final Map<Provider, Set<Service>> providersMap) {
for (final Provider provider : providersMap.keySet()) {
// check if services can be turned off
final NetworkElement element = getElementImplementingProvider(provider.getName());
if (element == null) {
throw new InvalidParameterValueException("Unable to find the Network Element implementing the Service Provider '" + provider.getName() + "'");
}
final Set<Service> enabledServices = new HashSet<>();
enabledServices.addAll(providersMap.get(provider));
if (enabledServices != null && !enabledServices.isEmpty()) {
if (!element.canEnableIndividualServices()) {
final Set<Service> requiredServices = new HashSet<>();
requiredServices.addAll(element.getCapabilities().keySet());
if (requiredServices.contains(Network.Service.Gateway)) {
requiredServices.remove(Network.Service.Gateway);
}
if (requiredServices.contains(Network.Service.Firewall)) {
requiredServices.remove(Network.Service.Firewall);
}
if (enabledServices.contains(Network.Service.Firewall)) {
enabledServices.remove(Network.Service.Firewall);
}
// exclude gateway service
if (enabledServices.size() != requiredServices.size()) {
final StringBuilder servicesSet = new StringBuilder();
for (final Service requiredService : requiredServices) {
// skip gateway service as we don't allow setting it via API
if (requiredService == Service.Gateway) {
continue;
}
servicesSet.append(requiredService.getName() + ", ");
}
servicesSet.delete(servicesSet.toString().length() - 2, servicesSet.toString().length());
throw new InvalidParameterValueException("Cannot enable subset of Services, Please specify the complete list of Services: " + servicesSet.toString() + " for Service Provider " + provider.getName());
}
}
final List<String> serviceList = new ArrayList<>();
for (final Service service : enabledServices) {
// check if the service is provided by this Provider
if (!element.getCapabilities().containsKey(service)) {
throw new UnsupportedServiceException(provider.getName() + " Provider cannot provide service " + service.getName());
}
serviceList.add(service.getName());
}
if (!element.verifyServicesCombination(enabledServices)) {
throw new UnsupportedServiceException("Provider " + provider.getName() + " doesn't support services combination: " + serviceList);
}
}
}
}
use of com.cloud.exception.UnsupportedServiceException in project cosmic by MissionCriticalCloud.
the class NetworkModelImpl method checkCapabilityForProvider.
@Override
public void checkCapabilityForProvider(final Set<Provider> providers, final Service service, final Capability cap, final String capValue) {
for (final Provider provider : providers) {
final NetworkElement element = getElementImplementingProvider(provider.getName());
if (element != null) {
final Map<Service, Map<Capability, String>> elementCapabilities = element.getCapabilities();
if (elementCapabilities == null || !elementCapabilities.containsKey(service)) {
throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the element=" + element.getName() + " implementing Provider=" + provider.getName());
}
final Map<Capability, String> serviceCapabilities = elementCapabilities.get(service);
if (serviceCapabilities == null || serviceCapabilities.isEmpty()) {
throw new UnsupportedServiceException("Service " + service.getName() + " doesn't have capabilities for element=" + element.getName() + " implementing Provider=" + provider.getName());
}
final String value = serviceCapabilities.get(cap);
if (value == null || value.isEmpty()) {
throw new UnsupportedServiceException("Service " + service.getName() + " doesn't have capability " + cap.getName() + " for element=" + element.getName() + " implementing Provider=" + provider.getName());
}
if (!value.toLowerCase().contains(capValue.toLowerCase())) {
throw new UnsupportedServiceException("Service " + service.getName() + " doesn't support value " + capValue + " for capability " + cap.getName() + " for element=" + element.getName() + " implementing Provider=" + provider.getName());
}
} else {
throw new UnsupportedServiceException("Unable to find network element for provider " + provider.getName());
}
}
}
use of com.cloud.exception.UnsupportedServiceException in project cosmic by MissionCriticalCloud.
the class NetworkModelImpl method getNetworkOfferingServiceCapabilities.
@Override
public Map<Capability, String> getNetworkOfferingServiceCapabilities(final NetworkOffering offering, final 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<>();
// get the Provider for this Service for this offering
final 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
final 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?
final NetworkElement element = getElementImplementingProvider(provider);
if (element != null) {
final 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;
}
use of com.cloud.exception.UnsupportedServiceException in project cosmic by MissionCriticalCloud.
the class NetworkModelImpl method getNetworkServiceCapabilities.
@Override
public Map<Capability, String> getNetworkServiceCapabilities(final long networkId, final Service service) {
if (!areServicesSupportedInNetwork(networkId, service)) {
// addProxyObject with hardcoded tablename. Or we should probably look up the correct dao proxy object.
throw new UnsupportedServiceException("Service " + service.getName() + " is not supported in the network id=" + networkId);
}
Map<Capability, String> serviceCapabilities = new HashMap<>();
// get the Provider for this Service for this offering
final String provider = _ntwkSrvcDao.getProviderForServiceInNetwork(networkId, service);
final NetworkElement element = getElementImplementingProvider(provider);
if (element != null) {
final Map<Service, Map<Capability, String>> elementCapabilities = element.getCapabilities();
if (elementCapabilities == null || !elementCapabilities.containsKey(service)) {
throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the element=" + element.getName() + " implementing Provider=" + provider);
}
serviceCapabilities = elementCapabilities.get(service);
}
return serviceCapabilities;
}
use of com.cloud.exception.UnsupportedServiceException in project cloudstack by apache.
the class UserVmManagerImpl method unmanageUserVM.
@Override
public boolean unmanageUserVM(Long vmId) {
UserVmVO vm = _vmDao.findById(vmId);
if (vm == null || vm.getRemoved() != null) {
throw new InvalidParameterValueException("Unable to find a VM with ID = " + vmId);
}
vm = _vmDao.acquireInLockTable(vm.getId());
boolean result;
try {
if (vm.getState() != State.Running && vm.getState() != State.Stopped) {
s_logger.debug("VM ID = " + vmId + " is not running or stopped, cannot be unmanaged");
return false;
}
if (vm.getHypervisorType() != Hypervisor.HypervisorType.VMware) {
throw new UnsupportedServiceException("Unmanaging a VM is currently allowed for VMware VMs only");
}
List<VolumeVO> volumes = _volsDao.findByInstance(vm.getId());
checkUnmanagingVMOngoingVolumeSnapshots(vm);
checkUnmanagingVMVolumes(vm, volumes);
result = _itMgr.unmanage(vm.getUuid());
if (result) {
cleanupUnmanageVMResources(vm.getId());
unmanageVMFromDB(vm.getId());
publishUnmanageVMUsageEvents(vm, volumes);
} else {
throw new CloudRuntimeException("Error while unmanaging VM: " + vm.getUuid());
}
} catch (Exception e) {
s_logger.error("Could not unmanage VM " + vm.getUuid(), e);
throw new CloudRuntimeException(e);
} finally {
_vmDao.releaseFromLockTable(vm.getId());
}
return true;
}
Aggregations