Mercurial > hg > release > thermostat-1.2
changeset 1609:6e5c85ab43dc
Disable UI for starting/stopping profiling for dead VMs
Reviewed-by: vanaltj
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2014-December/012121.html
line wrap: on
line diff
--- a/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/Activator.java Mon Dec 08 14:56:05 2014 +0100 +++ b/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/Activator.java Tue Dec 09 14:43:58 2014 -0500 @@ -50,6 +50,7 @@ import com.redhat.thermostat.common.MultipleServiceTracker; 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.vm.profiler.common.ProfileDAO; public class Activator implements BundleActivator { @@ -63,6 +64,7 @@ Class<?>[] deps = new Class<?>[] { ApplicationService.class, AgentInfoDAO.class, + VmInfoDAO.class, ProfileDAO.class, RequestQueue.class, }; @@ -72,10 +74,11 @@ public void dependenciesAvailable(Map<String, Object> services) { ApplicationService service = (ApplicationService) services.get(ApplicationService.class.getName()); AgentInfoDAO agentInfoDao = (AgentInfoDAO) services.get(AgentInfoDAO.class.getName()); + VmInfoDAO vmInfoDao = (VmInfoDAO) services.get(VmInfoDAO.class.getName()); ProfileDAO profileDao = (ProfileDAO) services.get(ProfileDAO.class.getName()); RequestQueue queue = (RequestQueue) services.get(RequestQueue.class.getName()); - InformationService<VmRef> profileService = new VmProfileService(service, agentInfoDao, profileDao, queue); + InformationService<VmRef> profileService = new VmProfileService(service, agentInfoDao, vmInfoDao, profileDao, queue); Hashtable<String,String> properties = new Hashtable<>(); properties.put(Constants.GENERIC_SERVICE_CLASSNAME, VmRef.class.getName());
--- a/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileController.java Mon Dec 08 14:56:05 2014 +0100 +++ b/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileController.java Tue Dec 09 14:43:58 2014 -0500 @@ -60,8 +60,12 @@ import com.redhat.thermostat.common.model.Range; import com.redhat.thermostat.shared.locale.LocalizedString; import com.redhat.thermostat.shared.locale.Translate; +import com.redhat.thermostat.storage.core.HostRef; 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.AgentInformation; +import com.redhat.thermostat.storage.model.VmInfo.AliveStatus; import com.redhat.thermostat.vm.profiler.client.core.ProfilingResult; import com.redhat.thermostat.vm.profiler.client.core.ProfilingResultParser; import com.redhat.thermostat.vm.profiler.client.swing.internal.VmProfileView.Profile; @@ -78,6 +82,7 @@ private ApplicationService service; private ProfileDAO profileDao; private AgentInfoDAO agentInfoDao; + private VmInfoDAO vmInfoDao; private RequestQueue queue; private VmRef vm; @@ -92,18 +97,19 @@ private ProfileStatusChange previousStatus; public VmProfileController(ApplicationService service, - AgentInfoDAO agentInfoDao, ProfileDAO dao, + AgentInfoDAO agentInfoDao, VmInfoDAO vmInfoDao, ProfileDAO dao, RequestQueue queue, VmRef vm) { - this(service, agentInfoDao, dao, queue, new SystemClock(), new SwingVmProfileView(), vm); + this(service, agentInfoDao, vmInfoDao, dao, queue, new SystemClock(), new SwingVmProfileView(), vm); } VmProfileController(ApplicationService service, - AgentInfoDAO agentInfoDao, ProfileDAO dao, + AgentInfoDAO agentInfoDao, VmInfoDAO vmInfoDao, ProfileDAO dao, RequestQueue queue, Clock clock, final VmProfileView view, VmRef vm) { this.service = service; this.agentInfoDao = agentInfoDao; + this.vmInfoDao = vmInfoDao; this.profileDao = dao; this.queue = queue; this.clock = clock; @@ -217,7 +223,11 @@ message = translator.localize(LocaleResources.PROFILER_CURRENT_STATUS_INACTIVE).getContents(); } - if (profilingStartOrStopRequested) { + if (!isAlive()) { + view.enableStartProfiling(false); + view.enableStopProfiling(false); + view.setProfilingStatus(message, currentlyActive); + } else if (profilingStartOrStopRequested) { boolean statusChanged = (previousStatus == null && currentStatus != null) || (currentStatus != null && !(currentStatus.equals(previousStatus))); if (statusChanged) { @@ -238,6 +248,15 @@ previousStatus = currentStatus; } + private boolean isAlive() { + HostRef agent = vm.getHostRef(); + AgentInformation agentInfo = agentInfoDao.getAgentInformation(agent); + if (!agentInfo.isAlive()) { + return false; + } + return vmInfoDao.getVmInfo(vm).isAlive(agentInfo) == AliveStatus.RUNNING; + } + private void updateViewWithProfiledRuns() { long end = clock.getRealTimeMillis(); long start = end - TimeUnit.DAYS.toMillis(1); // FIXME hardcoded 1 day
--- a/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileService.java Mon Dec 08 14:56:05 2014 +0100 +++ b/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileService.java Tue Dec 09 14:43:58 2014 -0500 @@ -44,18 +44,21 @@ import com.redhat.thermostat.common.Filter; 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.vm.profiler.common.ProfileDAO; public class VmProfileService implements InformationService<VmRef> { private ApplicationService service; private AgentInfoDAO agentInfoDao; + private VmInfoDAO vmInfoDao; private ProfileDAO dao; private RequestQueue queue; - public VmProfileService(ApplicationService service, AgentInfoDAO agentInfoDao, ProfileDAO dao, RequestQueue queue) { + public VmProfileService(ApplicationService service, AgentInfoDAO agentInfoDao, VmInfoDAO vmInfoDao, ProfileDAO dao, RequestQueue queue) { this.service = service; this.agentInfoDao = agentInfoDao; + this.vmInfoDao = vmInfoDao; this.dao = dao; this.queue = queue; } @@ -73,7 +76,7 @@ @Override public InformationServiceController<VmRef> getInformationServiceController(VmRef ref) { - return new VmProfileController(service, agentInfoDao, dao, queue, ref); + return new VmProfileController(service, agentInfoDao, vmInfoDao, dao, queue, ref); } }
--- a/vm-profiler/client-swing/src/test/java/com/redhat/thermostat/vm/profiler/client/swing/internal/ActivatorTest.java Mon Dec 08 14:56:05 2014 +0100 +++ b/vm-profiler/client-swing/src/test/java/com/redhat/thermostat/vm/profiler/client/swing/internal/ActivatorTest.java Tue Dec 09 14:43:58 2014 -0500 @@ -45,6 +45,7 @@ import com.redhat.thermostat.client.core.InformationService; import com.redhat.thermostat.common.ApplicationService; import com.redhat.thermostat.storage.dao.AgentInfoDAO; +import com.redhat.thermostat.storage.dao.VmInfoDAO; import com.redhat.thermostat.testutils.StubBundleContext; import com.redhat.thermostat.vm.profiler.common.ProfileDAO; @@ -60,6 +61,9 @@ AgentInfoDAO agentInfoDao = mock(AgentInfoDAO.class); bundleContext.registerService(AgentInfoDAO.class, agentInfoDao, null); + VmInfoDAO vmInfoDao = mock(VmInfoDAO.class); + bundleContext.registerService(VmInfoDAO.class, vmInfoDao, null); + ProfileDAO profielDao = mock(ProfileDAO.class); bundleContext.registerService(ProfileDAO.class, profielDao, null);
--- a/vm-profiler/client-swing/src/test/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileControllerTest.java Mon Dec 08 14:56:05 2014 +0100 +++ b/vm-profiler/client-swing/src/test/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileControllerTest.java Tue Dec 09 14:43:58 2014 -0500 @@ -37,6 +37,7 @@ package com.redhat.thermostat.vm.profiler.client.swing.internal; import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; import static org.mockito.Matchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -67,7 +68,10 @@ import com.redhat.thermostat.storage.core.HostRef; 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.AgentInformation; +import com.redhat.thermostat.storage.model.VmInfo; +import com.redhat.thermostat.storage.model.VmInfo.AliveStatus; import com.redhat.thermostat.vm.profiler.client.core.ProfilingResult; import com.redhat.thermostat.vm.profiler.client.swing.internal.VmProfileView.Profile; import com.redhat.thermostat.vm.profiler.client.swing.internal.VmProfileView.ProfileAction; @@ -91,6 +95,7 @@ private Timer timer; private ApplicationService appService; private AgentInfoDAO agentInfoDao; + private VmInfoDAO vmInfoDao; private ProfileDAO profileDao; private RequestQueue queue; private Clock clock; @@ -99,6 +104,7 @@ private VmProfileController controller; private HostRef agent; + private VmInfo vmInfo; @Before public void setUp() { @@ -111,6 +117,10 @@ when(appService.getTimerFactory()).thenReturn(timerFactory); agentInfoDao = mock(AgentInfoDAO.class); + vmInfoDao = mock(VmInfoDAO.class); + vmInfo = mock(VmInfo.class); + when(vmInfo.isAlive(any(AgentInformation.class))).thenReturn(AliveStatus.RUNNING); + when(vmInfoDao.getVmInfo(isA(VmRef.class))).thenReturn(vmInfo); profileDao = mock(ProfileDAO.class); queue = mock(RequestQueue.class); @@ -125,6 +135,7 @@ when(vm.getVmId()).thenReturn(VM_ID); AgentInformation agentInfo = new AgentInformation(); + agentInfo.setAlive(true); agentInfo.setConfigListenAddress(AGENT_HOST + ":" + AGENT_PORT); when(agentInfoDao.getAgentInformation(agent)).thenReturn(agentInfo); } @@ -188,6 +199,23 @@ } @Test + public void timerDisablesViewActionsForDeadVMs() throws Exception { + when(clock.getRealTimeMillis()).thenReturn(SOME_TIMESTAMP); + controller = createController(); + + ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class); + verify(timer).setAction(runnableCaptor.capture()); + + when(vmInfo.isAlive(isA(AgentInformation.class))).thenReturn(AliveStatus.EXITED); + + Runnable runnable = runnableCaptor.getValue(); + runnable.run(); + + verify(view).enableStartProfiling(false); + verify(view).enableStopProfiling(false); + } + + @Test public void startProfilingWorks() throws Exception { controller = createController(); @@ -290,7 +318,7 @@ } private VmProfileController createController() { - return new VmProfileController(appService, agentInfoDao, profileDao, queue, clock, view, vm); + return new VmProfileController(appService, agentInfoDao, vmInfoDao, profileDao, queue, clock, view, vm); } private void assertRequestEquals(Request actual, Request expected) {
--- a/vm-profiler/client-swing/src/test/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileServiceTest.java Mon Dec 08 14:56:05 2014 +0100 +++ b/vm-profiler/client-swing/src/test/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileServiceTest.java Tue Dec 09 14:43:58 2014 -0500 @@ -50,7 +50,7 @@ public void worksWithDeadAndAliveVms() throws Exception { VmRef vm = mock(VmRef.class); - VmProfileService service = new VmProfileService(null, null, null, null); + VmProfileService service = new VmProfileService(null, null, null, null, null); Filter<VmRef> filter = service.getFilter(); assertTrue(filter.matches(vm));