Search in sources :

Example 36 with InstanceGroup

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;
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup)

Example 37 with 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);
}
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 InstanceGroup

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;
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup)

Example 39 with InstanceGroup

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());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Test(org.junit.jupiter.api.Test)

Example 40 with InstanceGroup

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());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)60 Stack (com.sequenceiq.freeipa.entity.Stack)32 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)31 Test (org.junit.jupiter.api.Test)30 Template (com.sequenceiq.freeipa.entity.Template)18 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)16 FreeIpaServerRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest)11 Json (com.sequenceiq.cloudbreak.common.json.Json)10 InstanceGroupRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest)10 NetworkRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.NetworkRequest)10 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)9 AwsInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate)9 InstanceGroupNetwork (com.sequenceiq.freeipa.entity.InstanceGroupNetwork)9 HashSet (java.util.HashSet)9 AzureInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate)8 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)7 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)6 InstanceTemplateRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest)6 HashMap (java.util.HashMap)6 CreateFreeIpaRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest)5