From ba6b04bd8bbd2ec4eceeabb3f7993d3991779b53 Mon Sep 17 00:00:00 2001 From: HyunSu1768 Date: Mon, 29 Jul 2024 07:43:43 +0900 Subject: [PATCH] feat :: migration to v2 --- .../deploy/adapter/V1DeployWebAdapter.kt | 9 +++++- .../in/DeployMigrationToV2PipelineUseCase.kt | 7 +++++ .../DeployMigrationToV2PipelineService.kt | 29 +++++++++++++++++++ .../domain/deploy/domain/Deploy.kt | 13 ++++++++- 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/port/in/DeployMigrationToV2PipelineUseCase.kt create mode 100644 src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/service/DeployMigrationToV2PipelineService.kt diff --git a/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/adapter/V1DeployWebAdapter.kt b/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/adapter/V1DeployWebAdapter.kt index 3e271b7..67b8f9b 100644 --- a/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/adapter/V1DeployWebAdapter.kt +++ b/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/adapter/V1DeployWebAdapter.kt @@ -16,7 +16,8 @@ class V1DeployWebAdapter( private val approveDeployUseCase: ApproveDeployUseCase, private val getAllDeployInTeamUseCase: GetAllDeployInTeamUseCase, private val getDeployDetailsUseCase: GetDeployDetailsUseCase, - private val migrationDeployUseCase: MigrationDeployUseCase + private val migrationDeployUseCase: MigrationDeployUseCase, + private val deployMigrationToV2PipelineUseCase: DeployMigrationToV2PipelineUseCase ) { @PostMapping fun createDeploy( @@ -52,4 +53,10 @@ class V1DeployWebAdapter( @PostMapping("/migration") fun migrationDeploy() = migrationDeployUseCase.migrationDeploy() + + @PutMapping("/migration/v2") + fun migrateToV2( + @PathVariable("deployId", required = true) + deployId: UUID + ) = deployMigrationToV2PipelineUseCase.migrationDeploy(deployId) } \ No newline at end of file diff --git a/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/port/in/DeployMigrationToV2PipelineUseCase.kt b/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/port/in/DeployMigrationToV2PipelineUseCase.kt new file mode 100644 index 0000000..5483b4f --- /dev/null +++ b/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/port/in/DeployMigrationToV2PipelineUseCase.kt @@ -0,0 +1,7 @@ +package xquare.app.xquareinfra.domain.deploy.application.port.`in` + +import java.util.UUID + +interface DeployMigrationToV2PipelineUseCase { + fun migrationDeploy(deployId: UUID) +} \ No newline at end of file diff --git a/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/service/DeployMigrationToV2PipelineService.kt b/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/service/DeployMigrationToV2PipelineService.kt new file mode 100644 index 0000000..c05f89d --- /dev/null +++ b/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/service/DeployMigrationToV2PipelineService.kt @@ -0,0 +1,29 @@ +package xquare.app.xquareinfra.domain.deploy.application.service + +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import xquare.app.xquareinfra.domain.container.application.port.out.FindContainerPort +import xquare.app.xquareinfra.domain.deploy.application.port.`in`.DeployMigrationToV2PipelineUseCase +import xquare.app.xquareinfra.domain.deploy.application.port.out.FindDeployPort +import xquare.app.xquareinfra.infrastructure.exception.BusinessLogicException +import xquare.app.xquareinfra.infrastructure.vault.VaultUtil +import java.util.* + +@Transactional +@Service +class DeployMigrationToV2PipelineService( + private val findDeployPort: FindDeployPort, + private val findContainerPort: FindContainerPort, + private val vaultUtil: VaultUtil +) : DeployMigrationToV2PipelineUseCase{ + override fun migrationDeploy(deployId: UUID) { + val deploy = findDeployPort.findById(deployId) ?: throw BusinessLogicException.DEPLOY_NOT_FOUND + val containers = findContainerPort.findAllByDeploy(deploy) + + containers.map { + vaultUtil.addSecret(it.environmentVariable, vaultUtil.getPath(deploy, it)) + } + + deploy.migrationToV2() + } +} \ No newline at end of file diff --git a/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/domain/Deploy.kt b/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/domain/Deploy.kt index 2ee1e1b..25527a8 100644 --- a/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/domain/Deploy.kt +++ b/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/domain/Deploy.kt @@ -1,5 +1,6 @@ package xquare.app.xquareinfra.domain.deploy.domain +import org.hibernate.annotations.ColumnDefault import xquare.app.xquareinfra.domain.BaseUUIDEntity import xquare.app.xquareinfra.domain.team.domain.Team import java.util.* @@ -18,7 +19,8 @@ class Deploy( deployStatus: DeployStatus, deployType: DeployType, useMysql: Boolean, - useRedis: Boolean + useRedis: Boolean, + isV2: Boolean = false ) : BaseUUIDEntity(id) { @Column(name = "deploy_name", nullable = false, unique = true) var deployName: String = deployName @@ -67,6 +69,11 @@ class Deploy( var useMysql = useMysql protected set + @Column(name = "is_v2", nullable = false) + @ColumnDefault("false") + var isV2 = isV2 + protected set + fun updateSecret(secretKey: String) { this.secretKey = secretKey } @@ -74,4 +81,8 @@ class Deploy( fun approveDeploy() { this.deployStatus = DeployStatus.AVAILABLE } + + fun migrationToV2() { + this.isV2 = true + } } \ No newline at end of file