changeset 1966:f3f9cc19b17c

Add VM status filter and display options to find-vm command Reviewed-by: jerboaa, jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-August/015247.html Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-June/019718.html PR3040
author Andrew Azores <aazores@redhat.com>
date Wed, 19 Aug 2015 10:11:52 -0400
parents 180cf94d4b41
children 9ae4735019dc
files vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/AbstractMatcher.java vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/CriterionMatcher.java vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/FindVmCommand.java vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/HostCriterion.java vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/Matcher.java vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/ResultsRenderer.java vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/UnrecognizedArgumentException.java vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/VmCriterion.java vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/locale/LocaleResources.java vm-find/command/src/main/resources/com/redhat/thermostat/vm/find/command/locale/strings.properties vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/AbstractMatcherTest.java vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/FindVmCommandTest.java vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/HostCriterionTest.java vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/HostMatcherTest.java vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/ResultsRendererTest.java vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/VmCriterionTest.java vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/VmMatcherTest.java vm-find/distribution/thermostat-plugin.xml
diffstat 18 files changed, 283 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/AbstractMatcher.java	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/AbstractMatcher.java	Wed Aug 19 10:11:52 2015 -0400
@@ -44,7 +44,7 @@
     protected final Map<CriterionMatcher, String> criteriaMap = new HashMap<>();
 
     @Override
