Search in sources :

Example 11 with TargetGroupPortPair

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));
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) RegionBackendServices(com.google.api.services.compute.Compute.RegionBackendServices) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) Test(org.junit.jupiter.api.Test)

Example 12 with TargetGroupPortPair

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));
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) Test(org.junit.jupiter.api.Test)

Example 13 with TargetGroupPortPair

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));
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) Test(org.junit.jupiter.api.Test)

Example 14 with TargetGroupPortPair

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\""));
}
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 15 with TargetGroupPortPair

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);
}
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)

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