use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer 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.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method convert.
public CloudStack convert(Stack stack, Collection<String> deleteRequestedInstances) {
Image image = null;
String environmentCrn = stack.getEnvironmentCrn();
DetailedEnvironmentResponse environment = environmentClientService.getByCrnAsInternal(environmentCrn);
List<Group> instanceGroups = buildInstanceGroups(stack, stack.getInstanceGroupsAsList(), stack.getStackAuthentication(), deleteRequestedInstances, environment);
try {
image = imageService.getImage(stack.getId());
} catch (CloudbreakImageNotFoundException e) {
LOGGER.debug(e.getMessage());
}
Network network = buildNetwork(stack);
StackTemplate stackTemplate = componentConfigProviderService.getStackTemplate(stack.getId());
InstanceAuthentication instanceAuthentication = buildInstanceAuthentication(stack.getStackAuthentication());
SpiFileSystem cloudFileSystem = buildSpiFileSystem(stack);
SpiFileSystem additionalCloudFileSystem = buildAdditionalSpiFileSystem(stack);
String template = null;
if (stackTemplate != null) {
template = stackTemplate.getTemplate();
}
Map<String, String> parameters = buildCloudStackParameters(stack, environment);
List<CloudLoadBalancer> cloudLoadBalancers = buildLoadBalancers(stack, instanceGroups);
return new CloudStack(instanceGroups, network, image, parameters, getUserDefinedTags(stack), template, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), cloudFileSystem, cloudLoadBalancers, additionalCloudFileSystem);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class StackToCloudStackConverterTest method testConvertWithKnoxLoadBalancer.
@Test
public void testConvertWithKnoxLoadBalancer() {
Set<InstanceGroup> instanceGroups = new LinkedHashSet<>();
InstanceGroup instanceGroup1 = mock(InstanceGroup.class);
InstanceGroup instanceGroup2 = mock(InstanceGroup.class);
when(instanceGroup1.getGroupName()).thenReturn("group1");
when(instanceGroup2.getGroupName()).thenReturn("group2");
instanceGroups.add(instanceGroup1);
instanceGroups.add(instanceGroup2);
when(stack.getInstanceGroupsAsList()).thenReturn(new ArrayList<>(instanceGroups));
Template template = new Template();
template.setVolumeTemplates(Sets.newHashSet());
when(instanceGroup1.getTemplate()).thenReturn(template);
when(instanceGroup1.getNotDeletedInstanceMetaDataSet()).thenReturn(Collections.emptySet());
when(instanceGroup1.getStack()).thenReturn(stack);
when(instanceGroup2.getTemplate()).thenReturn(template);
when(instanceGroup2.getNotDeletedInstanceMetaDataSet()).thenReturn(Collections.emptySet());
when(instanceGroup2.getStack()).thenReturn(stack);
TargetGroup targetGroup = mock(TargetGroup.class);
when(targetGroup.getType()).thenReturn(TargetGroupType.KNOX);
LoadBalancer loadBalancer = mock(LoadBalancer.class);
when(loadBalancer.getType()).thenReturn(LoadBalancerType.PRIVATE);
when(loadBalancer.getId()).thenReturn(1L);
when(loadBalancerPersistenceService.findByStackId(anyLong())).thenReturn(Set.of(loadBalancer));
when(targetGroupPersistenceService.findByLoadBalancerId(anyLong())).thenReturn(Set.of(targetGroup));
when(instanceGroupService.findByTargetGroupId(anyLong())).thenReturn(Set.of(instanceGroup1, instanceGroup2));
TargetGroupPortPair targetGroupPortPair = new TargetGroupPortPair(443, 8443);
when(loadBalancerConfigService.getTargetGroupPortPairs(any(TargetGroup.class))).thenReturn(Set.of(targetGroupPortPair));
CloudStack result = underTest.convert(stack);
assertEquals(1, result.getLoadBalancers().size());
CloudLoadBalancer cloudLoadBalancer = result.getLoadBalancers().iterator().next();
assertEquals(LoadBalancerType.PRIVATE, cloudLoadBalancer.getType());
assertEquals(Set.of(targetGroupPortPair), cloudLoadBalancer.getPortToTargetGroupMapping().keySet());
Set<String> groupNames = cloudLoadBalancer.getPortToTargetGroupMapping().values().stream().flatMap(Collection::stream).collect(Collectors.toSet()).stream().map(Group::getName).collect(Collectors.toSet());
assertEquals(Set.of("group1", "group2"), groupNames);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class StackToCloudStackConverterTest method testConvertWithLoadBalancerSkuSet.
@Test
public void testConvertWithLoadBalancerSkuSet() {
Set<InstanceGroup> instanceGroups = new LinkedHashSet<>();
InstanceGroup instanceGroup1 = mock(InstanceGroup.class);
instanceGroups.add(instanceGroup1);
Template template = new Template();
template.setVolumeTemplates(Sets.newHashSet());
TargetGroup targetGroup = mock(TargetGroup.class);
LoadBalancer loadBalancer = mock(LoadBalancer.class);
TargetGroupPortPair targetGroupPortPair = new TargetGroupPortPair(443, 8443);
when(instanceGroup1.getGroupName()).thenReturn("group1");
when(stack.getInstanceGroupsAsList()).thenReturn(new ArrayList<>(instanceGroups));
when(instanceGroup1.getTemplate()).thenReturn(template);
when(instanceGroup1.getNotDeletedInstanceMetaDataSet()).thenReturn(Collections.emptySet());
when(instanceGroup1.getStack()).thenReturn(stack);
when(targetGroup.getType()).thenReturn(TargetGroupType.KNOX);
when(loadBalancer.getType()).thenReturn(LoadBalancerType.PRIVATE);
when(loadBalancer.getId()).thenReturn(1L);
when(loadBalancer.getSku()).thenReturn(LoadBalancerSku.STANDARD);
when(loadBalancerPersistenceService.findByStackId(anyLong())).thenReturn(Set.of(loadBalancer));
when(targetGroupPersistenceService.findByLoadBalancerId(anyLong())).thenReturn(Set.of(targetGroup));
when(instanceGroupService.findByTargetGroupId(anyLong())).thenReturn(Set.of(instanceGroup1));
when(loadBalancerConfigService.getTargetGroupPortPairs(any(TargetGroup.class))).thenReturn(Set.of(targetGroupPortPair));
CloudStack result = underTest.convert(stack);
assertEquals(1, result.getLoadBalancers().size());
CloudLoadBalancer cloudLoadBalancer = result.getLoadBalancers().iterator().next();
assertEquals(LoadBalancerSku.STANDARD, cloudLoadBalancer.getSku());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class YarnLoadBalancerComponentFactoryService method create.
/**
* Creates a Yarn component for each of the loadbalancers that are to be created, using a set of pre-defined
* constants for the various component parameters.
*
* Each container is pointed at a specific docker image which contains the loadbalancing service and logic.
*/
public List<YarnComponent> create(CloudStack cloudStack, List<String> gatewayIPs, String applicationName) {
LOGGER.debug("Creating the loadbalancer components for application " + applicationName + " with gatewayIPs: " + gatewayIPs.toString() + ".");
Artifact artifact = createLoadBalancerArtifact();
if (checkDeHa(cloudStack)) {
artifact.setId(loadBalancerImageNameForDEHA);
}
Resource resource = createLoadBalancerResource();
String launchCommand = createLoadBalancerLaunchCommand(cloudStack);
Configuration configuration = createLoadBalancerConfiguration(gatewayIPs);
List<YarnComponent> loadBalancerComponents = Lists.newArrayList();
for (CloudLoadBalancer loadBalancer : cloudStack.getLoadBalancers()) {
String componentName = applicationNameUtil.createLoadBalancerComponentName(applicationName, loadBalancer.getType());
LOGGER.debug("Creating the load balancer Yarn component object for " + componentName + ".");
loadBalancerComponents.add(createLoadBalancerComponent(componentName, artifact, resource, launchCommand, configuration));
}
LOGGER.debug("Finished creating the Yarn load balancer components for application " + applicationName + ".");
return loadBalancerComponents;
}
Aggregations