Search in sources :

Example 1 with ApiGcpAiNotebookInstanceContainerImage

use of bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceContainerImage in project terra-workspace-manager by DataBiosphere.

the class CreateAiNotebookInstanceStepTest method setFields.

@Test
public void setFields() {
    var creationParameters = new ApiGcpAiNotebookInstanceCreationParameters().postStartupScript("script.sh").machineType("machine-type").installGpuDriver(true).customGpuDriverPath("custom-path").bootDiskType("boot-disk-type").bootDiskSizeGb(111L).dataDiskType("data-disk-type").dataDiskSizeGb(222L).metadata(Map.of("metadata-key", "metadata-value")).acceleratorConfig(new ApiGcpAiNotebookInstanceAcceleratorConfig().coreCount(4L).type("accelerator-type")).vmImage(new ApiGcpAiNotebookInstanceVmImage().projectId("project-id").imageFamily("image-family").imageName("image-name")).containerImage(new ApiGcpAiNotebookInstanceContainerImage().repository("repository").tag("tag"));
    Instance instance = CreateAiNotebookInstanceStep.setFields(creationParameters, "foo@bar.com", new Instance());
    assertEquals("script.sh", instance.getPostStartupScript());
    assertEquals(true, instance.getInstallGpuDriver());
    assertEquals("custom-path", instance.getCustomGpuDriverPath());
    assertEquals("boot-disk-type", instance.getBootDiskType());
    assertEquals(111L, instance.getBootDiskSizeGb());
    assertEquals("data-disk-type", instance.getDataDiskType());
    assertEquals(222L, instance.getDataDiskSizeGb());
    assertThat(instance.getMetadata(), Matchers.aMapWithSize(2));
    // git secrets gets a false positive if 'service_account' is double quoted.
    assertThat(instance.getMetadata(), Matchers.hasEntry("proxy-mode", "service_" + "account"));
    assertThat(instance.getMetadata(), Matchers.hasEntry("metadata-key", "metadata-value"));
    assertEquals("foo@bar.com", instance.getServiceAccount());
    assertEquals(sa_scopes, instance.getServiceAccountScopes());
    assertEquals(4L, instance.getAcceleratorConfig().getCoreCount());
    assertEquals("accelerator-type", instance.getAcceleratorConfig().getType());
    assertEquals("project-id", instance.getVmImage().getProject());
    assertEquals("image-family", instance.getVmImage().getImageFamily());
    assertEquals("image-name", instance.getVmImage().getImageName());
    assertEquals("repository", instance.getContainerImage().getRepository());
    assertEquals("tag", instance.getContainerImage().getTag());
}
Also used : ApiGcpAiNotebookInstanceVmImage(bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceVmImage) Instance(com.google.api.services.notebooks.v1.model.Instance) ApiGcpAiNotebookInstanceContainerImage(bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceContainerImage) ApiGcpAiNotebookInstanceCreationParameters(bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceCreationParameters) ApiGcpAiNotebookInstanceAcceleratorConfig(bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceAcceleratorConfig) Test(org.junit.jupiter.api.Test) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest)

Example 2 with ApiGcpAiNotebookInstanceContainerImage

use of bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceContainerImage in project terra-workspace-manager by DataBiosphere.

the class ValidationUtilsTest method notebookCreationParametersExactlyOneOfVmImageOrContainerImage.

@Test
public void notebookCreationParametersExactlyOneOfVmImageOrContainerImage() {
    // Nothing throws on successful validation.
    ResourceValidationUtils.validate(defaultNotebookCreationParameters());
    // Neither vmImage nor containerImage.
    assertThrows(InconsistentFieldsException.class, () -> ResourceValidationUtils.validate(defaultNotebookCreationParameters().containerImage(null).vmImage(null)));
    // Both vmImage and containerImage.
    assertThrows(InconsistentFieldsException.class, () -> ResourceValidationUtils.validate(defaultNotebookCreationParameters().containerImage(new ApiGcpAiNotebookInstanceContainerImage()).vmImage(new ApiGcpAiNotebookInstanceVmImage())));
    // Valid containerImage.
    ResourceValidationUtils.validate(defaultNotebookCreationParameters().vmImage(null).containerImage(new ApiGcpAiNotebookInstanceContainerImage().repository("my-repository")));
    // Valid vmImage.
    ResourceValidationUtils.validate(defaultNotebookCreationParameters().vmImage(new ApiGcpAiNotebookInstanceVmImage().imageName("image-name")).containerImage(null));
    ResourceValidationUtils.validate(defaultNotebookCreationParameters().vmImage(new ApiGcpAiNotebookInstanceVmImage().imageFamily("image-family")).containerImage(null));
    // Neither vmImage.imageName nor vmImage.familyName
    assertThrows(InconsistentFieldsException.class, () -> ResourceValidationUtils.validate(defaultNotebookCreationParameters().vmImage(new ApiGcpAiNotebookInstanceVmImage()).containerImage(null)));
    // Both vmImage.imageName and vmImage.familyName
    assertThrows(InconsistentFieldsException.class, () -> ResourceValidationUtils.validate(defaultNotebookCreationParameters().vmImage(new ApiGcpAiNotebookInstanceVmImage().imageName("image-name").imageFamily("image-family")).containerImage(null)));
}
Also used : ApiGcpAiNotebookInstanceVmImage(bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceVmImage) ApiGcpAiNotebookInstanceContainerImage(bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceContainerImage) Test(org.junit.jupiter.api.Test) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest)

Example 3 with ApiGcpAiNotebookInstanceContainerImage

use of bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceContainerImage 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)

Aggregations

ApiGcpAiNotebookInstanceContainerImage (bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceContainerImage)3 ApiGcpAiNotebookInstanceVmImage (bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceVmImage)3 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)2 ApiGcpAiNotebookInstanceAcceleratorConfig (bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceAcceleratorConfig)2 Test (org.junit.jupiter.api.Test)2 BadRequestException (bio.terra.common.exception.BadRequestException)1 ApiGcpAiNotebookInstanceCreationParameters (bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceCreationParameters)1 AcceleratorConfig (com.google.api.services.notebooks.v1.model.AcceleratorConfig)1 ContainerImage (com.google.api.services.notebooks.v1.model.ContainerImage)1 Instance (com.google.api.services.notebooks.v1.model.Instance)1 VmImage (com.google.api.services.notebooks.v1.model.VmImage)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HashMap (java.util.HashMap)1