Search in sources :

Example 1 with GroupNetwork

use of com.sequenceiq.cloudbreak.cloud.model.GroupNetwork 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 GroupNetwork

use of com.sequenceiq.cloudbreak.cloud.model.GroupNetwork 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 GroupNetwork

use of com.sequenceiq.cloudbreak.cloud.model.GroupNetwork 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 GroupNetwork

use of com.sequenceiq.cloudbreak.cloud.model.GroupNetwork 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 GroupNetwork

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

the class AwsGatewaySubnetMultiAzValidatorTest method testValidateWhenThereIsGatewayGroupButInstanceGroupNetworkDoesNotHaveSubnetsConfigured.

@Test
void testValidateWhenThereIsGatewayGroupButInstanceGroupNetworkDoesNotHaveSubnetsConfigured() {
    GroupNetwork groupNetwork = new GroupNetwork(OutboundInternetTraffic.ENABLED, null, Map.of());
    Group gatewayGroup = getGroup("aGroupName", InstanceGroupType.GATEWAY, groupNetwork);
    CloudStack cloudStack = getCloudStack(Set.of(gatewayGroup));
    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) Test(org.junit.jupiter.api.Test)

Aggregations

GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)8 GroupSubnet (com.sequenceiq.cloudbreak.cloud.model.GroupSubnet)6 Group (com.sequenceiq.cloudbreak.cloud.model.Group)5 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)4 Test (org.junit.jupiter.api.Test)4 Json (com.sequenceiq.cloudbreak.common.json.Json)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)2 Subnet (com.amazonaws.services.ec2.model.Subnet)2 InstanceGroupNetwork (com.sequenceiq.freeipa.entity.InstanceGroupNetwork)2 List (java.util.List)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)1 InstanceStatus (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)1 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)1 InstanceGroupNetwork (com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork)1 AzureResourceGroup (com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup)1 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)1