cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [23/39] git commit: updated refs/heads/master to 3e28747
Date Thu, 02 Apr 2015 18:23:04 GMT
Refactoring GetStorageStatsCommand and PrimaryStorageDownloadCommand to cope with the new design
Fix the NPE in the constructor that was never used
  - Basic tests added for all changes


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

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

----------------------------------------------------------------------
 .../api/storage/AbstractDownloadCommand.java    | 18 ++---
 .../storage/PrimaryStorageDownloadCommand.java  | 25 ++----
 .../xenserver/resource/CitrixResourceBase.java  | 14 +---
 .../CitrixGetStorageStatsCommandWrapper.java    | 69 ++++++++++++++++
 ...rixPrimaryStorageDownloadCommandWrapper.java | 83 ++++++++++++++++++++
 .../resource/wrapper/CitrixRequestWrapper.java  |  4 +
 .../wrapper/CitrixRequestWrapperTest.java       | 40 ++++++++++
 7 files changed, 217 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11d03368/core/src/com/cloud/agent/api/storage/AbstractDownloadCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/storage/AbstractDownloadCommand.java b/core/src/com/cloud/agent/api/storage/AbstractDownloadCommand.java
index 0bde5e3..0670eef 100644
--- a/core/src/com/cloud/agent/api/storage/AbstractDownloadCommand.java
+++ b/core/src/com/cloud/agent/api/storage/AbstractDownloadCommand.java
@@ -31,8 +31,8 @@ public abstract class AbstractDownloadCommand extends SsCommand {
     protected AbstractDownloadCommand() {
     }
 
-    protected AbstractDownloadCommand(String name, String url, ImageFormat format, Long accountId)
{
-        assert (url != null);
+    protected AbstractDownloadCommand(final String name, String url, final ImageFormat format,
final Long accountId) {
+        assert url != null;
         url = url.replace('\\', '/');
 
         this.url = url;
@@ -41,14 +41,14 @@ public abstract class AbstractDownloadCommand extends SsCommand {
         this.name = name;
     }
 
-    protected AbstractDownloadCommand(AbstractDownloadCommand that) {
+    protected AbstractDownloadCommand(final AbstractDownloadCommand that) {
         super(that);
-        assert (that.url != null);
+        assert that.url != null;
 
-        this.url = that.url.replace('\\', '/');
-        this.format = that.format;
-        this.accountId = that.accountId;
-        this.name = that.name;
+        url = that.url.replace('\\', '/');
+        format = that.format;
+        accountId = that.accountId;
+        name = that.name;
     }
 
     public String getUrl() {
@@ -73,7 +73,7 @@ public abstract class AbstractDownloadCommand extends SsCommand {
     }
 
     public void setUrl(String url) {
-        assert (url != null);
+        assert url != null;
         url = url.replace('\\', '/');
         this.url = url;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11d03368/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadCommand.java b/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadCommand.java
index f8b88c9..ce8ed21 100644
--- a/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadCommand.java
+++ b/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadCommand.java
@@ -37,22 +37,13 @@ public class PrimaryStorageDownloadCommand extends AbstractDownloadCommand
{
     String primaryStorageUrl;
 
     protected PrimaryStorageDownloadCommand() {
-
-    }
-
-    public PrimaryStorageDownloadCommand(String url, StoragePool pool, int wait) {
-        super(null, url, null, null);
-        this.poolId = pool.getId();
-        this.poolUuid = pool.getUuid();
-        this.primaryPool = new StorageFilerTO(pool);
-        setWait(wait);
     }
 
-    public PrimaryStorageDownloadCommand(String name, String url, ImageFormat format, long
accountId, StoragePool pool, int wait) {
+    public PrimaryStorageDownloadCommand(final String name, final String url, final ImageFormat
format, final long accountId, final StoragePool pool, final int wait) {
         super(name, url, format, accountId);
-        this.poolId = pool.getId();
-        this.poolUuid = pool.getUuid();
-        this.primaryPool = new StorageFilerTO(pool);
+        poolId = pool.getId();
+        poolUuid = pool.getUuid();
+        primaryPool = new StorageFilerTO(pool);
         setWait(wait);
     }
 
@@ -68,15 +59,15 @@ public class PrimaryStorageDownloadCommand extends AbstractDownloadCommand
{
         return primaryPool;
     }
 
-    public void setLocalPath(String path) {
-        this.localPath = path;
+    public void setLocalPath(final String path) {
+        localPath = path;
     }
 
     public String getLocalPath() {
         return localPath;
     }
 
-    public void setSecondaryStorageUrl(String url) {
+    public void setSecondaryStorageUrl(final String url) {
         secondaryStorageUrl = url;
     }
 
@@ -84,7 +75,7 @@ public class PrimaryStorageDownloadCommand extends AbstractDownloadCommand
{
         return secondaryStorageUrl;
     }
 
-    public void setPrimaryStorageUrl(String url) {
+    public void setPrimaryStorageUrl(final String url) {
         primaryStorageUrl = url;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11d03368/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 3c55a88..c412b54 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
@@ -441,12 +441,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
 
         if (cmd instanceof NetworkElementCommand) {
             return _vrResource.executeRequest((NetworkElementCommand)cmd);
-        } else if (clazz == AttachVolumeCommand.class) {
-            return execute((AttachVolumeCommand)cmd);
-        } else if (clazz == AttachIsoCommand.class) {
-            return execute((AttachIsoCommand) cmd);
-        } else if (clazz == UpgradeSnapshotCommand.class) {
-            return execute((UpgradeSnapshotCommand)cmd);
         } else if (clazz == GetStorageStatsCommand.class) {
             return execute((GetStorageStatsCommand)cmd);
         } else if (clazz == PrimaryStorageDownloadCommand.class) {
@@ -2751,7 +2745,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
         }
     }
 
-    String copy_vhd_from_secondarystorage(final Connection conn, final String mountpoint,
final String sruuid, final int wait) {
+    public String copyVhdFromSecondaryStorage(final Connection conn, final String mountpoint,
final String sruuid, final int wait) {
         final String nameLabel = "cloud-" + UUID.randomUUID().toString();
         final String results =
                 callHostPluginAsync(conn, "vmopspremium", "copy_vhd_from_secondarystorage",
wait, "mountpoint", mountpoint, "sruuid", sruuid, "namelabel", nameLabel);
@@ -2794,7 +2788,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
             }
             final String pUuid = poolsr.getUuid(conn);
             final boolean isISCSI = IsISCSI(poolsr.getType(conn));
-            final String uuid = copy_vhd_from_secondarystorage(conn, tmplpath, pUuid, wait);
+            final String uuid = copyVhdFromSecondaryStorage(conn, tmplpath, pUuid, wait);
             final VDI tmpl = getVDIbyUuid(conn, uuid);
             final VDI snapshotvdi = tmpl.snapshot(conn, new HashMap<String, String>());
             final String snapshotUuid = snapshotvdi.getUuid(conn);
@@ -6589,7 +6583,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
         }
     }
 
-    boolean IsISCSI(final String type) {
+    public boolean IsISCSI(final String type) {
         return SRType.LVMOHBA.equals(type) || SRType.LVMOISCSI.equals(type) || SRType.LVM.equals(type);
     }
 
@@ -6838,7 +6832,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
         return success;
     }
 
-    protected String getVhdParent(final Connection conn, final String primaryStorageSRUuid,
final String snapshotUuid, final Boolean isISCSI) {
+    public String getVhdParent(final Connection conn, final String primaryStorageSRUuid,
final String snapshotUuid, final Boolean isISCSI) {
         final String parentUuid =
                 callHostPlugin(conn, "vmopsSnapshot", "getVhdParent", "primaryStorageSRUuid",
primaryStorageSRUuid, "snapshotUuid", snapshotUuid, "isISCSI",
                         isISCSI.toString());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11d03368/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetStorageStatsCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetStorageStatsCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetStorageStatsCommandWrapper.java
new file mode 100644
index 0000000..e0001cc
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetStorageStatsCommandWrapper.java
@@ -0,0 +1,69 @@
+//
+// 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 org.apache.xmlrpc.XmlRpcException;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.GetStorageStatsAnswer;
+import com.cloud.agent.api.GetStorageStatsCommand;
+import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
+import com.cloud.resource.CommandWrapper;
+import com.xensource.xenapi.Connection;
+import com.xensource.xenapi.SR;
+import com.xensource.xenapi.Types.XenAPIException;
+
+public final class CitrixGetStorageStatsCommandWrapper extends CommandWrapper<GetStorageStatsCommand,
Answer, CitrixResourceBase> {
+
+    private static final Logger s_logger = Logger.getLogger(CitrixGetStorageStatsCommandWrapper.class);
+
+    @Override
+    public Answer execute(final GetStorageStatsCommand command, final CitrixResourceBase
citrixResourceBase) {
+        final Connection conn = citrixResourceBase.getConnection();
+        try {
+            final Set<SR> srs = SR.getByNameLabel(conn, command.getStorageId());
+            if (srs.size() != 1) {
+                final String msg = "There are " + srs.size() + " storageid: " + command.getStorageId();
+                s_logger.warn(msg);
+                return new GetStorageStatsAnswer(command, msg);
+            }
+            final SR sr = srs.iterator().next();
+            sr.scan(conn);
+            final long capacity = sr.getPhysicalSize(conn);
+            final long used = sr.getPhysicalUtilisation(conn);
+            return new GetStorageStatsAnswer(command, capacity, used);
+        } catch (final XenAPIException e) {
+            final String msg = "GetStorageStats Exception:" + e.toString() + "host:" + citrixResourceBase.getHost().getUuid()
+ "storageid: " + command.getStorageId();
+            s_logger.warn(msg);
+            return new GetStorageStatsAnswer(command, msg);
+        } catch (final XmlRpcException e) {
+            final String msg = "GetStorageStats Exception:" + e.getMessage() + "host:" +
citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
+            s_logger.warn(msg);
+            return new GetStorageStatsAnswer(command, msg);
+        }  catch (final Exception e) {
+            final String msg = "GetStorageStats Exception:" + e.getMessage() + "host:" +
citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
+            s_logger.warn(msg);
+            return new GetStorageStatsAnswer(command, msg);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11d03368/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixPrimaryStorageDownloadCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixPrimaryStorageDownloadCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixPrimaryStorageDownloadCommandWrapper.java
new file mode 100644
index 0000000..2705207
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixPrimaryStorageDownloadCommandWrapper.java
@@ -0,0 +1,83 @@
+//
+// 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.net.URI;
+import java.util.HashMap;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
+import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
+import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
+import com.cloud.resource.CommandWrapper;
+import com.xensource.xenapi.Connection;
+import com.xensource.xenapi.SR;
+import com.xensource.xenapi.VDI;
+
+public final class CitrixPrimaryStorageDownloadCommandWrapper extends CommandWrapper<PrimaryStorageDownloadCommand,
Answer, CitrixResourceBase> {
+
+    private static final Logger s_logger = Logger.getLogger(CitrixPrimaryStorageDownloadCommandWrapper.class);
+
+    @Override
+    public Answer execute(final PrimaryStorageDownloadCommand command, final CitrixResourceBase
citrixResourceBase) {
+        final String tmplturl = command.getUrl();
+        final String poolName = command.getPoolUuid();
+        final int wait = command.getWait();
+        try {
+            final URI uri = new URI(tmplturl);
+            final String tmplpath = uri.getHost() + ":" + uri.getPath();
+            final Connection conn = citrixResourceBase.getConnection();
+            SR poolsr = null;
+            final Set<SR> srs = SR.getByNameLabel(conn, poolName);
+            if (srs.size() != 1) {
+                final String msg = "There are " + srs.size() + " SRs with same name: " +
poolName;
+                s_logger.warn(msg);
+                return new PrimaryStorageDownloadAnswer(msg);
+            } else {
+                poolsr = srs.iterator().next();
+            }
+            final String pUuid = poolsr.getUuid(conn);
+            final boolean isISCSI = citrixResourceBase.IsISCSI(poolsr.getType(conn));
+            final String uuid = citrixResourceBase.copyVhdFromSecondaryStorage(conn, tmplpath,
pUuid, wait);
+            final VDI tmpl = citrixResourceBase.getVDIbyUuid(conn, uuid);
+            final VDI snapshotvdi = tmpl.snapshot(conn, new HashMap<String, String>());
+            final String snapshotUuid = snapshotvdi.getUuid(conn);
+            snapshotvdi.setNameLabel(conn, "Template " + command.getName());
+            final String parentuuid = citrixResourceBase.getVhdParent(conn, pUuid, snapshotUuid,
isISCSI);
+            final VDI parent = citrixResourceBase.getVDIbyUuid(conn, parentuuid);
+            final Long phySize = parent.getPhysicalUtilisation(conn);
+            tmpl.destroy(conn);
+            poolsr.scan(conn);
+            try {
+                Thread.sleep(5000);
+            } catch (final Exception e) {
+            }
+            return new PrimaryStorageDownloadAnswer(snapshotvdi.getUuid(conn), phySize);
+        } catch (final Exception e) {
+            final String msg = "Catch Exception " + e.getClass().getName() + " on host:"
+ citrixResourceBase.getHost().getUuid() + " for template: " + tmplturl + " due to "
+                    + e.toString();
+            s_logger.warn(msg, e);
+            return new PrimaryStorageDownloadAnswer(msg);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11d03368/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 1deefea..c31c340 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
@@ -30,6 +30,7 @@ import com.cloud.agent.api.Command;
 import com.cloud.agent.api.CreateStoragePoolCommand;
 import com.cloud.agent.api.DeleteStoragePoolCommand;
 import com.cloud.agent.api.GetHostStatsCommand;
+import com.cloud.agent.api.GetStorageStatsCommand;
 import com.cloud.agent.api.GetVmDiskStatsCommand;
 import com.cloud.agent.api.GetVmStatsCommand;
 import com.cloud.agent.api.MigrateCommand;
@@ -44,6 +45,7 @@ import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
 import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
 import com.cloud.agent.api.storage.CreateCommand;
 import com.cloud.agent.api.storage.DestroyCommand;
+import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
 import com.cloud.agent.api.storage.ResizeVolumeCommand;
 import com.cloud.resource.CommandWrapper;
 import com.cloud.resource.RequestWrapper;
@@ -89,6 +91,8 @@ public class CitrixRequestWrapper extends RequestWrapper {
         map.put(AttachVolumeCommand.class, new CitrixAttachVolumeCommandWrapper());
         map.put(AttachIsoCommand.class, new CitrixAttachIsoCommandWrapper());
         map.put(UpgradeSnapshotCommand.class, new CitrixUpgradeSnapshotCommandWrapper());
+        map.put(GetStorageStatsCommand.class, new CitrixGetStorageStatsCommandWrapper());
+        map.put(PrimaryStorageDownloadCommand.class, new CitrixPrimaryStorageDownloadCommandWrapper());
     }
 
     public static CitrixRequestWrapper getInstance() {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11d03368/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 d5f44e0..1873842 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
@@ -25,6 +25,7 @@ import com.cloud.agent.api.Command;
 import com.cloud.agent.api.CreateStoragePoolCommand;
 import com.cloud.agent.api.DeleteStoragePoolCommand;
 import com.cloud.agent.api.GetHostStatsCommand;
+import com.cloud.agent.api.GetStorageStatsCommand;
 import com.cloud.agent.api.GetVmDiskStatsCommand;
 import com.cloud.agent.api.GetVmStatsCommand;
 import com.cloud.agent.api.MigrateCommand;
@@ -41,11 +42,14 @@ import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
 import com.cloud.agent.api.storage.CreateAnswer;
 import com.cloud.agent.api.storage.CreateCommand;
 import com.cloud.agent.api.storage.DestroyCommand;
+import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
 import com.cloud.agent.api.storage.ResizeVolumeCommand;
+import com.cloud.agent.api.to.DataStoreTO;
 import com.cloud.agent.api.to.StorageFilerTO;
 import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
 import com.cloud.hypervisor.xenserver.resource.XsHost;
+import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Storage.StoragePoolType;
 import com.cloud.storage.VMTemplateStorageResourceAssoc;
 import com.cloud.vm.DiskProfile;
@@ -400,6 +404,42 @@ public class CitrixRequestWrapperTest {
 
         assertTrue(answer.getResult());
     }
+
+    @Test
+    public void testGetStorageStatsCommand() {
+        final XsHost xsHost = Mockito.mock(XsHost.class);
+        final DataStoreTO store = Mockito.mock(DataStoreTO.class);
+
+        final GetStorageStatsCommand storageStatsCommand = new GetStorageStatsCommand(store);
+
+        final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
+        assertNotNull(wrapper);
+
+        when(citrixResourceBase.getHost()).thenReturn(xsHost);
+
+        final Answer answer = wrapper.execute(storageStatsCommand, citrixResourceBase);
+        verify(citrixResourceBase, times(1)).getConnection();
+
+        assertFalse(answer.getResult());
+    }
+
+    @Test
+    public void testPrimaryStorageDownloadCommand() {
+        final XsHost xsHost = Mockito.mock(XsHost.class);
+        final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
+
+        final PrimaryStorageDownloadCommand storageDownloadCommand = new PrimaryStorageDownloadCommand("Test",
"http://127.0.0.1", ImageFormat.VHD, 1l, poolVO, 200);
+
+        final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
+        assertNotNull(wrapper);
+
+        when(citrixResourceBase.getHost()).thenReturn(xsHost);
+
+        final Answer answer = wrapper.execute(storageDownloadCommand, citrixResourceBase);
+        verify(citrixResourceBase, times(1)).getConnection();
+
+        assertFalse(answer.getResult());
+    }
 }
 
 class NotAValidCommand extends Command {


Mime
View raw message