Search in sources :

Example 51 with TransactionExecutionException

use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.

the class MetadataSetupService method cleanupRequestedInstancesWithoutFQDN.

public void cleanupRequestedInstancesWithoutFQDN(Long stackId, Set<String> instanceGroups) {
    try {
        transactionService.required(() -> {
            for (String instanceGroupName : instanceGroups) {
                Optional<InstanceGroup> ig = instanceGroupService.findOneWithInstanceMetadataByGroupNameInStack(stackId, instanceGroupName);
                if (ig.isPresent()) {
                    List<InstanceMetaData> requestedInstances = instanceMetaDataService.findAllByInstanceGroupAndInstanceStatus(ig.get(), InstanceStatus.REQUESTED);
                    List<InstanceMetaData> requestedInstancesWithoutFQDN = requestedInstances.stream().filter(instanceMetaData -> instanceMetaData.getDiscoveryFQDN() == null).collect(Collectors.toList());
                    LOGGER.info("Set requested instances without FQDN to terminated: {}", requestedInstancesWithoutFQDN);
                    for (InstanceMetaData inst : requestedInstancesWithoutFQDN) {
                        inst.setTerminationDate(clock.getCurrentTimeMillis());
                        inst.setInstanceStatus(InstanceStatus.TERMINATED);
                    }
                    instanceMetaDataService.saveAll(requestedInstances);
                }
            }
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) 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) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 52 with TransactionExecutionException

use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.

the class MetadataSetupService method handleRepairFail.

public void handleRepairFail(Long stackId, Set<String> hostNames) {
    LOGGER.info("Handle repair fail for hostnames: {}", hostNames);
    for (String hostName : hostNames) {
        try {
            transactionService.required(() -> {
                Optional<InstanceMetaData> instance = instanceMetaDataService.findByHostname(stackId, hostName);
                instance.ifPresentOrElse(instanceMetaData -> {
                    LOGGER.info("Instance status for {}: {}", hostName, instanceMetaData.getInstanceStatus());
                    if (InstanceStatus.REQUESTED.equals(instanceMetaData.getInstanceStatus())) {
                        LOGGER.info("Instance in requested status is deleted: {}", hostName);
                        restorePreviousTerminatedInstanceMetadata(stackId, hostName);
                        instanceMetaData.setTerminationDate(clock.getCurrentTimeMillis());
                        instanceMetaData.setInstanceStatus(InstanceStatus.TERMINATED);
                        instanceMetaDataService.save(instanceMetaData);
                    }
                }, () -> restorePreviousTerminatedInstanceMetadata(stackId, hostName));
            });
        } catch (TransactionExecutionException e) {
            throw new TransactionRuntimeExecutionException(e);
        }
    }
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 53 with TransactionExecutionException

use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.

the class StackService method getJsonByCrn.

public StackV4Response getJsonByCrn(String crn, Collection<String> entry) {
    try {
        return transactionService.required(() -> {
            Stack stack = getByCrnWithLists(crn);
            StackV4Response stackResponse = stackToStackV4ResponseConverter.convert(stack);
            stackResponse = stackResponseDecorator.decorate(stackResponse, stack, entry);
            return stackResponse;
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 54 with TransactionExecutionException

use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.

the class StackService method getByCrnInWorkspaceWithEntries.

public StackV4Response getByCrnInWorkspaceWithEntries(String crn, Long workspaceId, Set<String> entries, User user, StackType stackType) {
    try {
        return transactionService.required(() -> {
            Workspace workspace = workspaceService.get(workspaceId, user);
            ShowTerminatedClustersAfterConfig showTerminatedClustersAfterConfig = showTerminatedClusterConfigService.get();
            Optional<Stack> stack = findByCrnAndWorkspaceIdWithLists(crn, workspace.getId(), stackType, showTerminatedClustersAfterConfig);
            if (stack.isEmpty()) {
                throw new NotFoundException(format("Stack not found by crn '%s'", crn));
            }
            StackV4Response stackResponse = stackToStackV4ResponseConverter.convert(stack.get());
            stackResponse = stackResponseDecorator.decorate(stackResponse, stack.get(), entries);
            return stackResponse;
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : ShowTerminatedClustersAfterConfig(com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 55 with TransactionExecutionException

use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.

the class LeaderElectionServiceTest method testElectionNeededAndFails.

@Test
public void testElectionNeededAndFails() throws TransactionExecutionException {
    when(periscopeNodeRepository.countByLeaderIsTrueAndLastUpdatedIsGreaterThan(anyLong())).thenReturn(0L);
    when(transactionService.required(any(Supplier.class))).thenThrow(new TransactionExecutionException("Persisting went wrong", new RuntimeException()));
    underTest.leaderElection();
    verify(transactionService, times(1)).required(any(Supplier.class));
    verify(timer, times(1)).cancel();
    verify(timer, times(1)).purge();
    verify(timerFactory, times(1)).get();
    verify(timer, times(0)).schedule(any(TimerTask.class), anyLong(), anyLong());
}
Also used : TimerTask(java.util.TimerTask) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Supplier(java.util.function.Supplier) Test(org.junit.Test)

Aggregations

TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)56 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)34 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)26 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)17 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)12 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)10 List (java.util.List)10 Set (java.util.Set)10 Inject (javax.inject.Inject)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)9 Optional (java.util.Optional)9 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)8 Collection (java.util.Collection)8 Map (java.util.Map)8 Collectors (java.util.stream.Collectors)8 Service (org.springframework.stereotype.Service)8 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)7 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)7