use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class LoadBalancerConfigServiceTest method testCreateAzurePrivateLoadBalancerWithOozieHA.
@Test
public void testCreateAzurePrivateLoadBalancerWithOozieHA() {
Stack stack = createAzureStack(StackType.DATALAKE, PRIVATE_ID_1, true);
CloudSubnet subnet = getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1);
DetailedEnvironmentResponse environment = createEnvironment(subnet, false, "AZURE");
StackV4Request request = new StackV4Request();
request.setEnableLoadBalancer(false);
when(entitlementService.azureDatalakeLoadBalancerEnabled(anyString())).thenReturn(true);
when(blueprint.getBlueprintText()).thenReturn(getBlueprintText("input/de-ha.bp"));
when(subnetSelector.findSubnetById(any(), anyString())).thenReturn(Optional.of(subnet));
when(availabilitySetNameService.generateName(any(), any())).thenReturn("");
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
Set<LoadBalancer> loadBalancers = underTest.createLoadBalancers(stack, environment, request);
assertEquals(2, loadBalancers.size());
assert loadBalancers.stream().anyMatch(l -> LoadBalancerType.PRIVATE.equals(l.getType()));
assert loadBalancers.stream().anyMatch(l -> LoadBalancerType.OUTBOUND.equals(l.getType()));
InstanceGroup managerInstanceGroup = stack.getInstanceGroups().stream().filter(ig -> "manager".equals(ig.getGroupName())).findFirst().get();
assertEquals(2, managerInstanceGroup.getTargetGroups().size());
checkAvailabilitySetAttributes(loadBalancers);
});
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method buildLoadBalancers.
private List<CloudLoadBalancer> buildLoadBalancers(Stack stack, List<Group> instanceGroups) {
List<CloudLoadBalancer> cloudLoadBalancers = new ArrayList<>();
for (LoadBalancer loadBalancer : loadBalancerPersistenceService.findByStackId(stack.getId())) {
CloudLoadBalancer cloudLoadBalancer = new CloudLoadBalancer(loadBalancer.getType(), loadBalancer.getSku());
for (TargetGroup targetGroup : targetGroupPersistenceService.findByLoadBalancerId(loadBalancer.getId())) {
Set<TargetGroupPortPair> portPairs = loadBalancerConfigService.getTargetGroupPortPairs(targetGroup);
Set<String> targetInstanceGroupName = instanceGroupService.findByTargetGroupId(targetGroup.getId()).stream().map(InstanceGroup::getGroupName).collect(Collectors.toSet());
for (TargetGroupPortPair portPair : portPairs) {
cloudLoadBalancer.addPortToTargetGroupMapping(portPair, instanceGroups.stream().filter(ig -> targetInstanceGroupName.contains(ig.getName())).collect(Collectors.toSet()));
}
}
cloudLoadBalancers.add(cloudLoadBalancer);
}
return cloudLoadBalancers;
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class StackCreationActions method collectMetadataAction.
@Bean(name = "COLLECTMETADATA_STATE")
public Action<?, ?> collectMetadataAction() {
return new AbstractStackCreationAction<>(CollectMetadataResult.class) {
@Override
protected void doExecute(StackCreationContext context, CollectMetadataResult payload, Map<Object, Object> variables) {
Stack stack = stackCreationService.setupMetadata(context, payload);
StackCreationContext newContext = new StackCreationContext(context.getFlowParameters(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
sendEvent(newContext);
}
@Override
protected Selectable createRequest(StackCreationContext context) {
List<LoadBalancerType> loadBalancerTypes = loadBalancerPersistenceService.findByStackId(context.getStack().getId()).stream().map(LoadBalancer::getType).collect(Collectors.toList());
List<CloudResource> cloudResources = context.getStack().getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
return new CollectLoadBalancerMetadataRequest(context.getCloudContext(), context.getCloudCredential(), loadBalancerTypes, cloudResources);
}
};
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class LoadBalancerConfigService method setupLoadBalancer.
private void setupLoadBalancer(boolean dryRun, Stack stack, Set<LoadBalancer> loadBalancers, TargetGroup targetGroup, LoadBalancerType type) {
if (dryRun) {
LOGGER.debug("{} load balancer can be configured for stack {}. Adding mock LB to configurable LB list.", type, stack.getName());
LoadBalancer mockLb = new LoadBalancer();
mockLb.setType(type);
loadBalancers.add(mockLb);
} else {
LOGGER.debug("Found {} enabled instance groups in stack. Setting up {} load balancer.", targetGroup.getType(), type);
setupLoadBalancerWithTargetGroup(createLoadBalancerIfNotExists(loadBalancers, type, stack), targetGroup);
}
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class LoadBalancerConfigService method createLoadBalancerIfNotExists.
private LoadBalancer createLoadBalancerIfNotExists(Set<LoadBalancer> loadBalancers, LoadBalancerType type, Stack stack) {
LoadBalancer loadBalancer;
Optional<LoadBalancer> existingLoadBalancer = loadBalancers.stream().filter(lb -> lb.getType() == type).findFirst();
if (existingLoadBalancer.isPresent()) {
loadBalancer = existingLoadBalancer.get();
} else {
loadBalancer = new LoadBalancer();
loadBalancer.setType(type);
loadBalancer.setStack(stack);
loadBalancers.add(loadBalancer);
}
return loadBalancer;
}
Aggregations