Skip to content

Commit

Permalink
Merge pull request #20 from /issues/19/log_container_names_on_error
Browse files Browse the repository at this point in the history
#19 ISD-567 logs element parents
  • Loading branch information
pappist authored Apr 10, 2024
2 parents da7f92e + 69e10e7 commit 4e732f8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/data/Data.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ data class Revision(
val branch_id: String = "",
val resource_id: String = "",
val workspace_id: String = "",
val elements: List<Any?> = emptyList()
val elements: List<String> = emptyList()
)

data class Element(
Expand All @@ -54,7 +54,7 @@ data class Elements(
val branch_id: String = "",
val resource_id: String = "",
val workspace_id: String = "",
val elements: List<Any?> = emptyList()
val elements: Map<String, String> = mapOf()
)

const val REPO = "repo"
Expand Down
8 changes: 3 additions & 5 deletions src/main/kotlin/verticles/MainVerticle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class MainVerticle(
if (revisionId == inputRevision) {
if (requestSingleElements) {
revision.elements.forEach { element ->
val elemId = element as String
val elemId = element
vertx.eventBus().send(
TWCVERT_ADDRESS, JsonObject.mapFrom(
Message(
Expand Down Expand Up @@ -353,7 +353,7 @@ class MainVerticle(
)
}
} else {
val elementIds = revision.elements
val elementIds = revision.elements.map { Pair(it, "") }.toMap()
vertx.eventBus().send(
TWCVERT_ADDRESS, JsonObject.mapFrom(
Message(
Expand Down Expand Up @@ -433,9 +433,7 @@ class MainVerticle(
val branchId = elements.branch_id
val resourceId = elements.resource_id
val workspaceId = elements.workspace_id
val elementIds = elements.elements.map { element ->
JsonObject.mapFrom(element).getString("@id")
}
val elementIds = elements.elements
vertx.eventBus().send(
TWCVERT_ADDRESS, JsonObject.mapFrom(
Message(
Expand Down
39 changes: 28 additions & 11 deletions src/main/kotlin/verticles/RESTVerticle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,13 @@ class RESTVerticle(
val resourceId = obj.getString(RESOURCE_ID)
val branchId = obj.getString(BRANCH_ID)
val revisionId = obj.getInteger(REVISION_ID)
val elementIds = obj.getJsonArray(ELEMENT_IDS).map { it.toString().trim('"') }
val elementSize = elementIds.size.toLong()
val elementIDToParentPath = (obj.getJsonObject(ELEMENT_IDS) as Iterable<MutableMap.MutableEntry<String, Any>>)
.associate { Pair(it.key, it.value) }
.mapKeys { e -> e.key.trim('"') }
.mapValues { e -> e.value.toString() }
val elementSize = elementIDToParentPath.size.toLong()
queryPrepared(elementSize)
val requestData = elementIDToParentPath.keys.joinToString(",") { it }

client.post(
port, serverPath,
Expand All @@ -113,19 +117,32 @@ class RESTVerticle(
.putHeader("Cookie", "${twcMap[USER]}")
.putHeader("Cookie", "${twcMap[SESSION]}")
.timeout(timeout)
.sendBuffer(Buffer.buffer(elementIds.joinToString(","))) { ar ->
.sendBuffer(Buffer.buffer(requestData)) { ar ->
if (ar.succeeded()) {
if (ar.result().statusCode() == 200) {

val data = ar.result().bodyAsJsonObject()

queryCompleted(elementSize)
val containedElements = elementIds.flatMap { elementId ->
val element = data.getJsonObject(elementId).getJsonArray("data")
element.getJsonObject(0).getJsonArray("ldp:contains")
val containedElements = elementIDToParentPath.keys.flatMap { elementId ->
val element = data.getJsonObject(elementId)
val elementData = element.getJsonArray("data")
val elementStatus = element.getInteger("status")
val childElements = elementData.getJsonObject(0).getJsonArray("ldp:contains").map {
JsonObject.mapFrom(it).getString("@id")
}
if(elementStatus != 200 ) {
println("Unexpected status code ($elementStatus) was returned on fetching element details. Element server ID: $elementId, parent: ${elementIDToParentPath[elementId]}")
}
val parentName = elementData.getJsonObject(1).getString("kerml:name")
val parentType = elementData.getJsonObject(1).getString("@type")
val parentSegment = "$parentName (type: $parentType)"
childElements.map { childId -> Pair(childId, "${elementIDToParentPath.getOrDefault(elementId, "")} / $parentSegment") }
}

if (containedElements.isNotEmpty()) {
if (chunkSize > 1) {
println("First element in chunk: ${containedElements.first().first} is a child of ${containedElements.first().second}")
containedElements.withIndex().groupBy {
it.index / chunkSize
}.values.map { it.map {
Expand All @@ -135,7 +152,7 @@ class RESTVerticle(
branchId,
resourceId,
workspaceId,
chunkList
chunkList.toMap()
)
vertx.eventBus().send(
TWCMAIN_ADDRESS,
Expand All @@ -154,7 +171,7 @@ class RESTVerticle(
branchId,
resourceId,
workspaceId,
containedElements
containedElements.toMap()
)
vertx.eventBus().send(
TWCMAIN_ADDRESS,
Expand All @@ -170,12 +187,12 @@ class RESTVerticle(
elementContentHandler.handleContent(data, serverPath, workspaceId, resourceId, branchId, revisionId)
} else {
println("Error on requesting elements: ${ar.result().statusCode()} : ${ar.result().statusMessage()}")
printElementIds(elementIds)
printElementIds(elementIDToParentPath.keys.toList())
myError()
}
} else {
println("Query Root Element failed: ${ar.cause().message}")
printElementIds(elementIds)
printElementIds(elementIDToParentPath.keys.toList())
myError()
}

Expand Down Expand Up @@ -292,7 +309,7 @@ class RESTVerticle(
//println(data)
val revision = Revision(
revId, branchId, resourceId, workspaceId,
data.getJsonObject(0).getJsonArray("rootObjectIDs").list
data.getJsonObject(0).getJsonArray("rootObjectIDs").list.map { it.toString() }
)
//println(revision)
vertx.eventBus().send(
Expand Down

0 comments on commit 4e732f8

Please sign in to comment.