Search in sources :

Example 1 with GroupSubnet

use of com.sequenceiq.cloudbreak.cloud.model.GroupSubnet in project cloudbreak by hortonworks.

the class StackToCloudStackConverter method buildGroupNetwork.

private GroupNetwork buildGroupNetwork(com.sequenceiq.freeipa.entity.Network network, InstanceGroup instanceGroup) {
    GroupNetwork groupNetwork = null;
    InstanceGroupNetwork instanceGroupNetwork = instanceGroup.getInstanceGroupNetwork();
    if (instanceGroupNetwork != null) {
        Json attributes = instanceGroupNetwork.getAttributes();
        Map<String, Object> params = attributes == null ? Collections.emptyMap() : attributes.getMap();
        Set<GroupSubnet> subnets = new HashSet<>();
        if (params != null) {
            List<String> subnetIds = (List<String>) params.getOrDefault(NetworkConstants.SUBNET_IDS, new ArrayList<>());
            for (String subnetId : subnetIds) {
                GroupSubnet groupSubnet = new GroupSubnet(subnetId);
                subnets.add(groupSubnet);
            }
        }
        groupNetwork = new GroupNetwork(network.getOutboundInternetTraffic(), subnets, params);
    }
    return groupNetwork;
}
Also used : InstanceGroupNetwork(com.sequenceiq.freeipa.entity.InstanceGroupNetwork) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroupNetwork(com.sequenceiq.freeipa.entity.InstanceGroupNetwork) GroupSubnet(com.sequenceiq.cloudbreak.cloud.model.GroupSubnet) HashSet(java.util.HashSet)

Example 2 with GroupSubnet

use of com.sequenceiq.cloudbreak.cloud.model.GroupSubnet in project cloudbreak by hortonworks.

the class AwsGatewaySubnetMultiAzValidatorTest method testValidateWhenThereIsGatewayGroupButInstanceGroupNetworkHasConfigurationWithMultipleSubnetPerAvailabilityZone.

@Test
void testValidateWhenThereIsGatewayGroupButInstanceGroupNetworkHasConfigurationWithMultipleSubnetPerAvailabilityZone() {
    String aSubnetId = "aSubnetId";
    String availabilityZone = "anAZ";
    Set<GroupSubnet> of = Set.of(new GroupSubnet(aSubnetId));
    GroupNetwork groupNetwork = new GroupNetwork(OutboundInternetTraffic.ENABLED, of, Map.of());
    Group gatewayGroup = getGroup("aGroupName", InstanceGroupType.GATEWAY, groupNetwork);
    CloudStack cloudStack = getCloudStack(Set.of(gatewayGroup));
    when(awsClient.createEc2Client(any(), any())).thenReturn(ec2Client);
    Set<Subnet> subnets = Set.of(new Subnet().withSubnetId(aSubnetId).withAvailabilityZone(availabilityZone), new Subnet().withSubnetId("anotherSubnetId").withAvailabilityZone(availabilityZone));
    DescribeSubnetsResult describeSubnetsResult = new DescribeSubnetsResult().withSubnets(subnets);
    when(ec2Client.describeSubnets(any())).thenReturn(describeSubnetsResult);
    Assertions.assertThrows(CloudConnectorException.class, () -> underTest.validate(authenticatedContext, cloudStack));
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) GroupSubnet(com.sequenceiq.cloudbreak.cloud.model.GroupSubnet) Subnet(com.amazonaws.services.ec2.model.Subnet) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) GroupSubnet(com.sequenceiq.cloudbreak.cloud.model.GroupSubnet) Test(org.junit.jupiter.api.Test)

Example 3 with GroupSubnet

use of com.sequenceiq.cloudbreak.cloud.model.GroupSubnet in project cloudbreak by hortonworks.

the class AwsGatewaySubnetMultiAzValidator method getInstanceGroupNetworSubnetIds.

private Set<String> getInstanceGroupNetworSubnetIds(Group group) {
    Set<String> result = new HashSet<>();
    GroupNetwork network = group.getNetwork();
    if (network != null) {
        result = Optional.ofNullable(network.getSubnets()).orElse(new HashSet<>()).stream().map(GroupSubnet::getSubnetId).collect(Collectors.toSet());
    }
    return result;
}
Also used : GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) GroupSubnet(com.sequenceiq.cloudbreak.cloud.model.GroupSubnet) HashSet(java.util.HashSet)

