# HG changeset patch # User Andrew Azores # Date 1443473200 14400 # Node ID 9fbab9775a4443c69799043ff36965d38677b8bb # Parent 5db8eb6c7811f2a0720ef814baf9f424b3a98319 Add "Perform GC" button to GC tab See also: http://icedtea.classpath.org/pipermail/thermostat/2015-June/014335.html http://icedtea.classpath.org/pipermail/thermostat/2015-September/016405.html Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-September/016548.html PR2655 diff -r 5db8eb6c7811 -r 9fbab9775a44 vm-gc/client-core/pom.xml --- a/vm-gc/client-core/pom.xml Thu Sep 24 13:28:06 2015 -0400 +++ b/vm-gc/client-core/pom.xml Mon Sep 28 16:46:40 2015 -0400 @@ -130,6 +130,16 @@ com.redhat.thermostat + thermostat-client-command + ${project.version} + + + com.redhat.thermostat + thermostat-gc-remote-collector-client-common + ${project.version} + + + com.redhat.thermostat thermostat-common-test ${project.version} test diff -r 5db8eb6c7811 -r 9fbab9775a44 vm-gc/client-core/src/main/java/com/redhat/thermostat/vm/gc/client/core/VmGcView.java --- a/vm-gc/client-core/src/main/java/com/redhat/thermostat/vm/gc/client/core/VmGcView.java Thu Sep 24 13:28:06 2015 -0400 +++ b/vm-gc/client-core/src/main/java/com/redhat/thermostat/vm/gc/client/core/VmGcView.java Mon Sep 28 16:46:40 2015 -0400 @@ -43,6 +43,7 @@ import com.redhat.thermostat.client.core.views.BasicView; import com.redhat.thermostat.client.core.views.UIComponent; import com.redhat.thermostat.common.ActionListener; +import com.redhat.thermostat.gc.remote.common.command.GCAction; import com.redhat.thermostat.shared.locale.LocalizedString; import com.redhat.thermostat.storage.model.IntervalTimeData; import com.redhat.thermostat.vm.gc.common.GcCommonNameMapper.CollectorCommonName; @@ -67,6 +68,12 @@ public abstract void setCommonCollectorName(CollectorCommonName commonName); + public abstract void setEnableGCAction(boolean enable); + + public abstract void addGCActionListener(ActionListener listener); + public abstract Duration getUserDesiredDuration(); + + public abstract void displayWarning(LocalizedString string); } diff -r 5db8eb6c7811 -r 9fbab9775a44 vm-gc/client-core/src/main/java/com/redhat/thermostat/vm/gc/client/core/internal/Activator.java --- a/vm-gc/client-core/src/main/java/com/redhat/thermostat/vm/gc/client/core/internal/Activator.java Thu Sep 24 13:28:06 2015 -0400 +++ b/vm-gc/client-core/src/main/java/com/redhat/thermostat/vm/gc/client/core/internal/Activator.java Mon Sep 28 16:46:40 2015 -0400 @@ -41,6 +41,8 @@ import java.util.Map; import java.util.Objects; +import com.redhat.thermostat.gc.remote.common.GCRequest; +import com.redhat.thermostat.storage.dao.AgentInfoDAO; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; @@ -66,6 +68,8 @@ Class[] deps = new Class[] { VmMemoryStatDAO.class, VmGcStatDAO.class, + AgentInfoDAO.class, + GCRequest.class, ApplicationService.class, VmGcViewProvider.class }; @@ -78,12 +82,16 @@ Objects.requireNonNull(vmMemoryStatDAO); VmGcStatDAO vmGcStatDAO = (VmGcStatDAO) services.get(VmGcStatDAO.class.getName()); Objects.requireNonNull(vmGcStatDAO); + AgentInfoDAO agentInfoDAO = (AgentInfoDAO) services.get(AgentInfoDAO.class.getName()); + Objects.requireNonNull(agentInfoDAO); + GCRequest gcRequest = (GCRequest) services.get(GCRequest.class.getName()); + Objects.requireNonNull(gcRequest); ApplicationService appSvc = (ApplicationService) services.get(ApplicationService.class.getName()); Objects.requireNonNull(appSvc); VmGcViewProvider viewProvider = (VmGcViewProvider) services.get(VmGcViewProvider.class.getName()); Objects.requireNonNull(viewProvider); - VmGcService service = new VmGcServiceImpl(appSvc, vmMemoryStatDAO, vmGcStatDAO, viewProvider); + VmGcService service = new VmGcServiceImpl(appSvc, vmMemoryStatDAO, vmGcStatDAO, agentInfoDAO, viewProvider, gcRequest); Dictionary properties = new Hashtable<>(); properties.put(Constants.GENERIC_SERVICE_CLASSNAME, VmRef.class.getName()); properties.put(InformationService.KEY_SERVICE_ID, VmGcService.SERVICE_ID); diff -r 5db8eb6c7811 -r 9fbab9775a44 vm-gc/client-core/src/main/java/com/redhat/thermostat/vm/gc/client/core/internal/VmGcController.java --- a/vm-gc/client-core/src/main/java/com/redhat/thermostat/vm/gc/client/core/internal/VmGcController.java Thu Sep 24 13:28:06 2015 -0400 +++ b/vm-gc/client-core/src/main/java/com/redhat/thermostat/vm/gc/client/core/internal/VmGcController.java Mon Sep 28 16:46:40 2015 -0400 @@ -56,9 +56,15 @@ import com.redhat.thermostat.common.NotImplementedException; import com.redhat.thermostat.common.Timer; import com.redhat.thermostat.common.Timer.SchedulingType; +import com.redhat.thermostat.common.command.Request; +import com.redhat.thermostat.common.command.RequestResponseListener; +import com.redhat.thermostat.common.command.Response; +import com.redhat.thermostat.gc.remote.common.GCRequest; +import com.redhat.thermostat.gc.remote.common.command.GCAction; 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.AgentInfoDAO; import com.redhat.thermostat.storage.model.IntervalTimeData; import com.redhat.thermostat.storage.model.TimeStampedPojoComparator; import com.redhat.thermostat.vm.gc.client.core.VmGcView; @@ -82,6 +88,7 @@ private final VmGcStatDAO gcDao; private final VmMemoryStatDAO memDao; + private final AgentInfoDAO agentDAO; private final Set addedCollectors = new TreeSet<>(); // the last value seen for each collector @@ -91,13 +98,14 @@ private long lastSeenTimeStamp; - public VmGcController(ApplicationService appSvc, VmMemoryStatDAO vmMemoryStatDao, VmGcStatDAO vmGcStatDao, VmRef ref, VmGcViewProvider provider) { + public VmGcController(ApplicationService appSvc, VmMemoryStatDAO vmMemoryStatDao, VmGcStatDAO vmGcStatDao, AgentInfoDAO agentInfoDAO, VmRef ref, VmGcViewProvider provider, final GCRequest gcRequest) { this.ref = ref; this.view = provider.createView(); this.timer = appSvc.getTimerFactory().createTimer(); gcDao = vmGcStatDao; memDao = vmMemoryStatDao; + agentDAO = agentInfoDAO; view.addActionListener(new ActionListener() { @Override @@ -130,6 +138,26 @@ } }); + view.addGCActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + RequestResponseListener listener = new RequestResponseListener() { + @Override + public void fireComplete(Request request, Response response) { + if (response.getType() == Response.ResponseType.ERROR) { + view.displayWarning(translator.localize( + LocaleResources.ERROR_PERFORMING_GC, + VmGcController.this.ref.getHostRef().getAgentId(), + VmGcController.this.ref.getVmId())); + } + view.setEnableGCAction(true); + } + }; + view.setEnableGCAction(false); + gcRequest.sendGCRequestToAgent(VmGcController.this.ref, agentDAO, listener); + } + }); + Duration userDuration = view.getUserDesiredDuration(); //Has default of 10 minutes lastSeenTimeStamp = System.currentTimeMillis() - userDuration.unit.toMillis(userDuration.value); diff -r 5db8eb6c7811 -r 9fbab9775a44 vm-gc/client-core/src/main/java/com/redhat/thermostat/vm/gc/client/core/internal/VmGcServiceImpl.java --- a/vm-gc/client-core/src/main/java/com/redhat/thermostat/vm/gc/client/core/internal/VmGcServiceImpl.java Thu Sep 24 13:28:06 2015 -0400 +++ b/vm-gc/client-core/src/main/java/com/redhat/thermostat/vm/gc/client/core/internal/VmGcServiceImpl.java Mon Sep 28 16:46:40 2015 -0400 @@ -40,7 +40,9 @@ 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.gc.remote.common.GCRequest; import com.redhat.thermostat.storage.core.VmRef; +import com.redhat.thermostat.storage.dao.AgentInfoDAO; import com.redhat.thermostat.vm.gc.client.core.VmGcService; import com.redhat.thermostat.vm.gc.client.core.VmGcViewProvider; import com.redhat.thermostat.vm.gc.common.VmGcStatDAO; @@ -54,21 +56,25 @@ private ApplicationService appSvc; private VmMemoryStatDAO vmMemoryStatDAO; private VmGcStatDAO vmGcStatDAO; + private AgentInfoDAO agentInfoDAO; private VmGcViewProvider viewProvider; + private GCRequest gcRequest; public VmGcServiceImpl(ApplicationService appSvc, - VmMemoryStatDAO vmMemoryStatDAO, VmGcStatDAO vmGcStatDAO, - VmGcViewProvider viewProvider) { + VmMemoryStatDAO vmMemoryStatDAO, VmGcStatDAO vmGcStatDAO, AgentInfoDAO agentInfoDAO, + VmGcViewProvider viewProvider, GCRequest gcRequest) { this.appSvc = appSvc; this.vmMemoryStatDAO = vmMemoryStatDAO; this.vmGcStatDAO = vmGcStatDAO; + this.agentInfoDAO = agentInfoDAO; this.viewProvider = viewProvider; + this.gcRequest = gcRequest; } @Override public InformationServiceController getInformationServiceController( VmRef ref) { - return new VmGcController(appSvc, vmMemoryStatDAO, vmGcStatDAO, ref, viewProvider); + return new VmGcController(appSvc, vmMemoryStatDAO, vmGcStatDAO, agentInfoDAO, ref, viewProvider, gcRequest); } @Override diff -r 5db8eb6c7811 -r 9fbab9775a44 vm-gc/client-core/src/main/java/com/redhat/thermostat/vm/gc/client/locale/LocaleResources.java --- a/vm-gc/client-core/src/main/java/com/redhat/thermostat/vm/gc/client/locale/LocaleResources.java Thu Sep 24 13:28:06 2015 -0400 +++ b/vm-gc/client-core/src/main/java/com/redhat/thermostat/vm/gc/client/locale/LocaleResources.java Mon Sep 28 16:46:40 2015 -0400 @@ -56,6 +56,8 @@ VM_GC_COLLECTOR_CHART_REAL_TIME_LABEL, VM_GC_COLLECTOR_CHART_GC_TIME_LABEL, VM_GC_CONFIGURED_COLLECTOR, + + ERROR_PERFORMING_GC, ; static final String RESOURCE_BUNDLE = diff -r 5db8eb6c7811 -r 9fbab9775a44 vm-gc/client-core/src/main/resources/com/redhat/thermostat/vm/gc/client/locale/strings.properties --- a/vm-gc/client-core/src/main/resources/com/redhat/thermostat/vm/gc/client/locale/strings.properties Thu Sep 24 13:28:06 2015 -0400 +++ b/vm-gc/client-core/src/main/resources/com/redhat/thermostat/vm/gc/client/locale/strings.properties Mon Sep 28 16:46:40 2015 -0400 @@ -14,4 +14,6 @@ VM_GC_COLLECTOR_OVER_GENERATION = Collector {0} running on {1} VM_GC_COLLECTOR_CHART_REAL_TIME_LABEL = Time VM_GC_COLLECTOR_CHART_GC_TIME_LABEL = GC Time ({0}) -VM_GC_CONFIGURED_COLLECTOR = Configured Garbage Collector: \ No newline at end of file +VM_GC_CONFIGURED_COLLECTOR = Configured Garbage Collector: + +ERROR_PERFORMING_GC = Error performing Garbage Collection (agent: {0}, vm: {1}) \ No newline at end of file diff -r 5db8eb6c7811 -r 9fbab9775a44 vm-gc/client-core/src/test/java/com/redhat/thermostat/vm/gc/client/core/internal/ActivatorTest.java --- a/vm-gc/client-core/src/test/java/com/redhat/thermostat/vm/gc/client/core/internal/ActivatorTest.java Thu Sep 24 13:28:06 2015 -0400 +++ b/vm-gc/client-core/src/test/java/com/redhat/thermostat/vm/gc/client/core/internal/ActivatorTest.java Mon Sep 28 16:46:40 2015 -0400 @@ -41,6 +41,8 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; +import com.redhat.thermostat.gc.remote.common.GCRequest; +import com.redhat.thermostat.storage.dao.AgentInfoDAO; import org.junit.Test; import com.redhat.thermostat.client.core.InformationService; @@ -73,11 +75,15 @@ StubBundleContext context = new StubBundleContext(); VmMemoryStatDAO vmMemoryStatDAO = mock(VmMemoryStatDAO.class); VmGcStatDAO vmGcStatDAO = mock(VmGcStatDAO.class); + AgentInfoDAO agentInfoDAO = mock(AgentInfoDAO.class); + GCRequest gcRequest = mock(GCRequest.class); ApplicationService appSvc = mock(ApplicationService.class); VmGcViewProvider viewProvider = mock(VmGcViewProvider.class); context.registerService(VmMemoryStatDAO.class, vmMemoryStatDAO, null); context.registerService(VmGcStatDAO.class, vmGcStatDAO, null); + context.registerService(AgentInfoDAO.class, agentInfoDAO, null); + context.registerService(GCRequest.class, gcRequest, null); context.registerService(ApplicationService.class, appSvc, null); context.registerService(VmGcViewProvider.class, viewProvider, null); @@ -90,7 +96,7 @@ activator.stop(context); assertEquals(0, context.getServiceListeners().size()); - assertEquals(4, context.getAllServices().size()); + assertEquals(6, context.getAllServices().size()); } } diff -r 5db8eb6c7811 -r 9fbab9775a44 vm-gc/client-core/src/test/java/com/redhat/thermostat/vm/gc/client/core/internal/VmGcControllerTest.java --- a/vm-gc/client-core/src/test/java/com/redhat/thermostat/vm/gc/client/core/internal/VmGcControllerTest.java Thu Sep 24 13:28:06 2015 -0400 +++ b/vm-gc/client-core/src/test/java/com/redhat/thermostat/vm/gc/client/core/internal/VmGcControllerTest.java Mon Sep 28 16:46:40 2015 -0400 @@ -36,7 +36,6 @@ package com.redhat.thermostat.vm.gc.client.core.internal; -import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isA; import static org.mockito.Matchers.isNotNull; @@ -51,6 +50,10 @@ import java.util.Set; import java.util.concurrent.TimeUnit; +import com.redhat.thermostat.gc.remote.common.GCRequest; +import com.redhat.thermostat.storage.core.HostRef; +import com.redhat.thermostat.storage.dao.AgentInfoDAO; +import com.redhat.thermostat.storage.model.AgentInformation; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -106,11 +109,16 @@ gen.setCollector("collector1"); VmMemoryStat memoryStat = new VmMemoryStat("foo-agent", 1, "vmId", new Generation[] { gen }); + AgentInformation agentInfo = new AgentInformation("foo"); + // Setup DAO VmGcStatDAO vmGcStatDAO = mock(VmGcStatDAO.class); when(vmGcStatDAO.getLatestVmGcStats(isA(VmRef.class), isA(Long.class))).thenReturn(stats); VmMemoryStatDAO vmMemoryStatDAO = mock(VmMemoryStatDAO.class); when(vmMemoryStatDAO.getNewestMemoryStat(isA(VmRef.class))).thenReturn(memoryStat); + AgentInfoDAO agentInfoDAO = mock(AgentInfoDAO.class); + when(agentInfoDAO.getAgentInformation(isA(HostRef.class))).thenReturn(agentInfo); + // the following set should map to Concurrent Collector Set cms = new HashSet<>(); cms.add("CMS"); @@ -128,10 +136,12 @@ VmGcViewProvider viewProvider = mock(VmGcViewProvider.class); when(viewProvider.createView()).thenReturn(view); + GCRequest gcRequest = mock(GCRequest.class); + // Now start the controller VmRef ref = mock(VmRef.class); - new VmGcController(appSvc, vmMemoryStatDAO, vmGcStatDAO, ref, viewProvider); + new VmGcController(appSvc, vmMemoryStatDAO, vmGcStatDAO, agentInfoDAO, ref, viewProvider, gcRequest); // Extract relevant objects viewListener = viewArgumentCaptor.getValue(); diff -r 5db8eb6c7811 -r 9fbab9775a44 vm-gc/client-swing/pom.xml --- a/vm-gc/client-swing/pom.xml Thu Sep 24 13:28:06 2015 -0400 +++ b/vm-gc/client-swing/pom.xml Mon Sep 28 16:46:40 2015 -0400 @@ -117,6 +117,11 @@ com.redhat.thermostat + thermostat-gc-remote-collector-client-swing + ${project.version} + + + com.redhat.thermostat thermostat-common-test ${project.version} test diff -r 5db8eb6c7811 -r 9fbab9775a44 vm-gc/client-swing/src/main/java/com/redhat/thermostat/vm/gc/client/swing/internal/VmGcPanel.java --- a/vm-gc/client-swing/src/main/java/com/redhat/thermostat/vm/gc/client/swing/internal/VmGcPanel.java Thu Sep 24 13:28:06 2015 -0400 +++ b/vm-gc/client-swing/src/main/java/com/redhat/thermostat/vm/gc/client/swing/internal/VmGcPanel.java Mon Sep 28 16:46:40 2015 -0400 @@ -52,9 +52,13 @@ import javax.swing.BorderFactory; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.SwingUtilities; +import com.redhat.thermostat.gc.remote.client.common.RequestGCAction; +import com.redhat.thermostat.gc.remote.client.swing.ToolbarGCButton; +import com.redhat.thermostat.gc.remote.common.command.GCAction; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.DateAxis; @@ -104,6 +108,9 @@ private JLabel gcAlgoLabelDescr; private JLabel commonNameLabel; + private ToolbarGCButton toolbarGCButton; + private RequestGCAction requestGCAction; + private ActionNotifier userActionNotifier = new ActionNotifier<>(this); private final Map dataset = new HashMap<>(); @@ -124,6 +131,11 @@ gcPanelConstraints.weightx = 1; gcPanelConstraints.weighty = 1; + requestGCAction = new RequestGCAction(); + toolbarGCButton = new ToolbarGCButton(requestGCAction); + toolbarGCButton.setName("gcButton"); + visiblePanel.addToolBarButton(toolbarGCButton); + new ComponentVisibilityNotifier().initialize(visiblePanel, notifier); } @@ -350,6 +362,21 @@ } @Override + public void setEnableGCAction(final boolean enable) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + toolbarGCButton.setEnabled(enable); + } + }); + } + + @Override + public void addGCActionListener(ActionListener listener) { + requestGCAction.addActionListener(listener); + } + + @Override public Duration getUserDesiredDuration() { //Return the greatest duration of all controllers long timestamp = 0l; @@ -364,5 +391,10 @@ } return maxDuration; } + + @Override + public void displayWarning(LocalizedString string) { + JOptionPane.showMessageDialog(visiblePanel, string.getContents(), "Warning", JOptionPane.WARNING_MESSAGE); + } }