changeset 706:836bac77a113

Merge
author Roman Kennke <rkennke@redhat.com>
date Fri, 19 Oct 2012 19:59:30 +0200
parents 498473c85300 (current diff) b15571e2ce7d (diff)
children 3d4608e2e01f
files
diffstat 6 files changed, 251 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile	Fri Oct 19 19:59:30 2012 +0200
@@ -0,0 +1,44 @@
+MAVEN           = mvn
+SKIP_TESTS      = false
+REPO_LOC        = $(HOME)/.thermostat/.build/mvn_repository
+MAVEN_FLAGS     = 
+
+#
+# Do not change anything below
+#
+REPO_FLAG       = -Dmaven.repo.local=$(REPO_LOC)
+GOAL            = package
+POM             = pom.xml
+
+ifeq ($(SKIP_TESTS),true)
+	MAVEN_SKIP_TEST = -Dmaven.test.skip=true
+endif
+
+all: eclipse
+
+core:
+	$(MAVEN) -f $(POM) $(MAVEN_FLAGS) $(MAVEN_SKIP_TEST) clean $(GOAL)
+
+core-install: create-repo-dir
+	$(MAVEN) -f $(POM) $(MAVEN_FLAGS) $(REPO_FLAG) $(MAVEN_SKIP_TEST) clean install
+
+eclipse-test-deps: core-install
+	$(MAVEN) -f eclipse/test-deps-bundle-wrapping/pom.xml $(MAVEN_FLAGS) $(REPO_FLAG) $(MAVEN_SKIP_TEST) clean install
+
+eclipse-test-p2: eclipse-test-deps
+	$(MAVEN) -f eclipse/test-deps-p2-repository/pom.xml $(MAVEN_FLAGS) $(REPO_FLAG) $(MAVEN_SKIP_TEST) clean $(GOAL)
+
+eclipse: eclipse-test-p2
+	$(MAVEN) -f eclipse/pom.xml $(MAVEN_FLAGS) $(REPO_FLAG) $(MAVEN_SKIP_TEST) clean $(GOAL)
+
+create-repo-dir:
+	mkdir -p $(REPO_LOC)
+
+clean-repo:
+	find $(REPO_LOC)/com/redhat/thermostat -print0 | xargs -0 rm -rf
+
+echo-repo:
+	echo "Using private Maven repository: $(REPO_LOC)"
+
+# We only have phony targets
+.PHONY:	all core eclipse-test-deps eclipse-test-p2 eclipse create-repo-dir clean-repo echo-repo
--- a/README	Fri Oct 19 19:54:24 2012 +0200
+++ b/README	Fri Oct 19 19:59:30 2012 +0200
@@ -1,17 +1,23 @@
 Thank you for downloading Thermostat.
 
-This document contains the following information useful to compile and run
-Thermostat:
+
+CONTENT:
+--------------------------------------------------------------------------------
 
-1. REQUIREMENTS
-2. BUILDING THERMOSTAT
-3. RUNNING THERMOSTAT
-4. PASSING JVM SPECIFIC OPTIONS
-5. GNOME KEYRING
+1.  REQUIREMENTS
+2.  BUILDING THERMOSTAT
+2.1   BUILDING THERMOSTAT CORE
+2.2   BUILDING THERMOSTAT ECLIPSE
+3.  RUNNING THERMOSTAT
+3.1   RUNNING THERMOSTAT CORE
+3.1.1 PASSING JVM SPECIFIC OPTIONS
+3.1.2 GNOME KEYRING
+3.2   RUNNING THERMOSTAT ECLIPSE
+4.  REFERECES
 
 
 --------------------------------------------------------------------------------
-REQUIREMENTS
+1. REQUIREMENTS
 
 * OpenJDK7
 
@@ -20,6 +26,8 @@
 
 * Maven (it will download all the java dependencies for you)
 
