From e022463cf54b75d09e08d5bb8b95b593fb3d850c Mon Sep 17 00:00:00 2001 From: Dmytro Dovbii Date: Fri, 1 Apr 2016 14:17:17 +0300 Subject: [PATCH] [Cassandra] Use simple software configuration Change-Id: Ia838a0ba8d72f9446439bc1992baf807d5917570 Partially-Implements: bp refactor-apps-scripts --- .../package/Classes/CassandraCluster.yaml | 2 +- Cassandra/package/Classes/CassandraNode.yaml | 27 +++++++-------- .../Resources/DeployCassandra.template | 31 ----------------- .../Resources/RestartCassandra.template | 32 ----------------- .../Resources/UpdateCassandraYaml.template | 34 ------------------- .../{scripts => }/deployCassandra.sh | 0 .../{scripts => }/restartCassandra.sh | 0 .../{scripts => }/updateCassandraYaml.sh | 10 ++---- 8 files changed, 17 insertions(+), 119 deletions(-) delete mode 100644 Cassandra/package/Resources/DeployCassandra.template delete mode 100644 Cassandra/package/Resources/RestartCassandra.template delete mode 100644 Cassandra/package/Resources/UpdateCassandraYaml.template rename Cassandra/package/Resources/{scripts => }/deployCassandra.sh (100%) rename Cassandra/package/Resources/{scripts => }/restartCassandra.sh (100%) rename Cassandra/package/Resources/{scripts => }/updateCassandraYaml.sh (76%) diff --git a/Cassandra/package/Classes/CassandraCluster.yaml b/Cassandra/package/Classes/CassandraCluster.yaml index 5a75ddd1..651e717a 100644 --- a/Cassandra/package/Classes/CassandraCluster.yaml +++ b/Cassandra/package/Classes/CassandraCluster.yaml @@ -48,7 +48,7 @@ Methods: - $.regularNodes.pselect($.spawnInstance()) # Collect internal IPs of seed nodes - - $seedNodesAsString: join(',', $.seedNodes.select($.getInternalIp())) + - $seedNodesAsString: $.seedNodes.select($.getInternalIp()).join(',') # Deploy Cassandra with default conf - Parallel: diff --git a/Cassandra/package/Classes/CassandraNode.yaml b/Cassandra/package/Classes/CassandraNode.yaml index 67cf6d3a..e0d4dc16 100644 --- a/Cassandra/package/Classes/CassandraNode.yaml +++ b/Cassandra/package/Classes/CassandraNode.yaml @@ -15,7 +15,7 @@ Namespaces: std: io.murano res: io.murano.resources sys: io.murano.system - + conf: io.murano.configuration Name: CassandraNode @@ -29,7 +29,6 @@ Methods: .init: Body: - $._environment: $.find(std:Environment).require() - - $.resources: new(sys:Resources) updateConfiguration: Arguments: @@ -41,14 +40,16 @@ Methods: 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 - )) + + - $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) - - $.instance.agent.call($template, $.resources) configureSecurityGroups: @@ -97,8 +98,8 @@ Methods: 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) + - $file: sys:Resources.string('deployCassandra.sh') + - conf:Linux.runCommand($.instance.agent, $file) - $.setAttr(deployed, true) getInternalIp: @@ -113,7 +114,5 @@ Methods: 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) + - $command: format('sleep {0}; sudo service cassandra restart', $delay) + - conf:Linux.runCommand($.instance.agent, $command) \ No newline at end of file diff --git a/Cassandra/package/Resources/DeployCassandra.template b/Cassandra/package/Resources/DeployCassandra.template deleted file mode 100644 index 62fb94bf..00000000 --- a/Cassandra/package/Resources/DeployCassandra.template +++ /dev/null @@ -1,31 +0,0 @@ -# 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. - -FormatVersion: 2.0.0 -Version: 1.0.0 -Name: Deploy Cassandra - -Parameters: - appName: $appName - -Body: | - return deploy(args.appName).stdout - -Scripts: - deploy: - Type: Application - Version: 1.0.0 - EntryPoint: deployCassandra.sh - Files: [] - Options: - captureStdout: false - captureStderr: true diff --git a/Cassandra/package/Resources/RestartCassandra.template b/Cassandra/package/Resources/RestartCassandra.template deleted file mode 100644 index c3768c84..00000000 --- a/Cassandra/package/Resources/RestartCassandra.template +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - -FormatVersion: 2.0.0 -Version: 1.0.0 -Name: Restart Cassandra - -Parameters: - delay: $delay - -Body: | - restart('{0}'.format(args.delay)) - -Scripts: - restart: - Type: Application - Version: 1.0.0 - EntryPoint: restartCassandra.sh - Files: [] - Options: - captureStdout: true - captureStderr: false - verifyExitcode: false diff --git a/Cassandra/package/Resources/UpdateCassandraYaml.template b/Cassandra/package/Resources/UpdateCassandraYaml.template deleted file mode 100644 index cb9f24d7..00000000 --- a/Cassandra/package/Resources/UpdateCassandraYaml.template +++ /dev/null @@ -1,34 +0,0 @@ -# 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. - -FormatVersion: 2.0.0 -Version: 1.0.0 -Name: Update Cassandra Yaml - -Parameters: - clusterName: $clusterName - seedNodes: $seedNodes - listenAddress: $listenAddress - -Body: | - configure('{0} {1} {2}'.format(args.clusterName, args.seedNodes, args.listenAddress)) - -Scripts: - configure: - Type: Application - Version: 1.0.0 - EntryPoint: updateCassandraYaml.sh - Files: [] - Options: - captureStdout: true - captureStderr: true - diff --git a/Cassandra/package/Resources/scripts/deployCassandra.sh b/Cassandra/package/Resources/deployCassandra.sh similarity index 100% rename from Cassandra/package/Resources/scripts/deployCassandra.sh rename to Cassandra/package/Resources/deployCassandra.sh diff --git a/Cassandra/package/Resources/scripts/restartCassandra.sh b/Cassandra/package/Resources/restartCassandra.sh similarity index 100% rename from Cassandra/package/Resources/scripts/restartCassandra.sh rename to Cassandra/package/Resources/restartCassandra.sh diff --git a/Cassandra/package/Resources/scripts/updateCassandraYaml.sh b/Cassandra/package/Resources/updateCassandraYaml.sh similarity index 76% rename from Cassandra/package/Resources/scripts/updateCassandraYaml.sh rename to Cassandra/package/Resources/updateCassandraYaml.sh index 9817f5b7..88ab35f2 100644 --- a/Cassandra/package/Resources/scripts/updateCassandraYaml.sh +++ b/Cassandra/package/Resources/updateCassandraYaml.sh @@ -11,21 +11,17 @@ # License for the specific language governing permissions and limitations # under the License. -CLUSTER_NAME="$1" -SEED_NODES="$2" -LISTEN_ADDRESS="$3" - ## Configure Cassandra to use seed nodes # Set cluster name -sed -e "s/cluster_name:.*/cluster_name: \'$CLUSTER_NAME\'/g" -i /etc/cassandra/cassandra.yaml +sed -e "s/cluster_name:.*/cluster_name: \'%CLUSTER_NAME%\'/g" -i /etc/cassandra/cassandra.yaml # Seed provider class name sed -e "s/- class_name:.*/- class_name: org.apache.cassandra.locator.SimpleSeedProvider/g" -i /etc/cassandra/cassandra.yaml # Set seed nodes - nodes used to bootstrap other nodes sed -e "s/seeds:.*/seeds: \"$SEED_NODES\"/g" -i /etc/cassandra/cassandra.yaml # Set listen address and endpoint snitch class -sed -e "s/listen_address:.*/listen_address: $LISTEN_ADDRESS/g" -i /etc/cassandra/cassandra.yaml +sed -e "s/listen_address:.*/listen_address: %LISTEN_ADDRESS%/g" -i /etc/cassandra/cassandra.yaml sed -e "s/endpoint_snitch:.*/endpoint_snitch: GossipingPropertyFileSnitch/g" -i /etc/cassandra/cassandra.yaml # Set RPC address sed -e "s/^rpc_address:.*/rpc_address: 0.0.0.0/g" -i /etc/cassandra/cassandra.yaml -sed -e "s/#\s*broadcast_rpc_address:.*/broadcast_rpc_address: $LISTEN_ADDRESS/g" -i /etc/cassandra/cassandra.yaml +sed -e "s/#\s*broadcast_rpc_address:.*/broadcast_rpc_address: %LISTEN_ADDRESS%/g" -i /etc/cassandra/cassandra.yaml