diff --git a/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml b/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml index 55420c03b97..f3dbe3f69d4 100644 --- a/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml +++ b/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml @@ -177,13 +177,24 @@ + + + + + + + + + + params = new HashMap(1); params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true); - RouterDeploymentDefinition routerDeploymentDefinition = - new RouterDeploymentDefinition(network, dest,_accountMgr.getAccount(network.getAccountId()), - params, offering.getRedundantRouter()); + RouterDeploymentDefinition routerDeploymentDefinition = new RouterDeploymentDefinition(network, dest, _accountMgr.getAccount(network.getAccountId()), params, + offering.getRedundantRouter()); List routers = _routerMgr.deployVirtualRouter(routerDeploymentDefinition); int routerCounts = 1; @@ -207,8 +205,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor { routerCounts = 2; } if (routers == null || routers.size() < routerCounts) { - throw new ResourceUnavailableException("Can't find all necessary running routers!", - DataCenter.class, network.getDataCenterId()); + throw new ResourceUnavailableException("Can't find all necessary running routers!", DataCenter.class, network.getDataCenterId()); } return true; @@ -233,11 +230,9 @@ NetworkMigrationResponder, AggregatedCommandExecutor { return false; } - RouterDeploymentDefinition routerDeploymentDefinition = - new RouterDeploymentDefinition(network, dest,_accountMgr.getAccount(network.getAccountId()), - vm.getParameters(), offering.getRedundantRouter()); - List routers = - _routerMgr.deployVirtualRouter(routerDeploymentDefinition); + RouterDeploymentDefinition routerDeploymentDefinition = new RouterDeploymentDefinition(network, dest, _accountMgr.getAccount(network.getAccountId()), vm.getParameters(), + offering.getRedundantRouter()); + List routers = _routerMgr.deployVirtualRouter(routerDeploymentDefinition); if (routers == null || routers.size() == 0) { throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId()); @@ -250,8 +245,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor { if (canHandle(network, Service.Firewall)) { List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " + "router doesn't exist in the network " + - network.getId()); + s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " + "router doesn't exist in the network " + network.getId()); return true; } @@ -264,7 +258,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor { } DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId()); - NetworkTopology networkTopology = NetworkTopologyContext.getInstance().retrieveNetworkTopology(dcVO); + NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO); if (!networkTopology.applyFirewallRules(network, rules, routers)) { throw new CloudRuntimeException("Failed to apply firewall rules in network " + network.getId()); @@ -277,9 +271,9 @@ NetworkMigrationResponder, AggregatedCommandExecutor { } /* - * This function detects numbers like 12 ,32h ,42m .. etc,. 1) plain - * number like 12 2) time or tablesize like 12h, 34m, 45k, 54m , here - * last character is non-digit but from known characters . + * This function detects numbers like 12 ,32h ,42m .. etc,. 1) plain number + * like 12 2) time or tablesize like 12h, 34m, 45k, 54m , here last + * character is non-digit but from known characters . */ private static boolean containsOnlyNumbers(final String str, final String endChar) { if (str == null) { @@ -289,8 +283,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor { String number = str; if (endChar != null) { boolean matchedEndChar = false; - if (str.length() < 2) - { + if (str.length() < 2) { return false; // atleast one numeric and one char. example: } // 3h @@ -402,7 +395,10 @@ NetworkMigrationResponder, AggregatedCommandExecutor { return true; } - if (!_routerMgr.applyLoadBalancingRules(network, rules, routers)) { + DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId()); + NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO); + + if (!networkTopology.applyLoadBalancingRules(network, rules, routers)) { throw new CloudRuntimeException("Failed to apply load balancing rules in network " + network.getId()); } else { return true; @@ -422,8 +418,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor { if (canHandle(network, Service.Vpn)) { List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router elemnt doesn't need to apply vpn users on the backend; virtual router" + " doesn't exist in the network " + - network.getId()); + s_logger.debug("Virtual router elemnt doesn't need to apply vpn users on the backend; virtual router" + " doesn't exist in the network " + network.getId()); return null; } return _routerMgr.applyVpnUsers(network, users, routers); @@ -485,8 +480,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor { if (canHandle) { List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router elemnt doesn't need to associate ip addresses on the backend; virtual " + "router doesn't exist in the network " + - network.getId()); + s_logger.debug("Virtual router elemnt doesn't need to associate ip addresses on the backend; virtual " + "router doesn't exist in the network " + network.getId()); return true; } @@ -537,10 +531,8 @@ NetworkMigrationResponder, AggregatedCommandExecutor { + "For the record, sending 10 domains to MSIE 6 or Firefox 2 works as expected.", false); methodList.add(method); - method = - new LbStickinessMethod(StickinessMethodType.AppCookieBased, - "This is App session based sticky method. Define session stickiness on an existing application cookie. " - + "It can be used only for a specific http traffic"); + method = new LbStickinessMethod(StickinessMethodType.AppCookieBased, + "This is App session based sticky method. Define session stickiness on an existing application cookie. " + "It can be used only for a specific http traffic"); method.addParam("cookie-name", false, "This is the name of the cookie used by the application and which LB will " + "have to learn for each new session. Default value: Auto geneared based on ip", false); method.addParam("length", false, "This is the max number of characters that will be memorized and checked in " + "each cookie value. Default value:52", false); @@ -557,7 +549,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor { false, "When this option is specified, haproxy will match on the cookie prefix (or URL parameter prefix). " + "The appsession value is the data following this prefix. Example : appsession ASPSESSIONID len 64 timeout 3h prefix This will match the cookie ASPSESSIONIDXXXX=XXXXX, the appsession value will be XXXX=XXXXX.", - true); + true); method.addParam("mode", false, "This option allows to change the URL parser mode. 2 modes are currently supported : - path-parameters " + ": The parser looks for the appsession in the path parameters part (each parameter is separated by a semi-colon), " + "which is convenient for JSESSIONID for example.This is the default mode if the option is not set. - query-string :" @@ -586,7 +578,8 @@ NetworkMigrationResponder, AggregatedCommandExecutor { lbCapabilities.put(Capability.SupportedStickinessMethods, getHAProxyStickinessCapability()); lbCapabilities.put(Capability.LbSchemes, LoadBalancerContainer.Scheme.Public.toString()); - //specifies that LB rules can support autoscaling and the list of counters it supports + // specifies that LB rules can support autoscaling and the list of + // counters it supports AutoScaleCounter counter; List counterList = new ArrayList(); counter = new AutoScaleCounter(AutoScaleCounterCpu); @@ -641,8 +634,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor { if (canHandle(config, Service.StaticNat)) { List routers = _routerDao.listByNetworkAndRole(config.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router elemnt doesn't need to apply static nat on the backend; virtual " + "router doesn't exist in the network " + - config.getId()); + s_logger.debug("Virtual router elemnt doesn't need to apply static nat on the backend; virtual " + "router doesn't exist in the network " + config.getId()); return true; } @@ -681,7 +673,9 @@ NetworkMigrationResponder, AggregatedCommandExecutor { return true; } boolean result = true; - // NOTE that we need to pass caller account to destroyRouter, otherwise it will fail permission check there. Context passed in from deleteNetwork is the network account, + // NOTE that we need to pass caller account to destroyRouter, otherwise + // it will fail permission check there. Context passed in from + // deleteNetwork is the network account, // not caller account Account callerAccount = _accountMgr.getAccount(context.getCaller().getAccountId()); for (DomainRouterVO router : routers) { @@ -704,7 +698,8 @@ NetworkMigrationResponder, AggregatedCommandExecutor { @SuppressWarnings("unchecked") VirtualMachineProfile uservm = vm; - // If any router is running then send save password command otherwise save the password in DB + // If any router is running then send save password command otherwise + // save the password in DB for (VirtualRouter router : routers) { if (router.getState() == State.Running) { return _routerMgr.savePasswordToRouter(network, nic, uservm, routers); @@ -784,8 +779,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor { public OvsProvider configure(final ConfigureOvsElementCmd cmd) { OvsProviderVO element = _ovsProviderDao.findById(cmd.getId()); if (element == null) { - s_logger.debug("Can't find Ovs element with network service provider id " - + cmd.getId()); + s_logger.debug("Can't find Ovs element with network service provider id " + cmd.getId()); return null; } @@ -798,8 +792,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor { @Override public VirtualRouterProvider addElement(final Long nspId, final Type providerType) { if (!(providerType == Type.VirtualRouter || providerType == Type.VPCVirtualRouter)) { - throw new InvalidParameterValueException("Element " + getName() + " supports only providerTypes: " + Type.VirtualRouter.toString() + " and " + - Type.VPCVirtualRouter); + throw new InvalidParameterValueException("Element " + getName() + " supports only providerTypes: " + Type.VirtualRouter.toString() + " and " + Type.VPCVirtualRouter); } VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(nspId, providerType); if (element != null) { @@ -816,8 +809,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor { if (canHandle(network, Service.PortForwarding)) { List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " + "router doesn't exist in the network " + - network.getId()); + s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " + "router doesn't exist in the network " + network.getId()); return true; } @@ -842,7 +834,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor { @Override public boolean shutdownProviderInstances(final PhysicalNetworkServiceProvider provider, final ReservationContext context) throws ConcurrentOperationException, - ResourceUnavailableException { + ResourceUnavailableException { VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), getVirtualRouterProvider()); if (element == null) { return true; @@ -880,13 +872,13 @@ NetworkMigrationResponder, AggregatedCommandExecutor { @Override public boolean release(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final ReservationContext context) throws ConcurrentOperationException, - ResourceUnavailableException { + ResourceUnavailableException { return true; } @Override - public boolean configDhcpSupportForSubnet(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) - throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + public boolean configDhcpSupportForSubnet(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, + final ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { if (canHandle(network, Service.Dhcp)) { if (vm.getType() != VirtualMachine.Type.User) { return false; @@ -944,8 +936,8 @@ NetworkMigrationResponder, AggregatedCommandExecutor { } @Override - public boolean addPasswordAndUserdata(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) - throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + public boolean addPasswordAndUserdata(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, + final ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { if (canHandle(network, Service.UserData)) { if (vm.getType() != VirtualMachine.Type.User) { return false; @@ -975,9 +967,8 @@ NetworkMigrationResponder, AggregatedCommandExecutor { if (_networkMdl.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, getProvider())) { publicNetwork = true; } - boolean isPodBased = - (dest.getDataCenter().getNetworkType() == NetworkType.Basic || _networkMdl.isSecurityGroupSupportedInNetwork(network)) && - network.getTrafficType() == TrafficType.Guest; + boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic || _networkMdl.isSecurityGroupSupportedInNetwork(network)) + && network.getTrafficType() == TrafficType.Guest; List routers; @@ -988,15 +979,18 @@ NetworkMigrationResponder, AggregatedCommandExecutor { Long podId = dest.getPod().getId(); routers = _routerDao.listByNetworkAndPodAndRole(network.getId(), podId, Role.VIRTUAL_ROUTER); } else { - // With pod == null, it's network restart case, we would add all router to it + // With pod == null, it's network restart case, we would add all + // router to it // Ignore DnsBasicZoneUpdate() parameter here routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); } } - // for Basic zone, add all Running routers - we have to send Dhcp/vmData/password info to them when + // for Basic zone, add all Running routers - we have to send + // Dhcp/vmData/password info to them when // network.dns.basiczone.updates is set to "all" - // With pod == null, it's network restart case, we already add all routers to it + // With pod == null, it's network restart case, we already add all + // routers to it if (isPodBased && dest.getPod() != null && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) { Long podId = dest.getPod().getId(); List allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), podId, State.Running, Role.VIRTUAL_ROUTER); @@ -1022,7 +1016,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor { sc.and(sc.entity().isEnabled(), Op.EQ, enabled); } - //return only VR and VPC VR + // return only VR and VPC VR sc.and(sc.entity().getType(), Op.IN, VirtualRouterProvider.Type.VPCVirtualRouter, VirtualRouterProvider.Type.VirtualRouter); return sc.list(); @@ -1091,11 +1085,11 @@ NetworkMigrationResponder, AggregatedCommandExecutor { } if (vm.getType() == VirtualMachine.Type.DomainRouter) { assert vm instanceof DomainRouterVO; - DomainRouterVO router = (DomainRouterVO)vm.getVirtualMachine(); + DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine(); _routerMgr.setupDhcpForPvlan(false, router, router.getHostId(), nic); } else if (vm.getType() == VirtualMachine.Type.User) { assert vm instanceof UserVmVO; - UserVmVO userVm = (UserVmVO)vm.getVirtualMachine(); + UserVmVO userVm = (UserVmVO) vm.getVirtualMachine(); _userVmMgr.setupVmForPvlan(false, userVm.getHostId(), nic); } return true; @@ -1108,11 +1102,11 @@ NetworkMigrationResponder, AggregatedCommandExecutor { } if (vm.getType() == VirtualMachine.Type.DomainRouter) { assert vm instanceof DomainRouterVO; - DomainRouterVO router = (DomainRouterVO)vm.getVirtualMachine(); + DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine(); _routerMgr.setupDhcpForPvlan(true, router, router.getHostId(), nic); } else if (vm.getType() == VirtualMachine.Type.User) { assert vm instanceof UserVmVO; - UserVmVO userVm = (UserVmVO)vm.getVirtualMachine(); + UserVmVO userVm = (UserVmVO) vm.getVirtualMachine(); _userVmMgr.setupVmForPvlan(true, userVm.getHostId(), nic); } } @@ -1124,11 +1118,11 @@ NetworkMigrationResponder, AggregatedCommandExecutor { } if (vm.getType() == VirtualMachine.Type.DomainRouter) { assert vm instanceof DomainRouterVO; - DomainRouterVO router = (DomainRouterVO)vm.getVirtualMachine(); + DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine(); _routerMgr.setupDhcpForPvlan(true, router, router.getHostId(), nic); } else if (vm.getType() == VirtualMachine.Type.User) { assert vm instanceof UserVmVO; - UserVmVO userVm = (UserVmVO)vm.getVirtualMachine(); + UserVmVO userVm = (UserVmVO) vm.getVirtualMachine(); _userVmMgr.setupVmForPvlan(true, userVm.getHostId(), nic); } } @@ -1157,7 +1151,8 @@ NetworkMigrationResponder, AggregatedCommandExecutor { @Override public boolean cleanupAggregatedExecution(final Network network, final DeployDestination dest) throws ResourceUnavailableException { - // The VR code already cleansup in the Finish routine using finally, lets not waste another command + // The VR code already cleansup in the Finish routine using finally, + // lets not waste another command return true; } } diff --git a/server/src/com/cloud/network/router/NEWVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/NEWVirtualNetworkApplianceManagerImpl.java new file mode 100644 index 00000000000..7e416abdfcb --- /dev/null +++ b/server/src/com/cloud/network/router/NEWVirtualNetworkApplianceManagerImpl.java @@ -0,0 +1,301 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with 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. +package com.cloud.network.router; + +import java.util.List; +import java.util.Map; + +import javax.ejb.Local; +import javax.inject.Inject; +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd; +import org.apache.cloudstack.api.command.admin.router.UpgradeRouterTemplateCmd; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.log4j.Logger; + +import com.cloud.agent.AgentManager; +import com.cloud.agent.api.Answer; +import com.cloud.agent.manager.Commands; +import com.cloud.deploy.DeployDestination; +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.maint.Version; +import com.cloud.network.Network; +import com.cloud.network.RemoteAccessVpn; +import com.cloud.network.VirtualNetworkApplianceService; +import com.cloud.user.Account; +import com.cloud.user.User; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.DomainRouterVO; +import com.cloud.vm.VirtualMachineProfile.Param; + + +/** + * NetworkManager manages the network for the different end users. + * + */ +@Local(value = { NEWVirtualNetworkApplianceManager.class, VirtualNetworkApplianceService.class }) +public class NEWVirtualNetworkApplianceManagerImpl implements NEWVirtualNetworkApplianceManager { + + private static final Logger s_logger = Logger.getLogger(NEWVirtualNetworkApplianceManagerImpl.class); + + static final ConfigKey routerVersionCheckEnabled = new ConfigKey("Advanced", Boolean.class, "router.version.check", "true", + "If true, router minimum required version is checked before sending command", false); + + @Inject + private AgentManager _agentMgr; + + @Override + public String getName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setName(final String name) { + // TODO Auto-generated method stub + + } + + @Override + public void setConfigParams(final Map params) { + // TODO Auto-generated method stub + + } + + @Override + public Map getConfigParams() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getRunLevel() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setRunLevel(final int level) { + // TODO Auto-generated method stub + + } + + @Override + public boolean configure(final String name, final Map params) + throws ConfigurationException { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean start() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean stop() { + // TODO Auto-generated method stub + return false; + } + + @Override + public VirtualRouter startRouter(final long routerId, final boolean reprogramNetwork) + throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + // TODO Auto-generated method stub + return null; + } + + @Override + public VirtualRouter rebootRouter(final long routerId, final boolean reprogramNetwork) + throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + // TODO Auto-generated method stub + return null; + } + + @Override + public VirtualRouter upgradeRouter(final UpgradeRouterCmd cmd) { + // TODO Auto-generated method stub + return null; + } + + @Override + public VirtualRouter stopRouter(final long routerId, final boolean forced) + throws ResourceUnavailableException, ConcurrentOperationException { + // TODO Auto-generated method stub + return null; + } + + @Override + public VirtualRouter startRouter(final long id) + throws ResourceUnavailableException, InsufficientCapacityException, + ConcurrentOperationException { + // TODO Auto-generated method stub + return null; + } + + @Override + public VirtualRouter destroyRouter(final long routerId, final Account caller, + final Long callerUserId) throws ResourceUnavailableException, + ConcurrentOperationException { + // TODO Auto-generated method stub + return null; + } + + @Override + public VirtualRouter findRouter(final long routerId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List upgradeRouterTemplate(final UpgradeRouterTemplateCmd cmd) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List deployVirtualRouterInGuestNetwork( + final Network guestNetwork, final DeployDestination dest, final Account owner, + final Map params, final boolean isRedundant) + throws InsufficientCapacityException, ResourceUnavailableException, + ConcurrentOperationException { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean startRemoteAccessVpn(final Network network, final RemoteAccessVpn vpn, + final List routers) + throws ResourceUnavailableException { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean deleteRemoteAccessVpn(final Network network, final RemoteAccessVpn vpn, + final List routers) + throws ResourceUnavailableException { + // TODO Auto-generated method stub + return false; + } + + @Override + public List getRoutersForNetwork(final long networkId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public VirtualRouter stop(final VirtualRouter router, final boolean forced, + final User callingUser, final Account callingAccount) + throws ConcurrentOperationException, ResourceUnavailableException { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getDnsBasicZoneUpdate() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean removeDhcpSupportForSubnet(final Network network, + final List routers) throws ResourceUnavailableException { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean prepareAggregatedExecution(final Network network, + final List routers) throws AgentUnavailableException { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean completeAggregatedExecution(final Network network, + final List routers) throws AgentUnavailableException { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean cleanupAggregatedExecution(final Network network, + final List routers) throws AgentUnavailableException { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean sendCommandsToRouter(final VirtualRouter router, final Commands cmds) throws AgentUnavailableException { + if(!checkRouterVersion(router)){ + s_logger.debug("Router requires upgrade. Unable to send command to router:" + router.getId() + ", router template version : " + router.getTemplateVersion() + + ", minimal required version : " + MinVRVersion); + throw new CloudRuntimeException("Unable to send command. Upgrade in progress. Please contact administrator."); + } + Answer[] answers = null; + try { + answers = _agentMgr.send(router.getHostId(), cmds); + } catch (final OperationTimedoutException e) { + s_logger.warn("Timed Out", e); + throw new AgentUnavailableException("Unable to send commands to virtual router ", router.getHostId(), e); + } + + if (answers == null) { + return false; + } + + if (answers.length != cmds.size()) { + return false; + } + + // FIXME: Have to return state for individual command in the future + boolean result = true; + if (answers.length > 0) { + for (final Answer answer : answers) { + if (!answer.getResult()) { + result = false; + break; + } + } + } + return result; + } + + // Checks if the router is at the required version + // Compares MS version and router version + protected boolean checkRouterVersion(final VirtualRouter router) { + if(!routerVersionCheckEnabled.value()){ + //Router version check is disabled. + return true; + } + if(router.getTemplateVersion() == null){ + return false; + } + final String trimmedVersion = Version.trimRouterVersion(router.getTemplateVersion()); + return (Version.compare(trimmedVersion, MinVRVersion) >= 0); + } +} \ No newline at end of file diff --git a/server/src/com/cloud/network/rules/RuleApplier.java b/server/src/com/cloud/network/rules/RuleApplier.java index 70ca79360c3..a3f42f1c5d2 100644 --- a/server/src/com/cloud/network/rules/RuleApplier.java +++ b/server/src/com/cloud/network/rules/RuleApplier.java @@ -82,10 +82,6 @@ public abstract class RuleApplier { return router; } - public void setManager(final NEWVirtualNetworkApplianceManager applianceManager) { - this.applianceManager = applianceManager; - } - public NEWVirtualNetworkApplianceManager getApplianceManager() { return applianceManager; } diff --git a/server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java b/server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java index 88c3542426d..694119c53e1 100644 --- a/server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java +++ b/server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java @@ -14,8 +14,10 @@ import com.cloud.network.dao.LoadBalancerDao; import com.cloud.network.dao.NetworkDao; import com.cloud.network.lb.LoadBalancingRule; import com.cloud.network.lb.LoadBalancingRulesManager; +import com.cloud.network.router.NEWVirtualNetworkApplianceManager; import com.cloud.network.router.RouterControlHelper; import com.cloud.offerings.dao.NetworkOfferingDao; +import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.NicDao; @@ -36,6 +38,9 @@ public class VirtualNetworkApplianceFactory { @Inject protected NicDao nicDao; + @Inject + protected VirtualMachineManager itMgr; + @Inject protected NetworkOfferingDao networkOfferingDao; @@ -54,6 +59,9 @@ public class VirtualNetworkApplianceFactory { @Inject protected RouterControlHelper routerControlHelper; + @Inject + protected NEWVirtualNetworkApplianceManager applianceManager; + public LoadBalancingRules createLoadBalancingRules(final Network network, final List rules) { @@ -83,8 +91,10 @@ public class VirtualNetworkApplianceFactory { applier.loadBalancerDao = loadBalancerDao; applier.configDao = configDao; applier.nicDao = nicDao; + applier.itMgr = itMgr; applier.networkOfferingDao = networkOfferingDao; applier.routerDao = routerDao; applier.routerControlHelper = routerControlHelper; + applier.applianceManager = applianceManager; } } diff --git a/server/src/com/cloud/network/topology/BasicNetworkTopology.java b/server/src/com/cloud/network/topology/BasicNetworkTopology.java index fb34eb51d4e..58bd760cfca 100644 --- a/server/src/com/cloud/network/topology/BasicNetworkTopology.java +++ b/server/src/com/cloud/network/topology/BasicNetworkTopology.java @@ -116,7 +116,7 @@ public class BasicNetworkTopology implements NetworkTopology { RuleApplier ruleApplier = ruleApplierWrapper.getRuleType(); - // REMOVE THIS SHIT AND INJECT USING A FACTORY FOR THE VISITORS + // [FIXME] REMOVE THIS SHIT AND INJECT USING A FACTORY FOR THE VISITORS visitor.setApplianceManager(ruleApplier.getApplianceManager()); final DataCenter dc = _dcDao.findById(network.getDataCenterId()); @@ -175,7 +175,7 @@ public class BasicNetworkTopology implements NetworkTopology { if (!isZoneBasic && !disconnectedRouters.isEmpty() && disconnectedRouters.get(0).getIsRedundantRouter()) { // These disconnected redundant virtual routers are out of sync // now, stop them for synchronization - // handleSingleWorkingRedundantRouter(connectedRouters, + // [FIXME] handleSingleWorkingRedundantRouter(connectedRouters, // disconnectedRouters, msg); } } else if (!disconnectedRouters.isEmpty()) { @@ -206,6 +206,8 @@ public class BasicNetworkTopology implements NetworkTopology { return true; } + s_logger.debug("APPLYING LOAD BALANCING RULES"); + final String typeString = "loadbalancing rules"; final boolean isPodLevelException = false; final boolean failWhenDisconnect = false; @@ -224,6 +226,8 @@ public class BasicNetworkTopology implements NetworkTopology { return true; } + s_logger.debug("APPLYING FIREWALL RULES"); + final String typeString = "firewall rules"; final boolean isPodLevelException = false; final boolean failWhenDisconnect = false; diff --git a/server/src/com/cloud/network/topology/NetworkTopologyContext.java b/server/src/com/cloud/network/topology/NetworkTopologyContext.java index 9b8bb90729f..168c4cc8eda 100644 --- a/server/src/com/cloud/network/topology/NetworkTopologyContext.java +++ b/server/src/com/cloud/network/topology/NetworkTopologyContext.java @@ -19,27 +19,24 @@ package com.cloud.network.topology; import java.util.Hashtable; +import javax.inject.Inject; + import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter.NetworkType; -public final class NetworkTopologyContext { +public class NetworkTopologyContext { - private static NetworkTopologyContext instance; + private final Hashtable flyweight = new Hashtable();; - static { - instance = new NetworkTopologyContext(); - } + @Inject + private BasicNetworkTopology basicNetworkTopology; - private final Hashtable flyweight; + @Inject + private AdvancedNetworkTopology advancedNetworkTopology; - private NetworkTopologyContext() { - flyweight = new Hashtable(); - flyweight.put(NetworkType.Basic, new BasicNetworkTopology()); - flyweight.put(NetworkType.Advanced, new AdvancedNetworkTopology()); - } - - public static NetworkTopologyContext getInstance() { - return instance; + public void init() { + flyweight.put(NetworkType.Basic, basicNetworkTopology); + flyweight.put(NetworkType.Advanced, advancedNetworkTopology); } public NetworkTopology retrieveNetworkTopology(final DataCenter dc) {