+* Make
+
 * MongoDB server
 
 Thermostat requires mongodb (http://www.mongodb.org/) server >= 2.0.0
@@ -44,40 +52,74 @@
    aptitude install libgnome-keyring-dev
 
 --------------------------------------------------------------------------------
-BUILDING THERMOSTAT
+2. BUILDING THERMOSTAT
+
+Thermostat consists of "Thermostat Core" and "Thermostat Eclipse".
 
-1. Run "mvn clean package". All tests should pass and the build should succeed.
+Thermostat Core consists of:
+  * CLI client
+  * Swing GUI client
+  * The thermostat agent
+
+Thermostat Eclipse is an Eclipse-based Thermostat client.
+
+--------------------------------------------------------------------------------
+2.1. BUILDING THERMOSTAT CORE
+
+2.1.1.
+   Run "make core". All tests should pass and the build should succeed.
    Requires a graphical environment for the ui tests.
    
    You can skip the tests phase by running:
    
-   mvn clean package -Dmaven.test.skip=true
+   make core SKIP_TESTS=true
 
-   If maven is too chatty, you can try to pass the -q option too:
+   If maven is too chatty, you can try to pass the "-q" option via MAVEN_FLAGS::
    
-   mvn -q clean package -Dmaven.test.skip=true
+   make core SKIP_TESTS=true MAVEN_FLAGS="-q"
    
-2. The resultant Thermostat system can now be found under the directory
+2.1.2.
+   The resulting Thermostat system can now be found under the directory
    distribution/target.
            
-            
 --------------------------------------------------------------------------------
-RUNNING THERMOSTAT
+2.2. BUILDING THERMOSTAT ECLIPSE
+
+2.2.1.
+   Run "make eclipse". This will build both, Thermostat Core and Thermostat
+   Eclipse. All tests should pass and the build should succeed. Running Eclipse
+   plug-in tests will open an Eclipse instance during build. This requires a
+   working graphical environment and DISPLAY.
 
-0. cd into distribution/target directory just created
+   You can skip the tests phase by running:
+
+   make eclipse SKIP_TESTS=true
+
+2.2.2.
+   This produces a local "update-site" or p2 repository from which you can
+   install Thermostat Eclipse into your Eclipse. The repository is at:
 
-1. To start the agent and the db:
-   bin/thermostat service
+   eclipse/composite-repo/target/composite-repo
+
+--------------------------------------------------------------------------------
+3. RUNNING THERMOSTAT
+
+--------------------------------------------------------------------------------
+3.1. RUNNING THERMOSTAT CORE
 
-2. To start the gui client:
-   bin/thermostat gui
+  cd into distribution/target directory just created
+
+  To start the agent and the db:
+  bin/thermostat service --start
 
-3. To start the cli client:
-   bin/thermostat [--help]
+  To start the gui client:
+  bin/thermostat gui
+
+  To start the cli client:
+  bin/thermostat [--help]
 
 
---------------------------------------------------------------------------------
-PASSING JVM SPECIFIC OPTIONS
+3.1.1. PASSING JVM SPECIFIC OPTIONS
 
 In some cases, it may be desirable to pass arguments to the virtual machine,
 for example to increase memory or change the look and feel for the Swing Client.
@@ -93,8 +135,7 @@
     -J-Dswing.defaultlaf=javax.swing.plaf.nimbus.NimbusLookAndFeel
 
 
---------------------------------------------------------------------------------
-GNOME KEYRING
+3.1.2. GNOME KEYRING
 
 Thermostat includes experimental support to store user credentials in the
 Gnome Keyring daemon, this support is currently limited to passwords only.
@@ -113,3 +154,27 @@
 saved in the user session keychain and available to other applications that
 can access the keyring. 
 
+--------------------------------------------------------------------------------
+3.2. RUNNING THERMOSTAT ECLIPSE
+
+  The "eclipse/composite-repo/target/composite-repo" directory was
+  produced during step 2.2. In order to use this local repository
+  follow these steps:
+
+    "Help" => "Install New Software..."
+    "Add..."
+    "Local..."
+    Select "eclipse/composite-repo/target/composite-repo"
+    Give it any name you like and click "OK".
+    Select "Thermostat Eclipse Plug-ins", then "Next >"
+    Click through dialog, accepting options.
+   
+  After this you should be able to see Thermostat views in Eclipse:
+    "Window" => "Show View" => "Other..." => "Thermostat" 
+            
+
+--------------------------------------------------------------------------------
+4. REFERECES
+
+  User Guide:
+    http://icedtea.classpath.org/wiki/Thermostat/UserGuide
--- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDumpController.java	Fri Oct 19 19:54:24 2012 +0200
+++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDumpController.java	Fri Oct 19 19:59:30 2012 +0200
@@ -206,6 +206,15 @@
     }
 
     class HeapOverviewDataCollector implements Runnable {
+
+        private long desiredUpdateTimeStamp = System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1);
+
+        @Override
+        public void run() {
+            checkForHeapDumps();
+            updateMemoryChartAndDisplay();
+        }
+
         private void checkForHeapDumps() {
             Collection<HeapInfo> heapInfos = heapDAO.getAllHeapInfo(ref);
             List<HeapDump> heapDumps = new ArrayList<HeapDump>(heapInfos.size());
@@ -215,10 +224,10 @@
             view.updateHeapDumpList(heapDumps);
         }
 
