[MongoDB] Use simple software configuration

Change-Id: Ie3d6766754e8ee1300580de7a9441f47a09fc81f
Partially-Implements: bp refactor-apps-scripts
This commit is contained in:
Dmytro Dovbii 2016-04-01 14:12:38 +03:00
parent 3b51222b09
commit 69da599031
11 changed files with 22 additions and 193 deletions

View File

@ -15,6 +15,7 @@ Namespaces:
std: io.murano
res: io.murano.resources
sys: io.murano.system
conf: io.murano.configuration
Name: MongoDB
@ -53,49 +54,49 @@ Methods:
External: true
- $._environment.securityGroupManager.addGroupIngress($securityGroupIngress)
- $.instance.deploy()
- $resources: new(sys:Resources)
# Deploy MongoDB
- $template: $resources.yaml('DeployMongoDB.template')
- $._environment.reporter.report($this, 'Deploying MongoDB.')
- $.instance.agent.call($template, $resources)
- conf:Linux.runCommand($.instance.agent, "sudo apt-get update && sudo apt-get -y install mongodb")
# Configure MongoDB
- $template: $resources.yaml('ConfigureMongoDB.template')
- $._environment.reporter.report($this, 'Configuring MongoDB.')
- $.instance.agent.call($template, $resources)
- $file: sys:Resources.string('configureMongoDB.sh')
- conf:Linux.runCommand($.instance.agent, $file)
# Add firewall rules
- $template: $resources.yaml('AddFirewallRules.template')
- $._environment.reporter.report($this, 'Adding firewall rules for MongoDB.')
- $.instance.agent.call($template, $resources)
- $file: sys:Resources.string('addFirewallRules.sh')
- conf:Linux.runCommand($.instance.agent, $file)
# Create database on MongoDB
- If: $.database != '' and $.database != null
Then:
- $template: $resources.yaml('CreateMongoDBDatabase.template').bind(dict(
database => $.database
))
- $._environment.reporter.report($this, 'Creating database on MongoDB.')
- $.instance.agent.call($template, $resources)
- $replacement:
"%DATABASE%": $.database
- $file: sys:Resources.string('createMongoDBDatabase.sh').replace($replacement)
- conf:Linux.runCommand($.instance.agent, $file)
# Create user for database
- If: $.username != '' and $.username != null
Then:
- $template: $resources.yaml('CreateUserForMongoDBDatabase.template').bind(dict(
database => $.database,
username => $.username,
password => $.password
))
- $._environment.reporter.report($this, 'Creating user for database on MongoDB.')
- $.instance.agent.call($template, $resources)
- $replacements:
"%DATABASE%": $.database
"%USERNAME%": $.username
"%PASSWORD%": $.password
- $file: sys:Resources.string('createUserForMongoDBDatabase.sh').replace($replacements)
- conf:Linux.runCommand($.instance.agent, $file)
- conf:Linux.runCommand($.instance.agent, 'sudo rm -rf /tmp/murano')
# Report MongoDB information
- If: $.instance.assignFloatingIp
Then:
- $host: $.instance.floatingIpAddress
Else:
- $host: $.instance.ipAddresses[0]
- $host: $.instance.ipAddresses.first()
- $._environment.reporter.report($this, format('MongoDB is available at {0}:{1}.', $host, 27017))
- $._environment.reporter.report($this, format('MongoDB web admin endpoint is available at http://{0}:{1}.', $host, 28017))
- $.setAttr(deployed, true)

View File

@ -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: Add Firewall Rules
Parameters:
appName: $appName
Body: |
return addFirewallRules(args.appName).stdout
Scripts:
addFirewallRules:
Type: Application
Version: 1.0.0
EntryPoint: addFirewallRules.sh
Files: []
Options:
captureStdout: true
captureStderr: true

View File

@ -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: Configure MongoDB
Parameters:
appName: $appName
Body: |
return configureMongoDB(args.appName).stdout
Scripts:
configureMongoDB:
Type: Application
Version: 1.0.0
EntryPoint: configureMongoDB.sh
Files: []
Options:
captureStdout: true
captureStderr: true

View File

@ -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: Create MongoDB database
Parameters:
database: $database
Body: |
return createMongoDBDatabase(args.database).stdout
Scripts:
createMongoDBDatabase:
Type: Application
Version: 1.0.0
EntryPoint: createMongoDBDatabase.sh
Files: []
Options:
captureStdout: true
captureStderr: true

View File

@ -1,33 +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: Create user for MongoDB database
Parameters:
database: $database
username: $username
password: $password
Body: |
return createUserForMongoDBDatabase('{0} {1} {2}'.format(args.database, args.username, args.password)).stdout
Scripts:
createUserForMongoDBDatabase:
Type: Application
Version: 1.0.0
EntryPoint: createUserForMongoDBDatabase.sh
Files: []
Options:
captureStdout: true
captureStderr: true

View File

@ -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 MongoDB
Parameters:
appName: $appName
Body: |
return deployMongoDB(args.appName).stdout
Scripts:
deployMongoDB:
Type: Application
Version: 1.0.0
EntryPoint: deployMongoDB.sh
Files: []
Options:
captureStdout: true
captureStderr: true

View File

@ -15,6 +15,6 @@
# the MongoDB database will be not really created,
# so the default collection named system.users needs to be created.
sudo mongo <<EOF
use $1
use %DATABASE%
db.createCollection("system.users")
EOF

View File

@ -12,6 +12,6 @@
# under the License.
sudo mongo <<EOF
use $1
db.addUser("$2","$3")
use %DATABASE%
db.addUser("%USERNAME%","%PASSWORD%")
EOF

View File

@ -1,15 +0,0 @@
#!/bin/bash
# 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.
sudo apt-get update
sudo apt-get install -y mongodb