Search in sources :

Example 1 with UFBqDataset

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

the class BqDataset method execute.

/**
 * Update a BigQuery dataset in the workspace.
 */
@Override
protected void execute() {
    workspaceOption.overrideIfSpecified();
    // all update parameters are optional, but make sure at least one is specified
    if (!resourceUpdateOptions.isDefined() && !bqDatasetLifetimeOptions.isDefined() && !bqDatasetNewIds.isDefined()) {
        throw new UserActionableException("Specify at least one property to update.");
    }
    // get the resource and make sure it's the right type
    bio.terra.cli.businessobject.resource.BqDataset resource = Context.requireWorkspace().getResource(resourceUpdateOptions.resourceNameOption.name).castToType(Resource.Type.BQ_DATASET);
    if (resource.getStewardshipType().equals(StewardshipType.REFERENCED)) {
        if (bqDatasetLifetimeOptions.isDefined()) {
            throw new UserActionableException("Default lifetime can only be updated for controlled resources.");
        }
        UpdateReferencedBqDatasetParams.Builder updateParams = new UpdateReferencedBqDatasetParams.Builder().resourceParams(resourceUpdateOptions.populateMetadataFields().build()).datasetId(bqDatasetNewIds.getNewBqDatasetId()).projectId(bqDatasetNewIds.getNewGcpProjectId());
        resource.updateReferenced(updateParams.build());
    } else {
        resource.updateControlled(new UpdateControlledBqDatasetParams.Builder().resourceFields(resourceUpdateOptions.populateMetadataFields().build()).defaultPartitionLifetimeSeconds(bqDatasetLifetimeOptions.getDefaultPartitionLifetimeSeconds()).defaultTableLifetimeSeconds(bqDatasetLifetimeOptions.getDefaultTableLifetimeSeconds()).build());
    }
    formatOption.printReturnValue(new UFBqDataset(resource), BqDataset::printText);
}
Also used : UFBqDataset(bio.terra.cli.serialization.userfacing.resource.UFBqDataset) UpdateReferencedBqDatasetParams(bio.terra.cli.serialization.userfacing.input.UpdateReferencedBqDatasetParams) UserActionableException(bio.terra.cli.exception.UserActionableException) UFBqDataset(bio.terra.cli.serialization.userfacing.resource.UFBqDataset) UpdateControlledBqDatasetParams(bio.terra.cli.serialization.userfacing.input.UpdateControlledBqDatasetParams) WorkspaceOverride(bio.terra.cli.command.shared.options.WorkspaceOverride)

Example 2 with UFBqDataset

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

the class PassthroughApps method bqShow.

@Test
@DisplayName("bq show dataset metadata")
void bqShow() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
    // `terra resource create bq-dataset --name=$name --dataset-id=$datasetId --format=json`
    String name = "bqShow";
    String datasetId = randomDatasetId();
    UFBqDataset dataset = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "create", "bq-dataset", "--name=" + name, "--dataset-id=" + datasetId);
    // `terra bq show --format=prettyjson [project id]:[dataset id]`
    TestCommand.Result cmd = TestCommand.runCommand("bq", "show", "--format=prettyjson", datasetId);
    assertThat("bq show includes the dataset id", cmd.stdOut, CoreMatchers.containsString("\"id\": \"" + dataset.projectId + ":" + dataset.datasetId + "\""));
    // `terra resources delete --name=$name`
    TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + name, "--quiet");
}
Also used : TestCommand(harness.TestCommand) UFBqDataset(bio.terra.cli.serialization.userfacing.resource.UFBqDataset) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with UFBqDataset

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

the class BqDatasetControlled method updateIndividualProperties.

