class RecipeExecutionFailureCollector {

    public List<RecipeFailure> collectErrors(CloudbreakOrchestratorException exception) {
        Multimap<String, String> nodesWithErrors = getNodesWithErrors(exception);

        if (nodesWithErrors.isEmpty()) {
            throw new CloudbreakServiceException("Failed to collect recipe execution failures. Cause exception contains no information.", exception);
        }

        List<RecipeFailure> failures = nodesWithErrors.asMap().entrySet().stream()
                .flatMap(e -> e.getValue().stream()
                        .map(v -> new SimpleImmutableEntry<>(e.getKey(), v))
                        .map(failure -> new RecipeFailure(failure.getKey(), getRecipePhase(failure.getValue()), getFailedRecipeName(failure.getValue()))))
                .filter(failure -> !failure.getRecipeName().isEmpty() && !failure.getPhase().isEmpty())
                .collect(Collectors.toList());

        return failures;
    }

}