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

DRAFT Joel/leo swag #8883

Draft
wants to merge 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import jakarta.inject.Provider;
import jakarta.mail.MessagingException;
import java.time.Clock;
Expand All @@ -16,7 +17,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.broadinstitute.dsde.workbench.client.leonardo.model.DiskStatus;
import org.broadinstitute.dsde.workbench.client.leonardo.model.ListPersistentDiskResponse;
import org.pmiops.workbench.billing.FreeTierBillingService;
Expand All @@ -29,8 +29,10 @@
import org.pmiops.workbench.firecloud.FireCloudService;
import org.pmiops.workbench.firecloud.FirecloudTransforms;
import org.pmiops.workbench.legacy_leonardo_client.ApiException;
import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoGceWithPdConfigInResponse;
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.LeonardoRuntimeConfig.CloudServiceEnum;
import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoRuntimeStatus;
import org.pmiops.workbench.leonardo.LeonardoApiClient;
import org.pmiops.workbench.mail.MailService;
Expand Down Expand Up @@ -331,8 +333,17 @@ private boolean isDiskAttached(ListPersistentDiskResponse diskResponse, String g

if (leonardoMapper.toApiListDisksResponse(diskResponse).isGceRuntime()) {
return leonardoApiClient.listRuntimesByProjectAsService(googleProject).stream()
.flatMap(runtime -> Stream.ofNullable(runtime.getDiskConfig()))
.anyMatch(diskConfig -> diskName.equals(diskConfig.getName()));
.map(LeonardoListRuntimeResponse::getRuntimeConfig)
.filter(runtimeConfig -> CloudServiceEnum.GCE.equals(runtimeConfig.getCloudService()))
.map(
runtimeConfig ->
new Gson()
.fromJson(
new Gson().toJson(runtimeConfig),
LeonardoGceWithPdConfigInResponse.class))
.anyMatch(
gceWithPdConfig ->
diskResponse.getId().equals(gceWithPdConfig.getPersistentDiskId()));
} else {
return leonardoApiClient.listAppsInProjectAsService(googleProject).stream()
.anyMatch(userAppEnvironment -> diskName.equals(userAppEnvironment.getDiskName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import jakarta.inject.Provider;
import jakarta.validation.constraints.NotNull;
import java.io.IOException;
Expand Down Expand Up @@ -49,9 +48,9 @@
import org.pmiops.workbench.legacy_leonardo_client.api.RuntimesApi;
import org.pmiops.workbench.legacy_leonardo_client.api.ServiceInfoApi;
import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoCreateRuntimeRequest;
import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoDataprocConfig;
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.LeonardoMachineConfig;
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 @@ -84,7 +83,7 @@ public class LeonardoApiClientImpl implements LeonardoApiClient {
// Keep in sync with
// https://github.com/DataBiosphere/leonardo/blob/develop/core/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/runtimeModels.scala#L162
private static final Set<LeonardoRuntimeStatus> STOPPABLE_RUNTIME_STATUSES =
ImmutableSet.of(
Set.of(
LeonardoRuntimeStatus.RUNNING,
LeonardoRuntimeStatus.STARTING,
LeonardoRuntimeStatus.UPDATING);
Expand Down Expand Up @@ -229,8 +228,8 @@ private Object buildRuntimeConfig(Runtime runtime) {
} else if (runtime.getGceWithPdConfig() != null) {
return leonardoMapper.toLeonardoGceWithPdConfig(runtime.getGceWithPdConfig());
} else {
LeonardoMachineConfig machineConfig =
leonardoMapper.toLeonardoMachineConfig(runtime.getDataprocConfig());
LeonardoDataprocConfig machineConfig =
leonardoMapper.toLeonardoDataprocConfig(runtime.getDataprocConfig());
if (workbenchConfigProvider.get().featureFlags.enablePrivateDataprocWorker) {
machineConfig.setWorkerPrivateAccess(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoCloudContext;
import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoCloudProvider;
import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoClusterError;
import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoDataprocConfig;
import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoDiskConfig;
import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoGceConfig;
import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoGceWithPdConfig;
import org.pmiops.workbench.legacy_leonardo_client.model.LeonardoGceWithPdConfigInResponse;
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.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;
Expand Down Expand Up @@ -61,15 +62,14 @@ public interface LeonardoMapper {
RuntimeConfigurationType.GENERALANALYSIS, "preset-general-analysis",
RuntimeConfigurationType.HAILGENOMICANALYSIS, "preset-hail-genomic-analysis");

DataprocConfig toDataprocConfig(LeonardoMachineConfig leonardoMachineConfig);
DataprocConfig toDataprocConfig(LeonardoDataprocConfig leonardoDataprocConfig);

@Mapping(target = "properties", ignore = true)
@Mapping(target = "workerPrivateAccess", ignore = true)
@Mapping(target = "region", ignore = true)
@Mapping(target = "cloudService", constant = "DATAPROC")
@Mapping(target = "componentGatewayEnabled", constant = "true")
LeonardoMachineConfig toLeonardoMachineConfig(DataprocConfig dataprocConfig);

GceConfig toGceConfig(LeonardoGceConfig leonardoGceConfig);
LeonardoDataprocConfig toLeonardoDataprocConfig(DataprocConfig dataprocConfig);

@Mapping(target = "bootDiskSize", ignore = true)
@Mapping(target = "cloudService", constant = "GCE")
Expand All @@ -85,11 +85,11 @@ public interface LeonardoMapper {
@Mapping(target = "cloudService", constant = "DATAPROC")
LeonardoUpdateDataprocConfig toUpdateDataprocConfig(DataprocConfig dataprocConfig);

@Mapping(target = "persistentDisk", source = "leonardoDiskConfig")
@Mapping(target = "machineType", source = "leonardoGceConfig.machineType")
@Mapping(target = "gpuConfig", source = "leonardoGceConfig.gpuConfig")
@Mapping(target = "diskSize", ignore = true)
GceConfig toGceConfig(LeonardoGceWithPdConfigInResponse leonardoConfig);

GceWithPdConfig toGceWithPdConfig(
LeonardoGceConfig leonardoGceConfig, LeonardoDiskConfig leonardoDiskConfig);
LeonardoGceWithPdConfigInResponse leonardoConfig, PersistentDiskRequest persistentDisk);

@Mapping(target = "labels", ignore = true)
PersistentDiskRequest diskConfigToPersistentDiskRequest(LeonardoDiskConfig leonardoDiskConfig);
Expand Down Expand Up @@ -121,7 +121,7 @@ default void setDiskEnvironmentType(Disk disk, @Nullable Object diskLabels) {
.ifPresentOrElse(disk::setAppType, () -> disk.gceRuntime(true));
}

@Mapping(target = "patchInProgress", ignore = true)
@Mapping(target = "workspaceId", ignore = true)
LeonardoListRuntimeResponse toListRuntimeResponse(LeonardoGetRuntimeResponse runtime);

@Nullable
Expand Down Expand Up @@ -192,19 +192,13 @@ ListRuntimeResponse toApiListRuntimeResponse(
@AfterMapping
default void getRuntimeAfterMapper(
@MappingTarget Runtime runtime, LeonardoGetRuntimeResponse leonardoGetRuntimeResponse) {
mapRuntimeConfig(
runtime,
leonardoGetRuntimeResponse.getRuntimeConfig(),
leonardoGetRuntimeResponse.getDiskConfig());
mapRuntimeConfig(runtime, leonardoGetRuntimeResponse.getRuntimeConfig());
}

@AfterMapping
default void listRuntimeAfterMapper(
@MappingTarget Runtime runtime, LeonardoListRuntimeResponse leonardoListRuntimeResponse) {
mapRuntimeConfig(
runtime,
leonardoListRuntimeResponse.getRuntimeConfig(),
leonardoListRuntimeResponse.getDiskConfig());
mapRuntimeConfig(runtime, leonardoListRuntimeResponse.getRuntimeConfig());
}

@Mapping(target = "createdDate", source = "auditInfo.createdDate")
Expand Down Expand Up @@ -264,42 +258,47 @@ default RuntimeConfigurationType mapRuntimeConfigurationLabels(Object runtimeLab
}
}

default void mapRuntimeConfig(
Runtime runtime, Object runtimeConfigObj, @Nullable LeonardoDiskConfig diskConfig) {
default void mapRuntimeConfig(Runtime runtime, LeonardoRuntimeConfig runtimeConfigObj) {
if (runtimeConfigObj == null) {
return;
}

Gson gson = new Gson();
String runtimeConfigJson = gson.toJson(runtimeConfigObj);
LeonardoRuntimeConfig runtimeConfig =
gson.fromJson(runtimeConfigJson, LeonardoRuntimeConfig.class);

if (CloudServiceEnum.DATAPROC.equals(runtimeConfig.getCloudService())) {
runtime.dataprocConfig(
toDataprocConfig(gson.fromJson(runtimeConfigJson, LeonardoMachineConfig.class)));
} else if (CloudServiceEnum.GCE.equals(runtimeConfig.getCloudService())) {
// Unfortunately the discriminator does not allow us to distinguish plain GCE config
// from GceWithPd; use the diskConfig to help differentiate.
LeonardoGceConfig leonardoGceConfig =
gson.fromJson(runtimeConfigJson, LeonardoGceConfig.class);
if (diskConfig != null) {
runtime.gceWithPdConfig(toGceWithPdConfig(leonardoGceConfig, diskConfig));
} else {
runtime.gceConfig(toGceConfig(leonardoGceConfig));
}
} else {
throw new IllegalArgumentException(
"Invalid LeonardoGetRuntimeResponse.RuntimeConfig.cloudService : "
+ runtimeConfig.getCloudService());
CloudServiceEnum cloudService = runtimeConfigObj.getCloudService();
if (cloudService == null) {
return;
}

switch (cloudService) {
case DATAPROC:
{
runtime.dataprocConfig(
toDataprocConfig(
new Gson()
.fromJson(
new Gson().toJson(runtimeConfigObj), LeonardoDataprocConfig.class)));
break;
}
case GCE:
LeonardoGceWithPdConfigInResponse leonardoConfig =
new Gson()
.fromJson(
new Gson().toJson(runtimeConfigObj), LeonardoGceWithPdConfigInResponse.class);

// we never actually had the disk at this point! if we did, we would do something with this
// leonardoConfig.getPersistentDiskId(); // but what do I do with this?
// runtime.gceWithPdConfig(toGceWithPdConfig(leonardoConfig, disk));
runtime.gceConfig(toGceConfig(leonardoConfig));
break;
default:
throw new IllegalArgumentException("Invalid RuntimeConfig.cloudService : " + cloudService);
}
}

default RuntimeStatus toApiRuntimeStatus(LeonardoRuntimeStatus leonardoRuntimeStatus) {
if (leonardoRuntimeStatus == null) {
default RuntimeStatus toApiRuntimeStatus(LeonardoRuntimeStatus clusterStatus) {
if (clusterStatus == null) {
return RuntimeStatus.UNKNOWN;
}
return RuntimeStatus.fromValue(leonardoRuntimeStatus.toString());
return RuntimeStatus.fromValue(clusterStatus.toString());
}

default DiskStatus toApiDiskStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobInfo;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Streams;
import com.google.protobuf.util.Timestamps;
import jakarta.annotation.Nullable;
Expand Down Expand Up @@ -307,7 +306,7 @@ public List<ListRuntimeResponse> deleteRuntimesInWorkspace(
// receive runtimes with that status from Leo. We don't want to because we reuse runtime
// names and thus could have >1 deleted runtimes with the same name in the project.
List<LeonardoRuntimeStatus> acceptableStates =
ImmutableList.of(LeonardoRuntimeStatus.DELETING, LeonardoRuntimeStatus.ERROR);
List.of(LeonardoRuntimeStatus.DELETING, LeonardoRuntimeStatus.ERROR);
runtimesInProjectAffected.stream()
.filter(runtime -> !acceptableStates.contains(runtime.getStatus()))
.forEach(
Expand Down
Loading