# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. Namespaces: =: com.example.apache std: io.murano res: io.murano.resources sys: io.murano.system conf: io.murano.configuration Name: CassandraNode Extends: std:Application Properties: instance: Contract: $.class(res:Instance).notNull() Methods: .init: Body: - $._environment: $.find(std:Environment).require() updateConfiguration: Arguments: - clusterName: Contract: $.string().notNull() - seedNodes: Contract: $.string().notNull() Body: # Listen address is internal (so it gets resolved by node itself correctly) - $listenAddress: $.instance.ipAddresses[0] - $replacements: "%LISTEN_ADDRESS%": $listenAddress "%CLUSTER_NAME%": $clusterName "%SEED_NODES%": $seedNodes - $file: sys:Resources.string('updateCassandraYaml.sh').replace($replacements) - conf:Linux.runCommand($.instance.agent, $file) - $msg: format('Updating Cassandra configuration at node "{0}"', $listenAddress) - $._environment.reporter.report($this, $msg) configureSecurityGroups: Body: # Based on Cassandra 2.1 defaults - $securityGroupIngress: # Cassandra JMX monitoring port - ToPort: 7199 FromPort: 7199 IpProtocol: tcp External: true # Cassandra inter-node cluster communication - ToPort: 7000 FromPort: 7000 IpProtocol: tcp External: true # Cassandra SSL inter-node cluster communication - ToPort: 7001 FromPort: 7001 IpProtocol: tcp External: true # Cassandra client port (Thrift) - ToPort: 9160 FromPort: 9160 IpProtocol: tcp External: true # Cassandra client port - ToPort: 9042 FromPort: 9042 IpProtocol: tcp External: true - $._environment.securityGroupManager.addGroupIngress($securityGroupIngress) spawnInstance: Body: - $msg: format('Creating a VM for Cassandra node "{0}"', $.instance.name) - $._environment.reporter.report($this, $msg) - $.configureSecurityGroups() - $.instance.deploy() - $address: $.instance.ipAddresses[0] - $._environment.reporter.report($this, 'Instance "{0}" is created'.format($address)) deployInstance: Body: - If: not $.getAttr(deployed, false) Then: - $address: $.instance.ipAddresses[0] - $._environment.reporter.report($this, 'Deploying Cassandra node "{0}"'.format($address)) - $file: sys:Resources.string('deployCassandra.sh') - conf:Linux.runCommand($.instance.agent, $file) - $.setAttr(deployed, true) getInternalIp: Body: - Return: $.instance.ipAddresses[0] ## Restarts an existing Cassandra after given delay (in seconds) restartCassandra: Arguments: - delay: Contract: $.int().notNull() Body: - $msg: format('Restarting Cassandra node "{0}"', $.instance.name) - $._environment.reporter.report($this, $msg) - $command: format('sleep {0}; sudo service cassandra restart', $delay) - conf:Linux.runCommand($.instance.agent, $command)