merging cmd-visitor into cmd-visitor-rebase, with the upstream from ACS repo

Conflicts:
	server/src/com/cloud/network/rules/DhcpRules.java
	server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
This commit is contained in:
Wilder Rodrigues 2014-09-05 10:57:30 +02:00
parent 00e3af4584
commit a18e01cfde
7 changed files with 60 additions and 59 deletions

View File

@ -47,7 +47,7 @@ public class AdvancedVpnRules extends BasicVpnRules {
Vpc vpc = _vpcDao.findById(_remoteAccessVpn.getVpcId());
if (router.getState() != State.Running) {
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());

View File

@ -49,9 +49,9 @@ public class DhcpRules extends RuleApplier {
}
final Network network = _networkDao.findById(_nic.getNetworkId());
final String networkTag = _networkModel.getNetworkTag(router.getHypervisorType(), network);
final String networkTag = _networkModel.getNetworkTag(_router.getHypervisorType(), network);
_setupCommand = PvlanSetupCommand.createDhcpSetup(op, _nic.getBroadCastUri(), networkTag, router.getInstanceName(), _nic.getMacAddress(), _nic.getIp4Address());
_setupCommand = PvlanSetupCommand.createDhcpSetup(op, _nic.getBroadCastUri(), networkTag, _router.getInstanceName(), _nic.getMacAddress(), _nic.getIp4Address());
return visitor.visit(this);
}

View File

