-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/csr retrieve entity #1246
Draft
thomasBousselin
wants to merge
19
commits into
feature/new-csr
Choose a base branch
from
feature/csr-retrieve-entity
base: feature/new-csr
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
41e4af9
wip: not tested merge entities function
thomasBousselin c7bff1e
wip: not tested merge entities function
thomasBousselin cc6de35
feat: retrieve Entity Working
thomasBousselin e89f92f
feat: first error handling and fix pr comments
thomasBousselin 3de35ba
feat: test for mergeEntity
thomasBousselin 53f0b87
fix: working Where statement for CSR / add some tests on Query CSR / …
bobeal c8bf170
feat: fix merging returning lists and PR comments
thomasBousselin e8ccf0c
feat: fix merging returning lists and PR comments
thomasBousselin 8387130
feat: updating
thomasBousselin dd31576
feat: MR comment - clearer name - no warning impact in ApiException -…
thomasBousselin 3bcf7b3
feat: get warnings from merge
thomasBousselin 690fd59
feat: separate context source utils + work with sysAttrs
thomasBousselin f38c04b
feat: warning following rfc7234 + docker-compose for csr + fix tests
thomasBousselin 129228a
feat: doc csr launch
thomasBousselin b07e032
feat: doc csr launch
thomasBousselin 6d4831a
chore: slight refactoring of the docker compose context source instance
bobeal 8740239
chore: misc typo, wording and naming
bobeal f74ceec
feat: always call context source for normalized representation + PR c…
thomasBousselin deca20c
feat: registrationName in CSR + Warning fixes
thomasBousselin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
API_GATEWAY_PORT=8090 | ||
KAFKA_PORT=29093 | ||
POSTGRES_PORT=5433 | ||
SEARCH_SERVICE_PORT=8093 | ||
SUBSCRIPTION_SERVICE_PORT=8094 | ||
|
||
# Used by subscription service when searching entities for recurring subscriptions | ||
# (those defined with a timeInterval parameter) | ||
SUBSCRIPTION_ENTITY_SERVICE_URL=http://search-service:8093 | ||
|
||
# Used as a base URL by subscription service when serving contexts for notifications | ||
SUBSCRIPTION_STELLIO_URL=http://localhost:8090 | ||
|
||
CONTAINER_NAME_PREFIX=context-source- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
search-service/src/main/kotlin/com/egm/stellio/search/csr/model/CSRFilters.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.egm.stellio.search.csr.model | ||
|
||
import java.net.URI | ||
|
||
data class CSRFilters( // we should use a combination of EntitiesQuery TemporalQuery (when we implement all operations) | ||
val ids: Set<URI> = emptySet(), | ||
val csf: String? = null | ||
) { | ||
fun buildWhereStatement(): String { | ||
val idFilter = if (ids.isNotEmpty()) | ||
""" | ||
( | ||
entity_info.id is null OR | ||
entity_info.id in ('${ids.joinToString("', '")}') | ||
) AND | ||
( | ||
entity_info.idPattern is null OR | ||
${ids.joinToString(" OR ") { "'$it' ~ entity_info.idPattern" }} | ||
) | ||
""".trimIndent() | ||
else "true" | ||
return idFilter | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
search-service/src/main/kotlin/com/egm/stellio/search/csr/model/NGSILDWarning.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.egm.stellio.search.csr.model | ||
|
||
import org.springframework.http.HttpHeaders | ||
import org.springframework.http.ResponseEntity | ||
|
||
/** | ||
* Implements NGSILD-Warning as defined in 6.3.17 | ||
*/ | ||
open class NGSILDWarning( | ||
private val code: Int, | ||
open val message: String, | ||
open val csr: ContextSourceRegistration | ||
) { | ||
// follow rfc7234 https://www.rfc-editor.org/rfc/rfc7234.html#section-5.5 | ||
fun getHeaderMessage(): String = "$code ${getWarnAgent()} \"${getWarnText()}\"" | ||
|
||
// new line are forbidden in headers | ||
private fun getWarnText(): String = message.replace("\n", " ") | ||
private fun getWarnAgent(): String = csr.registrationName ?: csr.id.toString() | ||
|
||
companion object { | ||
const val HEADER_NAME = "NGSILD-Warning" | ||
const val RESPONSE_IS_STALE_WARNING_CODE = 110 | ||
const val REVALIDATION_FAILED_WARNING_CODE = 111 | ||
const val MISCELLANEOUS_WARNING_CODE = 199 | ||
const val MISCELLANEOUS_PERSISTENT_WARNING_CODE = 299 | ||
} | ||
} | ||
|
||
data class ResponseIsStaleWarning( | ||
override val message: String, | ||
override val csr: ContextSourceRegistration | ||
) : NGSILDWarning(RESPONSE_IS_STALE_WARNING_CODE, message, csr) | ||
|
||
data class RevalidationFailedWarning( | ||
override val message: String, | ||
override val csr: ContextSourceRegistration | ||
) : NGSILDWarning(REVALIDATION_FAILED_WARNING_CODE, message, csr) | ||
|
||
data class MiscellaneousWarning( | ||
override val message: String, | ||
override val csr: ContextSourceRegistration | ||
) : NGSILDWarning(MISCELLANEOUS_WARNING_CODE, message, csr) | ||
|
||
data class MiscellaneousPersistentWarning( | ||
override val message: String, | ||
override val csr: ContextSourceRegistration | ||
) : NGSILDWarning(MISCELLANEOUS_PERSISTENT_WARNING_CODE, message, csr) | ||
|
||
fun ResponseEntity<*>.addWarnings(warnings: List<NGSILDWarning>?): ResponseEntity<*> { | ||
val headers = HttpHeaders.writableHttpHeaders(this.headers) | ||
if (!warnings.isNullOrEmpty()) | ||
headers.addAll(NGSILDWarning.HEADER_NAME, warnings.map { it.getHeaderMessage() }) | ||
|
||
return ResponseEntity.status(this.statusCode) | ||
.headers(headers) | ||
.body(this.body) | ||
} |
91 changes: 91 additions & 0 deletions
91
search-service/src/main/kotlin/com/egm/stellio/search/csr/service/ContextSourceCaller.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.egm.stellio.search.csr.service | ||
|
||
import arrow.core.Either | ||
import arrow.core.left | ||
import arrow.core.raise.either | ||
import arrow.core.right | ||
import com.egm.stellio.search.csr.model.* | ||
import com.egm.stellio.shared.model.CompactedEntity | ||
import com.egm.stellio.shared.util.QUERY_PARAM_GEOMETRY_PROPERTY | ||
import com.egm.stellio.shared.util.QUERY_PARAM_LANG | ||
import com.egm.stellio.shared.util.QUERY_PARAM_OPTIONS | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.core.codec.DecodingException | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.http.HttpMethod | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.util.MultiValueMap | ||
import org.springframework.web.reactive.function.client.WebClient | ||
import org.springframework.web.reactive.function.client.awaitBodyOrNull | ||
import org.springframework.web.reactive.function.client.awaitExchange | ||
import java.net.URI | ||
|
||
object ContextSourceCaller { | ||
val logger: Logger = LoggerFactory.getLogger(javaClass) | ||
|
||
suspend fun getDistributedInformation( | ||
httpHeaders: HttpHeaders, | ||
csr: ContextSourceRegistration, | ||
path: String, | ||
params: MultiValueMap<String, String> | ||
): Either<NGSILDWarning, CompactedEntity?> = either { | ||
val uri = URI("${csr.endpoint}$path") | ||
params.remove(QUERY_PARAM_GEOMETRY_PROPERTY) | ||
params.remove(QUERY_PARAM_OPTIONS) // only request normalized | ||
params.remove(QUERY_PARAM_LANG) // todo not sure its needed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is handled when doing the final representation, so yes, it should be removed. |
||
val request = WebClient.create() | ||
.method(HttpMethod.GET) | ||
.uri { uriBuilder -> | ||
uriBuilder.scheme(uri.scheme) | ||
.host(uri.host) | ||
.port(uri.port) | ||
.path(uri.path) | ||
.queryParams(params) | ||
.build() | ||
} | ||
.header(HttpHeaders.LINK, httpHeaders.getFirst(HttpHeaders.LINK)) | ||
return runCatching { | ||
val (statusCode, response) = request | ||
.awaitExchange { response -> | ||
response.statusCode() to response.awaitBodyOrNull<CompactedEntity>() | ||
} | ||
when { | ||
statusCode.is2xxSuccessful -> { | ||
logger.info("Successfully received data from CSR ${csr.id} at $uri") | ||
response.right() | ||
} | ||
|
||
statusCode.isSameCodeAs(HttpStatus.NOT_FOUND) -> { | ||
logger.info("CSR returned 404 at $uri: $response") | ||
null.right() | ||
} | ||
|
||
else -> { | ||
logger.warn("Error contacting CSR at $uri: $response") | ||
MiscellaneousPersistentWarning( | ||
"$uri returned an error $statusCode with response: $response", | ||
csr | ||
).left() | ||
} | ||
} | ||
}.fold( | ||
onSuccess = { it }, | ||
onFailure = { e -> | ||
logger.warn("Error contacting CSR at $uri: ${e.message}") | ||
logger.warn(e.stackTraceToString()) | ||
when (e) { | ||
is DecodingException -> RevalidationFailedWarning( | ||
"$uri returned badly formed data message: \"${e.cause}:${e.message}\"", | ||
csr | ||
) | ||
|
||
else -> MiscellaneousWarning( | ||
"Error connecting to $uri message : \"${e.cause}:${e.message}\"", | ||
csr | ||
) | ||
}.left() | ||
} | ||
) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't forget to "bind" in CSRService (create and get operations)