Search in sources :

Example 6 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class NetworkModelImpl method listSupportedNetworkServiceProviders.

@Override
public List<? extends Provider> listSupportedNetworkServiceProviders(final String serviceName) {
    Network.Service service = null;
    if (serviceName != null) {
        service = Network.Service.getService(serviceName);
        if (service == null) {
            throw new InvalidParameterValueException("Invalid Network Service=" + serviceName);
        }
    }
    final Set<Provider> supportedProviders = new HashSet<>();
    if (service != null) {
        final List<Provider> providers = s_serviceToImplementedProvidersMap.get(service);
        if (providers != null && !providers.isEmpty()) {
            supportedProviders.addAll(providers);
        }
    } else {
        for (final List<Provider> pList : s_serviceToImplementedProvidersMap.values()) {
            supportedProviders.addAll(pList);
        }
    }
    return new ArrayList<>(supportedProviders);
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Network(com.cloud.legacymodel.network.Network) ArrayList(java.util.ArrayList) Service(com.cloud.legacymodel.network.Network.Service) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider) HashSet(java.util.HashSet)

Example 7 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class NetworkModelImpl method getProviderServicesMap.

Map<Provider, Set<Service>> getProviderServicesMap(final long networkId) {
    final Map<Provider, Set<Service>> map = new HashMap<>();
    final List<NetworkServiceMapVO> nsms = _ntwkSrvcDao.getServicesInNetwork(networkId);
    for (final NetworkServiceMapVO nsm : nsms) {
        Set<Service> services = map.get(Provider.getProvider(nsm.getProvider()));
        if (services == null) {
            services = new HashSet<>();
        }
        services.add(Service.getService(nsm.getService()));
        map.put(Provider.getProvider(nsm.getProvider()), services);
    }
    return map;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Service(com.cloud.legacymodel.network.Network.Service) NetworkServiceMapVO(com.cloud.network.dao.NetworkServiceMapVO) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider)

Example 8 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class NetworkModelImpl method getNetworkOfferingServiceProvidersMap.

@Override
public Map<Service, Set<Provider>> getNetworkOfferingServiceProvidersMap(final long networkOfferingId) {
    final Map<Service, Set<Provider>> serviceProviderMap = new HashMap<>();
    final List<NetworkOfferingServiceMapVO> map = _ntwkOfferingSrvcDao.listByNetworkOfferingId(networkOfferingId);
    for (final NetworkOfferingServiceMapVO instance : map) {
        final String service = instance.getService();
        Set<Provider> providers;
        providers = serviceProviderMap.get(Service.getService(service));
        if (providers == null) {
            providers = new HashSet<>();
        }
        providers.add(Provider.getProvider(instance.getProvider()));
        serviceProviderMap.put(Service.getService(service), providers);
    }
    return serviceProviderMap;
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) Set(java.util.Set) TreeSet(java.util.TreeSet) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Service(com.cloud.legacymodel.network.Network.Service) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider)

Example 9 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method destroyNetwork.

