Posts Tagged Grails
Moving from Mor.ph to Google AppEngine
Posted by Morten in Uncategorized on August 10, 2009
Moving from Mor.ph AppSpace to Google AppEngine isn’t as easy as I hoped.
Installing AppEngine plug in
Initially moving the Application by installing the app-engine plug in is straight forward. Except that the command-line written in the plug in page for executing the initial setup is wrong. Ive corrected it now.
Windows users need to run the update command with the following command-line:
%APPENGINE_HOME%/bin/appcfg.cmd update ./target/war
Also unless the app-engine code executes correctly it will not clean up the staging directory. This causes problems if your using plug ins such as the ui-performance plug in. That is written to execute on a “clean” staging directory. If you it’s not cleaned up the plug in will try to compress the gziped version the files as well.
GORM
The problem however is that the GORM functions are not available, since the AppEngine is using a different data storage not supported by Hibernate.
There is a solution to this, install the GORM-JPA plug in. This gives you most GORM functions, but using Google AppEngines data storage.
Issues
From here I’ve run into several issues along the way. The framework for deploying to Google AppEngine crashes when running on Windows machines; if you have allot of libraries and classes in your project. Google AppEngine fails to save my entities, JSON conversion is acting up as it tries to serialize class meta data for some reason, which is were I’m currently stuck.
Light at the end of the Tunnel
Now I’d also like to mention that these issues are being ironed out. There are people looking at most of them, it’s just that Grails on Google AppEngine is relatively young so to speak. Even Java on Google AppEngine is quite new, if not Google AppEngine in it self.
Also I’d also like to mention the dashboard on Google AppEngine. It’s great!
The Dashboard on Google AppEngine gives the overview logs I got from Mor.ph, but they are presented better. They also give me some summaries on where most errors occur (which URLs crash) and which URLs are consuming the most CPU. This helps me to optimize specific URLs.
Since my application uses a REST service consumed through AJAX I can optimize parts of the application on the back end, and monitor the usage of parts of the web service.
Saving entites on Google AppEngine
Posted by Morten in Uncategorized on August 10, 2009
I ran into a problem with Grails on Google AppEngine. When I was saving my entities it tried to save the wrong type of entity. I ran out of ideas on this one and brought it up on the Grails User mailinglist.
I started to work on some reproduction code and then I went to Denmark for some vacation. When I get back however, Keith Thomas had run into the same issue and figured out that it had something to do with the constraints on the domain classes.
Sure enough removing the constraints fixed the issue with saving. Ill try to see if the problem is specific to some kinds of constraints, since I still have my reproduction project to test it in.
Grails and Google AppEngine on Windows
Posted by Morten in Uncategorized on July 27, 2009
In a previous post I described a problem where the app-engine command would fail when enhancing the domain objects for persistence.
The problem was that the command line became too long to execute on windows, when executing the enhancement task.
I’ve been working on several workarounds for this problem.
- Enhancing the classes during compilation
- Enhancing the classes manually
- Enhancing the classes programmatically
- Modifying the ant target to produce shorter command line calls
Enhancing during compilation
Make sure you have version JDK 1.6 and add the enhancer and its requirements to the compilation class-path. Produces no errors during compilation, but no enhancement is done. Fails when not all libraries included, so something is happening. I’m not sure it can find the persistence.xml file to use.
Enhancing the classes manually
I had problems where the enhancer wouldn’t find the domain objects when compiled into a package. It would say that the classes we’re not included in my class-path, even though they were.
However, working with the manual enhancement I found a wonderful option called checkonly. So you could set the enhancement tool to just check if the classes are enhanced. This would be a excellent extra option for the grails app-engine plug-in, if you could call grails app-engine diagnostic and see which files that are enhanced.
Enhancing the classes programmatically
This seems to be a viable option. I modified the app-engine plugin for grails to do the enhancement programmatically, however it failed to enhance the files with two problems. Out of the box, the persistance.xml file is not located where it should be to enhance the compiled classes. It must be copied to a location where the enhancer can find it. The other problem was that of how grails organizes its compiled files.
Modifying the ant target to produce shorter command line calls
This is what I’ve got working right now. In the Google SDK I modify the ant-macros.xml
<macrodef name="enhance_war" description="Run the ORM enhancer on an exploded war">
<attribute name="war" description="The exploded war directory containing the application"/>
<element name="args" optional="true" description="Additional arguments to the enhancer"/>
<sequential>
<enhance failonerror="true" >
<args/>
<classpath>
<pathelement path="${appengine.tools.classpath}"/>
<pathelement path="@{war}/WEB-INF/classes"/>
<fileset dir="@{war}/WEB-INF/lib" includes="*.jar"/>
</classpath>
<fileset dir="@{war}/WEB-INF/classes" includes="**/*.class"/>
</enhance>
</sequential>
</macrodef>
becomes
<macrodef name="enhance_war" description="Run the ORM enhancer on an exploded war">
<attribute name="war" description="The exploded war directory containing the application"/>
<element name="args" optional="true" description="Additional arguments to the enhancer"/>
<sequential>
<enhance failonerror="true" >
<args/>
<classpath>
<pathelement path="${appengine.tools.classpath}"/>
<pathelement path="@{war}/WEB-INF/classes"/>
<fileset dir="@{war}/WEB-INF/lib" includes="*.jar"/>
</classpath>
<fileset dir="@{war}/WEB-INF/classes/persisted" includes="**/*.class"/>
</enhance>
</sequential>
</macrodef>
Now all my domain classes that requires persistence is in a package called persisted. The macro should be modified to fit your needs or find a convention to follow in all your projects running on Google AppEngine.
Slowly learning about active plugins for Grails
Posted by Morten in Uncategorized on July 16, 2009
I was adding a comment to the GORM-JPA plugin, the other day. While doing it I clicked in the option to send me update notifications on the grails site. At first I regretted it. It sends a mail for each update.
However I havn’t deactivated it. Here’s why. All of a sudden I get an email sent to me about different plugins. It slowly shows me different plugins, that are activly updated.
The spam isn’t unmanageable, especially with GMail since it combines the emails that relate to the same page. Atleast with the current rate of page updated, I can live with the emails in exchange for getting tips about different plugins.
Grails and Google AppEngine
Posted by Morten in Uncategorized on July 14, 2009
I suggest a temporary fix to the described problems here.
I’m porting my Grails project from Mor.ph to Google AppEngine. If your using Windows certain things will not work out of the box.
To be able to use GORM you need to install the GORM-JPA plugin. Now you should in theory be able to use the GORM dynamic functions.
Alas however installing the GORM-JPA plugin will make the packaging functions for Google AppEngine fail. Google has a step in the deployment process where they enhance the byte-code to allow storage in their storage solution.
You run into this error
... java.io.IOException: CreateProcess: ...
Windows can only support command-lines with a length of 8191. The enhancement step reaches this limit when enhancing Grails applications. The Eclipse plugin has this issue mentioned here.
I’ve tried the following workarounds, with no luck:
- Running the packaging step in Powershell, hoping that powershell doesn’t have this limit.
- Running the packaging step in Cygwin, hoping that the linux emulation would work around the process execution limit.
Currently I’m working on rewriting the ant macro for the enhancement step in Google’s SDK. There are some improvements that can be done.
This is what the macro looks like in ant-macros.xml
<!--
A macrodef for ORM enhancement for a war. Use like:
<enhance_war war="${war}"/>
-->
<macrodef name="enhance_war" description="Run the ORM enhancer on an exploded war">
<attribute name="war" description="The exploded war directory containing the application"/>
<element name="args" optional="true" description="Additional arguments to the enhancer"/>
<sequential>
<enhance failonerror="true">
<args/>
<classpath>
<pathelement path="${appengine.tools.classpath}"/>
<pathelement path="@{war}/WEB-INF/classes"/>
<fileset dir="@{war}/WEB-INF/lib" includes="*.jar"/>
</classpath>
<fileset dir="@{war}/WEB-INF/classes" includes="**/*.class"/>
</enhance>
</sequential>
</macrodef>
Notice that the class path argument contains a fileset of the lib directories. This can be changed to just include the path element, since Java will resolve the .jar files.
The second part of the problem is the argument fileset list
<fileset dir="@{war}/WEB-INF/classes" includes="**/*.class"/>
Grails creates a lot of class files, so just fixing the class path will not fix the command line problem. Ive been working on excluding files that do not need enhancement, such as the app-engine plugin classes themselves. Another idea is to move the domain into its own package, thus its own directory. This however leads to issues with naming, apparently the compiled groovy classes are not named according to how Datanucleus would like it.
I tried using the Datanucleus tool directly without success.
The latest Idea I have is to somehow wrap into the compilation step of the grails war target and do the enhancement there, and turn the enhancement step off when using just the app-engine plugin.
Upgrading from Grails 1.1 to Grails 1.1.1
Posted by Morten in Uncategorized on July 12, 2009
Simple enough I downloaded the new version of Grails, updated the environment variables and its good to go in the command line.
I placed the grails-1.1.1 directory next to the grails-1.1 directory, that way I can revert to 1.1 if I manage to screw things up too much.
Next I needed to point IntelliJ to the new version of grails. I found this to be a bit trickier. I’m not used to navigation this configuration, but eventually I found it. Right clicking on the project root in the project folders there is an option called Module Settings.
Press new and point it to the grails-1.1.1 directory.
Right my first test compilation failed. Apparently the ui-performance plugin was acting up with the 1.1.1 version of grails.
It turns out that there is a known issue with the ui-performance1.1 versiona and version 1.1.1 of grails. The error you when you create your war file is the following:
Error executing script War: groovy.lang.MissingMethodException: No signature of method: com.studentsonly.grails.plugins.uiperformance.ResourceVersionHelper.version() is applicable for argument types: (java.io.File, java.lang.String)
now the issue is reported here. There is already a fix for it, all you have to do is upgrade to version 1.1.1 of the ui-performance plugin.
grails install-plugin ui-performance
Now I got it to work after upgrading the plugin and running the clean command.
grails clean
Now everything is working accordingly.
Upgrade complete.
Removing the morph-deploy plugin
Posted by Morten in Uncategorized on July 12, 2009
Since I’m moving the project to Google AppEngine I no longer require the morph-deploy plugin.
I removed the .jar and properties files from the directory containing the mor.ph keys to deploy the application.
I removed the plugin using
grails uninstall-plugin morph-deploy
Next remove the mor.ph specific datasource from the config file.
production {
dataSource {
driverClassName = 'com.mysql.jdbc.Driver'
dbCreate = "update"
jndiName = "java:comp/env/jdbc/morph-ds"
dialect = 'org.hibernate.dialect.MySQLDialect'
}
}
Remember to run a clean command.
grails clean
And your done!
Moving from Morph to Google AppEngine
Posted by Morten in Uncategorized on July 12, 2009
Since Mor.ph is terminating their free subscription I’ll be moving my application from Mor.ph to Google AppEngine. I like Mor.ph but the project is not at a stage of development where I wish to pay for it to be hosted somewhere.
To do this I need to:
- upgrade grails to 1.1.1
- remove the morph-deploy plugin
- install the appengine plugin
I’ll make some posts for each step
IETester
Posted by Morten in Uncategorized on May 27, 2009
I found a new tool for testing web-applications in IE today. It’s called IETester, and it allows me to test IE versions 5.5 to 8 in the same application. Which is great, since my Vista machine only runs 8 normally.
I use it to verify my Grails application in IE6. Tonight I managed to create a unit test capturing the issue I was experiencing in IE6, using IETester and QUnit, so now I know where to take off tomorrow.
However it isn’t that stable, I’m running it on a 64-bit machine which might add some extra strain on the application. But for me it needed to be re-started or crashed a few times while I was isolating the bug I am working on.
Important Announcement on Morph AppSpace
Posted by Morten in Uncategorized on May 27, 2009
I just received an email with the this subject. It basically states that Morph will be shutting down AppSpace to focus on their new configurable service model, Morph AppCloud. If this is true then developer subscriptions will be shutdown as of the 6th of June.