use of bio.terra.common.exception.BadRequestException in project terra-workspace-manager by DataBiosphere.
the class CreateAiNotebookInstanceStep method setFields.
@VisibleForTesting
static Instance setFields(ApiGcpAiNotebookInstanceCreationParameters creationParameters, String serviceAccountEmail, Instance instance) {
instance.setPostStartupScript(Optional.ofNullable(creationParameters.getPostStartupScript()).orElse(DEFAULT_POST_STARTUP_SCRIPT)).setMachineType(creationParameters.getMachineType()).setInstallGpuDriver(creationParameters.isInstallGpuDriver()).setCustomGpuDriverPath(creationParameters.getCustomGpuDriverPath()).setBootDiskType(creationParameters.getBootDiskType()).setBootDiskSizeGb(creationParameters.getBootDiskSizeGb()).setDataDiskType(creationParameters.getDataDiskType()).setDataDiskSizeGb(creationParameters.getDataDiskSizeGb());
Map<String, String> metadata = new HashMap<>();
Optional.ofNullable(creationParameters.getMetadata()).ifPresent(metadata::putAll);
// https://cloud.google.com/ai-platform/notebooks/docs/troubleshooting#opening_a_notebook_results_in_a_403_forbidden_error
if (metadata.put(PROXY_MODE_METADATA_KEY, PROXY_MODE_SA_VALUE) != null) {
throw new BadRequestException("proxy-mode metadata is reserved for Terra.");
}
instance.setMetadata(metadata);
instance.setServiceAccount(serviceAccountEmail);
instance.setServiceAccountScopes(SERVICE_ACCOUNT_SCOPES);
ApiGcpAiNotebookInstanceAcceleratorConfig acceleratorConfig = creationParameters.getAcceleratorConfig();
if (acceleratorConfig != null) {
instance.setAcceleratorConfig(new AcceleratorConfig().setType(acceleratorConfig.getType()).setCoreCount(acceleratorConfig.getCoreCount()));
}
ApiGcpAiNotebookInstanceVmImage vmImageParameters = creationParameters.getVmImage();
if (vmImageParameters != null) {
instance.setVmImage(new VmImage().setProject(vmImageParameters.getProjectId()).setImageFamily(vmImageParameters.getImageFamily()).setImageName(vmImageParameters.getImageName()));
}
ApiGcpAiNotebookInstanceContainerImage containerImageParameters = creationParameters.getContainerImage();
if (containerImageParameters != null) {
instance.setContainerImage(new ContainerImage().setRepository(containerImageParameters.getRepository()).setTag(containerImageParameters.getTag()));
}
return instance;
}
use of bio.terra.common.exception.BadRequestException in project terra-workspace-manager by DataBiosphere.
the class RetrieveNetworkNameStep method pickAndStoreNetwork.
private void pickAndStoreNetwork(SubnetworkList subnetworks, FlightMap workingMap) {
if (subnetworks.getItems().isEmpty()) {
throw new BadRequestException(String.format("No subnetworks available for location '%s'", resource.getLocation()));
}
// Arbitrarily grab the first subnetwork. We don't have a use case for multiple subnetworks or
// them mattering yet, so use any available subnetwork.
Subnetwork subnetwork = subnetworks.getItems().get(0);
workingMap.put(CREATE_NOTEBOOK_NETWORK_NAME, extractNameFromUrl(subnetwork.getNetwork()));
workingMap.put(CREATE_NOTEBOOK_SUBNETWORK_NAME, subnetwork.getName());
}
Aggregations