-        @Override
-        public void run() {
-            checkForHeapDumps();
-            List<VmMemoryStat> vmInfo = vmDao.getLatestVmMemoryStats(ref, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1));
+        private void updateMemoryChartAndDisplay() {
+            List<VmMemoryStat> vmInfo = null;
+            vmInfo = vmDao.getLatestVmMemoryStats(ref, desiredUpdateTimeStamp);
+
             for (VmMemoryStat memoryStats: vmInfo) {
                 long used = 0l;
                 long capacity = 0l;
@@ -251,9 +260,11 @@
                 String _capacity= formatter.format(capacity) + " " + Scale.B;
                 
                 view.updateUsedAndCapacity(_used, _capacity);
+                desiredUpdateTimeStamp = Math.max(desiredUpdateTimeStamp, memoryStats.getTimeStamp());
             }
 
             model.notifyListenersOfModelChange();
         }
+
     }
 }
--- a/client/heapdumper/src/test/java/com/redhat/thermostat/client/heap/HeapDumpControllerTest.java	Fri Oct 19 19:54:24 2012 +0200
+++ b/client/heapdumper/src/test/java/com/redhat/thermostat/client/heap/HeapDumpControllerTest.java	Fri Oct 19 19:59:30 2012 +0200
@@ -38,6 +38,8 @@
 
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.isA;
 import static org.mockito.Matchers.same;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.mock;
@@ -46,8 +48,10 @@
 import static org.mockito.Mockito.when;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 import org.junit.After;
 import org.junit.Before;
@@ -70,6 +74,9 @@
 import com.redhat.thermostat.common.dao.VmRef;
 import com.redhat.thermostat.common.heap.HeapDump;
 import com.redhat.thermostat.common.model.HeapInfo;
+import com.redhat.thermostat.common.model.VmMemoryStat;
+import com.redhat.thermostat.common.model.VmMemoryStat.Generation;
+import com.redhat.thermostat.common.model.VmMemoryStat.Space;
 
 public class HeapDumpControllerTest {
 
@@ -310,4 +317,89 @@
         assertTrue(heapDumps.getValue().contains(new HeapDump(info1, heapDao)));
         assertTrue(heapDumps.getValue().contains(new HeapDump(info2, heapDao)));
     }
