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

时间:2017-07-14 07:43:49

标签: google-app-engine google-cloud-platform google-cloud-dataflow

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

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();
  }
}

管道代码:

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();            
    }
}

部署到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>

我的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>

我的app.yaml

service: [MY_SERVICE]
runtime: java
env: flex

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

resources:
  memory_gb: 2.0
health_check:
  enable_health_check: False

1 个答案:

答案 0 :(得分:-2)

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

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

  1. 仅使用Hello World测试servlet。如果它不起作用可能是配置问题。
  2. 使用您的数据流逻辑测试servlet。如果它无法正常工作,我会通过评论除第一行以外的所有内容进行测试,然后使用第二行评论第一行,依此类推。