use of com.sequenceiq.common.api.type.LoadBalancerType 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.common.api.type.LoadBalancerType in project cloudbreak by hortonworks.
the class CreateCloudLoadBalancersHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<CreateCloudLoadBalancersRequest> event) {
CreateCloudLoadBalancersRequest request = event.getData();
CloudContext cloudContext = request.getCloudContext();
try {
LOGGER.info("Updating cloud stack with load balancer network information");
CloudStack origCloudStack = request.getCloudStack();
Stack stack = request.getStack();
CloudStack updatedCloudStack = new CloudStack(origCloudStack.getGroups(), cloudStackConverter.buildNetwork(stack), origCloudStack.getImage(), origCloudStack.getParameters(), origCloudStack.getTags(), origCloudStack.getTemplate(), origCloudStack.getInstanceAuthentication(), origCloudStack.getLoginUserName(), origCloudStack.getPublicKey(), origCloudStack.getFileSystem().orElse(null), origCloudStack.getLoadBalancers());
CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
LOGGER.debug("Initiating cloud load balancer creation");
List<CloudResourceStatus> resourceStatus = connector.resources().launchLoadBalancers(ac, updatedCloudStack, persistenceNotifier);
LOGGER.debug("Waiting for cloud load balancers to be fully created");
List<CloudResource> resources = ResourceLists.transform(resourceStatus);
PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatus);
if (!task.completed(statePollerResult)) {
syncPollingScheduler.schedule(task);
}
if (resourceStatus.stream().anyMatch(CloudResourceStatus::isFailed)) {
Set<String> names = resourceStatus.stream().filter(CloudResourceStatus::isFailed).map(r -> r.getCloudResource().getName()).collect(Collectors.toSet());
throw new CloudbreakException("Creation failed for load balancers: " + names);
}
Set<String> types = updatedCloudStack.getLoadBalancers().stream().map(CloudLoadBalancer::getType).map(LoadBalancerType::toString).collect(Collectors.toSet());
LOGGER.info("Cloud load balancer creation for load balancer types {} successful", types);
return new CreateCloudLoadBalancersSuccess(stack);
} catch (Exception e) {
LOGGER.warn("Failed to created cloud load balance resources.", e);
return new CreateCloudLoadBalancersFailure(request.getResourceId(), e);
}
}
use of com.sequenceiq.common.api.type.LoadBalancerType in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonService method convertLoadBalancer.
@VisibleForTesting
AwsLoadBalancer convertLoadBalancer(CloudLoadBalancer cloudLoadBalancer, Map<String, List<String>> instanceIdsByGroupName, AwsNetworkView awsNetworkView, List<AwsLoadBalancer> awsLoadBalancers) {
// Check and see if we already have a load balancer whose scheme matches this one.
AwsLoadBalancer currentLoadBalancer = null;
LoadBalancerType cloudLbType = cloudLoadBalancer.getType();
Set<String> subnetIds = selectLoadBalancerSubnetIds(cloudLbType, awsNetworkView, cloudLoadBalancer);
AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(cloudLbType);
currentLoadBalancer = awsLoadBalancers.stream().filter(lb -> lb.getScheme() == scheme).findFirst().orElse(new AwsLoadBalancer(scheme));
currentLoadBalancer.addSubnets(subnetIds);
setupLoadBalancer(cloudLoadBalancer, instanceIdsByGroupName, currentLoadBalancer);
return currentLoadBalancer;
}
use of com.sequenceiq.common.api.type.LoadBalancerType 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.common.api.type.LoadBalancerType 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;
}
Aggregations