Remove duplicated code

This commit is contained in:
Hugo Trippaers 2014-07-17 12:13:48 +02:00
parent 1e4695b9aa
commit 5651a13cfd
2 changed files with 14 additions and 53 deletions

View File

@ -193,7 +193,6 @@ public class VirtualRoutingResource {
}
}
private CheckS2SVpnConnectionsAnswer execute(CheckS2SVpnConnectionsCommand cmd) {
StringBuffer buff = new StringBuffer();
@ -226,7 +225,7 @@ public class VirtualRoutingResource {
}
}
protected Answer execute(CheckRouterCommand cmd) {
private Answer execute(CheckRouterCommand cmd) {
final ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.RVR_CHECK, null);
if (!result.isSuccess()) {
return new CheckRouterAnswer(cmd, result.getDetails());
@ -234,7 +233,7 @@ public class VirtualRoutingResource {
return new CheckRouterAnswer(cmd, result.getDetails(), true);
}
protected Answer execute(GetDomRVersionCmd cmd) {
private Answer execute(GetDomRVersionCmd cmd) {
final ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.VERSION, null);
if (!result.isSuccess()) {
return new GetDomRVersionAnswer(cmd, "GetDomRVersionCmd failed");
@ -246,7 +245,6 @@ public class VirtualRoutingResource {
return new GetDomRVersionAnswer(cmd, result.getDetails(), lines[0], lines[1]);
}
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
_name = name;
@ -270,44 +268,12 @@ public class VirtualRoutingResource {
return true;
}
public String connect(final String ipAddress) {
public boolean connect(final String ipAddress) {
return connect(ipAddress, _port);
}
public String connect(final String ipAddress, final int port) {
for (int i = 0; i <= _retry; i++) {
SocketChannel sch = null;
try {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Trying to connect to " + ipAddress);
}
sch = SocketChannel.open();
sch.configureBlocking(true);
final InetSocketAddress addr = new InetSocketAddress(ipAddress, port);
sch.connect(addr);
return null;
} catch (final IOException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Could not connect to " + ipAddress);
}
} finally {
if (sch != null) {
try {
sch.close();
} catch (final IOException e) {
}
}
}
try {
Thread.sleep(_sleep);
} catch (final InterruptedException e) {
}
}
s_logger.debug("Unable to logon to " + ipAddress);
return "Unable to connect";
public boolean connect(final String ipAddress, final int port) {
return connect(ipAddress, port, _sleep);
}
public boolean connect(final String ipAddress, int retry, int sleep) {

View File

@ -1822,10 +1822,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
if (pool.getType() == StoragePoolType.CLVM && volFormat == PhysicalDiskFormat.RAW) {
return "CLVM";
} else if ((poolType == StoragePoolType.NetworkFilesystem
|| poolType == StoragePoolType.SharedMountPoint
|| poolType == StoragePoolType.Filesystem
|| poolType == StoragePoolType.Gluster)
&& volFormat == PhysicalDiskFormat.QCOW2 ) {
|| poolType == StoragePoolType.SharedMountPoint
|| poolType == StoragePoolType.Filesystem
|| poolType == StoragePoolType.Gluster)
&& volFormat == PhysicalDiskFormat.QCOW2 ) {
return "QCOW2";
}
return null;
@ -2141,7 +2141,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
protected ExecutionResult prepareNetworkElementCommand(SetSourceNatCommand cmd) {
Connect conn;
String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
String routerIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
IpAddressTO pubIP = cmd.getIpAddress();
try {
@ -2179,7 +2179,6 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
protected ExecutionResult prepareNetworkElementCommand(IpAssocVpcCommand cmd) {
Connect conn;
int i = 0;
String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
try {
@ -2295,12 +2294,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
int nicNum = 0;
for (IpAddressTO ip : ips) {
boolean newNic = false;
if (!broadcastUriAllocatedToVM.containsKey(ip.getBroadcastUri())) {
/* plug a vif into router */
VifHotPlug(conn, routerName, ip.getBroadcastUri(), ip.getVifMacAddress());
broadcastUriAllocatedToVM.put(ip.getBroadcastUri(), nicPos++);
newNic = true;
}
nicNum = broadcastUriAllocatedToVM.get(ip.getBroadcastUri());
@ -3441,12 +3438,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
protected Answer execute(RebootRouterCommand cmd) {
RebootAnswer answer = (RebootAnswer)execute((RebootCommand)cmd);
String result = _virtRouterResource.connect(cmd.getPrivateIpAddress());
if (result == null) {
if (_virtRouterResource.connect(cmd.getPrivateIpAddress())) {
networkUsage(cmd.getPrivateIpAddress(), "create", null);
return answer;
} else {
return new Answer(cmd, false, result);
return new Answer(cmd, false, "Failed to connect to virtual router " + cmd.getVmName());
}
}
@ -4057,9 +4053,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
s_logger.debug("Ping command port, " + privateIp + ":" + cmdPort);
}
String result = _virtRouterResource.connect(privateIp, cmdPort);
if (result != null) {
return new CheckSshAnswer(cmd, "Can not ping System vm " + vmName + "due to:" + result);
if (!_virtRouterResource.connect(privateIp, cmdPort)) {
return new CheckSshAnswer(cmd, "Can not ping System vm " + vmName + " because of a connection failure");
}
if (s_logger.isDebugEnabled()) {