add logcall in Helper.kt

This commit is contained in:
2024-11-30 18:43:29 +01:00
parent a8f1a4d38b
commit ff78cc7b39
4 changed files with 15 additions and 19 deletions

View File

@@ -3,7 +3,7 @@ package ltd.hlaeja.service
import java.util.UUID import java.util.UUID
import ltd.hlaeja.library.deviceConfiguration.Node import ltd.hlaeja.library.deviceConfiguration.Node
import ltd.hlaeja.property.DeviceConfigurationProperty import ltd.hlaeja.property.DeviceConfigurationProperty
import mu.KotlinLogging import ltd.hlaeja.util.logCall
import org.springframework.http.HttpStatus.NOT_FOUND import org.springframework.http.HttpStatus.NOT_FOUND
import org.springframework.http.HttpStatus.NO_CONTENT import org.springframework.http.HttpStatus.NO_CONTENT
import org.springframework.http.HttpStatus.REQUEST_TIMEOUT import org.springframework.http.HttpStatus.REQUEST_TIMEOUT
@@ -12,8 +12,6 @@ import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.reactive.function.client.awaitBodyOrNull import org.springframework.web.reactive.function.client.awaitBodyOrNull
import org.springframework.web.server.ResponseStatusException import org.springframework.web.server.ResponseStatusException
private val log = KotlinLogging.logger {}
@Service @Service
class DeviceConfigurationService( class DeviceConfigurationService(
private val webClient: WebClient, private val webClient: WebClient,
@@ -27,8 +25,4 @@ class DeviceConfigurationService(
.retrieve() .retrieve()
.onStatus(NOT_FOUND::equals) { throw ResponseStatusException(NO_CONTENT) } .onStatus(NOT_FOUND::equals) { throw ResponseStatusException(NO_CONTENT) }
.awaitBodyOrNull<Node.Response>() ?: throw ResponseStatusException(REQUEST_TIMEOUT) .awaitBodyOrNull<Node.Response>() ?: throw ResponseStatusException(REQUEST_TIMEOUT)
private fun logCall(url: String) {
log.debug("calling: {}", url)
}
} }

View File

@@ -3,7 +3,7 @@ package ltd.hlaeja.service
import java.util.UUID import java.util.UUID
import ltd.hlaeja.library.deviceData.MeasurementData import ltd.hlaeja.library.deviceData.MeasurementData
import ltd.hlaeja.property.DeviceDataProperty import ltd.hlaeja.property.DeviceDataProperty
import mu.KotlinLogging import ltd.hlaeja.util.logCall
import org.springframework.http.HttpStatus.NOT_FOUND import org.springframework.http.HttpStatus.NOT_FOUND
import org.springframework.http.HttpStatus.NO_CONTENT import org.springframework.http.HttpStatus.NO_CONTENT
import org.springframework.http.HttpStatus.REQUEST_TIMEOUT import org.springframework.http.HttpStatus.REQUEST_TIMEOUT
@@ -13,8 +13,6 @@ import org.springframework.web.reactive.function.client.awaitBodilessEntity
import org.springframework.web.reactive.function.client.awaitBodyOrNull import org.springframework.web.reactive.function.client.awaitBodyOrNull
import org.springframework.web.server.ResponseStatusException import org.springframework.web.server.ResponseStatusException
private val log = KotlinLogging.logger {}
@Service @Service
class DeviceDataService( class DeviceDataService(
private val webClient: WebClient, private val webClient: WebClient,
@@ -25,8 +23,7 @@ class DeviceDataService(
client: UUID, client: UUID,
node: UUID, node: UUID,
): MeasurementData.Response = webClient.get() ): MeasurementData.Response = webClient.get()
.uri("${deviceDataProperty.url}/client-$client/node-$node") .uri("${deviceDataProperty.url}/client-$client/node-$node".also(::logCall))
.also { log.debug("{}/client-{}/node-{}", deviceDataProperty.url, client, node) }
.retrieve() .retrieve()
.onStatus(NOT_FOUND::equals) { throw ResponseStatusException(NO_CONTENT) } .onStatus(NOT_FOUND::equals) { throw ResponseStatusException(NO_CONTENT) }
.awaitBodyOrNull<MeasurementData.Response>() ?: throw ResponseStatusException(REQUEST_TIMEOUT) .awaitBodyOrNull<MeasurementData.Response>() ?: throw ResponseStatusException(REQUEST_TIMEOUT)
@@ -35,8 +32,7 @@ class DeviceDataService(
client: UUID, client: UUID,
request: MeasurementData.Request, request: MeasurementData.Request,
) = webClient.post() ) = webClient.post()
.uri("${deviceDataProperty.url}/client-$client") .uri("${deviceDataProperty.url}/client-$client".also(::logCall))
.also { log.debug("{}/client-{}", deviceDataProperty.url, client) }
.bodyValue(request) .bodyValue(request)
.retrieve() .retrieve()
.awaitBodilessEntity() .awaitBodilessEntity()

View File

@@ -3,7 +3,7 @@ package ltd.hlaeja.service
import java.util.UUID import java.util.UUID
import ltd.hlaeja.library.deviceRegistry.Identity import ltd.hlaeja.library.deviceRegistry.Identity
import ltd.hlaeja.property.DeviceRegistryProperty import ltd.hlaeja.property.DeviceRegistryProperty
import mu.KotlinLogging import ltd.hlaeja.util.logCall
import org.springframework.http.HttpStatus.NOT_ACCEPTABLE import org.springframework.http.HttpStatus.NOT_ACCEPTABLE
import org.springframework.http.HttpStatus.NOT_FOUND import org.springframework.http.HttpStatus.NOT_FOUND
import org.springframework.http.HttpStatus.REQUEST_TIMEOUT import org.springframework.http.HttpStatus.REQUEST_TIMEOUT
@@ -12,8 +12,6 @@ import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.reactive.function.client.awaitBodyOrNull import org.springframework.web.reactive.function.client.awaitBodyOrNull
import org.springframework.web.server.ResponseStatusException import org.springframework.web.server.ResponseStatusException
private val log = KotlinLogging.logger {}
@Service @Service
class DeviceRegistryService( class DeviceRegistryService(
private val webClient: WebClient, private val webClient: WebClient,
@@ -23,8 +21,7 @@ class DeviceRegistryService(
suspend fun getIdentityFromDevice( suspend fun getIdentityFromDevice(
device: UUID, device: UUID,
): Identity.Response = webClient.get() ): Identity.Response = webClient.get()
.uri("${deviceRegistryProperty.url}/identity/device-$device") .uri("${deviceRegistryProperty.url}/identity/device-$device".also(::logCall))
.also { log.debug("{}/node/device-{}", deviceRegistryProperty.url, device) }
.retrieve() .retrieve()
.onStatus(NOT_FOUND::equals) { throw ResponseStatusException(NOT_ACCEPTABLE) } .onStatus(NOT_FOUND::equals) { throw ResponseStatusException(NOT_ACCEPTABLE) }
.awaitBodyOrNull<Identity.Response>() ?: throw ResponseStatusException(REQUEST_TIMEOUT) .awaitBodyOrNull<Identity.Response>() ?: throw ResponseStatusException(REQUEST_TIMEOUT)

View File

@@ -0,0 +1,9 @@
package ltd.hlaeja.util
import mu.KotlinLogging
private val log = KotlinLogging.logger {}
fun logCall(url: String) {
log.debug("calling: {}", url)
}