@Override
public Stack create(CbUser user, Stack stack) {
MDCBuilder.buildMdcContext(stack);
Stack savedStack = null;
Template template = templateRepository.findOne(stack.getTemplate().getId());
stack.setOwner(user.getUserId());
stack.setAccount(user.getAccount());
stack.setHash(generateHash(stack));
try {
savedStack = stackRepository.save(stack);
LOGGER.info("Publishing {} event [StackId: '{}']", ReactorConfig.PROVISION_REQUEST_EVENT, stack.getId());
reactor.notify(ReactorConfig.PROVISION_REQUEST_EVENT, Event.wrap(new ProvisionRequest(template.cloudPlatform(), stack.getId())));
} catch (DataIntegrityViolationException ex) {
throw new DuplicateKeyValueException(stack.getName(), ex);
}
return savedStack;
}