mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
ovs tunnel network -- add lock entry in ovs_tunnel_account
This commit is contained in:
parent
334c41a7e8
commit
38ab26bcb0
@ -9,17 +9,27 @@ public class OvsCreateTunnelAnswer extends Answer {
|
||||
long account;
|
||||
String inPortName;
|
||||
|
||||
public OvsCreateTunnelAnswer(Command cmd, boolean success, String details) {
|
||||
//for debug info
|
||||
String fromIp;
|
||||
String toIp;
|
||||
String key;
|
||||
String bridge;
|
||||
|
||||
public OvsCreateTunnelAnswer(Command cmd, boolean success, String details, String bridge) {
|
||||
super(cmd, success, details);
|
||||
OvsCreateTunnelCommand c = (OvsCreateTunnelCommand)cmd;
|
||||
from = c.getFrom();
|
||||
to = c.getTo();
|
||||
account = c.getAccount();
|
||||
inPortName = "[]";
|
||||
fromIp = c.getFromIp();
|
||||
toIp = c.getRemoteIp();
|
||||
key = c.getKey();
|
||||
this.bridge = bridge;
|
||||
}
|
||||
|
||||
public OvsCreateTunnelAnswer(Command cmd, boolean success, String details, String inPortName) {
|
||||
this(cmd, success, details);
|
||||
public OvsCreateTunnelAnswer(Command cmd, boolean success, String details, String inPortName, String bridge) {
|
||||
this(cmd, success, details, bridge);
|
||||
this.inPortName = inPortName;
|
||||
}
|
||||
|
||||
@ -39,4 +49,20 @@ public class OvsCreateTunnelAnswer extends Answer {
|
||||
public String getInPortName() {
|
||||
return inPortName;
|
||||
}
|
||||
|
||||
public String getFromIp() {
|
||||
return fromIp;
|
||||
}
|
||||
|
||||
public String getToIp() {
|
||||
return toIp;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getBridge() {
|
||||
return bridge;
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,17 +9,21 @@ public class OvsCreateTunnelCommand extends Command {
|
||||
Long to;
|
||||
long account;
|
||||
|
||||
//for debug info
|
||||
String fromIp;
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public OvsCreateTunnelCommand(String remoteIp, String key, Long from, Long to, long account) {
|
||||
public OvsCreateTunnelCommand(String remoteIp, String key, Long from, Long to, long account, String fromIp) {
|
||||
this.remoteIp = remoteIp;
|
||||
this.key = key;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.account = account;
|
||||
this.fromIp = fromIp;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
@ -42,4 +46,8 @@ public class OvsCreateTunnelCommand extends Command {
|
||||
return account;
|
||||
}
|
||||
|
||||
public String getFromIp() {
|
||||
return fromIp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
<classpathentry kind="lib" path="/thirdparty/vmware-vim.jar"/>
|
||||
<classpathentry kind="lib" path="/thirdparty/vmware-vim25.jar"/>
|
||||
<classpathentry kind="lib" path="/thirdparty/gson.jar"/>
|
||||
<classpathentry kind="lib" path="/thirdparty/xenserver-5.6.100-1.jar"/>
|
||||
<classpathentry kind="lib" path="/thirdparty/xenserver-5.6.100-1.jar" sourcepath="/home/frank/dev/oss1/deps/XenServerJava"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/deps"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
@ -4020,25 +4020,26 @@ public abstract class CitrixResourceBase implements ServerResource {
|
||||
|
||||
private OvsCreateTunnelAnswer execute(OvsCreateTunnelCommand cmd) {
|
||||
Connection conn = getConnection();
|
||||
String bridge = "unknown";
|
||||
try {
|
||||
Network nw = createTunnelNetwork(conn, cmd.getAccount());
|
||||
if (nw == null) {
|
||||
return new OvsCreateTunnelAnswer(cmd, false, "Cannot create network");
|
||||
return new OvsCreateTunnelAnswer(cmd, false, "Cannot create network", bridge);
|
||||
}
|
||||
|
||||
String bridge = nw.getBridge(conn);
|
||||
bridge = nw.getBridge(conn);
|
||||
String result = callHostPlugin(conn, "ovstunnel", "create_tunnel", "bridge", bridge, "remote_ip", cmd.getRemoteIp(), "key", cmd.getKey(), "from", cmd.getFrom().toString(), "to", cmd
|
||||
.getTo().toString());
|
||||
|
||||
String[] res = result.split(":");
|
||||
if (res.length == 2 && res[0].equalsIgnoreCase("SUCCESS")) {
|
||||
return new OvsCreateTunnelAnswer(cmd, true, result, res[1]);
|
||||
return new OvsCreateTunnelAnswer(cmd, true, result, res[1], bridge);
|
||||
} else {
|
||||
return new OvsCreateTunnelAnswer(cmd, false, result);
|
||||
return new OvsCreateTunnelAnswer(cmd, false, result, bridge);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("caught execption when creating ovs tunnel", e);
|
||||
return new OvsCreateTunnelAnswer(cmd, false, e.getMessage());
|
||||
return new OvsCreateTunnelAnswer(cmd, false, e.getMessage(), bridge);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -78,7 +78,13 @@ public class OvsTunnelManagerImpl implements OvsTunnelManager {
|
||||
try {
|
||||
key = _tunnelDao.askKey(from, to);
|
||||
ta = new OvsTunnelAccountVO(from, to, key, account);
|
||||
OvsTunnelAccountVO lock = _tunnelAccountDao.acquireInLockTable(Long.valueOf(1));
|
||||
if (lock == null) {
|
||||
s_logger.warn("Cannot lock table ovs_tunnel_account");
|
||||
return -1;
|
||||
}
|
||||
_tunnelAccountDao.persist(ta);
|
||||
_tunnelAccountDao.releaseFromLockTable(lock.getId());
|
||||
} catch (EntityExistsException e) {
|
||||
ta = _tunnelAccountDao.getByFromToAccount(from, to, account);
|
||||
if (ta == null) {
|
||||
@ -93,12 +99,9 @@ public class OvsTunnelManagerImpl implements OvsTunnelManager {
|
||||
|
||||
private void handleCreateTunnelAnswer(Answer[] answers){
|
||||
OvsCreateTunnelAnswer r = (OvsCreateTunnelAnswer) answers[0];
|
||||
/*
|
||||
String s = String.format(
|
||||
"(hostIP:%1$s, remoteIP:%2$s, bridge:%3$s, greKey:%4$s)",
|
||||
r.getHostIp(), r.getRemoteIp(), r.getBridge(), r.getKey());
|
||||
*/
|
||||
String s = "hi";
|
||||
"(hostIP:%1$s, remoteIP:%2$s, bridge:%3$s, greKey:%4$s, portName:%5$s)",
|
||||
r.getFromIp(), r.getToIp(), r.getBridge(), r.getKey(), r.getInPortName());
|
||||
Long from = r.getFrom();
|
||||
Long to = r.getTo();
|
||||
long account = r.getAccount();
|
||||
@ -109,13 +112,11 @@ public class OvsTunnelManagerImpl implements OvsTunnelManager {
|
||||
|
||||
if (!r.getResult()) {
|
||||
ta.setState("FAILED");
|
||||
s_logger.warn("Create GRE tunnel failed due to " + r.getDetails()
|
||||
+ s);
|
||||
s_logger.warn("Create GRE tunnel failed due to " + r.getDetails() + s);
|
||||
} else {
|
||||
ta.setState("SUCCESS");
|
||||
ta.setPortName(r.getInPortName());
|
||||
s_logger.warn("Create GRE tunnel Success " + r.getDetails()
|
||||
+ s);
|
||||
s_logger.warn("Create GRE tunnel " + r.getDetails() + s);
|
||||
}
|
||||
_tunnelAccountDao.update(ta.getId(), ta);
|
||||
}
|
||||
@ -182,15 +183,16 @@ public class OvsTunnelManagerImpl implements OvsTunnelManager {
|
||||
for (Pair<Long, Integer> i : toHosts) {
|
||||
HostVO rHost = _hostDao.findById(i.first());
|
||||
Commands cmds = new Commands(
|
||||
new OvsCreateTunnelCommand(rHost.getPrivateIpAddress(), i.second().toString(), Long.valueOf(hostId), i.first(), accountId));
|
||||
new OvsCreateTunnelCommand(rHost.getPrivateIpAddress(), i.second().toString(), Long.valueOf(hostId), i.first(), accountId, myIp));
|
||||
s_logger.debug("Ask host " + hostId + " to create gre tunnel to " + i.first());
|
||||
Answer[] answers = _agentMgr.send(hostId, cmds);
|
||||
handleCreateTunnelAnswer(answers);
|
||||
}
|
||||
|
||||
for (Pair<Long, Integer> i : fromHosts) {
|
||||
HostVO rHost = _hostDao.findById(i.first());
|
||||
Commands cmd2s = new Commands(
|
||||
new OvsCreateTunnelCommand(myIp, i.second().toString(), i.first(), Long.valueOf(hostId), accountId));
|
||||
new OvsCreateTunnelCommand(myIp, i.second().toString(), i.first(), Long.valueOf(hostId), accountId, rHost.getPrivateIpAddress()));
|
||||
s_logger.debug("Ask host " + i.first() + " to create gre tunnel to " + hostId);
|
||||
Answer[] answers = _agentMgr.send(i.first(), cmd2s);
|
||||
handleCreateTunnelAnswer(answers);
|
||||
@ -234,11 +236,18 @@ public class OvsTunnelManagerImpl implements OvsTunnelManager {
|
||||
String toStr = (to == 0 ? "all peers" : Long.toString(to));
|
||||
|
||||
if (ans.getResult()) {
|
||||
OvsTunnelAccountVO lock = _tunnelAccountDao.acquireInLockTable(Long.valueOf(1));
|
||||
if (lock == null) {
|
||||
s_logger.warn(String.format("failed to lock ovs_tunnel_account, remove record of tunnel(from=%1$s, to=%2$s account=%3$s) failed", from, to, account));
|
||||
return;
|
||||
}
|
||||
|
||||
if (to == 0) {
|
||||
_tunnelAccountDao.removeByFromAccount(from, account);
|
||||
} else {
|
||||
_tunnelAccountDao.removeByFromToAccount(from, to, account);
|
||||
}
|
||||
_tunnelAccountDao.releaseFromLockTable(lock.getId());
|
||||
|
||||
s_logger.debug(String.format("Destroy tunnel(account:%1$s, from:%2$s, to:%3$s) successful", account, from, toStr));
|
||||
} else {
|
||||
|
||||
@ -1395,6 +1395,8 @@ CREATE TABLE `cloud`.`ovs_tunnel_account`(
|
||||
PRIMARY KEY(`from`, `to`, `account`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
INSERT INTO `cloud`.`ovs_tunnel_account` (`from`, `to`, `account`, `key`, `port_name`, `state`) VALUES (0, 0, 0, 0, 'lock', 'SUCCESS');
|
||||
|
||||
CREATE TABLE `cloud`.`ovs_vlan_mapping_dirty`(
|
||||
`id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT,
|
||||
`account_id` bigint unsigned COMMENT 'account id',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user