Search in sources :

Example 36 with InstanceMetaData

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

the class FreeIpaTopologyServiceTest method testUpdateReplicationTopology.

@MethodSource("testUpdateReplicationTopologyParameters")
@ParameterizedTest(name = "Run {index}: numNodes={0}, expectedSegmentsToAdd={1}, expectedSegmentsToRemove={2}")
void testUpdateReplicationTopology(int numNodes, int expectedSegmentsToAdd, int expectedSegmentsToRemove) throws FreeIpaClientException {
    Set<InstanceMetaData> imSet = new HashSet<>();
    for (int i = 0; i < numNodes; i++) {
        InstanceMetaData im = new InstanceMetaData();
        im.setDiscoveryFQDN(String.format("ipaserver%d.example.com", i));
        imSet.add(im);
    }
    when(instanceMetaDataService.findNotTerminatedForStack(anyLong())).thenReturn(imSet);
    TopologySuffix caSuffix = new TopologySuffix();
    caSuffix.setCn("ca");
    TopologySuffix domainSuffix = new TopologySuffix();
    domainSuffix.setCn("domain");
    when(freeIpaClient.findAllTopologySuffixes()).thenReturn(List.of(caSuffix, domainSuffix));
    List<TopologySegment> topologySegments1 = new LinkedList<>();
    for (int i = 1; i < numNodes; i++) {
        TopologySegment segment = new TopologySegment();
        segment.setLeftNode("ipaserver0.example.com");
        segment.setRightNode(String.format("ipaserver%d.example.com", i));
        topologySegments1.add(segment);
    }
    List<TopologySegment> topologySegments2 = new LinkedList<>();
    topologySegments2.addAll(topologySegments1);
    when(freeIpaClient.findTopologySegments(Mockito.anyString())).thenReturn(topologySegments1).thenReturn(topologySegments1).thenReturn(topologySegments2).thenReturn(topologySegments2);
    if (expectedSegmentsToAdd > 0) {
        when(freeIpaClient.addTopologySegment(Mockito.anyString(), Mockito.any())).thenReturn(new TopologySegment());
    }
    if (expectedSegmentsToRemove > 0) {
        when(freeIpaClient.deleteTopologySegment(Mockito.anyString(), Mockito.any())).thenReturn(new TopologySegment());
    }
    underTest.updateReplicationTopology(1L, Set.of(), freeIpaClient);
    Mockito.verify(freeIpaClient, Mockito.times(expectedSegmentsToAdd)).addTopologySegment(Mockito.eq("ca"), Mockito.any());
    Mockito.verify(freeIpaClient, Mockito.times(expectedSegmentsToAdd)).addTopologySegment(Mockito.eq("domain"), Mockito.any());
    Mockito.verify(freeIpaClient, Mockito.times(expectedSegmentsToRemove)).deleteTopologySegment(Mockito.eq("ca"), Mockito.any());
    Mockito.verify(freeIpaClient, Mockito.times(expectedSegmentsToRemove)).deleteTopologySegment(Mockito.eq("domain"), Mockito.any());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) TopologySuffix(com.sequenceiq.freeipa.client.model.TopologySuffix) TopologySegment(com.sequenceiq.freeipa.client.model.TopologySegment) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 37 with InstanceMetaData

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

the class InstanceMetaDataServiceTest method testSaveInstanceAndGetUpdatedStackWhenNoAvailabilityZoneDataAvailable.

