2121import io .airlift .log .Logger ;
2222import io .trino .gateway .ha .clustermonitor .ClusterStats ;
2323import io .trino .gateway .ha .clustermonitor .TrinoStatus ;
24+ import io .trino .gateway .ha .config .ProxyBackendConfiguration ;
2425import io .trino .gateway .ha .config .RoutingConfiguration ;
2526
2627import java .util .ArrayList ;
@@ -51,6 +52,7 @@ static class LocalStats
5152 private int queuedQueryCount ;
5253 private TrinoStatus trinoStatus ;
5354 private String proxyTo ;
55+ private String externalUrl ;
5456 private String routingGroup ;
5557 private String clusterId ;
5658 private Map <String , Integer > userQueuedCount ;
@@ -62,6 +64,7 @@ static class LocalStats
6264 queuedQueryCount = stats .queuedQueryCount ();
6365 trinoStatus = stats .trinoStatus ();
6466 proxyTo = stats .proxyTo ();
67+ externalUrl = stats .externalUrl ();
6568 routingGroup = stats .routingGroup ();
6669 if (stats .userQueuedCount () != null ) {
6770 userQueuedCount = new HashMap <String , Integer >(stats .userQueuedCount ());
@@ -116,6 +119,16 @@ public void proxyTo(String proxyTo)
116119 this .proxyTo = proxyTo ;
117120 }
118121
122+ public String getExternalUrl ()
123+ {
124+ return this .externalUrl ;
125+ }
126+
127+ public void externalUrl (String externalUrl )
128+ {
129+ this .externalUrl = externalUrl ;
130+ }
131+
119132 public String routingGroup ()
120133 {
121134 return this .routingGroup ;
@@ -135,6 +148,16 @@ public void userQueuedCount(Map<String, Integer> userQueuedCount)
135148 {
136149 this .userQueuedCount = userQueuedCount ;
137150 }
151+
152+ ProxyBackendConfiguration backendConfiguration ()
153+ {
154+ ProxyBackendConfiguration backendConfiguration = new ProxyBackendConfiguration ();
155+ backendConfiguration .setExternalUrl (externalUrl );
156+ backendConfiguration .setProxyTo (proxyTo );
157+ backendConfiguration .setRoutingGroup (routingGroup );
158+ backendConfiguration .setActive (true );
159+ return backendConfiguration ;
160+ }
138161 }
139162
140163 @ Inject
@@ -233,6 +256,21 @@ public String provideDefaultCluster(String user)
233256 return getBackendForRoutingGroup (defaultRoutingGroup , user ).orElseThrow (() -> new RouterException ("did not find any cluster for the default routing group: " + defaultRoutingGroup ));
234257 }
235258
259+ public Optional <ProxyBackendConfiguration > getBackendConfigurationForRoutingGroup (String routingGroup , String user )
260+ {
261+ Optional <LocalStats > localStats = getClusterToRoute (user , routingGroup );
262+ localStats .ifPresent (stats -> updateLocalStats (stats , user ));
263+ return localStats .map (LocalStats ::backendConfiguration );
264+ }
265+
266+ @ Override
267+ public ProxyBackendConfiguration provideBackendConfiguration (String routingGroup , String user )
268+ {
269+ return getBackendConfigurationForRoutingGroup (routingGroup , user )
270+ .orElseGet (() -> getBackendConfigurationForRoutingGroup (defaultRoutingGroup , user )
271+ .orElseThrow (() -> new RouterException ("did not find any cluster for the default routing group: " + defaultRoutingGroup )));
272+ }
273+
236274 @ Override
237275 public String provideClusterForRoutingGroup (String routingGroup , String user )
238276 {
0 commit comments