Mercurial > hg > thermostat-ng > agent
changeset 2744:b1c3824710b9
Resurrect vm-io plugin
This patch brings back the vm-io plugin.
Reviewed-by: neugens
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-August/024772.html
author | Simon Tooke <stooke@redhat.com> |
---|---|
date | Thu, 31 Aug 2017 10:24:26 -0400 |
parents | 915993144f20 |
children | c21830a1925f |
files | distribution/assembly/plugin-assembly.xml distribution/pom.xml plugins/pom.xml plugins/vm-io/agent/pom.xml plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/Activator.java plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/Constants.java plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoBackend.java plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatBuilder.java plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatBuilderImpl.java plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatDAO.java plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatDAOImpl.java plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/model/VmIoStat.java plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/model/VmIoStatTypeAdapter.java plugins/vm-io/agent/src/test/java/com/redhat/thermostat/vm/io/agent/internal/ActivatorTest.java plugins/vm-io/agent/src/test/java/com/redhat/thermostat/vm/io/agent/internal/VmIoBackendTest.java plugins/vm-io/agent/src/test/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatBuilderTest.java plugins/vm-io/agent/src/test/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatDAOImplTest.java plugins/vm-io/agent/src/test/java/com/redhat/thermostat/vm/io/model/VmIoStatTest.java plugins/vm-io/agent/src/test/java/com/redhat/thermostat/vm/io/model/VmIoStatTypeAdapterTest.java plugins/vm-io/common/pom.xml plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/Constants.java plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/VmIoStat.java plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/VmIoStatDAO.java plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/internal/Activator.java plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatCategoryRegistration.java plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatDAOImpl.java plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatDAOImplStatementDescriptorRegistration.java plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatTypeAdapter.java plugins/vm-io/common/src/main/resources/META-INF/services/com.redhat.thermostat.storage.core.auth.CategoryRegistration plugins/vm-io/common/src/main/resources/META-INF/services/com.redhat.thermostat.storage.core.auth.StatementDescriptorRegistration plugins/vm-io/common/src/test/java/com/redhat/thermostat/vm/io/common/VmIoStatTest.java plugins/vm-io/common/src/test/java/com/redhat/thermostat/vm/io/common/internal/ActivatorTest.java plugins/vm-io/common/src/test/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatCategoryRegistrationTest.java plugins/vm-io/common/src/test/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatDAOImplStatementDescriptorRegistrationTest.java plugins/vm-io/common/src/test/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatDAOImplTest.java plugins/vm-io/common/src/test/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatTypeAdapterTest.java plugins/vm-io/distribution/assemblies/plugin-assembly.xml plugins/vm-io/distribution/configFiles/gateway.properties plugins/vm-io/distribution/thermostat-plugin.xml plugins/vm-io/pom.xml |
diffstat | 40 files changed, 839 insertions(+), 1690 deletions(-) [+] |
line wrap: on
line diff
--- a/distribution/assembly/plugin-assembly.xml Tue Aug 29 12:05:38 2017 +0200 +++ b/distribution/assembly/plugin-assembly.xml Thu Aug 31 10:24:26 2017 -0400 @@ -56,6 +56,7 @@ <include>com.redhat.thermostat:thermostat-jvm-overview-distribution</include> <include>com.redhat.thermostat:thermostat-vm-gc-distribution</include> <include>com.redhat.thermostat:thermostat-vm-memory-distribution</include> + <include>com.redhat.thermostat:thermostat-vm-io-distribution</include> <!-- <include>com.redhat.thermostat:thermostat-numa-distribution</include>--> <!-- <include>com.redhat.thermostat:thermostat-thread-distribution</include>--> <!-- <include>com.redhat.thermostat:thermostat-vm-byteman-distribution</include>--> @@ -63,7 +64,6 @@ <!-- <include>com.redhat.thermostat:thermostat-vm-compiler-distribution</include>--> <!-- <include>com.redhat.thermostat:thermostat-vm-cpu-distribution</include>--> <!-- <include>com.redhat.thermostat:thermostat-vm-heap-analysis-distribution</include>--> -<!-- <include>com.redhat.thermostat:thermostat-vm-io-distribution</include>--> <!-- <include>com.redhat.thermostat:thermostat-vm-jmx-distribution</include>--> <include>com.redhat.thermostat:thermostat-commands-distribution</include> <include>com.redhat.thermostat:thermostat-killvm-distribution</include>
--- a/distribution/pom.xml Tue Aug 29 12:05:38 2017 +0200 +++ b/distribution/pom.xml Thu Aug 31 10:24:26 2017 -0400 @@ -505,6 +505,12 @@ </dependency> <dependency> <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-vm-io-distribution</artifactId> + <version>${project.version}</version> + <type>zip</type> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> <artifactId>thermostat-killvm-distribution</artifactId> <version>${project.version}</version> <type>zip</type> @@ -574,12 +580,6 @@ <!--</dependency>--> <!--<dependency>--> <!--<groupId>com.redhat.thermostat</groupId>--> - <!--<artifactId>thermostat-vm-io-distribution</artifactId>--> - <!--<version>${project.version}</version>--> - <!--<type>zip</type>--> - <!--</dependency>--> - <!--<dependency>--> - <!--<groupId>com.redhat.thermostat</groupId>--> <!--<artifactId>thermostat-vm-jmx-distribution</artifactId>--> <!--<version>${project.version}</version>--> <!--<type>zip</type>-->
--- a/plugins/pom.xml Tue Aug 29 12:05:38 2017 +0200 +++ b/plugins/pom.xml Thu Aug 31 10:24:26 2017 -0400 @@ -59,6 +59,7 @@ <module>host-network</module> <module>jvm-overview</module> <module>vm-gc</module> + <module>vm-io</module> <module>vm-memory</module> <module>commands</module> <!--<module>vm-byteman</module>--> @@ -66,7 +67,6 @@ <!--<module>vm-classstat</module>--> <!--<module>vm-compiler</module>--> <!--<module>vm-heap-analysis</module>--> - <!--<module>vm-io</module>--> <!--<module>vm-jmx</module>--> <!--<module>vm-profiler</module>--> <!--<module>numa</module>-->
--- a/plugins/vm-io/agent/pom.xml Tue Aug 29 12:05:38 2017 +0200 +++ b/plugins/vm-io/agent/pom.xml Thu Aug 31 10:24:26 2017 -0400 @@ -59,8 +59,7 @@ <instructions> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> <Bundle-SymbolicName>com.redhat.thermostat.vm.io.agent</Bundle-SymbolicName> - <Bundle-Activator>com.redhat.thermostat.vm.io.agent.internal.Activator</Bundle-Activator> - <Export-Package /> + <Export-Package>com.redhat.thermostat.vm.io.model</Export-Package> <Private-Package> com.redhat.thermostat.vm.io.agent.internal </Private-Package> @@ -71,6 +70,19 @@ </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> + + <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <executions> @@ -161,5 +173,10 @@ <artifactId>thermostat-common-portability</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-jvm-overview-agent</artifactId> + <version>1.99.12-SNAPSHOT</version> + </dependency> </dependencies> </project>
--- a/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/Activator.java Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +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.io.agent.internal; - -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; - -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.Clock; -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.SystemClock; -import com.redhat.thermostat.common.Version; -import com.redhat.thermostat.storage.core.WriterID; -import com.redhat.thermostat.vm.io.common.VmIoStatDAO; - -public class Activator implements BundleActivator { - - private MultipleServiceTracker tracker; - private VmIoBackend 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, - VmIoStatDAO.class, - WriterID.class, - }; - tracker = new MultipleServiceTracker(context, deps, new Action() { - @Override - public void dependenciesAvailable(DependencyProvider services) { - VmIoStatDAO vmIoStatDao = services.get(VmIoStatDAO.class); - Version version = new Version(context.getBundle()); - WriterID writerId = services.get(WriterID.class); - Clock clock = new SystemClock(); - backend = new VmIoBackend(clock, version, vmIoStatDao, registrar, writerId); - 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(); - } -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/Constants.java Thu Aug 31 10:24:26 2017 -0400 @@ -0,0 +1,44 @@ +/* + * 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.io.agent.internal; + +import com.redhat.thermostat.common.Ordered; + +public class Constants { + + public static final int ORDER_VALUE = Ordered.ORDER_IO_GROUP + 50; +}
--- a/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoBackend.java Tue Aug 29 12:05:38 2017 +0200 +++ b/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoBackend.java Thu Aug 31 10:24:26 2017 -0400 @@ -36,66 +36,97 @@ package com.redhat.thermostat.vm.io.agent.internal; -import com.redhat.thermostat.agent.VmStatusListenerRegistrar; -import com.redhat.thermostat.backend.VmListenerBackend; -import com.redhat.thermostat.backend.VmUpdate; -import com.redhat.thermostat.backend.VmUpdateListener; -import com.redhat.thermostat.common.Clock; +import com.redhat.thermostat.backend.Backend; +import com.redhat.thermostat.common.SystemClock; 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.VmUpdate; +import com.redhat.thermostat.jvm.overview.agent.VmUpdateListener; import com.redhat.thermostat.storage.core.WriterID; -import com.redhat.thermostat.vm.io.common.Constants; -import com.redhat.thermostat.vm.io.common.VmIoStat; -import com.redhat.thermostat.vm.io.common.VmIoStatDAO; +import com.redhat.thermostat.vm.io.model.VmIoStat; +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.BundleContext; +@Component +@Service(value = Backend.class) public class VmIoBackend extends VmListenerBackend { + private final ListenerCreator listenerCreator; + + @Reference private VmIoStatDAO vmIoStatDAO; + + @Reference + private WriterID writerId; + private VmIoStatBuilder builder; - public VmIoBackend(Clock clock, Version version, - VmIoStatDAO vmIoStatDao, - VmStatusListenerRegistrar registrar, WriterID writerId) { - this(version, - vmIoStatDao, - new VmIoStatBuilderImpl(clock, writerId), - registrar, writerId); + public VmIoBackend() { + + this(new ListenerCreator()); } - VmIoBackend(Version version, - VmIoStatDAO vmIoStatDao, VmIoStatBuilder builder, - VmStatusListenerRegistrar registrar, WriterID writerId) { + VmIoBackend(ListenerCreator listenerCreator) { super("VM IO Backend", "Gathers IO statistics about a JVM", "Red Hat, Inc.", - version.getVersionNumber(), true , registrar, writerId); - this.vmIoStatDAO = vmIoStatDao; - this.builder = builder; + true); + this.listenerCreator = listenerCreator; + } + + @Activate + protected void componentActivated(BundleContext context) { + VmStatusListenerRegistrar registrar = new VmStatusListenerRegistrar(context); + Version version = new Version(context.getBundle()); + this.builder = new VmIoStatBuilderImpl(new SystemClock(), writerId); + initialize(writerId, registrar, version.getVersionNumber()); + } + + @Deactivate + protected void componentDeactivated() { + if (isActive()) { + deactivate(); + } + } + + // DS bind method + void bindVVmIoStatDAO(VmIoStatDAO dao) { + this.vmIoStatDAO = dao; + } + + // DS bind method + void bindWriterId(WriterID id) { + this.writerId = id; } @Override - protected VmUpdateListener createVmListener(String writerId, String vmId, int pid) { - return new VmIoBackendListener(vmIoStatDAO, builder, vmId, pid); + protected VmUpdateListener createVmListener(String writerId, String jvmId, int pid) { + return listenerCreator.create(vmIoStatDAO, builder, jvmId, pid); } private static class VmIoBackendListener implements VmUpdateListener { private VmIoStatDAO vmIoStatDAO; private VmIoStatBuilder builder; - private String vmId; + private String jvmId; private int pid; - - public VmIoBackendListener (VmIoStatDAO vmIoStatDAO, VmIoStatBuilder builder, String vmId, int pid) { + VmIoBackendListener(VmIoStatDAO vmIoStatDAO, VmIoStatBuilder builder, String jvmId, int pid) { this.vmIoStatDAO = vmIoStatDAO; this.builder = builder; - this.vmId = vmId; + this.jvmId = jvmId; this.pid = pid; } @Override public void countersUpdated(VmUpdate update) { - VmIoStat dataBuilt = builder.build(vmId, pid); + VmIoStat dataBuilt = builder.build(jvmId, pid); if (dataBuilt != null) { - vmIoStatDAO.putVmIoStat(dataBuilt); + vmIoStatDAO.put(dataBuilt); } } } @@ -105,4 +136,10 @@ return Constants.ORDER_VALUE; } + // For testing purposes + static class ListenerCreator { + VmIoBackendListener create(VmIoStatDAO dao, VmIoStatBuilder builder, String jvmId, int pid) { + return new VmIoBackendListener(dao, builder, jvmId, pid); + } + } }
--- a/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatBuilder.java Tue Aug 29 12:05:38 2017 +0200 +++ b/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatBuilder.java Thu Aug 31 10:24:26 2017 -0400 @@ -36,7 +36,7 @@ package com.redhat.thermostat.vm.io.agent.internal; -import com.redhat.thermostat.vm.io.common.VmIoStat; +import com.redhat.thermostat.vm.io.model.VmIoStat; public interface VmIoStatBuilder { VmIoStat build(String vmId, Integer pid);
--- a/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatBuilderImpl.java Tue Aug 29 12:05:38 2017 +0200 +++ b/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatBuilderImpl.java Thu Aug 31 10:24:26 2017 -0400 @@ -40,7 +40,7 @@ import com.redhat.thermostat.common.portability.PortableVmIoStat; import com.redhat.thermostat.common.portability.PortableVmIoStatFactory; import com.redhat.thermostat.storage.core.WriterID; -import com.redhat.thermostat.vm.io.common.VmIoStat; +import com.redhat.thermostat.vm.io.model.VmIoStat; public class VmIoStatBuilderImpl implements VmIoStatBuilder {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatDAO.java Thu Aug 31 10:24:26 2017 -0400 @@ -0,0 +1,47 @@ +/* + * 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.io.agent.internal; + +import com.redhat.thermostat.annotations.Service; +import com.redhat.thermostat.vm.io.model.VmIoStat; + +@Service +public interface VmIoStatDAO { + + void put(VmIoStat stat); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatDAOImpl.java Thu Aug 31 10:24:26 2017 -0400 @@ -0,0 +1,160 @@ +/* + * 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.io.agent.internal; + +import java.io.IOException; +import java.net.URI; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Logger; + +import com.redhat.thermostat.agent.http.HttpRequestService; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugin.PluginConfiguration; +import com.redhat.thermostat.common.plugin.PluginDAOBase; +import com.redhat.thermostat.common.plugin.SystemID; +import com.redhat.thermostat.common.utils.LoggingUtils; +import com.redhat.thermostat.vm.io.model.VmIoStat; +import com.redhat.thermostat.vm.io.model.VmIoStatTypeAdapter; +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; + +@Component +@Service(value = VmIoStatDAO.class) +public class VmIoStatDAOImpl extends PluginDAOBase<VmIoStat, VmIoStatDAOImpl> implements VmIoStatDAO { + + private static final Logger logger = LoggingUtils.getLogger(VmIoStatDAOImpl.class); + + public static final String PLUGIN_ID = "vm-io"; + + private final JsonHelper jsonHelper; + private final ConfigurationCreator configCreator; + private PluginConfiguration config; + + @Reference + private ConfigurationInfoSource configurationInfoSource; + + @Reference + private SystemID systemID; + + @Reference + private HttpRequestService httpRequestService; + + public VmIoStatDAOImpl() { + this(new JsonHelper(new VmIoStatTypeAdapter()), new ConfigurationCreator()); + } + + VmIoStatDAOImpl(JsonHelper jh, ConfigurationCreator creator) { + this.jsonHelper = jh; + this.configCreator = creator; + } + + @Activate + public void activate() throws Exception { + config = configCreator.create(configurationInfoSource); + } + + public String getPluginId() { + return PLUGIN_ID; + } + + public Logger getLogger() { + return logger; + } + + @Override + protected PluginConfiguration getConfig() { + return config; + } + + @Override + protected HttpRequestService getHttpRequestService() { + return httpRequestService; + } + + @Override + protected String toJsonString(VmIoStat obj) throws IOException { + return jsonHelper.toJson(Arrays.asList(obj)); + } + + @Override + protected URI getPostURI(URI basepath) { + return basepath.resolve("systems/" + systemID.getSystemID() + "/jvms/" + "ssss"); + } + + // DS bind methods + protected void bindSystemID(SystemID systemid) { + this.systemID = systemid; + } + + protected void bindConfigurationInfoSource(ConfigurationInfoSource cfg) { + this.configurationInfoSource = cfg; + } + + protected void bindHttpRequestService(HttpRequestService httpRequestService) { + this.httpRequestService = httpRequestService; + } + + protected void unbindHttpRequestService(HttpRequestService httpRequestService) { + this.httpRequestService = null; + } + + // For testing purposes + static class JsonHelper { + + private final VmIoStatTypeAdapter typeAdapter; + + JsonHelper(VmIoStatTypeAdapter typeAdapter) { + this.typeAdapter = typeAdapter; + } + + String toJson(List<VmIoStat> infos) throws IOException { + return typeAdapter.toJson(infos); + } + } + + // For Testing purposes + static class ConfigurationCreator { + + PluginConfiguration create(ConfigurationInfoSource source) { + return new PluginConfiguration(source, PLUGIN_ID); + } + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/model/VmIoStat.java Thu Aug 31 10:24:26 2017 -0400 @@ -0,0 +1,131 @@ +/* + * 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.io.model; + +import com.redhat.thermostat.storage.core.Entity; +import com.redhat.thermostat.storage.core.Persist; +import com.redhat.thermostat.storage.model.BasePojo; +import com.redhat.thermostat.storage.model.TimeStampedPojo; + +@Entity +public class VmIoStat extends BasePojo implements TimeStampedPojo { + + private long timeStamp; + private String jvmId; + + private long charactersRead; + private long charactersWritten; + private long readSyscalls; + private long writeSyscalls; + + public VmIoStat() { + super(null); + } + + public VmIoStat(String writerId, String jvmId, long timeStamp, + long charactersRead, long charactersWritten, long readSyscalls, long writeSyscalls) { + super(writerId); + this.jvmId = jvmId; + this.timeStamp = timeStamp; + this.charactersRead = charactersRead; + this.charactersWritten = charactersWritten; + this.readSyscalls = readSyscalls; + this.writeSyscalls = writeSyscalls; + } + + @Override + @Persist + public long getTimeStamp() { + return timeStamp; + } + + @Persist + public void setTimeStamp(long timeStamp) { + this.timeStamp = timeStamp; + } + + @Persist + public String getJvmId() { + return jvmId; + } + + @Persist + public void setJvmId(String jvmId) { + this.jvmId = jvmId; + } + + @Persist + public long getCharactersRead() { + return charactersRead; + } + + @Persist + public void setCharactersRead(long charactersRead) { + this.charactersRead = charactersRead; + } + + @Persist + public long getCharactersWritten() { + return charactersWritten; + } + + @Persist + public void setCharactersWritten(long charactersWritten) { + this.charactersWritten = charactersWritten; + } + + @Persist + public long getReadSyscalls() { + return readSyscalls; + } + + @Persist + public void setReadSyscalls(long readSyscalls) { + this.readSyscalls = readSyscalls; + } + + @Persist + public long getWriteSyscalls() { + return writeSyscalls; + } + + @Persist + public void setWriteSyscalls(long writeSyscalls) { + this.writeSyscalls = writeSyscalls; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/model/VmIoStatTypeAdapter.java Thu Aug 31 10:24:26 2017 -0400 @@ -0,0 +1,96 @@ +/* + * 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.io.model; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +import java.io.IOException; +import java.util.List; + +public class VmIoStatTypeAdapter extends TypeAdapter<List<com.redhat.thermostat.vm.io.model.VmIoStat>> { + + 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 CHARACTERS_READ = "charactersRead"; + private static final String CHARACTERS_WRITTEN = "charactersWritten"; + private static final String READ_SYSCALLS = "readSyscalls"; + private static final String WRITE_SYSCALLS = "writeSyscalls"; + + @Override + public List<com.redhat.thermostat.vm.io.model.VmIoStat> read(JsonReader in) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public void write(JsonWriter out, List<com.redhat.thermostat.vm.io.model.VmIoStat> stats) throws IOException { + out.beginArray(); + for (com.redhat.thermostat.vm.io.model.VmIoStat stat : stats) { + writeVmIoStat(out, stat); + } + out.endArray(); + } + + private void writeVmIoStat(JsonWriter out, com.redhat.thermostat.vm.io.model.VmIoStat stat) throws IOException { + out.beginObject(); + out.name(TIMESTAMP); + writeLong(out, stat.getTimeStamp()); + out.name(JVM_ID); + out.value(stat.getJvmId()); + out.name(AGENT_ID); + out.value(stat.getAgentId()); + out.name(CHARACTERS_READ); + writeLong(out, stat.getCharactersRead()); + out.name(CHARACTERS_WRITTEN); + writeLong(out, stat.getCharactersWritten()); + out.name(READ_SYSCALLS); + writeLong(out, stat.getReadSyscalls()); + out.name(WRITE_SYSCALLS); + writeLong(out, stat.getWriteSyscalls()); + out.endObject(); + } + + private void writeLong(JsonWriter out, long value) throws IOException { + out.beginObject(); + out.name(TYPE_LONG); + out.value(String.valueOf(value)); + out.endObject(); + } +}
--- a/plugins/vm-io/agent/src/test/java/com/redhat/thermostat/vm/io/agent/internal/ActivatorTest.java Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +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.io.agent.internal; - -import static org.junit.Assert.assertEquals; -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.io.common.VmIoStatDAO; - -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); - VmIoStatDAO vmCpuStatDAO = mock(VmIoStatDAO.class); - WriterID idService = mock(WriterID.class); - - context.registerService(BackendService.class.getName(), service, null); - context.registerService(VmIoStatDAO.class, vmCpuStatDAO, null); - context.registerService(WriterID.class, idService, null); - - Activator activator = new Activator(); - - activator.start(context); - - assertTrue(context.isServiceRegistered(Backend.class.getName(), VmIoBackend.class)); - - assertEquals(3, context.getServiceListeners().size()); - assertEquals(4, context.getAllServices().size()); - } - -} -
--- a/plugins/vm-io/agent/src/test/java/com/redhat/thermostat/vm/io/agent/internal/VmIoBackendTest.java Tue Aug 29 12:05:38 2017 +0200 +++ b/plugins/vm-io/agent/src/test/java/com/redhat/thermostat/vm/io/agent/internal/VmIoBackendTest.java Thu Aug 31 10:24:26 2017 -0400 @@ -36,87 +36,113 @@ package com.redhat.thermostat.vm.io.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.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +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.agent.VmStatusListenerRegistrar; import com.redhat.thermostat.common.Ordered; -import com.redhat.thermostat.common.Version; import com.redhat.thermostat.storage.core.WriterID; -import com.redhat.thermostat.vm.io.common.VmIoStatDAO; +import com.redhat.thermostat.vm.io.agent.internal.VmIoBackend.ListenerCreator; public class VmIoBackendTest { - private VmIoBackend backend; - private VmIoStatDAO vmIoStatDao; - private VmStatusListenerRegistrar registrar; - private VmIoStatBuilder ioStatBuilder; + private TestVmIoBackend backend; + private ListenerCreator listenerCreator; @Before public void setup() { - vmIoStatDao = mock(VmIoStatDAO.class); - - Version version = mock(Version.class); - when(version.getVersionNumber()).thenReturn("0.0.0"); - - registrar = mock(VmStatusListenerRegistrar.class); - - WriterID id = mock(WriterID.class); - ioStatBuilder = mock(VmIoStatBuilderImpl.class); - backend = new VmIoBackend(version, vmIoStatDao, ioStatBuilder, registrar, id); + listenerCreator = mock(ListenerCreator.class); + backend = new TestVmIoBackend(listenerCreator); } @Test - public void testActivate() { - backend.activate(); + 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); - verify(registrar).register(backend); - assertTrue(backend.isActive()); + 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 testActivateTwice() { - assertTrue(backend.activate()); - assertTrue(backend.isActive()); - assertTrue(backend.activate()); - assertTrue(backend.isActive()); + public void testComponentDeactivated() { + // Begin with backend appearing active for this test + backend.active = true; - assertTrue(backend.deactivate()); - } - - @Test - public void testDeactivate() { - backend.activate(); - backend.deactivate(); - - verify(registrar).unregister(backend); + assertTrue(backend.isActive()); + backend.componentDeactivated(); assertFalse(backend.isActive()); } @Test - public void testDeactivateTwice() { - assertTrue(backend.activate()); - assertTrue(backend.isActive()); + public void testCreateVmListener() { + final String writerId = "myAgent"; + final String vmId = "myJVM"; + final int pid = 1234; - assertTrue(backend.deactivate()); - assertFalse(backend.isActive()); - assertTrue(backend.deactivate()); - assertFalse(backend.isActive()); + VmIoStatDAO dao = mock(VmIoStatDAO.class); + backend.bindVVmIoStatDAO(dao); + backend.createVmListener(writerId, vmId, pid); + + verify(listenerCreator).create(eq(dao), any(VmIoStatBuilder.class), eq(vmId), eq(pid)); } @Test public void testOrderValue() { - int orderValue = backend.getOrderValue(); + int order = backend.getOrderValue(); + assertTrue(order >= Ordered.ORDER_IO_GROUP); + } + + static class TestVmIoBackend extends VmIoBackend { + WriterID writerId; + VmStatusListenerRegistrar registrar; + String version; + boolean active; + + TestVmIoBackend(ListenerCreator creator) { + super(creator); + } - assertTrue(orderValue >= Ordered.ORDER_IO_GROUP); - assertTrue(orderValue < Ordered.ORDER_THREAD_GROUP); + // 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; + } } } +
--- a/plugins/vm-io/agent/src/test/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatBuilderTest.java Tue Aug 29 12:05:38 2017 +0200 +++ b/plugins/vm-io/agent/src/test/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatBuilderTest.java Thu Aug 31 10:24:26 2017 -0400 @@ -39,8 +39,7 @@ import com.redhat.thermostat.common.Clock; import com.redhat.thermostat.shared.config.OS; import com.redhat.thermostat.storage.core.WriterID; -import com.redhat.thermostat.vm.io.common.VmIoStat; -import org.junit.Assume; +import com.redhat.thermostat.vm.io.model.VmIoStat; import org.junit.Before; import org.junit.Test; @@ -61,7 +60,7 @@ public void testBuilderBuildsNullForUnknownPid() { Clock clock = mock(Clock.class); VmIoStatBuilder builder = new VmIoStatBuilderImpl(clock, writerID); - VmIoStat result = builder.build("vmId", 0); + VmIoStat result = builder.build("jvmId", 0); if (OS.IS_WINDOWS) // on Windows implementation, pid 0 will return information for the current process assertNotNull(result); else
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-io/agent/src/test/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatDAOImplTest.java Thu Aug 31 10:24:26 2017 -0400 @@ -0,0 +1,61 @@ +/* + * 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.io.agent.internal; + +import org.junit.Before; + +import com.redhat.thermostat.vm.io.model.VmIoStat; + +public class VmIoStatDAOImplTest { + + private static final long SOME_TIMESTAMP = 1234; + private static final String SOME_VM_ID = "321"; + private static final long SOME_CHARACTERS_READ = 123456; + private static final long SOME_CHARACTERS_WRITTEN = 67798; + private static final long SOME_READ_SYSCALLS = 123456; + private static final long SOME_WRITE_SYSCALLS = 67798; + + private VmIoStat ioStat; + + @Before + public void setUp() { + this.ioStat = new VmIoStat("foo-agent", SOME_VM_ID, SOME_TIMESTAMP, + SOME_CHARACTERS_READ, SOME_CHARACTERS_WRITTEN, + SOME_READ_SYSCALLS, SOME_WRITE_SYSCALLS); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-io/agent/src/test/java/com/redhat/thermostat/vm/io/model/VmIoStatTest.java Thu Aug 31 10:24:26 2017 -0400 @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <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.io.model; + +import com.redhat.thermostat.testutils.DataObjectTest; + +public class VmIoStatTest extends DataObjectTest { + + @Override + public Class<?>[] getDataClasses() { + return new Class[] { com.redhat.thermostat.vm.io.model.VmIoStat.class }; + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-io/agent/src/test/java/com/redhat/thermostat/vm/io/model/VmIoStatTypeAdapterTest.java Thu Aug 31 10:24:26 2017 -0400 @@ -0,0 +1,65 @@ +/* + * 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.io.model; + +import com.redhat.thermostat.vm.io.model.VmIoStat; +import com.redhat.thermostat.vm.io.model.VmIoStatTypeAdapter; +import org.junit.Test; + +import java.io.IOException; +import java.util.Arrays; + +import static com.redhat.thermostat.testutils.JsonUtils.assertJsonEquals; + +public class VmIoStatTypeAdapterTest { + + @Test + public void testWrite() throws IOException { + VmIoStatTypeAdapter typeAdapter = new VmIoStatTypeAdapter(); + VmIoStat stat = new VmIoStat(); + stat.setTimeStamp(100l); + stat.setAgentId("AGENT-1"); + stat.setJvmId("VM-1"); + stat.setCharactersRead(2000l); + stat.setCharactersWritten(1000l); + stat.setReadSyscalls(30l); + stat.setWriteSyscalls(40l); + final String expected = "[{\"timeStamp\":{\"$numberLong\":\"100\"},\"jvmId\":\"VM-1\",\"agentId\":\"AGENT-1\",\"charactersRead\":{\"$numberLong\":\"2000\"},\"charactersWritten\":{\"$numberLong\":\"1000\"},\"readSyscalls\":{\"$numberLong\":\"30\"},\"writeSyscalls\":{\"$numberLong\":\"40\"}}]"; + assertJsonEquals(expected, typeAdapter.toJson(Arrays.asList(stat))); + } + +}
--- a/plugins/vm-io/common/pom.xml Tue Aug 29 12:05:38 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-io</artifactId> - <groupId>com.redhat.thermostat</groupId> - <version>1.99.12-SNAPSHOT</version> - </parent> - <artifactId>thermostat-vm-io-common</artifactId> - <packaging>bundle</packaging> - <name>Thermostat VM IO 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.io.common</Bundle-SymbolicName> - <Bundle-Activator>com.redhat.thermostat.vm.io.common.internal.Activator</Bundle-Activator> - <Export-Package> - com.redhat.thermostat.vm.io.common, - </Export-Package> - <Private-Package> - com.redhat.thermostat.vm.io.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</groupId> - <artifactId>thermostat-common-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-storage-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-common-test</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-storage-testutils</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - </dependencies> -</project>
--- a/plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/Constants.java Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +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.io.common; - -import com.redhat.thermostat.common.Ordered; - -public class Constants { - - public static final int ORDER_VALUE = Ordered.ORDER_IO_GROUP + 50; -}
--- a/plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/VmIoStat.java Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,131 +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.io.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 VmIoStat extends BasePojo implements TimeStampedPojo { - - private long timeStamp; - private String vmId; - - private long charactersRead; - private long charactersWritten; - private long readSyscalls; - private long writeSyscalls; - - public VmIoStat() { - super(null); - } - - public VmIoStat(String writerId, String vmId, long timeStamp, - long charactersRead, long charactersWritten, long readSyscalls, long writeSyscalls) { - super(writerId); - this.vmId = vmId; - this.timeStamp = timeStamp; - this.charactersRead = charactersRead; - this.charactersWritten = charactersWritten; - this.readSyscalls = readSyscalls; - this.writeSyscalls = writeSyscalls; - } - - @Override - @Persist - public long getTimeStamp() { - return timeStamp; - } - - @Persist - public void setTimeStamp(long timeStamp) { - this.timeStamp = timeStamp; - } - - @Persist - public String getVmId() { - return vmId; - } - - @Persist - public void setVmId(String vmId) { - this.vmId = vmId; - } - - @Persist - public long getCharactersRead() { - return charactersRead; - } - - @Persist - public void setCharactersRead(long charactersRead) { - this.charactersRead = charactersRead; - } - - @Persist - public long getCharactersWritten() { - return charactersWritten; - } - - @Persist - public void setCharactersWritten(long charactersWritten) { - this.charactersWritten = charactersWritten; - } - - @Persist - public long getReadSyscalls() { - return readSyscalls; - } - - @Persist - public void setReadSyscalls(long readSyscalls) { - this.readSyscalls = readSyscalls; - } - - @Persist - public long getWriteSyscalls() { - return writeSyscalls; - } - - @Persist - public void setWriteSyscalls(long writeSyscalls) { - this.writeSyscalls = writeSyscalls; - } - -}
--- a/plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/VmIoStatDAO.java Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +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.io.common; - -import java.util.List; - -import com.redhat.thermostat.annotations.Service; -import com.redhat.thermostat.storage.core.AgentId; -import com.redhat.thermostat.storage.core.VmId; -import com.redhat.thermostat.storage.core.VmRef; - -@Service -public interface VmIoStatDAO { - - public VmIoStat getOldest(VmRef ref); - - public VmIoStat getNewest(VmRef ref); - - @Deprecated - public List<VmIoStat> getLatestVmIoStats(VmRef ref, long since); - - public List<VmIoStat> getLatestVmIoStats(AgentId agentId, VmId vmId, long since); - - public List<VmIoStat> getVmIoStats(VmRef ref, long since, long to); - - public void putVmIoStat(VmIoStat stat); - -} -
--- a/plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/internal/Activator.java Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.io.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.io.common.VmIoStatDAO; - -public class Activator implements BundleActivator { - - private ServiceTracker<Storage, VmIoStatDAO> tracker; - private ServiceRegistration<VmIoStatDAO> reg; - - @Override - public void start(BundleContext context) throws Exception { - tracker = new ServiceTracker<Storage, VmIoStatDAO>(context, Storage.class, null) { - @Override - public VmIoStatDAO addingService(ServiceReference<Storage> reference) { - Storage storage = context.getService(reference); - VmIoStatDAO vmIoStatDao = new VmIoStatDAOImpl(storage); - reg = context.registerService(VmIoStatDAO.class, vmIoStatDao, null); - return vmIoStatDao; - } - - @Override - public void removedService(ServiceReference<Storage> reference, VmIoStatDAO service) { - reg.unregister(); - context.ungetService(reference); - } - }; - tracker.open(); - } - - @Override - public void stop(BundleContext context) throws Exception { - tracker.close(); - } - -}
--- a/plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatCategoryRegistration.java Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +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.io.common.internal; - -import java.util.HashSet; -import java.util.Set; - -import com.redhat.thermostat.storage.core.auth.CategoryRegistration; - -/** - * 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 VmIoStatCategoryRegistration implements CategoryRegistration { - - @Override - public Set<String> getCategoryNames() { - Set<String> categories = new HashSet<>(1); - categories.add(VmIoStatDAOImpl.CATEGORY.getName()); - return categories; - } - -} -
--- a/plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatDAOImpl.java Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,143 +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.io.common.internal; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.logging.Logger; - -import com.redhat.thermostat.common.utils.LoggingUtils; -import com.redhat.thermostat.storage.core.AgentId; -import com.redhat.thermostat.storage.core.Category; -import com.redhat.thermostat.storage.core.Key; -import com.redhat.thermostat.storage.core.PreparedStatement; -import com.redhat.thermostat.storage.core.Storage; -import com.redhat.thermostat.storage.core.VmBoundaryPojoGetter; -import com.redhat.thermostat.storage.core.VmId; -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.io.common.VmIoStat; -import com.redhat.thermostat.vm.io.common.VmIoStatDAO; - -public class VmIoStatDAOImpl extends AbstractDao implements VmIoStatDAO { - - private static final Logger logger = LoggingUtils.getLogger(VmIoStatDAOImpl.class); - - static final Key<Long> KEY_CHARACTERS_READ = new Key<>("charactersRead"); - static final Key<Long> KEY_CHARACTERS_WRITTEN = new Key<>("charactersWritten"); - static final Key<Long> KEY_READ_SYSCALLS = new Key<>("readSyscalls"); - static final Key<Long> KEY_WRITE_SYSCALLS = new Key<>("writeSyscalls"); - - static final Category<VmIoStat> CATEGORY = new Category<>("vm-io-stats", VmIoStat.class, - Arrays.<Key<?>>asList(Key.AGENT_ID, Key.VM_ID, Key.TIMESTAMP, - KEY_CHARACTERS_READ, KEY_CHARACTERS_WRITTEN, KEY_READ_SYSCALLS, KEY_WRITE_SYSCALLS), - Collections.<Key<?>>singletonList(Key.TIMESTAMP)); - - static final String DESC_ADD_VM_IO_STAT = "ADD " + CATEGORY.getName() + - " SET '" + Key.AGENT_ID.getName() + "' = ?s , " + - "'" + Key.VM_ID.getName() + "' = ?s , " + - "'" + Key.TIMESTAMP.getName() + "' = ?l , " + - "'" + KEY_CHARACTERS_READ.getName() + "' = ?l , " + - "'" + KEY_CHARACTERS_WRITTEN.getName() + "' = ?l , " + - "'" + KEY_READ_SYSCALLS.getName() + "' = ?l , " + - "'" + KEY_WRITE_SYSCALLS.getName() + "' = ?l"; - - private final Storage storage; - private final VmLatestPojoListGetter<VmIoStat> latestGetter; - private final VmTimeIntervalPojoListGetter<VmIoStat> intervalGetter; - private final VmBoundaryPojoGetter<VmIoStat> boundaryGetter; - - VmIoStatDAOImpl(Storage storage) { - this.storage = storage; - storage.registerCategory(CATEGORY); - this.latestGetter = new VmLatestPojoListGetter<>(storage, CATEGORY); - this.intervalGetter = new VmTimeIntervalPojoListGetter<>(storage, CATEGORY); - this.boundaryGetter = new VmBoundaryPojoGetter<>(storage, CATEGORY); - } - - @Override - public List<VmIoStat> getLatestVmIoStats(VmRef ref, long since) { - return latestGetter.getLatest(ref, since); - } - - @Override - public List<VmIoStat> getLatestVmIoStats(AgentId agentId, VmId vmId, long since) { - return latestGetter.getLatest(agentId, vmId, since); - } - - @Override - public List<VmIoStat> getVmIoStats(VmRef ref, long since, long to) { - return intervalGetter.getLatest(ref, since, to); - } - - @Override - public VmIoStat getNewest(VmRef ref) { - return boundaryGetter.getNewestStat(ref); - } - - @Override - public VmIoStat getOldest(VmRef ref) { - return boundaryGetter.getOldestStat(ref); - } - - @Override - public void putVmIoStat(final VmIoStat stat) { - executeStatement(new AbstractDaoStatement<VmIoStat>(storage, CATEGORY, DESC_ADD_VM_IO_STAT) { - @Override - public PreparedStatement<VmIoStat> customize(PreparedStatement<VmIoStat> preparedStatement) { - preparedStatement.setString(0, stat.getAgentId()); - preparedStatement.setString(1, stat.getVmId()); - preparedStatement.setLong(2, stat.getTimeStamp()); - preparedStatement.setLong(3, stat.getCharactersRead()); - preparedStatement.setLong(4, stat.getCharactersWritten()); - preparedStatement.setLong(5, stat.getReadSyscalls()); - preparedStatement.setLong(6, stat.getWriteSyscalls()); - return preparedStatement; - } - }); - } - - @Override - protected Logger getLogger() { - return logger; - } -} -
--- a/plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatDAOImplStatementDescriptorRegistration.java Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +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.io.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; - -/** - * Registers the prepared query issued by this maven module via - * {@link VmLatestPojoListGetter}. - * - */ -public class VmIoStatDAOImplStatementDescriptorRegistration implements - StatementDescriptorRegistration { - - static final String latestDescriptor = String.format(VmLatestPojoListGetter.VM_LATEST_QUERY_FORMAT, - VmIoStatDAOImpl.CATEGORY.getName()); - static final String rangeDescriptor = String.format(VmTimeIntervalPojoListGetter.VM_INTERVAL_QUERY_FORMAT, - VmIoStatDAOImpl.CATEGORY.getName()); - static final String latestStatDescriptor = String.format(VmBoundaryPojoGetter.DESC_NEWEST_VM_STAT, - VmIoStatDAOImpl.CATEGORY.getName()); - static final String oldestStatDescriptor = String.format(VmBoundaryPojoGetter.DESC_OLDEST_VM_STAT, - VmIoStatDAOImpl.CATEGORY.getName()); - - @Override - public Set<String> getStatementDescriptors() { - Set<String> descs = new HashSet<>(); - descs.add(VmIoStatDAOImpl.DESC_ADD_VM_IO_STAT); - descs.add(latestStatDescriptor); - descs.add(oldestStatDescriptor); - descs.add(latestDescriptor); - descs.add(rangeDescriptor); - return descs; - } - -}
--- a/plugins/vm-io/common/src/main/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatTypeAdapter.java Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +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.io.common.internal; - -import com.google.gson.TypeAdapter; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import com.redhat.thermostat.vm.io.common.VmIoStat; - -import java.io.IOException; - -public class VmIoStatTypeAdapter extends TypeAdapter<VmIoStat> { - - private static final String TIMESTAMP = "timeStamp"; - private static final String VM_ID = "vmId"; - private static final String AGENT_ID = "agentId"; - private static final String CHARACTERS_READ = "charactersRead"; - private static final String CHARACTERS_WRITTEN = "charactersWritten"; - private static final String READ_SYSCALLS = "readSyscalls"; - private static final String WRITE_SYSCALLS = "writeSyscalls"; - private static final String TYPE_LONG = "$numberLong"; - - @Override - public VmIoStat read(JsonReader in) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public void write(JsonWriter out, VmIoStat stat) throws IOException { - out.beginObject(); - out.name(TIMESTAMP); - writeLong(out, stat.getTimeStamp()); - out.name(VM_ID); - out.value(stat.getVmId()); - out.name(AGENT_ID); - out.value(stat.getAgentId()); - out.name(CHARACTERS_READ); - writeLong(out, stat.getCharactersRead()); - out.name(CHARACTERS_WRITTEN); - writeLong(out, stat.getCharactersWritten()); - out.name(READ_SYSCALLS); - writeLong(out, stat.getReadSyscalls()); - out.name(WRITE_SYSCALLS); - writeLong(out, stat.getWriteSyscalls()); - out.endObject(); - } - - public void writeLong(JsonWriter out, long value) throws IOException { - out.beginObject(); - out.name(TYPE_LONG); - out.value(String.valueOf(value)); - out.endObject(); - } - -}
--- a/plugins/vm-io/common/src/main/resources/META-INF/services/com.redhat.thermostat.storage.core.auth.CategoryRegistration Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -com.redhat.thermostat.vm.io.common.internal.VmIoStatCategoryRegistration \ No newline at end of file
--- a/plugins/vm-io/common/src/main/resources/META-INF/services/com.redhat.thermostat.storage.core.auth.StatementDescriptorRegistration Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -com.redhat.thermostat.vm.io.common.internal.VmIoStatDAOImplStatementDescriptorRegistration \ No newline at end of file
--- a/plugins/vm-io/common/src/test/java/com/redhat/thermostat/vm/io/common/VmIoStatTest.java Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <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.io.common; - -import com.redhat.thermostat.testutils.DataObjectTest; - -public class VmIoStatTest extends DataObjectTest { - - @Override - public Class<?>[] getDataClasses() { - return new Class[] { VmIoStat.class }; - } -} -
--- a/plugins/vm-io/common/src/test/java/com/redhat/thermostat/vm/io/common/internal/ActivatorTest.java Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <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.io.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.io.common.VmIoStatDAO; - -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(VmIoStatDAO.class.getName(), VmIoStatDAOImpl.class)); - - activator.stop(context); - - assertEquals(0, context.getServiceListeners().size()); - assertEquals(1, context.getAllServices().size()); - } - -} -
--- a/plugins/vm-io/common/src/test/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatCategoryRegistrationTest.java Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.io.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; - -public class VmIoStatCategoryRegistrationTest extends ServiceLoaderTest<CategoryRegistration> { - - public VmIoStatCategoryRegistrationTest() { - super(CategoryRegistration.class, STORAGE_SERVICES, VmIoStatCategoryRegistration.class); - } - - @Test - public void registersAllCategories() { - VmIoStatCategoryRegistration reg = new VmIoStatCategoryRegistration(); - Set<String> categories = reg.getCategoryNames(); - assertEquals(1, categories.size()); - assertFalse("null descriptor not allowed", categories.contains(null)); - assertTrue(categories.contains(VmIoStatDAOImpl.CATEGORY.getName())); - } - -} -
--- a/plugins/vm-io/common/src/test/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatDAOImplStatementDescriptorRegistrationTest.java Tue Aug 29 12:05:38 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.io.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 VmIoStatDAOImplStatementDescriptorRegistrationTest extends ServiceLoaderTest<StatementDescriptorRegistration> { - - public VmIoStatDAOImplStatementDescriptorRegistrationTest() { - super(StatementDescriptorRegistration.class, STORAGE_SERVICES, VmIoStatDAOImplStatementDescriptorRegistration.class); - } - - @Test - public void registersAllDescriptors() { - VmIoStatDAOImplStatementDescriptorRegistration reg = new VmIoStatDAOImplStatementDescriptorRegistration(); - Set<String> descriptors = reg.getStatementDescriptors(); - assertEquals(5, descriptors.size()); - assertFalse("null descriptor not allowed", descriptors.contains(null)); - } - -} -
--- a/plugins/vm-io/common/src/test/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatDAOImplTest.java Tue Aug 29 12:05:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,244 +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.io.common.internal; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -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.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; - -import com.redhat.thermostat.common.Pair; -import com.redhat.thermostat.storage.core.AgentId; -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.VmId; -import com.redhat.thermostat.storage.core.VmRef; -import com.redhat.thermostat.storage.testutils.StatementDescriptorTester; -import com.redhat.thermostat.vm.io.common.VmIoStat; -import com.redhat.thermostat.vm.io.common.VmIoStatDAO; - -public class VmIoStatDAOImplTest { - - private static final long SOME_TIMESTAMP = 1234; - private static final String SOME_VM_ID = "321"; - private static final long SOME_CHARACTERS_READ = 123456; - private static final long SOME_CHARACTERS_WRITTEN = 67798; - private static final long SOME_READ_SYSCALLS = 123456; - private static final long SOME_WRITE_SYSCALLS = 67798; - - private VmIoStat ioStat; - - @Before - public void setUp() { - ioStat = new VmIoStat("foo-agent", SOME_VM_ID, SOME_TIMESTAMP, - SOME_CHARACTERS_READ, SOME_CHARACTERS_WRITTEN, - SOME_READ_SYSCALLS, SOME_WRITE_SYSCALLS); - } - - @Test - public void verifyDescriptorsAreSane() { - String addIoStat = "ADD vm-io-stats SET 'agentId' = ?s , " + - "'vmId' = ?s , " + - "'timeStamp' = ?l , " + - "'charactersRead' = ?l , " + - "'charactersWritten' = ?l , " + - "'readSyscalls' = ?l , " + - "'writeSyscalls' = ?l"; - - assertEquals(addIoStat, VmIoStatDAOImpl.DESC_ADD_VM_IO_STAT); - } - - @Test - public void canParseDescriptor() { - StatementDescriptorTester<VmIoStat> tester = new StatementDescriptorTester<>(); - StatementDescriptor<VmIoStat> desc = new StatementDescriptor<>(VmIoStatDAOImpl.CATEGORY, VmIoStatDAOImpl.DESC_ADD_VM_IO_STAT); - try { - tester.testParseBasic(desc); - tester.testParseSemantic(desc); - // pass - } catch (DescriptorParsingException e) { - fail(e.getMessage()); - } - } - - @Test - public void testCategory() { - assertEquals("vm-io-stats", VmIoStatDAOImpl.CATEGORY.getName()); - Collection<Key<?>> keys = VmIoStatDAOImpl.CATEGORY.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<Integer>("charactersRead"))); - assertTrue(keys.contains(new Key<Integer>("charactersWritten"))); - assertTrue(keys.contains(new Key<Integer>("readSyscalls"))); - assertTrue(keys.contains(new Key<Integer>("writeSyscalls"))); - assertEquals(7, keys.size()); - } - - @Test - public void testVmRefGetLatestIoStatsBasic() throws DescriptorParsingException, StatementExecutionException { - Pair<Storage, PreparedStatement<VmIoStat>> setup = setupGetLatest(); - Storage storage = setup.getFirst(); - PreparedStatement<VmIoStat> stmt = setup.getSecond(); - - HostRef hostRef = mock(HostRef.class); - when(hostRef.getAgentId()).thenReturn("system"); - - VmRef vmRef = mock(VmRef.class); - when(vmRef.getHostRef()).thenReturn(hostRef); - when(vmRef.getVmId()).thenReturn(SOME_VM_ID); - - VmIoStatDAO dao = new VmIoStatDAOImpl(storage); - List<VmIoStat> vmIoStats = dao.getLatestVmIoStats(vmRef, Long.MIN_VALUE); - - verify(storage).prepareStatement(anyDescriptor()); - verify(stmt).setString(0, "system"); - verify(stmt).setString(1, SOME_VM_ID); - verify(stmt).setLong(2, Long.MIN_VALUE); - verify(stmt).executeQuery(); - verifyNoMoreInteractions(stmt); - - assertEquals(1, vmIoStats.size()); - VmIoStat stat = vmIoStats.get(0); - assertEquals(SOME_TIMESTAMP, stat.getTimeStamp()); - assertEquals(SOME_VM_ID, stat.getVmId()); - assertEquals(SOME_CHARACTERS_READ, stat.getCharactersRead()); - assertEquals(SOME_CHARACTERS_WRITTEN, stat.getCharactersWritten()); - assertEquals(SOME_READ_SYSCALLS, stat.getReadSyscalls()); - assertEquals(SOME_WRITE_SYSCALLS, stat.getWriteSyscalls()); - } - - @Test - public void testGetLatestIoStatsBasic() throws DescriptorParsingException, StatementExecutionException { - Pair<Storage, PreparedStatement<VmIoStat>> setup = setupGetLatest(); - Storage storage = setup.getFirst(); - PreparedStatement<VmIoStat> stmt = setup.getSecond(); - - AgentId agentId = new AgentId("system"); - VmId vmId = new VmId(SOME_VM_ID); - - VmIoStatDAO dao = new VmIoStatDAOImpl(storage); - List<VmIoStat> vmIoStats = dao.getLatestVmIoStats(agentId, vmId, Long.MIN_VALUE); - - verify(storage).prepareStatement(anyDescriptor()); - verify(stmt).setString(0, "system"); - verify(stmt).setString(1, SOME_VM_ID); - verify(stmt).setLong(2, Long.MIN_VALUE); - verify(stmt).executeQuery(); - verifyNoMoreInteractions(stmt); - - assertEquals(1, vmIoStats.size()); - VmIoStat stat = vmIoStats.get(0); - assertEquals(SOME_TIMESTAMP, stat.getTimeStamp()); - assertEquals(SOME_VM_ID, stat.getVmId()); - assertEquals(SOME_CHARACTERS_READ, stat.getCharactersRead()); - assertEquals(SOME_CHARACTERS_WRITTEN, stat.getCharactersWritten()); - assertEquals(SOME_READ_SYSCALLS, stat.getReadSyscalls()); - assertEquals(SOME_WRITE_SYSCALLS, stat.getWriteSyscalls()); - } - - private Pair<Storage, PreparedStatement<VmIoStat>> setupGetLatest() throws - DescriptorParsingException, StatementExecutionException { - - @SuppressWarnings("unchecked") - Cursor<VmIoStat> cursor = (Cursor<VmIoStat>) mock(Cursor.class); - when(cursor.hasNext()).thenReturn(true).thenReturn(false); - when(cursor.next()).thenReturn(ioStat); - - Storage storage = mock(Storage.class); - @SuppressWarnings("unchecked") - PreparedStatement<VmIoStat> stmt = (PreparedStatement<VmIoStat>) mock(PreparedStatement.class); - when(storage.prepareStatement(anyDescriptor())).thenReturn(stmt); - when(stmt.executeQuery()).thenReturn(cursor); - - return new Pair<>(storage, stmt); - } - - @SuppressWarnings("unchecked") - private StatementDescriptor<VmIoStat> anyDescriptor() { - return (StatementDescriptor<VmIoStat>) any(StatementDescriptor.class); - } - - @SuppressWarnings("unchecked") - @Test - public void testPutVmIoStat() throws DescriptorParsingException, StatementExecutionException { - Storage storage = mock(Storage.class); - PreparedStatement<VmIoStat> add = mock(PreparedStatement.class); - when(storage.prepareStatement(any(StatementDescriptor.class))).thenReturn(add); - - VmIoStat stat = new VmIoStat("foo-agent", SOME_VM_ID, SOME_TIMESTAMP, - SOME_CHARACTERS_READ, SOME_CHARACTERS_WRITTEN, - SOME_READ_SYSCALLS, SOME_WRITE_SYSCALLS); - VmIoStatDAO dao = new VmIoStatDAOImpl(storage); - dao.putVmIoStat(stat); - - @SuppressWarnings("rawtypes") - ArgumentCaptor<StatementDescriptor> captor = ArgumentCaptor.forClass(StatementDescriptor.class); - - verify(storage).prepareStatement(captor.capture()); - StatementDescriptor<?> desc = captor.getValue(); - assertEquals(VmIoStatDAOImpl.DESC_ADD_VM_IO_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.getCharactersRead()); - verify(add).setLong(4, stat.getCharactersWritten()); - verify(add).setLong(5, stat.getReadSyscalls()); - verify(add).setLong(6, stat.getWriteSyscalls()); - verify(add).execute(); - verifyNoMoreInteractions(add); - } - -}
--- a/plugins/vm-io/common/src/test/java/com/redhat/thermostat/vm/io/common/internal/VmIoStatTypeAdapterTest.java Tue Aug 29 12:05:38 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.io.common.internal; - -import com.google.gson.GsonBuilder; -import com.google.gson.Gson; -import com.redhat.thermostat.vm.io.common.VmIoStat; -import org.junit.Test; - -import static com.redhat.thermostat.testutils.JsonUtils.assertJsonEquals; - -public class VmIoStatTypeAdapterTest { - - @Test - public void testWrite() { - GsonBuilder builder = new GsonBuilder(); - builder.registerTypeAdapter(VmIoStat.class, new VmIoStatTypeAdapter()); - Gson gson = builder.create(); - VmIoStat stat = new VmIoStat(); - stat.setTimeStamp(100l); - stat.setAgentId("AGENT-1"); - stat.setVmId("VM-1"); - stat.setCharactersRead(2000l); - stat.setCharactersWritten(1000l); - stat.setReadSyscalls(30l); - stat.setWriteSyscalls(40l); - assertJsonEquals("{\"timeStamp\":{\"$numberLong\":\"100\"},\"vmId\":\"VM-1\",\"agentId\":\"AGENT-1\",\"charactersRead\":{\"$numberLong\":\"2000\"},\"charactersWritten\":{\"$numberLong\":\"1000\"},\"readSyscalls\":{\"$numberLong\":\"30\"},\"writeSyscalls\":{\"$numberLong\":\"40\"}}", gson.toJson(stat)); - } - -}
--- a/plugins/vm-io/distribution/assemblies/plugin-assembly.xml Tue Aug 29 12:05:38 2017 +0200 +++ b/plugins/vm-io/distribution/assemblies/plugin-assembly.xml Thu Aug 31 10:24:26 2017 -0400 @@ -43,26 +43,32 @@ <formats> <format>zip</format> </formats> - <baseDirectory>${thermostat.plugin}</baseDirectory> - <includeBaseDirectory>true</includeBaseDirectory> + <includeBaseDirectory>false</includeBaseDirectory> <dependencySets> <dependencySet> <includes> - <include>com.redhat.thermostat:thermostat-vm-io-common</include> <include>com.redhat.thermostat:thermostat-vm-io-agent</include> </includes> <useProjectArtifact>false</useProjectArtifact> <useStrictFiltering>true</useStrictFiltering> + <outputDirectory>plugins/${thermostat.plugin}</outputDirectory> </dependencySet> </dependencySets> - - <files> - <file> - <source>thermostat-plugin.xml</source> - <outputDirectory>/</outputDirectory> + + <fileSets> + <fileSet> + <includes> + <include>thermostat-plugin.xml</include> + </includes> + <outputDirectory>plugins/${thermostat.plugin}</outputDirectory> <filtered>true</filtered> - </file> - </files> + </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-io/distribution/configFiles/gateway.properties Thu Aug 31 10:24:26 2017 -0400 @@ -0,0 +1,2 @@ +# URL to the microservice provided by the Thermostat web gateway +gatewayURL=https://localhost:30000/jvm-io/0.0.1
--- a/plugins/vm-io/distribution/thermostat-plugin.xml Tue Aug 29 12:05:38 2017 +0200 +++ b/plugins/vm-io/distribution/thermostat-plugin.xml Thu Aug 31 10:24:26 2017 -0400 @@ -43,7 +43,6 @@ <extension> <name>agent</name> <bundles> - <bundle><symbolic-name>com.redhat.thermostat.vm.io.common</symbolic-name><version>${project.version}</version></bundle> <bundle><symbolic-name>com.redhat.thermostat.vm.io.agent</symbolic-name><version>${project.version}</version></bundle> </bundles> </extension>