Search in sources :

Example 16 with LoadBalancerType

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();
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with LoadBalancerType

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());
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) ArrayList(java.util.ArrayList) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)

Example 18 with LoadBalancerType

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());
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with LoadBalancerType

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);
        }
    };
}
Also used : START_DATE(com.sequenceiq.cloudbreak.core.flow2.stack.provision.StackProvisionConstants.START_DATE) CreateCredentialRequest(com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialRequest) ProvisionEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ProvisionEvent) CreateUserDataSuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.userdata.CreateUserDataSuccess) Action(org.springframework.statemachine.action.Action) PrepareImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest) Date(java.util.Date) CollectLoadBalancerMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataRequest) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) LaunchLoadBalancerRequest(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchLoadBalancerRequest) TlsInfo(com.sequenceiq.cloudbreak.cloud.model.TlsInfo) StackWithFingerprintsEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.StackWithFingerprintsEvent) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) CreateUserDataRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.userdata.CreateUserDataRequest) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) ValidationRequest(com.sequenceiq.cloudbreak.cloud.event.setup.ValidationRequest) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) StackCreationService(com.sequenceiq.cloudbreak.core.flow2.stack.provision.service.StackCreationService) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) CreateCredentialResult(com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialResult) Collectors(java.util.stream.Collectors) GetTlsInfoResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult) Configuration(org.springframework.context.annotation.Configuration) SetupResult(com.sequenceiq.cloudbreak.cloud.event.setup.SetupResult) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) ValidationResult(com.sequenceiq.cloudbreak.cloud.event.setup.ValidationResult) Optional(java.util.Optional) StackCreationEvent(com.sequenceiq.cloudbreak.core.flow2.stack.provision.StackCreationEvent) SetupRequest(com.sequenceiq.cloudbreak.cloud.event.setup.SetupRequest) CollectLoadBalancerMetadataResult(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) FailurePolicy(com.sequenceiq.cloudbreak.domain.FailurePolicy) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) LaunchLoadBalancerResult(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchLoadBalancerResult) GetSSHFingerprintsResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) LaunchStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackResult) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) MetricType(com.sequenceiq.cloudbreak.service.metrics.MetricType) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) GetTlsInfoRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoRequest) StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) LaunchStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackRequest) Bean(org.springframework.context.annotation.Bean) StackCreationState(com.sequenceiq.cloudbreak.core.flow2.stack.provision.StackCreationState) CollectLoadBalancerMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataRequest) StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Bean(org.springframework.context.annotation.Bean)

Example 20 with LoadBalancerType

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;
}
Also used : Arrays(java.util.Arrays) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) OozieRoles(com.sequenceiq.cloudbreak.cmtemplate.configproviders.oozie.OozieRoles) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) ProviderParameterCalculator(com.sequenceiq.cloudbreak.common.mappable.ProviderParameterCalculator) PublicEndpointAccessGateway(com.sequenceiq.common.api.type.PublicEndpointAccessGateway) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SubnetSelector(com.sequenceiq.cloudbreak.converter.v4.environment.network.SubnetSelector) AzureStackV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.stack.AzureStackV4Parameters) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) Set(java.util.Set) LoadBalancerSku(com.sequenceiq.common.api.type.LoadBalancerSku) Collectors(java.util.stream.Collectors) KnoxRoles(com.sequenceiq.cloudbreak.cmtemplate.configproviders.knox.KnoxRoles) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) Optional(java.util.Optional) GCP(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.GCP) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) CLOUDERA_STACK_VERSION_7_2_11(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERA_STACK_VERSION_7_2_11) OOZIE_HTTPS_PORT(com.sequenceiq.cloudbreak.cmtemplate.configproviders.oozie.OozieHAConfigProvider.OOZIE_HTTPS_PORT) NetworkConstants(com.sequenceiq.cloudbreak.common.network.NetworkConstants) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) Network(com.sequenceiq.cloudbreak.domain.Network) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) AWS(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.AWS) Service(org.springframework.stereotype.Service) CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited) NetworkV4Base(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.NetworkV4Base) Map.entry(java.util.Map.entry) AzureInstanceGroupParameters(com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceGroupParameters) LoadBalancerCreation(com.sequenceiq.common.api.type.LoadBalancerCreation) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Logger(org.slf4j.Logger) AvailabilitySetNameService(com.sequenceiq.cloudbreak.cloud.model.instance.AvailabilitySetNameService) TargetGroupType(com.sequenceiq.common.api.type.TargetGroupType) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) Preconditions(com.google.common.base.Preconditions) AZURE(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.AZURE) Collections(java.util.Collections) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)

Aggregations

LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)36 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)21 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)18 StackResourceSummary (com.amazonaws.services.cloudformation.model.StackResourceSummary)12 Test (org.junit.jupiter.api.Test)12 CloudLoadBalancerMetadata (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)11 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)11 Network (com.sequenceiq.cloudbreak.cloud.model.Network)11 Test (org.junit.Test)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 CloudLoadBalancer (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer)9 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)8 ArrayList (java.util.ArrayList)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)5 Logger (org.slf4j.Logger)5 DescribeLoadBalancersResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4