use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class InstanceGroupRequestToInstanceGroupConverter method convert.
public InstanceGroup convert(InstanceGroupRequest source, NetworkRequest networkRequest, String accountId, Stack stack, FreeIpaServerRequest ipaServerRequest, DetailedEnvironmentResponse environment, EnumMap<CloudArgsForIgConverter, String> cloudArgsForIgConverter) {
InstanceGroup instanceGroup = new InstanceGroup();
CloudPlatform cloudPlatform = CloudPlatform.valueOf(stack.getCloudPlatform());
instanceGroup.setTemplate(source.getInstanceTemplate() == null ? defaultInstanceGroupProvider.createDefaultTemplate(cloudPlatform, accountId, cloudArgsForIgConverter.get(DISK_ENCRYPTION_SET_ID), cloudArgsForIgConverter.get(GCP_KMS_ENCRYPTION_KEY), cloudArgsForIgConverter.get(AWS_KMS_ENCRYPTION_KEY)) : templateConverter.convert(source.getInstanceTemplate(), cloudPlatform, accountId, cloudArgsForIgConverter.get(DISK_ENCRYPTION_SET_ID), cloudArgsForIgConverter.get(GCP_KMS_ENCRYPTION_KEY), cloudArgsForIgConverter.get(AWS_KMS_ENCRYPTION_KEY)));
instanceGroup.setSecurityGroup(securityGroupConverter.convert(source.getSecurityGroup()));
instanceGroup.setInstanceGroupNetwork(hasEmptyNetworkOnStackRequest(source, networkRequest, cloudPlatform) ? defaultInstanceGroupProvider.createDefaultNetwork(cloudPlatform, networkRequest) : instanceGroupNetworkConverter.convert(stack.getCloudPlatform(), source.getNetwork()));
instanceGroup.setAvailabilityZones(getAvailabilityZoneFromEnv(instanceGroup, environment));
String instanceGroupName = source.getName();
instanceGroup.setGroupName(instanceGroupName);
instanceGroup.setInstanceGroupType(source.getType());
instanceGroup.setAttributes(defaultInstanceGroupProvider.createAttributes(cloudPlatform, stack.getName(), instanceGroupName));
if (source.getNodeCount() > 0) {
addInstanceMetadatas(source, instanceGroup, ipaServerRequest.getHostname(), ipaServerRequest.getDomain(), stack.getPlatformvariant());
}
instanceGroup.setNodeCount(source.getNodeCount());
return instanceGroup;
}
use of com.sequenceiq.freeipa.entity.InstanceGroup 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.InstanceGroup 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.InstanceGroup in project cloudbreak by hortonworks.
the class MultiAzCalculatorServiceTest method testUpdateSubnetIdForSingleInstanceIfEligibleValidatorReturnFalse.
@Test
public void testUpdateSubnetIdForSingleInstanceIfEligibleValidatorReturnFalse() {
InstanceGroup instanceGroup = new InstanceGroup();
when(multiAzValidator.supportedForInstanceMetadataGeneration(instanceGroup)).thenReturn(Boolean.FALSE);
InstanceMetaData instanceMetaData = new InstanceMetaData();
underTest.updateSubnetIdForSingleInstanceIfEligible(SUBNET_AZ_PAIRS, new HashMap<>(Map.of(SUB_1, 2, SUB_2, 1)), instanceMetaData, instanceGroup);
assertNull(instanceMetaData.getSubnetId());
}
use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class MultiAzCalculatorServiceTest method testUpdateSubnetIdForSingleInstanceIfEligibleSubnetUsageEmpty.
@Test
public void testUpdateSubnetIdForSingleInstanceIfEligibleSubnetUsageEmpty() {
InstanceGroup instanceGroup = new InstanceGroup();
InstanceMetaData instanceMetaData = new InstanceMetaData();
underTest.updateSubnetIdForSingleInstanceIfEligible(SUBNET_AZ_PAIRS, new HashMap<>(), instanceMetaData, instanceGroup);
assertNull(instanceMetaData.getSubnetId());
}
Aggregations