1
1
package v2
2
2
3
+ import com.datastax.driver.core.Cluster
3
4
import com.google.api.services.compute.Compute
4
5
import com.google.api.services.compute.model.*
5
6
import groovy.sql.Sql
@@ -24,6 +25,7 @@ class BrokerController {
24
25
final String mariaId = ' 45e953d3-1598-4b54-95c9-16427e5e7059'
25
26
final String pgId = ' f80271a3-0c58-4c23-a550-8828fcce63ad'
26
27
final String mongoId = ' 1050698f-be8e-43ac-a3f2-a74eaec714de'
28
+ final String cassId = ' f6cc9ce6-ae3a-43cd-9ae0-ca45280bcc6e'
27
29
final String oraId = ' 1816c23f-6506-4704-959f-ee747ae6a06c'
28
30
final String rmqId = ' 302e9f58-106b-40c0-8bad-8a593bcc2243'
29
31
final def plans = [
@@ -32,6 +34,7 @@ class BrokerController {
32
34
(mariaId): [ service : ' maria' , ports : [ [ port : 3306 , kind : ' api' ] ] ],
33
35
(pgId): [ service : ' postgresql' , ports : [ [ port : 5432 , kind : ' api' ] ] ],
34
36
(mongoId): [ service : ' mongodb' , ports : [ [ port : 27017 , kind : ' api' ] ] ],
37
+ (cassId): [ service : ' cassandra' , ports : [ [ port : 9042 , kind : ' api' ] ] ],
35
38
(oraId): [ service : ' oracle' , ports : [ [ port : 1521 , kind : ' api' ], // [ port: 22, kind: 'ssh' ],
36
39
[ port : 8080 , kind : ' management' , dashboard : ' http://$ip:$port/apex' ] ] ],
37
40
(rmqId): [ service : ' rabbitmq' , ports : [ [ port : 5672 , kind : ' api' ],
@@ -607,6 +610,7 @@ class BrokerController {
607
610
[ id : mariaId, name : ' maria' , description : ' MariaDB database' ,metadata : [ displayName : ' MariaDB Galera Cluster' , bullets : [ ' MariaDB 10.0.12' ,' 2 nodes / 1GB memory pool each' , ' 10GB XtraDB storage' ], costs : [ [ amount : [ usd : 20 ], unit : ' month' ] ] ] ],
608
611
[ id : pgId, name : ' postgresql' , description : ' PostgreSQL database' , metadata : [ displayName : ' PostgreSQL' , bullets : [ ' PostgreSQL 9.3' , ' 1GB memory pool' , ' 10GB storage' ], costs : [ [ amount : [ usd : 0 ], unit : ' month' ] ] ] ],
609
612
[ id : mongoId, name : ' mongodb' , description : ' MongoDB NoSQL database' , metadata : [ displayName : ' MongoDB' , bullets : [ ' MongoDB 2.6' , ' 1GB memory pool' , ' 10GB storage' ], costs : [ [ amount : [ usd : 0.02 ], unit : ' hour' ] ] ] ],
613
+ [ id : cassId, name : ' cassandra' , description : ' Cassandra NoSQL database' , metadata : [ displayName : ' Cassandra' , bullets : [ ' Cassandra 2.1' , ' 2GB memory pool' , ' 10GB storage' ], costs : [ [ amount : [ usd : 0 ], unit : ' month' ] ] ] ],
610
614
[ id : oraId, name : ' oracle' , description : ' Oracle database' , metadata : [ displayName : ' Oracle' , bullets : [ ' Oracle 11gR2 XE' ,' 1GB memory pool' , ' 10GB storage' ], costs : [ [ amount : [ usd : 0 ], unit : ' month' ] ] ] ],
611
615
[ id : rmqId, name : ' rabbitmq' , description : ' RabbitMQ messaging broker' , metadata : [ displayName : ' RabbitMQ' , bullets : [ ' RabbitMQ 3.3' , ' 1GB persistence' ], costs : [ [ amount : [ usd : 0 ], unit : ' month' ] ] ] ]
612
616
]
@@ -718,6 +722,7 @@ class BrokerController {
718
722
case ' postgresql' : args = ' postgres' ; break // TODO introduce image that has password setup for postgres admin user
719
723
case ' mongodb' : args = " -e \" MONGOD_OPTIONS=--nojournal --smallfiles --noprealloc --auth\" -e MONGO_ROOT_PASSWORD=$pass arkadi/mongodb" ; break
720
724
// case 'mongodb': args = 'mongo mongod --nojournal --smallfiles --noprealloc'; break -- _/mongo image has no admin password
725
+ case ' cassandra' : args = " arkadi/cassandra" ; break // based on poklet/cassandra but with PasswordAuthenticator and CassandraAuthorizer
721
726
case ' oracle' : args = " alexeiled/docker-oracle-xe-11g" ; break
722
727
case ' rabbitmq' : args = " -e RABBITMQ_PASS=$pass tutum/rabbitmq" ; break
723
728
default :
@@ -881,6 +886,19 @@ class BrokerController {
881
886
creds = [ uri : " mongodb://$ip :$port /$db " , host : ip, port : port, username : user, password : pass ]
882
887
break
883
888
889
+ case ' cassandra' :
890
+ def (cluster, cass) = cassandra(ip, port, adminPass)
891
+ try {
892
+ cass. execute(" create keyspace $db with replication = {'class': 'SimpleStrategy', 'replication_factor': 1}" )
893
+ cass. execute(" create user $user with password '$pass '" )
894
+ cass. execute(" grant all on keyspace $db to $user " )
895
+ } finally {
896
+ cass. closeAsync()
897
+ cluster. closeAsync()
898
+ }
899
+ creds = [ uri : " cassandra://$ip :$port /$db " , host : ip, port : port, username : user, password : pass ]
900
+ break
901
+
884
902
case ' oracle' :
885
903
db = user
886
904
pass = pass. substring(0 , 16 )
@@ -912,6 +930,25 @@ class BrokerController {
912
930
}
913
931
}
914
932
933
+ def cassandra (String ip , int port , String adminPass ) {
934
+ // http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Cluster.Builder.html#addContactPointsWithPorts(java.util.Collection)
935
+ // ... if the Cassandra nodes are behind a router and are not accessed directly. Note that if you are in this situation (Cassandra nodes
936
+ // are behind a router, not directly accessible), you almost surely want to provide a specific AddressTranslater (through
937
+ // withAddressTranslater(com.datastax.driver.core.policies.AddressTranslater)) to translate actual Cassandra node addresses to the
938
+ // addresses the driver should use, otherwise the driver will not be able to auto-detect new nodes (and will generally not function optimally).
939
+ def builder = Cluster . builder(). addContactPointsWithPorts([new java.net.InetSocketAddress (ip, port)])
940
+ def cluster = builder. withCredentials(' cassandra' , adminPass). build()
941
+ try {
942
+ [cluster, cluster. connect()]
943
+ } catch (e) {
944
+ log. info(' Cannot authenticate as `cassandra` user, assuming default password must be changed: ' + e. message)
945
+ cluster = builder. withCredentials(' cassandra' , ' cassandra' ). build()
946
+ def cass = cluster. connect()
947
+ cass. execute(" alter user cassandra with password '$adminPass '" )
948
+ [cluster, cass]
949
+ }
950
+ }
951
+
915
952
def unbind () {
916
953
if (check(request, params)) return
917
954
// TODO erase credentials
0 commit comments