Search in sources :

Example 1 with UFGcpNotebook

use of bio.terra.cli.serialization.userfacing.resource.UFGcpNotebook in project terra-cli by DataBiosphere.

the class WorkspaceOverride method notebooks.

@Test
@DisplayName("notebook commands respect workspace override")
void notebooks() throws IOException, InterruptedException {
    workspaceCreator.login();
    // `terra workspace set --id=$id1`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + workspace1.id);
    // `terra resources create gcp-notebook --name=$name`
    String name = "notebooks";
    TestCommand.runCommandExpectSuccess("resource", "create", "gcp-notebook", "--name=" + name, "--workspace=" + workspace2.id);
    assertNotebookState(name, "PROVISIONING", workspace2.id);
    pollDescribeForNotebookState(name, "ACTIVE", workspace2.id);
    // `terra resources list --type=AI_NOTEBOOK --workspace=$id2`
    UFGcpNotebook matchedNotebook = listOneNotebookResourceWithName(name, workspace2.id);
    assertEquals(name, matchedNotebook.name, "list output for workspace 2 matches notebook name");
    // `terra resources list --type=AI_NOTEBOOK`
    List<UFGcpNotebook> matchedNotebooks = listNotebookResourcesWithName(name);
    assertEquals(0, matchedNotebooks.size(), "list output for notebooks in workspace 1 is empty");
    // `terra notebook start --name=$name`
    TestCommand.runCommandExpectSuccess("notebook", "start", "--name=" + name, "--workspace=" + workspace2.id);
    // `terra notebook stop --name=$name`
    TestCommand.runCommandExpectSuccess("notebook", "stop", "--name=" + name, "--workspace=" + workspace2.id);
}
Also used : UFGcpNotebook(bio.terra.cli.serialization.userfacing.resource.UFGcpNotebook) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with UFGcpNotebook

use of bio.terra.cli.serialization.userfacing.resource.UFGcpNotebook in project terra-cli by DataBiosphere.

the class GcpNotebookControlled method resolveAndCheckAccess.

@Test
@DisplayName("resolve and check-access for a controlled notebook")
void resolveAndCheckAccess() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
    // `terra resource create gcp-notebook --name=$name`
    String name = "resolveAndCheckAccess";
    UFGcpNotebook createdNotebook = TestCommand.runAndParseCommandExpectSuccess(UFGcpNotebook.class, "resource", "create", "gcp-notebook", "--name=" + name);
    // `terra resource resolve --name=$name --format=json`
    String resolved = TestCommand.runAndParseCommandExpectSuccess(String.class, "resource", "resolve", "--name=" + name);
    assertEquals(createdNotebook.instanceName, resolved, "resolve returns the instance name");
    // `terra resource check-access --name=$name`
    String stdErr = TestCommand.runCommandExpectExitCode(1, "resource", "check-access", "--name=" + name);
    assertThat("check-access error is because gcp notebooks are controlled resources", stdErr, CoreMatchers.containsString("Checking access is intended for REFERENCED resources only"));
}
Also used : UFGcpNotebook(bio.terra.cli.serialization.userfacing.resource.UFGcpNotebook) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with UFGcpNotebook

use of bio.terra.cli.serialization.userfacing.resource.UFGcpNotebook in project terra-cli by DataBiosphere.

the class GcpNotebookControlled method overrideLocationAndInstanceId.

@Test
@DisplayName("override the default location and instance id")
void overrideLocationAndInstanceId() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
    // `terra resource create gcp-notebook --name=$name
    // --cloning=$cloning --description=$description
    // --location=$location --instance-id=$instanceId`
    String name = "overrideLocationAndInstanceId";
    CloningInstructionsEnum cloning = CloningInstructionsEnum.REFERENCE;
    String description = "\"override default location and instance id\"";
    String location = "us-central1-b";
    // instance id must start with a letter
    String instanceId = "a" + UUID.randomUUID().toString();
    UFGcpNotebook createdNotebook = TestCommand.runAndParseCommandExpectSuccess(UFGcpNotebook.class, "resource", "create", "gcp-notebook", "--name=" + name, "--cloning=" + cloning, "--description=" + description, "--location=" + location, "--instance-id=" + instanceId);
    // check that the properties match
    assertEquals(name, createdNotebook.name, "create output matches name");
    assertEquals(cloning, createdNotebook.cloningInstructions, "create output matches cloning");
    assertEquals(description, createdNotebook.description, "create output matches description");
    assertEquals(location, createdNotebook.location, "create output matches location");
    assertEquals(instanceId, createdNotebook.instanceId, "create output matches instance id");
    // gcp notebooks are always private
    assertEquals(AccessScope.PRIVATE_ACCESS, createdNotebook.accessScope, "create output matches access");
    assertEquals(workspaceCreator.email.toLowerCase(), createdNotebook.privateUserName.toLowerCase(), "create output matches private user name");
    // `terra resource describe --name=$name --format=json`
    UFGcpNotebook describeResource = TestCommand.runAndParseCommandExpectSuccess(UFGcpNotebook.class, "resource", "describe", "--name=" + name);
    // check that the properties match
    assertEquals(name, describeResource.name, "describe resource output matches name");
    assertEquals(cloning, describeResource.cloningInstructions, "describe output matches cloning");
    assertEquals(description, describeResource.description, "describe output matches description");
    assertEquals(location, describeResource.location, "describe resource output matches location");
    assertEquals(instanceId, describeResource.instanceId, "describe resource output matches instance id");
    // gcp notebooks are always private
    assertEquals(AccessScope.PRIVATE_ACCESS, describeResource.accessScope, "describe output matches access");
    assertEquals(workspaceCreator.email.toLowerCase(), describeResource.privateUserName.toLowerCase(), "describe output matches private user name");
}
Also used : CloningInstructionsEnum(bio.terra.workspace.model.CloningInstructionsEnum) UFGcpNotebook(bio.terra.cli.serialization.userfacing.resource.UFGcpNotebook) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with UFGcpNotebook

