Cassandra inserts and updates should always be modeled as upserts when possible. Using the query builder in the Java native driver there isn’t a direct upsert called out, but we can do updates instead of inserts for all cases. The update acts as an upsert and it reduces the number of queries you will need to build.
1 2 3 4
Above you can see how we model our “upsert”. If a value isn’t found for the given where clause it will insert it.
You must use all parts of a Primary Key for an updates where cluase given a CQL Table with a compound key:
1 2 3 4 5 6
We can not do the following query:
1 2 3
You will get an
1 2 3 4
But the following will upsert:
1 2 3 4
If you are working on a Groovy script with @Grab, you will sometimes get download failures for dependencies. Such as the following:
This issues may have nothing to do with the actual dependency but an issue in your local m2 cache. The quick answer is to just delete
~/.m2/repository. But doing this will force you to re-download dependencies.
To only delete the cache for items giving you an issue you just need to delete the correct directories in both m2 and grapes cache. So for our Guava example you would do the following:
After that you should be able to run the groovy script normally.
New Relic with Grails by default will trace most web transactions through the controller but will not trace down into services. While most true work of a request belongs in services or libraries the default tracing leaves something to be desired.
This is easily fixed by adding New Relic annotations to services and libraries.
1 2 3 4
1 2 3 4 5 6 7 8
At this point your code is ready to give more detailed transactions, but the agent on the server must also be configured to accept custom tracing. The config option for this is not available from the web so you must update the
newrelic.yml file. Set
Now you will get any custom tracing added to your application as well as custom tracing from libraries.
If you are running grails 2.3.1 and see the following sequence pop up before you get some odd test failures.
1 2 3 4 5 6 7
Start using package in between and the problem will go away.
1 2 3 4 5 6 7 8 9 10 11 12 13
Using the JMS 1.2 plugin with Grails 2.3.0.RC1 was producing a number of odd results. Mostly with missing JMS files it turns out that the new spring version didn’t have the needed spring jms included. Just add the following to BuildConfig.groovy
1 2 3 4
Using the Grails Spring Security Core Plugin I found the need to customize the UserDetailsService and use a Grails service. (Part of the roles logic depended on an external API that we already had a service for.) This was easy to accomplish by subclassing the UserDetailsService class I wanted as a base in my case it was actually the SpringSamlUserDetailsService class because I was using the SAML plugin but normally you would subclass GormUserDetailsService. A great starting example is given in the documentation here.
The difference in my case was the need to use the Grails service, I went with providing the service in the resources.groovy file. Below is the example file of what I used.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Snip from CustomUserDetailsService.groovy
1 2 3 4
Getting, SAML message intended destination endpoint did not match recipient endpoint, errors mean the server itself dosen’t match the urls being given in the SAML messages.
We are using the Grails Spring Security SAML Plugin on a Tomcat server. In my case this was happening because we were doing SSL offloading on the load balancer. So if you look at the logs there should be an error log with the intended destination and the recipient endpoint.
In my case the first error was only different by http vs https. The fix for that was simply to apply the scheme attribute to that connector in tomcat. At which point everything was matching except that the port was now being added as 80 in my endpoint and that wasn’t in the intended endpoint. The fix for this was just to add the proxyPort to the connector as well.
So to fully support the OpenSAML on tomcat with SSL offloading I configured the connector as seen below. Take note of the scheme and proxyPort being set.
1 2 3 4 5 6
While working with Grails and the Spring Security plugin, the current spring security filter chain is available in the springSecurityFilterChain bean. It is very easy with that to show what the current chain looks like so you can work through filter chain issues. I used the following code in the Grails Console plugin to get the bean:
Also if you want to poke around the other beans available this is a great post to check out: Spring Beans from the Grails Console .
I’ve been working with the DataStax Enterprise 2.01 install for a bit now and it was working great until one day I was no longer able to get any queries to work using the cqlsh I was just getting the error that one or more nodes was unavailable. I tried restarting and still nothing would work I got a few errors in the logs (shown below).
I was able to quickly fix the error by removing my data directory and starting fresh as this is just my development environment that works great for me. You can find your data directory in the cassandra.yaml file ($DSE_HOME/resources/cassandra/conf/cassandra.yaml), look for the data_file_directories entry. Mine was set to /var/lib/cassandra/data so I just ran the following and started cassandra fresh and everything is back to working order.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
The grails release plugin is great for publishing plugins to grails central but it will also publish a plugin to a maven repo. You simple need to configure the new maven repo inside build config. But if you want to release snapshots to an internal maven but not have that config checked in publicly that is a bit more tricky. With a quick bit of code added to BuildConfig.groovy we can have it pull in the config from a file we can choose to not checkin. Now with our public code we don’t need to expose our internal login info. See the file changes below for an example.
Add this to BuildConfig.groovy:
1 2 3 4 5 6 7 8 9 10 11
Then you can create a file called mavenInfo.groovy:
1 2 3
Grab the gist.