Skip to content

Commit

Permalink
Rename async methods for semantic consistency
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Nov 2, 2024
1 parent 3ad82a3 commit 38114d7
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class ContainerBuildServiceImpl implements ContainerBuildService, JobHandler<Bui
// for which a scan is requested but not scan record exists
scanService?.scanOnBuild(entry)
buildStore.storeBuild(targetImage, entry)
persistenceService.saveBuild(WaveBuildRecord.fromEvent(event))
persistenceService.saveBuildAsync(WaveBuildRecord.fromEvent(event))
eventPublisher.publishEvent(event)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class ContainerMirrorServiceImpl implements ContainerMirrorService, JobHandler<M
// for which a scan is requested but not scan record exists
scanService?.scanOnMirror(updated)
store.putEntry(updated)
persistence.saveMirrorResult(result)
persistence.saveMirrorResultAsync(result)
log.debug "Mirror container completed - job=${jobSpec.operationName}; result=${result}; state=${jobState}"
}

Expand All @@ -142,7 +142,7 @@ class ContainerMirrorServiceImpl implements ContainerMirrorService, JobHandler<M
void onJobTimeout(JobSpec jobSpec, MirrorEntry entry) {
final result = entry.result.complete(null, "Container mirror timed out")
store.putEntry(entry.withResult(result))
persistence.saveMirrorResult(result)
persistence.saveMirrorResultAsync(result)
log.warn "Mirror container timed out - job=${jobSpec.operationName}; result=${result}"
}

