changeset 1897:6992e3f505a2

Disable "check for deadlock" button for dead VMs Reviewed-by: omajid, jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-November/016880.html Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-May/019049.html PR2987
author Andrew Azores <aazores@redhat.com>
date Wed, 01 Jun 2016 10:53:59 -0400
parents 73ee1b3b2d4c
children cdf0c0c66db6
files thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/view/VmDeadLockView.java thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationController.java thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/VmDeadLockController.java thread/client-controllers/src/test/java/com/redhat/thermostat/thread/client/controller/impl/VmDeadLockControllerTest.java thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingVmDeadLockView.java
diffstat 5 files changed, 61 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/view/VmDeadLockView.java	Wed Jun 01 09:49:51 2016 -0400
+++ b/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/view/VmDeadLockView.java	Wed Jun 01 10:53:59 2016 -0400
@@ -64,5 +64,7 @@
 
     public abstract void setDeadLockInformation(Information parsed, String rawText);
 
+    public abstract void setCheckDeadlockControlEnabled(boolean enabled);
+
 }
 
--- a/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationController.java	Wed Jun 01 09:49:51 2016 -0400
+++ b/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationController.java	Wed Jun 01 10:53:59 2016 -0400
@@ -64,6 +64,9 @@
 
     private static final Logger logger = LoggingUtils.getLogger(ThreadInformationController.class);
     private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer();
+
+    private VmRef ref;
+    private VmInfoDAO vmInfoDAO;
     
     private ThreadView view;
     private ThreadCollector collector;
@@ -79,7 +82,9 @@
                                        ProgressNotifier notifier)
     {
         this.appService = appService;
+        this.ref = ref;
         this.notifier = notifier;
+        this.vmInfoDAO = vmInfoDao;
 
         view = viewFactory.createView();
         view.setApplicationService(appService, ref.getVmId() + "-" + ref.getHostRef().getAgentId());
@@ -191,7 +196,7 @@
         TimerFactory tf = appService.getTimerFactory();
 
         VmDeadLockController deadLockController =
-                new VmDeadLockController(view.createDeadLockView(), collector, tf.createTimer(),
+                new VmDeadLockController(vmInfoDAO, ref, view.createDeadLockView(), collector, tf.createTimer(),
                         appService.getApplicationExecutor(), notifier);
         deadLockController.initialize();
 
--- a/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/VmDeadLockController.java	Wed Jun 01 09:49:51 2016 -0400
+++ b/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/VmDeadLockController.java	Wed Jun 01 10:53:59 2016 -0400
@@ -53,6 +53,8 @@
 import com.redhat.thermostat.common.Timer.SchedulingType;
 import com.redhat.thermostat.shared.locale.LocalizedString;
 import com.redhat.thermostat.shared.locale.Translate;
+import com.redhat.thermostat.storage.core.VmRef;
+import com.redhat.thermostat.storage.dao.VmInfoDAO;
 import com.redhat.thermostat.thread.client.common.DeadlockParser;
 import com.redhat.thermostat.thread.client.common.DeadlockParser.Information;
 import com.redhat.thermostat.thread.client.common.DeadlockParser.ParseException;
@@ -67,6 +69,9 @@
 
     private static final String NO_DEADLOCK = translate.localize(LocaleResources.NO_DEADLOCK_DETECTED).getContents();
 
+    private VmInfoDAO vmInfoDAO;
+    private VmRef vmRef;
+
     private VmDeadLockView view;
     private ThreadCollector collector;
     private Timer timer;
@@ -77,8 +82,10 @@
     private String previousDeadlockData = null;
 
 
-    public VmDeadLockController(VmDeadLockView view, ThreadCollector collector, Timer timer,
-            ExecutorService executor, ProgressNotifier notifier) {
+    public VmDeadLockController(VmInfoDAO vmInfoDAO, VmRef vmRef, VmDeadLockView view, ThreadCollector collector, Timer timer,
+                                ExecutorService executor, ProgressNotifier notifier) {
+        this.vmInfoDAO = vmInfoDAO;
+        this.vmRef = vmRef;
         this.view = view;
         this.collector = collector;
         this.timer = timer;
@@ -142,6 +149,8 @@
                 }
             }
         });