+
+    @Test
+    public void testTimerFetchesMemoryDataAndUpdatesView() {
+        createController();
+        Runnable timerAction = timerActionCaptor.getValue();
+
+        final long CAPACITY = 10;
+        final long USED = 5;
+        Space space = new Space();
+        space.capacity = CAPACITY;
+        space.maxCapacity = 20;
+        space.used = USED;
+        Generation gen = new Generation();
+        gen.name = "foobar";
+        gen.spaces = Arrays.asList(space);
+        VmMemoryStat stat = new VmMemoryStat();
+        stat.setGenerations(Arrays.asList(gen));
+
+        when(vmDao.getLatestVmMemoryStats(isA(VmRef.class), anyLong())).thenReturn(Arrays.asList(stat));
+
+        timerAction.run();
+
+        ArgumentCaptor<Long> timeStampCaptor = ArgumentCaptor.forClass(Long.class);
+        verify(vmDao).getLatestVmMemoryStats(isA(VmRef.class), timeStampCaptor.capture());
+        assertTimeStampIsAround(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1), timeStampCaptor.getValue());
+        verify(view).updateUsedAndCapacity(USED + " B", CAPACITY + " B");
+    }
+
+    @Test
+    public void testTimerFetchesMemoryDataDeltaOnly() {
+        ArgumentCaptor<Long> timeStampCaptor = ArgumentCaptor.forClass(Long.class);
+
+        final long DATA_TIMESTAMP = System.currentTimeMillis() + 1000000000;
+        Space space = new Space();
+        space.capacity = 10;
+        space.maxCapacity = 20;
+        space.used = 5;
+        Generation gen = new Generation();
+        gen.name = "foobar";
+        gen.spaces = Arrays.asList(space);
+        VmMemoryStat stat = new VmMemoryStat();
+        stat.setTimeStamp(DATA_TIMESTAMP);
+        stat.setGenerations(Arrays.asList(gen));
+
+        when(vmDao.getLatestVmMemoryStats(isA(VmRef.class), anyLong())).thenReturn(Arrays.asList(stat));
+
+        createController();
+        Runnable timerAction = timerActionCaptor.getValue();
+
+        timerAction.run();
+        timerAction.run();
+
+        verify(vmDao, times(2)).getLatestVmMemoryStats(isA(VmRef.class), timeStampCaptor.capture());
+
+        long timeStamp1 = timeStampCaptor.getAllValues().get(0);
+        assertTimeStampIsAround(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1), timeStamp1);
+
+        long timeStamp2 = timeStampCaptor.getAllValues().get(1);
+        assertTimeStampIsAround(DATA_TIMESTAMP, timeStamp2);
+    }
+
+    @Test
+    public void testTimerFetchesMemoryDataDeltaOnlyEvenWithNoData() {
+        ArgumentCaptor<Long> timeStampCaptor = ArgumentCaptor.forClass(Long.class);
+
+        createController();
+        Runnable timerAction = timerActionCaptor.getValue();
+
+        timerAction.run();
+        timerAction.run();
+
+        verify(vmDao, times(2)).getLatestVmMemoryStats(isA(VmRef.class), timeStampCaptor.capture());
+
+        long timeStamp1 = timeStampCaptor.getAllValues().get(0);
+        assertTimeStampIsAround(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1), timeStamp1);
+
+        long timeStamp2 = timeStampCaptor.getAllValues().get(1);
+        assertTimeStampIsAround(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1), timeStamp2);
+    }
+
+    private void assertTimeStampIsAround(long expected, long actual) {
+        assertTrue(actual <= expected + 1000);
+        assertTrue(actual >= expected - 1000);
+    }
+
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/core/p2.inf	Fri Oct 19 19:59:30 2012 +0200
@@ -0,0 +1,7 @@
+# Instructs Eclipse update manager to auto-start this bundle
+instructions.configure = \
+org.eclipse.equinox.p2.touchpoint.eclipse.setStartLevel(startLevel: 4); \
+org.eclipse.equinox.p2.touchpoint.eclipse.markStarted(started: true);
+instructions.unconfigure = \
+org.eclipse.equinox.p2.touchpoint.eclipse.setStartLevel(startLevel: -1); \
+org.eclipse.equinox.p2.touchpoint.eclipse.markStarted(started: false);
--- a/common/core/pom.xml	Fri Oct 19 19:54:24 2012 +0200
+++ b/common/core/pom.xml	Fri Oct 19 19:59:30 2012 +0200
@@ -97,6 +97,7 @@
             </Private-Package>
             <!-- Do not autogenerate uses clauses in Manifests -->
             <_nouses>true</_nouses>
+            <Include-Resource>META-INF/p2.inf=p2.inf</Include-Resource>
           </instructions>
         </configuration>
       </plugin>