Mercurial > hg > release > thermostat-1.2
changeset 663:9b18906b1dc6
Rename killvm bundle and packages.
This is a first step to come up with a consistent naming scheme. See:
http://icedtea.classpath.org/pipermail/thermostat/2012-August/003022.html
client.killvm => killvm.client
agent.killvm => killvm.agent
Reviewed-by: omajid
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-September/003448.html
line wrap: on
line diff
--- a/agent/killvm/pom.xml Tue Oct 02 17:43:44 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Copyright 2012 Red Hat, Inc. - - This file is part of Thermostat. - - Thermostat is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 2, or (at your - option) any later version. - - Thermostat is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Thermostat; see the file COPYING. If not see - <http://www.gnu.org/licenses />. - - Linking this code with other modules is making a combined work - based on this code. Thus, the terms and conditions of the GNU - General Public License cover the whole combination. - - As a special exception, the copyright holders of this code give - you permission to link this code with independent modules to - produce an executable, regardless of the license terms of these - independent modules, and to copy and distribute the resulting - executable under terms of your choice, provided that you also - meet, for each linked independent module, the terms and conditions - of the license of that module. An independent module is a module - which is not derived from or based on this code. If you modify - this code, you may extend this exception to your version of the - library, but you are not obligated to do so. If you do not wish - to do so, delete this exception statement from your version. - ---> -<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> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-agent</artifactId> - <version>0.5.0-SNAPSHOT</version> - </parent> - - <artifactId>thermostat-agent-killvm</artifactId> - <packaging>bundle</packaging> - - <name>Thermostat Agent Kill VM</name> - - <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.powermock</groupId> - <artifactId>powermock-api-mockito</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-module-junit4</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-agent-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-agent-command</artifactId> - <version>${project.version}</version> - </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-launcher</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - </dependency> - </dependencies> - - <build> - <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-Activator>com.redhat.thermostat.agent.killvm.internal.Activator</Bundle-Activator> - <Bundle-SymbolicName>com.redhat.thermostat.agent.killvm</Bundle-SymbolicName> - <Private-Package>com.redhat.thermostat.agent.killvm.internal</Private-Package> - <!-- Do not autogenerate uses clauses in Manifests --> - <_nouses>true</_nouses> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - -</project> \ No newline at end of file
--- a/agent/killvm/src/main/java/com/redhat/thermostat/agent/killvm/internal/Activator.java Tue Oct 02 17:43:44 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.agent.killvm.internal; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -import com.redhat.thermostat.agent.command.ReceiverRegistry; -import com.redhat.thermostat.common.utils.OSGIUtils; -import com.redhat.thermostat.service.process.UNIXProcessHandler; - -public class Activator implements BundleActivator { - - private ReceiverRegistry registry; - private UNIXProcessHandler unixService; - - @Override - public void start(final BundleContext context) throws Exception { - unixService = OSGIUtils.getInstance().getService(UNIXProcessHandler.class); - registry = new ReceiverRegistry(context); - registry.registerReceiver(new KillVmReceiver(unixService)); - } - - @Override - public void stop(BundleContext context) throws Exception { - // This only unregisters receivers which we've registered - // in start() - registry.unregisterReceivers(); - } -}
--- a/agent/killvm/src/main/java/com/redhat/thermostat/agent/killvm/internal/KillVmReceiver.java Tue Oct 02 17:43:44 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.agent.killvm.internal; - -import java.util.logging.Logger; - -import com.redhat.thermostat.agent.command.RequestReceiver; -import com.redhat.thermostat.common.command.Request; -import com.redhat.thermostat.common.command.Response; -import com.redhat.thermostat.common.command.Response.ResponseType; -import com.redhat.thermostat.service.process.UNIXProcessHandler; -import com.redhat.thermostat.service.process.UNIXSignal; - -public class KillVmReceiver implements RequestReceiver { - - private final UNIXProcessHandler unixService; - private static final Logger log = Logger.getLogger(KillVmReceiver.class.getName()); - - public KillVmReceiver(UNIXProcessHandler unixService) { - this.unixService = unixService; - } - - @Override - public Response receive(Request request) { - if (unixService == null) { - // no dice, should have service by now - log.severe("Unix service null!"); - return new Response(ResponseType.ERROR); - } - String vmId = request.getParameter("vm-id"); - unixService.sendSignal(vmId, UNIXSignal.TERM); - log.fine("Killed VM with ID " + vmId); - return new Response(ResponseType.OK); - } - -}
--- a/agent/killvm/src/test/java/com/redhat/thermostat/agent/killvm/internal/ActivatorTest.java Tue Oct 02 17:43:44 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.agent.killvm.internal; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.Dictionary; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import com.redhat.thermostat.agent.command.RequestReceiver; -import com.redhat.thermostat.common.utils.OSGIUtils; -import com.redhat.thermostat.service.process.UNIXProcessHandler; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(OSGIUtils.class) -public class ActivatorTest { - - /** - * Makes sure receiver is registered and unix service gets set. - * - * @throws Exception - */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Test - public void startStopTest() throws Exception { - OSGIUtils utils = mock(OSGIUtils.class); - PowerMockito.mockStatic(OSGIUtils.class); - when(OSGIUtils.getInstance()).thenReturn(utils); - BundleContext ctx = mock(BundleContext.class); - ServiceRegistration serviceReg = mock(ServiceRegistration.class); - when(ctx.registerService(anyString(), any(), any(Dictionary.class))).thenReturn(serviceReg); - Activator activator = new Activator(); - activator.start(ctx); - verify(utils).getService(UNIXProcessHandler.class); - verify(ctx).registerService(eq(RequestReceiver.class.getName()), isA(KillVmReceiver.class), any(Dictionary.class)); - activator.stop(ctx); - verify(serviceReg).unregister(); - } - -}
--- a/agent/killvm/src/test/java/com/redhat/thermostat/agent/killvm/internal/KillVmReceiverTest.java Tue Oct 02 17:43:44 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.agent.killvm.internal; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; - -import org.junit.Test; - -import com.redhat.thermostat.common.command.Request; -import com.redhat.thermostat.common.command.Response; -import com.redhat.thermostat.common.command.Response.ResponseType; -import com.redhat.thermostat.service.process.UNIXProcessHandler; - -public class KillVmReceiverTest { - - @Test - public void receiverReturnsOk() { - UNIXProcessHandler proc = mock(UNIXProcessHandler.class); - KillVmReceiver receiver = new KillVmReceiver(proc); - Request req = mock(Request.class); - Response response = receiver.receive(req); - assertEquals(ResponseType.OK, response.getType()); - } - - @Test - public void receiverReturnsError() { - KillVmReceiver receiver = new KillVmReceiver(null); - Request req = mock(Request.class); - Response response = receiver.receive(req); - assertEquals(ResponseType.ERROR, response.getType()); - } - - /** - * When a request is issued the fully qualified receiver class name is set - * via {@link Request#setReceiver(String)}. This test makes sure that this - * class is actually where it's supposed to be. - * - * @throws Exception - */ - @Test - public void killVmReceiverIsInAppropriatePackage() { - Class<?> receiver = null; - try { - // com.redhat.thermostat.client.killvm.internal.KillVMAction uses - // this class name. - receiver = Class - .forName("com.redhat.thermostat.agent.killvm.internal.KillVmReceiver"); - } catch (ClassNotFoundException e) { - fail("com.redhat.thermostat.agent.killvm.internal.KillVmReceiver class not found, but used by some request!"); - } - try { - Constructor<?> constructor = receiver.getConstructor(UNIXProcessHandler.class); - UNIXProcessHandler service = mock(UNIXProcessHandler.class); - Object instance = constructor.newInstance(service); - Method m = receiver.getMethod("receive", Request.class); - Request req = mock(Request.class); - m.invoke(instance, req); - } catch (Exception e) { - e.printStackTrace(); - fail("cannot invoke receiver's receive method"); - } - } -}
--- a/agent/pom.xml Tue Oct 02 17:43:44 2012 -0400 +++ b/agent/pom.xml Thu Sep 27 14:27:26 2012 +0200 @@ -63,7 +63,6 @@ <module>core</module> <module>command</module> <module>heapdumper</module> - <module>killvm</module> </modules> </project>
--- a/client/killvm/pom.xml Tue Oct 02 17:43:44 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<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-client</artifactId> - <groupId>com.redhat.thermostat</groupId> - <version>0.5.0-SNAPSHOT</version> - </parent> - <artifactId>thermostat-client-killvm</artifactId> - <packaging>bundle</packaging> - <name>Thermostat Client Terminate VM plugin</name> - <build> - <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-Activator>com.redhat.thermostat.client.killvm.internal.Activator</Bundle-Activator> - <Bundle-SymbolicName>com.redhat.thermostat.client.killvm</Bundle-SymbolicName> - <Export-Package>com.redhat.thermostat.client.killvm.locale</Export-Package> - <Private-Package>com.redhat.thermostat.client.killvm.internal</Private-Package> - </instructions> - <!-- Do not autogenerate uses clauses in Manifests --> - <_nouses>true</_nouses> - </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.powermock</groupId> - <artifactId>powermock-api-mockito</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-module-junit4</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.easytesting</groupId> - <artifactId>fest-swing</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>net.java.openjdk.cacio</groupId> - <artifactId>cacio-tta</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-client-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-client-command</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-common-command</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-osgi-process-handler</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> -</project>
--- a/client/killvm/src/main/java/com/redhat/thermostat/client/killvm/internal/Activator.java Tue Oct 02 17:43:44 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.killvm.internal; - -import java.util.Map; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -import com.redhat.thermostat.client.osgi.service.ContextAction; -import com.redhat.thermostat.client.osgi.service.VMContextAction; -import com.redhat.thermostat.common.MultipleServiceTracker; -import com.redhat.thermostat.common.MultipleServiceTracker.Action; -import com.redhat.thermostat.common.dao.AgentInfoDAO; -import com.redhat.thermostat.common.dao.VmInfoDAO; - -public class Activator implements BundleActivator { - - private MultipleServiceTracker killVmActionTracker; - private ServiceRegistration killActionRegistration; - - @Override - public void start(final BundleContext context) throws Exception { - Class<?>[] serviceDeps = new Class<?>[] { - AgentInfoDAO.class, - VmInfoDAO.class, - ContextAction.class, - }; - - killVmActionTracker = new MultipleServiceTracker(context, serviceDeps, new Action() { - @Override - public void dependenciesAvailable(Map<String, Object> services) { - AgentInfoDAO agentDao = (AgentInfoDAO) services.get(AgentInfoDAO.class.getName()); - VmInfoDAO vmDao = (VmInfoDAO) services.get(VmInfoDAO.class.getName()); - KillVMAction service = new KillVMAction(agentDao, vmDao, new SwingVMKilledListener()); - killActionRegistration = context.registerService(VMContextAction.class.getName(), service, null); - } - - @Override - public void dependenciesUnavailable() { - killActionRegistration.unregister(); - killActionRegistration = null; - } - }); - - killVmActionTracker.open(); - } - - @Override - public void stop(BundleContext context) throws Exception { - killVmActionTracker.close(); - // service automatically unregistered on bundle stop - } - -}
--- a/client/killvm/src/main/java/com/redhat/thermostat/client/killvm/internal/KillVMAction.java Tue Oct 02 17:43:44 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.killvm.internal; - -import java.net.InetSocketAddress; -import java.util.Objects; - -import com.redhat.thermostat.client.command.RequestQueue; -import com.redhat.thermostat.client.killvm.locale.LocaleResources; -import com.redhat.thermostat.client.osgi.service.VMContextAction; -import com.redhat.thermostat.client.osgi.service.VmFilter; -import com.redhat.thermostat.common.command.Request; -import com.redhat.thermostat.common.command.Request.RequestType; -import com.redhat.thermostat.common.command.RequestResponseListener; -import com.redhat.thermostat.common.dao.AgentInfoDAO; -import com.redhat.thermostat.common.dao.VmInfoDAO; -import com.redhat.thermostat.common.dao.VmRef; -import com.redhat.thermostat.common.locale.Translate; -import com.redhat.thermostat.common.model.VmInfo; -import com.redhat.thermostat.common.utils.OSGIUtils; - -/** - * Implements the {@link VMContextAction} entry point to provide a kill switch - * for the currently selected Virtual Machine. - */ -public class KillVMAction implements VMContextAction { - - private static final String RECEIVER = "com.redhat.thermostat.agent.killvm.internal.KillVmReceiver"; - private final AgentInfoDAO agentDao; - private final VmInfoDAO vmDao; - private final Translate t; - private final RequestResponseListener listener; - - public KillVMAction(AgentInfoDAO agentDao, VmInfoDAO vmDao, RequestResponseListener listener) { - Objects.requireNonNull(listener, "Listener can't be null"); - this.agentDao = agentDao; - this.vmDao = vmDao; - this.t = LocaleResources.createLocalizer(); - this.listener = listener; - } - - @Override - public String getName() { - return t.localize(LocaleResources.ACTION_NAME); - } - - @Override - public String getDescription() { - return t.localize(LocaleResources.ACTION_DESCRIPTION); - } - - @Override - public void execute(VmRef reference) { - String address = agentDao.getAgentInformation(reference.getAgent()).getConfigListenAddress(); - - String [] host = address.split(":"); - InetSocketAddress target = new InetSocketAddress(host[0], Integer.parseInt(host[1])); - Request murderer = getKillRequest(target); - murderer.setParameter("vm-id", reference.getIdString()); - murderer.setReceiver(RECEIVER); - murderer.addListener(listener); - - RequestQueue queue = OSGIUtils.getInstance().getService(RequestQueue.class); - queue.putRequest(murderer); - } - - // testing hook; keep this package private - Request getKillRequest(InetSocketAddress target) { - return new Request(RequestType.RESPONSE_EXPECTED, target); - } - - @Override - public VmFilter getFilter() { - return new LocalAndAliveFilter(); - } - - private class LocalAndAliveFilter implements VmFilter { - - @Override - public boolean matches(VmRef ref) { - VmInfo vmInfo = vmDao.getVmInfo(ref); - return vmInfo.isAlive(); - } - - } -}
--- a/client/killvm/src/main/java/com/redhat/thermostat/client/killvm/internal/SwingVMKilledListener.java Tue Oct 02 17:43:44 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.killvm.internal; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; - -import com.redhat.thermostat.client.killvm.locale.LocaleResources; -import com.redhat.thermostat.common.command.Request; -import com.redhat.thermostat.common.command.RequestResponseListener; -import com.redhat.thermostat.common.command.Response; -import com.redhat.thermostat.common.locale.Translate; - -public class SwingVMKilledListener implements RequestResponseListener { - - private final Translate t; - private static final Logger logger = Logger - .getLogger(SwingVMKilledListener.class.getName()); - - public SwingVMKilledListener() { - this.t = LocaleResources.createLocalizer(); - } - - @Override - public void fireComplete(Request request, Response response) { - switch (response.getType()) { - case EXCEPTION: - logger.log(Level.SEVERE, - "Exception response from kill VM request. Command channel failure?"); - showErrorMessage(t.localize(LocaleResources.KILL_ACTION_EXCEPTION_RESPONSE_MSG)); - break; - case ERROR: - String vmId = request.getParameter("vm-id"); - logger.log(Level.SEVERE, - "Kill request error for VM ID " - + vmId); - showErrorMessage(t.localize(LocaleResources.KILL_ACTION_ERROR_RESPONSE_MSG, vmId)); - break; - case PONG: // fall-through, also OK :) - case OK: - logger.log(Level.INFO, - "VM with id " + request.getParameter("vm-id") - + " killed on host " - + request.getTarget().toString()); - break; - default: - logger.log(Level.WARNING, "Unknown result from KILL VM command."); - break; - } - } - - /* - * protected for testing - * - */ - protected void showErrorMessage(final String message) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - JOptionPane.showMessageDialog(null, message, "", - JOptionPane.ERROR_MESSAGE); - } - }); - } -}
--- a/client/killvm/src/main/java/com/redhat/thermostat/client/killvm/locale/LocaleResources.java Tue Oct 02 17:43:44 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.killvm.locale; - -import com.redhat.thermostat.common.locale.Translate; - -public enum LocaleResources { - - ACTION_NAME, - ACTION_DESCRIPTION, - KILL_ACTION_EXCEPTION_RESPONSE_MSG, - KILL_ACTION_ERROR_RESPONSE_MSG, - MISSING_INFO; - - public static final String RESOURCE_BUNDLE = - "com.redhat.thermostat.client.killvm.locale.strings"; - - public static Translate createLocalizer() { - return new Translate(RESOURCE_BUNDLE); - } -}
--- a/client/killvm/src/main/resources/com/redhat/thermostat/client/killvm/locale/strings.properties Tue Oct 02 17:43:44 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -ACTION_NAME = Kill Application -ACTION_DESCRIPTION = Kill the selected VM Process -MISSING_INFO = Missing Information -KILL_ACTION_EXCEPTION_RESPONSE_MSG = Channel Transport Error. Please check your configuration! -KILL_ACTION_ERROR_RESPONSE_MSG = Failed to kill VM with pid {0} \ No newline at end of file
--- a/client/killvm/src/test/java/com/redhat/thermostat/client/killvm/internal/ActivatorTest.java Tue Oct 02 17:43:44 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.killvm.internal; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.Dictionary; - -import org.junit.Ignore; -import org.junit.Test; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -import com.redhat.thermostat.client.osgi.service.VMContextAction; - -public class ActivatorTest { - - @Ignore(value="testing activator is slightly more complex") - @Test - public void startRegistersKillVMAction() throws Exception { - BundleContext ctx = mock(BundleContext.class); - ServiceRegistration serviceReg = mock(ServiceRegistration.class); - when(ctx.registerService(anyString(), any(), any(Dictionary.class))) - .thenReturn(serviceReg); - Activator activator = new Activator(); - activator.start(ctx); - verify(ctx).registerService(eq(VMContextAction.class.getName()), - isA(KillVMAction.class), any(Dictionary.class)); - } - -}
--- a/client/killvm/src/test/java/com/redhat/thermostat/client/killvm/internal/KillVMActionTest.java Tue Oct 02 17:43:44 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,139 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.killvm.internal; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.net.InetSocketAddress; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import com.redhat.thermostat.client.command.RequestQueue; -import com.redhat.thermostat.client.osgi.service.VmFilter; -import com.redhat.thermostat.common.command.Request; -import com.redhat.thermostat.common.command.RequestResponseListener; -import com.redhat.thermostat.common.dao.AgentInfoDAO; -import com.redhat.thermostat.common.dao.HostRef; -import com.redhat.thermostat.common.dao.VmInfoDAO; -import com.redhat.thermostat.common.dao.VmRef; -import com.redhat.thermostat.common.model.AgentInformation; -import com.redhat.thermostat.common.model.VmInfo; -import com.redhat.thermostat.common.utils.OSGIUtils; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(OSGIUtils.class) -public class KillVMActionTest { - - @Test - public void killVMFilterOnlyMatchesLiveVMs() { - AgentInfoDAO agentDao = mock(AgentInfoDAO.class); - VmInfoDAO vmInfoDao = mock(VmInfoDAO.class); - - VmRef matching = mock(VmRef.class); - - VmInfo vmInfo = mock(VmInfo.class); - when(vmInfoDao.getVmInfo(matching)).thenReturn(vmInfo); - - RequestResponseListener listener = mock(RequestResponseListener.class); - - KillVMAction action = new KillVMAction(agentDao, vmInfoDao, listener); - - VmFilter filter = action.getFilter(); - - when(vmInfo.isAlive()).thenReturn(true); - assertTrue(filter.matches(matching)); - - when(vmInfo.isAlive()).thenReturn(false); - assertFalse(filter.matches(matching)); - } - - @Test - public void canQueueKillRequest() { - VmRef ref = mock(VmRef.class); - HostRef hostref = mock(HostRef.class); - when(ref.getAgent()).thenReturn(hostref); - String agentAddress = "127.0.0.1:8888"; - - AgentInformation agentInfo = mock(AgentInformation.class); - when(agentInfo.getConfigListenAddress()).thenReturn(agentAddress); - - AgentInfoDAO agentDao = mock(AgentInfoDAO.class); - when(agentDao.getAgentInformation(hostref)).thenReturn(agentInfo); - VmInfoDAO vmInfoDao = mock(VmInfoDAO.class); - - RequestResponseListener agentResponseListener = mock(RequestResponseListener.class); - - final Request req = mock(Request.class); - KillVMAction action = new KillVMAction(agentDao, vmInfoDao, agentResponseListener) { - @Override - Request getKillRequest(InetSocketAddress target) { - return req; - } - }; - OSGIUtils utils = mock(OSGIUtils.class); - PowerMockito.mockStatic(OSGIUtils.class); - when(OSGIUtils.getInstance()).thenReturn(utils); - RequestQueue queue = mock(RequestQueue.class); - when(utils.getService(RequestQueue.class)).thenReturn(queue); - action.execute(ref); - ArgumentCaptor<String> vmIdParamCaptor = ArgumentCaptor - .forClass(String.class); - verify(req).setParameter(vmIdParamCaptor.capture(), any(String.class)); - assertEquals("vm-id", vmIdParamCaptor.getValue()); - verify(req).addListener(agentResponseListener); - ArgumentCaptor<String> receiverCaptor = ArgumentCaptor - .forClass(String.class); - verify(req).setReceiver(receiverCaptor.capture()); - assertEquals( - "com.redhat.thermostat.agent.killvm.internal.KillVmReceiver", - receiverCaptor.getValue()); - verify(queue).putRequest(req); - } - -}
--- a/client/killvm/src/test/java/com/redhat/thermostat/client/killvm/internal/SwingVMKilledListenerTest.java Tue Oct 02 17:43:44 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,97 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.killvm.internal; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.net.SocketAddress; - -import org.junit.Test; - -import com.redhat.thermostat.common.command.Request; -import com.redhat.thermostat.common.command.Response; -import com.redhat.thermostat.common.command.Response.ResponseType; - -public class SwingVMKilledListenerTest { - - @Test - public void exceptionShowsError() { - ResponseActionListener listener = new ResponseActionListener(); - Request request = mock(Request.class); - Response resp = new Response(ResponseType.EXCEPTION); - listener.fireComplete(request, resp); - assertTrue(listener.isActionPerformed()); - } - - @Test - public void errorShowsError() { - ResponseActionListener listener = new ResponseActionListener(); - Request request = mock(Request.class); - Response resp = new Response(ResponseType.ERROR); - listener.fireComplete(request, resp); - assertTrue(listener.isActionPerformed()); - } - - @Test - public void okShowsNoMessage() { - ResponseActionListener listener = new ResponseActionListener(); - Request request = mock(Request.class); - SocketAddress addr = mock(SocketAddress.class); - when(request.getTarget()).thenReturn(addr); - Response resp = new Response(ResponseType.OK); - listener.fireComplete(request, resp); - assertFalse(listener.isActionPerformed()); - } - - private class ResponseActionListener extends SwingVMKilledListener { - - private boolean actionPerformed = false; - - public boolean isActionPerformed() { - return actionPerformed; - } - - @Override - protected void showErrorMessage(final String message) { - actionPerformed = true; - } - - } -}
--- a/client/killvm/src/test/java/com/redhat/thermostat/client/killvm/locale/TranslateTest.java Tue Oct 02 17:43:44 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.killvm.locale; - -import java.io.IOException; -import java.util.Locale; -import java.util.Properties; - -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.redhat.thermostat.common.locale.Translate; - -public class TranslateTest { - - private Locale lang; - private Translate t; - - @Before - public void setUp() { - this.lang = Locale.getDefault(); - Locale.setDefault(Locale.US); - t = LocaleResources.createLocalizer(); - } - - @After - public void tearDown() { - Locale.setDefault(lang); - t = null; - } - - @Test - public void testLocalizeWithoutArguments() { - String testString = t.localize(LocaleResources.MISSING_INFO); - Assert.assertEquals("Missing Information", testString); - } - - @Test - public void testLocalizedStringsArePresent() throws IOException { - - String stringsResource = "/" + LocaleResources.RESOURCE_BUNDLE.replace(".", "/") + ".properties"; - - Properties props = new Properties(); - props.load(getClass().getResourceAsStream(stringsResource)); - - Assert.assertEquals(LocaleResources.values().length, props.values().size()); - for (LocaleResources resource : LocaleResources.values()) { - Assert.assertTrue("missing property from resource bound file: " + resource, - props.containsKey(resource.name())); - } - } - -}
--- a/client/pom.xml Tue Oct 02 17:43:44 2012 -0400 +++ b/client/pom.xml Thu Sep 27 14:27:26 2012 +0200 @@ -61,7 +61,6 @@ <modules> <module>core</module> <module>vmclassstat</module> - <module>killvm</module> <module>heapdumper</module> <module>memory-stats-panel</module> <module>living-vm-filter</module>
--- a/distribution/config/commands/agent.properties Tue Oct 02 17:43:44 2012 -0400 +++ b/distribution/config/commands/agent.properties Thu Sep 27 14:27:26 2012 +0200 @@ -5,7 +5,7 @@ thermostat-common-command-@project.version@.jar, \ thermostat-agent-command-@project.version@.jar, \ thermostat-agent-heapdumper-@project.version@.jar, \ - thermostat-agent-killvm-@project.version@.jar, \ + thermostat-killvm-agent-@project.version@.jar, \ thermostat-thread-collector-@project.version@.jar, \ thermostat-thread-harvester-@project.version@.jar
--- a/distribution/config/commands/gui.properties Tue Oct 02 17:43:44 2012 -0400 +++ b/distribution/config/commands/gui.properties Thu Sep 27 14:27:26 2012 +0200 @@ -3,7 +3,7 @@ thermostat-client-core-@project.version@.jar, \ thermostat-client-command-@project.version@.jar, \ thermostat-client-heapdumper-@project.version@.jar, \ - thermostat-client-killvm-@project.version@.jar, \ + thermostat-killvm-client-swing-@project.version@.jar, \ thermostat-client-vmclassstat-@project.version@.jar, \ thermostat-osgi-living-vm-filter-@project.version@.jar, \ thermostat-osgi-memory-stats-panel-@project.version@.jar, \ @@ -21,4 +21,4 @@ usage = thermostat gui # This command does not have any options -#options = \ No newline at end of file +#options =
--- a/distribution/pom.xml Tue Oct 02 17:43:44 2012 -0400 +++ b/distribution/pom.xml Thu Sep 27 14:27:26 2012 +0200 @@ -294,10 +294,15 @@ </dependency> <dependency> <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-agent-killvm</artifactId> + <artifactId>thermostat-killvm-agent</artifactId> <version>${project.version}</version> </dependency> <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-killvm-client-swing</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>com.redhat.thermostat</groupId> <artifactId>thermostat-common-core</artifactId> <version>${project.version}</version> @@ -314,11 +319,6 @@ </dependency> <dependency> <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-client-killvm</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.redhat.thermostat</groupId> <artifactId>thermostat-client-heapdumper</artifactId> <version>${project.version}</version> </dependency>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/agent/pom.xml Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright 2012 Red Hat, Inc. + + This file is part of Thermostat. + + Thermostat is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + Thermostat is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Thermostat; see the file COPYING. If not see + <http://www.gnu.org/licenses />. + + Linking this code with other modules is making a combined work + based on this code. Thus, the terms and conditions of the GNU + General Public License cover the whole combination. + + As a special exception, the copyright holders of this code give + you permission to link this code with independent modules to + produce an executable, regardless of the license terms of these + independent modules, and to copy and distribute the resulting + executable under terms of your choice, provided that you also + meet, for each linked independent module, the terms and conditions + of the license of that module. An independent module is a module + which is not derived from or based on this code. If you modify + this code, you may extend this exception to your version of the + library, but you are not obligated to do so. If you do not wish + to do so, delete this exception statement from your version. + +--> +<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> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-killvm</artifactId> + <version>0.5.0-SNAPSHOT</version> + </parent> + + <artifactId>thermostat-killvm-agent</artifactId> + <packaging>bundle</packaging> + + <name>Thermostat Agent Kill VM</name> + + <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.powermock</groupId> + <artifactId>powermock-api-mockito</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-agent-core</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-agent-command</artifactId> + <version>${project.version}</version> + </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-launcher</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + </dependency> + </dependencies> + + <build> + <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-Activator>com.redhat.thermostat.killvm.agent.internal.Activator</Bundle-Activator> + <Bundle-SymbolicName>com.redhat.thermostat.killvm.agent</Bundle-SymbolicName> + <Private-Package>com.redhat.thermostat.killvm.agent.internal</Private-Package> + <!-- Do not autogenerate uses clauses in Manifests --> + <_nouses>true</_nouses> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + +</project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/agent/src/main/java/com/redhat/thermostat/killvm/agent/internal/Activator.java Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,64 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.killvm.agent.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.agent.command.ReceiverRegistry; +import com.redhat.thermostat.common.utils.OSGIUtils; +import com.redhat.thermostat.service.process.UNIXProcessHandler; + +public class Activator implements BundleActivator { + + private ReceiverRegistry registry; + private UNIXProcessHandler unixService; + + @Override + public void start(final BundleContext context) throws Exception { + unixService = OSGIUtils.getInstance().getService(UNIXProcessHandler.class); + registry = new ReceiverRegistry(context); + registry.registerReceiver(new KillVmReceiver(unixService)); + } + + @Override + public void stop(BundleContext context) throws Exception { + // This only unregisters receivers which we've registered + // in start() + registry.unregisterReceivers(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/agent/src/main/java/com/redhat/thermostat/killvm/agent/internal/KillVmReceiver.java Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,70 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.killvm.agent.internal; + +import java.util.logging.Logger; + +import com.redhat.thermostat.agent.command.RequestReceiver; +import com.redhat.thermostat.common.command.Request; +import com.redhat.thermostat.common.command.Response; +import com.redhat.thermostat.common.command.Response.ResponseType; +import com.redhat.thermostat.service.process.UNIXProcessHandler; +import com.redhat.thermostat.service.process.UNIXSignal; + +public class KillVmReceiver implements RequestReceiver { + + private final UNIXProcessHandler unixService; + private static final Logger log = Logger.getLogger(KillVmReceiver.class.getName()); + + public KillVmReceiver(UNIXProcessHandler unixService) { + this.unixService = unixService; + } + + @Override + public Response receive(Request request) { + if (unixService == null) { + // no dice, should have service by now + log.severe("Unix service null!"); + return new Response(ResponseType.ERROR); + } + String vmId = request.getParameter("vm-id"); + unixService.sendSignal(vmId, UNIXSignal.TERM); + log.fine("Killed VM with ID " + vmId); + return new Response(ResponseType.OK); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/agent/src/test/java/com/redhat/thermostat/killvm/agent/internal/ActivatorTest.java Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,89 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.killvm.agent.internal; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Dictionary; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.redhat.thermostat.agent.command.RequestReceiver; +import com.redhat.thermostat.common.utils.OSGIUtils; +import com.redhat.thermostat.killvm.agent.internal.Activator; +import com.redhat.thermostat.killvm.agent.internal.KillVmReceiver; +import com.redhat.thermostat.service.process.UNIXProcessHandler; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(OSGIUtils.class) +public class ActivatorTest { + + /** + * Makes sure receiver is registered and unix service gets set. + * + * @throws Exception + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void startStopTest() throws Exception { + OSGIUtils utils = mock(OSGIUtils.class); + PowerMockito.mockStatic(OSGIUtils.class); + when(OSGIUtils.getInstance()).thenReturn(utils); + BundleContext ctx = mock(BundleContext.class); + ServiceRegistration serviceReg = mock(ServiceRegistration.class); + when(ctx.registerService(anyString(), any(), any(Dictionary.class))).thenReturn(serviceReg); + Activator activator = new Activator(); + activator.start(ctx); + verify(utils).getService(UNIXProcessHandler.class); + verify(ctx).registerService(eq(RequestReceiver.class.getName()), isA(KillVmReceiver.class), any(Dictionary.class)); + activator.stop(ctx); + verify(serviceReg).unregister(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/agent/src/test/java/com/redhat/thermostat/killvm/agent/internal/KillVmReceiverTest.java Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,103 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.killvm.agent.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +import org.junit.Test; + +import com.redhat.thermostat.common.command.Request; +import com.redhat.thermostat.common.command.Response; +import com.redhat.thermostat.common.command.Response.ResponseType; +import com.redhat.thermostat.killvm.agent.internal.KillVmReceiver; +import com.redhat.thermostat.service.process.UNIXProcessHandler; + +public class KillVmReceiverTest { + + @Test + public void receiverReturnsOk() { + UNIXProcessHandler proc = mock(UNIXProcessHandler.class); + KillVmReceiver receiver = new KillVmReceiver(proc); + Request req = mock(Request.class); + Response response = receiver.receive(req); + assertEquals(ResponseType.OK, response.getType()); + } + + @Test + public void receiverReturnsError() { + KillVmReceiver receiver = new KillVmReceiver(null); + Request req = mock(Request.class); + Response response = receiver.receive(req); + assertEquals(ResponseType.ERROR, response.getType()); + } + + /** + * When a request is issued the fully qualified receiver class name is set + * via {@link Request#setReceiver(String)}. This test makes sure that this + * class is actually where it's supposed to be. + * + * @throws Exception + */ + @Test + public void killVmReceiverIsInAppropriatePackage() { + Class<?> receiver = null; + try { + // com.redhat.thermostat.client.killvm.internal.KillVMAction uses + // this class name. + receiver = Class + .forName("com.redhat.thermostat.killvm.agent.internal.KillVmReceiver"); + } catch (ClassNotFoundException e) { + fail("com.redhat.thermostat.agent.killvm.internal.KillVmReceiver class not found, but used by some request!"); + } + try { + Constructor<?> constructor = receiver.getConstructor(UNIXProcessHandler.class); + UNIXProcessHandler service = mock(UNIXProcessHandler.class); + Object instance = constructor.newInstance(service); + Method m = receiver.getMethod("receive", Request.class); + Request req = mock(Request.class); + m.invoke(instance, req); + } catch (Exception e) { + e.printStackTrace(); + fail("cannot invoke receiver's receive method"); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/client-swing/pom.xml Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,99 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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-killvm</artifactId> + <groupId>com.redhat.thermostat</groupId> + <version>0.5.0-SNAPSHOT</version> + </parent> + <artifactId>thermostat-killvm-client-swing</artifactId> + <packaging>bundle</packaging> + <name>Thermostat Client Terminate VM plugin</name> + <build> + <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-Activator>com.redhat.thermostat.killvm.client.internal.Activator</Bundle-Activator> + <Bundle-SymbolicName>com.redhat.thermostat.killvm.client</Bundle-SymbolicName> + <Export-Package>com.redhat.thermostat.killvm.client.locale</Export-Package> + <Private-Package>com.redhat.thermostat.killvm.client.internal</Private-Package> + </instructions> + <!-- Do not autogenerate uses clauses in Manifests --> + <_nouses>true</_nouses> + </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.powermock</groupId> + <artifactId>powermock-api-mockito</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.easytesting</groupId> + <artifactId>fest-swing</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>net.java.openjdk.cacio</groupId> + <artifactId>cacio-tta</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-client-core</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-client-command</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-common-command</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-osgi-process-handler</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> +</project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/client-swing/src/main/java/com/redhat/thermostat/killvm/client/internal/Activator.java Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,90 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.killvm.client.internal; + +import java.util.Map; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +import com.redhat.thermostat.client.osgi.service.ContextAction; +import com.redhat.thermostat.client.osgi.service.VMContextAction; +import com.redhat.thermostat.common.MultipleServiceTracker; +import com.redhat.thermostat.common.MultipleServiceTracker.Action; +import com.redhat.thermostat.common.dao.AgentInfoDAO; +import com.redhat.thermostat.common.dao.VmInfoDAO; + +public class Activator implements BundleActivator { + + private MultipleServiceTracker killVmActionTracker; + private ServiceRegistration killActionRegistration; + + @Override + public void start(final BundleContext context) throws Exception { + Class<?>[] serviceDeps = new Class<?>[] { + AgentInfoDAO.class, + VmInfoDAO.class, + ContextAction.class, + }; + + killVmActionTracker = new MultipleServiceTracker(context, serviceDeps, new Action() { + @Override + public void dependenciesAvailable(Map<String, Object> services) { + AgentInfoDAO agentDao = (AgentInfoDAO) services.get(AgentInfoDAO.class.getName()); + VmInfoDAO vmDao = (VmInfoDAO) services.get(VmInfoDAO.class.getName()); + KillVMAction service = new KillVMAction(agentDao, vmDao, new SwingVMKilledListener()); + killActionRegistration = context.registerService(VMContextAction.class.getName(), service, null); + } + + @Override + public void dependenciesUnavailable() { + killActionRegistration.unregister(); + killActionRegistration = null; + } + }); + + killVmActionTracker.open(); + } + + @Override + public void stop(BundleContext context) throws Exception { + killVmActionTracker.close(); + // service automatically unregistered on bundle stop + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/client-swing/src/main/java/com/redhat/thermostat/killvm/client/internal/KillVMAction.java Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,120 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.killvm.client.internal; + +import java.net.InetSocketAddress; +import java.util.Objects; + +import com.redhat.thermostat.client.command.RequestQueue; +import com.redhat.thermostat.client.osgi.service.VMContextAction; +import com.redhat.thermostat.client.osgi.service.VmFilter; +import com.redhat.thermostat.common.command.Request; +import com.redhat.thermostat.common.command.Request.RequestType; +import com.redhat.thermostat.common.command.RequestResponseListener; +import com.redhat.thermostat.common.dao.AgentInfoDAO; +import com.redhat.thermostat.common.dao.VmInfoDAO; +import com.redhat.thermostat.common.dao.VmRef; +import com.redhat.thermostat.common.locale.Translate; +import com.redhat.thermostat.common.model.VmInfo; +import com.redhat.thermostat.common.utils.OSGIUtils; +import com.redhat.thermostat.killvm.client.locale.LocaleResources; + +/** + * Implements the {@link VMContextAction} entry point to provide a kill switch + * for the currently selected Virtual Machine. + */ +public class KillVMAction implements VMContextAction { + + private static final String RECEIVER = "com.redhat.thermostat.killvm.agent.internal.KillVmReceiver"; + private final AgentInfoDAO agentDao; + private final VmInfoDAO vmDao; + private final Translate t; + private final RequestResponseListener listener; + + public KillVMAction(AgentInfoDAO agentDao, VmInfoDAO vmDao, RequestResponseListener listener) { + Objects.requireNonNull(listener, "Listener can't be null"); + this.agentDao = agentDao; + this.vmDao = vmDao; + this.t = LocaleResources.createLocalizer(); + this.listener = listener; + } + + @Override + public String getName() { + return t.localize(LocaleResources.ACTION_NAME); + } + + @Override + public String getDescription() { + return t.localize(LocaleResources.ACTION_DESCRIPTION); + } + + @Override + public void execute(VmRef reference) { + String address = agentDao.getAgentInformation(reference.getAgent()).getConfigListenAddress(); + + String [] host = address.split(":"); + InetSocketAddress target = new InetSocketAddress(host[0], Integer.parseInt(host[1])); + Request murderer = getKillRequest(target); + murderer.setParameter("vm-id", reference.getIdString()); + murderer.setReceiver(RECEIVER); + murderer.addListener(listener); + + RequestQueue queue = OSGIUtils.getInstance().getService(RequestQueue.class); + queue.putRequest(murderer); + } + + // testing hook; keep this package private + Request getKillRequest(InetSocketAddress target) { + return new Request(RequestType.RESPONSE_EXPECTED, target); + } + + @Override + public VmFilter getFilter() { + return new LocalAndAliveFilter(); + } + + private class LocalAndAliveFilter implements VmFilter { + + @Override + public boolean matches(VmRef ref) { + VmInfo vmInfo = vmDao.getVmInfo(ref); + return vmInfo.isAlive(); + } + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/client-swing/src/main/java/com/redhat/thermostat/killvm/client/internal/SwingVMKilledListener.java Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,102 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.killvm.client.internal; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; + +import com.redhat.thermostat.common.command.Request; +import com.redhat.thermostat.common.command.RequestResponseListener; +import com.redhat.thermostat.common.command.Response; +import com.redhat.thermostat.common.locale.Translate; +import com.redhat.thermostat.killvm.client.locale.LocaleResources; + +public class SwingVMKilledListener implements RequestResponseListener { + + private final Translate t; + private static final Logger logger = Logger + .getLogger(SwingVMKilledListener.class.getName()); + + public SwingVMKilledListener() { + this.t = LocaleResources.createLocalizer(); + } + + @Override + public void fireComplete(Request request, Response response) { + switch (response.getType()) { + case EXCEPTION: + logger.log(Level.SEVERE, + "Exception response from kill VM request. Command channel failure?"); + showErrorMessage(t.localize(LocaleResources.KILL_ACTION_EXCEPTION_RESPONSE_MSG)); + break; + case ERROR: + String vmId = request.getParameter("vm-id"); + logger.log(Level.SEVERE, + "Kill request error for VM ID " + + vmId); + showErrorMessage(t.localize(LocaleResources.KILL_ACTION_ERROR_RESPONSE_MSG, vmId)); + break; + case PONG: // fall-through, also OK :) + case OK: + logger.log(Level.INFO, + "VM with id " + request.getParameter("vm-id") + + " killed on host " + + request.getTarget().toString()); + break; + default: + logger.log(Level.WARNING, "Unknown result from KILL VM command."); + break; + } + } + + /* + * protected for testing + * + */ + protected void showErrorMessage(final String message) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + JOptionPane.showMessageDialog(null, message, "", + JOptionPane.ERROR_MESSAGE); + } + }); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/client-swing/src/main/java/com/redhat/thermostat/killvm/client/locale/LocaleResources.java Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,55 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.killvm.client.locale; + +import com.redhat.thermostat.common.locale.Translate; + +public enum LocaleResources { + + ACTION_NAME, + ACTION_DESCRIPTION, + KILL_ACTION_EXCEPTION_RESPONSE_MSG, + KILL_ACTION_ERROR_RESPONSE_MSG, + MISSING_INFO; + + public static final String RESOURCE_BUNDLE = + "com.redhat.thermostat.killvm.client.locale.strings"; + + public static Translate createLocalizer() { + return new Translate(RESOURCE_BUNDLE); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/client-swing/src/main/resources/com/redhat/thermostat/killvm/client/locale/strings.properties Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,5 @@ +ACTION_NAME = Kill Application +ACTION_DESCRIPTION = Kill the selected VM Process +MISSING_INFO = Missing Information +KILL_ACTION_EXCEPTION_RESPONSE_MSG = Channel Transport Error. Please check your configuration! +KILL_ACTION_ERROR_RESPONSE_MSG = Failed to kill VM with pid {0} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/client-swing/src/test/java/com/redhat/thermostat/killvm/client/internal/ActivatorTest.java Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,73 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.killvm.client.internal; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Dictionary; + +import org.junit.Ignore; +import org.junit.Test; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +import com.redhat.thermostat.client.osgi.service.VMContextAction; +import com.redhat.thermostat.killvm.client.internal.Activator; +import com.redhat.thermostat.killvm.client.internal.KillVMAction; + +public class ActivatorTest { + + @Ignore(value="testing activator is slightly more complex") + @Test + public void startRegistersKillVMAction() throws Exception { + BundleContext ctx = mock(BundleContext.class); + ServiceRegistration serviceReg = mock(ServiceRegistration.class); + when(ctx.registerService(anyString(), any(), any(Dictionary.class))) + .thenReturn(serviceReg); + Activator activator = new Activator(); + activator.start(ctx); + verify(ctx).registerService(eq(VMContextAction.class.getName()), + isA(KillVMAction.class), any(Dictionary.class)); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/client-swing/src/test/java/com/redhat/thermostat/killvm/client/internal/KillVMActionTest.java Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,139 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.killvm.client.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.net.InetSocketAddress; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.redhat.thermostat.client.command.RequestQueue; +import com.redhat.thermostat.client.osgi.service.VmFilter; +import com.redhat.thermostat.common.command.Request; +import com.redhat.thermostat.common.command.RequestResponseListener; +import com.redhat.thermostat.common.dao.AgentInfoDAO; +import com.redhat.thermostat.common.dao.HostRef; +import com.redhat.thermostat.common.dao.VmInfoDAO; +import com.redhat.thermostat.common.dao.VmRef; +import com.redhat.thermostat.common.model.AgentInformation; +import com.redhat.thermostat.common.model.VmInfo; +import com.redhat.thermostat.common.utils.OSGIUtils; +import com.redhat.thermostat.killvm.client.internal.KillVMAction; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(OSGIUtils.class) +public class KillVMActionTest { + + @Test + public void killVMFilterOnlyMatchesLiveVMs() { + AgentInfoDAO agentDao = mock(AgentInfoDAO.class); + VmInfoDAO vmInfoDao = mock(VmInfoDAO.class); + + VmRef matching = mock(VmRef.class); + + VmInfo vmInfo = mock(VmInfo.class); + when(vmInfoDao.getVmInfo(matching)).thenReturn(vmInfo); + + RequestResponseListener listener = mock(RequestResponseListener.class); + + KillVMAction action = new KillVMAction(agentDao, vmInfoDao, listener); + + VmFilter filter = action.getFilter(); + + when(vmInfo.isAlive()).thenReturn(true); + assertTrue(filter.matches(matching)); + + when(vmInfo.isAlive()).thenReturn(false); + assertFalse(filter.matches(matching)); + } + + @Test + public void canQueueKillRequest() { + VmRef ref = mock(VmRef.class); + HostRef hostref = mock(HostRef.class); + when(ref.getAgent()).thenReturn(hostref); + String agentAddress = "127.0.0.1:8888"; + + AgentInformation agentInfo = mock(AgentInformation.class); + when(agentInfo.getConfigListenAddress()).thenReturn(agentAddress); + + AgentInfoDAO agentDao = mock(AgentInfoDAO.class); + when(agentDao.getAgentInformation(hostref)).thenReturn(agentInfo); + VmInfoDAO vmInfoDao = mock(VmInfoDAO.class); + + RequestResponseListener agentResponseListener = mock(RequestResponseListener.class); + + final Request req = mock(Request.class); + KillVMAction action = new KillVMAction(agentDao, vmInfoDao, agentResponseListener) { + @Override + Request getKillRequest(InetSocketAddress target) { + return req; + } + }; + OSGIUtils utils = mock(OSGIUtils.class); + PowerMockito.mockStatic(OSGIUtils.class); + when(OSGIUtils.getInstance()).thenReturn(utils); + RequestQueue queue = mock(RequestQueue.class); + when(utils.getService(RequestQueue.class)).thenReturn(queue); + action.execute(ref); + ArgumentCaptor<String> vmIdParamCaptor = ArgumentCaptor + .forClass(String.class); + verify(req).setParameter(vmIdParamCaptor.capture(), any(String.class)); + assertEquals("vm-id", vmIdParamCaptor.getValue()); + verify(req).addListener(agentResponseListener); + ArgumentCaptor<String> receiverCaptor = ArgumentCaptor + .forClass(String.class); + verify(req).setReceiver(receiverCaptor.capture()); + assertEquals( + "com.redhat.thermostat.killvm.agent.internal.KillVmReceiver", + receiverCaptor.getValue()); + verify(queue).putRequest(req); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/client-swing/src/test/java/com/redhat/thermostat/killvm/client/internal/SwingVMKilledListenerTest.java Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,98 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.killvm.client.internal; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.net.SocketAddress; + +import org.junit.Test; + +import com.redhat.thermostat.common.command.Request; +import com.redhat.thermostat.common.command.Response; +import com.redhat.thermostat.common.command.Response.ResponseType; +import com.redhat.thermostat.killvm.client.internal.SwingVMKilledListener; + +public class SwingVMKilledListenerTest { + + @Test + public void exceptionShowsError() { + ResponseActionListener listener = new ResponseActionListener(); + Request request = mock(Request.class); + Response resp = new Response(ResponseType.EXCEPTION); + listener.fireComplete(request, resp); + assertTrue(listener.isActionPerformed()); + } + + @Test + public void errorShowsError() { + ResponseActionListener listener = new ResponseActionListener(); + Request request = mock(Request.class); + Response resp = new Response(ResponseType.ERROR); + listener.fireComplete(request, resp); + assertTrue(listener.isActionPerformed()); + } + + @Test + public void okShowsNoMessage() { + ResponseActionListener listener = new ResponseActionListener(); + Request request = mock(Request.class); + SocketAddress addr = mock(SocketAddress.class); + when(request.getTarget()).thenReturn(addr); + Response resp = new Response(ResponseType.OK); + listener.fireComplete(request, resp); + assertFalse(listener.isActionPerformed()); + } + + private class ResponseActionListener extends SwingVMKilledListener { + + private boolean actionPerformed = false; + + public boolean isActionPerformed() { + return actionPerformed; + } + + @Override + protected void showErrorMessage(final String message) { + actionPerformed = true; + } + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/client-swing/src/test/java/com/redhat/thermostat/killvm/client/locale/TranslateTest.java Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,91 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.killvm.client.locale; + +import java.io.IOException; +import java.util.Locale; +import java.util.Properties; + +import junit.framework.Assert; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.redhat.thermostat.common.locale.Translate; +import com.redhat.thermostat.killvm.client.locale.LocaleResources; + +public class TranslateTest { + + private Locale lang; + private Translate t; + + @Before + public void setUp() { + this.lang = Locale.getDefault(); + Locale.setDefault(Locale.US); + t = LocaleResources.createLocalizer(); + } + + @After + public void tearDown() { + Locale.setDefault(lang); + t = null; + } + + @Test + public void testLocalizeWithoutArguments() { + String testString = t.localize(LocaleResources.MISSING_INFO); + Assert.assertEquals("Missing Information", testString); + } + + @Test + public void testLocalizedStringsArePresent() throws IOException { + + String stringsResource = "/" + LocaleResources.RESOURCE_BUNDLE.replace(".", "/") + ".properties"; + + Properties props = new Properties(); + props.load(getClass().getResourceAsStream(stringsResource)); + + Assert.assertEquals(LocaleResources.values().length, props.values().size()); + for (LocaleResources resource : LocaleResources.values()) { + Assert.assertTrue("missing property from resource bound file: " + resource, + props.containsKey(resource.name())); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/killvm/pom.xml Thu Sep 27 14:27:26 2012 +0200 @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright 2012 Red Hat, Inc. + + This file is part of Thermostat. + + Thermostat is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + Thermostat is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Thermostat; see the file COPYING. If not see + <http://www.gnu.org/licenses />. + + Linking this code with other modules is making a combined work + based on this code. Thus, the terms and conditions of the GNU + General Public License cover the whole combination. + + As a special exception, the copyright holders of this code give + you permission to link this code with independent modules to + produce an executable, regardless of the license terms of these + independent modules, and to copy and distribute the resulting + executable under terms of your choice, provided that you also + meet, for each linked independent module, the terms and conditions + of the license of that module. An independent module is a module + which is not derived from or based on this code. If you modify + this code, you may extend this exception to your version of the + library, but you are not obligated to do so. If you do not wish + to do so, delete this exception statement from your version. + +--> +<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> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat</artifactId> + <version>0.5.0-SNAPSHOT</version> + </parent> + + <artifactId>thermostat-killvm</artifactId> + <packaging>pom</packaging> + + <name>Thermostat Kill VM Plugins</name> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <modules> + <module>client-swing</module> + <module>agent</module> + </modules> +</project> +