使用调用Dataflow Pipeline的Servlet部署GAE灵活项目时出错

时间:2021-03-27 15:35:19

I'm trying to deploy an App Engine Flexible Environment Project in JAVA with just a simple Servlet that create a Pipeline to execute in Google Dataflow each time the service is called, BUT I always got the same error deploying from Eclipse or Console. Anyone who knows why this error is occurring ? Please Help!

我正在尝试在JAVA中部署App Engine灵活环境项目,只需要一个简单的Servlet,每次调用服务时都会创建一个在Google Dataflow中执行的Pipeline,但我总是从Eclipse或Console中部署相同的错误。谁知道为什么会发生这种错误?请帮忙!

Servlet Code:

Servlet代码:

import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/execute")
public class ServletPipeline extends HttpServlet {

  public void doGet(HttpServletRequest request, HttpServletResponse response) 
      throws IOException, OutOfMemoryError  {

      BacktestingPipeline.execute();
  }
}

Pipeline Code:

管道代码:

import org.apache.beam.runners.dataflow.DataflowRunner;
import org.apache.beam.runners.dataflow.options.DataflowPipelineOptions;
import org.apache.beam.sdk.Pipeline;
import org.apache.beam.sdk.options.PipelineOptionsFactory;
import org.apache.beam.sdk.transforms.Create;
import org.apache.beam.sdk.transforms.DoFn;
import org.apache.beam.sdk.transforms.MapElements;
import org.apache.beam.sdk.transforms.ParDo;
import org.apache.beam.sdk.transforms.SimpleFunction;

public class BacktestingPipeline 
{
    public static void execute ()
    {
                //Create Pipeline Options for Google Cloud Dataflow
                DataflowPipelineOptions options = PipelineOptionsFactory.as(DataflowPipelineOptions.class);  

                options.setProject("[PROJECT_ID]");
                options.setTempLocation("gs://[MY_BUCKET]/temp");
                options.setStagingLocation("gs://[MY_BUCKET]/staging");
                options.setRunner(DataflowRunner.class);

                Pipeline p = Pipeline.create(options);

                p.apply(Create.of("Hello", "World"))
                .apply(MapElements.via(new SimpleFunction<String, String>() {
                  @Override
                  public String apply(String input) {
                    return input.toUpperCase();
                  }
                }))
                .apply(ParDo.of(new DoFn<String, Void>() {
                  @ProcessElement
                  public void processElement(ProcessContext c)  {
                    c.element();
                  }
                }));
                p.run();            
    }
}

Error deploying to GAE:

部署到GAE时出错:

