Skip to content

Commit 6e2cb08

Browse files
fixing VPC IP Association and ACL rules. Have to rewrite in a better why the apply rules method in the Advanced Topology
1 parent acc3f23 commit 6e2cb08

6 files changed

Lines changed: 116 additions & 21 deletions

File tree

server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,6 @@ public boolean finalizeVirtualMachineProfile(final VirtualMachineProfile profile
397397
return super.finalizeVirtualMachineProfile(profile, dest, context);
398398
}
399399

400-
protected boolean sendNetworkACLs(final VirtualRouter router, final List<? extends NetworkACLItem> rules, final long guestNetworkId, final boolean isPrivateGateway)
401-
throws ResourceUnavailableException {
402-
Commands cmds = new Commands(Command.OnError.Continue);
403-
createNetworkACLsCommands(rules, router, cmds, guestNetworkId, isPrivateGateway);
404-
return sendCommandsToRouter(router, cmds);
405-
}
406-
407400
private void createNetworkACLsCommands(final List<? extends NetworkACLItem> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId, final boolean privateGateway) {
408401
List<NetworkACLTO> rulesTO = new ArrayList<NetworkACLTO>();
409402
String guestVlan = null;

server/src/com/cloud/network/rules/NicPlugInOutRules.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter
127127
}
128128
}
129129

130-
// Let the IpAssociationRule call the visitor fot the NicPlugInOutRule
130+
// The visit will be done from the AdvancedNetworkTopology, after the VpcIpAssociation is done.
131131
return true;
132132
}
133133

server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ public IpAssociationRules createIpAssociationRules(final Network network, final
158158
return ipAssociationRules;
159159
}
160160

