changeset 416:6cef11203d8f

Allow list-heap-dumps command to filter by host and vm Reviewed-by: rkennke Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-June/001977.html
author Omair Majid <omajid@redhat.com>
date Thu, 21 Jun 2012 12:27:44 -0400
parents 17313a694032
children ad3de6c0a03b
files client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/ListHeapDumpsCommand.java client/heapdumper/src/test/java/com/redhat/thermostat/client/heap/ListHeapDumpsCommandTest.java common/core/src/main/java/com/redhat/thermostat/common/cli/HostVMArguments.java common/core/src/test/java/com/redhat/thermostat/common/cli/HostVMArgumentsTest.java tools/src/main/java/com/redhat/thermostat/tools/cli/HostVMArguments.java tools/src/main/java/com/redhat/thermostat/tools/cli/VMInfoCommand.java tools/src/main/java/com/redhat/thermostat/tools/cli/VMStatCommand.java tools/src/test/java/com/redhat/thermostat/tools/cli/HostVMArgumentsTest.java
diffstat 8 files changed, 319 insertions(+), 188 deletions(-) [+]
line wrap: on
line diff
--- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/ListHeapDumpsCommand.java	Thu Jun 21 17:50:09 2012 +0200
+++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/ListHeapDumpsCommand.java	Thu Jun 21 12:27:44 2012 -0400
@@ -37,6 +37,7 @@
 package com.redhat.thermostat.client.heap;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Date;
 
@@ -45,6 +46,7 @@
 import com.redhat.thermostat.common.cli.Command;
 import com.redhat.thermostat.common.cli.CommandContext;
 import com.redhat.thermostat.common.cli.CommandException;
+import com.redhat.thermostat.common.cli.HostVMArguments;
 import com.redhat.thermostat.common.cli.TableRenderer;
 import com.redhat.thermostat.common.dao.DAOFactory;
 import com.redhat.thermostat.common.dao.HeapDAO;
@@ -80,7 +82,7 @@
 
     @Override
     public Collection<ArgumentSpec> getAcceptedArguments() {
-        return new ArrayList<>();
+        return HostVMArguments.getArgumentSpecs(false, false);
     }
 
     @Override
