Skip to content

Instantly share code, notes, and snippets.

@snrostov
Created December 29, 2016 16:46
Show Gist options
  • Select an option

  • Save snrostov/110d8cc8c6f44c5fd7fe94cfb3b01e61 to your computer and use it in GitHub Desktop.

Select an option

Save snrostov/110d8cc8c6f44c5fd7fe94cfb3b01e61 to your computer and use it in GitHub Desktop.
import com.google.gson.GsonBuilder
import java.io.File
fun forEachEntry(action: (it: FullEntry) -> Unit) {
val gson = GsonBuilder().create()
var i = 0
File("/Users/sergey/Downloads/container-8490.log").forEachLine {
val first = it.indexOf('{')
if (first > 0) {
val info = it.substring(0, first)
val json = it.substring(first)
val fromJson = gson.fromJson(json, Entry::class.java)
if (fromJson != null) {
action(FullEntry(++i, info, fromJson))
}
}
}
}
fun main(args: Array<String>) {
val objects = mutableMapOf<String, MutableList<FullEntry>>()
val actions = mutableMapOf<String, MutableList<FullEntry>>()
forEachEntry {
val (_, _, fromJson) = it
val id = fromJson.id
if (id != null) {
objects.getOrPut(id) { mutableListOf() }.add(it)
}
if (fromJson.respond != null) {
val msg = "Smev action with uniqId '"
val indexOf = fromJson.respond.indexOf(msg)
if (indexOf > 0) {
val a = indexOf + msg.length
val b = fromJson.respond.indexOf('\'', a)
val guid = fromJson.respond.substring(a, b)
actions.getOrPut(guid) { mutableListOf() }.add(it)
}
}
}
forEachEntry { claim ->
val (_, _, fromJson) = claim
val claimEntries = objects[fromJson.id]
if (fromJson.soap != null) {
if (fromJson.soap.contains("newAction")) {
actions[fromJson.id]?.forEach { status ->
if (claim.num > status.num) {
val statusEntries = objects[status.entry.id]
println("Found status at line ${status.num} is created BEFORE claim at line ${claim.num}")
println(" Status update:")
println(" ${status.toString().replace('\n', ' ')}")
println(" Claim create:")
println(" ${claimEntries?.getOrNull(0)?.toString()?.replace('\n', ' ')}")
println(" ${claimEntries?.getOrNull(1)?.toString()?.replace('\n', ' ')}")
}
}
}
}
}
}
data class FullEntry(
val num: Int,
val info: String,
val entry: Entry
)
data class Entry(val step: String?,
val status: String?,
val soap: String?,
val respond: String?,
val time: Double?,
val type: String?,
val id: String?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment