Search in sources :

Example 81 with InstanceMetaData

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

the class InstanceGroupRequestToInstanceGroupConverter method addInstanceMetadatas.

private void addInstanceMetadatas(InstanceGroupRequest request, InstanceGroup instanceGroup, String hostname, String domain, String variant) {
    Set<InstanceMetaData> instanceMetaDataSet = new LinkedHashSet<>();
    for (int i = 0; i < request.getNodeCount(); i++) {
        InstanceMetaData instanceMetaData = new InstanceMetaData();
        instanceMetaData.setInstanceGroup(instanceGroup);
        instanceMetaData.setDiscoveryFQDN(hostname + String.format("%d.", i) + domain);
        instanceMetaDataSet.add(instanceMetaData);
        instanceMetaData.setVariant(variant);
    }
    instanceGroup.setInstanceMetaData(instanceMetaDataSet);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) LinkedHashSet(java.util.LinkedHashSet)

Example 82 with InstanceMetaData

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

the class InstanceMetaDataServiceTest method createValidImSet.

private Set<InstanceMetaData> createValidImSet() {
    InstanceMetaData im1 = new InstanceMetaData();
    im1.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
    im1.setInstanceId("pgw");
    InstanceMetaData im2 = new InstanceMetaData();
    im2.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
    im2.setInstanceId("im2");
    InstanceMetaData im3 = new InstanceMetaData();
    im3.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
    im3.setInstanceId("im3");
    return Set.of(im1, im2, im3);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData)

Example 83 with InstanceMetaData

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

the class InstanceMetaDataServiceTest method testSaveInstanceAndGetUpdatedStackWhenAvailabilityZoneDataIsAvailable.

@Test
public void testSaveInstanceAndGetUpdatedStackWhenAvailabilityZoneDataIsAvailable() {
    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("aSubnetId", "anAvailabilityZoneId");
    when(multiAzCalculatorService.prepareSubnetAzMap(environmentResponse)).thenReturn(subnetAzMap);
    Map<String, Integer> subnetUsage = Map.of();
    when(multiAzCalculatorService.calculateCurrentSubnetUsage(subnetAzMap, instanceGroup)).thenReturn(subnetUsage);
    when(multiAzCalculatorService.filterSubnetByLeastUsedAz(instanceGroup, subnetAzMap)).thenReturn(subnetAzMap);
    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).filterSubnetByLeastUsedAz(actualInstanceGroup, subnetAzMap);
    verify(multiAzCalculatorService).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 84 with InstanceMetaData

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

the class InstanceMetaDataServiceTest method initializeStackWithInstanceGroup.

private Stack initializeStackWithInstanceGroup() {
    Stack stack = new Stack();
    stack.setEnvironmentCrn(ENVIRONMENT_ID);
    stack.setId(STACK_ID);
    InstanceGroup instanceGroup = new InstanceGroup();
    stack.getInstanceGroups().add(instanceGroup);
    instanceGroup.setInstanceGroupType(InstanceGroupType.MASTER);
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceGroup.setInstanceMetaData(Sets.newHashSet(instanceMetaData));
    instanceGroup.setGroupName(GROUP_NAME);
    instanceMetaData.setDiscoveryFQDN("host1.domain");
    instanceMetaData.setInstanceId(INSTANCE_ID_1);
    instanceMetaData.setPrivateId(INSTANCE_PRIVATE_ID_1);
    instanceMetaData = new InstanceMetaData();
    instanceMetaData.setDiscoveryFQDN("host2.domain");
    instanceMetaData.setInstanceId(INSTANCE_ID_2);
    instanceMetaData.setPrivateId(INSTANCE_PRIVATE_ID_2);
    instanceGroup.getInstanceMetaData().add(instanceMetaData);
    return stack;
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup)

Example 85 with InstanceMetaData

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

the class MultiAzCalculatorServiceTest method createInstanceMetadata.

private InstanceMetaData createInstanceMetadata(String subnetId) {
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setSubnetId(subnetId);
    instanceMetaData.setInstanceStatus(InstanceStatus.CREATED);
    return instanceMetaData;
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData)

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