GoogleCloudPlatform / google-cloud-eclipse

Google Cloud Platform plugin for Eclipse
Apache License 2.0
86 stars 49 forks source link

Bookshelf sample app fails to start on local server #1557

Closed elharo closed 7 years ago

elharo commented 7 years ago

not immediately clear why:

image

elharo commented 7 years ago

INFO: submitting command: /Users/elharo/google-cloud-sdk/bin/dev_appserver.py /Users/elharo/workspaces/runtime-gcloud-eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/bookshelf-standard-2 --host=localhost --port=8080 --admin_host=localhost --admin_port=8000 --max_module_instances=1 --automatic_restart=false

chanseokoh commented 7 years ago

I was also perplexed by what's going on. After some time, I happened to open the Console view, and I see

google.appengine.api.yaml_errors.EventError: Unable to assign value '[YOUR-PROJECT-ID]' to attribute 'application':
Value '[YOUR-PROJECT-ID]' for application does not match expression '^(?:(?:[a-z\d\-]{1,100}\~)?(?:(?!\-)[a-z\d\-\.]{1,100}:)?(?!-)[a-z\d\-]{0,99}[a-z\d])$'
  in "<string>", line 1, column 14:
    application: '[YOUR-PROJECT-ID]'
                 ^

Removing the <application> element fixes that problem. Running locally works, but the app gives 503. It might be that the app needs further configuration. Not sure.

HTTP ERROR 503

Problem accessing /. Reason:

    java.lang.IllegalStateException: Invalid storage type. Check if bookshelf.storageType property is set.
Caused by:

javax.servlet.UnavailableException: java.lang.IllegalStateException: Invalid storage type. Check if bookshelf.storageType property is set.
    at org.mortbay.jetty.servlet.ServletHolder.makeUnavailable(ServletHolder.java:415)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:458)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:224)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at com.google.appengine.tools.development.JettyContainerService.startContainer(JettyContainerService.java:268)
    at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:284)
    at com.google.appengine.tools.development.AutomaticInstanceHolder.startUp(AutomaticInstanceHolder.java:26)
    at com.google.appengine.tools.development.AbstractModule.startup(AbstractModule.java:87)
    at com.google.appengine.tools.development.Modules.startup(Modules.java:105)
    at com.google.appengine.tools.development.devappserver2.DevAppServer2Impl.doStart(DevAppServer2Impl.java:250)
    at com.google.appengine.tools.development.devappserver2.DevAppServer2Impl.access$000(DevAppServer2Impl.java:52)
    at com.google.appengine.tools.development.devappserver2.DevAppServer2Impl$1.run(DevAppServer2Impl.java:216)
    at com.google.appengine.tools.development.devappserver2.DevAppServer2Impl$1.run(DevAppServer2Impl.java:214)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.google.appengine.tools.development.devappserver2.DevAppServer2Impl.start(DevAppServer2Impl.java:214)
    at com.google.appengine.tools.development.devappserver2.StandaloneInstance$StartAction.apply(StandaloneInstance.java:131)
    at com.google.appengine.tools.development.devappserver2.StandaloneInstance$StartAction.apply(StandaloneInstance.java:83)
    at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:47)
    at com.google.appengine.tools.development.devappserver2.StandaloneInstance.run(StandaloneInstance.java:67)
    at com.google.appengine.tools.development.devappserver2.StandaloneInstance.main(StandaloneInstance.java:45)
Powered by Jetty://
chanseokoh commented 7 years ago

However, looking at the bookshelf doc, it sounds like it should just work:

Running the app on your local machine

To run the app locally:

  1. In the getting-started-java/bookshelf/2-structured-data directory, enter this command to start a local web server: mvn -Plocal clean jetty:run-exploded -DprojectID=[YOUR-PROJECT-ID]
  2. In your web browser, navigate to http://localhost:8080
akerekes commented 7 years ago

From the error message we seem to miss the bookshelf.storageType property:

https://github.com/GoogleCloudPlatform/getting-started-java/blob/master/bookshelf-standard/2-structured-data/pom.xml#L34

chanseokoh commented 7 years ago

So the issue is like, dev_appserver doesn't import properties defined in pom.xml? dev_appserver is independent of build systems and configurations, so basically users may need to provide properties to dev_appserver themselves when necessary? Or, could it be that the app is just broken?

briandealwis commented 7 years ago

It looks like some maven plugin uses the pom properties to fill in web.xml as part of the build.

akerekes commented 7 years ago

What are the steps to import this into Eclipse?

akerekes commented 7 years ago

Please refer to http://stackoverflow.com/a/42954117/1927782 for steps on how to import the project.

briandealwis commented 7 years ago

Importing the bookshelf-2 has a number of problems.

  1. The example projects (in fact, the com.google.cloud.samples:shared-configuration parent) have switched to using the errorprone compiler which leads to configuration errors when importing the projects. This is arguably something we should fix.
    • We could add m2e lifecycle-metadata to com.google.cloud.samples:shared-configuration as I did with https://github.com/GoogleCloudPlatform/appengine-plugins-core/pull/354 but this turns into a game of whackamole.
    • We can workaround this by adding a lifecycle-mapping to ignore errorprone, similar to what we do for the versions-maven-plugin (used in the appengine-standard-archetype/HelloAppEngine archetype). But this only helps people who have CT4E installed.
    • I think we may should also turn these into proper m2e configurators that are picked up by the m2e discovery when importing the projects.
  2. We don't auto-discover appengine projects and add our facet, so the user has to manually convert the project to an AES project using our converter. But we rightly error out as the Dynamic Web Facet is version 3.1. There are two errors here, but they're in bookshelf-2 (actually all the bookshelf projects):
  3. Finally m2e is not applying resource filtering to the web.xml and so the ${bookshelf.storageType} is never propagated. This is actually a bug in m2e-wtp Here there are two issues: first, m2e-wtp only checks if the maven-war-plugin configuration specifies the filteringDeploymentDescriptors property, but it doesn't look for the maven.war.filteringDeploymentDescriptors user property which is used in the bookshelf poms. This user property was removed from the maven-war-plugin in 3.0.0 MWAR-376. But we're pulling in the default version 2.2.
    • we can provide a fix for m2e-wtp (filed as bug 514577 with a fix) (Fixed in m2e-wtp 1.3.2 in Oxygen)
    • we can explicitly specify the maven-war-plugin in the bookshelf parent pom
  4. Finally, I hit an error as the Google Cloud SDK wasn't found (#1709)

