1818import lombok .RequiredArgsConstructor ;
1919
2020/** Connectivity convenience methods for AI Core with deployment. */
21- @ RequiredArgsConstructor (access = AccessLevel .PUBLIC )
21+ @ RequiredArgsConstructor (access = AccessLevel .PROTECTED )
2222public class AiCoreDeployment implements AiCoreDestination {
2323
2424 private static Map <String , AiDeploymentList > CACHE = new LinkedHashMap <>();
@@ -36,6 +36,18 @@ public class AiCoreDeployment implements AiCoreDestination {
3636 @ Nonnull
3737 private final String resourceGroup ;
3838
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+
3951 /**
4052 * Create a new instance of the AI Core service with a deployment.
4153 *
@@ -47,7 +59,7 @@ public class AiCoreDeployment implements AiCoreDestination {
4759 public static AiCoreDeployment forModelName (
4860 @ Nonnull final AiCoreService service , @ Nonnull final String modelName ) {
4961 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 ) );
5163 }
5264
5365 /**
@@ -61,7 +73,7 @@ public static AiCoreDeployment forModelName(
6173 public static AiCoreDeployment forScenarioId (
6274 @ Nonnull final AiCoreService service , @ Nonnull final String scenarioId ) {
6375 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 ) );
6577 }
6678
6779 /**
@@ -74,7 +86,7 @@ public static AiCoreDeployment forScenarioId(
7486 @ Nonnull
7587 public static AiCoreDeployment forDeploymentId (
7688 @ Nonnull final AiCoreService service , @ Nonnull final String deploymentId ) {
77- return new AiCoreDeployment (service , obj -> deploymentId , "default" );
89+ return new AiCoreDeployment (service , obj -> deploymentId );
7890 }
7991
8092 @ Nonnull
@@ -196,12 +208,13 @@ protected static boolean isDeploymentOfModel(
196208 * @throws NoSuchElementException if no deployment is found for the scenario id.
197209 */
198210 @ Nonnull
199- protected String getDeploymentId (@ Nonnull final Predicate <AiDeployment > predicate )
211+ protected String getDeploymentId (
212+ @ Nonnull final ApiClient client , @ Nonnull final Predicate <AiDeployment > predicate )
200213 throws NoSuchElementException {
201214
202215 final var resourceGroup = getResourceGroup ();
203216 final var deployments =
204- CACHE .computeIfAbsent (resourceGroup , rg -> new DeploymentApi (client () ).query (rg ));
217+ CACHE .computeIfAbsent (resourceGroup , rg -> new DeploymentApi (client ).query (rg ));
205218
206219 final var first =
207220 deployments .getResources ().stream ().filter (predicate ).map (AiDeployment ::getId ).findFirst ();
0 commit comments