Mercurial > hg > thermostat-ng > agent
changeset 2777:c30824312ec5
Add configuration to plugins to allow for deactivation of Backends at startup.
Reviewed-By: jkang, jerboaa
Review-Thread:
http://icedtea.classpath.org/pipermail/thermostat/2017-August/024612.html
http://icedtea.classpath.org/pipermail/thermostat/2017-September/024925.html
http://icedtea.classpath.org/pipermail/thermostat/2017-October/025247.html
line wrap: on
line diff
--- a/plugins/commands/agent/src/main/java/com/redhat/thermostat/commands/agent/internal/CommandsBackend.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/commands/agent/src/main/java/com/redhat/thermostat/commands/agent/internal/CommandsBackend.java Thu Oct 19 12:12:42 2017 -0400 @@ -45,7 +45,9 @@ import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; import org.eclipse.jetty.http.HttpHeader; @@ -73,7 +75,10 @@ import com.redhat.thermostat.storage.core.StorageCredentials; import com.redhat.thermostat.storage.core.WriterID; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "commands" +) @Service(value = Backend.class) public class CommandsBackend extends BaseBackend { @@ -176,6 +181,16 @@ receiverReg = new ReceiverRegistry(ctx); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin " + PLUGIN_ID); + } + @Deactivate protected void noOp() { /*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/commands/agent/src/main/java/com/redhat/thermostat/commands/agent/internal/CommandsBackendConfiguration.java Thu Oct 19 12:12:42 2017 -0400 @@ -0,0 +1,79 @@ +/* + * 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.commands.agent.internal; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.backend.BackendConfiguration; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugin.BackendConfigurationUtil; + +@Component +@Service(value = BackendConfiguration.class) +public class CommandsBackendConfiguration implements BackendConfiguration { + + private static final String PLUGIN_ID = "commands"; + private String location; + + @Reference + private ConfigurationInfoSource configInfoSource; + + @Override + public boolean isEnabled() { + BackendConfigurationUtil configuration = new BackendConfigurationUtil(configInfoSource, PLUGIN_ID); + return configuration.isEnabled(); + } + + @Override + public String getPluginId() { + return PLUGIN_ID; + } + + @Override + public String getLocation() { + return location; + } + + @Activate + public void activate(BundleContext context) { + location = context.getBundle().getLocation(); + } +} \ No newline at end of file
--- a/plugins/commands/agent/src/main/java/com/redhat/thermostat/commands/agent/internal/receiver/PingReceiver.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/commands/agent/src/main/java/com/redhat/thermostat/commands/agent/internal/receiver/PingReceiver.java Thu Oct 19 12:12:42 2017 -0400 @@ -41,6 +41,8 @@ import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.Service; @@ -50,7 +52,10 @@ import com.redhat.thermostat.commands.model.WebSocketResponse.ResponseType; import com.redhat.thermostat.common.utils.LoggingUtils; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "commands" +) @Service(value = RequestReceiver.class) @Property(name = "servicename", value = PingReceiver.ACTION_NAME) public class PingReceiver implements RequestReceiver { @@ -73,5 +78,9 @@ return new WebSocketResponse(request.getSequenceId(), ResponseType.OK); } + @Modified + public void modified() { + logger.fine("Configuration changed for commands"); + } }
--- a/plugins/commands/distribution/configFiles/backend-config.properties Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/commands/distribution/configFiles/backend-config.properties Thu Oct 19 12:12:42 2017 -0400 @@ -1,2 +1,3 @@ # Web socket base URL to the commands microservice provided by the Thermostat web gateway gatewayURL=wss://127.0.0.1:30000/commands/v1 +enabled=true
--- a/plugins/host-cpu/agent/src/main/java/com/redhat/thermostat/host/cpu/agent/internal/CpuStatDAOImpl.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/host-cpu/agent/src/main/java/com/redhat/thermostat/host/cpu/agent/internal/CpuStatDAOImpl.java Thu Oct 19 12:12:42 2017 -0400 @@ -40,10 +40,13 @@ import java.net.URI; import java.util.Arrays; import java.util.List; +import java.util.logging.Level; import java.util.logging.Logger; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; @@ -56,7 +59,10 @@ import com.redhat.thermostat.host.cpu.model.CpuStat; import com.redhat.thermostat.host.cpu.model.CpuStatTypeAdapter; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "host-cpu" +) @Service(value = CpuStatDAO.class) public class CpuStatDAOImpl extends PluginDAOBase<CpuStat> implements CpuStatDAO { @@ -91,6 +97,16 @@ config = configCreator.create(configurationInfoSource); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + public void modified() throws Exception { + logger.config("Doing nothing on configuration change for plugin " + PLUGIN_ID); + } + public String getPluginId() { return PLUGIN_ID; }
--- a/plugins/host-cpu/agent/src/main/java/com/redhat/thermostat/host/cpu/agent/internal/HostCpuBackend.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/host-cpu/agent/src/main/java/com/redhat/thermostat/host/cpu/agent/internal/HostCpuBackend.java Thu Oct 19 12:12:42 2017 -0400 @@ -38,25 +38,35 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; +import java.util.logging.Level; +import java.util.logging.Logger; import com.redhat.thermostat.backend.Backend; import com.redhat.thermostat.backend.HostPollingAction; import com.redhat.thermostat.backend.HostPollingBackend; import com.redhat.thermostat.common.Version; +import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.host.cpu.model.CpuStat; import com.redhat.thermostat.storage.core.WriterID; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; import org.osgi.framework.BundleContext; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "host-cpu" +) @Service(value = Backend.class) public class HostCpuBackend extends HostPollingBackend { + private static final Logger logger = LoggingUtils.getLogger(HostCpuBackend.class); + @Reference private CpuStatDAO cpuStatDAO; @@ -82,6 +92,16 @@ registerAction(new CpuProcBackendAction(writerID, cpuStatDAO)); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + public void modified() throws Exception { + logger.config("Doing nothing on configuration change for plugin host-cpu"); + } + @Deactivate protected void componentDeactivated() { if (isActive()) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/host-cpu/agent/src/main/java/com/redhat/thermostat/host/cpu/agent/internal/HostCpuBackendConfiguration.java Thu Oct 19 12:12:42 2017 -0400 @@ -0,0 +1,80 @@ +/* + * 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.host.cpu.agent.internal; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.backend.BackendConfiguration; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugin.BackendConfigurationUtil; + +@Component +@Service(value = BackendConfiguration.class) +public class HostCpuBackendConfiguration implements BackendConfiguration { + + private static final String PLUGIN_ID = "host-cpu"; + private String location; + + @Reference + private ConfigurationInfoSource configInfoSource; + + @Override + public boolean isEnabled() { + BackendConfigurationUtil configuration = new BackendConfigurationUtil(configInfoSource, PLUGIN_ID); + return configuration.isEnabled(); + } + + @Override + public String getPluginId() { + return PLUGIN_ID; + } + + @Override + public String getLocation() { + return location; + } + + @Activate + public void activate(BundleContext context) { + location = context.getBundle().getLocation(); + } + +} \ No newline at end of file
--- a/plugins/host-cpu/distribution/configFiles/backend-config.properties Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/host-cpu/distribution/configFiles/backend-config.properties Thu Oct 19 12:12:42 2017 -0400 @@ -1,2 +1,3 @@ -# URL to the microservice provided by the Thermostat web gateway -gatewayURL=https://localhost:30000/system-cpu/0.0.1 +# Web socket base URL to the commands microservice provided by the Thermostat web gateway +gatewayURL=wss://127.0.0.1:30000/commands/v1 +enabled=true \ No newline at end of file
--- a/plugins/host-memory/agent/src/main/java/com/redhat/thermostat/host/memory/agent/internal/HostMemoryBackend.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/host-memory/agent/src/main/java/com/redhat/thermostat/host/memory/agent/internal/HostMemoryBackend.java Thu Oct 19 12:12:42 2017 -0400 @@ -38,6 +38,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; +import java.util.logging.Level; +import java.util.logging.Logger; import com.redhat.thermostat.backend.Backend; import com.redhat.thermostat.common.portability.HostName; @@ -45,19 +47,27 @@ import com.redhat.thermostat.backend.HostPollingAction; import com.redhat.thermostat.backend.HostPollingBackend; import com.redhat.thermostat.common.Version; +import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.storage.core.WriterID; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; import org.osgi.framework.BundleContext; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "host-memory" +) @Service(value = Backend.class) public class HostMemoryBackend extends HostPollingBackend { + private static final Logger logger = LoggingUtils.getLogger(HostMemoryBackend.class); + @Reference private MemoryStatDAO memoryStatDAO; @@ -83,6 +93,17 @@ registerAction(new MemoryProcBackendAction(writerID, memoryStatDAO)); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + public void modified() throws Exception { + logger.config("Doing nothing on configuration change for plugin host-memory"); + } + + @Deactivate protected void componentDeactivated() { if (isActive()) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/host-memory/agent/src/main/java/com/redhat/thermostat/host/memory/agent/internal/HostMemoryBackendConfiguration.java Thu Oct 19 12:12:42 2017 -0400 @@ -0,0 +1,80 @@ +/* + * 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.host.memory.agent.internal; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.backend.BackendConfiguration; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugin.BackendConfigurationUtil; + +@Component +@Service(value = BackendConfiguration.class) +public class HostMemoryBackendConfiguration implements BackendConfiguration { + + private static final String PLUGIN_ID = "host-memory"; + private String location; + + @Reference + private ConfigurationInfoSource configInfoSource; + + @Override + public boolean isEnabled() { + BackendConfigurationUtil configuration = new BackendConfigurationUtil(configInfoSource, PLUGIN_ID); + return configuration.isEnabled(); + } + + @Override + public String getPluginId() { + return PLUGIN_ID; + } + + @Override + public String getLocation() { + return location; + } + + @Activate + public void activate(BundleContext context) { + location = context.getBundle().getLocation(); + } + +} \ No newline at end of file
--- a/plugins/host-memory/agent/src/main/java/com/redhat/thermostat/host/memory/agent/internal/MemoryStatDAOImpl.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/host-memory/agent/src/main/java/com/redhat/thermostat/host/memory/agent/internal/MemoryStatDAOImpl.java Thu Oct 19 12:12:42 2017 -0400 @@ -44,6 +44,8 @@ import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; @@ -56,7 +58,10 @@ import com.redhat.thermostat.host.memory.model.MemoryStat; import com.redhat.thermostat.host.memory.model.MemoryStatTypeAdapter; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "host-memory" +) @Service(value = MemoryStatDAO.class) public class MemoryStatDAOImpl extends PluginDAOBase<MemoryStat> implements MemoryStatDAO { @@ -91,6 +96,16 @@ config = configCreator.create(configurationInfoSource); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.fine("Doing nothing on configuration change for plugin " + PLUGIN_ID); + } + public String getPluginId() { return PLUGIN_ID; }
--- a/plugins/host-memory/distribution/configFiles/backend-config.properties Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/host-memory/distribution/configFiles/backend-config.properties Thu Oct 19 12:12:42 2017 -0400 @@ -1,2 +1,3 @@ # URL to the microservice provided by the Thermostat web gateway gatewayURL=https://localhost:30000/system-memory/0.0.1 +enabled=true
--- a/plugins/host-network/agent/src/main/java/com/redhat/thermostat/host/network/internal/HostNetworkBackend.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/host-network/agent/src/main/java/com/redhat/thermostat/host/network/internal/HostNetworkBackend.java Thu Oct 19 12:12:42 2017 -0400 @@ -39,6 +39,7 @@ import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; +import java.util.logging.Logger; import com.redhat.thermostat.backend.Backend; import com.redhat.thermostat.backend.HostPollingAction; @@ -46,21 +47,29 @@ import com.redhat.thermostat.common.Version; import com.redhat.thermostat.common.Clock; import com.redhat.thermostat.common.SystemClock; +import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.host.network.model.NetworkInfoList; import com.redhat.thermostat.host.network.model.NetworkInterfaceInfo; import com.redhat.thermostat.storage.core.WriterID; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; import org.osgi.framework.BundleContext; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "host-network" +) @Service(value = Backend.class) public class HostNetworkBackend extends HostPollingBackend { + private static final Logger logger = LoggingUtils.getLogger(HostNetworkBackend.class); + private final long procCheckInterval = 1000; // TODO make this configurable. private final Clock clock; @@ -92,6 +101,16 @@ registerAction(new BackendAction(writerID, clock, networkInterfaceInfoDAO)); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin host-network"); + } + @Deactivate protected void componentDeactivated() { if (isActive()) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/host-network/agent/src/main/java/com/redhat/thermostat/host/network/internal/HostNetworkBackendConfiguration.java Thu Oct 19 12:12:42 2017 -0400 @@ -0,0 +1,80 @@ +/* + * 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.host.network.internal; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.backend.BackendConfiguration; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugin.BackendConfigurationUtil; + +@Component +@Service(value = BackendConfiguration.class) +public class HostNetworkBackendConfiguration implements BackendConfiguration { + + private static final String PLUGIN_ID = "host-network"; + private String location; + + @Reference + private ConfigurationInfoSource configInfoSource; + + @Override + public boolean isEnabled() { + BackendConfigurationUtil configuration = new BackendConfigurationUtil(configInfoSource, PLUGIN_ID); + return configuration.isEnabled(); + } + + @Override + public String getPluginId() { + return PLUGIN_ID; + } + + @Override + public String getLocation() { + return location; + } + + @Activate + public void activate(BundleContext context) { + location = context.getBundle().getLocation(); + } + +} \ No newline at end of file
--- a/plugins/host-network/agent/src/main/java/com/redhat/thermostat/host/network/internal/NetworkInfoListDAOImpl.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/host-network/agent/src/main/java/com/redhat/thermostat/host/network/internal/NetworkInfoListDAOImpl.java Thu Oct 19 12:12:42 2017 -0400 @@ -44,6 +44,8 @@ import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; @@ -56,7 +58,10 @@ import com.redhat.thermostat.host.network.model.NetworkInfoList; import com.redhat.thermostat.host.network.model.NetworkInfoListTypeAdapter; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "host-network" +) @Service(value = NetworkInfoListDAO.class) public class NetworkInfoListDAOImpl extends PluginDAOBase<NetworkInfoList> implements NetworkInfoListDAO { @@ -87,6 +92,16 @@ config = configCreator.create(configurationInfoSource); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin " + PLUGIN_ID); + } + NetworkInfoListDAOImpl(JsonHelper jsonHelper, ConfigurationCreator creator) throws Exception { this.jsonHelper = jsonHelper; this.configCreator = creator;
--- a/plugins/host-network/distribution/configFiles/backend-config.properties Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/host-network/distribution/configFiles/backend-config.properties Thu Oct 19 12:12:42 2017 -0400 @@ -1,2 +1,3 @@ # URL to the microservice provided by the Thermostat web gateway gatewayURL=https://localhost:30000/system-network/0.0.1 +enabled=true
--- a/plugins/host-overview/agent/src/main/java/com/redhat/thermostat/host/overview/internal/HostOverviewBackend.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/host-overview/agent/src/main/java/com/redhat/thermostat/host/overview/internal/HostOverviewBackend.java Thu Oct 19 12:12:42 2017 -0400 @@ -36,9 +36,15 @@ package com.redhat.thermostat.host.overview.internal; +import java.util.logging.Logger; + +import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.host.overview.internal.models.HostInfoBuilderImpl; +import com.redhat.thermostat.host.overview.internal.models.HostInfoDAOImpl; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; @@ -52,9 +58,14 @@ import com.redhat.thermostat.host.overview.model.HostInfo; import com.redhat.thermostat.storage.core.WriterID; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "host-overview" +) @Service(value = Backend.class) public class HostOverviewBackend extends BaseBackend { + + private static final Logger logger = LoggingUtils.getLogger(HostOverviewBackend.class); private final HostInfoBuilderCreator builderCreator; @@ -106,6 +117,16 @@ Version version = new Version(context.getBundle()); setVersion(version.getVersionNumber()); } + + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin host-overview"); + } @Deactivate protected void componentDeactivated() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/host-overview/agent/src/main/java/com/redhat/thermostat/host/overview/internal/HostOverviewBackendConfiguration.java Thu Oct 19 12:12:42 2017 -0400 @@ -0,0 +1,80 @@ +/* + * 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.host.overview.internal; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.backend.BackendConfiguration; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugin.BackendConfigurationUtil; + +@Component +@Service(value = BackendConfiguration.class) +public class HostOverviewBackendConfiguration implements BackendConfiguration { + + private static final String PLUGIN_ID = "host-overview"; + private String location; + + @Reference + private ConfigurationInfoSource configInfoSource; + + @Override + public boolean isEnabled() { + BackendConfigurationUtil configuration = new BackendConfigurationUtil(configInfoSource, PLUGIN_ID); + return configuration.isEnabled(); + } + + @Override + public String getPluginId() { + return PLUGIN_ID; + } + + @Override + public String getLocation() { + return location; + } + + @Activate + public void activate(BundleContext context) { + location = context.getBundle().getLocation(); + } + +} \ No newline at end of file
--- a/plugins/host-overview/agent/src/main/java/com/redhat/thermostat/host/overview/internal/models/HostInfoDAOImpl.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/host-overview/agent/src/main/java/com/redhat/thermostat/host/overview/internal/models/HostInfoDAOImpl.java Thu Oct 19 12:12:42 2017 -0400 @@ -44,6 +44,8 @@ import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; @@ -56,7 +58,10 @@ import com.redhat.thermostat.host.overview.model.HostInfo; import com.redhat.thermostat.host.overview.model.HostInfoTypeAdapter; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "host-overview" +) @Service(value = HostInfoDAO.class) public class HostInfoDAOImpl extends PluginDAOBase<HostInfo> implements HostInfoDAO { @@ -93,6 +98,16 @@ this.config = configCreator.create(configurationInfoSource); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin " + PLUGIN_ID); + } + public URI getPostURI(final URI base, HostInfo obj) { return base.resolve("systems/" + systemID.getSystemID()); }
--- a/plugins/host-overview/distribution/configFiles/backend-config.properties Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/host-overview/distribution/configFiles/backend-config.properties Thu Oct 19 12:12:42 2017 -0400 @@ -1,2 +1,3 @@ # URL to the microservice provided by the Thermostat web gateway gatewayURL=https://localhost:30000/systems/0.0.1 +enabled=true \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/jvm-overview/agent/src/main/java/com/redhat/thermostat/jvm/overview/agent/internal/JvmOverviewBackendConfiguration.java Thu Oct 19 12:12:42 2017 -0400 @@ -0,0 +1,80 @@ +/* + * 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.jvm.overview.agent.internal; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.backend.BackendConfiguration; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugin.BackendConfigurationUtil; + +@Component +@Service(value = BackendConfiguration.class) +public class JvmOverviewBackendConfiguration implements BackendConfiguration { + + private static final String PLUGIN_ID = "jvm-overview"; + private String location; + + @Reference + private ConfigurationInfoSource configInfoSource; + + @Override + public boolean isEnabled() { + BackendConfigurationUtil configuration = new BackendConfigurationUtil(configInfoSource, PLUGIN_ID); + return configuration.isEnabled(); + } + + @Override + public String getPluginId() { + return PLUGIN_ID; + } + + @Override + public String getLocation() { + return location; + } + + @Activate + public void activate(BundleContext context) { + location = context.getBundle().getLocation(); + } + +} \ No newline at end of file
--- a/plugins/jvm-overview/agent/src/main/java/com/redhat/thermostat/jvm/overview/agent/internal/VMMonitorBackend.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/jvm-overview/agent/src/main/java/com/redhat/thermostat/jvm/overview/agent/internal/VMMonitorBackend.java Thu Oct 19 12:12:42 2017 -0400 @@ -48,6 +48,8 @@ import com.redhat.thermostat.storage.core.WriterID; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; @@ -63,7 +65,10 @@ /** */ -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "jvm-overview" +) @Service(value = Backend.class) public class VMMonitorBackend extends BaseBackend { private static final Logger logger = LoggingUtils.getLogger(VMMonitorBackend.class); @@ -103,6 +108,16 @@ notifier.start(); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin jvm-overview"); + } + @Deactivate private void _deactivate_() { notifier.stop();
--- a/plugins/jvm-overview/agent/src/main/java/com/redhat/thermostat/jvm/overview/agent/internal/model/VmInfoDAOImpl.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/jvm-overview/agent/src/main/java/com/redhat/thermostat/jvm/overview/agent/internal/model/VmInfoDAOImpl.java Thu Oct 19 12:12:42 2017 -0400 @@ -47,6 +47,8 @@ import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; @@ -61,7 +63,10 @@ import com.redhat.thermostat.jvm.overview.agent.model.VmInfo; import com.redhat.thermostat.storage.core.AgentId; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "jvm-overview" +) @Service(VmInfoDAO.class) public class VmInfoDAOImpl implements VmInfoDAO { @@ -101,6 +106,16 @@ this.gatewayURL = config.getGatewayURL(); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin jvm-overview"); + } + @Override public VmInfo getVmInfo(final VmId id) { return null; // TODO Remove once VM Id completer is removed
--- a/plugins/jvm-overview/distribution/configFiles/backend-config.properties Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/jvm-overview/distribution/configFiles/backend-config.properties Thu Oct 19 12:12:42 2017 -0400 @@ -1,2 +1,3 @@ # URL to the microservice provided by the Thermostat web gateway gatewayURL=https://localhost:30000/jvms/0.0.1/ +enabled=true
--- a/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatBackend.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatBackend.java Thu Oct 19 12:12:42 2017 -0400 @@ -38,21 +38,31 @@ import com.redhat.thermostat.backend.Backend; import com.redhat.thermostat.common.Version; +import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.jvm.overview.agent.VmListenerBackend; import com.redhat.thermostat.jvm.overview.agent.VmStatusListenerRegistrar; import com.redhat.thermostat.jvm.overview.agent.VmUpdateListener; import com.redhat.thermostat.storage.core.WriterID; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; import org.osgi.framework.BundleContext; -@Component +import java.util.logging.Logger; + +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "vm-classstat" +) @Service(value = Backend.class) public class VmClassStatBackend extends VmListenerBackend { + private static final Logger logger = LoggingUtils.getLogger(VmClassStatBackend.class); + private final ListenerCreator listenerCreator; @Reference @@ -80,6 +90,17 @@ initialize(writerID, registrar, version.getVersionNumber()); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin vm-classstat"); + } + + @Deactivate protected void componentDeactivated() { if (isActive()) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatBackendConfiguration.java Thu Oct 19 12:12:42 2017 -0400 @@ -0,0 +1,79 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.classstat.agent.internal; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.backend.BackendConfiguration; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugin.BackendConfigurationUtil; + +@Component +@Service(value = BackendConfiguration.class) +public class VmClassStatBackendConfiguration implements BackendConfiguration { + + private static final String PLUGIN_ID = "vm-classstat"; + private String location; + + @Reference + private ConfigurationInfoSource configInfoSource; + + @Override + public boolean isEnabled() { + BackendConfigurationUtil configuration = new BackendConfigurationUtil(configInfoSource, PLUGIN_ID); + return configuration.isEnabled(); + } + + @Override + public String getPluginId() { + return PLUGIN_ID; + } + + @Override + public String getLocation() { + return location; + } + + @Activate + public void activate(BundleContext context) { + location = context.getBundle().getLocation(); + } +}
--- a/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatDAOImpl.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-classstat/agent/src/main/java/com/redhat/thermostat/vm/classstat/agent/internal/VmClassStatDAOImpl.java Thu Oct 19 12:12:42 2017 -0400 @@ -53,10 +53,16 @@ import com.redhat.thermostat.vm.classstat.model.VmClassStatTypeAdapter; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "vm-classstat" +) @Service(value = VmClassStatDAO.class) public class VmClassStatDAOImpl extends PluginDAOBase<VmClassStat> implements VmClassStatDAO { @@ -93,6 +99,16 @@ this.gatewayURL = config.getGatewayURL(); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin vm-classstat"); + } + @Override protected String toJsonString(VmClassStat obj) throws IOException { return jsonHelper.toJson(Arrays.asList(obj));
--- a/plugins/vm-classstat/distribution/configFiles/backend-config.properties Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-classstat/distribution/configFiles/backend-config.properties Thu Oct 19 12:12:42 2017 -0400 @@ -1,2 +1,3 @@ # URL to the microservice provided by the Thermostat web gateway -gatewayURL=https://localhost:30000/jvm-classstat/0.0.1 \ No newline at end of file +gatewayURL=https://localhost:30000/jvm-classstat/0.0.1 +enabled=true \ No newline at end of file
--- a/plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatBackend.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatBackend.java Thu Oct 19 12:12:42 2017 -0400 @@ -36,24 +36,34 @@ package com.redhat.thermostat.vm.compiler.agent.internal; +import java.util.logging.Logger; + import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; import org.osgi.framework.BundleContext; import com.redhat.thermostat.backend.Backend; import com.redhat.thermostat.common.Version; +import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.jvm.overview.agent.VmListenerBackend; import com.redhat.thermostat.jvm.overview.agent.VmStatusListenerRegistrar; import com.redhat.thermostat.jvm.overview.agent.VmUpdateListener; import com.redhat.thermostat.storage.core.WriterID; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "vm-compiler" +) @Service(value = Backend.class) public class VmCompilerStatBackend extends VmListenerBackend { + private static final Logger logger = LoggingUtils.getLogger(VmCompilerStatBackend.class); + private final ListenerCreator listenerCreator; @Reference @@ -78,6 +88,16 @@ initialize(writerID, registrar, version.getVersionNumber()); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin vm-compiler"); + } + @Deactivate protected void componentDeactivated() { if (isActive()) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatBackendConfiguration.java Thu Oct 19 12:12:42 2017 -0400 @@ -0,0 +1,79 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.compiler.agent.internal; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.backend.BackendConfiguration; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugin.BackendConfigurationUtil; + +@Component +@Service(value = BackendConfiguration.class) +public class VmCompilerStatBackendConfiguration implements BackendConfiguration { + + private static final String PLUGIN_ID = "vm-compiler"; + private String location; + + @Reference + private ConfigurationInfoSource configInfoSource; + + @Override + public boolean isEnabled() { + BackendConfigurationUtil configuration = new BackendConfigurationUtil(configInfoSource, PLUGIN_ID); + return configuration.isEnabled(); + } + + @Override + public String getPluginId() { + return PLUGIN_ID; + } + + @Override + public String getLocation() { + return location; + } + + @Activate + public void activate(BundleContext context) { + location = context.getBundle().getLocation(); + } +}
--- a/plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatDaoImpl.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-compiler/agent/src/main/java/com/redhat/thermostat/vm/compiler/agent/internal/VmCompilerStatDaoImpl.java Thu Oct 19 12:12:42 2017 -0400 @@ -45,6 +45,8 @@ import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; @@ -57,7 +59,10 @@ import com.redhat.thermostat.vm.compiler.model.VmCompilerStat; import com.redhat.thermostat.vm.compiler.model.VmCompilerStatTypeAdapter; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "vm-compiler" +) @Service(value = VmCompilerStatDao.class) public class VmCompilerStatDaoImpl extends PluginDAOBase<VmCompilerStat> implements VmCompilerStatDao { @@ -93,6 +98,17 @@ this.gatewayURL = config.getGatewayURL(); } + + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin vm-compiler"); + } + @Override protected String toJsonString(VmCompilerStat obj) throws IOException { return jsonHelper.toJson(Arrays.asList(obj));
--- a/plugins/vm-compiler/distribution/configFiles/backend-config.properties Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-compiler/distribution/configFiles/backend-config.properties Thu Oct 19 12:12:42 2017 -0400 @@ -1,2 +1,3 @@ # URL to the jvm-compiler microservice provided by the Thermostat web gateway gatewayURL=https://localhost:30000/jvm-compiler/0.0.1 +enabled=true \ No newline at end of file
--- a/plugins/vm-cpu/agent/src/main/java/com/redhat/thermostat/vm/cpu/agent/internal/VmCpuBackend.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-cpu/agent/src/main/java/com/redhat/thermostat/vm/cpu/agent/internal/VmCpuBackend.java Thu Oct 19 12:12:42 2017 -0400 @@ -58,12 +58,17 @@ import com.redhat.thermostat.vm.cpu.agent.model.VmCpuStat; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; import org.osgi.framework.BundleContext; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "vm-cpu" +) @Service(value = Backend.class) public class VmCpuBackend extends VmPollingBackend { @@ -94,6 +99,17 @@ registerAction(action); } + + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + LOGGER.config("Doing nothing on configuration change for plugin vm-cpu"); + } + @Deactivate protected void componentDeactivated() { if (isActive()) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-cpu/agent/src/main/java/com/redhat/thermostat/vm/cpu/agent/internal/VmCpuBackendConfiguration.java Thu Oct 19 12:12:42 2017 -0400 @@ -0,0 +1,80 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.cpu.agent.internal; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.backend.BackendConfiguration; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugin.BackendConfigurationUtil; + +@Component +@Service(value = BackendConfiguration.class) +public class VmCpuBackendConfiguration implements BackendConfiguration { + + private static final String PLUGIN_ID = "vm-cpu"; + private String location; + + @Reference + private ConfigurationInfoSource configInfoSource; + + @Override + public boolean isEnabled() { + BackendConfigurationUtil configuration = new BackendConfigurationUtil(configInfoSource, PLUGIN_ID); + return configuration.isEnabled(); + } + + @Override + public String getPluginId() { + return PLUGIN_ID; + } + + @Override + public String getLocation() { + return location; + } + + @Activate + public void activate(BundleContext context) { + location = context.getBundle().getLocation(); + } + +} \ No newline at end of file
--- a/plugins/vm-cpu/agent/src/main/java/com/redhat/thermostat/vm/cpu/agent/internal/VmCpuStatDAOImpl.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-cpu/agent/src/main/java/com/redhat/thermostat/vm/cpu/agent/internal/VmCpuStatDAOImpl.java Thu Oct 19 12:12:42 2017 -0400 @@ -52,10 +52,15 @@ import com.redhat.thermostat.vm.cpu.agent.model.VmCpuStatTypeAdapter; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "vm-cpu" +) @Service(value = VmCpuStatDAO.class) public class VmCpuStatDAOImpl extends PluginDAOBase<VmCpuStat> implements VmCpuStatDAO { @@ -89,6 +94,17 @@ pluginConfiguration = configurationCreator.create(configurationInfoSource); } + + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin vm-cpu"); + } + @Override protected String toJsonString(VmCpuStat obj) throws IOException { return jsonHelper.toJson(Collections.singletonList(obj));
--- a/plugins/vm-cpu/distribution/configFiles/backend-config.properties Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-cpu/distribution/configFiles/backend-config.properties Thu Oct 19 12:12:42 2017 -0400 @@ -1,2 +1,3 @@ # URL to the jvm-cpu microservice provided by the Thermostat web gateway gatewayURL=https://localhost:30000/jvm-cpu/0.0.1 +enabled=true \ No newline at end of file
--- a/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/VmGcBackend.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/VmGcBackend.java Thu Oct 19 12:12:42 2017 -0400 @@ -36,11 +36,16 @@ package com.redhat.thermostat.vm.gc.agent.internal; +import java.util.logging.Logger; + +import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.jvm.overview.agent.VmListenerBackend; import com.redhat.thermostat.jvm.overview.agent.VmStatusListenerRegistrar; import com.redhat.thermostat.jvm.overview.agent.VmUpdateListener; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; @@ -50,10 +55,15 @@ import com.redhat.thermostat.storage.core.WriterID; import com.redhat.thermostat.vm.gc.agent.internal.models.VmGcStatDAO; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "vm-gc" +) @Service(value = Backend.class) public class VmGcBackend extends VmListenerBackend { - + + private static final Logger logger = LoggingUtils.getLogger(VmGcBackend.class); + private final ListenerCreator listenerCreator; @Reference @@ -81,6 +91,16 @@ Version version = new Version(context.getBundle()); initialize(writerId, registrar, version.getVersionNumber()); } + + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin vm-gc"); + } @Deactivate protected void componentDeactivated() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/VmGcBackendConfiguration.java Thu Oct 19 12:12:42 2017 -0400 @@ -0,0 +1,80 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.internal; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.backend.BackendConfiguration; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugin.BackendConfigurationUtil; + +@Component +@Service(value = BackendConfiguration.class) +public class VmGcBackendConfiguration implements BackendConfiguration { + + private static final String PLUGIN_ID = "vm-gc"; + private String location; + + @Reference + private ConfigurationInfoSource configInfoSource; + + @Override + public boolean isEnabled() { + BackendConfigurationUtil configuration = new BackendConfigurationUtil(configInfoSource, PLUGIN_ID); + return configuration.isEnabled(); + } + + @Override + public String getPluginId() { + return PLUGIN_ID; + } + + @Override + public String getLocation() { + return location; + } + + @Activate + public void activate(BundleContext context) { + location = context.getBundle().getLocation(); + } + +} \ No newline at end of file
--- a/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/models/VmGcStatDAOImpl.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/models/VmGcStatDAOImpl.java Thu Oct 19 12:12:42 2017 -0400 @@ -46,6 +46,8 @@ import com.redhat.thermostat.common.plugin.SystemID; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; @@ -56,7 +58,10 @@ import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.vm.gc.agent.model.VmGcStat; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "vm-gc" +) @Service(value = VmGcStatDAO.class) public class VmGcStatDAOImpl implements VmGcStatDAO { @@ -92,6 +97,16 @@ this.gatewayURL = config.getGatewayURL(); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin " + PLUGIN_ID); + } + void bindSystemID(final SystemID id) { this.systemID = id; }
--- a/plugins/vm-gc/distribution/configFiles/backend-config.properties Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-gc/distribution/configFiles/backend-config.properties Thu Oct 19 12:12:42 2017 -0400 @@ -1,2 +1,3 @@ # URL to the jvm-gc microservice provided by the Thermostat web gateway gatewayURL=https://localhost:30000/jvm-gc/0.0.3 +enabled=true
--- a/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoBackend.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoBackend.java Thu Oct 19 12:12:42 2017 -0400 @@ -39,6 +39,7 @@ import com.redhat.thermostat.backend.Backend; import com.redhat.thermostat.common.SystemClock; import com.redhat.thermostat.common.Version; +import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.jvm.overview.agent.VmListenerBackend; import com.redhat.thermostat.jvm.overview.agent.VmStatusListenerRegistrar; import com.redhat.thermostat.jvm.overview.agent.VmUpdate; @@ -47,15 +48,24 @@ import com.redhat.thermostat.vm.io.model.VmIoStat; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; import org.osgi.framework.BundleContext; -@Component +import java.util.logging.Logger; + +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "vm-io" +) @Service(value = Backend.class) public class VmIoBackend extends VmListenerBackend { - + + private Logger logger = LoggingUtils.getLogger(VmIoBackend.class); + private final ListenerCreator listenerCreator; @Reference @@ -87,6 +97,16 @@ initialize(writerId, registrar, version.getVersionNumber()); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.fine("Doing nothing on configuration change for plugin vm-io"); + } + @Deactivate protected void componentDeactivated() { if (isActive()) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoBackendConfiguration.java Thu Oct 19 12:12:42 2017 -0400 @@ -0,0 +1,80 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.io.agent.internal; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.backend.BackendConfiguration; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugin.BackendConfigurationUtil; + +@Component +@Service(value = BackendConfiguration.class) +public class VmIoBackendConfiguration implements BackendConfiguration { + + private static final String PLUGIN_ID = "vm-io"; + private String location; + + @Reference + private ConfigurationInfoSource configInfoSource; + + @Override + public boolean isEnabled() { + BackendConfigurationUtil configuration = new BackendConfigurationUtil(configInfoSource, PLUGIN_ID); + return configuration.isEnabled(); + } + + @Override + public String getPluginId() { + return PLUGIN_ID; + } + + @Override + public String getLocation() { + return location; + } + + @Activate + public void activate(BundleContext context) { + location = context.getBundle().getLocation(); + } + +} \ No newline at end of file
--- a/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatDAOImpl.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatDAOImpl.java Thu Oct 19 12:12:42 2017 -0400 @@ -52,10 +52,15 @@ import com.redhat.thermostat.vm.io.model.VmIoStatTypeAdapter; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "vm-io" +) @Service(value = VmIoStatDAO.class) public class VmIoStatDAOImpl extends PluginDAOBase<VmIoStat> implements VmIoStatDAO { @@ -89,6 +94,16 @@ config = configCreator.create(configurationInfoSource); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.fine("Doing nothing on configuration change for plugin " + PLUGIN_ID); + } + public String getPluginId() { return PLUGIN_ID; }
--- a/plugins/vm-io/distribution/configFiles/backend-config.properties Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-io/distribution/configFiles/backend-config.properties Thu Oct 19 12:12:42 2017 -0400 @@ -1,2 +1,3 @@ # URL to the microservice provided by the Thermostat web gateway gatewayURL=https://localhost:30000/jvm-io/0.0.1 +enabled=true
--- a/plugins/vm-memory/agent/src/main/java/com/redhat/thermostat/vm/memory/agent/internal/VmMemoryBackend.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-memory/agent/src/main/java/com/redhat/thermostat/vm/memory/agent/internal/VmMemoryBackend.java Thu Oct 19 12:12:42 2017 -0400 @@ -36,8 +36,13 @@ package com.redhat.thermostat.vm.memory.agent.internal; +import java.util.logging.Logger; + +import com.redhat.thermostat.common.utils.LoggingUtils; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; @@ -52,10 +57,15 @@ import com.redhat.thermostat.vm.memory.agent.internal.models.VmMemoryStatDAO; import com.redhat.thermostat.vm.memory.agent.internal.models.VmTlabStatDAO; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "vm-memory" +) @Service(value = Backend.class) public class VmMemoryBackend extends VmListenerBackend { + private static final Logger logger = LoggingUtils.getLogger(VmMemoryBackend.class); + private final ListenerCreator listenerCreator; @Reference @@ -83,6 +93,16 @@ initialize(writerId, registrar, version.getVersionNumber()); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin vm-memory"); + } + @Deactivate protected void componentDeactivated() { if (isActive()) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-memory/agent/src/main/java/com/redhat/thermostat/vm/memory/agent/internal/VmMemoryBackendConfiguration.java Thu Oct 19 12:12:42 2017 -0400 @@ -0,0 +1,80 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.memory.agent.internal; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.backend.BackendConfiguration; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugin.BackendConfigurationUtil; + +@Component +@Service(value = BackendConfiguration.class) +public class VmMemoryBackendConfiguration implements BackendConfiguration { + + private static final String PLUGIN_ID = "vm-memory"; + private String location; + + @Reference + private ConfigurationInfoSource configInfoSource; + + @Override + public boolean isEnabled() { + BackendConfigurationUtil configuration = new BackendConfigurationUtil(configInfoSource, PLUGIN_ID); + return configuration.isEnabled(); + } + + @Override + public String getPluginId() { + return PLUGIN_ID; + } + + @Override + public String getLocation() { + return location; + } + + @Activate + public void activate(BundleContext context) { + location = context.getBundle().getLocation(); + } + +} \ No newline at end of file
--- a/plugins/vm-memory/agent/src/main/java/com/redhat/thermostat/vm/memory/agent/internal/models/VmMemoryStatDAOImpl.java Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-memory/agent/src/main/java/com/redhat/thermostat/vm/memory/agent/internal/models/VmMemoryStatDAOImpl.java Thu Oct 19 12:12:42 2017 -0400 @@ -46,6 +46,8 @@ import com.redhat.thermostat.common.plugin.SystemID; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; @@ -56,7 +58,10 @@ import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.vm.memory.agent.model.VmMemoryStat; -@Component +@Component( + policy = ConfigurationPolicy.REQUIRE, + configurationPid = "vm-memory" +) @Service(value = VmMemoryStatDAO.class) public class VmMemoryStatDAOImpl implements VmMemoryStatDAO { @@ -93,6 +98,16 @@ this.gatewayURL = config.getGatewayURL(); } + /* + * Default OSGI behaviour is to restart the component when configuration changes. + * The @modified method acts as a callback to prevent this from happening since + * we don't need to restart the component for our use-case. + */ + @Modified + protected void modified() { + logger.config("Doing nothing on configuration change for plugin vm-memory"); + } + void bindSystemID(final SystemID id) { this.systemID = id; }
--- a/plugins/vm-memory/distribution/configFiles/backend-config.properties Thu Oct 19 11:44:23 2017 -0400 +++ b/plugins/vm-memory/distribution/configFiles/backend-config.properties Thu Oct 19 12:12:42 2017 -0400 @@ -1,2 +1,3 @@ # URL to the jvm-memory microservice provided by the Thermostat web gateway gatewayURL=https://localhost:30000/jvm-memory/0.0.3 +enabled=true