use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class LoadBalancerToLoadBalancerResponseConverterTest method testNoSavedCloudConfig.
@Test
public void testNoSavedCloudConfig() {
LoadBalancer source = getSource();
// GIVEN
given(targetGroupService.findByLoadBalancerId(any())).willReturn(createAwsTargetGroups());
// WHEN
LoadBalancerResponse response = underTest.convert(source);
// THEN
assertAllFieldsNotNull(response, List.of("awsResourceId", "azureResourceId", "gcpResourceId"));
assertNull(response.getAwsResourceId());
assertNull(response.getAzureResourceId());
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class LoadBalancerSANProviderTest method loadBalancerSetUp.
private void loadBalancerSetUp(String dns, String ip) {
LoadBalancer loadBalancer = new LoadBalancer();
if (dns != null) {
loadBalancer.setDns("foobar.timbuk2.com");
}
if (ip != null) {
loadBalancer.setIp("10.10.10.10");
}
Set<LoadBalancer> loadBalancers = new HashSet<>();
loadBalancers.add(loadBalancer);
when(loadBalancerPersistenceService.findByStackId(ID)).thenReturn(loadBalancers);
when(loadBalancerConfigService.selectLoadBalancerForFrontend(loadBalancers, LoadBalancerType.PUBLIC)).thenReturn(Optional.of(loadBalancer));
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class MetadataSetupServiceTest method saveLoadBalancerMetadataAndSetEndpointToOldStack.
@Test
public void saveLoadBalancerMetadataAndSetEndpointToOldStack() {
Stack oldStack = new Stack();
oldStack.setId(OLD_STACK_ID);
oldStack.setName(OLD_STACK_NAME);
oldStack.setCloudPlatform("DEFAULT");
oldStack.setEnvironmentCrn(STACK_CRN);
oldStack.setDisplayName(STACK_DISPLAY_NAME);
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setId(INSTANCE_GROUP_ID);
instanceGroup.setGroupName(GROUP_NAME);
instanceGroup.setInstanceGroupType(InstanceGroupType.GATEWAY);
InstanceMetaData pgwInstanceMetadata = new InstanceMetaData();
pgwInstanceMetadata.setInstanceStatus(STOPPED);
pgwInstanceMetadata.setDiscoveryFQDN("master0.subdomain.cldr.work");
pgwInstanceMetadata.setInstanceMetadataType(GATEWAY_PRIMARY);
instanceGroup.setInstanceMetaData(Set.of(pgwInstanceMetadata));
oldStack.setInstanceGroups(Set.of(instanceGroup));
stack.setName(STACK_NAME);
stack.setCloudPlatform("DEFAULT");
stack.setEnvironmentCrn(STACK_CRN);
stack.setDisplayName(STACK_DISPLAY_NAME);
LoadBalancer loadBalancer = new LoadBalancer();
loadBalancer.setStack(stack);
loadBalancer.setType(LoadBalancerType.PUBLIC);
Set<LoadBalancer> loadBalancerSet = new HashSet<>();
loadBalancerSet.add(loadBalancer);
when(loadBalancerPersistenceService.findByStackId(STACK_ID)).thenReturn(loadBalancerSet);
when(loadBalancerPersistenceService.findByStackId(OLD_STACK_ID)).thenReturn(new HashSet<>());
when(loadBalancerConfigService.generateLoadBalancerEndpoint(stack)).thenCallRealMethod();
StackIdView stackIdView = new StackIdViewImpl(STACK_ID, STACK_NAME, "no");
StackStatus stackStatus = new StackStatus();
stackStatus.setStatus(Status.AVAILABLE);
stackStatus.setStack(stack);
StackIdView stackIdViewOld = new StackIdViewImpl(OLD_STACK_ID, OLD_STACK_NAME, "old_no");
StackStatus stoppedStackStatus = new StackStatus();
stoppedStackStatus.setStatus(Status.STOPPED);
stoppedStackStatus.setStack(oldStack);
when(stackService.getByEnvironmentCrnAndStackType(STACK_CRN, StackType.DATALAKE)).thenReturn(List.of(stackIdView, stackIdViewOld));
when(stackStatusService.findFirstByStackIdOrderByCreatedDesc(STACK_ID)).thenReturn(Optional.of(stackStatus));
when(stackStatusService.findFirstByStackIdOrderByCreatedDesc(OLD_STACK_ID)).thenReturn(Optional.of(stoppedStackStatus));
when(stackService.getByIdWithGatewayInTransaction(OLD_STACK_ID)).thenReturn(oldStack);
when(targetGroupPersistenceService.findByLoadBalancerId(any())).thenReturn(Set.of());
Iterable<CloudLoadBalancerMetadata> cloudLoadBalancerMetaDataStatuses = getCloudLoadBalancerMetaDataStatuses();
underTest.saveLoadBalancerMetadata(stack, cloudLoadBalancerMetaDataStatuses);
verify(loadBalancerPersistenceService).save(loadBalancerCaptor.capture());
LoadBalancer loadBalancerValue = loadBalancerCaptor.getValue();
assertThat(loadBalancerValue.getHostedZoneId()).isSameAs(HOSTED_ZONE);
assertThat(loadBalancerValue.getIp()).isSameAs(PUBLIC_IP);
assertThat(loadBalancerValue.getDns()).isSameAs(CLOUD_DNS);
assertThat(loadBalancerValue.getEndpoint()).isEqualTo("master0");
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class FreeIPAEndpointManagementServiceTest method testRegisterLoadBalancerWithIP.
@Test
public void testRegisterLoadBalancerWithIP() {
LoadBalancer loadBalancer = new LoadBalancer();
loadBalancer.setType(LoadBalancerType.PUBLIC);
loadBalancer.setIp(LB_IP);
loadBalancer.setEndpoint(LB_ENDPOINT);
when(loadBalancerPersistenceService.findByStackId(any())).thenReturn(Set.of(loadBalancer));
when(loadBalancerConfigService.selectLoadBalancerForFrontend(any(), any())).thenReturn(Optional.of(loadBalancer));
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
ThreadBasedUserCrnProvider.doAs(TEST_USER_CRN, () -> underTest.registerLoadBalancerDomainWithFreeIPA(stack));
ArgumentCaptor<AddDnsARecordRequest> requestCaptor = ArgumentCaptor.forClass(AddDnsARecordRequest.class);
verify(dnsV1Endpoint, times(1)).addDnsARecordInternal(any(), requestCaptor.capture());
assertEquals(LB_IP, requestCaptor.getValue().getIp());
assertEquals(LB_ENDPOINT, requestCaptor.getValue().getHostname());
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class GatewayPublicEndpointManagementServiceTest method testUpdateDnsEntryForLoadBalancers.
@Test
void testUpdateDnsEntryForLoadBalancers() {
SecurityConfig securityConfig = new SecurityConfig();
Cluster cluster = TestUtil.cluster();
LoadBalancer loadBalancer = new LoadBalancer();
loadBalancer.setEndpoint("gateway");
loadBalancer.setDns("http://cloud.dns");
loadBalancer.setHostedZoneId("1");
loadBalancer.setType(LoadBalancerType.PUBLIC);
Stack stack = cluster.getStack();
stack.setSecurityConfig(securityConfig);
stack.setCluster(cluster);
stack.setLoadBalancers(Set.of(loadBalancer));
String envName = "anEnvName";
DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.builder().withName(envName).build();
when(loadBalancerPersistenceService.findByStackId(anyLong())).thenReturn(Set.of(loadBalancer));
when(loadBalancerConfigService.selectLoadBalancerForFrontend(any(), any())).thenReturn(Optional.of(loadBalancer));
when(environmentClientService.getByCrn(anyString())).thenReturn(environment);
when(dnsManagementService.createOrUpdateDnsEntryWithCloudDns(any(), any(), any(), any(), any())).thenReturn(Boolean.TRUE);
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
boolean result = underTest.updateDnsEntryForLoadBalancers(stack);
assert result;
});
}
Aggregations