Problems using org.apache.lucene on Appengine - google-app-engine

Hi on my last project I used the lucene-analyzer for generating keywords on appengine. Now i want to use it again with my new project but it seems that it is restricted by GAE. I tried to set the version back to the version I used at my last Project but it doesn´t work anymore. I get the following error:
java.lang.NoClassDefFoundError: java.lang.management.ManagementFactory is a restricted class. Please see the Google App Engine developer's guide for more details.
[INFO] at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
[INFO] at org.apache.lucene.util.RamUsageEstimator.<clinit>(RamUsageEstimator.java:223)
[INFO] at org.apache.lucene.util.ArrayUtil.<clinit>(ArrayUtil.java:32)
[INFO] at java.lang.Class.forName0(Native Method)
[INFO] at java.lang.Class.forName(Class.java:190)
[INFO] at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70)
[INFO] at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:64)
[INFO] at org.apache.lucene.analysis.tokenattributes.CharTermAttributeImpl.<init>(CharTermAttributeImpl.java:33)
[INFO] at org.apache.lucene.analysis.tokenattributes.PackedTokenAttributeImpl.<init>(PackedTokenAttributeImpl.java:40)
[INFO] at org.apache.lucene.util.AttributeFactory$1.createInstance(AttributeFactory.java:140)
[INFO] at org.apache.lucene.util.AttributeFactory$StaticImplementationAttributeFactory.createAttributeInstance(AttributeFactory.java:103)
[INFO] at org.apache.lucene.util.AttributeSource.addAttribute(AttributeSource.java:222)
[INFO] at org.apache.lucene.analysis.standard.StandardTokenizer.<init>(StandardTokenizer.java:182)
[INFO] at org.apache.lucene.analysis.de.GermanAnalyzer.createComponents(GermanAnalyzer.java:194)
[INFO] at org.apache.lucene.analysis.Analyzer.tokenStream(Analyzer.java:144)
does anybody know why i get this error?

You get this error because Lucene's RamUsageEstimator tries to access the ManagementFactory class to determine the VM's object alignment. java.lang.management.ManagementFactory is restricted on GAE (probably for security reasons), and a NoClassDefFoundError is thrown.
If you look at LuceneAppEngine and LuGAEne (projects providing a directory implementation that lets you use Lucene on Google App Engine), you can see that they provide an alternative RamUsageEstimator, where they catch that exception:
https://github.com/UltimaPhoenix/luceneappengine/blob/416f86f1ab303d37d183af9e7e220b22437d71b9/src/main/java/org/apache/lucene/util/RamUsageEstimator.java#L179
https://github.com/svenjacobs/lugaene/blob/a3ced4f2a112d3810c4c5a0d84d4efcf4bf1e709/src/main/java/org/apache/lucene/util/RamUsageEstimator.java#L250
I think you should consider using one of these "lucene-GAE" projects if you want to use the lucene-analyzer on GAE.
I don't know why it worked for you in your previous project. Maybe you used one of these lucene-GAE projects and forgot to include it in the new project?

Related

No plugin found for prefix 'gcloud' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo]

