use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class LoadBalancerConfigConverterTest method testConvertGcpTargetGroup.
@Test
public void testConvertGcpTargetGroup() {
CloudLoadBalancerMetadata cloudLoadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withParameters(creatGcpParams(1)).build();
TargetGroup targetGroup = new TargetGroup();
targetGroup.setType(TargetGroupType.KNOX);
TargetGroupPortPair portPair = new TargetGroupPortPair(PORT1, PORT2);
when(loadBalancerConfigService.getTargetGroupPortPairs(eq(targetGroup))).thenReturn(Set.of(portPair));
TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = underTest.convertTargetGroup(GCP, cloudLoadBalancerMetadata, targetGroup);
assertNotNull(targetGroupConfigDbWrapper.getGcpConfig());
GcpTargetGroupConfigDb gcpTargetGroupConfigDb = targetGroupConfigDbWrapper.getGcpConfig();
assertEquals(1, gcpTargetGroupConfigDb.getPortMapping().size());
assertEquals(PORT1, gcpTargetGroupConfigDb.getPortMapping().keySet().iterator().next());
GcpLoadBalancerNamesDb gcpLoadBalancerNamesDb = gcpTargetGroupConfigDb.getPortMapping().get(PORT1);
assertEquals(BACKEND_SERVICE_NAME, gcpLoadBalancerNamesDb.getBackendServiceName());
assertEquals(INSTANCE_GROUP_NAME, gcpLoadBalancerNamesDb.getInstanceGroupName());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class GCPLoadBalancerMetadataCollectorTest method testCollectSinglePublicLoadBalancer.
@Test
public void testCollectSinglePublicLoadBalancer() {
List<CloudResource> resources = new ArrayList<>();
resources.add(createCloudResource(FORWARDING_RULE_NAME_1, ResourceType.GCP_FORWARDING_RULE));
ForwardingRule publicFowardingRule = createPublicFowardingRule();
when(forwardingRuleListResponse.getItems()).thenReturn(List.of(publicFowardingRule));
List<CloudLoadBalancerMetadata> result = underTest.collectLoadBalancer(authenticatedContext, List.of(LoadBalancerType.PUBLIC), resources);
assertEquals(1, result.size());
assertEquals(PUBLIC_IP, result.get(0).getIp());
assertEquals(FORWARDING_RULE_NAME_1, result.get(0).getName());
assertEquals(FORWARDING_RULE_NAME_1, result.get(0).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)));
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class GCPLoadBalancerMetadataCollectorTest method testCollectPublicAndPrivateLoadBalancer.
@Test
public void testCollectPublicAndPrivateLoadBalancer() {
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 = createPrivateFowardingRule();
when(forwardingRuleListResponse.getItems()).thenReturn(List.of(publicFowardingRule, publicFowardingRule2));
List<CloudLoadBalancerMetadata> result = underTest.collectLoadBalancer(authenticatedContext, List.of(LoadBalancerType.PUBLIC, LoadBalancerType.PRIVATE), resources);
assertEquals(2, result.size());
Optional<CloudLoadBalancerMetadata> publicResult = result.stream().filter(p -> p.getType().equals(LoadBalancerType.PUBLIC)).findFirst();
assertTrue(publicResult.isPresent());
assertEquals(FORWARDING_RULE_NAME_1, publicResult.get().getName());
assertEquals(FORWARDING_RULE_NAME_1, publicResult.get().getStringParameter(GcpLoadBalancerMetadataView.LOADBALANCER_NAME));
assertEquals(PUBLIC_IP, publicResult.get().getIp());
assertEquals(BACKEND_SERVICE_NAME, publicResult.get().getStringParameter(GcpLoadBalancerMetadataView.getBackendServiceParam(8080)));
assertEquals(INSTANCE_GROUP_NAME, publicResult.get().getStringParameter(GcpLoadBalancerMetadataView.getInstanceGroupParam(8080)));
Optional<CloudLoadBalancerMetadata> privateResult = result.stream().filter(p -> p.getType().equals(LoadBalancerType.PRIVATE)).findFirst();
assertTrue(privateResult.isPresent());
assertEquals(FORWARDING_RULE_NAME_2, privateResult.get().getName());
assertEquals(FORWARDING_RULE_NAME_2, privateResult.get().getStringParameter(GcpLoadBalancerMetadataView.LOADBALANCER_NAME));
assertEquals(PRIVATE_IP, privateResult.get().getIp());
assertEquals(BACKEND_SERVICE_NAME, privateResult.get().getStringParameter(GcpLoadBalancerMetadataView.getBackendServiceParam(443)));
assertEquals(INSTANCE_GROUP_NAME, privateResult.get().getStringParameter(GcpLoadBalancerMetadataView.getInstanceGroupParam(443)));
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class MetadataSetupServiceTest method saveLoadBalancerMetadata.
@Test
public void saveLoadBalancerMetadata() {
stack.setName(STACK_NAME);
stack.setCloudPlatform("DEFAULT");
stack.setEnvironmentCrn(STACK_CRN);
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(loadBalancerConfigService.generateLoadBalancerEndpoint(stack)).thenCallRealMethod();
StackStatus stackStatus = new StackStatus();
stackStatus.setStatus(Status.AVAILABLE);
stackStatus.setStack(stack);
StackIdView stackIdView = new StackIdViewImpl(STACK_ID, STACK_NAME, "no");
when(stackService.getByEnvironmentCrnAndStackType(STACK_CRN, StackType.DATALAKE)).thenReturn(List.of(stackIdView));
when(stackStatusService.findFirstByStackIdOrderByCreatedDesc(STACK_ID)).thenReturn(Optional.of(stackStatus));
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("STACK_NAME-gateway");
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class LoadBalancerMetadataHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<LoadBalancerMetadataRequest> event) {
LoadBalancerMetadataRequest request = event.getData();
CloudContext cloudContext = request.getCloudContext();
try {
LOGGER.info("Fetch cloud load balancer metadata");
List<CloudLoadBalancerMetadata> loadBalancerStatuses = loadBalancerMetadataService.collectMetadata(cloudContext, request.getCloudCredential(), request.getTypesPresentInStack(), request.getCloudResources());
Set<CloudLoadBalancerMetadata> failedStatues = loadBalancerStatuses.stream().filter(this::isMissingMetadata).collect(Collectors.toSet());
if (!failedStatues.isEmpty()) {
Set<String> names = failedStatues.stream().map(CloudLoadBalancerMetadata::getName).collect(Collectors.toSet());
throw new CloudbreakException("Creation failed for load balancers: " + names);
}
LOGGER.info("Persisting load balancer metadata to the database: {}", loadBalancerStatuses);
metadataSetupService.saveLoadBalancerMetadata(request.getStack(), loadBalancerStatuses);
LOGGER.info("Load balancer metadata collection was successful");
return new LoadBalancerMetadataSuccess(request.getStack());
} catch (Exception e) {
LOGGER.warn("Failed to fetch cloud load balancer metadata.", e);
return new LoadBalancerMetadataFailure(request.getResourceId(), e);
}
}
Aggregations