Skip to content

Commit

Permalink
feat :: 배포 내역 조회 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunSu1768 committed Jul 29, 2024
1 parent dcacce6 commit 4dc6b94
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import xquare.app.xquareinfra.domain.container.adapter.dto.request.CreateGradleD
import xquare.app.xquareinfra.domain.container.adapter.dto.request.CreateNodeDockerfileRequest
import xquare.app.xquareinfra.domain.container.adapter.dto.request.CreateNodeWithNginxDockerfileRequest
import xquare.app.xquareinfra.domain.container.adapter.dto.request.SetContainerConfigRequest
import xquare.app.xquareinfra.domain.container.application.port.`in`.CreateGradleDockerfileUseCase
import xquare.app.xquareinfra.domain.container.application.port.`in`.CreateNodeDockerfileUseCase
import xquare.app.xquareinfra.domain.container.application.port.`in`.CreateNodeWithNginxDockerfileUseCase
import xquare.app.xquareinfra.domain.container.application.port.`in`.SetContainerConfigUseCase
import xquare.app.xquareinfra.domain.container.adapter.dto.response.GetContainerDeployHistoryResponse
import xquare.app.xquareinfra.domain.container.application.port.`in`.*
import xquare.app.xquareinfra.domain.container.application.service.GetContainerDeployHistoryService
import xquare.app.xquareinfra.domain.container.domain.ContainerEnvironment
import java.util.*