...
[INFO] GCLOUD: I0713 19:39:08.452653    46 jvmti_globals.cc:352] Build time: Jun 22 2017 16:09:00
[INFO] GCLOUD: I0713 19:39:08.453889    46 jvmti_agent.cc:158] Java debuglet initialization started
[INFO] GCLOUD: I0713 19:39:08.454350    46 jvmti_agent.cc:192] Java debuglet initialization completed
[INFO] GCLOUD: I0713 19:39:08.509760    46 jvmti_agent.cc:203] Java VM started
[INFO] GCLOUD: I0713 19:39:08.515812    46 jvmti_agent.cc:213] JvmtiAgent::JvmtiOnVMInit initialization time: 6068 microseconds
[INFO] GCLOUD: I0713 19:39:08.516059    57 jvmti_agent_thread.cc:99] Agent thread started: CloudDebugger_main_worker_thread
[INFO] GCLOUD: I0713 19:39:08.516363    57 jvm_internals.cc:376] Loading internals from /opt/cdbg/cdbg_java_agent_internals.jar
[INFO] GCLOUD: openjdk version "1.8.0_131"
[INFO] GCLOUD: OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-1~bpo8+1-b11)
[INFO] GCLOUD: OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)
[INFO] GCLOUD:
[INFO] GCLOUD: I0713 19:39:08.712635    57 jni_logger.cc:31] Initializing ClassPathLookup, default classpath: true, extra classpath: [/var/lib/jetty/webapps/root/WEB-INF/classes, /var/lib/jetty/webapps/root/WEB-INF/lib], config: null
[INFO] GCLOUD: org.eclipse.jetty.util.log: Logging initialized @277ms to org.eclipse.jetty.util.log.Slf4jLog
[INFO] GCLOUD: org.eclipse.jetty.setuid.SetUIDListener: Setting umask=02
[INFO] GCLOUD: org.eclipse.jetty.setuid.SetUIDListener: Opened ServerConnector@4e04a765{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
[INFO] GCLOUD: org.eclipse.jetty.setuid.SetUIDListener: Setting GID=999
[INFO] GCLOUD: org.eclipse.jetty.setuid.SetUIDListener: Setting UID=999
[INFO] GCLOUD: org.eclipse.jetty.server.Server: jetty-9.4.5.v20170502
[INFO] GCLOUD: org.eclipse.jetty.deploy.providers.ScanningAppProvider: Deployment monitor [file:///var/lib/jetty/webapps/] at interval 0
[INFO] GCLOUD: I0713 19:39:10.374073    57 jni_logger.cc:31] Total size of indexed resources database: 431735 bytes
[INFO] GCLOUD: I0713 19:39:10.665549    57 jvm_internals.cc:132] ClassPathLookup constructor time: 1957471 microseconds
[INFO] GCLOUD: I0713 19:39:10.672448    57 yaml_data_visibility_config_reader.cc:33] debugger-config.yaml was not found.  Using default settings.
[INFO] GCLOUD: I0713 19:39:12.667318    57 jni_logger.cc:31] Debuggee gcp:271259282847:4fb4ffcfa9706933 registered: {"debuggee":{"id":"gcp:271259282847:4fb4ffcfa9706933","project":"271259282847","uniquifier":"1523BCAEC984DB9222692DCF325FC70185D7E805","description":"multibacktesting-2017-distributor-20170713t142425-402646356863159386","agentVersion":"google.com/java-gcp/@2","labels":{"module":"distributor","minorversion":"402646356863159386","version":"20170713t142425"}}}, agent version: 2.15
[INFO] GCLOUD: I0713 19:39:12.667506    57 jvmti_agent.cc:415] Attaching Java debuglet
[INFO] GCLOUD: I0713 19:39:12.667809    57 rate_limit.cc:143] CPU count: 1
[INFO] GCLOUD: I0713 19:39:12.667858    57 debugger.cc:100] Initializing Java debuglet
[INFO] GCLOUD: I0713 19:39:12.678215    57 debugger.cc:109] Debugger::Initialize initialization time: 10 ms
[INFO] GCLOUD:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15:20 min
[INFO] Finished at: 2017-07-13T14:39:30-05:00
[INFO] Final Memory: 21M/262M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.cloud.tools:appengine-maven-plugin:1.3.1:deploy (default-cli) on project testing-dataflow-servlet: Execution default-cli of goal com.google.cloud.tools:appengine-maven-plugin:1.3.1:deploy failed: Non zero exit: 1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.google.cloud.tools:appengine-maven-plugin:1.3.1:deploy (default-cli) on project testing-dataflow-servlet: Execution default-cli of goal com.google.cloud.tools:appengine-maven-plugin:1.3.1:deploy failed: Non zero exit: 1
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal com.google.cloud.tools:appengine-maven-plugin:1.3.1:deploy failed: Non zero exit: 1
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        ... 20 more
Caused by: com.google.cloud.tools.appengine.api.AppEngineException: Non zero exit: 1
        at com.google.cloud.tools.appengine.cloudsdk.process.NonZeroExceptionExitListener.onExit(NonZeroExceptionExitListener.java:30)
        at com.google.cloud.tools.appengine.cloudsdk.internal.process.DefaultProcessRunner.syncRun(DefaultProcessRunner.java:211)
        at com.google.cloud.tools.appengine.cloudsdk.internal.process.DefaultProcessRunner.run(DefaultProcessRunner.java:137)
        at com.google.cloud.tools.appengine.cloudsdk.CloudSdk.runGcloudCommand(CloudSdk.java:193)
        at com.google.cloud.tools.appengine.cloudsdk.CloudSdk.runAppCommandInWorkingDirectory(CloudSdk.java:136)
        at com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineDeployment.deploy(CloudSdkAppEngineDeployment.java:90)
        at com.google.cloud.tools.maven.DeployMojo.execute(DeployMojo.java:107)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        ... 21 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
