Skip to content

Commit

Permalink
migrate getRuntime
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthibault79 committed Oct 29, 2024
1 parent 22b9156 commit 7f4725b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,9 +92,9 @@ public ResponseEntity<Runtime> 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",
Expand All @@ -106,7 +106,7 @@ public ResponseEntity<Runtime> getRuntime(String workspaceNamespace) {
}
}

private String formatRuntimeErrors(@Nullable List<LeonardoClusterError> errors) {
private String formatRuntimeErrors(@Nullable List<ClusterError> errors) {
if (errors == null || errors.isEmpty()) {
return "no error messages";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> fileList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -98,6 +99,8 @@ public class LeonardoApiClientImpl implements LeonardoApiClient {

private final LeonardoApiClientFactory leonardoApiClientFactory;
private final Provider<RuntimesApi> runtimesApiProvider;
private final Provider<org.broadinstitute.dsde.workbench.client.leonardo.api.RuntimesApi>
newRuntimesApiProvider;
private final Provider<RuntimesApi> serviceRuntimesApiProvider;

private final Provider<ResourcesApi> resourcesApiProvider;
Expand All @@ -119,7 +122,10 @@ public class LeonardoApiClientImpl implements LeonardoApiClient {
@Autowired
public LeonardoApiClientImpl(
LeonardoApiClientFactory leonardoApiClientFactory,
@Qualifier(LeonardoConfig.USER_RUNTIMES_API) Provider<RuntimesApi> runtimesApiProvider,
@Qualifier(LeonardoConfig.LEGACY_USER_RUNTIMES_API) Provider<RuntimesApi> runtimesApiProvider,
@Qualifier(LeonardoConfig.USER_RUNTIMES_API)
Provider<org.broadinstitute.dsde.workbench.client.leonardo.api.RuntimesApi>
newRuntimesApiProvider,
@Qualifier(LeonardoConfig.SERVICE_RUNTIMES_API)
Provider<RuntimesApi> serviceRuntimesApiProvider,
@Qualifier(LeonardoConfig.SERVICE_RESOURCE_API) Provider<ResourcesApi> resourcesApiProvider,
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -130,16 +131,26 @@ 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();
api.setApiClient(apiClient);
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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",
Expand All @@ -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(
Expand Down Expand Up @@ -316,11 +317,11 @@ default DiskStatus toApiDiskStatus(
}

@Nullable
default String getJupyterImage(@Nullable List<LeonardoRuntimeImage> images) {
default String getJupyterImage(@Nullable List<RuntimeImage> images) {
return Optional.ofNullable(images)
.flatMap(
i -> i.stream().filter(image -> "Jupyter".equals(image.getImageType())).findFirst())
.map(LeonardoRuntimeImage::getImageUrl)
.map(RuntimeImage::getImageUrl)
.orElse(null);
}
}

0 comments on commit 7f4725b

Please sign in to comment.