use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class StackToCloudStackConverterTest method testConvertWithLoadBalancerSkuSet.
@Test
public void testConvertWithLoadBalancerSkuSet() {
Set<InstanceGroup> instanceGroups = new LinkedHashSet<>();
InstanceGroup instanceGroup1 = mock(InstanceGroup.class);
instanceGroups.add(instanceGroup1);
Template template = new Template();
template.setVolumeTemplates(Sets.newHashSet());
TargetGroup targetGroup = mock(TargetGroup.class);
LoadBalancer loadBalancer = mock(LoadBalancer.class);
TargetGroupPortPair targetGroupPortPair = new TargetGroupPortPair(443, 8443);
when(instanceGroup1.getGroupName()).thenReturn("group1");
when(stack.getInstanceGroupsAsList()).thenReturn(new ArrayList<>(instanceGroups));
when(instanceGroup1.getTemplate()).thenReturn(template);
when(instanceGroup1.getNotDeletedInstanceMetaDataSet()).thenReturn(Collections.emptySet());
when(instanceGroup1.getStack()).thenReturn(stack);
when(targetGroup.getType()).thenReturn(TargetGroupType.KNOX);
when(loadBalancer.getType()).thenReturn(LoadBalancerType.PRIVATE);
when(loadBalancer.getId()).thenReturn(1L);
when(loadBalancer.getSku()).thenReturn(LoadBalancerSku.STANDARD);
when(loadBalancerPersistenceService.findByStackId(anyLong())).thenReturn(Set.of(loadBalancer));
when(targetGroupPersistenceService.findByLoadBalancerId(anyLong())).thenReturn(Set.of(targetGroup));
when(instanceGroupService.findByTargetGroupId(anyLong())).thenReturn(Set.of(instanceGroup1));
when(loadBalancerConfigService.getTargetGroupPortPairs(any(TargetGroup.class))).thenReturn(Set.of(targetGroupPortPair));
CloudStack result = underTest.convert(stack);
assertEquals(1, result.getLoadBalancers().size());
CloudLoadBalancer cloudLoadBalancer = result.getLoadBalancers().iterator().next();
assertEquals(LoadBalancerSku.STANDARD, cloudLoadBalancer.getSku());
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class StackToStackV4ResponseConverterTest method testConvertWithLoadBalancers.
@Test
public void testConvertWithLoadBalancers() throws CloudbreakImageNotFoundException {
Set<LoadBalancer> loadBalancers = Set.of(new LoadBalancer());
Stack source = getSource();
// GIVEN
given(imageService.getImage(source.getId())).willReturn(mock(Image.class));
given(imageToStackImageV4ResponseConverter.convert(any())).willReturn(new StackImageV4Response());
given(stackToCustomDomainsSettingsV4Response.convert(any())).willReturn(new CustomDomainSettingsV4Response());
given(stackAuthenticationToStackAuthenticationV4ResponseConverter.convert(any())).willReturn(new StackAuthenticationV4Response());
given(networkToNetworkV4ResponseConverter.convert(any())).willReturn(new NetworkV4Response());
given(workspaceToWorkspaceResourceV4ResponseConverter.convert(any())).willReturn(new WorkspaceResourceV4Response());
given(cloudbreakDetailsToCloudbreakDetailsV4ResponseConverter.convert(any())).willReturn(new CloudbreakDetailsV4Response());
given(stackToPlacementSettingsV4ResponseConverter.convert(any())).willReturn(new PlacementSettingsV4Response());
given(telemetryConverter.convert(any())).willReturn(new TelemetryResponse());
given(instanceGroupToInstanceGroupV4ResponseConverter.convert(any())).willReturn(new InstanceGroupV4Response());
given(databaseAvailabilityTypeToDatabaseResponseConverter.convert(any(), any())).willReturn(new DatabaseResponse());
given(loadBalancerService.findByStackId(any())).willReturn(loadBalancers);
// WHEN
source.setLoadBalancers(loadBalancers);
StackV4Response result = underTest.convert(source);
// THEN
assertNotNull(result.getLoadBalancers());
assertTrue(result.isEnableLoadBalancer());
verify(restRequestThreadLocalService).setWorkspace(source.getWorkspace());
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class StackV4RequestToStackConverterTest method testConvertWithKnoxLoadBalancer.
@Test
public void testConvertWithKnoxLoadBalancer() {
initMocks();
setDefaultRegions(AWS);
StackV4Request request = getRequest("stack-datalake-with-instancegroups.json");
ReflectionTestUtils.setField(underTest, "defaultRegions", "AWS:eu-west-2");
TargetGroup targetGroup = new TargetGroup();
targetGroup.setType(TargetGroupType.KNOX);
LoadBalancer loadBalancer = new LoadBalancer();
loadBalancer.setType(LoadBalancerType.PRIVATE);
loadBalancer.setTargetGroupSet(Set.of(targetGroup));
given(credentialClientService.getByCrn(anyString())).willReturn(credential);
given(credentialClientService.getByName(anyString())).willReturn(credential);
given(providerParameterCalculator.get(request)).willReturn(getMappable());
given(clusterV4RequestToClusterConverter.convert(any(ClusterV4Request.class))).willReturn(new Cluster());
given(telemetryConverter.convert(null, StackType.DATALAKE)).willReturn(new Telemetry());
given(loadBalancerConfigService.createLoadBalancers(any(), any(), eq(request))).willReturn(Set.of(loadBalancer));
// WHEN
Stack stack = underTest.convert(request);
// THEN
assertEquals(1, stack.getLoadBalancers().size());
assertEquals(1, stack.getLoadBalancers().iterator().next().getTargetGroupSet().size());
assertEquals(TargetGroupType.KNOX, stack.getLoadBalancers().iterator().next().getTargetGroupSet().iterator().next().getType());
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class StackV4RequestToStackConverter method convert.
public Stack convert(StackV4Request source) {
Workspace workspace = workspaceService.getForCurrentUser();
Stack stack = new Stack();
stack.setEnvironmentCrn(source.getEnvironmentCrn());
DetailedEnvironmentResponse environment = null;
if (!StringUtils.isEmpty(source.getEnvironmentCrn())) {
environment = measure(() -> environmentClientService.getByCrn(source.getEnvironmentCrn()), LOGGER, "Environment responded in {} ms for stack {}", source.getName());
}
if (isTemplate(source)) {
updateCustomDomainOrKerberos(source, stack);
updateCloudPlatformAndRelatedFields(source, stack, environment);
convertAsStackTemplate(source, stack, environment);
setNetworkAsTemplate(source, stack);
} else {
convertAsStack(source, stack);
updateCloudPlatformAndRelatedFields(source, stack, environment);
setNetworkIfApplicable(source, stack, environment);
setInstanceGroupNetworkIfApplicable(source, stack, environment);
stack.getComponents().add(getTelemetryComponent(stack, source));
}
Map<String, Object> asMap = providerParameterCalculator.get(source).asMap();
if (asMap != null) {
Map<String, String> parameter = new HashMap<>();
asMap.forEach((key, value) -> parameter.put(key, value.toString()));
stack.setParameters(parameter);
}
setTimeToLive(source, stack);
stack.setWorkspace(workspace);
stack.setDisplayName(source.getName());
stack.setDatalakeCrn(datalakeService.getDatalakeCrn(source, workspace));
stack.setStackAuthentication(stackAuthenticationV4RequestToStackAuthenticationConverter.convert(source.getAuthentication()));
stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.PROVISION_REQUESTED));
stack.setCreated(clock.getCurrentTimeMillis());
stack.setInstanceGroups(convertInstanceGroups(source, stack));
Optional<String> parentEnvCloudPlatform = Optional.ofNullable(environment).map(EnvironmentBaseResponse::getParentEnvironmentCloudPlatform);
measure(() -> updateCluster(source, stack, parentEnvCloudPlatform), LOGGER, "Converted cluster and updated the stack in {} ms for stack {}", source.getName());
stack.setGatewayPort(source.getGatewayPort());
stack.setUuid(UUID.randomUUID().toString());
stack.setType(source.getType());
stack.setInputs(Json.silent(new StackInputs(source.getInputs(), new HashMap<>(), new HashMap<>())));
if (source.getImage() != null) {
stack.getComponents().add(getImageComponent(source, stack));
}
if (!isTemplate(source) && environment != null) {
gatewaySecurityGroupDecorator.extendGatewaySecurityGroupWithDefaultGatewayCidrs(stack, environment.getTunnel());
}
stack.setExternalDatabaseCreationType(getIfNotNull(source.getExternalDatabase(), DatabaseRequest::getAvailabilityType));
stack.setExternalDatabaseEngineVersion(getIfNotNull(source.getExternalDatabase(), DatabaseRequest::getDatabaseEngineVersion));
stack.setDomainDnsResolver(targetedUpscaleSupportService.isUnboundEliminationSupported(Crn.safeFromString(source.getEnvironmentCrn()).getAccountId()) ? DnsResolverType.FREEIPA_FOR_ENV : DnsResolverType.LOCAL_UNBOUND);
determineServiceTypeTag(stack, source.getTags());
determineServiceFeatureTag(stack, source.getTags());
Set<LoadBalancer> loadBalancers = loadBalancerConfigService.createLoadBalancers(stack, environment, source);
stack.setLoadBalancers(loadBalancers);
return stack;
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class MetadataSetupServiceTest method saveLoadBalancerMetadata.
@Test
public void saveLoadBalancerMetadata() {
stack.setName(STACK_NAME);
stack.setCloudPlatform("DEFAULT");
stack.setEnvironmentCrn(STACK_CRN);
LoadBalancer loadBalancer = new LoadBalancer();
loadBalancer.setStack(stack);
loadBalancer.setType(LoadBalancerType.PUBLIC);
Set<LoadBalancer> loadBalancerSet = new HashSet<>();
loadBalancerSet.add(loadBalancer);
when(loadBalancerPersistenceService.findByStackId(STACK_ID)).thenReturn(loadBalancerSet);
when(loadBalancerConfigService.generateLoadBalancerEndpoint(stack)).thenCallRealMethod();
StackStatus stackStatus = new StackStatus();
stackStatus.setStatus(Status.AVAILABLE);
stackStatus.setStack(stack);
StackIdView stackIdView = new StackIdViewImpl(STACK_ID, STACK_NAME, "no");
when(stackService.getByEnvironmentCrnAndStackType(STACK_CRN, StackType.DATALAKE)).thenReturn(List.of(stackIdView));
when(stackStatusService.findFirstByStackIdOrderByCreatedDesc(STACK_ID)).thenReturn(Optional.of(stackStatus));
when(targetGroupPersistenceService.findByLoadBalancerId(any())).thenReturn(Set.of());
Iterable<CloudLoadBalancerMetadata> cloudLoadBalancerMetaDataStatuses = getCloudLoadBalancerMetaDataStatuses();
underTest.saveLoadBalancerMetadata(stack, cloudLoadBalancerMetaDataStatuses);
verify(loadBalancerPersistenceService).save(loadBalancerCaptor.capture());
LoadBalancer loadBalancerValue = loadBalancerCaptor.getValue();
assertThat(loadBalancerValue.getHostedZoneId()).isSameAs(HOSTED_ZONE);
assertThat(loadBalancerValue.getIp()).isSameAs(PUBLIC_IP);
assertThat(loadBalancerValue.getDns()).isSameAs(CLOUD_DNS);
assertThat(loadBalancerValue.getEndpoint()).isEqualTo("STACK_NAME-gateway");
}
Aggregations