I'm trying to deploy and run Google-pubsub sample code in Google app engine by this read me file. While running the deploy command I encounter below build error.
E:\java\cloud-pubsub-samples-java-master>mvn gcloud:deploy -Dgcloud.version=1 -DskipTests=true
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] pubsub-pull-sample
[INFO] Example for the Google Cloud Pub/Sub on Google App Engine.
[INFO] Cloud Dataflow Examples
[INFO] cloud-pubsub-samples-java
Downloading: https://repo.maven.apache.org/maven2/org/eclipse/m2e/lifecycle-mapping/1.0.0/lifecycle-mapping-1.0.0.pom
[WARNING] The POM for org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 is missing, no dependency information available
Downloading: https://repo.maven.apache.org/maven2/org/eclipse/m2e/lifecycle-mapping/1.0.0/lifecycle-mapping-1.0.0.jar
[WARNING] Failed to retrieve plugin descriptor for org.eclipse.m2e:lifecycle-mapping:1.0.0: Plugin org.eclipse.m2e:lifecycle-mapping:1.0.0 or one of its dependencies could not be resolved: Could not find artifact org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 in central (https://repo.maven.apache.org/maven2)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml (13 KB at 9.8 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml (20 KB at 8.9 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] pubsub-pull-sample ................................. SKIPPED
[INFO] Example for the Google Cloud Pub/Sub on Google App Engine. SKIPPED
[INFO] Cloud Dataflow Examples ............................ SKIPPED
[INFO] cloud-pubsub-samples-java .......................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.167 s
[INFO] Finished at: 2016-08-21T22:20:45+05:30
[INFO] Final Memory: 13M/245M
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'gcloud' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\JAISON.G\.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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/NoPluginFoundForPrefixException
This means that you haven't included the gcloud maven plugin in pom.xml. But you should no longer use gcloud, rather using appengine. See the documentation here.

GAE Flexible Environment Service error in memcache

I use jetty9-compat + java8 configuration and receive the following exception. Probably because of this I am not able to store objects in session, so in the end I cannot log in to my service.
[INFO] cze 28, 2016 11:17:56 AM com.google.apphosting.vmruntime.VmMetadataCache getMetadata
[INFO]
[INFO] INFO: Meta-data 'attributes/gae_affinity' path retrieval error: metadata
[INFO]
[INFO] cze 28, 2016 11:17:56 AM com.google.apphosting.vmruntime.VmApiProxyDelegate runSyncCall
[INFO]
[INFO] INFO: HTTP ApiProxy I/O error for memcache.Get: The target server failed to respond
[INFO]
[INFO] cze 28, 2016 11:17:56 AM com.google.appengine.api.memcache.LogAndContinueErrorHandler handleServiceError
[INFO]
[INFO] INFO: Service error in memcache
[INFO]
[INFO] com.google.appengine.api.memcache.MemcacheServiceException: RCP Failure for API call: memcache Get
[INFO]
[INFO] at com.google.apphosting.vmruntime.VmApiProxyDelegate.constructApiException(VmApiProxyDelegate.java:232)
[INFO]
[INFO] at com.google.apphosting.vmruntime.VmApiProxyDelegate.runSyncCall(VmApiProxyDelegate.java:195)
[INFO]
[INFO] at com.google.apphosting.vmruntime.VmApiProxyDelegate.makeApiCall(VmApiProxyDelegate.java:154)
[INFO]
[INFO] at com.google.apphosting.vmruntime.VmApiProxyDelegate.access$000(VmApiProxyDelegate.java:60)
[INFO]
[INFO] at com.google.apphosting.vmruntime.VmApiProxyDelegate$MakeSyncCall.call(VmApiProxyDelegate.java:436)
[INFO]
[INFO] at com.google.apphosting.vmruntime.VmApiProxyDelegate$MakeSyncCall.call(VmApiProxyDelegate.java:412)
[INFO]
[INFO] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[INFO]
[INFO] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[INFO]
[INFO] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[INFO]
[INFO] at java.lang.Thread.run(Thread.java:745)
[INFO]
[INFO]
[INFO]
[INFO] DEBUG 2016-06-28 11:17:56,493 api_server.py:277] Handled datastore_v3.Get in 0.0000
[INFO] cze 28, 2016 11:17:59 AM com.mysql.jdbc.log.Slf4JLogger logInfo
This issue is reproduced only locally, I face it too. I assume that it is caused by incorrect configuration of local memcached which is run by dev server.
I'll try to explain my point. In my case first request is always successful.
Because in case of first request Apache HttpClient opens a new connection and puts it into the pool.
There is source code https://github.com/GoogleCloudPlatform/appengine-java-vm-runtime/blob/master/appengine-managed-runtime/src/main/java/com/google/apphosting/vmruntime/VmApiProxyDelegate.java
All further requests are successful too, if they are executed with interval up to 10 seconds. But if there were no request within 10 seconds, next request fails.
It happens because memcached service closes connection from its side, but HttpClient doesn't know about it.
In VmApiProxyDelegate HttpClient is configured to close idle connections after 60 seconds. So, if I wait more than 1 minute instead of 10 seconds, my next request doesn't fail. Because in this case HttpClient opens new connection which is not closed yet.
To avoid this issue it would be correct to configure connection timeout from memcached stub side. But the documentation says that your requests to memcached can fail and you must handle these errors. So, I offer you to add error handler and some retry mechanism.
Of course all of the above fits your case, if everything is ok in your configuration. Taking into account that you did not provide examples of configuration and code, I assume that there everything is ok.

