-
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
dcacce6
commit 4dc6b94
Showing
7 changed files
with
203 additions
and
5 deletions.
There are no files selected for viewing
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
17 changes: 17 additions & 0 deletions
17
...pp/xquareinfra/domain/container/adapter/dto/response/GetContainerDeployHistoryResponse.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,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 | ||
) |
9 changes: 9 additions & 0 deletions
9
.../app/xquareinfra/domain/container/application/port/in/GetContainerDeployHistoryUseCase.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,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 | ||
} |
44 changes: 44 additions & 0 deletions
44
.../app/xquareinfra/domain/container/application/service/GetContainerDeployHistoryService.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,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) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/xquare/app/xquareinfra/infrastructure/feign/client/gocd/GocdClient.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,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 | ||
} |
97 changes: 97 additions & 0 deletions
97
.../xquareinfra/infrastructure/feign/client/gocd/dto/response/GetPipelinesHistoryResponse.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,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, | ||
) | ||
|
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