cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [18/39] git commit: updated refs/heads/master to 3e28747
Date Thu, 02 Apr 2015 18:22:59 GMT
Refactoring the CitrixRebootCommand in order to have the new design applied
  - Added basic tests
  - Changed the way RebootCommand gets called from RebootRouterCommand
  - Made a couple of methods public in the CitrixResourceBase and its subclasses


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

Branch: refs/heads/master
Commit: f2fab5c8c367c73463320375a56d55abbe0c4a61
Parents: 9e41b80
Author: wilderrodrigues <wrodrigues@schubergphilis.com>
Authored: Tue Mar 24 11:39:29 2015 +0100
Committer: wilderrodrigues <wrodrigues@schubergphilis.com>
Committed: Tue Mar 31 10:38:27 2015 +0200

----------------------------------------------------------------------
 .../xenserver/resource/CitrixResourceBase.java  |  2 +-
 .../xenserver/resource/XenServer56Resource.java |  2 +-
 .../resource/XenServer620SP1Resource.java       |  2 +-
 .../wrapper/CitrixRebootCommandWrapper.java     | 68 ++++++++++++++++++++
 .../CitrixRebootRouterCommandWrapper.java       |  6 +-
 .../resource/wrapper/CitrixRequestWrapper.java  |  2 +
 .../wrapper/CitrixRequestWrapperTest.java       | 16 ++---
 7 files changed, 81 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f2fab5c8/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 7c80f64..7882b0e 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
@@ -3228,7 +3228,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
         }
     }
 
