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();
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations