From ba8f64a951e350588a64b0fc3c7edd42196b31ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 16 Dec 2023 11:38:46 +0100 Subject: [PATCH] Make mirror parse errors configurable Currently Tycho tests are quite unstable because it could happen that mirrors list can't be processed and then an error occur in the logs what make the test fail their "no errors". But also as a user one might be annoyed to see errors because mirror list can't be processed. This adds a new static MIRROR_PARSE_ERROR_LEVEL filed to allow configuration of the error level. --- .../artifact/repository/MirrorSelector.java | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java index d362a067a2..b40c6bc423 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation * Cloudsmith Inc - bug fixes @@ -36,15 +36,22 @@ /** * Mirror support class for repositories. This class implements - * mirror support equivalent to the mirroring of update manager sites. A repository - * optionally provides a mirror URL via the {@link IRepository#PROP_MIRRORS_URL} key. - * The contents of the file at this URL is expected to be an XML document - * containing a list of elements. The mirrors are assumed to be already + * mirror support equivalent to the mirroring of update manager sites. A repository + * optionally provides a mirror URL via the {@link IRepository#PROP_MIRRORS_URL} key. + * The contents of the file at this URL is expected to be an XML document + * containing a list of elements. The mirrors are assumed to be already * sorted geographically with closer mirrors first. *

* Always use {@link MirrorSelector.MirrorInfoComparator} for comparison. */ public class MirrorSelector { + + /** + * Allows to globally control the level at what mirror errors are logged that + * originate from not being able to process mirror urls, the default is error. + */ + public static volatile int MIRROR_PARSE_ERROR_LEVEL = IStatus.ERROR; + private static final double LOG2 = Math.log(2); /** @@ -179,15 +186,15 @@ public MirrorSelector(IRepository repository, Transport transport) { *
 	 *                       ->   ->
 	 *                       q  * t                             (dot product)
-	 *  sim(q,t) = --------------------------- 
+	 *  sim(q,t) = ---------------------------
 	 *               / || -> ||   || -> || \
 	 *              |  || q  || * || t  ||  |             (euclidean lengths)
 	 *               \                     /
-	 *  
+	 *
 	 *                              N
 	 *                             ---
 	 *                             \
-	 *                              >   Q   * T           
+	 *                              >   Q   * T
 	 *                             /     ai    ai
 	 *                             ---
 	 *                            i = 1
@@ -199,7 +206,7 @@ public MirrorSelector(IRepository repository, Transport transport) {
 	 *              |   \ |   >   Q    *  \ |   >   T     |
 	 *              |    \|  /     ai      \|  /     ai   |
 	 *              |     |  ---            |  ---        |
-	 *               \    | i = 1           | i = 1      / 
+	 *               \    | i = 1           | i = 1      /
 	 * 
*/ public static final class MirrorInfoComparator implements Comparator { @@ -210,7 +217,7 @@ public static final class MirrorInfoComparator implements Comparator static final double WEIGHT_BYTESPERSECOND = 1d / 25000d; /** * This weight influences the failureCount classification - * Value was calculated by empirical tests. + * Value was calculated by empirical tests. */ static final double WEIGHT_FAILURECOUNT = 1.75d; @@ -249,7 +256,7 @@ public int compare(MirrorInfo o1, MirrorInfo o2) { /** * Parses the given mirror URL to obtain the list of mirrors. Returns the mirrors, * or null if mirrors could not be computed. - * + * * Originally copied from DefaultSiteParser.getMirrors in org.eclipse.update.core */ private MirrorInfo[] computeMirrors(String mirrorsURL, IProgressMonitor monitor) { @@ -275,7 +282,9 @@ private MirrorInfo[] computeMirrors(String mirrorsURL, IProgressMonitor monitor) LogHelper.log(new Status(IStatus.WARNING, Activator.ID, String.format("Mirrors URL %s was not found", mirrorsURL))); //$NON-NLS-1$ } else { - log("Error processing mirrors URL: " + mirrorsURL, e); //$NON-NLS-1$ + LogHelper.log( + new Status(MIRROR_PARSE_ERROR_LEVEL, Activator.ID, + "Error processing mirrors URL: " + mirrorsURL, e)); //$NON-NLS-1$ } } return null; @@ -322,7 +331,7 @@ private String enrichWithClientLocation(String baseURL) { } /** - * Returns an equivalent location for the given artifact location in the base + * Returns an equivalent location for the given artifact location in the base * repository. Always falls back to the given input location in case of failure * to compute mirrors. Never returns null. */ @@ -371,7 +380,7 @@ private MirrorInfoComparator getComparator() { } private void log(String message, Throwable exception) { - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, message, exception)); + LogHelper.log(new Status(MIRROR_PARSE_ERROR_LEVEL, Activator.ID, message, exception)); } /** @@ -409,7 +418,7 @@ public synchronized void reportResult(String toDownload, IStatus result) { } } - /** + /** * Return whether or not all the mirrors for this selector have proven to be invalid * @return whether or not there is a valid mirror in this selector. */ @@ -438,8 +447,8 @@ private MirrorInfo selectMirror(IProgressMonitor monitor) { Arrays.sort(mirrors, getComparator()); for (;;) { //this is a function that randomly selects a mirror based on a logarithmic - //distribution. Mirror 0 has a 1/2 chance of being selected, mirror 1 has a 1/4 chance, - // mirror 2 has a 1/8 chance, etc. This introduces some variation in the mirror + //distribution. Mirror 0 has a 1/2 chance of being selected, mirror 1 has a 1/4 chance, + // mirror 2 has a 1/8 chance, etc. This introduces some variation in the mirror //selection, while still heavily favoring better mirrors //the algorithm computes the most significant digit in a binary number by computing the base 2 logarithm //if the first digit is most significant, mirror 0 is selected, if the second is most significant, mirror 1 is selected, etc