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");
}
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());
}
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");
}
Aggregations