@Override
@DB
public boolean destroyNetwork(final long networkId, final ReservationContext context, final boolean forced) {
    final Account callerAccount = context.getAccount();
    NetworkVO network = _networksDao.findById(networkId);
    if (network == null) {
        s_logger.debug("Unable to find network with id: " + networkId);
        return false;
    }
    // Make sure that there are no user vms in the network that are not Expunged/Error
    final List<UserVmVO> userVms = _userVmDao.listByNetworkIdAndStates(networkId);
    for (final UserVmVO vm : userVms) {
        if (!(vm.getState() == VirtualMachine.State.Expunging && vm.getRemoved() != null)) {
            s_logger.warn("Can't delete the network, not all user vms are expunged. Vm " + vm + " is in " + vm.getState() + " state");
            return false;
        }
    }
    // Don't allow to delete network via api call when it has vms assigned to it
    final int nicCount = getActiveNicsInNetwork(networkId);
    if (nicCount > 0) {
        s_logger.debug("The network id=" + networkId + " has active Nics, but shouldn't.");
        // at this point we have already determined that there are no active user vms in network
        // if the op_networks table shows active nics, it's a bug in releasing nics updating op_networks
        _networksDao.changeActiveNicsBy(networkId, -1 * nicCount);
    }
    // In Basic zone, make sure that there are no non-removed console proxies and SSVMs using the network
    final Zone zone = _zoneRepository.findById(network.getDataCenterId()).orElse(null);
    if (zone.getNetworkType() == com.cloud.model.enumeration.NetworkType.Basic) {
        final List<VMInstanceVO> systemVms = _vmDao.listNonRemovedVmsByTypeAndNetwork(network.getId(), VirtualMachineType.ConsoleProxy, VirtualMachineType.SecondaryStorageVm);
        if (systemVms != null && !systemVms.isEmpty()) {
            s_logger.warn("Can't delete the network, not all consoleProxy/secondaryStorage vms are expunged");
            return false;
        }
    }
    // Shutdown network first
    shutdownNetwork(networkId, context, false);
    // get updated state for the network
    network = _networksDao.findById(networkId);
    if (network.getState() != Network.State.Allocated && network.getState() != Network.State.Setup && !forced) {
        s_logger.debug("Network is not not in the correct state to be destroyed: " + network.getState());
        return false;
    }
    boolean success = true;
    if (!cleanupNetworkResources(networkId, callerAccount, context.getCaller().getId())) {
        s_logger.warn("Unable to delete network id=" + networkId + ": failed to cleanup network resources");
        return false;
    }
    // get providers to destroy
    final List<Provider> providersToDestroy = getNetworkProviders(network.getId());
    for (final NetworkElement element : networkElements) {
        if (providersToDestroy.contains(element.getProvider())) {
            try {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Sending destroy to " + element);
                }
                if (!element.destroy(network, context)) {
                    success = false;
                    s_logger.warn("Unable to complete destroy of the network: failed to destroy network element " + element.getName());
                }
            } catch (final ResourceUnavailableException e) {
                s_logger.warn("Unable to complete destroy of the network due to element: " + element.getName(), e);
                success = false;
            } catch (final ConcurrentOperationException e) {
                s_logger.warn("Unable to complete destroy of the network due to element: " + element.getName(), e);
                success = false;
            } catch (final Exception e) {
                s_logger.warn("Unable to complete destroy of the network due to element: " + element.getName(), e);
                success = false;
            }
        }
    }
    if (success) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Network id=" + networkId + " is destroyed successfully, cleaning up corresponding resources now.");
        }
        final NetworkVO networkFinal = network;
        try {
            Transaction.execute(new TransactionCallbackNoReturn() {

                @Override
                public void doInTransactionWithoutResult(final TransactionStatus status) {
                    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, networkFinal.getGuruName());
                    // Deleting sync networks
                    final List<NetworkVO> syncNetworks = _networksDao.listSyncNetworksByRelatedNetwork(networkId);
                    syncNetworks.forEach(syncNetwork -> removeAndShutdownSyncNetwork(syncNetwork.getId()));
                    guru.trash(networkFinal, _networkOfferingDao.findById(networkFinal.getNetworkOfferingId()));
                    if (!deleteVlansInNetwork(networkFinal.getId(), context.getCaller().getId(), callerAccount)) {
                        s_logger.warn("Failed to delete network " + networkFinal + "; was unable to cleanup corresponding ip ranges");
                        throw new CloudRuntimeException("Failed to delete network " + networkFinal + "; was unable to cleanup corresponding ip ranges");
                    } else {
                        // commit transaction only when ips and vlans for the network are released successfully
                        try {
                            stateTransitTo(networkFinal, Event.DestroyNetwork);
                        } catch (final NoTransitionException e) {
                            s_logger.debug(e.getMessage());
                        }
                        if (_networksDao.remove(networkFinal.getId())) {
                            final NetworkDomainVO networkDomain = _networkDomainDao.getDomainNetworkMapByNetworkId(networkFinal.getId());
                            if (networkDomain != null) {
                                _networkDomainDao.remove(networkDomain.getId());
                            }
                            final NetworkAccountVO networkAccount = _networkAccountDao.getAccountNetworkMapByNetworkId(networkFinal.getId());
                            if (networkAccount != null) {
                                _networkAccountDao.remove(networkAccount.getId());
                            }
                        }
                        final NetworkOffering ntwkOff = _entityMgr.findById(NetworkOffering.class, networkFinal.getNetworkOfferingId());
                        final boolean updateResourceCount = resourceCountNeedsUpdate(ntwkOff, networkFinal.getAclType());
                        if (updateResourceCount) {
                            _resourceLimitMgr.decrementResourceCount(networkFinal.getAccountId(), ResourceType.network, networkFinal.getDisplayNetwork());
                        }
                    }
                }
            });
            if (_networksDao.findById(network.getId()) == null) {
                // remove its related ACL permission
                final Pair<Class<?>, Long> networkMsg = new Pair<>(Network.class, networkFinal.getId());
                _messageBus.publish(_name, EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, networkMsg);
            }
            return true;
        } catch (final CloudRuntimeException e) {
            s_logger.error("Failed to delete network", e);
            return false;
        }
    }
    return success;
}
Also used : PhysicalNetworkTrafficTypeDao(com.cloud.network.dao.PhysicalNetworkTrafficTypeDao) NetworkModel(com.cloud.network.NetworkModel) ConfigKey(com.cloud.framework.config.ConfigKey) HostDao(com.cloud.host.dao.HostDao) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException) VMNetworkMapVO(com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Nic(com.cloud.legacymodel.network.Nic) PodVlanMapDao(com.cloud.dc.dao.PodVlanMapDao) Scope(com.cloud.framework.config.ConfigKey.Scope) Transaction(com.cloud.utils.db.Transaction) TransactionCallbackWithExceptionNoReturn(com.cloud.utils.db.TransactionCallbackWithExceptionNoReturn) AgentManager(com.cloud.agent.AgentManager) PhysicalNetworkTrafficTypeVO(com.cloud.network.dao.PhysicalNetworkTrafficTypeVO) ReservationContext(com.cloud.vm.ReservationContext) VlanDao(com.cloud.dc.dao.VlanDao) Map(java.util.Map) NetworkServiceMapDao(com.cloud.network.dao.NetworkServiceMapDao) ZoneRepository(com.cloud.db.repository.ZoneRepository) PhysicalNetworkDao(com.cloud.network.dao.PhysicalNetworkDao) Host(com.cloud.legacymodel.dc.Host) PhysicalNetworkSetupInfo(com.cloud.legacymodel.network.PhysicalNetworkSetupInfo) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkGuru(com.cloud.network.guru.NetworkGuru) FirewallRule(com.cloud.legacymodel.network.FirewallRule) DataCenterVnetVO(com.cloud.dc.DataCenterVnetVO) NicTO(com.cloud.legacymodel.to.NicTO) TransactionStatus(com.cloud.utils.db.TransactionStatus) StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) Set(java.util.Set) StaticNatRule(com.cloud.legacymodel.network.StaticNatRule) NetworkElement(com.cloud.network.element.NetworkElement) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) Executors(java.util.concurrent.Executors) ACLType(com.cloud.legacymodel.acl.ControlledEntity.ACLType) ReservationStrategy(com.cloud.legacymodel.network.Nic.ReservationStrategy) DataCenter(com.cloud.legacymodel.dc.DataCenter) PortForwardingRulesDao(com.cloud.network.rules.dao.PortForwardingRulesDao) StaticNatRuleImpl(com.cloud.network.rules.StaticNatRuleImpl) AccountDao(com.cloud.user.dao.AccountDao) AdapterBase(com.cloud.utils.component.AdapterBase) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) IpAddressManager(com.cloud.network.IpAddressManager) NumbersUtil(com.cloud.utils.NumbersUtil) ManagerBase(com.cloud.utils.component.ManagerBase) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) StateMachine2(com.cloud.legacymodel.statemachine.StateMachine2) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine) CallContext(com.cloud.context.CallContext) Zone(com.cloud.db.model.Zone) IpDeployer(com.cloud.network.element.IpDeployer) NetworkOfferingServiceMapDao(com.cloud.offerings.dao.NetworkOfferingServiceMapDao) NicProfile(com.cloud.vm.NicProfile) ArrayList(java.util.ArrayList) Purpose(com.cloud.legacymodel.network.FirewallRule.Purpose) LinkedHashMap(java.util.LinkedHashMap) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) VlanVO(com.cloud.dc.VlanVO) ConfigurationDao(com.cloud.framework.config.dao.ConfigurationDao) DomainRouterVO(com.cloud.vm.DomainRouterVO) BroadcastDomainType(com.cloud.model.enumeration.BroadcastDomainType) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) VMInstanceDao(com.cloud.vm.dao.VMInstanceDao) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) DomainRouterDao(com.cloud.vm.dao.DomainRouterDao) MessageBus(com.cloud.framework.messagebus.MessageBus) VirtualMachineType(com.cloud.model.enumeration.VirtualMachineType) Op(com.cloud.utils.db.SearchCriteria.Op) EntityManager(com.cloud.dao.EntityManager) UserVmDao(com.cloud.vm.dao.UserVmDao) HostStatus(com.cloud.legacymodel.dc.HostStatus) InsufficientVirtualNetworkCapacityException(com.cloud.legacymodel.exceptions.InsufficientVirtualNetworkCapacityException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) NicDao(com.cloud.vm.dao.NicDao) PhysicalNetwork(com.cloud.network.PhysicalNetwork) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn) DB(com.cloud.utils.db.DB) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ManagedContextRunnable(com.cloud.common.managed.context.ManagedContextRunnable) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException) GlobalLock(com.cloud.utils.db.GlobalLock) NetworkOfferingDetailsDao(com.cloud.offerings.dao.NetworkOfferingDetailsDao) RulesManager(com.cloud.network.rules.RulesManager) CheckNetworkAnswer(com.cloud.legacymodel.communication.answer.CheckNetworkAnswer) NicSecondaryIpDao(com.cloud.vm.dao.NicSecondaryIpDao) AggregatedCommandExecutor(com.cloud.network.element.AggregatedCommandExecutor) LoggerFactory(org.slf4j.LoggerFactory) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) Service(com.cloud.legacymodel.network.Network.Service) NetworkType(com.cloud.model.enumeration.NetworkType) Networks(com.cloud.network.Networks) NetworkAccountVO(com.cloud.network.dao.NetworkAccountVO) AlertManager(com.cloud.alert.AlertManager) StateMachine2Transitions(com.cloud.utils.fsm.StateMachine2Transitions) AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) NetworkMigrationResponder(com.cloud.network.NetworkMigrationResponder) IllegalVirtualMachineException(com.cloud.legacymodel.exceptions.IllegalVirtualMachineException) DeploymentPlan(com.cloud.deploy.DeploymentPlan) VMNetworkMapDao(com.cloud.engine.cloud.entity.api.db.dao.VMNetworkMapDao) ResourceLimitService(com.cloud.user.ResourceLimitService) URI(java.net.URI) Vlan(com.cloud.legacymodel.dc.Vlan) Scheme(com.cloud.legacymodel.network.LoadBalancerContainer.Scheme) NetworkProfile(com.cloud.network.NetworkProfile) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) PublishScope(com.cloud.framework.messagebus.PublishScope) TrafficType(com.cloud.model.enumeration.TrafficType) VMInstanceVO(com.cloud.vm.VMInstanceVO) TransactionCallback(com.cloud.utils.db.TransactionCallback) DeployDestination(com.cloud.deploy.DeployDestination) IpAddress(com.cloud.network.IpAddress) VpcVirtualNetworkApplianceService(com.cloud.network.VpcVirtualNetworkApplianceService) AccountGuestVlanMapVO(com.cloud.network.dao.AccountGuestVlanMapVO) Command(com.cloud.legacymodel.communication.command.Command) AgentControlCommand(com.cloud.legacymodel.communication.command.agentcontrol.AgentControlCommand) NicVO(com.cloud.vm.NicVO) UUID(java.util.UUID) VpcManager(com.cloud.network.vpc.VpcManager) HypervisorType(com.cloud.model.enumeration.HypervisorType) PodVlanMapVO(com.cloud.dc.PodVlanMapVO) List(java.util.List) Provider(com.cloud.legacymodel.network.Network.Provider) NetworkDomainVO(com.cloud.network.dao.NetworkDomainVO) NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) User(com.cloud.legacymodel.user.User) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) Answer(com.cloud.legacymodel.communication.answer.Answer) NetUtils(com.cloud.utils.net.NetUtils) NetworkServiceMapVO(com.cloud.network.dao.NetworkServiceMapVO) NetworkDomainDao(com.cloud.network.dao.NetworkDomainDao) DataCenterVnetDao(com.cloud.dc.dao.DataCenterVnetDao) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) ResourceType(com.cloud.legacymodel.configuration.Resource.ResourceType) Event(com.cloud.legacymodel.network.Network.Event) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) SearchBuilder(com.cloud.utils.db.SearchBuilder) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand) Configurable(com.cloud.framework.config.Configurable) HashMap(java.util.HashMap) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) NetworkDao(com.cloud.network.dao.NetworkDao) ConfigurationException(javax.naming.ConfigurationException) Domain(com.cloud.legacymodel.domain.Domain) PortForwardingRuleVO(com.cloud.network.rules.PortForwardingRuleVO) JoinType(com.cloud.utils.db.JoinBuilder.JoinType) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Listener(com.cloud.agent.Listener) CheckNetworkCommand(com.cloud.legacymodel.communication.command.CheckNetworkCommand) IPAddressVO(com.cloud.network.dao.IPAddressVO) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkServiceProviderDao(com.cloud.network.dao.PhysicalNetworkServiceProviderDao) IPAddressDao(com.cloud.network.dao.IPAddressDao) GuestType(com.cloud.model.enumeration.GuestType) RedundantState(com.cloud.legacymodel.network.VirtualRouter.RedundantState) FirewallRulesDao(com.cloud.network.dao.FirewallRulesDao) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) PublicIp(com.cloud.network.addr.PublicIp) Network(com.cloud.legacymodel.network.Network) ConfigurationManager(com.cloud.configuration.ConfigurationManager) LoadBalancingRulesManager(com.cloud.network.lb.LoadBalancingRulesManager) Logger(org.slf4j.Logger) Pair(com.cloud.legacymodel.utils.Pair) NetworkACLManager(com.cloud.network.vpc.NetworkACLManager) Account(com.cloud.legacymodel.user.Account) Capability(com.cloud.legacymodel.network.Network.Capability) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) PrivateIpDao(com.cloud.network.vpc.dao.PrivateIpDao) AccountGuestVlanMapDao(com.cloud.network.dao.AccountGuestVlanMapDao) NetworkOffering(com.cloud.offering.NetworkOffering) TimeUnit(java.util.concurrent.TimeUnit) UserVmVO(com.cloud.vm.UserVmVO) RemoteAccessVpnService(com.cloud.network.vpn.RemoteAccessVpnService) NetworkOfferingDao(com.cloud.offerings.dao.NetworkOfferingDao) NetworkAccountDao(com.cloud.network.dao.NetworkAccountDao) Vpc(com.cloud.legacymodel.network.vpc.Vpc) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) FirewallManager(com.cloud.network.rules.FirewallManager) NicSecondaryIpVO(com.cloud.vm.dao.NicSecondaryIpVO) Comparator(java.util.Comparator) Collections(java.util.Collections) Account(com.cloud.legacymodel.user.Account) UserVmVO(com.cloud.vm.UserVmVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) NetworkElement(com.cloud.network.element.NetworkElement) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) NetworkDomainVO(com.cloud.network.dao.NetworkDomainVO) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.legacymodel.utils.Pair) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) Zone(com.cloud.db.model.Zone) NetworkGuru(com.cloud.network.guru.NetworkGuru) VMInstanceVO(com.cloud.vm.VMInstanceVO) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) InsufficientVirtualNetworkCapacityException(com.cloud.legacymodel.exceptions.InsufficientVirtualNetworkCapacityException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) IllegalVirtualMachineException(com.cloud.legacymodel.exceptions.IllegalVirtualMachineException) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) ConfigurationException(javax.naming.ConfigurationException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) NetworkAccountVO(com.cloud.network.dao.NetworkAccountVO) DB(com.cloud.utils.db.DB)

