用于登台位置的无效GCS URI

bjo*_*ndv 6 google-cloud-dataflow apache-beam

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

示例命令:

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".

Rob*_*sch 4

我设法解决了这个问题,方法是不使用maven-assembly-plugin来构建具有依赖项的 jar。当使用maven-dependency-pluginwithmaven-jar-plugin创建 jar-with-dependencies 时,暂存路径已正确构建,并且 Dataflow 成功启动作业。作为参考,这是我的 Maven jar 构建:

<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>
Run Code Online (Sandbox Code Playgroud)

由于 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一起,我发现了真正的问题是什么。触发我们的是这篇文章。问题在于maven-assembly-plugin打包 jar 的方式。在清单中的服务项下,并未FileSystemRegistrars包含所有内容。在我们的例子中,它错过了GcsFileSystemRegistrar. 我们通过使用maven-shade-plugin和解决了这个问题ServicesResourceTransformer。下面的解决方案确实解决了问题。上述解决方案只是一种解决方法。这是我们当前的构建:

<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>
Run Code Online (Sandbox Code Playgroud)

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