From 2014cb0febddfb332b650e943029ae6daf948012 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Wed, 23 May 2012 16:18:41 -0700 Subject: [PATCH] Plug nic support --- .../com/cloud/agent/api/PlugNicCommand.java | 50 +++ .../api/routing/SetFirewallRulesCommand.java | 2 - api/src/com/cloud/agent/api/to/NetworkTO.java | 1 - .../com/cloud/hypervisor/HypervisorGuru.java | 8 + api/src/com/cloud/network/NetworkService.java | 6 - .../cloud/network/element/VpcProvider.java | 27 -- .../VpcVirtualNetworkApplianceService.java | 43 ++ api/src/com/cloud/vm/Nic.java | 3 +- api/src/com/cloud/vm/UserVmService.java | 1 - core/src/com/cloud/vm/DomainRouterVO.java | 6 +- .../ConfigurationManagerImpl.java | 3 +- .../AgentBasedConsoleProxyManager.java | 22 + .../consoleproxy/ConsoleProxyManagerImpl.java | 20 +- .../cloud/hypervisor/HypervisorGuruBase.java | 3 +- .../src/com/cloud/network/NetworkManager.java | 40 +- .../com/cloud/network/NetworkManagerImpl.java | 381 ++++++++++-------- server/src/com/cloud/network/NetworkVO.java | 8 +- .../element/VpcVirtualRouterElement.java | 125 ++++-- .../cloud/network/guru/GuestNetworkGuru.java | 17 +- .../lb/ElasticLoadBalancerManagerImpl.java | 25 +- .../VirtualNetworkApplianceManagerImpl.java | 165 ++++---- .../VpcVirtualNetworkApplianceManager.java | 16 +- ...VpcVirtualNetworkApplianceManagerImpl.java | 116 +++--- .../src/com/cloud/network/vpc/VpcManager.java | 8 +- .../com/cloud/network/vpc/VpcManagerImpl.java | 5 +- .../com/cloud/network/vpc/VpcOfferingVO.java | 1 - server/src/com/cloud/network/vpc/VpcVO.java | 6 + .../cloud/server/ConfigurationServerImpl.java | 5 +- .../SecondaryStorageManagerImpl.java | 19 + .../src/com/cloud/vm/UserVmManagerImpl.java | 15 + .../src/com/cloud/vm/VirtualMachineGuru.java | 36 ++ .../com/cloud/vm/VirtualMachineManager.java | 20 + .../cloud/vm/VirtualMachineManagerImpl.java | 56 ++- .../src/com/cloud/vm/dao/DomainRouterDao.java | 6 + .../com/cloud/vm/dao/DomainRouterDaoImpl.java | 36 +- .../cloud/network/MockNetworkManagerImpl.java | 2 +- wscript | 2 +- 37 files changed, 889 insertions(+), 416 deletions(-) create mode 100644 api/src/com/cloud/agent/api/PlugNicCommand.java create mode 100644 api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java diff --git a/api/src/com/cloud/agent/api/PlugNicCommand.java b/api/src/com/cloud/agent/api/PlugNicCommand.java new file mode 100644 index 00000000000..041d373b8eb --- /dev/null +++ b/api/src/com/cloud/agent/api/PlugNicCommand.java @@ -0,0 +1,50 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.agent.api; + +import java.util.Map; + +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; + +/** + * @author Alena Prokharchyk + */ +public class PlugNicCommand extends Command { + public enum Param { + DhcpRange, + NetworkDomain + } + + VirtualMachineTO vm; + NicTO nic; + Map params; + + public VirtualMachineTO getVirtualMachine() { + return vm; + } + + @Override + public boolean executeInSequence() { + return true; + } + + protected PlugNicCommand() { + } + + public PlugNicCommand(VirtualMachineTO vm, NicTO nic, Map params) { + this.vm = vm; + this.nic = nic; + this.params = params; + } +} diff --git a/api/src/com/cloud/agent/api/routing/SetFirewallRulesCommand.java b/api/src/com/cloud/agent/api/routing/SetFirewallRulesCommand.java index 210acc35e65..f5011aa860f 100644 --- a/api/src/com/cloud/agent/api/routing/SetFirewallRulesCommand.java +++ b/api/src/com/cloud/agent/api/routing/SetFirewallRulesCommand.java @@ -17,8 +17,6 @@ import java.util.List; import java.util.Set; import com.cloud.agent.api.to.FirewallRuleTO; -import com.cloud.agent.api.to.LoadBalancerTO; -import com.cloud.utils.StringUtils; /** * diff --git a/api/src/com/cloud/agent/api/to/NetworkTO.java b/api/src/com/cloud/agent/api/to/NetworkTO.java index 788e367a2dd..6a7ec1394a9 100644 --- a/api/src/com/cloud/agent/api/to/NetworkTO.java +++ b/api/src/com/cloud/agent/api/to/NetworkTO.java @@ -173,5 +173,4 @@ public class NetworkTO { public boolean isSecurityGroupEnabled() { return this.isSecurityGroupEnabled; } - } diff --git a/api/src/com/cloud/hypervisor/HypervisorGuru.java b/api/src/com/cloud/hypervisor/HypervisorGuru.java index 8d869d74fab..09cc3673e7a 100644 --- a/api/src/com/cloud/hypervisor/HypervisorGuru.java +++ b/api/src/com/cloud/hypervisor/HypervisorGuru.java @@ -13,9 +13,11 @@ package com.cloud.hypervisor; import com.cloud.agent.api.Command; +import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.utils.component.Adapter; +import com.cloud.vm.NicProfile; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; @@ -45,4 +47,10 @@ public interface HypervisorGuru extends Adapter { * */ boolean trackVmHostChange(); + + /** + * @param profile + * @return + */ + NicTO toNicTO(NicProfile profile); } diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java index 3b05d996250..200aebfea69 100755 --- a/api/src/com/cloud/network/NetworkService.java +++ b/api/src/com/cloud/network/NetworkService.java @@ -32,7 +32,6 @@ import com.cloud.network.Networks.TrafficType; import com.cloud.user.Account; import com.cloud.user.User; import com.cloud.utils.Pair; -import com.cloud.vm.VirtualMachine; public interface NetworkService { @@ -144,10 +143,5 @@ public interface NetworkService { List listNetworksByVpc(long vpcId); - boolean addVmToNetwork(VirtualMachine vm, Network network); - - boolean removeVmFromNetwork(VirtualMachine vm, Network network); - boolean isVmPartOfNetwork(long vmId, long ntwkId); - } diff --git a/api/src/com/cloud/network/element/VpcProvider.java b/api/src/com/cloud/network/element/VpcProvider.java index 7c352000324..246ac0bdf4c 100644 --- a/api/src/com/cloud/network/element/VpcProvider.java +++ b/api/src/com/cloud/network/element/VpcProvider.java @@ -36,32 +36,5 @@ public interface VpcProvider extends NetworkElement{ boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; - /** - * Prepare for a nic to be plugged into the network. - * @param network - * @param nic - * @param vm - * @param context - * @return - * @throws ConcurrentOperationException - * @throws ResourceUnavailableException - * @throws InsufficientNetworkCapacityException - */ - boolean plugNic(Network network, NicProfile nic, VirtualMachineProfile vm, - ReservationContext context) throws ConcurrentOperationException, - ResourceUnavailableException, InsufficientCapacityException; - - /** - * A nic is unplugged from this network. - * @param network - * @param nic - * @param vm - * @param context - * @return - * @throws ConcurrentOperationException - * @throws ResourceUnavailableException - */ - boolean unplugNic(Network network, NicProfile nic, VirtualMachineProfile vm, - ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java b/api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java new file mode 100644 index 00000000000..4de760ffba4 --- /dev/null +++ b/api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java @@ -0,0 +1,43 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network; +import com.cloud.network.router.VirtualRouter; + +/** + * @author Alena Prokharchyk + */ +public interface VpcVirtualNetworkApplianceService { + + /** + * @param router + * @param network + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + * @throws InsufficientCapacityException + */ + public boolean addVmToNetwork(VirtualRouter router, Network network) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException; + + /** + * @param router + * @param network + * @return + */ + boolean removeVmFromNetwork(VirtualRouter router, Network network); +} diff --git a/api/src/com/cloud/vm/Nic.java b/api/src/com/cloud/vm/Nic.java index 3bc92920fd8..d121034867c 100644 --- a/api/src/com/cloud/vm/Nic.java +++ b/api/src/com/cloud/vm/Nic.java @@ -31,7 +31,8 @@ public interface Nic { } public enum State implements FiniteState { - Allocated("Resource is allocated but not reserved"), Reserving("Resource is being reserved right now"), Reserved("Resource has been reserved."), Releasing("Resource is being released"), Deallocating( + Allocated("Resource is allocated but not reserved"), Reserving("Resource is being reserved right now"), + Reserved("Resource has been reserved."), Releasing("Resource is being released"), Deallocating( "Resource is being deallocated"); String _description; diff --git a/api/src/com/cloud/vm/UserVmService.java b/api/src/com/cloud/vm/UserVmService.java index 8b8eb205b36..5d4b668790c 100755 --- a/api/src/com/cloud/vm/UserVmService.java +++ b/api/src/com/cloud/vm/UserVmService.java @@ -50,7 +50,6 @@ import com.cloud.template.VirtualMachineTemplate; import com.cloud.user.Account; import com.cloud.uservm.UserVm; import com.cloud.utils.exception.ExecutionException; -import com.cloud.vm.VirtualMachineProfile.Param; public interface UserVmService { /** diff --git a/core/src/com/cloud/vm/DomainRouterVO.java b/core/src/com/cloud/vm/DomainRouterVO.java index f5cc8f9b260..7b03dd15144 100755 --- a/core/src/com/cloud/vm/DomainRouterVO.java +++ b/core/src/com/cloud/vm/DomainRouterVO.java @@ -88,7 +88,7 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { boolean isPriorityBumpUp, RedundantState redundantState, boolean haEnabled, - boolean stopPending) { + boolean stopPending, Long vpcId) { super(id, serviceOfferingId, name, name, Type.DomainRouter, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled); this.elementId = elementId; this.isRedundantRouter = isRedundantRouter; @@ -96,6 +96,7 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { this.redundantState = redundantState; this.isPriorityBumpUp = isPriorityBumpUp; this.stopPending = stopPending; + this.vpcId = vpcId; } public DomainRouterVO(long id, @@ -113,7 +114,7 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { RedundantState redundantState, boolean haEnabled, boolean stopPending, - VirtualMachine.Type vmType) { + VirtualMachine.Type vmType, Long vpcId) { super(id, serviceOfferingId, name, name, vmType, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled); this.elementId = elementId; this.isRedundantRouter = isRedundantRouter; @@ -121,6 +122,7 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { this.redundantState = redundantState; this.isPriorityBumpUp = isPriorityBumpUp; this.stopPending = stopPending; + this.vpcId = vpcId; } public long getElementId() { diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index dffb8cbda7d..1e7d09017cd 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -1612,7 +1612,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura userNetwork.setBroadcastDomainType(broadcastDomainType); userNetwork.setNetworkDomain(networkDomain); - _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, false, Domain.ROOT_DOMAIN, null, null); + _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, false, + Domain.ROOT_DOMAIN, null, null, null); } } } diff --git a/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java b/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java index 72fb87a008d..983e90932c3 100755 --- a/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java +++ b/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java @@ -29,13 +29,19 @@ import com.cloud.agent.api.GetVncPortCommand; import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupProxyCommand; import com.cloud.agent.api.StopAnswer; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.manager.Commands; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.deploy.DeployDestination; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; import com.cloud.host.HostVO; import com.cloud.host.Status; import com.cloud.host.dao.HostDao; import com.cloud.info.ConsoleProxyInfo; +import com.cloud.network.Network; import com.cloud.utils.NumbersUtil; import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.component.Inject; @@ -341,4 +347,20 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu @Override public void finalizeExpunge(ConsoleProxyVO proxy) { } + + @Override + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + //not supported + throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType()); + } + + + @Override + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { + //not supported + throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType()); + } } diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 612d2b69797..b6f4af4d091 100755 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -41,6 +41,8 @@ import com.cloud.agent.api.check.CheckSshAnswer; import com.cloud.agent.api.check.CheckSshCommand; import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer; import com.cloud.agent.api.proxy.StartConsoleProxyAgentHttpHandlerCommand; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.manager.Commands; import com.cloud.api.ServerApiException; import com.cloud.api.commands.DestroyConsoleProxyCmd; @@ -79,6 +81,7 @@ import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo; import com.cloud.keystore.KeystoreDao; import com.cloud.keystore.KeystoreManager; import com.cloud.keystore.KeystoreVO; +import com.cloud.network.Network; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.TrafficType; @@ -90,7 +93,6 @@ import com.cloud.resource.ResourceManager; import com.cloud.resource.ResourceStateAdapter; import com.cloud.resource.ServerResource; import com.cloud.resource.UnableDeleteHostException; -import com.cloud.server.ManagementServer; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.servlet.ConsoleProxyServlet; @@ -1920,4 +1922,20 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } return _hashKey; } + + @Override + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + //not supported + throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType()); + } + + + @Override + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { + //not supported + throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType()); + } } diff --git a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java index d62e3800542..2c3348427b7 100644 --- a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java +++ b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java @@ -35,7 +35,8 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis super(); } - protected NicTO toNicTO(NicProfile profile) { + @Override + public NicTO toNicTO(NicProfile profile) { NicTO to = new NicTO(); to.setDeviceId(profile.getDeviceId()); to.setBroadcastType(profile.getBroadcastType()); diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 839e18f7eed..80346d998cb 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -109,7 +109,7 @@ public interface NetworkManager extends NetworkService { throws ConcurrentOperationException; List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId, - ACLType aclType, Boolean subdomainAccess) throws ConcurrentOperationException; + ACLType aclType, Boolean subdomainAccess, Long vpcId) throws ConcurrentOperationException; List getSystemAccountNetworkOfferings(String... offeringNames); @@ -231,8 +231,6 @@ public interface NetworkManager extends NetworkService { boolean canElementEnableIndividualServices(Provider provider); - PhysicalNetworkServiceProvider addDefaultVirtualRouterToPhysicalNetwork(long physicalNetworkId); - boolean areServicesSupportedInNetwork(long networkId, Service... services); boolean isNetworkSystem(Network network); @@ -252,9 +250,6 @@ public interface NetworkManager extends NetworkService { void canProviderSupportServices(Map> providersMap); - PhysicalNetworkServiceProvider addDefaultSecurityGroupProviderToPhysicalNetwork( - long physicalNetworkId); - List getPhysicalNetworkInfo(long dcId, HypervisorType hypervisorType); @@ -344,4 +339,37 @@ public interface NetworkManager extends NetworkService { * @return */ List getNtwkOffDistinctProviders(long networkId); + + + /** + * @param requested + * @param network + * @param isDefaultNic + * @param deviceId + * @param vm + * @return + * @throws InsufficientVirtualNetworkCapcityException + * @throws InsufficientAddressCapacityException + * @throws ConcurrentOperationException + */ + Pair allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, int deviceId, + VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, + InsufficientAddressCapacityException, ConcurrentOperationException; + + + /** + * @param vmProfile + * @param dest + * @param context + * @param nicId + * @param network + * @return + * @throws InsufficientVirtualNetworkCapcityException + * @throws InsufficientAddressCapacityException + * @throws ConcurrentOperationException + * @throws InsufficientCapacityException + * @throws ResourceUnavailableException + */ + NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context, long nicId, NetworkVO network) throws InsufficientVirtualNetworkCapcityException, + InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 4ba627e00ba..dfb54f4ea4b 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -187,6 +187,7 @@ import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.Ip; import com.cloud.utils.net.NetUtils; +import com.cloud.vm.DomainRouterVO; import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; import com.cloud.vm.NicVO; @@ -1509,16 +1510,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - public List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) + public List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, + String displayText, boolean isDefault) throws ConcurrentOperationException { - return setupNetwork(owner, offering, null, plan, name, displayText, false, null, null, null); + return setupNetwork(owner, offering, null, plan, name, displayText, false, null, null, null, null); } @Override @DB public List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId, - ACLType aclType, Boolean subdomainAccess) throws ConcurrentOperationException { + ACLType aclType, Boolean subdomainAccess, Long vpcId) throws ConcurrentOperationException { Account locked = _accountDao.acquireInLockTable(owner.getId()); if (locked == null) { @@ -1586,9 +1588,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Transaction txn = Transaction.currentTxn(); txn.start(); - NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), related, name, displayText, predefined.getNetworkDomain(), - offering.getGuestType(), plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.getSpecifyIpRanges()); - networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated, finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId()))); + NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), + related, name, displayText, predefined.getNetworkDomain(), offering.getGuestType(), + plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.getSpecifyIpRanges(), vpcId); + networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated, + finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId()))); if (domainId != null && aclType == ACLType.Domain) { _networksDao.addDomainToNetwork(id, domainId, subdomainAccess); @@ -1626,7 +1630,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB - public void allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException, ConcurrentOperationException { + public void allocate(VirtualMachineProfile vm, List> networks) + throws InsufficientCapacityException, ConcurrentOperationException { Transaction txn = Transaction.currentTxn(); txn.start(); @@ -1635,64 +1640,53 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag boolean[] deviceIds = new boolean[networks.size()]; Arrays.fill(deviceIds, false); - List nics = new ArrayList(networks.size()); - NicVO defaultNic = null; + List nics = new ArrayList(networks.size()); + NicProfile defaultNic = null; for (Pair network : networks) { NetworkVO config = network.first(); - NetworkGuru guru = _networkGurus.get(config.getGuruName()); NicProfile requested = network.second(); - if (requested != null && requested.getMode() == null) { - requested.setMode(config.getMode()); + + Boolean isDefaultNic = false; + if (vm != null && (requested != null && requested.isDefaultNic())) { + isDefaultNic = true; } - NicProfile profile = guru.allocate(config, requested, vm); - - if (vm != null && vm.getVirtualMachine().getType() == Type.User && (requested != null && requested.isDefaultNic())) { - profile.setDefaultNic(true); - } - - if (profile == null) { - continue; - } - - if (requested != null && requested.getMode() == null) { - profile.setMode(requested.getMode()); - } else { - profile.setMode(config.getMode()); - } - - NicVO vo = new NicVO(guru.getName(), vm.getId(), config.getId(), vm.getType()); - + while (deviceIds[deviceId] && deviceId < deviceIds.length) { deviceId++; } - - deviceId = applyProfileToNic(vo, profile, deviceId); - - vo = _nicDao.persist(vo); - - if (vo.isDefaultNic()) { - if (defaultNic != null) { - throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " + defaultNic + "; nic 2 = " + vo); - } - defaultNic = vo; + + Pair vmNicPair = allocateNic(requested, config, isDefaultNic, + deviceId, vm); + + NicProfile vmNic = vmNicPair.first(); + if (vmNic == null) { + continue; } - - int devId = vo.getDeviceId(); + + deviceId = vmNicPair.second(); + + int devId = vmNic.getDeviceId(); if (devId > deviceIds.length) { - throw new IllegalArgumentException("Device id for nic is too large: " + vo); + throw new IllegalArgumentException("Device id for nic is too large: " + vmNic); } if (deviceIds[devId]) { - throw new IllegalArgumentException("Conflicting device id for two different nics: " + devId); + throw new IllegalArgumentException("Conflicting device id for two different nics: " + vmNic); } deviceIds[devId] = true; - nics.add(vo); - - Integer networkRate = getNetworkRate(config.getId(), vm.getId()); - vm.addNic(new NicProfile(vo, network.first(), vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, - isSecurityGroupSupportedInNetwork(network.first()), getNetworkTag(vm.getHypervisorType(), - network.first()))); + + if (vmNic.isDefaultNic()) { + if (defaultNic != null) { + throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " + + defaultNic + "; nic 2 = " + vmNic); + } + defaultNic = vmNic; + } + + nics.add(vmNic); + vm.addNic(vmNic); + } if (nics.size() != networks.size()) { @@ -1706,6 +1700,49 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag txn.commit(); } + + + @DB + @Override + public Pair allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, + int deviceId, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, + InsufficientAddressCapacityException, ConcurrentOperationException{ + + NetworkVO ntwkVO = _networksDao.findById(network.getId()); + s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network); + NetworkGuru guru = _networkGurus.get(ntwkVO.getGuruName()); + + if (requested != null && requested.getMode() == null) { + requested.setMode(network.getMode()); + } + NicProfile profile = guru.allocate(network, requested, vm); + if (isDefaultNic != null) { + profile.setDefaultNic(isDefaultNic); + } + + if (profile == null) { + return null; + } + + if (requested != null && requested.getMode() == null) { + profile.setMode(requested.getMode()); + } else { + profile.setMode(network.getMode()); + } + + NicVO vo = new NicVO(guru.getName(), vm.getId(), network.getId(), vm.getType()); + + deviceId = applyProfileToNic(vo, profile, deviceId); + + vo = _nicDao.persist(vo); + + Integer networkRate = getNetworkRate(network.getId(), vm.getId()); + NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, + isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), + network)); + + return new Pair(vmNic, Integer.valueOf(deviceId)); + } protected Integer applyProfileToNic(NicVO vo, NicProfile profile, Integer deviceId) { if (profile.getDeviceId() != null) { @@ -1791,7 +1828,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Integer networkRate = getNetworkRate(config.getId(), null); to.setNetworkRateMbps(networkRate); - + return to; } @@ -1952,9 +1989,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag List nics = _nicDao.listByVmId(vmProfile.getId()); // we have to implement default nics first - to ensure that default network elements start up first in multiple -// nics - // case) - // (need for setting DNS on Dhcp to domR's Ip4 address) + // nics case)(need for setting DNS on Dhcp to domR's Ip4 address) Collections.sort(nics, new Comparator() { @Override @@ -1968,59 +2003,74 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag for (NicVO nic : nics) { Pair implemented = implementNetwork(nic.getNetworkId(), dest, context); - NetworkGuru guru = implemented.first(); - NetworkVO network = implemented.second(); - Integer networkRate = getNetworkRate(network.getId(), vmProfile.getId()); - NicProfile profile = null; - if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { - nic.setState(Nic.State.Reserving); - nic.setReservationId(context.getReservationId()); - _nicDao.update(nic.getId(), nic); - URI broadcastUri = nic.getBroadcastUri(); - if (broadcastUri == null) { - broadcastUri = network.getBroadcastUri(); - } - - URI isolationUri = nic.getIsolationUri(); - - profile = new NicProfile(nic, network, broadcastUri, isolationUri, networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); - guru.reserve(profile, network, vmProfile, dest, context); - nic.setIp4Address(profile.getIp4Address()); - nic.setAddressFormat(profile.getFormat()); - nic.setIp6Address(profile.getIp6Address()); - nic.setMacAddress(profile.getMacAddress()); - nic.setIsolationUri(profile.getIsolationUri()); - nic.setBroadcastUri(profile.getBroadCastUri()); - nic.setReserver(guru.getName()); - nic.setState(Nic.State.Reserved); - nic.setNetmask(profile.getNetmask()); - nic.setGateway(profile.getGateway()); - - if (profile.getStrategy() != null) { - nic.setReservationStrategy(profile.getStrategy()); - } - - updateNic(nic, network.getId(), 1); - } else { - profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); - guru.updateNicProfile(profile, network); - nic.setState(Nic.State.Reserved); - updateNic(nic, network.getId(), 1); - } - for (NetworkElement element : _networkElements) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Asking " + element.getName() + " to prepare for " + nic); - } - prepareElement(element, network, profile, vmProfile, dest, context); - } - - profile.setSecurityGroupEnabled(isSecurityGroupSupportedInNetwork(network)); - guru.updateNicProfile(profile, network); + NetworkVO network = implemented.second(); + NicProfile profile = prepareNic(vmProfile, dest, context, nic.getId(), network); vmProfile.addNic(profile); } } + @Override + public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination + dest, ReservationContext context, long nicId, NetworkVO network) + throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, + ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + + Integer networkRate = getNetworkRate(network.getId(), vmProfile.getId()); + NetworkGuru guru = _networkGurus.get(network.getGuruName()); + NicVO nic = _nicDao.findById(nicId); + + NicProfile profile = null; + if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { + nic.setState(Nic.State.Reserving); + nic.setReservationId(context.getReservationId()); + _nicDao.update(nic.getId(), nic); + URI broadcastUri = nic.getBroadcastUri(); + if (broadcastUri == null) { + broadcastUri = network.getBroadcastUri(); + } + + URI isolationUri = nic.getIsolationUri(); + + profile = new NicProfile(nic, network, broadcastUri, isolationUri, + networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); + guru.reserve(profile, network, vmProfile, dest, context); + nic.setIp4Address(profile.getIp4Address()); + nic.setAddressFormat(profile.getFormat()); + nic.setIp6Address(profile.getIp6Address()); + nic.setMacAddress(profile.getMacAddress()); + nic.setIsolationUri(profile.getIsolationUri()); + nic.setBroadcastUri(profile.getBroadCastUri()); + nic.setReserver(guru.getName()); + nic.setState(Nic.State.Reserved); + nic.setNetmask(profile.getNetmask()); + nic.setGateway(profile.getGateway()); + + if (profile.getStrategy() != null) { + nic.setReservationStrategy(profile.getStrategy()); + } + + updateNic(nic, network.getId(), 1); + } else { + profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), + networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); + guru.updateNicProfile(profile, network); + nic.setState(Nic.State.Reserved); + updateNic(nic, network.getId(), 1); + } + + for (NetworkElement element : _networkElements) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Asking " + element.getName() + " to prepare for " + nic); + } + prepareElement(element, network, profile, vmProfile, dest, context); + } + + profile.setSecurityGroupEnabled(isSecurityGroupSupportedInNetwork(network)); + guru.updateNicProfile(profile, network); + return profile; + } + @Override public void prepareNicForMigration(VirtualMachineProfile vm, DeployDestination dest) { List nics = _nicDao.listByVmId(vm.getId()); @@ -2041,36 +2091,42 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag List nics = _nicDao.listByVmId(vmProfile.getId()); for (NicVO nic : nics) { NetworkVO network = _networksDao.findById(nic.getNetworkId()); - if (nic.getState() == Nic.State.Reserved || nic.getState() == Nic.State.Reserving) { - Nic.State originalState = nic.getState(); - if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { - NetworkGuru guru = _networkGurus.get(network.getGuruName()); - nic.setState(Nic.State.Releasing); - _nicDao.update(nic.getId(), nic); - NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); - if (guru.release(profile, vmProfile, nic.getReservationId())) { - applyProfileToNicForRelease(nic, profile); - nic.setState(Nic.State.Allocated); - if (originalState == Nic.State.Reserved) { - updateNic(nic, network.getId(), -1); - } else { - _nicDao.update(nic.getId(), nic); - } - } - // Perform release on network elements - for (NetworkElement element : _networkElements) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Asking " + element.getName() + " to release " + nic); - } - //NOTE: Context appear to never be used in release method - //implementations. Consider removing it from interface Element - element.release(network, profile, vmProfile, null); - } - - } else { + releaseNic(vmProfile, nic, network); + } + } + + protected void releaseNic(VirtualMachineProfile vmProfile, NicVO nic, NetworkVO network) + throws ConcurrentOperationException, ResourceUnavailableException { + if (nic.getState() == Nic.State.Reserved || nic.getState() == Nic.State.Reserving) { + Nic.State originalState = nic.getState(); + if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { + NetworkGuru guru = _networkGurus.get(network.getGuruName()); + nic.setState(Nic.State.Releasing); + _nicDao.update(nic.getId(), nic); + NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, + isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); + if (guru.release(profile, vmProfile, nic.getReservationId())) { + applyProfileToNicForRelease(nic, profile); nic.setState(Nic.State.Allocated); - updateNic(nic, network.getId(), -1); + if (originalState == Nic.State.Reserved) { + updateNic(nic, network.getId(), -1); + } else { + _nicDao.update(nic.getId(), nic); + } } + // Perform release on network elements + for (NetworkElement element : _networkElements) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Asking " + element.getName() + " to release " + nic); + } + //NOTE: Context appear to never be used in release method + //implementations. Consider removing it from interface Element + element.release(network, profile, vmProfile, null); + } + + } else { + nic.setState(Nic.State.Allocated); + updateNic(nic, network.getId(), -1); } } } @@ -2541,16 +2597,28 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return network; } - public Network createVpcGuestNetwork(long ntwkOffId, String name, String displayText, String gateway, + @DB + protected Network createVpcGuestNetwork(long ntwkOffId, String name, String displayText, String gateway, String cidr, String vlanId, String networkDomain, Account owner, Long domainId, PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, long vpcId) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { + //1) Validate if network can be created for VPC _vpcMgr.validateGuestNtkwForVpc(_configMgr.getNetworkOffering(ntwkOffId), cidr, networkDomain, owner, _vpcMgr.getVpc(vpcId)); - return createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId, + //2) Create network + Network guestNetwork = createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId); + + //3) Add network to all VPC's routers + List routers = _routerDao.listRoutersByVpcId(vpcId); + for (DomainRouterVO router : routers) { + s_logger.debug("Adding router " + router + " to network " + guestNetwork); + _routerDao.addRouterToNetwork(router, guestNetwork); + } + + return guestNetwork; } @Override @@ -2751,7 +2819,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } List networks = setupNetwork(owner, ntwkOff, userNetwork, plan, name, displayText, true, domainId, - aclType, subdomainAccess); + aclType, subdomainAccess, vpcId); Network network = null; if (networks == null || networks.isEmpty()) { @@ -4849,6 +4917,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // add security group provider to the physical network addDefaultSecurityGroupProviderToPhysicalNetwork(pNetwork.getId()); + + // add VPCVirtualRouter as the defualt network service provider + addDefaultVpcVirtualRouterToPhysicalNetwork(pNetwork.getId()); txn.commit(); return pNetwork; @@ -6166,7 +6237,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } else { // locate physicalNetwork with supported traffic type // We can make this assumptions based on the fact that Public/Management/Control traffic types are -// supported only in one physical network in the zone in 3.0 + // supported only in one physical network in the zone in 3.0 for (PhysicalNetworkVO pNtwk : pNtwks) { if (_pNTrafficTypeDao.isTrafficTypeSupported(pNtwk.getId(), network.getTrafficType())) { physicalNetworkId = pNtwk.getId(); @@ -6193,8 +6264,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return networks.get(0); } - @Override - public PhysicalNetworkServiceProvider addDefaultVirtualRouterToPhysicalNetwork(long physicalNetworkId) { + protected PhysicalNetworkServiceProvider addDefaultVirtualRouterToPhysicalNetwork(long physicalNetworkId) { PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, Network.Provider.VirtualRouter.getName(), null, null); // add instance of the provider @@ -6206,9 +6276,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return nsp; } + + protected PhysicalNetworkServiceProvider addDefaultVpcVirtualRouterToPhysicalNetwork(long physicalNetworkId) { - @Override - public PhysicalNetworkServiceProvider addDefaultSecurityGroupProviderToPhysicalNetwork(long physicalNetworkId) { + PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, + Network.Provider.VPCVirtualRouter.getName(), null, null); + + return nsp; + } + + protected PhysicalNetworkServiceProvider addDefaultSecurityGroupProviderToPhysicalNetwork(long physicalNetworkId) { PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, Network.Provider.SecurityGroupProvider.getName(), null, null); @@ -6235,7 +6312,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag for (NetworkOfferingServiceMapVO serviceMap : servicesMap) { if (svcProviders.containsKey(serviceMap.getService())) { // FIXME - right now we pick up the first provider from the list, need to add more logic based on -// provider load, etc + // provider load, etc continue; } @@ -6249,7 +6326,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // check that provider is supported if (checkPhysicalNetwork) { if (!_pNSPDao.isServiceProviderEnabled(physicalNetworkId, provider, service)) { - throw new UnsupportedServiceException("Provider " + provider + " is either not enabled or doesn't support service " + service + " in physical network id=" + physicalNetworkId); + throw new UnsupportedServiceException("Provider " + provider + " is either not enabled or doesn't " + + "support service " + service + " in physical network id=" + physicalNetworkId); } } @@ -6613,7 +6691,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } catch (Exception ex) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Failed to retrive the default label for management traffic:" + "zone: " + dcId + " hypervisor: " + hypervisorType + " due to:" + ex.getMessage()); + s_logger.debug("Failed to retrive the default label for management traffic:" + "zone: " + dcId + + " hypervisor: " + hypervisorType + " due to:" + ex.getMessage()); } } return null; @@ -6640,18 +6719,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return providers; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkService#addVmToNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network) - */ - @Override - public boolean addVmToNetwork(VirtualMachine vm, Network network) { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkService#isVmPartOfNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network) - */ @Override public boolean isVmPartOfNetwork(long vmId, long ntwkId) { if (_nicDao.findByInstanceIdAndNetworkId(ntwkId, vmId) != null) { @@ -6660,12 +6727,4 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return false; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkService#removeVmFromNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network) - */ - @Override - public boolean removeVmFromNetwork(VirtualMachine vm, Network network) { - // TODO Auto-generated method stub - return false; - } } diff --git a/server/src/com/cloud/network/NetworkVO.java b/server/src/com/cloud/network/NetworkVO.java index 80633044b37..03cec169510 100644 --- a/server/src/com/cloud/network/NetworkVO.java +++ b/server/src/com/cloud/network/NetworkVO.java @@ -179,9 +179,9 @@ public class NetworkVO implements Network, Identity { public NetworkVO(long id, Network that, long offeringId, String guruName, long domainId, long accountId, long related, String name, String displayText, String networkDomain, GuestType guestType, long dcId, - Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges) { + Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges, Long vpcId) { this(id, that.getTrafficType(), that.getMode(), that.getBroadcastDomainType(), offeringId, domainId, accountId, - related, name, displayText, networkDomain, guestType, dcId, physicalNetworkId, aclType, specifyIpRanges); + related, name, displayText, networkDomain, guestType, dcId, physicalNetworkId, aclType, specifyIpRanges, vpcId); this.gateway = that.getGateway(); this.cidr = that.getCidr(); this.broadcastUri = that.getBroadcastUri(); @@ -208,11 +208,12 @@ public class NetworkVO implements Network, Identity { * @param guestType TODO * @param aclType TODO * @param specifyIpRanges TODO + * @param vpcId TODO * @param dataCenterId */ public NetworkVO(long id, TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long domainId, long accountId, long related, String name, String displayText, - String networkDomain, GuestType guestType, long dcId, Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges) { + String networkDomain, GuestType guestType, long dcId, Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges, Long vpcId) { this(trafficType, mode, broadcastDomainType, networkOfferingId, State.Allocated, dcId, physicalNetworkId); this.domainId = domainId; this.accountId = accountId; @@ -225,6 +226,7 @@ public class NetworkVO implements Network, Identity { this.uuid = UUID.randomUUID().toString(); this.guestType = guestType; this.specifyIpRanges = specifyIpRanges; + this.vpcId = vpcId; } @Override diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index 83859834fa0..712e90d3074 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -14,6 +14,7 @@ package com.cloud.network.element; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.ejb.Local; @@ -29,8 +30,10 @@ import com.cloud.network.Network.Capability; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkService; +import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VpcVirtualNetworkApplianceManager; import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcVirtualNetworkApplianceService; import com.cloud.offering.NetworkOffering; import com.cloud.utils.component.Inject; import com.cloud.vm.NicProfile; @@ -45,9 +48,10 @@ import com.cloud.vm.VirtualMachineProfile; public class VpcVirtualRouterElement extends VirtualRouterElement implements VpcProvider{ private static final Logger s_logger = Logger.getLogger(VpcVirtualRouterElement.class); @Inject - NetworkService _ntwkSvc; + NetworkService _ntwkService; @Inject - VpcVirtualNetworkApplianceManager _vpcElementMgr; + VpcVirtualNetworkApplianceService _vpcElementService; + private static final Map> capabilities = setCapabilities(); @@ -71,17 +75,34 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc throws ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException { - if (network.getVpcId() == null) { + Long vpcId = network.getVpcId(); + if (vpcId == null) { s_logger.warn("Network " + network + " is not associated with any VPC"); return false; } + boolean success = super.implement(network, offering, dest, context); if (success) { - success = success && _vpcElementMgr.addVpcElementToNetwork(network); + List routers = _routerDao.listRoutersByVpcId(vpcId); + for (VirtualRouter router : routers) { + //1) Check if router is already a part of the network + if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { + s_logger.debug("Router " + router + " is already part of the network " + network); + continue; + } + //2) Call plugNics in the network service + success = success && _vpcElementService.addVmToNetwork(router, network); + } + + if (!success) { + s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId); + } else { + s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId); + } } - - return success; + + return success; } @Override @@ -89,30 +110,92 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { - if (network.getVpcId() == null) { + Long vpcId = network.getVpcId(); + if (vpcId == null) { s_logger.warn("Network " + network + " is not associated with any VPC"); return false; } + boolean success = super.prepare(network, nic, vm, dest, context); if (success) { - success = success && _vpcElementMgr.addVpcElementToNetwork(network); + List routers = _routerDao.listRoutersByVpcId(vpcId); + for (VirtualRouter router : routers) { + //1) Check if router is already a part of the network + if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { + s_logger.debug("Router " + router + " is already part of the network " + network); + continue; + } + //2) Call plugNics in the network service + success = success && _vpcElementService.addVmToNetwork(router, network); + } + + if (!success) { + s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId); + } else { + s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId); + } } - return success; } @Override public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException { - - return _vpcElementMgr.removeVpcElementFromNetwork(network); + boolean success = true; + Long vpcId = network.getVpcId(); + if (vpcId == null) { + s_logger.debug("Network " + network + " doesn't belong to any vpc, so skipping unplug nic part"); + return success; + } + + List routers = _routerDao.listRoutersByVpcId(vpcId); + for (VirtualRouter router : routers) { + //1) Check if router is already a part of the network + if (!_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { + s_logger.debug("Router " + router + " is not a part the network " + network); + continue; + } + //2) Call unplugNics in the network service + success = success && _vpcElementService.removeVmFromNetwork(router, network); + } + + if (!success) { + s_logger.warn("Failed to unplug nic in network " + network + " for virtual router in vpc id=" + vpcId); + } else { + s_logger.debug("Successfully unplugged nic in network " + network + " for virtual router in vpc id=" + vpcId); + } + + return success; } @Override public boolean destroy(Network config) throws ConcurrentOperationException, ResourceUnavailableException { - - return _vpcElementMgr.removeVpcElementFromNetwork(config); + boolean success = true; + Long vpcId = config.getVpcId(); + if (vpcId == null) { + s_logger.debug("Network " + config + " doesn't belong to any vpc, so skipping unplug nic part"); + return success; + } + + List routers = _routerDao.listRoutersByVpcId(vpcId); + for (VirtualRouter router : routers) { + //1) Check if router is already a part of the network + if (!_ntwkService.isVmPartOfNetwork(router.getId(), config.getId())) { + s_logger.debug("Router " + router + " is not a part the network " + config); + continue; + } + //2) Call unplugNics in the network service + success = success && _vpcElementService.removeVmFromNetwork(router, config); + } + + if (!success) { + s_logger.warn("Failed to unplug nic in network " + config + " for virtual router in vpc id=" + vpcId); + } else { + s_logger.debug("Successfully unplugged nic in network " + config + " for virtual router in vpc id=" + vpcId); + } + + return success; } @Override @@ -135,20 +218,4 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc return capabilities; } - - @Override - public boolean plugNic(Network network, NicProfile nic, VirtualMachineProfile vm, - ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, - InsufficientCapacityException { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean unplugNic(Network network, NicProfile nic, VirtualMachineProfile vm, - ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - } diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java index f52a39c1b82..3407e329dec 100755 --- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java @@ -42,11 +42,11 @@ import com.cloud.network.Network.State; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkProfile; import com.cloud.network.NetworkVO; -import com.cloud.network.PhysicalNetworkVO; import com.cloud.network.Networks.AddressFormat; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.Mode; import com.cloud.network.Networks.TrafficType; +import com.cloud.network.PhysicalNetworkVO; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.NetworkDao; import com.cloud.network.dao.PhysicalNetworkDao; @@ -312,16 +312,21 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { if (nic.getIp4Address() == null) { nic.setBroadcastUri(network.getBroadcastUri()); nic.setIsolationUri(network.getBroadcastUri()); - nic.setGateway(network.getGateway()); String guestIp = null; if (network.getSpecifyIpRanges()) { _networkMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIp()); } else { - guestIp = _networkMgr.acquireGuestIpAddress(network, nic.getRequestedIp()); - if (guestIp == null) { - throw new InsufficientVirtualNetworkCapcityException("Unable to acquire Guest IP" + - " address for network " + network, DataCenter.class, dc.getId()); + //if Vm is router vm, set ip4 to the network gateway + if (vm.getVirtualMachine().getType() == VirtualMachine.Type.DomainRouter) { + guestIp = network.getGateway(); + } else { + nic.setGateway(network.getGateway()); + guestIp = _networkMgr.acquireGuestIpAddress(network, nic.getRequestedIp()); + if (guestIp == null) { + throw new InsufficientVirtualNetworkCapcityException("Unable to acquire Guest IP" + + " address for network " + network, DataCenter.class, dc.getId()); + } } nic.setIp4Address(guestIp); diff --git a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java index 6655a6e4bf5..8c15d807b44 100644 --- a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java +++ b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java @@ -39,6 +39,8 @@ import com.cloud.agent.api.check.CheckSshCommand; import com.cloud.agent.api.routing.LoadBalancerConfigCommand; import com.cloud.agent.api.routing.NetworkElementCommand; import com.cloud.agent.api.to.LoadBalancerTO; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.manager.Commands; import com.cloud.api.commands.CreateLoadBalancerRuleCmd; import com.cloud.configuration.Config; @@ -512,8 +514,10 @@ public class ElasticLoadBalancerManagerImpl implements throw new CloudRuntimeException("Cannot find virtual router provider " + typeString + " as service provider " + provider.getId()); } - elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), vrProvider.getId(), VirtualMachineName.getSystemVmName(id, _instance, _elbVmNamePrefix), template.getId(), template.getHypervisorType(), - template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false, RedundantState.UNKNOWN, _elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm); + elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), vrProvider.getId(), + VirtualMachineName.getSystemVmName(id, _instance, _elbVmNamePrefix), template.getId(), template.getHypervisorType(), + template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false, RedundantState.UNKNOWN, + _elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm, null); elbVm.setRole(Role.LB); elbVm = _itMgr.allocate(elbVm, template, _elasticLbVmOffering, networks, plan, null, owner); //TODO: create usage stats @@ -984,7 +988,6 @@ public class ElasticLoadBalancerManagerImpl implements } - @Override public Long convertToId(String vmName) { if (!VirtualMachineName.isValidSystemVmName(vmName, _instance, _elbVmNamePrefix)) { @@ -993,4 +996,20 @@ public class ElasticLoadBalancerManagerImpl implements return VirtualMachineName.getSystemVmId(vmName); } + + @Override + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + //not supported + throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType()); + } + + + @Override + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { + //not supported + throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType()); + } } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 2d8629bf78f..4490af64af6 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -67,8 +67,10 @@ import com.cloud.agent.api.routing.VpnUsersCfgCommand; import com.cloud.agent.api.to.FirewallRuleTO; import com.cloud.agent.api.to.IpAddressTO; import com.cloud.agent.api.to.LoadBalancerTO; +import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.PortForwardingRuleTO; import com.cloud.agent.api.to.StaticNatRuleTO; +import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.manager.Commands; import com.cloud.alert.AlertManager; import com.cloud.api.commands.UpgradeRouterCmd; @@ -1252,7 +1254,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork); for (int i = 0; i < count; i++) { DomainRouterVO router = deployRouter(owner, dest, plan, params, publicNetwork, guestNetwork, isRedundant, - vrProvider, offeringId, sourceNatIp); + vrProvider, offeringId, sourceNatIp, null); routers.add(router); } } finally { @@ -1265,7 +1267,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map params, boolean setupPublicNetwork, Network guestNetwork, boolean isRedundant, - VirtualRouterProvider vrProvider, long svcOffId, PublicIp sourceNatIp) throws ConcurrentOperationException, + VirtualRouterProvider vrProvider, long svcOffId, PublicIp sourceNatIp, Long vpcId) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { @@ -1332,7 +1334,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false, - RedundantState.UNKNOWN, offerHA, false); + RedundantState.UNKNOWN, offerHA, false, vpcId); router.setRole(Role.VIRTUAL_ROUTER); router = _itMgr.allocate(router, template, routerOffering, networks, plan, null, owner); } catch (InsufficientCapacityException ex) { @@ -1374,8 +1376,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //1) Guest network boolean hasGuestNetwork = false; if (guestNetwork != null) { - String defaultNetworkStartIp = null; s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork); + String defaultNetworkStartIp = null; if (guestNetwork.getCidr() != null && !setupPublicNetwork) { String startIp = _networkMgr.getStartIpAddress(guestNetwork.getId()); if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) { @@ -1385,8 +1387,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian " is already allocated, can't use it for domain router; will get random ip address from the range"); } } - - NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp); if (setupPublicNetwork) { @@ -1572,6 +1572,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Override public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { + + boolean dnsProvided = true; + boolean dhcpProvided = true; DataCenterVO dc = _dcDao.findById(dest.getDataCenter().getId()); _dcDao.loadDetails(dc); @@ -1637,6 +1640,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } } else if (nic.getTrafficType() == TrafficType.Guest) { + dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dns, Provider.VirtualRouter); + dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter); //build bootloader parameter for the guest buf.append(createGuestBootLoadArgs(nic, defaultDns1, defaultDns2, router)); } else if (nic.getTrafficType() == TrafficType.Public) { @@ -1676,77 +1681,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (profile.getHypervisorType() == HypervisorType.VMware) { buf.append(" extra_pubnics=" + _routerExtraPublicNics); } + - if (s_logger.isDebugEnabled()) { - s_logger.debug("Boot Args for " + profile + ": " + buf.toString()); - } - - return true; - } - - protected StringBuilder createGuestBootLoadArgs(NicProfile guestNic, String defaultDns1, - String defaultDns2, DomainRouterVO router) { - long guestNetworkId = guestNic.getNetworkId(); - NetworkVO guestNetwork = _networkDao.findById(guestNetworkId); - String dhcpRange = null; - DataCenterVO dc = _dcDao.findById(guestNetwork.getDataCenterId()); - - if (dc.getNetworkType() == NetworkType.Advanced) { - String cidr = guestNetwork.getCidr(); - if (cidr != null) { - dhcpRange = NetUtils.getDhcpRange(cidr); - } - } - - StringBuilder buf = new StringBuilder(); - - boolean isRedundant = router.getIsRedundantRouter(); - if (isRedundant) { - buf.append(" redundant_router=1"); - List routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.VIRTUAL_ROUTER); - try { - int priority = getUpdatedPriority(guestNetwork, routers, router); - router.setPriority(priority); - } catch (InsufficientVirtualNetworkCapcityException e) { - s_logger.error("Failed to get update priority!", e); - throw new CloudRuntimeException("Failed to get update priority!"); - } - } - - - if (guestNic.isDefaultNic() && dc.getNetworkType() == NetworkType.Basic) { - long cidrSize = NetUtils.getCidrSize(guestNic.getNetmask()); - String cidr = NetUtils.getCidrSubNet(guestNic.getGateway(), cidrSize); - if (cidr != null) { - dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize); - } - } - - if (dhcpRange != null) { - buf.append(" dhcprange=" + dhcpRange); - } - - if (isRedundant) { - Network net = _networkMgr.getNetwork(guestNic.getNetworkId()); - buf.append(" guestgw=").append(net.getGateway()); - String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask())); - buf.append(" guestbrd=").append(brd); - buf.append(" guestcidrsize=").append(NetUtils.getCidrSize(guestNic.getNetmask())); - buf.append(" router_pr=").append(router.getPriority()); - } - - String domain = guestNetwork.getNetworkDomain(); - if (domain != null) { - buf.append(" domain=" + domain); - } - - boolean dnsProvided = false; - boolean dhcpProvided = false; - if (guestNic.getTrafficType() == TrafficType.Guest) { - //FiXME - for multiple guest network case this should be set individually - dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(guestNic.getNetworkId(), Service.Dns, Provider.VirtualRouter); - dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(guestNic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter); - } /* If virtual router didn't provide DNS service but provide DHCP service, we need to override the DHCP response * to return DNS server rather than * virtual router itself. */ @@ -1767,6 +1703,67 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian buf.append(" useextdns=true"); } } + + if (s_logger.isDebugEnabled()) { + s_logger.debug("Boot Args for " + profile + ": " + buf.toString()); + } + + return true; + } + + protected StringBuilder createGuestBootLoadArgs(NicProfile guestNic, String defaultDns1, + String defaultDns2, DomainRouterVO router) { + long guestNetworkId = guestNic.getNetworkId(); + NetworkVO guestNetwork = _networkDao.findById(guestNetworkId); + String dhcpRange = null; + DataCenterVO dc = _dcDao.findById(guestNetwork.getDataCenterId()); + + StringBuilder buf = new StringBuilder(); + + boolean isRedundant = router.getIsRedundantRouter(); + if (isRedundant) { + buf.append(" redundant_router=1"); + List routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.VIRTUAL_ROUTER); + try { + int priority = getUpdatedPriority(guestNetwork, routers, router); + router.setPriority(priority); + } catch (InsufficientVirtualNetworkCapcityException e) { + s_logger.error("Failed to get update priority!", e); + throw new CloudRuntimeException("Failed to get update priority!"); + } + Network net = _networkMgr.getNetwork(guestNic.getNetworkId()); + buf.append(" guestgw=").append(net.getGateway()); + String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask())); + buf.append(" guestbrd=").append(brd); + buf.append(" guestcidrsize=").append(NetUtils.getCidrSize(guestNic.getNetmask())); + buf.append(" router_pr=").append(router.getPriority()); + } + + //setup network domain + String domain = guestNetwork.getNetworkDomain(); + if (domain != null) { + buf.append(" domain=" + domain); + } + + //setup dhcp range + if (dc.getNetworkType() == NetworkType.Basic) { + if (guestNic.isDefaultNic()) { + long cidrSize = NetUtils.getCidrSize(guestNic.getNetmask()); + String cidr = NetUtils.getCidrSubNet(guestNic.getGateway(), cidrSize); + if (cidr != null) { + dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize); + } + } + } else if (dc.getNetworkType() == NetworkType.Advanced) { + String cidr = guestNetwork.getCidr(); + if (cidr != null) { + dhcpRange = NetUtils.getDhcpRange(cidr); + } + } + + if (dhcpRange != null) { + buf.append(" dhcprange=" + dhcpRange); + } return buf; } @@ -3054,4 +3051,20 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return routerControlIpAddress; } + + @Override + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + //not supported + throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType()); + } + + + @Override + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { + //not supported + throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType()); + } } diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java index a6679a03785..32da887f311 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java @@ -19,8 +19,8 @@ import com.cloud.deploy.DeployDestination; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; -import com.cloud.network.Network; import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcVirtualNetworkApplianceService; import com.cloud.user.Account; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.VirtualMachineProfile.Param; @@ -28,7 +28,7 @@ import com.cloud.vm.VirtualMachineProfile.Param; /** * @author Alena Prokharchyk */ -public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplianceManager{ +public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplianceManager, VpcVirtualNetworkApplianceService{ /** * @param vpc @@ -44,16 +44,4 @@ public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplian throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException; - /** - * @param network - * @return - */ - boolean addVpcElementToNetwork(Network network); - - /** - * @param network - * @return - */ - boolean removeVpcElementFromNetwork(Network network); - } diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index 7ef2de5070d..b24ea65c91a 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -12,6 +12,7 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.network.router; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -19,11 +20,19 @@ import javax.ejb.Local; import org.apache.log4j.Logger; +import com.cloud.agent.AgentManager.OnError; +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.PlugNicCommand; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; +import com.cloud.agent.manager.Commands; import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; +import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network; import com.cloud.network.NetworkService; @@ -33,21 +42,25 @@ import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.PhysicalNetworkDao; import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcVirtualNetworkApplianceService; import com.cloud.network.vpc.Dao.VpcDao; import com.cloud.network.vpc.Dao.VpcOfferingDao; import com.cloud.user.Account; import com.cloud.utils.Pair; import com.cloud.utils.component.Inject; import com.cloud.utils.db.DB; +import com.cloud.utils.net.NetUtils; import com.cloud.vm.DomainRouterVO; +import com.cloud.vm.ReservationContext; import com.cloud.vm.VirtualMachineProfile.Param; /** * @author Alena Prokharchyk */ -@Local(value = { VpcVirtualNetworkApplianceManager.class}) -public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplianceManagerImpl implements VpcVirtualNetworkApplianceManager{ +@Local(value = { VpcVirtualNetworkApplianceManager.class, VpcVirtualNetworkApplianceService.class,}) +public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplianceManagerImpl implements +VpcVirtualNetworkApplianceManager{ private static final Logger s_logger = Logger.getLogger(VpcVirtualNetworkApplianceManagerImpl.class); @Inject @@ -105,7 +118,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToVpc(owner, vpc); DomainRouterVO router = deployRouter(owner, dest, plan, params, true, null, false, - vrProvider, offeringId, sourceNatIp); + vrProvider, offeringId, sourceNatIp, vpc.getId()); routers.add(router); } finally { @@ -126,60 +139,61 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian } @Override - public boolean addVpcElementToNetwork(Network network) { - boolean success = true; - Long vpcId = network.getVpcId(); - if (vpcId == null) { - s_logger.debug("Network " + network + " doesn't belong to any vpc, so skipping plug nic part"); - return success; + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + + String networkDomain = network.getNetworkDomain(); + String cidr = network.getCidr(); + String dhcpRange = null; + if (cidr != null) { + dhcpRange = NetUtils.getDhcpRange(cidr); } - List routers = _routerDao.listRoutersByVpcId(vpcId); - for (VirtualRouter router : routers) { - //1) Check if router is already a part of the network - if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { - s_logger.debug("Router " + router + " is already part of the network " + network); - continue; - } - //2) Call plugNics in the network service - success = success && _ntwkService.addVmToNetwork(router, network); + boolean result = true; + + //FIXME - Anthony, here I send plug nic command + try { + Map params = new HashMap(); + params.put(PlugNicCommand.Param.NetworkDomain, networkDomain); + params.put(PlugNicCommand.Param.DhcpRange, dhcpRange); + + PlugNicCommand plugNicCmd = new PlugNicCommand(vm, nic, params); + + Commands cmds = new Commands(OnError.Stop); + cmds.addCommand("plugnic", plugNicCmd); + _agentMgr.send(dest.getHost().getId(), cmds); + + Answer plugNicAnswer = cmds.getAnswer(Answer.class); + if (!(plugNicAnswer != null && plugNicAnswer.getResult())) { + s_logger.warn("Unable to plug nic for vm " + vm.getHostName()); + result = false; + } + + } catch (OperationTimedoutException e) { + throw new AgentUnavailableException("Unable to plug nic for vm " + vm.getHostName(), dest.getHost().getId(), e); } - if (!success) { - s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId); - } else { - s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId); - } - - return success; + return result; } - + @Override - public boolean removeVpcElementFromNetwork(Network network) { - boolean success = true; - Long vpcId = network.getVpcId(); - if (vpcId == null) { - s_logger.debug("Network " + network + " doesn't belong to any vpc, so skipping unplug nic part"); - return success; - } + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { - List routers = _routerDao.listRoutersByVpcId(vpcId); - for (VirtualRouter router : routers) { - //1) Check if router is already a part of the network - if (!_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { - s_logger.debug("Router " + router + " is not a part the network " + network); - continue; - } - //2) Call unplugNics in the network service - success = success && _ntwkService.removeVmFromNetwork(router, network); - } - - if (!success) { - s_logger.warn("Failed to unplug nic in network " + network + " for virtual router in vpc id=" + vpcId); - } else { - s_logger.debug("Successfully unplugged nic in network " + network + " for virtual router in vpc id=" + vpcId); - } - - return success; + //FIXME - Anthony, add unplug nic agent command + return true; + } + + @Override + public boolean addVmToNetwork(VirtualRouter router, Network network) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException { + return _itMgr.addVmToNetwork(router, network); + } + + + @Override + public boolean removeVmFromNetwork(VirtualRouter router, Network network) { + return _itMgr.removeVmFromNetwork(router, network); } } diff --git a/server/src/com/cloud/network/vpc/VpcManager.java b/server/src/com/cloud/network/vpc/VpcManager.java index 19e268b1f12..e6f025024de 100644 --- a/server/src/com/cloud/network/vpc/VpcManager.java +++ b/server/src/com/cloud/network/vpc/VpcManager.java @@ -19,6 +19,7 @@ import java.util.Set; import com.cloud.exception.ConcurrentOperationException; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; +import com.cloud.network.element.VpcProvider; import com.cloud.network.vpc.VpcOffering.State; import com.cloud.offering.NetworkOffering; import com.cloud.user.Account; @@ -70,6 +71,11 @@ public interface VpcManager extends VpcService{ * @return * @throws ConcurrentOperationException */ - void validateGuestNtkwForVpc(NetworkOffering guestNtwkOff, String cidr, String networkDomain, Account networkOwner, Vpc vpc) throws ConcurrentOperationException; + void validateGuestNtkwForVpc(NetworkOffering guestNtwkOff, String cidr, String networkDomain, Account networkOwner, + Vpc vpc) throws ConcurrentOperationException; + /** + * @return + */ + VpcProvider getVpcElement(); } diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index ff3895ae257..c8e7f042130 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -686,7 +686,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ try { //1) CIDR is required if (cidr == null) { - throw new InvalidParameterValueException("CIDR is required when create network for VPC"); + throw new InvalidParameterValueException("Gateway/netmask are required when create network for VPC"); } //2) Network cidr should be within vpcCidr @@ -738,7 +738,8 @@ public class VpcManagerImpl implements VpcManager, Manager{ } } - private VpcProvider getVpcElement() { + @Override + public VpcProvider getVpcElement() { if (vpcElement == null) { vpcElement = ((VpcProvider)_ntwkMgr.getElementImplementingProvider(Provider.VPCVirtualRouter.getName())); } diff --git a/server/src/com/cloud/network/vpc/VpcOfferingVO.java b/server/src/com/cloud/network/vpc/VpcOfferingVO.java index 2b96f2047dc..2109e1c0cd7 100644 --- a/server/src/com/cloud/network/vpc/VpcOfferingVO.java +++ b/server/src/com/cloud/network/vpc/VpcOfferingVO.java @@ -130,7 +130,6 @@ public class VpcOfferingVO implements VpcOffering{ return buf.append(id).append("-").append(name).append("]").toString(); } - public void setName(String name) { this.name = name; } diff --git a/server/src/com/cloud/network/vpc/VpcVO.java b/server/src/com/cloud/network/vpc/VpcVO.java index a20d5c2b9ae..9f6c9379040 100644 --- a/server/src/com/cloud/network/vpc/VpcVO.java +++ b/server/src/com/cloud/network/vpc/VpcVO.java @@ -165,5 +165,11 @@ public class VpcVO implements Vpc, Identity { public void setDisplayText(String displayText) { this.displayText = displayText; } + + @Override + public String toString() { + StringBuilder buf = new StringBuilder("[VPC ["); + return buf.append(id).append("-").append(name).append("]").toString(); + } } diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 3c79e4e363b..5bb1858f388 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -1076,8 +1076,9 @@ public class ConfigurationServerImpl implements ConfigurationServer { } if (broadcastDomainType != null) { - NetworkVO network = new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, domainId, accountId, related, null, null, networkDomain, Network.GuestType.Shared, zoneId, null, - null, specifyIpRanges); + NetworkVO network = new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, + domainId, accountId, related, null, null, networkDomain, Network.GuestType.Shared, zoneId, null, + null, specifyIpRanges, null); network.setGuruName(guruNames.get(network.getTrafficType())); network.setDns1(zone.getDns1()); network.setDns2(zone.getDns2()); diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index 6accab99594..470f363d39b 100755 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -42,6 +42,8 @@ import com.cloud.agent.api.StartupStorageCommand; import com.cloud.agent.api.StopAnswer; import com.cloud.agent.api.check.CheckSshAnswer; import com.cloud.agent.api.check.CheckSshCommand; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.manager.Commands; import com.cloud.capacity.dao.CapacityDao; import com.cloud.cluster.ClusterManager; @@ -68,6 +70,7 @@ import com.cloud.info.RunningHostCountInfo; import com.cloud.info.RunningHostInfoAgregator; import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo; import com.cloud.keystore.KeystoreManager; +import com.cloud.network.Network; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.TrafficType; @@ -1412,4 +1415,20 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } return null; } + + @Override + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + //not supported + throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType()); + } + + + @Override + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { + //not supported + throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType()); + } } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 11000762ec1..de0a237085f 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -3582,5 +3582,20 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager return vm; } + @Override + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + //not supported + throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType()); + } + + + @Override + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { + //not supported + throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType()); + } } diff --git a/server/src/com/cloud/vm/VirtualMachineGuru.java b/server/src/com/cloud/vm/VirtualMachineGuru.java index f736310ebb8..f8355f580cf 100644 --- a/server/src/com/cloud/vm/VirtualMachineGuru.java +++ b/server/src/com/cloud/vm/VirtualMachineGuru.java @@ -13,9 +13,15 @@ package com.cloud.vm; import com.cloud.agent.api.StopAnswer; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.manager.Commands; import com.cloud.deploy.DeployDestination; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InsufficientNetworkCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network; /** * A VirtualMachineGuru knows how to process a certain type of virtual machine. @@ -68,4 +74,34 @@ public interface VirtualMachineGuru { * @return id if the handler works for this vm and can parse id. null if not. */ Long convertToId(String vmName); + + /** + * Prepare for a nic to be plugged into the network. + * @param network + * @param nic + * @param vm + * @param context + * @param dest TODO + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + * @throws InsufficientNetworkCapacityException + */ + boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException; + + /** + * A nic is unplugged from this network. + * @param network + * @param nic + * @param vm + * @param context + * @param dest TODO + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + */ + boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/server/src/com/cloud/vm/VirtualMachineManager.java b/server/src/com/cloud/vm/VirtualMachineManager.java index 3387a8e22e7..a7f89ba5cd1 100644 --- a/server/src/com/cloud/vm/VirtualMachineManager.java +++ b/server/src/com/cloud/vm/VirtualMachineManager.java @@ -15,6 +15,7 @@ package com.cloud.vm; import java.util.List; import java.util.Map; +import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; import com.cloud.exception.AgentUnavailableException; @@ -26,6 +27,7 @@ import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.VirtualMachineMigrationException; import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.network.Network; import com.cloud.network.NetworkVO; import com.cloud.offering.ServiceOffering; import com.cloud.service.ServiceOfferingVO; @@ -132,4 +134,22 @@ public interface VirtualMachineManager extends Manager { */ boolean upgradeVmDb(long vmId, long serviceOfferingId); + /** + * @param vm + * @param network + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + * @throws InsufficientCapacityException + */ + boolean addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException; + + /** + * @param vm + * @param network + * @return + */ + boolean removeVmFromNetwork(VirtualMachine vm, Network network); + } diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index b73d0fd8e48..c2809153240 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -57,6 +57,7 @@ import com.cloud.agent.api.StartupRoutingCommand; import com.cloud.agent.api.StartupRoutingCommand.VmState; import com.cloud.agent.api.StopAnswer; import com.cloud.agent.api.StopCommand; +import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.manager.Commands; import com.cloud.agent.manager.allocator.HostAllocator; @@ -103,6 +104,7 @@ import com.cloud.hypervisor.HypervisorGuruManager; import com.cloud.network.Network; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; +import com.cloud.network.dao.NetworkDao; import com.cloud.offering.ServiceOffering; import com.cloud.org.Cluster; import com.cloud.resource.ResourceManager; @@ -217,6 +219,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene protected StoragePoolDao _storagePoolDao; @Inject protected HypervisorGuruManager _hvGuruMgr; + @Inject + protected NetworkDao _networkDao; @Inject(adapter = DeploymentPlanner.class) protected Adapters _planners; @@ -748,11 +752,10 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene reuseVolume = true; } - VirtualMachineTO vmTO = null; Commands cmds = null; vmGuru.finalizeVirtualMachineProfile(vmProfile, dest, ctx); - vmTO = hvGuru.implement(vmProfile); + VirtualMachineTO vmTO = hvGuru.implement(vmProfile); cmds = new Commands(OnError.Stop); cmds.addCommand(new StartCommand(vmTO)); @@ -2426,4 +2429,53 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene vmForUpdate.setServiceOfferingId(newSvcOff.getId()); return _vmDao.update(vmId, vmForUpdate); } + + @Override + public boolean addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException { + + VMInstanceVO vmVO = _vmDao.findById(vm.getId()); + NetworkVO networkVO = _networkDao.findById(network.getId()); + ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), + _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM)); + + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, + null, null, null); + + DataCenter dc = _configMgr.getZone(network.getDataCenterId()); + Host host = _hostDao.findById(vm.getHostId()); + DeployDestination dest = new DeployDestination(dc, null, null, host); + + s_logger.debug("Adding vm " + vm + " to network " + network); + + //1) allocate nic + NicProfile nic = _networkMgr.allocateNic(null, network, false, + 100, vmProfile).first(); + + //2) Prepare nic + nic = _networkMgr.prepareNic(vmProfile, dest, context, nic.getId(), networkVO); + + //3) plug the nic to the vm + VirtualMachineGuru vmGuru = getVmGuru(vmVO); + + //4) Convert vmProfile to vmTO + HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType()); + VirtualMachineTO vmTO = hvGuru.implement(vmProfile); + + //5) Convert nicProfile to NicTO + NicTO nicTO = hvGuru.toNicTO(nic); + + return vmGuru.plugNic(network, nicTO, vmTO, context, null); + + } + + @Override + public boolean removeVmFromNetwork(VirtualMachine vm, Network network) { + //1) TODO - release the nic + + //2) TODO - unplug the nic + + return true; + } + } diff --git a/server/src/com/cloud/vm/dao/DomainRouterDao.java b/server/src/com/cloud/vm/dao/DomainRouterDao.java index dfac0928843..36ee86ce329 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDao.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDao.java @@ -111,4 +111,10 @@ public interface DomainRouterDao extends GenericDao { * @return */ List listRoutersByVpcId(long vpcId); + + /** + * @param routerId + * @param guestNetwork + */ + void addRouterToNetwork(DomainRouterVO router, Network guestNetwork); } diff --git a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java index 11f982cfaed..bac97751df3 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java @@ -47,7 +47,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im HostDaoImpl _hostsDao = ComponentLocator.inject(HostDaoImpl.class); RouterNetworkDaoImpl _routerNetworkDao = ComponentLocator.inject(RouterNetworkDaoImpl.class); UserStatisticsDaoImpl _userStatsDao = ComponentLocator.inject(UserStatisticsDaoImpl.class); - + protected final SearchBuilder VpcSearch; protected DomainRouterDaoImpl() { AllFieldsSearch = createSearchBuilder(); @@ -65,6 +65,11 @@ public class DomainRouterDaoImpl extends GenericDaoBase im AllFieldsSearch.and("elementId", AllFieldsSearch.entity().getElementId(), Op.EQ); AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ); AllFieldsSearch.done(); + + VpcSearch = createSearchBuilder(); + VpcSearch.and("role", VpcSearch.entity().getRole(), Op.EQ); + VpcSearch.and("vpcId", VpcSearch.entity().getVpcId(), Op.EQ); + VpcSearch.done(); IdNetworkIdStatesSearch = createSearchBuilder(); IdNetworkIdStatesSearch.and("id", IdNetworkIdStatesSearch.entity().getId(), Op.EQ); @@ -259,15 +264,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im if (guestNetworks != null && !guestNetworks.isEmpty()) { // 2) add router to the network for (Network guestNetwork : guestNetworks) { - addRouterToNetwork(router.getId(), guestNetwork); - // 3) create user stats entry - UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(), - guestNetwork.getId(), null, router.getId(), router.getType().toString()); - if (stats == null) { - stats = new UserStatisticsVO(router.getAccountId(), router.getDataCenterIdToDeployIn(), null, router.getId(), - router.getType().toString(), guestNetwork.getId()); - _userStatsDao.persist(stats); - } + addRouterToNetwork(router, guestNetwork); } } @@ -275,10 +272,21 @@ public class DomainRouterDaoImpl extends GenericDaoBase im return newRouter; } - - protected void addRouterToNetwork(long routerId, Network guestNetwork) { - RouterNetworkVO routerNtwkMap = new RouterNetworkVO(routerId, guestNetwork.getId(), guestNetwork.getGuestType()); + @Override + @DB + public void addRouterToNetwork(DomainRouterVO router, Network guestNetwork) { + + //1) add router to network + RouterNetworkVO routerNtwkMap = new RouterNetworkVO(router.getId(), guestNetwork.getId(), guestNetwork.getGuestType()); _routerNetworkDao.persist(routerNtwkMap); + //2) create user stats entry for the network + UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(), + guestNetwork.getId(), null, router.getId(), router.getType().toString()); + if (stats == null) { + stats = new UserStatisticsVO(router.getAccountId(), router.getDataCenterIdToDeployIn(), null, router.getId(), + router.getType().toString(), guestNetwork.getId()); + _userStatsDao.persist(stats); + } } @Override @@ -288,7 +296,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override public List listRoutersByVpcId(long vpcId) { - SearchCriteria sc = AllFieldsSearch.create(); + SearchCriteria sc = VpcSearch.create(); sc.setParameters("vpcId", vpcId); sc.setParameters("role", Role.VIRTUAL_ROUTER); return listBy(sc); diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index a07b2c564f2..1921c503d57 100755 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -201,7 +201,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS @Override public List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId, - ACLType aclType, Boolean subdomainAccess) throws ConcurrentOperationException { + ACLType aclType, Boolean subdomainAccess, Long vpcId) throws ConcurrentOperationException { // TODO Auto-generated method stub return null; } diff --git a/wscript b/wscript index 844085841e7..2e9f510fdd4 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-22T23:46:23Z' +VERSION = '3.0.3.2012-05-23T23:17:18Z' APPNAME = 'cloud' import shutil,os