Search in sources :

Example 16 with TargetGroupPortPair

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

the class AzureTemplateBuilderTest method buildWithStandardLoadBalancerOnlyTargetGroupsUpdated.

@ParameterizedTest(name = "buildWithStandardLoadBalancerOnlyTargetGroupsUpdated {0}")
@MethodSource("templatesPathDataProvider")
public void buildWithStandardLoadBalancerOnlyTargetGroupsUpdated(String templatePath) {
    assumeTrue(isTemplateVersionGreaterOrEqualThan(templatePath, "2.7.3.0"));
    // GIVEN
    ReflectionTestUtils.setField(azureTemplateBuilder, FIELD_ARM_TEMPLATE_PATH, templatePath);
    String lbGroupExpectedBlob = "\"tags\":{},\"sku\":{\"name\":\"Standard\",\"tier\":\"Regional\"},\"properties\":{\"publicIPAllocationM" + "ethod\":\"Static\"}},{\"apiVersion\":\"2016-09-01\",\"type\":\"Microsoft.Network/networkInterfa" + "ces\",\"name\":\"[concat(parameters('nicNamePrefix'),'m0')]\",\"location\":\"[parameters('regio" + "n')]\",\"tags\":{},\"dependsOn\":[\"[concat('Microsoft.Network/networkSecurityGroups/',variable" + "s('gateway-groupsecGroupName'))]\"";
    String nonLbGroupExpectedBlob = "\"tags\":{},\"properties\":{\"publicIPAllocationMethod\":\"Dynamic\"}},{\"apiVersion\":\"2016-09-01\",\"" + "type\":\"Microsoft.Network/networkInterfaces\",\"name\":\"[concat(parameters('nicNamePrefix'),'" + "m0')]\",\"location\":\"[parameters('region')]\",\"tags\":{},\"dependsOn\":[\"[concat('Microsoft" + ".Network/networkSecurityGroups/',variables('core-groupsecGroupName'))]\"";
    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");
    Map<String, Object> lbParams = new HashMap<>();
    Map<String, Object> lbAsName = new HashMap<>();
    lbAsName.put("name", "gateway-group-as");
    lbParams.put("availabilitySet", lbAsName);
    Group lbGroup = new Group("gateway-group", InstanceGroupType.GATEWAY, Collections.singletonList(instance), security, null, lbParams, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), ROOT_VOLUME_SIZE, Optional.empty(), createGroupNetwork(), emptyMap());
    Group nonLbGroup = new Group("core-group", InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), ROOT_VOLUME_SIZE, Optional.empty(), createGroupNetwork(), emptyMap());
    groups.add(lbGroup);
    groups.add(nonLbGroup);
    List<CloudLoadBalancer> loadBalancers = new ArrayList<>();
    CloudLoadBalancer loadBalancer = new CloudLoadBalancer(LoadBalancerType.PUBLIC, LoadBalancerSku.STANDARD);
    loadBalancer.addPortToTargetGroupMapping(new TargetGroupPortPair(443, 8443), Set.of(lbGroup));
    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
    String strippedTemplateString = templateString.replaceAll("\\s", "");
    assertTrue(strippedTemplateString.contains(lbGroupExpectedBlob));
    assertTrue(strippedTemplateString.contains(nonLbGroupExpectedBlob));
}
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 17 with TargetGroupPortPair

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

the class LoadBalancerConfigConverterTest method testConvertAwsTargetGroupExtraPortsInMetadata.

@Test
public void testConvertAwsTargetGroupExtraPortsInMetadata() {
    CloudLoadBalancerMetadata cloudLoadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withParameters(createAwsParams(3)).build();
    TargetGroup targetGroup = new TargetGroup();
    targetGroup.setType(TargetGroupType.KNOX);
    TargetGroupPortPair portPair1 = new TargetGroupPortPair(PORT1, PORT1);
    TargetGroupPortPair portPair2 = new TargetGroupPortPair(PORT2, PORT2);
    when(loadBalancerConfigService.getTargetGroupPortPairs(eq(targetGroup))).thenReturn(Set.of(portPair1, portPair2));
    TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = underTest.convertTargetGroup(AWS, cloudLoadBalancerMetadata, targetGroup);
    assertNotNull(targetGroupConfigDbWrapper.getAwsConfig());
    AwsTargetGroupConfigDb awsTargetGroupConfigDb = targetGroupConfigDbWrapper.getAwsConfig();
    assertEquals(2, awsTargetGroupConfigDb.getPortArnMapping().size());
    assertEquals(Set.of(PORT1, PORT2), awsTargetGroupConfigDb.getPortArnMapping().keySet());
}
Also used : TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) AwsTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupConfigDb) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.Test)

Example 18 with TargetGroupPortPair

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

the class LoadBalancerConfigConverterTest method testConvertAzureTargetGroupMissingAvailabilitySetInMetadata.

