Search in sources :

Example 1 with ErrorMessageSanitizer

use of jetbrains.buildServer.serverSide.impl.ErrorMessageSanitizer in project teamcity-git by JetBrains.

the class GitGcErrorsHealthPage method fillModel.

@Override
public void fillModel(@NotNull final Map<String, Object> model, @NotNull final HttpServletRequest request) {
    HealthStatusItem item = getStatusItem(request);
    Object errors = item.getAdditionalData().get(GitGcErrorsHealthReport.ERRORS_KEY);
    Map<String, Pair<String, String>> sortedErrors = new TreeMap<>();
    if (errors instanceof Map) {
        File mainDataDirectory;
        try {
            mainDataDirectory = myServerPaths.getDataDirectory().getCanonicalFile();
        } catch (IOException e) {
            mainDataDirectory = myServerPaths.getDataDirectory().getAbsoluteFile();
        }
        ErrorMessageSanitizer errorMessageSanitizer = new ErrorMessageSanitizer(mainDataDirectory.getAbsolutePath(), "<TeamCity Data Directory>");
        File currentNodeDataDir = NodeSpecificConfigs.getNodeDataDirectory(mainDataDirectory);
        errorMessageSanitizer.addSanitizedPath(currentNodeDataDir.getAbsolutePath(), "<Node Data Directory>");
        // noinspection unchecked
        Set<Map.Entry> entries = ((Map) errors).entrySet();
        for (Map.Entry entry : entries) {
            Object key = entry.getKey();
            Object value = entry.getValue();
            if (key instanceof File && value instanceof String) {
                try {
                    String url = myMirrorManager.getUrl(((File) key).getName());
                    if (url != null) {
                        sortedErrors.put(url, Pair.create(errorMessageSanitizer.sanitize(((File) key).getCanonicalPath()), (String) value));
                    }
                } catch (IOException e) {
                    LOG.warnAndDebugDetails("Error while preparing health report data", e);
                }
            }
        }
    }
    model.put("errors", sortedErrors);
}
Also used : HealthStatusItem(jetbrains.buildServer.serverSide.healthStatus.HealthStatusItem) IOException(java.io.IOException) TreeMap(java.util.TreeMap) ErrorMessageSanitizer(jetbrains.buildServer.serverSide.impl.ErrorMessageSanitizer) TreeMap(java.util.TreeMap) Map(java.util.Map) File(java.io.File) Pair(com.intellij.openapi.util.Pair)

Aggregations

Pair (com.intellij.openapi.util.Pair)1 File (java.io.File)1 IOException (java.io.IOException)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 HealthStatusItem (jetbrains.buildServer.serverSide.healthStatus.HealthStatusItem)1 ErrorMessageSanitizer (jetbrains.buildServer.serverSide.impl.ErrorMessageSanitizer)1