161-
public VpcIpAssociationRules createVpcIpAssociationRules(final Network network, final List<? extends PublicIpAddress> ipAddresses, final NicPlugInOutRules nicPlugInOutRules) {
162-
VpcIpAssociationRules ipAssociationRules = new VpcIpAssociationRules(network, ipAddresses, nicPlugInOutRules);
161+
public VpcIpAssociationRules createVpcIpAssociationRules(final Network network, final List<? extends PublicIpAddress> ipAddresses) {
162+
VpcIpAssociationRules ipAssociationRules = new VpcIpAssociationRules(network, ipAddresses);
163163

164164
initBeans(ipAssociationRules);
165165

server/src/com/cloud/network/rules/VpcIpAssociationRules.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,13 @@ public class VpcIpAssociationRules extends RuleApplier {
4747

4848
private final List<? extends PublicIpAddress> _ipAddresses;
4949

50-
private final NicPlugInOutRules _nicPlugInOutRules;
51-
5250
private Map<String, String> _vlanMacAddress;
5351

5452
private List<PublicIpAddress> _ipsToSend;
5553

56-
public VpcIpAssociationRules(final Network network, final List<? extends PublicIpAddress> ipAddresses, final NicPlugInOutRules nicPlugInOutRules) {
54+
public VpcIpAssociationRules(final Network network, final List<? extends PublicIpAddress> ipAddresses) {
5755
super(network);
5856
_ipAddresses = ipAddresses;
59-
_nicPlugInOutRules = nicPlugInOutRules;
6057
}
6158

6259
@Override
@@ -90,10 +87,6 @@ public List<? extends PublicIpAddress> getIpAddresses() {
9087
return _ipAddresses;
9188
}
9289

93-
public NicPlugInOutRules getNicPlugInOutRules() {
94-
return _nicPlugInOutRules;
95-
}
96-
9790
public Map<String, String> getVlanMacAddress() {
9891
return _vlanMacAddress;
9992
}

server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,21 @@
1717

1818
package org.apache.cloudstack.network.topology;
1919

20+
import java.util.ArrayList;
2021
import java.util.List;
2122

2223
import org.apache.log4j.Logger;
2324
import org.springframework.beans.factory.annotation.Autowired;
2425
import org.springframework.beans.factory.annotation.Qualifier;
2526
import org.springframework.stereotype.Component;
2627

28+
import com.cloud.dc.DataCenter;
29+
import com.cloud.dc.DataCenter.NetworkType;
30+
import com.cloud.dc.Pod;
2731
import com.cloud.deploy.DeployDestination;
32+
import com.cloud.exception.AgentUnavailableException;
2833
import com.cloud.exception.ResourceUnavailableException;
34+
import com.cloud.host.Status;
2935
import com.cloud.network.Network;
3036
import com.cloud.network.PublicIpAddress;
3137
import com.cloud.network.router.VirtualRouter;
@@ -39,6 +45,7 @@
3945
import com.cloud.network.vpc.NetworkACLItem;
4046
import com.cloud.vm.DomainRouterVO;
4147
import com.cloud.vm.NicProfile;
48+
import com.cloud.vm.VirtualMachine.State;
4249
import com.cloud.vm.VirtualMachineProfile;
4350

4451
@Component
@@ -105,14 +112,25 @@ public boolean associatePublicIP(final Network network, final List<? extends Pub
105112
final Long podId = null;
106113

107114
NicPlugInOutRules nicPlugInOutRules = _virtualNetworkApplianceFactory.createNicPluInOutRules(network, ipAddresses);
108-
VpcIpAssociationRules ipAssociationRules = _virtualNetworkApplianceFactory.createVpcIpAssociationRules(network, ipAddresses, nicPlugInOutRules);
115+
nicPlugInOutRules.accept(_advancedVisitor, router);
109116

110-
return applyRules(network, routers, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(ipAssociationRules));
117+
VpcIpAssociationRules ipAssociationRules = _virtualNetworkApplianceFactory.createVpcIpAssociationRules(network, ipAddresses);
118+
boolean result = applyRules(network, routers, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(ipAssociationRules));
119+
120+
if (result) {
121+
_advancedVisitor.visit(nicPlugInOutRules);
122+
}
123+
124+
return result;
111125
}
112126

113127
@Override
114128
public boolean applyNetworkACLs(final Network network, final List<? extends NetworkACLItem> rules, final List<? extends VirtualRouter> routers, final boolean isPrivateGateway)
115129
throws ResourceUnavailableException {
130+
if (rules == null || rules.isEmpty()) {
131+
s_logger.debug("No network ACLs to be applied for network " + network.getId());
132+
return true;
133+
}
116134

117135
s_logger.debug("APPLYING NETWORK ACLs RULES");
118136

@@ -125,4 +143,92 @@ public boolean applyNetworkACLs(final Network network, final List<? extends Netw
125143

126144
return applyRules(network, routers, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(aclsRules));
127145
}
146+
147+
@Override
148+
public boolean applyRules(final Network network, final List<? extends VirtualRouter> routers, final String typeString, final boolean isPodLevelException, final Long podId, final boolean failWhenDisconnect,
149+
final RuleApplierWrapper<RuleApplier> ruleApplierWrapper)
150+
throws ResourceUnavailableException {
151+
152+
if (routers == null || routers.isEmpty()) {
153+
s_logger.warn("Unable to apply " + typeString + ", virtual router doesn't exist in the network " + network.getId());
154+
throw new ResourceUnavailableException("Unable to apply " + typeString, DataCenter.class, network.getDataCenterId());
155+
}
156+
157+
RuleApplier ruleApplier = ruleApplierWrapper.getRuleType();
158+
159+
final DataCenter dc = _dcDao.findById(network.getDataCenterId());
160+
final boolean isZoneBasic = (dc.getNetworkType() == NetworkType.Basic);
161+
162+
// isPodLevelException and podId is only used for basic zone
163+
assert !((!isZoneBasic && isPodLevelException) || (isZoneBasic && isPodLevelException && podId == null));
164+
165+
final List<VirtualRouter> connectedRouters = new ArrayList<VirtualRouter>();
166+
final List<VirtualRouter> disconnectedRouters = new ArrayList<VirtualRouter>();
167+
boolean result = true;
168+
final String msg = "Unable to apply " + typeString + " on disconnected router ";
169+
for (final VirtualRouter router : routers) {
170+
if (router.getState() == State.Running) {
171+
s_logger.debug("Applying " + typeString + " in network " + network);
172+
173+
if (router.isStopPending()) {
174+
if (_hostDao.findById(router.getHostId()).getState() == Status.Up) {
175+
throw new ResourceUnavailableException("Unable to process due to the stop pending router " + router.getInstanceName() +
176+
" haven't been stopped after it's host coming back!", DataCenter.class, router.getDataCenterId());
177+
}
178+
s_logger.debug("Router " + router.getInstanceName() + " is stop pending, so not sending apply " + typeString + " commands to the backend");
179+
continue;
180+
}
181+
182+
try {
183+
ruleApplier.accept(_advancedVisitor, router);
184+
185+
connectedRouters.add(router);
186+
} catch (final AgentUnavailableException e) {
187+
s_logger.warn(msg + router.getInstanceName(), e);
188+
disconnectedRouters.add(router);
189+
}
190+
191+
//If rules fail to apply on one domR and not due to disconnection, no need to proceed with the rest
192+
if (!result) {
193+
if (isZoneBasic && isPodLevelException) {
194+
throw new ResourceUnavailableException("Unable to apply " + typeString + " on router ", Pod.class, podId);
195+
}
196+
throw new ResourceUnavailableException("Unable to apply " + typeString + " on router ", DataCenter.class, router.getDataCenterId());
197+
}
198+
199+
} else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
200+
s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending apply " + typeString + " commands to the backend");
201+
} else {
202+
s_logger.warn("Unable to apply " + typeString + ", virtual router is not in the right state " + router.getState());
203+
if (isZoneBasic && isPodLevelException) {
204+
throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", Pod.class, podId);
205+
}
206+
throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", DataCenter.class,
207+
router.getDataCenterId());
208+
}
209+
}
210+
211+
if (!connectedRouters.isEmpty()) {
212+
if (!isZoneBasic && !disconnectedRouters.isEmpty() && disconnectedRouters.get(0).getIsRedundantRouter()) {
213+
// These disconnected redundant virtual routers are out of sync now, stop them for synchronization
214+
//[FIXME] handleSingleWorkingRedundantRouter(connectedRouters, disconnectedRouters, msg);
215+
}
216+
} else if (!disconnectedRouters.isEmpty()) {
217+
for (final VirtualRouter router : disconnectedRouters) {
218+
if (s_logger.isDebugEnabled()) {
219+
s_logger.debug(msg + router.getInstanceName() + "(" + router.getId() + ")");
220+
}
221+
}
222+
if (isZoneBasic && isPodLevelException) {
223+
throw new ResourceUnavailableException(msg, Pod.class, podId);
224+
}
225+
throw new ResourceUnavailableException(msg, DataCenter.class, disconnectedRouters.get(0).getDataCenterId());
226+
}
227+
228+
result = true;
229+
if (failWhenDisconnect) {
230+
result = !connectedRouters.isEmpty();
231+
}
232+
return result;
233+
}
128234
}

server/src/org/apache/cloudstack/network/topology/AdvancedNetworkVisitor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ public boolean visit(final NicPlugInOutRules nicPlugInOutRules) throws ResourceU
7777

7878
final Commands commands = nicPlugInOutRules.getNetUsageCommands();
7979

80-
return _applianceManager.sendCommandsToRouter(router, commands);
80+
if (commands.size() > 0) {
81+
return _applianceManager.sendCommandsToRouter(router, commands);
82+
}
83+
return true;
8184
}
8285

8386
@Override

0 commit comments

Comments
 (0)