Search in sources :

Example 21 with CloudLoadBalancer

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;
}
Also used : CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) ArrayList(java.util.ArrayList) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)

Example 22 with CloudLoadBalancer

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);
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) AzureResourceGroup(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup) SecurityGroup(com.sequenceiq.cloudbreak.domain.SecurityGroup) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate)

Example 23 with CloudLoadBalancer

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Template(com.sequenceiq.cloudbreak.domain.Template) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) Collection(java.util.Collection) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with CloudLoadBalancer

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());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Template(com.sequenceiq.cloudbreak.domain.Template) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with CloudLoadBalancer

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;
}
Also used : CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) Configuration(com.sequenceiq.cloudbreak.cloud.yarn.client.model.core.Configuration) Resource(com.sequenceiq.cloudbreak.cloud.yarn.client.model.core.Resource) YarnComponent(com.sequenceiq.cloudbreak.cloud.yarn.client.model.core.YarnComponent) Artifact(com.sequenceiq.cloudbreak.cloud.yarn.client.model.core.Artifact)

Aggregations

CloudLoadBalancer (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer)47 TargetGroupPortPair (com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)27 Group (com.sequenceiq.cloudbreak.cloud.model.Group)24 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)21 ArrayList (java.util.ArrayList)21 Test (org.junit.jupiter.api.Test)20 List (java.util.List)15 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)13 LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)13 HashMap (java.util.HashMap)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)12 Set (java.util.Set)12 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)10 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)10 Network (com.sequenceiq.cloudbreak.cloud.model.Network)10 Map (java.util.Map)10 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)9