Search in sources :

Example 1 with RevokeSecurityGroupIngressResult

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

the class AWSSecurityGroupClient method removeIngressRules.

public DeferredResult<Void> removeIngressRules(String groupId, List<IpPermission> rules) {
    if (CollectionUtils.isNotEmpty(rules)) {
        RevokeSecurityGroupIngressRequest req = new RevokeSecurityGroupIngressRequest().withGroupId(groupId).withIpPermissions(rules);
        String message = "Remove Ingress Rules from AWS Security Group with id [" + groupId + "].";
        AWSDeferredResultAsyncHandler<RevokeSecurityGroupIngressRequest, RevokeSecurityGroupIngressResult> handler = new AWSDeferredResultAsyncHandler<RevokeSecurityGroupIngressRequest, RevokeSecurityGroupIngressResult>(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("Ingress rules cannot be removed because " + "they do not exist: %s", Utils.toString(e)));
                    return null;
                } else {
                    return e;
                }
            }
        };
        this.client.revokeSecurityGroupIngressAsync(req, handler);
        return handler.toDeferredResult().thenApply(r -> (Void) null);
    } else {
        return DeferredResult.completed(null);
    }
}
Also used : RevokeSecurityGroupIngressResult(com.amazonaws.services.ec2.model.RevokeSecurityGroupIngressResult) AWSUtils(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) RevokeSecurityGroupIngressRequest(com.amazonaws.services.ec2.model.RevokeSecurityGroupIngressRequest)

Aggregations

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