use of com.sequenceiq.common.api.type.OutboundInternetTraffic in project cloudbreak by hortonworks.
the class OutboundInternetTrafficValidator method isValid.
@Override
public boolean isValid(EnvironmentNetworkRequest environmentNetworkRequest, ConstraintValidatorContext constraintValidatorContext) {
OutboundInternetTraffic outboundInternetTraffic = environmentNetworkRequest.getOutboundInternetTraffic();
ServiceEndpointCreation serviceEndpointCreation = environmentNetworkRequest.getServiceEndpointCreation();
if (outboundInternetTraffic == OutboundInternetTraffic.DISABLED && (serviceEndpointCreation == null || serviceEndpointCreation == ServiceEndpointCreation.DISABLED)) {
return false;
}
return true;
}
use of com.sequenceiq.common.api.type.OutboundInternetTraffic in project cloudbreak by hortonworks.
the class SecurityGroupBuilderUtil method egress.
public void egress(AmazonEc2Client amazonEc2Client, AuthenticatedContext ac, AwsNetworkView awsNetworkView, String securityGroupId, List<IpPermission> egress) {
OutboundInternetTraffic outboundInternetTraffic = awsNetworkView.getOutboundInternetTraffic();
List<String> prefixListIds = awsNetworkService.getPrefixListIds(amazonEc2Client, ac.getCloudContext().getLocation().getRegion().getRegionName(), outboundInternetTraffic);
List<String> vpcCidrs = awsNetworkService.getVpcCidrs(ac, awsNetworkView);
if (outboundInternetTraffic == OutboundInternetTraffic.DISABLED && (!prefixListIds.isEmpty() || !vpcCidrs.isEmpty())) {
List<IpPermission> permissions = new ArrayList<>();
for (String existingVpcCidr : vpcCidrs) {
IpPermission e = new IpPermission().withIpProtocol("-1").withIpv4Ranges(new IpRange().withCidrIp(existingVpcCidr));
if (!egress.contains(e)) {
permissions.add(e);
}
}
for (String prefixListId : prefixListIds) {
IpPermission e = new IpPermission().withIpProtocol("-1").withFromPort(0).withToPort(TO_PORT).withPrefixListIds(new PrefixListId().withPrefixListId(prefixListId));
if (!egress.contains(e)) {
permissions.add(e);
}
}
if (!permissions.isEmpty()) {
AuthorizeSecurityGroupEgressRequest reguest = new AuthorizeSecurityGroupEgressRequest().withGroupId(securityGroupId).withIpPermissions(permissions);
amazonEc2Client.addEgress(reguest);
LOGGER.info("Egress added to {}", securityGroupId);
} else {
LOGGER.debug("No permission for egress request, skip it");
}
} else {
LOGGER.debug("Egress creation skipped: {}, prefix list size: {}, vpc cidrs size: {}", outboundInternetTraffic, prefixListIds.size(), vpcCidrs.size());
}
}
Aggregations