5
5
import com .wherobots .db .AppStatus ;
6
6
import com .wherobots .db .Region ;
7
7
import com .wherobots .db .Runtime ;
8
+ import com .wherobots .db .SessionType ;
8
9
import com .wherobots .db .jdbc .serde .JsonUtil ;
9
10
import io .github .resilience4j .core .IntervalFunction ;
10
11
import io .github .resilience4j .core .functions .CheckedSupplier ;
@@ -34,11 +35,14 @@ public abstract class WherobotsSessionSupplier {
34
35
35
36
private static final Logger logger = LoggerFactory .getLogger (WherobotsSessionSupplier .class );
36
37
37
- private static final String SQL_SESSION_ENDPOINT = "https://%s/sql/session?region=%s&reuse_session=%s " ;
38
+ private static final String SQL_SESSION_ENDPOINT = "https://%s/sql/session?region=%s" ;
38
39
private static final String PROTOCOL_VERSION = "1.0.0" ;
39
40
40
41
@ JsonInclude (JsonInclude .Include .NON_NULL )
41
- private record SqlSessionRequestPayload (String runtimeId , Integer shutdownAfterInactiveSeconds ) {}
42
+ private record SqlSessionRequestPayload (
43
+ String runtimeId ,
44
+ Integer shutdownAfterInactiveSeconds ,
45
+ String sessionType ) {}
42
46
private record SqlSessionAppMeta (String url ) {}
43
47
private record SqlSessionResponsePayload (AppStatus status , SqlSessionAppMeta appMeta ) {}
44
48
@@ -52,7 +56,7 @@ private record SqlSessionResponsePayload(AppStatus status, SqlSessionAppMeta app
52
56
* @return
53
57
* @throws SQLException
54
58
*/
55
- public static WherobotsSession create (String host , Runtime runtime , Region region , boolean reuse , Map <String , String > headers )
59
+ public static WherobotsSession create (String host , Runtime runtime , Region region , SessionType sessionType , Map <String , String > headers )
56
60
throws SQLException {
57
61
HttpClient client = HttpClient .newBuilder ()
58
62
.followRedirects (HttpClient .Redirect .NORMAL )
@@ -67,7 +71,7 @@ public static WherobotsSession create(String host, Runtime runtime, Region regio
67
71
Retry retry = RetryRegistry .of (config ).retry ("session" );
68
72
69
73
try {
70
- URI sessionIdUri = new SqlSessionSupplier (client , headers , host , runtime , region , reuse ).get ();
74
+ URI sessionIdUri = new SqlSessionSupplier (client , headers , host , runtime , region , sessionType ).get ();
71
75
URI wsUri = Retry .decorateCheckedSupplier (retry , new SessionWsUriSupplier (client , headers , sessionIdUri )).get ();
72
76
return create (wsUri , headers );
73
77
} catch (SQLException e ) {
@@ -103,20 +107,23 @@ private record SqlSessionSupplier(HttpClient client,
103
107
String host ,
104
108
Runtime runtime ,
105
109
Region region ,
106
- boolean reuse )
110
+ SessionType sessionType )
107
111
implements CheckedSupplier <URI > {
108
112
109
113
@ Override
110
114
public URI get () throws IOException , InterruptedException {
111
- logger .info ("{} {} runtime in {} from {}..." ,
112
- reuse ? "Recycling" : "Requesting" , runtime .name , region .name , host );
115
+ logger .info ("Requesting {} runtime using {} session type in {} from {}..." ,
116
+ runtime . name , sessionType .name , region .name , host );
113
117
114
118
HttpRequest .BodyPublisher body = HttpRequest .BodyPublishers .ofString (
115
- JsonUtil .serialize (new SqlSessionRequestPayload (runtime .name , null )));
119
+ JsonUtil .serialize (new SqlSessionRequestPayload (
120
+ runtime .name ,
121
+ null ,
122
+ sessionType .name )));
116
123
117
124
HttpRequest .Builder request = HttpRequest .newBuilder ()
118
125
.POST (body )
119
- .uri (URI .create (String .format (SQL_SESSION_ENDPOINT , host , region .name , reuse )))
126
+ .uri (URI .create (String .format (SQL_SESSION_ENDPOINT , host , region .name )))
120
127
.header ("Content-Type" , "application/json" );
121
128
headers .forEach (request ::header );
122
129
0 commit comments