+
+        view.setCheckDeadlockControlEnabled(vmInfoDAO.getVmInfo(vmRef).isAlive());
     }
 
     private void checkForDeadLock() {
--- a/thread/client-controllers/src/test/java/com/redhat/thermostat/thread/client/controller/impl/VmDeadLockControllerTest.java	Wed Jun 01 09:49:51 2016 -0400
+++ b/thread/client-controllers/src/test/java/com/redhat/thermostat/thread/client/controller/impl/VmDeadLockControllerTest.java	Wed Jun 01 10:53:59 2016 -0400
@@ -36,24 +36,23 @@
 
 package com.redhat.thermostat.thread.client.controller.impl;
 
-import static org.mockito.Matchers.anyString;
 import static org.mockito.Matchers.isA;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
 
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
 
+import com.redhat.thermostat.storage.core.VmRef;
+import com.redhat.thermostat.storage.dao.VmInfoDAO;
+import com.redhat.thermostat.storage.model.VmInfo;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 
-import com.redhat.thermostat.client.core.progress.ProgressHandle;
 import com.redhat.thermostat.client.core.progress.ProgressNotifier;
 import com.redhat.thermostat.client.core.views.BasicView;
 import com.redhat.thermostat.client.core.views.BasicView.Action;
@@ -68,6 +67,9 @@
 
 public class VmDeadLockControllerTest {
 
+    private VmInfoDAO vmInfoDao;
+    private VmInfo vmInfo;
+    private VmRef vmRef;
     private Timer timer;
     private VmDeadLockView view;
     private ThreadCollector collector;
@@ -78,6 +80,14 @@
 
     @Before
     public void setUp() {
+        vmInfoDao = mock(VmInfoDAO.class);
+
+        vmInfo = mock(VmInfo.class);
+        when(vmInfoDao.getVmInfo(isA(VmRef.class))).thenReturn(vmInfo);
+        when(vmInfo.isAlive()).thenReturn(true);
+
+        vmRef = mock(VmRef.class);
+
         timer = mock(Timer.class);
 
         view = mock(VmDeadLockView.class);
@@ -88,7 +98,7 @@
 
         notifier = mock(ProgressNotifier.class);
 
-        controller = new VmDeadLockController(view, collector, timer, executor, notifier);
+        controller = new VmDeadLockController(vmInfoDao, vmRef, view, collector, timer, executor, notifier);
     }
 
     @Test
@@ -218,5 +228,18 @@
 
         // pass if no exceptions thrown
     }
+
+    @Test
+    public void verifyDeadlockControlEnabledWhenVmAlive() {
+        controller.initialize();
+        verify(view).setCheckDeadlockControlEnabled(true);
+    }
+
+    @Test
+    public void verifyDeadlockControlDisabledWhenVmDead() {
+        when(vmInfo.isAlive()).thenReturn(false);
+        controller.initialize();
+        verify(view).setCheckDeadlockControlEnabled(false);
+    }
 }
 
--- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingVmDeadLockView.java	Wed Jun 01 09:49:51 2016 -0400
+++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingVmDeadLockView.java	Wed Jun 01 10:53:59 2016 -0400
@@ -79,12 +79,12 @@
     private static final Translate<LocaleResources> translate = LocaleResources.createLocalizer();
 
     private final JPanel actualComponent = new JPanel();
+    private final JButton checkForDeadlockButton;
 
     private final JSplitPane deadlockTextAndVisualization = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
 
     private final JPanel graphical = new JPanel();
     private final ThermostatTextArea description = new ThermostatTextArea();
-
     /**
      * Whether to set the divider's location. Do this only once to set a sane
      * initial value but don't change anything after and allow the user to tweak
@@ -98,15 +98,15 @@
         GridBagConstraints c = new GridBagConstraints();
         c.gridy = 0;
         c.anchor = GridBagConstraints.LINE_END;
-        JButton recheckButton = new JButton(translate.localize(LocaleResources.CHECK_FOR_DEADLOCKS).getContents());
-        recheckButton.addActionListener(new ActionListener() {
+        checkForDeadlockButton = new JButton(translate.localize(LocaleResources.CHECK_FOR_DEADLOCKS).getContents());
+        checkForDeadlockButton.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
                 deadLockNotifier.fireAction(VmDeadLockViewAction.CHECK_FOR_DEADLOCK);
             }
         });
 
-        actualComponent.add(recheckButton, c);
+        actualComponent.add(checkForDeadlockButton, c);
 
         c.anchor = GridBagConstraints.LINE_START;
         c.gridy++;
@@ -215,6 +215,16 @@
         return graphComponent;
     }
 
+    @Override
+    public void setCheckDeadlockControlEnabled(final boolean enabled) {
+        SwingUtilities.invokeLater(new Runnable() {
+            @Override
+            public void run() {
+                SwingVmDeadLockView.this.checkForDeadlockButton.setEnabled(enabled);
+            }
+        });
+    }
+
     private static void addDeadlockToGraph(Information info, mxGraph graph, Object parent, FontMetrics metrics) {
         graph.getModel().beginUpdate(); // batch updates
         try {