Search in sources :

Example 26 with TransactionExecutionException

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

the class StackScaleV4RequestToUpdateClusterV4RequestConverter method convert.

public UpdateClusterV4Request convert(StackScaleV4Request source) {
    try {
        return transactionService.required(() -> {
            UpdateClusterV4Request updateStackJson = new UpdateClusterV4Request();
            Stack stack = stackService.getByIdWithListsInTransaction(source.getStackId());
            stack.getInstanceGroups().stream().filter(instanceGroup -> source.getGroup().equals(instanceGroup.getGroupName())).findFirst().ifPresentOrElse(instanceGroup -> {
                String blueprintText = stack.getCluster().getBlueprint().getBlueprintText();
                BlueprintTextProcessor blueprintTextProcessor = clusterDefinitionTextProcessorFactory.createBlueprintTextProcessor(blueprintText);
                boolean dataNodeComponentInHostGroup = blueprintTextProcessor.isComponentExistsInHostGroup("DATANODE", instanceGroup.getGroupName());
                HostGroupAdjustmentV4Request hostGroupAdjustmentJson = new HostGroupAdjustmentV4Request();
                hostGroupAdjustmentJson.setWithStackUpdate(true);
                hostGroupAdjustmentJson.setValidateNodeCount(dataNodeComponentInHostGroup);
                hostGroupAdjustmentJson.setHostGroup(source.getGroup());
                hostGroupAdjustmentJson.setForced(source.getForced());
                int scaleNumber = source.getDesiredCount() - instanceGroup.getNotTerminatedInstanceMetaDataSet().size();
                hostGroupAdjustmentJson.setScalingAdjustment(scaleNumber);
                updateStackJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
            }, () -> {
                throw new BadRequestException(String.format("Group '%s' not available on stack", source.getGroup()));
            });
            return updateStackJson;
        });
    } catch (TransactionExecutionException e) {
        throw e.getCause();
    }
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) BlueprintTextProcessor(com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) UpdateClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 27 with TransactionExecutionException

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

the class DisableOnGCPRestartAction method restart.

@Override
public void restart(FlowParameters flowParameters, String flowChainId, String event, Object payload) {
    Payload stackPayload = (Payload) payload;
    Stack stack = stackService.getByIdWithTransaction(stackPayload.getResourceId());
    if (stack.getPlatformVariant().equals(GCP)) {
        try {
            flowLogService.terminate(stackPayload.getResourceId(), flowParameters.getFlowId());
        } catch (TransactionExecutionException e) {
            throw new TransactionRuntimeExecutionException(e);
        }
    } else {
        restart(flowParameters, flowChainId, event, payload, stack);
    }
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Payload(com.sequenceiq.cloudbreak.common.event.Payload) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 28 with TransactionExecutionException

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

the class ImageCatalogService method createForLoggedInUser.

public ImageCatalog createForLoggedInUser(ImageCatalog imageCatalog, Long workspaceId, String accountId, String creator) {
    String resourceCrn = createCRN(accountId);
    imageCatalog.setResourceCrn(resourceCrn);
    imageCatalog.setCreator(creator);
    try {
        return transactionService.required(() -> {
            ImageCatalog created = super.createForLoggedInUser(imageCatalog, workspaceId);
            ownerAssignmentService.assignResourceOwnerRoleIfEntitled(creator, resourceCrn, accountId);
            return created;
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 29 with TransactionExecutionException

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

the class UserService method createUser.

private User createUser(CloudbreakUser cloudbreakUser) {
    try {
        return transactionService.requiresNew(() -> {
            User user = new User();
            user.setUserId(cloudbreakUser.getUserId());
            user.setUserName(cloudbreakUser.getUsername());
            user.setUserCrn(cloudbreakUser.getUserCrn());
            Tenant tenant = tenantService.findByName(cloudbreakUser.getTenant()).orElse(null);
            if (tenant == null) {
                tenant = new Tenant();
                tenant.setName(cloudbreakUser.getTenant());
                tenant = tenantService.save(tenant);
                createTenantDefaultWorkspace(tenant);
            }
            user.setTenant(tenant);
            return userRepository.save(user);
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : CrnUser(com.sequenceiq.cloudbreak.auth.CrnUser) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) Tenant(com.sequenceiq.cloudbreak.workspace.model.Tenant) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 30 with TransactionExecutionException

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

the class UserService method findUserAndSetCrnIfExists.

private User findUserAndSetCrnIfExists(CloudbreakUser cloudbreakUser) {
    try {
        return transactionService.requiresNew(() -> {
            Optional<User> userByIdAndTenantName = userRepository.findByTenantNameAndUserId(cloudbreakUser.getTenant(), cloudbreakUser.getUserId());
            if (userByIdAndTenantName.isPresent()) {
                User user = userByIdAndTenantName.get();
                if (user.getUserCrn() == null) {
                    user.setUserCrn(cloudbreakUser.getUserCrn());
                    user = userRepository.save(user);
                }
                return user;
            }
            return null;
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : CrnUser(com.sequenceiq.cloudbreak.auth.CrnUser) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

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