Search in sources :

Example 11 with UFBqDataset

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

the class BqDatasetControlled method createDatasetWithoutSpecifyingDatasetId.

@Test
@DisplayName("create a new dataset but not specify dataset id")
void createDatasetWithoutSpecifyingDatasetId() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id --format=json`
    UFWorkspace workspace = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "set", "--id=" + getWorkspaceId());
    // `terra resource create bq-dataset --name=$name --dataset-id=$datasetId --format=json`
    String name = "createDatasetWithoutSpecifyingDatasetId";
    UFBqDataset createdDataset = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "create", "bq-dataset", "--name=" + name);
    // check that the name, project id, and dataset id match
    assertEquals(name, createdDataset.name, "create output matches name");
    assertEquals(workspace.googleProjectId, createdDataset.projectId, "create output matches project id");
    assertEquals(name, createdDataset.datasetId, "reuse resource name because dataset-id is not specified");
    // check that the dataset is in the list
    UFBqDataset matchedResource = listOneDatasetResourceWithName(name);
    assertEquals(name, matchedResource.name, "list output matches name");
    assertEquals(name, matchedResource.datasetId, "list output matches dataset id");
    // `terra resource describe --name=$name --format=json`
    UFBqDataset describeResource = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "describe", "--name=" + name);
    // check that the name, project id, and dataset id match
    assertEquals(name, describeResource.name, "describe resource output matches name");
    assertEquals(workspace.googleProjectId, describeResource.projectId, "describe resource output matches project id");
    assertEquals(name, describeResource.datasetId, "describe resource output matches dataset id");
    // `terra resource delete --name=$name`
    TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + name, "--quiet");
}
Also used : UFBqDataset(bio.terra.cli.serialization.userfacing.resource.UFBqDataset) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 12 with UFBqDataset

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

the class BqDatasetControlled method createWithAllOptions.

@Test
@DisplayName("create a controlled dataset, specifying all options")
void createWithAllOptions() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id --format=json`
    UFWorkspace workspace = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "set", "--id=" + getWorkspaceId());
    // `terra resources create bq-dataset --name=$name --dataset-id=$datasetId --access=$access
    // --cloning=$cloning --description=$description --location=$location --format=json`
    String name = "createWithAllOptions";
    String datasetId = randomDatasetId();
    AccessScope access = AccessScope.PRIVATE_ACCESS;
    CloningInstructionsEnum cloning = CloningInstructionsEnum.DEFINITION;
    String description = "\"create with all options\"";
    String location = "us-east1";
    UFBqDataset createdDataset = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "create", "bq-dataset", "--name=" + name, "--dataset-id=" + datasetId, "--access=" + access, "--cloning=" + cloning, "--description=" + description, "--location=" + location);
    // check that the properties match
    assertEquals(name, createdDataset.name, "create output matches name");
    assertEquals(workspace.googleProjectId, createdDataset.projectId, "create output matches project id");
    assertEquals(datasetId, createdDataset.datasetId, "create output matches dataset id");
    assertEquals(access, createdDataset.accessScope, "create output matches access");
    assertEquals(cloning, createdDataset.cloningInstructions, "create output matches cloning");
    assertEquals(description, createdDataset.description, "create output matches description");
    assertEquals(workspaceCreator.email.toLowerCase(), createdDataset.privateUserName.toLowerCase(), "create output matches private user name");
    Dataset createdDatasetOnCloud = ExternalBQDatasets.getBQClient(workspaceCreator.getCredentialsWithCloudPlatformScope()).getDataset(DatasetId.of(workspace.googleProjectId, datasetId));
    assertNotNull(createdDatasetOnCloud, "looking up dataset via BQ API succeeded");
    assertEquals(location, createdDatasetOnCloud.getLocation(), "dataset location matches create input");
    // `terra resources describe --name=$name --format=json`
    UFBqDataset describeResource = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "describe", "--name=" + name);
    // check that the properties match
    assertEquals(name, describeResource.name, "describe resource output matches name");
    assertEquals(datasetId, describeResource.datasetId, "describe resource output matches dataset id");
    assertEquals(access, describeResource.accessScope, "describe output matches access");
    assertEquals(cloning, describeResource.cloningInstructions, "describe output matches cloning");
    assertEquals(description, describeResource.description, "describe output matches description");
    assertEquals(workspaceCreator.email.toLowerCase(), describeResource.privateUserName.toLowerCase(), "describe output matches private user name");
    // `terra resources delete --name=$name`
    TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + name, "--quiet");
}
Also used : CloningInstructionsEnum(bio.terra.workspace.model.CloningInstructionsEnum) UFBqDataset(bio.terra.cli.serialization.userfacing.resource.UFBqDataset) UFBqDataset(bio.terra.cli.serialization.userfacing.resource.UFBqDataset) Dataset(com.google.cloud.bigquery.Dataset) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) AccessScope(bio.terra.workspace.model.AccessScope) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 13 with UFBqDataset

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

