From f7f581429e69f1055cb785bf6e82065408cbedae Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 8 Apr 2020 15:09:03 +0200 Subject: [PATCH] move apache mirrors/pattern to their place --- .../rxd/toolbox/switcher/ApacheMirrors.java | 41 ++++++++++++++++++- .../toolbox/switcher/GenericComponent.java | 5 +-- .../java/hu/rxd/toolbox/switcher/Mirror.java | 2 +- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/main/java/hu/rxd/toolbox/switcher/ApacheMirrors.java b/src/main/java/hu/rxd/toolbox/switcher/ApacheMirrors.java index f40403d..792ad83 100644 --- a/src/main/java/hu/rxd/toolbox/switcher/ApacheMirrors.java +++ b/src/main/java/hu/rxd/toolbox/switcher/ApacheMirrors.java @@ -1,7 +1,9 @@ package hu.rxd.toolbox.switcher; +import java.net.URL; +import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; +import java.util.List; public class ApacheMirrors implements Mirrors { @@ -17,6 +19,41 @@ public String decodeStackVersion(String version) { @Override public Collection of0(Version ver) { - return Collections.EMPTY_LIST; + List ret = new ArrayList(); + String apache_mirror = "http://xenia.sote.hu/ftp/mirrors/www.apache.org/"; + String archive_mirror = "https://archive.apache.org/dist/"; + ret.add(new ApacheMirror(apache_mirror)); + ret.add(new ApacheMirror(archive_mirror)); + return ret; + } + + static class ApacheMirror implements Mirror { + + private String root; + + public ApacheMirror(String root) { + this.root = root; + } + + @Override + public URL getFor(Component c, String componentVersion) throws Exception { + String p = getPath(c, componentVersion); + return new URL(root + "" + p); + } + + private String getPath(Component c, String componentVersion) { + String v = componentVersion; + switch (c) { + case hadoop: + return String.format("hadoop/common/hadoop-%s/hadoop-%s.tar.gz", v, v); + case hive: + return String.format("hive/hive-%s/apache-hive-%s-bin.tar.gz", v, v); + case tez: + return String.format("tez/%s/apache-tez-%s-bin.tar.gz", v, v); + default: + throw new RuntimeException("unknown:" + c); + } + } + } } diff --git a/src/main/java/hu/rxd/toolbox/switcher/GenericComponent.java b/src/main/java/hu/rxd/toolbox/switcher/GenericComponent.java index 7c4b679..9f24665 100644 --- a/src/main/java/hu/rxd/toolbox/switcher/GenericComponent.java +++ b/src/main/java/hu/rxd/toolbox/switcher/GenericComponent.java @@ -114,8 +114,6 @@ protected File downloadArtifact(List candidateUrls) throws IOException { throw new IOException("Cant find a valid url; tried: " + candidateUrls); } - String apache_mirror = "http://xenia.sote.hu/ftp/mirrors/www.apache.org/"; - String archive_mirror = "https://archive.apache.org/dist/"; protected List getCandidateUrls(Version ver) throws Exception { List ret = new ArrayList<>(); @@ -126,8 +124,6 @@ protected List getCandidateUrls(Version ver) throws Exception { for (Mirror m : ver.type.getMirrors().of0(ver)) { ret.add(m.getFor(getComponentType(), componentVersion)); } - ret.add(new URL(apache_mirror + getApacheMirrorPath(ver))); - ret.add(new URL(archive_mirror + getApacheMirrorPath(ver))); break; } case HDP: @@ -159,5 +155,6 @@ protected List getCandidateUrls(Version ver) throws Exception { // http://public-repo-1.hortonworks.com/HDP/centos7/3.x/updates/3.0.0.0/tars/tez/tez-0.9.1.3.0.0.0-1634.tar.gz] // at hu.rxd.toolbox.HiveDevBoxSwitcher$GenericComponent.tryDownload(Hive + @Deprecated abstract String getApacheMirrorPath(Version version) throws Exception; } diff --git a/src/main/java/hu/rxd/toolbox/switcher/Mirror.java b/src/main/java/hu/rxd/toolbox/switcher/Mirror.java index 45f1a86..bb482d0 100644 --- a/src/main/java/hu/rxd/toolbox/switcher/Mirror.java +++ b/src/main/java/hu/rxd/toolbox/switcher/Mirror.java @@ -4,6 +4,6 @@ interface Mirror { - URL getFor(Component tez, String componentVersion) throws Exception; + URL getFor(Component component, String componentVersion) throws Exception; } \ No newline at end of file