use of com.alibaba.alink.common.exceptions.DistributePluginException in project Alink by alibaba.
the class PluginDownloader method loadPluginConfig.
private static String loadPluginConfig(String configFileName, FilePath remotePath, String localPath, boolean force) throws IOException {
final FilePath remoteFilePath = new FilePath(new Path(remotePath.getPath(), configFileName), remotePath.getFileSystem());
downloadFileLocked(localPath, configFileName, (rawPath, path) -> {
File rawFile = new File(rawPath.getPath());
if (force || !rawFile.exists()) {
download(remoteFilePath, path.getPath());
if (force) {
rawFile.delete();
}
if (!new File(path.getPath()).renameTo(new File(rawPath.getPath()))) {
throw new DistributePluginException(String.format("Commit file: %s fail.", path.getPath()));
}
}
});
return Files.toString(new File(new Path(localPath, configFileName).getPath()), StandardCharsets.UTF_8);
}
use of com.alibaba.alink.common.exceptions.DistributePluginException in project Alink by alibaba.
the class PluginDownloader method downloadPluginSafely.
public void downloadPluginSafely(String pluginName, String pluginVersion) throws IOException {
loadPluginConfig();
String pluginFolder = pluginName + "-" + pluginVersion;
if (jarsPluginConfigs.containsKey(pluginName)) {
final List<String> jars = getListOfJars(pluginName, pluginVersion);
final FilePath remotePath = new FilePath(new Path(getRemoteFlinkRoot().getPath(), pluginFolder), getRemoteFlinkRoot().getFileSystem());
downloadFileLocked(getLocalFlinkRoot(), pluginFolder, (rawPath, path) -> {
if (new File(rawPath.getPath()).exists()) {
return;
}
File f = new File(path.getPath());
if (f.exists()) {
// overwrite tmp file.
LOG.info("Tmp file {} exists. Delete first.", f);
try {
FileUtils.forceDelete(f);
} catch (IOException e) {
LOG.warn("Delete tmp file {} returns false.", f, e);
}
}
for (String jar : jars) {
download(new FilePath(new Path(remotePath.getPath(), jar), remotePath.getFileSystem()), new Path(path, jar).getPath());
}
if (!new File(path.getPath()).renameTo(new File(rawPath.getPath()))) {
throw new DistributePluginException(String.format("Commit file: %s fail.", path.getPath()));
}
});
} else if (resourcePluginConfigs.containsKey(pluginName)) {
final List<String> resources = getListOfResource(pluginName, pluginVersion);
final FilePath remotePath = new FilePath(new Path(getRemoteResourceRoot().getPath(), pluginFolder), getRemoteResourceRoot().getFileSystem());
downloadFileLocked(getLocalResourceRoot(), pluginFolder, (rawPath, path) -> {
if (new File(rawPath.getPath()).exists()) {
return;
}
File f = new File(path.getPath());
if (f.exists()) {
// overwrite tmp file.
LOG.info("Tmp file {} exists. Delete first.", f);
try {
FileUtils.forceDelete(f);
} catch (IOException e) {
LOG.warn("Delete tmp file {} returns false.", f, e);
}
}
for (String resource : resources) {
download(new FilePath(new Path(remotePath.getPath(), resource), remotePath.getFileSystem()), new Path(path, resource).getPath());
}
if (!new File(path.getPath()).renameTo(new File(rawPath.getPath()))) {
throw new DistributePluginException(String.format("Commit file: %s fail.", path.getPath()));
}
});
} else {
throw new DistributePluginException("plugin [" + pluginName + "] not found!");
}
}
Aggregations