Search in sources :

Example 1 with InstanceGroupNetwork

use of com.sequenceiq.freeipa.entity.InstanceGroupNetwork 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 InstanceGroupNetwork

use of com.sequenceiq.freeipa.entity.InstanceGroupNetwork in project cloudbreak by hortonworks.

the class InstanceGroupNetworkRequestToInstanceGroupNetworkConverter method convert.

public InstanceGroupNetwork convert(String cloudPlatform, @Nonnull InstanceGroupNetworkRequest source) {
    InstanceGroupNetwork entity = new InstanceGroupNetwork();
    entity.setCloudPlatform(cloudPlatform);
    Map<String, Object> params = new HashMap<>();
    InstanceGroupAwsNetworkParameters aws = source.getAws();
    if (aws != null && aws.getSubnetIds() != null) {
        List<String> subnetIds = aws.getSubnetIds();
        params.put(NetworkConstants.SUBNET_IDS, subnetIds);
    }
    entity.setAttributes(new Json(params));
    return entity;
}
Also used : HashMap(java.util.HashMap) InstanceGroupAwsNetworkParameters(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.InstanceGroupAwsNetworkParameters) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroupNetwork(com.sequenceiq.freeipa.entity.InstanceGroupNetwork)

Example 3 with InstanceGroupNetwork

use of com.sequenceiq.freeipa.entity.InstanceGroupNetwork in project cloudbreak by hortonworks.

the class InstanceMetadataServiceComponentTest method saveInstanceAndGetUpdatedStack.

@Test
public void saveInstanceAndGetUpdatedStack() {
    DetailedEnvironmentResponse detailedEnvResponse = DetailedEnvironmentResponse.builder().withCrn(ENV_CRN).withNetwork(EnvironmentNetworkResponse.builder().withSubnetMetas(Map.of("sub1", cloudSubnet("az", "sub1"), "sub2", cloudSubnet("az", "sub2"), "sub3", cloudSubnet("az", "sub3"), "sub4", cloudSubnet("az1", "sub4"))).build()).build();
    Stack stack = new Stack();
    stack.setEnvironmentCrn(ENV_CRN);
    InstanceGroup workerInstanceGroup = new InstanceGroup();
    workerInstanceGroup.setGroupName("worker");
    InstanceGroupNetwork instanceGroupNetwork = new InstanceGroupNetwork();
    instanceGroupNetwork.setCloudPlatform("AWS");
    instanceGroupNetwork.setAttributes(new Json(Map.of(SUBNET_IDS, List.of("sub1", "sub2", "sub3", "sub4"))));
    workerInstanceGroup.setInstanceGroupNetwork(instanceGroupNetwork);
    stack.setInstanceGroups(Set.of(workerInstanceGroup));
    when(cachedEnvironmentClientService.getByCrn(ENV_CRN)).thenReturn(detailedEnvResponse);
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setHostname("hostname");
    freeIpa.setDomain("domain");
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    instanceMetaDataService.saveInstanceAndGetUpdatedStack(stack, cloudInstances(42));
    Map<String, List<InstanceMetaData>> groupBySub = workerInstanceGroup.getInstanceMetaDataSet().stream().collect(Collectors.groupingBy(InstanceMetaData::getSubnetId, Collectors.mapping(Function.identity(), Collectors.toList())));
    Map<String, List<InstanceMetaData>> groupByAz = workerInstanceGroup.getInstanceMetaDataSet().stream().collect(Collectors.groupingBy(InstanceMetaData::getAvailabilityZone, Collectors.mapping(Function.identity(), Collectors.toList())));
    Assertions.assertEquals(2, groupByAz.size());
    Assertions.assertEquals(21, groupByAz.get("az").size());
    Assertions.assertEquals(21, groupByAz.get("az1").size());
    Assertions.assertEquals(4, groupBySub.size());
    Assertions.assertEquals(7, groupBySub.get("sub1").size());
    Assertions.assertEquals(7, groupBySub.get("sub2").size());
    Assertions.assertEquals(7, groupBySub.get("sub3").size());
    Assertions.assertEquals(21, groupBySub.get("sub4").size());
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) ArrayList(java.util.ArrayList) List(java.util.List) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroupNetwork(com.sequenceiq.freeipa.entity.InstanceGroupNetwork) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with InstanceGroupNetwork

use of com.sequenceiq.freeipa.entity.InstanceGroupNetwork in project cloudbreak by hortonworks.

