murano-apps/Cassandra/package/Classes/CassandraNode.yaml

120 lines
3.7 KiB
YAML

# 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:
=: io.murano.apps.apache
std: io.murano
res: io.murano.resources
sys: io.murano.system
Name: CassandraNode
Extends: std:Application
Properties:
instance:
Contract: $.class(res:Instance).notNull()
Methods:
.init:
Body:
- $._environment: $.find(std:Environment).require()
- $.resources: new(sys:Resources)
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]
- $template: $.resources.yaml('UpdateCassandraYaml.template').bind(dict(
clusterName => $clusterName,
seedNodes => $seedNodes,
listenAddress => $listenAddress
))
- $msg: format('Updating Cassandra configuration at node "{0}"', $listenAddress)
- $._environment.reporter.report($this, $msg)
- $.instance.agent.call($template, $.resources)
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))
- $template: $.resources.yaml('DeployCassandra.template')
- $.instance.agent.call($template, $.resources)
- $.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)
- $template: $.resources.yaml('RestartCassandra.template').bind(dict(
delay => $delay
))
- $.instance.agent.call($template, $.resources)