Skip to content

Commit

Permalink
move apache mirrors/pattern to their place
Browse files Browse the repository at this point in the history
  • Loading branch information
kgyrtkirk committed Apr 8, 2020
1 parent 2b8248e commit f7f5814
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
41 changes: 39 additions & 2 deletions src/main/java/hu/rxd/toolbox/switcher/ApacheMirrors.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -17,6 +19,41 @@ public String decodeStackVersion(String version) {

@Override
public Collection<Mirror> of0(Version ver) {
return Collections.EMPTY_LIST;
List<Mirror> ret = new ArrayList<Mirror>();
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);
}
}

}
}
5 changes: 1 addition & 4 deletions src/main/java/hu/rxd/toolbox/switcher/GenericComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ protected File downloadArtifact(List<URL> 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<URL> getCandidateUrls(Version ver) throws Exception {
List<URL> ret = new ArrayList<>();
Expand All @@ -126,8 +124,6 @@ protected List<URL> 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:
Expand Down Expand Up @@ -159,5 +155,6 @@ protected List<URL> 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;
}
2 changes: 1 addition & 1 deletion src/main/java/hu/rxd/toolbox/switcher/Mirror.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

interface Mirror {

URL getFor(Component tez, String componentVersion) throws Exception;
URL getFor(Component component, String componentVersion) throws Exception;

}

0 comments on commit f7f5814

Please sign in to comment.