use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.
the class GcpBackendServiceResourceBuilderTest method testBuildWithMultipleTrafficPorts.
@Test
public void testBuildWithMultipleTrafficPorts() throws Exception {
Map<String, Object> parameters = new HashMap<>();
parameters.put("hcport", 8443);
parameters.put("trafficports", List.of(443, 11443));
CloudResource hcResource = new CloudResource.Builder().type(ResourceType.GCP_HEALTH_CHECK).status(CommonStatus.CREATED).group("master").name("hcsuper").params(parameters).persistent(true).build();
CloudResource resource = new CloudResource.Builder().type(ResourceType.GCP_BACKEND_SERVICE).status(CommonStatus.CREATED).group("master").name("super").params(parameters).persistent(true).build();
when(group.getName()).thenReturn("master");
Compute.RegionBackendServices.Insert insert = mock(Compute.RegionBackendServices.Insert.class);
Map<TargetGroupPortPair, Set<Group>> targetGroupPortPairSetHashMap = new HashMap<>();
targetGroupPortPairSetHashMap.put(new TargetGroupPortPair(443, 8443), Set.of(group));
targetGroupPortPairSetHashMap.put(new TargetGroupPortPair(11443, 8443), Set.of(group));
when(cloudLoadBalancer.getPortToTargetGroupMapping()).thenReturn(targetGroupPortPairSetHashMap);
when(cloudLoadBalancer.getType()).thenReturn(LoadBalancerType.PRIVATE);
when(gcpContext.getCompute()).thenReturn(compute);
when(gcpContext.getProjectId()).thenReturn("id");
when(gcpContext.getLoadBalancerResources(any())).thenReturn(List.of(hcResource));
when(gcpContext.getLocation()).thenReturn(location);
when(location.getAvailabilityZone()).thenReturn(availabilityZone);
when(availabilityZone.value()).thenReturn("us-west2");
when(location.getRegion()).thenReturn(region);
when(region.getRegionName()).thenReturn("us-west2");
when(compute.regionBackendServices()).thenReturn(regionBackendServices);
when(regionBackendServices.insert(anyString(), anyString(), any())).thenReturn(insert);
when(insert.execute()).thenReturn(operation);
when(operation.getName()).thenReturn("name");
when(operation.getHttpErrorStatusCode()).thenReturn(null);
when(gcpLoadBalancerTypeConverter.getScheme(any(CloudLoadBalancer.class))).thenCallRealMethod();
List<CloudResource> cloudResources = underTest.build(gcpContext, authenticatedContext, Collections.singletonList(resource), cloudLoadBalancer, cloudStack);
Assert.assertEquals("super", cloudResources.get(0).getName());
Assertions.assertEquals(8443, cloudResources.get(0).getParameter("hcport", Integer.class));
List<Integer> ports = (List<Integer>) cloudResources.get(0).getParameters().get("trafficports");
Assertions.assertTrue(ports.contains(443));
Assertions.assertTrue(ports.contains(11443));
}
use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.
the class GcpForwardingRuleResourceBuilderTest method testCreateWhereEverythingGoesFine.
@Test
public void testCreateWhereEverythingGoesFine() {
when(gcpContext.getName()).thenReturn("name");
when(cloudLoadBalancer.getType()).thenReturn(LoadBalancerType.PUBLIC);
Map<TargetGroupPortPair, Set<Group>> targetGroupPortPairSetHashMap = new HashMap<>();
targetGroupPortPairSetHashMap.put(new TargetGroupPortPair(80, 8080), Collections.emptySet());
when(cloudLoadBalancer.getPortToTargetGroupMapping()).thenReturn(targetGroupPortPairSetHashMap);
List<CloudResource> cloudResources = underTest.create(gcpContext, authenticatedContext, cloudLoadBalancer);
Assertions.assertTrue(cloudResources.get(0).getName().startsWith("name-public-80"));
Assertions.assertEquals(1, cloudResources.size());
Assertions.assertEquals(8080, cloudResources.get(0).getParameter("hcport", Integer.class));
Assertions.assertEquals(80, cloudResources.get(0).getParameter("trafficport", Integer.class));
}
use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.
the class GcpHealthCheckResourceBuilderTest method testCreateWhenEverythingGoesFine.
@Test
public void testCreateWhenEverythingGoesFine() throws Exception {
when(gcpContext.getName()).thenReturn("name");
when(cloudLoadBalancer.getType()).thenReturn(LoadBalancerType.PUBLIC);
Map<TargetGroupPortPair, Set<Group>> targetGroupPortPairSetHashMap = new HashMap<>();
targetGroupPortPairSetHashMap.put(new TargetGroupPortPair(80, 8080), Collections.emptySet());
when(cloudLoadBalancer.getPortToTargetGroupMapping()).thenReturn(targetGroupPortPairSetHashMap);
List<CloudResource> cloudResources = underTest.create(gcpContext, authenticatedContext, cloudLoadBalancer);
Assertions.assertTrue(cloudResources.get(0).getName().startsWith("name-public-8080"));
Assertions.assertEquals(1, cloudResources.size());
Assertions.assertEquals(8080, cloudResources.get(0).getParameter("hcport", Integer.class));
}
use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.
the class AzureTemplateBuilderTest method buildWithGatewayInstanceGroupTypeAndStandardLoadBalancer.
@ParameterizedTest(name = "buildWithGatewayInstanceGroupTypeAndStandardLoadBalancer {0}")
@MethodSource("templatesPathDataProvider")
public void buildWithGatewayInstanceGroupTypeAndStandardLoadBalancer(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.STANDARD);
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\": \"Standard\""));
assertTrue(templateString.contains("\"tier\": \"Regional\""));
}
use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.
the class AzureTemplateBuilderTest method testNicDependenciesAreValidJson.
@ParameterizedTest(name = "testNicDependenciesAreValidJson {0}")
@MethodSource("templatesPathDataProvider")
public void testNicDependenciesAreValidJson(String templatePath) {
ReflectionTestUtils.setField(azureTemplateBuilder, FIELD_ARM_TEMPLATE_PATH, templatePath);
// GIVEN
assumeTrue(isTemplateVersionGreaterOrEqualThan(templatePath, "2.7.3.0"));
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 publicLb = new CloudLoadBalancer(LoadBalancerType.PUBLIC);
publicLb.addPortToTargetGroupMapping(new TargetGroupPortPair(443, 8443), new HashSet<>(groups));
loadBalancers.add(publicLb);
CloudLoadBalancer privateLb = new CloudLoadBalancer(LoadBalancerType.PRIVATE);
privateLb.addPortToTargetGroupMapping(new TargetGroupPortPair(443, 8443), new HashSet<>(groups));
loadBalancers.add(privateLb);
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");
when(azureUtils.getCustomResourceGroupName(any())).thenReturn("custom-resource-group-name");
when(azureUtils.getCustomNetworkId(any())).thenReturn("custom-vnet-id");
// This test is checking that valid json is created when using an existing network and no public IP.
when(azureUtils.isExistingNetwork(any())).thenReturn(true);
when(azureUtils.isPrivateIp(any())).thenReturn(true);
String templateString = azureTemplateBuilder.build(stackName, CUSTOM_IMAGE_NAME, azureCredentialView, azureStackView, cloudContext, cloudStack, AzureInstanceTemplateOperation.UPSCALE, null);
// THEN
validateJson(templateString);
}
Aggregations