Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix entity too large #658

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import groovy.transform.CompileStatic
import groovy.transform.ToString
import groovy.util.logging.Slf4j
import io.seqera.wave.api.ContainerConfig
import io.seqera.wave.api.FusionVersion
import io.seqera.wave.api.SubmitContainerTokenRequest
import io.seqera.wave.service.ContainerRequestData
import io.seqera.wave.tower.User
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,19 @@ class SurrealPersistenceService implements PersistenceService {

@Override
void saveBuild(WaveBuildRecord build) {
surrealDb.insertBuildAsync(getAuthorization(), build).subscribe({ result->
log.trace "Build request with id '$build.buildId' saved record: ${result}"
}, {error->
def msg = error.message
if( error instanceof HttpClientResponseException ){
msg += ":\n $error.response.body"
}
log.error("Error saving Build request record ${msg}\n${build}", error)
})
final query = "INSERT INTO wave_build ${JacksonHelper.toJson(build)}"
surrealDb
.sqlAsync(getAuthorization(), query)
.subscribe({result ->
log.trace "Conda file added in wave_build with buildId '$build.buildId': ${result}"
},
{error->
def msg = error.message
if( error instanceof HttpClientResponseException ){
msg += ":\n $error.response.body"
}
log.error("Error saving conda file in wave_build with buildId '$build.buildId => ${msg}\n", error)
})
}

@Override
Expand Down Expand Up @@ -168,15 +172,20 @@ class SurrealPersistenceService implements PersistenceService {

@Override
void saveContainerRequest(String token, WaveContainerRecord data) {
surrealDb.insertContainerRequestAsync(authorization, token, data).subscribe({ result->
log.trace "Container request with token '$token' saved record: ${result}"
}, {error->
def msg = error.message
if( error instanceof HttpClientResponseException ){
msg += ":\n $error.response.body"
}
log.error("Error saving container request record ${msg}\n${data}", error)
})
final query = "INSERT INTO wave_request ${JacksonHelper.toJsonAndAppend(data, Map.of('id',token))}"
pditommaso marked this conversation as resolved.
Show resolved Hide resolved
log.info("query = $query")
surrealDb
.sqlAsync(getAuthorization(), query)
.subscribe({result ->
log.trace "Container request with token '$token' saved record: ${result}"
},
{error->
def msg = error.message
if( error instanceof HttpClientResponseException ){
msg += ":\n $error.response.body"
}
log.error("Error saving container request record ${msg}\n${data}", error)
})
}

void updateContainerRequest(String token, ContainerDigestPair digest) {
Expand Down
16 changes: 16 additions & 0 deletions src/main/groovy/io/seqera/wave/util/JacksonHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,20 @@ class JacksonHelper {
config != null ? YAML_MAPPER.writeValueAsString(config) : null
}

/**
* Converts a concrete instance of of {@code T} to a json
* representation and appends it to the specified {@code Map}
*
* @param config A concrete instance of of {@code T}
* @param map A map to append the json representation
* @return A json representation of the specified object
*/
static String toJsonAndAppend(Object config, Map map) {
if ( !config )
return null
Map configMap = DEFAULT_JSON_MAPPER.convertValue(config, Map)
configMap.putAll(map)
DEFAULT_JSON_MAPPER.writeValueAsString(configMap)
}

}
39 changes: 39 additions & 0 deletions src/test/groovy/io/seqera/wave/util/JacksonHelperTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Wave, containers provisioning service
* Copyright (c) 2024, Seqera Labs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package io.seqera.wave.util

import spock.lang.Specification
/**
*
* @author Munish Chouhan <[email protected]>
*/
class JacksonHelperTest extends Specification {

def "toJsonAndAppend should append map to config and return JSON string"() {
given:
def config = [name: "test"]
Map map = [id: "token"]

when:
def result = JacksonHelper.toJsonAndAppend(config, map)

then:
result == '{"name":"test","id":"token"}'
}
}