use of software.amazon.awssdk.services.s3.model.Tag in project herd by FINRAOS.
the class S3ServiceTest method testTagObjects.
@Test
public void testTagObjects() {
// Create an S3 file transfer request parameters DTO to access S3 objects.
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
s3FileTransferRequestParamsDto.setFiles(Arrays.asList(new File(TEST_S3_KEY_PREFIX + "/" + LOCAL_FILE)));
// Create an S3 file transfer request parameters DTO to tag S3 objects.
S3FileTransferRequestParamsDto s3ObjectTaggerParamsDto = new S3FileTransferRequestParamsDto();
s3ObjectTaggerParamsDto.setAwsAccessKeyId(AWS_ASSUMED_ROLE_ACCESS_KEY);
s3ObjectTaggerParamsDto.setAwsSecretKey(AWS_ASSUMED_ROLE_SECRET_KEY);
s3ObjectTaggerParamsDto.setSessionToken(AWS_ASSUMED_ROLE_SESSION_TOKEN);
// Create an S3 object tag.
Tag tag = new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE);
// Call the method under test.
s3Service.tagObjects(s3FileTransferRequestParamsDto, s3ObjectTaggerParamsDto, tag);
// Verify the external calls.
verify(s3Dao).tagObjects(s3FileTransferRequestParamsDto, s3ObjectTaggerParamsDto, tag);
verifyNoMoreInteractions(s3Dao);
}
use of software.amazon.awssdk.services.s3.model.Tag in project photon-model by vmware.
the class AWSRemoteCleanup method cleanUpVpc.
/**
* Cleaning all VPC's that are not tagged with a name: enumtest-vpc or a default VPC in US_EAST_1 region
* Deleting a VPC would require its dependencies to be deleted in the following order:
* 1) EC2 Instances
* 2) NAT Gateway
* 3) Internet Gateway
* 4) VPN Gateway
* 5) Network ACL's
* 6) Security Group ( not deleting default SG)
* 7) Subnets
* NOTE: Not deleting RouteTables currently
*/
@Test
public void cleanUpVpc() {
if (this.isMock) {
return;
}
AmazonEC2 usEastEc2Client = this.ec2Clients.get(US_EAST_1_TAG);
DescribeVpcsResult vpcsResult = usEastEc2Client.describeVpcs();
List<Vpc> vpcs = vpcsResult.getVpcs();
List<String> vpcIdsToBeDeleted = new ArrayList<>();
List<String> enumTestVpcIds = new ArrayList<>();
try {
vpcs.stream().forEach(vpc -> {
vpc.getTags().stream().filter(tag -> tag.getKey().equalsIgnoreCase(NAME_TAG_KEY) && this.vpcTagsNotToBeDeleted.contains(tag.getValue().toLowerCase())).forEach(tag -> enumTestVpcIds.add(vpc.getVpcId()));
if (!vpc.getIsDefault()) {
vpcIdsToBeDeleted.add(vpc.getVpcId());
}
});
vpcIdsToBeDeleted.removeAll(enumTestVpcIds);
vpcIdsToBeDeleted.stream().forEach(vpcId -> {
DescribeInstancesRequest instancesRequest = new DescribeInstancesRequest().withFilters(new Filter(VPC_KEY, Collections.singletonList(vpcId)));
DescribeInstancesResult instancesResult = usEastEc2Client.describeInstances(instancesRequest);
deleteAwsEc2instances(vpcIdsToBeDeleted, instancesResult, usEastEc2Client);
deleteNATGateway(vpcId, usEastEc2Client);
deleteNetworkInterfaces(vpcId, usEastEc2Client);
deleteInternetGateways(vpcId, usEastEc2Client);
deleteVirtualPrivateGateways(vpcId, usEastEc2Client);
disassociateAndDeleteNetworkACLs(vpcId, usEastEc2Client);
deleteSecurityGroups(vpcId, usEastEc2Client);
deleteSubnets(vpcId, usEastEc2Client);
DeleteVpcRequest deleteVpcRequest = new DeleteVpcRequest().withVpcId(vpcId);
this.host.log("Terminating stale vpc: %s", vpcId);
usEastEc2Client.deleteVpc(deleteVpcRequest);
});
} catch (Exception e) {
this.host.log(Level.INFO, e.getMessage());
}
}
use of software.amazon.awssdk.services.s3.model.Tag in project photon-model by vmware.
the class AWSUtils method tagResourcesWithName.
/**
* Synchronous Tagging of one or many AWS resources with the provided name.
*/
public static void tagResourcesWithName(AmazonEC2AsyncClient client, String name, String... resourceIds) {
Tag awsNameTag = new Tag().withKey(AWS_TAG_NAME).withValue(name);
tagResources(client, Collections.singletonList(awsNameTag), resourceIds);
}
use of software.amazon.awssdk.services.s3.model.Tag in project photon-model by vmware.
the class AWSComputeStateCreationAdapterService method createTags.
/**
* POSTs all tags for newly discovered instances. Even if some tags already exist we rely on
* IDEMPOTENT_POST behaviour and POST them again. All tags that got created successfully are
* stored in createdExternalTags list.
*/
private void createTags(AWSComputeStateCreationContext context, AWSComputeStateCreationStage next) {
// Get all tags from the instances to be created
Set<Tag> create = context.request.instancesToBeCreated.stream().flatMap(i -> i.getTags().stream()).collect(Collectors.toSet());
// Put them in a set to remove the duplicates
Set<Tag> allTags = new HashSet<>();
allTags.addAll(create);
// POST each of the tags. If a tag exists it won't be created again. We don't want the name
// tags, so filter them out
List<Operation> operations = new ArrayList<>();
Map<Long, Tag> tagsCreationOperationIdsMap = new ConcurrentHashMap<>();
allTags.stream().filter(t -> !AWSConstants.AWS_TAG_NAME.equals(t.getKey())).forEach(t -> {
TagState tagState = newTagState(t.getKey(), t.getValue(), true, context.request.tenantLinks);
Operation op = Operation.createPost(this, TagService.FACTORY_LINK).setBody(tagState);
operations.add(op);
tagsCreationOperationIdsMap.put(op.getId(), t);
});
if (operations.isEmpty()) {
context.creationStage = next;
handleComputeStateCreateOrUpdate(context);
} else {
OperationJoin.create(operations).setCompletion((ops, exs) -> {
if (exs != null && !exs.isEmpty()) {
logSevere(() -> String.format("Error creating %s external tags for compute" + "states: %s", exs.size(), Utils.toString(exs.get(0))));
}
ops.values().stream().filter(operation -> operation.getStatusCode() == Operation.STATUS_CODE_OK || operation.getStatusCode() == Operation.STATUS_CODE_NOT_MODIFIED).forEach(operation -> {
if (tagsCreationOperationIdsMap.containsKey(operation.getId())) {
context.createdExternalTags.add(tagsCreationOperationIdsMap.get(operation.getId()));
}
});
context.creationStage = next;
handleComputeStateCreateOrUpdate(context);
}).sendWith(this);
}
}
use of software.amazon.awssdk.services.s3.model.Tag in project photon-model by vmware.
the class TestAWSProvisionTask method assertTags.
private void assertTags(Set<TagState> expectedTagStates, Instance instance, String instanceName) {
Set<Tag> expectedTags = expectedTagStates.stream().map(ts -> new Tag(ts.key, ts.value)).collect(Collectors.toSet());
Set<Tag> actualTags = new HashSet<>(instance.getTags());
// account for the name tag
assertEquals(expectedTags.size() + 1, actualTags.size());
assertTrue(actualTags.containsAll(expectedTags));
Tag nameTag = new Tag(AWSConstants.AWS_TAG_NAME, instanceName);
assertTrue(actualTags.contains(nameTag));
}
Aggregations