Skip to content

Commit

Permalink
adding WebSocketMessageData to GitLabAssignment for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-ali-55 committed Nov 21, 2023
1 parent bb63217 commit 5522d73
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ class WebsocketMessageConsumerService(
private val logger = KotlinLogging.logger {}

fun consume(
messageData: WebSocketMessageData,
assignment: GitLabAssignment
) {
logger.info { "Processing message of type ${messageData.type}" }
if (assignment.webSocketMessageData == null) return

logger.info { "Processing message of type ${assignment.webSocketMessageData.type}" }
// improvement may want to add some validations here before executing query

logInfoStatusIfNeeded(messageData.statusLoggingEnabled, assignment)
val queryResult = executeQuery(messageData.query, messageData.variables)
logInfoStatusIfNeeded(assignment.webSocketMessageData.statusLoggingEnabled, assignment)
val queryResult = executeQuery(assignment.webSocketMessageData.query, assignment.webSocketMessageData.variables)

queryResult
.getOrNull()
?.let {
if (it.second) {
it.first as List<Any>
it.first as List<*>
} else {
listOf(it.first)
}
Expand All @@ -52,7 +53,7 @@ class WebsocketMessageConsumerService(
vsmClient.saveServiceV2(
eventType = EventType.STATE.type,
dummyRequest = DummyRequest(
type = messageData.type,
type = assignment.webSocketMessageData.type,
orgName = assignment.connectorConfiguration.orgName,
runId = assignment.runId,
configurationId = assignment.configurationId,
Expand All @@ -66,10 +67,10 @@ class WebsocketMessageConsumerService(

performResultLogging(
queryResult,
messageData.statusLoggingEnabled,
messageData.adminLoggingEnabled,
messageData.successMessage,
messageData.failureMessage,
assignment.webSocketMessageData.statusLoggingEnabled,
assignment.webSocketMessageData.adminLoggingEnabled,
assignment.webSocketMessageData.successMessage,
assignment.webSocketMessageData.failureMessage,
assignment
)
}
Expand Down Expand Up @@ -117,63 +118,6 @@ class WebsocketMessageConsumerService(
}
}
}

// @PostConstruct
fun dummy(
gitLabAssignment: GitLabAssignment
) {
consume(
WebSocketMessageData(
type = "GET_ALL_REPOS",
statusLoggingEnabled = true,
adminLoggingEnabled = true,
variables = mapOf(
"pageCount" to 10,
"cursor" to null,
"group" to "cider"
),
failureMessage = "",
successMessage = "",
query = """
query AllGroupsQuery(${'$'}group: ID!, ${'$'}pageCount: Int!, ${'$'}cursor: String) {
group(fullPath: ${'$'}group) {
id
name
projects(first: ${'$'}pageCount, after: ${'$'}cursor, includeSubgroups: true) {
pageInfo {
hasNextPage
endCursor
}
nodes {
name
path
id
archived
visibility
topics
webUrl
description
lastActivityAt
languages {
name
share
}
repository {
diskPath
rootRef
}
group {
fullPath
}
}
}
}
}
""".trimIndent()
),
gitLabAssignment,
)
}
}

data class DummyRequest(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package net.leanix.vsm.gitlab.broker.connector.domain

import net.leanix.vsm.gitlab.broker.connector.application.WebSocketMessageData
import java.util.UUID

data class GitLabAssignment(
val runId: UUID,
val workspaceId: UUID,
val configurationId: UUID,
val connectorConfiguration: GitLabConfiguration
val connectorConfiguration: GitLabConfiguration,
val webSocketMessageData: WebSocketMessageData?
)

data class GitLabConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class InitialStateRunner(
assignmentService.getAssignments()?.let {
// initialStateService.initState(it)
it.forEach {
websocketMessageConsumerService.dummy(it)
websocketMessageConsumerService.consume(it)
}
}
}.onSuccess {
Expand Down

0 comments on commit 5522d73

Please sign in to comment.