public void setupMetadata(CloudPlatform cloudPlatform, Long stackId) {
Stack stack = stackRepository.findOneWithLists(stackId);
MDCBuilder.buildMdcContext(stack);
try {
MetadataSetup metadataSetup = metadataSetups.get(cloudPlatform);
metadataSetup.setupMetadata(stack);
} catch (Exception e) {
LOGGER.error("Unhandled exception occurred while creating stack.", e);
LOGGER.info("Publishing {} event [StackId: '{}']", ReactorConfig.STACK_CREATE_FAILED_EVENT, stackId);
StackOperationFailure stackCreationFailure = new StackOperationFailure(stackId, "Internal server error occurred while creating stack.");
reactor.notify(ReactorConfig.STACK_CREATE_FAILED_EVENT, Event.wrap(stackCreationFailure));