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);
}
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);
}
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);
}
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;
}
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;
}
Aggregations