use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class AwsDownscaleServiceTest method downscaleWithLoadBalancers.
@Test
void downscaleWithLoadBalancers() {
CloudStack stack = mock(CloudStack.class);
List<CloudResource> resources = Collections.emptyList();
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
InstanceTemplate workerTemplate = mock(InstanceTemplate.class);
when(workerTemplate.getGroupName()).thenReturn("worker");
List<CloudInstance> cloudInstances = List.of(new CloudInstance("i-worker1", workerTemplate, instanceAuthentication, "subnet-1", "az1"));
CloudLoadBalancer privateLoadBalancer = new CloudLoadBalancer(LoadBalancerType.PRIVATE);
CloudLoadBalancer publicLoadBalancer = new CloudLoadBalancer(LoadBalancerType.PUBLIC);
CloudContext context = CloudContext.Builder.builder().withId(1L).withName("teststack").withCrn("crn").withPlatform("AWS").withVariant("AWS").withLocation(Location.location(Region.region("eu-west-1"), AvailabilityZone.availabilityZone("eu-west-1a"))).withAccountId("1").build();
AuthenticatedContext authenticatedContext = new AuthenticatedContext(context, new CloudCredential());
AmazonAutoScalingClient amazonAutoScalingClient = mock(AmazonAutoScalingClient.class);
when(awsClient.createAutoScalingClient(any(), anyString())).thenReturn(amazonAutoScalingClient);
AmazonEc2Client amazonEC2Client = mock(AmazonEc2Client.class);
when(awsClient.createEc2Client(any(), anyString())).thenReturn(amazonEC2Client);
AmazonEC2Waiters amazonEC2Waiters = mock(AmazonEC2Waiters.class);
when(amazonEC2Client.waiters()).thenReturn(amazonEC2Waiters);
Waiter waiter = mock(Waiter.class);
when(amazonEC2Waiters.instanceTerminated()).thenReturn(waiter);
when(cfStackUtil.getAutoscalingGroupName(any(), (String) any(), any())).thenReturn("autoscalegroup-1");
when(stack.getLoadBalancers()).thenReturn(List.of(privateLoadBalancer, publicLoadBalancer));
doNothing().when(loadBalancerService).removeLoadBalancerTargets(any(), any(), any());
DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult = new DescribeAutoScalingGroupsResult();
AutoScalingGroup autoScalingGroup = new AutoScalingGroup();
autoScalingGroup.setInstances(List.of(new Instance().withInstanceId("i-worker1")));
describeAutoScalingGroupsResult.setAutoScalingGroups(List.of(autoScalingGroup));
ArgumentCaptor<DescribeAutoScalingGroupsRequest> describeAutoScalingGroupsRequest = ArgumentCaptor.forClass(DescribeAutoScalingGroupsRequest.class);
ArgumentCaptor<DetachInstancesRequest> detachInstancesRequestArgumentCaptor = ArgumentCaptor.forClass(DetachInstancesRequest.class);
when(amazonAutoScalingClient.describeAutoScalingGroups(describeAutoScalingGroupsRequest.capture())).thenReturn(describeAutoScalingGroupsResult);
when(amazonAutoScalingClient.detachInstances(detachInstancesRequestArgumentCaptor.capture())).thenReturn(new DetachInstancesResult());
mockDescribeInstances(amazonEC2Client);
underTest.downscale(authenticatedContext, stack, resources, cloudInstances);
verify(loadBalancerService).removeLoadBalancerTargets(any(), any(), any());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class AwsLaunchServiceLoadBalancerTest method setupMocksForUpdate.
private void setupMocksForUpdate(AwsNetworkView awsNetworkView, Network network, List<CloudResource> instances, Set<LoadBalancerType> types) {
List<CloudLoadBalancer> loadBalancers = new ArrayList<>();
List<AwsLoadBalancer> awsLoadBalancers = new ArrayList<>();
for (LoadBalancerType type : types) {
loadBalancers.add(createCloudLoadBalancer(type));
AwsLoadBalancerScheme scheme = AwsLoadBalancerScheme.INTERNET_FACING;
if (LoadBalancerType.PRIVATE.equals(type)) {
scheme = AwsLoadBalancerScheme.INTERNAL;
}
AwsLoadBalancer awsLoadBalancer = new AwsLoadBalancer(scheme);
awsLoadBalancer.getOrCreateListener(PORT, PORT);
awsLoadBalancers.add(awsLoadBalancer);
}
when(cfStackUtil.getCfStackName(any())).thenReturn(STACK_NAME);
when(awsClient.createCloudFormationClient(any(), anyString())).thenReturn(cfClient);
when(cfClient.updateStack(any())).thenReturn(null);
when(cfClient.listStackResources(any())).thenReturn(result);
when(cloudFormationTemplateBuilder.build(any(ModelContext.class))).thenReturn("{}");
when(awsStackRequestHelper.createUpdateStackRequest(any(), any(), anyString(), anyString())).thenReturn(null);
when(cfClient.waiters()).thenReturn(waiters);
when(waiters.stackUpdateComplete()).thenReturn(updateWaiter);
when(ac.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getId()).thenReturn(1L);
when(cloudContext.getLocation()).thenReturn(location);
when(location.getRegion()).thenReturn(region);
when(region.value()).thenReturn("region");
when(cloudStack.getLoadBalancers()).thenReturn(loadBalancers);
when(cloudStack.getNetwork()).thenReturn(network);
when(awsModelService.buildDefaultModelContext(any(), any(), any())).thenReturn(new ModelContext());
when(awsLoadBalancerCommonService.getAwsLoadBalancers(eq(loadBalancers), any(), any())).thenReturn(awsLoadBalancers);
PowerMockito.mockStatic(AwsPageCollector.class);
PowerMockito.when(AwsPageCollector.getAllRouteTables(any(), any())).thenReturn(List.of());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer 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.CloudLoadBalancer 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);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer 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));
}
Aggregations