You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by hu...@apache.org on 2014/06/25 15:51:39 UTC
[3/8] git commit: updated refs/heads/master to ab0dca0
Fix several potential issues reported by coverity.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/49b0936a
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/49b0936a
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/49b0936a
Branch: refs/heads/master
Commit: 49b0936a725d66755f54b84ff4f1e3b92b455174
Parents: 17850c7
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Tue Jun 24 10:14:43 2014 +0200
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Wed Jun 25 15:51:28 2014 +0200
----------------------------------------------------------------------
.../VirtualNetworkApplianceManagerImpl.java | 57 +++----
.../VpcVirtualNetworkApplianceManagerImpl.java | 165 +++++++++----------
2 files changed, 106 insertions(+), 116 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/49b0936a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index 7991d7e..271602d 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -294,7 +294,7 @@ import com.cloud.vm.dao.VMInstanceDao;
*/
@Local(value = { VirtualNetworkApplianceManager.class, VirtualNetworkApplianceService.class })
public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements VirtualNetworkApplianceManager, VirtualNetworkApplianceService,
- VirtualMachineGuru, Listener, Configurable, StateListener<State, VirtualMachine.Event, VirtualMachine> {
+VirtualMachineGuru, Listener, Configurable, StateListener<State, VirtualMachine.Event, VirtualMachine> {
private static final Logger s_logger = Logger.getLogger(VirtualNetworkApplianceManagerImpl.class);
@Inject
@@ -610,7 +610,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
if (router.isStopPending()) {
s_logger.info("Clear the stop pending flag of router " + router.getHostName() + " after stop router successfully");
router.setStopPending(false);
- router = _routerDao.persist(router);
+ _routerDao.persist(router);
virtualRouter.setStopPending(false);
}
return virtualRouter;
@@ -2028,7 +2028,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
private DomainRouterVO startVirtualRouter(DomainRouterVO router, User user, Account caller, Map<Param, Object> params)
throws StorageUnavailableException, InsufficientCapacityException,
- ConcurrentOperationException, ResourceUnavailableException {
+ ConcurrentOperationException, ResourceUnavailableException {
if (router.getRole() != Role.VIRTUAL_ROUTER || !router.getIsRedundantRouter()) {
return this.start(router, user, caller, params, null);
@@ -2118,11 +2118,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
protected List<DomainRouterVO> startRouters(final Map<Param, Object> params, final List<DomainRouterVO> routers) throws StorageUnavailableException,
InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
- List<DomainRouterVO> runningRouters = null;
-
- if (routers != null) {
- runningRouters = new ArrayList<DomainRouterVO>();
- }
+ List<DomainRouterVO> runningRouters = new ArrayList<DomainRouterVO>();
for (DomainRouterVO router : routers) {
boolean skip = false;
@@ -2547,6 +2543,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
// at VR startup time, information in VirtualMachineProfile may not updated to DB yet,
// getRouterControlIp() may give wrong IP under basic network mode in VMware environment
final NicProfile controlNic = getControlNic(profile);
+ if (controlNic == null) {
+ throw new CloudRuntimeException("VirtualMachine " + profile.getInstanceName() + " doesn't have a control interface");
+ }
final SetMonitorServiceCommand command = new SetMonitorServiceCommand(servicesTO);
command.setAccessDetail(NetworkElementCommand.ROUTER_IP, controlNic.getIp4Address());
command.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(networkId, router.getId()));
@@ -2846,7 +2845,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer)cmds.getAnswer("getDomRVersion");
router.setTemplateVersion(versionAnswer.getTemplateVersion());
router.setScriptsVersion(versionAnswer.getScriptsVersion());
- router = _routerDao.persist(router, guestNetworks);
+ _routerDao.persist(router, guestNetworks);
}
return result;
@@ -3435,9 +3434,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
private void createApplyPortForwardingRulesCommands(final List<? extends PortForwardingRule> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
- List<PortForwardingRuleTO> rulesTO = null;
+ List<PortForwardingRuleTO> rulesTO = new ArrayList<PortForwardingRuleTO>();
if (rules != null) {
- rulesTO = new ArrayList<PortForwardingRuleTO>();
for (final PortForwardingRule rule : rules) {
final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
final PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, null, sourceIp.getAddress().addr());
@@ -3463,9 +3461,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
private void createApplyStaticNatRulesCommands(final List<? extends StaticNatRule> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
- List<StaticNatRuleTO> rulesTO = null;
+ List<StaticNatRuleTO> rulesTO = new ArrayList<StaticNatRuleTO>();
if (rules != null) {
- rulesTO = new ArrayList<StaticNatRuleTO>();
for (final StaticNatRule rule : rules) {
final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
final StaticNatRuleTO ruleTO = new StaticNatRuleTO(rule, null, sourceIp.getAddress().addr(), rule.getDestIpAddress());
@@ -3900,7 +3897,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
private void createFirewallRulesCommands(final List<? extends FirewallRule> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
- List<FirewallRuleTO> rulesTO = null;
+ List<FirewallRuleTO> rulesTO = new ArrayList<FirewallRuleTO>();
String systemRule = null;
Boolean defaultEgressPolicy = false;
if (rules != null) {
@@ -3909,7 +3906,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
systemRule = String.valueOf(FirewallRule.FirewallRuleType.System);
}
}
- rulesTO = new ArrayList<FirewallRuleTO>();
for (final FirewallRule rule : rules) {
_rulesDao.loadSourceCidrs((FirewallRuleVO)rule);
final FirewallRule.TrafficType traffictype = rule.getTrafficType();
@@ -4061,9 +4057,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
private void createApplyStaticNatCommands(final List<? extends StaticNat> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
- List<StaticNatRuleTO> rulesTO = null;
+ List<StaticNatRuleTO> rulesTO = new ArrayList<StaticNatRuleTO>();
if (rules != null) {
- rulesTO = new ArrayList<StaticNatRuleTO>();
for (final StaticNat rule : rules) {
final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
final StaticNatRuleTO ruleTO =
@@ -4349,21 +4344,21 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
List<Long> jobIds = new ArrayList<Long>();
for(DomainRouterVO router: routers){
if(!checkRouterVersion(router)){
- s_logger.debug("Upgrading template for router: "+router.getId());
- Map<String, String> params = new HashMap<String, String>();
- params.put("ctxUserId", "1");
- params.put("ctxAccountId", "" + router.getAccountId());
-
- RebootRouterCmd cmd = new RebootRouterCmd();
- ComponentContext.inject(cmd);
- params.put("id", ""+router.getId());
- params.put("ctxStartEventId", "1");
+ s_logger.debug("Upgrading template for router: "+router.getId());
+ Map<String, String> params = new HashMap<String, String>();
+ params.put("ctxUserId", "1");
+ params.put("ctxAccountId", "" + router.getAccountId());
+
+ RebootRouterCmd cmd = new RebootRouterCmd();
+ ComponentContext.inject(cmd);
+ params.put("id", ""+router.getId());
+ params.put("ctxStartEventId", "1");
AsyncJobVO job = new AsyncJobVO("", User.UID_SYSTEM, router.getAccountId(), RebootRouterCmd.class.getName(),
- ApiGsonHelper.getBuilder().create().toJson(params), router.getId(),
- cmd.getInstanceType() != null ? cmd.getInstanceType().toString() : null, null);
- job.setDispatcher(_asyncDispatcher.getName());
- long jobId = _asyncMgr.submitAsyncJob(job);
- jobIds.add(jobId);
+ ApiGsonHelper.getBuilder().create().toJson(params), router.getId(),
+ cmd.getInstanceType() != null ? cmd.getInstanceType().toString() : null, null);
+ job.setDispatcher(_asyncDispatcher.getName());
+ long jobId = _asyncMgr.submitAsyncJob(job);
+ jobIds.add(jobId);
} else {
s_logger.debug("Router: " + router.getId() + " is already at the latest version. No upgrade required");
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/49b0936a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
index 431806b..ef2ab3d 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -17,6 +17,24 @@
package com.cloud.network.router;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeSet;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.Command.OnError;
@@ -113,21 +131,6 @@ import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfile.Param;
import com.cloud.vm.dao.VMInstanceDao;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeSet;
@Component
@Local(value = {VpcVirtualNetworkApplianceManager.class, VpcVirtualNetworkApplianceService.class})
@@ -177,7 +180,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
@Override
public List<DomainRouterVO> deployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner, Map<Param, Object> params) throws InsufficientCapacityException,
- ConcurrentOperationException, ResourceUnavailableException {
+ ConcurrentOperationException, ResourceUnavailableException {
List<DomainRouterVO> routers = findOrDeployVirtualRouterInVpc(vpc, dest, owner, params);
@@ -186,7 +189,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
@DB
protected List<DomainRouterVO> findOrDeployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner, Map<Param, Object> params)
- throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
+ throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
s_logger.debug("Deploying Virtual Router in VPC " + vpc);
Vpc vpcLock = _vpcDao.acquireInLockTable(vpc.getId());
@@ -295,7 +298,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
@Override
public boolean removeVpcRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException,
- ResourceUnavailableException {
+ ResourceUnavailableException {
if (network.getTrafficType() != TrafficType.Guest) {
s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest);
return false;
@@ -326,18 +329,18 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
protected DomainRouterVO deployVpcRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map<Param, Object> params, boolean isRedundant,
- VirtualRouterProvider vrProvider, long svcOffId, Long vpcId, PublicIp sourceNatIp) throws ConcurrentOperationException, InsufficientAddressCapacityException,
- InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException {
+ VirtualRouterProvider vrProvider, long svcOffId, Long vpcId, PublicIp sourceNatIp) throws ConcurrentOperationException, InsufficientAddressCapacityException,
+ InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException {
LinkedHashMap<Network, List<? extends NicProfile>> networks = createVpcRouterNetworks(owner, isRedundant, plan, new Pair<Boolean, PublicIp>(true, sourceNatIp),vpcId);
DomainRouterVO router =
- super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, networks, true, _vpcMgr.getSupportedVpcHypervisors());
+ super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, networks, true, _vpcMgr.getSupportedVpcHypervisors());
return router;
}
protected boolean setupVpcGuestNetwork(Network network, VirtualRouter router, boolean add, NicProfile guestNic) throws ConcurrentOperationException,
- ResourceUnavailableException {
+ ResourceUnavailableException {
boolean result = true;
if (router.getState() == State.Running) {
@@ -360,7 +363,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
} else {
s_logger.warn("Unable to setup guest network on virtual router " + router + " is not in the right state " + router.getState());
throw new ResourceUnavailableException("Unable to setup guest network on the backend," + " virtual router " + router + " is not in the right state",
- DataCenter.class, router.getDataCenterId());
+ DataCenter.class, router.getDataCenterId());
}
}
@@ -387,7 +390,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
NicProfile nicProfile = _networkModel.getNicProfile(router, nic.getNetworkId(), null);
SetupGuestNetworkCommand setupCmd =
- new SetupGuestNetworkCommand(dhcpRange, networkDomain, false, null, defaultDns1, defaultDns2, add, _itMgr.toNicTO(nicProfile, router.getHypervisorType()));
+ new SetupGuestNetworkCommand(dhcpRange, networkDomain, false, null, defaultDns1, defaultDns2, add, _itMgr.toNicTO(nicProfile, router.getHypervisorType()));
String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask()));
setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
@@ -406,7 +409,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
private void createVpcAssociatePublicIPCommands(final VirtualRouter router, final List<? extends PublicIpAddress> ips, Commands cmds,
- Map<String, String> vlanMacAddress) {
+ Map<String, String> vlanMacAddress) {
Pair<IpAddressTO, Long> sourceNatIpAdd = null;
Boolean addSourceNat = null;
@@ -442,8 +445,8 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
String macAddress = vlanMacAddress.get(BroadcastDomainType.getValue(BroadcastDomainType.fromString(ipAddr.getVlanTag())));
IpAddressTO ip =
- new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, false, ipAddr.isSourceNat(), ipAddr.getVlanTag(), ipAddr.getGateway(),
- ipAddr.getNetmask(), macAddress, networkRate, ipAddr.isOneToOneNat());
+ new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, false, ipAddr.isSourceNat(), ipAddr.getVlanTag(), ipAddr.getGateway(),
+ ipAddr.getNetmask(), macAddress, networkRate, ipAddr.isOneToOneNat());
ip.setTrafficType(network.getTrafficType());
ip.setNetworkName(_networkModel.getNetworkTag(router.getHypervisorType(), network));
@@ -483,7 +486,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
@Override
public boolean associatePublicIP(Network network, final List<? extends PublicIpAddress> ipAddress, List<? extends VirtualRouter> routers)
- throws ResourceUnavailableException {
+ throws ResourceUnavailableException {
if (ipAddress == null || ipAddress.isEmpty()) {
s_logger.debug("No ip association rules to be applied for network " + network.getId());
return true;
@@ -501,14 +504,14 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
Map<String, PublicIpAddress> nicsToUnplug = nicsToChange.second();
//1) Unplug the nics
- for (String vlanTag : nicsToUnplug.keySet()) {
+ for (Entry<String, PublicIpAddress> entry : nicsToUnplug.entrySet()) {
Network publicNtwk = null;
try {
- publicNtwk = _networkModel.getNetwork(nicsToUnplug.get(vlanTag).getNetworkId());
- URI broadcastUri = BroadcastDomainType.Vlan.toUri(vlanTag);
+ publicNtwk = _networkModel.getNetwork(entry.getValue().getNetworkId());
+ URI broadcastUri = BroadcastDomainType.Vlan.toUri(entry.getKey());
_itMgr.removeVmFromNetwork(router, publicNtwk, broadcastUri);
} catch (ConcurrentOperationException e) {
- s_logger.warn("Failed to remove router " + router + " from vlan " + vlanTag + " in public network " + publicNtwk + " due to ", e);
+ s_logger.warn("Failed to remove router " + router + " from vlan " + entry.getKey() + " in public network " + publicNtwk + " due to ", e);
return false;
}
}
@@ -549,15 +552,15 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
//Create network usage commands. Send commands to router after IPAssoc
NetworkUsageCommand netUsageCmd =
- new NetworkUsageCommand(router.getPrivateIpAddress(), router.getInstanceName(), true, defaultNic.getIp4Address(), vpc.getCidr());
+ new NetworkUsageCommand(router.getPrivateIpAddress(), router.getInstanceName(), true, defaultNic.getIp4Address(), vpc.getCidr());
netUsagecmds.addCommand(netUsageCmd);
UserStatisticsVO stats =
- _userStatsDao.findBy(router.getAccountId(), router.getDataCenterId(), publicNtwk.getId(), publicNic.getIp4Address(), router.getId(), router.getType()
- .toString());
+ _userStatsDao.findBy(router.getAccountId(), router.getDataCenterId(), publicNtwk.getId(), publicNic.getIp4Address(), router.getId(), router.getType()
+ .toString());
if (stats == null) {
stats =
- new UserStatisticsVO(router.getAccountId(), router.getDataCenterId(), publicNic.getIp4Address(), router.getId(), router.getType().toString(),
- publicNtwk.getId());
+ new UserStatisticsVO(router.getAccountId(), router.getDataCenterId(), publicNic.getIp4Address(), router.getId(), router.getType().toString(),
+ publicNtwk.getId());
_userStatsDao.persist(stats);
}
}
@@ -638,7 +641,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
@Override
public boolean applyNetworkACLs(Network network, final List<? extends NetworkACLItem> rules, List<? extends VirtualRouter> routers, final boolean isPrivateGateway)
- throws ResourceUnavailableException {
+ throws ResourceUnavailableException {
if (rules == null || rules.isEmpty()) {
s_logger.debug("No network ACLs to be applied for network " + network.getId());
return true;
@@ -652,14 +655,14 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
protected boolean sendNetworkACLs(VirtualRouter router, List<? extends NetworkACLItem> rules, long guestNetworkId, boolean isPrivateGateway)
- throws ResourceUnavailableException {
+ throws ResourceUnavailableException {
Commands cmds = new Commands(Command.OnError.Continue);
createNetworkACLsCommands(rules, router, cmds, guestNetworkId, isPrivateGateway);
return sendCommandsToRouter(router, cmds);
}
private void createNetworkACLsCommands(List<? extends NetworkACLItem> rules, VirtualRouter router, Commands cmds, long guestNetworkId, boolean privateGateway) {
- List<NetworkACLTO> rulesTO = null;
+ List<NetworkACLTO> rulesTO = new ArrayList<NetworkACLTO>();
String guestVlan = null;
Network guestNtwk = _networkDao.findById(guestNetworkId);
URI uri = guestNtwk.getBroadcastUri();
@@ -668,12 +671,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
if (rules != null) {
- rulesTO = new ArrayList<NetworkACLTO>();
-
for (NetworkACLItem rule : rules) {
-// if (rule.getSourceCidrList() == null && (rule.getPurpose() == Purpose.Firewall || rule.getPurpose() == Purpose.NetworkACL)) {
-// _firewallDao.loadSourceCidrs((FirewallRuleVO)rule);
-// }
NetworkACLTO ruleTO = new NetworkACLTO(rule, guestVlan, rule.getTrafficType());
rulesTO.add(ruleTO);
}
@@ -754,19 +752,19 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
}
PlugNicCommand plugNicCmd =
- new PlugNicCommand(getNicTO(router, publicNic.getNetworkId(), publicNic.getBroadcastUri().toString()), router.getInstanceName(), router.getType());
+ new PlugNicCommand(getNicTO(router, publicNic.getNetworkId(), publicNic.getBroadcastUri().toString()), router.getInstanceName(), router.getType());
cmds.addCommand(plugNicCmd);
VpcVO vpc = _vpcDao.findById(router.getVpcId());
NetworkUsageCommand netUsageCmd =
- new NetworkUsageCommand(router.getPrivateIpAddress(), router.getInstanceName(), true, publicNic.getIp4Address(), vpc.getCidr());
+ new NetworkUsageCommand(router.getPrivateIpAddress(), router.getInstanceName(), true, publicNic.getIp4Address(), vpc.getCidr());
usageCmds.add(netUsageCmd);
UserStatisticsVO stats =
- _userStatsDao.findBy(router.getAccountId(), router.getDataCenterId(), publicNtwk.getId(), publicNic.getIp4Address(), router.getId(), router.getType()
- .toString());
+ _userStatsDao.findBy(router.getAccountId(), router.getDataCenterId(), publicNtwk.getId(), publicNic.getIp4Address(), router.getId(), router.getType()
+ .toString());
if (stats == null) {
stats =
- new UserStatisticsVO(router.getAccountId(), router.getDataCenterId(), publicNic.getIp4Address(), router.getId(), router.getType().toString(),
- publicNtwk.getId());
+ new UserStatisticsVO(router.getAccountId(), router.getDataCenterId(), publicNic.getIp4Address(), router.getId(), router.getType().toString(),
+ publicNtwk.getId());
_userStatsDao.persist(stats);
}
}
@@ -793,8 +791,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
//set private network
PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(guestNic.getNetworkId(), guestNic.getIp4Address());
Network network = _networkDao.findById(guestNic.getNetworkId());
- // should this be a vlan id or a broadcast uri???
- String vlanTag = BroadcastDomainType.getValue(network.getBroadcastUri());
+ BroadcastDomainType.getValue(network.getBroadcastUri());
String netmask = NetUtils.getCidrNetmask(network.getCidr());
PrivateIpAddress ip = new PrivateIpAddress(ipVO, network.getBroadcastUri().toString(), network.getGateway(), netmask, guestNic.getMacAddress());
@@ -808,7 +805,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
//set network acl on private gateway
List<NetworkACLItemVO> networkACLs = _networkACLItemDao.listByACL(privateGwAclId);
s_logger.debug("Found " + networkACLs.size() + " network ACLs to apply as a part of VPC VR " + router + " start for private gateway ip = " +
- ipVO.getIpAddress());
+ ipVO.getIpAddress());
createNetworkACLsCommands(networkACLs, router, cmds, ipVO.getNetworkId(), true);
}
@@ -890,7 +887,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
List<NetworkACLItemVO> networkACLs = _networkACLMgr.listNetworkACLItems(guestNetworkId);
if ((networkACLs != null) && !networkACLs.isEmpty()) {
s_logger.debug("Found " + networkACLs.size() + " network ACLs to apply as a part of VPC VR " + router + " start for guest network id=" +
- guestNetworkId);
+ guestNetworkId);
createNetworkACLsCommands(networkACLs, router, cmds, guestNetworkId, false);
}
}
@@ -964,9 +961,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
if (router.getState() == State.Running) {
PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(privateNic.getNetworkId(), privateNic.getIp4Address());
Network network = _networkDao.findById(privateNic.getNetworkId());
- // TODO should this be a lan tag or a broadcast uri???
- // or maybe conditional; in case of vlan ... in case of lswitch
- String vlanTag = BroadcastDomainType.getValue(network.getBroadcastUri());
String netmask = NetUtils.getCidrNetmask(network.getCidr());
PrivateIpAddress ip = new PrivateIpAddress(ipVO, network.getBroadcastUri().toString(), network.getGateway(), netmask, privateNic.getMacAddress());
@@ -993,7 +987,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
s_logger.warn("Unable to setup private gateway, virtual router " + router + " is not in the right state " + router.getState());
throw new ResourceUnavailableException("Unable to setup Private gateway on the backend," + " virtual router " + router + " is not in the right state",
- DataCenter.class, router.getDataCenterId());
+ DataCenter.class, router.getDataCenterId());
}
return true;
}
@@ -1061,7 +1055,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
s_logger.warn("Unable to apply StaticRoute, virtual router is not in the right state " + router.getState());
throw new ResourceUnavailableException("Unable to apply StaticRoute on the backend," + " virtual router is not in the right state", DataCenter.class,
- router.getDataCenterId());
+ router.getDataCenterId());
}
}
return result;
@@ -1092,7 +1086,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
if (router.getState() != State.Running) {
s_logger.warn("Unable to apply site-to-site VPN configuration, virtual router is not in the right state " + router.getState());
throw new ResourceUnavailableException("Unable to apply site 2 site VPN configuration," + " virtual router is not in the right state", DataCenter.class,
- router.getDataCenterId());
+ router.getDataCenterId());
}
return applySite2SiteVpn(true, router, conn);
@@ -1103,7 +1097,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
if (router.getState() != State.Running) {
s_logger.warn("Unable to apply site-to-site VPN configuration, virtual router is not in the right state " + router.getState());
throw new ResourceUnavailableException("Unable to apply site 2 site VPN configuration," + " virtual router is not in the right state", DataCenter.class,
- router.getDataCenterId());
+ router.getDataCenterId());
}
return applySite2SiteVpn(false, router, conn);
@@ -1133,8 +1127,8 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
Boolean dpd = gw.getDpd();
Site2SiteVpnCfgCommand cmd =
- new Site2SiteVpnCfgCommand(isCreate, localPublicIp, localPublicGateway, localGuestCidr, peerGatewayIp, peerGuestCidrList, ikePolicy, espPolicy, ipsecPsk,
- ikeLifetime, espLifetime, dpd, conn.isPassive());
+ new Site2SiteVpnCfgCommand(isCreate, localPublicIp, localPublicGateway, localGuestCidr, peerGatewayIp, peerGuestCidrList, ikePolicy, espPolicy, ipsecPsk,
+ ikeLifetime, espLifetime, dpd, conn.isPassive());
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
@@ -1166,8 +1160,8 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
for (final PrivateIpAddress ipAddr : ipAddrList) {
Network network = _networkModel.getNetwork(ipAddr.getNetworkId());
IpAddressTO ip =
- new IpAddressTO(Account.ACCOUNT_ID_SYSTEM, ipAddr.getIpAddress(), add, false, ipAddr.getSourceNat(), ipAddr.getBroadcastUri(), ipAddr.getGateway(),
- ipAddr.getNetmask(), ipAddr.getMacAddress(), null, false);
+ new IpAddressTO(Account.ACCOUNT_ID_SYSTEM, ipAddr.getIpAddress(), add, false, ipAddr.getSourceNat(), ipAddr.getBroadcastUri(), ipAddr.getGateway(),
+ ipAddr.getNetmask(), ipAddr.getMacAddress(), null, false);
ip.setTrafficType(network.getTrafficType());
ip.setNetworkName(_networkModel.getNetworkTag(router.getHypervisorType(), network));
@@ -1186,15 +1180,13 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
protected LinkedHashMap<Network, List<? extends NicProfile>> createVpcRouterNetworks(Account owner, boolean isRedundant, DeploymentPlan plan, Pair<Boolean, PublicIp> sourceNatIp,
- long vpcId) throws ConcurrentOperationException, InsufficientAddressCapacityException {
-
- LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(4);
+ long vpcId) throws ConcurrentOperationException, InsufficientAddressCapacityException {
TreeSet<String> publicVlans = new TreeSet<String>();
publicVlans.add(sourceNatIp.second().getVlanTag());
//1) allocate nic for control and source nat public ip
- networks = super.createRouterNetworks(owner, isRedundant, plan, null, sourceNatIp);
+ LinkedHashMap<Network, List<? extends NicProfile>> networks = super.createRouterNetworks(owner, isRedundant, plan, null, sourceNatIp);
//2) allocate nic for private gateways if needed
List<PrivateGateway> privateGateways = _vpcMgr.getVpcPrivateGateways(vpcId);
@@ -1225,7 +1217,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
for (IPAddressVO ip : ips) {
PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
if ((ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating) && _vpcMgr.isIpAllocatedToVpc(ip) &&
- !publicVlans.contains(publicIp.getVlanTag())) {
+ !publicVlans.contains(publicIp.getVlanTag())) {
s_logger.debug("Allocating nic for router in vlan " + publicIp.getVlanTag());
NicProfile publicNic = new NicProfile();
publicNic.setDefaultNic(false);
@@ -1262,6 +1254,9 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
protected NicProfile createPrivateNicProfileForGateway(VpcGateway privateGateway) {
Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(privateNetwork.getDataCenterId(), privateNetwork.getId(), privateGateway.getIp4Address());
+ if (ipVO == null) {
+ throw new CloudRuntimeException("Unable to assign a private IP for private gateway " + privateGateway.getUuid());
+ }
Nic privateNic = _nicDao.findByIp4AddressAndNetworkId(ipVO.getIpAddress(), privateNetwork.getId());
NicProfile privateNicProfile = new NicProfile();
@@ -1269,14 +1264,14 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
if (privateNic != null) {
VirtualMachine vm = _vmDao.findById(privateNic.getInstanceId());
privateNicProfile =
- new NicProfile(privateNic, privateNetwork, privateNic.getBroadcastUri(), privateNic.getIsolationUri(), _networkModel.getNetworkRate(
- privateNetwork.getId(), vm.getId()), _networkModel.isSecurityGroupSupportedInNetwork(privateNetwork), _networkModel.getNetworkTag(
- vm.getHypervisorType(), privateNetwork));
+ new NicProfile(privateNic, privateNetwork, privateNic.getBroadcastUri(), privateNic.getIsolationUri(), _networkModel.getNetworkRate(
+ privateNetwork.getId(), vm.getId()), _networkModel.isSecurityGroupSupportedInNetwork(privateNetwork), _networkModel.getNetworkTag(
+ vm.getHypervisorType(), privateNetwork));
} else {
String netmask = NetUtils.getCidrNetmask(privateNetwork.getCidr());
PrivateIpAddress ip =
- new PrivateIpAddress(ipVO, privateNetwork.getBroadcastUri().toString(), privateNetwork.getGateway(), netmask,
- NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())));
+ new PrivateIpAddress(ipVO, privateNetwork.getBroadcastUri().toString(), privateNetwork.getGateway(), netmask,
+ NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())));
URI netUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
privateNicProfile.setIp4Address(ip.getIpAddress());
@@ -1309,7 +1304,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
protected Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> getNicsToChangeOnRouter(final List<? extends PublicIpAddress> publicIps,
- VirtualRouter router) {
+ VirtualRouter router) {
//1) check which nics need to be plugged/unplugged and plug/unplug them
Map<String, PublicIpAddress> nicsToPlug = new HashMap<String, PublicIpAddress>();
@@ -1364,7 +1359,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> nicsToChange =
- new Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>>(nicsToPlug, nicsToUnplug);
+ new Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>>(nicsToPlug, nicsToUnplug);
return nicsToChange;
}
@@ -1401,7 +1396,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
if (router.getState() != State.Running) {
s_logger.warn("Failed to add/remove Remote Access VPN users: router not in running state");
throw new ResourceUnavailableException("Failed to add/remove Remote Access VPN users: router not in running state: " + router.getState(), DataCenter.class,
- vpc.getZoneId());
+ vpc.getZoneId());
}
Commands cmds = new Commands(Command.OnError.Continue);
@@ -1438,7 +1433,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
if (router.getState() != State.Running) {
s_logger.warn("Unable to apply remote access VPN configuration, virtual router is not in the right state " + router.getState());
throw new ResourceUnavailableException("Unable to apply remote access VPN configuration," + " virtual router is not in the right state", DataCenter.class,
- router.getDataCenterId());
+ router.getDataCenterId());
}
Commands cmds = new Commands(Command.OnError.Stop);
@@ -1453,16 +1448,16 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
Answer answer = cmds.getAnswer("users");
if (!answer.getResult()) {
s_logger.error("Unable to start vpn: unable add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " +
- router.getInstanceName() + " due to " + answer.getDetails());
+ router.getInstanceName() + " due to " + answer.getDetails());
throw new ResourceUnavailableException("Unable to start vpn: Unable to add users to vpn in zone " + router.getDataCenterId() + " for account " +
- vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
+ vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
}
answer = cmds.getAnswer("startVpn");
if (!answer.getResult()) {
s_logger.error("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() +
- " due to " + answer.getDetails());
+ " due to " + answer.getDetails());
throw new ResourceUnavailableException("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " +
- router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
+ router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
}
return true;
@@ -1481,7 +1476,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
} else {
s_logger.warn("Failed to delete remote access VPN: domR " + router + " is not in right state " + router.getState());
throw new ResourceUnavailableException("Failed to delete remote access VPN: domR is not in right state " + router.getState(), DataCenter.class,
- router.getDataCenterId());
+ router.getDataCenterId());
}
return true;