use of com.sequenceiq.cloudbreak.domain.projection.StackIdView in project cloudbreak by hortonworks.
the class StackService method findClustersConnectedToDatalakeByDatalakeStackId.
public Set<StackIdView> findClustersConnectedToDatalakeByDatalakeStackId(Long datalakeStackId) {
Stack datalakeStack = get(datalakeStackId);
Set<StackIdView> stacksConnectedByDatalakeCrn;
if (datalakeStack != null) {
stacksConnectedByDatalakeCrn = findByDatalakeCrn(datalakeStack.getResourceCrn());
} else {
stacksConnectedByDatalakeCrn = Collections.emptySet();
}
return stacksConnectedByDatalakeCrn;
}
use of com.sequenceiq.cloudbreak.domain.projection.StackIdView 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.domain.projection.StackIdView in project cloudbreak by hortonworks.
the class StackServiceTest method testFindClustersConnectedToDatalakeByDatalakeStackIdWhereNoResultFromDatalakeResource.
@Test
public void testFindClustersConnectedToDatalakeByDatalakeStackIdWhereNoResultFromDatalakeResource() throws TransactionExecutionException {
StackIdView i = new StackIdViewImpl(1L, "no", "no");
StackIdView j = new StackIdViewImpl(2L, "nope", "no");
StackIdView k = new StackIdViewImpl(3L, "none", "no");
Set<StackIdView> result = findClusterConnectedToDatalake(Set.of(i, j, k));
assertEquals(3, result.size());
}
use of com.sequenceiq.cloudbreak.domain.projection.StackIdView 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");
}
use of com.sequenceiq.cloudbreak.domain.projection.StackIdView in project cloudbreak by hortonworks.
the class MetadataSetupService method saveLoadBalancerMetadata.
public void saveLoadBalancerMetadata(Stack stack, Iterable<CloudLoadBalancerMetadata> cloudLoadBalancerMetadataList) {
try {
LOGGER.info("Save load balancer metadata for stack: {}", stack.getName());
Set<LoadBalancer> allLoadBalancerMetadata = loadBalancerPersistenceService.findByStackId(stack.getId());
for (CloudLoadBalancerMetadata cloudLoadBalancerMetadata : cloudLoadBalancerMetadataList) {
LoadBalancer loadBalancerEntry = createLoadBalancerMetadataIfAbsent(allLoadBalancerMetadata, stack, cloudLoadBalancerMetadata.getType());
loadBalancerEntry.setDns(cloudLoadBalancerMetadata.getCloudDns());
loadBalancerEntry.setHostedZoneId(cloudLoadBalancerMetadata.getHostedZoneId());
loadBalancerEntry.setIp(cloudLoadBalancerMetadata.getIp());
loadBalancerEntry.setType(cloudLoadBalancerMetadata.getType());
String endpoint = loadBalancerConfigService.generateLoadBalancerEndpoint(stack);
List<StackIdView> byEnvironmentCrnAndStackType = stackService.getByEnvironmentCrnAndStackType(stack.getEnvironmentCrn(), StackType.DATALAKE);
List<StackStatus> stoppedDatalakes = byEnvironmentCrnAndStackType.stream().map(s -> stackStatusService.findFirstByStackIdOrderByCreatedDesc(s.getId())).filter(Optional::isPresent).map(Optional::get).filter(status -> status.getStatus().isStopState()).collect(Collectors.toList());
if (!stoppedDatalakes.isEmpty()) {
/* Starts to check for a situation where we are resizing a datalake that did not previously have loadbalancers
so that we can use the same endpoint name for a seamless transistion
*/
LOGGER.info("Using old datalake endpoint name for resized datalake: {}, env: {}", stack.getName(), stack.getEnvironmentCrn());
if (stoppedDatalakes.size() > 1) {
String ids = stoppedDatalakes.stream().map(stackStatus -> stackStatus.getStack().getId()).map(Object::toString).collect(Collectors.joining(","));
LOGGER.warn("more than one datalake found to resize from: {}", ids);
}
Long oldId = stoppedDatalakes.get(0).getStack().getId();
Set<LoadBalancer> oldLoadbalancers = loadBalancerPersistenceService.findByStackId(oldId);
if (oldLoadbalancers.isEmpty()) {
Stack oldStack = stackService.getByIdWithGatewayInTransaction(oldId);
if (stack.getDisplayName().equals(oldStack.getDisplayName())) {
endpoint = oldStack.getPrimaryGatewayInstance().getShortHostname();
}
}
}
LOGGER.info("Saving load balancer endpoint as: {}", endpoint);
loadBalancerEntry.setEndpoint(endpoint);
loadBalancerEntry.setProviderConfig(loadBalancerConfigConverter.convertLoadBalancer(stack.getCloudPlatform(), cloudLoadBalancerMetadata));
loadBalancerPersistenceService.save(loadBalancerEntry);
Set<TargetGroup> targetGroups = targetGroupPersistenceService.findByLoadBalancerId(loadBalancerEntry.getId());
for (TargetGroup targetGroup : targetGroups) {
targetGroup.setProviderConfig(loadBalancerConfigConverter.convertTargetGroup(stack.getCloudPlatform(), cloudLoadBalancerMetadata, targetGroup));
targetGroupPersistenceService.save(targetGroup);
}
}
} catch (Exception ex) {
throw new CloudbreakServiceException("Load balancer metadata collection failed", ex);
}
}
Aggregations