Search in sources :

Example 1 with UFResource

use of bio.terra.cli.serialization.userfacing.UFResource 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 2 with UFResource

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

the class Describe method execute.

/**
 * Describe a resource.
 */
@Override
protected void execute() {
    workspaceOption.overrideIfSpecified();
    Resource resource = Context.requireWorkspace().getResource(resourceNameOption.name);
    formatOption.printReturnValue(resource.serializeToCommand(), UFResource::print);
}
Also used : UFResource(bio.terra.cli.serialization.userfacing.UFResource) UFResource(bio.terra.cli.serialization.userfacing.UFResource) Resource(bio.terra.cli.businessobject.Resource) WorkspaceOverride(bio.terra.cli.command.shared.options.WorkspaceOverride)

Aggregations

UFResource (bio.terra.cli.serialization.userfacing.UFResource)2 Resource (bio.terra.cli.businessobject.Resource)1 WorkspaceOverride (bio.terra.cli.command.shared.options.WorkspaceOverride)1 UFClonedResource (bio.terra.cli.serialization.userfacing.UFClonedResource)1 UFClonedWorkspace (bio.terra.cli.serialization.userfacing.UFClonedWorkspace)1 UFWorkspace (bio.terra.cli.serialization.userfacing.UFWorkspace)1 UFBqDataset (bio.terra.cli.serialization.userfacing.resource.UFBqDataset)1 UFGcsBucket (bio.terra.cli.serialization.userfacing.resource.UFGcsBucket)1 UFGitRepo (bio.terra.cli.serialization.userfacing.resource.UFGitRepo)1 Test (org.junit.jupiter.api.Test)1