cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [06/39] git commit: updated refs/heads/master to 3e28747
Date Thu, 02 Apr 2015 18:22:47 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/30e72e4a/plugins/hypervisors/xenserver/src/org/apache/cloudstack/hypervisor/xenserver/XenServerResourceNewBase.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/org/apache/cloudstack/hypervisor/xenserver/XenServerResourceNewBase.java
b/plugins/hypervisors/xenserver/src/org/apache/cloudstack/hypervisor/xenserver/XenServerResourceNewBase.java
index 161a7b2..4971eb3 100644
--- a/plugins/hypervisors/xenserver/src/org/apache/cloudstack/hypervisor/xenserver/XenServerResourceNewBase.java
+++ b/plugins/hypervisors/xenserver/src/org/apache/cloudstack/hypervisor/xenserver/XenServerResourceNewBase.java
@@ -25,6 +25,11 @@ import java.util.concurrent.TimeoutException;
 import org.apache.log4j.Logger;
 import org.apache.xmlrpc.XmlRpcException;
 
+import com.cloud.agent.api.StartupCommand;
+import com.cloud.hypervisor.xenserver.resource.XenServer620SP1Resource;
+import com.cloud.utils.Pair;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VirtualMachine;
 import com.xensource.xenapi.Connection;
 import com.xensource.xenapi.Event;
 import com.xensource.xenapi.EventBatch;
@@ -35,12 +40,6 @@ import com.xensource.xenapi.Types;
 import com.xensource.xenapi.Types.XenAPIException;
 import com.xensource.xenapi.VM;
 
