Mercurial > hg > release > thermostat-0.5
changeset 803:01d39c35e3fc
Move VM CPU to its own bundle
This patch moves the VM CPU controller/view into its own core and swing
bundles in the top-level of the source tree. The swing bundle registers
the controller dynamically using a VmInformationService. Strings
specific to VM CPU have been removed from the client-core bundle and the
VmCpuStatDAO has been removed from VmInformationServiceController and
from UiFacadeFactory.
Reviewed-by: jerboaa
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-November/004287.html
line wrap: on
line diff
--- a/client/core/src/main/java/com/redhat/thermostat/client/core/views/VmCpuView.java Tue Nov 27 14:50:16 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.core.views; - -import java.util.List; - -import com.redhat.thermostat.storage.model.DiscreteTimeData; - -public abstract class VmCpuView extends BasicView implements UIComponent { - - public abstract void addData(List<DiscreteTimeData<? extends Number>> data); - - public abstract void clearData(); - -}
--- a/client/core/src/main/java/com/redhat/thermostat/client/core/views/VmCpuViewProvider.java Tue Nov 27 14:50:16 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.core.views; - -public interface VmCpuViewProvider extends ViewProvider { - - @Override - public VmCpuView createView(); -}
--- a/client/core/src/main/java/com/redhat/thermostat/client/locale/LocaleResources.java Tue Nov 27 14:50:16 2012 -0500 +++ b/client/core/src/main/java/com/redhat/thermostat/client/locale/LocaleResources.java Tue Nov 27 14:51:18 2012 -0500 @@ -110,13 +110,8 @@ HOST_INFO_TAB_IO, - VM_INFO_TAB_CPU, VM_INFO_TAB_GC, - VM_CPU_TITLE, - VM_CPU_CHART_LOAD_LABEL, - VM_CPU_CHART_TIME_LABEL, - VM_GC_TITLE, VM_GC_COLLECTOR_OVER_GENERATION,
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/UiFacadeFactory.java Tue Nov 27 14:50:16 2012 -0500 +++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/UiFacadeFactory.java Tue Nov 27 14:51:18 2012 -0500 @@ -43,7 +43,6 @@ import com.redhat.thermostat.client.osgi.service.VMContextAction; import com.redhat.thermostat.common.dao.HostInfoDAO; import com.redhat.thermostat.common.dao.HostRef; -import com.redhat.thermostat.common.dao.VmCpuStatDAO; import com.redhat.thermostat.common.dao.VmGcStatDAO; import com.redhat.thermostat.common.dao.VmInfoDAO; import com.redhat.thermostat.common.dao.VmMemoryStatDAO; @@ -54,7 +53,6 @@ void setHostInfoDao(HostInfoDAO hostInfoDao); void setVmInfoDao(VmInfoDAO vmInfoDAO); - void setVmCpuStatDao(VmCpuStatDAO vmCpuStatDAO); void setVmMemoryStatDao(VmMemoryStatDAO vmMemoryStatDao); void setVmGcStatDao(VmGcStatDAO vmGcStatDao);
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/VmCpuController.java Tue Nov 27 14:50:16 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,127 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.ui; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import com.redhat.thermostat.client.core.views.UIComponent; -import com.redhat.thermostat.client.core.views.VmCpuView; -import com.redhat.thermostat.client.core.views.VmCpuViewProvider; -import com.redhat.thermostat.client.core.views.BasicView.Action; -import com.redhat.thermostat.common.ActionEvent; -import com.redhat.thermostat.common.ActionListener; -import com.redhat.thermostat.common.NotImplementedException; -import com.redhat.thermostat.common.Timer; -import com.redhat.thermostat.common.Timer.SchedulingType; -import com.redhat.thermostat.common.appctx.ApplicationContext; -import com.redhat.thermostat.common.dao.VmCpuStatDAO; -import com.redhat.thermostat.common.dao.VmRef; -import com.redhat.thermostat.storage.model.DiscreteTimeData; -import com.redhat.thermostat.storage.model.VmCpuStat; - -public class VmCpuController { - - private final VmRef ref; - private final VmCpuStatDAO dao; - private final VmCpuView view; - - private final Timer timer; - - private long lastSeenTimeStamp = Long.MIN_VALUE; - - public VmCpuController(VmCpuStatDAO vmCpuStatDao, VmRef ref, VmCpuViewProvider provider) { - this.ref = ref; - dao = vmCpuStatDao; - timer = ApplicationContext.getInstance().getTimerFactory().createTimer(); - - timer.setAction(new Runnable() { - @Override - public void run() { - doUpdateVmCpuCharts(); - } - }); - timer.setTimeUnit(TimeUnit.SECONDS); - timer.setDelay(5); - timer.setInitialDelay(0); - timer.setSchedulingType(SchedulingType.FIXED_RATE); - - view = provider.createView(); - - view.addActionListener(new ActionListener<VmCpuView.Action>() { - @Override - public void actionPerformed(ActionEvent<Action> actionEvent) { - switch (actionEvent.getActionId()) { - case HIDDEN: - stop(); - break; - case VISIBLE: - start(); - break; - default: - throw new NotImplementedException("unknown event : " + actionEvent.getActionId()); - } - } - }); - } - - private void start() { - timer.start(); - } - - private void doUpdateVmCpuCharts() { - List<VmCpuStat> stats = dao.getLatestVmCpuStats(ref, lastSeenTimeStamp); - List<DiscreteTimeData<? extends Number>> toDisplay = new ArrayList<>(stats.size()); - for (VmCpuStat stat: stats) { - DiscreteTimeData<? extends Number> data = - new DiscreteTimeData<Number>(stat.getTimeStamp(), stat.getCpuLoad()); - toDisplay.add(data); - lastSeenTimeStamp = Math.max(lastSeenTimeStamp, stat.getTimeStamp()); - } - - view.addData(toDisplay); - } - - private void stop() { - timer.stop(); - } - - public UIComponent getView() { - return (UIComponent) view; - } -}
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/VmInformationController.java Tue Nov 27 14:50:16 2012 -0500 +++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/VmInformationController.java Tue Nov 27 14:51:18 2012 -0500 @@ -41,12 +41,10 @@ import com.redhat.thermostat.client.core.VmInformationService; import com.redhat.thermostat.client.core.controllers.VmInformationServiceController; import com.redhat.thermostat.client.core.views.BasicView; -import com.redhat.thermostat.client.core.views.VmCpuViewProvider; import com.redhat.thermostat.client.core.views.VmGcViewProvider; import com.redhat.thermostat.client.core.views.VmInformationView; import com.redhat.thermostat.client.core.views.VmInformationViewProvider; import com.redhat.thermostat.client.locale.LocaleResources; -import com.redhat.thermostat.common.dao.VmCpuStatDAO; import com.redhat.thermostat.common.dao.VmGcStatDAO; import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.dao.VmRef; @@ -59,21 +57,17 @@ private final VmInformationView view; - private final VmCpuController cpuController; private final VmGcController gcController; - public VmInformationController(UiFacadeFactory uiFacadeFactory, VmCpuStatDAO vmCpuStatDao, VmMemoryStatDAO vmMemoryStatDao, VmGcStatDAO vmGcStatDao, VmRef vmRef, VmInformationViewProvider provider) { - this(OSGIUtils.getInstance(), uiFacadeFactory, vmCpuStatDao, vmMemoryStatDao, vmGcStatDao, vmRef, provider); + public VmInformationController(UiFacadeFactory uiFacadeFactory, VmMemoryStatDAO vmMemoryStatDao, VmGcStatDAO vmGcStatDao, VmRef vmRef, VmInformationViewProvider provider) { + this(OSGIUtils.getInstance(), uiFacadeFactory, vmMemoryStatDao, vmGcStatDao, vmRef, provider); } - VmInformationController(OSGIUtils serviceProvider, UiFacadeFactory uiFacadeFactory, VmCpuStatDAO vmCpuStatDao, VmMemoryStatDAO vmMemoryStatDao, VmGcStatDAO vmGcStatDao, VmRef vmRef, VmInformationViewProvider provider) { - VmCpuViewProvider vmCpuProvider = serviceProvider.getService(VmCpuViewProvider.class); - cpuController = new VmCpuController(vmCpuStatDao, vmRef, vmCpuProvider); + VmInformationController(OSGIUtils serviceProvider, UiFacadeFactory uiFacadeFactory, VmMemoryStatDAO vmMemoryStatDao, VmGcStatDAO vmGcStatDao, VmRef vmRef, VmInformationViewProvider provider) { VmGcViewProvider vmGCProvider = serviceProvider.getService(VmGcViewProvider.class); gcController = new VmGcController(vmMemoryStatDao, vmGcStatDao, vmRef, vmGCProvider); view = provider.createView(); - view.addChildView(translator.localize(LocaleResources.VM_INFO_TAB_CPU), cpuController.getView()); view.addChildView(translator.localize(LocaleResources.VM_INFO_TAB_GC), gcController.getView()); Collection<VmInformationService> vmInfoServices = uiFacadeFactory.getVmInformationServices();
--- a/client/core/src/main/resources/com/redhat/thermostat/client/locale/strings.properties Tue Nov 27 14:50:16 2012 -0500 +++ b/client/core/src/main/resources/com/redhat/thermostat/client/locale/strings.properties Tue Nov 27 14:51:18 2012 -0500 @@ -68,13 +68,8 @@ HOST_INFO_TAB_IO = IO -VM_INFO_TAB_CPU = CPU VM_INFO_TAB_GC = GC -VM_CPU_TITLE = Cpu Usage by Virtual Machine -VM_CPU_CHART_LOAD_LABEL = % CPU -VM_CPU_CHART_TIME_LABEL = Time - VM_GC_TITLE = Garbage Collection in the VM VM_GC_COLLECTOR_OVER_GENERATION = Collector {0} running on {1} VM_GC_COLLECTOR_CHART_REAL_TIME_LABEL = Time
--- a/client/core/src/test/java/com/redhat/thermostat/client/ui/VmCpuControllerTest.java Tue Nov 27 14:50:16 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.ui; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; - -import com.redhat.thermostat.client.core.views.VmCpuView; -import com.redhat.thermostat.client.core.views.VmCpuViewProvider; -import com.redhat.thermostat.common.ActionEvent; -import com.redhat.thermostat.common.ActionListener; -import com.redhat.thermostat.common.Timer; -import com.redhat.thermostat.common.TimerFactory; -import com.redhat.thermostat.common.appctx.ApplicationContext; -import com.redhat.thermostat.common.appctx.ApplicationContextUtil; -import com.redhat.thermostat.common.dao.VmCpuStatDAO; -import com.redhat.thermostat.common.dao.VmRef; -import com.redhat.thermostat.storage.model.VmCpuStat; - - -public class VmCpuControllerTest { - - @Before - public void setUp() { - ApplicationContextUtil.resetApplicationContext(); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) // any(List.class) - @Test - public void testChartUpdate() { - - VmCpuStat stat1 = new VmCpuStat(123, 12345, 50.5); - List<VmCpuStat> stats = new ArrayList<VmCpuStat>(); - stats.add(stat1); - - VmCpuStatDAO vmCpuStatDAO = mock(VmCpuStatDAO.class); - when(vmCpuStatDAO.getLatestVmCpuStats(any(VmRef.class), eq(Long.MIN_VALUE))).thenReturn(stats).thenReturn(new ArrayList<VmCpuStat>()); - - VmRef ref = mock(VmRef.class); - - Timer timer = mock(Timer.class); - ArgumentCaptor<Runnable> timerActionCaptor = ArgumentCaptor.forClass(Runnable.class); - doNothing().when(timer).setAction(timerActionCaptor.capture()); - - TimerFactory timerFactory = mock(TimerFactory.class); - when(timerFactory.createTimer()).thenReturn(timer); - ApplicationContext.getInstance().setTimerFactory(timerFactory); - - final VmCpuView view = mock(VmCpuView.class); - ArgumentCaptor<ActionListener> viewArgumentCaptor = ArgumentCaptor.forClass(ActionListener.class); - doNothing().when(view).addActionListener(viewArgumentCaptor.capture()); - - VmCpuViewProvider viewProvider = mock(VmCpuViewProvider.class); - when(viewProvider.createView()).thenReturn(view); - - @SuppressWarnings("unused") - VmCpuController controller = new VmCpuController(vmCpuStatDAO, ref, viewProvider); - - ActionListener<VmCpuView.Action> l = viewArgumentCaptor.getValue(); - - l.actionPerformed(new ActionEvent<>(view, VmCpuView.Action.VISIBLE)); - - verify(timer).start(); - - timerActionCaptor.getValue().run(); - - l.actionPerformed(new ActionEvent<>(view, VmCpuView.Action.HIDDEN)); - - verify(timer).stop(); - - verify(view).addData(any(List.class)); - // We don't verify atMost() since we might increase the update rate in the future. - } -}
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/Main.java Tue Nov 27 14:50:16 2012 -0500 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/Main.java Tue Nov 27 14:51:18 2012 -0500 @@ -284,7 +284,6 @@ uiFacadeFactory.setHostInfoDao(daoFactory.getHostInfoDAO()); uiFacadeFactory.setVmInfoDao(daoFactory.getVmInfoDAO()); - uiFacadeFactory.setVmCpuStatDao(daoFactory.getVmCpuStatDAO()); uiFacadeFactory.setVmMemoryStatDao(daoFactory.getVmMemoryStatDAO()); uiFacadeFactory.setVmGcStatDao(daoFactory.getVmGcStatDAO());
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/UiFacadeFactoryImpl.java Tue Nov 27 14:50:16 2012 -0500 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/UiFacadeFactoryImpl.java Tue Nov 27 14:51:18 2012 -0500 @@ -56,7 +56,6 @@ import com.redhat.thermostat.client.ui.VmInformationController; import com.redhat.thermostat.common.dao.HostInfoDAO; import com.redhat.thermostat.common.dao.HostRef; -import com.redhat.thermostat.common.dao.VmCpuStatDAO; import com.redhat.thermostat.common.dao.VmGcStatDAO; import com.redhat.thermostat.common.dao.VmInfoDAO; import com.redhat.thermostat.common.dao.VmMemoryStatDAO; @@ -76,7 +75,6 @@ private HostInfoDAO hostInfoDao; private VmInfoDAO vmInfoDao; - private VmCpuStatDAO vmCpuStatDao; private VmMemoryStatDAO vmMemoryStatDao; private VmGcStatDAO vmGcStatDao; @@ -100,10 +98,6 @@ this.vmInfoDao = vmInfoDao; } - public void setVmCpuStatDao(VmCpuStatDAO vmCpuStatDao) { - this.vmCpuStatDao = vmCpuStatDao; - } - @Override public void setVmMemoryStatDao(VmMemoryStatDAO vmMemoryStatDao) { this.vmMemoryStatDao = vmMemoryStatDao; @@ -136,7 +130,7 @@ @Override public VmInformationController getVmController(VmRef ref) { VmInformationViewProvider viewProvider = serviceProvider.getService(VmInformationViewProvider.class); - return new VmInformationController(this, vmCpuStatDao, vmMemoryStatDao, vmGcStatDao, ref, viewProvider); + return new VmInformationController(this, vmMemoryStatDao, vmGcStatDao, ref, viewProvider); } @Override
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/osgi/ThermostatActivator.java Tue Nov 27 14:50:16 2012 -0500 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/osgi/ThermostatActivator.java Tue Nov 27 14:51:18 2012 -0500 @@ -47,7 +47,6 @@ import com.redhat.thermostat.client.core.views.ClientConfigViewProvider; import com.redhat.thermostat.client.core.views.HostInformationViewProvider; import com.redhat.thermostat.client.core.views.SummaryViewProvider; -import com.redhat.thermostat.client.core.views.VmCpuViewProvider; import com.redhat.thermostat.client.core.views.VmGcViewProvider; import com.redhat.thermostat.client.core.views.VmInformationViewProvider; import com.redhat.thermostat.client.osgi.service.HostDecorator; @@ -59,7 +58,6 @@ import com.redhat.thermostat.client.swing.views.SwingClientConfigurationViewProvider; import com.redhat.thermostat.client.swing.views.SwingHostInformationViewProvider; import com.redhat.thermostat.client.swing.views.SwingSummaryViewProvider; -import com.redhat.thermostat.client.swing.views.SwingVmCpuViewProvider; import com.redhat.thermostat.client.swing.views.SwingVmGcViewProvider; import com.redhat.thermostat.client.swing.views.SwingVmInformationViewProvider; import com.redhat.thermostat.client.ui.UiFacadeFactory; @@ -91,8 +89,6 @@ context.registerService(VmInformationViewProvider.class.getName(), vmInfoProvider, null); VmGcViewProvider vmGcProvider = new SwingVmGcViewProvider(); context.registerService(VmGcViewProvider.class.getName(), vmGcProvider, null); - VmCpuViewProvider vmCpuProvider = new SwingVmCpuViewProvider(); - context.registerService(VmCpuViewProvider.class.getName(), vmCpuProvider, null); // Summary view SummaryViewProvider summaryViewProvider = new SwingSummaryViewProvider();
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/views/SwingVmCpuViewProvider.java Tue Nov 27 14:50:16 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.swing.views; - -import com.redhat.thermostat.client.core.views.VmCpuView; -import com.redhat.thermostat.client.core.views.VmCpuViewProvider; - -public class SwingVmCpuViewProvider implements VmCpuViewProvider { - - @Override - public VmCpuView createView() { - return new VmCpuPanel(); - } - -}
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/views/VmCpuPanel.java Tue Nov 27 14:50:16 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,151 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.swing.views; - -import java.awt.Component; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JPanel; -import javax.swing.SwingUtilities; - -import org.jfree.chart.ChartFactory; -import org.jfree.chart.JFreeChart; -import org.jfree.data.time.FixedMillisecond; -import org.jfree.data.time.RegularTimePeriod; -import org.jfree.data.time.TimeSeries; -import org.jfree.data.time.TimeSeriesCollection; - -import com.redhat.thermostat.client.core.views.VmCpuView; -import com.redhat.thermostat.client.locale.LocaleResources; -import com.redhat.thermostat.client.swing.SwingComponent; -import com.redhat.thermostat.client.swing.components.HeaderPanel; -import com.redhat.thermostat.client.swing.components.RecentTimeSeriesChartPanel; -import com.redhat.thermostat.client.ui.ComponentVisibleListener; -import com.redhat.thermostat.client.ui.RecentTimeSeriesChartController; -import com.redhat.thermostat.common.ActionListener; -import com.redhat.thermostat.common.locale.Translate; -import com.redhat.thermostat.storage.model.DiscreteTimeData; - -public class VmCpuPanel extends VmCpuView implements SwingComponent { - - private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); - - private HeaderPanel visiblePanel; - - private final TimeSeriesCollection data = new TimeSeriesCollection(); - private final TimeSeries cpuTimeSeries = new TimeSeries("cpu-stats"); - - public VmCpuPanel() { - super(); - data.addSeries(cpuTimeSeries); - - initializePanel(); - - visiblePanel.addHierarchyListener(new ComponentVisibleListener() { - @Override - public void componentShown(Component component) { - notifier.fireAction(Action.VISIBLE); - } - - @Override - public void componentHidden(Component component) { - notifier.fireAction(Action.HIDDEN); - } - }); - } - - @Override - public void addActionListener(ActionListener<Action> listener) { - notifier.addActionListener(listener); - } - - @Override - public void removeActionListener(ActionListener<Action> listener) { - notifier.removeActionListener(listener); - } - - @Override - public Component getUiComponent() { - return visiblePanel; - } - - private void initializePanel() { - visiblePanel = new HeaderPanel(); - visiblePanel.setHeader(translator.localize(LocaleResources.VM_CPU_TITLE)); - - JFreeChart chart = ChartFactory.createTimeSeriesChart( - null, - translator.localize(LocaleResources.VM_CPU_CHART_TIME_LABEL), - translator.localize(LocaleResources.VM_CPU_CHART_LOAD_LABEL), - data, - false, false, false); - - chart.getXYPlot().getRangeAxis().setLowerBound(0.0); - - JPanel chartPanel = new RecentTimeSeriesChartPanel(new RecentTimeSeriesChartController(chart)); - - visiblePanel.setContent(chartPanel); - } - - @Override - public void addData(List<DiscreteTimeData<? extends Number>> data) { - final List<DiscreteTimeData<? extends Number>> copy = new ArrayList<>(data); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - for (DiscreteTimeData<? extends Number> data: copy) { - RegularTimePeriod period = new FixedMillisecond(data.getTimeInMillis()); - if (cpuTimeSeries.getDataItem(period) == null) { - cpuTimeSeries.add(period, data.getData(), false); - } - } - cpuTimeSeries.fireSeriesChanged(); - } - }); - } - - @Override - public void clearData() { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - cpuTimeSeries.clear(); - } - }); - } -}
--- a/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/osgi/ThermostatActivatorTest.java Tue Nov 27 14:50:16 2012 -0500 +++ b/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/osgi/ThermostatActivatorTest.java Tue Nov 27 14:51:18 2012 -0500 @@ -45,7 +45,6 @@ import com.redhat.thermostat.client.core.views.ClientConfigViewProvider; import com.redhat.thermostat.client.core.views.HostInformationViewProvider; import com.redhat.thermostat.client.core.views.SummaryViewProvider; -import com.redhat.thermostat.client.core.views.VmCpuViewProvider; import com.redhat.thermostat.client.core.views.VmGcViewProvider; import com.redhat.thermostat.client.core.views.VmInformationViewProvider; import com.redhat.thermostat.client.osgi.service.HostDecorator; @@ -54,7 +53,6 @@ import com.redhat.thermostat.client.swing.views.SwingClientConfigurationViewProvider; import com.redhat.thermostat.client.swing.views.SwingHostInformationViewProvider; import com.redhat.thermostat.client.swing.views.SwingSummaryViewProvider; -import com.redhat.thermostat.client.swing.views.SwingVmCpuViewProvider; import com.redhat.thermostat.client.swing.views.SwingVmGcViewProvider; import com.redhat.thermostat.client.swing.views.SwingVmInformationViewProvider; import com.redhat.thermostat.test.StubBundleContext; @@ -73,11 +71,10 @@ assertTrue(ctx.isServiceRegistered(SummaryViewProvider.class.getName(), SwingSummaryViewProvider.class)); assertTrue(ctx.isServiceRegistered(HostInformationViewProvider.class.getName(), SwingHostInformationViewProvider.class)); assertTrue(ctx.isServiceRegistered(VmInformationViewProvider.class.getName(), SwingVmInformationViewProvider.class)); - assertTrue(ctx.isServiceRegistered(VmCpuViewProvider.class.getName(), SwingVmCpuViewProvider.class)); assertTrue(ctx.isServiceRegistered(VmGcViewProvider.class.getName(), SwingVmGcViewProvider.class)); assertTrue(ctx.isServiceRegistered(AgentInformationViewProvider.class.getName(), SwingAgentInformationViewProvider.class)); assertTrue(ctx.isServiceRegistered(ClientConfigViewProvider.class.getName(), SwingClientConfigurationViewProvider.class)); - assertEquals(8, ctx.getAllServices().size()); + assertEquals(7, ctx.getAllServices().size()); } }
--- a/distribution/config/commands/gui.properties Tue Nov 27 14:50:16 2012 -0500 +++ b/distribution/config/commands/gui.properties Tue Nov 27 14:51:18 2012 -0500 @@ -15,6 +15,8 @@ thermostat-host-memory-client-swing-@project.version@.jar, \ thermostat-vm-overview-client-core-@project.version@.jar, \ thermostat-vm-overview-client-swing-@project.version@.jar, \ + thermostat-vm-cpu-client-core-@project.version@.jar, \ + thermostat-vm-cpu-client-swing-@project.version@.jar, \ thermostat-client-heapdumper-core-@project.version@.jar, \ thermostat-client-heapdumper-swing-@project.version@.jar, \ thermostat-killvm-client-swing-@project.version@.jar, \
--- a/distribution/pom.xml Tue Nov 27 14:50:16 2012 -0500 +++ b/distribution/pom.xml Tue Nov 27 14:51:18 2012 -0500 @@ -353,6 +353,16 @@ </dependency> <dependency> <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-vm-cpu-client-core</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-vm-cpu-client-swing</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> <artifactId>thermostat-client-vmclassstat-swing</artifactId> <version>${project.version}</version> </dependency>
--- a/eclipse/com.redhat.thermostat.client.feature/feature.xml Tue Nov 27 14:50:16 2012 -0500 +++ b/eclipse/com.redhat.thermostat.client.feature/feature.xml Tue Nov 27 14:51:18 2012 -0500 @@ -147,4 +147,11 @@ version="0.0.0" unpack="false"/> + <plugin + id="com.redhat.thermostat.vm.cpu.client.core" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + </feature>
--- a/eclipse/com.redhat.thermostat.client.feature/pom.xml Tue Nov 27 14:50:16 2012 -0500 +++ b/eclipse/com.redhat.thermostat.client.feature/pom.xml Tue Nov 27 14:51:18 2012 -0500 @@ -36,6 +36,11 @@ </dependency> <dependency> <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-vm-cpu-client-core</artifactId> + <version>0.5.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> <artifactId>thermostat-client-vmclassstat-core</artifactId> <version>0.5.0-SNAPSHOT</version> </dependency>
--- a/eclipse/com.redhat.thermostat.eclipse.chart.common/META-INF/MANIFEST.MF Tue Nov 27 14:50:16 2012 -0500 +++ b/eclipse/com.redhat.thermostat.eclipse.chart.common/META-INF/MANIFEST.MF Tue Nov 27 14:51:18 2012 -0500 @@ -7,10 +7,6 @@ Bundle-Vendor: Red Hat Inc. Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Import-Package: com.redhat.thermostat.client.core.views, - com.redhat.thermostat.host.cpu.client.core, - com.redhat.thermostat.host.cpu.client.locale, - com.redhat.thermostat.host.memory.client.core, - com.redhat.thermostat.host.memory.client.locale, com.redhat.thermostat.client.locale, com.redhat.thermostat.client.osgi.service, com.redhat.thermostat.client.ui, @@ -22,8 +18,14 @@ com.redhat.thermostat.common.utils, com.redhat.thermostat.eclipse, com.redhat.thermostat.eclipse.views, + com.redhat.thermostat.host.cpu.client.core, + com.redhat.thermostat.host.cpu.client.locale, + com.redhat.thermostat.host.memory.client.core, + com.redhat.thermostat.host.memory.client.locale, com.redhat.thermostat.storage.core, com.redhat.thermostat.storage.model, + com.redhat.thermostat.vm.cpu.client.core, + com.redhat.thermostat.vm.cpu.client.locale, org.jfree.chart, org.jfree.chart.axis, org.jfree.chart.event,
--- a/eclipse/com.redhat.thermostat.eclipse.chart.common/src/com/redhat/thermostat/eclipse/chart/common/Activator.java Tue Nov 27 14:50:16 2012 -0500 +++ b/eclipse/com.redhat.thermostat.eclipse.chart.common/src/com/redhat/thermostat/eclipse/chart/common/Activator.java Tue Nov 27 14:51:18 2012 -0500 @@ -39,11 +39,11 @@ import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; -import com.redhat.thermostat.client.core.views.VmCpuViewProvider; import com.redhat.thermostat.client.core.views.VmGcViewProvider; import com.redhat.thermostat.common.utils.OSGIUtils; import com.redhat.thermostat.host.cpu.client.core.HostCpuViewProvider; import com.redhat.thermostat.host.memory.client.core.HostMemoryViewProvider; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuViewProvider; public class Activator extends AbstractUIPlugin {
--- a/eclipse/com.redhat.thermostat.eclipse.chart.common/src/com/redhat/thermostat/eclipse/chart/common/SWTVmCpuView.java Tue Nov 27 14:50:16 2012 -0500 +++ b/eclipse/com.redhat.thermostat.eclipse.chart.common/src/com/redhat/thermostat/eclipse/chart/common/SWTVmCpuView.java Tue Nov 27 14:51:18 2012 -0500 @@ -51,11 +51,11 @@ import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; -import com.redhat.thermostat.client.core.views.VmCpuView; -import com.redhat.thermostat.client.locale.LocaleResources; import com.redhat.thermostat.common.locale.Translate; import com.redhat.thermostat.eclipse.SWTComponent; import com.redhat.thermostat.storage.model.DiscreteTimeData; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuView; +import com.redhat.thermostat.vm.cpu.client.locale.LocaleResources; public class SWTVmCpuView extends VmCpuView implements SWTComponent {
--- a/eclipse/com.redhat.thermostat.eclipse.chart.common/src/com/redhat/thermostat/eclipse/chart/common/SWTVmCpuViewProvider.java Tue Nov 27 14:50:16 2012 -0500 +++ b/eclipse/com.redhat.thermostat.eclipse.chart.common/src/com/redhat/thermostat/eclipse/chart/common/SWTVmCpuViewProvider.java Tue Nov 27 14:51:18 2012 -0500 @@ -36,9 +36,9 @@ package com.redhat.thermostat.eclipse.chart.common; -import com.redhat.thermostat.client.core.views.VmCpuView; -import com.redhat.thermostat.client.core.views.VmCpuViewProvider; import com.redhat.thermostat.eclipse.SWTViewProvider; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuView; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuViewProvider; public class SWTVmCpuViewProvider extends SWTViewProvider implements VmCpuViewProvider {
--- a/eclipse/com.redhat.thermostat.eclipse.chart.common/src/com/redhat/thermostat/eclipse/chart/common/VmCpuViewPart.java Tue Nov 27 14:50:16 2012 -0500 +++ b/eclipse/com.redhat.thermostat.eclipse.chart.common/src/com/redhat/thermostat/eclipse/chart/common/VmCpuViewPart.java Tue Nov 27 14:51:18 2012 -0500 @@ -38,13 +38,13 @@ import org.eclipse.swt.widgets.Composite; -import com.redhat.thermostat.client.core.views.VmCpuViewProvider; -import com.redhat.thermostat.client.ui.VmCpuController; import com.redhat.thermostat.common.dao.VmCpuStatDAO; import com.redhat.thermostat.common.dao.VmRef; import com.redhat.thermostat.common.utils.OSGIUtils; import com.redhat.thermostat.eclipse.SWTComponent; import com.redhat.thermostat.eclipse.views.VmRefViewPart; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuController; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuViewProvider; public class VmCpuViewPart extends VmRefViewPart {
--- a/eclipse/com.redhat.thermostat.eclipse.test.ui/META-INF/MANIFEST.MF Tue Nov 27 14:50:16 2012 -0500 +++ b/eclipse/com.redhat.thermostat.eclipse.test.ui/META-INF/MANIFEST.MF Tue Nov 27 14:51:18 2012 -0500 @@ -10,9 +10,6 @@ org.junit;bundle-version="4.10.0", org.hamcrest;bundle-version="1.1.0" Import-Package: com.redhat.thermostat.client.core.views, - com.redhat.thermostat.host.cpu.client.core, - com.redhat.thermostat.host.memory.client.core, - com.redhat.thermostat.host.overview.client.core, com.redhat.thermostat.client.osgi.service, com.redhat.thermostat.client.ui, com.redhat.thermostat.client.vmclassstat.core, @@ -22,7 +19,11 @@ com.redhat.thermostat.eclipse.chart.common, com.redhat.thermostat.eclipse.chart.vmclassstat, com.redhat.thermostat.eclipse.internal.views, + com.redhat.thermostat.host.cpu.client.core, + com.redhat.thermostat.host.memory.client.core, + com.redhat.thermostat.host.overview.client.core, com.redhat.thermostat.storage.model, + com.redhat.thermostat.vm.cpu.client.core, org.apache.log4j;version="1.2.13", org.eclipse.swtbot.eclipse.finder, org.eclipse.swtbot.eclipse.finder.matchers,
--- a/eclipse/com.redhat.thermostat.eclipse.test/META-INF/MANIFEST.MF Tue Nov 27 14:50:16 2012 -0500 +++ b/eclipse/com.redhat.thermostat.eclipse.test/META-INF/MANIFEST.MF Tue Nov 27 14:51:18 2012 -0500 @@ -13,9 +13,6 @@ com.redhat.thermostat.bundles.org.mockito.mockito-core;resolution:=optional Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Import-Package: com.redhat.thermostat.client.core.views, - com.redhat.thermostat.host.cpu.client.core, - com.redhat.thermostat.host.memory.client.core, - com.redhat.thermostat.host.overview.client.core, com.redhat.thermostat.client.osgi.service, com.redhat.thermostat.client.ui, com.redhat.thermostat.client.vmclassstat.core, @@ -28,6 +25,10 @@ com.redhat.thermostat.eclipse.internal.model, com.redhat.thermostat.eclipse.internal.views, com.redhat.thermostat.eclipse.views, + com.redhat.thermostat.host.cpu.client.core, + com.redhat.thermostat.host.memory.client.core, + com.redhat.thermostat.host.overview.client.core, + com.redhat.thermostat.vm.cpu.client.core, org.mockito, org.mockito.stubbing Export-Package: com.redhat.thermostat.eclipse.test.model,
--- a/eclipse/com.redhat.thermostat.eclipse.test/src/com/redhat/thermostat/eclipse/test/views/VmCpuViewPartTest.java Tue Nov 27 14:50:16 2012 -0500 +++ b/eclipse/com.redhat.thermostat.eclipse.test/src/com/redhat/thermostat/eclipse/test/views/VmCpuViewPartTest.java Tue Nov 27 14:51:18 2012 -0500 @@ -50,8 +50,6 @@ import org.junit.Test; import org.mockito.InOrder; -import com.redhat.thermostat.client.core.views.VmCpuViewProvider; -import com.redhat.thermostat.client.ui.VmCpuController; import com.redhat.thermostat.common.dao.HostRef; import com.redhat.thermostat.common.dao.VmCpuStatDAO; import com.redhat.thermostat.common.dao.VmRef; @@ -60,6 +58,8 @@ import com.redhat.thermostat.eclipse.chart.common.SWTVmCpuViewProvider; import com.redhat.thermostat.eclipse.chart.common.VmCpuViewPart; import com.redhat.thermostat.eclipse.internal.views.RefViewPart; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuController; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuViewProvider; public class VmCpuViewPartTest extends AbstractRefViewPartTest<VmRef> {
--- a/pom.xml Tue Nov 27 14:50:16 2012 -0500 +++ b/pom.xml Tue Nov 27 14:51:18 2012 -0500 @@ -135,6 +135,7 @@ <module>host-cpu</module> <module>host-memory</module> <module>vm-overview</module> + <module>vm-cpu</module> <!-- development related modules --> <module>dev</module> </modules>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-core/pom.xml Tue Nov 27 14:51:18 2012 -0500 @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>thermostat-vm-cpu</artifactId> + <groupId>com.redhat.thermostat</groupId> + <version>0.5.0-SNAPSHOT</version> + </parent> + <artifactId>thermostat-vm-cpu-client-core</artifactId> + <packaging>bundle</packaging> + <name>Thermostat VM CPU Core Client plugin</name> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Private-Package></Private-Package> + <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> + <Bundle-SymbolicName>com.redhat.thermostat.vm.cpu.client.core</Bundle-SymbolicName> + <Export-Package> + com.redhat.thermostat.vm.cpu.client.core, + com.redhat.thermostat.vm.cpu.client.locale + </Export-Package> + <!-- Do not autogenerate uses clauses in Manifests --> + <_nouses>true</_nouses> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-common-core</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-client-core</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> +</project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-core/src/main/java/com/redhat/thermostat/vm/cpu/client/core/VmCpuController.java Tue Nov 27 14:51:18 2012 -0500 @@ -0,0 +1,134 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.cpu.client.core; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import com.redhat.thermostat.client.core.controllers.VmInformationServiceController; +import com.redhat.thermostat.client.core.views.BasicView.Action; +import com.redhat.thermostat.client.core.views.UIComponent; +import com.redhat.thermostat.common.ActionEvent; +import com.redhat.thermostat.common.ActionListener; +import com.redhat.thermostat.common.NotImplementedException; +import com.redhat.thermostat.common.Timer; +import com.redhat.thermostat.common.Timer.SchedulingType; +import com.redhat.thermostat.common.appctx.ApplicationContext; +import com.redhat.thermostat.common.dao.VmCpuStatDAO; +import com.redhat.thermostat.common.dao.VmRef; +import com.redhat.thermostat.common.locale.Translate; +import com.redhat.thermostat.storage.model.DiscreteTimeData; +import com.redhat.thermostat.storage.model.VmCpuStat; +import com.redhat.thermostat.vm.cpu.client.locale.LocaleResources; + +public class VmCpuController implements VmInformationServiceController { + private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); + + private final VmRef ref; + private final VmCpuStatDAO dao; + private final VmCpuView view; + + private final Timer timer; + + private long lastSeenTimeStamp = Long.MIN_VALUE; + + public VmCpuController(VmCpuStatDAO vmCpuStatDao, VmRef ref, VmCpuViewProvider provider) { + this.ref = ref; + dao = vmCpuStatDao; + timer = ApplicationContext.getInstance().getTimerFactory().createTimer(); + + timer.setAction(new Runnable() { + @Override + public void run() { + doUpdateVmCpuCharts(); + } + }); + timer.setTimeUnit(TimeUnit.SECONDS); + timer.setDelay(5); + timer.setInitialDelay(0); + timer.setSchedulingType(SchedulingType.FIXED_RATE); + + view = provider.createView(); + + view.addActionListener(new ActionListener<VmCpuView.Action>() { + @Override + public void actionPerformed(ActionEvent<Action> actionEvent) { + switch (actionEvent.getActionId()) { + case HIDDEN: + stop(); + break; + case VISIBLE: + start(); + break; + default: + throw new NotImplementedException("unknown event : " + actionEvent.getActionId()); + } + } + }); + } + + private void start() { + timer.start(); + } + + private void doUpdateVmCpuCharts() { + List<VmCpuStat> stats = dao.getLatestVmCpuStats(ref, lastSeenTimeStamp); + List<DiscreteTimeData<? extends Number>> toDisplay = new ArrayList<>(stats.size()); + for (VmCpuStat stat: stats) { + DiscreteTimeData<? extends Number> data = + new DiscreteTimeData<Number>(stat.getTimeStamp(), stat.getCpuLoad()); + toDisplay.add(data); + lastSeenTimeStamp = Math.max(lastSeenTimeStamp, stat.getTimeStamp()); + } + + view.addData(toDisplay); + } + + private void stop() { + timer.stop(); + } + + public UIComponent getView() { + return (UIComponent) view; + } + + @Override + public String getLocalizedName() { + return translator.localize(LocaleResources.VM_INFO_TAB_CPU); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-core/src/main/java/com/redhat/thermostat/vm/cpu/client/core/VmCpuService.java Tue Nov 27 14:51:18 2012 -0500 @@ -0,0 +1,69 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.cpu.client.core; + +import com.redhat.thermostat.client.core.VmFilter; +import com.redhat.thermostat.client.core.VmInformationService; +import com.redhat.thermostat.client.core.controllers.VmInformationServiceController; +import com.redhat.thermostat.client.osgi.service.AlwaysMatchFilter; +import com.redhat.thermostat.common.dao.VmCpuStatDAO; +import com.redhat.thermostat.common.dao.VmRef; +import com.redhat.thermostat.common.utils.OSGIUtils; + +public class VmCpuService implements VmInformationService { + + private static final VmFilter FILTER = new AlwaysMatchFilter(); + + private VmCpuStatDAO vmCpuStatDAO; + + public VmCpuService(VmCpuStatDAO vmCpuStatDAO) { + this.vmCpuStatDAO = vmCpuStatDAO; + } + + @Override + public VmInformationServiceController getInformationServiceController( + VmRef ref) { + VmCpuViewProvider provider = OSGIUtils.getInstance().getService(VmCpuViewProvider.class); + return new VmCpuController(vmCpuStatDAO, ref, provider); + } + + @Override + public VmFilter getFilter() { + return FILTER; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-core/src/main/java/com/redhat/thermostat/vm/cpu/client/core/VmCpuView.java Tue Nov 27 14:51:18 2012 -0500 @@ -0,0 +1,51 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.cpu.client.core; + +import java.util.List; + +import com.redhat.thermostat.client.core.views.BasicView; +import com.redhat.thermostat.client.core.views.UIComponent; +import com.redhat.thermostat.storage.model.DiscreteTimeData; + +public abstract class VmCpuView extends BasicView implements UIComponent { + + public abstract void addData(List<DiscreteTimeData<? extends Number>> data); + + public abstract void clearData(); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-core/src/main/java/com/redhat/thermostat/vm/cpu/client/core/VmCpuViewProvider.java Tue Nov 27 14:51:18 2012 -0500 @@ -0,0 +1,45 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.cpu.client.core; + +import com.redhat.thermostat.client.core.views.ViewProvider; + +public interface VmCpuViewProvider extends ViewProvider { + + @Override + public VmCpuView createView(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-core/src/main/java/com/redhat/thermostat/vm/cpu/client/locale/LocaleResources.java Tue Nov 27 14:51:18 2012 -0500 @@ -0,0 +1,56 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.cpu.client.locale; + +import com.redhat.thermostat.common.locale.Translate; + +public enum LocaleResources { + + VM_INFO_TAB_CPU, + + VM_CPU_TITLE, + VM_CPU_CHART_LOAD_LABEL, + VM_CPU_CHART_TIME_LABEL, + ; + + static final String RESOURCE_BUNDLE = + "com.redhat.thermostat.vm.cpu.client.locale.strings"; + + public static Translate<LocaleResources> createLocalizer() { + return new Translate<>(RESOURCE_BUNDLE, LocaleResources.class); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-core/src/main/resources/com/redhat/thermostat/vm/cpu/client/locale/strings.properties Tue Nov 27 14:51:18 2012 -0500 @@ -0,0 +1,5 @@ +VM_INFO_TAB_CPU = CPU + +VM_CPU_TITLE = Cpu Usage by Virtual Machine +VM_CPU_CHART_LOAD_LABEL = % CPU +VM_CPU_CHART_TIME_LABEL = Time \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-core/src/test/java/com/redhat/thermostat/vm/cpu/client/core/VmCpuControllerTest.java Tue Nov 27 14:51:18 2012 -0500 @@ -0,0 +1,120 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.cpu.client.core; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; + +import com.redhat.thermostat.common.ActionEvent; +import com.redhat.thermostat.common.ActionListener; +import com.redhat.thermostat.common.Timer; +import com.redhat.thermostat.common.TimerFactory; +import com.redhat.thermostat.common.appctx.ApplicationContext; +import com.redhat.thermostat.common.appctx.ApplicationContextUtil; +import com.redhat.thermostat.common.dao.VmCpuStatDAO; +import com.redhat.thermostat.common.dao.VmRef; +import com.redhat.thermostat.storage.model.VmCpuStat; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuController; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuView; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuViewProvider; + + +public class VmCpuControllerTest { + + @Before + public void setUp() { + ApplicationContextUtil.resetApplicationContext(); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) // any(List.class) + @Test + public void testChartUpdate() { + + VmCpuStat stat1 = new VmCpuStat(123, 12345, 50.5); + List<VmCpuStat> stats = new ArrayList<VmCpuStat>(); + stats.add(stat1); + + VmCpuStatDAO vmCpuStatDAO = mock(VmCpuStatDAO.class); + when(vmCpuStatDAO.getLatestVmCpuStats(any(VmRef.class), eq(Long.MIN_VALUE))).thenReturn(stats).thenReturn(new ArrayList<VmCpuStat>()); + + VmRef ref = mock(VmRef.class); + + Timer timer = mock(Timer.class); + ArgumentCaptor<Runnable> timerActionCaptor = ArgumentCaptor.forClass(Runnable.class); + doNothing().when(timer).setAction(timerActionCaptor.capture()); + + TimerFactory timerFactory = mock(TimerFactory.class); + when(timerFactory.createTimer()).thenReturn(timer); + ApplicationContext.getInstance().setTimerFactory(timerFactory); + + final VmCpuView view = mock(VmCpuView.class); + ArgumentCaptor<ActionListener> viewArgumentCaptor = ArgumentCaptor.forClass(ActionListener.class); + doNothing().when(view).addActionListener(viewArgumentCaptor.capture()); + + VmCpuViewProvider viewProvider = mock(VmCpuViewProvider.class); + when(viewProvider.createView()).thenReturn(view); + + @SuppressWarnings("unused") + VmCpuController controller = new VmCpuController(vmCpuStatDAO, ref, viewProvider); + + ActionListener<VmCpuView.Action> l = viewArgumentCaptor.getValue(); + + l.actionPerformed(new ActionEvent<>(view, VmCpuView.Action.VISIBLE)); + + verify(timer).start(); + + timerActionCaptor.getValue().run(); + + l.actionPerformed(new ActionEvent<>(view, VmCpuView.Action.HIDDEN)); + + verify(timer).stop(); + + verify(view).addData(any(List.class)); + // We don't verify atMost() since we might increase the update rate in the future. + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-swing/pom.xml Tue Nov 27 14:51:18 2012 -0500 @@ -0,0 +1,82 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>thermostat-vm-cpu</artifactId> + <groupId>com.redhat.thermostat</groupId> + <version>0.5.0-SNAPSHOT</version> + </parent> + <artifactId>thermostat-vm-cpu-client-swing</artifactId> + <packaging>bundle</packaging> + <name>Thermostat VM CPU Swing Client plugin</name> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Private-Package>com.redhat.thermostat.vm.cpu.client.swing</Private-Package> + <Bundle-Activator>com.redhat.thermostat.vm.cpu.client.swing.Activator</Bundle-Activator> + <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> + <Bundle-SymbolicName>com.redhat.thermostat.vm.cpu.client.swing</Bundle-SymbolicName> + <!-- Do not autogenerate uses clauses in Manifests --> + <_nouses>true</_nouses> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.easytesting</groupId> + <artifactId>fest-swing</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>net.java.openjdk.cacio</groupId> + <artifactId>cacio-tta</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.jfree</groupId> + <artifactId>jfreechart</artifactId> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-common-core</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-client-swing</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-vm-cpu-client-core</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> +</project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-swing/src/main/java/com/redhat/thermostat/vm/cpu/client/swing/Activator.java Tue Nov 27 14:51:18 2012 -0500 @@ -0,0 +1,89 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.cpu.client.swing; + +import java.util.Objects; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; +import org.osgi.util.tracker.ServiceTracker; + +import com.redhat.thermostat.client.core.VmInformationService; +import com.redhat.thermostat.common.dao.VmCpuStatDAO; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuService; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuViewProvider; + +public class Activator implements BundleActivator { + + private ServiceTracker tracker; + private ServiceRegistration reg; + + @Override + public void start(final BundleContext context) throws Exception { + VmCpuViewProvider viewProvider = new SwingVmCpuViewProvider(); + context.registerService(VmCpuViewProvider.class.getName(), viewProvider, null); + + tracker = new ServiceTracker(context, VmCpuStatDAO.class.getName(), null) { + + @Override + public Object addingService(ServiceReference reference) { + VmCpuStatDAO vmCpuStatDAO = (VmCpuStatDAO) context.getService(reference); + Objects.requireNonNull(vmCpuStatDAO); + VmCpuService service = new VmCpuService(vmCpuStatDAO); + reg = context.registerService(VmInformationService.class.getName(), service, null); + + return super.addingService(reference); + } + + @Override + public void removedService(ServiceReference reference, Object service) { + context.ungetService(reference); + reg.unregister(); + } + }; + tracker.open(); + } + + @Override + public void stop(BundleContext context) throws Exception { + tracker.close(); + } + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-swing/src/main/java/com/redhat/thermostat/vm/cpu/client/swing/SwingVmCpuViewProvider.java Tue Nov 27 14:51:18 2012 -0500 @@ -0,0 +1,49 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.cpu.client.swing; + +import com.redhat.thermostat.vm.cpu.client.core.VmCpuView; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuViewProvider; + +public class SwingVmCpuViewProvider implements VmCpuViewProvider { + + @Override + public VmCpuView createView() { + return new VmCpuPanel(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-swing/src/main/java/com/redhat/thermostat/vm/cpu/client/swing/VmCpuPanel.java Tue Nov 27 14:51:18 2012 -0500 @@ -0,0 +1,151 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.cpu.client.swing; + +import java.awt.Component; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.data.time.FixedMillisecond; +import org.jfree.data.time.RegularTimePeriod; +import org.jfree.data.time.TimeSeries; +import org.jfree.data.time.TimeSeriesCollection; + +import com.redhat.thermostat.client.swing.SwingComponent; +import com.redhat.thermostat.client.swing.components.HeaderPanel; +import com.redhat.thermostat.client.swing.components.RecentTimeSeriesChartPanel; +import com.redhat.thermostat.client.ui.ComponentVisibleListener; +import com.redhat.thermostat.client.ui.RecentTimeSeriesChartController; +import com.redhat.thermostat.common.ActionListener; +import com.redhat.thermostat.common.locale.Translate; +import com.redhat.thermostat.storage.model.DiscreteTimeData; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuView; +import com.redhat.thermostat.vm.cpu.client.locale.LocaleResources; + +public class VmCpuPanel extends VmCpuView implements SwingComponent { + + private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); + + private HeaderPanel visiblePanel; + + private final TimeSeriesCollection data = new TimeSeriesCollection(); + private final TimeSeries cpuTimeSeries = new TimeSeries("cpu-stats"); + + public VmCpuPanel() { + super(); + data.addSeries(cpuTimeSeries); + + initializePanel(); + + visiblePanel.addHierarchyListener(new ComponentVisibleListener() { + @Override + public void componentShown(Component component) { + notifier.fireAction(Action.VISIBLE); + } + + @Override + public void componentHidden(Component component) { + notifier.fireAction(Action.HIDDEN); + } + }); + } + + @Override + public void addActionListener(ActionListener<Action> listener) { + notifier.addActionListener(listener); + } + + @Override + public void removeActionListener(ActionListener<Action> listener) { + notifier.removeActionListener(listener); + } + + @Override + public Component getUiComponent() { + return visiblePanel; + } + + private void initializePanel() { + visiblePanel = new HeaderPanel(); + visiblePanel.setHeader(translator.localize(LocaleResources.VM_CPU_TITLE)); + + JFreeChart chart = ChartFactory.createTimeSeriesChart( + null, + translator.localize(LocaleResources.VM_CPU_CHART_TIME_LABEL), + translator.localize(LocaleResources.VM_CPU_CHART_LOAD_LABEL), + data, + false, false, false); + + chart.getXYPlot().getRangeAxis().setLowerBound(0.0); + + JPanel chartPanel = new RecentTimeSeriesChartPanel(new RecentTimeSeriesChartController(chart)); + + visiblePanel.setContent(chartPanel); + } + + @Override + public void addData(List<DiscreteTimeData<? extends Number>> data) { + final List<DiscreteTimeData<? extends Number>> copy = new ArrayList<>(data); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + for (DiscreteTimeData<? extends Number> data: copy) { + RegularTimePeriod period = new FixedMillisecond(data.getTimeInMillis()); + if (cpuTimeSeries.getDataItem(period) == null) { + cpuTimeSeries.add(period, data.getData(), false); + } + } + cpuTimeSeries.fireSeriesChanged(); + } + }); + } + + @Override + public void clearData() { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + cpuTimeSeries.clear(); + } + }); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/client-swing/src/test/java/com/redhat/thermostat/vm/cpu/client/swing/ActivatorTest.java Tue Nov 27 14:51:18 2012 -0500 @@ -0,0 +1,98 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.cpu.client.swing; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +import org.junit.Test; + +import com.redhat.thermostat.client.core.VmInformationService; +import com.redhat.thermostat.common.dao.VmCpuStatDAO; +import com.redhat.thermostat.test.StubBundleContext; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuService; +import com.redhat.thermostat.vm.cpu.client.core.VmCpuViewProvider; + +public class ActivatorTest { + + @Test + public void verifyActivatorDoesNotRegisterServiceOnMissingDeps() throws Exception { + StubBundleContext context = new StubBundleContext(); + + Activator activator = new Activator(); + + activator.start(context); + + // View provider registers unconditionally + assertEquals(1, context.getAllServices().size()); + assertEquals(1, context.getServiceListeners().size()); + + activator.stop(context); + + assertEquals(0, context.getServiceListeners().size()); + } + + @Test + public void verifyActivatorRegistersServices() throws Exception { + StubBundleContext context = new StubBundleContext(); + VmCpuStatDAO vmCpuStatDAO = mock(VmCpuStatDAO.class); + + context.registerService(VmCpuStatDAO.class, vmCpuStatDAO, null); + + Activator activator = new Activator(); + + activator.start(context); + + assertTrue(context.isServiceRegistered(VmInformationService.class.getName(), VmCpuService.class)); + + activator.stop(context); + + assertEquals(0, context.getServiceListeners().size()); + assertEquals(2, context.getAllServices().size()); + } + + @Test + public void verifyStartRegistersViewProvider() throws Exception { + StubBundleContext ctx = new StubBundleContext(); + Activator activator = new Activator(); + activator.start(ctx); + assertTrue(ctx.isServiceRegistered(VmCpuViewProvider.class.getName(), SwingVmCpuViewProvider.class)); + assertEquals(1, ctx.getAllServices().size()); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-cpu/pom.xml Tue Nov 27 14:51:18 2012 -0500 @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright 2012 Red Hat, Inc. + + This file is part of Thermostat. + + Thermostat is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + Thermostat is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Thermostat; see the file COPYING. If not see + <http://www.gnu.org/licenses />. + + Linking this code with other modules is making a combined work + based on this code. Thus, the terms and conditions of the GNU + General Public License cover the whole combination. + + As a special exception, the copyright holders of this code give + you permission to link this code with independent modules to + produce an executable, regardless of the license terms of these + independent modules, and to copy and distribute the resulting + executable under terms of your choice, provided that you also + meet, for each linked independent module, the terms and conditions + of the license of that module. An independent module is a module + which is not derived from or based on this code. If you modify + this code, you may extend this exception to your version of the + library, but you are not obligated to do so. If you do not wish + to do so, delete this exception statement from your version. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat</artifactId> + <version>0.5.0-SNAPSHOT</version> + </parent> + + <artifactId>thermostat-vm-cpu</artifactId> + <packaging>pom</packaging> + + <name>Thermostat VM CPU plugin</name> + + <modules> + <module>client-core</module> + <module>client-swing</module> + </modules> + +</project>