use of bio.terra.cli.serialization.userfacing.resource.UFGcpNotebook in project terra-cli by DataBiosphere.

the class GcpNotebookControlled method assertNotebookState.

/**
 * Helper method to call `terra resource describe` and assert that the notebook state matches that
 * given. Filters on the specified workspace id; Uses the current workspace if null.
 */
static void assertNotebookState(String resourceName, String notebookState, UUID workspaceId) throws JsonProcessingException {
    UFGcpNotebook describeNotebook = workspaceId == null ? TestCommand.runAndParseCommandExpectSuccess(UFGcpNotebook.class, "resource", "describe", "--name=" + resourceName) : TestCommand.runAndParseCommandExpectSuccess(UFGcpNotebook.class, "resource", "describe", "--name=" + resourceName, "--workspace=" + workspaceId);
    assertEquals(notebookState, describeNotebook.state, "notebook state matches");
    if (!notebookState.equals("PROVISIONING")) {
        assertNotNull(describeNotebook.proxyUri, "proxy url is populated");
    }
}
Also used : UFGcpNotebook(bio.terra.cli.serialization.userfacing.resource.UFGcpNotebook)

Example 5 with UFGcpNotebook

use of bio.terra.cli.serialization.userfacing.resource.UFGcpNotebook in project terra-cli by DataBiosphere.

the class GcpNotebookControlled method listDescribeReflectCreateDelete.

@Test
@DisplayName("list and describe reflect creating and deleting a controlled notebook")
void listDescribeReflectCreateDelete() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
    // `terra resource create gcp-notebook --name=$name`
    String name = "listDescribeReflectCreateDelete";
    UFGcpNotebook createdNotebook = TestCommand.runAndParseCommandExpectSuccess(UFGcpNotebook.class, "resource", "create", "gcp-notebook", "--name=" + name);
    // check that the name and notebook name match
    assertEquals(name, createdNotebook.name, "create output matches name");
    // gcp notebooks are always private
    assertEquals(AccessScope.PRIVATE_ACCESS, createdNotebook.accessScope, "create output matches access");
    assertEquals(workspaceCreator.email.toLowerCase(), createdNotebook.privateUserName.toLowerCase(), "create output matches private user name");
    // check that the notebook is in the list
    UFGcpNotebook matchedResource = listOneNotebookResourceWithName(name);
    assertEquals(name, matchedResource.name, "list output matches name");
    // `terra resource describe --name=$name --format=json`
    UFGcpNotebook describeResource = TestCommand.runAndParseCommandExpectSuccess(UFGcpNotebook.class, "resource", "describe", "--name=" + name);
    // check that the name matches and the instance id is populated
    assertEquals(name, describeResource.name, "describe resource output matches name");
    assertNotNull(describeResource.instanceName, "describe resource output includes instance name");
    // gcp notebooks are always private
    assertEquals(AccessScope.PRIVATE_ACCESS, describeResource.accessScope, "describe output matches access");
    assertEquals(workspaceCreator.email.toLowerCase(), describeResource.privateUserName.toLowerCase(), "describe output matches private user name");
    // `terra notebook delete --name=$name`
    TestCommand.Result cmd = TestCommand.runCommand("resource", "delete", "--name=" + name, "--quiet");
    // TODO (PF-745): use long-running job commands here
    boolean cliTimedOut = cmd.exitCode == 1 && cmd.stdErr.contains("CLI timed out waiting for the job to complete. It's still running on the server.");
    assertTrue(cmd.exitCode == 0 || cliTimedOut, "delete either succeeds or times out");
    if (!cliTimedOut) {
        // confirm it no longer appears in the resources list
        List<UFGcpNotebook> listedNotebooks = listNotebookResourcesWithName(name);
        assertThat("deleted notebook no longer appears in the resources list", listedNotebooks, Matchers.empty());
    }
}
Also used : TestCommand(harness.TestCommand) UFGcpNotebook(bio.terra.cli.serialization.userfacing.resource.UFGcpNotebook) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

UFGcpNotebook (bio.terra.cli.serialization.userfacing.resource.UFGcpNotebook)6 DisplayName (org.junit.jupiter.api.DisplayName)4 Test (org.junit.jupiter.api.Test)4 WorkspaceOverride (bio.terra.cli.command.shared.options.WorkspaceOverride)1 CreateGcpNotebookParams (bio.terra.cli.serialization.userfacing.input.CreateGcpNotebookParams)1 CreateResourceParams (bio.terra.cli.serialization.userfacing.input.CreateResourceParams)1 CloningInstructionsEnum (bio.terra.workspace.model.CloningInstructionsEnum)1 TestCommand (harness.TestCommand)1