Search in sources :

Example 1 with ServiceDetail

use of com.amazonaws.services.ec2.model.ServiceDetail 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)

Example 2 with ServiceDetail

use of com.amazonaws.services.ec2.model.ServiceDetail in project cloudbreak by hortonworks.

the class AwsNetworkCfTemplateProviderTest method createDescribeVpcEndpointServicesResultWithDifferentAzs.

private static DescribeVpcEndpointServicesResult createDescribeVpcEndpointServicesResultWithDifferentAzs() {
    DescribeVpcEndpointServicesResult describeVpcEndpointServicesResult = new DescribeVpcEndpointServicesResult();
    List<ServiceDetail> serviceDetails = new ArrayList<>();
    ServiceDetail serviceDetail1 = new ServiceDetail().withServiceName(String.format(AwsNetworkCfTemplateProvider.VPC_INTERFACE_SERVICE_ENDPOINT_NAME_PATTERN, "region", "interface1"));
    serviceDetail1.setAvailabilityZones(List.of("az1"));
    serviceDetails.add(serviceDetail1);
    ServiceDetail serviceDetail2 = new ServiceDetail().withServiceName(String.format(AwsNetworkCfTemplateProvider.VPC_INTERFACE_SERVICE_ENDPOINT_NAME_PATTERN, "region", "interface2"));
    serviceDetail2.setAvailabilityZones(List.of("az2", "az3"));
    serviceDetails.add(serviceDetail2);
    ServiceDetail serviceDetail3 = new ServiceDetail().withServiceName(String.format(AwsNetworkCfTemplateProvider.VPC_INTERFACE_SERVICE_ENDPOINT_NAME_PATTERN, "region", "interface3"));
    serviceDetail3.setAvailabilityZones(List.of("az5", "az6"));
    serviceDetails.add(serviceDetail3);
    describeVpcEndpointServicesResult.setServiceDetails(serviceDetails);
    return describeVpcEndpointServicesResult;
}
Also used : DescribeVpcEndpointServicesResult(com.amazonaws.services.ec2.model.DescribeVpcEndpointServicesResult) ArrayList(java.util.ArrayList) ServiceDetail(com.amazonaws.services.ec2.model.ServiceDetail)

Example 3 with ServiceDetail

use of com.amazonaws.services.ec2.model.ServiceDetail in project cloudbreak by hortonworks.

the class AwsNetworkCfTemplateProviderTest method createDescribeVpcEndpointServicesResult.

private static DescribeVpcEndpointServicesResult createDescribeVpcEndpointServicesResult(String... services) {
    DescribeVpcEndpointServicesResult describeVpcEndpointServicesResult = new DescribeVpcEndpointServicesResult();
    List<ServiceDetail> serviceDetails = new ArrayList<>();
    for (String service : services) {
        ServiceDetail serviceDetail = new ServiceDetail().withServiceName(String.format(AwsNetworkCfTemplateProvider.VPC_INTERFACE_SERVICE_ENDPOINT_NAME_PATTERN, "region", service));
        serviceDetail.setAvailabilityZones(List.of("az1", "az2"));
        serviceDetails.add(serviceDetail);
    }
    describeVpcEndpointServicesResult.setServiceDetails(serviceDetails);
    return describeVpcEndpointServicesResult;
}
Also used : DescribeVpcEndpointServicesResult(com.amazonaws.services.ec2.model.DescribeVpcEndpointServicesResult) ArrayList(java.util.ArrayList) ServiceDetail(com.amazonaws.services.ec2.model.ServiceDetail) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 4 with ServiceDetail

use of com.amazonaws.services.ec2.model.ServiceDetail in project cloudbreak by hortonworks.

the class AwsNetworkCfTemplateProvider method describeVpcServiceDetails.

private List<ServiceDetail> describeVpcServiceDetails(NetworkCreationRequest networkCreationRequest, Map<String, String> endpointNameMappings) {
    AwsCredentialView awsCredential = new AwsCredentialView(networkCreationRequest.getCloudCredential());
    AmazonEc2Client awsClientAccess = awsClient.createEc2Client(awsCredential, networkCreationRequest.getRegion().value());
    return awsClientAccess.describeVpcEndpointServices().getServiceDetails().stream().filter(sd -> endpointNameMappings.containsKey(sd.getServiceName())).collect(Collectors.toList());
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) 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) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)

Aggregations

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