Search in sources :

Example 1 with CloudResourceUid

use of bio.terra.janitor.model.CloudResourceUid in project terra-cloud-resource-lib by DataBiosphere.

the class StorageCow method create.

/**
 * See {@link Storage#create(BucketInfo, Storage.BucketTargetOption...)}.
 */
public BucketCow create(BucketInfo bucketInfo) {
    CleanupRecorder.record(new CloudResourceUid().googleBucketUid(new GoogleBucketUid().bucketName(bucketInfo.getName())), clientConfig);
    Bucket bucket = operationAnnotator.executeCowOperation(StorageOperation.GOOGLE_CREATE_BUCKET, () -> storage.create(bucketInfo), () -> SerializeUtils.convert(bucketInfo));
    return new BucketCow(clientConfig, bucket);
}
Also used : CloudResourceUid(bio.terra.janitor.model.CloudResourceUid) GoogleBucketUid(bio.terra.janitor.model.GoogleBucketUid)

Example 2 with CloudResourceUid

use of bio.terra.janitor.model.CloudResourceUid in project terra-cloud-resource-lib by DataBiosphere.

the class BlobCowTest method copyTo.

@Test
public void copyTo() throws Exception {
    BlobId sourceBlobId = BlobId.of(reusableBucket.getBucketInfo().getName(), IntegrationUtils.randomName());
    BlobId targetBlobId = BlobId.of(reusableBucket.getBucketInfo().getName(), IntegrationUtils.randomName());
    final String contents = "hello my blob";
    BlobCow source = createBlobWithContents(storageCow, sourceBlobId, contents);
    assertEquals(contents, StorageIntegrationUtils.readContents(source));
    List<CloudResourceUid> record = CleanupRecorder.startNewRecordForTesting();
    assertNull(storageCow.get(targetBlobId));
    CopyWriter copyWriter = source.copyTo(targetBlobId);
    copyWriter.getResult();
    BlobCow target = storageCow.get(targetBlobId);
    assertEquals(contents, StorageIntegrationUtils.readContents(target));
    assertThat(record, Matchers.contains(new CloudResourceUid().googleBlobUid(new GoogleBlobUid().blobName(targetBlobId.getName()).bucketName(targetBlobId.getBucket()))));
    assertTrue(source.delete());
    assertTrue(target.delete());
}
Also used : CloudResourceUid(bio.terra.janitor.model.CloudResourceUid) GoogleBlobUid(bio.terra.janitor.model.GoogleBlobUid) BlobId(com.google.cloud.storage.BlobId) CopyWriter(com.google.cloud.storage.CopyWriter) Test(org.junit.jupiter.api.Test)

Example 3 with CloudResourceUid

use of bio.terra.janitor.model.CloudResourceUid in project terra-cloud-resource-lib by DataBiosphere.

the class StorageCowTest method createGetDeleteBucket.

@Test
public void createGetDeleteBucket() {
    List<CloudResourceUid> record = CleanupRecorder.startNewRecordForTesting();
    String bucketName = IntegrationUtils.randomName();
    assertNull(storageCow.get(bucketName));
    BucketCow createdBucket = storageCow.create(BucketInfo.of(bucketName));
    assertEquals(bucketName, createdBucket.getBucketInfo().getName());
    assertEquals(bucketName, storageCow.get(bucketName).getBucketInfo().getName());
    assertThat(record, Matchers.contains(new CloudResourceUid().googleBucketUid(new GoogleBucketUid().bucketName(bucketName))));
    assertTrue(storageCow.delete(bucketName));
    assertNull(storageCow.get(bucketName));
}
Also used : CloudResourceUid(bio.terra.janitor.model.CloudResourceUid) GoogleBucketUid(bio.terra.janitor.model.GoogleBucketUid) Test(org.junit.jupiter.api.Test)

Example 4 with CloudResourceUid

use of bio.terra.janitor.model.CloudResourceUid in project terra-cloud-resource-lib by DataBiosphere.

the class StorageCowTest method createGetDeleteBlob.

