changeset 1768:3cb516445ee5

Avoid using HostVMArguments in kill-vm. Alterations to kill-vm command to reflect avoidance of HostVMArguments. PR2455 Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-June/014231.html
author James Aziz <jaziz@redhat.com>
date Thu, 25 Jun 2015 09:58:54 -0400
parents 51debcf29b2c
children 688a79263a66
files killvm/command/src/main/java/com/redhat/thermostat/killvm/command/KillVMCommand.java killvm/command/src/main/java/com/redhat/thermostat/killvm/command/locale/LocaleResources.java killvm/command/src/main/resources/com/redhat/thermostat/killvm/command/locale/strings.properties
diffstat 3 files changed, 13 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/killvm/command/src/main/java/com/redhat/thermostat/killvm/command/KillVMCommand.java	Wed Jun 24 10:51:15 2015 -0400
+++ b/killvm/command/src/main/java/com/redhat/thermostat/killvm/command/KillVMCommand.java	Thu Jun 25 09:58:54 2015 -0400
@@ -36,7 +36,6 @@
 
 package com.redhat.thermostat.killvm.command;
 
-import com.redhat.thermostat.client.cli.HostVMArguments;
 import com.redhat.thermostat.common.cli.AbstractCommand;
 import com.redhat.thermostat.common.cli.CommandContext;
 import com.redhat.thermostat.common.cli.CommandException;
@@ -46,13 +45,14 @@
 import com.redhat.thermostat.shared.locale.Translate;
 import com.redhat.thermostat.storage.core.AgentId;
 import com.redhat.thermostat.storage.core.VmId;
-import com.redhat.thermostat.storage.core.VmRef;
 import com.redhat.thermostat.storage.dao.AgentInfoDAO;
 import com.redhat.thermostat.storage.dao.VmInfoDAO;
 import com.redhat.thermostat.storage.model.VmInfo;
 
 public class KillVMCommand extends AbstractCommand {
 
+    static final String VM_ID_ARGUMENT = "vmId";
+
     private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer();
 
     private final ShellVMKilledListener listener;
@@ -74,16 +74,17 @@
         listener.setOut(ctx.getConsole().getOutput());
         listener.setErr(ctx.getConsole().getError());
 
-        HostVMArguments args = new HostVMArguments(ctx.getArguments(), false, true);
+        String vmId = ctx.getArguments().getArgument(VM_ID_ARGUMENT);
+        if (vmId == null)
+            throw new CommandException(translator.localize(LocaleResources.VMID_REQUIRED));
 
-        attemptToKillVM(args.getVM());
+        attemptToKillVM(new VmId(vmId));
     }
 
-    private void attemptToKillVM(VmRef vmRef) throws CommandException {
-        VmId id = new VmId(vmRef.getVmId());
-        VmInfo result = vmInfoDAO.getVmInfo(id);
+    private void attemptToKillVM(VmId vmId) throws CommandException {
+        VmInfo result = vmInfoDAO.getVmInfo(vmId);
         if (result == null) {
-            throw new CommandException(translator.localize(LocaleResources.VM_NOT_FOUND, vmRef.getVmId()));
+            throw new CommandException(translator.localize(LocaleResources.VM_NOT_FOUND, vmId.get()));
         }
         sendKillRequest(new AgentId(result.getAgentId()), result.getVmPid());
     }
--- a/killvm/command/src/main/java/com/redhat/thermostat/killvm/command/locale/LocaleResources.java	Wed Jun 24 10:51:15 2015 -0400
+++ b/killvm/command/src/main/java/com/redhat/thermostat/killvm/command/locale/LocaleResources.java	Thu Jun 25 09:58:54 2015 -0400
@@ -45,7 +45,8 @@
     AGENT_SERVICE_UNAVAILABLE,
     REQUEST_SERVICE_UNAVAILABLE,
     KILL_INTERRUPTED,
-    VM_NOT_FOUND;
+    VM_NOT_FOUND,
+    VMID_REQUIRED;
 
     public static final String RESOURCE_BUNDLE =
             "com.redhat.thermostat.killvm.command.locale.strings";
--- a/killvm/command/src/main/resources/com/redhat/thermostat/killvm/command/locale/strings.properties	Wed Jun 24 10:51:15 2015 -0400
+++ b/killvm/command/src/main/resources/com/redhat/thermostat/killvm/command/locale/strings.properties	Thu Jun 25 09:58:54 2015 -0400
@@ -3,4 +3,5 @@
 AGENT_SERVICE_UNAVAILABLE = Unable to get agent information (AgentInfoDAO is unavailable)
 REQUEST_SERVICE_UNAVAILABLE = Unable to get request information (KillVMRequest is unavailable)
 KILL_INTERRUPTED = Command interrupted while waiting for response from murderer
-VM_NOT_FOUND = VM with ID {0} not found.
\ No newline at end of file
+VM_NOT_FOUND = VM with ID {0} not found.
+VMID_REQUIRED = A vmId is required
\ No newline at end of file