gcloud-java authentication datastore (upgrade to v1beta3 in 0.1.7/0.2.0)

I had a java GAE application running using gcloud-java 0.1.4 for some time and wanted to upgrade to gcloud-java 0.1.7/0.2.0, as we are experiences several 404s etc. (another problem). We are using gcloud as we connect to a datastore instance in another GAE application.
But after upgrading the package, our authentication fails. From what I read in release notes, we had to re-enable the datastore-api on the "host" application, so we did but without any results. When "downgrading" again, the application works as intended but still with some stability issues.
Are there other undocumented fixes/methods to get it to work?
My connection code/function looks like (stripped):
fis = new FileInputStream(Constants.PATH_TO_JSON_KEY);
sac = AuthCredentials.createForJson(fis);
DatastoreOptions.Builder builder = DatastoreOptions.builder();
builder.projectId(Constants.DATASTORE_PROJECT_ID);
builder.authCredentials(sac);
DatastoreOptions options = builder.build();
return options.service();
EDIT:
Here are the some of the stack traces that I get.
[INFO] apr 17, 2016 6:19:33 PM com.google.datastore.v1beta3.client.DatastoreFactory makeClient
[INFO] com.google.cloud.datastore.DatastoreException: Not authorized.
[INFO] at com.google.cloud.datastore.spi.DefaultDatastoreRpc.translate(DefaultDatastoreRpc.java:102)
[INFO] at com.google.cloud.datastore.spi.DefaultDatastoreRpc.runQuery(DefaultDatastoreRpc.java:157)
[INFO] at com.google.cloud.datastore.DatastoreImpl$1.call(DatastoreImpl.java:92)
[INFO] at com.google.cloud.datastore.DatastoreImpl$1.call(DatastoreImpl.java:89)
[INFO] at com.google.cloud.RetryHelper.doRetry(RetryHelper.java:181)
[INFO] at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:247)
[INFO] at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:237)
[INFO] at com.google.cloud.datastore.DatastoreImpl.runQuery(DatastoreImpl.java:88)
[INFO] at com.google.cloud.datastore.QueryResultsImpl.sendRequest(QueryResultsImpl.java:73)
[INFO] at com.google.cloud.datastore.QueryResultsImpl.<init>(QueryResultsImpl.java:57)
[INFO] at com.google.cloud.datastore.DatastoreImpl.run(DatastoreImpl.java:82)
[INFO] at com.google.cloud.datastore.DatastoreImpl.run(DatastoreImpl.java:73)
.....
[INFO] Caused by: com.google.datastore.v1beta3.client.DatastoreException: Not authorized., code=PERMISSION_DENIED
[INFO] at com.google.datastore.v1beta3.client.RemoteRpc.makeException(RemoteRpc.java:126)
[INFO] at com.google.datastore.v1beta3.client.RemoteRpc.makeException(RemoteRpc.java:169)
[INFO] at com.google.datastore.v1beta3.client.RemoteRpc.call(RemoteRpc.java:89)
[INFO] at com.google.datastore.v1beta3.client.Datastore.runQuery(Datastore.java:108)
[INFO] at com.google.cloud.datastore.spi.DefaultDatastoreRpc.runQuery(DefaultDatastoreRpc.java:155)
[INFO] ... 56 more
Thanks for reporting this issue. I have a couple of follow up questions so that we can get to the bottom of this:
Does the project ID you set (Constants.DATASTORE_PROJECT_ID) contain any prefixes with a tilde, perhaps "s~" or "e~"? Datastore v1beta3 no longer accepts those prefixes; instead you should provide everything after the tilde as your project ID. For example, if your project ID is s~my-project-id-123, you should use just my-project-id-123. This might be the issue if you see an error message similar to:
com.google.datastore.v1beta3.client.DatastoreFactory makeClient: Not using any credentials
com.google.cloud.datastore.DatastoreException: The project s~my-project-id-123 does not exist.
If that isn't the issue, do you mind providing a stack trace and a copy of the exception text (removing confidential information as necessary). Thanks!
The service account we were using wasnt set setup with the appropriate permissions in the destination application. So we had (from advice from google) re-add the service account as a viewer here: https://console.cloud.google.com/permissions/projectpermissions
I hope this can help others in the future!