@Test
public void testSaveInstanceAndGetUpdatedStackWhenNoAvailabilityZoneDataAvailable() {
    Stack stack = initializeStackWithInstanceGroup();
    InstanceGroup instanceGroup = stack.getInstanceGroups().stream().findFirst().get();
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setHostname("ipa");
    freeIpa.setDomain("dom");
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    InstanceTemplate template = mock(InstanceTemplate.class);
    when(template.getGroupName()).thenReturn(GROUP_NAME);
    when(template.getPrivateId()).thenReturn(INSTANCE_PRIVATE_ID_3);
    List<CloudInstance> cloudInstances = List.of(new CloudInstance(INSTANCE_ID_3, template, null, "subnet-1", "az1"));
    DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
    when(cachedEnvironmentClientService.getByCrn(ENVIRONMENT_ID)).thenReturn(environmentResponse);
    Map<String, String> subnetAzMap = Map.of();
    when(multiAzCalculatorService.prepareSubnetAzMap(environmentResponse)).thenReturn(subnetAzMap);
    Map<String, Integer> subnetUsage = Map.of();
    when(multiAzCalculatorService.calculateCurrentSubnetUsage(subnetAzMap, instanceGroup)).thenReturn(subnetUsage);
    Stack actualStack = underTest.saveInstanceAndGetUpdatedStack(stack, cloudInstances);
    verify(instanceMetaDataRepository).save(any());
    assertEquals(3, actualStack.getAllInstanceMetaDataList().size());
    InstanceGroup actualInstanceGroup = actualStack.getInstanceGroups().stream().filter(ig -> GROUP_NAME.equals(ig.getGroupName())).findFirst().get();
    InstanceMetaData instanceMetaData = actualInstanceGroup.getInstanceMetaData().stream().filter(im -> INSTANCE_PRIVATE_ID_3 == im.getPrivateId()).findFirst().get();
    assertEquals("ipa3.dom", instanceMetaData.getDiscoveryFQDN());
    verify(multiAzCalculatorService, times(0)).filterSubnetByLeastUsedAz(actualInstanceGroup, subnetAzMap);
    verify(multiAzCalculatorService, times(0)).updateSubnetIdForSingleInstanceIfEligible(subnetAzMap, subnetUsage, instanceMetaData, actualInstanceGroup);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Test(org.junit.jupiter.api.Test)

Example 38 with InstanceMetaData

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

the class InstanceMetaDataServiceTest method testGetPrimaryGwInstance.

@Test
public void testGetPrimaryGwInstance() {
    InstanceMetaData primaryGwInstance = underTest.getPrimaryGwInstance(createValidImSet());
    assertEquals("pgw", primaryGwInstance.getInstanceId());
    assertEquals(InstanceMetadataType.GATEWAY_PRIMARY, primaryGwInstance.getInstanceMetadataType());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Test(org.junit.jupiter.api.Test)

Example 39 with InstanceMetaData

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

Example 40 with InstanceMetaData

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

the class MultiAzCalculatorServiceTest method testUpdateSubnetIdForSingleInstanceIfEligibleDontModifyExisting.

@Test
public void testUpdateSubnetIdForSingleInstanceIfEligibleDontModifyExisting() {
    InstanceGroup instanceGroup = new InstanceGroup();
    when(multiAzValidator.supportedForInstanceMetadataGeneration(instanceGroup)).thenReturn(Boolean.TRUE);
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setSubnetId("ASDF");
    underTest.updateSubnetIdForSingleInstanceIfEligible(SUBNET_AZ_PAIRS, new HashMap<>(Map.of(SUB_1, 2, SUB_2, 1)), instanceMetaData, instanceGroup);
    assertEquals("ASDF", instanceMetaData.getSubnetId());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)163 Stack (com.sequenceiq.freeipa.entity.Stack)104 Test (org.junit.jupiter.api.Test)77 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)30 List (java.util.List)19 Logger (org.slf4j.Logger)19 LoggerFactory (org.slf4j.LoggerFactory)19 Map (java.util.Map)18 Collectors (java.util.stream.Collectors)18 Inject (javax.inject.Inject)18 Set (java.util.Set)16 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)13 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)13 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)12 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)11 StackService (com.sequenceiq.freeipa.service.stack.StackService)10 ArrayList (java.util.ArrayList)10 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)9 HealthDetailsFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse)9 Operation (com.sequenceiq.freeipa.entity.Operation)9