use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class LoadBalancerRecreatorService method collectLoadBalancerMetadata.
private List<CloudLoadBalancerMetadata> collectLoadBalancerMetadata(AuthenticatedContext authenticatedContext, Long stackId) {
List<LoadBalancerType> loadBalancerTypes = loadBalancerPersistenceService.findByStackId(stackId).stream().map(LoadBalancer::getType).collect(Collectors.toList());
List<CloudResource> cloudResources = resourceService.findByStackIdAndType(stackId, ResourceType.ELASTIC_LOAD_BALANCER).stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
CollectLoadBalancerMetadataRequest request = new CollectLoadBalancerMetadataRequest(authenticatedContext.getCloudContext(), authenticatedContext.getCloudCredential(), loadBalancerTypes, cloudResources);
eventBus.notify(request.selector(), Event.wrap(request));
try {
CollectLoadBalancerMetadataResult res = request.await();
LOGGER.debug("Collect load balancer metadata result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
String msg = "Failed to collect the load balancer metadata. " + res.getErrorDetails().getMessage();
LOGGER.debug(msg);
throw new CloudbreakServiceException(msg, res.getErrorDetails());
}
return res.getResults();
} catch (InterruptedException e) {
LOGGER.error("Error while collect load balancer metadata", e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class LoadBalancerRecreatorService method recreate.
@Override
public void recreate(CreateResourcesRequest request, AwsContext awsContext, AuthenticatedContext ac) throws Exception {
LOGGER.info("Launching elastic load balancers");
CloudCredential cloudCredential = ac.getCloudCredential();
String region = ac.getCloudContext().getLocation().getRegion().value();
AwsCredentialView awsCredentialView = new AwsCredentialView(cloudCredential);
AmazonElasticLoadBalancingClient elasticLoadBalancingClient = commonAwsClient.createElasticLoadBalancingClient(awsCredentialView, region);
CloudStack cloudStack = request.getCloudStack();
loadBalancerLaunchService.launchLoadBalancerResources(ac, cloudStack, persistenceNotifier, elasticLoadBalancingClient, false);
List<CloudLoadBalancerMetadata> cloudLoadBalancerMetadata = collectLoadBalancerMetadata(ac, ac.getCloudContext().getId());
Stack stack = stackService.getByIdWithLists(ac.getCloudContext().getId());
metadataSetupService.saveLoadBalancerMetadata(stack, cloudLoadBalancerMetadata);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class AzureMetadataCollector method collectLoadBalancer.
@Override
public List<CloudLoadBalancerMetadata> collectLoadBalancer(AuthenticatedContext ac, List<LoadBalancerType> loadBalancerTypes, List<CloudResource> resources) {
LOGGER.debug("Collecting Azure load balancer metadata, for cluster {}", ac.getCloudContext().getName());
List<CloudLoadBalancerMetadata> cloudLoadBalancerMetadata = new ArrayList<>();
String resourceGroup = azureUtils.getTemplateResource(resources).getName();
final String stackName = azureUtils.getStackName(ac.getCloudContext());
AzureClient azureClient = ac.getParameter(AzureClient.class);
for (LoadBalancerType type : loadBalancerTypes) {
String loadBalancerName = AzureLoadBalancer.getLoadBalancerName(type, stackName);
LOGGER.debug("Attempting to collect metadata for load balancer {}, type {}", loadBalancerName, type);
try {
Optional<String> ip;
if (LoadBalancerType.PUBLIC.equals(type)) {
ip = lookupPublicIp(resourceGroup, azureClient, loadBalancerName);
} else if (LoadBalancerType.PRIVATE.equals(type)) {
ip = lookupPrivateIp(resourceGroup, azureClient, loadBalancerName);
} else {
ip = Optional.empty();
}
if (ip.isPresent()) {
Map<String, Object> parameters = azureLbMetadataCollector.getParameters(ac, resourceGroup, loadBalancerName);
CloudLoadBalancerMetadata loadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withType(type).withIp(ip.get()).withName(loadBalancerName).withParameters(parameters).build();
cloudLoadBalancerMetadata.add(loadBalancerMetadata);
LOGGER.debug("Saved metadata for load balancer: {}", loadBalancerMetadata);
} else {
LOGGER.warn("Unable to find metadata for load balancer {}.", loadBalancerName);
}
} catch (RuntimeException e) {
LOGGER.warn("Unable to find metadata for load balancer " + loadBalancerName, e);
}
}
return cloudLoadBalancerMetadata;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class GcpMetadataCollector method collectLoadBalancer.
@Override
public List<CloudLoadBalancerMetadata> collectLoadBalancer(AuthenticatedContext ac, List<LoadBalancerType> loadBalancerTypes, List<CloudResource> resources) {
CloudCredential credential = ac.getCloudCredential();
Compute compute = gcpComputeFactory.buildCompute(credential);
String projectId = gcpStackUtil.getProjectId(credential);
String region = ac.getCloudContext().getLocation().getRegion().getRegionName();
List<CloudLoadBalancerMetadata> results = new ArrayList<>();
Set<String> names = resources.stream().filter(resource -> resource.getType().equals(ResourceType.GCP_FORWARDING_RULE)).map(CloudResource::getName).collect(Collectors.toSet());
try {
ForwardingRuleList forwardingRuleList = compute.forwardingRules().list(projectId, region).execute();
if (forwardingRuleList.getWarning() != null) {
LOGGER.warn("Warning fetching GCP loadbalancer metadata, {}", forwardingRuleList.getWarning().getMessage());
}
for (ForwardingRule item : forwardingRuleList.getItems()) {
LoadBalancerType itemType = gcpLoadBalancerTypeConverter.getScheme(item.getLoadBalancingScheme()).getCbType();
if (names.contains(item.getName()) && loadBalancerTypes.contains(itemType)) {
Map<String, Object> params = getParams(compute, projectId, item);
CloudLoadBalancerMetadata loadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withType(itemType).withIp(item.getIPAddress()).withName(item.getName()).withParameters(params).build();
results.add(loadBalancerMetadata);
}
}
} catch (RuntimeException | IOException e) {
LOGGER.error("Couldn't collect GCP LB metadata for {} ", projectId, e);
}
// no-op
return results;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.
the class GCPLoadBalancerMetadataCollectorTest method testNullPortInformation.
@Test
public void testNullPortInformation() {
List<CloudResource> resources = new ArrayList<>();
resources.add(createCloudResource(FORWARDING_RULE_NAME_1, ResourceType.GCP_FORWARDING_RULE));
ForwardingRule publicFowardingRule = createPublicFowardingRule();
publicFowardingRule.setPorts(null);
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(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)));
}
Aggregations