Skip to content
This repository was archived by the owner on Mar 27, 2023. It is now read-only.

Commit e6ddb58

Browse files
author
Michel Zimmer
committed
Remove DOT format from stats endpoint
1 parent 15969d0 commit e6ddb58

File tree

10 files changed

+37
-296
lines changed

10 files changed

+37
-296
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ LABEL org.opencontainers.image.vendor="neuland – Büro für Informatik GmbH"
1212
LABEL org.opencontainers.image.licenses="Apache-2.0"
1313
LABEL org.opencontainers.image.title="bandwhichd-server"
1414
LABEL org.opencontainers.image.description="bandwhichd server collecting measurements and calculating statistics"
15-
LABEL org.opencontainers.image.version="0.6.0-rc8"
15+
LABEL org.opencontainers.image.version="0.6.0-rc9"
1616
USER guest
1717
ENTRYPOINT ["/opt/java/openjdk/bin/java"]
1818
CMD ["-jar", "/opt/bandwhichd-server.jar"]
1919
EXPOSE 8080
2020
STOPSIGNAL SIGTERM
21-
COPY --from=build --chown=root:root /tmp/bandwhichd-server/target/scala-3.1.3/bandwhichd-server-assembly-0.6.0-rc8.jar /opt/bandwhichd-server.jar
21+
COPY --from=build --chown=root:root /tmp/bandwhichd-server/target/scala-3.1.3/bandwhichd-server-assembly-0.6.0-rc9.jar /opt/bandwhichd-server.jar

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ lazy val root = (project in file("."))
22
.settings(
33
organization := "de.neuland-bfi",
44
name := "bandwhichd-server",
5-
version := "0.6.0-rc8",
5+
version := "0.6.0-rc9",
66
scalaVersion := "3.1.3",
77
Compile / scalaSource := baseDirectory.value / "src" / "main" / "scala",
88
Test / scalaSource := baseDirectory.value / "src" / "test" / "scala",
Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package de.neuland.bandwhichd.server.adapter.in.v1.stats
22

33
import de.neuland.bandwhichd.server.domain.stats.*
4-
import de.neuland.bandwhichd.server.lib.dot.*
5-
import io.circe.Json
6-
7-
import java.util.concurrent.atomic.AtomicReference
4+
import io.circe.{Encoder, Json}
85

96
object StatsCodecs {
10-
val circeEncoder: io.circe.Encoder[MonitoredStats] =
7+
val encoder: Encoder[MonitoredStats] =
118
(stats: MonitoredStats) =>
129
Json.obj(
1310
"hosts" -> Json.fromFields(
@@ -40,32 +37,4 @@ object StatsCodecs {
4037
})
4138
)
4239
)
43-
44-
val dotEncoder
45-
: de.neuland.bandwhichd.server.lib.dot.codec.Encoder[MonitoredStats] =
46-
(stats: MonitoredStats) => {
47-
48-
val nodeStatements: Seq[Node] =
49-
stats.allHosts.toSeq.map(host =>
50-
Node(
51-
id = NodeId(host.hostId.uuid.toString),
52-
attributes = Seq(
53-
Attribute.Label(host.host.toString)
54-
)
55-
)
56-
)
57-
val edgeStatements: Seq[Edge] =
58-
stats.connections.toSeq
59-
.map(connection =>
60-
Edge(
61-
idA = NodeId(connection._1.uuid.toString),
62-
idB = NodeId(connection._2.uuid.toString)
63-
)
64-
)
65-
66-
Graph(
67-
`type` = Directed,
68-
statements = nodeStatements ++ edgeStatements
69-
)
70-
}
7140
}

