use of software.amazon.awssdk.services.s3.model.Tag in project herd by FINRAOS.
the class S3DaoTest method testTagObjectsAmazonServiceException.
@Test
public void testTagObjectsAmazonServiceException() {
// Try to retrieve S3 object metadata when AmazonServiceException is expected tpo be thrown..
try {
S3FileTransferRequestParamsDto params = new S3FileTransferRequestParamsDto();
params.setS3BucketName(MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_INTERNAL_ERROR);
params.setFiles(Arrays.asList(new File(TARGET_S3_KEY)));
s3Dao.tagObjects(params, new S3FileTransferRequestParamsDto(), new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE));
fail();
} catch (IllegalStateException e) {
assertEquals(String.format("Failed to tag S3 object with \"%s\" key in \"%s\" bucket. " + "Reason: InternalError (Service: null; Status Code: 0; Error Code: InternalError; Request ID: null)", TARGET_S3_KEY, MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_INTERNAL_ERROR), e.getMessage());
}
}
use of software.amazon.awssdk.services.s3.model.Tag in project photon-model by vmware.
the class AWSComputeStateCreationAdapterService method updateTagLinks.
/**
* Updates tag links of existing computes using TagsUtil.
*/
private DeferredResult<AWSComputeStateCreationContext> updateTagLinks(AWSComputeStateCreationContext context) {
if (context.request.instancesToBeUpdated == null || context.request.instancesToBeUpdated.size() == 0) {
logFine(() -> "No local compute states to be updated so there are no tags to update.");
return DeferredResult.completed(context);
} else {
List<DeferredResult<Set<String>>> updateCSTagLinksOps = new ArrayList<>();
for (String instanceId : context.request.instancesToBeUpdated.keySet()) {
Instance instance = context.request.instancesToBeUpdated.get(instanceId);
ComputeState existingComputeState = context.request.computeStatesToBeUpdated.get(instanceId);
Map<String, String> remoteTags = new HashMap<>();
for (Tag awsInstanceTag : instance.getTags()) {
if (!awsInstanceTag.getKey().equals(AWSConstants.AWS_TAG_NAME)) {
remoteTags.put(awsInstanceTag.getKey(), awsInstanceTag.getValue());
}
}
updateCSTagLinksOps.add(updateLocalTagStates(this, existingComputeState, remoteTags, null));
}
return DeferredResult.allOf(updateCSTagLinksOps).thenApply(gnore -> context);
}
}
use of software.amazon.awssdk.services.s3.model.Tag in project photon-model by vmware.
the class AWSComputeStateCreationAdapterService method createInternalTypeTags.
private void createInternalTypeTags(AWSComputeStateCreationContext context, AWSComputeStateCreationStage next) {
// Go over the list of internal tags to be created. Find whatever already does not have an
// associated tag state and create an operation for its creation.
List<Operation> joinOperations = new ArrayList<>();
for (String resourceType : internalTagList) {
TagState typeTag = newTagState(TAG_KEY_TYPE, resourceType, false, context.request.tenantLinks);
Operation op = Operation.createPost(this, TagService.FACTORY_LINK).setBody(typeTag);
joinOperations.add(op);
}
OperationJoin.create(joinOperations).setCompletion((ops, exs) -> {
if (exs != null) {
exs.values().forEach(ex -> logWarning(() -> String.format("Error creating internal tag%s", ex.getMessage())));
context.creationStage = next;
handleComputeStateCreateOrUpdate(context);
return;
}
for (String internalTagValue : internalTagList) {
TagState tagState = newTagState(TAG_KEY_TYPE, internalTagValue, false, context.request.tenantLinks);
context.internalTagLinksMap.put(tagState.value, new HashSet<>(Arrays.asList(tagState.documentSelfLink)));
}
context.creationStage = next;
handleComputeStateCreateOrUpdate(context);
}).sendWith(this);
}
use of software.amazon.awssdk.services.s3.model.Tag in project photon-model by vmware.
the class AWSNetworkStateEnumerationAdapterService method createTags.
/**
* Gets the Networks and Subnets tags information and creates TagState for each tag
*/
private void createTags(AWSNetworkStateCreationContext context, AWSNetworkStateCreationStage next) {
// Collect all tags in a List
List<Tag> allNetworkAndSubnetsTags = context.awsVpcs.values().stream().filter(vpc -> !context.localNetworkStateMap.containsKey(vpc.getVpcId())).flatMap(vpc -> vpc.getTags().stream()).collect(Collectors.toList());
allNetworkAndSubnetsTags.addAll(context.awsSubnets.values().stream().filter(subnet -> !context.localSubnetStateMap.containsKey(subnet.getSubnetId())).flatMap(subnet -> subnet.getTags().stream()).collect(Collectors.toList()));
// 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<>();
allNetworkAndSubnetsTags.stream().filter(t -> !AWSConstants.AWS_TAG_NAME.equals(t.getKey())).forEach(t -> {
TagState tagState = newTagState(t.getKey(), t.getValue(), true, context.request.tenantLinks);
Operation createTagOp = Operation.createPost(this, TagService.FACTORY_LINK).setBody(tagState);
operations.add(createTagOp);
tagsCreationOperationIdsMap.put(createTagOp.getId(), t);
});
if (operations.isEmpty()) {
context.networkCreationStage = next;
handleNetworkStateChanges(context);
} else {
OperationJoin.create(operations).setCompletion((ops, exs) -> {
if (exs != null && !exs.isEmpty()) {
this.logWarning("Failure creating external tags for network and subnets: %s", exs.get(0).getMessage());
}
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.networkCreationStage = next;
handleNetworkStateChanges(context);
}).sendWith(this);
}
}
use of software.amazon.awssdk.services.s3.model.Tag in project photon-model by vmware.
the class AWSNetworkStateEnumerationAdapterService method createInternalTypeTags.
/**
* Method to create the internal tags for subnets and VPCs.
*/
private void createInternalTypeTags(AWSNetworkStateCreationContext context, AWSNetworkStateCreationStage next) {
// Go over the list of internal tags to be created. Find whatever already does not have an
// associated tag state and create an operation for its creation.
List<Operation> joinOperations = new ArrayList<>();
for (String resourceType : internalTagList) {
TagState typeTag = newTagState(TAG_KEY_TYPE, resourceType, false, context.request.tenantLinks);
Operation op = Operation.createPost(this, TagService.FACTORY_LINK).setBody(typeTag);
joinOperations.add(op);
}
OperationJoin.create(joinOperations).setCompletion((ops, exs) -> {
if (exs != null) {
exs.values().forEach(ex -> logWarning(() -> String.format("Error creating internal tag : %s", ex.getMessage())));
context.networkCreationStage = next;
handleNetworkStateChanges(context);
return;
}
for (String internalTagValue : internalTagList) {
TagState tagState = newTagState(TAG_KEY_TYPE, internalTagValue, false, context.request.tenantLinks);
if (internalTagValue.equalsIgnoreCase(AWSResourceType.ec2_vpc.toString())) {
context.networkInternalTagsMap.put(PhotonModelConstants.TAG_KEY_TYPE, tagState.value);
context.networkInternalTagLinksSet.add(tagState.documentSelfLink);
} else {
context.subnetInternalTagsMap.put(PhotonModelConstants.TAG_KEY_TYPE, tagState.value);
context.subnetInternalTagLinksSet.add(tagState.documentSelfLink);
}
}
context.networkCreationStage = next;
handleNetworkStateChanges(context);
}).sendWith(this);
}
Aggregations