Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joel/leo client get list runtimes #8895

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,9 @@ dependencies {
exclude group: 'org.apache.oltu.oauth2', module: 'org.apache.oltu.oauth2.common'
}

// updated 2 Oct 2024 to most recent develop
// updated 21 Oct 2024 to most recent develop
// see https://github.com/DataBiosphere/leonardo/actions/workflows/publish_java_client.yml
implementation("org.broadinstitute.dsde.workbench:leonardo-client_2.13:1.3.6-3fbffee")
implementation("org.broadinstitute.dsde.workbench:leonardo-client_2.13:1.3.6-880147e")

implementation group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '4.0.5'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ public boolean isDiskAttached(ListPersistentDiskResponse diskResponse, String go
return leonardoApiClient.listRuntimesByProjectAsService(googleProject).stream()
// this filter/map follows the discriminator logic in the source Leonardo Swagger
// for OneOfRuntimeConfigInResponse

// TODO: does all this go away for the new client?

.filter(
resp -> {
var runtimeConfig =
Expand Down
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 @@ -273,6 +274,8 @@ default void mapRuntimeConfig(
return;
}

// TODO: does all this go away for the new client?

Gson gson = new Gson();
String runtimeConfigJson = gson.toJson(runtimeConfigObj);
LeonardoRuntimeConfig runtimeConfig =
Expand Down Expand Up @@ -314,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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,8 @@ public void testCreateRuntime_dataproc() throws ApiException {

LeonardoCreateRuntimeRequest createRuntimeRequest = createRuntimeRequestCaptor.getValue();

// TODO: does all this go away for the new client?

Gson gson = new Gson();
LeonardoMachineConfig createLeonardoMachineConfig =
gson.fromJson(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void setUp() {
.thenReturn(cloudStorageCounts);

LeonardoListRuntimeResponse leonardoListRuntimeResponse =
TestMockFactory.createLeonardoListRuntimesResponse();
TestMockFactory.createListRuntimeResponse();
List<LeonardoListRuntimeResponse> runtimes = List.of(leonardoListRuntimeResponse);
when(mockLeonardoNotebooksClient.listRuntimesByProjectAsService(WORKSPACE_NAMESPACE))
.thenReturn(runtimes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static RawlsWorkspaceDetails createTerraWorkspace(
.googleProject(DEFAULT_GOOGLE_PROJECT);
}

public static LeonardoListRuntimeResponse createLeonardoListRuntimesResponse() {
public static LeonardoListRuntimeResponse createListRuntimeResponse() {
return new LeonardoListRuntimeResponse()
.runtimeName("runtime")
.cloudContext(
Expand Down
Loading