Search in sources :

Example 61 with LoadBalancer

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());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Template(com.sequenceiq.cloudbreak.domain.Template) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 62 with LoadBalancer

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());
}
Also used : TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) DatabaseResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.database.DatabaseResponse) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CustomDomainSettingsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.customdomain.CustomDomainSettingsV4Response) StackImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.StackImageV4Response) Image(com.sequenceiq.cloudbreak.cloud.model.Image) WorkspaceResourceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.workspace.responses.WorkspaceResourceV4Response) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) StackAuthenticationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.authentication.StackAuthenticationV4Response) NetworkV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.network.NetworkV4Response) CloudbreakDetailsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.CloudbreakDetailsV4Response) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) PlacementSettingsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.PlacementSettingsV4Response) AbstractEntityConverterTest(com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest) Test(org.junit.Test)

Example 63 with LoadBalancer

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());
}
Also used : ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AbstractJsonConverterTest(com.sequenceiq.cloudbreak.converter.AbstractJsonConverterTest) Test(org.junit.jupiter.api.Test)

Example 64 with LoadBalancer

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;
}
Also used : HashMap(java.util.HashMap) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) EnvironmentBaseResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentBaseResponse) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) StackInputs(com.sequenceiq.cloudbreak.cloud.model.StackInputs) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace)

Example 65 with LoadBalancer

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");
}
Also used : StackIdViewImpl(com.sequenceiq.cloudbreak.service.stack.StackIdViewImpl) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) StackIdView(com.sequenceiq.cloudbreak.domain.projection.StackIdView) HashSet(java.util.HashSet) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)74 Test (org.junit.Test)48 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)46 SubnetTest (com.sequenceiq.cloudbreak.core.network.SubnetTest)39 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)37 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)32 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)26 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)20 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)16 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)12 Test (org.junit.jupiter.api.Test)12 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)9 LoadBalancerPersistenceService (com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService)9 HashSet (java.util.HashSet)9 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)8 TargetGroup (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup)8 LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)8 Map (java.util.Map)8 Optional (java.util.Optional)8 Json (com.sequenceiq.cloudbreak.common.json.Json)7