# 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.databases std: io.murano res: io.murano.resources sys: io.murano.system conf: io.murano.configuration Name: MongoDB Extends: std:Application Properties: instance: Contract: $.class(res:Instance).notNull() database: Contract: $.string() username: Contract: $.string() password: Contract: $.string() Methods: .init: Body: - $._environment: $.find(std:Environment).require() deploy: Body: - If: not $.getAttr(deployed, false) Then: # Create VM for MongoDB - $._environment.reporter.report($this, 'Creating VM for MongoDB.') - $securityGroupIngress: - ToPort: 27017 FromPort: 27017 IpProtocol: tcp External: true - ToPort: 28017 FromPort: 28017 IpProtocol: tcp External: true - $._environment.securityGroupManager.addGroupIngress($securityGroupIngress) - $.instance.deploy() # Deploy MongoDB - $._environment.reporter.report($this, 'Deploying MongoDB.') - conf:Linux.runCommand($.instance.agent, "sudo apt-get update && sudo apt-get -y install mongodb") # Configure MongoDB - $._environment.reporter.report($this, 'Configuring MongoDB.') - $file: sys:Resources.string('configureMongoDB.sh') - conf:Linux.runCommand($.instance.agent, $file) # Add firewall rules - $._environment.reporter.report($this, 'Adding firewall rules for MongoDB.') - $file: sys:Resources.string('addFirewallRules.sh') - conf:Linux.runCommand($.instance.agent, $file) # Create database on MongoDB - If: $.database != '' and $.database != null Then: - $._environment.reporter.report($this, 'Creating database on MongoDB.') - $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: - $._environment.reporter.report($this, 'Creating user for database on MongoDB.') - $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.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)