Search in sources :

Example 51 with Status

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status in project cloudbreak by hortonworks.

the class StackDownscaleValidatorServiceTest method testCheckClusterInValidStatusWhenInStoppedStatus.

@Test
public void testCheckClusterInValidStatusWhenInStoppedStatus() {
    Stack stack = new Stack();
    stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.STOPPED));
    expectedException.expect(BadRequestException.class);
    expectedException.expectMessage("Cluster is in Stopped status. Please start the cluster for downscale.");
    underTest.checkClusterInValidStatus(stack);
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 52 with Status

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status in project cloudbreak by hortonworks.

the class StackStatusCheckerJob method switchToShortSyncIfNecessary.

private void switchToShortSyncIfNecessary(JobExecutionContext context) {
    if (isLongSyncJob(context)) {
        Stack stack = stackService.get(getStackId());
        Status stackStatus = stack.getStatus();
        if (!longSyncableStates().contains(stackStatus)) {
            jobService.schedule(getStackId(), StackJobAdapter.class);
        }
    }
}
Also used : DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 53 with Status

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status in project cloudbreak by hortonworks.

the class ArchiveInstanceMetaDataJob method executeTracedJob.

@Override
protected void executeTracedJob(JobExecutionContext context) throws JobExecutionException {
    StackView stackView = stackViewService.findById(getStackId()).orElseGet(StackView::new);
    Status stackStatus = stackView.getStatus();
    if (!Status.getUnschedulableStatuses().contains(stackStatus)) {
        archiveInstanceMetaDataOnStack(stackView);
    } else {
        LOGGER.debug("Existing stack InstanceMetaData archiving will be descheduled, because stack {} state is {}", stackView.getResourceCrn(), stackStatus);
        jobService.unschedule(context.getJobDetail().getKey());
    }
}
Also used : Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) StackView(com.sequenceiq.cloudbreak.domain.view.StackView)

Example 54 with Status

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status 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)

Example 55 with Status

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status in project cloudbreak by hortonworks.

the class RecoveryTeardownService method handleRecoveryTeardownError.

public void handleRecoveryTeardownError(StackView stack, Exception errorDetails) {
    Long stackId = stack.getId();
    String stackUpdateMessage = "Recovery failed: " + errorDetails.getMessage();
    DetailedStackStatus status = DetailedStackStatus.CLUSTER_RECOVERY_FAILED;
    stackUpdater.updateStackStatus(stackId, status, stackUpdateMessage);
    LOGGER.info("Error during stack recovery flow: ", errorDetails);
    metricService.incrementMetricCounter(MetricType.STACK_RECOVERY_TEARDOWN_FAILED, stack, errorDetails);
    flowMessageService.fireEventAndLog(stackId, status.name(), DATALAKE_RECOVERY_FAILED, stackUpdateMessage);
}
Also used : DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)

Aggregations

DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)23 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)22 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)18 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)12 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 StackStatusV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response)9 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)7 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)6 Collection (java.util.Collection)6 List (java.util.List)6 Set (java.util.Set)6 Inject (javax.inject.Inject)6 PollerStoppedException (com.dyngr.exception.PollerStoppedException)5 ClusterV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.ClusterV4Response)5 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)5