18
18
import lombok .RequiredArgsConstructor ;
19
19
20
20
/** Connectivity convenience methods for AI Core with deployment. */
21
- @ RequiredArgsConstructor (access = AccessLevel .PUBLIC )
21
+ @ RequiredArgsConstructor (access = AccessLevel .PROTECTED )
22
22
public class AiCoreDeployment implements AiCoreDestination {
23
23
24
24
private static Map <String , AiDeploymentList > CACHE = new LinkedHashMap <>();
@@ -36,6 +36,18 @@ public class AiCoreDeployment implements AiCoreDestination {
36
36
@ Nonnull
37
37
private final String resourceGroup ;
38
38
39
+ /**
40
+ * Default constructor with "default" resource group.
41
+ *
42
+ * @param service The AI Core service.
43
+ * @param deploymentId The deployment id handler.
44
+ */
45
+ public AiCoreDeployment (
46
+ @ Nonnull final AiCoreService service ,
47
+ @ Nonnull final Function <AiCoreDeployment , String > deploymentId ) {
48
+ this (service , deploymentId , "default" );
49
+ }
50
+
39
51
/**
40
52
* Create a new instance of the AI Core service with a deployment.
41
53
*
@@ -47,7 +59,7 @@ public class AiCoreDeployment implements AiCoreDestination {
47
59
public static AiCoreDeployment forModelName (
48
60
@ Nonnull final AiCoreService service , @ Nonnull final String modelName ) {
49
61
final Predicate <AiDeployment > p = deployment -> isDeploymentOfModel (modelName , deployment );
50
- return new AiCoreDeployment (service , obj -> obj .getDeploymentId (p ), "default" );
62
+ return new AiCoreDeployment (service , obj -> obj .getDeploymentId (service . client ( ), p ) );
51
63
}
52
64
53
65
/**
@@ -61,7 +73,7 @@ public static AiCoreDeployment forModelName(
61
73
public static AiCoreDeployment forScenarioId (
62
74
@ Nonnull final AiCoreService service , @ Nonnull final String scenarioId ) {
63
75
final Predicate <AiDeployment > p = deployment -> scenarioId .equals (deployment .getScenarioId ());
64
- return new AiCoreDeployment (service , obj -> obj .getDeploymentId (p ), "default" );
76
+ return new AiCoreDeployment (service , obj -> obj .getDeploymentId (service . client ( ), p ) );
65
77
}
66
78
67
79
/**
@@ -74,7 +86,7 @@ public static AiCoreDeployment forScenarioId(
74
86
@ Nonnull
75
87
public static AiCoreDeployment forDeploymentId (
76
88
@ Nonnull final AiCoreService service , @ Nonnull final String deploymentId ) {
77
- return new AiCoreDeployment (service , obj -> deploymentId , "default" );
89
+ return new AiCoreDeployment (service , obj -> deploymentId );
78
90
}
79
91
80
92
@ Nonnull
@@ -196,12 +208,13 @@ protected static boolean isDeploymentOfModel(
196
208
* @throws NoSuchElementException if no deployment is found for the scenario id.
197
209
*/
198
210
@ Nonnull
199
- protected String getDeploymentId (@ Nonnull final Predicate <AiDeployment > predicate )
211
+ protected String getDeploymentId (
212
+ @ Nonnull final ApiClient client , @ Nonnull final Predicate <AiDeployment > predicate )
200
213
throws NoSuchElementException {
201
214
202
215
final var resourceGroup = getResourceGroup ();
203
216
final var deployments =
204
- CACHE .computeIfAbsent (resourceGroup , rg -> new DeploymentApi (client () ).query (rg ));
217
+ CACHE .computeIfAbsent (resourceGroup , rg -> new DeploymentApi (client ).query (rg ));
205
218
206
219
final var first =
207
220
deployments .getResources ().stream ().filter (predicate ).map (AiDeployment ::getId ).findFirst ();
0 commit comments