-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d855db
commit 24fd095
Showing
9 changed files
with
161 additions
and
8 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/net/leanix/vsm/gitlab/broker/connector/adapter/feign/RunFeignProvider.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,25 @@ | ||
package net.leanix.vsm.gitlab.broker.connector.adapter.feign | ||
|
||
import net.leanix.vsm.gitlab.broker.connector.adapter.feign.data.RunState | ||
import net.leanix.vsm.gitlab.broker.connector.adapter.feign.data.UpdateRunStateRequest | ||
import net.leanix.vsm.gitlab.broker.connector.domain.GitLabAssignment | ||
import net.leanix.vsm.gitlab.broker.connector.domain.RunProvider | ||
import net.leanix.vsm.gitlab.broker.shared.Constants.GITLAB_ENTERPRISE_CONNECTOR | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class RunFeignProvider(private val vsmClient: VsmClient) : RunProvider { | ||
|
||
override fun updateRun(assignment: GitLabAssignment, runState: RunState, message: String?) { | ||
vsmClient.updateRunState( | ||
runId = assignment.runId, | ||
UpdateRunStateRequest( | ||
state = RunState.FINISHED, | ||
workspaceId = assignment.workspaceId.toString(), | ||
connector = GITLAB_ENTERPRISE_CONNECTOR, | ||
orgName = assignment.connectorConfiguration.orgName, | ||
message = message | ||
) | ||
) | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
...kotlin/net/leanix/vsm/gitlab/broker/connector/adapter/feign/data/UpdateRunStateRequest.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,18 @@ | ||
package net.leanix.vsm.gitlab.broker.connector.adapter.feign.data | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class UpdateRunStateRequest( | ||
val state: RunState, | ||
val workspaceId: String? = null, | ||
val connector: String? = null, | ||
val orgName: String? = null, | ||
val message: String? = null, | ||
val region: String? = null | ||
) | ||
|
||
enum class RunState { | ||
RUNNING, | ||
FINISHED, | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/net/leanix/vsm/gitlab/broker/connector/domain/RunProvider.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,8 @@ | ||
package net.leanix.vsm.gitlab.broker.connector.domain | ||
|
||
import net.leanix.vsm.gitlab.broker.connector.adapter.feign.data.RunState | ||
|
||
interface RunProvider { | ||
|
||
fun updateRun(assignment: GitLabAssignment, runState: RunState, message: String?) | ||
} |
16 changes: 15 additions & 1 deletion
16
src/main/kotlin/net/leanix/vsm/gitlab/broker/connector/runner/ShutdownService.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 |
---|---|---|
@@ -1,16 +1,30 @@ | ||
package net.leanix.vsm.gitlab.broker.connector.runner | ||
|
||
import jakarta.annotation.PreDestroy | ||
import net.leanix.vsm.gitlab.broker.connector.adapter.feign.data.RunState | ||
import net.leanix.vsm.gitlab.broker.connector.domain.RunProvider | ||
import net.leanix.vsm.gitlab.broker.shared.cache.AssignmentsCache | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ShutdownService { | ||
class ShutdownService(private val runProvider: RunProvider) { | ||
|
||
private val logger = LoggerFactory.getLogger(ShutdownService::class.java) | ||
|
||
@PreDestroy | ||
fun onDestroy() { | ||
logger.info("Shutting down gitlab on-prem") | ||
if (AssignmentsCache.getAll().isEmpty()) { | ||
logger.info("Shutting down github broker before receiving any assignment") | ||
} else { | ||
AssignmentsCache.getAll().values.forEach { assignment -> | ||
runProvider.updateRun( | ||
runState = RunState.FINISHED, | ||
assignment = assignment, | ||
message = "gracefully stopped GitHub broker" | ||
) | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ enum class LogStatus { | |
STARTED, | ||
IN_PROGRESS, | ||
FAILED, | ||
SUCCESSFUL | ||
SUCCESSFUL, | ||
FINISHED | ||
} |
61 changes: 61 additions & 0 deletions
61
src/test/kotlin/net/leanix/vsm/gitlab/broker/connector/runner/ShutdownServiceTest.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,61 @@ | ||
package net.leanix.vsm.gitlab.broker.connector.runner | ||
|
||
import io.mockk.clearAllMocks | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import net.leanix.vsm.gitlab.broker.connector.adapter.feign.data.RunState | ||
import net.leanix.vsm.gitlab.broker.connector.domain.GitLabAssignment | ||
import net.leanix.vsm.gitlab.broker.connector.domain.GitLabConfiguration | ||
import net.leanix.vsm.gitlab.broker.connector.domain.RunProvider | ||
import net.leanix.vsm.gitlab.broker.shared.cache.AssignmentsCache | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import java.util.* | ||
|
||
class ShutdownServiceTest { | ||
|
||
private val runProvider: RunProvider = mockk(relaxed = true) | ||
private val shutdownService = ShutdownService(runProvider) | ||
|
||
@BeforeEach | ||
fun setup() { | ||
clearAllMocks() | ||
AssignmentsCache.deleteAll() | ||
} | ||
|
||
@Test | ||
fun `test onDestroy with empty assignment cache`() { | ||
shutdownService.onDestroy() | ||
|
||
// Assert no interactions with the run status provider | ||
verify(exactly = 0) { runProvider.updateRun(any(), any(), any()) } | ||
} | ||
|
||
@Test | ||
fun `test onDestroy with assignments`() { | ||
val assignment = GitLabAssignment( | ||
UUID.randomUUID(), | ||
UUID.randomUUID(), | ||
UUID.randomUUID(), | ||
GitLabConfiguration( | ||
orgName = "orgName" | ||
) | ||
) | ||
AssignmentsCache.addAll(listOf(assignment)) | ||
|
||
// val runStateSlot = slot<UpdateRunStateRequest>() | ||
|
||
every { runProvider.updateRun(any(), any(), any()) } answers { } | ||
|
||
shutdownService.onDestroy() | ||
|
||
verify { | ||
runProvider.updateRun( | ||
eq(assignment), | ||
eq(RunState.FINISHED), | ||
eq("gracefully stopped GitHub broker") | ||
) | ||
} | ||
} | ||
} |
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