@@ -90,6 +92,8 @@
 
     @Override
     public void run(CommandContext ctx) throws CommandException {
+        HostVMArguments args = new HostVMArguments(ctx.getArguments(), false, false);
+
         TableRenderer renderer = new TableRenderer(4);
 
         renderer.printLine(COLUMN_NAMES);
@@ -99,21 +103,27 @@
         VmInfoDAO vmDAO = daoFactory.getVmInfoDAO();
         HeapDAO heapDAO = daoFactory.getHeapDAO();
 
-        for (HostRef hostRef : hostDAO.getHosts()) {
-            for (VmRef vmRef : vmDAO.getVMs(hostRef)) {
-                Collection<HeapInfo> infos = heapDAO.getAllHeapInfo(vmRef);
-                for (HeapInfo info : infos) {
-                    renderer.printLine(hostRef.getStringID(),
-                                       vmRef.getStringID(),
-                                       info.getHeapDumpId(),
-                                       new Date(info.getTimestamp()).toString());
-                }
+        Collection<HostRef> hosts = args.getHost() != null ? Arrays.asList(args.getHost()) : hostDAO.getHosts();
+        for (HostRef hostRef : hosts) {
+            Collection<VmRef> vms = args.getVM() != null ? Arrays.asList(args.getVM()) : vmDAO.getVMs(hostRef);
+            for (VmRef vmRef : vms) {
+                printDumpsForVm(heapDAO, hostRef, vmRef, renderer);
             }
         }
 
         renderer.render(ctx.getConsole().getOutput());
     }
 
+    private void printDumpsForVm(HeapDAO heapDAO, HostRef hostRef, VmRef vmRef, TableRenderer renderer) {
+        Collection<HeapInfo> infos = heapDAO.getAllHeapInfo(vmRef);
+        for (HeapInfo info : infos) {
+            renderer.printLine(hostRef.getStringID(),
+                               vmRef.getStringID(),
+                               info.getHeapDumpId(),
+                               new Date(info.getTimestamp()).toString());
+        }
+    }
+
     @Override
     public void disable() {
         /* NO-OP */
--- a/client/heapdumper/src/test/java/com/redhat/thermostat/client/heap/ListHeapDumpsCommandTest.java	Thu Jun 21 17:50:09 2012 +0200
+++ b/client/heapdumper/src/test/java/com/redhat/thermostat/client/heap/ListHeapDumpsCommandTest.java	Thu Jun 21 12:27:44 2012 -0400
@@ -39,7 +39,11 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.isA;
+import static org.mockito.Mockito.eq;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Matchers.argThat;
 import static org.mockito.Mockito.when;
 
 import java.util.ArrayList;
@@ -53,12 +57,15 @@
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.mockito.ArgumentMatcher;
+import org.mockito.Matchers;
 
 import com.redhat.thermostat.common.appctx.ApplicationContext;
 import com.redhat.thermostat.common.appctx.ApplicationContextUtil;
 import com.redhat.thermostat.common.cli.ArgumentSpec;
 import com.redhat.thermostat.common.cli.Command;
 import com.redhat.thermostat.common.cli.CommandException;
+import com.redhat.thermostat.common.cli.SimpleArguments;
 import com.redhat.thermostat.common.dao.DAOFactory;
 import com.redhat.thermostat.common.dao.HeapDAO;
 import com.redhat.thermostat.common.dao.HostInfoDAO;
@@ -106,7 +113,7 @@
     public void verifyArguments() {
         Command command = new ListHeapDumpsCommand();
         List<ArgumentSpec> arguments = new ArrayList<>(command.getAcceptedArguments());
-        assertTrue(arguments.isEmpty());
+        assertEquals(2, arguments.size());
     }
 
     @Test
@@ -123,7 +130,7 @@
 
         Command command = new ListHeapDumpsCommand();
         TestCommandContextFactory factory = new TestCommandContextFactory();
-        command.run(factory.createContext(null));
+        command.run(factory.createContext(new SimpleArguments()));
         assertEquals("HOST ID VM ID HEAP ID TIMESTAMP\n", factory.getOutput());
     }
 
@@ -132,7 +139,7 @@
         HostRef hostRef = mock(HostRef.class);
         when(hostRef.getStringID()).thenReturn("host-id");
         VmRef vmRef = mock(VmRef.class);
-        when(vmRef.getStringID()).thenReturn("vm-id");
+        when(vmRef.getStringID()).thenReturn("1");
 
         HeapInfo heapInfo = mock(HeapInfo.class);
         Calendar timestamp = Calendar.getInstance();
@@ -159,10 +166,111 @@
 
         Command command = new ListHeapDumpsCommand();
         TestCommandContextFactory factory = new TestCommandContextFactory();
-        command.run(factory.createContext(null));
+        command.run(factory.createContext(new SimpleArguments()));
+
+        String expected = "HOST ID VM ID HEAP ID TIMESTAMP\n" +
+                          "host-id 1     0001    Thu Jun 07 15:32:00 UTC 2012\n";
+
+        assertEquals(expected, factory.getOutput());
+    }
+
+    @Test
+    public void verifyWorksWithFilterOnHost() throws CommandException {
+        HostRef hostRef1 = mock(HostRef.class);
+        when(hostRef1.getStringID()).thenReturn("host1");
+        VmRef vmRef1 = mock(VmRef.class);
+        when(vmRef1.getStringID()).thenReturn("1");
+
+        HostRef hostRef2 = mock(HostRef.class);
+        when(hostRef2.getStringID()).thenReturn("host2");
+        VmRef vmRef2 = mock(VmRef.class);
+        when(vmRef2.getStringID()).thenReturn("2");
+
+        HeapInfo heapInfo = mock(HeapInfo.class);
+        Calendar timestamp = Calendar.getInstance();
+        timestamp.set(2012, 5, 7, 15, 32, 0);
+        when(heapInfo.getTimestamp()).thenReturn(timestamp.getTimeInMillis());
+        when(heapInfo.getHeapDumpId()).thenReturn("0001");
+
+        HeapDAO heapDao = mock(HeapDAO.class);
+
+        VmInfoDAO vmInfo = mock(VmInfoDAO.class);
+        when(vmInfo.getVMs(isA(HostRef.class))).thenReturn(Arrays.asList(vmRef1)).thenReturn(Arrays.asList(vmRef2));
+
+        HostInfoDAO hostInfo = mock(HostInfoDAO.class);
+        when(hostInfo.getHosts()).thenReturn(Arrays.asList(hostRef1, hostRef2));
+
+        when(heapDao.getAllHeapInfo(vmRef1)).thenReturn(Arrays.asList(heapInfo));
+        when(heapDao.getAllHeapInfo(vmRef2)).thenReturn(Arrays.asList(heapInfo));
+
+        DAOFactory daoFactory = mock(DAOFactory.class);
+        when(daoFactory.getHostInfoDAO()).thenReturn(hostInfo);
+        when(daoFactory.getVmInfoDAO()).thenReturn(vmInfo);
+        when(daoFactory.getHeapDAO()).thenReturn(heapDao);
+
+        ApplicationContext.getInstance().setDAOFactory(daoFactory);
+
+        Command command = new ListHeapDumpsCommand();
+        TestCommandContextFactory factory = new TestCommandContextFactory();
+
+        SimpleArguments args = new SimpleArguments();
+        args.addArgument("hostId", "host1");
+
+        command.run(factory.createContext(args));
 
         String expected = "HOST ID VM ID HEAP ID TIMESTAMP\n" +
-                          "host-id vm-id 0001    Thu Jun 07 15:32:00 UTC 2012\n";
+                          "host1   1     0001    Thu Jun 07 15:32:00 UTC 2012\n";
+
+        assertEquals(expected, factory.getOutput());
+    }
+
+    @Test
+    public void verifyWorksWithFilterOnHostAndVM() throws CommandException {
+        HostRef hostRef1 = mock(HostRef.class);
+        when(hostRef1.getStringID()).thenReturn("host1");
+        when(hostRef1.getAgentId()).thenReturn("host1");
+        VmRef vmRef1 = mock(VmRef.class);
+        when(vmRef1.getStringID()).thenReturn("1");
+
+        HostRef hostRef2 = mock(HostRef.class);
+        when(hostRef2.getStringID()).thenReturn("host2");
+        VmRef vmRef2 = mock(VmRef.class);
+        when(vmRef2.getStringID()).thenReturn("2");
+
+        HeapInfo heapInfo = mock(HeapInfo.class);
+        Calendar timestamp = Calendar.getInstance();
+        timestamp.set(2012, 5, 7, 15, 32, 0);
+        when(heapInfo.getTimestamp()).thenReturn(timestamp.getTimeInMillis());
+        when(heapInfo.getHeapDumpId()).thenReturn("0001");
+
+        HeapDAO heapDao = mock(HeapDAO.class);
+
+        VmInfoDAO vmInfo = mock(VmInfoDAO.class);
+        when(vmInfo.getVMs(isA(HostRef.class))).thenReturn(Arrays.asList(vmRef1)).thenReturn(Arrays.asList(vmRef2));
+
+        HostInfoDAO hostInfo = mock(HostInfoDAO.class);
+        when(hostInfo.getHosts()).thenReturn(Arrays.asList(hostRef1, hostRef2));
+
+        when(heapDao.getAllHeapInfo(vmRef1)).thenReturn(Arrays.asList(heapInfo));
+        when(heapDao.getAllHeapInfo(vmRef2)).thenReturn(Arrays.asList(heapInfo));
+
+        DAOFactory daoFactory = mock(DAOFactory.class);
+        when(daoFactory.getHostInfoDAO()).thenReturn(hostInfo);
+        when(daoFactory.getVmInfoDAO()).thenReturn(vmInfo);
+        when(daoFactory.getHeapDAO()).thenReturn(heapDao);
+
+        ApplicationContext.getInstance().setDAOFactory(daoFactory);
+
+        Command command = new ListHeapDumpsCommand();
+        TestCommandContextFactory factory = new TestCommandContextFactory();
+
+        SimpleArguments args = new SimpleArguments();
+        args.addArgument("hostId", "host1");
+        args.addArgument("vmId", "1"); // vm id must be an int for the arg parser to work
+
+        command.run(factory.createContext(args));
+
+        String expected = "HOST ID VM ID HEAP ID TIMESTAMP\n";
 
         assertEquals(expected, factory.getOutput());
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/core/src/main/java/com/redhat/thermostat/common/cli/HostVMArguments.java	Thu Jun 21 12:27:44 2012 -0400
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2012 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.common.cli;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import com.redhat.thermostat.common.dao.HostRef;
+import com.redhat.thermostat.common.dao.VmRef;
+
+public class HostVMArguments {
+
+    static final String HOST_ID_ARGUMENT = "hostId";
+    static final String VM_ID_ARGUMENT = "vmId";
+
+    private HostRef host;
+    private VmRef vm;
+
+    public HostVMArguments(Arguments args) throws CommandException {
+        this(args, true, true);
+    }
+
+    public HostVMArguments(Arguments args, boolean hostRequired, boolean vmRequired) throws CommandException {
+        String hostId = args.getArgument(HOST_ID_ARGUMENT);
+        String vmId = args.getArgument(VM_ID_ARGUMENT);
+        if (hostRequired && hostId == null) {
+            throw new CommandException("a " + HOST_ID_ARGUMENT + "is required");
+        } else if (hostId == null) {
+            host = null;
+        } else {
+            host = new HostRef(hostId, "dummy");
+        }
+        try {
+            int parsedVmId = parseVmId(vmId);
+            vm = new VmRef(host, parsedVmId, "dummy");
+        } catch (CommandException ce) {
+            if (vmRequired) {
+                throw ce;
+            }
+            vm = null;
+        }
+    }
+
+    private int parseVmId(String vmId) throws CommandException {
+        try {
+            return Integer.parseInt(vmId);
+        } catch (NumberFormatException ex) {
+            throw new CommandException("Invalid VM ID: " + vmId, ex);
+        }
+    }
+
+    public HostRef getHost() {
+        return host;
+    }
+
+    public VmRef getVM() {
+        return vm;
+    }
+
+    /**
+     * @return a collection of arguments for accepting hosts and vms (where both
+     * are required)
+     */
+    public static Collection<ArgumentSpec> getArgumentSpecs() {
+        return getArgumentSpecs(true);
+    }
+
+    /**
+     * @return a collection of arguments for accepting hosts and vms (where the
+     * vm is optional)
+     */
+    public static Collection<ArgumentSpec> getArgumentSpecs(boolean vmRequired) {
+        return getArgumentSpecs(true, vmRequired);
+    }
+
+    /**
+     * @return a collection of arguments for accepting hosts and vms (where the
+     * vm is optional)
+     */
+    public static Collection<ArgumentSpec> getArgumentSpecs(boolean hostRequired, boolean vmRequired) {
+        ArgumentSpec vmId = new SimpleArgumentSpec(VM_ID_ARGUMENT, "the ID of the VM to monitor", vmRequired, true);
+        ArgumentSpec hostId = new SimpleArgumentSpec(HOST_ID_ARGUMENT, "the ID of the host to monitor", hostRequired, true);
+        return Arrays.asList(vmId, hostId);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/core/src/test/java/com/redhat/thermostat/common/cli/HostVMArgumentsTest.java	Thu Jun 21 12:27:44 2012 -0400
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2012 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.common.cli;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+
+import org.junit.Test;
+
+import com.redhat.thermostat.common.cli.ArgumentSpec;
+import com.redhat.thermostat.common.cli.HostVMArguments;
+
+public class HostVMArgumentsTest {
+
+    @Test
+    public void testArgumentSpecification() {
+        ArrayList<ArgumentSpec> args = new ArrayList<>(HostVMArguments.getArgumentSpecs(false));
+        assertEquals(2, args.size());
+
+        // TODO different order should be okay
+        ArgumentSpec vmIdArg = args.get(0);
+        assertEquals("vmId", vmIdArg.getName());
+        assertEquals(false, vmIdArg.isRequired());
+
+        ArgumentSpec hostIdArg = args.get(1);
+        assertEquals("hostId", hostIdArg.getName());
+        assertEquals(true, hostIdArg.isRequired());
+    }
+}
--- a/tools/src/main/java/com/redhat/thermostat/tools/cli/HostVMArguments.java	Thu Jun 21 17:50:09 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc.
- *
- * This file is part of Thermostat.
- *
- * Thermostat is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2, or (at your
- * option) any later version.
- *
- * Thermostat is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Thermostat; see the file COPYING.  If not see
- * <http://www.gnu.org/licenses/>.
- *
- * Linking this code with other modules is making a combined work
- * based on this code.  Thus, the terms and conditions of the GNU
- * General Public License cover the whole combination.
- *
- * As a special exception, the copyright holders of this code give
- * you permission to link this code with independent modules to
- * produce an executable, regardless of the license terms of these
- * independent modules, and to copy and distribute the resulting
- * executable under terms of your choice, provided that you also
- * meet, for each linked independent module, the terms and conditions
- * of the license of that module.  An independent module is a module
- * which is not derived from or based on this code.  If you modify
- * this code, you may extend this exception to your version of the
- * library, but you are not obligated to do so.  If you do not wish
- * to do so, delete this exception statement from your version.
- */
-
-package com.redhat.thermostat.tools.cli;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-import com.redhat.thermostat.common.cli.ArgumentSpec;
-import com.redhat.thermostat.common.cli.Arguments;
-import com.redhat.thermostat.common.cli.CommandException;
-import com.redhat.thermostat.common.cli.SimpleArgumentSpec;
-import com.redhat.thermostat.common.dao.HostRef;
-import com.redhat.thermostat.common.dao.VmRef;
-
-class HostVMArguments {
-
-    static final String HOST_ID_ARGUMENT = "hostId";
-    static final String VM_ID_ARGUMENT = "vmId";
-
-    private HostRef host;
-    private VmRef vm;
-
-    HostVMArguments(Arguments args) throws CommandException {
-        this(args, true);
-    }
-
-    HostVMArguments(Arguments args, boolean vmRequired) throws CommandException {
-        String hostId = args.getArgument(HOST_ID_ARGUMENT);
-        String vmId = args.getArgument(VM_ID_ARGUMENT);
-        host = new HostRef(hostId, "dummy");
-        try {
-            int parsedVmId = parseVmId(vmId);
-            vm = new VmRef(host, parsedVmId, "dummy");
-        } catch (CommandException ce) {
-            if (vmRequired) {
-                throw ce;
-            }
-            vm = null;
-        }
-    }
-
-    private int parseVmId(String vmId) throws CommandException {
-        try {
-            return Integer.parseInt(vmId);
-        } catch (NumberFormatException ex) {
-            throw new CommandException("Invalid VM ID: " + vmId, ex);
-        }
-    }
-
-    HostRef getHost() {
-        return host;
-    }
-
-    VmRef getVM() {
-        return vm;
-    }
-
-    /**
-     * @return a collection of arguments for accepting hosts and vms (where both
-     * are required)
-     */
-    static Collection<ArgumentSpec> getArgumentSpecs() {
-        return getArgumentSpecs(true);
-    }
-
-    /**
-     * @return a collection of arguments for accepting hosts and vms (where the
-     * vm is optional)
-     */
-    static Collection<ArgumentSpec> getArgumentSpecs(boolean vmRequired) {
-        ArgumentSpec vmId = new SimpleArgumentSpec(VM_ID_ARGUMENT, "the ID of the VM to monitor", vmRequired, true);
-        ArgumentSpec hostId = new SimpleArgumentSpec(HOST_ID_ARGUMENT, "the ID of the host to monitor", true, true);
-        return Arrays.asList(vmId, hostId);
-    }
-}
--- a/tools/src/main/java/com/redhat/thermostat/tools/cli/VMInfoCommand.java	Thu Jun 21 17:50:09 2012 +0200
+++ b/tools/src/main/java/com/redhat/thermostat/tools/cli/VMInfoCommand.java	Thu Jun 21 12:27:44 2012 -0400
@@ -45,6 +45,7 @@
 import com.redhat.thermostat.common.cli.Command;
 import com.redhat.thermostat.common.cli.CommandContext;
 import com.redhat.thermostat.common.cli.CommandException;
+import com.redhat.thermostat.common.cli.HostVMArguments;
 import com.redhat.thermostat.common.cli.TableRenderer;
 import com.redhat.thermostat.common.dao.DAOException;
 import com.redhat.thermostat.common.dao.DAOFactory;
@@ -64,7 +65,7 @@
     public void run(CommandContext ctx) throws CommandException {
         DAOFactory daoFactory = ApplicationContext.getInstance().getDAOFactory();
         VmInfoDAO vmsDAO = daoFactory.getVmInfoDAO();
-        HostVMArguments hostVMArgs = new HostVMArguments(ctx.getArguments(), false);
+        HostVMArguments hostVMArgs = new HostVMArguments(ctx.getArguments(), true, false);
         HostRef host = hostVMArgs.getHost();
         VmRef vm = hostVMArgs.getVM();
         try {
--- a/tools/src/main/java/com/redhat/thermostat/tools/cli/VMStatCommand.java	Thu Jun 21 17:50:09 2012 +0200
+++ b/tools/src/main/java/com/redhat/thermostat/tools/cli/VMStatCommand.java	Thu Jun 21 12:27:44 2012 -0400
@@ -51,6 +51,7 @@
 import com.redhat.thermostat.common.cli.Command;
 import com.redhat.thermostat.common.cli.CommandContext;
 import com.redhat.thermostat.common.cli.CommandException;
+import com.redhat.thermostat.common.cli.HostVMArguments;
 import com.redhat.thermostat.common.cli.SimpleArgumentSpec;
 import com.redhat.thermostat.common.dao.DAOFactory;
 import com.redhat.thermostat.common.dao.VmCpuStatDAO;
--- a/tools/src/test/java/com/redhat/thermostat/tools/cli/HostVMArgumentsTest.java	Thu Jun 21 17:50:09 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc.
- *
- * This file is part of Thermostat.
- *
- * Thermostat is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2, or (at your
- * option) any later version.
- *
- * Thermostat is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Thermostat; see the file COPYING.  If not see
- * <http://www.gnu.org/licenses/>.
- *
- * Linking this code with other modules is making a combined work
- * based on this code.  Thus, the terms and conditions of the GNU
- * General Public License cover the whole combination.
- *
- * As a special exception, the copyright holders of this code give
- * you permission to link this code with independent modules to
- * produce an executable, regardless of the license terms of these
- * independent modules, and to copy and distribute the resulting
- * executable under terms of your choice, provided that you also
- * meet, for each linked independent module, the terms and conditions
- * of the license of that module.  An independent module is a module
- * which is not derived from or based on this code.  If you modify
- * this code, you may extend this exception to your version of the
- * library, but you are not obligated to do so.  If you do not wish
- * to do so, delete this exception statement from your version.
- */
-
-package com.redhat.thermostat.tools.cli;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-
-import org.junit.Test;
-
-import com.redhat.thermostat.common.cli.ArgumentSpec;
-
-public class HostVMArgumentsTest {
-
-    @Test
-    public void testArgumentSpecification() {
-        ArrayList<ArgumentSpec> args = new ArrayList<>(HostVMArguments.getArgumentSpecs(false));
-        assertEquals(2, args.size());
-
-        // TODO different order should be okay
-        ArgumentSpec vmIdArg = args.get(0);
-        assertEquals("vmId", vmIdArg.getName());
-        assertEquals(false, vmIdArg.isRequired());
-
-        ArgumentSpec hostIdArg = args.get(1);
-        assertEquals("hostId", hostIdArg.getName());
-        assertEquals(true, hostIdArg.isRequired());
-    }
-}