|
1 | 1 | package de.upb.cs.swt.delphi.instanceregistry.Docker |
2 | 2 |
|
3 | 3 |
|
| 4 | +import java.nio.ByteOrder |
| 5 | + |
4 | 6 | import akka.{Done, NotUsed} |
5 | 7 | import akka.actor.{ActorSystem, PoisonPill} |
6 | 8 | import akka.http.scaladsl.client.RequestBuilding._ |
@@ -223,54 +225,20 @@ class ContainerCommands(connection: DockerConnection) extends JsonSupport with C |
223 | 225 | .toMat(Sink.asPublisher(fanout = true))(Keep.both) |
224 | 226 | .run() |
225 | 227 |
|
226 | | - val sink = Sink.foreach[String] { msg => |
227 | | - println(s"Got log message: $msg") |
228 | | - streamActor ! TextMessage(msg) |
229 | | - } |
230 | | - |
231 | | - val flow: Flow[String, Message, Future[Done]] = Flow.fromSinkAndSourceMat(sink, Source.empty[Message]) (Keep.left) |
232 | | - |
233 | | - val delimiter: Flow[ByteString, ByteString, NotUsed] = Framing.delimiter( |
234 | | - ByteString("\uFFFD"), //TODO: Understand and implement dockers MUX - protocol for log entries ... |
235 | | - maximumFrameLength = 100000, |
236 | | - allowTruncation = true |
237 | | - ) |
| 228 | + val delimiter: Flow[ByteString, ByteString, NotUsed] = Framing.lengthField(4, 4, 100000, ByteOrder.BIG_ENDIAN) |
238 | 229 |
|
239 | 230 | val request = Get(buildUri(containersPath / containerId.substring(0,11) / "logs", queryParams)) |
240 | 231 |
|
241 | 232 | val res = connection.sendRequest(request).flatMap { res => |
242 | 233 | val logLines = res.entity.dataBytes.via(delimiter).map(_.utf8String) |
243 | 234 | logLines.runForeach { line => |
244 | | - println(s"Got log message $line") |
| 235 | + log.debug(s"Streaming log message $line") |
245 | 236 | streamActor ! TextMessage(line) |
246 | 237 | } |
247 | 238 | } |
248 | 239 |
|
249 | | - /* |
250 | | -
|
251 | | - val (upgradeResponseFuture, closed) = Http().singleWebSocketRequest(WebSocketRequest(buildUri(containersPath / containerId.substring(0,11) / "logs", queryParams).withScheme("http")), flow) |
252 | | -
|
253 | | - val connected = upgradeResponseFuture.map { upgrade => |
254 | | -
|
255 | | - if(upgrade.response.status == StatusCodes.OK){ |
256 | | - println(s"Response: ${upgrade.response}") |
257 | | - println(s"Response Headers: ${upgrade.response.headers}") |
258 | | - println(s"Response Entity: ${Unmarshal(upgrade.response.entity).to[String]}") |
259 | | - Done |
260 | | - } else { |
261 | | - throw new RuntimeException(s"Connection failed: ${upgrade.response.status}") |
262 | | - } |
263 | | -
|
264 | | - } |
265 | | -
|
266 | | - connected.onComplete(println) |
267 | | - closed.onComplete { _ => |
268 | | - streamActor ! PoisonPill |
269 | | - println("Closed completed.") |
270 | | - } |
271 | | - */ |
272 | 240 | res.onComplete{ _ => |
273 | | - println("Closed") |
| 241 | + log.info("Log stream finished successfully.") |
274 | 242 | streamActor ! PoisonPill |
275 | 243 | } |
276 | 244 | Success(streamPublisher) |
|
0 commit comments