changeset 383:1974926fb7a0

Added missing license header, clarify MongoStorage new methods. Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-June/001864.html PR 1032
author Roman Kennke <rkennke@redhat.com>
date Mon, 18 Jun 2012 20:15:58 +0200
parents 4b2b830097f3
children b1aa706a6ce9
files common/core/src/main/java/com/redhat/thermostat/common/dao/HeapDAO.java common/core/src/main/java/com/redhat/thermostat/common/dao/HeapDAOImpl.java common/core/src/main/java/com/redhat/thermostat/common/model/HeapInfo.java common/core/src/main/java/com/redhat/thermostat/common/storage/MongoStorage.java common/core/src/test/java/com/redhat/thermostat/common/dao/HeapDAOTest.java common/core/src/test/java/com/redhat/thermostat/common/model/HeapInfoTest.java
diffstat 6 files changed, 198 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/common/core/src/main/java/com/redhat/thermostat/common/dao/HeapDAO.java	Mon Jun 18 12:48:34 2012 -0400
+++ b/common/core/src/main/java/com/redhat/thermostat/common/dao/HeapDAO.java	Mon Jun 18 20:15:58 2012 +0200
@@ -1,3 +1,39 @@
+/*
+ * 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.common.dao;
 
 import com.redhat.thermostat.common.model.HeapInfo;
--- a/common/core/src/main/java/com/redhat/thermostat/common/dao/HeapDAOImpl.java	Mon Jun 18 12:48:34 2012 -0400
+++ b/common/core/src/main/java/com/redhat/thermostat/common/dao/HeapDAOImpl.java	Mon Jun 18 20:15:58 2012 +0200
@@ -1,3 +1,39 @@
+/*
+ * 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.common.dao;
 
 import java.io.InputStream;
--- a/common/core/src/main/java/com/redhat/thermostat/common/model/HeapInfo.java	Mon Jun 18 12:48:34 2012 -0400
+++ b/common/core/src/main/java/com/redhat/thermostat/common/model/HeapInfo.java	Mon Jun 18 20:15:58 2012 +0200
@@ -1,3 +1,39 @@
+/*
+ * 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.common.model;
 
 import java.io.InputStream;
--- a/common/core/src/main/java/com/redhat/thermostat/common/storage/MongoStorage.java	Mon Jun 18 12:48:34 2012 -0400
+++ b/common/core/src/main/java/com/redhat/thermostat/common/storage/MongoStorage.java	Mon Jun 18 20:15:58 2012 +0200
@@ -100,14 +100,17 @@
         this.agentId = agentId;
     }
 
-    private BasicDBObject getAgentDBObject() {
-        return new BasicDBObject(KEY_AGENT_ID, agentId.toString());
+    private BasicDBObject getAgentQueryKeyFromGlobalAgent() {
+        if (agentId != null) {
+            return new BasicDBObject(KEY_AGENT_ID, agentId.toString());
+        } else {
+            return null;
+        }
     }
 
-    private BasicDBObject getAgentDBObject(Chunk chunk) {
-        if (agentId != null) {
-            return getAgentDBObject();
-        } else if (chunk.get(Key.AGENT_ID) != null) {
+    private BasicDBObject getAgentQueryKeyFromChunkOrGlobalAgent(Chunk chunk) {
+        BasicDBObject queryKey = getAgentQueryKeyFromGlobalAgent();
+        if (queryKey == null && chunk.get(Key.AGENT_ID) != null) {
             return new BasicDBObject(KEY_AGENT_ID, chunk.get(Key.AGENT_ID));
         } else {
             return null;
@@ -118,13 +121,13 @@
     public void putChunk(Chunk chunk) {
         Category cat = chunk.getCategory();
         DBCollection coll = getCachedCollection(cat.getName());
-        BasicDBObject toInsert = getAgentDBObject(chunk);
+        BasicDBObject toInsert = getAgentQueryKeyFromChunkOrGlobalAgent(chunk);
         BasicDBObject replaceKey = null;
         boolean replace = chunk.getReplace();
         Map<String, BasicDBObject> nestedParts = new HashMap<String, BasicDBObject>();
         Map<String, BasicDBObject> replaceKeyNestedParts = null;
         if (replace) {
-            replaceKey = getAgentDBObject(chunk);
+            replaceKey = getAgentQueryKeyFromChunkOrGlobalAgent(chunk);
             replaceKeyNestedParts = new HashMap<String, BasicDBObject>();
         }
         for (Key<?> key : cat.getKeys()) {
@@ -180,7 +183,7 @@
         Category cat = chunk.getCategory();
         DBCollection coll = getCachedCollection(cat.getName());
         BasicDBObject toUpdate = new BasicDBObject();
-        BasicDBObject updateKey = getAgentDBObject(chunk);
+        BasicDBObject updateKey = getAgentQueryKeyFromChunkOrGlobalAgent(chunk);
         Map<String, BasicDBObject> nestedParts = new HashMap<String, BasicDBObject>();
         Map<String, BasicDBObject> updateKeyNestedParts = new HashMap<String, BasicDBObject>();
         for (Key<?> key : cat.getKeys()) {
@@ -245,7 +248,7 @@
     }
 
     private DBObject createConfigDBObject(AgentInformation agentInfo) {
-        BasicDBObject result = getAgentDBObject();
+        BasicDBObject result = getAgentQueryKeyFromGlobalAgent();
         result.put(StorageConstants.KEY_AGENT_CONFIG_AGENT_START_TIME, agentInfo.getStartTime());
         result.put(StorageConstants.KEY_AGENT_CONFIG_AGENT_STOP_TIME, agentInfo.getStopTime());
         result.put(StorageConstants.KEY_AGENT_CONFIG_AGENT_ALIVE, agentInfo.isAlive());
@@ -281,7 +284,7 @@
 
     @Override
     public void purge() {
-        BasicDBObject deleteKey = getAgentDBObject();
+        BasicDBObject deleteKey = getAgentQueryKeyFromGlobalAgent();
         for (DBCollection coll : collectionCache.values()) {
             coll.remove(deleteKey);
         }
@@ -347,13 +350,13 @@
         DBCollection configCollection = db.getCollection(StorageConstants.CATEGORY_AGENT_CONFIG);
         DBObject toInsert = createConfigDBObject(agentInfo);
         /* cast required to disambiguate between putAll(BSONObject) and putAll(Map) */