-import com.cloud.agent.api.StartupCommand;
-import com.cloud.hypervisor.xenserver.resource.XenServer620SP1Resource;
-import com.cloud.utils.Pair;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.vm.VirtualMachine;
-
 /**
  *
  * XenServerResourceNewBase is an abstract base class that encapsulates how
@@ -67,16 +66,16 @@ public class XenServerResourceNewBase extends XenServer620SP1Resource
{
 
     @Override
     public StartupCommand[] initialize() throws IllegalArgumentException {
-        StartupCommand[] cmds = super.initialize();
+        final StartupCommand[] cmds = super.initialize();
 
-        Connection conn = getConnection();
+        final Connection conn = getConnection();
         Pool pool;
         try {
-            pool = Pool.getByUuid(conn, _host.pool);
-            Pool.Record poolr = pool.getRecord(conn);
+            pool = Pool.getByUuid(conn, _host.getPool());
+            final Pool.Record poolr = pool.getRecord(conn);
 
-            Host.Record masterRecord = poolr.master.getRecord(conn);
-            if (_host.uuid.equals(masterRecord.uuid)) {
+            final Host.Record masterRecord = poolr.master.getRecord(conn);
+            if (_host.getUuid().equals(masterRecord.uuid)) {
                 _listener = new VmEventListener(true);
 
                 //
@@ -87,36 +86,37 @@ public class XenServerResourceNewBase extends XenServer620SP1Resource
{
             } else {
                 _listener = new VmEventListener(false);
             }
-        } catch (XenAPIException e) {
+        } catch (final XenAPIException e) {
             throw new CloudRuntimeException("Unable to determine who is the master", e);
-        } catch (XmlRpcException e) {
+        } catch (final XmlRpcException e) {
             throw new CloudRuntimeException("Unable to determine who is the master", e);
         }
         return cmds;
     }
 
-    protected void waitForTask2(Connection c, Task task, long pollInterval, long timeout)
throws XenAPIException, XmlRpcException, TimeoutException {
-        long beginTime = System.currentTimeMillis();
+    protected void waitForTask2(final Connection c, final Task task, final long pollInterval,
final long timeout) throws XenAPIException, XmlRpcException, TimeoutException {
+        final long beginTime = System.currentTimeMillis();
         if (s_logger.isTraceEnabled()) {
             s_logger.trace("Task " + task.getNameLabel(c) + " (" + task.getType(c) + ") sent
to " + c.getSessionReference() + " is pending completion with a " + timeout +
-                           "ms timeout");
+                    "ms timeout");
         }
-        Set<String> classes = new HashSet<String>();
+        final Set<String> classes = new HashSet<String>();
         classes.add("Task/" + task.toWireString());
         String token = "";
-        Double t = new Double(timeout / 1000);
+        final Double t = new Double(timeout / 1000);
         while (true) {
-            EventBatch map = Event.from(c, classes, token, t);
+            final EventBatch map = Event.from(c, classes, token, t);
             token = map.token;
             @SuppressWarnings("unchecked")
+            final
             Set<Event.Record> events = map.events;
             if (events.size() == 0) {
-                String msg = "No event for task " + task.toWireString();
+                final String msg = "No event for task " + task.toWireString();
                 s_logger.warn(msg);
                 task.cancel(c);
                 throw new TimeoutException(msg);
             }
-            for (Event.Record rec : events) {
+            for (final Event.Record rec : events) {
                 if (!(rec.snapshot instanceof Task.Record)) {
                     if (s_logger.isDebugEnabled()) {
                         s_logger.debug("Skipping over " + rec);
@@ -124,7 +124,7 @@ public class XenServerResourceNewBase extends XenServer620SP1Resource
{
                     continue;
                 }
 
-                Task.Record taskRecord = (Task.Record)rec.snapshot;
+                final Task.Record taskRecord = (Task.Record)rec.snapshot;
 
                 if (taskRecord.status != Types.TaskStatusType.PENDING) {
                     if (s_logger.isDebugEnabled()) {
@@ -139,7 +139,7 @@ public class XenServerResourceNewBase extends XenServer620SP1Resource
{
                 }
             }
             if (System.currentTimeMillis() - beginTime > timeout) {
-                String msg = "Async " + timeout / 1000 + " seconds timeout for task " + task.toString();
+                final String msg = "Async " + timeout / 1000 + " seconds timeout for task
" + task.toString();
                 s_logger.warn(msg);
                 task.cancel(c);
                 throw new TimeoutException(msg);
@@ -155,7 +155,7 @@ public class XenServerResourceNewBase extends XenServer620SP1Resource
{
         Set<String> _classes;
         String _token = "";
 
-        public VmEventListener(boolean isMaster) {
+        public VmEventListener(final boolean isMaster) {
             _isMaster = isMaster;
             _classes = new HashSet<String>();
             _classes.add("VM");
@@ -163,22 +163,23 @@ public class XenServerResourceNewBase extends XenServer620SP1Resource
{
 
         @Override
         public void run() {
-            setName("XS-Listener-" + _host.ip);
+            setName("XS-Listener-" + _host.getIp());
             while (!_stop) {
                 try {
-                    Connection conn = getConnection();
+                    final Connection conn = getConnection();
                     EventBatch results;
                     try {
                         results = Event.from(conn, _classes, _token, new Double(30));
-                    } catch (Exception e) {
+                    } catch (final Exception e) {
                         s_logger.error("Retrying the waiting on VM events due to: ", e);
                         continue;
                     }
 
                     _token = results.token;
                     @SuppressWarnings("unchecked")
+                    final
                     Set<Event.Record> events = results.events;
-                    for (Event.Record event : events) {
+                    for (final Event.Record event : events) {
                         try {
                             if (!(event.snapshot instanceof VM.Record)) {
                                 if (s_logger.isDebugEnabled()) {
@@ -186,24 +187,24 @@ public class XenServerResourceNewBase extends XenServer620SP1Resource
{
                                 }
                                 continue;
                             }
-                            VM.Record vm = (VM.Record)event.snapshot;
+                            final VM.Record vm = (VM.Record)event.snapshot;
 
                             String hostUuid = null;
                             if (vm.residentOn != null && !vm.residentOn.toWireString().contains("OpaqueRef:NULL"))
{
                                 hostUuid = vm.residentOn.getUuid(conn);
                             }
                             recordChanges(conn, vm, hostUuid);
-                        } catch (Exception e) {
+                        } catch (final Exception e) {
                             s_logger.error("Skipping over " + event, e);
                         }
                     }
-                } catch (Throwable th) {
+                } catch (final Throwable th) {
                     s_logger.error("Exception caught in eventlistener thread: ", th);
                 }
             }
         }
 
-        protected void recordChanges(Connection conn, VM.Record rec, String hostUuid) {
+        protected void recordChanges(final Connection conn, final VM.Record rec, final String
hostUuid) {
 
         }
 
@@ -211,16 +212,16 @@ public class XenServerResourceNewBase extends XenServer620SP1Resource
{
         public void start() {
             if (_isMaster) {
                 // Throw away the initial set of events because they're history
-                Connection conn = getConnection();
+                final Connection conn = getConnection();
                 EventBatch results;
                 try {
                     results = Event.from(conn, _classes, _token, new Double(30));
-                } catch (Exception e) {
+                } catch (final Exception e) {
                     s_logger.error("Retrying the waiting on VM events due to: ", e);
                     throw new CloudRuntimeException("Unable to start a listener thread to
listen to VM events", e);
                 }
                 _token = results.token;
-                s_logger.debug("Starting the event listener thread for " + _host.uuid);
+                s_logger.debug("Starting the event listener thread for " + _host.getUuid());
                 super.start();
             }
         }
@@ -234,7 +235,7 @@ public class XenServerResourceNewBase extends XenServer620SP1Resource
{
                 if (_changes.size() == 0) {
                     return null;
                 }
-                HashMap<String, Pair<String, VirtualMachine.State>> diff = _changes;
+                final HashMap<String, Pair<String, VirtualMachine.State>> diff
= _changes;
                 _changes = new HashMap<String, Pair<String, VirtualMachine.State>>();
                 return diff;
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/30e72e4a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/CitrixResourceBaseTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/CitrixResourceBaseTest.java
b/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/CitrixResourceBaseTest.java
index 0c2944c..e79e8af 100644
--- a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/CitrixResourceBaseTest.java
+++ b/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/CitrixResourceBaseTest.java
@@ -39,6 +39,10 @@ import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.mockito.Spy;
 
+import com.cloud.agent.api.ScaleVmAnswer;
+import com.cloud.agent.api.ScaleVmCommand;
+import com.cloud.agent.api.to.IpAddressTO;
+import com.cloud.agent.api.to.VirtualMachineTO;
 import com.xensource.xenapi.Connection;
 import com.xensource.xenapi.Host;
 import com.xensource.xenapi.Types;
@@ -46,35 +50,29 @@ import com.xensource.xenapi.VIF;
 import com.xensource.xenapi.VM;
 import com.xensource.xenapi.XenAPIObject;
 
-import com.cloud.agent.api.ScaleVmAnswer;
-import com.cloud.agent.api.ScaleVmCommand;
-import com.cloud.agent.api.to.IpAddressTO;
-import com.cloud.agent.api.to.VirtualMachineTO;
-import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase.XsHost;
-
 public class CitrixResourceBaseTest {
 
     @Spy
     CitrixResourceBase _resource = new CitrixResourceBase() {
 
         @Override
-        public ScaleVmAnswer execute(ScaleVmCommand cmd) {
+        public ScaleVmAnswer execute(final ScaleVmCommand cmd) {
             return super.execute(cmd);
         }
 
         @Override
-        public String callHostPlugin(Connection conn, String plugin, String cmd, String...
params) {
+        public String callHostPlugin(final Connection conn, final String plugin, final String
cmd, final String... params) {
             return "Success";
         }
 
         @Override
-        protected void scaleVM(Connection conn, VM vm, VirtualMachineTO vmSpec, Host host)
throws Types.XenAPIException, XmlRpcException {
-            _host.speed = 500;
+        protected void scaleVM(final Connection conn, final VM vm, final VirtualMachineTO
vmSpec, final Host host) throws Types.XenAPIException, XmlRpcException {
+            _host.setSpeed(500);
             super.scaleVM(conn, vm, vmSpec, host);
         }
 
         @Override
-        protected boolean isDmcEnabled(Connection conn, Host host) throws Types.XenAPIException,
XmlRpcException {
+        protected boolean isDmcEnabled(final Connection conn, final Host host) throws Types.XenAPIException,
XmlRpcException {
             return true;
         }
     };
@@ -105,18 +103,18 @@ public class CitrixResourceBaseTest {
     @Test(expected = XmlRpcException.class)
     public void testScaleVMF1() throws Types.BadServerResponse, Types.XenAPIException, XmlRpcException
{
         doReturn(conn).when(_resource).getConnection();
-        Set<VM> vms = mock(Set.class);
+        final Set<VM> vms = mock(Set.class);
 
-        Iterator iter = mock(Iterator.class);
+        final Iterator iter = mock(Iterator.class);
         doReturn(iter).when(vms).iterator();
         when(iter.hasNext()).thenReturn(true).thenReturn(false);
         doReturn(vm).when(iter).next();
-        VM.Record vmr = mock(VM.Record.class);
+        final VM.Record vmr = mock(VM.Record.class);
         when(vm.getRecord(conn)).thenThrow(new XmlRpcException("XmlRpcException"));
         when(vm.getRecord(conn)).thenReturn(vmr);
         vmr.powerState = Types.VmPowerState.RUNNING;
         vmr.residentOn = mock(Host.class);
-        XenAPIObject object = mock(XenAPIObject.class);
+        final XenAPIObject object = mock(XenAPIObject.class);
         doReturn(new String("OpaqueRef:NULL")).when(object).toWireString();
         doNothing().when(_resource).scaleVM(conn, vm, vmSpec, host);
 
@@ -139,7 +137,7 @@ public class CitrixResourceBaseTest {
         doNothing().when(vm).setVCPUsNumberLive(conn, 1L);
         doReturn(500).when(vmSpec).getMinSpeed();
         doReturn(false).when(vmSpec).getLimitCpuUse();
-        Map<String, String> args = mock(HashMap.class);
+        final Map<String, String> args = mock(HashMap.class);
         when(host.callPlugin(conn, "vmops", "add_to_VCPUs_params_live", args)).thenReturn("Success");
         doReturn(null).when(_resource).callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live",
"key", "weight", "value", "253", "vmname", "i-2-3-VM");
 
@@ -164,7 +162,7 @@ public class CitrixResourceBaseTest {
         doReturn(500).when(vmSpec).getMaxSpeed();
         doReturn(true).when(vmSpec).getLimitCpuUse();
         doReturn(null).when(_resource).callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live",
"key", "cap", "value", "99", "vmname", "i-2-3-VM");
-        Map<String, String> args = mock(HashMap.class);
+        final Map<String, String> args = mock(HashMap.class);
         when(host.callPlugin(conn, "vmops", "add_to_VCPUs_params_live", args)).thenReturn("Success");
         doReturn(null).when(_resource).callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live",
"key", "weight", "value", "253", "vmname", "i-2-3-VM");
 
@@ -178,12 +176,12 @@ public class CitrixResourceBaseTest {
 
     @Test
     public void testSetNicDevIdIfCorrectVifIsNotNull() throws Exception {
-        IpAddressTO ip = mock(IpAddressTO.class);
+        final IpAddressTO ip = mock(IpAddressTO.class);
         when(ip.isAdd()).thenReturn(false);
-        VIF correctVif = null;
+        final VIF correctVif = null;
         try {
             _resource.setNicDevIdIfCorrectVifIsNotNull(conn, ip, correctVif);
-        } catch (NullPointerException e) {
+        } catch (final NullPointerException e) {
             fail("this test is meant to show that null pointer is not thrown");
         }
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/30e72e4a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapperTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapperTest.java
b/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapperTest.java
index f8af543..3e7fb57 100644
--- a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapperTest.java
+++ b/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapperTest.java
@@ -14,6 +14,7 @@ import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 
 import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.ReadyCommand;
 import com.cloud.agent.api.RebootAnswer;
 import com.cloud.agent.api.RebootCommand;
 import com.cloud.agent.api.RebootRouterCommand;
@@ -96,4 +97,16 @@ public class CitrixRequestWrapperTest {
 
         assertFalse(answer.getResult());
     }
+
+    @Test
+    public void testReadyCommandCommand() {
+        final ReadyCommand readyCommand = new ReadyCommand();
+
+        final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
+        assertNotNull(wrapper);
+
+        final Answer answer = wrapper.execute(readyCommand, citrixResourceBase);
+
+        assertFalse(answer.getResult());
+    }
 }
\ No newline at end of file


Mime
View raw message