Search in sources :

Example 1 with StackIdViewImpl

use of com.sequenceiq.cloudbreak.service.stack.StackIdViewImpl in project cloudbreak by hortonworks.

the class MetadataSetupServiceTest method saveLoadBalancerMetadataAndSetEndpointToOldStack.

@Test
public void saveLoadBalancerMetadataAndSetEndpointToOldStack() {
    Stack oldStack = new Stack();
    oldStack.setId(OLD_STACK_ID);
    oldStack.setName(OLD_STACK_NAME);
    oldStack.setCloudPlatform("DEFAULT");
    oldStack.setEnvironmentCrn(STACK_CRN);
    oldStack.setDisplayName(STACK_DISPLAY_NAME);
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setId(INSTANCE_GROUP_ID);
    instanceGroup.setGroupName(GROUP_NAME);
    instanceGroup.setInstanceGroupType(InstanceGroupType.GATEWAY);
    InstanceMetaData pgwInstanceMetadata = new InstanceMetaData();
    pgwInstanceMetadata.setInstanceStatus(STOPPED);
    pgwInstanceMetadata.setDiscoveryFQDN("master0.subdomain.cldr.work");
    pgwInstanceMetadata.setInstanceMetadataType(GATEWAY_PRIMARY);
    instanceGroup.setInstanceMetaData(Set.of(pgwInstanceMetadata));
    oldStack.setInstanceGroups(Set.of(instanceGroup));
    stack.setName(STACK_NAME);
    stack.setCloudPlatform("DEFAULT");
    stack.setEnvironmentCrn(STACK_CRN);
    stack.setDisplayName(STACK_DISPLAY_NAME);
    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(loadBalancerPersistenceService.findByStackId(OLD_STACK_ID)).thenReturn(new HashSet<>());
    when(loadBalancerConfigService.generateLoadBalancerEndpoint(stack)).thenCallRealMethod();
    StackIdView stackIdView = new StackIdViewImpl(STACK_ID, STACK_NAME, "no");
    StackStatus stackStatus = new StackStatus();
    stackStatus.setStatus(Status.AVAILABLE);
    stackStatus.setStack(stack);
    StackIdView stackIdViewOld = new StackIdViewImpl(OLD_STACK_ID, OLD_STACK_NAME, "old_no");
    StackStatus stoppedStackStatus = new StackStatus();
    stoppedStackStatus.setStatus(Status.STOPPED);
    stoppedStackStatus.setStack(oldStack);
    when(stackService.getByEnvironmentCrnAndStackType(STACK_CRN, StackType.DATALAKE)).thenReturn(List.of(stackIdView, stackIdViewOld));
    when(stackStatusService.findFirstByStackIdOrderByCreatedDesc(STACK_ID)).thenReturn(Optional.of(stackStatus));
    when(stackStatusService.findFirstByStackIdOrderByCreatedDesc(OLD_STACK_ID)).thenReturn(Optional.of(stoppedStackStatus));
    when(stackService.getByIdWithGatewayInTransaction(OLD_STACK_ID)).thenReturn(oldStack);
    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("master0");
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) 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) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) HashSet(java.util.HashSet) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with StackIdViewImpl

use of com.sequenceiq.cloudbreak.service.stack.StackIdViewImpl in project cloudbreak by hortonworks.

the class DatalakeServiceTest method testGetDatalakeStackByStackEnvironmentCrnWithResult.

@Test
public void testGetDatalakeStackByStackEnvironmentCrnWithResult() {
    Stack stack = new Stack();
    stack.setType(StackType.WORKLOAD);
    when(stackService.getByEnvironmentCrnAndStackType(any(), any())).thenReturn(List.of(new StackIdViewImpl(1L, "no", "no")));
    when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(new Stack());
    Optional<Stack> res = underTest.getDatalakeStackByStackEnvironmentCrn(stack);
    Assertions.assertTrue(!res.isEmpty());
}
Also used : StackIdViewImpl(com.sequenceiq.cloudbreak.service.stack.StackIdViewImpl) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 3 with StackIdViewImpl

use of com.sequenceiq.cloudbreak.service.stack.StackIdViewImpl 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

StackIdViewImpl (com.sequenceiq.cloudbreak.service.stack.StackIdViewImpl)3 Test (org.junit.jupiter.api.Test)3 CloudLoadBalancerMetadata (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)2 StackIdView (com.sequenceiq.cloudbreak.domain.projection.StackIdView)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)2 LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)2 HashSet (java.util.HashSet)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 CloudInstanceMetaData (com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)1