Search in sources :

Example 1 with AwsServiceEndpointView

use of com.sequenceiq.cloudbreak.cloud.aws.view.AwsServiceEndpointView in project cloudbreak by hortonworks.

the class AwsNetworkCfTemplateProvider method createInterfaceServiceEndpointsIfNeeded.

private List<AwsServiceEndpointView> createInterfaceServiceEndpointsIfNeeded(NetworkCreationRequest networkCreationRequest, List<SubnetRequest> subnets) {
    PrivateEndpointType privateEndpointType = networkCreationRequest.getEndpointType();
    if (USE_VPC_ENDPOINT == privateEndpointType && CollectionUtils.isNotEmpty(interfaceServices)) {
        List<AwsServiceEndpointView> interfaceServiceEndpoints = createInterfaceServiceEndpoints(networkCreationRequest, subnets);
        LOGGER.debug("The following interface endpoints will be created in the new vpc: {}", interfaceServiceEndpoints);
        return interfaceServiceEndpoints;
    } else {
        LOGGER.debug("No interface endpoints will be created in the new vpc. serviceEndpointCreation: {}, interfaceServices: {}", privateEndpointType, interfaceServices);
        return List.of();
    }
}
Also used : PrivateEndpointType(com.sequenceiq.common.model.PrivateEndpointType) AwsServiceEndpointView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsServiceEndpointView)

Example 2 with AwsServiceEndpointView

use of com.sequenceiq.cloudbreak.cloud.aws.view.AwsServiceEndpointView in project cloudbreak by hortonworks.

the class AwsNetworkCfTemplateProvider method createInterfaceServiceEndpoints.

private List<AwsServiceEndpointView> createInterfaceServiceEndpoints(NetworkCreationRequest networkCreationRequest, List<SubnetRequest> subnets) {
    Map<String, String> endpointNameMappings = interfaceServices.stream().collect(Collectors.toMap(s -> String.format(VPC_INTERFACE_SERVICE_ENDPOINT_NAME_PATTERN, networkCreationRequest.getRegion().value(), s), s -> s));
    List<ServiceDetail> serviceDetails = describeVpcServiceDetails(networkCreationRequest, endpointNameMappings);
    Map<String, SubnetRequest> subnetByZoneMap = createPublicSubnetByZoneMap(subnets);
    List<AwsServiceEndpointView> interfaceServceEndpoints = new ArrayList<>();
    for (ServiceDetail serviceDetail : serviceDetails) {
        List<SubnetRequest> subnetRequests = serviceDetail.getAvailabilityZones().stream().filter(az -> subnetByZoneMap.containsKey(az)).map(az -> subnetByZoneMap.get(az)).collect(Collectors.toList());
        if (!subnetRequests.isEmpty()) {
            interfaceServceEndpoints.add(new AwsServiceEndpointView(endpointNameMappings.get(serviceDetail.getServiceName()), subnetRequests));
        }
    }
    return interfaceServceEndpoints;
}
Also used : TemplateException(freemarker.template.TemplateException) LoggerFactory(org.slf4j.LoggerFactory) NetworkCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Strings(com.google.common.base.Strings) SubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) USE_VPC_ENDPOINT(com.sequenceiq.common.model.PrivateEndpointType.USE_VPC_ENDPOINT) Map(java.util.Map) Template(freemarker.template.Template) Logger(org.slf4j.Logger) IOException(java.io.IOException) PrivateEndpointType(com.sequenceiq.common.model.PrivateEndpointType) Collectors(java.util.stream.Collectors) ServiceDetail(com.amazonaws.services.ec2.model.ServiceDetail) FreeMarkerTemplateUtils(com.sequenceiq.cloudbreak.util.FreeMarkerTemplateUtils) List(java.util.List) Component(org.springframework.stereotype.Component) AwsServiceEndpointView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsServiceEndpointView) Configuration(freemarker.template.Configuration) SubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest) ArrayList(java.util.ArrayList) ServiceDetail(com.amazonaws.services.ec2.model.ServiceDetail) AwsServiceEndpointView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsServiceEndpointView)

Aggregations

AwsServiceEndpointView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsServiceEndpointView)2 PrivateEndpointType (com.sequenceiq.common.model.PrivateEndpointType)2 ServiceDetail (com.amazonaws.services.ec2.model.ServiceDetail)1 Strings (com.google.common.base.Strings)1 AmazonEc2Client (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 NetworkCreationRequest (com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest)1 SubnetRequest (com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest)1 FreeMarkerTemplateUtils (com.sequenceiq.cloudbreak.util.FreeMarkerTemplateUtils)1 USE_VPC_ENDPOINT (com.sequenceiq.common.model.PrivateEndpointType.USE_VPC_ENDPOINT)1 Configuration (freemarker.template.Configuration)1 Template (freemarker.template.Template)1 TemplateException (freemarker.template.TemplateException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1