cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [04/39] git commit: updated refs/heads/master to 3e28747
Date Thu, 02 Apr 2015 18:22:45 GMT
Refactoring the GetVmStatsCommand
  - Added basic tests


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

Branch: refs/heads/master
Commit: 8f04108e23dffc3f7930bdbe111eb11f2653b453
Parents: 0e51379
Author: wilderrodrigues <wrodrigues@schubergphilis.com>
Authored: Tue Mar 24 10:52:31 2015 +0100
Committer: wilderrodrigues <wrodrigues@schubergphilis.com>
Committed: Tue Mar 31 10:38:25 2015 +0200

----------------------------------------------------------------------
 .../xenserver/resource/CitrixResourceBase.java  |  4 +-
 .../resource/wrapper/CitrixRequestWrapper.java  |  2 +
 .../wrapper/GetVmStatsCommandWrapper.java       | 82 ++++++++++++++++++++
 .../wrapper/CitrixRequestWrapperTest.java       | 15 ++++
 4 files changed, 101 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8f04108e/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 42d37d5..024307d 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
@@ -2358,7 +2358,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
         }
     }
 
-    protected HashMap<String, VmStatsEntry> getVmStats(final Connection conn, final
GetVmStatsCommand cmd, final List<String> vmUUIDs, final String hostGuid) {
+    public HashMap<String, VmStatsEntry> getVmStats(final Connection conn, final GetVmStatsCommand
cmd, final List<String> vmUUIDs, final String hostGuid) {
         final HashMap<String, VmStatsEntry> vmResponseMap = new HashMap<String,
VmStatsEntry>();
 
         for (final String vmUUID : vmUUIDs) {
@@ -6674,7 +6674,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
         return false;
     }
 
-    protected VM getVM(final Connection conn, final String vmName) {
+    public VM getVM(final Connection conn, final String vmName) {
         // Look up VMs with the specified name
         Set<VM> vms;
         try {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8f04108e/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 98989ab..9c2f08d 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.GetHostStatsCommand;
+import com.cloud.agent.api.GetVmStatsCommand;
 import com.cloud.agent.api.ReadyCommand;
 import com.cloud.agent.api.RebootRouterCommand;
 import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
@@ -57,6 +58,7 @@ public class CitrixRequestWrapper extends RequestWrapper {
         map.put(WatchConsoleProxyLoadCommand.class, new CitrixWatchConsoleProxyLoadCommandWrapper());
         map.put(ReadyCommand.class, new CitrixReadyCommandWrapper());
         map.put(GetHostStatsCommand.class, new GetHostStatsCommandWrapper());
+        map.put(GetVmStatsCommand.class, new GetVmStatsCommandWrapper());
     }
 
     public static CitrixRequestWrapper getInstance() {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8f04108e/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetVmStatsCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetVmStatsCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetVmStatsCommandWrapper.java
new file mode 100644
index 0000000..1b4863a
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetVmStatsCommandWrapper.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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.apache.xmlrpc.XmlRpcException;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.GetVmStatsAnswer;
+import com.cloud.agent.api.GetVmStatsCommand;
+import com.cloud.agent.api.VmStatsEntry;
+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 GetVmStatsCommandWrapper extends CommandWrapper<GetVmStatsCommand,
Answer, CitrixResourceBase> {
+
+    private static final Logger s_logger = Logger.getLogger(GetVmStatsCommandWrapper.class);
+
+    @Override
+    public Answer execute(final GetVmStatsCommand command, final CitrixResourceBase citrixResourceBase)
{
+        final Connection conn = citrixResourceBase.getConnection();
+        final List<String> vmNames = command.getVmNames();
+        final HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String,
VmStatsEntry>();
+        if (vmNames.size() == 0) {
+            return new GetVmStatsAnswer(command, vmStatsNameMap);
+        }
+        try {
+
+            // Determine the UUIDs of the requested VMs
+            final List<String> vmUUIDs = new ArrayList<String>();
+
+            for (final String vmName : vmNames) {
+                final VM vm = citrixResourceBase.getVM(conn, vmName);
+                vmUUIDs.add(vm.getUuid(conn));
+            }
+
+            final HashMap<String, VmStatsEntry> vmStatsUUIDMap = citrixResourceBase.getVmStats(conn,
command, vmUUIDs, command.getHostGuid());
+            if (vmStatsUUIDMap == null) {
+                return new GetVmStatsAnswer(command, vmStatsNameMap);
+            }
+
+            for (final Map.Entry<String,VmStatsEntry>entry : vmStatsUUIDMap.entrySet())
{
+                vmStatsNameMap.put(vmNames.get(vmUUIDs.indexOf(entry.getKey())), entry.getValue());
+            }
+
+            return new GetVmStatsAnswer(command, vmStatsNameMap);
+        } catch (final XenAPIException e) {
+            final String msg = "Unable to get VM stats" + e.toString();
+            s_logger.warn(msg, e);
+            return new GetVmStatsAnswer(command, vmStatsNameMap);
+        } catch (final XmlRpcException e) {
+            final String msg = "Unable to get VM stats" + e.getMessage();
+            s_logger.warn(msg, e);
+            return new GetVmStatsAnswer(command, vmStatsNameMap);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8f04108e/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 027a5fd..e54e809 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
@@ -8,6 +8,8 @@ import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
+import java.util.ArrayList;
+
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -17,6 +19,7 @@ import org.mockito.runners.MockitoJUnitRunner;
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.Command;
 import com.cloud.agent.api.GetHostStatsCommand;
+import com.cloud.agent.api.GetVmStatsCommand;
 import com.cloud.agent.api.ReadyCommand;
 import com.cloud.agent.api.RebootAnswer;
 import com.cloud.agent.api.RebootCommand;
@@ -136,6 +139,18 @@ public class CitrixRequestWrapperTest {
 
         assertTrue(answer.getResult());
     }
+
+    @Test
+    public void testGetVmStatsCommandCommand() {
+        final GetVmStatsCommand statsCommand = new GetVmStatsCommand(new ArrayList<String>(),
null, null);
+
+        final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
+        assertNotNull(wrapper);
+
+        final Answer answer = wrapper.execute(statsCommand, citrixResourceBase);
+
+        assertTrue(answer.getResult());
+    }
 }
 
 class NotAValidCommand extends Command {


Mime
View raw message