-        toInsert.putAll((BSONObject) getAgentDBObject());
+        toInsert.putAll((BSONObject) getAgentQueryKeyFromGlobalAgent());
         configCollection.insert(toInsert, WriteConcern.SAFE);
     }
     
     @Override
     public void updateAgentInformation(AgentInformation agentInfo) {
-        BasicDBObject queryObject = getAgentDBObject();
+        BasicDBObject queryObject = getAgentQueryKeyFromGlobalAgent();
 
         DBObject updated = createConfigDBObject(agentInfo);
         updated.putAll((BSONObject) queryObject);
@@ -365,14 +368,14 @@
     @Override
     public void removeAgentInformation() {
         DBCollection configCollection = db.getCollection(StorageConstants.CATEGORY_AGENT_CONFIG);
-        BasicDBObject toRemove = getAgentDBObject();
+        BasicDBObject toRemove = getAgentQueryKeyFromGlobalAgent();
         configCollection.remove(toRemove, WriteConcern.NORMAL);
     }
 
     @Override
     public String getBackendConfig(String backendName, String configurationKey) {
         DBCollection configCollection = db.getCollection(StorageConstants.CATEGORY_AGENT_CONFIG);
-        BasicDBObject query = getAgentDBObject();
+        BasicDBObject query = getAgentQueryKeyFromGlobalAgent();
         query.put(StorageConstants.KEY_AGENT_CONFIG_BACKENDS + "." + backendName, new BasicDBObject("$exists", true));
         DBObject config = configCollection.findOne(query);
         Object value = config.get(configurationKey);
--- a/common/core/src/test/java/com/redhat/thermostat/common/dao/HeapDAOTest.java	Mon Jun 18 12:48:34 2012 -0400
+++ b/common/core/src/test/java/com/redhat/thermostat/common/dao/HeapDAOTest.java	Mon Jun 18 20:15:58 2012 +0200
@@ -1,3 +1,39 @@
+/*
+ * 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.common.dao;
 
 import static org.junit.Assert.assertEquals;
--- a/common/core/src/test/java/com/redhat/thermostat/common/model/HeapInfoTest.java	Mon Jun 18 12:48:34 2012 -0400
+++ b/common/core/src/test/java/com/redhat/thermostat/common/model/HeapInfoTest.java	Mon Jun 18 20:15:58 2012 +0200
@@ -1,3 +1,39 @@
+/*
+ * 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.common.model;
 
 import static org.junit.Assert.*;