Search in sources :

Example 6 with BadRequestException

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;
}
Also used : AcceleratorConfig(com.google.api.services.notebooks.v1.model.AcceleratorConfig) ApiGcpAiNotebookInstanceAcceleratorConfig(bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceAcceleratorConfig) ApiGcpAiNotebookInstanceVmImage(bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceVmImage) HashMap(java.util.HashMap) ContainerImage(com.google.api.services.notebooks.v1.model.ContainerImage) ApiGcpAiNotebookInstanceContainerImage(bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceContainerImage) ApiGcpAiNotebookInstanceContainerImage(bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceContainerImage) BadRequestException(bio.terra.common.exception.BadRequestException) VmImage(com.google.api.services.notebooks.v1.model.VmImage) ApiGcpAiNotebookInstanceVmImage(bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceVmImage) ApiGcpAiNotebookInstanceAcceleratorConfig(bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceAcceleratorConfig) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with BadRequestException

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());
}
Also used : Subnetwork(com.google.api.services.compute.model.Subnetwork) BadRequestException(bio.terra.common.exception.BadRequestException)

Aggregations

BadRequestException (bio.terra.common.exception.BadRequestException)7 ControlledResourceIamRole (bio.terra.workspace.service.iam.model.ControlledResourceIamRole)2 Pool (bio.terra.buffer.common.Pool)1 Resource (bio.terra.buffer.common.Resource)1 NotFoundException (bio.terra.buffer.common.exception.NotFoundException)1 StorageCow (bio.terra.cloudres.google.storage.StorageCow)1 InternalServerErrorException (bio.terra.common.exception.InternalServerErrorException)1 ValidationException (bio.terra.common.exception.ValidationException)1 FlightMap (bio.terra.stairway.FlightMap)1 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)1 InternalLogicException (bio.terra.workspace.common.exception.InternalLogicException)1 ApiGcpAiNotebookInstanceAcceleratorConfig (bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceAcceleratorConfig)1 ApiGcpAiNotebookInstanceContainerImage (bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceContainerImage)1 ApiGcpAiNotebookInstanceCreationParameters (bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceCreationParameters)1 ApiGcpAiNotebookInstanceVmImage (bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceVmImage)1 ApiGcpGcsBucketCreationParameters (bio.terra.workspace.generated.model.ApiGcpGcsBucketCreationParameters)1 ApiJobControl (bio.terra.workspace.generated.model.ApiJobControl)1 ApiPrivateResourceUser (bio.terra.workspace.generated.model.ApiPrivateResourceUser)1 JobBuilder (bio.terra.workspace.service.job.JobBuilder)1 ControlledAiNotebookInstanceResource (bio.terra.workspace.service.resource.controlled.cloud.gcp.ainotebook.ControlledAiNotebookInstanceResource)1