-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix serialization of S3 paths with spaces (#3565)
Signed-off-by: Ben Sherman <[email protected]> Signed-off-by: Paolo Di Tommaso <[email protected]> Co-authored-by: Paolo Di Tommaso <[email protected]>
- Loading branch information
1 parent
b24ee13
commit 935df94
Showing
4 changed files
with
99 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,22 +17,47 @@ | |
|
||
package nextflow.cloud.aws.util | ||
|
||
|
||
import com.esotericsoftware.kryo.Kryo | ||
import com.esotericsoftware.kryo.Serializer | ||
import com.esotericsoftware.kryo.io.Input | ||
import com.esotericsoftware.kryo.io.Output | ||
import com.upplication.s3fs.S3Path | ||
import groovy.transform.CompileStatic | ||
import nextflow.util.PathSerializer | ||
import groovy.util.logging.Slf4j | ||
import nextflow.util.SerializerRegistrant | ||
import org.pf4j.Extension | ||
|
||
/** | ||
* Register the S3Path serializer | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
@Slf4j | ||
@Extension | ||
@CompileStatic | ||
class S3PathSerializer implements SerializerRegistrant { | ||
class S3PathSerializer extends Serializer<S3Path> implements SerializerRegistrant { | ||
|
||
@Override | ||
void register(Map<Class, Object> serializers) { | ||
serializers.put(S3Path, PathSerializer) | ||
serializers.put(S3Path, S3PathSerializer) | ||
} | ||
|
||
@Override | ||
void write(Kryo kryo, Output output, S3Path target) { | ||
final scheme = target.getFileSystem().provider().getScheme() | ||
final path = target.toString() | ||
log.trace "S3Path serialization > scheme: $scheme; path: $path" | ||
output.writeString(scheme) | ||
output.writeString(path) | ||
} | ||
|
||
@Override | ||
S3Path read(Kryo kryo, Input input, Class<S3Path> type) { | ||
final scheme = input.readString() | ||
final path = input.readString() | ||
if( scheme != 's3' ) throw new IllegalStateException("Unexpected scheme for S3 path -- offending value '$scheme'") | ||
log.trace "S3Path de-serialization > scheme: $scheme; path: $path" | ||
return (S3Path) S3PathFactory.create("s3://${path}") | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
plugins/nf-amazon/src/test/nextflow/util/S3PathSerializerTest.groovy
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2020-2022, Seqera Labs | ||
* Copyright 2013-2019, Centre for Genomic Regulation (CRG) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package nextflow.util | ||
|
||
import nextflow.cloud.aws.util.S3PathFactory | ||
import spock.lang.Specification | ||
/** | ||
* | ||
* @author Ben Sherman <[email protected]> | ||
*/ | ||
class S3PathSerializerTest extends Specification { | ||
|
||
def 'should serialise s3 path' () { | ||
when: | ||
def path = S3PathFactory.parse('s3://mybucket/file.txt') | ||
def buffer = KryoHelper.serialize(path) | ||
then: | ||
KryoHelper.deserialize(buffer).getClass().getName() == 'com.upplication.s3fs.S3Path' | ||
KryoHelper.deserialize(buffer) == S3PathFactory.parse('s3://mybucket/file.txt') | ||
} | ||
|
||
def 'should serialise s3 path with spaces' () { | ||
when: | ||
def path = S3PathFactory.parse('s3://mybucket/file with spaces.txt') | ||
def buffer = KryoHelper.serialize(path) | ||
then: | ||
KryoHelper.deserialize(buffer).getClass().getName() == 'com.upplication.s3fs.S3Path' | ||
KryoHelper.deserialize(buffer) == S3PathFactory.parse('s3://mybucket/file with spaces.txt') | ||
} | ||
|
||
} |