tower-cli icon indicating copy to clipboard operation
tower-cli copied to clipboard

Cannot import compute environment from file when Labels are included

Open k1sauce opened this issue 1 year ago • 2 comments

As the title says when I am trying to make a compute environment via

tw compute-envs import -n test1 test-no-label.json

everything is ok New AWS-BATCH compute environment 'test1' added at [ClearNote_Health / discovery-pipeline-prod] workspace however when I am trying to use a pre-existing resource label

tw compute-envs import -n test1 test.json

I get the following error

java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to io.seqera.tower.model.LabelDbDto
	at [email protected]/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at [email protected]/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
	at [email protected]/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at [email protected]/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at [email protected]/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at [email protected]/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at [email protected]/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at io.seqera.tower.cli.commands.computeenvs.ImportCmd.exec(ImportCmd.java:68)
	at io.seqera.tower.cli.commands.AbstractApiCmd.call(AbstractApiCmd.java:413)
	at io.seqera.tower.cli.commands.AbstractApiCmd.call(AbstractApiCmd.java:65)
	at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
	at picocli.CommandLine.access$1300(CommandLine.java:145)
	at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
	at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
	at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
	at picocli.CommandLine.execute(CommandLine.java:2078)
	at io.seqera.tower.cli.Tower.main(Tower.java:99)

The only difference between the two input json files is the addition of the label field

"labels" : [{
    "id" : 226590710615802,
    "name" : "pipeline",
    "value" : "overlord",
    "resource" : true
  }] 

Seqera Platform version: 23.4.3_46971e7 Tower CLI version: 0.9.2 (build 39a2ec6)

I suspect the error is related to how the stream / map is implemented here https://github.com/seqeralabs/tower-cli/blob/2d10b5b9ab61195b685ff2f809240d88864375be/src/main/java/io/seqera/tower/cli/commands/computeenvs/ImportCmd.java#L67

k1sauce avatar Mar 26 '24 23:03 k1sauce

Seems to be a result of the way Jackson deserializes things in the object mapper. Just need to supply the type info. The relevant bit of code is here: https://github.com/seqeralabs/tower-cli/blob/2d10b5b9ab61195b685ff2f809240d88864375be/src/main/java/io/seqera/tower/cli/shared/ComputeEnvExportFormat.java#L135C58-L135C82

Need to return return mapper.readValue(node.toString(), new TypeReference<List<LabelDbDto>>() {});

And in L132 List<LabelDbDto> labelDbDtos = extractJsonNodeValue(root, "labels", mapper);

If I have time I will open a PR

k1sauce avatar Mar 27 '24 01:03 k1sauce

Just to confirm, I am observing the same error when trying to use a json from a pre-existing CE with pre-existing labels.

FloWuenne avatar May 10 '24 13:05 FloWuenne