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