use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class GCPLoadBalancerMetadataCollectorTest method testCollectLoadBalancerWithNoIps.
@Test
public void testCollectLoadBalancerWithNoIps() {
List<CloudResource> resources = new ArrayList<>();
resources.add(createCloudResource(FORWARDING_RULE_NAME_1, ResourceType.GCP_FORWARDING_RULE));
ForwardingRule forwardingRule = new ForwardingRule();
forwardingRule.setLoadBalancingScheme("EXTERNAL");
forwardingRule.setName(FORWARDING_RULE_NAME_1);
when(forwardingRuleListResponse.getItems()).thenReturn(List.of(forwardingRule));
List<CloudLoadBalancerMetadata> result = underTest.collectLoadBalancer(authenticatedContext, List.of(LoadBalancerType.PUBLIC), resources);
assertEquals(1, result.size());
assertEquals(null, result.get(0).getIp());
assertEquals(LoadBalancerType.PUBLIC, result.get(0).getType());
assertEquals(FORWARDING_RULE_NAME_1, result.get(0).getName());
assertEquals(FORWARDING_RULE_NAME_1, result.get(0).getStringParameter(GcpLoadBalancerMetadataView.LOADBALANCER_NAME));
assertNull(result.get(0).getStringParameter(GcpLoadBalancerMetadataView.getBackendServiceParam(8080)));
assertNull(result.get(0).getStringParameter(GcpLoadBalancerMetadataView.getInstanceGroupParam(8080)));
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class GCPLoadBalancerMetadataCollectorTest method testCollectSinglePublicLoadBalancerWithMultipleForwardingRules.
@Test
public void testCollectSinglePublicLoadBalancerWithMultipleForwardingRules() {
List<CloudResource> resources = new ArrayList<>();
resources.add(createCloudResource(FORWARDING_RULE_NAME_1, ResourceType.GCP_FORWARDING_RULE));
resources.add(createCloudResource(FORWARDING_RULE_NAME_2, ResourceType.GCP_FORWARDING_RULE));
ForwardingRule publicFowardingRule = createPublicFowardingRule();
ForwardingRule publicFowardingRule2 = createPublicFowardingRule();
publicFowardingRule2.setIPAddress(PUBLIC_IP2);
publicFowardingRule2.setName(FORWARDING_RULE_NAME_2);
when(forwardingRuleListResponse.getItems()).thenReturn(List.of(publicFowardingRule, publicFowardingRule2));
List<CloudLoadBalancerMetadata> result = underTest.collectLoadBalancer(authenticatedContext, List.of(LoadBalancerType.PUBLIC), resources);
assertEquals(2, result.size());
assertEquals(PUBLIC_IP, result.get(0).getIp());
assertEquals(PUBLIC_IP2, result.get(1).getIp());
assertEquals(FORWARDING_RULE_NAME_1, result.get(0).getName());
assertEquals(FORWARDING_RULE_NAME_1, result.get(0).getStringParameter(GcpLoadBalancerMetadataView.LOADBALANCER_NAME));
assertEquals(FORWARDING_RULE_NAME_2, result.get(1).getName());
assertEquals(FORWARDING_RULE_NAME_2, result.get(1).getStringParameter(GcpLoadBalancerMetadataView.LOADBALANCER_NAME));
assertEquals(LoadBalancerType.PUBLIC, result.get(0).getType());
assertEquals(BACKEND_SERVICE_NAME, result.get(0).getStringParameter(GcpLoadBalancerMetadataView.getBackendServiceParam(8080)));
assertEquals(INSTANCE_GROUP_NAME, result.get(0).getStringParameter(GcpLoadBalancerMetadataView.getInstanceGroupParam(8080)));
assertEquals(BACKEND_SERVICE_NAME, result.get(1).getStringParameter(GcpLoadBalancerMetadataView.getBackendServiceParam(8080)));
assertEquals(INSTANCE_GROUP_NAME, result.get(1).getStringParameter(GcpLoadBalancerMetadataView.getInstanceGroupParam(8080)));
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class GCPLoadBalancerMetadataCollectorTest method testCollectPrivateLoadBalancer.
@Test
public void testCollectPrivateLoadBalancer() {
List<CloudResource> resources = new ArrayList<>();
resources.add(createCloudResource(FORWARDING_RULE_NAME_2, ResourceType.GCP_FORWARDING_RULE));
ForwardingRule privateForwardingRule = createPrivateFowardingRule();
when(forwardingRuleListResponse.getItems()).thenReturn(List.of(privateForwardingRule));
List<CloudLoadBalancerMetadata> result = underTest.collectLoadBalancer(authenticatedContext, List.of(LoadBalancerType.PRIVATE), resources);
assertEquals(1, result.size());
assertEquals(PRIVATE_IP, result.get(0).getIp());
assertEquals(LoadBalancerType.PRIVATE, result.get(0).getType());
assertEquals(FORWARDING_RULE_NAME_2, result.get(0).getName());
assertEquals(FORWARDING_RULE_NAME_2, result.get(0).getStringParameter(GcpLoadBalancerMetadataView.LOADBALANCER_NAME));
assertEquals(BACKEND_SERVICE_NAME, result.get(0).getStringParameter(GcpLoadBalancerMetadataView.getBackendServiceParam(443)));
assertEquals(INSTANCE_GROUP_NAME, result.get(0).getStringParameter(GcpLoadBalancerMetadataView.getInstanceGroupParam(443)));
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class GCPLoadBalancerMetadataCollectorTest method testCollectOtherType.
@Test
public void testCollectOtherType() {
List<CloudResource> resources = new ArrayList<>();
resources.add(createCloudResource(FORWARDING_RULE_NAME_2, ResourceType.GCP_FORWARDING_RULE));
ForwardingRule privateForwardingRule = createPrivateFowardingRule();
when(forwardingRuleListResponse.getItems()).thenReturn(List.of(privateForwardingRule));
List<CloudLoadBalancerMetadata> result = underTest.collectLoadBalancer(authenticatedContext, List.of(LoadBalancerType.PUBLIC), resources);
assertEquals(0, result.size());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata 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");
}
Aggregations