PS D:\Andres Ortiz\Eclipse Workspace\testing-dataflow-servlet>

My pom.xml

我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <packaging>war</packaging>
  <version>0.1.0-SNAPSHOT</version>

  <groupId>com.testing</groupId>
  <artifactId>testing-dataflow-servlet</artifactId>  

  <properties>
    <appengine.maven.plugin.version>1.3.1</appengine.maven.plugin.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
    <failOnMissingWebXml>false</failOnMissingWebXml>
  </properties>

  <prerequisites>
    <maven>3.5</maven>
  </prerequisites>

  <dependencies>

    <!-- Compile/runtime dependencies -->
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-1.0-sdk</artifactId>
        <version>1.9.54</version>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.0-b07</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>

    <!-- Test Dependencies -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.xerial.snappy</groupId>
        <artifactId>snappy-java</artifactId>
        <version>1.1.4</version>
    </dependency>

    <dependency>
        <groupId>com.google.cloud.dataflow</groupId>
        <artifactId>google-cloud-dataflow-java-sdk-all</artifactId>
        <version>2.0.0</version>
    </dependency>    
  </dependencies>

  <build>
    <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
    <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.4.1</version>
        <executions>
          <execution>
            <id>enforce-maven</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireMavenVersion>
                  <version>3.0</version>
                </requireMavenVersion>
              </rules>    
            </configuration>
          </execution>
        </executions>
      </plugin>      

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <version>2.4</version>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>display-dependency-updates</goal>
              <goal>display-plugin-updates</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>appengine-maven-plugin</artifactId>
        <version>${appengine.maven.plugin.version}</version>
      </plugin>

    </plugins>
  </build>
</project>

My app.yaml

我的app.yaml

service: [MY_SERVICE]
runtime: java
env: flex

I have tried this in the app.yaml, but it does not works.

我在app.yaml中试过这个,但它不起作用。

resources:
  memory_gb: 2.0
health_check:
  enable_health_check: False

1 个解决方案

#1


-2  

It could be related with the exceptions you're throwing in doGet method. Try removing it. If the servlet is still not working it could be related with your Dataflow logic. Maybe it could also be related with the fact that you're not returning anything inside the doGet method.

它可能与您在doGet方法中抛出的异常有关。尝试删除它。如果servlet仍然无法运行,则可能与您的Dataflow逻辑有关。也许它也可能与你在doGet方法中没有返回任何内容的事实有关。

I'll do a sequential testing from the beggining.

我将从开始进行顺序测试。

  1. Test the servlet with just a Hello World. If it's not working is probably a configuration issue.
  2. 仅使用Hello World测试servlet。如果它不起作用可能是一个配置问题。
  3. Test the servlet with your Dataflow logic. If it's not working I'll test it with commenting everything except the first line, then the first one with the second one and so on.
  4. 使用Dataflow逻辑测试servlet。如果它不工作,我将测试它除了第一行,然后第一行与第二行,依此类推。

#1


-2  

It could be related with the exceptions you're throwing in doGet method. Try removing it. If the servlet is still not working it could be related with your Dataflow logic. Maybe it could also be related with the fact that you're not returning anything inside the doGet method.

它可能与您在doGet方法中抛出的异常有关。尝试删除它。如果servlet仍然无法运行,则可能与您的Dataflow逻辑有关。也许它也可能与你在doGet方法中没有返回任何内容的事实有关。

I'll do a sequential testing from the beggining.

我将从开始进行顺序测试。

  1. Test the servlet with just a Hello World. If it's not working is probably a configuration issue.
  2. 仅使用Hello World测试servlet。如果它不起作用可能是一个配置问题。
  3. Test the servlet with your Dataflow logic. If it's not working I'll test it with commenting everything except the first line, then the first one with the second one and so on.
  4. 使用Dataflow逻辑测试servlet。如果它不工作,我将测试它除了第一行,然后第一行与第二行,依此类推。