GAE : javax.security.auth.Subject.getSubject() cannot be invoked on local dev server

If I start my local google app engine dev server by using the App Engine maven plugin :
mvn appengine:devserver
and I try to launch a mapreduce job (using the appengine-mapreduce library), I get a java.security.AccessControlException: access denied ("javax.security.auth.AuthPermission" "getSubject") because the code try to invoke javax.security.auth.Subject.getSubject() method (see below for the full stack trace)
It's very weird because :
1) the javax.security.auth.Subject.getSubject() is in the white list of gae and can be invoked
2) If I start the server from intellij, I don't get this exception and the map reduce job is launched successfully
I tried with GAE 1.8.1, 1.8.2 and the latest 1.8.3 and respectively the same version for the maven google appengine plugin.
What is going wrong ?
The full stack trace :
[INFO] java.security.AccessControlException: access denied ("javax.security.auth.AuthPermission" "getSubject")
[INFO] at java.security.AccessControlContext.checkPermission(AccessControlContext.java:366)
[INFO] at java.security.AccessController.checkPermission(AccessController.java:560)
[INFO] at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
[INFO] at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:383)
[INFO] at javax.security.auth.Subject.getSubject(Subject.java:287)
[INFO] at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:467)
[INFO] at org.apache.hadoop.mapreduce.JobContext.(JobContext.java:80)
[INFO] at com.google.appengine.tools.mapreduce.AppEngineJobContext.(AppEngineJobContext.java:123)
[INFO] at com.google.appengine.tools.mapreduce.AppEngineJobContext.createContextForNewJob(AppEngineJobContext.java:132)
[INFO] at com.google.appengine.tools.mapreduce.v2.impl.handlers.Controller.handleStart(Controller.java:85)
[INFO] at com.google.appengine.tools.mapreduce.v2.impl.handlers.Status.handleStartJob(Status.java:81)
[INFO] at com.google.appengine.tools.mapreduce.v2.impl.handlers.Status.handleCommand(Status.java:182)
[INFO] at com.google.appengine.tools.mapreduce.MapReduceServlet.doPost(MapReduceServlet.java:203)
[INFO] at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
[INFO] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
[INFO] at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:263)

getting error Reason: Not a v4.0.0 POM. for project org.kohsuke.stapler:maven-stapler-plugin trying to build slideshow-plugin

