Mercurial > hg > thermostat-ng > agent
changeset 2640:5f97c4af3bf3
This patch brings over some cleanup code from the old Thermostat.
Some factory and builder classes are added to common-portablility, and clients of that
package are updated to use those new classes.
line wrap: on
line diff
--- a/agent/core/src/main/java/com/redhat/thermostat/utils/management/internal/MXBeanConnectionPoolImpl.java Tue May 09 10:31:37 2017 +0200 +++ b/agent/core/src/main/java/com/redhat/thermostat/utils/management/internal/MXBeanConnectionPoolImpl.java Mon May 08 19:16:24 2017 -0400 @@ -61,6 +61,7 @@ import com.redhat.thermostat.agent.ipc.server.ThermostatIPCCallbacks; import com.redhat.thermostat.common.portability.ProcessUserInfo; import com.redhat.thermostat.common.portability.ProcessUserInfoBuilder; +import com.redhat.thermostat.common.portability.ProcessUserInfoBuilderFactory; import com.redhat.thermostat.common.portability.linux.ProcDataSource; import com.redhat.thermostat.agent.utils.management.MXBeanConnection; import com.redhat.thermostat.agent.utils.management.MXBeanConnectionException; @@ -95,7 +96,7 @@ private boolean started; public MXBeanConnectionPoolImpl(File binPath, UserNameUtil userNameUtil, AgentIPCService ipcService) { - this(new ConnectorCreator(), binPath, ProcessUserInfo.createBuilder(new ProcDataSource(), userNameUtil), + this(new ConnectorCreator(), binPath, ProcessUserInfoBuilderFactory.createBuilder(new ProcDataSource(), userNameUtil), ipcService, new FileSystemUtils()); }
--- a/agent/ipc/server/src/main/java/com/redhat/thermostat/agent/ipc/server/internal/IPCConfigurationWriter.java Tue May 09 10:31:37 2017 +0200 +++ b/agent/ipc/server/src/main/java/com/redhat/thermostat/agent/ipc/server/internal/IPCConfigurationWriter.java Mon May 08 19:16:24 2017 -0400 @@ -44,7 +44,7 @@ import java.util.UUID; import com.redhat.thermostat.agent.ipc.common.internal.IPCType; -import com.redhat.thermostat.common.portability.PortableProcessImpl; +import com.redhat.thermostat.common.portability.PortableProcessFactory; import com.redhat.thermostat.shared.config.OS; class IPCConfigurationWriter { @@ -167,7 +167,7 @@ return new Properties(); } int getCurrentUid() { - return PortableProcessImpl.getInstance().getUid(0); // if pid=0, gets uid of current process + return PortableProcessFactory.getInstance().getUid(0); // if pid=0, gets uid of current process } }
--- a/agent/ipc/tcp-socket/client/pom.xml Tue May 09 10:31:37 2017 +0200 +++ b/agent/ipc/tcp-socket/client/pom.xml Mon May 08 19:16:24 2017 -0400 @@ -48,7 +48,7 @@ <artifactId>thermostat-agent-ipc-tcpsocket-client</artifactId> <packaging>jar</packaging> - <name>Thermostat IPC Client</name> + <name>Thermostat IPC Client - TCP</name> <dependencies> <dependency>
--- a/agent/ipc/tcp-socket/common/pom.xml Tue May 09 10:31:37 2017 +0200 +++ b/agent/ipc/tcp-socket/common/pom.xml Mon May 08 19:16:24 2017 -0400 @@ -48,7 +48,7 @@ <artifactId>thermostat-agent-ipc-tcpsocket-common</artifactId> <packaging>bundle</packaging> - <name>Thermostat IPC Common</name> + <name>Thermostat IPC Common - TCP</name> <dependencies> <dependency>
--- a/agent/ipc/tcp-socket/server/pom.xml Tue May 09 10:31:37 2017 +0200 +++ b/agent/ipc/tcp-socket/server/pom.xml Mon May 08 19:16:24 2017 -0400 @@ -48,7 +48,7 @@ <artifactId>thermostat-agent-ipc-tcpsocket-server</artifactId> <packaging>bundle</packaging> - <name>Thermostat IPC Server</name> + <name>Thermostat IPC Server - TCP</name> <dependencies> <dependency>
--- a/agent/ipc/unix-socket/client/pom.xml Tue May 09 10:31:37 2017 +0200 +++ b/agent/ipc/unix-socket/client/pom.xml Mon May 08 19:16:24 2017 -0400 @@ -48,7 +48,7 @@ <artifactId>thermostat-agent-ipc-unixsocket-client</artifactId> <packaging>jar</packaging> - <name>Thermostat IPC Client</name> + <name>Thermostat IPC Client - Unix Sockets</name> <dependencies> <dependency>
--- a/agent/ipc/unix-socket/common/pom.xml Tue May 09 10:31:37 2017 +0200 +++ b/agent/ipc/unix-socket/common/pom.xml Mon May 08 19:16:24 2017 -0400 @@ -48,7 +48,7 @@ <artifactId>thermostat-agent-ipc-unixsocket-common</artifactId> <packaging>bundle</packaging> - <name>Thermostat IPC Common</name> + <name>Thermostat IPC Common - Unix Sockets</name> <dependencies> <dependency>
--- a/agent/ipc/unix-socket/server/pom.xml Tue May 09 10:31:37 2017 +0200 +++ b/agent/ipc/unix-socket/server/pom.xml Mon May 08 19:16:24 2017 -0400 @@ -48,7 +48,7 @@ <artifactId>thermostat-agent-ipc-unixsocket-server</artifactId> <packaging>bundle</packaging> - <name>Thermostat IPC Server</name> + <name>Thermostat IPC Server - Unix Sockets</name> <dependencies> <dependency>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/portability/src/main/java/com/redhat/thermostat/common/portability/PortableHostFactory.java Mon May 08 19:16:24 2017 -0400 @@ -0,0 +1,57 @@ +/* + * 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.common.portability; + +import com.redhat.thermostat.common.portability.internal.linux.LinuxPortableHostImpl; +import com.redhat.thermostat.common.portability.internal.macos.MacOSHostImpl; +import com.redhat.thermostat.common.portability.internal.windows.WindowsPortableHostImpl; +import com.redhat.thermostat.shared.config.OS; + +public class PortableHostFactory { + + private static final PortableHost INSTANCE = createInstance(); + + private static PortableHost createInstance() { + return OS.IS_LINUX ? LinuxPortableHostImpl.createInstance() + : OS.IS_WINDOWS ? WindowsPortableHostImpl.createInstance() : MacOSHostImpl.createInstance(); + } + + public static PortableHost getInstance() { + return INSTANCE; + } +} +
--- a/common/portability/src/main/java/com/redhat/thermostat/common/portability/PortableHostImpl.java Tue May 09 10:31:37 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +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.common.portability; - -import com.redhat.thermostat.common.portability.internal.linux.LinuxPortableHostImpl; -import com.redhat.thermostat.common.portability.internal.macos.MacOSHostImpl; -import com.redhat.thermostat.common.portability.internal.windows.WindowsPortableHostImpl; -import com.redhat.thermostat.shared.config.OS; - -public class PortableHostImpl { - - private static final PortableHost INSTANCE = createInstance(); - - private static PortableHost createInstance() { - return OS.IS_LINUX ? LinuxPortableHostImpl.createInstance() - : OS.IS_WINDOWS ? WindowsPortableHostImpl.createInstance() : MacOSHostImpl.createInstance(); - } - - public static PortableHost getInstance() { - return INSTANCE; - } -} -
--- a/common/portability/src/main/java/com/redhat/thermostat/common/portability/PortableMemoryStat.java Tue May 09 10:31:37 2017 +0200 +++ b/common/portability/src/main/java/com/redhat/thermostat/common/portability/PortableMemoryStat.java Mon May 08 19:16:24 2017 -0400 @@ -82,8 +82,4 @@ public long getCommitLimit() { return commitLimit; } - - public static PortableMemoryStat build() { - return PortableHostImpl.getInstance().getMemoryStat(); - } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/portability/src/main/java/com/redhat/thermostat/common/portability/PortableMemoryStatFactory.java Mon May 08 19:16:24 2017 -0400 @@ -0,0 +1,44 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.common.portability; + +public class PortableMemoryStatFactory { + + public static PortableMemoryStat build() { + return PortableHostFactory.getInstance().getMemoryStat(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/portability/src/main/java/com/redhat/thermostat/common/portability/PortableProcessFactory.java Mon May 08 19:16:24 2017 -0400 @@ -0,0 +1,56 @@ +/* + * 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.common.portability; + +import com.redhat.thermostat.common.portability.internal.linux.LinuxPortableProcessImpl; +import com.redhat.thermostat.common.portability.internal.macos.MacOSProcessImpl; +import com.redhat.thermostat.common.portability.internal.windows.WindowsPortableProcessImpl; +import com.redhat.thermostat.shared.config.OS; + +public final class PortableProcessFactory { + + private static final PortableProcess INSTANCE = createInstance(); + + private static PortableProcess createInstance() { + return OS.IS_LINUX ? LinuxPortableProcessImpl.createInstance() + : OS.IS_WINDOWS ? WindowsPortableProcessImpl.createInstance() : MacOSProcessImpl.INSTANCE; + } + + public static PortableProcess getInstance() { + return INSTANCE; + } +}
--- a/common/portability/src/main/java/com/redhat/thermostat/common/portability/PortableProcessImpl.java Tue May 09 10:31:37 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +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.common.portability; - -import com.redhat.thermostat.common.portability.internal.linux.LinuxPortableProcessImpl; -import com.redhat.thermostat.common.portability.internal.macos.MacOSProcessImpl; -import com.redhat.thermostat.common.portability.internal.windows.WindowsPortableProcessImpl; -import com.redhat.thermostat.shared.config.OS; - -public final class PortableProcessImpl { - - private static final PortableProcess INSTANCE = createInstance(); - - private static PortableProcess createInstance() { - return OS.IS_LINUX ? LinuxPortableProcessImpl.createInstance() - : OS.IS_WINDOWS ? WindowsPortableProcessImpl.createInstance() : MacOSProcessImpl.INSTANCE; - } - - public static PortableProcess getInstance() { - return INSTANCE; - } -}
--- a/common/portability/src/main/java/com/redhat/thermostat/common/portability/PortableProcessStat.java Tue May 09 10:31:37 2017 +0200 +++ b/common/portability/src/main/java/com/redhat/thermostat/common/portability/PortableProcessStat.java Mon May 08 19:16:24 2017 -0400 @@ -69,9 +69,5 @@ public long getKernelTime() { return kernelTime; } - - public static PortableProcessStat build(int pid) { - return PortableProcessImpl.getInstance().getProcessStat(pid); - } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/portability/src/main/java/com/redhat/thermostat/common/portability/PortableProcessStatFactory.java Mon May 08 19:16:24 2017 -0400 @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.common.portability; + +public class PortableProcessStatFactory { + + public static PortableProcessStat build(int pid) { + return PortableProcessFactory.getInstance().getProcessStat(pid); + } +} +
--- a/common/portability/src/main/java/com/redhat/thermostat/common/portability/PortableVmIoStat.java Tue May 09 10:31:37 2017 +0200 +++ b/common/portability/src/main/java/com/redhat/thermostat/common/portability/PortableVmIoStat.java Mon May 08 19:16:24 2017 -0400 @@ -55,10 +55,6 @@ this.charactersWritten = charactersWritten; } - public static PortableVmIoStat build(Clock clock, int pid) { - return PortableProcessImpl.getInstance().getVmIoStat(clock, pid); - } - public long getTimeStamp() { return timeStamp; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/portability/src/main/java/com/redhat/thermostat/common/portability/PortableVmIoStatFactory.java Mon May 08 19:16:24 2017 -0400 @@ -0,0 +1,46 @@ +/* + * 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.common.portability; + +import com.redhat.thermostat.common.Clock; + +public class PortableVmIoStatFactory { + + public static PortableVmIoStat build(Clock clock, int pid) { + return PortableProcessFactory.getInstance().getVmIoStat(clock, pid); + } +}
--- a/common/portability/src/main/java/com/redhat/thermostat/common/portability/ProcessChecker.java Tue May 09 10:31:37 2017 +0200 +++ b/common/portability/src/main/java/com/redhat/thermostat/common/portability/ProcessChecker.java Mon May 08 19:16:24 2017 -0400 @@ -41,6 +41,7 @@ import com.redhat.thermostat.shared.config.OS; import java.io.File; + /** * Utility for checking whether a process exists or not. *
--- a/common/portability/src/main/java/com/redhat/thermostat/common/portability/ProcessUserInfo.java Tue May 09 10:31:37 2017 +0200 +++ b/common/portability/src/main/java/com/redhat/thermostat/common/portability/ProcessUserInfo.java Mon May 08 19:16:24 2017 -0400 @@ -36,13 +36,6 @@ package com.redhat.thermostat.common.portability; -import com.redhat.thermostat.common.portability.internal.UnimplementedError; -import com.redhat.thermostat.common.portability.internal.linux.LinuxProcessUserInfoBuilderImpl; -import com.redhat.thermostat.common.portability.internal.macos.MacOSUserInfoBuilderImpl; -import com.redhat.thermostat.common.portability.linux.ProcDataSource; -import com.redhat.thermostat.common.portability.internal.windows.WindowsUserInfoBuilderImpl; -import com.redhat.thermostat.shared.config.OS; - public class ProcessUserInfo { private long uid; @@ -65,30 +58,4 @@ public String getUsername() { return username; } - - public static ProcessUserInfoBuilder createBuilder(ProcDataSource source, UserNameUtil userNameUtil) { - final ProcessUserInfoBuilder builder; - if (OS.IS_LINUX) { - builder = new LinuxProcessUserInfoBuilderImpl(source, userNameUtil); - } else if (OS.IS_WINDOWS) { - builder = new WindowsUserInfoBuilderImpl(); - } else if (OS.IS_MACOS) { - builder = new MacOSUserInfoBuilderImpl(); - } else { - throw new UnimplementedError("ProcessUserInfo"); - } - return builder; - } - - public static ProcessUserInfoBuilder createBuilder() { - final ProcessUserInfoBuilder builder; - if (OS.IS_LINUX) { - builder = new LinuxProcessUserInfoBuilderImpl(); - } else if (OS.IS_WINDOWS) { - builder = new WindowsUserInfoBuilderImpl(); - } else { - builder = new MacOSUserInfoBuilderImpl(); - } - return builder; - } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/portability/src/main/java/com/redhat/thermostat/common/portability/ProcessUserInfoBuilderFactory.java Mon May 08 19:16:24 2017 -0400 @@ -0,0 +1,73 @@ +/* + * 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.common.portability; + +import com.redhat.thermostat.common.portability.internal.UnimplementedError; +import com.redhat.thermostat.common.portability.internal.linux.LinuxProcessUserInfoBuilderImpl; +import com.redhat.thermostat.common.portability.internal.macos.MacOSUserInfoBuilderImpl; +import com.redhat.thermostat.common.portability.internal.windows.WindowsUserInfoBuilderImpl; +import com.redhat.thermostat.common.portability.linux.ProcDataSource; +import com.redhat.thermostat.shared.config.OS; + +public class ProcessUserInfoBuilderFactory { + + public static ProcessUserInfoBuilder createBuilder(ProcDataSource source, UserNameUtil userNameUtil) { + final ProcessUserInfoBuilder builder; + if (OS.IS_LINUX) { + builder = new LinuxProcessUserInfoBuilderImpl(source, userNameUtil); + } else if (OS.IS_WINDOWS) { + builder = new WindowsUserInfoBuilderImpl(); + } else if (OS.IS_MACOS) { + builder = new MacOSUserInfoBuilderImpl(); + } else { + throw new UnimplementedError("ProcessUserInfo"); + } + return builder; + } + + public static ProcessUserInfoBuilder createBuilder() { + final ProcessUserInfoBuilder builder; + if (OS.IS_LINUX) { + builder = new LinuxProcessUserInfoBuilderImpl(); + } else if (OS.IS_WINDOWS) { + builder = new WindowsUserInfoBuilderImpl(); + } else { + builder = new MacOSUserInfoBuilderImpl(); + } + return builder; + } +}
--- a/common/portability/src/main/java/com/redhat/thermostat/common/portability/SysConf.java Tue May 09 10:31:37 2017 +0200 +++ b/common/portability/src/main/java/com/redhat/thermostat/common/portability/SysConf.java Mon May 08 19:16:24 2017 -0400 @@ -58,7 +58,7 @@ } private static long getWindowsClockTicksPerSecond() { - return PortableHostImpl.getInstance().getClockTicksPerSecond(); + return PortableHostFactory.getInstance().getClockTicksPerSecond(); } public static long getLinuxClockTicksPerSecond() {
--- a/common/portability/src/main/java/com/redhat/thermostat/common/portability/internal/macos/MacOSUserInfoBuilderImpl.java Tue May 09 10:31:37 2017 +0200 +++ b/common/portability/src/main/java/com/redhat/thermostat/common/portability/internal/macos/MacOSUserInfoBuilderImpl.java Mon May 08 19:16:24 2017 -0400 @@ -37,7 +37,7 @@ package com.redhat.thermostat.common.portability.internal.macos; import com.redhat.thermostat.common.portability.PortableProcess; -import com.redhat.thermostat.common.portability.PortableProcessImpl; +import com.redhat.thermostat.common.portability.PortableProcessFactory; import com.redhat.thermostat.common.portability.ProcessUserInfo; import com.redhat.thermostat.common.portability.ProcessUserInfoBuilder; import com.redhat.thermostat.common.utils.LoggingUtils; @@ -56,7 +56,7 @@ private static final Logger logger = LoggingUtils.getLogger(MacOSUserInfoBuilderImpl.class); public MacOSUserInfoBuilderImpl() { - this(PortableProcessImpl.getInstance()); + this(PortableProcessFactory.getInstance()); } MacOSUserInfoBuilderImpl(PortableProcess helper) {
--- a/common/portability/src/main/java/com/redhat/thermostat/common/portability/internal/windows/WindowsUserInfoBuilderImpl.java Tue May 09 10:31:37 2017 +0200 +++ b/common/portability/src/main/java/com/redhat/thermostat/common/portability/internal/windows/WindowsUserInfoBuilderImpl.java Mon May 08 19:16:24 2017 -0400 @@ -36,7 +36,7 @@ package com.redhat.thermostat.common.portability.internal.windows; -import com.redhat.thermostat.common.portability.PortableProcessImpl; +import com.redhat.thermostat.common.portability.PortableProcessFactory; import com.redhat.thermostat.common.portability.ProcessUserInfo; import com.redhat.thermostat.common.portability.ProcessUserInfoBuilder; import com.redhat.thermostat.common.portability.PortableProcess; @@ -56,7 +56,7 @@ private static final Logger logger = LoggingUtils.getLogger(WindowsUserInfoBuilderImpl.class); public WindowsUserInfoBuilderImpl() { - this(PortableProcessImpl.getInstance()); + this(PortableProcessFactory.getInstance()); } WindowsUserInfoBuilderImpl(PortableProcess helper) {
--- a/plugins/com.redhat.thermostat.host.overview/agent/pom.xml Tue May 09 10:31:37 2017 +0200 +++ b/plugins/com.redhat.thermostat.host.overview/agent/pom.xml Mon May 08 19:16:24 2017 -0400 @@ -81,6 +81,63 @@ </execution> </executions> </plugin> + + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> + <Bundle-SymbolicName>com.redhat.thermostat.host.memory.agent</Bundle-SymbolicName> + <Bundle-Activator>com.redhat.thermostat.host.memory.agent.internal.Activator</Bundle-Activator> + <Export-Package /> + <Private-Package> + com.redhat.thermostat.host.memory.agent.internal + </Private-Package> + <!-- Do not autogenerate uses clauses in Manifests --> + <_nouses>true</_nouses> + </instructions> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <executions> + <execution> + <id>copy</id> + <phase>generate-resources</phase> + <goals> + <goal>copy-resources</goal> + </goals> + <configuration> + <overwrite>true</overwrite> + <outputDirectory>${project.build.directory}</outputDirectory> + <resources> + <resource> + <directory>../../../common/portability/target</directory> + <includes> + <include>${sharedlib.prefix}thermostat-common-portability${sharedlib.suffix}</include> + </includes> + </resource> + </resources> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <!-- the test needs to link to common-portability native libraries --> + <systemPropertyVariables> + <com.redhat.thermostat.shared.loader.testNativesHome>${project.build.directory}</com.redhat.thermostat.shared.loader.testNativesHome> + </systemPropertyVariables> + </configuration> + </plugin> + </plugins> </build>
--- a/plugins/com.redhat.thermostat.host.overview/agent/src/main/java/com/redhat/thermostat/host/overview/agent/internal/HostInfoBuilderImpl.java Tue May 09 10:31:37 2017 +0200 +++ b/plugins/com.redhat.thermostat.host.overview/agent/src/main/java/com/redhat/thermostat/host/overview/agent/internal/HostInfoBuilderImpl.java Mon May 08 19:16:24 2017 -0400 @@ -37,7 +37,7 @@ package com.redhat.thermostat.host.overview.agent.internal; import com.redhat.thermostat.common.portability.PortableHost; -import com.redhat.thermostat.common.portability.PortableHostImpl; +import com.redhat.thermostat.common.portability.PortableHostFactory; import com.redhat.thermostat.host.overview.agent.internal.models.HostInfoBuilder; import com.redhat.thermostat.host.overview.common.model.HostInfo; import com.redhat.thermostat.storage.core.WriterID; @@ -51,7 +51,7 @@ private final PortableHost helper; HostInfoBuilderImpl(final WriterID writerID) { - this(writerID, PortableHostImpl.getInstance()); + this(writerID, PortableHostFactory.getInstance()); } HostInfoBuilderImpl(final WriterID writerID, PortableHost helper) {
--- a/plugins/host-cpu/agent/src/main/java/com/redhat/thermostat/host/cpu/agent/internal/WindowsCpuStatBuilder.java Tue May 09 10:31:37 2017 +0200 +++ b/plugins/host-cpu/agent/src/main/java/com/redhat/thermostat/host/cpu/agent/internal/WindowsCpuStatBuilder.java Mon May 08 19:16:24 2017 -0400 @@ -38,7 +38,7 @@ import com.redhat.thermostat.common.Clock; import com.redhat.thermostat.common.portability.PortableHost; -import com.redhat.thermostat.common.portability.PortableHostImpl; +import com.redhat.thermostat.common.portability.PortableHostFactory; import com.redhat.thermostat.host.cpu.common.model.CpuStat; import com.redhat.thermostat.storage.core.WriterID; @@ -53,7 +53,7 @@ WindowsCpuStatBuilder(Clock clock, WriterID writerId) { this.writerId = writerId; this.clock = clock; - this.portableHost = PortableHostImpl.getInstance(); + this.portableHost = PortableHostFactory.getInstance(); } @Override
--- a/plugins/host-memory/agent/src/main/java/com/redhat/thermostat/host/memory/agent/internal/MemoryStatBuilder.java Tue May 09 10:31:37 2017 +0200 +++ b/plugins/host-memory/agent/src/main/java/com/redhat/thermostat/host/memory/agent/internal/MemoryStatBuilder.java Mon May 08 19:16:24 2017 -0400 @@ -41,6 +41,7 @@ import java.util.logging.Level; import java.util.logging.Logger; +import com.redhat.thermostat.common.portability.PortableMemoryStatFactory; import com.redhat.thermostat.common.portability.linux.ProcDataSource; import com.redhat.thermostat.common.NotImplementedException; import com.redhat.thermostat.common.Size; @@ -127,7 +128,7 @@ private MemoryStat buildPortably() { long timestamp = System.currentTimeMillis(); - PortableMemoryStat memstat = PortableMemoryStat.build(); + PortableMemoryStat memstat = PortableMemoryStatFactory.build(); String wId = writerId.getWriterID(); return new MemoryStat(wId, timestamp, memstat.getTotal(), memstat.getFree(), memstat.getBuffers(), memstat.getCached(), memstat.getSwapTotal(), memstat.getSwapFree(), memstat.getCommitLimit());
--- a/plugins/vm-byteman/agent/src/main/java/com/redhat/thermostat/vm/byteman/agent/internal/BytemanRequestReceiver.java Tue May 09 10:31:37 2017 +0200 +++ b/plugins/vm-byteman/agent/src/main/java/com/redhat/thermostat/vm/byteman/agent/internal/BytemanRequestReceiver.java Mon May 08 19:16:24 2017 -0400 @@ -44,8 +44,8 @@ import java.util.logging.Level; import java.util.logging.Logger; -import com.redhat.thermostat.common.portability.ProcessUserInfo; import com.redhat.thermostat.common.portability.ProcessUserInfoBuilder; +import com.redhat.thermostat.common.portability.ProcessUserInfoBuilderFactory; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.Reference; @@ -156,7 +156,7 @@ } protected void bindUserNameUtil(UserNameUtil userNameUtil) { - ProcessUserInfoBuilder userInfoBuilder = ProcessUserInfo.createBuilder(new ProcDataSource(), userNameUtil); + ProcessUserInfoBuilder userInfoBuilder = ProcessUserInfoBuilderFactory.createBuilder(new ProcDataSource(), userNameUtil); attachManager.setUserInfoBuilder(userInfoBuilder); }
--- a/plugins/vm-cpu/agent/src/main/java/com/redhat/thermostat/vm/cpu/agent/internal/ProcessStatusInfoBuilderImpl.java Tue May 09 10:31:37 2017 +0200 +++ b/plugins/vm-cpu/agent/src/main/java/com/redhat/thermostat/vm/cpu/agent/internal/ProcessStatusInfoBuilderImpl.java Mon May 08 19:16:24 2017 -0400 @@ -36,7 +36,7 @@ package com.redhat.thermostat.vm.cpu.agent.internal; -import com.redhat.thermostat.common.portability.PortableProcessImpl; +import com.redhat.thermostat.common.portability.PortableProcessFactory; import com.redhat.thermostat.common.portability.PortableProcessStat; /** @@ -49,7 +49,7 @@ public ProcessStatusInfo build(int pid) { - final PortableProcessStat info = PortableProcessImpl.getInstance().getProcessStat(pid); + final PortableProcessStat info = PortableProcessFactory.getInstance().getProcessStat(pid); return info != null ? new ProcessStatusInfo(pid, info.getUserTime(), info.getKernelTime()) : null; }
--- a/plugins/vm-cpu/agent/src/main/java/com/redhat/thermostat/vm/cpu/agent/internal/VmCpuBackend.java Tue May 09 10:31:37 2017 +0200 +++ b/plugins/vm-cpu/agent/src/main/java/com/redhat/thermostat/vm/cpu/agent/internal/VmCpuBackend.java Mon May 08 19:16:24 2017 -0400 @@ -50,7 +50,7 @@ import com.redhat.thermostat.common.Clock; import com.redhat.thermostat.common.SystemClock; import com.redhat.thermostat.common.Version; -import com.redhat.thermostat.common.portability.PortableHostImpl; +import com.redhat.thermostat.common.portability.PortableHostFactory; import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.shared.config.OS; import com.redhat.thermostat.storage.core.WriterID; @@ -112,7 +112,7 @@ } private int getCpuCount() { - return PortableHostImpl.getInstance().getCPUCount(); + return PortableHostFactory.getInstance().getCPUCount(); } private int getLinuxCpuCount(ProcDataSource dataSource) {
--- a/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatBuilderImpl.java Tue May 09 10:31:37 2017 +0200 +++ b/plugins/vm-io/agent/src/main/java/com/redhat/thermostat/vm/io/agent/internal/VmIoStatBuilderImpl.java Mon May 08 19:16:24 2017 -0400 @@ -38,6 +38,7 @@ import com.redhat.thermostat.common.Clock; import com.redhat.thermostat.common.portability.PortableVmIoStat; +import com.redhat.thermostat.common.portability.PortableVmIoStatFactory; import com.redhat.thermostat.storage.core.WriterID; import com.redhat.thermostat.vm.io.common.VmIoStat; @@ -53,7 +54,7 @@ public synchronized VmIoStat build(String vmId, Integer pid) { - PortableVmIoStat data = PortableVmIoStat.build(clock, pid); + PortableVmIoStat data = PortableVmIoStatFactory.build(clock, pid); return (data != null) ? new VmIoStat(writerId, vmId, data.getTimeStamp(), data.getCharactersRead(), data.getCharactersWritten(), data.getReadSyscalls(), data.getWriteSyscalls()) : null; }
--- a/process-handler/src/main/java/com/redhat/thermostat/service/internal/windows/WindowsProcessUtilities.java Tue May 09 10:31:37 2017 +0200 +++ b/process-handler/src/main/java/com/redhat/thermostat/service/internal/windows/WindowsProcessUtilities.java Mon May 08 19:16:24 2017 -0400 @@ -36,7 +36,7 @@ package com.redhat.thermostat.service.internal.windows; -import com.redhat.thermostat.common.portability.PortableProcessImpl; +import com.redhat.thermostat.common.portability.PortableProcessFactory; import com.redhat.thermostat.service.internal.ProcessUtilitiesBase; import com.redhat.thermostat.service.process.UNIXSignal; @@ -74,7 +74,7 @@ @Override public void sendSignal(Integer pid, UNIXSignal signal) { - PortableProcessImpl.getInstance().terminateProcess(pid); + PortableProcessFactory.getInstance().terminateProcess(pid); } }
--- a/system-backend/src/main/java/com/redhat/thermostat/backend/system/internal/InfoBuilderFactoryImpl.java Tue May 09 10:31:37 2017 +0200 +++ b/system-backend/src/main/java/com/redhat/thermostat/backend/system/internal/InfoBuilderFactoryImpl.java Mon May 08 19:16:24 2017 -0400 @@ -38,8 +38,8 @@ import com.redhat.thermostat.backend.system.internal.models.InfoBuilderFactory; import com.redhat.thermostat.backend.system.internal.models.ProcessEnvironmentBuilder; -import com.redhat.thermostat.common.portability.ProcessUserInfo; import com.redhat.thermostat.common.portability.ProcessUserInfoBuilder; +import com.redhat.thermostat.common.portability.ProcessUserInfoBuilderFactory; import com.redhat.thermostat.common.portability.UserNameUtil; import com.redhat.thermostat.common.portability.linux.ProcDataSource; @@ -56,6 +56,6 @@ } public ProcessUserInfoBuilder createProcessUserInfoBuilder(final UserNameUtil userNameUtil) { - return ProcessUserInfo.createBuilder(new ProcDataSource(), userNameUtil); + return ProcessUserInfoBuilderFactory.createBuilder(new ProcDataSource(), userNameUtil); } }
--- a/system-backend/src/main/java/com/redhat/thermostat/backend/system/internal/ProcessEnvironmentBuilderImpl.java Tue May 09 10:31:37 2017 +0200 +++ b/system-backend/src/main/java/com/redhat/thermostat/backend/system/internal/ProcessEnvironmentBuilderImpl.java Mon May 08 19:16:24 2017 -0400 @@ -38,7 +38,7 @@ import com.redhat.thermostat.backend.system.internal.models.ProcessEnvironmentBuilder; import com.redhat.thermostat.common.portability.PortableProcess; -import com.redhat.thermostat.common.portability.PortableProcessImpl; +import com.redhat.thermostat.common.portability.PortableProcessFactory; import java.util.Map; @@ -50,7 +50,7 @@ private final PortableProcess helper; ProcessEnvironmentBuilderImpl() { - this(PortableProcessImpl.getInstance()); + this(PortableProcessFactory.getInstance()); } ProcessEnvironmentBuilderImpl(PortableProcess wh) {