Search in sources :

Example 1 with RevokeSecurityGroupEgressResult

use of com.amazonaws.services.ec2.model.RevokeSecurityGroupEgressResult in project photon-model by vmware.

the class AWSSecurityGroupClient method removeEgressRules.

public DeferredResult<Void> removeEgressRules(String groupId, List<IpPermission> rules) {
    if (CollectionUtils.isNotEmpty(rules)) {
        RevokeSecurityGroupEgressRequest req = new RevokeSecurityGroupEgressRequest().withGroupId(groupId).withIpPermissions(rules);
        String message = "Remove Egress Rules from AWS Security Group with id [" + groupId + "].";
        AWSDeferredResultAsyncHandler<RevokeSecurityGroupEgressRequest, RevokeSecurityGroupEgressResult> handler = new AWSDeferredResultAsyncHandler<RevokeSecurityGroupEgressRequest, RevokeSecurityGroupEgressResult>(this.service, message) {

            @Override
            protected Exception consumeError(Exception e) {
                if (e instanceof AmazonEC2Exception && ((AmazonEC2Exception) e).getErrorCode().equals(SECURITY_GROUP_RULE_NOT_FOUND)) {
                    Utils.log(AWSUtils.class, AWSUtils.class.getSimpleName(), Level.WARNING, () -> String.format("Egress rules cannot be removed because " + "they do not exist: %s", Utils.toString(e)));
                    return null;
                } else {
                    return e;
                }
            }
        };
        this.client.revokeSecurityGroupEgressAsync(req, handler);
        return handler.toDeferredResult().thenApply(r -> (Void) null);
    } else {
        return DeferredResult.completed(null);
    }
}
Also used : RevokeSecurityGroupEgressRequest(com.amazonaws.services.ec2.model.RevokeSecurityGroupEgressRequest) AWSUtils(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils) RevokeSecurityGroupEgressResult(com.amazonaws.services.ec2.model.RevokeSecurityGroupEgressResult) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception)

Aggregations

AmazonServiceException (com.amazonaws.AmazonServiceException)1 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)1 RevokeSecurityGroupEgressRequest (com.amazonaws.services.ec2.model.RevokeSecurityGroupEgressRequest)1 RevokeSecurityGroupEgressResult (com.amazonaws.services.ec2.model.RevokeSecurityGroupEgressResult)1 AWSUtils (com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils)1