You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ek...@apache.org on 2015/05/22 12:56:52 UTC

[6/8] git commit: updated refs/heads/master to 0c6758f

CLOUDSTACK-8502

Added CitrixStorageSubSystemCommandWrapper to complete the CitrixResourceBase refactor.
  - All 101 unit tests are green


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

Branch: refs/heads/master
Commit: add42777203999e99c310005e02d8dd31fff2f95
Parents: 3efdc6c
Author: wilderrodrigues <wr...@schubergphilis.com>
Authored: Thu May 21 13:59:49 2015 +0200
Committer: wilderrodrigues <wr...@schubergphilis.com>
Committed: Thu May 21 13:59:49 2015 +0200

----------------------------------------------------------------------
 core/src/com/cloud/resource/RequestWrapper.java |  4 +++
 .../xenserver/resource/CitrixResourceBase.java  | 14 +++-----
 .../CitrixStorageSubSystemCommandWrapper.java   | 38 ++++++++++++++++++++
 .../wrapper/CitrixRequestWrapperTest.java       | 22 ++++++++++++
 4 files changed, 69 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/add42777/core/src/com/cloud/resource/RequestWrapper.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/resource/RequestWrapper.java b/core/src/com/cloud/resource/RequestWrapper.java
index 31388d6..4e754d6 100644
--- a/core/src/com/cloud/resource/RequestWrapper.java
+++ b/core/src/com/cloud/resource/RequestWrapper.java
@@ -75,6 +75,8 @@ public abstract class RequestWrapper {
                 commandWrapper = resourceCommands.get(commandClass2);
 
                 keepCommandClass = commandClass2;
+            } catch (final ClassCastException e) {
+                throw new NullPointerException("No key found for '" + keepCommandClass.getClass() + "' in the Map!");
             } catch (final NullPointerException e) {
                 // Will now traverse all the resource hierarchy. Returning null
                 // is not a problem.
@@ -108,6 +110,8 @@ public abstract class RequestWrapper {
                 keepResourceClass = resourceClass2;
 
                 commandWrapper = retrieveCommands(command.getClass(), resourceCommands2);
+            } catch (final ClassCastException e) {
+                throw new NullPointerException("No key found for '" + command.getClass() + "' in the Map!");
             } catch (final NullPointerException e) {
                 throw e;
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/add42777/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 2b3035c..6aaaf0e 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
@@ -46,7 +46,6 @@ import javax.naming.ConfigurationException;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
-import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
 import org.apache.cloudstack.storage.to.TemplateObjectTO;
 import org.apache.cloudstack.storage.to.VolumeObjectTO;
 import org.apache.log4j.Logger;
@@ -717,7 +716,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
                     if (record.isControlDomain || record.isASnapshot || record.isATemplate) {
                         continue; // Skip DOM0
                     }
-                    String platform = StringUtils.mapToString(record.platform);
+                    final String platform = StringUtils.mapToString(record.platform);
                     if (platform.isEmpty()) {
                         continue; //Skip if platform is null
                     }
@@ -1642,13 +1641,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
 
     @Override
     public Answer executeRequest(final Command cmd) {
-
-        // We need this one because the StorageSubSystemCommand is from another
-        // hierarchy.
-        if (cmd instanceof StorageSubSystemCommand) {
-            return storageHandler.handleStorageCommands((StorageSubSystemCommand) cmd);
-        }
-
         final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
         try {
             return wrapper.execute(cmd, this);
@@ -2012,6 +2004,10 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         return _migratewait;
     }
 
+    public StorageSubsystemCommandHandler getStorageHandler() {
+        return storageHandler;
+    }
+
     protected boolean getHostInfo(final Connection conn) throws IllegalArgumentException {
         try {
             final Host myself = Host.getByUuid(conn, _host.getUuid());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/add42777/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixStorageSubSystemCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixStorageSubSystemCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixStorageSubSystemCommandWrapper.java
new file mode 100644
index 0000000..c14818e
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixStorageSubSystemCommandWrapper.java
@@ -0,0 +1,38 @@
+//
+// 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 org.apache.cloudstack.storage.command.StorageSubSystemCommand;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
+import com.cloud.resource.CommandWrapper;
+import com.cloud.resource.ResourceWrapper;
+import com.cloud.storage.resource.StorageSubsystemCommandHandler;
+
+@ResourceWrapper(handles =  StorageSubSystemCommand.class)
+public final class CitrixStorageSubSystemCommandWrapper extends CommandWrapper<StorageSubSystemCommand, Answer, CitrixResourceBase> {
+
+    @Override
+    public Answer execute(final StorageSubSystemCommand command, final CitrixResourceBase citrixResourceBase) {
+        final StorageSubsystemCommandHandler handler = citrixResourceBase.getStorageHandler();
+        return handler.handleStorageCommands(command);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/add42777/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 6a1be8c..8d66c65 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
@@ -33,6 +33,8 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.cloudstack.storage.command.AttachAnswer;
+import org.apache.cloudstack.storage.command.AttachCommand;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.cloudstack.storage.to.VolumeObjectTO;
 import org.apache.xmlrpc.XmlRpcException;
@@ -109,6 +111,7 @@ 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.DiskTO;
 import com.cloud.agent.api.to.IpAddressTO;
 import com.cloud.agent.api.to.NicTO;
 import com.cloud.agent.api.to.StorageFilerTO;
@@ -123,6 +126,7 @@ import com.cloud.network.PhysicalNetworkSetupInfo;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Storage.StoragePoolType;
 import com.cloud.storage.VMTemplateStorageResourceAssoc;
+import com.cloud.storage.resource.StorageSubsystemCommandHandler;
 import com.cloud.vm.DiskProfile;
 import com.cloud.vm.VirtualMachine;
 import com.xensource.xenapi.Connection;
@@ -1807,6 +1811,24 @@ public class CitrixRequestWrapperTest {
         // Requires more testing, but the VirtualResourceRouting is quite big.
         assertNull(answer);
     }
+
+    @Test
+    public void testStorageSubSystemCommand() {
+        final DiskTO disk = Mockito.mock(DiskTO.class);
+        final String vmName = "Test";
+        final AttachCommand command = new AttachCommand(disk, vmName);
+
+        final StorageSubsystemCommandHandler handler = Mockito.mock(StorageSubsystemCommandHandler.class);
+        when(citrixResourceBase.getStorageHandler()).thenReturn(handler);
+
+        when(handler.handleStorageCommands(command)).thenReturn(new AttachAnswer(disk));
+
+        final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
+        assertNotNull(wrapper);
+
+        final Answer answer = wrapper.execute(command, citrixResourceBase);
+        assertTrue(answer.getResult());
+    }
 }
 
 class NotAValidCommand extends Command {