diff --git a/src/main/groovy/io/seqera/wave/controller/ContainerController.groovy b/src/main/groovy/io/seqera/wave/controller/ContainerController.groovy index 713ffae89..fabef4017 100644 --- a/src/main/groovy/io/seqera/wave/controller/ContainerController.groovy +++ b/src/main/groovy/io/seqera/wave/controller/ContainerController.groovy @@ -284,7 +284,7 @@ class ContainerController { protected void storeContainerRequest0(SubmitContainerTokenRequest req, ContainerRequest data, TokenData token, String target, String ip) { try { final recrd = new WaveContainerRecord(req, data, target, ip, token.expiration) - persistenceService.saveContainerRequest(recrd) + persistenceService.saveContainerRequestAsync(recrd) } catch (Throwable e) { log.error("Unable to store container request with token: ${token}", e) diff --git a/src/main/groovy/io/seqera/wave/core/RegistryProxyService.groovy b/src/main/groovy/io/seqera/wave/core/RegistryProxyService.groovy index 1d9bf61de..32cf49604 100644 --- a/src/main/groovy/io/seqera/wave/core/RegistryProxyService.groovy +++ b/src/main/groovy/io/seqera/wave/core/RegistryProxyService.groovy @@ -133,7 +133,7 @@ class RegistryProxyService { return try { - persistenceService.updateContainerRequest(route.token, digest) + persistenceService.updateContainerRequestAsync(route.token, digest) } catch (Throwable t) { log.error("Unable store container request for token: $route.token", t) } diff --git a/src/main/groovy/io/seqera/wave/service/builder/impl/ContainerBuildServiceImpl.groovy b/src/main/groovy/io/seqera/wave/service/builder/impl/ContainerBuildServiceImpl.groovy index 26250c2c3..6dbe9f787 100644 --- a/src/main/groovy/io/seqera/wave/service/builder/impl/ContainerBuildServiceImpl.groovy +++ b/src/main/groovy/io/seqera/wave/service/builder/impl/ContainerBuildServiceImpl.groovy @@ -352,7 +352,7 @@ class ContainerBuildServiceImpl implements ContainerBuildService, JobHandler mirrorStore = new HashMap<>() @Override - void saveBuild(WaveBuildRecord record) { + void saveBuildAsync(WaveBuildRecord record) { buildStore[record.buildId] = record } @@ -76,12 +76,12 @@ class LocalPersistenceService implements PersistenceService { } @Override - void saveContainerRequest(WaveContainerRecord data) { + void saveContainerRequestAsync(WaveContainerRecord data) { requestStore.put(data.id, data) } @Override - void updateContainerRequest(String token, ContainerDigestPair digest) { + void updateContainerRequestAsync(String token, ContainerDigestPair digest) { final data = requestStore.get(token) if( data ) { requestStore.put(token, new WaveContainerRecord(data, digest.source, digest.target)) @@ -99,7 +99,7 @@ class LocalPersistenceService implements PersistenceService { } @Override - void saveScanRecord(WaveScanRecord scanRecord) { + void saveScanRecordAsync(WaveScanRecord scanRecord) { scanStore.put(scanRecord.id, scanRecord) } @@ -129,7 +129,7 @@ class LocalPersistenceService implements PersistenceService { } @Override - void saveMirrorResult(MirrorResult mirror) { + void saveMirrorResultAsync(MirrorResult mirror) { mirrorStore.put(mirror.mirrorId, mirror) } diff --git a/src/main/groovy/io/seqera/wave/service/persistence/impl/SurrealPersistenceService.groovy b/src/main/groovy/io/seqera/wave/service/persistence/impl/SurrealPersistenceService.groovy index 64ad6f7c8..829c6a384 100644 --- a/src/main/groovy/io/seqera/wave/service/persistence/impl/SurrealPersistenceService.groovy +++ b/src/main/groovy/io/seqera/wave/service/persistence/impl/SurrealPersistenceService.groovy @@ -100,7 +100,7 @@ class SurrealPersistenceService implements PersistenceService { } @Override - void saveBuild(WaveBuildRecord build) { + void saveBuildAsync(WaveBuildRecord build) { // note: use surreal sql in order to by-pass issue with large payload // see https://github.com/seqeralabs/wave/issues/559#issuecomment-2369412170 final query = "INSERT INTO wave_build ${JacksonHelper.toJson(build)}" @@ -198,7 +198,7 @@ class SurrealPersistenceService implements PersistenceService { } @Override - void saveContainerRequest(WaveContainerRecord data) { + void saveContainerRequestAsync(WaveContainerRecord data) { // note: use surreal sql in order to by-pass issue with large payload // see https://github.com/seqeralabs/wave/issues/559#issuecomment-2369412170 final query = "INSERT INTO wave_request ${JacksonHelper.toJson(data)}" @@ -216,7 +216,7 @@ class SurrealPersistenceService implements PersistenceService { }) } - void updateContainerRequest(String token, ContainerDigestPair digest) { + void updateContainerRequestAsync(String token, ContainerDigestPair digest) { final query = """\ UPDATE wave_request:$token SET sourceDigest = '$digest.source', @@ -253,7 +253,7 @@ class SurrealPersistenceService implements PersistenceService { } @Override - void saveScanRecord(WaveScanRecord scanRecord) { + void saveScanRecordAsync(WaveScanRecord scanRecord) { final vulnerabilities = scanRecord.vulnerabilities ?: List.of() // create a multi-command surreal sql statement to insert all vulnerabilities @@ -380,7 +380,7 @@ class SurrealPersistenceService implements PersistenceService { * @param mirror {@link MirrorEntry} object */ @Override - void saveMirrorResult(MirrorResult mirror) { + void saveMirrorResultAsync(MirrorResult mirror) { surrealDb.insertMirrorAsync(getAuthorization(), mirror).subscribe({ result-> log.trace "Mirror request with id '$mirror.mirrorId' saved record: ${result}" }, {error-> diff --git a/src/main/groovy/io/seqera/wave/service/scan/ContainerScanServiceImpl.groovy b/src/main/groovy/io/seqera/wave/service/scan/ContainerScanServiceImpl.groovy index 73305463e..d0e3d7511 100644 --- a/src/main/groovy/io/seqera/wave/service/scan/ContainerScanServiceImpl.groovy +++ b/src/main/groovy/io/seqera/wave/service/scan/ContainerScanServiceImpl.groovy @@ -304,7 +304,7 @@ class ContainerScanServiceImpl implements ContainerScanService, JobHandler> 'digest' and: - 1 * persistenceService.saveBuild(_) >> null + 1 * persistenceService.saveBuildAsync(_) >> null and: 1 * eventPublisher.publishEvent(_) } @@ -406,7 +406,7 @@ class ContainerBuildServiceTest extends Specification { then: 1 * buildStore.storeBuild(req.targetImage, _) >> null and: - 1 * persistenceService.saveBuild(_) >> null + 1 * persistenceService.saveBuildAsync(_) >> null and: 1 * eventPublisher.publishEvent(_) } @@ -435,7 +435,7 @@ class ContainerBuildServiceTest extends Specification { then: 1 * buildStore.storeBuild(req.targetImage, _) >> null and: - 1 * persistenceService.saveBuild(_) >> null + 1 * persistenceService.saveBuildAsync(_) >> null and: 1 * eventPublisher.publishEvent(_) } diff --git a/src/test/groovy/io/seqera/wave/service/mirror/ContainerMirrorServiceTest.groovy b/src/test/groovy/io/seqera/wave/service/mirror/ContainerMirrorServiceTest.groovy index d892af4f6..c9eedc079 100644 --- a/src/test/groovy/io/seqera/wave/service/mirror/ContainerMirrorServiceTest.groovy +++ b/src/test/groovy/io/seqera/wave/service/mirror/ContainerMirrorServiceTest.groovy @@ -105,7 +105,7 @@ class ContainerMirrorServiceTest extends Specification { and: def state = MirrorResult.of(request) and: - persistenceService.saveMirrorResult(state) + persistenceService.saveMirrorResultAsync(state) when: def copy = mirrorService.getMirrorResult(request.mirrorId) then: diff --git a/src/test/groovy/io/seqera/wave/service/persistence/impl/SurrealPersistenceServiceTest.groovy b/src/test/groovy/io/seqera/wave/service/persistence/impl/SurrealPersistenceServiceTest.groovy index 43227ad5c..a8eb7c47b 100644 --- a/src/test/groovy/io/seqera/wave/service/persistence/impl/SurrealPersistenceServiceTest.groovy +++ b/src/test/groovy/io/seqera/wave/service/persistence/impl/SurrealPersistenceServiceTest.groovy @@ -128,7 +128,7 @@ class SurrealPersistenceServiceTest extends Specification implements SurrealDBTe when: storage.initializeDb() and: - storage.saveBuild(build) + storage.saveBuildAsync(build) then: sleep 100 def stored = storage.loadBuild(request.buildId) @@ -160,7 +160,7 @@ class SurrealPersistenceServiceTest extends Specification implements SurrealDBTe def record = WaveBuildRecord.fromEvent(event) and: - persistence.saveBuild(record) + persistence.saveBuildAsync(record) when: sleep 100 @@ -248,7 +248,7 @@ class SurrealPersistenceServiceTest extends Specification implements SurrealDBTe def build1 = WaveBuildRecord.fromEvent(new BuildEvent(request, result)) when: - persistence.saveBuild(build1) + persistence.saveBuildAsync(build1) sleep 100 then: persistence.loadBuild(request.buildId) == build1 @@ -281,7 +281,7 @@ class SurrealPersistenceServiceTest extends Specification implements SurrealDBTe and: def request = new WaveContainerRecord(req, data, wave, addr, exp) and: - persistence.saveContainerRequest(request) + persistence.saveContainerRequestAsync(request) and: sleep 200 // <-- the above request is async, give time to save it @@ -293,7 +293,7 @@ class SurrealPersistenceServiceTest extends Specification implements SurrealDBTe // should update the record when: - persistence.updateContainerRequest(TOKEN, new ContainerDigestPair('111', '222')) + persistence.updateContainerRequestAsync(TOKEN, new ContainerDigestPair('111', '222')) and: sleep 200 then: @@ -323,7 +323,7 @@ class SurrealPersistenceServiceTest extends Specification implements SurrealDBTe def CVE4 = new ScanVulnerability('cve-4', 'x4', 'title4', 'package4', 'version4', 'fixed4', 'url4') def scan = new WaveScanRecord(SCAN_ID, BUILD_ID, null, null, CONTAINER_IMAGE, PLATFORM, NOW, Duration.ofSeconds(10), 'SUCCEEDED', [CVE1, CVE2, CVE3], null, null) when: - persistence.saveScanRecord(scan) + persistence.saveScanRecordAsync(scan) sleep 200 then: def result = persistence.loadScanRecord(SCAN_ID) @@ -343,7 +343,7 @@ class SurrealPersistenceServiceTest extends Specification implements SurrealDBTe def scanRecord2 = new WaveScanRecord(SCAN_ID2, BUILD_ID2, null, null, CONTAINER_IMAGE, PLATFORM, NOW, Duration.ofSeconds(20), 'FAILED', [CVE1, CVE4], 1, "Error 'quote'") and: // should save the same CVE into another build - persistence.saveScanRecord(scanRecord2) + persistence.saveScanRecordAsync(scanRecord2) sleep 200 then: def result2 = persistence.loadScanRecord(SCAN_ID2) @@ -373,7 +373,7 @@ class SurrealPersistenceServiceTest extends Specification implements SurrealDBTe !persistence.existsScanRecord(SCAN_ID) when: - persistence.saveScanRecord(scan) + persistence.saveScanRecordAsync(scan) sleep 200 then: persistence.existsScanRecord(SCAN_ID) @@ -401,7 +401,7 @@ class SurrealPersistenceServiceTest extends Specification implements SurrealDBTe storage.initializeDb() and: def result = MirrorEntry.of(request).getResult() - storage.saveMirrorResult(result) + storage.saveMirrorResultAsync(result) sleep 100 when: @@ -461,9 +461,9 @@ class SurrealPersistenceServiceTest extends Specification implements SurrealDBTe def result1 = MirrorResult.of(request1).complete(1, 'err') def result2 = MirrorResult.of(request2).complete(0, 'ok') def result3 = MirrorResult.of(request3).complete(0, 'ok') - storage.saveMirrorResult(result1) - storage.saveMirrorResult(result2) - storage.saveMirrorResult(result3) + storage.saveMirrorResultAsync(result1) + storage.saveMirrorResultAsync(result2) + storage.saveMirrorResultAsync(result3) sleep 100 when: @@ -509,7 +509,7 @@ class SurrealPersistenceServiceTest extends Specification implements SurrealDBTe def build1 = WaveBuildRecord.fromEvent(new BuildEvent(request, result)) when: - persistence.saveBuild(build1) + persistence.saveBuildAsync(build1) sleep 100 then: persistence.loadBuild(request.buildId) == build1 @@ -565,10 +565,10 @@ class SurrealPersistenceServiceTest extends Specification implements SurrealDBTe def scan4 = new WaveScanRecord('sc-01234567890abcdef_4', '103', null, null, CONTAINER_IMAGE, PLATFORM,Instant.now(), Duration.ofSeconds(10), 'SUCCEEDED', [CVE1], null, null) when: - persistence.saveScanRecord(scan1) - persistence.saveScanRecord(scan2) - persistence.saveScanRecord(scan3) - persistence.saveScanRecord(scan4) + persistence.saveScanRecordAsync(scan1) + persistence.saveScanRecordAsync(scan2) + persistence.saveScanRecordAsync(scan3) + persistence.saveScanRecordAsync(scan4) and: sleep 200 then: diff --git a/src/test/groovy/io/seqera/wave/service/scan/ContainerScanServiceImplTest.groovy b/src/test/groovy/io/seqera/wave/service/scan/ContainerScanServiceImplTest.groovy index 4ab8ca50b..05fe4efac 100644 --- a/src/test/groovy/io/seqera/wave/service/scan/ContainerScanServiceImplTest.groovy +++ b/src/test/groovy/io/seqera/wave/service/scan/ContainerScanServiceImplTest.groovy @@ -452,21 +452,21 @@ class ContainerScanServiceImplTest extends Specification { scanService.storeScanEntry(scanSucceeded) then: 1 * scanStore.storeScan(scanSucceeded) >> null - 1 * persistenceService.saveScanRecord(new WaveScanRecord(scanSucceeded)) >> null + 1 * persistenceService.saveScanRecordAsync(new WaveScanRecord(scanSucceeded)) >> null 0 * cleanupService.cleanupScanId(container) >> null when: scanService.storeScanEntry(scanNotDone) then: 1 * scanStore.storeScan(scanNotDone) >> null - 1 * persistenceService.saveScanRecord(new WaveScanRecord(scanNotDone)) >> null + 1 * persistenceService.saveScanRecordAsync(new WaveScanRecord(scanNotDone)) >> null 0 * cleanupService.cleanupScanId(container) >> null when: scanService.storeScanEntry(scanFailed) then: 1 * scanStore.storeScan(scanFailed) >> null - 1 * persistenceService.saveScanRecord(new WaveScanRecord(scanFailed)) >> null + 1 * persistenceService.saveScanRecordAsync(new WaveScanRecord(scanFailed)) >> null 1 * cleanupService.cleanupScanId(container) >> null } }