use of bio.terra.cli.serialization.userfacing.resource.UFBqTable in project terra-cli by DataBiosphere.
the class BqTable 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() && !bqDatasetNewIds.isDefined() && newBqTableId == null) {
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.BqTable resource = Context.requireWorkspace().getResource(resourceUpdateOptions.resourceNameOption.name).castToType(Resource.Type.BQ_TABLE);
UpdateReferencedBqTableParams.Builder bqTableParams = new UpdateReferencedBqTableParams.Builder().resourceParams(resourceUpdateOptions.populateMetadataFields().build()).tableId(newBqTableId).datasetId(bqDatasetNewIds.getNewBqDatasetId()).projectId(bqDatasetNewIds.getNewGcpProjectId());
resource.updateReferenced(bqTableParams.build());
formatOption.printReturnValue(new UFBqTable(resource), BqTable::printText);
}
use of bio.terra.cli.serialization.userfacing.resource.UFBqTable in project terra-cli by DataBiosphere.
the class BqTableReferenced method listDescribeReflectAdd.
@Test
@DisplayName("list and describe reflect adding a new referenced data table")
void listDescribeReflectAdd() throws IOException {
workspaceCreator.login();
// `terra workspace set --id=$id`
TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
// `terra resource add-ref bq-table --name=$name --project-id=$projectId
// --dataset-id=$datasetId --table-id=$dataTableId --format=json`
String name = "listDescribeReflectAdd";
UFBqTable addedDataTable = TestCommand.runAndParseCommandExpectSuccess(UFBqTable.class, "resource", "add-ref", "bq-table", "--name=" + name, "--project-id=" + externalDataset.getProjectId(), "--dataset-id=" + externalDataset.getDatasetId(), "--table-id=" + externalDataTableName);
// check that the name, project id, dataset id and table id match
assertEquals(name, addedDataTable.name, "add ref output matches name");
assertEquals(externalDataset.getProjectId(), addedDataTable.projectId, "add ref output matches project id");
assertEquals(externalDataset.getDatasetId(), addedDataTable.datasetId, "add ref output matches dataset id");
assertEquals(externalDataTableName, addedDataTable.dataTableId, "add ref output matches data table id");
// check that the data table is in the list
List<UFBqTable> matchedResourceList = listDataTableResourcesWithName(name);
assertEquals(1, matchedResourceList.size(), "Only 1 data table in the list");
UFBqTable matchedResource = matchedResourceList.get(0);
assertEquals(name, matchedResource.name, "list output matches name");
assertEquals(externalDataset.getProjectId(), matchedResource.projectId, "list output matches project id");
assertEquals(externalDataset.getDatasetId(), matchedResource.datasetId, "list output matches dataset id");
assertEquals(externalDataTableName, matchedResource.dataTableId, "List output matches data table id");
// `terra resource describe --name=$name --format=json`
UFBqTable describeResource = TestCommand.runAndParseCommandExpectSuccess(UFBqTable.class, "resource", "describe", "--name=" + name);
// check that the name, project id, dataset id and table id match
assertEquals(name, describeResource.name, "describe resource output matches name");
assertEquals(externalDataset.getProjectId(), describeResource.projectId, "describe resource output matches project id");
assertEquals(externalDataset.getDatasetId(), describeResource.datasetId, "describe resource output matches dataset id");
assertEquals(externalDataTableName, describeResource.dataTableId, "describe resource output matches data table id");
// `terra resource delete --name=$name`
TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + name, "--quiet");
}
use of bio.terra.cli.serialization.userfacing.resource.UFBqTable in project terra-cli by DataBiosphere.
the class BqTableReferenced method updateMultipleOrNoProperties.
@Test
@DisplayName("update a referenced data table, specifying multiple or none of the properties")
void updateMultipleOrNoProperties() throws IOException, InterruptedException {
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 controlledDataset = "controlledDataset";
String datasetId = randomDatasetId();
UFBqDataset createdDataset = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "create", "bq-dataset", "--name=" + controlledDataset, "--dataset-id=" + datasetId);
String tableInControlledDataset = "tableInControlledDataset";
ExternalBQDatasets.createTable(workspaceCreator.getCredentialsWithCloudPlatformScope(), createdDataset.projectId, createdDataset.datasetId, tableInControlledDataset);
// `terra resources add-ref bq-table --name=$name --project-id=$projectId
// --dataset-id=$datasetId --description=$description`
String name = "updateMultipleOrNoProperties";
String description = "updateDescription";
TestCommand.runCommandExpectSuccess("resource", "add-ref", "bq-table", "--name=" + name, "--description=" + description, "--project-id=" + externalDataset.getProjectId(), "--dataset-id=" + externalDataset.getDatasetId(), "--table-id=" + externalDataTableName);
// call update without specifying any properties to modify
// `terra resources update bq-table --name=$name`
String stdErr = TestCommand.runCommandExpectExitCode(1, "resource", "update", "bq-table", "--name=" + name);
assertThat("error message says that at least one property must be specified", stdErr, CoreMatchers.containsString("Specify at least one property to update"));
// update both the name and description
// `terra resources update bq-table --name=$newName --new-name=$newName
// --description=$newDescription`
String newName = "updateMultipleOrNoProperties_NEW";
String newDescription = "updateDescription_NEW";
UFBqTable updateDataTable = TestCommand.runAndParseCommandExpectSuccess(UFBqTable.class, "resource", "update", "bq-table", "--name=" + name, "--new-name=" + newName, "--description=" + newDescription, "--new-project-id=" + createdDataset.projectId, "--new-dataset-id=" + createdDataset.datasetId, "--new-table-id=" + tableInControlledDataset);
assertEquals(newName, updateDataTable.name);
assertEquals(newDescription, updateDataTable.description);
assertEquals(createdDataset.datasetId, updateDataTable.datasetId);
assertEquals(createdDataset.projectId, updateDataTable.projectId);
assertEquals(tableInControlledDataset, updateDataTable.dataTableId);
// `terra resources describe --name=$newName`
UFBqTable describeDataTable = TestCommand.runAndParseCommandExpectSuccess(UFBqTable.class, "resource", "describe", "--name=" + newName);
assertEquals(newDescription, describeDataTable.description);
assertEquals(newName, describeDataTable.name);
assertEquals(createdDataset.projectId, describeDataTable.projectId);
assertEquals(createdDataset.datasetId, describeDataTable.datasetId);
assertEquals(tableInControlledDataset, describeDataTable.dataTableId);
// `terra resource delete --name=$name`
TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + controlledDataset, "--quiet");
TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + newName, "--quiet");
}
use of bio.terra.cli.serialization.userfacing.resource.UFBqTable in project terra-cli by DataBiosphere.
the class BqTableReferenced method updateIndividualProperties.
@Test
@DisplayName("update a referenced 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 add-ref bq-table --name=$name --project-id=$projectId
// --dataset-id=$datasetId --description=$description`
String name = "updateIndividualProperties";
String description = "updateDescription";
TestCommand.runCommandExpectSuccess("resource", "add-ref", "bq-table", "--name=" + name, "--description=" + description, "--project-id=" + externalDataset.getProjectId(), "--dataset-id=" + externalDataset.getDatasetId(), "--table-id=" + externalDataTableName);
// update just the name
// `terra resources update bq-table --name=$name --new-name=$newName`
String newName = "updateIndividualProperties_NEW";
UFBqTable updateDataTable = TestCommand.runAndParseCommandExpectSuccess(UFBqTable.class, "resource", "update", "bq-table", "--name=" + name, "--new-name=" + newName);
assertEquals(newName, updateDataTable.name);
assertEquals(description, updateDataTable.description);
// `terra resources describe --name=$newName`
UFBqTable describeDataTable = TestCommand.runAndParseCommandExpectSuccess(UFBqTable.class, "resource", "describe", "--name=" + newName);
assertEquals(description, describeDataTable.description);
// update just the description
// `terra resources update bq-table --name=$newName --description=$newDescription`
String newDescription = "updateDescription_NEW";
updateDataTable = TestCommand.runAndParseCommandExpectSuccess(UFBqTable.class, "resource", "update", "bq-table", "--name=" + newName, "--description=" + newDescription);
assertEquals(newName, updateDataTable.name);
assertEquals(newDescription, updateDataTable.description);
// `terra resources describe --name=$newName`
describeDataTable = TestCommand.runAndParseCommandExpectSuccess(UFBqTable.class, "resource", "describe", "--name=" + newName);
assertEquals(newDescription, describeDataTable.description);
updateDataTable = TestCommand.runAndParseCommandExpectSuccess(UFBqTable.class, "resource", "update", "bq-table", "--name=" + newName, "--new-table-id=" + externalDataTableName2);
assertEquals(externalDataTableName2, updateDataTable.dataTableId);
assertEquals(externalDataset.getDatasetId(), updateDataTable.datasetId);
assertEquals(externalDataset.getProjectId(), updateDataTable.projectId);
updateDataTable = TestCommand.runAndParseCommandExpectSuccess(UFBqTable.class, "resource", "update", "bq-table", "--name=" + newName, "--new-dataset-id=" + externalDataset2.getDatasetId());
assertEquals(externalDataTableName2, updateDataTable.dataTableId);
assertEquals(externalDataset2.getDatasetId(), updateDataTable.datasetId);
assertEquals(externalDataset2.getProjectId(), updateDataTable.projectId);
}
use of bio.terra.cli.serialization.userfacing.resource.UFBqTable in project terra-cli by DataBiosphere.
the class BqTableReferenced method addWithAllOptions.
@Test
@DisplayName("add a referenced data table, specifying all options")
void addWithAllOptions() throws IOException {
workspaceCreator.login();
// `terra workspace set --id=$id`
TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
// `terra resource add-ref bq-table --name=$name --project-id=$projectId
// --dataset-id=$datasetId --cloning=$cloning
// --description=$description --format=json`
String name = "addWithAllOptions";
CloningInstructionsEnum cloning = CloningInstructionsEnum.NOTHING;
String description = "add with all options";
UFBqTable addedDataTable = TestCommand.runAndParseCommandExpectSuccess(UFBqTable.class, "resource", "add-ref", "bq-table", "--name=" + name, "--project-id=" + externalDataset.getProjectId(), "--dataset-id=" + externalDataset.getDatasetId(), "--table-id=" + externalDataTableName, "--cloning=" + cloning, "--description=" + description);
// check that the properties match
assertEquals(name, addedDataTable.name, "add ref output matches name");
assertEquals(externalDataset.getProjectId(), addedDataTable.projectId, "add ref output matches project id");
assertEquals(externalDataset.getDatasetId(), addedDataTable.datasetId, "add ref output matches dataset id");
assertEquals(externalDataTableName, addedDataTable.dataTableId, "add ref output matches data table id");
assertEquals(cloning, addedDataTable.cloningInstructions, "add ref output matches cloning");
assertEquals(description, addedDataTable.description, "add ref output matches description");
// `terra resource describe --name=$name --format=json`
UFBqTable describeResource = TestCommand.runAndParseCommandExpectSuccess(UFBqTable.class, "resource", "describe", "--name=" + name);
// check that the properties match
assertEquals(name, describeResource.name, "describe resource output matches name");
assertEquals(externalDataset.getProjectId(), describeResource.projectId, "describe resource output matches project id");
assertEquals(externalDataset.getDatasetId(), describeResource.datasetId, "describe resource output matches dataset id");
assertEquals(externalDataTableName, describeResource.dataTableId, "describe resource output matches data table id");
assertEquals(cloning, describeResource.cloningInstructions, "describe output matches cloning");
assertEquals(description, describeResource.description, "describe output matches description");
// `terra resources delete --name=$name`
TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + name, "--quiet");
}
Aggregations