cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [1/3] git commit: updated refs/heads/4.9 to 55b9180
Date Wed, 23 Nov 2016 08:31:17 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/4.9 1137a79cc -> 55b918076


CLOUDSTACK-9503: Increased the VR script timeout. Most of the changes are about converting
int/long time values to joda Duration.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/83b5a8b2
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/83b5a8b2
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/83b5a8b2

Branch: refs/heads/4.9
Commit: 83b5a8b2b2a68fc8d2d7d6074125630fb0752cbf
Parents: be89f64
Author: Abhinandan Prateek <aprateek@apache.org>
Authored: Tue Sep 20 13:00:46 2016 +0530
Committer: Abhinandan Prateek <aprateek@apache.org>
Committed: Tue Nov 1 16:14:23 2016 +0530

----------------------------------------------------------------------
 .../resource/virtualnetwork/VRScripts.java      |  5 ++++-
 .../virtualnetwork/VirtualRouterDeployer.java   |  5 +++--
 .../virtualnetwork/VirtualRoutingResource.java  | 15 ++++++++-------
 .../VirtualRoutingResourceTest.java             |  5 +++--
 .../resource/HypervDirectConnectResource.java   |  9 +++++----
 .../kvm/resource/LibvirtComputingResource.java  | 14 ++++++++------
 .../LibvirtOvsCreateTunnelCommandWrapper.java   | 12 ++++--------
 .../LibvirtPvlanSetupCommandWrapper.java        |  5 +++--
 .../resource/LibvirtComputingResourceTest.java  | 20 +++++++++-----------
 .../resources/Ovm3VirtualRoutingResource.java   |  8 +++++---
 .../vmware/resource/VmwareResource.java         |  8 +++++---
 .../xenserver/resource/CitrixResourceBase.java  |  8 +++++---
 .../java/com/cloud/utils/script/Script.java     | 18 +++++++++++++++++-
 .../java/com/cloud/utils/ssh/SshHelper.java     | 10 ++++++++--
 14 files changed, 87 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83b5a8b2/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java b/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java
index a251505..838f087 100644
--- a/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java
+++ b/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java
@@ -19,6 +19,8 @@
 
 package com.cloud.agent.resource.virtualnetwork;
 