-    public boolean match(MatchContext matchContext) {
+    public boolean match(MatchContext matchContext) throws UnrecognizedArgumentException {
         for (Map.Entry<? extends CriterionMatcher, String> entry : criteriaMap.entrySet()) {
             boolean match = entry.getKey().match(matchContext, entry.getValue());
             if (!match) {
--- a/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/CriterionMatcher.java	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/CriterionMatcher.java	Wed Aug 19 10:11:52 2015 -0400
@@ -38,6 +38,6 @@
 
 interface CriterionMatcher {
 
-    boolean match(MatchContext matchContext, String string);
+    boolean match(MatchContext matchContext, String string) throws UnrecognizedArgumentException;
 
 }
--- a/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/FindVmCommand.java	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/FindVmCommand.java	Wed Aug 19 10:11:52 2015 -0400
@@ -152,11 +152,11 @@
     }
 
     static List<MatchContext> performSearch(HostInfoDAO hostInfoDAO, VmInfoDAO vmInfoDAO,
-             Iterable<AgentInformation> agents, HostMatcher hostMatcher, VmMatcher vmMatcher) {
+             Iterable<AgentInformation> agents, HostMatcher hostMatcher, VmMatcher vmMatcher) throws UnrecognizedArgumentException {
         List<MatchContext> matchContexts = new ArrayList<>();
         for (AgentInformation agentInformation : filterAgents(hostInfoDAO, agents, hostMatcher)) {
             HostInfo hostInfo = getHostInfo(hostInfoDAO, agentInformation);
-            List<VmInfo> matchingVms = getMatchingVms(hostInfoDAO, vmInfoDAO, agentInformation, hostInfo, vmMatcher);
+            List<VmInfo> matchingVms = getMatchingVms(vmInfoDAO, agentInformation, hostInfo, vmMatcher);
             for (VmInfo vm : matchingVms) {
                 MatchContext context = MatchContext.builder()
                         .agentInfo(agentInformation)
@@ -169,7 +169,7 @@
         return matchContexts;
     }
 
-    static List<AgentInformation> filterAgents(HostInfoDAO hostInfoDAO, Iterable<AgentInformation> agents, HostMatcher hostMatcher) {
+    static List<AgentInformation> filterAgents(HostInfoDAO hostInfoDAO, Iterable<AgentInformation> agents, HostMatcher hostMatcher) throws UnrecognizedArgumentException {
         List<AgentInformation> list = new ArrayList<>();
         for (AgentInformation agent : agents) {
             HostInfo hostInfo = hostInfoDAO.getHostInfo(new HostRef(agent.getAgentId(), "dummy"));
@@ -188,8 +188,7 @@
         return hostInfoDAO.getHostInfo(new HostRef(agentInformation.getAgentId(), "dummy"));
     }
 
-    static List<VmInfo> getMatchingVms(HostInfoDAO hostInfoDAO, VmInfoDAO vmInfoDAO,
-                                AgentInformation agent, HostInfo hostInfo, VmMatcher vmMatcher) {
+    static List<VmInfo> getMatchingVms(VmInfoDAO vmInfoDAO, AgentInformation agent, HostInfo hostInfo, VmMatcher vmMatcher) throws UnrecognizedArgumentException {
         List<VmInfo> list = new ArrayList<>();
         for (VmRef vmRef : vmInfoDAO.getVMs(new HostRef(agent.getAgentId(), "dummy"))) {
             VmInfo vmInfo = vmInfoDAO.getVmInfo(vmRef);
--- a/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/HostCriterion.java	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/HostCriterion.java	Wed Aug 19 10:11:52 2015 -0400
@@ -51,7 +51,7 @@
     }
 
     @Override
-    public boolean match(MatchContext matchContext, String value) {
+    public boolean match(MatchContext matchContext, String value) throws UnrecognizedArgumentException {
         return this.criterionMatcher.match(matchContext, value);
     }
 
--- a/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/Matcher.java	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/Matcher.java	Wed Aug 19 10:11:52 2015 -0400
@@ -38,6 +38,6 @@
 
 interface Matcher {
 
-    boolean match(MatchContext matchContext);
+    boolean match(MatchContext matchContext) throws UnrecognizedArgumentException;
 
 }
--- a/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/ResultsRenderer.java	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/ResultsRenderer.java	Wed Aug 19 10:11:52 2015 -0400
@@ -52,6 +52,7 @@
     enum Field {
         VM_ID("show-vm-ids", new VmIdFieldAdapter()),
         MAINCLASS("show-mainclasses", new MainClassFieldAdapter()),
+        VMSTATUS("show-vmstatuses", new VmStatusFieldAdapter()),
         VMNAME("show-vmnames", new VmNameFieldAdapter()),
         JAVAVERSION("show-javaversions", new JavaVersionFieldAdapter()),
         VMVERSION("show-vmversions", new VmVersionFieldAdapter()),
@@ -148,6 +149,13 @@
         }
     }
 
+    static class VmStatusFieldAdapter implements FieldAdapter {
+        @Override
+        public String map(MatchContext matchContext) {
+            return matchContext.getVmInfo().isAlive(matchContext.getAgentInfo()).toString().toUpperCase();
+        }
+    }
+
     static class VmNameFieldAdapter implements FieldAdapter {
         @Override
         public String map(MatchContext matchContext) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/UnrecognizedArgumentException.java	Wed Aug 19 10:11:52 2015 -0400
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2012-2016 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.vm.find.command.internal;
+
+import com.redhat.thermostat.common.cli.CommandException;
+import com.redhat.thermostat.shared.locale.Translate;
+import com.redhat.thermostat.vm.find.command.locale.LocaleResources;
+
+import java.util.Collection;
+
+public class UnrecognizedArgumentException extends CommandException {
+
+    public UnrecognizedArgumentException(Translate<LocaleResources> translator, String commandName, String argumentName, String providedValue, Collection<String> acceptedValues) {
+        super(translator.localize(LocaleResources.UNRECOGNIZED_ARGUMENT, commandName, argumentName, providedValue, acceptedValues.toString()));
+    }
+
+}
--- a/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/VmCriterion.java	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/VmCriterion.java	Wed Aug 19 10:11:52 2015 -0400
@@ -36,14 +36,20 @@
 
 package com.redhat.thermostat.vm.find.command.internal;
 
+import com.redhat.thermostat.storage.model.VmInfo;
+import com.redhat.thermostat.vm.find.command.locale.LocaleResources;
+
 import java.nio.file.InvalidPathException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.regex.PatternSyntaxException;
 
 enum VmCriterion implements CriterionMatcher {
     JAVA_VERSION("javaversion", new JavaVersionMatcher()),
     MAINCLASS("mainclass", new MainclassMatcher()),
+    VM_STATUS("vmstatus", new VmStatusMatcher()),
     VM_NAME("vmname", new VmNameMatcher()),
     VM_ARGS("vmargs", new VmArgsMatcher()),
     VM_VERSION("vmversion", new VmVersionMatcher()),
@@ -60,7 +66,7 @@
     }
 
     @Override
-    public boolean match(MatchContext matchContext, String value) {
+    public boolean match(MatchContext matchContext, String value) throws UnrecognizedArgumentException {
         return this.criterionMatcher.match(matchContext, value);
     }
 
@@ -96,6 +102,38 @@
         }
     }
 
+    static class VmStatusMatcher implements CriterionMatcher {
+        @Override
+        public boolean match(MatchContext matchContext, String string) throws UnrecognizedArgumentException {
+            if (!isRecognizedValue(string)) {
+                throw new UnrecognizedArgumentException(LocaleResources.createTranslator(),
+                        FindVmCommand.REGISTER_NAME, "--" + VM_STATUS.getCliSwitch(), string, getAcceptedValues());
+            }
+
+            VmInfo.AliveStatus status = matchContext.getVmInfo().isAlive(matchContext.getAgentInfo());
+            return status.toString().equalsIgnoreCase(string);
+        }
+
+        private static boolean isRecognizedValue(String s) {
+            boolean matched = false;
+            for (VmInfo.AliveStatus status : VmInfo.AliveStatus.values()) {
+                matched = status.toString().equalsIgnoreCase(s);
+                if (matched) {
+                    break;
+                }
+            }
+            return matched;
+        }
+
+        private static List<String> getAcceptedValues() {
+            List<String> list = new ArrayList<>();
+            for (VmInfo.AliveStatus status : VmInfo.AliveStatus.values()) {
+                list.add(status.toString().toUpperCase());
+            }
+            return list;
+        }
+    }
+
     static class VmNameMatcher implements CriterionMatcher {
         @Override
         public boolean match(MatchContext matchContext, String s) {
--- a/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/locale/LocaleResources.java	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/locale/LocaleResources.java	Wed Aug 19 10:11:52 2015 -0400
@@ -46,6 +46,7 @@
     VM_SERVICE_UNAVAILABLE,
     NO_CRITERIA_GIVEN,
     AGENT_FLAGS_CLASH,
+    UNRECOGNIZED_ARGUMENT,
     ;
 
     static final String RESOURCE_BUNDLE =
--- a/vm-find/command/src/main/resources/com/redhat/thermostat/vm/find/command/locale/strings.properties	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/main/resources/com/redhat/thermostat/vm/find/command/locale/strings.properties	Wed Aug 19 10:11:52 2015 -0400
@@ -3,4 +3,5 @@
 HOST_SERVICE_UNAVAILABLE = Unable to get host information (HostInfoDAO is unavailable)
 VM_SERVICE_UNAVAILABLE = Unable to get vm information (VmInfoDAO is unavailable)
 NO_CRITERIA_GIVEN = No filtering criteria were specified
-AGENT_FLAGS_CLASH = --{0} and --{1} cannot be used in conjunction
\ No newline at end of file
+AGENT_FLAGS_CLASH = --{0} and --{1} cannot be used in conjunction
+UNRECOGNIZED_ARGUMENT = {0} {1} does not recognize provided argument "{2}". Expected: {3}
\ No newline at end of file
--- a/vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/AbstractMatcherTest.java	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/AbstractMatcherTest.java	Wed Aug 19 10:11:52 2015 -0400
@@ -57,7 +57,7 @@
     }
 
     @Test
-    public void testMatch() {
+    public void testMatch() throws UnrecognizedArgumentException {
         AbstractMatcher matcher = new TestMatcher();
         AgentInformation fooAgent = new AgentInformation("foo");
         AgentInformation barAgent = new AgentInformation("bar");
--- a/vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/FindVmCommandTest.java	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/FindVmCommandTest.java	Wed Aug 19 10:11:52 2015 -0400
@@ -36,7 +36,6 @@
 
 package com.redhat.thermostat.vm.find.command.internal;
 
-import com.redhat.thermostat.common.Pair;
 import com.redhat.thermostat.common.cli.Arguments;
 import com.redhat.thermostat.common.cli.CommandException;
 import com.redhat.thermostat.storage.core.HostRef;
@@ -50,7 +49,6 @@
 import com.redhat.thermostat.test.TestCommandContextFactory;
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.internal.runners.statements.InvokeMethod;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
@@ -410,7 +408,7 @@
     }
 
     @Test
-    public void testPerformSearch() {
+    public void testPerformSearch() throws UnrecognizedArgumentException {
         AgentInformation agentInfo1 = new AgentInformation("agentInfo1");
         HostRef hostRef1 = new HostRef(agentInfo1.getAgentId(), "dummy");
         AgentInformation agentInfo2 = new AgentInformation("agentInfo2");
@@ -544,7 +542,7 @@
     }
 
     @Test
-    public void testFilterAgents() {
+    public void testFilterAgents() throws UnrecognizedArgumentException {
         AgentInformation foo = new AgentInformation("foo");
         HostRef fooRef = new HostRef(foo.getAgentId(), "dummy");
         AgentInformation bar = new AgentInformation("bar");
@@ -579,7 +577,7 @@
     }
 
     @Test
-    public void testGetMatchingVms() {
+    public void testGetMatchingVms() throws UnrecognizedArgumentException {
         AgentInformation agent = new AgentInformation("agent");
         HostRef hostRef = new HostRef(agent.getAgentId(), "dummy");
 
@@ -627,25 +625,25 @@
         command.setVmInfoDAO(vmInfoDAO);
 
         VmMatcher allMatcher = new VmMatcher(Collections.<String, String>emptyMap());
-        List<VmInfo> all = FindVmCommand.getMatchingVms(hostInfoDAO, vmInfoDAO, agent, hostInfo, allMatcher);
+        List<VmInfo> all = FindVmCommand.getMatchingVms(vmInfoDAO, agent, hostInfo, allMatcher);
         assertThat(all, is(equalTo(Arrays.asList(vmInfo1, vmInfo2, vmInfo3))));
 
         Map<String, String> userMap = new HashMap<>();
         userMap.put("username", "foo-user");
         VmMatcher userMatcher = new VmMatcher(userMap);
-        List<VmInfo> users = FindVmCommand.getMatchingVms(hostInfoDAO, vmInfoDAO, agent, hostInfo, userMatcher);
+        List<VmInfo> users = FindVmCommand.getMatchingVms(vmInfoDAO, agent, hostInfo, userMatcher);
         assertThat(users, is(equalTo(Collections.singletonList(vmInfo1))));
 
         Map<String, String> versionMap = new HashMap<>();
         versionMap.put("javaversion", "1.8");
         VmMatcher versionMatcher = new VmMatcher(versionMap);
-        List<VmInfo> versions = FindVmCommand.getMatchingVms(hostInfoDAO, vmInfoDAO, agent, hostInfo, versionMatcher);
+        List<VmInfo> versions = FindVmCommand.getMatchingVms(vmInfoDAO, agent, hostInfo, versionMatcher);
         assertThat(versions, is(equalTo(Arrays.asList(vmInfo1, vmInfo2))));
 
         Map<String, String> noneMap = new HashMap<>();
         noneMap.put("javaversion", "1.0");
         VmMatcher noneMatcher = new VmMatcher(noneMap);
-        List<VmInfo> none = FindVmCommand.getMatchingVms(hostInfoDAO, vmInfoDAO, agent, hostInfo, noneMatcher);
+        List<VmInfo> none = FindVmCommand.getMatchingVms(vmInfoDAO, agent, hostInfo, noneMatcher);
         assertThat(none, is(equalTo(Collections.<VmInfo>emptyList())));
     }
 
--- a/vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/HostCriterionTest.java	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/HostCriterionTest.java	Wed Aug 19 10:11:52 2015 -0400
@@ -45,7 +45,7 @@
 public class HostCriterionTest {
 
     @Test
-    public void testHostname() {
+    public void testHostname() throws UnrecognizedArgumentException {
         HostCriterion hostCriterion = HostCriterion.HOSTNAME;
         HostInfo hostInfo = new HostInfo();
         hostInfo.setHostname("foo");
@@ -58,7 +58,7 @@
     }
 
     @Test
-    public void testOsKernel() {
+    public void testOsKernel() throws UnrecognizedArgumentException {
         HostCriterion hostCriterion = HostCriterion.OS_KERNEL;
         HostInfo hostInfo = new HostInfo();
         hostInfo.setOsKernel("foo");
@@ -71,7 +71,7 @@
     }
 
     @Test
-    public void testOsName() {
+    public void testOsName() throws UnrecognizedArgumentException {
         HostCriterion hostCriterion = HostCriterion.OS_NAME;
         HostInfo hostInfo = new HostInfo();
         hostInfo.setOsName("foo");
--- a/vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/HostMatcherTest.java	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/HostMatcherTest.java	Wed Aug 19 10:11:52 2015 -0400
@@ -48,7 +48,7 @@
 public class HostMatcherTest {
 
     @Test
-    public void testTestMatch() {
+    public void testTestMatch() throws UnrecognizedArgumentException {
         Map<String, String> map = new HashMap<>();
         map.put("hostname", "foo");
         map.put("osname", "bar");
--- a/vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/ResultsRendererTest.java	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/ResultsRendererTest.java	Wed Aug 19 10:11:52 2015 -0400
@@ -73,8 +73,8 @@
         HOST_INFO.setOsKernel("foo-kern");
 
         AGENT_INFO.setAlive(true);
-        AGENT_INFO.setStartTime(150l);
-        AGENT_INFO.setStopTime(100l);
+        AGENT_INFO.setStartTime(50l);
+        AGENT_INFO.setStopTime(-1l);
         AGENT_INFO.setAgentId("foo-agent");
 
         VM_INFO.setJavaHome("/some/path/to/jdk");
@@ -86,6 +86,8 @@
         VM_INFO.setVmId("foo-id");
         VM_INFO.setVmName("Example JVM Implementation");
         VM_INFO.setVmPid(2);
+        VM_INFO.setStartTimeStamp(100l);
+        VM_INFO.setStopTimeStamp(-1l);
     }
 
     @Test
@@ -103,6 +105,13 @@
     }
 
     @Test
+    public void testVmStatus() {
+        ResultsRenderer.Field field = ResultsRenderer.Field.VMSTATUS;
+        String result = field.getAdaptedField(MATCH_CONTEXT);
+        assertThat(result, containsString("RUNNING"));
+    }
+
+    @Test
     public void testVmName() {
         ResultsRenderer.Field field = ResultsRenderer.Field.VMNAME;
         String result = field.getAdaptedField(MATCH_CONTEXT);
--- a/vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/VmCriterionTest.java	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/VmCriterionTest.java	Wed Aug 19 10:11:52 2015 -0400
@@ -36,6 +36,7 @@
 
 package com.redhat.thermostat.vm.find.command.internal;
 
+import com.redhat.thermostat.storage.model.AgentInformation;
 import com.redhat.thermostat.storage.model.VmInfo;
 import org.junit.Test;
 
@@ -45,7 +46,7 @@
 public class VmCriterionTest {
 
     @Test
-    public void testJavaVersion() {
+    public void testJavaVersion() throws UnrecognizedArgumentException {
         VmCriterion criterion = VmCriterion.JAVA_VERSION;
         VmInfo vmInfo = new VmInfo();
         vmInfo.setJavaVersion("1.8");
@@ -60,7 +61,7 @@
     }
 
     @Test
-    public void testMainClass() {
+    public void testMainClass() throws UnrecognizedArgumentException {
         VmCriterion criterion = VmCriterion.MAINCLASS;
         VmInfo vmInfo = new VmInfo();
         vmInfo.setMainClass("com.example.java.ExampleApplet");
@@ -80,7 +81,138 @@
     }
 
     @Test
-    public void testVmName() {
+    public void testVmStatusWithRunningVM() throws UnrecognizedArgumentException {
+        VmCriterion criterion = VmCriterion.VM_STATUS;
+        VmInfo vmInfo = new VmInfo();
+        vmInfo.setStartTimeStamp(100l);
+        vmInfo.setStopTimeStamp(-1l);
+        AgentInformation agentInfo = new AgentInformation();
+        agentInfo.setStartTime(50l);
+        agentInfo.setStopTime(-1l);
+        agentInfo.setAlive(true);
+        MatchContext matchContext = MatchContext.builder().vmInfo(vmInfo).agentInfo(agentInfo).build();
+        assertThat(criterion.match(matchContext, "RUNNING"), is(true));
+        assertThat(criterion.match(matchContext, "RuNnInG"), is(true));
+        assertThat(criterion.match(matchContext, "running"), is(true));
+        assertThat(criterion.match(matchContext, "EXITED"), is(false));
+        assertThat(criterion.match(matchContext, "ExItEd"), is(false));
+        assertThat(criterion.match(matchContext, "exited"), is(false));
+        assertThat(criterion.match(matchContext, "UNKNOWN"), is(false));
+        assertThat(criterion.match(matchContext, "UnKnOwN"), is(false));
+        assertThat(criterion.match(matchContext, "unknown"), is(false));
+    }
+
+    @Test
+    public void testVmStatusWithExitedVM() throws UnrecognizedArgumentException {
+        VmCriterion criterion = VmCriterion.VM_STATUS;
+        VmInfo vmInfo = new VmInfo();
+        vmInfo.setStartTimeStamp(100l);
+        vmInfo.setStopTimeStamp(150l);
+        AgentInformation agentInfo = new AgentInformation();
+        agentInfo.setStartTime(50l);
+        agentInfo.setStopTime(-1l);
+        agentInfo.setAlive(true);
+        MatchContext matchContext = MatchContext.builder().vmInfo(vmInfo).agentInfo(agentInfo).build();
+        assertThat(criterion.match(matchContext, "RUNNING"), is(false));
+        assertThat(criterion.match(matchContext, "RuNnInG"), is(false));
+        assertThat(criterion.match(matchContext, "running"), is(false));
+        assertThat(criterion.match(matchContext, "EXITED"), is(true));
+        assertThat(criterion.match(matchContext, "ExItEd"), is(true));
+        assertThat(criterion.match(matchContext, "exited"), is(true));
+        assertThat(criterion.match(matchContext, "UNKNOWN"), is(false));
+        assertThat(criterion.match(matchContext, "UnKnOwN"), is(false));
+        assertThat(criterion.match(matchContext, "unknown"), is(false));
+    }
+
+    @Test
+    public void testVmStatusWithExitedVMAndDeadAgent() throws UnrecognizedArgumentException {
+        VmCriterion criterion = VmCriterion.VM_STATUS;
+        VmInfo vmInfo = new VmInfo();
+        vmInfo.setStartTimeStamp(100l);
+        vmInfo.setStopTimeStamp(150l);
+        AgentInformation agentInfo = new AgentInformation();
+        agentInfo.setStartTime(50l);
+        agentInfo.setStopTime(125l);
+        agentInfo.setAlive(false);
+        MatchContext matchContext = MatchContext.builder().vmInfo(vmInfo).agentInfo(agentInfo).build();
+        assertThat(criterion.match(matchContext, "RUNNING"), is(false));
+        assertThat(criterion.match(matchContext, "RuNnInG"), is(false));
+        assertThat(criterion.match(matchContext, "running"), is(false));
+        assertThat(criterion.match(matchContext, "EXITED"), is(true));
+        assertThat(criterion.match(matchContext, "ExItEd"), is(true));
+        assertThat(criterion.match(matchContext, "exited"), is(true));
+        assertThat(criterion.match(matchContext, "UNKNOWN"), is(false));
+        assertThat(criterion.match(matchContext, "UnKnOwN"), is(false));
+        assertThat(criterion.match(matchContext, "unknown"), is(false));
+    }
+
+    @Test
+    public void testVmStatusWithRunningVMAndDeadAgent() throws UnrecognizedArgumentException {
+        VmCriterion criterion = VmCriterion.VM_STATUS;
+        VmInfo vmInfo = new VmInfo();
+        vmInfo.setStartTimeStamp(100l);
+        vmInfo.setStopTimeStamp(-1l);
+        AgentInformation agentInfo = new AgentInformation();
+        agentInfo.setStartTime(50l);
+        agentInfo.setStopTime(125l);
+        agentInfo.setAlive(false);
+        MatchContext matchContext = MatchContext.builder().vmInfo(vmInfo).agentInfo(agentInfo).build();
+        assertThat(criterion.match(matchContext, "RUNNING"), is(false));
+        assertThat(criterion.match(matchContext, "RuNnInG"), is(false));
+        assertThat(criterion.match(matchContext, "running"), is(false));
+        assertThat(criterion.match(matchContext, "EXITED"), is(false));
+        assertThat(criterion.match(matchContext, "ExItEd"), is(false));
+        assertThat(criterion.match(matchContext, "exited"), is(false));
+        assertThat(criterion.match(matchContext, "UNKNOWN"), is(true));
+        assertThat(criterion.match(matchContext, "UnKnOwN"), is(true));
+        assertThat(criterion.match(matchContext, "unknown"), is(true));
+    }
+
+    @Test(expected = UnrecognizedArgumentException.class)
+    public void testVmStatusDoesNotAcceptSubstrings() throws UnrecognizedArgumentException {
+        VmCriterion criterion = VmCriterion.VM_STATUS;
+        VmInfo vmInfo = new VmInfo();
+        vmInfo.setStartTimeStamp(100l);
+        vmInfo.setStopTimeStamp(-1l);
+        AgentInformation agentInfo = new AgentInformation();
+        agentInfo.setStartTime(50l);
+        agentInfo.setStopTime(-1l);
+        agentInfo.setAlive(true);
+        MatchContext matchContext = MatchContext.builder().vmInfo(vmInfo).agentInfo(agentInfo).build();
+        criterion.match(matchContext, "RUN");
+    }
+
+    @Test(expected = UnrecognizedArgumentException.class)
+    public void testVmStatusDoesNotAcceptSubstrings2() throws UnrecognizedArgumentException {
+        VmCriterion criterion = VmCriterion.VM_STATUS;
+        VmInfo vmInfo = new VmInfo();
+        vmInfo.setStartTimeStamp(100l);
+        vmInfo.setStopTimeStamp(-1l);
+        AgentInformation agentInfo = new AgentInformation();
+        agentInfo.setStartTime(50l);
+        agentInfo.setStopTime(-1l);
+        agentInfo.setAlive(true);
+        MatchContext matchContext = MatchContext.builder().vmInfo(vmInfo).agentInfo(agentInfo).build();
+        criterion.match(matchContext, "EXIT");
+    }
+
+
+    @Test(expected = UnrecognizedArgumentException.class)
+    public void testVmStatusDoesNotAcceptSubstrings3() throws UnrecognizedArgumentException {
+        VmCriterion criterion = VmCriterion.VM_STATUS;
+        VmInfo vmInfo = new VmInfo();
+        vmInfo.setStartTimeStamp(100l);
+        vmInfo.setStopTimeStamp(-1l);
+        AgentInformation agentInfo = new AgentInformation();
+        agentInfo.setStartTime(50l);
+        agentInfo.setStopTime(-1l);
+        agentInfo.setAlive(true);
+        MatchContext matchContext = MatchContext.builder().vmInfo(vmInfo).agentInfo(agentInfo).build();
+        criterion.match(matchContext, "UNK");
+    }
+
+    @Test
+    public void testVmName() throws UnrecognizedArgumentException {
         VmCriterion criterion = VmCriterion.VM_NAME;
         VmInfo vmInfo = new VmInfo();
         vmInfo.setVmName("Example JVM Implementation Name");
@@ -93,7 +225,7 @@
     }
 
     @Test
-    public void testVmArgs() {
+    public void testVmArgs() throws UnrecognizedArgumentException {
         VmCriterion criterion = VmCriterion.VM_ARGS;
         VmInfo vmInfo = new VmInfo();
         vmInfo.setVmArguments("-Xmx1024M -Xms1024M");
@@ -110,7 +242,7 @@
     }
 
     @Test
-    public void testVmVersion() {
+    public void testVmVersion() throws UnrecognizedArgumentException {
         VmCriterion criterion = VmCriterion.VM_VERSION;
         VmInfo vmInfo = new VmInfo();
         vmInfo.setVmVersion("20.5.6");
@@ -125,7 +257,7 @@
     }
 
     @Test
-    public void testUsername() {
+    public void testUsername() throws UnrecognizedArgumentException {
         VmCriterion criterion = VmCriterion.USERNAME;
         VmInfo vmInfo = new VmInfo();
         vmInfo.setUsername("foo-user");
@@ -138,7 +270,7 @@
     }
 
     @Test
-    public void testJavahome() {
+    public void testJavahome() throws UnrecognizedArgumentException {
         VmCriterion criterion = VmCriterion.JAVA_HOME;
         VmInfo vmInfo = new VmInfo();
         vmInfo.setJavaHome("/some/filesystem/path/to/jdk");
--- a/vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/VmMatcherTest.java	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/command/src/test/java/com/redhat/thermostat/vm/find/command/internal/VmMatcherTest.java	Wed Aug 19 10:11:52 2015 -0400
@@ -48,7 +48,7 @@
 public class VmMatcherTest {
 
     @Test
-    public void testTestMatch() {
+    public void testTestMatch() throws UnrecognizedArgumentException {
         Map<String, String> map = new HashMap<>();
         map.put("username", "foo-user");
         VmMatcher matcher = new VmMatcher(map);
--- a/vm-find/distribution/thermostat-plugin.xml	Tue Aug 18 11:15:33 2015 -0400
+++ b/vm-find/distribution/thermostat-plugin.xml	Wed Aug 19 10:11:52 2015 -0400
@@ -77,6 +77,10 @@
           <description>enable display of mainclass</description>
         </option>
         <option>
+          <long>show-vmstatuses</long>
+          <description>enable display of VM statuses (RUNNING, EXITED, UNKNOWN)</description>
+        </option>
+        <option>
           <long>show-vmnames</long>
           <description>enable display of VM names</description>
         </option>
@@ -129,6 +133,13 @@
           <description>the main class the VM is running. Can be fully qualified name, substring, or regular expression</description>
         </option>
         <option>
+          <long>vmstatus</long>
+          <short>s</short>
+          <argument>status</argument>
+          <required>false</required>
+          <description>the status of the VM. Can be RUNNING, EXITED, or UNKNOWN, case insensitive</description>
+        </option>
+        <option>
           <long>vmname</long>
           <short>n</short>
           <argument>name</argument>