Updated Branches: refs/heads/master ecc30ddc0 -> f2c468d00
Removed unused imports and obsolete methods from ConfigurationManager/ConfigurationServer, NetworkManager/NetworkService Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f2c468d0 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f2c468d0 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f2c468d0 Branch: refs/heads/master Commit: f2c468d00c2afcd2ccccc50d7f02de2c61b11997 Parents: ecc30dd Author: Alena Prokharchyk <alena.prokharc...@citrix.com> Authored: Tue May 28 15:29:27 2013 -0700 Committer: Alena Prokharchyk <alena.prokharc...@citrix.com> Committed: Tue May 28 15:40:44 2013 -0700 ---------------------------------------------------------------------- .../configuration/ConfigurationManagerImpl.java | 130 +------ server/src/com/cloud/network/NetworkManager.java | 20 +- .../src/com/cloud/network/NetworkManagerImpl.java | 306 +++++++++----- .../src/com/cloud/network/NetworkServiceImpl.java | 10 +- .../com/cloud/server/ConfigurationServerImpl.java | 29 +- .../com/cloud/network/MockNetworkManagerImpl.java | 22 - .../test/com/cloud/vpc/MockNetworkManagerImpl.java | 54 +--- 7 files changed, 241 insertions(+), 330 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f2c468d0/server/src/com/cloud/configuration/ConfigurationManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 8baf1fb..79375f9 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -39,11 +39,6 @@ import javax.naming.NamingException; import javax.naming.directory.DirContext; import javax.naming.directory.InitialDirContext; -import com.cloud.dc.*; -import com.cloud.dc.dao.*; -import com.cloud.user.*; -import com.cloud.event.UsageEventUtils; -import com.cloud.utils.db.*; import org.apache.cloudstack.acl.SecurityChecker; import org.apache.cloudstack.api.ApiConstants.LDAPParams; import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd; @@ -71,7 +66,13 @@ import org.apache.cloudstack.api.command.admin.zone.CreateZoneCmd; import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd; import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd; import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd; -import org.apache.cloudstack.region.*; +import org.apache.cloudstack.region.PortableIp; +import org.apache.cloudstack.region.PortableIpDao; +import org.apache.cloudstack.region.PortableIpRange; +import org.apache.cloudstack.region.PortableIpRangeDao; +import org.apache.cloudstack.region.PortableIpRangeVO; +import org.apache.cloudstack.region.PortableIpVO; +import org.apache.cloudstack.region.Region; import org.apache.cloudstack.region.dao.RegionDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO; @@ -149,8 +150,8 @@ import com.cloud.network.dao.PhysicalNetworkDao; import com.cloud.network.dao.PhysicalNetworkTrafficTypeDao; import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO; import com.cloud.network.dao.PhysicalNetworkVO; -import com.cloud.network.rules.LoadBalancerContainer.Scheme; import com.cloud.network.element.DhcpServiceProvider; +import com.cloud.network.rules.LoadBalancerContainer.Scheme; import com.cloud.network.vpc.VpcManager; import com.cloud.offering.DiskOffering; import com.cloud.offering.NetworkOffering; @@ -192,6 +193,11 @@ import com.cloud.utils.NumbersUtil; import com.cloud.utils.StringUtils; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.crypt.DBEncryptionUtil; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GlobalLock; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; import com.cloud.vm.NicIpAlias; @@ -200,59 +206,8 @@ import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.NicIpAliasDao; import com.cloud.vm.dao.NicIpAliasVO; import com.cloud.vm.dao.NicSecondaryIpDao; -import edu.emory.mathcs.backport.java.util.Arrays; -import org.apache.cloudstack.acl.SecurityChecker; -import org.apache.cloudstack.api.ApiConstants.LDAPParams; -import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd; -import org.apache.cloudstack.api.command.admin.ldap.LDAPConfigCmd; -import org.apache.cloudstack.api.command.admin.ldap.LDAPRemoveCmd; -import org.apache.cloudstack.api.command.admin.network.CreateNetworkOfferingCmd; -import org.apache.cloudstack.api.command.admin.network.DeleteNetworkOfferingCmd; -import org.apache.cloudstack.api.command.admin.network.UpdateNetworkOfferingCmd; -import org.apache.cloudstack.api.command.admin.offering.CreateDiskOfferingCmd; -import org.apache.cloudstack.api.command.admin.offering.CreateServiceOfferingCmd; -import org.apache.cloudstack.api.command.admin.offering.DeleteDiskOfferingCmd; -import org.apache.cloudstack.api.command.admin.offering.DeleteServiceOfferingCmd; -import org.apache.cloudstack.api.command.admin.offering.UpdateDiskOfferingCmd; -import org.apache.cloudstack.api.command.admin.offering.UpdateServiceOfferingCmd; -import org.apache.cloudstack.api.command.admin.pod.DeletePodCmd; -import org.apache.cloudstack.api.command.admin.pod.UpdatePodCmd; -import org.apache.cloudstack.api.command.admin.vlan.CreateVlanIpRangeCmd; -import org.apache.cloudstack.api.command.admin.vlan.DedicatePublicIpRangeCmd; -import org.apache.cloudstack.api.command.admin.vlan.DeleteVlanIpRangeCmd; -import org.apache.cloudstack.api.command.admin.vlan.ReleasePublicIpRangeCmd; -import org.apache.cloudstack.api.command.admin.zone.CreateZoneCmd; -import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd; -import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd; -import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd; -import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; -import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO; -import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; -import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; -import javax.ejb.Local; -import javax.inject.Inject; -import javax.naming.ConfigurationException; -import javax.naming.Context; -import javax.naming.NamingException; -import javax.naming.directory.DirContext; -import javax.naming.directory.InitialDirContext; -import java.net.URI; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; +import edu.emory.mathcs.backport.java.util.Arrays; @Component @Local(value = { ConfigurationManager.class, ConfigurationService.class }) @@ -938,10 +893,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati */ } - Grouping.AllocationState allocationState = null; if (allocationStateStr != null && !allocationStateStr.isEmpty()) { try { - allocationState = Grouping.AllocationState.valueOf(allocationStateStr); + Grouping.AllocationState.valueOf(allocationStateStr); } catch (IllegalArgumentException ex) { throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr + "' to a supported state"); } @@ -1363,10 +1317,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("Please enter a valid IPv6 address for IP6 DNS2"); } - Grouping.AllocationState allocationState = null; if (allocationStateStr != null && !allocationStateStr.isEmpty()) { try { - allocationState = Grouping.AllocationState.valueOf(allocationStateStr); + Grouping.AllocationState.valueOf(allocationStateStr); } catch (IllegalArgumentException ex) { throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr + "' to a supported state"); } @@ -2346,7 +2299,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati String endIP = cmd.getEndIp(); String newVlanGateway = cmd.getGateway(); String newVlanNetmask = cmd.getNetmask(); - Long userId = UserContext.current().getCallerUserId(); String vlanId = cmd.getVlan(); Boolean forVirtualNetwork = cmd.isForVirtualNetwork(); Long networkId = cmd.getNetworkID(); @@ -3351,43 +3303,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("Please ensure that your end IP is in the same subnet as your IP range's gateway, as per the IP range's netmask."); } } - - private void checkPrivateIpRangeErrors(Long podId, String startIP, String endIP) { - HostPodVO pod = _podDao.findById(podId); - if (pod == null) { - throw new InvalidParameterValueException("Please specify a valid pod."); - } - - // Check that the start and end IPs are valid - if (!NetUtils.isValidIp(startIP)) { - throw new InvalidParameterValueException("Please specify a valid start IP"); - } - - if (endIP != null && !NetUtils.isValidIp(endIP)) { - throw new InvalidParameterValueException("Please specify a valid end IP"); - } - - if (endIP != null && !NetUtils.validIpRange(startIP, endIP)) { - throw new InvalidParameterValueException("Please specify a valid IP range."); - } - - // Check that the IPs that are being added are compatible with the pod's - // CIDR - String cidrAddress = getCidrAddress(podId); - long cidrSize = getCidrSize(podId); - - if (endIP != null && !NetUtils.sameSubnetCIDR(startIP, endIP, cidrSize)) { - throw new InvalidParameterValueException("Please ensure that your start IP and end IP are in the same subnet, as per the pod's CIDR size."); - } - - if (!NetUtils.sameSubnetCIDR(startIP, cidrAddress, cidrSize)) { - throw new InvalidParameterValueException("Please ensure that your start IP is in the same subnet as the pod's CIDR address."); - } - - if (endIP != null && !NetUtils.sameSubnetCIDR(endIP, cidrAddress, cidrSize)) { - throw new InvalidParameterValueException("Please ensure that your end IP is in the same subnet as the pod's CIDR address."); - } - } + private String getCidrAddress(String cidr) { String[] cidrPair = cidr.split("\\/"); @@ -3399,15 +3315,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati return Integer.parseInt(cidrPair[1]); } - private String getCidrAddress(long podId) { - HostPodVO pod = _podDao.findById(podId); - return pod.getCidrAddress(); - } - - private long getCidrSize(long podId) { - HostPodVO pod = _podDao.findById(podId); - return pod.getCidrSize(); - } @Override public void checkPodCidrSubnets(long dcId, Long podIdToBeSkipped, String cidr) { @@ -4359,7 +4266,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati public boolean isOfferingForVpc(NetworkOffering offering) { boolean vpcProvider = _ntwkOffServiceMapDao.isProviderForNetworkOffering(offering.getId(), Provider.VPCVirtualRouter); - boolean internalLb = offering.getInternalLb(); return vpcProvider; } @@ -4516,6 +4422,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // Note: This method will be used for entity name validations in the coming // releases (place holder for now) + @SuppressWarnings("unused") private void validateEntityName(String str) { String forbidden = "~!@#$%^&*()+="; char[] searchChars = forbidden.toCharArray(); @@ -4741,7 +4648,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati String endIP = cmd.getEndIp(); String gateway = cmd.getGateway(); String netmask = cmd.getNetmask(); - Long userId = UserContext.current().getCallerUserId(); String vlanId = cmd.getVlan(); Region region = _regionDao.findById(regionId); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f2c468d0/server/src/com/cloud/network/NetworkManager.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 19f396a..8627251 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -19,7 +19,6 @@ package com.cloud.network; import java.util.List; import java.util.Map; -import com.cloud.network.element.DhcpServiceProvider; import org.apache.cloudstack.acl.ControlledEntity.ACLType; import com.cloud.dc.DataCenter; @@ -39,6 +38,7 @@ import com.cloud.network.Network.Service; import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.IPAddressVO; import com.cloud.network.dao.NetworkVO; +import com.cloud.network.element.DhcpServiceProvider; import com.cloud.network.element.LoadBalancingServiceProvider; import com.cloud.network.element.StaticNatServiceProvider; import com.cloud.network.element.UserDataServiceProvider; @@ -59,7 +59,6 @@ import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.Type; import com.cloud.vm.VirtualMachineProfile; -import org.apache.cloudstack.region.PortableIp; /** * NetworkManager manages the network for the different end users. @@ -319,9 +318,6 @@ public interface NetworkManager { InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; - PublicIp assignVpnGatewayIpAddress(long dcId, Account owner, long vpcId) throws InsufficientAddressCapacityException, ConcurrentOperationException; - - /** * @param addr */ @@ -346,10 +342,7 @@ public interface NetworkManager { * @return */ int getNetworkLockTimeout(); - - - boolean cleanupIpResources(long addrId, long userId, Account caller); - + boolean restartNetwork(Long networkId, Account callerAccount, User callerUser, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; @@ -370,26 +363,23 @@ public interface NetworkManager { Map<String, String> finalizeServicesAndProvidersForNetwork(NetworkOffering offering, Long physicalNetworkId); - List<Provider> getProvidersForServiceInNetwork(Network network, Service service); StaticNatServiceProvider getStaticNatProviderForNetwork(Network network); + boolean isNetworkInlineMode(Network network); int getRuleCountForIp(Long addressId, FirewallRule.Purpose purpose, FirewallRule.State state); LoadBalancingServiceProvider getLoadBalancingProviderForNetwork(Network network, Scheme lbScheme); - boolean isSecondaryIpSetForNic(long nicId); - public String allocateGuestIP(Account ipOwner, boolean isSystem, long zoneId, Long networkId, String requestedIp) - throws InsufficientAddressCapacityException; - + public String allocateGuestIP(Account ipOwner, boolean isSystem, long zoneId, Long networkId, String requestedIp) throws InsufficientAddressCapacityException; List<? extends Nic> listVmNics(Long vmId, Long nicId); + String allocatePublicIpForGuestNic(Long networkId, DataCenter dc, Pod pod, Account caller, String requestedIp) throws InsufficientAddressCapacityException; - boolean removeVmSecondaryIpsOfNic(long nicId); NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f2c468d0/server/src/com/cloud/network/NetworkManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index b443dca..fda0773 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -16,9 +16,46 @@ // under the License. package com.cloud.network; +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import javax.ejb.Local; +import javax.inject.Inject; +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.acl.ControlledEntity.ACLType; +import org.apache.cloudstack.acl.SecurityChecker.AccessType; +import org.apache.cloudstack.region.PortableIp; +import org.apache.cloudstack.region.PortableIpDao; +import org.apache.cloudstack.region.PortableIpVO; +import org.apache.cloudstack.region.Region; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; -import com.cloud.agent.api.*; +import com.cloud.agent.api.AgentControlAnswer; +import com.cloud.agent.api.AgentControlCommand; +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.CheckNetworkAnswer; +import com.cloud.agent.api.CheckNetworkCommand; +import com.cloud.agent.api.Command; +import com.cloud.agent.api.StartupCommand; +import com.cloud.agent.api.StartupRoutingCommand; import com.cloud.agent.api.to.NicTO; import com.cloud.alert.AlertManager; import com.cloud.api.ApiDBUtils; @@ -26,9 +63,16 @@ import com.cloud.configuration.Config; import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.Resource.ResourceType; import com.cloud.configuration.dao.ConfigurationDao; -import com.cloud.dc.*; +import com.cloud.dc.AccountVlanMapVO; +import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter.NetworkType; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.DataCenterVnetVO; +import com.cloud.dc.Pod; +import com.cloud.dc.PodVlanMapVO; +import com.cloud.dc.Vlan; import com.cloud.dc.Vlan.VlanType; +import com.cloud.dc.VlanVO; import com.cloud.dc.dao.AccountVlanMapDao; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.DataCenterVnetDao; @@ -43,25 +87,61 @@ import com.cloud.event.ActionEventUtils; import com.cloud.event.EventTypes; import com.cloud.event.UsageEventUtils; import com.cloud.event.dao.UsageEventDao; -import com.cloud.exception.*; +import com.cloud.exception.AccountLimitException; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.ConnectionException; +import com.cloud.exception.InsufficientAddressCapacityException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InsufficientVirtualNetworkCapcityException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.PermissionDeniedException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.UnsupportedServiceException; import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.Status; import com.cloud.host.dao.HostDao; -import com.cloud.server.ConfigurationServer; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.IpAddress.State; -import com.cloud.network.Network.*; +import com.cloud.network.Network.Capability; +import com.cloud.network.Network.Event; +import com.cloud.network.Network.GuestType; +import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; import com.cloud.network.Networks.AddressFormat; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.IsolationType; import com.cloud.network.Networks.TrafficType; import com.cloud.network.addr.PublicIp; -import com.cloud.network.dao.*; -import com.cloud.network.element.*; +import com.cloud.network.dao.AccountGuestVlanMapDao; +import com.cloud.network.dao.AccountGuestVlanMapVO; +import com.cloud.network.dao.FirewallRulesDao; +import com.cloud.network.dao.IPAddressDao; +import com.cloud.network.dao.IPAddressVO; +import com.cloud.network.dao.LoadBalancerDao; +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkDomainDao; +import com.cloud.network.dao.NetworkServiceMapDao; +import com.cloud.network.dao.NetworkServiceMapVO; +import com.cloud.network.dao.NetworkVO; +import com.cloud.network.dao.PhysicalNetworkDao; +import com.cloud.network.dao.PhysicalNetworkServiceProviderDao; +import com.cloud.network.dao.PhysicalNetworkTrafficTypeDao; +import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO; +import com.cloud.network.dao.PhysicalNetworkVO; +import com.cloud.network.dao.UserIpv6AddressDao; +import com.cloud.network.element.DhcpServiceProvider; +import com.cloud.network.element.IpDeployer; +import com.cloud.network.element.IpDeployingRequester; +import com.cloud.network.element.LoadBalancingServiceProvider; +import com.cloud.network.element.NetworkElement; +import com.cloud.network.element.StaticNatServiceProvider; +import com.cloud.network.element.UserDataServiceProvider; import com.cloud.network.guru.NetworkGuru; import com.cloud.network.lb.LoadBalancingRulesManager; -import com.cloud.network.rules.*; +import com.cloud.network.rules.FirewallManager; +import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.FirewallRule.Purpose; import com.cloud.network.rules.FirewallRuleVO; import com.cloud.network.rules.LoadBalancerContainer.Scheme; @@ -83,7 +163,13 @@ import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.offerings.dao.NetworkOfferingDetailsDao; import com.cloud.offerings.dao.NetworkOfferingServiceMapDao; import com.cloud.org.Grouping; -import com.cloud.user.*; +import com.cloud.server.ConfigurationServer; +import com.cloud.user.Account; +import com.cloud.user.AccountManager; +import com.cloud.user.ResourceLimitService; +import com.cloud.user.User; +import com.cloud.user.UserContext; +import com.cloud.user.UserVO; import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; import com.cloud.utils.Journal; @@ -92,35 +178,35 @@ import com.cloud.utils.Pair; import com.cloud.utils.component.AdapterBase; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.concurrency.NamedThreadFactory; -import com.cloud.utils.db.*; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GlobalLock; import com.cloud.utils.db.JoinBuilder.JoinType; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.fsm.NoTransitionException; import com.cloud.utils.fsm.StateMachine2; import com.cloud.utils.net.Ip; import com.cloud.utils.net.NetUtils; -import com.cloud.vm.*; +import com.cloud.vm.Nic; import com.cloud.vm.Nic.ReservationStrategy; +import com.cloud.vm.NicProfile; +import com.cloud.vm.NicVO; +import com.cloud.vm.ReservationContext; +import com.cloud.vm.ReservationContextImpl; +import com.cloud.vm.UserVmVO; +import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.Type; -import com.cloud.vm.dao.*; -import org.apache.cloudstack.acl.ControlledEntity.ACLType; -import org.apache.cloudstack.acl.SecurityChecker.AccessType; -import org.apache.cloudstack.region.PortableIp; -import org.apache.cloudstack.region.PortableIpDao; -import org.apache.cloudstack.region.PortableIpVO; -import org.apache.cloudstack.region.Region; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import javax.ejb.Local; -import javax.inject.Inject; -import javax.naming.ConfigurationException; -import java.net.URI; -import java.util.*; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; +import com.cloud.vm.VirtualMachineProfile; +import com.cloud.vm.dao.NicDao; +import com.cloud.vm.dao.NicSecondaryIpDao; +import com.cloud.vm.dao.NicSecondaryIpVO; +import com.cloud.vm.dao.UserVmDao; +import com.cloud.vm.dao.VMInstanceDao; /** * NetworkManagerImpl implements NetworkManager. @@ -260,9 +346,6 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L PortableIpDao _portableIpDao; protected StateMachine2<Network.State, Network.Event, Network> _stateMachine; - private final HashMap<String, NetworkOfferingVO> _systemNetworks = new HashMap<String, NetworkOfferingVO>(5); - private static Long _privateOfferingId = null; - ScheduledExecutorService _executor; SearchBuilder<IPAddressVO> AssignIpAddressSearch; @@ -488,11 +571,6 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L return ipToReturn; } - @Override - public PublicIp assignVpnGatewayIpAddress(long dcId, Account owner, long vpcId) throws InsufficientAddressCapacityException, ConcurrentOperationException { - return assignDedicateIpAddress(owner, null, vpcId, dcId, false); - } - @DB @Override @@ -512,6 +590,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L // this ownerId comes from owner or type Account. See the class "AccountVO" and the annotations in that class // to get the table name and field name that is queried to fill this ownerid. ConcurrentOperationException ex = new ConcurrentOperationException("Unable to lock account"); + throw ex; } if (s_logger.isDebugEnabled()) { s_logger.debug("lock account " + ownerId + " is acquired"); @@ -2173,11 +2252,13 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L } } + @Override public void removeNic(VirtualMachineProfile<? extends VMInstanceVO> vm, Nic nic) { removeNic(vm, _nicDao.findById(nic.getId())); } + protected void removeNic(VirtualMachineProfile<? extends VMInstanceVO> vm, NicVO nic) { nic.setState(Nic.State.Deallocating); _nicDao.update(nic.getId(), nic); @@ -3239,8 +3320,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L return false; } - @Override - public boolean cleanupIpResources(long ipId, long userId, Account caller) { + + protected boolean cleanupIpResources(long ipId, long userId, Account caller) { boolean success = true; // Revoke all firewall rules for the ip @@ -3348,9 +3429,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L throws InsufficientAddressCapacityException { String ipaddr = null; Account caller = UserContext.current().getCaller(); - long callerUserId = UserContext.current().getCallerUserId(); // check permissions - DataCenter zone = _configMgr.getZone(zoneId); Network network = _networksDao.findById(networkId); _accountMgr.checkAccess(caller, null, false, network); @@ -3955,7 +4034,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L String requestedIpv4, String requestedIpv6) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { //This method allocates direct ip for the Shared network in Advance zones - boolean ipv4 = false, ipv6 = false; + boolean ipv4 = false; Transaction txn = Transaction.currentTxn(); txn.start(); @@ -3998,7 +4077,6 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L //FIXME - get ipv6 address from the placeholder if it's stored there if (network.getIp6Gateway() != null) { if (nic.getIp6Address() == null) { - ipv6 = true; UserIpv6Address ip = _ipv6Mgr.assignDirectIp6Address(dc.getId(), vm.getOwner(), network.getId(), requestedIpv6); Vlan vlan = _vlanDao.findById(ip.getVlanId()); nic.setIp6Address(ip.getAddress().toString()); @@ -4057,37 +4135,39 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L public NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context, VirtualMachineProfile<? extends VMInstanceVO> vmProfile, boolean prepare) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { - - VirtualMachine vm = vmProfile.getVirtualMachine(); - DataCenter dc = _configMgr.getZone(network.getDataCenterId()); - Host host = _hostDao.findById(vm.getHostId()); - DeployDestination dest = new DeployDestination(dc, null, null, host); - - NicProfile nic = getNicProfileForVm(network, requested, vm); - - //1) allocate nic (if needed) Always allocate if it is a user vm - if (nic == null || (vmProfile.getType() == VirtualMachine.Type.User)) { - int deviceId = _nicDao.countNics(vm.getId()); - - nic = allocateNic(requested, network, false, - deviceId, vmProfile).first(); - - if (nic == null) { - throw new CloudRuntimeException("Failed to allocate nic for vm " + vm + " in network " + network); - } - - s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network); - } - - //2) prepare nic - if (prepare) { - Pair<NetworkGuru, NetworkVO> implemented = implementNetwork(nic.getNetworkId(), dest, context); - nic = prepareNic(vmProfile, dest, context, nic.getId(), implemented.second()); - s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network); - } - - return nic; + + VirtualMachine vm = vmProfile.getVirtualMachine(); + DataCenter dc = _configMgr.getZone(network.getDataCenterId()); + Host host = _hostDao.findById(vm.getHostId()); + DeployDestination dest = new DeployDestination(dc, null, null, host); + + NicProfile nic = getNicProfileForVm(network, requested, vm); + + //1) allocate nic (if needed) Always allocate if it is a user vm + if (nic == null || (vmProfile.getType() == VirtualMachine.Type.User)) { + int deviceId = _nicDao.countNics(vm.getId()); + + nic = allocateNic(requested, network, false, + deviceId, vmProfile).first(); + + if (nic == null) { + throw new CloudRuntimeException("Failed to allocate nic for vm " + vm + " in network " + network); } + + s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network); + } + + //2) prepare nic + if (prepare) { + Pair<NetworkGuru, NetworkVO> implemented = implementNetwork(nic.getNetworkId(), dest, context); + nic = prepareNic(vmProfile, dest, context, nic.getId(), implemented.second()); + s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network); + } + + return nic; + } + + @Override public List<NicProfile> getNicProfiles(VirtualMachine vm) { List<NicVO> nics = _nicDao.listByVmId(vm.getId()); @@ -4137,6 +4217,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L return map; } + @Override public List<Provider> getProvidersForServiceInNetwork(Network network, Service service) { Map<Service, Set<Provider>> service2ProviderMap = getServiceProvidersMap(network.getId()); @@ -4147,6 +4228,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L return null; } + protected List<NetworkElement> getElementForServiceInNetwork(Network network, Service service) { List<NetworkElement> elements = new ArrayList<NetworkElement>(); List<Provider> providers = getProvidersForServiceInNetwork(network, service); @@ -4168,7 +4250,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L } return elements; } - + + @Override public StaticNatServiceProvider getStaticNatProviderForNetwork(Network network) { //only one provider per Static nat service is supoprted @@ -4177,6 +4260,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L return (StaticNatServiceProvider)element; } + @Override public LoadBalancingServiceProvider getLoadBalancingProviderForNetwork(Network network, Scheme lbScheme) { List<NetworkElement> lbElements = getElementForServiceInNetwork(network, Service.Lb); @@ -4202,7 +4286,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L assert lbElement instanceof LoadBalancingServiceProvider; return (LoadBalancingServiceProvider)lbElement; } - + + @Override public boolean isNetworkInlineMode(Network network) { NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId()); @@ -4218,47 +4303,50 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L return rules.size(); } - @Override + + @Override public boolean isSecondaryIpSetForNic(long nicId) { NicVO nic = _nicDao.findById(nicId); return nic.getSecondaryIp(); } - @Override - public boolean removeVmSecondaryIpsOfNic(long nicId) { - Transaction txn = Transaction.currentTxn(); - txn.start(); - List <NicSecondaryIpVO> ipList = _nicSecondaryIpDao.listByNicId(nicId); - if (ipList != null) { - for (NicSecondaryIpVO ip: ipList) { - _nicSecondaryIpDao.remove(ip.getId()); - } - s_logger.debug("Revoving nic secondary ip entry ..."); + + private boolean removeVmSecondaryIpsOfNic(long nicId) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + List <NicSecondaryIpVO> ipList = _nicSecondaryIpDao.listByNicId(nicId); + if (ipList != null) { + for (NicSecondaryIpVO ip: ipList) { + _nicSecondaryIpDao.remove(ip.getId()); } - txn.commit(); - return true; - } + s_logger.debug("Revoving nic secondary ip entry ..."); + } + txn.commit(); + return true; + } - @Override - public String allocatePublicIpForGuestNic(Long networkId, DataCenter dc, Pod pod,Account owner, - String requestedIp) throws InsufficientAddressCapacityException { - PublicIp ip = assignPublicIpAddress(dc.getId(), null, owner, VlanType.DirectAttached, networkId, requestedIp, false); - if (ip == null) { - s_logger.debug("There is no free public ip address"); - return null; - } - Ip ipAddr = ip.getAddress(); - return ipAddr.addr(); - } - - @Override - public NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType) { - NicVO nic = new NicVO(null, null, network.getId(), null); - nic.setIp4Address(ip4Address); - nic.setReservationStrategy(ReservationStrategy.PlaceHolder); - nic.setState(Nic.State.Reserved); - nic.setVmType(vmType); - return _nicDao.persist(nic); + + @Override + public String allocatePublicIpForGuestNic(Long networkId, DataCenter dc, Pod pod,Account owner, + String requestedIp) throws InsufficientAddressCapacityException { + PublicIp ip = assignPublicIpAddress(dc.getId(), null, owner, VlanType.DirectAttached, networkId, requestedIp, false); + if (ip == null) { + s_logger.debug("There is no free public ip address"); + return null; } + Ip ipAddr = ip.getAddress(); + return ipAddr.addr(); + } + + + @Override + public NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType) { + NicVO nic = new NicVO(null, null, network.getId(), null); + nic.setIp4Address(ip4Address); + nic.setReservationStrategy(ReservationStrategy.PlaceHolder); + nic.setState(Nic.State.Reserved); + nic.setVmType(vmType); + return _nicDao.persist(nic); + } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f2c468d0/server/src/com/cloud/network/NetworkServiceImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java index f880bcc..4eed735 100755 --- a/server/src/com/cloud/network/NetworkServiceImpl.java +++ b/server/src/com/cloud/network/NetworkServiceImpl.java @@ -2549,7 +2549,6 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { if (removeVlan != null){ List<Integer> tokens = processVlanRange(network,removeVlan); boolean result = removeVlanRange(network, tokens.get(0), tokens.get(1)); - } if (tags != null && tags.size() > 1) { @@ -2795,9 +2794,6 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { return true; } - private boolean physicalNetworkHasAllocatedVnets(long zoneId, long physicalNetworkId) { - return !_dcDao.listAllocatedVnets(physicalNetworkId).isEmpty(); - } @Override @ActionEvent(eventType = EventTypes.EVENT_PHYSICAL_NETWORK_DELETE, eventDescription = "deleting physical network", async = true) @@ -3758,14 +3754,12 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { } } - - + private boolean getAllowSubdomainAccessGlobal() { return _allowSubdomainNetworkAccess; } - - + @Override public List<Pair<TrafficType, String>> listTrafficTypeImplementor(ListTrafficTypeImplementorsCmd cmd) { String type = cmd.getTrafficType(); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f2c468d0/server/src/com/cloud/server/ConfigurationServerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index bc52e9a..35f977b 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -36,18 +36,12 @@ import java.util.Map; import java.util.Properties; import java.util.UUID; import java.util.regex.Pattern; -import java.util.StringTokenizer; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.inject.Inject; import javax.naming.ConfigurationException; -import com.cloud.configuration.*; -import com.cloud.dc.*; -import com.cloud.dc.dao.DcDetailsDao; -import com.cloud.user.*; -import com.cloud.utils.db.GenericDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; @@ -56,13 +50,25 @@ import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; +import com.cloud.configuration.Config; +import com.cloud.configuration.ConfigurationVO; +import com.cloud.configuration.Resource; import com.cloud.configuration.Resource.ResourceOwnerType; import com.cloud.configuration.Resource.ResourceType; +import com.cloud.configuration.ResourceCountVO; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.configuration.dao.ResourceCountDao; +import com.cloud.dc.ClusterDetailsDao; +import com.cloud.dc.ClusterDetailsVO; +import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenter.NetworkType; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.DcDetailVO; +import com.cloud.dc.HostPodVO; +import com.cloud.dc.VlanVO; import com.cloud.dc.dao.ClusterDao; import com.cloud.dc.dao.DataCenterDao; +import com.cloud.dc.dao.DcDetailsDao; import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.VlanDao; import com.cloud.domain.DomainVO; @@ -95,6 +101,11 @@ import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.test.IPRangeConfig; +import com.cloud.user.Account; +import com.cloud.user.AccountDetailVO; +import com.cloud.user.AccountDetailsDao; +import com.cloud.user.AccountVO; +import com.cloud.user.User; import com.cloud.user.dao.AccountDao; import com.cloud.utils.PasswordGenerator; import com.cloud.utils.PropertiesUtil; @@ -106,7 +117,6 @@ import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; import com.cloud.utils.script.Script; -import com.cloud.uuididentity.dao.IdentityDao; @Component @@ -124,12 +134,10 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio @Inject private DataCenterDao _dataCenterDao; @Inject private NetworkDao _networkDao; @Inject private VlanDao _vlanDao; - private String _domainSuffix; @Inject private DomainDao _domainDao; @Inject private AccountDao _accountDao; @Inject private ResourceCountDao _resourceCountDao; @Inject private NetworkOfferingServiceMapDao _ntwkOfferingServiceMapDao; - @Inject private IdentityDao _identityDao; @Inject private DcDetailsDao _dcDetailsDao; @Inject private ClusterDetailsDao _clusterDetailsDao; @Inject private StoragePoolDetailsDao _storagePoolDetailsDao; @@ -162,9 +170,6 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio // Get init String init = _configDao.getValue("init"); - // Get domain suffix - needed for network creation - _domainSuffix = _configDao.getValue("guest.domain.suffix"); - if (init == null || init.equals("false")) { s_logger.debug("ConfigurationServer is saving default values to the database."); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f2c468d0/server/test/com/cloud/network/MockNetworkManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index 53c0fa8..7ab322b 100755 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -518,14 +518,6 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage return false; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#cleanupIpResources(long, long, com.cloud.user.Account) - */ - @Override - public boolean cleanupIpResources(long addrId, long userId, Account caller) { - // TODO Auto-generated method stub - return false; - } /* (non-Javadoc) * @see com.cloud.network.NetworkManager#restartNetwork(java.lang.Long, com.cloud.user.Account, com.cloud.user.User, boolean) @@ -795,15 +787,6 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage return null; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#assignVpnGatewayIpAddress(long, com.cloud.user.Account, long) - */ - @Override - public PublicIp assignVpnGatewayIpAddress(long dcId, Account owner, long vpcId) - throws InsufficientAddressCapacityException, ConcurrentOperationException { - // TODO Auto-generated method stub - return null; - } /* (non-Javadoc) * @see com.cloud.network.NetworkManager#markPublicIpAsAllocated(com.cloud.network.IPAddressVO) @@ -939,11 +922,6 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage return null; } - @Override - public boolean removeVmSecondaryIpsOfNic(long nicId) { - // TODO Auto-generated method stub - return false; - } @Override public NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f2c468d0/server/test/com/cloud/vpc/MockNetworkManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java index a1ece44..d46be7c 100644 --- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java @@ -1142,10 +1142,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage return false; } - - - - + /* (non-Javadoc) * @see com.cloud.network.NetworkManager#releaseNic(com.cloud.vm.VirtualMachineProfile, com.cloud.vm.Nic) */ @@ -1156,10 +1153,6 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage } - - - - /* (non-Javadoc) * @see com.cloud.network.NetworkManager#createNicForVm(com.cloud.network.Network, com.cloud.vm.NicProfile, com.cloud.vm.ReservationContext, com.cloud.vm.VirtualMachineProfileImpl, boolean, boolean) */ @@ -1172,24 +1165,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage return null; } - - - - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#assignVpnGatewayIpAddress(long, com.cloud.user.Account, long) - */ - @Override - public PublicIp assignVpnGatewayIpAddress(long dcId, Account owner, long vpcId) - throws InsufficientAddressCapacityException, ConcurrentOperationException { - // TODO Auto-generated method stub - return null; - } - - - - - + /* (non-Javadoc) * @see com.cloud.network.NetworkManager#markPublicIpAsAllocated(com.cloud.network.IPAddressVO) */ @@ -1200,9 +1176,6 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage } - - - /* (non-Javadoc) * @see com.cloud.network.NetworkManager#assignDedicateIpAddress(com.cloud.user.Account, java.lang.Long, java.lang.Long, long, boolean) */ @@ -1240,22 +1213,6 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage } - - - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#cleanupIpResources(long, long, com.cloud.user.Account) - */ - @Override - public boolean cleanupIpResources(long addrId, long userId, Account caller) { - // TODO Auto-generated method stub - return false; - } - - - - - /* (non-Javadoc) * @see com.cloud.network.NetworkManager#restartNetwork(java.lang.Long, com.cloud.user.Account, com.cloud.user.User, boolean) */ @@ -1436,13 +1393,6 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage @Override - public boolean removeVmSecondaryIpsOfNic(long nicId) { - // TODO Auto-generated method stub - return false; - } - - - @Override public NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType) { // TODO Auto-generated method stub return null;