-    void rebootVM(final Connection conn, final VM vm, final String vmName) throws Exception
{
+    public void rebootVM(final Connection conn, final VM vm, final String vmName) throws
Exception {
         Task task = null;
         try {
             task = vm.cleanRebootAsync(conn);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f2fab5c8/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56Resource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56Resource.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56Resource.java
index 1de7b96..1bb2ff4 100644
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56Resource.java
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56Resource.java
@@ -80,7 +80,7 @@ public class XenServer56Resource extends CitrixResourceBase {
     }
 
     @Override
-    protected void disableVlanNetwork(final Connection conn, final Network network) {
+    public void disableVlanNetwork(final Connection conn, final Network network) {
         try {
             final Network.Record networkr = network.getRecord(conn);
             if (!networkr.nameLabel.startsWith("VLAN")) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f2fab5c8/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer620SP1Resource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer620SP1Resource.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer620SP1Resource.java
index ac2b2a6..e6c66a4 100644
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer620SP1Resource.java
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer620SP1Resource.java
@@ -94,7 +94,7 @@ public class XenServer620SP1Resource extends XenServer620Resource {
     }
 
     @Override
-    protected HashMap<String, HashMap<String, VgpuTypesInfo>> getGPUGroupDetails(final
Connection conn) throws XenAPIException, XmlRpcException {
+    public HashMap<String, HashMap<String, VgpuTypesInfo>> getGPUGroupDetails(final
Connection conn) throws XenAPIException, XmlRpcException {
         final HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails =
new HashMap<String, HashMap<String, VgpuTypesInfo>>();
         final Host host = Host.getByUuid(conn, _host.getUuid());
         final Set<PGPU> pgpus = host.getPGPUs(conn);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f2fab5c8/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRebootCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRebootCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRebootCommandWrapper.java
new file mode 100644
index 0000000..f2cb54c
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRebootCommandWrapper.java
@@ -0,0 +1,68 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.hypervisor.xenserver.resource.wrapper;
+
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.RebootAnswer;
+import com.cloud.agent.api.RebootCommand;
+import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
+import com.cloud.resource.CommandWrapper;
+import com.xensource.xenapi.Connection;
+import com.xensource.xenapi.Types.XenAPIException;
+import com.xensource.xenapi.VM;
+
+public final class CitrixRebootCommandWrapper extends CommandWrapper<RebootCommand, Answer,
CitrixResourceBase> {
+
+    private static final Logger s_logger = Logger.getLogger(CitrixRebootCommandWrapper.class);
+
+    @Override
+    public Answer execute(final RebootCommand command, final CitrixResourceBase citrixResourceBase)
{
+        final Connection conn = citrixResourceBase.getConnection();
+        s_logger.debug("7. The VM " + command.getVmName() + " is in Starting state");
+        try {
+            Set<VM> vms = null;
+            try {
+                vms = VM.getByNameLabel(conn, command.getVmName());
+            } catch (final XenAPIException e0) {
+                s_logger.debug("getByNameLabel failed " + e0.toString());
+                return new RebootAnswer(command, "getByNameLabel failed " + e0.toString(),
false);
+            } catch (final Exception e0) {
+                s_logger.debug("getByNameLabel failed " + e0.getMessage());
+                return new RebootAnswer(command, "getByNameLabel failed", false);
+            }
+            for (final VM vm : vms) {
+                try {
+                    citrixResourceBase.rebootVM(conn, vm, vm.getNameLabel(conn));
+                } catch (final Exception e) {
+                    final String msg = e.toString();
+                    s_logger.warn(msg, e);
+                    return new RebootAnswer(command, msg, false);
+                }
+            }
+            return new RebootAnswer(command, "reboot succeeded", true);
+        } finally {
+            s_logger.debug("8. The VM " + command.getVmName() + " is in Running state");
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f2fab5c8/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRebootRouterCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRebootRouterCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRebootRouterCommandWrapper.java
index c244335..5d860b9 100644
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRebootRouterCommandWrapper.java
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRebootRouterCommandWrapper.java
@@ -20,7 +20,6 @@
 package com.cloud.hypervisor.xenserver.resource.wrapper;
 
 import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.RebootAnswer;
 import com.cloud.agent.api.RebootCommand;
 import com.cloud.agent.api.RebootRouterCommand;
 import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
@@ -33,7 +32,10 @@ public final class CitrixRebootRouterCommandWrapper extends CommandWrapper<Reboo
     public Answer execute(final RebootRouterCommand command, final CitrixResourceBase citrixResourceBase)
{
         final Connection conn = citrixResourceBase.getConnection();
 
-        final RebootAnswer answer = citrixResourceBase.execute((RebootCommand)command);
+        final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
+
+        final RebootCommand rebootCommand = new RebootCommand(command.getVmName());
+        final Answer answer = wrapper.execute(rebootCommand, citrixResourceBase);
 
         if (answer.getResult()) {
             final String cnct = citrixResourceBase.connect(conn, command.getVmName(), command.getPrivateIpAddress());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f2fab5c8/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapper.java
index 5e3e6e4..f83218b 100644
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapper.java
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapper.java
@@ -28,6 +28,7 @@ import com.cloud.agent.api.GetHostStatsCommand;
 import com.cloud.agent.api.GetVmDiskStatsCommand;
 import com.cloud.agent.api.GetVmStatsCommand;
 import com.cloud.agent.api.ReadyCommand;
+import com.cloud.agent.api.RebootCommand;
 import com.cloud.agent.api.RebootRouterCommand;
 import com.cloud.agent.api.StopCommand;
 import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
@@ -65,6 +66,7 @@ public class CitrixRequestWrapper extends RequestWrapper {
         map.put(GetVmDiskStatsCommand.class, new CitrixGetVmDiskStatsCommandWrapper());
         map.put(CheckHealthCommand.class, new CitrixCheckHealthCommandWrapper());
         map.put(StopCommand.class, new CitrixStopCommandWrapper());
+        map.put(RebootCommand.class, new CitrixRebootCommandWrapper());
     }
 
     public static CitrixRequestWrapper getInstance() {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f2fab5c8/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 74f7cdc..98023f7 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
@@ -1,10 +1,8 @@
 package com.cloud.hypervisor.xenserver.resource.wrapper;
 
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
@@ -24,7 +22,6 @@ import com.cloud.agent.api.GetVmDiskStatsCommand;
 import com.cloud.agent.api.GetVmStatsCommand;
 import com.cloud.agent.api.ReadyCommand;
 import com.cloud.agent.api.RebootAnswer;
-import com.cloud.agent.api.RebootCommand;
 import com.cloud.agent.api.RebootRouterCommand;
 import com.cloud.agent.api.StopCommand;
 import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
@@ -64,21 +61,16 @@ public class CitrixRequestWrapperTest {
 
     @Test
     public void testExecuteRebootRouterCommand() {
-        final RebootRouterCommand rebootCommand = new RebootRouterCommand("", "");
+        final RebootRouterCommand rebootRouterCommand = new RebootRouterCommand("Test", "127.0.0.1");
 
         final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
         assertNotNull(wrapper);
 
-        doReturn(rebootAnswer).when(citrixResourceBase).execute((RebootCommand)rebootCommand);
-        doReturn(false).when(rebootAnswer).getResult();
+        final Answer answer = wrapper.execute(rebootRouterCommand, citrixResourceBase);
 
-        final Answer answer = wrapper.execute(rebootCommand, citrixResourceBase);
+        verify(citrixResourceBase, times(2)).getConnection();
 
-        verify(citrixResourceBase, times(1)).getConnection();
-        verify(citrixResourceBase, times(1)).execute((RebootCommand)rebootCommand);
-
-        assertFalse(rebootAnswer.getResult());
-        assertEquals(answer, rebootAnswer);
+        assertFalse(answer.getResult());
     }
 
     @Test


Mime
View raw message