# HG changeset patch # User Severin Gehwolf # Date 1501783000 -7200 # Node ID 406fe8f9d8bf230195f896ee160cd6c1ce04f4cc # Parent 08bb838d3c6c46874660242bdf4fbebad0f23b64 [commands] Register receiver with correct agent/systemId. Reviewed-by: stooke Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-August/024427.html diff -r 08bb838d3c6c -r 406fe8f9d8bf plugins/commands/agent/src/main/java/com/redhat/thermostat/commands/agent/internal/CommandsBackend.java --- a/plugins/commands/agent/src/main/java/com/redhat/thermostat/commands/agent/internal/CommandsBackend.java Fri Jul 28 12:16:49 2017 +0200 +++ b/plugins/commands/agent/src/main/java/com/redhat/thermostat/commands/agent/internal/CommandsBackend.java Thu Aug 03 19:56:40 2017 +0200 @@ -61,6 +61,7 @@ import com.redhat.thermostat.common.Version; import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; import com.redhat.thermostat.common.plugin.PluginConfiguration; +import com.redhat.thermostat.common.plugin.SystemID; import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.shared.config.CommonPaths; import com.redhat.thermostat.shared.config.SSLConfiguration; @@ -91,6 +92,9 @@ private ReceiverRegistry receiverReg; @Reference + private SystemID systemId; + + @Reference private WriterID agentId; @Reference @@ -184,13 +188,9 @@ boolean expired = false; try { URI microserviceURI = config.getGatewayURL(); - // String agent = agentId.getWriterID(); - // FIXME: Use reasonable agent/system name to register, not - // hard-coded one - // Unfortunately, the microservice is currently set up only for - // a hard-coded one. - String agent = "testAgent"; - String cmdUriPath = String.format(ENDPOINT_FORMAT, "ignoreMe", agent); + String agent = agentId.getWriterID(); + String sysId = systemId.getSystemID(); + String cmdUriPath = String.format(ENDPOINT_FORMAT, sysId, agent); URI agentUri = microserviceURI.resolve(cmdUriPath); AgentSocketOnMessageCallback onMsgCallback = new AgentSocketOnMessageCallback(receiverReg); CmdChannelAgentSocket agentSocket = new CmdChannelAgentSocket( @@ -233,10 +233,21 @@ return "Basic " + encodedAuthorization; } + // DS bind method protected void bindPaths(CommonPaths paths) { this.paths = paths; } + // DS bind method + protected void bindAgentId(WriterID agentId) { + this.agentId = agentId; + } + + // DS bind method + protected void bindSystemId(SystemID systemId) { + this.systemId = systemId; + } + static class WsClientCreator { WebSocketClientFacade createClient(SSLConfiguration sslConfig) { return new WebSocketClientFacadeImpl(sslConfig); diff -r 08bb838d3c6c -r 406fe8f9d8bf plugins/commands/agent/src/test/java/com/redhat/thermostat/commands/agent/internal/CommandsBackendTest.java --- a/plugins/commands/agent/src/test/java/com/redhat/thermostat/commands/agent/internal/CommandsBackendTest.java Fri Jul 28 12:16:49 2017 +0200 +++ b/plugins/commands/agent/src/test/java/com/redhat/thermostat/commands/agent/internal/CommandsBackendTest.java Thu Aug 03 19:56:40 2017 +0200 @@ -64,13 +64,17 @@ import com.redhat.thermostat.commands.agent.internal.socket.CmdChannelAgentSocket; import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; import com.redhat.thermostat.common.plugin.PluginConfiguration; +import com.redhat.thermostat.common.plugin.SystemID; import com.redhat.thermostat.shared.config.CommonPaths; import com.redhat.thermostat.shared.config.SSLConfiguration; import com.redhat.thermostat.storage.core.StorageCredentials; +import com.redhat.thermostat.storage.core.WriterID; public class CommandsBackendTest { private static final URI GW_URL = URI.create("ws://example.com/commands/v1/"); + private static final String AGENT_ID = "fooAgent"; + private static final String SYSTEM_ID = "barSystem"; private CommandsBackend backend; private StorageCredentials creds; private BundleContext bundleContext; @@ -97,6 +101,12 @@ when(bundle.getVersion()).thenReturn(mock(Version.class)); when(bundleContext.getBundle()).thenReturn(bundle); backend.componentActivated(bundleContext); + WriterID wId = mock(WriterID.class); + when(wId.getWriterID()).thenReturn(AGENT_ID); + SystemID sId = mock(SystemID.class); + when(sId.getSystemID()).thenReturn(SYSTEM_ID); + backend.bindAgentId(wId); + backend.bindSystemId(sId); } @Test @@ -146,7 +156,7 @@ verify(client).connect(any(CmdChannelAgentSocket.class), uriCaptor.capture(), reqCaptor.capture()); assertTrue("Expected successful activation", success); URI uri = uriCaptor.getValue(); - URI expectedURI = GW_URL.resolve("systems/ignoreMe/agents/testAgent"); + URI expectedURI = GW_URL.resolve("systems/" + SYSTEM_ID + "/agents/" + AGENT_ID); assertEquals(expectedURI, uri); ClientUpgradeRequest req = reqCaptor.getValue(); String expectedHeader = base64EncodedHeader(username + ":" + password);