src/main/scala/de/neuland/bandwhichd/server/adapter/in/v1/stats/StatsController.scala

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import cats.implicits.*
66
import de.neuland.bandwhichd.server.application.StatsApplicationService
77
import de.neuland.bandwhichd.server.domain.measurement.Timing
88
import de.neuland.bandwhichd.server.domain.stats.*
9-
import de.neuland.bandwhichd.server.lib.dot.Dot
109
import de.neuland.bandwhichd.server.lib.http4s.Helpers
11-
import de.neuland.bandwhichd.server.lib.http4s.dot.DotHttp4s
1210
import de.neuland.bandwhichd.server.lib.time.cats.TimeContext
1311
import io.circe.Json
1412
import io.circe.syntax.*
@@ -40,53 +38,10 @@ class StatsController[F[_]: Async](
4038
response <- {
4139
val statsWithinMonitoredNetworks: MonitoredStats =
4240
monitoredStats.withoutHostsOutsideOfMonitoredNetworks
43-
if (useDotInsteadOfJson(request.headers)) {
44-
import de.neuland.bandwhichd.server.lib.http4s.dot.DotHttp4s.dotEntityEncoder
45-
val dot: Dot = StatsCodecs.dotEncoder(statsWithinMonitoredNetworks)
46-
Ok(dot)
47-
} else {
48-
import org.http4s.circe.CirceEntityEncoder.circeEntityEncoder
49-
val json: Json =
50-
statsWithinMonitoredNetworks.asJson(StatsCodecs.circeEncoder)
51-
Ok(json)
52-
}
41+
import org.http4s.circe.CirceEntityEncoder.circeEntityEncoder
42+
val json: Json =
43+
statsWithinMonitoredNetworks.asJson(StatsCodecs.encoder)
44+
Ok(json)
5345
}
5446
} yield response
55-
56-
private def useDotInsteadOfJson(headers: Headers) = {
57-
val maybeAcceptHeader: Option[Accept] =
58-
headers.get(
59-
Header.Select.recurringHeadersWithMerge(
60-
org.http4s.headers.Accept.headerSemigroupInstance,
61-
org.http4s.headers.Accept.headerInstance
62-
)
63-
)
64-
65-
maybeAcceptHeader.fold(false) { acceptHeader =>
66-
67-
val mediaRangeAndQValues: NonEmptyList[MediaRangeAndQValue] =
68-
acceptHeader.values
69-
70-
val maybeDotMediaRangeAndQValue: Option[MediaRangeAndQValue] =
71-
mediaRangeAndQValues.find { mediaRangeAndQValue =>
72-
DotHttp4s.mediaType.satisfiedBy(mediaRangeAndQValue.mediaRange)
73-
}
74-
75-
maybeDotMediaRangeAndQValue.fold(false) { dotMediaRangeAndQValue =>
76-
77-
val maybeJsonMediaRangeAndQValue =
78-
mediaRangeAndQValues.find { mediaRangeAndQValue =>
79-
MediaType.application.json.satisfiedBy(
80-
mediaRangeAndQValue.mediaRange
81-
)
82-
}
83-
84-
maybeJsonMediaRangeAndQValue.fold(true) { jsonMediaRangeAndQValue =>
85-
dotMediaRangeAndQValue.qValue.compare(
86-
jsonMediaRangeAndQValue.qValue
87-
) >= 0
88-
}
89-
}
90-
}
91-
}
9247
}

src/main/scala/de/neuland/bandwhichd/server/domain/stats/Stats.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import de.neuland.bandwhichd.server.domain.measurement.{Measurement, Timing}
77
import de.neuland.bandwhichd.server.domain.stats.Stats.Bundle
88
import de.neuland.bandwhichd.server.lib.time.Interval
99
import de.neuland.bandwhichd.server.lib.time.cats.TimeContext
10-
import fs2.Stream
1110

1211
import java.nio.charset.StandardCharsets.UTF_8
1312
import java.time.temporal.ChronoUnit.HOURS

src/main/scala/de/neuland/bandwhichd/server/lib/dot/Dot.scala

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/main/scala/de/neuland/bandwhichd/server/lib/dot/codec/Encoder.scala

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/main/scala/de/neuland/bandwhichd/server/lib/dot/fs2/BC.scala

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/main/scala/de/neuland/bandwhichd/server/lib/http4s/dot/DotHttp4s.scala

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)