use of com.sequenceiq.common.api.type.LoadBalancerType in project cloudbreak by hortonworks.
the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationWithEndpointGatewayAndPrivateSubnet.
@Test
public void testUpdateCloudformationWithEndpointGatewayAndPrivateSubnet() {
List<CloudResource> instances = createInstances();
AwsNetworkView awsNetworkView = createNetworkView(PRIVATE_ID_1, PUBLIC_ID_1);
Network network = createNetwork(PRIVATE_ID_1, PUBLIC_ID_1);
Set<LoadBalancerType> types = Set.of(LoadBalancerType.PUBLIC, LoadBalancerType.PRIVATE);
List<StackResourceSummary> firstUpdateSummaries = createFirstUpdateSummaries(types);
List<StackResourceSummary> secondUpdateSummaries = createFullSummaries(types);
setupMocksForUpdate(awsNetworkView, network, instances, Set.of(LoadBalancerType.PUBLIC, LoadBalancerType.PRIVATE));
when(result.getStackResourceSummaries()).thenReturn(List.of()).thenReturn(firstUpdateSummaries).thenReturn(firstUpdateSummaries).thenReturn(secondUpdateSummaries);
when(ac.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location);
when(location.getAvailabilityZone()).thenReturn(availabilityZone("az1"));
underTest.updateCloudformationWithLoadBalancers(ac, cloudStack, null, null);
verify(cfClient, times(2)).updateStack(any());
verify(result, times(5)).getStackResourceSummaries();
}
use of com.sequenceiq.common.api.type.LoadBalancerType 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.common.api.type.LoadBalancerType in project cloudbreak by hortonworks.
the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationWithLoadBalancerMissingTargetGroupArn.
@Test
public void testUpdateCloudformationWithLoadBalancerMissingTargetGroupArn() {
List<CloudResource> instances = createInstances();
AwsNetworkView awsNetworkView = createNetworkView(PRIVATE_ID_1, null);
Network network = createNetwork(PRIVATE_ID_1, null);
String expectedError = String.format("Could not create load balancer listeners: target group %s arn not found.", AwsTargetGroup.getTargetGroupName(PORT, AwsLoadBalancerScheme.INTERNAL));
Set<LoadBalancerType> types = Set.of(LoadBalancerType.PRIVATE);
List<StackResourceSummary> firstUpdateSummaries = createFirstUpdateSummaries(types);
StackResourceSummary tgSummary = firstUpdateSummaries.get(TG_INDEX);
tgSummary.setPhysicalResourceId(null);
List<StackResourceSummary> secondUpdateSummaries = createFullSummaries(types);
setupMocksForUpdate(awsNetworkView, network, instances, types);
when(result.getStackResourceSummaries()).thenReturn(List.of()).thenReturn(firstUpdateSummaries).thenReturn(firstUpdateSummaries).thenReturn(secondUpdateSummaries);
CloudConnectorException exception = assertThrows(CloudConnectorException.class, () -> underTest.updateCloudformationWithLoadBalancers(ac, cloudStack, null, null));
verify(cfClient, times(1)).updateStack(any());
verify(result, times(2)).getStackResourceSummaries();
assertEquals(expectedError, exception.getMessage());
}
use of com.sequenceiq.common.api.type.LoadBalancerType in project cloudbreak by hortonworks.
the class StackCreationActions method collectMetadataAction.
@Bean(name = "COLLECTMETADATA_STATE")
public Action<?, ?> collectMetadataAction() {
return new AbstractStackCreationAction<>(CollectMetadataResult.class) {
@Override
protected void doExecute(StackCreationContext context, CollectMetadataResult payload, Map<Object, Object> variables) {
Stack stack = stackCreationService.setupMetadata(context, payload);
StackCreationContext newContext = new StackCreationContext(context.getFlowParameters(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
sendEvent(newContext);
}
@Override
protected Selectable createRequest(StackCreationContext context) {
List<LoadBalancerType> loadBalancerTypes = loadBalancerPersistenceService.findByStackId(context.getStack().getId()).stream().map(LoadBalancer::getType).collect(Collectors.toList());
List<CloudResource> cloudResources = context.getStack().getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
return new CollectLoadBalancerMetadataRequest(context.getCloudContext(), context.getCloudCredential(), loadBalancerTypes, cloudResources);
}
};
}
use of com.sequenceiq.common.api.type.LoadBalancerType in project cloudbreak by hortonworks.
the class LoadBalancerConfigService method createLoadBalancerIfNotExists.
private LoadBalancer createLoadBalancerIfNotExists(Set<LoadBalancer> loadBalancers, LoadBalancerType type, Stack stack) {
LoadBalancer loadBalancer;
Optional<LoadBalancer> existingLoadBalancer = loadBalancers.stream().filter(lb -> lb.getType() == type).findFirst();
if (existingLoadBalancer.isPresent()) {
loadBalancer = existingLoadBalancer.get();
} else {
loadBalancer = new LoadBalancer();
loadBalancer.setType(type);
loadBalancer.setStack(stack);
loadBalancers.add(loadBalancer);
}
return loadBalancer;
}
Aggregations