Expand All @@ -153,7 +153,7 @@ class ContainerMirrorServiceImpl implements ContainerMirrorService, JobHandler<M
void onJobException(JobSpec job, MirrorEntry entry, Throwable error) {
final result = entry.result.complete(null, error.message)
store.putEntry(entry.withResult(result))
persistence.saveMirrorResult(result)
persistence.saveMirrorResultAsync(result)
log.error("Mirror container errored - job=${job.operationName}; result=${result}", error)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface PersistenceService {
*
* @param build A {@link WaveBuildRecord} object
*/
void saveBuild(WaveBuildRecord build)
void saveBuildAsync(WaveBuildRecord build)

/**
* Retrieve a {@link WaveBuildRecord} object for the given build id
Expand Down Expand Up @@ -80,15 +80,15 @@ interface PersistenceService {
*
* @param data A {@link WaveContainerRecord} object representing a Wave request record
*/
void saveContainerRequest(WaveContainerRecord data)
void saveContainerRequestAsync(WaveContainerRecord data)

/**
* Update a container request with the digest of the resolved request
*
* @param token The request unique token
* @param digest The resolved digest
*/
void updateContainerRequest(String token, ContainerDigestPair digest)
void updateContainerRequestAsync(String token, ContainerDigestPair digest)

/**
* Retrieve a {@link WaveContainerRecord} object corresponding to the a specified request token
Expand All @@ -103,7 +103,7 @@ interface PersistenceService {
*
* @param data A {@link WaveScanRecord} object representing the a container scan request
*/
void saveScanRecord(WaveScanRecord scanRecord)
void saveScanRecordAsync(WaveScanRecord scanRecord)

/**
* Retrieve a {@link WaveScanRecord} object for the specified build ID
Expand Down Expand Up @@ -144,7 +144,7 @@ interface PersistenceService {
*
* @param mirror {@link MirrorEntry} object
*/
void saveMirrorResult(MirrorResult mirror)
void saveMirrorResultAsync(MirrorResult mirror)

/**
* Retrieve all {@link WaveScanRecord} object for the given partial scan id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class LocalPersistenceService implements PersistenceService {
private Map<String,MirrorResult> mirrorStore = new HashMap<>()

@Override
void saveBuild(WaveBuildRecord record) {
void saveBuildAsync(WaveBuildRecord record) {
buildStore[record.buildId] = record
}

Expand Down Expand Up @@ -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))
Expand All @@ -99,7 +99,7 @@ class LocalPersistenceService implements PersistenceService {
}

@Override
void saveScanRecord(WaveScanRecord scanRecord) {
void saveScanRecordAsync(WaveScanRecord scanRecord) {
scanStore.put(scanRecord.id, scanRecord)
}

Expand Down Expand Up @@ -129,7 +129,7 @@ class LocalPersistenceService implements PersistenceService {
}

@Override
void saveMirrorResult(MirrorResult mirror) {
void saveMirrorResultAsync(MirrorResult mirror) {
mirrorStore.put(mirror.mirrorId, mirror)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
Expand Down Expand Up @@ -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)}"
Expand All @@ -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',
Expand Down Expand Up @@ -253,7 +253,7 @@ class SurrealPersistenceService implements PersistenceService {
}

@Override
void saveScanRecord(WaveScanRecord scanRecord) {
void saveScanRecordAsync(WaveScanRecord scanRecord) {
final vulnerabilities = scanRecord.vulnerabilities ?: List.<ScanVulnerability>of()

// create a multi-command surreal sql statement to insert all vulnerabilities
Expand Down Expand Up @@ -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->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class ContainerScanServiceImpl implements ContainerScanService, JobHandler<ScanE
//save scan results in the redis cache
scanStore.storeScan(scan)
// save in the persistent layer
persistenceService.saveScanRecord(new WaveScanRecord(scan))
persistenceService.saveScanRecordAsync(new WaveScanRecord(scan))
// when the scan fails delete the scanId via cleanup service
// this is needed to prevent the caching of the scanId and
// allow re-scanning the container in case of a job failure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class BuildControllerTest extends Specification {
final event = new BuildEvent(build, result)
final entry = WaveBuildRecord.fromEvent(event)
and:
persistenceService.saveBuild(entry)
persistenceService.saveBuildAsync(entry)
when:
def req = HttpRequest.GET("/v1alpha1/builds/${build.buildId}")
def res = client.toBlocking().exchange(req, WaveBuildRecord)
Expand Down Expand Up @@ -135,7 +135,7 @@ class BuildControllerTest extends Specification {
requestIp: '127.0.0.1',
startTime: Instant.now().minus(1, ChronoUnit.DAYS) )
and:
persistenceService.saveBuild(build1)
persistenceService.saveBuildAsync(build1)
sleep(500)

when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ScanControllerTest extends Specification {
'SUCCEEDED',
results))
and:
persistenceService.saveScanRecord(scan)
persistenceService.saveScanRecordAsync(scan)

when:
def req = HttpRequest.GET("/v1alpha1/scans/${scan.id}")
Expand Down
22 changes: 11 additions & 11 deletions src/test/groovy/io/seqera/wave/controller/ViewControllerTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class ViewControllerTest extends Specification {
exitStatus: 0 )

when:
persistenceService.saveBuild(record1)
persistenceService.saveBuildAsync(record1)
and:
def request = HttpRequest.GET("/view/builds/${record1.buildId}")
def response = client.toBlocking().exchange(request, String)
Expand Down Expand Up @@ -180,7 +180,7 @@ class ViewControllerTest extends Specification {
exitStatus: 0 )

when:
persistenceService.saveBuild(record1)
persistenceService.saveBuildAsync(record1)
and:
def request = HttpRequest.GET("/view/builds/${record1.buildId}")
def response = client.toBlocking().exchange(request, String)
Expand Down Expand Up @@ -222,7 +222,7 @@ class ViewControllerTest extends Specification {
def container = new WaveContainerRecord(req, data, wave, addr, exp)

when:
persistenceService.saveContainerRequest(container)
persistenceService.saveContainerRequestAsync(container)
and:
def request = HttpRequest.GET("/view/containers/${token}")
def response = client.toBlocking().exchange(request, String)
Expand Down Expand Up @@ -398,7 +398,7 @@ class ViewControllerTest extends Specification {
)

when:
persistenceService.saveScanRecord(scan)
persistenceService.saveScanRecordAsync(scan)
and:
def request = HttpRequest.GET("/view/scans/${scan.id}")
def response = client.toBlocking().exchange(request, String)
Expand Down Expand Up @@ -432,7 +432,7 @@ class ViewControllerTest extends Specification {
)

when:
persistenceService.saveMirrorResult(record1)
persistenceService.saveMirrorResultAsync(record1)
and:
def request = HttpRequest.GET("/view/mirrors/${record1.mirrorId}")
def response = client.toBlocking().exchange(request, String)
Expand Down Expand Up @@ -491,9 +491,9 @@ class ViewControllerTest extends Specification {
exitStatus: 0 )

and:
persistenceService.saveBuild(record1)
persistenceService.saveBuild(record2)
persistenceService.saveBuild(record3)
persistenceService.saveBuildAsync(record1)
persistenceService.saveBuildAsync(record2)
persistenceService.saveBuildAsync(record3)

when:
def request = HttpRequest.GET("/view/builds/0727765dc72cee24")
Expand Down Expand Up @@ -544,7 +544,7 @@ class ViewControllerTest extends Specification {
exitStatus: 0 )

when:
persistenceService.saveBuild(record1)
persistenceService.saveBuildAsync(record1)
and:
def request = HttpRequest.GET("/view/builds/112233-1")
def response = client.toBlocking().exchange(request, String)
Expand Down Expand Up @@ -718,8 +718,8 @@ class ViewControllerTest extends Specification {
def scan2 = new WaveScanRecord('sc-1234567890abcde_2', '101', null, null, CONTAINER_IMAGE, PLATFORM, Instant.now(), Duration.ofSeconds(10), 'SUCCEEDED', [CVE1, CVE2, CVE3], null, null)

when:
persistenceService.saveScanRecord(scan1)
persistenceService.saveScanRecord(scan2)
persistenceService.saveScanRecordAsync(scan1)
persistenceService.saveScanRecordAsync(scan2)
and:
def request = HttpRequest.GET("/view/scans/1234567890abcde")
def response = client.toBlocking().exchange(request, String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ class ContainerBuildServiceTest extends Specification {
and:
1 * proxyService.getImageDigest(_, _) >> 'digest'
and:
1 * persistenceService.saveBuild(_) >> null
1 * persistenceService.saveBuildAsync(_) >> null
and:
1 * eventPublisher.publishEvent(_)
}
Expand Down Expand Up @@ -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(_)
}
Expand Down Expand Up @@ -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(_)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 38114d7

Please sign in to comment.