@Test
public void createGetDeleteBlob() {
    BlobId blobId = BlobId.of(reusableBucket.getBucketInfo().getName(), IntegrationUtils.randomName());
    assertNull(storageCow.get(blobId));
    List<CloudResourceUid> record = CleanupRecorder.startNewRecordForTesting();
    BlobCow createdBlob = storageCow.create(BlobInfo.newBuilder(blobId).build());
    assertEquals(blobId.getName(), createdBlob.getBlobInfo().getName());
    assertEquals(blobId.getName(), storageCow.get(blobId).getBlobInfo().getName());
    assertThat(record, Matchers.contains(new CloudResourceUid().googleBlobUid(new GoogleBlobUid().bucketName(blobId.getBucket()).blobName(blobId.getName()))));
    assertTrue(storageCow.delete(blobId));
    assertNull(storageCow.get(blobId));
}
Also used : CloudResourceUid(bio.terra.janitor.model.CloudResourceUid) GoogleBlobUid(bio.terra.janitor.model.GoogleBlobUid) Test(org.junit.jupiter.api.Test)

Example 5 with CloudResourceUid

use of bio.terra.janitor.model.CloudResourceUid in project terra-cloud-resource-lib by DataBiosphere.

the class ComputeRequestDataTest method serializeCreateNetwork.

@Test
public void serializeCreateNetwork() {
    CreateNetworkRequestData createNetwork = CreateNetworkRequestData.builder().setName("my-network").setTenantId("my-tenant").setSubscriptionId("my-sub").setResourceGroupName("my-rg").setRegion(Region.US_EAST).setAddressSpaceCidr("192.168.0.0/16").setSubnetName("my-subnet").setAddressPrefix("192.168.1.0/24").setNetworkSecurityGroup(mockNetworkSecurityGroup()).build();
    assertEquals(ComputeManagerOperation.AZURE_CREATE_NETWORK, createNetwork.cloudOperation());
    assertEquals("{\"tenantId\":\"my-tenant\",\"subscriptionId\":\"my-sub\",\"resourceGroupName\":\"my-rg\"," + "\"name\":\"my-network\",\"region\":\"eastus\"," + "\"addressSpaceCidr\":\"192.168.0.0/16\",\"subnetName\":\"my-subnet\"," + "\"addressPrefix\":\"192.168.1.0/24\",\"networkSecurityGroupName\":\"my-nsg\"}", createNetwork.serialize().toString());
    assertEquals(Optional.of(new CloudResourceUid().azureNetwork(new AzureNetwork().resourceGroup(azureResourceGroup(createNetwork)).networkName("my-network"))), createNetwork.resourceUidCreation());
}
Also used : CloudResourceUid(bio.terra.janitor.model.CloudResourceUid) CreateNetworkRequestData(bio.terra.cloudres.azure.resourcemanager.compute.data.CreateNetworkRequestData) AzureNetwork(bio.terra.janitor.model.AzureNetwork) Test(org.junit.jupiter.api.Test)

Aggregations

CloudResourceUid (bio.terra.janitor.model.CloudResourceUid)12 Test (org.junit.jupiter.api.Test)9 GoogleBlobUid (bio.terra.janitor.model.GoogleBlobUid)3 GoogleBucketUid (bio.terra.janitor.model.GoogleBucketUid)2 CreateDiskRequestData (bio.terra.cloudres.azure.resourcemanager.compute.data.CreateDiskRequestData)1 CreateNetworkRequestData (bio.terra.cloudres.azure.resourcemanager.compute.data.CreateNetworkRequestData)1 CreateNetworkSecurityGroupRequestData (bio.terra.cloudres.azure.resourcemanager.compute.data.CreateNetworkSecurityGroupRequestData)1 CreatePublicIpRequestData (bio.terra.cloudres.azure.resourcemanager.compute.data.CreatePublicIpRequestData)1 CreateVirtualMachineRequestData (bio.terra.cloudres.azure.resourcemanager.compute.data.CreateVirtualMachineRequestData)1 AzureDisk (bio.terra.janitor.model.AzureDisk)1 AzureNetwork (bio.terra.janitor.model.AzureNetwork)1 AzureNetworkSecurityGroup (bio.terra.janitor.model.AzureNetworkSecurityGroup)1 AzurePublicIp (bio.terra.janitor.model.AzurePublicIp)1 AzureVirtualMachine (bio.terra.janitor.model.AzureVirtualMachine)1 GoogleBigQueryDatasetUid (bio.terra.janitor.model.GoogleBigQueryDatasetUid)1 GoogleBigQueryTableUid (bio.terra.janitor.model.GoogleBigQueryTableUid)1 Dataset (com.google.api.services.bigquery.model.Dataset)1 DatasetReference (com.google.api.services.bigquery.model.DatasetReference)1 Table (com.google.api.services.bigquery.model.Table)1 TableReference (com.google.api.services.bigquery.model.TableReference)1