用于登台位置的无效GCS URI

时间:2018-04-04 15:20:37

标签: google-cloud-dataflow apache-beam

当通过包含所有依赖项的jar启动数据流作业(v.2.4.0)时,而不是使用提供的GCS路径,似乎在本地创建了gs:/文件夹,因此数据流工作者尝试访问<localjarfolderpath>/gs:/...而不是真正的GCS路径gs://... 如果我是正确的,那么数据流1.x.x就不是这样了。

示例命令:

java -cp 0.1-1.0-SNAPSHOT-jar-with-dependencies.jar Main --stagingLocation=gs://test/staging/

云控制台出错:

Staged package 0.1-1.0-SNAPSHOT-jar-with-dependencies-89nvLkMzfT53iBBXlpW_oA.jar at location <localjarfolderpath>/gs:/test/staging/ is inaccessible. ... The pattern must be of the form "gs://<bucket>/path/to/file".

2 个答案:

答案 0 :(得分:4)

我设法通过不使用maven-assembly-plugin来构造具有依赖关系的jar来解决它。使用maven-dependency-pluginmaven-jar-plugin创建jar-with-dependencies时,正确构建了分段路径,Dataflow成功启动了作业。作为参考,这是我的maven jar build:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/lib</outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
                <classpathPrefix>lib/</classpathPrefix>
                <mainClass>com.package.main</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>

由于jar包含类路径的清单条目,因此您可以使用以下命令启动作业:

java -jar my-dataflow-job.jar

请注意,jar和包含所有依赖项的lib必须位于同一目录中。

<强>更新 我注意到java -jar命令并不总是正确设置类路径,即使它是在清单中定义的。如果您在使用java -jar命令时遇到问题,则以下命令应该有效:

java -cp "my-dataflow-job.jar:lib/*" org.company.dataflow.Main

更新2:@IvanPlantevin一起,我发现了真正的问题。触发我们的是post。问题是maven-assembly-plugin打包jar的方式。在清单中,在服务下,并非所有FileSystemRegistrars都包含在内。在我们的例子中,它错过了GcsFileSystemRegistrar。我们已使用maven-shade-pluginServicesResourceTransformer修复了问题。下面的解决方案真正解决了这个问题。上述解决方案仅仅是一种解决方法。这是我们目前的构建:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.1.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <!-- NOTE! Don't forget the ServicesResourceTransformer, otherwise other file system registrars are not added to the jar! -->
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.package.main</mainClass>
                            </transformer>
                        </transformers>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <shadedClassifierName>runner</shadedClassifierName>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

最后,您可以按常规方式启动它:java -jar my-dataflow-job.jar

答案 1 :(得分:0)

我也遇到了这个错误 - 我通过从我的pom.xml中删除beam-runners依赖关系并让google-cloud-dataflow-java-sdk-all自动获取它来解决它。不完全确定为什么会有效,但确实如此。