@Test
public void testConvertAzureTargetGroupMissingAvailabilitySetInMetadata() {
    Map<String, Object> azureParams = createAzureParams(1);
    azureParams.put(AzureLoadBalancerMetadataView.getAvailabilitySetParam(PORT2), null);
    CloudLoadBalancerMetadata cloudLoadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withParameters(azureParams).build();
    TargetGroup targetGroup = new TargetGroup();
    targetGroup.setType(TargetGroupType.KNOX);
    TargetGroupPortPair portPair1 = new TargetGroupPortPair(PORT1, PORT2);
    TargetGroupPortPair portPair2 = new TargetGroupPortPair(PORT2, PORT2);
    TargetGroupPortPair portPair3 = new TargetGroupPortPair(PORT3, PORT3);
    when(loadBalancerConfigService.getTargetGroupPortPairs(eq(targetGroup))).thenReturn(Set.of(portPair1, portPair2, portPair3));
    TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = underTest.convertTargetGroup(AZURE, cloudLoadBalancerMetadata, targetGroup);
    assertNotNull(targetGroupConfigDbWrapper.getAzureConfig());
    AzureTargetGroupConfigDb azureTargetGroupConfigDb = targetGroupConfigDbWrapper.getAzureConfig();
    assertEquals(Set.of(PORT1, PORT2, PORT3), azureTargetGroupConfigDb.getPortAvailabilitySetMapping().keySet());
    List<String> availabilitySets = azureTargetGroupConfigDb.getPortAvailabilitySetMapping().get(PORT1);
    assertEquals(List.of(AVAILABILITY_SET_NAME), availabilitySets);
    availabilitySets = azureTargetGroupConfigDb.getPortAvailabilitySetMapping().get(PORT2);
    assertEquals(List.of(MISSING_CLOUD_RESOURCE), availabilitySets);
    availabilitySets = azureTargetGroupConfigDb.getPortAvailabilitySetMapping().get(PORT3);
    assertEquals(List.of(MISSING_CLOUD_RESOURCE), availabilitySets);
}
Also used : TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) AzureTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.azure.AzureTargetGroupConfigDb) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.Test)

Example 19 with TargetGroupPortPair

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

the class LoadBalancerConfigConverterTest method testConvertAwsTargetGroup.

@Test
public void testConvertAwsTargetGroup() {
    CloudLoadBalancerMetadata cloudLoadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withParameters(createAwsParams(1)).build();
    TargetGroup targetGroup = new TargetGroup();
    targetGroup.setType(TargetGroupType.KNOX);
    TargetGroupPortPair portPair = new TargetGroupPortPair(PORT1, PORT2);
    when(loadBalancerConfigService.getTargetGroupPortPairs(eq(targetGroup))).thenReturn(Set.of(portPair));
    TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = underTest.convertTargetGroup(AWS, cloudLoadBalancerMetadata, targetGroup);
    assertNotNull(targetGroupConfigDbWrapper.getAwsConfig());
    AwsTargetGroupConfigDb awsTargetGroupConfigDb = targetGroupConfigDbWrapper.getAwsConfig();
    assertEquals(1, awsTargetGroupConfigDb.getPortArnMapping().size());
    assertEquals(PORT1, awsTargetGroupConfigDb.getPortArnMapping().keySet().iterator().next());
    AwsTargetGroupArnsDb targetGroupArns = awsTargetGroupConfigDb.getPortArnMapping().get(PORT1);
    assertEquals(LISTENER_ARN, targetGroupArns.getListenerArn());
    assertEquals(TARGET_ARN, targetGroupArns.getTargetGroupArn());
}
Also used : TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) AwsTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupConfigDb) AwsTargetGroupArnsDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupArnsDb) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.Test)

Example 20 with TargetGroupPortPair

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

the class LoadBalancerConfigConverterTest method testConvertAzureTargetGroup.

@Test
public void testConvertAzureTargetGroup() {
    CloudLoadBalancerMetadata cloudLoadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withParameters(createAzureParams(1)).build();
    TargetGroup targetGroup = new TargetGroup();
    targetGroup.setType(TargetGroupType.KNOX);
    TargetGroupPortPair portPair = new TargetGroupPortPair(PORT1, PORT2);
    when(loadBalancerConfigService.getTargetGroupPortPairs(eq(targetGroup))).thenReturn(Set.of(portPair));
    TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = underTest.convertTargetGroup(AZURE, cloudLoadBalancerMetadata, targetGroup);
    assertNotNull(targetGroupConfigDbWrapper.getAzureConfig());
    AzureTargetGroupConfigDb azureTargetGroupConfigDb = targetGroupConfigDbWrapper.getAzureConfig();
    assertEquals(1, azureTargetGroupConfigDb.getPortAvailabilitySetMapping().size());
    assertEquals(PORT1, azureTargetGroupConfigDb.getPortAvailabilitySetMapping().keySet().iterator().next());
    List<String> availabilitySets = azureTargetGroupConfigDb.getPortAvailabilitySetMapping().get(PORT1);
    assertEquals(1, availabilitySets.size());
    assertEquals(AVAILABILITY_SET_NAME, availabilitySets.get(0));
}
Also used : TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) AzureTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.azure.AzureTargetGroupConfigDb) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.Test)

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