use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.
the class StackToCreateFreeIpaRequestConverterTest method testConvert.
@Test
void testConvert() {
// Initialize
Stack stack = new Stack();
stack.setEnvironmentCrn(ENVIRONMENT_CRN);
stack.setName(NAME + "_" + TERMINATION_TIME);
stack.setRegion(REGION);
stack.setAvailabilityZone(AVAILIBILTYY_ZONE);
stack.setGatewayport(GATEWAY_PORT);
stack.setUseCcm(true);
stack.setTunnel(Tunnel.CCMV2);
stack.setPlatformvariant(CLOUD_PLATFORM);
StackStatus stackStatus = new StackStatus();
stackStatus.setStack(stack);
stackStatus.setDetailedStackStatus(DetailedStackStatus.DELETE_COMPLETED);
stackStatus.setStatus(Status.DELETE_COMPLETED);
stack.setStackStatus(stackStatus);
InstanceGroup ig = new InstanceGroup();
ig.setGroupName(INSTANCE_GROUP_NAME);
Template template = new Template();
template.setInstanceType(INSTANCE_TYPE);
template.setAttributes(new Json(Map.of(AwsInstanceTemplate.EC2_SPOT_PERCENTAGE, EC2_SPOT_PERCENTAGE, AwsInstanceTemplate.EC2_SPOT_MAX_PRICE, EC2_SPOT_MAX_PRICE)));
template.setVolumeType(VOLUME_TYPE);
template.setVolumeCount(VOLUMNE_COUNT);
template.setVolumeSize(VOLUMNE_SIZE);
ig.setTemplate(template);
InstanceGroupNetwork igNetwork = new InstanceGroupNetwork();
igNetwork.setAttributes(new Json(Map.of(NetworkConstants.SUBNET_IDS, SUBNET_IDS)));
ig.setInstanceGroupNetwork(igNetwork);
ig.setNodeCount(NODE_COUNT);
SecurityGroup sg = new SecurityGroup();
sg.setSecurityGroupIds(SECURITY_GROUP_IDS);
SecurityRule sr = new SecurityRule();
sr.setModifiable(true);
sr.setPorts(PORT);
sr.setProtocol(PROTOCOL);
sr.setCidr(CIDR);
sg.setSecurityRules(Set.of(sr));
ig.setSecurityGroup(sg);
ig.setInstanceGroupType(InstanceGroupType.MASTER);
stack.setInstanceGroups(Set.of(ig));
StackAuthentication stackAuthentication = new StackAuthentication();
stackAuthentication.setLoginUserName(LOGIN_NAME);
stackAuthentication.setPublicKey(PUBLIC_KEY);
stackAuthentication.setPublicKeyId(PUBLIC_KEY_ID);
stack.setStackAuthentication(stackAuthentication);
Network network = new Network();
network.setNetworkCidrs(List.of(CIDR));
network.setOutboundInternetTraffic(OutboundInternetTraffic.ENABLED);
network.setAttributes(new Json(Map.of("vpcId", VPC_ID, "subnetId", SUBNET_ID)));
network.setCloudPlatform(CLOUD_PLATFORM);
stack.setNetwork(network);
ImageEntity image = new ImageEntity();
image.setImageCatalogUrl(IMAGE_CATALOG_URL);
image.setImageId(IMAGE_ID);
image.setOs(IMAGE_OS);
stack.setImage(image);
FreeIpa freeIpa = new FreeIpa();
freeIpa.setAdminGroupName(ADMIN_GROUP_NAME);
freeIpa.setAdminPassword(ADMIN_PASSWORD);
freeIpa.setDomain(DOMAIN);
freeIpa.setHostname(HOSTNAME);
Telemetry telemetry = new Telemetry();
Map<String, Object> fluentAttributes = Map.of("fluent", "attributes");
telemetry.setFluentAttributes(fluentAttributes);
Logging logging = new Logging();
logging.setStorageLocation(STORAGE_LOCATION);
S3CloudStorageV1Parameters s3Storage = new S3CloudStorageV1Parameters();
logging.setS3(s3Storage);
AdlsGen2CloudStorageV1Parameters adlsStorage = new AdlsGen2CloudStorageV1Parameters();
logging.setAdlsGen2(adlsStorage);
GcsCloudStorageV1Parameters gcsStorage = new GcsCloudStorageV1Parameters();
logging.setGcs(gcsStorage);
CloudwatchParams cloudwatchParamsStorage = new CloudwatchParams();
logging.setCloudwatch(cloudwatchParamsStorage);
telemetry.setLogging(logging);
Features features = new Features();
features.setClusterLogsCollection(new FeatureSetting());
features.setMonitoring(new FeatureSetting());
features.setCloudStorageLogging(new FeatureSetting());
features.setWorkloadAnalytics(new FeatureSetting());
telemetry.setFeatures(features);
WorkloadAnalytics workloadAnalytics = new WorkloadAnalytics();
workloadAnalytics.setAttributes(Map.of());
telemetry.setWorkloadAnalytics(workloadAnalytics);
stack.setTelemetry(telemetry);
Backup backup = new Backup();
backup.setStorageLocation(BACKUP_STORAGE_LOCATION);
S3CloudStorageV1Parameters s3BackupLocation = new S3CloudStorageV1Parameters();
backup.setS3(s3BackupLocation);
AdlsGen2CloudStorageV1Parameters adlsBackupLocation = new AdlsGen2CloudStorageV1Parameters();
backup.setAdlsGen2(adlsBackupLocation);
GcsCloudStorageV1Parameters gcsBackupLocation = new GcsCloudStorageV1Parameters();
backup.setGcs(gcsBackupLocation);
stack.setBackup(backup);
StackTags tags = new StackTags(USER_DEFINED_TAGS, APPLICATION_TAGS, DEFAULT_TAGS);
stack.setTags(new Json(tags));
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
// Convert
CreateFreeIpaRequest request = underTest.convert(stack);
// Validate
assertNotNull(request);
assertEquals(ENVIRONMENT_CRN, request.getEnvironmentCrn());
assertEquals(NAME, request.getName());
assertEquals(GATEWAY_PORT, request.getGatewayPort());
assertTrue(request.getUseCcm());
assertEquals(Tunnel.CCMV2, request.getTunnel());
assertEquals(CLOUD_PLATFORM, request.getVariant());
PlacementRequest placementRequest = request.getPlacement();
assertNotNull(placementRequest);
assertEquals(REGION, placementRequest.getRegion());
assertEquals(AVAILIBILTYY_ZONE, placementRequest.getAvailabilityZone());
assertEquals(1, request.getInstanceGroups().size());
InstanceGroupRequest igRequest = request.getInstanceGroups().get(0);
assertEquals(INSTANCE_GROUP_NAME, igRequest.getName());
InstanceTemplateRequest templateRequest = igRequest.getInstanceTemplate();
assertNotNull(templateRequest);
assertEquals(INSTANCE_TYPE, templateRequest.getInstanceType());
assertNotNull(templateRequest.getAws());
assertNotNull(templateRequest.getAws().getSpot());
assertEquals(EC2_SPOT_PERCENTAGE, templateRequest.getAws().getSpot().getPercentage());
assertEquals(EC2_SPOT_MAX_PRICE, templateRequest.getAws().getSpot().getMaxPrice());
List<VolumeRequest> volumeRequests = templateRequest.getAttachedVolumes().stream().collect(Collectors.toList());
assertEquals(1, volumeRequests.size());
assertEquals(VOLUME_TYPE, volumeRequests.get(0).getType());
assertEquals(VOLUMNE_COUNT, volumeRequests.get(0).getCount());
assertEquals(VOLUMNE_SIZE, volumeRequests.get(0).getSize());
assertNotNull(igRequest.getNetwork());
assertNotNull(igRequest.getNetwork().getAws());
assertEquals(SUBNET_IDS, igRequest.getNetwork().getAws().getSubnetIds());
assertEquals(NODE_COUNT, ig.getNodeCount());
assertNotNull(igRequest.getSecurityGroup());
assertEquals(SECURITY_GROUP_IDS, igRequest.getSecurityGroup().getSecurityGroupIds());
List<SecurityRuleRequest> srRequst = igRequest.getSecurityGroup().getSecurityRules();
assertEquals(1, srRequst.size());
assertTrue(srRequst.get(0).isModifiable());
assertEquals(List.of(PORT), srRequst.get(0).getPorts());
assertEquals(PROTOCOL, srRequst.get(0).getProtocol());
assertEquals(CIDR, srRequst.get(0).getSubnet());
assertEquals(InstanceGroupType.MASTER, ig.getInstanceGroupType());
StackAuthenticationRequest stackAuthenticationRequest = request.getAuthentication();
assertNotNull(stackAuthenticationRequest);
assertEquals(LOGIN_NAME, stackAuthenticationRequest.getLoginUserName());
assertEquals(PUBLIC_KEY, stackAuthenticationRequest.getPublicKey());
assertEquals(PUBLIC_KEY_ID, stackAuthenticationRequest.getPublicKeyId());
NetworkRequest networkRequest = request.getNetwork();
assertNotNull(networkRequest);
assertEquals(CloudPlatform.AWS, networkRequest.getCloudPlatform());
assertEquals(List.of(CIDR), networkRequest.getNetworkCidrs());
assertEquals(OutboundInternetTraffic.ENABLED, networkRequest.getOutboundInternetTraffic());
assertNotNull(networkRequest.getAws());
assertNull(networkRequest.getAzure());
assertNull(networkRequest.getGcp());
assertNull(networkRequest.getMock());
assertNull(networkRequest.getYarn());
assertEquals(CloudPlatform.AWS, networkRequest.getAws().getCloudPlatform());
assertEquals(VPC_ID, networkRequest.getAws().getVpcId());
assertEquals(SUBNET_ID, networkRequest.getAws().getSubnetId());
ImageSettingsRequest imageSettingsRequest = request.getImage();
assertNotNull(imageSettingsRequest);
assertEquals(IMAGE_ID, imageSettingsRequest.getId());
assertEquals(IMAGE_CATALOG_URL, imageSettingsRequest.getCatalog());
assertEquals(IMAGE_OS, imageSettingsRequest.getOs());
FreeIpaServerRequest freeIpaServerRequest = request.getFreeIpa();
assertNotNull(freeIpaServerRequest);
assertEquals(ADMIN_GROUP_NAME, freeIpaServerRequest.getAdminGroupName());
assertEquals(ADMIN_PASSWORD, freeIpaServerRequest.getAdminPassword());
assertEquals(DOMAIN, freeIpaServerRequest.getDomain());
assertEquals(HOSTNAME, freeIpaServerRequest.getHostname());
TelemetryRequest telemetryRequest = request.getTelemetry();
assertNotNull(telemetryRequest);
assertEquals(fluentAttributes, telemetryRequest.getFluentAttributes());
assertNotNull(telemetryRequest.getLogging());
assertEquals(STORAGE_LOCATION_REQUEST, telemetryRequest.getLogging().getStorageLocation());
assertEquals(s3Storage, telemetryRequest.getLogging().getS3());
assertEquals(adlsStorage, telemetryRequest.getLogging().getAdlsGen2());
assertEquals(gcsStorage, telemetryRequest.getLogging().getGcs());
assertNotNull(telemetryRequest.getLogging().getCloudwatch());
assertNotNull(telemetryRequest.getFeatures());
assertNotNull(telemetryRequest.getFeatures().getClusterLogsCollection());
assertNotNull(telemetryRequest.getFeatures().getMonitoring());
assertNotNull(telemetryRequest.getFeatures().getCloudStorageLogging());
assertNotNull(telemetryRequest.getFeatures().getWorkloadAnalytics());
assertNotNull(telemetryRequest.getWorkloadAnalytics());
assertEquals(Map.of(), telemetryRequest.getWorkloadAnalytics().getAttributes());
BackupRequest backupRequest = request.getBackup();
assertNotNull(backupRequest);
assertEquals(BACKUP_STORAGE_LOCATION_REQUEST, backupRequest.getStorageLocation());
assertEquals(s3BackupLocation, backupRequest.getS3());
assertEquals(adlsBackupLocation, backupRequest.getAdlsGen2());
assertEquals(gcsBackupLocation, backupRequest.getGcs());
assertEquals(USER_DEFINED_TAGS, request.getTags());
}
use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.
the class StackToDescribeFreeIpaResponseConverterTest method convertTest.
@ParameterizedTest(name = "tunnel={0}")
@EnumSource(Tunnel.class)
@NullSource
void convertTest(Tunnel tunnel) {
FreeIpaServerResponse freeIpaServerResponse = new FreeIpaServerResponse();
Stack stack = createStack(tunnel);
ImageEntity image = new ImageEntity();
FreeIpa freeIpa = new FreeIpa();
freeIpa.setDomain(DOMAIN);
UserSyncStatus userSyncStatus = new UserSyncStatus();
when(authenticationResponseConverter.convert(stack.getStackAuthentication())).thenReturn(STACK_AUTHENTICATION_RESPONSE);
when(imageSettingsResponseConverter.convert(image)).thenReturn(IMAGE_SETTINGS_RESPONSE);
when(freeIpaServerResponseConverter.convert(freeIpa)).thenReturn(freeIpaServerResponse);
when(instanceGroupConverter.convert(stack.getInstanceGroups(), true)).thenReturn(INSTANCE_GROUP_RESPONSES);
when(userSyncStatusConverter.convert(userSyncStatus)).thenReturn(USERSYNC_STATUS_RESPONSE);
when(balancedDnsAvailabilityChecker.isBalancedDnsAvailable(stack)).thenReturn(true);
when(stackToAvailabilityStatusConverter.convert(stack)).thenReturn(AvailabilityStatus.AVAILABLE);
DescribeFreeIpaResponse result = underTest.convert(stack, image, freeIpa, Optional.of(userSyncStatus), true);
assertThat(result).returns(NAME, DescribeFreeIpaResponse::getName).returns(ENV_CRN, DescribeFreeIpaResponse::getEnvironmentCrn).returns(RESOURCE_CRN, DescribeFreeIpaResponse::getCrn).returns(CLOUD_PLATFORM, DescribeFreeIpaResponse::getCloudPlatform).returns(STACK_AUTHENTICATION_RESPONSE, DescribeFreeIpaResponse::getAuthentication).returns(IMAGE_SETTINGS_RESPONSE, DescribeFreeIpaResponse::getImage).returns(freeIpaServerResponse, DescribeFreeIpaResponse::getFreeIpa).returns(INSTANCE_GROUP_RESPONSES, DescribeFreeIpaResponse::getInstanceGroups).returns(STATUS, DescribeFreeIpaResponse::getStatus).returns(STATUS_REASON, DescribeFreeIpaResponse::getStatusReason).returns(STATUS_STRING, DescribeFreeIpaResponse::getStatusString).returns(APP_VERSION, DescribeFreeIpaResponse::getAppVersion).returns(VARIANT, DescribeFreeIpaResponse::getVariant).returns(USERSYNC_STATUS_RESPONSE, DescribeFreeIpaResponse::getUserSyncStatus).returns(tunnel, DescribeFreeIpaResponse::getTunnel);
assertThat(freeIpaServerResponse).returns(Set.of(SERVER_IP), FreeIpaServerResponse::getServerIp).returns(FREEIPA_HOST, FreeIpaServerResponse::getFreeIpaHost).returns(GATEWAY_PORT, FreeIpaServerResponse::getFreeIpaPort);
}
use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.
the class InstanceMetaDataService method saveInstanceAndGetUpdatedStack.
public Stack saveInstanceAndGetUpdatedStack(Stack stack, List<CloudInstance> cloudInstances) {
FreeIpa freeIpa = freeIpaService.findByStack(stack);
DetailedEnvironmentResponse environment = measure(() -> cachedEnvironmentClientService.getByCrn(stack.getEnvironmentCrn()), LOGGER, "Environment properties were queried under {} ms for environment {}", stack.getEnvironmentCrn());
Map<String, List<CloudInstance>> instancesPerGroup = cloudInstances.stream().collect(Collectors.groupingBy(cloudInstance -> cloudInstance.getTemplate().getGroupName()));
for (Map.Entry<String, List<CloudInstance>> instancesPerGroupEntry : instancesPerGroup.entrySet()) {
InstanceGroup instanceGroup = getInstanceGroup(stack.getInstanceGroups(), instancesPerGroupEntry.getKey());
if (instanceGroup != null) {
Map<String, String> subnetAzMap = multiAzCalculatorService.prepareSubnetAzMap(environment);
Map<String, Integer> currentSubnetUsage = multiAzCalculatorService.calculateCurrentSubnetUsage(subnetAzMap, instanceGroup);
for (CloudInstance cloudInstance : instancesPerGroupEntry.getValue()) {
InstanceMetaData instanceMetaData = new InstanceMetaData();
Long privateId = cloudInstance.getTemplate().getPrivateId();
instanceMetaData.setPrivateId(privateId);
instanceMetaData.setInstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus.REQUESTED);
instanceMetaData.setInstanceGroup(instanceGroup);
instanceMetaData.setDiscoveryFQDN(freeIpa.getHostname() + String.format("%d.", privateId) + freeIpa.getDomain());
if (!subnetAzMap.isEmpty()) {
Map<String, String> filteredSubnetsByLeastUsedAz = multiAzCalculatorService.filterSubnetByLeastUsedAz(instanceGroup, subnetAzMap);
multiAzCalculatorService.updateSubnetIdForSingleInstanceIfEligible(filteredSubnetsByLeastUsedAz, currentSubnetUsage, instanceMetaData, instanceGroup);
}
instanceMetaDataRepository.save(instanceMetaData);
LOGGER.debug("Saved InstanceMetaData: {}", instanceMetaData);
instanceGroup.getInstanceMetaDataSet().add(instanceMetaData);
}
}
}
return stack;
}
use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.
the class CcmUserDataServiceTest method testFetchAndSaveCcmParametersWhenCcmV2JumpgateIsEnabled.
@Test
void testFetchAndSaveCcmParametersWhenCcmV2JumpgateIsEnabled() {
Stack stack = getAStack();
stack.setTunnel(Tunnel.CCMV2_JUMPGATE);
DefaultCcmV2JumpgateParameters defaultCcmV2JumpgateParameters = mock(DefaultCcmV2JumpgateParameters.class);
FreeIpa freeIpa = mock(FreeIpa.class);
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
when(freeIpa.getDomain()).thenReturn("cldr.work.site");
when(ccmV2JumpgateParameterSupplier.getCcmV2JumpgateParameters(anyString(), any(Optional.class), anyString(), anyString())).thenReturn(defaultCcmV2JumpgateParameters);
when(defaultCcmV2JumpgateParameters.getAgentCrn()).thenReturn("testAgentCrn");
when(hostDiscoveryService.determineGatewayFqdn(any(), any())).thenReturn("datahub.master0.cldr.work.site");
CcmConnectivityParameters ccmParameters = ThreadBasedUserCrnProvider.doAs(TEST_USER_CRN, () -> underTest.fetchAndSaveCcmParameters(stack));
assertEquals(CcmConnectivityMode.CCMV2_JUMPGATE, ccmParameters.getConnectivityMode(), "CCM V2 Jumpgate should be enabled.");
assertEquals(defaultCcmV2JumpgateParameters, ccmParameters.getCcmV2JumpgateParameters(), "CCM V2 Jumpgate Parameters should match.");
verify(ccmV2JumpgateParameterSupplier, times(1)).getCcmV2JumpgateParameters(anyString(), any(Optional.class), anyString(), anyString());
verifyNoInteractions(ccmParameterSupplier);
verify(stackService, times(1)).setCcmV2AgentCrnByStackId(100L, "testAgentCrn");
}
use of com.sequenceiq.freeipa.entity.FreeIpa 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);
}
Aggregations