From e988c8c7eb893c840c01888ea118890eb2c70fcc Mon Sep 17 00:00:00 2001 From: Alexander Ryabokon Date: Mon, 10 Jun 2024 14:26:52 +0300 Subject: [PATCH] Add response to ComponentsRegistryService.checkCacheActualityAndClean --- .../jira/config/ComponentRegistryService.kt | 3 ++- .../config/ComponentRegistryServiceImpl.kt | 27 ++++++++++--------- .../octopus/jira/model/UpdateCacheResult.kt | 3 +++ 3 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 components-registry/src/main/kotlin/org/octopusden/octopus/jira/model/UpdateCacheResult.kt diff --git a/components-registry/src/main/kotlin/org/octopusden/octopus/jira/config/ComponentRegistryService.kt b/components-registry/src/main/kotlin/org/octopusden/octopus/jira/config/ComponentRegistryService.kt index 53cfb6d..b71d569 100644 --- a/components-registry/src/main/kotlin/org/octopusden/octopus/jira/config/ComponentRegistryService.kt +++ b/components-registry/src/main/kotlin/org/octopusden/octopus/jira/config/ComponentRegistryService.kt @@ -12,6 +12,7 @@ import org.octopusden.octopus.jira.model.VCSSettings import org.octopusden.octopus.releng.dto.ComponentVersion import org.octopusden.octopus.releng.dto.JiraComponentVersion import java.util.Optional +import org.octopusden.octopus.jira.model.UpdateCacheResult import org.octopusden.octopus.releng.JiraComponentVersionFormatter import org.octopusden.releng.versions.VersionNames @@ -55,7 +56,7 @@ interface ComponentRegistryService { fun getDetailedComponentVersions(component: String, versions: Set): DetailedComponentVersions - fun checkCacheActualityAndClean(forceClean: Boolean = false) + fun checkCacheActualityAndClean(forceClean: Boolean = false): UpdateCacheResult fun getVersionNames(): VersionNames diff --git a/components-registry/src/main/kotlin/org/octopusden/octopus/jira/config/ComponentRegistryServiceImpl.kt b/components-registry/src/main/kotlin/org/octopusden/octopus/jira/config/ComponentRegistryServiceImpl.kt index 3bedbb8..4837503 100644 --- a/components-registry/src/main/kotlin/org/octopusden/octopus/jira/config/ComponentRegistryServiceImpl.kt +++ b/components-registry/src/main/kotlin/org/octopusden/octopus/jira/config/ComponentRegistryServiceImpl.kt @@ -4,7 +4,6 @@ import com.atlassian.cache.CacheManager import com.atlassian.jira.project.Project import com.atlassian.jira.project.version.Version import feign.FeignException -import java.util.Date import java.util.Optional import java.util.SortedSet import org.octopusden.octopus.components.registry.client.ComponentsRegistryServiceClient @@ -41,6 +40,7 @@ import org.octopusden.releng.versions.VersionNames import org.slf4j.LoggerFactory import javax.inject.Inject import javax.inject.Named +import org.octopusden.octopus.jira.model.UpdateCacheResult @Named class ComponentRegistryServiceImpl @Inject constructor( @@ -52,7 +52,7 @@ class ComponentRegistryServiceImpl @Inject constructor( private val jiraComponentVersionFormatter = createJiraComponentVersionFormatter() - private var fixedRemoteDate: Date = Date(0L) + private var fixedRemoteStatus: Any = "initial status" private val allComponentsCache = cacheManager.getCache(CacheId.ALL_COMPONENTS.id()) { _: Unit -> client.getAllComponents().components.map { it.toModel() } @@ -283,19 +283,20 @@ class ComponentRegistryServiceImpl @Inject constructor( return detailedComponentVersionsCache.get(DetailedComponentVersionsCacheRequest(component, versions.toSortedSet()))!! } - override fun checkCacheActualityAndClean(forceClean: Boolean) { - val remoteDate = client.getServiceStatus().cacheUpdatedAt - if (forceClean || this.fixedRemoteDate != remoteDate) { - log.info("Cleaning CR cache force=$forceClean $fixedRemoteDate != $remoteDate") - CacheId.values() - .forEach { - cacheManager.getManagedCache(it.id()) - ?.clear() - } - this.fixedRemoteDate = remoteDate + override fun checkCacheActualityAndClean(forceClean: Boolean): UpdateCacheResult { + val serviceStatus = client.getServiceStatus() + val remoteStatus = serviceStatus.versionControlRevision ?: serviceStatus.cacheUpdatedAt + + val fixedRemoteStatus = this.fixedRemoteStatus + + val message = if (forceClean || fixedRemoteStatus != remoteStatus) { + CacheId.values().forEach { cacheId -> cacheManager.getManagedCache(cacheId.id())?.clear() } + this.fixedRemoteStatus = remoteStatus + "Cleaned CR cache" } else { - log.debug("Skip clean CR cache force=$forceClean fixedRemoteDate=$fixedRemoteDate remoteDate=$remoteDate") + "Skip clean CR cache" } + return UpdateCacheResult("$message force='$forceClean', fixedRemoteStatus='$fixedRemoteStatus', remoteStatus='$remoteStatus'") } private fun clearResponse(function: () -> T): T? { diff --git a/components-registry/src/main/kotlin/org/octopusden/octopus/jira/model/UpdateCacheResult.kt b/components-registry/src/main/kotlin/org/octopusden/octopus/jira/model/UpdateCacheResult.kt new file mode 100644 index 0000000..9160258 --- /dev/null +++ b/components-registry/src/main/kotlin/org/octopusden/octopus/jira/model/UpdateCacheResult.kt @@ -0,0 +1,3 @@ +package org.octopusden.octopus.jira.model + +data class UpdateCacheResult(val message: String)