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);
}
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());
}
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));
}
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));
}
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());
}
Aggregations