Mercurial > hg > thermostat-ng > agent
changeset 2701:23ccc7c79110
Remove more unused code
review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-June/023842.html
reviewed-by: jerboaa
author | Mario Torre <neugens.limasoftware@gmail.com> |
---|---|
date | Fri, 23 Jun 2017 12:13:02 +0200 |
parents | 4d45a6637faa |
children | 459d991a6ade |
files | plugins/jvm-overview/agent/src/main/java/com/redhat/thermostat/jvm/overview/agent/model/VmLatestPojoListGetter.java plugins/jvm-overview/agent/src/main/java/com/redhat/thermostat/jvm/overview/agent/model/VmTimeIntervalPojoListGetter.java storage/core/pom.xml storage/core/src/main/java/com/redhat/thermostat/storage/core/Categories.java storage/core/src/main/java/com/redhat/thermostat/storage/core/Category.java storage/core/src/main/java/com/redhat/thermostat/storage/core/CategoryAdapter.java storage/core/src/main/java/com/redhat/thermostat/storage/core/HostBoundaryPojoGetter.java storage/core/src/main/java/com/redhat/thermostat/storage/core/HostLatestPojoListGetter.java storage/core/src/main/java/com/redhat/thermostat/storage/core/HostTimeIntervalPojoListGetter.java storage/core/src/main/java/com/redhat/thermostat/storage/core/auth/CategoryRegistration.java storage/core/src/main/java/com/redhat/thermostat/storage/core/auth/StatementDescriptorRegistration.java storage/core/src/main/java/com/redhat/thermostat/storage/internal/AdaptedCategory.java storage/core/src/test/java/com/redhat/thermostat/storage/core/CategoryAdapterTest.java storage/core/src/test/java/com/redhat/thermostat/storage/core/CategoryTest.java |
diffstat | 14 files changed, 0 insertions(+), 1343 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/jvm-overview/agent/src/main/java/com/redhat/thermostat/jvm/overview/agent/model/VmLatestPojoListGetter.java Wed Jun 21 06:33:05 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -/* - * Copyright 2012-2017 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.jvm.overview.agent.model; - -import java.util.List; -import java.util.logging.Logger; - -import com.redhat.thermostat.common.utils.LoggingUtils; -import com.redhat.thermostat.storage.core.AgentId; -import com.redhat.thermostat.storage.core.Category; -import com.redhat.thermostat.storage.core.Key; -import com.redhat.thermostat.storage.model.TimeStampedPojo; - -/** - * Get a {@link List} of {@link TimeStampedPojo}s newer than a given time stamp. - * - * @see VmTimeIntervalPojoListGetter - */ -public class VmLatestPojoListGetter<T extends TimeStampedPojo> { - - public static final String VM_LATEST_QUERY_FORMAT = "QUERY %s WHERE '" - + Key.AGENT_ID.getName() + "' = ?s AND '" - + Key.VM_ID.getName() + "' = ?s AND '" - + Key.TIMESTAMP.getName() + "' > ?l SORT '" - + Key.TIMESTAMP.getName() + "' DSC"; - private static final Logger logger = LoggingUtils.getLogger(VmLatestPojoListGetter.class); - - private final Category<T> cat; - private final String queryLatest; - - public VmLatestPojoListGetter(Category<T> cat) { - this.cat = cat; - this.queryLatest = String.format(VM_LATEST_QUERY_FORMAT, cat.getName()); - } - - /** - * @deprecated use {@link #getLatest(AgentId, VmId, long)} - */ - @Deprecated - public List<T> getLatest(VmRef vmRef, long since) { - return getLatest(new AgentId(vmRef.getHostRef().getAgentId()), new VmId(vmRef.getVmId()), since); - } - - public List<T> getLatest(final AgentId agentId, final VmId vmId, final long since) { - return null; - } - - // package private for tests - String getQueryLatestDesc() { - return queryLatest; - } - - public Logger getLogger() { - return logger; - } - -} -
--- a/plugins/jvm-overview/agent/src/main/java/com/redhat/thermostat/jvm/overview/agent/model/VmTimeIntervalPojoListGetter.java Wed Jun 21 06:33:05 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,97 +0,0 @@ -/* - * Copyright 2012-2017 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.jvm.overview.agent.model; - -import java.util.List; -import java.util.logging.Logger; - -import com.redhat.thermostat.common.utils.LoggingUtils; -import com.redhat.thermostat.storage.core.AgentId; -import com.redhat.thermostat.storage.core.Category; -import com.redhat.thermostat.storage.core.Key; -import com.redhat.thermostat.storage.model.TimeStampedPojo; - -/** - * Get a {@link List} of {@link TimeStampedPojo}s in a given time interval - * range. - * - * @see VmLatestPojoListGetter - */ -public class VmTimeIntervalPojoListGetter<T extends TimeStampedPojo> { - - // The query for VmTimeIntervalPojoListGetter should query for since <= timestamp < to - // in order not to miss data for multiple consecutive queries of the form [a, b), [b, c), ... - // If the query were since < timestamp < to then queries of (a, b), (b, c), ... would - // result in missed data at the endpoints (b, ...) - public static final String VM_INTERVAL_QUERY_FORMAT = "QUERY %s WHERE '" - + Key.AGENT_ID.getName() + "' = ?s AND '" - + Key.VM_ID.getName() + "' = ?s AND '" - + Key.TIMESTAMP.getName() + "' >= ?l AND '" - + Key.TIMESTAMP.getName() + "' < ?l SORT '" - + Key.TIMESTAMP.getName() + "' DSC"; - - private static final Logger logger = LoggingUtils.getLogger(VmTimeIntervalPojoListGetter.class); - - private final Category<T> cat; - private final String query; - - public VmTimeIntervalPojoListGetter(Category<T> cat) { - this.cat = cat; - this.query = String.format(VM_INTERVAL_QUERY_FORMAT, cat.getName()); - } - - /** - * @deprecated use {@link #getLatest(AgentId, VmId, long, long)} - */ - @Deprecated - public List<T> getLatest(final VmRef vmRef, final long since, final long to) { - return getLatest(new AgentId(vmRef.getHostRef().getAgentId()), new VmId(vmRef.getVmId()), since, to); - } - - public List<T> getLatest(final AgentId agentId, final VmId vmId, final long since, final long to) { - return null; - } - - // package private for tests - String getQueryLatestDesc() { - return query; - } - - protected Logger getLogger() { - return logger; - } -}
--- a/storage/core/pom.xml Wed Jun 21 06:33:05 2017 -0400 +++ b/storage/core/pom.xml Fri Jun 23 12:13:02 2017 +0200 @@ -64,14 +64,9 @@ <Bundle-Activator>com.redhat.thermostat.storage.internal.Activator</Bundle-Activator> <Export-Package> com.redhat.thermostat.storage.core, - com.redhat.thermostat.storage.core.experimental, - com.redhat.thermostat.storage.core.experimental.statement, - com.redhat.thermostat.storage.core.auth, com.redhat.thermostat.storage.config, com.redhat.thermostat.storage.model, com.redhat.thermostat.storage.dao, - com.redhat.thermostat.storage.query, - com.redhat.thermostat.storage.monitor, </Export-Package> <!-- TODO: For the thread tab (i.e. thread plug-in) the web server bundle requires model classes provided by said bundle. Since
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/core/Categories.java Wed Jun 21 06:33:05 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * Copyright 2012-2017 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.storage.core; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class Categories { - - private static final Map<String, Category<?>> namesToCategories = new HashMap<>(); - - public static synchronized boolean contains(String name) { - return namesToCategories.containsKey(name); - } - - public static synchronized void add(Category<?> category) { - if (namesToCategories.containsKey(category.getName())) { - throw new IllegalArgumentException("category already registered"); - } - namesToCategories.put(category.getName(), category); - } - - public static synchronized void remove(Category<?> category) { - namesToCategories.remove(category.getName()); - } - - public static synchronized Category<?> getByName(String categoryName) { - return namesToCategories.get(categoryName); - } - - public static synchronized List<Category<?>> getAllCategories() { - return Collections.unmodifiableList(new ArrayList<Category<?>>(namesToCategories.values())); - } - -} -
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/core/Category.java Wed Jun 21 06:33:05 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,257 +0,0 @@ -/* - * Copyright 2012-2017 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.storage.core; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import com.redhat.thermostat.storage.model.Pojo; - -/** - * A description for data persisted in storage. It describes how model objects - * are going to be categorized in persistent storage. - * - * @param <T> - * The model class used for data mapped to this category. - */ -public class Category<T extends Pojo> { - - /* - * The name of the category. This is an de-facto immutable field set only by - * the constructor via setName(). An exception to this rule is - * AdaptedCategory and JSON serialization. - * - * This field gets serialized via JSON. - */ - protected String name; - /* - * A de-facto unmodifiable map of key-name => key pairs. A key-name may - * represent a property in storage. Set via the constructor. Exceptions are - * AdaptedCategory and JSON serialization. - * - * This key map gets serialized via JSON. - */ - protected Map<String, Key<?>> keys; - - /* - * A de-facto unmodifiable list of keys to be indexed. All of these keys - * should be indexed by the storage (so sorting by this should be possible). - * Set via the constructor. Exceptions are AdaptedCategory and JSON - * serialization. - * - * This list gets serialized via JSON. - */ - protected List<Key<?>> indexedKeys; - - /* - * A de-facto immutable field, set via setDataClass() called by the - * constructor. If null dataClassName must be set. This is to make Category - * JSON serializable. - * - * This field does not get serialized. Instead it's name gets serialized. - */ - private transient Class<T> dataClass; - /* - * A de-facto immutable field, set via setDataClass() called by the - * constructor. Essentially a buddy-field to dataClass. - * - * This field gets serialized via JSON. - */ - protected String dataClassName; - - /* No-arg Constructor. - * - * Used for serialization and - implicitly - by AdaptedCategory - */ - protected Category() { - // empty - } - - /** - * Creates a new Category instance with the specified name. - * - * @param name - * the name of the category - * @param dataClass - * the Class object representing the data - * @param keys - * an array of Key object which represent the data for this category - * - * @throws IllegalArgumentException - * if a Category is created with a name that has been used - * before - */ - public Category(String name, Class<T> dataClass, Key<?>... keys) { - this(name, dataClass, Arrays.asList(keys), Collections.<Key<?>>emptyList()); - } - - /** - * Creates a new Category instance with the specified name. - * - * @param name - * the name of the category - * @param dataClass - * the Class object representing the data - * @param indexedKeys - * the keys that will be used for sorting and should be indexed - * (or otherwise optimized) by the storage - * @param keys - * an array of Key object which represent the data for this category - * - * @throws IllegalArgumentException - * if a Category is created with a name that has been used - * before - */ - public Category(String name, Class<T> dataClass, List<Key<?>> keys, List<Key<?>> indexedKeys) { - Map<String, Key<?>> keysMap = new HashMap<String, Key<?>>(); - for (Key<?> key : keys) { - keysMap.put(key.getName(), key); - } - this.keys = Collections.unmodifiableMap(keysMap); - this.indexedKeys = Collections.unmodifiableList(indexedKeys); - setName(name); - setDataClass(dataClass); - } - - /** - * - * @return The category name which uniquely identifies this category. - */ - public String getName() { - return name; - } - - private void setName(String name) { - if (Categories.contains(name)) { - throw new IllegalStateException("category " + name + " already created!"); - } - - this.name = name; - - if (name != null) { - Categories.add(this); - } - } - - private void setDataClass(Class<T> dataClass) { - this.dataClass = dataClass; - if (dataClass != null) { - dataClassName = dataClass.getName(); - } - } - - public Class<T> getDataClass() { - if (dataClass == null && dataClassName != null) { - initializeDataClassFromName(); - } - return dataClass; - } - - @SuppressWarnings("unchecked") - private void initializeDataClassFromName() { - try { - dataClass = (Class<T>) Class.forName(dataClassName); - } catch (ClassNotFoundException e) { - throw new StorageException(e); - } - } - - /** - * - * @return A collection of {@link Key}s for this category or an empty - * collection if no keys. - */ - public synchronized Collection<Key<?>> getKeys() { - if (keys == null) { - return Collections.emptySet(); - } - return keys.values(); - } - - /** - * - * @param name - * The name of the key to retrieve. - * @return The key with the specified name or {@code null} if there was no - * such key. - */ - public Key<?> getKey(String name) { - if (keys == null) { - return null; - } - return keys.get(name); - } - - public List<Key<?>> getIndexedKeys() { - return indexedKeys; - } - - @Override - public String toString() { - return getName() + "|" + getDataClass().getName() + "|" + keys; - } - - @Override - public int hashCode() { - /* - * The assumption is that name, keys and dataClass are immutable once - * created. This occurs either via JSON deserialization, the only public - * constructor or AdaptedCategory. - */ - - // ignore indexed keys intentionally - return Objects.hash(name, keys, getDataClass()); - } - - @Override - public boolean equals(Object o) { - if (! (o instanceof Category)) { - return false; - } - Category<?> other = (Category<?>) o; - // ignore indexed keys intentionally - return Objects.equals(name, other.name) && - Objects.equals(keys, other.keys) && - Objects.equals(getDataClass(), other.getDataClass()); - } -} -
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/core/CategoryAdapter.java Wed Jun 21 06:33:05 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/* - * Copyright 2012-2017 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.storage.core; - -import java.util.Objects; - -import com.redhat.thermostat.storage.internal.AdaptedCategory; -import com.redhat.thermostat.storage.model.Pojo; - -/** - * - * Adapts a given category to an aggregate equivalent. - * - * @param <T> The source data type. - * @param <S> The target data type after adaptation. - */ -public final class CategoryAdapter<T extends Pojo, S extends Pojo> { - - private final Category<T> sourceCategory; - - /** - * Constructor. - * - * @param sourceCategory - * A known source category. - * @throws NullPointerException - * if sourceCategory was null. - * @throws IllegalArgumentException - * if sourceCategory is not known. - */ - public CategoryAdapter(Category<T> sourceCategory) { - Objects.requireNonNull(sourceCategory); - if (!Categories.contains(sourceCategory.getName())) { - throw new IllegalStateException("Only registered categories can be adapted!"); - } - this.sourceCategory = sourceCategory; - } - - public Category<S> getAdapted(Class<S> targetType) { - AdaptedCategory<S, T> adapted = new AdaptedCategory<>(sourceCategory, targetType); - return adapted; - } -} -
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/core/HostBoundaryPojoGetter.java Wed Jun 21 06:33:05 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -/* - * Copyright 2012-2017 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.storage.core; - -import java.util.logging.Logger; - -import com.redhat.thermostat.common.utils.LoggingUtils; -import com.redhat.thermostat.storage.model.TimeStampedPojo; - -public class HostBoundaryPojoGetter<T extends TimeStampedPojo> { - - // QUERY %s WHERE 'agentId' = ?s AND \ - // SORT 'timeStamp' DSC \ - // LIMIT 1 - public static final String DESC_NEWEST_HOST_STAT = "QUERY %s " + - "WHERE '" + Key.AGENT_ID.getName() + "' = ?s " + - "SORT '" + Key.TIMESTAMP.getName() + "' DSC " + - "LIMIT 1"; - - // QUERY %s WHERE 'agentId' = ?s AND \ - // SORT 'timeStamp' ASC \ - // LIMIT 1 - public static final String DESC_OLDEST_HOST_STAT = "QUERY %s " + - "WHERE '" + Key.AGENT_ID.getName() + "' = ?s " + - "SORT '" + Key.TIMESTAMP.getName() + "' ASC " + - "LIMIT 1"; - - private static final Logger logger = LoggingUtils.getLogger(HostBoundaryPojoGetter.class); - - private final Category<T> cat; - private final String queryNewest; - private final String queryOldest; - - public HostBoundaryPojoGetter(Category<T> cat) { - this.cat = cat; - this.queryNewest = String.format(DESC_NEWEST_HOST_STAT, cat.getName()); - this.queryOldest = String.format(DESC_OLDEST_HOST_STAT, cat.getName()); - } - - /** - * @deprecated use {@link #getNewestStat(AgentId)} - */ - @Deprecated - public T getNewestStat(HostRef ref) { - return runAgentIdQuery(ref.getAgentId(), queryNewest); - } - - public T getNewestStat(AgentId agentId) { - return runAgentIdQuery(agentId.get(), queryNewest); - } - - /** - * @deprecated use {@link #getOldestStat(AgentId)} - */ - @Deprecated - public T getOldestStat(HostRef ref) { - return runAgentIdQuery(ref.getAgentId(), queryOldest); - } - - public T getOldestStat(AgentId agentId) { - return runAgentIdQuery(agentId.get(), queryOldest); - } - - private T runAgentIdQuery(final String agentId, final String descriptor) { - return null; - } - - //Package private for testing - String getNewestQueryDesc() { - return queryNewest; - } - - String getOldestQueryDesc() { - return queryOldest; - } - - protected Logger getLogger() { - return logger; - } -}
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/core/HostLatestPojoListGetter.java Wed Jun 21 06:33:05 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/* - * Copyright 2012-2017 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.storage.core; - -import java.util.List; -import java.util.logging.Logger; - -import com.redhat.thermostat.common.utils.LoggingUtils; -import com.redhat.thermostat.storage.model.TimeStampedPojo; - -/** - * @see HostTimeIntervalPojoListGetter - */ -public class HostLatestPojoListGetter<T extends TimeStampedPojo> { - - public static final String HOST_LATEST_QUERY_FORMAT = "QUERY %s WHERE '" - + Key.AGENT_ID.getName() + "' = ?s AND '" - + Key.TIMESTAMP.getName() + "' > ?l SORT '" - + Key.TIMESTAMP.getName() + "' DSC"; - - private static final Logger logger = LoggingUtils.getLogger(HostLatestPojoListGetter.class); - - private final Category<T> cat; - private final String queryLatest; - - public HostLatestPojoListGetter(Category<T> cat) { - this.cat = cat; - this.queryLatest = String.format(HOST_LATEST_QUERY_FORMAT, cat.getName()); - } - - /** - * @deprecated use {@link #getLatest(AgentId, long)} - */ - @Deprecated - public List<T> getLatest(final HostRef hostRef, final long since) { - return getLatest(new AgentId(hostRef.getAgentId()), since); - } - - public List<T> getLatest(final AgentId agentId, final long since) { - return null; - } - - // package private for testing - String getQueryLatestDesc() { - return queryLatest; - } - - protected Logger getLogger() { - return logger; - } -} -
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/core/HostTimeIntervalPojoListGetter.java Wed Jun 21 06:33:05 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/* - * Copyright 2012-2017 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.storage.core; - -import java.util.List; -import java.util.logging.Logger; - -import com.redhat.thermostat.common.utils.LoggingUtils; -import com.redhat.thermostat.storage.model.TimeStampedPojo; - -/** - * @see HostLatestPojoListGetter - */ -public class HostTimeIntervalPojoListGetter<T extends TimeStampedPojo> { - - public static final String HOST_INTERVAL_QUERY_FORMAT = "QUERY %s WHERE '" - + Key.AGENT_ID.getName() + "' = ?s AND '" - + Key.TIMESTAMP.getName() + "' >= ?l AND '" - + Key.TIMESTAMP.getName() + "' < ?l SORT '" - + Key.TIMESTAMP.getName() + "' DSC"; - - private static final Logger logger = LoggingUtils.getLogger(HostTimeIntervalPojoListGetter.class); - - private final Category<T> cat; - private final String query; - - public HostTimeIntervalPojoListGetter(Category<T> cat) { - this.cat = cat; - this.query = String.format(HOST_INTERVAL_QUERY_FORMAT, cat.getName()); - } - - /** - * @deprecated use {@link #getLatest(AgentId, long, long)} - */ - @Deprecated - public List<T> getLatest(final HostRef hostRef, final long since, final long to) { - return getLatest(new AgentId(hostRef.getAgentId()), since, to); - } - - public List<T> getLatest(final AgentId agentId, final long since, final long to) { - return null; - } - - // package private for testing - String getQueryLatestDesc() { - return query; - } - - protected Logger getLogger() { - return logger; - } -} -
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/core/auth/CategoryRegistration.java Wed Jun 21 06:33:05 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * Copyright 2012-2017 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.storage.core.auth; - -import java.util.ServiceLoader; -import java.util.Set; - -import com.redhat.thermostat.storage.core.Category; - -/** - * {@link ServiceLoader} interface used for registering - * trusted {@link Category}s. The web storage endpoint - * uses implementations of this interface in order to collect - * the set of all trusted categories. - * - */ -public interface CategoryRegistration { - - /** - * - * @return The set of category names to register. - */ - Set<String> getCategoryNames(); -} -
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/core/auth/StatementDescriptorRegistration.java Wed Jun 21 06:33:05 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * Copyright 2012-2017 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.storage.core.auth; - -import java.util.ServiceLoader; -import java.util.Set; - - -/** - * {@link ServiceLoader} interface used for registering - * trusted statement descriptors. The web storage endpoint - * uses implementations of this interface in order to collect - * the set of all trusted statement descriptors. - * - */ -public interface StatementDescriptorRegistration { - - /** - * - * @return A set of string descriptors which should get - * added to the trusted registry. The returned set - * must not contain <code>null</code>. - */ - Set<String> getStatementDescriptors(); - -} -
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/internal/AdaptedCategory.java Wed Jun 21 06:33:05 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * Copyright 2012-2017 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.storage.internal; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import com.redhat.thermostat.storage.core.Category; -import com.redhat.thermostat.storage.core.Key; -import com.redhat.thermostat.storage.model.AggregateResult; -import com.redhat.thermostat.storage.model.Pojo; - -/** - * An adapted category. This facilitates aggregate queries for which the data - * class type changes. - * - * @param <T> The type to adapt a category to. - * @param <S> The source type to adapt things from. - */ -public final class AdaptedCategory<T extends Pojo, S extends Pojo> extends Category<T> { - - /** - * Constructor used by CategoryAdapter which has just - * performed a registration check. That means only categories - * constructed via public Category constructors can get adapted. - * - */ - public AdaptedCategory(Category<S> category, Class<T> dataClass) { - this.name = category.getName(); - Map<String, Key<?>> mappedKeys = new HashMap<>(); - for (Key<?> key: category.getKeys()) { - mappedKeys.put(key.getName(), key); - } - this.keys = Collections.unmodifiableMap(mappedKeys); - if (!AggregateResult.class.isAssignableFrom(dataClass)) { - String msg = "Can only adapt to aggregate results!"; - throw new IllegalArgumentException(msg); - } - this.indexedKeys = Collections.unmodifiableList(category.getIndexedKeys()); - this.dataClassName = dataClass.getName(); - } - -} -
--- a/storage/core/src/test/java/com/redhat/thermostat/storage/core/CategoryAdapterTest.java Wed Jun 21 06:33:05 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * Copyright 2012-2017 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.storage.core; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import org.junit.Test; - -public class CategoryAdapterTest { - - @Test - public void canCreateAdapterFromNull() { - try { - new CategoryAdapter<>(null); - } catch (NullPointerException e) { - // pass - } - } - - @Test - public void cannotAdaptUnknown() { - Category<?> unknown = mock(Category.class); - when(unknown.getName()).thenReturn("foo"); - try { - new CategoryAdapter<>(unknown); - } catch (IllegalStateException e) { - // pass - } - } -} -
--- a/storage/core/src/test/java/com/redhat/thermostat/storage/core/CategoryTest.java Wed Jun 21 06:33:05 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,189 +0,0 @@ -/* - * Copyright 2012-2017 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.storage.core; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.lang.reflect.Field; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -import org.junit.Test; - -import com.redhat.thermostat.storage.model.Pojo; - -public class CategoryTest { - - private static class TestObj implements Pojo { - // Dummy class for testing. - } - - @Test - public void testGetKey() { - Key<String> key1 = new Key<String>("key1"); - Category<TestObj> category = new Category<>("testGetKey", TestObj.class, key1); - assertEquals(key1, category.getKey("key1")); - } - - @Test - public void testGetNonExistingKey() { - Key<String> key1 = new Key<String>("key1"); - Category<TestObj> category = new Category<>("testGetNonExistingKey", TestObj.class, key1); - assertNull(category.getKey("key2")); - } - - @Test - public void testGetKeys() { - Key<String> key1 = new Key<String>("key1"); - Key<String> key2 = new Key<String>("key2"); - Key<String> key3 = new Key<String>("key3"); - Key<String> key4 = new Key<String>("key4"); - Category<TestObj> category = new Category<>("testGetKeys", TestObj.class, key1, key2, key3, key4); - assertEquals(4, category.getKeys().size()); - assertTrue(category.getKeys().contains(key1)); - assertTrue(category.getKeys().contains(key2)); - assertTrue(category.getKeys().contains(key3)); - assertTrue(category.getKeys().contains(key4)); - } - - @Test(expected=UnsupportedOperationException.class) - public void verifyThatKeysAreUnmodifiable() { - Key<String> key1 = new Key<String>("key1"); - Key<String> key2 = new Key<String>("key2"); - Key<String> key3 = new Key<String>("key3"); - Category<TestObj> category = new Category<>("verifyThatKeysAreUnmodifiable", TestObj.class, key1, key2, key3); - - Collection<Key<?>> keys = category.getKeys(); - - keys.remove(key1); - } - - @Test - public void testEquals() { - Key<String> key1 = new Key<String>("key1"); - Key<String> key2 = new Key<String>("key2"); - Key<String> key3 = new Key<String>("key3"); - Category<TestObj> category = new Category<>("testEquals", TestObj.class, key1, key2, key3); - assertTrue(category.equals(category)); - Key<String> key4 = new Key<String>("key4"); - Category<TestObj> otherCategory = new Category<>("testEquals2", TestObj.class, key1, key2, key4); - assertFalse(category.equals(otherCategory)); - } - - @Test - public void testHashCode() { - Key<String> key1 = new Key<String>("key1"); - Category<TestObj> category = new Category<>("testHashCode", TestObj.class, key1); - Map<String, Key<?>> keys = new HashMap<>(); - keys.put(key1.getName(), key1); - int expectedHash = Objects.hash("testHashCode", keys, TestObj.class); - assertEquals(expectedHash, category.hashCode()); - } - - /** - * If a Category instance gets serialized we only set the dataClassName. - * However, getting the dataClass from the name must still work. - */ - @Test - public void testGetDataClassByName() { - Category<TestObj> category = new Category<>("testGetDataClassByName", null); - // set dataClassName via reflection - try { - Field dataClassName = Category.class.getDeclaredField("dataClassName"); - dataClassName.setAccessible(true); - dataClassName.set(category, TestObj.class.getName()); - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - // now we should be able to get the dataclass itself - Class<TestObj> dataClass = category.getDataClass(); - assertNotNull(dataClass); - assertEquals(TestObj.class, dataClass); - } - - @Test - public void testHashCodeWithDataClassNotSet() { - Category<TestObj> category = new Category<>("testHashCodeWithDataClassNotSet", null); - // set dataClassName via reflection - try { - Field dataClassName = Category.class.getDeclaredField("dataClassName"); - dataClassName.setAccessible(true); - dataClassName.set(category, TestObj.class.getName()); - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - // hash code must not change if dataclass gets set internally - int firstHashCode = category.hashCode(); - Class<TestObj> dataClass = category.getDataClass(); - // hashCode should have initialized dataClass - assertNotNull(dataClass); - assertEquals(TestObj.class, dataClass); - assertEquals(firstHashCode, category.hashCode()); - } - - @Test - public void getKeysNull() { - Category<TestObj> cat = new Category<>(); - // this must not throw NPE - Collection<Key<?>> keys = cat.getKeys(); - assertTrue(keys.isEmpty()); - try { - keys.add(new Key<>()); - fail("empty keys must be immutable"); - } catch (UnsupportedOperationException e) { - // pass - } - } - - @Test - public void getKeyByNameNull() { - Category<TestObj> cat = new Category<>(); - // This must not throw a NPE - Key<?> key = cat.getKey("foo-key-not-there"); - assertNull(key); - } -} -