@Test
@DisplayName("update a controlled dataset, one property at a time")
void updateIndividualProperties() 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 = "updateIndividualProperties";
    String description = "updateDescription";
    String datasetId = randomDatasetId();
    TestCommand.runCommandExpectSuccess("resource", "create", "bq-dataset", "--name=" + name, "--description=" + description, "--dataset-id=" + datasetId);
    // update just the name
    // `terra resources update bq-dataset --name=$name --new-name=$newName`
    String newName = "updateIndividualProperties_NEW";
    UFBqDataset updateDataset = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "update", "bq-dataset", "--name=" + name, "--new-name=" + newName);
    assertEquals(newName, updateDataset.name);
    assertEquals(description, updateDataset.description);
    // `terra resources describe --name=$newName`
    UFBqDataset describeDataset = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "describe", "--name=" + newName);
    assertEquals(description, describeDataset.description);
    // update just the description
    // `terra resources update bq-dataset --name=$newName --description=$newDescription`
    String newDescription = "updateDescription_NEW";
    updateDataset = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "update", "bq-dataset", "--name=" + newName, "--description=" + newDescription);
    assertEquals(newName, updateDataset.name);
    assertEquals(newDescription, updateDataset.description);
    // `terra resources describe --name=$newName`
    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 4 with UFBqDataset

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

the class BqDatasetControlled method listDescribeReflectCreate.

@Test
@DisplayName("list and describe reflect creating a new controlled dataset")
void listDescribeReflectCreate() 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 = "listDescribeReflectCreate";
    String datasetId = randomDatasetId();
    UFBqDataset createdDataset = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "create", "bq-dataset", "--name=" + name, "--dataset-id=" + datasetId);
    // 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(datasetId, createdDataset.datasetId, "create output matches dataset id");
    // check that the dataset is in the list
    UFBqDataset matchedResource = listOneDatasetResourceWithName(name);
    assertEquals(name, matchedResource.name, "list output matches name");
    assertEquals(datasetId, 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(datasetId, 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 5 with UFBqDataset

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

the class BqDatasetLifetime method updateDefaultLifetimes.

@Test
@DisplayName("create with no default lifetimes and test update calls")
void updateDefaultLifetimes(TestInfo testInfo) throws IOException {
    final String name = testInfo.getTestMethod().orElseThrow().getName();
    final Duration partitionLifetime = Duration.ofSeconds(9600);
    final Duration tableLifetime = Duration.ofSeconds(4800);
    // Create a dataset with no lifetimes configured
    final UFBqDataset bqDataset = createDatasetWithLDefaultLifetimes(name);
    validateDefaultLifetimes(bqDataset, null, null);
    // Now update the dataset with a default partition lifetime only and make sure it is set and
    // table stays the same.
    updateDatasetWithDefaultLifetimes(name, "--default-partition-lifetime=" + toSecondsString(partitionLifetime));
    validateDefaultLifetimes(bqDataset, partitionLifetime.toMillis(), null);
    // Now update the dataset with a default table lifetime only and make sure it is set and
    // partition stays the same.
    updateDatasetWithDefaultLifetimes(name, "--default-table-lifetime=" + toSecondsString(tableLifetime));
    validateDefaultLifetimes(bqDataset, partitionLifetime.toMillis(), tableLifetime.toMillis());
    // Now set both to zero in a single call and make sure both get cleared.
    updateDatasetWithDefaultLifetimes(name, "--default-partition-lifetime=0", "--default-table-lifetime=0");
    validateDefaultLifetimes(bqDataset, null, null);
    // Test that flags can be passed along with generic controlled resource update flags by renaming
    // the dataset (then renaming it back) along with a default lifetime update.
    final String renamed = name + "Renamed";
    updateDatasetWithDefaultLifetimes(name, "--new-name=" + renamed, "--default-partition-lifetime=" + toSecondsString(partitionLifetime));
    validateDefaultLifetimes(bqDataset, partitionLifetime.toMillis(), null);
    updateDatasetWithDefaultLifetimes(renamed, "--new-name=" + name, "--default-table-lifetime=" + toSecondsString(tableLifetime));
    validateDefaultLifetimes(bqDataset, partitionLifetime.toMillis(), tableLifetime.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