Mercurial > hg > release > thermostat-0.6
changeset 883:86a3f700aeac
Disable thread recording button for dead vms
Dead VMs can not be interacted with anymore. Disable the button that
starts thread recording in such cases.
Reviewd-by: rkennke
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-December/004405.html
PR1229
line wrap: on
line diff
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/ActionButtonUI.java Mon Dec 31 11:12:50 2012 -0500 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/ActionButtonUI.java Mon Dec 31 12:47:52 2012 -0500 @@ -39,6 +39,7 @@ import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.Image; import java.awt.Rectangle; import java.awt.Shape; import java.awt.image.BufferedImage; @@ -48,6 +49,7 @@ import javax.swing.AbstractButton; import javax.swing.ButtonModel; +import javax.swing.GrayFilter; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.plaf.metal.MetalButtonUI; @@ -59,6 +61,7 @@ private BufferedImage sourceIcon; private BufferedImage rollOverIcon; + private Image disabledIcon; ActionButtonUI() {} @@ -99,6 +102,10 @@ rollOverIcon = getBrighterImage(sourceIcon); } + if (disabledIcon == null) { + disabledIcon = GrayFilter.createDisabledImage(sourceIcon); + } + int x = 3; int y = button.getHeight() / 2 - h / 2; @@ -107,7 +114,9 @@ x = button.getWidth() / 2 - w / 2; } - if (model.isRollover()) { + if (!model.isEnabled()) { + g.drawImage(disabledIcon, x, y, null); + } else if (model.isRollover()) { g.drawImage(rollOverIcon, x, y, null); } else { g.drawImage(sourceIcon, x, y, null);
--- a/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/view/ThreadView.java Mon Dec 31 11:12:50 2012 -0500 +++ b/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/view/ThreadView.java Mon Dec 31 12:47:52 2012 -0500 @@ -67,6 +67,7 @@ notifier.removeActionListener(listener); } + public abstract void setEnableRecordingControl(boolean enable); public abstract void setRecording(boolean recording, boolean notify); public abstract VMThreadCapabilitiesView createVMThreadCapabilitiesView();
--- a/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationController.java Mon Dec 31 11:12:50 2012 -0500 +++ b/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationController.java Mon Dec 31 12:47:52 2012 -0500 @@ -45,6 +45,7 @@ import com.redhat.thermostat.common.ActionListener; import com.redhat.thermostat.common.ApplicationService; import com.redhat.thermostat.common.TimerFactory; +import com.redhat.thermostat.common.dao.VmInfoDAO; import com.redhat.thermostat.common.dao.VmRef; import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.thread.client.common.ThreadTableBean; @@ -66,6 +67,7 @@ private ApplicationService appService; public ThreadInformationController(VmRef ref, ApplicationService appService, + VmInfoDAO vmInfoDao, ThreadCollectorFactory collectorFactory, ThreadViewProvider viewFactory) { @@ -79,6 +81,10 @@ view.setRecording(isRecording(), false); view.addThreadActionListener(new ThreadActionListener()); + + if (!vmInfoDao.getVmInfo(ref).isAlive()) { + view.setEnableRecordingControl(false); + } } private boolean isRecording() {
--- a/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationService.java Mon Dec 31 11:12:50 2012 -0500 +++ b/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationService.java Mon Dec 31 12:47:52 2012 -0500 @@ -41,6 +41,7 @@ import com.redhat.thermostat.client.core.NameMatchingRefFilter; import com.redhat.thermostat.client.core.controllers.InformationServiceController; import com.redhat.thermostat.common.ApplicationService; +import com.redhat.thermostat.common.dao.VmInfoDAO; import com.redhat.thermostat.common.dao.VmRef; import com.redhat.thermostat.thread.client.common.ThreadViewProvider; import com.redhat.thermostat.thread.client.common.collector.ThreadCollectorFactory; @@ -51,13 +52,16 @@ private Filter<VmRef> filter = new NameMatchingRefFilter<>(); private ApplicationService service; + private VmInfoDAO vmInfoDao; private ThreadCollectorFactory collectorFactory; private ThreadViewProvider viewFactory; - public ThreadInformationService(ApplicationService appService, ThreadCollectorFactory collectorFactory, + public ThreadInformationService(ApplicationService appService, VmInfoDAO vmInfoDao, + ThreadCollectorFactory collectorFactory, ThreadViewProvider viewFactory) { this.service = appService; + this.vmInfoDao = vmInfoDao; this.collectorFactory = collectorFactory; this.viewFactory = viewFactory; } @@ -69,7 +73,7 @@ @Override public InformationServiceController<VmRef> getInformationServiceController(VmRef ref) { - return new ThreadInformationController(ref, service, collectorFactory, viewFactory); + return new ThreadInformationController(ref, service, vmInfoDao, collectorFactory, viewFactory); } @Override
--- a/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/osgi/Activator.java Mon Dec 31 11:12:50 2012 -0500 +++ b/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/osgi/Activator.java Mon Dec 31 12:47:52 2012 -0500 @@ -39,6 +39,7 @@ import java.util.Dictionary; import java.util.Hashtable; import java.util.Map; +import java.util.Objects; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -49,6 +50,7 @@ import com.redhat.thermostat.common.Constants; import com.redhat.thermostat.common.MultipleServiceTracker; import com.redhat.thermostat.common.MultipleServiceTracker.Action; +import com.redhat.thermostat.common.dao.VmInfoDAO; import com.redhat.thermostat.common.dao.VmRef; import com.redhat.thermostat.thread.client.common.ThreadViewProvider; import com.redhat.thermostat.thread.client.common.collector.ThreadCollectorFactory; @@ -63,6 +65,7 @@ Class[] classes = new Class[] { ThreadCollectorFactory.class, ApplicationService.class, + VmInfoDAO.class, ThreadViewProvider.class }; @@ -74,9 +77,10 @@ public void dependenciesAvailable(Map<String, Object> services) { ThreadCollectorFactory collectorFactory = (ThreadCollectorFactory) services.get(ThreadCollectorFactory.class.getName()); ApplicationService applicationService = (ApplicationService) services.get(ApplicationService.class.getName()); + VmInfoDAO vmInfoDao = Objects.requireNonNull((VmInfoDAO) services.get(VmInfoDAO.class.getName())); ThreadViewProvider viewFactory = (ThreadViewProvider) services.get(ThreadViewProvider.class.getName()); - InformationService<VmRef> vmInfoService = new ThreadInformationService(applicationService, collectorFactory, viewFactory); + InformationService<VmRef> vmInfoService = new ThreadInformationService(applicationService, vmInfoDao, collectorFactory, viewFactory); Dictionary<String, String> properties = new Hashtable<>(); properties.put(Constants.GENERIC_SERVICE_CLASSNAME, VmRef.class.getName()); registration = context.registerService(InformationService.class.getName(), vmInfoService, properties);
--- a/thread/client-controllers/src/test/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationControllerTest.java Mon Dec 31 11:12:50 2012 -0500 +++ b/thread/client-controllers/src/test/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationControllerTest.java Mon Dec 31 12:47:52 2012 -0500 @@ -36,6 +36,8 @@ package com.redhat.thermostat.thread.client.controller.impl; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.isA; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -54,7 +56,9 @@ import com.redhat.thermostat.common.Timer; import com.redhat.thermostat.common.TimerFactory; import com.redhat.thermostat.common.dao.HostRef; +import com.redhat.thermostat.common.dao.VmInfoDAO; import com.redhat.thermostat.common.dao.VmRef; +import com.redhat.thermostat.storage.model.VmInfo; import com.redhat.thermostat.thread.client.common.ThreadTableBean; import com.redhat.thermostat.thread.client.common.ThreadViewProvider; import com.redhat.thermostat.thread.client.common.collector.ThreadCollector; @@ -76,6 +80,8 @@ private ThreadInformationController controller; private ApplicationService appService; + private VmInfo vmInfo; + private VmInfoDAO vmInfoDao; private ThreadTableView threadTableView; private VMThreadCapabilitiesView threadCapsView; @@ -85,6 +91,10 @@ @Before public void setUp() { appService = mock(ApplicationService.class); + vmInfo = mock(VmInfo.class); + when(vmInfo.isAlive()).thenReturn(true); + vmInfoDao = mock(VmInfoDAO.class); + when(vmInfoDao.getVmInfo(isA(VmRef.class))).thenReturn(vmInfo); setUpTimers(); setUpView(); } @@ -138,7 +148,7 @@ ThreadCollector collector = mock(ThreadCollector.class); when(collectorFactory.getCollector(ref)).thenReturn(collector); - controller = new ThreadInformationController(ref, appService, collectorFactory, viewFactory); + controller = new ThreadInformationController(ref, appService, vmInfoDao, collectorFactory, viewFactory); } @Test @@ -176,7 +186,7 @@ ApplicationCache cache = mock(ApplicationCache.class); when(appService.getApplicationCache()).thenReturn(cache); - controller = new ThreadInformationController(ref, appService, collectorFactory, viewFactory); + controller = new ThreadInformationController(ref, appService, vmInfoDao, collectorFactory, viewFactory); verify(collector).isHarvesterCollecting(); verify(view, times(1)).setRecording(false, false); @@ -196,6 +206,17 @@ verify(collector, times(2)).stopHarvester(); verify(view, times(1)).setRecording(true, false); + + verify(view, times(0)).setEnableRecordingControl(false); + } + + @Test + public void verifyRecordingControlDisabledForDeadVms() { + when(vmInfo.isAlive()).thenReturn(false); + + createController(); + + verify(view).setEnableRecordingControl(false); } @Test
--- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadView.java Mon Dec 31 11:12:50 2012 -0500 +++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadView.java Mon Dec 31 12:47:52 2012 -0500 @@ -185,6 +185,16 @@ super.setApplicationService(appService, uniqueId); DIVIDER_LOCATION_KEY = "divider." + uniqueId; } + + @Override + public void setEnableRecordingControl(final boolean enable) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + panel.getToggleButton().setEnabled(enable); + } + }); + } @Override public void setRecording(final boolean recording, final boolean notify) {
--- a/thread/client-swing/src/test/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadViewTest.java Mon Dec 31 11:12:50 2012 -0500 +++ b/thread/client-swing/src/test/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadViewTest.java Mon Dec 31 12:47:52 2012 -0500 @@ -63,6 +63,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import com.redhat.thermostat.common.ActionEvent; @@ -140,6 +141,18 @@ togglefixture.requireToolTip(t.localize(LocaleResources.START_RECORDING)); } + @Category(GUITest.class) + @GUITest + @Test + public void verifyToggleButtonIsDisabled() { + frameFixture.show(); + + view.setEnableRecordingControl(false); + + JToggleButtonFixture togglefixture = frameFixture.toggleButton("recordButton"); + togglefixture.requireDisabled(); + } + @GUITest @Test public void verifTableViewLinksToDetailsView() throws InvocationTargetException, InterruptedException {