Search in sources :

Example 31 with TargetGroupPortPair

use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.

the class AzureTemplateBuilderTest method buildWithGatewayInstanceGroupTypeAndLoadBalancer.

@ParameterizedTest(name = "buildWithGatewayInstanceGroupTypeAndLoadBalancer {0}")
@MethodSource("templatesPathDataProvider")
public void buildWithGatewayInstanceGroupTypeAndLoadBalancer(String templatePath) {
    assumeTrue(isTemplateVersionGreaterOrEqualThan(templatePath, "2.7.3.0"));
    // GIVEN
    ReflectionTestUtils.setField(azureTemplateBuilder, FIELD_ARM_TEMPLATE_PATH, templatePath);
    Network network = new Network(new Subnet(SUBNET_CIDR));
    Map<String, String> parameters = new HashMap<>();
    parameters.put("persistentStorage", "persistentStorageTest");
    parameters.put("attachedStorageOption", "attachedStorageOptionTest");
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    groups.add(new Group("gateway-group", InstanceGroupType.GATEWAY, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), ROOT_VOLUME_SIZE, Optional.empty(), createGroupNetwork(), emptyMap()));
    List<CloudLoadBalancer> loadBalancers = new ArrayList<>();
    CloudLoadBalancer loadBalancer = new CloudLoadBalancer(LoadBalancerType.PUBLIC);
    loadBalancer.addPortToTargetGroupMapping(new TargetGroupPortPair(443, 8443), new HashSet<>(groups));
    loadBalancers.add(loadBalancer);
    cloudStack = new CloudStack(groups, network, image, parameters, tags, azureTemplateBuilder.getTemplateString(), instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), null, loadBalancers);
    azureStackView = new AzureStackView("mystack", 3, groups, azureStorageView, azureSubnetStrategy, Collections.emptyMap());
    // WHEN
    when(azureAcceleratedNetworkValidator.validate(any())).thenReturn(ACCELERATED_NETWORK_SUPPORT);
    when(azureStorage.getImageStorageName(any(AzureCredentialView.class), any(CloudContext.class), any(CloudStack.class))).thenReturn("test");
    when(azureStorage.getDiskContainerName(any(CloudContext.class))).thenReturn("testStorageContainer");
    String templateString = azureTemplateBuilder.build(stackName, CUSTOM_IMAGE_NAME, azureCredentialView, azureStackView, cloudContext, cloudStack, AzureInstanceTemplateOperation.PROVISION, null);
    // THEN
    gson.fromJson(templateString, Map.class);
    assertTrue(templateString.contains("\"type\": \"Microsoft.Network/loadBalancers\","));
    assertTrue(templateString.contains("\"frontendPort\": 443,"));
    assertTrue(templateString.contains("\"backendPort\": 443,"));
    assertTrue(templateString.contains("\"name\": \"port-443-rule\","));
    assertTrue(templateString.contains("\"name\": \"port-8443-probe\","));
    assertTrue(templateString.contains("\"type\": \"Microsoft.Network/publicIPAddresses\","));
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) AzureStackView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 32 with TargetGroupPortPair

use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.

the class AzureTemplateBuilderTest method buildWithGatewayInstanceGroupTypeAndBasicLoadBalancer.

@ParameterizedTest(name = "buildWithGatewayInstanceGroupTypeAndBasicLoadBalancer {0}")
@MethodSource("templatesPathDataProvider")
public void buildWithGatewayInstanceGroupTypeAndBasicLoadBalancer(String templatePath) {
    assumeTrue(isTemplateVersionGreaterOrEqualThan(templatePath, "2.7.3.0"));
    // GIVEN
    ReflectionTestUtils.setField(azureTemplateBuilder, FIELD_ARM_TEMPLATE_PATH, templatePath);
    Network network = new Network(new Subnet(SUBNET_CIDR));
    Map<String, String> parameters = new HashMap<>();
    parameters.put("persistentStorage", "persistentStorageTest");
    parameters.put("attachedStorageOption", "attachedStorageOptionTest");
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    groups.add(new Group("gateway-group", InstanceGroupType.GATEWAY, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), ROOT_VOLUME_SIZE, Optional.empty(), createGroupNetwork(), emptyMap()));
    List<CloudLoadBalancer> loadBalancers = new ArrayList<>();
    CloudLoadBalancer loadBalancer = new CloudLoadBalancer(LoadBalancerType.PUBLIC, LoadBalancerSku.BASIC);
    loadBalancer.addPortToTargetGroupMapping(new TargetGroupPortPair(443, 8443), new HashSet<>(groups));
    loadBalancers.add(loadBalancer);
    cloudStack = new CloudStack(groups, network, image, parameters, tags, azureTemplateBuilder.getTemplateString(), instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), null, loadBalancers);
    azureStackView = new AzureStackView("mystack", 3, groups, azureStorageView, azureSubnetStrategy, Collections.emptyMap());
    // WHEN
    when(azureAcceleratedNetworkValidator.validate(any())).thenReturn(ACCELERATED_NETWORK_SUPPORT);
    when(azureStorage.getImageStorageName(any(AzureCredentialView.class), any(CloudContext.class), any(CloudStack.class))).thenReturn("test");
    when(azureStorage.getDiskContainerName(any(CloudContext.class))).thenReturn("testStorageContainer");
    String templateString = azureTemplateBuilder.build(stackName, CUSTOM_IMAGE_NAME, azureCredentialView, azureStackView, cloudContext, cloudStack, AzureInstanceTemplateOperation.PROVISION, null);
    // THEN
    gson.fromJson(templateString, Map.class);
    assertTrue(templateString.contains("\"type\": \"Microsoft.Network/loadBalancers\","));
    assertTrue(templateString.contains("\"frontendPort\": 443,"));
    assertTrue(templateString.contains("\"backendPort\": 443,"));
    assertTrue(templateString.contains("\"name\": \"port-443-rule\","));
    assertTrue(templateString.contains("\"name\": \"port-8443-probe\","));
    assertTrue(templateString.contains("\"type\": \"Microsoft.Network/publicIPAddresses\","));
    assertTrue(templateString.contains("\"name\": \"Basic\""));
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) AzureStackView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 33 with TargetGroupPortPair

