Mercurial > hg > thermostat-ng > agent
changeset 2632:a5387a1249f7
Ready agent for communication with web gateway
Reviewed-by: neugens
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-May/022936.html
author | Elliott Baron <ebaron@redhat.com> |
---|---|
date | Fri, 05 May 2017 12:11:28 -0400 |
parents | 690d9498ebb2 |
children | 1887270ae88b |
files | agent/cli/src/main/java/com/redhat/thermostat/agent/cli/internal/Activator.java agent/cli/src/main/java/com/redhat/thermostat/agent/cli/internal/AgentApplication.java agent/cli/src/main/java/com/redhat/thermostat/agent/cli/internal/ServiceCommand.java agent/cli/src/test/java/com/redhat/thermostat/agent/cli/internal/ActivatorTest.java agent/cli/src/test/java/com/redhat/thermostat/agent/cli/internal/AgentApplicationTest.java agent/cli/src/test/java/com/redhat/thermostat/agent/cli/internal/ServiceCommandTest.java agent/core/src/main/java/com/redhat/thermostat/agent/Agent.java agent/core/src/main/java/com/redhat/thermostat/agent/internal/Activator.java agent/core/src/test/java/com/redhat/thermostat/agent/AgentTest.java distribution/assembly/plugin-assembly.xml distribution/pom.xml |
diffstat | 11 files changed, 50 insertions(+), 838 deletions(-) [+] |
line wrap: on
line diff
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/internal/Activator.java Fri May 05 12:10:15 2017 -0400 +++ b/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/internal/Activator.java Fri May 05 12:11:28 2017 -0400 @@ -38,9 +38,6 @@ import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; -import org.osgi.util.tracker.ServiceTrackerCustomizer; import com.redhat.thermostat.common.ExitStatus; import com.redhat.thermostat.common.MultipleServiceTracker; @@ -49,7 +46,6 @@ import com.redhat.thermostat.common.cli.CommandRegistry; import com.redhat.thermostat.common.cli.CommandRegistryImpl; import com.redhat.thermostat.shared.config.SSLConfiguration; -import com.redhat.thermostat.storage.core.StorageCredentials; import com.redhat.thermostat.storage.core.WriterID; public class Activator implements BundleActivator { @@ -57,7 +53,6 @@ private CommandRegistry reg; private AgentApplication agentApplication; private MultipleServiceTracker tracker; - private ServiceTracker<StorageCredentials, StorageCredentials> credsTracker; @Override public void start(final BundleContext context) throws Exception { @@ -74,9 +69,7 @@ public void dependenciesAvailable(DependencyProvider services) { ExitStatus exitStatus = services.get(ExitStatus.class); WriterID writerID = services.get(WriterID.class); - SSLConfiguration sslConf = services.get(SSLConfiguration.class); - agentApplication = new AgentApplication(context, exitStatus, writerID, sslConf); - reg.registerCommand("service", new ServiceCommand(context)); + agentApplication = new AgentApplication(context, exitStatus, writerID); reg.registerCommand("agent", agentApplication); } @@ -86,34 +79,7 @@ reg.unregisterCommands(); } }); - credsTracker = new ServiceTracker<StorageCredentials, StorageCredentials>( - context, StorageCredentials.class, new ServiceTrackerCustomizer<StorageCredentials, StorageCredentials>() { - - @Override - public StorageCredentials addingService(ServiceReference<StorageCredentials> ref) { - StorageCredentials creds = context.getService(ref); - agentApplication.setStorageCredentials(creds); - return creds; - } - - @Override - public void modifiedService(ServiceReference<StorageCredentials> ref, - StorageCredentials creds) { - // nothing - } - - @Override - public void removedService(ServiceReference<StorageCredentials> ref, - StorageCredentials arg1) { - if (agentApplication != null) { - agentApplication.setStorageCredentials(null); // remove creds - } - context.ungetService(ref); - } - - }); tracker.open(); - credsTracker.open(); } @Override @@ -124,7 +90,6 @@ agentApplication.shutdown(ExitStatus.EXIT_SUCCESS); } reg.unregisterCommands(); - credsTracker.close(); tracker.close(); } }
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/internal/AgentApplication.java Fri May 05 12:10:15 2017 -0400 +++ b/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/internal/AgentApplication.java Fri May 05 12:11:28 2017 -0400 @@ -45,11 +45,7 @@ import org.osgi.framework.ServiceReference; import org.osgi.util.tracker.ServiceTracker; -import sun.misc.Signal; -import sun.misc.SignalHandler; - import com.redhat.thermostat.agent.Agent; -import com.redhat.thermostat.agent.cli.internal.locale.LocaleResources; import com.redhat.thermostat.agent.command.ConfigurationServer; import com.redhat.thermostat.agent.config.AgentConfigsUtils; import com.redhat.thermostat.agent.config.AgentOptionParser; @@ -65,24 +61,17 @@ import com.redhat.thermostat.common.cli.Arguments; import com.redhat.thermostat.common.cli.CommandContext; import com.redhat.thermostat.common.cli.CommandException; -import com.redhat.thermostat.common.cli.DependencyServices; import com.redhat.thermostat.common.tools.ApplicationState; import com.redhat.thermostat.common.utils.HostPortPair; import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.shared.config.InvalidConfigurationException; -import com.redhat.thermostat.shared.config.SSLConfiguration; -import com.redhat.thermostat.shared.locale.Translate; -import com.redhat.thermostat.storage.core.Connection.ConnectionListener; -import com.redhat.thermostat.storage.core.Connection.ConnectionStatus; -import com.redhat.thermostat.storage.core.ConnectionException; -import com.redhat.thermostat.storage.core.DbService; -import com.redhat.thermostat.storage.core.DbServiceFactory; -import com.redhat.thermostat.storage.core.Storage; -import com.redhat.thermostat.storage.core.StorageCredentials; import com.redhat.thermostat.storage.core.WriterID; import com.redhat.thermostat.storage.dao.AgentInfoDAO; import com.redhat.thermostat.storage.dao.BackendInfoDAO; +import sun.misc.Signal; +import sun.misc.SignalHandler; + @SuppressWarnings("restriction") public final class AgentApplication extends AbstractStateNotifyingCommand { @@ -100,37 +89,30 @@ private static final String SIGTERM_NAME = "TERM"; private static final Logger logger = LoggingUtils.getLogger(AgentApplication.class); - private static final Translate<LocaleResources> t = LocaleResources.createLocalizer(); private final BundleContext bundleContext; private final ConfigurationCreator configurationCreator; private AgentStartupConfiguration configuration; private AgentOptionParser parser; - private DbServiceFactory dbServiceFactory; @SuppressWarnings("rawtypes") private ServiceTracker configServerTracker; private MultipleServiceTracker depTracker; private final ExitStatus exitStatus; private final WriterID writerId; - private final SSLConfiguration sslConf; - private final DependencyServices depServices; private CountDownLatch shutdownLatch; private CustomSignalHandler handler; - public AgentApplication(BundleContext bundleContext, ExitStatus exitStatus, WriterID writerId, SSLConfiguration sslConf) { - this(bundleContext, exitStatus, writerId, sslConf, new DependencyServices(), new ConfigurationCreator(), new DbServiceFactory()); + public AgentApplication(BundleContext bundleContext, ExitStatus exitStatus, WriterID writerId) { + this(bundleContext, exitStatus, writerId, new ConfigurationCreator()); } - AgentApplication(BundleContext bundleContext, ExitStatus exitStatus, WriterID writerId, SSLConfiguration sslConf, DependencyServices depServices, ConfigurationCreator configurationCreator, DbServiceFactory dbServiceFactory) { + AgentApplication(BundleContext bundleContext, ExitStatus exitStatus, WriterID writerId, ConfigurationCreator configurationCreator) { this.bundleContext = bundleContext; this.configurationCreator = configurationCreator; - this.dbServiceFactory = dbServiceFactory; this.exitStatus = exitStatus; this.writerId = writerId; - this.sslConf = sslConf; - this.depServices = depServices; } private void parseArguments(Arguments args) throws InvalidConfigurationException { @@ -143,10 +125,6 @@ long startTime = System.currentTimeMillis(); configuration.setStartTime(startTime); - StorageCredentials creds = depServices.getRequiredService(StorageCredentials.class); - final DbService dbService = dbServiceFactory.createDbService( - configuration.getDBConnectionString(), creds, sslConf); - shutdownLatch = new CountDownLatch(1); configServerTracker = new ServiceTracker(bundleContext, ConfigurationServer.class.getName(), null) { @@ -157,44 +135,12 @@ try { configServer.startListening(hostPort.getHost(), hostPort.getPort()); - - ConnectionListener connectionListener = new ConnectionListener() { - @Override - public void changed(ConnectionStatus newStatus) { - switch (newStatus) { - case DISCONNECTED: - logger.warning("Unexpected disconnect event."); - break; - case CONNECTING: - logger.fine("Connecting to storage."); - break; - case CONNECTED: - logger.fine("Connected to storage"); - handleConnected(configServer); - break; - case FAILED_TO_CONNECT: - // ConnectionException will be thrown - break; - default: - logger.warning("Unfamiliar ConnectionStatus value: " + newStatus.toString()); - } - } - }; - - dbService.addConnectionListener(connectionListener); - logger.fine("Connecting to storage..."); - - dbService.connect(); + prepareAgent(configServer); } catch (IOException e) { logger.log(Level.SEVERE, e.getMessage()); // log stack trace as info only logger.log(Level.INFO, e.getMessage(), e); shutdown(ExitStatus.EXIT_ERROR); - } catch (ConnectionException e) { - logger.log(Level.SEVERE, "Could not connect to storage (" + e.getMessage() + ")"); - // log stack trace as info only - logger.log(Level.INFO, "Could not connect to storage", e); - shutdown(ExitStatus.EXIT_ERROR); } return configServer; @@ -225,14 +171,6 @@ } } - void setStorageCredentials(StorageCredentials creds) { - if (creds == null) { - depServices.removeService(StorageCredentials.class); - } else { - depServices.addService(StorageCredentials.class, creds); - } - } - @Override public void run(CommandContext ctx) throws CommandException { configuration = configurationCreator.create(); @@ -294,7 +232,7 @@ } - Agent startAgent(final Storage storage, AgentInfoDAO agentInfoDAO, BackendInfoDAO backendInfoDAO) { + Agent startAgent(AgentInfoDAO agentInfoDAO, BackendInfoDAO backendInfoDAO) { BackendRegistry backendRegistry = null; try { backendRegistry = new BackendRegistry(bundleContext); @@ -307,7 +245,7 @@ throw new RuntimeException(e); } - final Agent agent = new Agent(backendRegistry, configuration, storage, agentInfoDAO, backendInfoDAO, writerId); + final Agent agent = new Agent(backendRegistry, configuration, agentInfoDAO, backendInfoDAO, writerId); try { logger.fine("Starting agent."); agent.start(); @@ -332,9 +270,8 @@ return agent; } - private void handleConnected(final ConfigurationServer configServer) { + private void prepareAgent(final ConfigurationServer configServer) { Class<?>[] deps = new Class<?>[] { - Storage.class, AgentInfoDAO.class, BackendInfoDAO.class }; @@ -342,11 +279,10 @@ @Override public void dependenciesAvailable(DependencyProvider services) { - Storage storage = services.get(Storage.class); AgentInfoDAO agentInfoDAO = services.get(AgentInfoDAO.class); BackendInfoDAO backendInfoDAO = services.get(BackendInfoDAO.class); - Agent agent = startAgent(storage, agentInfoDAO, backendInfoDAO); + Agent agent = startAgent(agentInfoDAO, backendInfoDAO); handler = new CustomSignalHandler(agent, configServer); Signal.handle(new Signal(SIGINT_NAME), handler); Signal.handle(new Signal(SIGTERM_NAME), handler);
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/internal/ServiceCommand.java Fri May 05 12:10:15 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,202 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.agent.cli.internal; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Semaphore; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; - -import com.redhat.thermostat.agent.cli.internal.locale.LocaleResources; -import com.redhat.thermostat.common.ActionEvent; -import com.redhat.thermostat.common.ActionListener; -import com.redhat.thermostat.common.cli.AbstractStateNotifyingCommand; -import com.redhat.thermostat.common.cli.CommandContext; -import com.redhat.thermostat.common.cli.CommandException; -import com.redhat.thermostat.common.cli.Console; -import com.redhat.thermostat.common.tools.ApplicationState; -import com.redhat.thermostat.common.utils.LoggingUtils; -import com.redhat.thermostat.launcher.Launcher; -import com.redhat.thermostat.shared.locale.Translate; - -/** - * Simple service that allows starting Agent and DB Backend - * in a single step. - */ -public class ServiceCommand extends AbstractStateNotifyingCommand implements ActionListener<ApplicationState> { - - private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); - private static final Logger logger = LoggingUtils.getLogger(ServiceCommand.class); - - private List<ActionListener<ApplicationState>> listeners; - private Semaphore agentBarrier = new Semaphore(0); - private BundleContext context; - private Launcher launcher; - private boolean storageFailed = false; - private boolean agentStarted = false; - private CommandContext cmdCtx; - - public ServiceCommand(BundleContext context) { - this.context = context; - listeners = new ArrayList<>(); - listeners.add(this); - } - - @Override - public void run(CommandContext ctx) throws CommandException { - cmdCtx = ctx; - ServiceReference launcherRef = context.getServiceReference(Launcher.class); - requireNonNull(launcherRef, translator.localize(LocaleResources.LAUNCHER_UNAVAILABLE)); - launcher = (Launcher) context.getService(launcherRef); - String[] storageStartArgs = new String[] { "storage", "--start" }; - launcher.run(storageStartArgs, listeners, false); - agentBarrier.acquireUninterruptibly(); - - if (storageFailed) { - storageFailed = false; - context.ungetService(launcherRef); - getNotifier().fireAction(ApplicationState.FAIL); - throw new CommandException(translator.localize(LocaleResources.SERVICE_FAILED_TO_START_DB)); - } - - String[] storageStopArgs = new String[] { "storage", "--stop" }; - launcher.run(storageStopArgs, false); - - if (agentStarted) { - getNotifier().fireAction(ApplicationState.STOP); - } - - context.ungetService(launcherRef); - cmdCtx = null; - } - - @Override - public void actionPerformed(ActionEvent<ApplicationState> actionEvent) { - if (actionEvent.getSource() instanceof AbstractStateNotifyingCommand) { - AbstractStateNotifyingCommand storage = (AbstractStateNotifyingCommand) actionEvent.getSource(); - // Implementation detail: there is a single StorageCommand instance registered - // as an OSGi service. We remove ourselves as listener so that we don't get - // notified in the case that the command is invoked by some other means later. - storage.getNotifier().removeActionListener(this); - - try { - switch (actionEvent.getActionId()) { - case START: - // Payload is connection URL - Object payload = actionEvent.getPayload(); - if (payload == null || !(payload instanceof String)) { - getNotifier().fireAction(ApplicationState.FAIL); - throw new CommandException(translator.localize(LocaleResources.UNEXPECTED_RESULT_STORAGE)); - } - String dbUrl = (String) payload; - String[] agentArgs = new String[] {"agent", "-d", dbUrl}; - logger.fine("starting agent now..."); - listeners.clear(); - listeners.add(new AgentStartedListener(cmdCtx.getConsole())); - launcher.run(agentArgs, listeners, false); - break; - case FAIL: - storageFailed = true; - // Payload is exception - payload = actionEvent.getPayload(); - if (payload == null || !(payload instanceof Exception)) { - getNotifier().fireAction(ApplicationState.FAIL); - throw new CommandException(translator.localize(LocaleResources.UNEXPECTED_RESULT_STORAGE)); - } - Exception ex = (Exception) payload; - cmdCtx.getConsole().getError().println(ex.getMessage()); - logger.log(Level.WARNING, ex.getMessage(), ex); - break; - } - } catch (CommandException e) { - cmdCtx.getConsole().getError().println(e.getMessage()); - } finally { - agentBarrier.release(); - } - } - } - - @Override - public boolean isStorageRequired() { - return false; - } - - private class AgentStartedListener implements ActionListener<ApplicationState> { - - private final Console console; - - private AgentStartedListener(Console console) { - this.console = console; - } - - @Override - public void actionPerformed(ActionEvent<ApplicationState> actionEvent) { - if (actionEvent.getSource() instanceof AbstractStateNotifyingCommand) { - AbstractStateNotifyingCommand agent = (AbstractStateNotifyingCommand) actionEvent.getSource(); - // Implementation detail: there is a single AgentCommand instance registered - // as an OSGi service. We remove ourselves as listener so that we don't get - // notified in the case that the command is invoked by some other means later. - agent.getNotifier().removeActionListener(this); - - ApplicationState state = actionEvent.getActionId(); - // propagate the Agent ActionEvent - switch (state) { - case START: - agentStarted = true; - logger.fine("Agent started via service. Agent ID was: " + actionEvent.getPayload()); - getNotifier().fireAction(ApplicationState.START, actionEvent.getPayload()); - break; - case FAIL: - console.getError().println(translator.localize(LocaleResources.STARTING_AGENT_FAILED).getContents()); - getNotifier().fireAction(ApplicationState.FAIL, actionEvent.getPayload()); - break; - case STOP: - getNotifier().fireAction(ApplicationState.STOP); - break; - default: - throw new AssertionError("Unexpected state " + state); - } - } - } - } - -} -
--- a/agent/cli/src/test/java/com/redhat/thermostat/agent/cli/internal/ActivatorTest.java Fri May 05 12:10:15 2017 -0400 +++ b/agent/cli/src/test/java/com/redhat/thermostat/agent/cli/internal/ActivatorTest.java Fri May 05 12:11:28 2017 -0400 @@ -65,10 +65,9 @@ activator.start(bundleContext); - assertEquals(4, bundleContext.getServiceListeners().size()); + assertEquals(3, bundleContext.getServiceListeners().size()); assertCommandIsRegistered(bundleContext, "agent", AgentApplication.class); - assertCommandIsRegistered(bundleContext, "service", ServiceCommand.class); activator.stop(bundleContext);
--- a/agent/cli/src/test/java/com/redhat/thermostat/agent/cli/internal/AgentApplicationTest.java Fri May 05 12:10:15 2017 -0400 +++ b/agent/cli/src/test/java/com/redhat/thermostat/agent/cli/internal/AgentApplicationTest.java Fri May 05 12:11:28 2017 -0400 @@ -39,9 +39,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -56,7 +54,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.osgi.framework.BundleContext; @@ -74,17 +71,8 @@ import com.redhat.thermostat.common.cli.Arguments; import com.redhat.thermostat.common.cli.CommandContext; import com.redhat.thermostat.common.cli.CommandException; -import com.redhat.thermostat.common.cli.DependencyServices; import com.redhat.thermostat.common.utils.HostPortPair; import com.redhat.thermostat.shared.config.InvalidConfigurationException; -import com.redhat.thermostat.shared.config.SSLConfiguration; -import com.redhat.thermostat.storage.core.Connection.ConnectionListener; -import com.redhat.thermostat.storage.core.Connection.ConnectionStatus; -import com.redhat.thermostat.storage.core.ConnectionException; -import com.redhat.thermostat.storage.core.DbService; -import com.redhat.thermostat.storage.core.DbServiceFactory; -import com.redhat.thermostat.storage.core.Storage; -import com.redhat.thermostat.storage.core.StorageCredentials; import com.redhat.thermostat.storage.core.WriterID; import com.redhat.thermostat.storage.dao.AgentInfoDAO; import com.redhat.thermostat.storage.dao.BackendInfoDAO; @@ -99,10 +87,8 @@ private StubBundleContext context; private ConfigurationServer configServer; - private DbService dbService; private ConfigurationCreator configCreator; private ExitStatus exitStatus; - private DbServiceFactory dbServiceFactory; private WriterID writerId; @Before @@ -118,18 +104,13 @@ configCreator = mock(ConfigurationCreator.class); when(configCreator.create()).thenReturn(config); - Storage storage = mock(Storage.class); - context.registerService(Storage.class, storage, null); AgentInfoDAO agentInfoDAO = mock(AgentInfoDAO.class); context.registerService(AgentInfoDAO.class.getName(), agentInfoDAO, null); BackendInfoDAO backendInfoDAO = mock(BackendInfoDAO.class); context.registerService(BackendInfoDAO.class.getName(), backendInfoDAO, null); configServer = mock(ConfigurationServer.class); context.registerService(ConfigurationServer.class.getName(), configServer, null); - dbServiceFactory = mock(DbServiceFactory.class); - dbService = mock(DbService.class); writerId = mock(WriterID.class); - when(dbServiceFactory.createDbService(anyString(), any(StorageCredentials.class), any(SSLConfiguration.class))).thenReturn(dbService); exitStatus = mock(ExitStatus.class); } @@ -138,16 +119,13 @@ public void tearDown() { context = null; configServer = null; - dbService = null; configCreator = null; - dbServiceFactory = null; exitStatus = null; } @Test public void testAgentStartup() throws CommandException, InterruptedException { - final AgentApplication agent = new AgentApplication(context, exitStatus, writerId, mock(SSLConfiguration.class), new DependencyServices(), configCreator, dbServiceFactory); - agent.setStorageCredentials(mock(StorageCredentials.class)); + final AgentApplication agent = new AgentApplication(context, exitStatus, writerId, configCreator); final CountDownLatch latch = new CountDownLatch(1); final CommandException[] ce = new CommandException[1]; final long timeoutMillis = 5000L; @@ -163,24 +141,6 @@ } } - @Test - public void testAgentStartupConnectFailure() throws CommandException, InterruptedException { - final AgentApplication agent = new AgentApplication(context, exitStatus, writerId, mock(SSLConfiguration.class), new DependencyServices(), configCreator, dbServiceFactory); - agent.setStorageCredentials(mock(StorageCredentials.class)); - - Arguments args = mock(Arguments.class); - final CommandContext commandContext = mock(CommandContext.class); - when(commandContext.getArguments()).thenReturn(args); - - // Throw a ConnectionException when we try to connect to storage - doThrow(new ConnectionException()).when(dbService).connect(); - - agent.run(commandContext); - - // Ensure we shut down command channel server - verify(configServer).stopListening(); - } - /* * Having the PrepareForTest annotation on method level does not seem to * deadlock the test, which seems to be more or less reliably reproducible @@ -201,10 +161,9 @@ .withArguments(any(BundleContext.class)) .thenThrow(InvalidSyntaxException.class); final AgentApplication agent = new AgentApplication(context, - exitStatus, writerId, mock(SSLConfiguration.class), - mock(DependencyServices.class), configCreator, dbServiceFactory); + exitStatus, writerId, configCreator); try { - agent.startAgent(null, null, null); + agent.startAgent(null, null); } catch (RuntimeException e) { assertEquals(InvalidSyntaxException.class, e.getCause().getClass()); } @@ -219,18 +178,17 @@ .thenReturn(mock(BackendRegistry.class)); Agent mockAgent = mock(Agent.class); whenNew(Agent.class).withParameterTypes(BackendRegistry.class, - AgentStartupConfiguration.class, Storage.class, + AgentStartupConfiguration.class, AgentInfoDAO.class, BackendInfoDAO.class, WriterID.class).withArguments( any(BackendRegistry.class), - any(AgentStartupConfiguration.class), any(Storage.class), + any(AgentStartupConfiguration.class), any(AgentInfoDAO.class), any(BackendInfoDAO.class), any(WriterID.class)).thenReturn(mockAgent); doThrow(LaunchException.class).when(mockAgent).start(); final AgentApplication agent = new AgentApplication(context, - exitStatus, writerId, mock(SSLConfiguration.class), - mock(DependencyServices.class), configCreator, dbServiceFactory); + exitStatus, writerId, configCreator); try { - agent.startAgent(null, null, null); + agent.startAgent(null, null); } catch (RuntimeException e) { fail("Should not have thrown RuntimeException"); } @@ -242,21 +200,6 @@ final CommandContext commandContext = mock(CommandContext.class); when(commandContext.getArguments()).thenReturn(args); - // Immediately switch to CONNECTED state on dbService.connect - final ArgumentCaptor<ConnectionListener> listenerCaptor = ArgumentCaptor.forClass(ConnectionListener.class); - doNothing().when(dbService).addConnectionListener(listenerCaptor.capture()); - - doAnswer(new Answer<Void>() { - - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - ConnectionListener listener = listenerCaptor.getValue(); - listener.changed(ConnectionStatus.CONNECTED); - return null; - } - - }).when(dbService).connect(); - // Run agent in a new thread so we can timeout on failure Thread t = new Thread(new Runnable() {
--- a/agent/cli/src/test/java/com/redhat/thermostat/agent/cli/internal/ServiceCommandTest.java Fri May 05 12:10:15 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,413 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.agent.cli.internal; - -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.Collection; - -import com.redhat.thermostat.testutils.Asserts; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - -import com.redhat.thermostat.common.ActionEvent; -import com.redhat.thermostat.common.ActionListener; -import com.redhat.thermostat.common.ActionNotifier; -import com.redhat.thermostat.common.cli.AbstractStateNotifyingCommand; -import com.redhat.thermostat.common.cli.CommandContext; -import com.redhat.thermostat.common.cli.CommandException; -import com.redhat.thermostat.common.cli.Console; -import com.redhat.thermostat.common.tools.ApplicationState; -import com.redhat.thermostat.launcher.Launcher; -import com.redhat.thermostat.testutils.StubBundleContext; - -public class ServiceCommandTest { - - private ByteArrayOutputStream stdErrOut; - private Launcher mockLauncher; - private ServiceCommand serviceCommand; - private CommandContext mockCommandContext; - - private static ActionEvent<ApplicationState> mockActionEvent; - private static Collection<ActionListener<ApplicationState>> listeners; - - private static final String[] STORAGE_START_ARGS = { "storage", "--start" }; - private static final String[] STORAGE_STOP_ARGS = { "storage", "--stop" }; - private static final String[] AGENT_ARGS = {"agent", "-d", "Test String"}; - private static final String AGENT_ID = "Test ID"; - - @SuppressWarnings("unchecked") - @Before - public void setUp() { - StubBundleContext bundleContext = new StubBundleContext(); - mockLauncher = mock(Launcher.class); - bundleContext.registerService(Launcher.class, mockLauncher, null); - serviceCommand = new ServiceCommand(bundleContext); - - AbstractStateNotifyingCommand mockStorageCommand = mock(AbstractStateNotifyingCommand.class); - mockActionEvent = mock(ActionEvent.class); - when(mockActionEvent.getSource()).thenReturn(mockStorageCommand); - mockCommandContext = mock(CommandContext.class); - Console console = mock(Console.class); - stdErrOut = new ByteArrayOutputStream(); - PrintStream err = new PrintStream(stdErrOut); - when(console.getError()).thenReturn(err); - when(mockCommandContext.getConsole()).thenReturn(console); - - ActionNotifier<ApplicationState> mockNotifier = mock(ActionNotifier.class); - when(mockStorageCommand.getNotifier()).thenReturn(mockNotifier); - when(mockActionEvent.getPayload()).thenReturn(new String("Test String")); - } - - @After - public void tearDown() { - listeners = null; - mockLauncher = null; - serviceCommand = null; - mockActionEvent = null; - mockCommandContext = null; - } - - @SuppressWarnings("unchecked") - @Test(timeout=1000) - public void testRunOnce() throws CommandException, InterruptedException { - doAnswer(new Answer<Void>() { - public Void answer(InvocationOnMock invocation) throws Throwable { - Object[] args = invocation.getArguments(); - listeners = (Collection<ActionListener<ApplicationState>>)args[1]; - - when(mockActionEvent.getActionId()).thenReturn(ApplicationState.START); - - for(ActionListener<ApplicationState> listener : listeners) { - listener.actionPerformed(mockActionEvent); - } - return null; - } - }).when(mockLauncher).run(eq(STORAGE_START_ARGS), isA(Collection.class), anyBoolean()); - - doAnswer(new Answer<Void>() { - public Void answer(InvocationOnMock invocation) throws Throwable { - Object[] args = invocation.getArguments(); - listeners = (Collection<ActionListener<ApplicationState>>)args[1]; - - when(mockActionEvent.getActionId()).thenReturn(ApplicationState.START); - when(mockActionEvent.getPayload()).thenReturn(AGENT_ID); - - for(ActionListener<ApplicationState> listener : listeners) { - listener.actionPerformed(mockActionEvent); - } - return null; - } - }).when(mockLauncher).run(eq(AGENT_ARGS), isA(Collection.class), anyBoolean()); - - final boolean[] result = new boolean[2]; - final String[] agentIdFound = new String[1]; - serviceCommand.getNotifier().addActionListener(new ActionListener<ApplicationState>() { - @SuppressWarnings("incomplete-switch") - @Override - public void actionPerformed(ActionEvent<ApplicationState> actionEvent) { - switch (actionEvent.getActionId()) { - case FAIL: - result[0] = false; - break; - case START: - result[0] = true; - agentIdFound[0] = (String) actionEvent.getPayload(); - break; - case STOP: - result[1] = true; - break; - } - } - }); - - boolean exTriggered = false; - try { - serviceCommand.run(mockCommandContext); - } catch (CommandException e) { - exTriggered = true; - } - Assert.assertFalse(exTriggered); - Assert.assertTrue("Agent expected to fire START event", result[0]); - Assert.assertTrue("Agent expected to fire STOP event", result[1]); - Assert.assertEquals("Payload does not contain AgentId matching the agent started", agentIdFound[0], AGENT_ID); - - verify(mockLauncher, times(1)).run(eq(STORAGE_START_ARGS), isA(Collection.class), anyBoolean()); - verify(mockLauncher, times(1)).run(eq(STORAGE_STOP_ARGS), anyBoolean()); - verify(mockLauncher, times(1)).run(eq(AGENT_ARGS), isA(Collection.class), anyBoolean()); - verify(mockActionEvent, times(2)).getActionId(); - } - - @Test(timeout=1000) - public void testStorageStartUnknownPath() throws CommandException { - doAnswer(new Answer<Void>() { - public Void answer(InvocationOnMock invocation) throws Throwable { - Object[] args = invocation.getArguments(); - listeners = (Collection<ActionListener<ApplicationState>>)args[1]; - - when(mockActionEvent.getActionId()).thenReturn(ApplicationState.START); - // Return a null payload in order to trigger unknown path - when(mockActionEvent.getPayload()).thenReturn(null); - - for(ActionListener<ApplicationState> listener : listeners) { - listener.actionPerformed(mockActionEvent); - } - return null; - } - }).when(mockLauncher).run(eq(STORAGE_START_ARGS), isA(Collection.class), anyBoolean()); - - final boolean[] result = new boolean[1]; - serviceCommand.getNotifier().addActionListener(new ActionListener<ApplicationState>() { - @SuppressWarnings("incomplete-switch") - @Override - public void actionPerformed(ActionEvent<ApplicationState> actionEvent) { - switch (actionEvent.getActionId()) { - case FAIL: - result[0] = true; - break; - case START: - result[0] = false; - break; - case STOP: - result[0] = false; - break; - } - } - }); - - boolean exTriggered = false; - try { - serviceCommand.run(mockCommandContext); - } catch (CommandException e) { - exTriggered = true; - } - Assert.assertFalse(exTriggered); - Asserts.assertEqualsIgnoreCR("Unexpected result from storage.\n", stdErrOut.toString()); - Assert.assertTrue("Agent expected to fire FAIL event", result[0]); - - verify(mockLauncher, times(1)).run(eq(STORAGE_START_ARGS), isA(Collection.class), anyBoolean()); - verify(mockLauncher, times(1)).run(eq(STORAGE_STOP_ARGS), anyBoolean()); - verify(mockLauncher, never()).run(eq(AGENT_ARGS), isA(Collection.class), anyBoolean()); - verify(mockActionEvent, times(1)).getActionId(); - } - - @SuppressWarnings("unchecked") - @Test(timeout=1000) - public void testStorageFailStart() throws CommandException, InterruptedException { - doAnswer(new Answer<Void>() { - public Void answer(InvocationOnMock invocation) throws Throwable { - Object[] args = invocation.getArguments(); - listeners = (Collection<ActionListener<ApplicationState>>)args[1]; - - when(mockActionEvent.getActionId()).thenReturn(ApplicationState.FAIL); - when(mockActionEvent.getPayload()).thenReturn(new Exception("Test Exception")); - - for(ActionListener<ApplicationState> listener : listeners) { - listener.actionPerformed(mockActionEvent); - } - return null; - } - }).when(mockLauncher).run(eq(STORAGE_START_ARGS), isA(Collection.class), anyBoolean()); - - final boolean[] result = new boolean[1]; - serviceCommand.getNotifier().addActionListener(new ActionListener<ApplicationState>() { - @SuppressWarnings("incomplete-switch") - @Override - public void actionPerformed(ActionEvent<ApplicationState> actionEvent) { - switch (actionEvent.getActionId()) { - case FAIL: - result[0] = true; - break; - case START: - result[0] = false; - break; - case STOP: - result[0] = false; - break; - } - } - }); - - boolean exTriggered = false; - try { - serviceCommand.run(mockCommandContext); - } catch (CommandException e) { - exTriggered = true; - } - Assert.assertTrue(exTriggered); - Asserts.assertEqualsIgnoreCR("Test Exception\n", stdErrOut.toString()); - Assert.assertTrue("Agent expected to fire FAIL event", result[0]); - - verify(mockLauncher, times(1)).run(eq(STORAGE_START_ARGS), isA(Collection.class), anyBoolean()); - verify(mockLauncher, never()).run(eq(STORAGE_STOP_ARGS), anyBoolean()); - verify(mockLauncher, never()).run(eq(AGENT_ARGS), isA(Collection.class), anyBoolean()); - verify(mockActionEvent, times(1)).getActionId(); - } - - @Test(timeout=1000) - public void testStorageFailStartUnknownPath() throws CommandException { - doAnswer(new Answer<Void>() { - public Void answer(InvocationOnMock invocation) throws Throwable { - Object[] args = invocation.getArguments(); - listeners = (Collection<ActionListener<ApplicationState>>)args[1]; - - when(mockActionEvent.getActionId()).thenReturn(ApplicationState.FAIL); - // Return a null payload in order to trigger unknown path - when(mockActionEvent.getPayload()).thenReturn(null); - - for(ActionListener<ApplicationState> listener : listeners) { - listener.actionPerformed(mockActionEvent); - } - return null; - } - }).when(mockLauncher).run(eq(STORAGE_START_ARGS), isA(Collection.class), anyBoolean()); - - final boolean[] result = new boolean[1]; - serviceCommand.getNotifier().addActionListener(new ActionListener<ApplicationState>() { - @SuppressWarnings("incomplete-switch") - @Override - public void actionPerformed(ActionEvent<ApplicationState> actionEvent) { - switch (actionEvent.getActionId()) { - case FAIL: - result[0] = true; - break; - case START: - result[0] = false; - break; - case STOP: - result[0] = false; - break; - } - } - }); - - boolean exTriggered = false; - try { - serviceCommand.run(mockCommandContext); - } catch (CommandException e) { - exTriggered = true; - } - Assert.assertTrue(exTriggered); - Asserts.assertEqualsIgnoreCR("Unexpected result from storage.\n", stdErrOut.toString()); - Assert.assertTrue("Agent expected to fire FAIL event", result[0]); - - verify(mockLauncher, times(1)).run(eq(STORAGE_START_ARGS), isA(Collection.class), anyBoolean()); - verify(mockLauncher, never()).run(eq(STORAGE_STOP_ARGS), anyBoolean()); - verify(mockLauncher, never()).run(eq(AGENT_ARGS), isA(Collection.class), anyBoolean()); - verify(mockActionEvent, times(1)).getActionId(); - } - - @Test - public void testAgentStartFail() throws CommandException { - doAnswer(new Answer<Void>() { - public Void answer(InvocationOnMock invocation) throws Throwable { - Object[] args = invocation.getArguments(); - listeners = (Collection<ActionListener<ApplicationState>>)args[1]; - - when(mockActionEvent.getActionId()).thenReturn(ApplicationState.START); - - for(ActionListener<ApplicationState> listener : listeners) { - listener.actionPerformed(mockActionEvent); - } - return null; - } - }).when(mockLauncher).run(eq(STORAGE_START_ARGS), isA(Collection.class), anyBoolean()); - doAnswer(new Answer<Void>() { - public Void answer(InvocationOnMock invocation) throws Throwable { - Object[] args = invocation.getArguments(); - listeners = (Collection<ActionListener<ApplicationState>>)args[1]; - - when(mockActionEvent.getActionId()).thenReturn(ApplicationState.FAIL); - - for(ActionListener<ApplicationState> listener : listeners) { - listener.actionPerformed(mockActionEvent); - } - return null; - } - }).when(mockLauncher).run(eq(AGENT_ARGS), isA(Collection.class), anyBoolean()); - - final boolean[] result = new boolean[1]; - serviceCommand.getNotifier().addActionListener(new ActionListener<ApplicationState>() { - @SuppressWarnings("incomplete-switch") - @Override - public void actionPerformed(ActionEvent<ApplicationState> actionEvent) { - switch (actionEvent.getActionId()) { - case FAIL: - result[0] = true; - break; - case START: - result[0] = false; - break; - case STOP: - result[0] = false; - break; - } - } - }); - - boolean exTriggered = false; - try { - serviceCommand.run(mockCommandContext); - } catch (CommandException e) { - exTriggered = true; - } - Assert.assertFalse(exTriggered); - Asserts.assertEqualsIgnoreCR("Thermostat agent failed to start. See logs for details.\n", stdErrOut.toString()); - Assert.assertTrue("Agent expected to fire FAIL event", result[0]); - - verify(mockLauncher, times(1)).run(eq(STORAGE_START_ARGS), isA(Collection.class), anyBoolean()); - verify(mockLauncher, times(1)).run(eq(STORAGE_STOP_ARGS), anyBoolean()); - verify(mockLauncher, times(1)).run(eq(AGENT_ARGS), isA(Collection.class), anyBoolean()); - verify(mockActionEvent, times(2)).getActionId(); - } - -} -
--- a/agent/core/src/main/java/com/redhat/thermostat/agent/Agent.java Fri May 05 12:10:15 2017 -0400 +++ b/agent/core/src/main/java/com/redhat/thermostat/agent/Agent.java Fri May 05 12:11:28 2017 -0400 @@ -51,7 +51,6 @@ import com.redhat.thermostat.common.ThermostatExtensionRegistry; import com.redhat.thermostat.common.utils.HostPortPair; import com.redhat.thermostat.common.utils.LoggingUtils; -import com.redhat.thermostat.storage.core.Storage; import com.redhat.thermostat.storage.core.WriterID; import com.redhat.thermostat.storage.dao.AgentInfoDAO; import com.redhat.thermostat.storage.dao.BackendInfoDAO; @@ -70,7 +69,6 @@ private final BackendRegistry backendRegistry; private final AgentStartupConfiguration config; private final Map<Backend, BackendInformation> backendInfos; - private final Storage storage; private final AgentInfoDAO agentDao; private final BackendInfoDAO backendDao; private final WriterID writerID; @@ -127,17 +125,16 @@ } }; - public Agent(BackendRegistry registry, AgentStartupConfiguration config, Storage storage, + public Agent(BackendRegistry registry, AgentStartupConfiguration config, AgentInfoDAO agentInfoDao, BackendInfoDAO backendInfoDao, WriterID writerId) { - this(registry, config, storage, agentInfoDao, backendInfoDao, writerId, new MXBeanConnectionPoolTracker()); + this(registry, config, agentInfoDao, backendInfoDao, writerId, new MXBeanConnectionPoolTracker()); } - Agent(BackendRegistry registry, AgentStartupConfiguration config, Storage storage, + Agent(BackendRegistry registry, AgentStartupConfiguration config, AgentInfoDAO agentInfoDao, BackendInfoDAO backendInfoDao, WriterID writerId, MXBeanConnectionPoolTracker poolTracker) { this.backendRegistry = registry; this.config = config; - this.storage = storage; this.agentDao = agentInfoDao; this.backendDao = backendInfoDao; this.writerID = writerId; @@ -215,7 +212,7 @@ System.out.println("purging database"); logger.info("purging database"); agentDao.removeAgentInformation(agentInfo); - storage.purge(agentInfo.getAgentId()); + //storage.purge(agentInfo.getAgentId()); TODO Need purge functionality } private void updateAgentStatusToStopped() {
--- a/agent/core/src/main/java/com/redhat/thermostat/agent/internal/Activator.java Fri May 05 12:10:15 2017 -0400 +++ b/agent/core/src/main/java/com/redhat/thermostat/agent/internal/Activator.java Fri May 05 12:11:28 2017 -0400 @@ -50,15 +50,13 @@ import com.redhat.thermostat.agent.config.AgentConfigsUtils; import com.redhat.thermostat.agent.ipc.server.AgentIPCService; import com.redhat.thermostat.agent.utils.management.MXBeanConnectionPool; -import com.redhat.thermostat.common.portability.UserNameUtil; import com.redhat.thermostat.common.MultipleServiceTracker; import com.redhat.thermostat.common.MultipleServiceTracker.Action; import com.redhat.thermostat.common.MultipleServiceTracker.DependencyProvider; +import com.redhat.thermostat.common.portability.UserNameUtil; import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.shared.config.CommonPaths; import com.redhat.thermostat.shared.config.InvalidConfigurationException; -import com.redhat.thermostat.storage.config.FileStorageCredentials; -import com.redhat.thermostat.storage.core.StorageCredentials; import com.redhat.thermostat.utils.management.internal.AgentProxyFilter; import com.redhat.thermostat.utils.management.internal.MXBeanConnectionPoolControl; import com.redhat.thermostat.utils.management.internal.MXBeanConnectionPoolImpl; @@ -83,8 +81,6 @@ public CommonPaths addingService(ServiceReference<CommonPaths> ref) { CommonPaths paths = context.getService(ref); try { - StorageCredentials creds = new FileStorageCredentials(paths.getUserAgentAuthConfigFile()); - context.registerService(StorageCredentials.class, creds, null); AgentConfigsUtils.setConfigFiles(paths.getSystemAgentConfigurationFile(), paths.getUserAgentConfigurationFile()); VmBlacklistImpl blacklist = new VmBlacklistImpl(); blacklist.addVmFilter(new AgentProxyFilter());
--- a/agent/core/src/test/java/com/redhat/thermostat/agent/AgentTest.java Fri May 05 12:10:15 2017 -0400 +++ b/agent/core/src/test/java/com/redhat/thermostat/agent/AgentTest.java Fri May 05 12:11:28 2017 -0400 @@ -40,11 +40,9 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -53,25 +51,19 @@ import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; import com.redhat.thermostat.agent.config.AgentStartupConfiguration; -import com.redhat.thermostat.agent.utils.management.MXBeanConnectionPool; import com.redhat.thermostat.backend.Backend; import com.redhat.thermostat.backend.BackendRegistry; import com.redhat.thermostat.common.ActionEvent; import com.redhat.thermostat.common.ActionListener; -import com.redhat.thermostat.common.LaunchException; import com.redhat.thermostat.common.ThermostatExtensionRegistry; import com.redhat.thermostat.common.utils.HostPortPair; -import com.redhat.thermostat.storage.core.Storage; import com.redhat.thermostat.storage.core.WriterID; import com.redhat.thermostat.storage.dao.AgentInfoDAO; import com.redhat.thermostat.storage.dao.BackendInfoDAO; import com.redhat.thermostat.storage.model.AgentInformation; import com.redhat.thermostat.storage.model.BackendInformation; -import com.redhat.thermostat.testutils.StubBundleContext; import com.redhat.thermostat.utils.management.internal.MXBeanConnectionPoolImpl; import com.redhat.thermostat.utils.management.internal.MXBeanConnectionPoolTracker; @@ -82,7 +74,6 @@ private BackendRegistry backendRegistry; private Backend backend; - private Storage storage; private AgentInfoDAO agentInfoDao; private BackendInfoDAO backendInfoDao; private MXBeanConnectionPoolImpl pool; @@ -95,7 +86,6 @@ when(config.purge()).thenReturn(true); when(config.getConfigPublishAddress()).thenReturn(new HostPortPair("foo", 23)); - storage = mock(Storage.class); agentInfoDao = mock(AgentInfoDAO.class); backendInfoDao = mock(BackendInfoDAO.class); @@ -116,7 +106,7 @@ @SuppressWarnings("unused") @Test public void testAgentInit() throws Exception { - Agent agent = new Agent(backendRegistry, config, storage, agentInfoDao, backendInfoDao, null, poolTracker); + Agent agent = new Agent(backendRegistry, config, agentInfoDao, backendInfoDao, null, poolTracker); verify(backendRegistry).addActionListener(any(ActionListener.class)); } @@ -128,7 +118,7 @@ UUID uuid = UUID.randomUUID(); WriterID id = mock(WriterID.class); when(id.getWriterID()).thenReturn(uuid.toString()); - Agent agent = new Agent(backendRegistry, config, storage, agentInfoDao, backendInfoDao, id, poolTracker); + Agent agent = new Agent(backendRegistry, config, agentInfoDao, backendInfoDao, id, poolTracker); agent.start(); @@ -149,7 +139,7 @@ // Start agent. WriterID id = mock(WriterID.class); - Agent agent = new Agent(backendRegistry, config, storage, agentInfoDao, backendInfoDao, id, poolTracker); + Agent agent = new Agent(backendRegistry, config, agentInfoDao, backendInfoDao, id, poolTracker); verify(backendRegistry).addActionListener(backendListener.capture()); agent.start(); @@ -197,7 +187,7 @@ UUID uuid = UUID.randomUUID(); WriterID id = mock(WriterID.class); when(id.getWriterID()).thenReturn(uuid.toString()); - Agent agent = new Agent(backendRegistry, config, storage, agentInfoDao, backendInfoDao, id, poolTracker); + Agent agent = new Agent(backendRegistry, config, agentInfoDao, backendInfoDao, id, poolTracker); agent.start(); // stop agent @@ -207,7 +197,7 @@ ArgumentCaptor<AgentInformation> argument = ArgumentCaptor.forClass(AgentInformation.class); verify(agentInfoDao, never()).updateAgentInformation(argument.capture()); - verify(storage, times(1)).purge(uuid.toString()); + //verify(storage, times(1)).purge(uuid.toString()); TODO verify(pool).shutdown(); } @@ -221,7 +211,7 @@ when(config.getConfigPublishAddress()).thenReturn(new HostPortPair("foo", 23)); WriterID id = mock(WriterID.class); - Agent agent = new Agent(backendRegistry, config, storage, agentInfoDao, backendInfoDao, id, poolTracker); + Agent agent = new Agent(backendRegistry, config, agentInfoDao, backendInfoDao, id, poolTracker); agent.start(); // stop agent @@ -230,7 +220,7 @@ verify(backendRegistry).stop(); verify(agentInfoDao).updateAgentInformation(isA(AgentInformation.class)); - verify(storage, times(0)).purge(anyString()); + //verify(storage, times(0)).purge(anyString()); TODO verify(pool).shutdown(); }
--- a/distribution/assembly/plugin-assembly.xml Fri May 05 12:10:15 2017 -0400 +++ b/distribution/assembly/plugin-assembly.xml Fri May 05 12:11:28 2017 -0400 @@ -50,22 +50,22 @@ <unpack>true</unpack> <includes> <include>com.redhat.thermostat:thermostat-host-overview-distribution</include> - <include>com.redhat.thermostat:thermostat-host-cpu-distribution</include> - <include>com.redhat.thermostat:thermostat-host-memory-distribution</include> - <include>com.redhat.thermostat:thermostat-numa-distribution</include> - <include>com.redhat.thermostat:thermostat-thread-distribution</include> - <include>com.redhat.thermostat:thermostat-vm-byteman-distribution</include> - <include>com.redhat.thermostat:thermostat-vm-classstat-distribution</include> - <include>com.redhat.thermostat:thermostat-vm-compiler-distribution</include> - <include>com.redhat.thermostat:thermostat-vm-cpu-distribution</include> - <include>com.redhat.thermostat:thermostat-vm-gc-distribution</include> - <include>com.redhat.thermostat:thermostat-vm-heap-analysis-distribution</include> - <include>com.redhat.thermostat:thermostat-vm-io-distribution</include> - <include>com.redhat.thermostat:thermostat-vm-jmx-distribution</include> - <include>com.redhat.thermostat:thermostat-vm-memory-distribution</include> - <include>com.redhat.thermostat:thermostat-vm-profiler-distribution</include> - <include>com.redhat.thermostat:thermostat-killvm-distribution</include> - <include>com.redhat.thermostat:thermostat-vm-numa-distribution</include> +<!-- <include>com.redhat.thermostat:thermostat-host-cpu-distribution</include>--> +<!-- <include>com.redhat.thermostat:thermostat-host-memory-distribution</include>--> +<!-- <include>com.redhat.thermostat:thermostat-numa-distribution</include>--> +<!-- <include>com.redhat.thermostat:thermostat-thread-distribution</include>--> +<!-- <include>com.redhat.thermostat:thermostat-vm-byteman-distribution</include>--> +<!-- <include>com.redhat.thermostat:thermostat-vm-classstat-distribution</include>--> +<!-- <include>com.redhat.thermostat:thermostat-vm-compiler-distribution</include>--> +<!-- <include>com.redhat.thermostat:thermostat-vm-cpu-distribution</include>--> +<!-- <include>com.redhat.thermostat:thermostat-vm-gc-distribution</include>--> +<!-- <include>com.redhat.thermostat:thermostat-vm-heap-analysis-distribution</include>--> +<!-- <include>com.redhat.thermostat:thermostat-vm-io-distribution</include>--> +<!-- <include>com.redhat.thermostat:thermostat-vm-jmx-distribution</include>--> +<!-- <include>com.redhat.thermostat:thermostat-vm-memory-distribution</include>--> +<!-- <include>com.redhat.thermostat:thermostat-vm-profiler-distribution</include>--> +<!-- <include>com.redhat.thermostat:thermostat-killvm-distribution</include>--> +<!-- <include>com.redhat.thermostat:thermostat-vm-numa-distribution</include>--> </includes> </dependencySet> </dependencySets>
--- a/distribution/pom.xml Fri May 05 12:10:15 2017 -0400 +++ b/distribution/pom.xml Fri May 05 12:11:28 2017 -0400 @@ -287,6 +287,7 @@ <goal>single</goal> </goals> </execution> +<!-- TODO Uncomment once Byteman plugin is ported to use web-gateway <execution> <id>assemble-all-plugin-libs</id> <configuration> @@ -300,7 +301,7 @@ <goals> <goal>single</goal> </goals> - </execution> + </execution>--> <execution> <id>assemble-scripts</id> <configuration>