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\","));
}
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\""));
}
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;
}
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);
}
}
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;
}
Aggregations