From 7f4725bea742695529749adb5f667bed530e9f39 Mon Sep 17 00:00:00 2001 From: Joel Thibault Date: Tue, 29 Oct 2024 17:26:07 -0400 Subject: [PATCH] migrate getRuntime --- .../workbench/api/RuntimeController.java | 12 +++++------ .../workbench/leonardo/LeonardoApiClient.java | 4 ++-- .../leonardo/LeonardoApiClientImpl.java | 20 +++++++++++++------ .../workbench/leonardo/LeonardoConfig.java | 15 ++++++++++++-- .../utils/mappers/LeonardoMapper.java | 11 +++++----- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/api/src/main/java/org/pmiops/workbench/api/RuntimeController.java b/api/src/main/java/org/pmiops/workbench/api/RuntimeController.java index 89bf97a893c..c10b025cf64 100644 --- a/api/src/main/java/org/pmiops/workbench/api/RuntimeController.java +++ b/api/src/main/java/org/pmiops/workbench/api/RuntimeController.java @@ -17,16 +17,16 @@ import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.broadinstitute.dsde.workbench.client.leonardo.model.ClusterError; +import org.broadinstitute.dsde.workbench.client.leonardo.model.ClusterStatus; +import org.broadinstitute.dsde.workbench.client.leonardo.model.GetRuntimeResponse; import org.pmiops.workbench.config.WorkbenchConfig; import org.pmiops.workbench.db.model.DbUser; import org.pmiops.workbench.db.model.DbWorkspace; import org.pmiops.workbench.exceptions.BadRequestException; import org.pmiops.workbench.exceptions.NotFoundException; import org.pmiops.workbench.interactiveanalysis.InteractiveAnalysisService; -import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoClusterError; -import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoGetRuntimeResponse; import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoListRuntimeResponse; -import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoRuntimeStatus; import org.pmiops.workbench.leonardo.LeonardoApiClient; import org.pmiops.workbench.leonardo.LeonardoApiHelper; import org.pmiops.workbench.leonardo.PersistentDiskUtils; @@ -92,9 +92,9 @@ public ResponseEntity getRuntime(String workspaceNamespace) { DbWorkspace dbWorkspace = workspaceService.lookupWorkspaceByNamespace(workspaceNamespace); String googleProject = dbWorkspace.getGoogleProject(); try { - LeonardoGetRuntimeResponse leoRuntimeResponse = + GetRuntimeResponse leoRuntimeResponse = leonardoNotebooksClient.getRuntime(googleProject, user.getRuntimeName()); - if (LeonardoRuntimeStatus.ERROR.equals(leoRuntimeResponse.getStatus())) { + if (ClusterStatus.ERROR.equals(leoRuntimeResponse.getStatus())) { log.warning( String.format( "Observed Leonardo runtime with unexpected error status:\n%s", @@ -106,7 +106,7 @@ public ResponseEntity getRuntime(String workspaceNamespace) { } } - private String formatRuntimeErrors(@Nullable List errors) { + private String formatRuntimeErrors(@Nullable List errors) { if (errors == null || errors.isEmpty()) { return "no error messages"; } diff --git a/api/src/main/java/org/pmiops/workbench/leonardo/LeonardoApiClient.java b/api/src/main/java/org/pmiops/workbench/leonardo/LeonardoApiClient.java index a7996dc22fc..fa694d8b0e4 100644 --- a/api/src/main/java/org/pmiops/workbench/leonardo/LeonardoApiClient.java +++ b/api/src/main/java/org/pmiops/workbench/leonardo/LeonardoApiClient.java @@ -2,6 +2,7 @@ import java.util.List; import java.util.Map; +import org.broadinstitute.dsde.workbench.client.leonardo.model.GetRuntimeResponse; import org.broadinstitute.dsde.workbench.client.leonardo.model.ListPersistentDiskResponse; import org.pmiops.workbench.db.model.DbWorkspace; import org.pmiops.workbench.exceptions.WorkbenchException; @@ -59,8 +60,7 @@ LeonardoGetRuntimeResponse getRuntimeAsService(String googleProject, String runt int stopAllUserRuntimesAsService(String userEmail) throws WorkbenchException; /** Gets information about a notebook runtime */ - LeonardoGetRuntimeResponse getRuntime(String googleProject, String runtimeName) - throws WorkbenchException; + GetRuntimeResponse getRuntime(String googleProject, String runtimeName) throws WorkbenchException; /** Send files over to notebook runtime */ void localizeForRuntime(String googleProject, String runtimeName, Map fileList) diff --git a/api/src/main/java/org/pmiops/workbench/leonardo/LeonardoApiClientImpl.java b/api/src/main/java/org/pmiops/workbench/leonardo/LeonardoApiClientImpl.java index 6ea53ae9dbc..01f493f47dc 100644 --- a/api/src/main/java/org/pmiops/workbench/leonardo/LeonardoApiClientImpl.java +++ b/api/src/main/java/org/pmiops/workbench/leonardo/LeonardoApiClientImpl.java @@ -32,6 +32,7 @@ import org.broadinstitute.dsde.workbench.client.leonardo.api.AppsApi; import org.broadinstitute.dsde.workbench.client.leonardo.api.DisksApi; import org.broadinstitute.dsde.workbench.client.leonardo.model.AppStatus; +import org.broadinstitute.dsde.workbench.client.leonardo.model.GetRuntimeResponse; import org.broadinstitute.dsde.workbench.client.leonardo.model.ListAppResponse; import org.broadinstitute.dsde.workbench.client.leonardo.model.ListPersistentDiskResponse; import org.broadinstitute.dsde.workbench.client.leonardo.model.UpdateDiskRequest; @@ -98,6 +99,8 @@ public class LeonardoApiClientImpl implements LeonardoApiClient { private final LeonardoApiClientFactory leonardoApiClientFactory; private final Provider runtimesApiProvider; + private final Provider + newRuntimesApiProvider; private final Provider serviceRuntimesApiProvider; private final Provider resourcesApiProvider; @@ -119,7 +122,10 @@ public class LeonardoApiClientImpl implements LeonardoApiClient { @Autowired public LeonardoApiClientImpl( LeonardoApiClientFactory leonardoApiClientFactory, - @Qualifier(LeonardoConfig.USER_RUNTIMES_API) Provider runtimesApiProvider, + @Qualifier(LeonardoConfig.LEGACY_USER_RUNTIMES_API) Provider runtimesApiProvider, + @Qualifier(LeonardoConfig.USER_RUNTIMES_API) + Provider + newRuntimesApiProvider, @Qualifier(LeonardoConfig.SERVICE_RUNTIMES_API) Provider serviceRuntimesApiProvider, @Qualifier(LeonardoConfig.SERVICE_RESOURCE_API) Provider resourcesApiProvider, @@ -139,6 +145,7 @@ public LeonardoApiClientImpl( WorkspaceDao workspaceDao) { this.leonardoApiClientFactory = leonardoApiClientFactory; this.runtimesApiProvider = runtimesApiProvider; + this.newRuntimesApiProvider = newRuntimesApiProvider; this.serviceRuntimesApiProvider = serviceRuntimesApiProvider; this.resourcesApiProvider = resourcesApiProvider; this.proxyApiProvider = proxyApiProvider; @@ -349,13 +356,14 @@ public void deleteRuntime(String googleProject, String runtimeName, Boolean dele } @Override - public LeonardoGetRuntimeResponse getRuntime(String googleProject, String runtimeName) { - RuntimesApi runtimesApi = runtimesApiProvider.get(); + public GetRuntimeResponse getRuntime(String googleProject, String runtimeName) { + org.broadinstitute.dsde.workbench.client.leonardo.api.RuntimesApi runtimesApi = + newRuntimesApiProvider.get(); try { - return legacyLeonardoRetryHandler.runAndThrowChecked( + return leonardoRetryHandler.runAndThrowChecked( (context) -> runtimesApi.getRuntime(googleProject, runtimeName)); - } catch (org.pmiops.workbench.legacy_leonardo_client.ApiException e) { - throw ExceptionUtils.convertLegacyLeonardoException(e); + } catch (ApiException e) { + throw ExceptionUtils.convertLeonardoException(e); } } diff --git a/api/src/main/java/org/pmiops/workbench/leonardo/LeonardoConfig.java b/api/src/main/java/org/pmiops/workbench/leonardo/LeonardoConfig.java index cf065b3b090..cc1de9ae3d5 100644 --- a/api/src/main/java/org/pmiops/workbench/leonardo/LeonardoConfig.java +++ b/api/src/main/java/org/pmiops/workbench/leonardo/LeonardoConfig.java @@ -24,6 +24,7 @@ @org.springframework.context.annotation.Configuration public class LeonardoConfig { + public static final String LEGACY_USER_RUNTIMES_API = "legacyUserRuntimesApi"; public static final String USER_RUNTIMES_API = "userRuntimesApi"; public static final String SERVICE_RUNTIMES_API = "svcRuntimesApi"; @@ -130,9 +131,9 @@ public org.pmiops.workbench.notebooks.ApiClient workbenchServiceAccountClient( return apiClient; } - @Bean(name = USER_RUNTIMES_API) + @Bean(name = LEGACY_USER_RUNTIMES_API) @RequestScope(proxyMode = ScopedProxyMode.DEFAULT) - public RuntimesApi runtimesApi( + public RuntimesApi legacyRuntimesApi( @Qualifier(LEGACY_USER_LEONARDO_CLIENT) org.pmiops.workbench.legacy_leonardo_client.ApiClient apiClient) { RuntimesApi api = new RuntimesApi(); @@ -140,6 +141,16 @@ public RuntimesApi runtimesApi( return api; } + @Bean(name = USER_RUNTIMES_API) + @RequestScope(proxyMode = ScopedProxyMode.DEFAULT) + public org.broadinstitute.dsde.workbench.client.leonardo.api.RuntimesApi runtimesApi( + @Qualifier(USER_LEONARDO_CLIENT) ApiClient apiClient) { + org.broadinstitute.dsde.workbench.client.leonardo.api.RuntimesApi api = + new org.broadinstitute.dsde.workbench.client.leonardo.api.RuntimesApi(); + api.setApiClient(apiClient); + return api; + } + @Bean(name = USER_DISKS_API) @RequestScope(proxyMode = ScopedProxyMode.DEFAULT) public DisksApi disksApi(@Qualifier(USER_LEONARDO_CLIENT) ApiClient apiClient) { diff --git a/api/src/main/java/org/pmiops/workbench/utils/mappers/LeonardoMapper.java b/api/src/main/java/org/pmiops/workbench/utils/mappers/LeonardoMapper.java index a3870496c79..0fc436689bc 100644 --- a/api/src/main/java/org/pmiops/workbench/utils/mappers/LeonardoMapper.java +++ b/api/src/main/java/org/pmiops/workbench/utils/mappers/LeonardoMapper.java @@ -10,8 +10,10 @@ import org.broadinstitute.dsde.workbench.client.leonardo.model.AllowedChartName; import org.broadinstitute.dsde.workbench.client.leonardo.model.CloudContext; import org.broadinstitute.dsde.workbench.client.leonardo.model.CloudProvider; +import org.broadinstitute.dsde.workbench.client.leonardo.model.GetRuntimeResponse; import org.broadinstitute.dsde.workbench.client.leonardo.model.ListAppResponse; import org.broadinstitute.dsde.workbench.client.leonardo.model.ListPersistentDiskResponse; +import org.broadinstitute.dsde.workbench.client.leonardo.model.RuntimeImage; import org.mapstruct.AfterMapping; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -31,7 +33,6 @@ import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoMachineConfig; import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoRuntimeConfig; import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoRuntimeConfig.CloudServiceEnum; -import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoRuntimeImage; import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoRuntimeStatus; import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoUpdateDataprocConfig; import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoUpdateGceConfig; @@ -159,7 +160,7 @@ default String toGoogleProject(@Nullable CloudContext lcc) { @Mapping( target = "googleProject", source = "cloudContext", - qualifiedByName = "legacy_cloudContextToGoogleProject") + qualifiedByName = "cloudContextToGoogleProject") @Mapping( target = "configurationType", source = "labels", @@ -168,7 +169,7 @@ default String toGoogleProject(@Nullable CloudContext lcc) { @Mapping(target = "gceConfig", ignore = true) @Mapping(target = "gceWithPdConfig", ignore = true) @Mapping(target = "dataprocConfig", ignore = true) - Runtime toApiRuntime(LeonardoGetRuntimeResponse runtime); + Runtime toApiRuntime(GetRuntimeResponse runtime); @Mapping(target = "createdDate", source = "auditInfo.createdDate") @Mapping( @@ -316,11 +317,11 @@ default DiskStatus toApiDiskStatus( } @Nullable - default String getJupyterImage(@Nullable List images) { + default String getJupyterImage(@Nullable List images) { return Optional.ofNullable(images) .flatMap( i -> i.stream().filter(image -> "Jupyter".equals(image.getImageType())).findFirst()) - .map(LeonardoRuntimeImage::getImageUrl) + .map(RuntimeImage::getImageUrl) .orElse(null); } }