Example 10 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method shutdownNetworkElementsAndResources.

@Override
public boolean shutdownNetworkElementsAndResources(final ReservationContext context, final boolean cleanupElements, final Network network) {
    // get providers to shutdown
    final List<Provider> providersToShutdown = getNetworkProviders(network.getId());
    // 1) Cleanup all the rules for the network. If it fails, just log the failure and proceed with shutting down
    // the elements
    boolean cleanupResult = true;
    boolean cleanupNeeded = false;
    try {
        for (final Provider provider : providersToShutdown) {
            if (provider.cleanupNeededOnShutdown()) {
                cleanupNeeded = true;
                break;
            }
        }
        if (cleanupNeeded) {
            cleanupResult = shutdownNetworkResources(network.getId(), context.getAccount(), context.getCaller().getId());
        }
    } catch (final Exception ex) {
        s_logger.warn("shutdownNetworkRules failed during the network " + network + " shutdown due to ", ex);
    } finally {
        // just warn the administrator that the network elements failed to shutdown
        if (!cleanupResult) {
            s_logger.warn("Failed to cleanup network id=" + network.getId() + " resources as a part of shutdownNetwork");
        }
    }
    // 2) Shutdown all the network elements
    boolean success = true;
    for (final NetworkElement element : networkElements) {
        if (providersToShutdown.contains(element.getProvider())) {
            try {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Sending network shutdown to " + element.getName());
                }
                if (!element.shutdown(network, context, cleanupElements)) {
                    s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName());
                    success = false;
                }
            } catch (final ResourceUnavailableException e) {
                s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e);
                success = false;
            } catch (final ConcurrentOperationException e) {
                s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e);
                success = false;
            } catch (final Exception e) {
                s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e);
                success = false;
            }
        }
    }
    return success;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) InsufficientVirtualNetworkCapacityException(com.cloud.legacymodel.exceptions.InsufficientVirtualNetworkCapacityException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) IllegalVirtualMachineException(com.cloud.legacymodel.exceptions.IllegalVirtualMachineException) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) ConfigurationException(javax.naming.ConfigurationException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider)

Aggregations

Provider (com.cloud.legacymodel.network.Network.Provider)55 Service (com.cloud.legacymodel.network.Network.Service)29 HashSet (java.util.HashSet)25 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)22 HashMap (java.util.HashMap)22 Set (java.util.Set)22 ArrayList (java.util.ArrayList)21 NetworkElement (com.cloud.network.element.NetworkElement)19 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)15 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)14 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)14 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)13 DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)13 NetworkOrchestrationService (com.cloud.engine.orchestration.service.NetworkOrchestrationService)12 ResourceLimitService (com.cloud.user.ResourceLimitService)12 Network (com.cloud.legacymodel.network.Network)11 VpcProvider (com.cloud.network.element.VpcProvider)10 NicProfile (com.cloud.vm.NicProfile)10 SortedSet (java.util.SortedSet)10 NetworkVO (com.cloud.network.dao.NetworkVO)8