+import org.joda.time.Duration;
+
 public class VRScripts {
     public final static String CONFIG_PERSIST_LOCATION = "/var/cache/cloud/";
     public final static String IP_ASSOCIATION_CONFIG = "ip_associations.json";
@@ -40,7 +42,8 @@ public class VRScripts {
     public static final String LOAD_BALANCER_CONFIG = "load_balancer.json";
 
     public final static String CONFIG_CACHE_LOCATION = "/var/cache/cloud/";
-    public final static int DEFAULT_EXECUTEINVR_TIMEOUT = 120; //Seconds
+    public final static Duration VR_SCRIPT_EXEC_TIMEOUT = Duration.standardMinutes(10);
+    public final static Duration CONNECTION_TIMEOUT = Duration.standardMinutes(1);
 
     // New scripts for use with chef
     public static final String UPDATE_CONFIG = "update_config.py";

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83b5a8b2/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRouterDeployer.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRouterDeployer.java b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRouterDeployer.java
index f6a1694..6501292 100644
--- a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRouterDeployer.java
+++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRouterDeployer.java
@@ -19,13 +19,14 @@
 
 package com.cloud.agent.resource.virtualnetwork;
 
+import org.joda.time.Duration;
+
 import com.cloud.agent.api.routing.NetworkElementCommand;
 import com.cloud.utils.ExecutionResult;
 
 public interface VirtualRouterDeployer {
     ExecutionResult executeInVR(String routerIp, String script, String args);
-    /* timeout in seconds */
-    ExecutionResult executeInVR(String routerIp, String script, String args, int timeout);
+    ExecutionResult executeInVR(String routerIp, String script, String args, Duration timeout);
     ExecutionResult createFileInVR(String routerIp, String path, String filename, String
content);
     ExecutionResult prepareCommand(NetworkElementCommand cmd);
     ExecutionResult cleanupCommand(NetworkElementCommand cmd);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83b5a8b2/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
index f3edc69..87a38d3 100644
--- a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
+++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
@@ -22,6 +22,7 @@ package com.cloud.agent.resource.virtualnetwork;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.nio.channels.SocketChannel;
+import org.joda.time.Duration;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -73,7 +74,7 @@ public class VirtualRoutingResource {
     private int _sleep;
     private int _retry;
     private int _port;
-    private int _eachTimeout;
+    private Duration _eachTimeout;
 
     private String _cfgVersion = "1.0";
 
@@ -153,10 +154,10 @@ public class VirtualRoutingResource {
     }
 
     private ExecutionResult applyConfigToVR(String routerAccessIp, ConfigItem c) {
-        return applyConfigToVR(routerAccessIp, c, VRScripts.DEFAULT_EXECUTEINVR_TIMEOUT);
+        return applyConfigToVR(routerAccessIp, c, VRScripts.VR_SCRIPT_EXEC_TIMEOUT);
     }
 
-    private ExecutionResult applyConfigToVR(String routerAccessIp, ConfigItem c, int timeout)
{
+    private ExecutionResult applyConfigToVR(String routerAccessIp, ConfigItem c, Duration
timeout) {
         if (c instanceof FileConfigItem) {
             FileConfigItem configItem = (FileConfigItem)c;
             return _vrDeployer.createFileInVR(routerAccessIp, configItem.getFilePath(), configItem.getFileName(),
configItem.getFileContents());
@@ -271,7 +272,7 @@ public class VirtualRoutingResource {
         _port = NumbersUtil.parseInt(value, 3922);
 
         value = (String)params.get("router.aggregation.command.each.timeout");
-        _eachTimeout = NumbersUtil.parseInt(value, 3);
+        _eachTimeout = Duration.standardSeconds(NumbersUtil.parseInt(value, 10));
 
         if (_vrDeployer == null) {
             throw new ConfigurationException("Unable to find the resource for VirtualRouterDeployer!");
@@ -374,9 +375,9 @@ public class VirtualRoutingResource {
                 FileConfigItem fileConfigItem = new FileConfigItem(VRScripts.CONFIG_CACHE_LOCATION,
cfgFileName, sb.toString());
                 ScriptConfigItem scriptConfigItem = new ScriptConfigItem(VRScripts.VR_CFG,
"-c " + VRScripts.CONFIG_CACHE_LOCATION + cfgFileName);
                 // 120s is the minimal timeout
-                int timeout = answerCounts * _eachTimeout;
-                if (timeout < 120) {
-                    timeout = 120;
+                Duration timeout = _eachTimeout.withDurationAdded(_eachTimeout.getStandardSeconds(),
answerCounts);
+                if (timeout.isShorterThan(VRScripts.VR_SCRIPT_EXEC_TIMEOUT)) {
+                    timeout = VRScripts.VR_SCRIPT_EXEC_TIMEOUT;
                 }
 
                 ExecutionResult result = applyConfigToVR(cmd.getRouterAccessIp(), fileConfigItem);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83b5a8b2/core/test/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java
----------------------------------------------------------------------
diff --git a/core/test/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java
b/core/test/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java
index 6b5f1d1..6405037 100644
--- a/core/test/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java
+++ b/core/test/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java
@@ -31,6 +31,7 @@ import java.util.UUID;
 
 import javax.naming.ConfigurationException;
 
+import org.joda.time.Duration;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -97,11 +98,11 @@ public class VirtualRoutingResourceTest implements VirtualRouterDeployer
{
 
     @Override
     public ExecutionResult executeInVR(final String routerIp, final String script, final
String args) {
-        return executeInVR(routerIp, script, args, 60);
+        return executeInVR(routerIp, script, args, Duration.standardSeconds(60L));
     }
 
     @Override
-    public ExecutionResult executeInVR(final String routerIp, final String script, final
String args, final int timeout) {
+    public ExecutionResult executeInVR(final String routerIp, final String script, final
String args, final Duration timeout) {
         assertEquals(routerIp, ROUTERIP);
         verifyCommand(_currentCmd, script, args);
         return new ExecutionResult(true, null);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83b5a8b2/plugins/hypervisors/hyperv/src/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/hyperv/src/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java
b/plugins/hypervisors/hyperv/src/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java
index 5b5ec57..862cc30 100644
--- a/plugins/hypervisors/hyperv/src/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java
+++ b/plugins/hypervisors/hyperv/src/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java
@@ -32,6 +32,7 @@ import java.security.NoSuchAlgorithmException;
 import java.security.UnrecoverableKeyException;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
+import org.joda.time.Duration;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -622,11 +623,11 @@ public class HypervDirectConnectResource extends ServerResourceBase
implements S
 
     @Override
     public ExecutionResult executeInVR(final String routerIP, final String script, final
String args) {
-        return executeInVR(routerIP, script, args, 120);
+        return executeInVR(routerIP, script, args, Duration.standardSeconds(120L));
     }
 
     @Override
-    public ExecutionResult executeInVR(final String routerIP, final String script, final
String args, final int timeout) {
+    public ExecutionResult executeInVR(final String routerIP, final String script, final
String args, final Duration timeout) {
         Pair<Boolean, String> result;
 
         //TODO: Password should be masked, cannot output to log directly
@@ -635,8 +636,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements
S
         }
 
         try {
-            result = SshHelper.sshExecute(routerIP, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(),
null, "/opt/cloud/bin/" + script + " " + args,
-                    60000, 60000, timeout * 1000);
+            result = SshHelper.sshExecute(routerIP, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(),
null, "/opt/cloud/bin/" + script + " " + args, VRScripts.CONNECTION_TIMEOUT,
+                    VRScripts.CONNECTION_TIMEOUT, timeout);
         } catch (final Exception e) {
             final String msg = "Command failed due to " + e ;
             s_logger.error(msg);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83b5a8b2/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index 883c8c9..2b1cf68 100755
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -25,6 +25,7 @@ import java.io.Reader;
 import java.net.InetAddress;
 import java.net.URI;
 import java.net.URISyntaxException;
+import org.joda.time.Duration;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
@@ -189,7 +190,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
 
     private long _hvVersion;
     private long _kernelVersion;
-    private int _timeout;
+    private Duration _timeout;
+    private static final int NUMMEMSTATS =2;
 
     private KVMHAMonitor _monitor;
     public static final String SSHKEYSPATH = "/root/.ssh";
@@ -276,12 +278,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
 
     @Override
     public ExecutionResult executeInVR(final String routerIp, final String script, final
String args) {
-        return executeInVR(routerIp, script, args, _timeout / 1000);
+        return executeInVR(routerIp, script, args, _timeout);
     }
 
     @Override
-    public ExecutionResult executeInVR(final String routerIp, final String script, final
String args, final int timeout) {
-        final Script command = new Script(_routerProxyPath, timeout * 1000, s_logger);
+    public ExecutionResult executeInVR(final String routerIp, final String script, final
String args, final Duration timeout) {
+        final Script command = new Script(_routerProxyPath, timeout, s_logger);
         final AllLinesParser parser = new AllLinesParser();
         command.add(script);
         command.add(routerIp);
@@ -383,7 +385,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
         return _updateHostPasswdPath;
     }
 
-    public int getTimeout() {
+    public Duration getTimeout() {
         return _timeout;
     }
 
@@ -774,7 +776,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
         }
 
         value = (String)params.get("scripts.timeout");
-        _timeout = NumbersUtil.parseInt(value, 30 * 60) * 1000;
+        _timeout = Duration.standardSeconds(NumbersUtil.parseInt(value, 30 * 60));
 
         value = (String)params.get("stop.script.timeout");
         _stopTimeout = NumbersUtil.parseInt(value, 120) * 1000;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83b5a8b2/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsCreateTunnelCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsCreateTunnelCommandWrapper.java
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsCreateTunnelCommandWrapper.java
index b840e8b..03d9cf9 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsCreateTunnelCommandWrapper.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsCreateTunnelCommandWrapper.java
@@ -29,7 +29,7 @@ import com.cloud.resource.CommandWrapper;
 import com.cloud.resource.ResourceWrapper;
 import com.cloud.utils.script.Script;
 
-@ResourceWrapper(handles =  OvsCreateTunnelCommand.class)
+@ResourceWrapper(handles = OvsCreateTunnelCommand.class)
 public final class LibvirtOvsCreateTunnelCommandWrapper extends CommandWrapper<OvsCreateTunnelCommand,
Answer, LibvirtComputingResource> {
 
     private static final Logger s_logger = Logger.getLogger(LibvirtOvsCreateTunnelCommandWrapper.class);
@@ -40,13 +40,10 @@ public final class LibvirtOvsCreateTunnelCommandWrapper extends CommandWrapper<O
         try {
             if (!libvirtComputingResource.findOrCreateTunnelNetwork(bridge)) {
                 s_logger.debug("Error during bridge setup");
-                return new OvsCreateTunnelAnswer(command, false,
-                        "Cannot create network", bridge);
+                return new OvsCreateTunnelAnswer(command, false, "Cannot create network",
bridge);
             }
 
-            libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getFrom(),
-                    command.getNetworkName());
-
+            libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getFrom(),
command.getNetworkName());
             final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(),
libvirtComputingResource.getTimeout(), s_logger);
             scriptCommand.add("create_tunnel");
             scriptCommand.add("--bridge", bridge);
@@ -57,8 +54,7 @@ public final class LibvirtOvsCreateTunnelCommandWrapper extends CommandWrapper<O
 
             final String result = scriptCommand.execute();
             if (result != null) {
-                return new OvsCreateTunnelAnswer(command, true, result, null,
-                        bridge);
+                return new OvsCreateTunnelAnswer(command, true, result, null, bridge);
             } else {
                 return new OvsCreateTunnelAnswer(command, false, result, bridge);
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83b5a8b2/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPvlanSetupCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPvlanSetupCommandWrapper.java
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPvlanSetupCommandWrapper.java
index 435b98a..3e01dc4 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPvlanSetupCommandWrapper.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPvlanSetupCommandWrapper.java
@@ -22,6 +22,7 @@ package com.cloud.hypervisor.kvm.resource.wrapper;
 import java.util.List;
 
 import org.apache.log4j.Logger;
+import org.joda.time.Duration;
 import org.libvirt.Connect;
 import org.libvirt.LibvirtException;
 
@@ -45,8 +46,8 @@ public final class LibvirtPvlanSetupCommandWrapper extends CommandWrapper<PvlanS
         final String op = command.getOp();
         final String dhcpName = command.getDhcpName();
         final String dhcpMac = command.getDhcpMac();
-        final String dhcpIp = command.getDhcpIp();
         final String vmMac = command.getVmMac();
+        final String dhcpIp = command.getDhcpIp();
         boolean add = true;
 
         String opr = "-A";
@@ -58,7 +59,7 @@ public final class LibvirtPvlanSetupCommandWrapper extends CommandWrapper<PvlanS
         String result = null;
         try {
             final String guestBridgeName = libvirtComputingResource.getGuestBridgeName();
-            final int timeout = libvirtComputingResource.getTimeout();
+            final Duration timeout = libvirtComputingResource.getTimeout();
 
             if (command.getType() == PvlanSetupCommand.Type.DHCP) {
                 final String ovsPvlanDhcpHostPath = libvirtComputingResource.getOvsPvlanDhcpHostPath();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83b5a8b2/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
index 04a27f3..c5942a9 100644
--- a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
+++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
@@ -53,6 +53,7 @@ import org.apache.cloudstack.utils.linux.CPUStat;
 import org.apache.cloudstack.utils.linux.MemStat;
 import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
 import org.apache.commons.lang.SystemUtils;
+import org.joda.time.Duration;
 import org.junit.Assert;
 import org.junit.Assume;
 import org.junit.Test;
@@ -1621,7 +1622,7 @@ public class LibvirtComputingResourceTest {
         when(libvirtUtilitiesHelper.retrieveSshPubKeyPath()).thenReturn("/path/pub/keys");
         when(libvirtUtilitiesHelper.retrieveSshPrvKeyPath()).thenReturn("/path/pvt/keys");
 
-        when(libvirtComputingResource.getTimeout()).thenReturn(0);
+        when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
 
         final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
         assertNotNull(wrapper);
@@ -2177,7 +2178,7 @@ public class LibvirtComputingResourceTest {
         final OvsVpcPhysicalTopologyConfigCommand command = new OvsVpcPhysicalTopologyConfigCommand(hosts,
tiers, vms, cidr);
 
         when(libvirtComputingResource.getOvsTunnelPath()).thenReturn("/path");
-        when(libvirtComputingResource.getTimeout()).thenReturn(0);
+        when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
 
 
         final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
@@ -2221,7 +2222,7 @@ public class LibvirtComputingResourceTest {
         final OvsVpcRoutingPolicyConfigCommand command = new OvsVpcRoutingPolicyConfigCommand(id,
cidr, acls, tiers);
 
         when(libvirtComputingResource.getOvsTunnelPath()).thenReturn("/path");
-        when(libvirtComputingResource.getTimeout()).thenReturn(0);
+        when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
 
 
         final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
@@ -2697,6 +2698,7 @@ public class LibvirtComputingResourceTest {
         when(libvirtComputingResource.findOrCreateTunnelNetwork(bridge)).thenReturn(true);
         when(libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getFrom(),
                 command.getNetworkName())).thenReturn(true);
+        when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
 
         final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
         assertNotNull(wrapper);
@@ -4271,8 +4273,7 @@ public class LibvirtComputingResourceTest {
         final String guestBridgeName = "br0";
         when(libvirtComputingResource.getGuestBridgeName()).thenReturn(guestBridgeName);
 
-        final int timeout = 0;
-        when(libvirtComputingResource.getTimeout()).thenReturn(timeout);
+        when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
         final String ovsPvlanDhcpHostPath = "/pvlan";
         when(libvirtComputingResource.getOvsPvlanDhcpHostPath()).thenReturn(ovsPvlanDhcpHostPath);
         when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
@@ -4313,8 +4314,7 @@ public class LibvirtComputingResourceTest {
 
         final String guestBridgeName = "br0";
         when(libvirtComputingResource.getGuestBridgeName()).thenReturn(guestBridgeName);
-        final int timeout = 0;
-        when(libvirtComputingResource.getTimeout()).thenReturn(timeout);
+        when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
 
         final String ovsPvlanVmPath = "/pvlan";
         when(libvirtComputingResource.getOvsPvlanVmPath()).thenReturn(ovsPvlanVmPath);
@@ -4343,8 +4343,7 @@ public class LibvirtComputingResourceTest {
         final String guestBridgeName = "br0";
         when(libvirtComputingResource.getGuestBridgeName()).thenReturn(guestBridgeName);
 
-        final int timeout = 0;
-        when(libvirtComputingResource.getTimeout()).thenReturn(timeout);
+        when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
         final String ovsPvlanDhcpHostPath = "/pvlan";
         when(libvirtComputingResource.getOvsPvlanDhcpHostPath()).thenReturn(ovsPvlanDhcpHostPath);
         when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
@@ -4385,8 +4384,7 @@ public class LibvirtComputingResourceTest {
         final String guestBridgeName = "br0";
         when(libvirtComputingResource.getGuestBridgeName()).thenReturn(guestBridgeName);
 
-        final int timeout = 0;
-        when(libvirtComputingResource.getTimeout()).thenReturn(timeout);
+        when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
         final String ovsPvlanDhcpHostPath = "/pvlan";
         when(libvirtComputingResource.getOvsPvlanDhcpHostPath()).thenReturn(ovsPvlanDhcpHostPath);
         when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83b5a8b2/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3VirtualRoutingResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3VirtualRoutingResource.java
b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3VirtualRoutingResource.java
index 46c6076..f99169d 100644
--- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3VirtualRoutingResource.java
+++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3VirtualRoutingResource.java
@@ -17,6 +17,8 @@
 
 package com.cloud.hypervisor.ovm3.resources;
 
+import org.joda.time.Duration;
+
 import javax.ejb.Local;
 
 import org.apache.log4j.Logger;
@@ -27,6 +29,7 @@ import com.cloud.agent.api.routing.IpAssocVpcCommand;
 import com.cloud.agent.api.routing.NetworkElementCommand;
 import com.cloud.agent.api.routing.SetSourceNatCommand;
 import com.cloud.agent.api.to.IpAddressTO;
+import com.cloud.agent.resource.virtualnetwork.VRScripts;
 import com.cloud.agent.resource.virtualnetwork.VirtualRouterDeployer;
 import com.cloud.hypervisor.ovm3.objects.CloudstackPlugin;
 import com.cloud.hypervisor.ovm3.objects.Connection;
@@ -38,7 +41,6 @@ public class Ovm3VirtualRoutingResource implements VirtualRouterDeployer
{
     private final Logger logger = Logger
             .getLogger(Ovm3VirtualRoutingResource.class);
     private String domRCloudPath = "/opt/cloud/bin/";
-    private int vrTimeout = 600;
     private Connection c;
     private String agentName;
     public Ovm3VirtualRoutingResource() {
@@ -53,12 +55,12 @@ public class Ovm3VirtualRoutingResource implements VirtualRouterDeployer
{
     @Override
     public ExecutionResult executeInVR(String routerIp, String script,
             String args) {
-        return executeInVR(routerIp, script, args, vrTimeout);
+        return executeInVR(routerIp, script, args, VRScripts.VR_SCRIPT_EXEC_TIMEOUT);
     }
 
     @Override
     public ExecutionResult executeInVR(String routerIp, String script,
-            String args, int timeout) {
+            String args, Duration timeout) {
         if (!script.contains(domRCloudPath)) {
             script = domRCloudPath + "/" + script;
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83b5a8b2/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index fdbc244..f56ffff 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -24,6 +24,7 @@ import java.net.InetSocketAddress;
 import java.net.URI;
 import java.nio.channels.SocketChannel;
 import java.rmi.RemoteException;
+import org.joda.time.Duration;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -210,6 +211,7 @@ import com.cloud.agent.api.to.NicTO;
 import com.cloud.agent.api.to.StorageFilerTO;
 import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.agent.api.to.VolumeTO;
+import com.cloud.agent.resource.virtualnetwork.VRScripts;
 import com.cloud.agent.resource.virtualnetwork.VirtualRouterDeployer;
 import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource;
 import com.cloud.dc.DataCenter.NetworkType;
@@ -1197,11 +1199,11 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
 
     @Override
     public ExecutionResult executeInVR(String routerIP, String script, String args) {
-        return executeInVR(routerIP, script, args, 120);
+        return executeInVR(routerIP, script, args, VRScripts.VR_SCRIPT_EXEC_TIMEOUT);
     }
 
     @Override
-    public ExecutionResult executeInVR(String routerIP, String script, String args, int timeout)
{
+    public ExecutionResult executeInVR(String routerIP, String script, String args, Duration
timeout) {
         Pair<Boolean, String> result;
 
         //TODO: Password should be masked, cannot output to log directly
@@ -1212,7 +1214,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
         try {
             VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
             result = SshHelper.sshExecute(routerIP, DefaultDomRSshPort, "root", mgr.getSystemVMKeyFile(),
null, "/opt/cloud/bin/" + script + " " + args,
-                    60000, 60000, timeout * 1000);
+                    VRScripts.CONNECTION_TIMEOUT, VRScripts.CONNECTION_TIMEOUT, timeout);
         } catch (Exception e) {
             String msg = "Command failed due to " + VmwareHelper.getExceptionMessage(e);
             s_logger.error(msg);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83b5a8b2/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
index 7c8bca7..ed86f75 100644
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
@@ -29,6 +29,7 @@ import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.nio.charset.Charset;
+import org.joda.time.Duration;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -97,6 +98,7 @@ import com.cloud.agent.api.to.IpAddressTO;
 import com.cloud.agent.api.to.NfsTO;
 import com.cloud.agent.api.to.NicTO;
 import com.cloud.agent.api.to.VirtualMachineTO;
+import com.cloud.agent.resource.virtualnetwork.VRScripts;
 import com.cloud.agent.resource.virtualnetwork.VirtualRouterDeployer;
 import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource;
 import com.cloud.exception.InternalErrorException;
@@ -1652,18 +1654,18 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
     @Override
     public ExecutionResult executeInVR(final String routerIP, final String script, final
String args) {
         // Timeout is 120 seconds by default
-        return executeInVR(routerIP, script, args, 120);
+        return executeInVR(routerIP, script, args, VRScripts.VR_SCRIPT_EXEC_TIMEOUT);
     }
 
     @Override
-    public ExecutionResult executeInVR(final String routerIP, final String script, final
String args, final int timeout) {
+    public ExecutionResult executeInVR(final String routerIP, final String script, final
String args, final Duration timeout) {
         Pair<Boolean, String> result;
         String cmdline = "/opt/cloud/bin/router_proxy.sh " + script + " " + routerIP + "
" + args;
         // semicolon need to be escape for bash
         cmdline = cmdline.replaceAll(";", "\\\\;");
         try {
             s_logger.debug("Executing command in VR: " + cmdline);
-            result = SshHelper.sshExecute(_host.getIp(), 22, _username, null, _password.peek(),
cmdline, 60000, 60000, timeout * 1000);
+            result = SshHelper.sshExecute(_host.getIp(), 22, _username, null, _password.peek(),
cmdline, VRScripts.CONNECTION_TIMEOUT, VRScripts.CONNECTION_TIMEOUT, timeout);
         } catch (final Exception e) {
             return new ExecutionResult(false, e.getMessage());
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83b5a8b2/utils/src/main/java/com/cloud/utils/script/Script.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/script/Script.java b/utils/src/main/java/com/cloud/utils/script/Script.java
index b8cb4fe..7608475 100644
--- a/utils/src/main/java/com/cloud/utils/script/Script.java
+++ b/utils/src/main/java/com/cloud/utils/script/Script.java
@@ -39,6 +39,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.log4j.Logger;
+import org.joda.time.Duration;
 
 import com.cloud.utils.PropertiesUtil;
 import com.cloud.utils.concurrency.NamedThreadFactory;
@@ -64,10 +65,15 @@ public class Script implements Callable<String> {
     Process _process;
     Thread _thread;
 
-    public int getExitValue()  {
+    public int getExitValue() {
         return _process.exitValue();
     }
 
+    public Script(String command, Duration timeout, Logger logger) {
+        this(command, timeout.getMillis(), logger);
+    }
+
+    @Deprecated
     public Script(String command, long timeout, Logger logger) {
         _command = new ArrayList<String>();
         _command.add(command);
@@ -80,6 +86,11 @@ public class Script implements Callable<String> {
         _logger = logger != null ? logger : s_logger;
     }
 
+    public Script(boolean runWithSudo, String command, Duration timeout, Logger logger) {
+        this(runWithSudo, command, timeout.getMillis(), logger);
+    }
+
+    @Deprecated
     public Script(boolean runWithSudo, String command, long timeout, Logger logger) {
         this(command, timeout, logger);
         if (runWithSudo) {
@@ -95,6 +106,11 @@ public class Script implements Callable<String> {
         this(command, 0, s_logger);
     }
 
+    public Script(String command, Duration timeout) {
+        this(command, timeout.getMillis(), s_logger);
+    }
+
+    @Deprecated
     public Script(String command, long timeout) {
         this(command, timeout, s_logger);
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83b5a8b2/utils/src/main/java/com/cloud/utils/ssh/SshHelper.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/ssh/SshHelper.java b/utils/src/main/java/com/cloud/utils/ssh/SshHelper.java
index d3c88c8..8889016 100644
--- a/utils/src/main/java/com/cloud/utils/ssh/SshHelper.java
+++ b/utils/src/main/java/com/cloud/utils/ssh/SshHelper.java
@@ -23,6 +23,7 @@ import java.io.File;
 import java.io.InputStream;
 
 import org.apache.log4j.Logger;
+import org.joda.time.Duration;
 
 import com.trilead.ssh2.ChannelCondition;
 
@@ -122,8 +123,13 @@ public class SshHelper {
         }
     }
 
-    public static Pair<Boolean, String> sshExecute(String host, int port, String user,
File pemKeyFile, String password, String command, int connectTimeoutInMs,
-        int kexTimeoutInMs, int waitResultTimeoutInMs) throws Exception {
+    public static Pair<Boolean, String> sshExecute(String host, int port, String user,
File pemKeyFile, String password, String command, Duration connectTimeout,
+            Duration kexTimeout, Duration waitTime) throws Exception {
+        return sshExecute(host, port, user, pemKeyFile, password, command, (int)connectTimeout.getMillis(),
(int)kexTimeout.getMillis(), (int)waitTime.getMillis());
+    }
+
+    public static Pair<Boolean, String> sshExecute(String host, int port, String user,
File pemKeyFile, String password, String command, int connectTimeoutInMs, int kexTimeoutInMs,
+            int waitResultTimeoutInMs) throws Exception {
 
         com.trilead.ssh2.Connection conn = null;
         com.trilead.ssh2.Session sess = null;


Mime
View raw message