use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.

the class GcpHealthCheckResourceBuilder method create.

@Override
public List<CloudResource> create(GcpContext context, AuthenticatedContext auth, CloudLoadBalancer loadBalancer) {
    List<CloudResource> resources = new ArrayList<>();
    List<Integer> healthPorts = loadBalancer.getPortToTargetGroupMapping().keySet().stream().map(TargetGroupPortPair::getHealthCheckPort).distinct().collect(Collectors.toList());
    for (Integer healthCheckPort : healthPorts) {
        String resourceName = getResourceNameService().resourceName(resourceType(), context.getName(), loadBalancer.getType(), healthCheckPort);
        Map<String, Object> parameters = Map.of(HCPORT, healthCheckPort);
        resources.add(new Builder().type(resourceType()).name(resourceName).params(parameters).build());
    }
    return resources;
}
Also used : Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)

Example 34 with TargetGroupPortPair

use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.

the class AwsLoadBalancerCommonService method setupLoadBalancer.

private void setupLoadBalancer(CloudLoadBalancer cloudLoadBalancer, Map<String, List<String>> instanceIdsByGroupName, AwsLoadBalancer awsLoadBalancer) {
    LOGGER.debug("Configuring target instances for listeners.");
    for (Map.Entry<TargetGroupPortPair, Set<Group>> entry : cloudLoadBalancer.getPortToTargetGroupMapping().entrySet()) {
        AwsListener listener = awsLoadBalancer.getOrCreateListener(entry.getKey().getTrafficPort(), entry.getKey().getHealthCheckPort());
        Set<String> instanceIds = entry.getValue().stream().flatMap(tg -> instanceIdsByGroupName.get(tg.getName()).stream()).collect(Collectors.toSet());
        LOGGER.debug(String.format("Adding instances %s to listener %s", instanceIds, listener.getName()));
        listener.addInstancesToTargetGroup(instanceIds);
    }
}
Also used : Logger(org.slf4j.Logger) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) List(java.util.List) GroupSubnet(com.sequenceiq.cloudbreak.cloud.model.GroupSubnet) Service(org.springframework.stereotype.Service) Group(com.sequenceiq.cloudbreak.cloud.model.Group) Map(java.util.Map) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme) LoadBalancerTypeConverter(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.LoadBalancerTypeConverter) Set(java.util.Set) HashSet(java.util.HashSet) AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) Map(java.util.Map) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)

Example 35 with TargetGroupPortPair

use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.

the class AwsLaunchServiceLoadBalancerTest method createCloudLoadBalancer.

private CloudLoadBalancer createCloudLoadBalancer(LoadBalancerType type) {
    Group group = new Group(INSTANCE_NAME, GATEWAY, List.of(), null, null, null, null, null, null, 100, null, createGroupNetwork(), emptyMap());
    CloudLoadBalancer cloudLoadBalancer = new CloudLoadBalancer(type);
    cloudLoadBalancer.addPortToTargetGroupMapping(new TargetGroupPortPair(PORT, PORT), Set.of(group));
    return cloudLoadBalancer;
}
Also used : AwsTargetGroup(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)

Aggregations

TargetGroupPortPair (com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)36 CloudLoadBalancer (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer)24 Group (com.sequenceiq.cloudbreak.cloud.model.Group)19 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)14 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 TargetGroup (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup)11 Set (java.util.Set)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)9 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)8 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)8 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)8 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)8 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)8 Network (com.sequenceiq.cloudbreak.cloud.model.Network)8 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)8 List (java.util.List)7