Mercurial > hg > thermostat-ng > agent
changeset 2770:bde0a709ca30
Reactive and convert the JVM-Compiler plugin to declarative services. Merge c.r.t.compiler.agent and c.r.t.compiler.common bundles.
Reviewed-by: jmatsuok, stooke
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-September/024798.html
author | Chris Lessard <clessard@redhat.com> |
---|---|
date | Fri, 06 Oct 2017 14:14:13 -0400 |
parents | 6dbace3c1515 |
children | 1a0d260468d1 |
files | distribution/assembly/plugin-assembly.xml distribution/pom.xml plugins/pom.xml plugins/vm-compiler/agent/pom.xml plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/Activator.java plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatBackend.java plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatDao.java plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatDaoImpl.java plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatVmListener.java plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/model/VmCompilerStat.java plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/model/VmCompilerStatTypeAdapter.java plugins/vm-compiler/agent/src/test/java/com/redhat/thermostat/vm/compiler/agent/internal/ActivatorTest.java plugins/vm-compiler/agent/src/test/java/com/redhat/thermostat/vm/compiler/agent/internal/VmClassStatBackendTest.java plugins/vm-compiler/agent/src/test/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatBackendTest.java plugins/vm-compiler/agent/src/test/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatDaoImplTest.java plugins/vm-compiler/agent/src/test/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatVmListenerTest.java plugins/vm-compiler/common/pom.xml plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/ParsedVmCompilerStat.java plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/VmCompilerStat.java plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/VmCompilerStatDao.java plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/internal/Activator.java plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatCategoryRegistration.java plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatDaoImpl.java plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatDaoImplStatementDescriptorRegistration.java plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatTypeAdapter.java plugins/vm-compiler/common/src/main/resources/META-INF/services/com.redhat.thermostat.storage.core.auth.CategoryRegistration plugins/vm-compiler/common/src/main/resources/META-INF/services/com.redhat.thermostat.storage.core.auth.StatementDescriptorRegistration plugins/vm-compiler/common/src/test/java/com/redhat/thermostat/vm/compiler/common/VmCompilerStatTest.java plugins/vm-compiler/common/src/test/java/com/redhat/thermostat/vm/compiler/common/internal/ActivatorTest.java plugins/vm-compiler/common/src/test/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatCategoryRegistrationTest.java plugins/vm-compiler/common/src/test/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatDaoImplStatementDescriptorRegistrationTest.java plugins/vm-compiler/common/src/test/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatDaoImplTest.java plugins/vm-compiler/common/src/test/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatTypeAdapterTest.java plugins/vm-compiler/distribution/assemblies/plugin-assembly.xml plugins/vm-compiler/distribution/configFiles/gateway.properties plugins/vm-compiler/distribution/thermostat-plugin.xml plugins/vm-compiler/pom.xml |
diffstat | 37 files changed, 959 insertions(+), 1949 deletions(-) [+] |
line wrap: on
line diff
--- a/distribution/assembly/plugin-assembly.xml Mon Oct 02 15:09:26 2017 +0200 +++ b/distribution/assembly/plugin-assembly.xml Fri Oct 06 14:14:13 2017 -0400 @@ -60,10 +60,10 @@ <include>com.redhat.thermostat.agent:thermostat-vm-byteman-distribution</include> <include>com.redhat.thermostat.agent:thermostat-commands-distribution</include> <include>com.redhat.thermostat.agent:thermostat-killvm-distribution</include> -<!-- <include>com.redhat.thermostat.agent:thermostat-numa-distribution</include>--> + <include>com.redhat.thermostat.agent:thermostat-vm-compiler-distribution</include> + <!-- <include>com.redhat.thermostat.agent:thermostat-numa-distribution</include>--> <!-- <include>com.redhat.thermostat.agent:thermostat-thread-distribution</include>--> <!-- <include>com.redhat.thermostat.agent:thermostat-vm-classstat-distribution</include>--> -<!-- <include>com.redhat.thermostat.agent:thermostat-vm-compiler-distribution</include>--> <!-- <include>com.redhat.thermostat.agent:thermostat-vm-cpu-distribution</include>--> <!-- <include>com.redhat.thermostat.agent:thermostat-vm-heap-analysis-distribution</include>--> <!-- <include>com.redhat.thermostat.agent:thermostat-vm-jmx-distribution</include>-->
--- a/distribution/pom.xml Mon Oct 02 15:09:26 2017 +0200 +++ b/distribution/pom.xml Fri Oct 06 14:14:13 2017 -0400 @@ -1,4 +1,3 @@ -<?xml version="1.0" encoding="UTF-8"?> <!-- Copyright 2012-2017 Red Hat, Inc. @@ -558,12 +557,12 @@ <!--<version>${project.version}</version>--> <!--<type>zip</type>--> <!--</dependency>--> - <!--<dependency>--> - <!--<groupId>com.redhat.thermostat.agent</groupId>--> - <!--<artifactId>thermostat-vm-compiler-distribution</artifactId>--> - <!--<version>${project.version}</version>--> - <!--<type>zip</type>--> - <!--</dependency>--> + <dependency> + <groupId>com.redhat.thermostat.agent</groupId> + <artifactId>thermostat-vm-compiler-distribution</artifactId> + <version>${project.version}</version> + <type>zip</type> + </dependency> <!--<dependency>--> <!--<groupId>com.redhat.thermostat.agent</groupId>--> <!--<artifactId>thermostat-vm-cpu-distribution</artifactId>-->
--- a/plugins/pom.xml Mon Oct 02 15:09:26 2017 +0200 +++ b/plugins/pom.xml Fri Oct 06 14:14:13 2017 -0400 @@ -63,9 +63,9 @@ <module>vm-memory</module> <module>commands</module> <module>vm-byteman</module> + <module>vm-compiler</module> <!--<module>vm-cpu</module>--> <!--<module>vm-classstat</module>--> - <!--<module>vm-compiler</module>--> <!--<module>vm-heap-analysis</module>--> <!--<module>vm-jmx</module>--> <!--<module>vm-profiler</module>-->
--- a/plugins/vm-compiler/agent/pom.xml Mon Oct 02 15:09:26 2017 +0200 +++ b/plugins/vm-compiler/agent/pom.xml Fri Oct 06 14:14:13 2017 -0400 @@ -56,8 +56,10 @@ <instructions> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> <Bundle-SymbolicName>com.redhat.thermostat.vm.compiler.agent</Bundle-SymbolicName> - <Bundle-Activator>com.redhat.thermostat.vm.compiler.agent.internal.Activator</Bundle-Activator> - <Export-Package /> + <Export-Package> + com.redhat.thermostat.vm.compiler, + com.redhat.thermostat.vm.compiler.model + </Export-Package> <Private-Package> com.redhat.thermostat.vm.compiler.agent.internal </Private-Package> @@ -66,6 +68,18 @@ </instructions> </configuration> </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + <executions> + <execution> + <id>generate-scr-scrdescriptor</id> + <goals> + <goal>scr</goal> + </goals> + </execution> + </executions> + </plugin> </plugins> </build> <dependencies> @@ -96,11 +110,6 @@ </dependency> <dependency> <groupId>com.redhat.thermostat.agent</groupId> - <artifactId>thermostat-vm-compiler-common</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.redhat.thermostat.agent</groupId> <artifactId>thermostat-agent-core</artifactId> <version>${project.version}</version> </dependency> @@ -115,5 +124,25 @@ <version>${project.version}</version> <scope>test</scope> </dependency> + <!-- declarative services --> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.scr.annotations</artifactId> + </dependency> + <dependency> + <groupId>com.redhat.thermostat.agent</groupId> + <artifactId>thermostat-common-plugin</artifactId> + <version>2.99.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>com.redhat.thermostat.agent</groupId> + <artifactId>thermostat-jvm-overview-agent</artifactId> + <version>2.99.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project>
--- a/plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/Activator.java Mon Oct 02 15:09:26 2017 +0200 +++ /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 - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.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.compiler.common.VmCompilerStatDao; - -public class Activator implements BundleActivator { - - private MultipleServiceTracker tracker; - private VmCompilerStatBackend backend; - private ServiceRegistration<Backend> reg; - - @Override - public void start(final BundleContext context) throws Exception { - - final VmStatusListenerRegistrar registrar = new VmStatusListenerRegistrar(context); - - Class<?>[] deps = new Class<?>[] { - BackendService.class, - VmCompilerStatDao.class, - WriterID.class, // vm compiler uses it - }; - tracker = new MultipleServiceTracker(context, deps, new Action() { - - @Override - public void dependenciesAvailable(DependencyProvider services) { - VmCompilerStatDao vmCompilerStatDao = services.get(VmCompilerStatDao.class); - Version version = new Version(context.getBundle()); - WriterID id = services.get(WriterID.class); - backend = new VmCompilerStatBackend(vmCompilerStatDao, 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. - */ - VmCompilerStatBackend getBackend() { - return backend; - } -} -
--- a/plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatBackend.java Mon Oct 02 15:09:26 2017 +0200 +++ b/plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatBackend.java Fri Oct 06 14:14:13 2017 -0400 @@ -36,30 +36,75 @@ package com.redhat.thermostat.vm.compiler.agent.internal; -import com.redhat.thermostat.agent.VmStatusListenerRegistrar; -import com.redhat.thermostat.backend.VmListenerBackend; -import com.redhat.thermostat.backend.VmUpdateListener; +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; + +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.compiler.common.Constants; -import com.redhat.thermostat.vm.compiler.common.VmCompilerStatDao; +@Component +@Service(value = Backend.class) public class VmCompilerStatBackend extends VmListenerBackend { - private final VmCompilerStatDao vmCompilerStats; + private final ListenerCreator listenerCreator; + + @Reference + private VmCompilerStatDao vmCompilerStatDao; + + @Reference + private WriterID writerID; - public VmCompilerStatBackend(VmCompilerStatDao vmCompilerStatDao, Version version, - VmStatusListenerRegistrar registrar, WriterID writerId) { - super("VM Compiler Backend", - "Gathers compiler statistics about a JVM", - "Red Hat, Inc.", version.getVersionNumber(), true, registrar, writerId); - this.vmCompilerStats = vmCompilerStatDao; + public VmCompilerStatBackend() { + this(new ListenerCreator()); } - - @Override - protected VmUpdateListener createVmListener(String writerId, String vmId, int pid) { - return new VmCompilerStatVmListener(writerId, vmCompilerStats, vmId); + + VmCompilerStatBackend(ListenerCreator creator) { + super("JVM Compiler Backend", "Gathers compiler statistics about a JVM", "Red Hat, Inc.", true); + this.listenerCreator = creator; + } + + @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 jvmId, int pid) { + return listenerCreator.create(writerId, vmCompilerStatDao, jvmId); + } + + // DS bind method + protected void bindVmCompilersStats(VmCompilerStatDao dao) { + this.vmCompilerStatDao = dao; + } + + // DS bind method + protected void bindWriterId(WriterID id) { + this.writerID = id; + } + + // For testing purposes + static class ListenerCreator { + VmCompilerStatVmListener create(String writerId, VmCompilerStatDao dao, String vmId) { + return new VmCompilerStatVmListener(writerId, dao, vmId); + } + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatDao.java Fri Oct 06 14:14:13 2017 -0400 @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.compiler.agent.internal; + +import com.redhat.thermostat.annotations.Service; +import com.redhat.thermostat.vm.compiler.model.VmCompilerStat; + +@Service +public interface VmCompilerStatDao { + public void put(VmCompilerStat stat); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatDaoImpl.java Fri Oct 06 14:14:13 2017 -0400 @@ -0,0 +1,161 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.compiler.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 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; + +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.compiler.model.VmCompilerStat; +import com.redhat.thermostat.vm.compiler.model.VmCompilerStatTypeAdapter; + +@Component +@Service(value = VmCompilerStatDao.class) +public class VmCompilerStatDaoImpl extends PluginDAOBase<VmCompilerStat> implements VmCompilerStatDao { + + private static final Logger logger = LoggingUtils.getLogger(VmCompilerStatDaoImpl.class); + private static final String PLUGIN_ID = "vm-compiler"; + + 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 VmCompilerStatDaoImpl() { + this(new JsonHelper(new VmCompilerStatTypeAdapter()), new ConfigurationCreator()); + } + + VmCompilerStatDaoImpl(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(VmCompilerStat 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, VmCompilerStat 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 VmCompilerStatTypeAdapter typeAdapter; + + public JsonHelper(VmCompilerStatTypeAdapter typeAdapter) { + this.typeAdapter = typeAdapter; + } + + public String toJson(List<VmCompilerStat> info) throws IOException { + return typeAdapter.toJson(info); + } + } + + // For Testing purposes + static class ConfigurationCreator { + PluginConfiguration create(ConfigurationInfoSource source) { + return new PluginConfiguration(source, PLUGIN_ID); + } + } +}
--- a/plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatVmListener.java Mon Oct 02 15:09:26 2017 +0200 +++ b/plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatVmListener.java Fri Oct 06 14:14:13 2017 -0400 @@ -39,53 +39,52 @@ 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.compiler.common.VmCompilerStat; -import com.redhat.thermostat.vm.compiler.common.VmCompilerStatDao; +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.compiler.model.VmCompilerStat; class VmCompilerStatVmListener implements VmUpdateListener { private static final Logger logger = LoggingUtils.getLogger(VmCompilerStatVmListener.class); private final VmCompilerStatDao dao; - private final String vmId; + private final String jvmId; private final String writerId; private boolean error; VmCompilerStatVmListener(String writerId, VmCompilerStatDao dao, String vmId) { this.dao = dao; - this.vmId = vmId; + this.jvmId = vmId; this.writerId = writerId; } @Override public void countersUpdated(VmUpdate update) { try { - long totalCompiles = longValueOrUnknown(update, "totalCompiles", vmId); - long totalBailouts = longValueOrUnknown(update, "totalBailouts", vmId); - long totalInvalidates = longValueOrUnknown(update, "totalInvalidates", vmId); + long totalCompiles = longValueOrUnknown(update, "totalCompiles", jvmId); + long totalBailouts = longValueOrUnknown(update, "totalBailouts", jvmId); + long totalInvalidates = longValueOrUnknown(update, "totalInvalidates", jvmId); long compilationTime = update.getPerformanceCounterLong("java.ci.totalTime") / update.getPerformanceCounterLong("sun.os.hrt.frequency"); - long lastSize = longValueOrUnknown(update, "lastSize", vmId); - long lastType = longValueOrUnknown(update, "lastType", vmId); + long lastSize = longValueOrUnknown(update, "lastSize", jvmId); + long lastType = longValueOrUnknown(update, "lastType", jvmId); String lastMethod = update.getPerformanceCounterString("sun.ci.lastMethod"); - long lastFailedType = longValueOrUnknown(update, "lastFailedType", vmId); + long lastFailedType = longValueOrUnknown(update, "lastFailedType", jvmId); String lastFailedMethod = update.getPerformanceCounterString("sun.ci.lastFailedMethod"); long timestamp = System.currentTimeMillis(); - VmCompilerStat stat = new VmCompilerStat(writerId, vmId, timestamp, + VmCompilerStat stat = new VmCompilerStat(writerId, jvmId, timestamp, totalCompiles, totalBailouts, totalInvalidates, compilationTime, lastSize, lastType, lastMethod, lastFailedType, lastFailedMethod); - dao.putVmCompilerStat(stat); + dao.put(stat); } catch (VmUpdateException e) { - logger.log(Level.WARNING, "Error gathering class info for VM " + vmId, e); + logger.log(Level.WARNING, "Error gathering class info for VM " + jvmId, e); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/model/VmCompilerStat.java Fri Oct 06 14:14:13 2017 -0400 @@ -0,0 +1,207 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.compiler.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 VmCompilerStat 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 totalCompiles; + private long totalBailouts; + private long totalInvalidates; + + /** + * There's unit no explicitly mentioned for this jstat value anywhere + * that I could find. The closest thing I got was the hotspot + * implementation referring to ComplilationMXBean which mentions the + * return value is in milliseconds. + */ + private long compilationTime; + + private long lastSize; + + /** + * From hotspot code, this is an enum with the values: + * { no_compile, normal_compile, osr_compile, native_compile } + */ + private long lastType; + + /** + * is of the form "name/of/package/Class$InnerClass methodName" + */ + private String lastMethod; + + /** + * From hotspot code, this is an enum with the values: + * { no_compile, normal_compile, osr_compile, native_compile } + */ + private long lastFailedType; + + /** + * is of the form "name/of/package/Class$InnerClass methodName" + */ + private String lastFailedMethod; + + public VmCompilerStat(String writerId, String vmId, long timestamp, long totalCompiles, long totalBailouts, + long totalInvalidates, long compilationTime, long lastSize, long lastType, String lastMethod, + long lastFailedType, String lastFailedMethod) { + super(writerId); + this.jvmId = vmId; + this.timestamp = timestamp; + this.totalCompiles = totalCompiles; + this.totalBailouts = totalBailouts; + this.totalInvalidates = totalInvalidates; + this.compilationTime = compilationTime; + this.lastSize = lastSize; + this.lastType = lastType; + this.lastMethod = lastMethod; + this.lastFailedType = lastFailedType; + this.lastFailedMethod = lastFailedMethod; + } + + 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 compilation tasks performed */ + public long getTotalCompiles() { + return totalCompiles; + } + + public void setTotalCompiles(long totalCompiles) { + this.totalCompiles = totalCompiles; + } + + /** Number of failed compilation tasks */ + public long getTotalBailouts() { + return totalBailouts; + } + + public void setTotalBailouts(long totalBailouts) { + this.totalBailouts = totalBailouts; + } + + /** Number of invalidated compilation tasks */ + public long getTotalInvalidates() { + return totalInvalidates; + } + + public void setTotalInvalidates(long totalInvalidates) { + this.totalInvalidates = totalInvalidates; + } + + /** Time spent in compilation. Cumulative, measured in ms */ + public long getCompilationTime() { + return compilationTime; + } + + /** Time spent in compilation. Cumulative, measured in ms */ + public void setCompilationTime(long compilationTime) { + this.compilationTime = compilationTime; + } + + /** Code Size in bytes of last compilation */ + public long getLastSize() { + return lastSize; + } + + public void setLastSize(long lastSize) { + this.lastSize = lastSize; + } + + /** Type of last compilation */ + public long getLastType() { + return lastType; + } + + public void setLastType(long lastType) { + this.lastType = lastType; + } + + /** Name of class and method for last compile */ + public String getLastMethod() { + return lastMethod; + } + + public void setLastMethod(String lastMethod) { + this.lastMethod = lastMethod; + } + + /** Type of last failed compilation */ + public long getLastFailedType() { + return lastFailedType; + } + + public void setLastFailedType(long lastFailedType) { + this.lastFailedType = lastFailedType; + } + + /** Name of class and method for last failed compile */ + public String getLastFailedMethod() { + return lastFailedMethod; + } + + public void setLastFailedMethod(String lastFailedMethod) { + this.lastFailedMethod = lastFailedMethod; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/model/VmCompilerStatTypeAdapter.java Fri Oct 06 14:14:13 2017 -0400 @@ -0,0 +1,114 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.compiler.model; + +import java.io.IOException; +import java.util.List; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +public class VmCompilerStatTypeAdapter extends TypeAdapter<List<VmCompilerStat>> { + + private static final String TYPE_LONG = "$numberLong"; + private static final String AGENT_ID = "agentId"; + private static final String JVM_ID = "jvmId"; + private static final String TIMESTAMP = "timeStamp"; + private static final String TOTAL_COMPILES = "totalCompiles"; + private static final String TOTAL_BAILOUTS = "totalBailouts"; + private static final String TOTAL_INVALIDATES = "totalInvalidates"; + private static final String COMPILATION_TIME = "compilationTime"; + private static final String LAST_SIZE = "lastSize"; + private static final String LAST_TYPE = "lastType"; + private static final String LAST_METHOD = "lastMethod"; + private static final String LAST_FAILED_TYPE = "lastFailedType"; + private static final String LAST_FAILED_METHOD = "lastFailedMethod"; + + + @Override + public List<VmCompilerStat> read(JsonReader in) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public void write(JsonWriter out, List<VmCompilerStat> stats) throws IOException { + out.beginArray(); + for (VmCompilerStat stat : stats) { + writeCompilerStat(out, stat); + } + out.endArray(); + } + + public void writeCompilerStat(JsonWriter out, VmCompilerStat stat) throws IOException { + out.beginObject(); + out.name(AGENT_ID); + out.value(stat.getAgentId()); + out.name(JVM_ID); + out.value(stat.getJvmId()); + out.name(TIMESTAMP); + writeLong(out, stat.getTimeStamp()); + out.name(TOTAL_COMPILES); + writeLong(out, stat.getTotalCompiles()); + out.name(TOTAL_BAILOUTS); + writeLong(out, stat.getTotalBailouts()); + out.name(TOTAL_INVALIDATES); + writeLong(out, stat.getTotalInvalidates()); + out.name(COMPILATION_TIME); + writeLong(out, stat.getCompilationTime()); + out.name(LAST_SIZE); + writeLong(out, stat.getLastSize()); + out.name(LAST_TYPE); + writeLong(out, stat.getLastType()); + out.name(LAST_METHOD); + out.value(stat.getLastMethod()); + out.name(LAST_FAILED_TYPE); + writeLong(out, stat.getLastFailedType()); + out.name(LAST_FAILED_METHOD); + out.value(stat.getLastFailedMethod()); + out.endObject(); + } + + + private void writeLong(JsonWriter out, long value) throws IOException { + // Write MongoDB representation of a Long + out.beginObject(); + out.name(TYPE_LONG); + out.value(String.valueOf(value)); + out.endObject(); + } +}
--- a/plugins/vm-compiler/agent/src/test/java/com/redhat/thermostat/vm/compiler/agent/internal/ActivatorTest.java Mon Oct 02 15:09:26 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,112 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.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.compiler.agent.internal.Activator; -import com.redhat.thermostat.vm.compiler.agent.internal.VmCompilerStatBackend; -import com.redhat.thermostat.vm.compiler.common.VmCompilerStatDao; - -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); - VmCompilerStatDao vmCompilerStatDao = mock(VmCompilerStatDao.class); - WriterID idService = mock(WriterID.class); - - context.registerService(BackendService.class, service, null); - context.registerService(VmCompilerStatDao.class, vmCompilerStatDao, null); - context.registerService(WriterID.class, idService, null); - - Activator activator = new Activator(); - - activator.start(context); - - assertTrue(context.isServiceRegistered(Backend.class.getName(), VmCompilerStatBackend.class)); - VmCompilerStatBackend 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()); - } - -} -
--- a/plugins/vm-compiler/agent/src/test/java/com/redhat/thermostat/vm/compiler/agent/internal/VmClassStatBackendTest.java Mon Oct 02 15:09:26 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.agent.internal; - -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import org.junit.Before; -import org.junit.Test; - -import com.redhat.thermostat.agent.VmStatusListenerRegistrar; -import com.redhat.thermostat.common.Version; -import com.redhat.thermostat.storage.core.WriterID; -import com.redhat.thermostat.vm.compiler.common.VmCompilerStatDao; - -public class VmClassStatBackendTest { - - private VmCompilerStatBackend backend; - - @Before - public void setup() { - VmCompilerStatDao vmCompilerStatDao = mock(VmCompilerStatDao.class); - - Version version = mock(Version.class); - when(version.getVersionNumber()).thenReturn("0.0.0"); - - VmStatusListenerRegistrar registrar = mock(VmStatusListenerRegistrar.class); - - WriterID id = mock(WriterID.class); - backend = new VmCompilerStatBackend(vmCompilerStatDao, version, registrar, id); - } - -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-compiler/agent/src/test/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatBackendTest.java Fri Oct 06 14:14:13 2017 -0400 @@ -0,0 +1,139 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.compiler.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 static org.mockito.Mockito.verify; + +import com.redhat.thermostat.jvm.overview.agent.VmStatusListenerRegistrar; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Version; + +import com.redhat.thermostat.storage.core.WriterID; + +public class VmCompilerStatBackendTest { + + private TestVmCompilerBackend backend; + private VmCompilerStatBackend.ListenerCreator listenerCreator; + + @Before + public void setup() { + listenerCreator = mock(VmCompilerStatBackend.ListenerCreator.class); + backend = new TestVmCompilerBackend(listenerCreator); + } + + @Test + public void testComponentActivated() { + BundleContext context = mock(BundleContext.class); + Bundle bundle = mock(Bundle.class); + Version version = new Version(1, 2, 3); + when(bundle.getVersion()).thenReturn(version); + when(context.getBundle()).thenReturn(bundle); + + WriterID id = mock(WriterID.class); + 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; + + VmCompilerStatDao dao = mock(VmCompilerStatDao.class); + backend.bindVmCompilersStats(dao); + backend.createVmListener(writerId, jvmId, pid); + + verify(listenerCreator).create(writerId, dao, jvmId); + } + + static class TestVmCompilerBackend extends VmCompilerStatBackend { + WriterID writerId; + VmStatusListenerRegistrar registrar; + String version; + boolean active; + + TestVmCompilerBackend(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; + } + } + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-compiler/agent/src/test/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatDaoImplTest.java Fri Oct 06 14:14:13 2017 -0400 @@ -0,0 +1,130 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.compiler.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 org.junit.Before; +import org.junit.Test; + +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.compiler.model.VmCompilerStat; + +public class VmCompilerStatDaoImplTest { + + private static final String WRITER_ID = "writerId"; + private static final String VM_ID = "1234"; + private static final long TIMESTAMP = 123455667L; + private static final long TOTAL_COMPILES = 12L; + private static final long TOTAL_BAILOUTS = 13L; + private static final long TOTAL_INVALIDATES = 1L; + private static final long COMPILATION_TIME = 2132131L; + private static final long LAST_SIZE = 231L; + private static final long LAST_TYPE = 123L; + private static final String LAST_METHOD = "fakeMethod"; + private static final long LAST_FAILED_TYPE = 123L; + private static final String LAST_FAILED_METHOD = "failedMethod"; + private static final String SOME_SYSTEM_ID = "somesystemid"; + private static final String SOME_VM_ID = "1234"; + 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-compiler/"); + } + + private VmCompilerStat compilerStat; + private VmCompilerStatDaoImpl.JsonHelper jsonHelper; + private VmCompilerStatDaoImpl dao; + private HttpRequestService httpRequestService; + + @Before + public void setUp() throws IOException { + this.compilerStat = new VmCompilerStat(WRITER_ID, + VM_ID, + TIMESTAMP, + TOTAL_COMPILES, + TOTAL_BAILOUTS, + TOTAL_INVALIDATES, + COMPILATION_TIME, + LAST_SIZE, + LAST_TYPE, + LAST_METHOD, + LAST_FAILED_TYPE, + LAST_FAILED_METHOD + ); + + jsonHelper = mock(VmCompilerStatDaoImpl.JsonHelper.class); + when(jsonHelper.toJson(anyListOf(VmCompilerStat.class))).thenReturn(JSON); + + ConfigurationInfoSource source = mock(ConfigurationInfoSource.class); + PluginConfiguration config = mock(PluginConfiguration.class); + when(config.getGatewayURL()).thenReturn(GATEWAY_URI); + VmCompilerStatDaoImpl.ConfigurationCreator creator = mock(VmCompilerStatDaoImpl.ConfigurationCreator.class); + when(creator.create(source)).thenReturn(config); + + httpRequestService = mock(HttpRequestService.class); + dao = new VmCompilerStatDaoImpl(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(compilerStat); + + verify(jsonHelper).toJson(eq(Arrays.asList(compilerStat))); + String s = verify(httpRequestService).sendHttpRequest(JSON, GATEWAY_URI.resolve("systems/" + SOME_SYSTEM_ID + "/jvms/" + SOME_VM_ID), HttpRequestService.Method.POST); + } +}
--- a/plugins/vm-compiler/agent/src/test/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatVmListenerTest.java Mon Oct 02 15:09:26 2017 +0200 +++ b/plugins/vm-compiler/agent/src/test/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatVmListenerTest.java Fri Oct 06 14:14:13 2017 -0400 @@ -47,11 +47,9 @@ 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.compiler.agent.internal.VmCompilerStatVmListener; -import com.redhat.thermostat.vm.compiler.common.VmCompilerStat; -import com.redhat.thermostat.vm.compiler.common.VmCompilerStatDao; +import com.redhat.thermostat.jvm.overview.agent.VmUpdate; +import com.redhat.thermostat.jvm.overview.agent.VmUpdateException; +import com.redhat.thermostat.vm.compiler.model.VmCompilerStat; public class VmCompilerStatVmListenerTest { @@ -81,10 +79,10 @@ listener.countersUpdated(update); ArgumentCaptor<VmCompilerStat> arg = ArgumentCaptor.forClass(VmCompilerStat.class); - verify(dao).putVmCompilerStat(arg.capture()); + verify(dao).put(arg.capture()); VmCompilerStat stat = arg.getValue(); assertEquals(COMPILATION_TIME, (Long) stat.getCompilationTime()); - assertEquals(VM_ID, stat.getVmId()); + assertEquals(VM_ID, stat.getJvmId()); } @Test
--- a/plugins/vm-compiler/common/pom.xml Mon Oct 02 15:09:26 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,133 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Copyright 2012-2017 Red Hat, Inc. - - This file is part of Thermostat. - - Thermostat is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 2, or (at your - option) any later version. - - Thermostat is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Thermostat; see the file COPYING. If not see - <http://www.gnu.org/licenses/>. - - Linking this code with other modules is making a combined work - based on this code. Thus, the terms and conditions of the GNU - General Public License cover the whole combination. - - As a special exception, the copyright holders of this code give - you permission to link this code with independent modules to - produce an executable, regardless of the license terms of these - independent modules, and to copy and distribute the resulting - executable under terms of your choice, provided that you also - meet, for each linked independent module, the terms and conditions - of the license of that module. An independent module is a module - which is not derived from or based on this code. If you modify - this code, you may extend this exception to your version of the - library, but you are not obligated to do so. If you do not wish - to do so, delete this exception statement from your version. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <artifactId>thermostat-vm-compiler</artifactId> - <groupId>com.redhat.thermostat.agent</groupId> - <version>2.99.0-SNAPSHOT</version> - </parent> - <artifactId>thermostat-vm-compiler-common</artifactId> - <packaging>bundle</packaging> - <name>Thermostat VM Compiler Common plugin</name> - <build> - <resources> - <resource> - <directory>src/main/resources</directory> - <filtering>true</filtering> - <excludes> - <exclude>**/*.png</exclude> - </excludes> - </resource> - <resource> - <directory>src/main/resources</directory> - <filtering>false</filtering> - <includes> - <include>**/*.png</include> - </includes> - </resource> - </resources> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> - <Bundle-SymbolicName>com.redhat.thermostat.vm.compiler.common</Bundle-SymbolicName> - <Bundle-Activator>com.redhat.thermostat.vm.compiler.common.internal.Activator</Bundle-Activator> - <Export-Package> - com.redhat.thermostat.vm.compiler.common, - com.redhat.thermostat.vm.compiler.common.model - </Export-Package> - <Private-Package> - com.redhat.thermostat.vm.compiler.common.internal - </Private-Package> - <!-- Do not autogenerate uses clauses in Manifests --> - <_nouses>true</_nouses> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>com.redhat.thermostat.agent</groupId> - <artifactId>thermostat-common-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.redhat.thermostat.agent</groupId> - <artifactId>thermostat-storage-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.redhat.thermostat.agent</groupId> - <artifactId>thermostat-common-test</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.google.code.gson</groupId> - <artifactId>gson</artifactId> - <version>${gson.version}</version> - </dependency> - </dependencies> -</project>
--- a/plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/ParsedVmCompilerStat.java Mon Oct 02 15:09:26 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.common; - -import java.util.concurrent.TimeUnit; - -import com.redhat.thermostat.common.Duration; -import com.redhat.thermostat.common.Size; - -public class ParsedVmCompilerStat { - - public static enum CompileType { - NO_COMPILE, - NORMAL_COMPILE, - OSR_COMPILE, - NATIVE_COMPILE,; - } - - private final VmCompilerStat original; - - public ParsedVmCompilerStat(VmCompilerStat stat) { - this.original = stat; - } - - public long getTotalCompiles() { - return original.getTotalCompiles(); - } - - public long getTotalInvalidates() { - return original.getTotalInvalidates(); - } - - public long getTotalBailouts() { - return original.getTotalBailouts(); - } - - public Duration getCompilationTime() { - return new Duration(original.getCompilationTime(), TimeUnit.MILLISECONDS); - } - - public CompileType getLastType() { - return getCompileType(original.getLastType()); - } - - public Size getLastSize() { - return Size.bytes(original.getLastSize()); - } - - public String getLastMethod() { - return toStandardMethodName(original.getLastMethod()); - } - - public CompileType getLastFailedType() { - return getCompileType(original.getLastFailedType()); - } - - public String getLastFailedMethod() { - return toStandardMethodName(original.getLastFailedMethod()); - } - - private CompileType getCompileType(long typeValue) { - if (typeValue < 0 || typeValue >= CompileType.values().length) { - throw new IllegalArgumentException("Unexpected compile-type code: " + typeValue); - } - return CompileType.values()[(int) typeValue]; - } - - private String toStandardMethodName(String encodedMethodName) { - if (encodedMethodName == null || encodedMethodName.trim().isEmpty()) { - return "<none>"; - } - String[] parts = encodedMethodName.split(" "); - String className = parts[0].replace('/', '.'); - String methodName = parts[1]; - return className + "." + methodName + "(...)"; - - } - -}
--- a/plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/VmCompilerStat.java Mon Oct 02 15:09:26 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,240 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.common; - -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 VmCompilerStat 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 totalCompiles; - private long totalBailouts; - private long totalInvalidates; - - /** - * There's unit no explicitly mentioned for this jstat value anywhere - * that I could find. The closest thing I got was the hotspot - * implementation referring to ComplilationMXBean which mentions the - * return value is in milliseconds. - */ - private long compilationTime; - - private long lastSize; - - /** - * From hotspot code, this is an enum with the values: - * { no_compile, normal_compile, osr_compile, native_compile } - */ - private long lastType; - - /** - * is of the form "name/of/package/Class$InnerClass methodName" - */ - private String lastMethod; - - /** - * From hotspot code, this is an enum with the values: - * { no_compile, normal_compile, osr_compile, native_compile } - */ - private long lastFailedType; - - /** - * is of the form "name/of/package/Class$InnerClass methodName" - */ - private String lastFailedMethod; - - public VmCompilerStat() { - this(null, null, UNKNOWN, - UNKNOWN, UNKNOWN, UNKNOWN, - UNKNOWN, - UNKNOWN, UNKNOWN, null, - UNKNOWN, null); - } - - public VmCompilerStat(String writerId, String vmId, long timestamp, - long totalCompiles, long totalBailouts, long totalInvalidates, - long compilationTime, - long lastSize, long lastType, String lastMethod, - long lastFailedType, String lastFailedMethod) { - super(writerId); - this.vmId = vmId; - this.timestamp = timestamp; - this.totalCompiles = totalCompiles; - this.totalBailouts = totalBailouts; - this.totalInvalidates = totalInvalidates; - this.compilationTime = compilationTime; - this.lastSize = lastSize; - this.lastType = lastType; - this.lastMethod = lastMethod; - this.lastFailedType = lastFailedType; - this.lastFailedMethod = lastFailedMethod; - } - - @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 compilation tasks performed */ - @Persist - public long getTotalCompiles() { - return totalCompiles; - } - - @Persist - public void setTotalCompiles(long totalCompiles) { - this.totalCompiles = totalCompiles; - } - - /** Number of failed compilation tasks */ - @Persist - public long getTotalBailouts() { - return totalBailouts; - } - - @Persist - public void setTotalBailouts(long totalBailouts) { - this.totalBailouts = totalBailouts; - } - - /** Number of invalidated compilation tasks */ - @Persist - public long getTotalInvalidates() { - return totalInvalidates; - } - - @Persist - public void setTotalInvalidates(long totalInvalidates) { - this.totalInvalidates = totalInvalidates; - } - - /** Time spent in compilation. Cumulative, measured in ms */ - @Persist - public long getCompilationTime() { - return compilationTime; - } - - /** Time spent in compilation. Cumulative, measured in ms */ - @Persist - public void setCompilationTime(long compilationTime) { - this.compilationTime = compilationTime; - } - - /** Code Size in bytes of last compilation */ - @Persist - public long getLastSize() { - return lastSize; - } - - @Persist - public void setLastSize(long lastSize) { - this.lastSize = lastSize; - } - - /** Type of last compilation */ - @Persist - public long getLastType() { - return lastType; - } - - @Persist - public void setLastType(long lastType) { - this.lastType = lastType; - } - - /** Name of class and method for last compile */ - @Persist - public String getLastMethod() { - return lastMethod; - } - - @Persist - public void setLastMethod(String lastMethod) { - this.lastMethod = lastMethod; - } - - /** Type of last failed compilation */ - @Persist - public long getLastFailedType() { - return lastFailedType; - } - - @Persist - public void setLastFailedType(long lastFailedType) { - this.lastFailedType = lastFailedType; - } - - /** Name of class and method for last failed compile */ - @Persist - public String getLastFailedMethod() { - return lastFailedMethod; - } - - @Persist - public void setLastFailedMethod(String lastFailedMethod) { - this.lastFailedMethod = lastFailedMethod; - } - -}
--- a/plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/VmCompilerStatDao.java Mon Oct 02 15:09:26 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.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; - -@Service -public interface VmCompilerStatDao { - - static final Key<Long> totalCompilesKey = new Key<>("totalCompiles"); - static final Key<Long> totalBailoutsKey = new Key<>("totalBailouts"); - static final Key<Long> totalInvalidatesKey = new Key<>("totalInvalidates"); - static final Key<Long> compilationTimeKey = new Key<>("compilationTime"); - static final Key<Long> lastSizeKey = new Key<>("lastSize"); - static final Key<Long> lastTypeKey = new Key<>("lastType"); - static final Key<String> lastMethodKey = new Key<>("lastMethod"); - static final Key<Long> lastFailedTypeKey = new Key<>("lastFailedType"); - static final Key<String> lastFailedMethodKey = new Key<>("lastFailedMethod"); - - - static final Category<VmCompilerStat> vmCompilerStatsCategory = new Category<>( - "vm-compiler-stats", VmCompilerStat.class, - Arrays.<Key<?>>asList( - Key.AGENT_ID, Key.VM_ID, Key.TIMESTAMP, - totalCompilesKey, totalBailoutsKey, totalInvalidatesKey, - compilationTimeKey, - lastSizeKey, lastTypeKey, lastMethodKey, - lastFailedTypeKey, lastFailedMethodKey), - Arrays.<Key<?>>asList(Key.TIMESTAMP)); - - public List<VmCompilerStat> getLatestCompilerStats(VmRef ref, long since); - - public List<VmCompilerStat> getCompilerStats(VmRef ref, long since, long to); - - public void putVmCompilerStat(VmCompilerStat stat); - - public abstract VmCompilerStat getOldest(VmRef ref); - - public abstract VmCompilerStat getNewest(VmRef ref); - -} -
--- a/plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/internal/Activator.java Mon Oct 02 15:09:26 2017 +0200 +++ /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 - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.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.compiler.common.VmCompilerStatDao; - -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); - VmCompilerStatDao vmCompilerStatDao = new VmCompilerStatDaoImpl(storage); - reg = context.registerService(VmCompilerStatDao.class.getName(), vmCompilerStatDao, 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(); - } - -} -
--- a/plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatCategoryRegistration.java Mon Oct 02 15:09:26 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.common.internal; - -import java.util.HashSet; -import java.util.Set; - -import com.redhat.thermostat.storage.core.auth.CategoryRegistration; -import com.redhat.thermostat.vm.compiler.common.VmCompilerStatDao; - -/** - * 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 VmCompilerStatCategoryRegistration implements CategoryRegistration { - - @Override - public Set<String> getCategoryNames() { - Set<String> categories = new HashSet<>(1); - categories.add(VmCompilerStatDao.vmCompilerStatsCategory.getName()); - return categories; - } - -} -
--- a/plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatDaoImpl.java Mon Oct 02 15:09:26 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,133 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.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.compiler.common.VmCompilerStat; -import com.redhat.thermostat.vm.compiler.common.VmCompilerStatDao; - -class VmCompilerStatDaoImpl extends AbstractDao implements VmCompilerStatDao { - - private static final Logger logger = LoggingUtils.getLogger(VmCompilerStatDaoImpl.class); - - static final String DESC_ADD_VM_COMPILER_STAT = "ADD " + vmCompilerStatsCategory.getName() + - " SET '" + Key.AGENT_ID.getName() + "' = ?s , " + - "'" + Key.VM_ID.getName() + "' = ?s , " + - "'" + Key.TIMESTAMP.getName() + "' = ?l , " + - "'" + totalCompilesKey.getName() + "' = ?l , " + - "'" + totalBailoutsKey.getName() + "' = ?l , " + - "'" + totalInvalidatesKey.getName() + "' = ?l , " + - "'" + compilationTimeKey.getName() + "' = ?l , " + - "'" + lastSizeKey.getName() + "' = ?l , " + - "'" + lastTypeKey.getName() + "' = ?l , " + - "'" + lastMethodKey.getName() + "' = ?s , " + - "'" + lastFailedTypeKey.getName() + "' = ?l , " + - "'" + lastFailedMethodKey.getName() + "' = ?s"; - - private final Storage storage; - private final VmLatestPojoListGetter<VmCompilerStat> latestGetter; - private final VmTimeIntervalPojoListGetter<VmCompilerStat> intervalGetter; - private final VmBoundaryPojoGetter<VmCompilerStat> boundaryGetter; - - VmCompilerStatDaoImpl(Storage storage) { - this.storage = storage; - storage.registerCategory(vmCompilerStatsCategory); - this.latestGetter = new VmLatestPojoListGetter<>(storage, vmCompilerStatsCategory); - this.intervalGetter = new VmTimeIntervalPojoListGetter<>(storage, vmCompilerStatsCategory); - this.boundaryGetter = new VmBoundaryPojoGetter<>(storage, vmCompilerStatsCategory); - } - - @Override - public List<VmCompilerStat> getLatestCompilerStats(VmRef ref, long lastUpdateTime) { - return latestGetter.getLatest(ref, lastUpdateTime); - } - - @Override - public List<VmCompilerStat> getCompilerStats(VmRef ref, long since, long to) { - return intervalGetter.getLatest(ref, since, to); - } - - @Override - public void putVmCompilerStat(final VmCompilerStat stat) { - executeStatement(new AbstractDaoStatement<VmCompilerStat>(storage, vmCompilerStatsCategory, DESC_ADD_VM_COMPILER_STAT) { - @Override - public PreparedStatement<VmCompilerStat> customize(PreparedStatement<VmCompilerStat> preparedStatement) { - preparedStatement.setString(0, stat.getAgentId()); - preparedStatement.setString(1, stat.getVmId()); - preparedStatement.setLong(2, stat.getTimeStamp()); - preparedStatement.setLong(3, stat.getTotalCompiles()); - preparedStatement.setLong(4, stat.getTotalBailouts()); - preparedStatement.setLong(5, stat.getTotalInvalidates()); - preparedStatement.setLong(6, stat.getCompilationTime()); - preparedStatement.setLong(7, stat.getLastSize()); - preparedStatement.setLong(8, stat.getLastType()); - preparedStatement.setString(9, stat.getLastMethod()); - preparedStatement.setLong(10, stat.getLastFailedType()); - preparedStatement.setString(11, stat.getLastFailedMethod()); - return preparedStatement; - } - }); - } - - @Override - public VmCompilerStat getOldest(final VmRef ref) { - return boundaryGetter.getOldestStat(ref); - } - - @Override - public VmCompilerStat getNewest(final VmRef ref) { - return boundaryGetter.getNewestStat(ref); - } - - @Override - protected Logger getLogger() { - return logger; - } -} -
--- a/plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatDaoImplStatementDescriptorRegistration.java Mon Oct 02 15:09:26 2017 +0200 +++ /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 - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.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.compiler.common.VmCompilerStatDao; - -/** - * Registers the prepared query issued by this maven module via - * {@link VmLatestPojoListGetter}. - * - */ -public class VmCompilerStatDaoImplStatementDescriptorRegistration implements - StatementDescriptorRegistration { - - static final String LATEST = String.format(VmLatestPojoListGetter.VM_LATEST_QUERY_FORMAT, - VmCompilerStatDao.vmCompilerStatsCategory.getName()); - static final String RANGE = String.format(VmTimeIntervalPojoListGetter.VM_INTERVAL_QUERY_FORMAT, - VmCompilerStatDao.vmCompilerStatsCategory.getName()); - static final String LATEST_STAT = String.format(VmBoundaryPojoGetter.DESC_NEWEST_VM_STAT, - VmCompilerStatDao.vmCompilerStatsCategory.getName()); - static final String OLDEST_STAT = String.format(VmBoundaryPojoGetter.DESC_OLDEST_VM_STAT, - VmCompilerStatDao.vmCompilerStatsCategory.getName()); - - @Override - public Set<String> getStatementDescriptors() { - Set<String> descs = new HashSet<>(1); - descs.add(LATEST); - descs.add(RANGE); - descs.add(LATEST_STAT); - descs.add(OLDEST_STAT); - descs.add(VmCompilerStatDaoImpl.DESC_ADD_VM_COMPILER_STAT); - return descs; - } - -} -
--- a/plugins/vm-compiler/common/src/main/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatTypeAdapter.java Mon Oct 02 15:09:26 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.common.internal; - -import com.google.gson.TypeAdapter; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import com.redhat.thermostat.vm.compiler.common.VmCompilerStat; - -import java.io.IOException; - -public class VmCompilerStatTypeAdapter extends TypeAdapter<VmCompilerStat> { - - private static final String TYPE_LONG = "$numberLong"; - private static final String AGENT_ID = "agentId"; - private static final String VM_ID = "vmId"; - private static final String TIMESTAMP = "timeStamp"; - private static final String TOTAL_COMPILES = "totalCompiles"; - private static final String TOTAL_BAILOUTS = "totalBailouts"; - private static final String TOTAL_INVALIDATES = "totalInvalidates"; - private static final String COMPILATION_TIME = "compilationTime"; - private static final String LAST_SIZE = "lastSize"; - private static final String LAST_TYPE = "lastType"; - private static final String LAST_METHOD = "lastMethod"; - private static final String LAST_FAILED_TYPE = "lastFailedType"; - private static final String LAST_FAILED_METHOD = "lastFailedMethod"; - - - @Override - public VmCompilerStat read(JsonReader in) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public void write(JsonWriter out, VmCompilerStat stat) throws IOException { - out.beginObject(); - out.name(AGENT_ID); - out.value(stat.getAgentId()); - out.name(VM_ID); - out.value(stat.getVmId()); - out.name(TIMESTAMP); - writeLong(out, stat.getTimeStamp()); - out.name(TOTAL_COMPILES); - writeLong(out, stat.getTotalCompiles()); - out.name(TOTAL_BAILOUTS); - writeLong(out, stat.getTotalBailouts()); - out.name(TOTAL_INVALIDATES); - writeLong(out, stat.getTotalInvalidates()); - out.name(COMPILATION_TIME); - writeLong(out, stat.getCompilationTime()); - out.name(LAST_SIZE); - writeLong(out, stat.getLastSize()); - out.name(LAST_TYPE); - writeLong(out, stat.getLastType()); - out.name(LAST_METHOD); - out.value(stat.getLastMethod()); - out.name(LAST_FAILED_TYPE); - writeLong(out, stat.getLastFailedType()); - out.name(LAST_FAILED_METHOD); - out.value(stat.getLastFailedMethod()); - out.endObject(); - } - - private void writeLong(JsonWriter out, long value) throws IOException { - // Write MongoDB representation of a Long - out.beginObject(); - out.name(TYPE_LONG); - out.value(String.valueOf(value)); - out.endObject(); - } -}
--- a/plugins/vm-compiler/common/src/main/resources/META-INF/services/com.redhat.thermostat.storage.core.auth.CategoryRegistration Mon Oct 02 15:09:26 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -com.redhat.thermostat.vm.compiler.common.internal.VmCompilerStatCategoryRegistration -
--- a/plugins/vm-compiler/common/src/main/resources/META-INF/services/com.redhat.thermostat.storage.core.auth.StatementDescriptorRegistration Mon Oct 02 15:09:26 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -com.redhat.thermostat.vm.compiler.common.internal.VmCompilerStatDaoImplStatementDescriptorRegistration -
--- a/plugins/vm-compiler/common/src/test/java/com/redhat/thermostat/vm/compiler/common/VmCompilerStatTest.java Mon Oct 02 15:09:26 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.common; - -import com.redhat.thermostat.testutils.DataObjectTest; - -public class VmCompilerStatTest extends DataObjectTest { - - @Override - public Class<?>[] getDataClasses() { - return new Class[] { VmCompilerStat.class }; - } - -} -
--- a/plugins/vm-compiler/common/src/test/java/com/redhat/thermostat/vm/compiler/common/internal/ActivatorTest.java Mon Oct 02 15:09:26 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.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.compiler.common.VmCompilerStatDao; -import com.redhat.thermostat.vm.compiler.common.internal.Activator; -import com.redhat.thermostat.vm.compiler.common.internal.VmCompilerStatDaoImpl; - -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(VmCompilerStatDao.class.getName(), VmCompilerStatDaoImpl.class)); - - activator.stop(context); - - assertEquals(0, context.getServiceListeners().size()); - assertEquals(1, context.getAllServices().size()); - } - -} -
--- a/plugins/vm-compiler/common/src/test/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatCategoryRegistrationTest.java Mon Oct 02 15:09:26 2017 +0200 +++ /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 - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.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.compiler.common.VmCompilerStatDao; - -public class VmCompilerStatCategoryRegistrationTest extends ServiceLoaderTest<CategoryRegistration> { - - public VmCompilerStatCategoryRegistrationTest() { - super(CategoryRegistration.class, STORAGE_SERVICES, VmCompilerStatCategoryRegistration.class); - } - - @Test - public void registersAllCategories() { - VmCompilerStatCategoryRegistration reg = new VmCompilerStatCategoryRegistration(); - Set<String> categories = reg.getCategoryNames(); - assertEquals(1, categories.size()); - assertFalse("null descriptor not allowed", categories.contains(null)); - assertTrue(categories.contains(VmCompilerStatDao.vmCompilerStatsCategory.getName())); - } - -} -
--- a/plugins/vm-compiler/common/src/test/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatDaoImplStatementDescriptorRegistrationTest.java Mon Oct 02 15:09:26 2017 +0200 +++ /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 - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.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 VmCompilerStatDaoImplStatementDescriptorRegistrationTest extends ServiceLoaderTest<StatementDescriptorRegistration> { - - public VmCompilerStatDaoImplStatementDescriptorRegistrationTest() { - super(StatementDescriptorRegistration.class, STORAGE_SERVICES, VmCompilerStatDaoImplStatementDescriptorRegistration.class); - } - - @Test - public void registersAllDescriptors() { - VmCompilerStatDaoImplStatementDescriptorRegistration reg = new VmCompilerStatDaoImplStatementDescriptorRegistration(); - Set<String> descriptors = reg.getStatementDescriptors(); - assertEquals(5, descriptors.size()); - assertFalse("null descriptor not allowed", descriptors.contains(null)); - } - -} -
--- a/plugins/vm-compiler/common/src/test/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatDaoImplTest.java Mon Oct 02 15:09:26 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,214 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.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.compiler.common.VmCompilerStat; -import com.redhat.thermostat.vm.compiler.common.VmCompilerStatDao; -import com.redhat.thermostat.vm.compiler.common.internal.VmCompilerStatDaoImpl; - -public class VmCompilerStatDaoImplTest { - - private static final Long TIMESTAMP = 1234L; - private static final String VM_ID = "vmId"; - private static final Long TOTAL_COMPILES = 12345L; - private static final Long TOTAL_BAILOUTS= 2345L; - private static final Long TOTAL_INVALIDATES = 3456L; - private static final Long COMPILATION_TIME = 4567L; - private static final Long LAST_SIZE = 5678L; - private static final Long LAST_TYPE = 6789L; - private static final String LAST_METHOD = "lastMethod()"; - private static final Long LAST_FAILED_TYPE = 789L; - private static final String LAST_FAILED_METHOD = "lastFailedMethod()"; - - @Test - public void testStatementDescriptorsAreSane() { - String addVmCompilerStat = "ADD vm-compiler-stats SET 'agentId' = ?s , " + - "'vmId' = ?s , " + - "'timeStamp' = ?l , " + - "'totalCompiles' = ?l , " + - "'totalBailouts' = ?l , " + - "'totalInvalidates' = ?l , " + - "'compilationTime' = ?l , " + - "'lastSize' = ?l , " + - "'lastType' = ?l , " + - "'lastMethod' = ?s , " + - "'lastFailedType' = ?l , " + - "'lastFailedMethod' = ?s"; - - assertEquals(addVmCompilerStat, VmCompilerStatDaoImpl.DESC_ADD_VM_COMPILER_STAT); - } - - @Test - public void testCategory() { - assertEquals("vm-compiler-stats", VmCompilerStatDao.vmCompilerStatsCategory.getName()); - Collection<Key<?>> keys = VmCompilerStatDao.vmCompilerStatsCategory.getKeys(); - assertTrue(keys.contains(new Key<>("agentId"))); - assertTrue(keys.contains(new Key<Integer>("vmId"))); - assertTrue(keys.contains(new Key<Long>("timeStamp"))); - assertTrue(keys.contains(new Key<Long>("totalCompiles"))); - assertTrue(keys.contains(new Key<Long>("totalBailouts"))); - assertTrue(keys.contains(new Key<Long>("totalInvalidates"))); - assertTrue(keys.contains(new Key<Long>("compilationTime"))); - assertTrue(keys.contains(new Key<Long>("lastSize"))); - assertTrue(keys.contains(new Key<Long>("lastType"))); - assertTrue(keys.contains(new Key<Long>("lastMethod"))); - assertTrue(keys.contains(new Key<Long>("lastFailedType"))); - assertTrue(keys.contains(new Key<Long>("lastFailedMethod"))); - assertEquals(12, keys.size()); - } - - @Test - public void testGetLatestCompilerStatsBasic() throws DescriptorParsingException, StatementExecutionException { - - VmCompilerStat vmCompilerStat = getCompilerStat(); - - @SuppressWarnings("unchecked") - Cursor<VmCompilerStat> cursor = mock(Cursor.class); - when(cursor.hasNext()).thenReturn(true).thenReturn(false); - when(cursor.next()).thenReturn(vmCompilerStat); - - Storage storage = mock(Storage.class); - @SuppressWarnings("unchecked") - PreparedStatement<VmCompilerStat> stmt = (PreparedStatement<VmCompilerStat>) 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); - - VmCompilerStatDao dao = new VmCompilerStatDaoImpl(storage); - List<VmCompilerStat> vmCompilerStats = dao.getLatestCompilerStats(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, vmCompilerStats.size()); - VmCompilerStat stat = vmCompilerStats.get(0); - assertEquals(VM_ID, stat.getVmId()); - assertEquals(TIMESTAMP, (Long) stat.getTimeStamp()); - assertEquals(TOTAL_COMPILES, (Long) stat.getTotalCompiles()); - assertEquals(TOTAL_BAILOUTS, (Long) stat.getTotalBailouts()); - assertEquals(TOTAL_INVALIDATES, (Long) stat.getTotalInvalidates()); - assertEquals(COMPILATION_TIME, (Long) stat.getCompilationTime()); - assertEquals(LAST_SIZE, (Long) stat.getLastSize()); - assertEquals(LAST_TYPE, (Long) stat.getLastType()); - assertEquals(LAST_METHOD, stat.getLastMethod()); - assertEquals(LAST_FAILED_TYPE, (Long) stat.getLastFailedType()); - assertEquals(LAST_FAILED_METHOD, stat.getLastFailedMethod()); - } - - @SuppressWarnings("unchecked") - private StatementDescriptor<VmCompilerStat> anyDescriptor() { - return (StatementDescriptor<VmCompilerStat>) any(StatementDescriptor.class); - } - - @SuppressWarnings("unchecked") - @Test - public void testPutVmCompilerStat() throws DescriptorParsingException, StatementExecutionException { - - Storage storage = mock(Storage.class); - PreparedStatement<VmCompilerStat> add = mock(PreparedStatement.class); - when(storage.prepareStatement(any(StatementDescriptor.class))).thenReturn(add); - - VmCompilerStat stat = getCompilerStat(); - VmCompilerStatDao dao = new VmCompilerStatDaoImpl(storage); - dao.putVmCompilerStat(stat); - - @SuppressWarnings("rawtypes") - ArgumentCaptor<StatementDescriptor> captor = ArgumentCaptor.forClass(StatementDescriptor.class); - - verify(storage).prepareStatement(captor.capture()); - StatementDescriptor<?> desc = captor.getValue(); - assertEquals(VmCompilerStatDaoImpl.DESC_ADD_VM_COMPILER_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.getTotalCompiles()); - verify(add).setLong(4, stat.getTotalBailouts()); - verify(add).setLong(5, stat.getTotalInvalidates()); - verify(add).setLong(6, stat.getCompilationTime()); - verify(add).setLong(7, stat.getLastSize()); - verify(add).setLong(8, stat.getLastType()); - verify(add).setString(9, stat.getLastMethod()); - verify(add).setLong(10, stat.getLastFailedType()); - verify(add).setString(11, stat.getLastFailedMethod()); - verify(add).execute(); - verifyNoMoreInteractions(add); - } - - private VmCompilerStat getCompilerStat() { - return new VmCompilerStat("foo-agent", VM_ID, TIMESTAMP, - TOTAL_COMPILES, TOTAL_BAILOUTS, TOTAL_INVALIDATES, - COMPILATION_TIME, - LAST_SIZE, LAST_TYPE, LAST_METHOD, - LAST_FAILED_TYPE, LAST_FAILED_METHOD); - } - -} -
--- a/plugins/vm-compiler/common/src/test/java/com/redhat/thermostat/vm/compiler/common/internal/VmCompilerStatTypeAdapterTest.java Mon Oct 02 15:09:26 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.compiler.common.internal; - -import com.google.gson.GsonBuilder; -import com.google.gson.Gson; -import com.redhat.thermostat.vm.compiler.common.VmCompilerStat; -import org.junit.Test; - -import static com.redhat.thermostat.testutils.JsonUtils.assertJsonEquals; - -public class VmCompilerStatTypeAdapterTest { - - @Test - public void testRead() { - GsonBuilder builder = new GsonBuilder(); - builder.registerTypeAdapter(VmCompilerStat.class, new VmCompilerStatTypeAdapter()); - Gson gson = builder.create(); - VmCompilerStat stat = new VmCompilerStat(); - stat.setTimeStamp(100l); - stat.setVmId("1"); - stat.setAgentId("1"); - stat.setCompilationTime(20l); - stat.setLastFailedMethod("methodFail()"); - stat.setLastFailedType(1l); - stat.setLastMethod("successfulMethod()"); - stat.setLastType(2l); - stat.setLastSize(300l); - stat.setTotalInvalidates(10l); - stat.setTotalBailouts(30l); - stat.setTotalCompiles(40l); - System.out.println(gson.toJson(stat)); - assertJsonEquals("{\"agentId\":\"1\",\"vmId\":\"1\",\"timeStamp\":{\"$numberLong\":\"100\"},\"totalCompiles\":{\"$numberLong\":\"40\"},\"totalBailouts\":{\"$numberLong\":\"30\"},\"totalInvalidates\":{\"$numberLong\":\"10\"},\"compilationTime\":{\"$numberLong\":\"20\"},\"lastSize\":{\"$numberLong\":\"300\"},\"lastType\":{\"$numberLong\":\"2\"},\"lastMethod\":\"successfulMethod()\",\"lastFailedType\":{\"$numberLong\":\"1\"},\"lastFailedMethod\":\"methodFail()\"}", gson.toJson(stat)); - } -}
--- a/plugins/vm-compiler/distribution/assemblies/plugin-assembly.xml Mon Oct 02 15:09:26 2017 +0200 +++ b/plugins/vm-compiler/distribution/assemblies/plugin-assembly.xml Fri Oct 06 14:14:13 2017 -0400 @@ -37,32 +37,38 @@ --> <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" - 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"> - <id>plugin-assembly</id> - <formats> - <format>zip</format> - </formats> - <baseDirectory>${thermostat.plugin}</baseDirectory> - <includeBaseDirectory>true</includeBaseDirectory> - - <dependencySets> - <dependencySet> - <includes> - <include>com.redhat.thermostat.agent:thermostat-vm-compiler-common</include> - <include>com.redhat.thermostat.agent:thermostat-vm-compiler-agent</include> - </includes> - <useProjectArtifact>false</useProjectArtifact> - <useStrictFiltering>true</useStrictFiltering> - </dependencySet> - </dependencySets> - - <files> - <file> - <source>thermostat-plugin.xml</source> - <outputDirectory>/</outputDirectory> - <filtered>true</filtered> - </file> - </files> + 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"> +<id>plugin-assembly</id> +<formats> + <format>zip</format> +</formats> +<includeBaseDirectory>false</includeBaseDirectory> + +<dependencySets> + <dependencySet> + <includes> + <include>com.redhat.thermostat.agent:thermostat-vm-compiler-agent</include> + </includes> + <useProjectArtifact>false</useProjectArtifact> + <useStrictFiltering>true</useStrictFiltering> + <outputDirectory>plugins/${thermostat.plugin}</outputDirectory> + </dependencySet> +</dependencySets> + +<fileSets> + <fileSet> + <includes> + <include>thermostat-plugin.xml</include> + </includes> + <outputDirectory>plugins/${thermostat.plugin}</outputDirectory> + <filtered>true</filtered> + </fileSet> + <fileSet> + <directory>configFiles</directory> + <outputDirectory>etc/plugins.d/${thermostat.plugin}</outputDirectory> + <filtered>true</filtered> + </fileSet> +</fileSets> </assembly>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-compiler/distribution/configFiles/gateway.properties Fri Oct 06 14:14:13 2017 -0400 @@ -0,0 +1,2 @@ +# URL to the jvm-compiler microservice provided by the Thermostat web gateway +gatewayURL=https://localhost:30000/jvm-compiler/0.0.1
--- a/plugins/vm-compiler/distribution/thermostat-plugin.xml Mon Oct 02 15:09:26 2017 +0200 +++ b/plugins/vm-compiler/distribution/thermostat-plugin.xml Fri Oct 06 14:14:13 2017 -0400 @@ -37,13 +37,12 @@ --> <plugin xmlns="http://icedtea.classpath.org/thermostat/plugins/v1.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://icedtea.classpath.org/thermostat/plugins/v1.0 thermostat-plugin.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://icedtea.classpath.org/thermostat/plugins/v1.0 thermostat-plugin.xsd"> <extensions> <extension> <name>agent</name> <bundles> - <bundle><symbolic-name>com.redhat.thermostat.vm.compiler.common</symbolic-name><version>${project.version}</version></bundle> <bundle><symbolic-name>com.redhat.thermostat.vm.compiler.agent</symbolic-name><version>${project.version}</version></bundle> </bundles> </extension>