use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class AzureLoadBalancerModelBuilderTest method createCloudLoadBalancer.
private CloudLoadBalancer createCloudLoadBalancer(LoadBalancerSku sku) {
Group targetGroup = new Group(INSTANCE_GROUP_NAME, InstanceGroupType.GATEWAY, List.of(new CloudInstance(INSTANCE_NAME, null, null, "subnet-1", "az1")), null, null, null, null, null, 64, null, createGroupNetwork(), emptyMap());
CloudLoadBalancer cloudLoadBalancer = new CloudLoadBalancer(LoadBalancerType.PRIVATE, sku);
cloudLoadBalancer.addPortToTargetGroupMapping(new TargetGroupPortPair(443, 443), Set.of(targetGroup));
return cloudLoadBalancer;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class CreateCloudLoadBalancersHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<CreateCloudLoadBalancersRequest> event) {
CreateCloudLoadBalancersRequest request = event.getData();
CloudContext cloudContext = request.getCloudContext();
try {
LOGGER.info("Updating cloud stack with load balancer network information");
CloudStack origCloudStack = request.getCloudStack();
Stack stack = request.getStack();
CloudStack updatedCloudStack = new CloudStack(origCloudStack.getGroups(), cloudStackConverter.buildNetwork(stack), origCloudStack.getImage(), origCloudStack.getParameters(), origCloudStack.getTags(), origCloudStack.getTemplate(), origCloudStack.getInstanceAuthentication(), origCloudStack.getLoginUserName(), origCloudStack.getPublicKey(), origCloudStack.getFileSystem().orElse(null), origCloudStack.getLoadBalancers());
CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
LOGGER.debug("Initiating cloud load balancer creation");
List<CloudResourceStatus> resourceStatus = connector.resources().launchLoadBalancers(ac, updatedCloudStack, persistenceNotifier);
LOGGER.debug("Waiting for cloud load balancers to be fully created");
List<CloudResource> resources = ResourceLists.transform(resourceStatus);
PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatus);
if (!task.completed(statePollerResult)) {
syncPollingScheduler.schedule(task);
}
if (resourceStatus.stream().anyMatch(CloudResourceStatus::isFailed)) {
Set<String> names = resourceStatus.stream().filter(CloudResourceStatus::isFailed).map(r -> r.getCloudResource().getName()).collect(Collectors.toSet());
throw new CloudbreakException("Creation failed for load balancers: " + names);
}
Set<String> types = updatedCloudStack.getLoadBalancers().stream().map(CloudLoadBalancer::getType).map(LoadBalancerType::toString).collect(Collectors.toSet());
LOGGER.info("Cloud load balancer creation for load balancer types {} successful", types);
return new CreateCloudLoadBalancersSuccess(stack);
} catch (Exception e) {
LOGGER.warn("Failed to created cloud load balance resources.", e);
return new CreateCloudLoadBalancersFailure(request.getResourceId(), e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonService method convertLoadBalancer.
@VisibleForTesting
AwsLoadBalancer convertLoadBalancer(CloudLoadBalancer cloudLoadBalancer, Map<String, List<String>> instanceIdsByGroupName, AwsNetworkView awsNetworkView, List<AwsLoadBalancer> awsLoadBalancers) {
// Check and see if we already have a load balancer whose scheme matches this one.
AwsLoadBalancer currentLoadBalancer = null;
LoadBalancerType cloudLbType = cloudLoadBalancer.getType();
Set<String> subnetIds = selectLoadBalancerSubnetIds(cloudLbType, awsNetworkView, cloudLoadBalancer);
AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(cloudLbType);
currentLoadBalancer = awsLoadBalancers.stream().filter(lb -> lb.getScheme() == scheme).findFirst().orElse(new AwsLoadBalancer(scheme));
currentLoadBalancer.addSubnets(subnetIds);
setupLoadBalancer(cloudLoadBalancer, instanceIdsByGroupName, currentLoadBalancer);
return currentLoadBalancer;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class StackToCloudStackConverterTest method testConvertWithMultipleKnoxLoadBalancers.
@Test
public void testConvertWithMultipleKnoxLoadBalancers() {
Set<InstanceGroup> instanceGroups = new LinkedHashSet<>();
InstanceGroup instanceGroup1 = mock(InstanceGroup.class);
InstanceGroup instanceGroup2 = mock(InstanceGroup.class);
when(instanceGroup1.getGroupName()).thenReturn("group1");
when(instanceGroup2.getGroupName()).thenReturn("group2");
instanceGroups.add(instanceGroup1);
instanceGroups.add(instanceGroup2);
when(stack.getInstanceGroupsAsList()).thenReturn(new ArrayList<>(instanceGroups));
Template template = new Template();
template.setVolumeTemplates(Set.of());
when(instanceGroup1.getTemplate()).thenReturn(template);
when(instanceGroup1.getNotDeletedInstanceMetaDataSet()).thenReturn(Set.of());
when(instanceGroup1.getStack()).thenReturn(stack);
when(instanceGroup2.getTemplate()).thenReturn(template);
when(instanceGroup2.getNotDeletedInstanceMetaDataSet()).thenReturn(Set.of());
when(instanceGroup2.getStack()).thenReturn(stack);
TargetGroup targetGroup = mock(TargetGroup.class);
when(targetGroup.getType()).thenReturn(TargetGroupType.KNOX);
LoadBalancer internalLoadBalancer = mock(LoadBalancer.class);
when(internalLoadBalancer.getType()).thenReturn(LoadBalancerType.PRIVATE);
when(internalLoadBalancer.getId()).thenReturn(1L);
LoadBalancer externalLoadBalancer = mock(LoadBalancer.class);
when(externalLoadBalancer.getType()).thenReturn(LoadBalancerType.PUBLIC);
when(externalLoadBalancer.getId()).thenReturn(2L);
when(loadBalancerPersistenceService.findByStackId(anyLong())).thenReturn(Set.of(internalLoadBalancer, externalLoadBalancer));
when(targetGroupPersistenceService.findByLoadBalancerId(anyLong())).thenReturn(Set.of(targetGroup));
when(instanceGroupService.findByTargetGroupId(anyLong())).thenReturn(Set.of(instanceGroup1, instanceGroup2));
when(loadBalancerConfigService.getTargetGroupPortPairs(any(TargetGroup.class))).thenReturn(Set.of(new TargetGroupPortPair(443, 8443)));
CloudStack result = underTest.convert(stack);
assertEquals(2, result.getLoadBalancers().size());
Optional<CloudLoadBalancer> internalCloudLoadBalancer = result.getLoadBalancers().stream().filter(lb -> lb.getType() == LoadBalancerType.PRIVATE).findFirst();
assertTrue(internalCloudLoadBalancer.isPresent());
Optional<CloudLoadBalancer> externalCloudLoadBalancer = result.getLoadBalancers().stream().filter(lb -> lb.getType() == LoadBalancerType.PUBLIC).findFirst();
assertTrue(externalCloudLoadBalancer.isPresent());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class AwsDownscaleService method getTargetGroupArns.
private List<String> getTargetGroupArns(List<CloudLoadBalancer> loadBalancers, AuthenticatedContext auth) {
List<String> targetGroupArns = new ArrayList<>();
for (CloudLoadBalancer loadBalancer : loadBalancers) {
for (Map.Entry<TargetGroupPortPair, Set<Group>> entry : loadBalancer.getPortToTargetGroupMapping().entrySet()) {
String region = auth.getCloudContext().getLocation().getRegion().value();
AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(loadBalancer.getType());
String targetGroupArn = cfStackUtil.getResourceArnByLogicalId(auth, AwsTargetGroup.getTargetGroupName(entry.getKey().getTrafficPort(), scheme), region);
targetGroupArns.add(targetGroupArn);
}
}
return targetGroupArns;
}
Aggregations