# HG changeset patch # User Elliott Baron # Date 1506099656 14400 # Node ID 87f42669d0f4487c0d37f8a69d39f203fc95c959 # Parent 22f2b3ea360945926494c8a424503f873dd1a662 Remove runtime copy of ipc.properties Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-September/025153.html diff -r 22f2b3ea3609 -r 87f42669d0f4 agent/ipc/server/pom.xml --- a/agent/ipc/server/pom.xml Fri Sep 22 10:10:52 2017 -0400 +++ b/agent/ipc/server/pom.xml Fri Sep 22 13:00:56 2017 -0400 @@ -77,11 +77,6 @@ com.redhat.thermostat - thermostat-storage-core - ${project.version} - - - com.redhat.thermostat thermostat-agent-ipc-common ${project.version} diff -r 22f2b3ea3609 -r 87f42669d0f4 agent/ipc/server/src/main/java/com/redhat/thermostat/agent/ipc/server/internal/Activator.java --- a/agent/ipc/server/src/main/java/com/redhat/thermostat/agent/ipc/server/internal/Activator.java Fri Sep 22 10:10:52 2017 -0400 +++ b/agent/ipc/server/src/main/java/com/redhat/thermostat/agent/ipc/server/internal/Activator.java Fri Sep 22 13:00:56 2017 -0400 @@ -51,7 +51,6 @@ import com.redhat.thermostat.common.MultipleServiceTracker.DependencyProvider; import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.shared.config.CommonPaths; -import com.redhat.thermostat.storage.core.WriterID; public class Activator implements BundleActivator { @@ -64,15 +63,14 @@ public void start(final BundleContext context) throws Exception { propBuilder = new ServerIPCPropertiesBuilder(context); - Class[] deps = new Class[] { CommonPaths.class, WriterID.class }; + Class[] deps = new Class[] { CommonPaths.class }; tracker = new MultipleServiceTracker(context, deps, new Action() { @Override public void dependenciesAvailable(DependencyProvider services) { CommonPaths paths = (CommonPaths) services.get(CommonPaths.class); - WriterID writerID = (WriterID) services.get(WriterID.class); File propFile = paths.getUserIPCConfigurationFile(); - ipcService = new AgentIPCServiceImpl(propBuilder, context, propFile, writerID); + ipcService = new AgentIPCServiceImpl(propBuilder, context, propFile); reg = context.registerService(AgentIPCService.class.getName(), ipcService, null); } diff -r 22f2b3ea3609 -r 87f42669d0f4 agent/ipc/server/src/main/java/com/redhat/thermostat/agent/ipc/server/internal/AgentIPCServiceImpl.java --- a/agent/ipc/server/src/main/java/com/redhat/thermostat/agent/ipc/server/internal/AgentIPCServiceImpl.java Fri Sep 22 10:10:52 2017 -0400 +++ b/agent/ipc/server/src/main/java/com/redhat/thermostat/agent/ipc/server/internal/AgentIPCServiceImpl.java Fri Sep 22 13:00:56 2017 -0400 @@ -54,35 +54,28 @@ import com.redhat.thermostat.agent.ipc.server.AgentIPCService; import com.redhat.thermostat.agent.ipc.server.ServerTransport; import com.redhat.thermostat.agent.ipc.server.ThermostatIPCCallbacks; -import com.redhat.thermostat.storage.core.WriterID; class AgentIPCServiceImpl implements AgentIPCService { - static final String RUNTIME_IPC_CONFIG_PREFIX = "thermostat-ipc.properties."; - private final ServerIPCPropertiesBuilder propBuilder; private final ServiceTracker transportTracker; // Access/modification of this field should by synchronized private final Map transports; // IPC configuration residing in USER_THERMOSTAT_HOME private final File propFile; - private final WriterID writerID; private final FileHelper helper; private ServerTransport transport; private IPCProperties props; private boolean started; - AgentIPCServiceImpl(ServerIPCPropertiesBuilder propBuilder, BundleContext context, File propFile, - WriterID writerID) { - this(propBuilder, context, propFile, writerID, new FileHelper()); + AgentIPCServiceImpl(ServerIPCPropertiesBuilder propBuilder, BundleContext context, File propFile) { + this(propBuilder, context, propFile, new FileHelper()); } - AgentIPCServiceImpl(ServerIPCPropertiesBuilder propBuilder, BundleContext context, File propFile, - WriterID writerID, FileHelper helper) { + AgentIPCServiceImpl(ServerIPCPropertiesBuilder propBuilder, BundleContext context, File propFile, FileHelper helper) { this.propBuilder = propBuilder; this.propFile = propFile; - this.writerID = writerID; this.transports = new HashMap<>(); this.helper = helper; this.started = false; @@ -182,23 +175,7 @@ IPCConfigurationWriter writer = helper.getConfigurationWriter(propFile); writer.write(); } - - // Copy read-only copy of IPC properties file to a world-readable location - String destDirPath = helper.getSystemProperty("java.io.tmpdir"); - if (destDirPath == null) { - throw new IOException("Required system property \"java.io.tmpdir\" is not defined"); - } - File destDir = helper.getFile(destDirPath); - - // Append agent ID to IPC config filename - String filename = RUNTIME_IPC_CONFIG_PREFIX.concat(writerID.getWriterID()); - File runtimeIpcConfig = helper.getFile(destDir, filename); - runtimeIpcConfig.deleteOnExit(); - - // Copy config file to destination - helper.copy(propFile.toPath(), runtimeIpcConfig.toPath()); - - return propBuilder.getProperties(runtimeIpcConfig); + return propBuilder.getProperties(propFile); } // Helper class for testing purposes diff -r 22f2b3ea3609 -r 87f42669d0f4 agent/ipc/server/src/test/java/com/redhat/thermostat/agent/ipc/server/internal/ActivatorTest.java --- a/agent/ipc/server/src/test/java/com/redhat/thermostat/agent/ipc/server/internal/ActivatorTest.java Fri Sep 22 10:10:52 2017 -0400 +++ b/agent/ipc/server/src/test/java/com/redhat/thermostat/agent/ipc/server/internal/ActivatorTest.java Fri Sep 22 13:00:56 2017 -0400 @@ -46,7 +46,6 @@ import com.redhat.thermostat.agent.ipc.server.AgentIPCService; import com.redhat.thermostat.shared.config.CommonPaths; -import com.redhat.thermostat.storage.core.WriterID; import com.redhat.thermostat.testutils.StubBundleContext; public class ActivatorTest { @@ -71,8 +70,6 @@ CommonPaths paths = mock(CommonPaths.class); context.registerService(CommonPaths.class, paths, null); - WriterID writerID = mock(WriterID.class); - context.registerService(WriterID.class, writerID, null); Activator activator = new Activator(); @@ -81,7 +78,7 @@ activator.stop(context); assertEquals(0, context.getServiceListeners().size()); - assertEquals(2, context.getAllServices().size()); + assertEquals(1, context.getAllServices().size()); } @Test diff -r 22f2b3ea3609 -r 87f42669d0f4 agent/ipc/server/src/test/java/com/redhat/thermostat/agent/ipc/server/internal/AgentIPCServiceImplTest.java --- a/agent/ipc/server/src/test/java/com/redhat/thermostat/agent/ipc/server/internal/AgentIPCServiceImplTest.java Fri Sep 22 10:10:52 2017 -0400 +++ b/agent/ipc/server/src/test/java/com/redhat/thermostat/agent/ipc/server/internal/AgentIPCServiceImplTest.java Fri Sep 22 13:00:56 2017 -0400 @@ -47,7 +47,6 @@ import java.io.File; import java.io.IOException; -import java.nio.file.Path; import java.nio.file.attribute.UserPrincipal; import java.util.Map; @@ -60,7 +59,6 @@ import com.redhat.thermostat.agent.ipc.server.ServerTransport; import com.redhat.thermostat.agent.ipc.server.ThermostatIPCCallbacks; import com.redhat.thermostat.agent.ipc.server.internal.AgentIPCServiceImpl.FileHelper; -import com.redhat.thermostat.storage.core.WriterID; import com.redhat.thermostat.testutils.StubBundleContext; public class AgentIPCServiceImplTest { @@ -74,11 +72,6 @@ private FileHelper helper; private IPCConfigurationWriter writer; private File userPropFile; - private File tmpdirFile; - private File runtimePropFile; - private Path userPropPath; - private Path runtimePropPath; - private WriterID writerID; private ServerIPCPropertiesBuilder propBuilder; private StubBundleContext context; @@ -88,24 +81,13 @@ transport = mock(ServerTransport.class); when(transport.getType()).thenReturn(IPCType.UNKNOWN); userPropFile = mock(File.class); - userPropPath = mock(Path.class); - when(userPropFile.toPath()).thenReturn(userPropPath); propBuilder = mock(ServerIPCPropertiesBuilder.class); props = mock(IPCProperties.class); when(props.getType()).thenReturn(IPCType.UNKNOWN); - runtimePropFile = mock(File.class); - when(propBuilder.getProperties(runtimePropFile)).thenReturn(props); - runtimePropPath = mock(Path.class); - when(runtimePropFile.toPath()).thenReturn(runtimePropPath); - writerID = mock(WriterID.class); - when(writerID.getWriterID()).thenReturn(AGENT_ID); + when(propBuilder.getProperties(userPropFile)).thenReturn(props); helper = mock(FileHelper.class); writer = mock(IPCConfigurationWriter.class); when(helper.getConfigurationWriter(userPropFile)).thenReturn(writer); - when(helper.getSystemProperty("java.io.tmpdir")).thenReturn(TMPDIR); - tmpdirFile = mock(File.class); - when(helper.getFile(TMPDIR)).thenReturn(tmpdirFile); - when(helper.getFile(tmpdirFile, AgentIPCServiceImpl.RUNTIME_IPC_CONFIG_PREFIX + AGENT_ID)).thenReturn(runtimePropFile); } @Test @@ -124,7 +106,7 @@ } @Test - public void testStartCreatesRuntimePropertyFile() throws Exception { + public void testStartCreatesPropertyFile() throws Exception { context.registerService(ServerTransport.class.getName(), transport, null); AgentIPCServiceImpl service = createService(); ThermostatIPCCallbacks callbacks = mock(ThermostatIPCCallbacks.class); @@ -133,27 +115,13 @@ service.createServer(SERVER_NAME, callbacks); assertTrue(service.isStarted()); - verify(helper).getSystemProperty("java.io.tmpdir"); - verify(helper).getFile(TMPDIR); - verify(helper).getFile(tmpdirFile, AgentIPCServiceImpl.RUNTIME_IPC_CONFIG_PREFIX + AGENT_ID); - verify(helper).copy(userPropPath, runtimePropPath); - verify(runtimePropFile).deleteOnExit(); + verify(helper).configFileExists(userPropFile); + verify(helper).getConfigurationWriter(userPropFile); + verify(writer).write(); } - @Test(expected=IOException.class) - public void testUndefinedTmpdirThrowsException() throws Exception { - when(helper.getSystemProperty("java.io.tmpdir")).thenReturn(null); - - context.registerService(ServerTransport.class.getName(), transport, null); - AgentIPCServiceImpl service = createService(); - ThermostatIPCCallbacks callbacks = mock(ThermostatIPCCallbacks.class); - - assertFalse(service.isStarted()); - service.createServer(SERVER_NAME, callbacks); - } - private AgentIPCServiceImpl createService() { - return new AgentIPCServiceImpl(propBuilder, context, userPropFile, writerID, helper); + return new AgentIPCServiceImpl(propBuilder, context, userPropFile, helper); } @Test