the class DefaultInstanceGroupProviderTest method createDefaultNetworkWithAwsAttributesShouldReturnWithNetworkAttributes.

@Test
void createDefaultNetworkWithAwsAttributesShouldReturnWithNetworkAttributes() {
    Json json = new Json(Map.of(NetworkConstants.SUBNET_IDS, Set.of("id")));
    NetworkRequest network = new NetworkRequest();
    AwsNetworkParameters awsNetworkParameters = new AwsNetworkParameters();
    awsNetworkParameters.setSubnetId("id");
    network.setAws(awsNetworkParameters);
    InstanceGroupNetwork defaultNetwork = underTest.createDefaultNetwork(CloudPlatform.AWS, network);
    assertThat(defaultNetwork.getAttributes()).isEqualTo(json);
}
Also used : NetworkRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.NetworkRequest) AwsNetworkParameters(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.AwsNetworkParameters) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroupNetwork(com.sequenceiq.freeipa.entity.InstanceGroupNetwork) Test(org.junit.jupiter.api.Test)

Example 5 with InstanceGroupNetwork

use of com.sequenceiq.freeipa.entity.InstanceGroupNetwork in project cloudbreak by hortonworks.

the class MultiAzCalculatorServiceTest method testCalculateRoundRobin.

@Test
public void testCalculateRoundRobin() {
    InstanceGroupNetwork instanceGroupNetwork = new InstanceGroupNetwork();
    instanceGroupNetwork.setAttributes(Json.silent(Map.of(SUBNET_IDS, List.of(SUB_1, SUB_2, "ONLYINIG"))));
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setInstanceGroupNetwork(instanceGroupNetwork);
    InstanceMetaData deletedInstance = createInstanceMetadata(SUB_1);
    deletedInstance.setInstanceStatus(InstanceStatus.TERMINATED);
    instanceGroup.setInstanceMetaData(Set.of(createInstanceMetadata(null), createInstanceMetadata(null), createInstanceMetadata(null), createInstanceMetadata(SUB_2), createInstanceMetadata(null), createInstanceMetadata(" "), createInstanceMetadata("IGNORED"), deletedInstance));
    when(multiAzValidator.supportedForInstanceMetadataGeneration(instanceGroup)).thenReturn(Boolean.TRUE);
    underTest.calculateByRoundRobin(SUBNET_AZ_PAIRS, instanceGroup);
    assertEquals(3, instanceGroup.getNotDeletedInstanceMetaDataSet().stream().filter(im -> SUB_1.equals(im.getSubnetId()) && "AZ1".equals(im.getAvailabilityZone())).count());
    assertEquals(2, instanceGroup.getNotDeletedInstanceMetaDataSet().stream().filter(im -> SUB_2.equals(im.getSubnetId()) && "AZ2".equals(im.getAvailabilityZone())).count());
    assertEquals(3, instanceGroup.getNotDeletedInstanceMetaDataSet().stream().filter(im -> SUB_2.equals(im.getSubnetId())).count());
    assertEquals(1, instanceGroup.getNotDeletedInstanceMetaDataSet().stream().filter(im -> "IGNORED".equals(im.getSubnetId())).count());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceGroupNetwork(com.sequenceiq.freeipa.entity.InstanceGroupNetwork) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceGroupNetwork (com.sequenceiq.freeipa.entity.InstanceGroupNetwork)14 Json (com.sequenceiq.cloudbreak.common.json.Json)8 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)8 Test (org.junit.jupiter.api.Test)7 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 List (java.util.List)4 NetworkRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.NetworkRequest)2 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)2 Stack (com.sequenceiq.freeipa.entity.Stack)2 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)1 GroupSubnet (com.sequenceiq.cloudbreak.cloud.model.GroupSubnet)1 StackTags (com.sequenceiq.cloudbreak.cloud.model.StackTags)1 AwsInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate)1 BackupRequest (com.sequenceiq.common.api.backup.request.BackupRequest)1 AdlsGen2CloudStorageV1Parameters (com.sequenceiq.common.api.cloudstorage.old.AdlsGen2CloudStorageV1Parameters)1 GcsCloudStorageV1Parameters (com.sequenceiq.common.api.cloudstorage.old.GcsCloudStorageV1Parameters)1 S3CloudStorageV1Parameters (com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters)1 CloudwatchParams (com.sequenceiq.common.api.telemetry.model.CloudwatchParams)1 Features (com.sequenceiq.common.api.telemetry.model.Features)1