use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class CollectLoadBalancerMetadataHandler method accept.
@Override
public void accept(Event<CollectLoadBalancerMetadataRequest> collectLBMetadataRequestEvent) {
LOGGER.debug("Received event: {}", collectLBMetadataRequestEvent);
CollectLoadBalancerMetadataRequest request = collectLBMetadataRequestEvent.getData();
try {
List<CloudLoadBalancerMetadata> loadBalancerStatuses = loadBalancerMetadataService.collectMetadata(request.getCloudContext(), request.getCloudCredential(), request.getTypesPresentInStack(), request.getCloudResources());
CollectLoadBalancerMetadataResult collectLBMetadataResult = new CollectLoadBalancerMetadataResult(request.getResourceId(), loadBalancerStatuses);
request.getResult().onNext(collectLBMetadataResult);
eventBus.notify(collectLBMetadataResult.selector(), new Event<>(collectLBMetadataRequestEvent.getHeaders(), collectLBMetadataResult));
LOGGER.debug("Load balancer metadata collection successfully finished");
} catch (RuntimeException e) {
LOGGER.error("Collecting load balancer metadata failed", e);
CollectLoadBalancerMetadataResult failure = new CollectLoadBalancerMetadataResult(e, request.getResourceId());
request.getResult().onNext(failure);
eventBus.notify(failure.selector(), new Event<>(collectLBMetadataRequestEvent.getHeaders(), failure));
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class YarnMetadataCollector method collectLoadBalancer.
@Override
public List<CloudLoadBalancerMetadata> collectLoadBalancer(AuthenticatedContext ac, List<LoadBalancerType> loadBalancerTypes, List<CloudResource> resources) {
List<CloudLoadBalancerMetadata> loadBalancerMetadata = Lists.newArrayList();
if (loadBalancerTypes.size() == 0) {
return loadBalancerMetadata;
}
YarnClient yarnClient = yarnClientUtil.createYarnClient(ac);
String loadBalancerApplicationName = applicationNameUtil.createLoadBalancerName(ac);
Iterable<Container> loadBalancerContainers = yarnLoadBalancerLaunchService.getContainers(loadBalancerApplicationName, yarnClient);
Iterator<Container> containerIterator = loadBalancerContainers.iterator();
for (LoadBalancerType loadBalancerType : loadBalancerTypes) {
Container container = containerIterator.next();
CloudLoadBalancerMetadata metadata = new CloudLoadBalancerMetadata.Builder().withType(loadBalancerType).withName(applicationNameUtil.createLoadBalancerComponentName(loadBalancerApplicationName, loadBalancerType)).withIp(container.getIp()).build();
loadBalancerMetadata.add(metadata);
}
return loadBalancerMetadata;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class AwsMetaDataCollectorTest method testCollectLoadBalancerOnlyDefaultGateway.
@MockitoSettings(strictness = Strictness.LENIENT)
@Test
public void testCollectLoadBalancerOnlyDefaultGateway() {
setupMethodsForLoadBalancer(true);
when(awsLoadBalancerMetadataCollector.getParameters(any(), any(), any())).thenReturn(Map.of());
AuthenticatedContext ac = authenticatedContext();
List<CloudLoadBalancerMetadata> metadata = awsMetadataCollector.collectLoadBalancer(ac, List.of(LoadBalancerType.PRIVATE), null);
assertEquals(1, metadata.size());
Optional<CloudLoadBalancerMetadata> internalMetadata = metadata.stream().filter(m -> m.getType() == LoadBalancerType.PRIVATE).findFirst();
assertTrue(internalMetadata.isPresent());
assertEquals(INTERNAL_LB_DNS, internalMetadata.get().getCloudDns());
assertEquals(ZONE_1, internalMetadata.get().getHostedZoneId());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class LoadBalancerConfigConverterTest method testConvertAwsTargetGroupExtraPortsInMetadata.
@Test
public void testConvertAwsTargetGroupExtraPortsInMetadata() {
CloudLoadBalancerMetadata cloudLoadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withParameters(createAwsParams(3)).build();
TargetGroup targetGroup = new TargetGroup();
targetGroup.setType(TargetGroupType.KNOX);
TargetGroupPortPair portPair1 = new TargetGroupPortPair(PORT1, PORT1);
TargetGroupPortPair portPair2 = new TargetGroupPortPair(PORT2, PORT2);
when(loadBalancerConfigService.getTargetGroupPortPairs(eq(targetGroup))).thenReturn(Set.of(portPair1, portPair2));
TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = underTest.convertTargetGroup(AWS, cloudLoadBalancerMetadata, targetGroup);
assertNotNull(targetGroupConfigDbWrapper.getAwsConfig());
AwsTargetGroupConfigDb awsTargetGroupConfigDb = targetGroupConfigDbWrapper.getAwsConfig();
assertEquals(2, awsTargetGroupConfigDb.getPortArnMapping().size());
assertEquals(Set.of(PORT1, PORT2), awsTargetGroupConfigDb.getPortArnMapping().keySet());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class LoadBalancerConfigConverterTest method testConvertAzureTargetGroupMissingAvailabilitySetInMetadata.
@Test
public void testConvertAzureTargetGroupMissingAvailabilitySetInMetadata() {
Map<String, Object> azureParams = createAzureParams(1);
azureParams.put(AzureLoadBalancerMetadataView.getAvailabilitySetParam(PORT2), null);
CloudLoadBalancerMetadata cloudLoadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withParameters(azureParams).build();
TargetGroup targetGroup = new TargetGroup();
targetGroup.setType(TargetGroupType.KNOX);
TargetGroupPortPair portPair1 = new TargetGroupPortPair(PORT1, PORT2);
TargetGroupPortPair portPair2 = new TargetGroupPortPair(PORT2, PORT2);
TargetGroupPortPair portPair3 = new TargetGroupPortPair(PORT3, PORT3);
when(loadBalancerConfigService.getTargetGroupPortPairs(eq(targetGroup))).thenReturn(Set.of(portPair1, portPair2, portPair3));
TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = underTest.convertTargetGroup(AZURE, cloudLoadBalancerMetadata, targetGroup);
assertNotNull(targetGroupConfigDbWrapper.getAzureConfig());
AzureTargetGroupConfigDb azureTargetGroupConfigDb = targetGroupConfigDbWrapper.getAzureConfig();
assertEquals(Set.of(PORT1, PORT2, PORT3), azureTargetGroupConfigDb.getPortAvailabilitySetMapping().keySet());
List<String> availabilitySets = azureTargetGroupConfigDb.getPortAvailabilitySetMapping().get(PORT1);
assertEquals(List.of(AVAILABILITY_SET_NAME), availabilitySets);
availabilitySets = azureTargetGroupConfigDb.getPortAvailabilitySetMapping().get(PORT2);
assertEquals(List.of(MISSING_CLOUD_RESOURCE), availabilitySets);
availabilitySets = azureTargetGroupConfigDb.getPortAvailabilitySetMapping().get(PORT3);
assertEquals(List.of(MISSING_CLOUD_RESOURCE), availabilitySets);
}
Aggregations