Skip to content

Commit 0ad3661

Browse files
moving sendCommand to the NetworkGeneralHelper;
adding handle single network method to the NetworkGeneralHelper; moving getRealPriority to the NetworkGeneralHelper; making priority constants part of the VirtualNetworkApplianceManager; changing the network topology implementation in order to use the NetworkGeneralManager instead of the appliance Conflicts: server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java server/src/org/apache/cloudstack/network/topology/BasicNetworkTopology.java
1 parent 9d9e440 commit 0ad3661

File tree

9 files changed

+235
-274
lines changed

9 files changed

+235
-274
lines changed

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

Lines changed: 177 additions & 113 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA
6464
public static final int DEFAULT_ROUTER_VM_RAMSIZE = 128; // 128M
6565
public static final int DEFAULT_ROUTER_CPU_MHZ = 500; // 500 MHz
6666
public static final boolean USE_POD_VLAN = false;
67+
public static final int DEFAULT_PRIORITY = 100;
68+
public static final int DEFAULT_DELTA = 2;
6769

6870
/**
6971
/*

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

Lines changed: 17 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
import com.cloud.agent.api.AgentControlAnswer;
6868
import com.cloud.agent.api.AgentControlCommand;
6969
import com.cloud.agent.api.Answer;
70-
import com.cloud.agent.api.BumpUpPriorityCommand;
7170
import com.cloud.agent.api.CheckRouterAnswer;
7271
import com.cloud.agent.api.CheckRouterCommand;
7372
import com.cloud.agent.api.CheckS2SVpnConnectionsAnswer;
@@ -384,12 +383,11 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
384383
OpRouterMonitorServiceDao _opRouterMonitorServiceDao;
385384

386385
@Inject
387-
NetworkTopologyContext networkTopologyContext;
388-
386+
protected NetworkTopologyContext _networkTopologyContext;
389387
@Inject
390-
protected NetworkGeneralHelper nwHelper;
388+
protected NetworkGeneralHelper _nwHelper;
391389
@Inject
392-
protected RouterDeploymentDefinitionBuilder routerDeploymentManagerBuilder;
390+
protected RouterDeploymentDefinitionBuilder _routerDeploymentManagerBuilder;
393391

394392
int _routerRamSize;
395393
int _routerCpuMHz;
@@ -424,7 +422,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
424422

425423
@Override
426424
public VirtualRouter destroyRouter(final long routerId, final Account caller, final Long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException {
427-
return nwHelper.destroyRouter(routerId, caller, callerUserId);
425+
return _nwHelper.destroyRouter(routerId, caller, callerUserId);
428426
}
429427

430428
@Override
@@ -647,7 +645,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
647645
useLocalStorage, true, null, true, VirtualMachine.Type.DomainRouter, true);
648646
offering.setUniqueName(ServiceOffering.routerDefaultOffUniqueName);
649647
offering = _serviceOfferingDao.persistSystemServiceOffering(offering);
650-
routerDeploymentManagerBuilder.setOfferingId(offering.getId());
648+
_routerDeploymentManagerBuilder.setOfferingId(offering.getId());
651649

652650
// this can sometimes happen, if DB is manually or programmatically
653651
// manipulated
@@ -1127,14 +1125,6 @@ protected void recoverRedundantNetwork(final DomainRouterVO masterRouter, final
11271125
}
11281126
}
11291127

1130-
private int getRealPriority(final DomainRouterVO router) {
1131-
int priority = router.getPriority();
1132-
if (router.getIsPriorityBumpUp()) {
1133-
priority += DEFAULT_DELTA;
1134-
}
1135-
return priority;
1136-
}
1137-
11381128
protected class RvRStatusUpdateTask extends ManagedContextRunnable {
11391129

11401130
public RvRStatusUpdateTask() {
@@ -1183,7 +1173,7 @@ private void checkSanity(final List<DomainRouterVO> routers) {
11831173
}
11841174
}
11851175
if (masterRouter != null && backupRouter != null) {
1186-
if (getRealPriority(masterRouter) - DEFAULT_DELTA + 1 != getRealPriority(backupRouter) || backupRouter.getIsPriorityBumpUp()) {
1176+
if (_nwHelper.getRealPriority(masterRouter) - DEFAULT_DELTA + 1 != _nwHelper.getRealPriority(backupRouter) || backupRouter.getIsPriorityBumpUp()) {
11871177
recoverRedundantNetwork(masterRouter, backupRouter);
11881178
}
11891179
}
@@ -1391,9 +1381,6 @@ protected void getRouterAlerts() {
13911381
}
13921382
}
13931383

1394-
private final static int DEFAULT_PRIORITY = 100;
1395-
private final static int DEFAULT_DELTA = 2;
1396-
13971384
protected int getUpdatedPriority(final Network guestNetwork, final List<DomainRouterVO> routers, final DomainRouterVO exclude)
13981385
throws InsufficientVirtualNetworkCapacityException {
13991386
int priority;
@@ -1407,8 +1394,8 @@ protected int getUpdatedPriority(final Network guestNetwork, final List<DomainRo
14071394
}
14081395
// FIXME Assume the maxPriority one should be running or just
14091396
// created.
1410-
if (r.getId() != exclude.getId() && getRealPriority(r) > maxPriority) {
1411-
maxPriority = getRealPriority(r);
1397+
if (r.getId() != exclude.getId() && _nwHelper.getRealPriority(r) > maxPriority) {
1398+
maxPriority = _nwHelper.getRealPriority(r);
14121399
}
14131400
}
14141401
if (maxPriority == 0) {
@@ -2121,7 +2108,7 @@ public boolean finalizeStart(final VirtualMachineProfile profile, final long hos
21212108
if (nic.getBroadcastUri().getScheme().equals("pvlan")) {
21222109
final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic");
21232110

2124-
final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
2111+
final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(dcVO);
21252112
try {
21262113
result = networkTopology.setupDhcpForPvlan(true, router, router.getHostId(), nicProfile);
21272114
} catch (final ResourceUnavailableException e) {
@@ -2154,7 +2141,7 @@ public void finalizeStop(final VirtualMachineProfile profile, final Answer answe
21542141
if (network.getTrafficType() == TrafficType.Guest && nic.getBroadcastUri() != null && nic.getBroadcastUri().getScheme().equals("pvlan")) {
21552142
final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic");
21562143

2157-
final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
2144+
final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(dcVO);
21582145
try {
21592146
networkTopology.setupDhcpForPvlan(false, domR, domR.getHostId(), nicProfile);
21602147
} catch (final ResourceUnavailableException e) {
@@ -2187,7 +2174,7 @@ public boolean startRemoteAccessVpn(final Network network, final RemoteAccessVpn
21872174
final Commands cmds = new Commands(Command.OnError.Stop);
21882175
createApplyVpnCommands(true, vpn, router, cmds);
21892176

2190-
if (!sendCommandsToRouter(router, cmds)) {
2177+
if (!_nwHelper.sendCommandsToRouter(router, cmds)) {
21912178
throw new AgentUnavailableException("Unable to send commands to virtual router ", router.getHostId());
21922179
}
21932180

@@ -2222,7 +2209,7 @@ public boolean deleteRemoteAccessVpn(final Network network, final RemoteAccessVp
22222209
if (router.getState() == State.Running) {
22232210
final Commands cmds = new Commands(Command.OnError.Continue);
22242211
createApplyVpnCommands(false, vpn, router, cmds);
2225-
result = result && sendCommandsToRouter(router, cmds);
2212+
result = result && _nwHelper.sendCommandsToRouter(router, cmds);
22262213
} else if (router.getState() == State.Stopped) {
22272214
s_logger.debug("Router " + router + " is in Stopped state, not sending deleteRemoteAccessVpn command to it");
22282215
continue;
@@ -2277,7 +2264,7 @@ public boolean removeDhcpSupportForSubnet(final Network network, final List<Doma
22772264
}
22782265
createDeleteIpAliasCommand(router, revokedIpAliasTOs, activeIpAliasTOs, network.getId(), cmds);
22792266
configDnsMasq(router, network, cmds);
2280-
final boolean result = sendCommandsToRouter(router, cmds);
2267+
final boolean result = _nwHelper.sendCommandsToRouter(router, cmds);
22812268
if (result) {
22822269
Transaction.execute(new TransactionCallbackNoReturn() {
22832270
@Override
@@ -2412,7 +2399,7 @@ public VirtualRouter startRouter(final long routerId, final boolean reprogramNet
24122399
} else {
24132400
params.put(Param.ReProgramGuestNetworks, false);
24142401
}
2415-
final VirtualRouter virtualRouter = nwHelper.startVirtualRouter(router, user, caller, params);
2402+
final VirtualRouter virtualRouter = _nwHelper.startVirtualRouter(router, user, caller, params);
24162403
if (virtualRouter == null) {
24172404
throw new CloudRuntimeException("Failed to start router with id " + routerId);
24182405
}
@@ -2776,92 +2763,6 @@ private void createDhcpEntryCommandsForVMs(final DomainRouterVO router, final Co
27762763
}
27772764
}
27782765

2779-
@Override
2780-
public boolean sendCommandsToRouter(final VirtualRouter router, final Commands cmds) throws AgentUnavailableException {
2781-
if (!nwHelper.checkRouterVersion(router)) {
2782-
s_logger.debug("Router requires upgrade. Unable to send command to router:" + router.getId() + ", router template version : " + router.getTemplateVersion()
2783-
+ ", minimal required version : " + MinVRVersion);
2784-
throw new CloudRuntimeException("Unable to send command. Upgrade in progress. Please contact administrator.");
2785-
}
2786-
Answer[] answers = null;
2787-
try {
2788-
answers = _agentMgr.send(router.getHostId(), cmds);
2789-
} catch (final OperationTimedoutException e) {
2790-
s_logger.warn("Timed Out", e);
2791-
throw new AgentUnavailableException("Unable to send commands to virtual router ", router.getHostId(), e);
2792-
}
2793-
2794-
if (answers == null) {
2795-
return false;
2796-
}
2797-
2798-
if (answers.length != cmds.size()) {
2799-
return false;
2800-
}
2801-
2802-
// FIXME: Have to return state for individual command in the future
2803-
boolean result = true;
2804-
if (answers.length > 0) {
2805-
for (final Answer answer : answers) {
2806-
if (!answer.getResult()) {
2807-
result = false;
2808-
break;
2809-
}
2810-
}
2811-
}
2812-
return result;
2813-
}
2814-
2815-
protected void handleSingleWorkingRedundantRouter(final List<? extends VirtualRouter> connectedRouters, final List<? extends VirtualRouter> disconnectedRouters,
2816-
final String reason) throws ResourceUnavailableException {
2817-
if (connectedRouters.isEmpty() || disconnectedRouters.isEmpty()) {
2818-
return;
2819-
}
2820-
if (connectedRouters.size() != 1 || disconnectedRouters.size() != 1) {
2821-
s_logger.warn("How many redundant routers do we have?? ");
2822-
return;
2823-
}
2824-
if (!connectedRouters.get(0).getIsRedundantRouter()) {
2825-
throw new ResourceUnavailableException("Who is calling this with non-redundant router or non-domain router?", DataCenter.class, connectedRouters.get(0)
2826-
.getDataCenterId());
2827-
}
2828-
if (!disconnectedRouters.get(0).getIsRedundantRouter()) {
2829-
throw new ResourceUnavailableException("Who is calling this with non-redundant router or non-domain router?", DataCenter.class, disconnectedRouters.get(0)
2830-
.getDataCenterId());
2831-
}
2832-
2833-
final DomainRouterVO connectedRouter = (DomainRouterVO) connectedRouters.get(0);
2834-
DomainRouterVO disconnectedRouter = (DomainRouterVO) disconnectedRouters.get(0);
2835-
2836-
if (s_logger.isDebugEnabled()) {
2837-
s_logger.debug("About to stop the router " + disconnectedRouter.getInstanceName() + " due to: " + reason);
2838-
}
2839-
final String title = "Virtual router " + disconnectedRouter.getInstanceName() + " would be stopped after connecting back, due to " + reason;
2840-
final String context = "Virtual router (name: " + disconnectedRouter.getInstanceName() + ", id: " + disconnectedRouter.getId()
2841-
+ ") would be stopped after connecting back, due to: " + reason;
2842-
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, disconnectedRouter.getDataCenterId(), disconnectedRouter.getPodIdToDeployIn(), title, context);
2843-
disconnectedRouter.setStopPending(true);
2844-
disconnectedRouter = _routerDao.persist(disconnectedRouter);
2845-
2846-
final int connRouterPR = getRealPriority(connectedRouter);
2847-
final int disconnRouterPR = getRealPriority(disconnectedRouter);
2848-
if (connRouterPR < disconnRouterPR) {
2849-
// connRouterPR < disconnRouterPR, they won't equal at anytime
2850-
if (!connectedRouter.getIsPriorityBumpUp()) {
2851-
final BumpUpPriorityCommand command = new BumpUpPriorityCommand();
2852-
command.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(connectedRouter.getId()));
2853-
command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, connectedRouter.getInstanceName());
2854-
final Answer answer = _agentMgr.easySend(connectedRouter.getHostId(), command);
2855-
if (!answer.getResult()) {
2856-
s_logger.error("Failed to bump up " + connectedRouter.getInstanceName() + "'s priority! " + answer.getDetails());
2857-
}
2858-
} else {
2859-
final String t = "Can't bump up virtual router " + connectedRouter.getInstanceName() + "'s priority due to it's already bumped up!";
2860-
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, connectedRouter.getDataCenterId(), connectedRouter.getPodIdToDeployIn(), t, t);
2861-
}
2862-
}
2863-
}
2864-
28652766
@Override
28662767
public List<VirtualRouter> getRoutersForNetwork(final long networkId) {
28672768
final List<DomainRouterVO> routers = _routerDao.findByNetwork(networkId);
@@ -3191,7 +3092,7 @@ public List<Long> upgradeRouterTemplate(final UpgradeRouterTemplateCmd cmd) {
31913092
private List<Long> rebootRouters(final List<DomainRouterVO> routers) {
31923093
final List<Long> jobIds = new ArrayList<Long>();
31933094
for (final DomainRouterVO router : routers) {
3194-
if (!nwHelper.checkRouterVersion(router)) {
3095+
if (!_nwHelper.checkRouterVersion(router)) {
31953096
s_logger.debug("Upgrading template for router: " + router.getId());
31963097
final Map<String, String> params = new HashMap<String, String>();
31973098
params.put("ctxUserId", "1");
@@ -3265,8 +3166,8 @@ protected boolean aggregationExecution(final AggregationControlCommand.Action ac
32653166
for (DomainRouterVO router : routers) {
32663167
AggregationControlCommand cmd = new AggregationControlCommand(action, router.getInstanceName(), getRouterControlIp(router.getId()), getRouterIpInNetwork(
32673168
network.getId(), router.getId()));
3268-
Commands cmds = new Commands(cmd);
3269-
if (!sendCommandsToRouter(router, cmds)) {
3169+
final Commands cmds = new Commands(cmd);
3170+
if (!_nwHelper.sendCommandsToRouter(router, cmds)) {
32703171
return false;
32713172
}
32723173
}

0 commit comments

Comments
 (0)