# HG changeset patch # User Simon Tooke # Date 1508354119 14400 # Node ID 4f12f8ffdc9bdf79e15444dfc4a6e264db9cb17f # Parent 9e3d6eedbbee1018d203e167adbbdc0db6694a0b Resurrect Jvm ClassStat plugin This patch brings back the agent side of the Vm Classtat plugin. Reviewed-by: neugens Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-October/025330.html diff -r 9e3d6eedbbee -r 4f12f8ffdc9b distribution/assembly/plugin-assembly.xml --- a/distribution/assembly/plugin-assembly.xml Tue Oct 10 12:29:18 2017 -0400 +++ b/distribution/assembly/plugin-assembly.xml Wed Oct 18 15:15:19 2017 -0400 @@ -62,10 +62,10 @@ com.redhat.thermostat.agent:thermostat-killvm-distribution com.redhat.thermostat.agent:thermostat-vm-compiler-distribution com.redhat.thermostat.agent:thermostat-jcmd-stats-collector-distribution - + com.redhat.thermostat.agent:thermostat-vm-classstat-distribution + com.redhat.thermostat.agent:thermostat-vm-cpu-distribution + - - com.redhat.thermostat.agent:thermostat-vm-cpu-distribution diff -r 9e3d6eedbbee -r 4f12f8ffdc9b distribution/pom.xml --- a/distribution/pom.xml Tue Oct 10 12:29:18 2017 -0400 +++ b/distribution/pom.xml Wed Oct 18 15:15:19 2017 -0400 @@ -557,12 +557,12 @@ - - - - - - + + com.redhat.thermostat.agent + thermostat-vm-classstat-distribution + ${project.version} + zip + com.redhat.thermostat.agent thermostat-vm-compiler-distribution diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/pom.xml --- a/plugins/pom.xml Tue Oct 10 12:29:18 2017 -0400 +++ b/plugins/pom.xml Wed Oct 18 15:15:19 2017 -0400 @@ -57,16 +57,18 @@ host-cpu host-memory host-network + commands + jcmd-stats-collector jvm-overview + vm-classstat vm-gc vm-io vm-memory - commands vm-byteman vm-compiler - jcmd-stats-collector vm-cpu + diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/pom.xml --- a/plugins/vm-classstat/agent/pom.xml Tue Oct 10 12:29:18 2017 -0400 +++ b/plugins/vm-classstat/agent/pom.xml Wed Oct 18 15:15:19 2017 -0400 @@ -56,8 +56,9 @@ Red Hat, Inc. com.redhat.thermostat.vm.classstat.agent - com.redhat.thermostat.vm.classstat.agent.internal.Activator - + + com.redhat.thermostat.vm.classstat.model + com.redhat.thermostat.vm.classstat.agent.internal @@ -66,8 +67,21 @@ + + org.apache.felix + maven-scr-plugin + + + generate-scr-scrdescriptor + + scr + + + + + junit @@ -96,11 +110,6 @@ com.redhat.thermostat.agent - thermostat-vm-classstat-common - ${project.version} - - - com.redhat.thermostat.agent thermostat-agent-core ${project.version} @@ -115,5 +124,20 @@ ${project.version} test + + com.google.code.gson + gson + ${gson.version} + + + com.redhat.thermostat.agent + thermostat-common-plugin + ${project.version} + + + com.redhat.thermostat.agent + thermostat-jvm-overview-agent + ${project.version} + diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/Activator.java --- a/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/Activator.java Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +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 - * . - * - * 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.classstat.agent.internal; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -import com.redhat.thermostat.agent.VmStatusListenerRegistrar; -import com.redhat.thermostat.backend.Backend; -import com.redhat.thermostat.backend.BackendService; -import com.redhat.thermostat.common.MultipleServiceTracker; -import com.redhat.thermostat.common.MultipleServiceTracker.Action; -import com.redhat.thermostat.common.MultipleServiceTracker.DependencyProvider; -import com.redhat.thermostat.common.Version; -import com.redhat.thermostat.storage.core.WriterID; -import com.redhat.thermostat.vm.classstat.common.VmClassStatDAO; - -public class Activator implements BundleActivator { - - private MultipleServiceTracker tracker; - private VmClassStatBackend backend; - private ServiceRegistration reg; - - @Override - public void start(final BundleContext context) throws Exception { - - final VmStatusListenerRegistrar registrar = new VmStatusListenerRegistrar(context); - - Class[] deps = new Class[] { - BackendService.class, - VmClassStatDAO.class, - WriterID.class, // vm class stat backend uses it - }; - tracker = new MultipleServiceTracker(context, deps, new Action() { - - @Override - public void dependenciesAvailable(DependencyProvider services) { - VmClassStatDAO vmClassStatDao = services.get(VmClassStatDAO.class); - Version version = new Version(context.getBundle()); - WriterID id = services.get(WriterID.class); - backend = new VmClassStatBackend(vmClassStatDao, version, registrar, id); - reg = context.registerService(Backend.class, backend, null); - } - - @Override - public void dependenciesUnavailable() { - if (backend.isActive()) { - backend.deactivate(); - } - reg.unregister(); - } - }); - tracker.open(); - } - - @Override - public void stop(BundleContext context) throws Exception { - tracker.close(); - } - - /* - * For testing purposes only. - */ - VmClassStatBackend getBackend() { - return backend; - } -} - diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatBackend.java --- a/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatBackend.java Tue Oct 10 12:29:18 2017 -0400 +++ b/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatBackend.java Wed Oct 18 15:15:19 2017 -0400 @@ -36,28 +36,76 @@ package com.redhat.thermostat.vm.classstat.agent.internal; -import com.redhat.thermostat.agent.VmStatusListenerRegistrar; -import com.redhat.thermostat.backend.VmListenerBackend; -import com.redhat.thermostat.backend.VmUpdateListener; +import com.redhat.thermostat.backend.Backend; import com.redhat.thermostat.common.Version; +import com.redhat.thermostat.jvm.overview.agent.VmListenerBackend; +import com.redhat.thermostat.jvm.overview.agent.VmStatusListenerRegistrar; +import com.redhat.thermostat.jvm.overview.agent.VmUpdateListener; import com.redhat.thermostat.storage.core.WriterID; -import com.redhat.thermostat.vm.classstat.common.VmClassStatDAO; +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.BundleContext; +@Component +@Service(value = Backend.class) public class VmClassStatBackend extends VmListenerBackend { - private final VmClassStatDAO vmClassStats; + private final ListenerCreator listenerCreator; + + @Reference + private VmClassStatDAO vmClassStatDao; - public VmClassStatBackend(VmClassStatDAO vmClassStatDAO, Version version, - VmStatusListenerRegistrar registrar, WriterID writerId) { + @Reference + private WriterID writerID; + + public VmClassStatBackend() { + this(new ListenerCreator()); + } + + VmClassStatBackend(ListenerCreator lc) { super("VM Classes Backend", "Gathers class loading statistics about a JVM", - "Red Hat, Inc.", version.getVersionNumber(), true, registrar, writerId); - this.vmClassStats = vmClassStatDAO; + "Red Hat, Inc.",true); + this.listenerCreator = lc; + + } + + @Activate + public void componentActivated(BundleContext ctx) { + VmStatusListenerRegistrar registrar = new VmStatusListenerRegistrar(ctx); + Version version = new Version(ctx.getBundle()); + initialize(writerID, registrar, version.getVersionNumber()); + } + + @Deactivate + protected void componentDeactivated() { + if (isActive()) { + deactivate(); + } } @Override - protected VmUpdateListener createVmListener(String writerId, String vmId, int pid) { - return new VmClassStatVmListener(writerId, vmClassStats, vmId); + protected VmUpdateListener createVmListener(String writerId, String jvmId, int pid) { + return listenerCreator.create(writerId, vmClassStatDao, jvmId); + } + + // DS bind method + protected void bindVmClassStatDao(VmClassStatDAO dao) { + this.vmClassStatDao = dao; + } + + // DS bind method + protected void bindWriterId(WriterID id) { + this.writerID = id; + } + + static class ListenerCreator { + protected VmUpdateListener create(String writerId, VmClassStatDAO dao, String jvmId) { + return new VmClassStatVmListener(writerId, dao, jvmId); + } } } diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatDAO.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatDAO.java Wed Oct 18 15:15:19 2017 -0400 @@ -0,0 +1,46 @@ +/* + * 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 + * . + * + * 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.classstat.agent.internal; + +import com.redhat.thermostat.annotations.Service; +import com.redhat.thermostat.vm.classstat.model.VmClassStat; + +@Service +public interface VmClassStatDAO { + void put(VmClassStat stat); +} + diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatDAOImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatDAOImpl.java Wed Oct 18 15:15:19 2017 -0400 @@ -0,0 +1,162 @@ +/* + * 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 + * . + * + * 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.classstat.agent.internal; + +import java.io.IOException; +import java.net.URI; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import com.redhat.thermostat.agent.http.HttpRequestService; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugin.PluginConfiguration; +import com.redhat.thermostat.common.plugin.PluginDAOBase; +import com.redhat.thermostat.common.plugin.SystemID; +import com.redhat.thermostat.common.utils.LoggingUtils; +import com.redhat.thermostat.vm.classstat.model.VmClassStat; +import com.redhat.thermostat.vm.classstat.model.VmClassStatTypeAdapter; +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; + +@Component +@Service(value = VmClassStatDAO.class) +public class VmClassStatDAOImpl extends PluginDAOBase implements VmClassStatDAO { + + private static final Logger logger = LoggingUtils.getLogger(VmClassStatDAOImpl.class); + + private static final String PLUGIN_ID = "vm-classstat"; + + private final JsonHelper jsonHelper; + private final ConfigurationCreator configCreator; + private URI gatewayURL; + private PluginConfiguration config; + + @Reference + private ConfigurationInfoSource configurationInfoSource; + + @Reference + private HttpRequestService httpRequestService; + + @Reference + private SystemID systemID; + + public VmClassStatDAOImpl() { + this(new JsonHelper(new VmClassStatTypeAdapter()), new ConfigurationCreator()); + } + + VmClassStatDAOImpl(JsonHelper jsonHelper, ConfigurationCreator creator) { + this.jsonHelper = jsonHelper; + this.configCreator = creator; + } + + @Activate + public void activate() throws Exception { + config = configCreator.create(configurationInfoSource); + this.gatewayURL = config.getGatewayURL(); + } + + @Override + protected String toJsonString(VmClassStat obj) throws IOException { + return jsonHelper.toJson(Arrays.asList(obj)); + } + + @Override + protected HttpRequestService getHttpRequestService() { + return httpRequestService; + } + + @Override + protected PluginConfiguration getConfig() { + return config; + } + + @Override + protected URI getPostURI(URI basepath, VmClassStat obj) { + return basepath.resolve("systems/" + systemID.getSystemID() + "/jvms/" + obj.getJvmId()); + } + + @Override + protected Logger getLogger() { + return logger; + } + + public String getPluginId() { + return PLUGIN_ID; + } + + protected void bindSystemID(final SystemID id) { + this.systemID = id; + } + + protected void bindConfigurationInfoSource(ConfigurationInfoSource cfg) { + this.configurationInfoSource = cfg; + } + + protected void bindHttpRequestService(HttpRequestService httpRequestService) { + this.httpRequestService = httpRequestService; + } + + protected void unbindHttpRequestService(HttpRequestService httpRequestService) { + this.httpRequestService = null; + logger.log(Level.INFO, "Unbound HTTP service. Further attempts to store data will fail until bound again."); + } + + // For testing purposes + static class JsonHelper { + private final VmClassStatTypeAdapter typeAdapter; + + public JsonHelper(VmClassStatTypeAdapter typeAdapter) { + this.typeAdapter = typeAdapter; + } + + public String toJson(List info) throws IOException { + return typeAdapter.toJson(info); + } + } + + // For Testing purposes + static class ConfigurationCreator { + PluginConfiguration create(ConfigurationInfoSource source) { + return new PluginConfiguration(source, PLUGIN_ID); + } + } +} + diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatDataExtractor.java --- a/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatDataExtractor.java Tue Oct 10 12:29:18 2017 -0400 +++ b/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatDataExtractor.java Wed Oct 18 15:15:19 2017 -0400 @@ -36,8 +36,8 @@ package com.redhat.thermostat.vm.classstat.agent.internal; -import com.redhat.thermostat.backend.VmUpdate; -import com.redhat.thermostat.backend.VmUpdateException; +import com.redhat.thermostat.jvm.overview.agent.VmUpdate; +import com.redhat.thermostat.jvm.overview.agent.VmUpdateException; /** * A helper class to provide type-safe access to commonly used jvmstat monitors diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatVmListener.java --- a/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatVmListener.java Tue Oct 10 12:29:18 2017 -0400 +++ b/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatVmListener.java Wed Oct 18 15:15:19 2017 -0400 @@ -39,12 +39,11 @@ import java.util.logging.Level; import java.util.logging.Logger; -import com.redhat.thermostat.backend.VmUpdate; -import com.redhat.thermostat.backend.VmUpdateException; -import com.redhat.thermostat.backend.VmUpdateListener; import com.redhat.thermostat.common.utils.LoggingUtils; -import com.redhat.thermostat.vm.classstat.common.VmClassStatDAO; -import com.redhat.thermostat.vm.classstat.common.model.VmClassStat; +import com.redhat.thermostat.jvm.overview.agent.VmUpdate; +import com.redhat.thermostat.jvm.overview.agent.VmUpdateException; +import com.redhat.thermostat.jvm.overview.agent.VmUpdateListener; +import com.redhat.thermostat.vm.classstat.model.VmClassStat; class VmClassStatVmListener implements VmUpdateListener { @@ -78,7 +77,7 @@ unloadedClasses, unloadedBytes, classLoadTime); - dao.putVmClassStat(stat); + dao.put(stat); } catch (VmUpdateException e) { logger.log(Level.WARNING, "Error gathering class info for VM " + vmId, e); diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/model/VmClassStat.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/model/VmClassStat.java Wed Oct 18 15:15:19 2017 -0400 @@ -0,0 +1,142 @@ +/* + * 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 + * . + * + * 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.classstat.model; + +import com.redhat.thermostat.storage.core.Entity; +import com.redhat.thermostat.storage.model.BasePojo; +import com.redhat.thermostat.storage.model.TimeStampedPojo; + +@Entity +public class VmClassStat extends BasePojo implements TimeStampedPojo { + + // See the jdk sources for more information: + // - jdk/src/share/classes/sun/tools/jstat/resources/jstat_options + // - jdk/src/share/classes/sun/tools/jstat/resources/jstat_unsupported_options + + public static final int UNKNOWN = -1; + + private String jvmId; + private long timestamp; + private long loadedClasses; + private long loadedBytes; + private long unloadedClasses; + private long unloadedBytes; + private long classLoadTime; + + public VmClassStat() { + this(null, null, UNKNOWN, + UNKNOWN, UNKNOWN, + UNKNOWN, UNKNOWN, + UNKNOWN); + } + + public VmClassStat(String writerId, String jvmId, long timestamp, + long loadedClasses, long loadedBytes, + long unloadedClasses, long unloadedBytes, + long classLoadTime) { + super(writerId); + this.jvmId = jvmId; + this.timestamp = timestamp; + this.loadedClasses = loadedClasses; + this.loadedBytes = loadedBytes; + this.unloadedClasses = unloadedClasses; + this.unloadedBytes = unloadedBytes; + this.classLoadTime = classLoadTime; + } + + public String getJvmId() { + return jvmId; + } + + public void setJvmId(String jvmId) { + this.jvmId = jvmId; + } + + @Override + public long getTimeStamp() { + return timestamp; + } + + public void setTimeStamp(long timestamp) { + this.timestamp = timestamp; + } + + /** Number of classes loaded */ + public long getLoadedClasses() { + return loadedClasses; + } + + public void setLoadedClasses(long loadedClasses) { + this.loadedClasses = loadedClasses; + } + + /** Accumulated Size of classes loaded */ + public long getLoadedBytes() { + return loadedBytes; + } + + public void setLoadedBytes(long bytes) { + this.loadedBytes = bytes; + } + + /** Number of classes unloaded */ + public long getUnloadedClasses() { + return unloadedClasses; + } + + public void setUnloadedClasses(long classes) { + this.unloadedClasses = classes; + } + + /** Accumulated size of classes unloaded */ + public long getUnloadedBytes() { + return unloadedBytes; + } + + public void setUnloadedBytes(long bytes) { + this.unloadedBytes = bytes; + } + + /** Accumulated time for class loading. In seconds */ + public long getClassLoadTime() { + return classLoadTime; + } + + public void setClassLoadTime(long seconds) { + this.classLoadTime = seconds; + } +} diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/model/VmClassStatTypeAdapter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/model/VmClassStatTypeAdapter.java Wed Oct 18 15:15:19 2017 -0400 @@ -0,0 +1,101 @@ +/* + * 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 + * . + * + * 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.classstat.model; + +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +import com.google.gson.TypeAdapter; + +import java.io.IOException; +import java.util.List; + +public class VmClassStatTypeAdapter extends TypeAdapter> { + + private static final String TYPE_LONG = "$numberLong"; + private static final String JVM_ID = "jvmId"; + private static final String AGENT_ID = "agentId"; + private static final String LOADED_CLASSES = "loadedClasses"; + private static final String LOADED_BYTES = "loadedBytes"; + private static final String UNLOADED_CLASSES = "unloadedClasses"; + private static final String UNLOADED_BYTES = "unloadedBytes"; + private static final String CLASS_LOAD_TIME = "classLoadTime"; + private static final String TIMESTAMP = "timeStamp"; + + @Override + public List read(JsonReader in) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public void write(JsonWriter out, List stats) throws IOException { + out.beginArray(); + for (VmClassStat stat : stats) { + write(out, stat); + } + out.endArray(); + } + + private void write(JsonWriter out, VmClassStat stat) throws IOException { + out.beginObject(); + out.name(JVM_ID); + out.value(stat.getJvmId()); + out.name(AGENT_ID); + out.value(stat.getAgentId()); + out.name(LOADED_CLASSES); + writeLong(out, stat.getLoadedClasses()); + out.name(LOADED_BYTES); + writeLong(out, stat.getLoadedBytes()); + out.name(UNLOADED_CLASSES); + writeLong(out, stat.getUnloadedClasses()); + out.name(UNLOADED_BYTES); + writeLong(out, stat.getUnloadedBytes()); + out.name(CLASS_LOAD_TIME); + writeLong(out, stat.getClassLoadTime()); + out.name(TIMESTAMP); + writeLong(out, stat.getTimeStamp()); + out.endObject(); + } + + private void writeLong(JsonWriter out, long timestamp) throws IOException { + // Write MongoDB representation of a Long + out.beginObject(); + out.name(TYPE_LONG); + out.value(String.valueOf(timestamp)); + out.endObject(); + } +} diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/agent/internal/ActivatorTest.java --- a/plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/agent/internal/ActivatorTest.java Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +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 - * . - * - * 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.classstat.agent.internal; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import org.junit.Test; -import org.osgi.framework.Bundle; -import org.osgi.framework.Version; - -import com.redhat.thermostat.backend.Backend; -import com.redhat.thermostat.backend.BackendService; -import com.redhat.thermostat.storage.core.WriterID; -import com.redhat.thermostat.testutils.StubBundleContext; -import com.redhat.thermostat.vm.classstat.common.VmClassStatDAO; - -public class ActivatorTest { - - @Test - public void verifyActivatorDoesNotRegisterServiceOnMissingDeps() throws Exception { - StubBundleContext context = new StubBundleContext(); - - Activator activator = new Activator(); - - activator.start(context); - - assertEquals(0, context.getAllServices().size()); - assertEquals(3, context.getServiceListeners().size()); - - activator.stop(context); - } - - @Test - public void verifyActivatorRegistersServices() throws Exception { - StubBundleContext context = new StubBundleContext() { - @Override - public Bundle getBundle() { - Bundle result = mock(Bundle.class); - when(result.getVersion()).thenReturn(Version.emptyVersion); - return result; - } - }; - BackendService service = mock(BackendService.class); - VmClassStatDAO vmClassStatDAO = mock(VmClassStatDAO.class); - WriterID idService = mock(WriterID.class); - - context.registerService(BackendService.class, service, null); - context.registerService(VmClassStatDAO.class, vmClassStatDAO, null); - context.registerService(WriterID.class, idService, null); - - Activator activator = new Activator(); - - activator.start(context); - - assertTrue(context.isServiceRegistered(Backend.class.getName(), VmClassStatBackend.class)); - VmClassStatBackend backend = activator.getBackend(); - assertNotNull(backend); - - // something in core thermostat activates the backend; do it manually here - backend.activate(); - - activator.stop(context); - - assertFalse(backend.isActive()); - - assertEquals(0, context.getServiceListeners().size()); - assertEquals(3, context.getAllServices().size()); - } - -} - diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatBackendTest.java --- a/plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatBackendTest.java Tue Oct 10 12:29:18 2017 -0400 +++ b/plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatBackendTest.java Wed Oct 18 15:15:19 2017 -0400 @@ -36,34 +36,104 @@ package com.redhat.thermostat.vm.classstat.agent.internal; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import org.junit.Before; -import org.junit.Test; +import com.redhat.thermostat.jvm.overview.agent.VmStatusListenerRegistrar; -import com.redhat.thermostat.agent.VmStatusListenerRegistrar; -import com.redhat.thermostat.common.Ordered; -import com.redhat.thermostat.common.Version; +import org.junit.Test; +import org.junit.Before; + import com.redhat.thermostat.storage.core.WriterID; -import com.redhat.thermostat.vm.classstat.common.VmClassStatDAO; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; public class VmClassStatBackendTest { - - private VmClassStatBackend backend; + + private TestVmClassBackend backend; + private VmClassStatBackend.ListenerCreator listenerCreator; @Before public void setup() { - VmClassStatDAO vmClassStatDao = mock(VmClassStatDAO.class); - - Version version = mock(Version.class); - when(version.getVersionNumber()).thenReturn("0.0.0"); - - VmStatusListenerRegistrar registrar = mock(VmStatusListenerRegistrar.class); + listenerCreator = mock(VmClassStatBackend.ListenerCreator.class); + backend = new TestVmClassBackend(listenerCreator); + } + + @Test + public void testComponentActivated() { + BundleContext context = mock(BundleContext.class); + Bundle bundle = mock(Bundle.class); + org.osgi.framework.Version version = new org.osgi.framework.Version(1, 2, 3); + when(bundle.getVersion()).thenReturn(version); + when(context.getBundle()).thenReturn(bundle); WriterID id = mock(WriterID.class); - backend = new VmClassStatBackend(vmClassStatDao, version, registrar, id); + backend.bindWriterId(id); + backend.componentActivated(context); + + assertEquals(id, backend.writerId); + assertEquals("1.2.3", backend.version); + assertNotNull(backend.registrar); + } + + @Test + public void testComponentDeactivated() { + // Begin with backend appearing active for this test + backend.active = true; + + assertTrue(backend.isActive()); + backend.componentDeactivated(); + assertFalse(backend.isActive()); + } + + @Test + public void testCreateVmListener() { + final String writerId = "myAgent"; + final String jvmId = "mhJVM"; + final int pid = 1234; + + VmClassStatDAO dao = mock(VmClassStatDAO.class); + backend.bindVmClassStatDao(dao); + backend.createVmListener(writerId, jvmId, pid); + + verify(listenerCreator).create(writerId, dao, jvmId); } + + static class TestVmClassBackend extends VmClassStatBackend { + WriterID writerId; + VmStatusListenerRegistrar registrar; + String version; + boolean active; + + TestVmClassBackend(ListenerCreator creator) { + super(creator); + } + + // Override to capture values + @Override + protected void initialize(WriterID writerId, VmStatusListenerRegistrar registrar, String version) { + this.writerId = writerId; + this.registrar = registrar; + this.version = version; + } + + // Override the following to test backend is deactivated when dependencies are lost + @Override + public boolean isActive() { + return active; + } + + @Override + public boolean deactivate() { + active = false; + return true; + } + } + } diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatDAOTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatDAOTest.java Wed Oct 18 15:15:19 2017 -0400 @@ -0,0 +1,125 @@ +/* + * 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 + * . + * + * 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.classstat.agent.internal; + + +import static org.mockito.Matchers.anyListOf; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.net.URI; +import java.util.Arrays; + + +import com.redhat.thermostat.agent.http.HttpRequestService; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugin.PluginConfiguration; +import com.redhat.thermostat.common.plugin.SystemID; +import com.redhat.thermostat.vm.classstat.model.VmClassStat; + +import org.junit.Before; +import org.junit.Test; + +public class VmClassStatDAOTest { + + private static final String VM_ID = "jvmId"; + private static final Long LOADED_CLASSES = 12345L; + private static final Long LOADED_BYTES = 2345L; + private static final Long UNLOADED_CLASSES = 3456L; + private static final Long UNLOADED_BYTES = 4567L; + private static final Long CLASS_LOAD_TIME = 5678L; + + private static final String WRITER_ID = "writerId"; + private static final long TIMESTAMP = 123455667L; + private static final String SOME_SYSTEM_ID = "somesystemid"; + private static final String AGENT_ID = "some-agent"; + private static final String JSON = "{\"this\":\"is\",\"also\":\"JSON\"}"; + + private static final URI GATEWAY_URI; + + static { + GATEWAY_URI = URI.create("http://example.com/jvm-classtat/"); + } + + private VmClassStat classStat; + private VmClassStatDAOImpl.JsonHelper jsonHelper; + private VmClassStatDAOImpl dao; + private HttpRequestService httpRequestService; + + @Before + public void setUp() throws IOException { + this.classStat = new VmClassStat(WRITER_ID, + VM_ID, + TIMESTAMP, + LOADED_CLASSES, + LOADED_BYTES, + UNLOADED_CLASSES, + UNLOADED_BYTES, + CLASS_LOAD_TIME + ); + + jsonHelper = mock(VmClassStatDAOImpl.JsonHelper.class); + when(jsonHelper.toJson(anyListOf(VmClassStat.class))).thenReturn(JSON); + + ConfigurationInfoSource source = mock(ConfigurationInfoSource.class); + PluginConfiguration config = mock(PluginConfiguration.class); + when(config.getGatewayURL()).thenReturn(GATEWAY_URI); + VmClassStatDAOImpl.ConfigurationCreator creator = mock(VmClassStatDAOImpl.ConfigurationCreator.class); + when(creator.create(source)).thenReturn(config); + + httpRequestService = mock(HttpRequestService.class); + dao = new VmClassStatDAOImpl(jsonHelper, creator); + dao.bindHttpRequestService(httpRequestService); + dao.bindConfigurationInfoSource(source); + } + + @Test + public void verifyPut() throws Exception { + SystemID id = mock(SystemID.class); + when(id.getSystemID()).thenReturn(SOME_SYSTEM_ID); + dao.bindSystemID(id); + dao.activate(); + dao.put(classStat); + + verify(jsonHelper).toJson(eq(Arrays.asList(classStat))); + String s = verify(httpRequestService).sendHttpRequest(JSON, GATEWAY_URI.resolve("systems/" + SOME_SYSTEM_ID + "/jvms/" + VM_ID), HttpRequestService.Method.POST); + } +} + diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatDataExtractorTest.java --- a/plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatDataExtractorTest.java Tue Oct 10 12:29:18 2017 -0400 +++ b/plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatDataExtractorTest.java Wed Oct 18 15:15:19 2017 -0400 @@ -41,11 +41,10 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.redhat.thermostat.jvm.overview.agent.VmUpdate; +import com.redhat.thermostat.jvm.overview.agent.VmUpdateException; import org.junit.Test; -import com.redhat.thermostat.backend.VmUpdate; -import com.redhat.thermostat.backend.VmUpdateException; - public class VmClassStatDataExtractorTest { @Test diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatVmListenerTest.java --- a/plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatVmListenerTest.java Tue Oct 10 12:29:18 2017 -0400 +++ b/plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatVmListenerTest.java Wed Oct 18 15:15:19 2017 -0400 @@ -37,23 +37,19 @@ package com.redhat.thermostat.vm.classstat.agent.internal; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import com.redhat.thermostat.jvm.overview.agent.VmUpdate; +import com.redhat.thermostat.jvm.overview.agent.VmUpdateException; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; -import com.redhat.thermostat.backend.VmUpdate; -import com.redhat.thermostat.backend.VmUpdateException; -import com.redhat.thermostat.vm.classstat.common.VmClassStatDAO; -import com.redhat.thermostat.vm.classstat.common.model.VmClassStat; +import com.redhat.thermostat.vm.classstat.model.VmClassStat; public class VmClassStatVmListenerTest { @@ -106,10 +102,10 @@ listener.countersUpdated(update); ArgumentCaptor arg = ArgumentCaptor.forClass(VmClassStat.class); - verify(dao).putVmClassStat(arg.capture()); + verify(dao).put(arg.capture()); VmClassStat stat = arg.getValue(); assertEquals(LOADED_CLASSES, (Long) stat.getLoadedClasses()); - assertEquals(VM_ID, stat.getVmId()); + assertEquals(VM_ID, stat.getJvmId()); } @Test diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/model/VmClassStatTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/model/VmClassStatTest.java Wed Oct 18 15:15:19 2017 -0400 @@ -0,0 +1,48 @@ +/* + * 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 + * . + * + * 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.classstat.model; + +import com.redhat.thermostat.testutils.DataObjectTest; + +public class VmClassStatTest extends DataObjectTest { + + @Override + public Class[] getDataClasses() { + return new Class[] { VmClassStat.class }; + } +} + diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/model/VmClassStatTypeAdapterTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-classstat/agent/src/test/java/com/redhat/thermostat/vm/classstat/model/VmClassStatTypeAdapterTest.java Wed Oct 18 15:15:19 2017 -0400 @@ -0,0 +1,48 @@ +/* + * 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 + * . + * + * 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.classstat.model; + +import com.google.gson.GsonBuilder; +import com.google.gson.Gson; +import org.junit.Test; + + +import static com.redhat.thermostat.testutils.JsonUtils.assertJsonEquals; + +public class VmClassStatTypeAdapterTest { + +} diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/pom.xml --- a/plugins/vm-classstat/common/pom.xml Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,133 +0,0 @@ - - - - 4.0.0 - - thermostat-vm-classstat - com.redhat.thermostat.agent - 2.99.0-SNAPSHOT - - thermostat-vm-classstat-common - bundle - Thermostat VM ClassStat Common plugin - - - - src/main/resources - true - - **/*.png - - - - src/main/resources - false - - **/*.png - - - - - - org.apache.felix - maven-bundle-plugin - true - - - Red Hat, Inc. - com.redhat.thermostat.vm.classstat.common - com.redhat.thermostat.vm.classstat.common.internal.Activator - - com.redhat.thermostat.vm.classstat.common, - com.redhat.thermostat.vm.classstat.common.model - - - com.redhat.thermostat.vm.classstat.common.internal - - - <_nouses>true - - - - - - - - junit - junit - test - - - org.mockito - mockito-core - test - - - org.osgi - org.osgi.core - provided - - - org.osgi - org.osgi.compendium - provided - - - com.redhat.thermostat.agent - thermostat-common-core - ${project.version} - - - com.redhat.thermostat.agent - thermostat-storage-core - ${project.version} - - - com.redhat.thermostat.agent - thermostat-common-test - ${project.version} - test - - - com.google.code.gson - gson - ${gson.version} - - - diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/src/main/java/com/redhat/thermostat/vm/classstat/common/VmClassStatDAO.java --- a/plugins/vm-classstat/common/src/main/java/com/redhat/thermostat/vm/classstat/common/VmClassStatDAO.java Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +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 - * . - * - * 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.classstat.common; - -import java.util.Arrays; -import java.util.List; - -import com.redhat.thermostat.annotations.Service; -import com.redhat.thermostat.storage.core.Category; -import com.redhat.thermostat.storage.core.Key; -import com.redhat.thermostat.storage.core.VmRef; -import com.redhat.thermostat.vm.classstat.common.model.VmClassStat; - -@Service -public interface VmClassStatDAO { - - static final Key loadedClassesKey = new Key<>("loadedClasses"); - static final Key loadedBytesKey = new Key<>("loadedBytes"); - static final Key unloadedClassesKey = new Key<>("unloadedClasses"); - static final Key unloadedBytesKey = new Key<>("unloadedBytes"); - static final Key classLoadTimeKey = new Key<>("classLoadTime"); - - static final Category vmClassStatsCategory = new Category<>( - "vm-class-stats", VmClassStat.class, - Arrays.>asList( - Key.AGENT_ID, Key.VM_ID, Key.TIMESTAMP, - loadedClassesKey, loadedBytesKey, - unloadedClassesKey, unloadedBytesKey, - classLoadTimeKey), - Arrays.>asList(Key.TIMESTAMP)); - - public List getLatestClassStats(VmRef ref, long since); - - public List getClassStats(VmRef ref, long since, long to); - - public void putVmClassStat(VmClassStat stat); - - public abstract VmClassStat getOldest(VmRef ref); - - public abstract VmClassStat getNewest(VmRef ref); - -} - diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/src/main/java/com/redhat/thermostat/vm/classstat/common/internal/Activator.java --- a/plugins/vm-classstat/common/src/main/java/com/redhat/thermostat/vm/classstat/common/internal/Activator.java Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +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 - * . - * - * 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.classstat.common.internal; - -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.storage.core.Storage; -import com.redhat.thermostat.vm.classstat.common.VmClassStatDAO; - -public class Activator implements BundleActivator { - - private ServiceTracker tracker; - private ServiceRegistration reg; - - @Override - public void start(BundleContext context) throws Exception { - tracker = new ServiceTracker(context, Storage.class.getName(), null) { - @Override - public Object addingService(ServiceReference reference) { - Storage storage = (Storage) context.getService(reference); - VmClassStatDAO vmClassStatDao = new VmClassStatDAOImpl(storage); - reg = context.registerService(VmClassStatDAO.class.getName(), vmClassStatDao, null); - return super.addingService(reference); - } - - @Override - public void removedService(ServiceReference reference, - Object service) { - reg.unregister(); - super.removedService(reference, service); - } - }; - tracker.open(); - } - - @Override - public void stop(BundleContext context) throws Exception { - tracker.close(); - } - -} - diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/src/main/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatCategoryRegistration.java --- a/plugins/vm-classstat/common/src/main/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatCategoryRegistration.java Tue Oct 10 12:29:18 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 - * . - * - * 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.classstat.common.internal; - -import java.util.HashSet; -import java.util.Set; - -import com.redhat.thermostat.storage.core.auth.CategoryRegistration; -import com.redhat.thermostat.vm.classstat.common.VmClassStatDAO; - -/** - * Registers the category used by this maven module. The web storage - * endpoint only allows categories to be registered which it knows of - * ahead of time. - * - */ -public class VmClassStatCategoryRegistration implements CategoryRegistration { - - @Override - public Set getCategoryNames() { - Set categories = new HashSet<>(1); - categories.add(VmClassStatDAO.vmClassStatsCategory.getName()); - return categories; - } - -} - diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/src/main/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatDAOImpl.java --- a/plugins/vm-classstat/common/src/main/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatDAOImpl.java Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,132 +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 - * . - * - * 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.classstat.common.internal; - -import java.util.List; -import java.util.logging.Logger; - -import com.redhat.thermostat.common.utils.LoggingUtils; -import com.redhat.thermostat.storage.core.Key; -import com.redhat.thermostat.storage.core.PreparedStatement; -import com.redhat.thermostat.storage.core.Storage; -import com.redhat.thermostat.storage.core.VmBoundaryPojoGetter; -import com.redhat.thermostat.storage.core.VmLatestPojoListGetter; -import com.redhat.thermostat.storage.core.VmRef; -import com.redhat.thermostat.storage.core.VmTimeIntervalPojoListGetter; -import com.redhat.thermostat.storage.dao.AbstractDao; -import com.redhat.thermostat.storage.dao.AbstractDaoStatement; -import com.redhat.thermostat.vm.classstat.common.VmClassStatDAO; -import com.redhat.thermostat.vm.classstat.common.model.VmClassStat; - -class VmClassStatDAOImpl extends AbstractDao implements VmClassStatDAO { - - private static final Logger logger = LoggingUtils.getLogger(VmClassStatDAOImpl.class); - // ADD vm-class-stats SET 'agentId' = ?s , \ - // 'vmId' = ?s , \ - // 'timeStamp' = ?l , \ - // 'loadedClasses' = ?l , \ - // 'loadedBytes' = ?l , \ - // 'unloadedClasses' = ?l , \ - // 'unloadedBytes' = ?l , \ - // 'classLoadTime' = ?l - static final String DESC_ADD_VM_CLASS_STAT = "ADD " + vmClassStatsCategory.getName() + - " SET '" + Key.AGENT_ID.getName() + "' = ?s , " + - "'" + Key.VM_ID.getName() + "' = ?s , " + - "'" + Key.TIMESTAMP.getName() + "' = ?l , " + - "'" + loadedClassesKey.getName() + "' = ?l , " + - "'" + loadedBytesKey.getName() + "' = ?l , " + - "'" + unloadedClassesKey.getName() + "' = ?l , " + - "'" + unloadedBytesKey.getName() + "' = ?l , " + - "'" + classLoadTimeKey.getName() + "' = ?l"; - - private final Storage storage; - private final VmLatestPojoListGetter latestGetter; - private final VmTimeIntervalPojoListGetter intervalGetter; - private final VmBoundaryPojoGetter boundaryGetter; - - VmClassStatDAOImpl(Storage storage) { - this.storage = storage; - storage.registerCategory(vmClassStatsCategory); - this.latestGetter = new VmLatestPojoListGetter<>(storage, vmClassStatsCategory); - this.intervalGetter = new VmTimeIntervalPojoListGetter<>(storage, vmClassStatsCategory); - this.boundaryGetter = new VmBoundaryPojoGetter<>(storage, vmClassStatsCategory); - } - - @Override - public List getLatestClassStats(VmRef ref, long lastUpdateTime) { - return latestGetter.getLatest(ref, lastUpdateTime); - } - - @Override - public List getClassStats(VmRef ref, long since, long to) { - return intervalGetter.getLatest(ref, since, to); - } - - @Override - public void putVmClassStat(final VmClassStat stat) { - executeStatement(new AbstractDaoStatement(storage, vmClassStatsCategory, DESC_ADD_VM_CLASS_STAT) { - @Override - public PreparedStatement customize(PreparedStatement preparedStatement) { - preparedStatement.setString(0, stat.getAgentId()); - preparedStatement.setString(1, stat.getVmId()); - preparedStatement.setLong(2, stat.getTimeStamp()); - preparedStatement.setLong(3, stat.getLoadedClasses()); - preparedStatement.setLong(4, stat.getLoadedBytes()); - preparedStatement.setLong(5, stat.getUnloadedClasses()); - preparedStatement.setLong(6, stat.getUnloadedBytes()); - preparedStatement.setLong(7, stat.getClassLoadTime()); - return preparedStatement; - } - }); - } - - @Override - public VmClassStat getOldest(final VmRef ref) { - return boundaryGetter.getOldestStat(ref); - } - - @Override - public VmClassStat getNewest(final VmRef ref) { - return boundaryGetter.getNewestStat(ref); - } - - @Override - protected Logger getLogger() { - return logger; - } -} - diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/src/main/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatDAOImplStatementDescriptorRegistration.java --- a/plugins/vm-classstat/common/src/main/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatDAOImplStatementDescriptorRegistration.java Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +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 - * . - * - * 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.classstat.common.internal; - -import java.util.HashSet; -import java.util.Set; - -import com.redhat.thermostat.storage.core.VmBoundaryPojoGetter; -import com.redhat.thermostat.storage.core.VmLatestPojoListGetter; -import com.redhat.thermostat.storage.core.VmTimeIntervalPojoListGetter; -import com.redhat.thermostat.storage.core.auth.StatementDescriptorRegistration; -import com.redhat.thermostat.vm.classstat.common.VmClassStatDAO; - -/** - * Registers the prepared query issued by this maven module via - * {@link VmLatestPojoListGetter}. - * - */ -public class VmClassStatDAOImplStatementDescriptorRegistration implements - StatementDescriptorRegistration { - - static final String LATEST = String.format(VmLatestPojoListGetter.VM_LATEST_QUERY_FORMAT, - VmClassStatDAO.vmClassStatsCategory.getName()); - static final String RANGE = String.format(VmTimeIntervalPojoListGetter.VM_INTERVAL_QUERY_FORMAT, - VmClassStatDAO.vmClassStatsCategory.getName()); - static final String LATEST_STAT = String.format(VmBoundaryPojoGetter.DESC_NEWEST_VM_STAT, - VmClassStatDAO.vmClassStatsCategory.getName()); - static final String OLDEST_STAT = String.format(VmBoundaryPojoGetter.DESC_OLDEST_VM_STAT, - VmClassStatDAO.vmClassStatsCategory.getName()); - - @Override - public Set getStatementDescriptors() { - Set descs = new HashSet<>(1); - descs.add(LATEST); - descs.add(RANGE); - descs.add(LATEST_STAT); - descs.add(OLDEST_STAT); - descs.add(VmClassStatDAOImpl.DESC_ADD_VM_CLASS_STAT); - return descs; - } - -} - diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/src/main/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatTypeAdapter.java --- a/plugins/vm-classstat/common/src/main/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatTypeAdapter.java Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +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 - * . - * - * 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.classstat.common.internal; - -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import com.redhat.thermostat.vm.classstat.common.model.VmClassStat; - -import com.google.gson.TypeAdapter; - -import java.io.IOException; - -public class VmClassStatTypeAdapter extends TypeAdapter { - - private static final String TYPE_LONG = "$numberLong"; - private static final String VM_ID = "vmId"; - private static final String AGENT_ID = "agentId"; - private static final String LOADED_CLASSES = "loadedClasses"; - private static final String LOADED_BYTES = "loadedBytes"; - private static final String UNLOADED_CLASSES = "unloadedClasses"; - private static final String UNLOADED_BYTES = "unloadedBytes"; - private static final String CLASS_LOAD_TIME = "classLoadTime"; - private static final String TIMESTAMP = "timeStamp"; - - @Override - public VmClassStat read(JsonReader in) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public void write(JsonWriter out, VmClassStat stat) throws IOException { - out.beginObject(); - out.name(VM_ID); - out.value(stat.getVmId()); - out.name(AGENT_ID); - out.value(stat.getAgentId()); - out.name(LOADED_CLASSES); - writeLong(out, stat.getLoadedClasses()); - out.name(LOADED_BYTES); - writeLong(out, stat.getLoadedBytes()); - out.name(UNLOADED_CLASSES); - writeLong(out, stat.getUnloadedClasses()); - out.name(UNLOADED_BYTES); - writeLong(out, stat.getUnloadedBytes()); - out.name(CLASS_LOAD_TIME); - writeLong(out, stat.getClassLoadTime()); - out.name(TIMESTAMP); - writeLong(out, stat.getTimeStamp()); - out.endObject(); - } - - private void writeLong(JsonWriter out, long timestamp) throws IOException { - // Write MongoDB representation of a Long - out.beginObject(); - out.name(TYPE_LONG); - out.value(String.valueOf(timestamp)); - out.endObject(); - } -} diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/src/main/java/com/redhat/thermostat/vm/classstat/common/model/VmClassStat.java --- a/plugins/vm-classstat/common/src/main/java/com/redhat/thermostat/vm/classstat/common/model/VmClassStat.java Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,158 +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 - * . - * - * 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.classstat.common.model; - -import com.redhat.thermostat.storage.core.Entity; -import com.redhat.thermostat.storage.core.Persist; -import com.redhat.thermostat.storage.model.BasePojo; -import com.redhat.thermostat.storage.model.TimeStampedPojo; - -@Entity -public class VmClassStat extends BasePojo implements TimeStampedPojo { - - // See the jdk sources for more information: - // - jdk/src/share/classes/sun/tools/jstat/resources/jstat_options - // - jdk/src/share/classes/sun/tools/jstat/resources/jstat_unsupported_options - - public static final int UNKNOWN = -1; - - private String vmId; - private long timestamp; - private long loadedClasses; - private long loadedBytes; - private long unloadedClasses; - private long unloadedBytes; - private long classLoadTime; - - public VmClassStat() { - this(null, null, UNKNOWN, - UNKNOWN, UNKNOWN, - UNKNOWN, UNKNOWN, - UNKNOWN); - } - - public VmClassStat(String writerId, String vmId, long timestamp, - long loadedClasses, long loadedBytes, - long unloadedClasses, long unloadedBytes, - long classLoadTime) { - super(writerId); - this.vmId = vmId; - this.timestamp = timestamp; - this.loadedClasses = loadedClasses; - this.loadedBytes = loadedBytes; - this.unloadedClasses = unloadedClasses; - this.unloadedBytes = unloadedBytes; - this.classLoadTime = classLoadTime; - } - - @Persist - public String getVmId() { - return vmId; - } - - @Persist - public void setVmId(String vmId) { - this.vmId = vmId; - } - - @Persist - @Override - public long getTimeStamp() { - return timestamp; - } - - @Persist - public void setTimeStamp(long timestamp) { - this.timestamp = timestamp; - } - - /** Number of classes loaded */ - @Persist - public long getLoadedClasses() { - return loadedClasses; - } - - @Persist - public void setLoadedClasses(long loadedClasses) { - this.loadedClasses = loadedClasses; - } - - /** Accumulated Size of classes loaded */ - @Persist - public long getLoadedBytes() { - return loadedBytes; - } - - @Persist - public void setLoadedBytes(long bytes) { - this.loadedBytes = bytes; - } - - /** Number of classes unloaded */ - @Persist - public long getUnloadedClasses() { - return unloadedClasses; - } - - @Persist - public void setUnloadedClasses(long classes) { - this.unloadedClasses = classes; - } - - /** Accumulated size of classes unloaded */ - @Persist - public long getUnloadedBytes() { - return unloadedBytes; - } - - @Persist - public void setUnloadedBytes(long bytes) { - this.unloadedBytes = bytes; - } - - /** Accumulated time for class loading. In seconds */ - @Persist - public long getClassLoadTime() { - return classLoadTime; - } - - @Persist - public void setClassLoadTime(long seconds) { - this.classLoadTime = seconds; - } - -} diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/src/main/resources/META-INF/services/com.redhat.thermostat.storage.core.auth.CategoryRegistration --- a/plugins/vm-classstat/common/src/main/resources/META-INF/services/com.redhat.thermostat.storage.core.auth.CategoryRegistration Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -com.redhat.thermostat.vm.classstat.common.internal.VmClassStatCategoryRegistration \ No newline at end of file diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/src/main/resources/META-INF/services/com.redhat.thermostat.storage.core.auth.StatementDescriptorRegistration --- a/plugins/vm-classstat/common/src/main/resources/META-INF/services/com.redhat.thermostat.storage.core.auth.StatementDescriptorRegistration Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -com.redhat.thermostat.vm.classstat.common.internal.VmClassStatDAOImplStatementDescriptorRegistration \ No newline at end of file diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/src/test/java/com/redhat/thermostat/vm/classstat/common/internal/ActivatorTest.java --- a/plugins/vm-classstat/common/src/test/java/com/redhat/thermostat/vm/classstat/common/internal/ActivatorTest.java Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +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 - * . - * - * 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.classstat.common.internal; - -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.storage.core.Storage; -import com.redhat.thermostat.testutils.StubBundleContext; -import com.redhat.thermostat.vm.classstat.common.VmClassStatDAO; - -public class ActivatorTest { - - @Test - public void verifyActivatorDoesNotRegisterServiceOnMissingDeps() throws Exception { - StubBundleContext context = new StubBundleContext(); - - Activator activator = new Activator(); - - activator.start(context); - - assertEquals(0, context.getAllServices().size()); - assertEquals(1, context.getServiceListeners().size()); - - activator.stop(context); - } - - @Test - public void verifyActivatorRegistersServices() throws Exception { - StubBundleContext context = new StubBundleContext(); - Storage storage = mock(Storage.class); - - context.registerService(Storage.class, storage, null); - - Activator activator = new Activator(); - - activator.start(context); - - assertTrue(context.isServiceRegistered(VmClassStatDAO.class.getName(), VmClassStatDAOImpl.class)); - - activator.stop(context); - - assertEquals(0, context.getServiceListeners().size()); - assertEquals(1, context.getAllServices().size()); - } - -} - diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/src/test/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatCategoryRegistrationTest.java --- a/plugins/vm-classstat/common/src/test/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatCategoryRegistrationTest.java Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +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 - * . - * - * 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.classstat.common.internal; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.Set; - -import org.junit.Test; - -import com.redhat.thermostat.storage.core.auth.CategoryRegistration; -import com.redhat.thermostat.testutils.ServiceLoaderTest; -import com.redhat.thermostat.vm.classstat.common.VmClassStatDAO; - -public class VmClassStatCategoryRegistrationTest extends ServiceLoaderTest { - - public VmClassStatCategoryRegistrationTest() { - super(CategoryRegistration.class, STORAGE_SERVICES, VmClassStatCategoryRegistration.class); - } - - @Test - public void registersAllCategories() { - VmClassStatCategoryRegistration reg = new VmClassStatCategoryRegistration(); - Set categories = reg.getCategoryNames(); - assertEquals(1, categories.size()); - assertFalse("null descriptor not allowed", categories.contains(null)); - assertTrue(categories.contains(VmClassStatDAO.vmClassStatsCategory.getName())); - } - -} - diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/src/test/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatDAOImplStatementDescriptorRegistrationTest.java --- a/plugins/vm-classstat/common/src/test/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatDAOImplStatementDescriptorRegistrationTest.java Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +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 - * . - * - * 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.classstat.common.internal; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - -import java.util.Set; - -import org.junit.Test; - -import com.redhat.thermostat.storage.core.auth.StatementDescriptorRegistration; -import com.redhat.thermostat.testutils.ServiceLoaderTest; - -public class VmClassStatDAOImplStatementDescriptorRegistrationTest extends ServiceLoaderTest { - - public VmClassStatDAOImplStatementDescriptorRegistrationTest() { - super(StatementDescriptorRegistration.class, STORAGE_SERVICES, VmClassStatDAOImplStatementDescriptorRegistration.class); - } - - @Test - public void registersAllDescriptors() { - VmClassStatDAOImplStatementDescriptorRegistration reg = new VmClassStatDAOImplStatementDescriptorRegistration(); - Set descriptors = reg.getStatementDescriptors(); - assertEquals(5, descriptors.size()); - assertFalse("null descriptor not allowed", descriptors.contains(null)); - } - -} - diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/src/test/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatDAOTest.java --- a/plugins/vm-classstat/common/src/test/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatDAOTest.java Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,188 +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 - * . - * - * 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.classstat.common.internal; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -import java.util.Collection; -import java.util.List; - -import org.junit.Test; -import org.mockito.ArgumentCaptor; - -import com.redhat.thermostat.storage.core.Cursor; -import com.redhat.thermostat.storage.core.DescriptorParsingException; -import com.redhat.thermostat.storage.core.HostRef; -import com.redhat.thermostat.storage.core.Key; -import com.redhat.thermostat.storage.core.PreparedStatement; -import com.redhat.thermostat.storage.core.StatementDescriptor; -import com.redhat.thermostat.storage.core.StatementExecutionException; -import com.redhat.thermostat.storage.core.Storage; -import com.redhat.thermostat.storage.core.VmRef; -import com.redhat.thermostat.vm.classstat.common.VmClassStatDAO; -import com.redhat.thermostat.vm.classstat.common.model.VmClassStat; - -public class VmClassStatDAOTest { - - private static final Long TIMESTAMP = 1234L; - private static final String VM_ID = "vmId"; - private static final Long LOADED_CLASSES = 12345L; - private static final Long LOADED_BYTES = 2345L; - private static final Long UNLOADED_CLASSES = 3456L; - private static final Long UNLOADED_BYTES = 4567L; - private static final Long CLASS_LOAD_TIME = 5678L; - - @Test - public void testStatementDescriptorsAreSane() { - String addVmClassStat = "ADD vm-class-stats SET 'agentId' = ?s , " + - "'vmId' = ?s , " + - "'timeStamp' = ?l , " + - "'loadedClasses' = ?l , " + - "'loadedBytes' = ?l , " + - "'unloadedClasses' = ?l , " + - "'unloadedBytes' = ?l , " + - "'classLoadTime' = ?l"; - - assertEquals(addVmClassStat, VmClassStatDAOImpl.DESC_ADD_VM_CLASS_STAT); - } - - @Test - public void testCategory() { - assertEquals("vm-class-stats", VmClassStatDAO.vmClassStatsCategory.getName()); - Collection> keys = VmClassStatDAO.vmClassStatsCategory.getKeys(); - assertTrue(keys.contains(new Key<>("agentId"))); - assertTrue(keys.contains(new Key("vmId"))); - assertTrue(keys.contains(new Key("timeStamp"))); - assertTrue(keys.contains(new Key("loadedClasses"))); - assertTrue(keys.contains(new Key("loadedBytes"))); - assertTrue(keys.contains(new Key("unloadedClasses"))); - assertTrue(keys.contains(new Key("unloadedBytes"))); - assertTrue(keys.contains(new Key("classLoadTime"))); - assertEquals(8, keys.size()); - } - - @Test - public void testGetLatestClassStatsBasic() throws DescriptorParsingException, StatementExecutionException { - - VmClassStat vmClassStat = getClassStat(); - - @SuppressWarnings("unchecked") - Cursor cursor = mock(Cursor.class); - when(cursor.hasNext()).thenReturn(true).thenReturn(false); - when(cursor.next()).thenReturn(vmClassStat); - - Storage storage = mock(Storage.class); - @SuppressWarnings("unchecked") - PreparedStatement stmt = (PreparedStatement) mock(PreparedStatement.class); - when(storage.prepareStatement(anyDescriptor())).thenReturn(stmt); - when(stmt.executeQuery()).thenReturn(cursor); - - HostRef hostRef = mock(HostRef.class); - when(hostRef.getAgentId()).thenReturn("system"); - - VmRef vmRef = mock(VmRef.class); - when(vmRef.getHostRef()).thenReturn(hostRef); - when(vmRef.getVmId()).thenReturn(VM_ID); - - VmClassStatDAO dao = new VmClassStatDAOImpl(storage); - List vmClassStats = dao.getLatestClassStats(vmRef, Long.MIN_VALUE); - - verify(storage).prepareStatement(anyDescriptor()); - verify(stmt).setString(0, "system"); - verify(stmt).setString(1, VM_ID); - verify(stmt).setLong(2, Long.MIN_VALUE); - verify(stmt).executeQuery(); - verifyNoMoreInteractions(stmt); - - assertEquals(1, vmClassStats.size()); - VmClassStat stat = vmClassStats.get(0); - assertEquals(TIMESTAMP, (Long) stat.getTimeStamp()); - assertEquals(LOADED_CLASSES, (Long) stat.getLoadedClasses()); - assertEquals(VM_ID, stat.getVmId()); - } - - @SuppressWarnings("unchecked") - private StatementDescriptor anyDescriptor() { - return (StatementDescriptor) any(StatementDescriptor.class); - } - - private VmClassStat getClassStat() { - return new VmClassStat("foo-agent", VM_ID, TIMESTAMP, - LOADED_CLASSES, LOADED_BYTES, - UNLOADED_CLASSES, UNLOADED_BYTES, - CLASS_LOAD_TIME); - } - - @SuppressWarnings("unchecked") - @Test - public void testPutVmClassStat() throws DescriptorParsingException, StatementExecutionException { - - Storage storage = mock(Storage.class); - PreparedStatement add = mock(PreparedStatement.class); - when(storage.prepareStatement(any(StatementDescriptor.class))).thenReturn(add); - - VmClassStat stat = new VmClassStat("foo-agent", VM_ID, TIMESTAMP, - LOADED_CLASSES, LOADED_BYTES, UNLOADED_CLASSES, UNLOADED_BYTES, CLASS_LOAD_TIME); - VmClassStatDAO dao = new VmClassStatDAOImpl(storage); - dao.putVmClassStat(stat); - - @SuppressWarnings("rawtypes") - ArgumentCaptor captor = ArgumentCaptor.forClass(StatementDescriptor.class); - - verify(storage).prepareStatement(captor.capture()); - StatementDescriptor desc = captor.getValue(); - assertEquals(VmClassStatDAOImpl.DESC_ADD_VM_CLASS_STAT, desc.getDescriptor()); - - verify(add).setString(0, stat.getAgentId()); - verify(add).setString(1, stat.getVmId()); - verify(add).setLong(2, stat.getTimeStamp()); - verify(add).setLong(3, stat.getLoadedClasses()); - verify(add).setLong(4, stat.getLoadedBytes()); - verify(add).setLong(5, stat.getUnloadedClasses()); - verify(add).setLong(6, stat.getUnloadedBytes()); - verify(add).setLong(7, stat.getClassLoadTime()); - verify(add).execute(); - verifyNoMoreInteractions(add); - } -} - diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/src/test/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatTypeAdapterTest.java --- a/plugins/vm-classstat/common/src/test/java/com/redhat/thermostat/vm/classstat/common/internal/VmClassStatTypeAdapterTest.java Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +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 - * . - * - * 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.classstat.common.internal; - -import com.google.gson.GsonBuilder; -import com.google.gson.Gson; -import org.junit.Test; - -import com.redhat.thermostat.vm.classstat.common.model.VmClassStat; - -import static com.redhat.thermostat.testutils.JsonUtils.assertJsonEquals; - -public class VmClassStatTypeAdapterTest { - - @Test - public void testRead() { - GsonBuilder builder = new GsonBuilder(); - builder.registerTypeAdapter(VmClassStat.class, new VmClassStatTypeAdapter()); - Gson gson = builder.create(); - VmClassStat stat = new VmClassStat(); - stat.setVmId("1"); - stat.setAgentId("2"); - stat.setTimeStamp(100l); - stat.setClassLoadTime(2000l); - stat.setLoadedBytes(10l); - stat.setLoadedClasses(1l); - stat.setUnloadedBytes(10l); - stat.setUnloadedClasses(1l); - assertJsonEquals("{\"vmId\":\"1\",\"agentId\":\"2\",\"loadedClasses\":{\"$numberLong\":\"1\"},\"loadedBytes\":{\"$numberLong\":\"10\"},\"unloadedClasses\":{\"$numberLong\":\"1\"},\"unloadedBytes\":{\"$numberLong\":\"10\"},\"classLoadTime\":{\"$numberLong\":\"2000\"},\"timeStamp\":{\"$numberLong\":\"100\"}}", gson.toJson(stat)); - } -} diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/common/src/test/java/com/redhat/thermostat/vm/classstat/common/model/VmClassStatTest.java --- a/plugins/vm-classstat/common/src/test/java/com/redhat/thermostat/vm/classstat/common/model/VmClassStatTest.java Tue Oct 10 12:29:18 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +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 - * . - * - * 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.classstat.common.model; - -import com.redhat.thermostat.testutils.DataObjectTest; - -public class VmClassStatTest extends DataObjectTest { - - @Override - public Class[] getDataClasses() { - return new Class[] { VmClassStat.class }; - } -} - diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/distribution/assemblies/plugin-assembly.xml --- a/plugins/vm-classstat/distribution/assemblies/plugin-assembly.xml Tue Oct 10 12:29:18 2017 -0400 +++ b/plugins/vm-classstat/distribution/assemblies/plugin-assembly.xml Wed Oct 18 15:15:19 2017 -0400 @@ -37,32 +37,38 @@ --> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> plugin-assembly zip - ${thermostat.plugin} - true + false - com.redhat.thermostat.agent:thermostat-vm-classstat-common com.redhat.thermostat.agent:thermostat-vm-classstat-agent false true + plugins/${thermostat.plugin} - - - - thermostat-plugin.xml - / + + + + + thermostat-plugin.xml + + plugins/${thermostat.plugin} true - - + + + configFiles + etc/plugins.d/${thermostat.plugin} + true + + diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/distribution/configFiles/gateway.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-classstat/distribution/configFiles/gateway.properties Wed Oct 18 15:15:19 2017 -0400 @@ -0,0 +1,2 @@ +# URL to the microservice provided by the Thermostat web gateway +gatewayURL=https://localhost:30000/jvm-classstat/0.0.1 \ No newline at end of file diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/distribution/thermostat-plugin.xml --- a/plugins/vm-classstat/distribution/thermostat-plugin.xml Tue Oct 10 12:29:18 2017 -0400 +++ b/plugins/vm-classstat/distribution/thermostat-plugin.xml Wed Oct 18 15:15:19 2017 -0400 @@ -43,7 +43,6 @@ agent - com.redhat.thermostat.vm.classstat.common${project.version} com.redhat.thermostat.vm.classstat.agent${project.version} diff -r 9e3d6eedbbee -r 4f12f8ffdc9b plugins/vm-classstat/pom.xml --- a/plugins/vm-classstat/pom.xml Tue Oct 10 12:29:18 2017 -0400 +++ b/plugins/vm-classstat/pom.xml Wed Oct 18 15:15:19 2017 -0400 @@ -52,7 +52,6 @@ agent - common distribution