Search in sources :

Example 6 with InstanceGroupNetwork

use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork 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 7 with InstanceGroupNetwork

use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.

the class MultiAzValidator method collectSubnetIds.

public Set<String> collectSubnetIds(Iterable<InstanceGroup> instanceGroups) {
    Set<String> allSubnetIds = new HashSet<>();
    for (InstanceGroup instanceGroup : instanceGroups) {
        InstanceGroupNetwork instanceGroupNetwork = instanceGroup.getInstanceGroupNetwork();
        if (instanceGroupNetwork != null) {
            Json attributes = instanceGroupNetwork.getAttributes();
            if (attributes != null) {
                List<String> subnetIds = (List<String>) attributes.getMap().getOrDefault(NetworkConstants.SUBNET_IDS, new ArrayList<>());
                allSubnetIds.addAll(subnetIds);
            }
        }
    }
    return allSubnetIds;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) HashSet(java.util.HashSet) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 8 with InstanceGroupNetwork

use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.

the class InstanceGroupV4RequestToInstanceGroupConverterTest method testConvert.

@Test
public void testConvert() {
    InstanceGroupV4Request request = getRequest("instance-group.json");
    // GIVEN
    given(providerParameterCalculator.get(request)).willReturn(getMappable());
    given(instanceTemplateV4RequestToTemplateConverter.convert(any(InstanceTemplateV4Request.class))).willReturn(new Template());
    given(securityGroupV4RequestToSecurityGroupConverter.convert(any(SecurityGroupV4Request.class))).willReturn(new SecurityGroup());
    given(instanceGroupNetworkV4RequestToInstanceGroupNetworkConverter.convert(any(InstanceGroupNetworkV4Request.class))).willReturn(new InstanceGroupNetwork());
    // WHEN
    InstanceGroup instanceGroup = underTest.convert(request, "variant");
    // THEN
    assertAllFieldsNotNull(instanceGroup, List.of("stack", "targetGroups"));
}
Also used : InstanceTemplateV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.InstanceTemplateV4Request) InstanceGroupNetworkV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.network.InstanceGroupNetworkV4Request) SecurityGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) SecurityGroup(com.sequenceiq.cloudbreak.domain.SecurityGroup) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) Template(com.sequenceiq.cloudbreak.domain.Template) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) AbstractJsonConverterTest(com.sequenceiq.cloudbreak.converter.AbstractJsonConverterTest) Test(org.junit.Test)

Example 9 with InstanceGroupNetwork

use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.

the class InstanceGroupNetworkV4RequestToInstanceGroupNetworkConverter method convert.

public InstanceGroupNetwork convert(InstanceGroupNetworkV4Request source) {
    InstanceGroupNetwork network = new InstanceGroupNetwork();
    CloudPlatform cloudPlatform = providerParameterCalculator.get(source).getCloudPlatform();
    network.setCloudPlatform(cloudPlatform.name());
    Map<String, Object> parameters = providerParameterCalculator.get(source).asMap();
    Optional.ofNullable(parameters).map(toJson()).ifPresent(network::setAttributes);
    return network;
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork)

Example 10 with InstanceGroupNetwork

use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.

the class InstanceGroupV4RequestToInstanceGroupConverter method setNetwork.

private void setNetwork(InstanceGroupV4Request source, InstanceGroup instanceGroup) {
    if (source.getNetwork() != null) {
        source.getNetwork().setCloudPlatform(source.getCloudPlatform());
        InstanceGroupNetwork instanceGroupNetwork = instanceGroupNetworkV4RequestToInstanceGroupNetworkConverter.convert(source.getNetwork());
        instanceGroup.setInstanceGroupNetwork(instanceGroupNetwork);
    }
}
Also used : InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork)

Aggregations

InstanceGroupNetwork (com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork)13 Json (com.sequenceiq.cloudbreak.common.json.Json)8 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)8 List (java.util.List)5 ArrayList (java.util.ArrayList)4 Test (org.junit.jupiter.api.Test)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 HashSet (java.util.HashSet)3 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)2 SecurityGroup (com.sequenceiq.cloudbreak.domain.SecurityGroup)2 Template (com.sequenceiq.cloudbreak.domain.Template)2 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)1 PlacementSettingsV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.environment.placement.PlacementSettingsV4Request)1 InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)1 InstanceGroupNetworkV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.network.InstanceGroupNetworkV4Request)1 SecurityGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request)1 InstanceTemplateV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.InstanceTemplateV4Request)1 Measure (com.sequenceiq.cloudbreak.aspect.Measure)1