Example 4 with GroupSubnet

use of com.sequenceiq.cloudbreak.cloud.model.GroupSubnet in project cloudbreak by hortonworks.

the class StackToCloudStackConverter method buildGroupNetwork.

public GroupNetwork buildGroupNetwork(com.sequenceiq.cloudbreak.domain.Network stackNetwork, InstanceGroup instanceGroup) {
    GroupNetwork groupNetwork = null;
    InstanceGroupNetwork instanceGroupNetwork = instanceGroup.getInstanceGroupNetwork();
    if (instanceGroupNetwork != null) {
        Json attributes = instanceGroupNetwork.getAttributes();
        Map<String, Object> params = attributes == null ? Collections.emptyMap() : attributes.getMap();
        Set<GroupSubnet> subnets = new HashSet<>();
        Set<GroupSubnet> endpointGatewaySubnets = new HashSet<>();
        if (params != null) {
            List<String> subnetIds = (List<String>) params.getOrDefault(NetworkConstants.SUBNET_IDS, new ArrayList<>());
            for (String subnetId : subnetIds) {
                GroupSubnet groupSubnet = new GroupSubnet(subnetId);
                subnets.add(groupSubnet);
            }
            List<String> endpointGatewaySubnetIds = (List<String>) params.getOrDefault(NetworkConstants.ENDPOINT_GATEWAY_SUBNET_IDS, new ArrayList<>());
            for (String endpointGatewaySubnetId : endpointGatewaySubnetIds) {
                GroupSubnet groupSubnet = new GroupSubnet(endpointGatewaySubnetId);
                endpointGatewaySubnets.add(groupSubnet);
            }
        }
        groupNetwork = new GroupNetwork(getOutboundInternetTraffic(stackNetwork), subnets, endpointGatewaySubnets, params);
    }
    return groupNetwork;
}
Also used : GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) GroupSubnet(com.sequenceiq.cloudbreak.cloud.model.GroupSubnet) HashSet(java.util.HashSet)

Example 5 with GroupSubnet

use of com.sequenceiq.cloudbreak.cloud.model.GroupSubnet in project cloudbreak by hortonworks.

the class AwsGatewaySubnetMultiAzValidatorTest method testValidateWhenThereIsGatewayGroupButInstanceGroupNetworkHasValidSubnetAndEC2ClientCallFails.

@Test
void testValidateWhenThereIsGatewayGroupButInstanceGroupNetworkHasValidSubnetAndEC2ClientCallFails() {
    String aSubnetId = "aSubnetId";
    Set<GroupSubnet> of = Set.of(new GroupSubnet(aSubnetId));
    GroupNetwork groupNetwork = new GroupNetwork(OutboundInternetTraffic.ENABLED, of, Map.of());
    Group gatewayGroup = getGroup("aGroupName", InstanceGroupType.GATEWAY, groupNetwork);
    CloudStack cloudStack = getCloudStack(Set.of(gatewayGroup));
    when(awsClient.createEc2Client(any(), any())).thenReturn(ec2Client);
    when(ec2Client.describeSubnets(any())).thenThrow(new AmazonServiceException("Something went wrong"));
    Assertions.assertThrows(CloudConnectorException.class, () -> underTest.validate(authenticatedContext, cloudStack));
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) AmazonServiceException(com.amazonaws.AmazonServiceException) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) GroupSubnet(com.sequenceiq.cloudbreak.cloud.model.GroupSubnet) Test(org.junit.jupiter.api.Test)

Aggregations

GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)6 GroupSubnet (com.sequenceiq.cloudbreak.cloud.model.GroupSubnet)6 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)3 Group (com.sequenceiq.cloudbreak.cloud.model.Group)3 HashSet (java.util.HashSet)3 Test (org.junit.jupiter.api.Test)3 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)2 Subnet (com.amazonaws.services.ec2.model.Subnet)2 Json (com.sequenceiq.cloudbreak.common.json.Json)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 InstanceGroupNetwork (com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork)1 InstanceGroupNetwork (com.sequenceiq.freeipa.entity.InstanceGroupNetwork)1