cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [02/39] git commit: updated refs/heads/master to 3e28747
Date Thu, 02 Apr 2015 18:22:43 GMT
Adding CitrixCreateCommandWrapper.java and basic unit tests


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

Branch: refs/heads/master
Commit: 4256418af9e1c3f5b97c6fe77968f31c0693ce15
Parents: a1e8778
Author: wilderrodrigues <wrodrigues@schubergphilis.com>
Authored: Fri Mar 20 10:14:04 2015 +0100
Committer: wilderrodrigues <wrodrigues@schubergphilis.com>
Committed: Tue Mar 31 10:38:24 2015 +0200

----------------------------------------------------------------------
 .../xenserver/resource/CitrixResourceBase.java  |  4 +-
 .../wrapper/CitrixCreateCommandWrapper.java     | 82 ++++++++++++++++++++
 .../resource/wrapper/CitrixRequestWrapper.java  |  2 +
 .../wrapper/CitrixRequestWrapperTest.java       | 21 +++++
 4 files changed, 107 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4256418a/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 73f11c2..b284768 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
@@ -5851,7 +5851,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
 
     }
 
-    protected VDI getVDIbyUuid(final Connection conn, final String uuid) {
+    public VDI getVDIbyUuid(final Connection conn, final String uuid) {
         return getVDIbyUuid(conn, uuid, true);
     }
 
@@ -6742,7 +6742,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
         }
     }
 
-    protected SR getStorageRepository(final Connection conn, final String srNameLabel) {
+    public SR getStorageRepository(final Connection conn, final String srNameLabel) {
         Set<SR> srs;
         try {
             srs = SR.getByNameLabel(conn, srNameLabel);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4256418a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixCreateCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixCreateCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixCreateCommandWrapper.java
new file mode 100644
index 0000000..c58c5a9
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixCreateCommandWrapper.java
@@ -0,0 +1,82 @@
+//
+// 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.HashMap;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.storage.CreateAnswer;
+import com.cloud.agent.api.storage.CreateCommand;
+import com.cloud.agent.api.to.StorageFilerTO;
+import com.cloud.agent.api.to.VolumeTO;
+import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
+import com.cloud.resource.CommandWrapper;
+import com.cloud.vm.DiskProfile;
+import com.xensource.xenapi.Connection;
+import com.xensource.xenapi.SR;
+import com.xensource.xenapi.Types;
+import com.xensource.xenapi.VDI;
+
+public final class CitrixCreateCommandWrapper extends CommandWrapper<CreateCommand, Answer,
CitrixResourceBase> {
+
+    private static final Logger s_logger = Logger.getLogger(CitrixCreateCommandWrapper.class);
+
+    @Override
+    public Answer execute(final CreateCommand command, final CitrixResourceBase citrixResourceBase)
{
+        final Connection conn = citrixResourceBase.getConnection();
+        final StorageFilerTO pool = command.getPool();
+        final DiskProfile dskch = command.getDiskCharacteristics();
+
+        VDI vdi = null;
+        try {
+            final SR poolSr = citrixResourceBase.getStorageRepository(conn, pool.getUuid());
+            if (command.getTemplateUrl() != null) {
+                VDI tmpltvdi = null;
+
+                tmpltvdi = citrixResourceBase.getVDIbyUuid(conn, command.getTemplateUrl());
+                vdi = tmpltvdi.createClone(conn, new HashMap<String, String>());
+                vdi.setNameLabel(conn, dskch.getName());
+            } else {
+                final VDI.Record vdir = new VDI.Record();
+                vdir.nameLabel = dskch.getName();
+                vdir.SR = poolSr;
+                vdir.type = Types.VdiType.USER;
+
+                vdir.virtualSize = dskch.getSize();
+                vdi = VDI.create(conn, vdir);
+            }
+
+            VDI.Record vdir;
+            vdir = vdi.getRecord(conn);
+
+            s_logger.debug("Succesfully created VDI for " + command + ".  Uuid = " + vdir.uuid);
+
+            final VolumeTO vol =
+                    new VolumeTO(command.getVolumeId(), dskch.getType(), pool.getType(),
pool.getUuid(), vdir.nameLabel, pool.getPath(), vdir.uuid, vdir.virtualSize, null);
+
+            return new CreateAnswer(command, vol);
+        } catch (final Exception e) {
+            s_logger.warn("Unable to create volume; Pool=" + pool + "; Disk: " + dskch, e);
+            return new CreateAnswer(command, e);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4256418a/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 124b297..854116c 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
@@ -24,6 +24,7 @@ import java.util.Hashtable;
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.Command;
 import com.cloud.agent.api.RebootRouterCommand;
+import com.cloud.agent.api.storage.CreateCommand;
 import com.cloud.resource.CommandWrapper;
 import com.cloud.resource.RequestWrapper;
 import com.cloud.resource.ServerResource;
@@ -47,6 +48,7 @@ public class CitrixRequestWrapper extends RequestWrapper {
 
     private void init() {
         map.put(RebootRouterCommand.class, new CitrixRebootRouterCommandWrapper());
+        map.put(CreateCommand.class, new CitrixCreateCommandWrapper());
     }
 
     public static CitrixRequestWrapper getInstance() {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4256418a/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 aa4ebb9..e19883a 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
@@ -7,6 +7,7 @@ import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
+import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
@@ -16,7 +17,10 @@ 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.agent.api.storage.CreateAnswer;
+import com.cloud.agent.api.storage.CreateCommand;
 import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
+import com.cloud.vm.DiskProfile;
 
 @RunWith(MockitoJUnitRunner.class)
 public class CitrixRequestWrapperTest {
@@ -25,6 +29,8 @@ public class CitrixRequestWrapperTest {
     protected CitrixResourceBase citrixResourceBase;
     @Mock
     protected RebootAnswer rebootAnswer;
+    @Mock
+    protected CreateAnswer createAnswer;
 
     @Test
     public void testWrapperInstance() {
@@ -44,9 +50,24 @@ public class CitrixRequestWrapperTest {
 
         final Answer answer = wrapper.execute(rebootCommand, citrixResourceBase);
 
+        verify(citrixResourceBase, times(1)).getConnection();
         verify(citrixResourceBase, times(1)).execute((RebootCommand)rebootCommand);
 
         assertFalse(rebootAnswer.getResult());
         assertEquals(answer, rebootAnswer);
     }
+
+    @Test
+    public void testExecuteCreateCommand() {
+        final CreateCommand createCommand = new CreateCommand(new DiskProfile(null), "",
new StoragePoolVO(), false);
+
+        final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
+        assertNotNull(wrapper);
+
+        final Answer answer = wrapper.execute(createCommand, citrixResourceBase);
+
+        verify(citrixResourceBase, times(1)).getConnection();
+
+        assertFalse(answer.getResult());
+    }
 }
\ No newline at end of file


Mime
View raw message