protected VMFile getRootFile(String imageID, String ownerID)
throws CannotTranslateException {
if (imageID == null) {
throw new CannotTranslateException("Request is missing image ID");
}
if (ownerID == null) {
throw new CannotTranslateException("Request is missing image ID");
}
String baseDir = this.getBaseDirectory();
if (baseDir == null) {
throw new CannotTranslateException("base directory missing");
}
final String imageURIstr = baseDir + "/" + ownerID + "/" + imageID;
URI imageURI;
try {
imageURI = new URI(imageURIstr);
} catch (URISyntaxException e) {
throw new CannotTranslateException(e.getMessage(), e);
}
if (this.scheme != null && this.scheme.equals("scp")) {
baseDir = baseDir.replaceFirst("gsiftp", "http");
final URL url;
try {
url = new URL(baseDir);
} catch (MalformedURLException e) {
throw new CannotTranslateException("unexpected, invalid URL: " +
imageURI.toASCIIString(), e);
}
if (url.getPort() != 22) {
String newurl = "scp://";
newurl += url.getHost();
newurl += ":22";
newurl += url.getPath() + "/" + ownerID + "/" + imageID;
try {
imageURI = new URI(newurl);
} catch (URISyntaxException e) {
throw new CannotTranslateException(e.getMessage(), e);
}
}
}