the class BqDatasetControlled method updateMultipleProperties.

@Test
@DisplayName("update a controlled dataset, specifying multiple properties")
void updateMultipleProperties() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
    // `terra resources create bq-dataset --name=$name --dataset-id=$datasetId
    // --description=$description`
    String name = "updateMultipleProperties";
    String description = "updateDescription";
    String datasetId = randomDatasetId();
    TestCommand.runCommandExpectSuccess("resource", "create", "bq-dataset", "--name=" + name, "--description=" + description, "--dataset-id=" + datasetId);
    // update both the name and description
    // `terra resources update bq-dataset --name=$newName --new-name=$newName
    // --description=$newDescription`
    String newName = "updateMultipleProperties_NEW";
    String newDescription = "updateDescription_NEW";
    UFBqDataset updateDataset = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "update", "bq-dataset", "--name=" + name, "--new-name=" + newName, "--description=" + newDescription);
    assertEquals(newName, updateDataset.name);
    assertEquals(newDescription, updateDataset.description);
    // `terra resources describe --name=$newName`
    UFBqDataset describeDataset = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "describe", "--name=" + newName);
    assertEquals(newDescription, describeDataset.description);
}
Also used : UFBqDataset(bio.terra.cli.serialization.userfacing.resource.UFBqDataset) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 14 with UFBqDataset

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

the class CloneWorkspace method cloneWorkspace.

@Test
public void cloneWorkspace(TestInfo testInfo) throws Exception {
    workspaceCreator.login();
    // create a workspace
    // `terra workspace create --format=json`
    sourceWorkspace = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "create");
    // Add a bucket resource
    UFGcsBucket sourceBucket = TestCommand.runAndParseCommandExpectSuccess(UFGcsBucket.class, "resource", "create", "gcs-bucket", "--name=" + "bucket_1", "--bucket-name=" + UUID.randomUUID(), "--cloning=COPY_RESOURCE");
    // Add another bucket resource with COPY_NOTHING
    UFGcsBucket copyNothingBucket = TestCommand.runAndParseCommandExpectSuccess(UFGcsBucket.class, "resource", "create", "gcs-bucket", "--name=" + "bucket_2", "--bucket-name=" + UUID.randomUUID(), "--cloning=COPY_NOTHING");
    // Add a dataset resource
    UFBqDataset sourceDataset = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "create", "bq-dataset", "--name=dataset_1", "--dataset-id=dataset_1", "--description=The first dataset.", "--cloning=COPY_RESOURCE");
    UFBqDataset datasetReference = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "add-ref", "bq-dataset", "--name=dataset_ref", "--project-id=" + externalDataset.getProjectId(), "--dataset-id=" + externalDataset.getDatasetId(), "--cloning=COPY_REFERENCE");
    UFGitRepo gitRepositoryReference = TestCommand.runAndParseCommandExpectSuccess(UFGitRepo.class, "resource", "add-ref", "git-repo", "--name=" + GIT_REPO_REF_NAME, "--repo-url=" + GIT_REPO_HTTPS_URL, "--cloning=COPY_REFERENCE");
    // Clone the workspace
    UFClonedWorkspace clonedWorkspace = TestCommand.runAndParseCommandExpectSuccess(UFClonedWorkspace.class, "workspace", "clone", "--name=cloned_workspace", "--description=A clone.");
    assertEquals(sourceWorkspace.id, clonedWorkspace.sourceWorkspace.id, "Correct source workspace ID for clone.");
    destinationWorkspace = clonedWorkspace.destinationWorkspace;
    assertThat("There are 5 cloned resources", clonedWorkspace.resources, hasSize(SOURCE_RESOURCE_NUM));
    UFClonedResource bucketClonedResource = getOrFail(clonedWorkspace.resources.stream().filter(cr -> sourceBucket.id.equals(cr.sourceResource.id)).findFirst());
    assertEquals(CloneResourceResult.SUCCEEDED, bucketClonedResource.result, "bucket clone succeeded");
    assertNotNull(bucketClonedResource.destinationResource, "Destination bucket resource was created");
    UFClonedResource copyNothingBucketClonedResource = getOrFail(clonedWorkspace.resources.stream().filter(cr -> copyNothingBucket.id.equals(cr.sourceResource.id)).findFirst());
    assertEquals(CloneResourceResult.SKIPPED, copyNothingBucketClonedResource.result, "COPY_NOTHING resource was skipped.");
    assertNull(copyNothingBucketClonedResource.destinationResource, "Skipped resource has no destination resource.");
    UFClonedResource datasetRefClonedResource = getOrFail(clonedWorkspace.resources.stream().filter(cr -> datasetReference.id.equals(cr.sourceResource.id)).findFirst());
    assertEquals(CloneResourceResult.SUCCEEDED, datasetRefClonedResource.result, "Dataset reference clone succeeded.");
    assertEquals(StewardshipType.REFERENCED, datasetRefClonedResource.destinationResource.stewardshipType, "Dataset reference has correct stewardship type.");
    UFClonedResource datasetClonedResource = getOrFail(clonedWorkspace.resources.stream().filter(cr -> sourceDataset.id.equals(cr.sourceResource.id)).findFirst());
    assertEquals(CloneResourceResult.SUCCEEDED, datasetClonedResource.result, "Dataset clone succeeded.");
    assertEquals("The first dataset.", datasetClonedResource.destinationResource.description, "Dataset description matches.");
    UFClonedResource gitRepoClonedResource = getOrFail(clonedWorkspace.resources.stream().filter(cr -> gitRepositoryReference.id.equals(cr.sourceResource.id)).findFirst());
    assertEquals(CloneResourceResult.SUCCEEDED, gitRepoClonedResource.result, "Git repo clone succeeded");
    assertEquals(GIT_REPO_REF_NAME, gitRepoClonedResource.destinationResource.name, "Resource type matches GIT_REPO");
    // Switch to the new workspace from the clone
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + clonedWorkspace.destinationWorkspace.id);
    // Validate resources
    List<UFResource> resources = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
    }, "resource", "list");
    assertThat("Destination workspace has three resources.", resources, hasSize(DESTINATION_RESOURCE_NUM));
}
Also used : UFClonedResource(bio.terra.cli.serialization.userfacing.UFClonedResource) UFResource(bio.terra.cli.serialization.userfacing.UFResource) UFBqDataset(bio.terra.cli.serialization.userfacing.resource.UFBqDataset) UFGitRepo(bio.terra.cli.serialization.userfacing.resource.UFGitRepo) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) UFClonedWorkspace(bio.terra.cli.serialization.userfacing.UFClonedWorkspace) UFGcsBucket(bio.terra.cli.serialization.userfacing.resource.UFGcsBucket) Test(org.junit.jupiter.api.Test)