Having worked around the above, it works!

xmuweili commented 7 years ago

Still have this issue on MacOS with Maven 3.5.0

elharo commented 7 years ago

OK, I'll try to take a look at this.

elharo commented 7 years ago

see https://cloud.google.com/java/getting-started/tutorial-app

jgmatu commented 7 years ago

Good Morning,

I have the same problem @chanseokoh Exception :

    javax.servlet.UnavailableException: java.lang.IllegalStateException: Invalid storage type. Check if bookshelf.storageType property is set.

My POM bockshelf:

     <parent> <!-- Only used for testing - NOT REQUIRED -->
        <artifactId>getting-started-java</artifactId>
        <groupId>com.example</groupId>
        <version>1.0.0</version>
        <relativePath>../</relativePath>
    </parent>

    <properties>
        <jetty.maven.plugin>9.4.3.v20170317</jetty.maven.plugin>
        <bookshelf.storageType>datastore</bookshelf.storageType> <!-- datastore or cloudsql -->
        <sql.dbName>bookshelf</sql.dbName> <!-- A reasonable default -->    
        <bookshelf.bucket>SECRET</bookshelf.bucket>                    <!-- bucket you created earlier -->
         <callback.host>SECRET</callback.host>     <!-- Typically projectname.appspot.com -->
         <bookshelf.clientID>SECRET</bookshelf.clientID>                <!-- for User Authentication -->
        <bookshelf.clientSecret>SECRET</bookshelf.clientSecret>        <!-- from g.co/cloud/console -->
    </properties>

    <profiles>

What can be the cause of problem? The storageType is properly set to datastore.

elharo commented 7 years ago

The initial sample works for me now (which it didn't used to). How deep in the tutorial were you?

elharo commented 7 years ago

deployment works though I do get this warning:

Nov 07, 2017 10:18:14 AM com.google.cloud.tools.eclipse.appengine.standard.java8.AppEngineWebBuilder build
WARNING: P/bookshelf-standard-2: no build required: missing appengine-web.xml

Surprising since this is a Java 7 project.

elharo commented 7 years ago

I'm going to close this for now since I can't reproduce. If you can with the latest CT4E, please reopen with more details.

jgmatu commented 7 years ago

Sorry I wrong of Google Cloud plataform proyect.

Sorry for the annoy!

nlonginow commented 6 years ago

Just downloaded and setup all cloud on MacOS (latest) and see this error as well. What is the fix?

Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T03:58:13-04:00) Maven home: /.../apache-maven-3.5.2 Java version: 1.8.0_131, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "10.13.1", arch: "x86_64", family: "mac"

chanseokoh commented 6 years ago

@nlonginow that is not an error message but what you get when you do mvn -version.

briandealwis commented 6 years ago

@chanseokoh I think @nlonginow is saying he's encountering this issue (Bookshelf sample app fails to start on local server) and he's reporting his configuration :-)

@nlonginow what version of Eclipse are you running? There is a bug in m2e-wtp that was fixed for Oxygen.

Vicmi13 commented 5 years ago

Hi, I figured out how to run correctly Bookshelf on the app engine standard Environment

I´m actually running with this

Maven home: /Applications/apache-maven-3.6.1 Java version: 1.8.0_211, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre`

IDE: STS (Sprint Tool Suite), Platform: Eclipse 2018-09 (4.9.0)

First of all.

I updated some repo versions, because when I was runnign locally with mvn -Plocal clean appengine:devserver have some errors with JSTL and doesn´t compile

Original POM.xml bookshelf-standard/2-structured-data/pom.xml

  <dependency>
      <groupId>javax.servlet</groupId>  
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>provided</scope>
  </dependency>
javax.servlet jsp-api 2.0
  <dependency>
     <groupId>jstl</groupId>
     <artifactId>jstl</artifactId>
     <version>1.2</version>
   </dependency>

my POm.xml Updated

 <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
    <scope>provided</scope>
</dependency>
  <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
      <scope>provided</scope>
  </dependency>

  <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
  <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
   </dependency>

I change <groupId><artifactID><version> of these 3 dependencies becasuse the older ones were deprecated (Validated with Maven Repository).

And that`s it, works good

Captura de pantalla 2019-05-22 a la(s) 14 31 27

For the deploying the app in the App Engine Standard Environment I updated appengine-web.xml, it was running with java 7 and for App Engine was deprecated Migrating from Java 7 to Java 8 Runtime Then run the command

mvn appengine:update -Dappengine.appId=[YOUR-PROJECT-ID] -Dappengine.version=[YOUR-VERSION]

Where YOUR-PROJECT-ID is the name that appears in your console and [YOUR-VERSION] is the number of the version you want to release (Remove [] )

And obtained a BUILD SUCCESS and perfectly running in https://[YOUR-PROJECT-ID].appspot.com

Captura de pantalla 2019-05-22 a la(s) 15 02 48