Search in sources :

Example 16 with UnsupportedServiceException

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

the class NetworkModelImpl method providerSupportsCapability.

@Override
public boolean providerSupportsCapability(Set<Provider> providers, Service service, Capability cap) {
    for (Provider provider : providers) {
        NetworkElement element = getElementImplementingProvider(provider.getName());
        if (element != null) {
            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());
            }
            Map<Capability, String> serviceCapabilities = elementCapabilities.get(service);
            if (serviceCapabilities == null || serviceCapabilities.isEmpty()) {
                throw new UnsupportedServiceException("Service " + service.getName() + " doesn't have capabilites for element=" + element.getName() + " implementing Provider=" + provider.getName());
            }
            if (serviceCapabilities.containsKey(cap)) {
                return true;
            }
        } else {
            throw new UnsupportedServiceException("Unable to find network element for provider " + provider.getName());
        }
    }
    return false;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.network.Network.Capability) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) Map(java.util.Map) HashMap(java.util.HashMap) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 17 with UnsupportedServiceException

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

the class NetworkModelImpl method checkCapabilityForProvider.

@Override
public void checkCapabilityForProvider(Set<Provider> providers, Service service, Capability cap, String capValue) {
    for (Provider provider : providers) {
        NetworkElement element = getElementImplementingProvider(provider.getName());
        if (element != null) {
            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());
            }
            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());
            }
            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());
        }
    }
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.network.Network.Capability) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) Map(java.util.Map) HashMap(java.util.HashMap) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 18 with UnsupportedServiceException

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

the class NetworkModelImpl method canProviderSupportServices.

@Override
public void canProviderSupportServices(Map<Provider, Set<Service>> providersMap) {
    for (Provider provider : providersMap.keySet()) {
        // check if services can be turned off
        NetworkElement element = getElementImplementingProvider(provider.getName());
        if (element == null) {
            throw new InvalidParameterValueException("Unable to find the Network Element implementing the Service Provider '" + provider.getName() + "'");
        }
        Set<Service> enabledServices = new HashSet<Service>();
        enabledServices.addAll(providersMap.get(provider));
        if (enabledServices != null && !enabledServices.isEmpty()) {
            if (!element.canEnableIndividualServices()) {
                Set<Service> requiredServices = new HashSet<Service>();
                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()) {
                    StringBuilder servicesSet = new StringBuilder();
                    for (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());
                }
            }
            List<String> serviceList = new ArrayList<String>();
            for (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);
            }
        }
    }
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) ArrayList(java.util.ArrayList) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider) HashSet(java.util.HashSet)

Example 19 with UnsupportedServiceException

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

the class ConfigDriveNetworkElement method postStateTransitionEvent.

@Override
public boolean postStateTransitionEvent(StateMachine2.Transition<VirtualMachine.State, VirtualMachine.Event> transition, VirtualMachine vm, boolean status, Object opaque) {
    if (transition.getToState().equals(VirtualMachine.State.Expunging) && transition.getEvent().equals(VirtualMachine.Event.ExpungeOperation)) {
        Nic nic = _networkModel.getDefaultNic(vm.getId());
        if (nic == null) {
            return true;
        }
        try {
            final Network network = _networkMgr.getNetwork(nic.getNetworkId());
            final UserDataServiceProvider userDataUpdateProvider = _networkModel.getUserDataUpdateProvider(network);
            final Provider provider = userDataUpdateProvider.getProvider();
            if (provider.equals(Provider.ConfigDrive)) {
                try {
                    return deleteConfigDriveIso(vm);
                } catch (ResourceUnavailableException e) {
                    LOG.error("Failed to delete config drive due to: ", e);
                    return false;
                }
            }
        } catch (UnsupportedServiceException usse) {
        }
    }
    return true;
}
Also used : UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) Network(com.cloud.network.Network) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) Nic(com.cloud.vm.Nic) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 20 with UnsupportedServiceException

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

the class UnmanagedVMsManagerImpl method unmanageVMInstance.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_UNMANAGE, eventDescription = "unmanaging VM", async = true)
public boolean unmanageVMInstance(long vmId) {
    VMInstanceVO vmVO = vmDao.findById(vmId);
    if (vmVO == null || vmVO.getRemoved() != null) {
        throw new InvalidParameterValueException("Could not find VM to unmanage, it is either removed or not existing VM");
    } else if (vmVO.getState() != VirtualMachine.State.Running && vmVO.getState() != VirtualMachine.State.Stopped) {
        throw new InvalidParameterValueException("VM with id = " + vmVO.getUuid() + " must be running or stopped to be unmanaged");
    } else if (vmVO.getHypervisorType() != Hypervisor.HypervisorType.VMware) {
        throw new UnsupportedServiceException("Unmanage VM is currently allowed for VMware VMs only");
    } else if (vmVO.getType() != VirtualMachine.Type.User) {
        throw new UnsupportedServiceException("Unmanage VM is currently allowed for guest VMs only");
    }
    performUnmanageVMInstancePrechecks(vmVO);
    Long hostId = findSuitableHostId(vmVO);
    String instanceName = vmVO.getInstanceName();
    if (!existsVMToUnmanage(instanceName, hostId)) {
        throw new CloudRuntimeException("VM with id = " + vmVO.getUuid() + " is not found in the hypervisor");
    }
    return userVmManager.unmanageUserVM(vmId);
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMInstanceVO(com.cloud.vm.VMInstanceVO) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

UnsupportedServiceException (com.cloud.exception.UnsupportedServiceException)22 NetworkElement (com.cloud.network.element.NetworkElement)12 HashMap (java.util.HashMap)12 Service (com.cloud.network.Network.Service)11 Map (java.util.Map)10 Capability (com.cloud.network.Network.Capability)9 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 Provider (com.cloud.network.Network.Provider)7 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)6 NetworkOrchestrationService (org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService)6 ArrayList (java.util.ArrayList)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)3 HashSet (java.util.HashSet)3 ResourceOwnerType (com.cloud.configuration.Resource.ResourceOwnerType)2 ResourceType (com.cloud.configuration.Resource.ResourceType)2 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)2 NetworkOfferingServiceMapVO (com.cloud.offerings.NetworkOfferingServiceMapVO)2 ResourceLimitService (com.cloud.user.ResourceLimitService)2