Example 15 with UFBqDataset

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

the class BqDatasetLifetime method createWithDefaultTableLifetime.

@Test
@DisplayName("create with default table lifetime only")
void createWithDefaultTableLifetime(TestInfo testInfo) throws IOException {
    final String name = testInfo.getTestMethod().orElseThrow().getName();
    final Duration lifetime = Duration.ofHours(2);
    final UFBqDataset bqDataset = createDatasetWithLDefaultLifetimes(name, "--default-table-lifetime=" + toSecondsString(lifetime));
    validateDefaultLifetimes(bqDataset, null, lifetime.toMillis());
}
Also used : UFBqDataset(bio.terra.cli.serialization.userfacing.resource.UFBqDataset) Duration(java.time.Duration) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

UFBqDataset (bio.terra.cli.serialization.userfacing.resource.UFBqDataset)25 Test (org.junit.jupiter.api.Test)21 DisplayName (org.junit.jupiter.api.DisplayName)20 UFWorkspace (bio.terra.cli.serialization.userfacing.UFWorkspace)4 Duration (java.time.Duration)4 WorkspaceOverride (bio.terra.cli.command.shared.options.WorkspaceOverride)3 UFGcsBucket (bio.terra.cli.serialization.userfacing.resource.UFGcsBucket)3 CreateBqDatasetParams (bio.terra.cli.serialization.userfacing.input.CreateBqDatasetParams)2 CreateResourceParams (bio.terra.cli.serialization.userfacing.input.CreateResourceParams)2 CloningInstructionsEnum (bio.terra.workspace.model.CloningInstructionsEnum)2 Dataset (com.google.cloud.bigquery.Dataset)2 UserActionableException (bio.terra.cli.exception.UserActionableException)1 UFClonedResource (bio.terra.cli.serialization.userfacing.UFClonedResource)1 UFClonedWorkspace (bio.terra.cli.serialization.userfacing.UFClonedWorkspace)1 UFResource (bio.terra.cli.serialization.userfacing.UFResource)1 UpdateControlledBqDatasetParams (bio.terra.cli.serialization.userfacing.input.UpdateControlledBqDatasetParams)1 UpdateReferencedBqDatasetParams (bio.terra.cli.serialization.userfacing.input.UpdateReferencedBqDatasetParams)1 UFBqTable (bio.terra.cli.serialization.userfacing.resource.UFBqTable)1 UFGitRepo (bio.terra.cli.serialization.userfacing.resource.UFGitRepo)1 AccessScope (bio.terra.workspace.model.AccessScope)1