-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 478-use-buildkit-for-container-image-builds
- Loading branch information
Showing
34 changed files
with
761 additions
and
317 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
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
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
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
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
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
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 |
---|---|---|
|
@@ -23,11 +23,14 @@ import groovy.transform.Canonical | |
import groovy.transform.CompileStatic | ||
import groovy.transform.Memoized | ||
import groovy.transform.ToString | ||
import groovy.util.logging.Slf4j | ||
|
||
/** | ||
* Model a blob cache metadata entry | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
@Slf4j | ||
@ToString(includePackage = false, includeNames = true) | ||
@Canonical | ||
@CompileStatic | ||
|
@@ -43,6 +46,21 @@ class BlobCacheInfo { | |
*/ | ||
final Map<String,String> headers | ||
|
||
/** | ||
* The blob length | ||
*/ | ||
final Long contentLength | ||
|
||
/** | ||
* The content type of this blob | ||
*/ | ||
final String contentType | ||
|
||
/** | ||
* The blob cache control directive | ||
*/ | ||
final String cacheControl | ||
|
||
/** | ||
* The instant when the cache request was created | ||
*/ | ||
|
@@ -73,29 +91,37 @@ class BlobCacheInfo { | |
locationUri && completionTime!=null | ||
} | ||
|
||
String getContentType() { | ||
headers?.find(it-> it.key.toLowerCase()=='content-type')?.value | ||
} | ||
|
||
String getCacheControl() { | ||
headers?.find(it-> it.key.toLowerCase()=='cache-control')?.value | ||
} | ||
|
||
static BlobCacheInfo create(String locationUrl, Map<String,List<String>> headers) { | ||
static BlobCacheInfo create(String locationUrl, Map<String,List<String>> request, Map<String,List<String>> response) { | ||
final headers0 = new LinkedHashMap<String,String>() | ||
for( Map.Entry<String,List<String>> it : headers ) | ||
for( Map.Entry<String,List<String>> it : request ) | ||
headers0.put( it.key, it.value.join(',') ) | ||
new BlobCacheInfo(locationUrl, headers0, Instant.now()) | ||
final length = headerLong0(response, 'Content-Length') | ||
final type = headerString0(response, 'Content-Type') | ||
final cache = headerString0(response, 'Cache-Control') | ||
new BlobCacheInfo(locationUrl, headers0, length, type, cache, Instant.now(), null, null, null) | ||
} | ||
|
||
static String headerString0(Map<String,List<String>> headers, String name) { | ||
headers?.find(it-> it.key.toLowerCase()==name.toLowerCase())?.value?.first() | ||
} | ||
|
||
static BlobCacheInfo create1(String locationUrl, Map<String,String> headers) { | ||
new BlobCacheInfo(locationUrl, headers, Instant.now()) | ||
static Long headerLong0(Map<String,List<String>> headers, String name) { | ||
try { | ||
return headerString0(headers,name) as Long | ||
} | ||
catch (NumberFormatException e) { | ||
log.warn "Unexpected content length value - cause: $e" | ||
return null | ||
} | ||
} | ||
|
||
BlobCacheInfo cached() { | ||
new BlobCacheInfo( | ||
locationUri, | ||
headers, | ||
contentLength, | ||
contentType, | ||
cacheControl, | ||
creationTime, | ||
creationTime, | ||
0) | ||
|
@@ -105,6 +131,9 @@ class BlobCacheInfo { | |
new BlobCacheInfo( | ||
locationUri, | ||
headers, | ||
contentLength, | ||
contentType, | ||
cacheControl, | ||
creationTime, | ||
Instant.now(), | ||
status, | ||
|
@@ -115,25 +144,33 @@ class BlobCacheInfo { | |
new BlobCacheInfo( | ||
locationUri, | ||
headers, | ||
contentLength, | ||
contentType, | ||
cacheControl, | ||
creationTime, | ||
Instant.now(), | ||
null, | ||
logs) | ||
logs | ||
) | ||
} | ||
|
||
BlobCacheInfo withLocation(String uri) { | ||
new BlobCacheInfo( | ||
uri, | ||
headers, | ||
contentLength, | ||
contentType, | ||
cacheControl, | ||
creationTime, | ||
completionTime, | ||
exitStatus, | ||
logs) | ||
logs | ||
) | ||
} | ||
|
||
@Memoized | ||
static BlobCacheInfo unknown() { | ||
new BlobCacheInfo(null, null, Instant.ofEpochMilli(0), Instant.ofEpochMilli(0), null) { | ||
new BlobCacheInfo(null, null, null, null, null, Instant.ofEpochMilli(0), Instant.ofEpochMilli(0), null) { | ||
@Override | ||
BlobCacheInfo withLocation(String uri) { | ||
// prevent the change of location for unknown status | ||
|
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
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
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 |
---|---|---|
|
@@ -20,12 +20,17 @@ package io.seqera.wave.service.builder | |
|
||
import java.util.concurrent.CompletableFuture | ||
|
||
import groovy.transform.CompileStatic | ||
import io.micronaut.runtime.event.annotation.EventListener | ||
import io.seqera.wave.core.RoutePath | ||
import io.seqera.wave.service.persistence.WaveBuildRecord | ||
|
||
/** | ||
* Declare container build service interface | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
@CompileStatic | ||
interface ContainerBuildService { | ||
|
||
/** | ||
|
@@ -65,4 +70,66 @@ interface ContainerBuildService { | |
: null | ||
} | ||
|
||
|
||
// ************************************************************** | ||
// ** build record operations | ||
// ************************************************************** | ||
|
||
@EventListener | ||
default void onBuildEvent(BuildEvent event) { | ||
saveBuildRecord(event) | ||
} | ||
|
||
/** | ||
* Store a build record for the given {@link BuildRequest} object. | ||
* | ||
* This method is expected to store the build record associated with the request | ||
* *only* in the short term store caching system, ie. without hitting the | ||
* long-term SurrealDB storage | ||
* | ||
* @param request The build request that needs to be storage | ||
*/ | ||
default void createBuildRecord(BuildRequest request) { | ||
final record0 = WaveBuildRecord.fromEvent(new BuildEvent(request)) | ||
createBuildRecord(record0.buildId, record0) | ||
} | ||
|
||
/** | ||
* Store the build record associated with the specified event both in the | ||
* short-term cache (redis) and long-term persistence layer (surrealdb) | ||
* | ||
* @param event The {@link BuildEvent} object for which the build record needs to be stored | ||
*/ | ||
default void saveBuildRecord(BuildEvent event) { | ||
final record0 = WaveBuildRecord.fromEvent(event) | ||
saveBuildRecord(record0.buildId, record0) | ||
} | ||
|
||
/** | ||
* Store a build record object. | ||
* | ||
* This method is expected to store the build record *only* in the short term store cache (redis), | ||
* ie. without hitting the long-term storage (surrealdb) | ||
* | ||
* @param buildId The Id of the build record | ||
* @param value The {@link WaveBuildRecord} to be stored | ||
*/ | ||
void createBuildRecord(String buildId, WaveBuildRecord value) | ||
|
||
/** | ||
* Store the specified build record both in the short-term cache (redis) | ||
* and long-term persistence layer (surrealdb) | ||
* | ||
* @param buildId The Id of the build record | ||
* @param value The {@link WaveBuildRecord} to be stored | ||
*/ | ||
void saveBuildRecord(String buildId, WaveBuildRecord value) | ||
|
||
/** | ||
* Retrieve the build record for the specified id. | ||
* | ||
* @param buildId The ID of the build record to be retrieve | ||
* @return The {@link WaveBuildRecord} associated with the corresponding Id, or {@code null} if it cannot be found | ||
*/ | ||
WaveBuildRecord getBuildRecord(String buildId) | ||
} |
Oops, something went wrong.