@ -74,7 +74,7 @@ public class DhcpSubNetRules extends RuleApplier {
_userVmDao.loadDetails(vm);
// check if this is not the primary subnet.
final NicVO domr_guest_nic = _nicDao.findByInstanceIdAndIpAddressAndVmtype(router.getId(), _nicDao.getIpAddress(_nic.getNetworkId(), router.getId()),
final NicVO domr_guest_nic = _nicDao.findByInstanceIdAndIpAddressAndVmtype(_router.getId(), _nicDao.getIpAddress(_nic.getNetworkId(), _router.getId()),
VirtualMachine.Type.DomainRouter);
// check if the router ip address and the vm ip address belong to same
// subnet.
@ -94,7 +94,7 @@ public class DhcpSubNetRules extends RuleApplier {
}
PublicIp routerPublicIP = null;
final DataCenter dc = _dcDao.findById(router.getDataCenterId());
final DataCenter dc = _dcDao.findById(_router.getDataCenterId());
if (ipInVmsubnet == false) {
try {
if ((_network.getTrafficType() == TrafficType.Guest) && (_network.getGuestType() == GuestType.Shared)) {
@ -106,10 +106,10 @@ public class DhcpSubNetRules extends RuleApplier {
vlanDbIdList.add(vlan.getId());
}
if (dc.getNetworkType() == NetworkType.Basic) {
routerPublicIP = _ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), vm.getPodIdToDeployIn(), caller, Vlan.VlanType.DirectAttached,
routerPublicIP = _ipAddrMgr.assignPublicIpAddressFromVlans(_router.getDataCenterId(), vm.getPodIdToDeployIn(), caller, Vlan.VlanType.DirectAttached,
vlanDbIdList, _nic.getNetworkId(), null, false);
} else {
routerPublicIP = _ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), null, caller, Vlan.VlanType.DirectAttached, vlanDbIdList,
routerPublicIP = _ipAddrMgr.assignPublicIpAddressFromVlans(_router.getDataCenterId(), null, caller, Vlan.VlanType.DirectAttached, vlanDbIdList,
_nic.getNetworkId(), null, false);
}
@ -121,7 +121,7 @@ public class DhcpSubNetRules extends RuleApplier {
return false;
}
// this means we did not create an IP alias on the router.
_nicAlias = new NicIpAliasVO(domr_guest_nic.getId(), _routerAliasIp, router.getId(), CallContext.current().getCallingAccountId(), _network.getDomainId(),
_nicAlias = new NicIpAliasVO(domr_guest_nic.getId(), _routerAliasIp, _router.getId(), CallContext.current().getCallingAccountId(), _network.getDomainId(),
_nic.getNetworkId(), _nic.getGateway(), _nic.getNetmask());
_nicAlias.setAliasCount((routerPublicIP.getIpMacAddress()));
_nicIpAliasDao.persist(_nicAlias);
@ -129,7 +129,7 @@ public class DhcpSubNetRules extends RuleApplier {
final boolean result = visitor.visit(this);
if (result == false) {
final NicIpAliasVO ipAliasVO = _nicIpAliasDao.findByInstanceIdAndNetworkId(_network.getId(), router.getId());
final NicIpAliasVO ipAliasVO = _nicIpAliasDao.findByInstanceIdAndNetworkId(_network.getId(), _router.getId());
final PublicIp routerPublicIPFinal = routerPublicIP;
Transaction.execute(new TransactionCallbackNoReturn() {
@Override

View File

@ -62,31 +62,31 @@ public class NicPlugInOutRules extends RuleApplier {
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
_router = router;
final Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> nicsToChange = getNicsToChangeOnRouter(_ipAddresses, router);
final Map<String, PublicIpAddress> nicsToPlug = nicsToChange.first();
final Map<String, PublicIpAddress> nicsToUnplug = nicsToChange.second();
Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> nicsToChange = getNicsToChangeOnRouter(_ipAddresses);
Map<String, PublicIpAddress> nicsToPlug = nicsToChange.first();
Map<String, PublicIpAddress> nicsToUnplug = nicsToChange.second();
// 1) Unplug the nics
for (final Entry<String, PublicIpAddress> entry : nicsToUnplug.entrySet()) {
for (Entry<String, PublicIpAddress> entry : nicsToUnplug.entrySet()) {
Network publicNtwk = null;
try {
publicNtwk = _networkModel.getNetwork(entry.getValue().getNetworkId());
final URI broadcastUri = BroadcastDomainType.Vlan.toUri(entry.getKey());
_itMgr.removeVmFromNetwork(router, publicNtwk, broadcastUri);
} catch (final ConcurrentOperationException e) {
s_logger.warn("Failed to remove router " + router + " from vlan " + entry.getKey() + " in public network " + publicNtwk + " due to ", e);
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 " + entry.getKey() + " in public network " + publicNtwk + " due to ", e);
return false;
}
}
_netUsageCommands = new Commands(Command.OnError.Continue);
final VpcVO vpc = _vpcDao.findById(router.getVpcId());
VpcVO vpc = _vpcDao.findById(_router.getVpcId());
// 2) Plug the nics
for (final String vlanTag : nicsToPlug.keySet()) {
final PublicIpAddress ip = nicsToPlug.get(vlanTag);
for (String vlanTag : nicsToPlug.keySet()) {
PublicIpAddress ip = nicsToPlug.get(vlanTag);
// have to plug the nic(s)
final NicProfile defaultNic = new NicProfile();
NicProfile defaultNic = new NicProfile();
if (ip.isSourceNat()) {
defaultNic.setDefaultNic(true);
}
@ -102,26 +102,25 @@ public class NicPlugInOutRules extends RuleApplier {
Network publicNtwk = null;
try {
publicNtwk = _networkModel.getNetwork(ip.getNetworkId());
publicNic = _itMgr.addVmToNetwork(router, publicNtwk, defaultNic);
} catch (final ConcurrentOperationException e) {
s_logger.warn("Failed to add router " + router + " to vlan " + vlanTag + " in public network " + publicNtwk + " due to ", e);
} catch (final InsufficientCapacityException e) {
s_logger.warn("Failed to add router " + router + " to vlan " + vlanTag + " in public network " + publicNtwk + " due to ", e);
publicNic = _itMgr.addVmToNetwork(_router, publicNtwk, defaultNic);
} catch (ConcurrentOperationException e) {
s_logger.warn("Failed to add router " + _router + " to vlan " + vlanTag + " in public network " + publicNtwk + " due to ", e);
} catch (InsufficientCapacityException e) {
s_logger.warn("Failed to add router " + _router + " to vlan " + vlanTag + " in public network " + publicNtwk + " due to ", e);
} finally {
if (publicNic == null) {
s_logger.warn("Failed to add router " + router + " to vlan " + vlanTag + " in public network " + publicNtwk);
s_logger.warn("Failed to add router " + _router + " to vlan " + vlanTag + " in public network " + publicNtwk);
return false;
}
}
// Create network usage commands. Send commands to router after
// IPAssoc
final NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(router.getPrivateIpAddress(), router.getInstanceName(), true, defaultNic.getIp4Address(),
vpc.getCidr());
NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(_router.getPrivateIpAddress(), _router.getInstanceName(), true, defaultNic.getIp4Address(), vpc.getCidr());
_netUsageCommands.addCommand(netUsageCmd);
UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterId(), publicNtwk.getId(), publicNic.getIp4Address(), router.getId(), router
.getType().toString());
UserStatisticsVO stats = _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(),
stats = new UserStatisticsVO(_router.getAccountId(), _router.getDataCenterId(), publicNic.getIp4Address(), _router.getId(), _router.getType().toString(),
publicNtwk.getId());
_userStatsDao.persist(stats);
}
@ -140,15 +139,15 @@ public class NicPlugInOutRules extends RuleApplier {
return _netUsageCommands;
}
private Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> getNicsToChangeOnRouter(final List<? extends PublicIpAddress> publicIps, final VirtualRouter router) {
private Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> getNicsToChangeOnRouter(final List<? extends PublicIpAddress> publicIps) {
// 1) check which nics need to be plugged/unplugged and plug/unplug them
final Map<String, PublicIpAddress> nicsToPlug = new HashMap<String, PublicIpAddress>();
final Map<String, PublicIpAddress> nicsToUnplug = new HashMap<String, PublicIpAddress>();
// find out nics to unplug
for (final PublicIpAddress ip : publicIps) {
final long publicNtwkId = ip.getNetworkId();
for (PublicIpAddress ip : publicIps) {
long publicNtwkId = ip.getNetworkId();
// if ip is not associated to any network, and there are no firewall
// rules, release it on the backend
@ -157,7 +156,7 @@ public class NicPlugInOutRules extends RuleApplier {
}
if (ip.getState() == IpAddress.State.Releasing) {
final Nic nic = _nicDao.findByIp4AddressAndNetworkIdAndInstanceId(publicNtwkId, router.getId(), ip.getAddress().addr());
Nic nic = _nicDao.findByIp4AddressAndNetworkIdAndInstanceId(publicNtwkId, _router.getId(), ip.getAddress().addr());
if (nic != null) {
nicsToUnplug.put(ip.getVlanTag(), ip);
s_logger.debug("Need to unplug the nic for ip=" + ip + "; vlan=" + ip.getVlanTag() + " in public network id =" + publicNtwkId);
@ -166,9 +165,9 @@ public class NicPlugInOutRules extends RuleApplier {
}
// find out nics to plug
for (final PublicIpAddress ip : publicIps) {
final URI broadcastUri = BroadcastDomainType.Vlan.toUri(ip.getVlanTag());
final long publicNtwkId = ip.getNetworkId();
for (PublicIpAddress ip : publicIps) {
URI broadcastUri = BroadcastDomainType.Vlan.toUri(ip.getVlanTag());
long publicNtwkId = ip.getNetworkId();
// if ip is not associated to any network, and there are no firewall
// rules, release it on the backend
@ -176,18 +175,18 @@ public class NicPlugInOutRules extends RuleApplier {
ip.setState(IpAddress.State.Releasing);
}
if ((ip.getState() == IpAddress.State.Allocated) || (ip.getState() == IpAddress.State.Allocating)) {
if (ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating) {
// nic has to be plugged only when there are no nics for this
// vlan tag exist on VR
final Nic nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(publicNtwkId, router.getId(), broadcastUri.toString());
Nic nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(publicNtwkId, _router.getId(), broadcastUri.toString());
if ((nic == null) && (nicsToPlug.get(ip.getVlanTag()) == null)) {
if (nic == null && nicsToPlug.get(ip.getVlanTag()) == null) {
nicsToPlug.put(ip.getVlanTag(), ip);
s_logger.debug("Need to plug the nic for ip=" + ip + "; vlan=" + ip.getVlanTag() + " in public network id =" + publicNtwkId);
} else {
final PublicIpAddress nicToUnplug = nicsToUnplug.get(ip.getVlanTag());
if (nicToUnplug != null) {
final NicVO nicVO = _nicDao.findByIp4AddressAndNetworkIdAndInstanceId(publicNtwkId, router.getId(), nicToUnplug.getAddress().addr());
NicVO nicVO = _nicDao.findByIp4AddressAndNetworkIdAndInstanceId(publicNtwkId, _router.getId(), nicToUnplug.getAddress().addr());
nicVO.setIp4Address(ip.getAddress().addr());
_nicDao.update(nicVO.getId(), nicVO);
s_logger.debug("Updated the nic " + nicVO + " with the new ip address " + ip.getAddress().addr());
@ -197,7 +196,7 @@ public class NicPlugInOutRules extends RuleApplier {
}
}
final Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> nicsToChange = new Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>>(nicsToPlug,
Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> nicsToChange = new Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>>(nicsToPlug,
nicsToUnplug);
return nicsToChange;

View File

@ -51,30 +51,30 @@ public class PrivateGatewayRules extends RuleApplier {
_network = _networkModel.getNetwork(_privateGateway.getNetworkId());
NicProfile requested = _vpcNetworkHelper.createPrivateNicProfileForGateway(_privateGateway);
if (!_networkHelper.checkRouterVersion(router)) {
s_logger.warn("Router requires upgrade. Unable to send command to router: " + router.getId());
if (!_networkHelper.checkRouterVersion(_router)) {
s_logger.warn("Router requires upgrade. Unable to send command to router: " + _router.getId());
return false;
}
_nicProfile = _itMgr.addVmToNetwork(router, _network, requested);
_nicProfile = _itMgr.addVmToNetwork(_router, _network, requested);
//setup source nat
// setup source nat
if (_nicProfile != null) {
_isAddOperation = true;
//result = setupVpcPrivateNetwork(router, true, guestNic);
// result = setupVpcPrivateNetwork(router, true, guestNic);
result = visitor.visit(this);
}
} catch (Exception ex) {
s_logger.warn("Failed to create private gateway " + _privateGateway + " on router " + router + " due to ", ex);
s_logger.warn("Failed to create private gateway " + _privateGateway + " on router " + _router + " due to ", ex);
} finally {
if (!result) {
s_logger.debug("Failed to setup gateway " + _privateGateway + " on router " + router + " with the source nat. Will now remove the gateway.");
s_logger.debug("Failed to setup gateway " + _privateGateway + " on router " + _router + " with the source nat. Will now remove the gateway.");
_isAddOperation = false;
boolean isRemoved = destroyPrivateGateway(visitor);
if (isRemoved) {
s_logger.debug("Removed the gateway " + _privateGateway + " from router " + router + " as a part of cleanup");
s_logger.debug("Removed the gateway " + _privateGateway + " from router " + _router + " as a part of cleanup");
} else {
s_logger.warn("Failed to remove the gateway " + _privateGateway + " from router " + router + " as a part of cleanup");
s_logger.warn("Failed to remove the gateway " + _privateGateway + " from router " + _router + " as a part of cleanup");
}
}
}
@ -95,8 +95,10 @@ public class PrivateGatewayRules extends RuleApplier {
}
public Network retrievePrivateNetwork() {
// This network might be the same we have already as an instance in the RuleApplier super class.
// Just doing this here, but will double check is remove if it's not needed.
// This network might be the same we have already as an instance in the
// RuleApplier super class.
// Just doing this here, but will double check is remove if it's not
// needed.
Network network = _networkDao.findById(_nicProfile.getNetworkId());
return network;
}
@ -119,7 +121,7 @@ public class PrivateGatewayRules extends RuleApplier {
return false;
}
//revoke network acl on the private gateway.
// revoke network acl on the private gateway.
if (!_networkACLMgr.revokeACLItemsForPrivateGw(_privateGateway)) {
s_logger.debug("Failed to delete network acl items on " + _privateGateway + " from router " + _router);
return false;

View File

@ -58,14 +58,14 @@ public class VpcIpAssociationRules extends RuleApplier {
for (PublicIpAddress ipAddr : _ipAddresses) {
String broadcastURI = BroadcastDomainType.Vlan.toUri(ipAddr.getVlanTag()).toString();
Nic nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(ipAddr.getNetworkId(), router.getId(), broadcastURI);
Nic nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(ipAddr.getNetworkId(), _router.getId(), broadcastURI);
String macAddress = null;
if (nic == null) {
if (ipAddr.getState() != IpAddress.State.Releasing) {
throw new CloudRuntimeException("Unable to find the nic in network " + ipAddr.getNetworkId() + " to apply the ip address " + ipAddr + " for");
}
s_logger.debug("Not sending release for ip address " + ipAddr + " as its nic is already gone from VPC router " + router);
s_logger.debug("Not sending release for ip address " + ipAddr + " as its nic is already gone from VPC router " + _router);
} else {
macAddress = nic.getMacAddress();
_vlanMacAddress.put(BroadcastDomainType.getValue(BroadcastDomainType.fromString(ipAddr.getVlanTag())), macAddress);

View File

@ -197,7 +197,7 @@ public class AdvancedNetworkTopology extends BasicNetworkTopology {
return true;
}
// only one router is supported in VPC now
// only one router is supported in VPC for now
VirtualRouter router = routers.get(0);
if (router.getVpcId() == null) {