Skip to content

Commit b399c31

Browse files
author
Sheng Yang
committed
CLOUDSTACK-6218: Serialize VR commands in VR resource
1 parent 36558e4 commit b399c31

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
import java.util.Queue;
7878
import java.util.UUID;
7979
import java.util.concurrent.LinkedBlockingQueue;
80+
import java.util.concurrent.locks.Lock;
81+
import java.util.concurrent.locks.ReentrantLock;
8082

8183
/**
8284
* VirtualNetworkResource controls and configures virtual networking
@@ -123,6 +125,7 @@ protected class VRScripts {
123125
private static final Logger s_logger = Logger.getLogger(VirtualRoutingResource.class);
124126
private VirtualRouterDeployer _vrDeployer;
125127
private Map <String, Queue> _vrAggregateCommandsSet;
128+
protected Map<String, Lock> _vrLockMap = new HashMap<String, Lock>();
126129

127130
private String _name;
128131
private int _sleep;
@@ -137,13 +140,22 @@ public VirtualRoutingResource(VirtualRouterDeployer deployer) {
137140

138141
public Answer executeRequest(final NetworkElementCommand cmd) {
139142
boolean aggregated = false;
143+
String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
144+
Lock lock;
145+
if (_vrLockMap.containsKey(routerName)) {
146+
lock = _vrLockMap.get(routerName);
147+
} else {
148+
lock = new ReentrantLock();
149+
_vrLockMap.put(routerName, lock);
150+
}
151+
lock.lock();
152+
140153
try {
141154
ExecutionResult rc = _vrDeployer.prepareCommand(cmd);
142155
if (!rc.isSuccess()) {
143156
s_logger.error("Failed to prepare VR command due to " + rc.getDetails());
144157
return new Answer(cmd, false, rc.getDetails());
145158
}
146-
String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
147159

148160
assert cmd.getRouterAccessIp() != null : "Why there is no access IP for VR?";
149161

@@ -174,6 +186,7 @@ public Answer executeRequest(final NetworkElementCommand cmd) {
174186
} catch (final IllegalArgumentException e) {
175187
return new Answer(cmd, false, e.getMessage());
176188
} finally {
189+
lock.unlock();
177190
if (!aggregated) {
178191
ExecutionResult rc = _vrDeployer.cleanupCommand(cmd);
179192
if (!rc.isSuccess()) {

0 commit comments

Comments
 (0)