【问题标题】:Install apt-get dependencies on Google Dataflow with Beam Java SDK使用 Beam Java SDK 在 Google Dataflow 上安装 apt-get 依赖项
【发布时间】:2017-08-23 09:01:13
【问题描述】:
我们目前正在尝试让 OpenCV 在 Google Cloud Dataflow 上的 Java 作业中运行。不幸的是,我们无法将 Dataflow 正在使用的 Docker 容器替换为安装了 OpenCV 的容器。 (See other question) 如果我们使用 Python SDK,则可以选择指定一个 setup.py 文件,该文件可用于调用 apt-get。使用 Java SDK 创建的作业是否有类似的东西?
感谢您的帮助!
【问题讨论】:
标签:
java
opencv
google-cloud-platform
google-cloud-dataflow
apache-beam
【解决方案1】:
我想出了一个解决方案,但可能有更优雅的方法来做到这一点。
@Setup
public void setupDoFn() {
ProcessBuilder pb = new ProcessBuilder("apt-get", "install", "-y", "libopencv-dev");
try {
Process p = pb.start();
String line;
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
logger.debug("Apt-get: " + line);
}
input.close();
// Initialize the OpenCV Libarary
nu.pattern.OpenCV.loadLibrary();
} catch (IOException e) {
e.printStackTrace();
// If we could not install OpenCV, we have to terminate the stream
System.exit(-1);
}
}