19
19
20
20
import io .seqera .tower .ApiException ;
21
21
import io .seqera .tower .cli .commands .global .WorkspaceOptionalOptions ;
22
+ import io .seqera .tower .cli .exceptions .InvalidDataStudioParentCheckpointException ;
22
23
import io .seqera .tower .cli .exceptions .TowerException ;
23
24
import io .seqera .tower .cli .responses .Response ;
24
25
import io .seqera .tower .cli .responses .datastudios .DataStudiosCreated ;
@@ -43,6 +44,9 @@ public class StartAsNewCmd extends AbstractStudiosCmd{
43
44
@ CommandLine .Mixin
44
45
public ParentDataStudioRefOptions parentDataStudioRefOptions ;
45
46
47
+ @ CommandLine .Option (names = {"--parent-checkpoint-id" }, description = "Parent Data Studio checkpoint id, to be used as staring point for the new Data Studio. If not provided, if will defaults to latest existing checkpoint of parent Data Studio." )
48
+ public String parentCheckpointId ;
49
+
46
50
@ CommandLine .Option (names = {"-n" , "--name" }, description = "Data Studio name." , required = true )
47
51
public String name ;
48
52
@@ -72,9 +76,7 @@ protected Response exec() throws ApiException {
72
76
throw new TowerException (String .format ("Parent DataStudio %s not found at %s workspace" , parentStudioSessionId , wspId ));
73
77
}
74
78
75
- DataStudioListCheckpointsResponse checkpoints = api ().listDataStudioCheckpoints (parentDataStudio .getSessionId (), parentDataStudio .getWorkspaceId (), null , 1 , null );
76
-
77
- DataStudioCreateRequest request = prepareRequest (parentDataStudio , checkpoints .getCheckpoints ());
79
+ DataStudioCreateRequest request = prepareRequest (parentDataStudio , parentCheckpointId , wspId );
78
80
DataStudioCreateResponse response = api ().createDataStudio (request , wspId , autoStart );
79
81
DataStudioDto dataStudioDto = response .getStudio ();
80
82
assert dataStudioDto != null ;
@@ -87,17 +89,30 @@ protected Response exec() throws ApiException {
87
89
}
88
90
}
89
91
90
- DataStudioCreateRequest prepareRequest (DataStudioDto parentDataStudio , List < DataStudioCheckpointDto > checkpoints ) throws ApiException {
92
+ DataStudioCreateRequest prepareRequest (DataStudioDto parentDataStudio , String parentCheckpointId , Long wspId ) throws ApiException {
91
93
DataStudioCreateRequest request = new DataStudioCreateRequest ();
92
94
request .setName (name );
93
95
if (description == null || description .isEmpty ()) {
94
96
request .description (String .format ("Started from studio %s" , parentDataStudio .getName ()));
95
97
} else {
96
98
request .description (description );
97
99
}
98
- if (checkpoints != null && !checkpoints .isEmpty ()) {
99
- request .setInitialCheckpointId (checkpoints .get (0 ).getId ());
100
+
101
+ if (parentCheckpointId == null ) {
102
+ DataStudioListCheckpointsResponse response = api ().listDataStudioCheckpoints (parentDataStudio .getSessionId (), parentDataStudio .getWorkspaceId (), null , 1 , null );
103
+ if (!response .getCheckpoints ().isEmpty ()) {
104
+ request .setInitialCheckpointId (response .getCheckpoints ().get (0 ).getId ());
105
+ }
106
+ } else {
107
+ try {
108
+ Long checkpoint = Long .valueOf (parentCheckpointId );
109
+ DataStudioCheckpointDto response = api ().getDataStudioCheckpoint (parentDataStudio .getSessionId (), checkpoint , wspId );
110
+ request .setInitialCheckpointId (response .getId ());
111
+ } catch (NumberFormatException | ApiException e ) {
112
+ throw new InvalidDataStudioParentCheckpointException (parentCheckpointId );
113
+ }
100
114
}
115
+
101
116
request .setDataStudioToolUrl (Objects .requireNonNull (parentDataStudio .getTemplate ()).getRepository ());
102
117
request .setComputeEnvId (Objects .requireNonNull (parentDataStudio .getComputeEnv ()).getId ());
103
118
0 commit comments