When i try to build (mvn) the slide-show plugin, i get error:
(see detaied stdout below)
mvn -e
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[WARNING] POM for 'org.kohsuke.stapler:maven-stapler-plugin:pom:1.15:runtime' is invalid.
Its dependencies (if any) will NOT be available to the current build.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).
Project ID: org.kohsuke.stapler:maven-stapler-plugin
POM Location: /home/kahmed/.m2/repository/org/kohsuke/stapler/maven-stapler-plugin/1.15/maven-stapler-plugin-1.15.pom
Reason: Not a v4.0.0 POM. for project org.kohsuke.stapler:maven-stapler-plugin at /home/kahmed/.m2/repository/org/kohsuke/stapler/maven-stapler-plugin/1.15/maven-stapler-plugin-1.15.pom
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Unable to build project for plugin 'org.kohsuke.stapler:maven-stapler-plugin': Not a v4.0.0 POM. for project org.kohsuke.stapler:maven-stapler-plugin at /home/kahmed/.m2/repository/org/kohsuke/stapler/maven-stapler-plugin/1.15/maven-stapler-plugin-1.15.pom
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.loadPluginFully(DefaultLifecycleExecutor.java:1599)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.findArtifactTypeHandlersInPlugins(DefaultLifecycleExecutor.java:1468)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.findExtensions(DefaultLifecycleExecutor.java:222)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:178)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.InvalidPluginException: Unable to build project for plugin 'org.kohsuke.stapler:maven-stapler-plugin': Not a v4.0.0 POM. for project org.kohsuke.stapler:maven-stapler-plugin at /home/kahmed/.m2/repository/org/kohsuke/stapler/maven-stapler-plugin/1.15/maven-stapler-plugin-1.15.pom
at org.apache.maven.plugin.DefaultPluginManager.checkRequiredMavenVersion(DefaultPluginManager.java:293)
at org.apache.maven.plugin.DefaultPluginManager.verifyVersionedPlugin(DefaultPluginManager.java:205)
at org.apache.maven.plugin.DefaultPluginManager.verifyPlugin(DefaultPluginManager.java:184)
at org.apache.maven.plugin.DefaultPluginManager.loadPluginFully(DefaultPluginManager.java:1626)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.loadPluginFully(DefaultLifecycleExecutor.java:1582)
... 15 more
Caused by: org.apache.maven.project.InvalidProjectModelException: Not a v4.0.0 POM. for project org.kohsuke.stapler:maven-stapler-plugin at /home/kahmed/.m2/repository/org/kohsuke/stapler/maven-stapler-plugin/1.15/maven-stapler-plugin-1.15.pom
at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1599)
at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1571)
at org.apache.maven.project.DefaultMavenProjectBuilder.findModelFromRepository(DefaultMavenProjectBuilder.java:562)
at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromRepository(DefaultMavenProjectBuilder.java:251)
at org.apache.maven.plugin.DefaultPluginManager.checkRequiredMavenVersion(DefaultPluginManager.java:277)
... 19 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Mon Apr 16 00:32:26 EDT 2012
[INFO] Final Memory: 15M/182M
[INFO] ------------------------------------------------------------------------
I am getting this too (although its for the akuma artifact) and can explain why, but have not yet found a good solution. Both define a parent POM and a new repo:
<parent>
<groupId>org.kohsuke</groupId>
<artifactId>pom</artifactId>
<version>2</version>
</parent>
<repositories>
<repository>
<id>m.g.o-public</id>
<url>http://maven.glassfish.org/content/groups/public/</url>
</repository>
</repositories>
The URL for this glassfish maven repo gives a 301 to https://maven.glass... and for some reason, maven decides to download the body of that response as the POM. If you look in your ~/.m2/repository/org/kohsuke/pom/2/pom-2.pom, you should see something like:
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/0.6.39</center>
</body>
</html>
Manually looking at the glassfish repo, I do not even see the desired parent POM (at this time).
I hope this helps. If you are able to figure it out, please post back as this is as far as I have gotten so far!
I had this problem also, with a different POM from another project, and I was attempting to build with Maven 3.X. The simple solution was to install the most recent 2.X version of Maven. After that, it built fine. Being a Maven novice, It appears the URI format for REPOS differs between the 2 versions.
Simply install Maven 2.X (I used 2.2.1), and put it's "bin" directory first in your PATH env variable, and you should be good to go.

Resources