Expand All @@ -18,7 +17,9 @@ class V2ContainerWebAdapter(
private val setContainerConfigUseCase: SetContainerConfigUseCase,
private val createGradleDockerfileUseCase: CreateGradleDockerfileUseCase,
private val createNodeWithNginxDockerfileUseCase: CreateNodeWithNginxDockerfileUseCase,
private val createNodeDockerfileUseCase: CreateNodeDockerfileUseCase
private val createNodeDockerfileUseCase: CreateNodeDockerfileUseCase,
private val getContainerDeployHistoryUseCase: GetContainerDeployHistoryUseCase,
private val getContainerDeployHistoryService: GetContainerDeployHistoryService
) {
@PutMapping("/config")
fun setContainerConfig(
Expand Down Expand Up @@ -57,4 +58,12 @@ class V2ContainerWebAdapter(
@RequestBody
createNodeWithNginxDockerfileRequest: CreateNodeWithNginxDockerfileRequest
) = createNodeWithNginxDockerfileUseCase.createNodeWithNginxDockerfile(deployId, containerEnvironment, createNodeWithNginxDockerfileRequest)

@GetMapping("/history")
fun getContainerDeployHistory(
@RequestParam(name = "deployId", required = true)
deployId: UUID,
@RequestParam(name = "environment", required = true)
containerEnvironment: ContainerEnvironment,
): GetContainerDeployHistoryResponse = getContainerDeployHistoryUseCase.getContainerDeployHistory(deployId, containerEnvironment)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package xquare.app.xquareinfra.domain.container.adapter.dto.response

data class GetContainerDeployHistoryResponse(
val histories: List<DeployHistoryResponse>
)

data class DeployHistoryResponse(
val name: String,
val scheduledDate: Long,
val commitMessage: String,
val stages: List<StageStatus>
)

data class StageStatus(
val name: String,
val isSuccessful: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package xquare.app.xquareinfra.domain.container.application.port.`in`

import xquare.app.xquareinfra.domain.container.adapter.dto.response.GetContainerDeployHistoryResponse
import xquare.app.xquareinfra.domain.container.domain.ContainerEnvironment
import java.util.UUID

interface GetContainerDeployHistoryUseCase {
fun getContainerDeployHistory(deployId: UUID, containerEnvironment: ContainerEnvironment): GetContainerDeployHistoryResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package xquare.app.xquareinfra.domain.container.application.service

import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import xquare.app.xquareinfra.domain.container.adapter.dto.response.DeployHistoryResponse
import xquare.app.xquareinfra.domain.container.adapter.dto.response.GetContainerDeployHistoryResponse
import xquare.app.xquareinfra.domain.container.adapter.dto.response.StageStatus
import xquare.app.xquareinfra.domain.container.application.port.`in`.GetContainerDeployHistoryUseCase
import xquare.app.xquareinfra.domain.container.domain.ContainerEnvironment
import xquare.app.xquareinfra.domain.deploy.application.port.out.FindDeployPort
import xquare.app.xquareinfra.infrastructure.exception.BusinessLogicException
import xquare.app.xquareinfra.infrastructure.feign.client.gocd.GocdClient
import java.util.*

@Transactional
@Service
class GetContainerDeployHistoryService(
private val findDeployPort: FindDeployPort,
private val gocdClient: GocdClient
) : GetContainerDeployHistoryUseCase{
override fun getContainerDeployHistory(
deployId: UUID,
containerEnvironment: ContainerEnvironment
): GetContainerDeployHistoryResponse {
val deploy = findDeployPort.findById(deployId) ?: throw BusinessLogicException.DEPLOY_NOT_FOUND
val histories = gocdClient.getPipelinesHistory("build-${deploy.deployName}-${containerEnvironment.name}", "application/vnd.go.cd.v1+json")

val response = histories.pipelines.map {
DeployHistoryResponse(
name = it.buildCause.materialRevisions[0].modifications.get(0).userName,
scheduledDate = it.scheduledDate,
stages = it.stages.map {
StageStatus(
name = it.name,
isSuccessful = it.status == "Passed"
)
}.toList(),
commitMessage = it.buildCause.materialRevisions[0].modifications.get(0).comment
)
}.sortedByDescending { it.scheduledDate }.toList()

return GetContainerDeployHistoryResponse(response)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package xquare.app.xquareinfra.infrastructure.feign.client.gocd

import org.springframework.cloud.openfeign.FeignClient
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestHeader
import xquare.app.xquareinfra.infrastructure.feign.client.gocd.dto.response.GetPipelinesHistoryResponse
import xquare.app.xquareinfra.infrastructure.feign.config.FeignConfig

@FeignClient(
name = "gocd-client",
url = "\${url.gocd}",
configuration = [FeignConfig::class]
)
interface GocdClient {
@GetMapping("/api/pipelines/{pipeline_name}/history")
fun getPipelinesHistory(
@PathVariable("pipeline_name") pipelineName: String,
@RequestHeader("Accept") accept: String
): GetPipelinesHistoryResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package xquare.app.xquareinfra.infrastructure.feign.client.gocd.dto.response

import com.fasterxml.jackson.annotation.JsonProperty

data class GetPipelinesHistoryResponse(
@JsonProperty("_links")
val links: Links,
val pipelines: List<Pipeline>,
)

data class Links(
val next: Next,
)

data class Next(
val href: String,
)

data class Pipeline(
val name: String,
val counter: Long,
val label: String,
@JsonProperty("natural_order")
val naturalOrder: Double,
@JsonProperty("can_run")
val canRun: Boolean,
@JsonProperty("preparing_to_schedule")
val preparingToSchedule: Boolean,
val comment: Any?,
@JsonProperty("scheduled_date")
val scheduledDate: Long,
@JsonProperty("build_cause")
val buildCause: BuildCause,
val stages: List<Stage>,
)

data class BuildCause(
@JsonProperty("trigger_message")
val triggerMessage: String,
@JsonProperty("trigger_forced")
val triggerForced: Boolean,
val approver: String,
@JsonProperty("material_revisions")
val materialRevisions: List<MaterialRevision>,
)

data class MaterialRevision(
val changed: Boolean,
val material: Material,
val modifications: List<Modification>,
)

data class Material(
val name: String,
val fingerprint: String,
val type: String,
val description: String,
)

data class Modification(
val revision: String,
@JsonProperty("modified_time")
val modifiedTime: Long,
@JsonProperty("user_name")
val userName: String,
val comment: String,
@JsonProperty("email_address")
val emailAddress: Any?,
)

data class Stage(
val result: String,
val status: String,
@JsonProperty("rerun_of_counter")
val rerunOfCounter: Any?,
val name: String,
val counter: String,
val scheduled: Boolean,
@JsonProperty("approval_type")
val approvalType: String,
@JsonProperty("approved_by")
val approvedBy: String,
@JsonProperty("operate_permission")
val operatePermission: Boolean,
@JsonProperty("can_run")
val canRun: Boolean,
val jobs: List<Job>,
)

data class Job(
val name: String,
@JsonProperty("scheduled_date")
val scheduledDate: Long,
val state: String,
val result: String,
)

1 change: 1 addition & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ server:
url:
deploy: ${DEPLOY_URL}
log: ${LOG_URL}
gocd: ${GOCD_URL}

secret:
projectSecret: ${PROJECT_SECRET}
Expand Down

0 comments on commit 4dc6b94

Please sign in to comment.