Search in sources :

Example 1 with StackIdView

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;
}
Also used : StackIdView(com.sequenceiq.cloudbreak.domain.projection.StackIdView) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack)

Example 2 with StackIdView

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");
}
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 3 with StackIdView

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());
}
Also used : StackIdView(com.sequenceiq.cloudbreak.domain.projection.StackIdView) Test(org.junit.Test)

Example 4 with StackIdView

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

Example 5 with StackIdView

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);
    }
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) Map(java.util.Map) TargetGroupPersistenceService(com.sequenceiq.cloudbreak.service.stack.TargetGroupPersistenceService) UPDATE_FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_FAILED) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) InstanceMetadataType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType) Collection(java.util.Collection) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) STARTED(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus.STARTED) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Optional(java.util.Optional) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) InstanceLifeCycle(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceLifeCycle) Clock(com.sequenceiq.cloudbreak.common.service.Clock) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) LoadBalancerConfigService(com.sequenceiq.cloudbreak.service.LoadBalancerConfigService) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Function(java.util.function.Function) StackStatusService(com.sequenceiq.cloudbreak.service.stackstatus.StackStatusService) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) LoadBalancerConfigConverter(com.sequenceiq.cloudbreak.service.LoadBalancerConfigConverter) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) TERMINATED(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus.TERMINATED) Logger(org.slf4j.Logger) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) STACK_INSTANCE_METADATA_RESTORED(com.sequenceiq.cloudbreak.event.ResourceEvent.STACK_INSTANCE_METADATA_RESTORED) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) StackIdView(com.sequenceiq.cloudbreak.domain.projection.StackIdView) CREATED(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus.CREATED) StringUtils(org.springframework.util.StringUtils) Optional(java.util.Optional) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) StackIdView(com.sequenceiq.cloudbreak.domain.projection.StackIdView) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup)

Aggregations

StackIdView (com.sequenceiq.cloudbreak.domain.projection.StackIdView)5 CloudLoadBalancerMetadata (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)3 LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)3 CloudInstanceMetaData (com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData)2 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)2 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)2 StackIdViewImpl (com.sequenceiq.cloudbreak.service.stack.StackIdViewImpl)2 StackType (com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType)1 UPDATE_FAILED (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_FAILED)1 InstanceLifeCycle (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceLifeCycle)1 InstanceMetadataType (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType)1 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)1 Image (com.sequenceiq.cloudbreak.cloud.model.Image)1 CREATED (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus.CREATED)1 STARTED (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus.STARTED)1 TERMINATED (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus.TERMINATED)1