murano-apps/OraclePDBConnector/package/Classes/OraclePDB.murano

146 lines
4.4 KiB
Plaintext

# Copyright 2015 Oracle and/or its affiliates. All rights reserved.
#
# 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.oracle.db.muranoPdb
std: io.murano
sys: io.murano.system
Name: OraclePDB
Extends: 'com.example.databases.SqlDatabase'
Properties:
name:
Contract: $.string().notNull()
username:
Contract: $.string()
Usage: Out
database:
Contract: $.string()
Usage: Out
password:
Contract: $.string()
Usage: Out
agent_queue:
Contract: $.string().notNull()
Default: 'static-agent-002-tasks'
Usage: In
agent:
Contract: $.class(sys:StaticAgent)
Usage: InOut
listener:
Contract: $.string()
Default: '1.1.1.1'
Usage: InOut
createDB:
Contract: $.bool()
Default: false
Usage: InOut
Methods:
initialize:
Body:
- $._environment: $.find(std:Environment).require()
deploy:
Body:
- If: not $.getAttr(deployed, false)
Then:
- $._environment.reporter.report($this, 'Oracle PDB')
- $.createAgent()
- $.getListener()
- $._environment.reporter.report($this, 'Listener {0}'.format($.listener))
- If: $.createDB
Then:
- $.createDatabase(database => $.database)
- $.createUser(username => $.username, password => $.password, database => $.database)
- $connection_string: $.getConnectionString(username => $.username, password => $.password)
- $._environment.reporter.report($this, 'Connection String {0}'.format($connection_string))
- $.setAttr(deployed, true)
createAgent:
Body:
- $queue: $._environment.agentListener.queueName()
- $.agent: new(sys:StaticAgent, env => $._environment,
input_queue => $.agent_queue,
response_queue => $queue )
createDatabase:
Arguments:
database:
Contract: $.string().notNull()
Body:
- $._environment.reporter.report($this, 'Creating a DB')
- $resources: new(sys:Resources)
- $command: $resources.yaml('CreatePDB.template').bind(dict(
database => $database
))
- $.agent.call($command, $resources)
getListener:
Body:
- $resources: new(sys:Resources)
- $command: $resources.yaml('GetListener.template')
- $.listener: $.agent.call($command, $resources)
createUser:
Arguments:
username:
Contract: $.string().notNull()
password:
Contract: $.string().notNull()
database:
Contract: $.string().notNull()
Body:
- $.user: $username
- $.password: $password
- $resources: new(sys:Resources)
- $command: $resources.yaml('CreateUser.template').bind(dict(
database => $database,
username => $username,
password => $password
))
- $.agent.call($command, $resources)
assignUser:
Arguments:
username:
Contract: $.string().notNull()
database:
Contract: $.string().notNull()
Body:
- $._environment.reporter.report($this, 'Assigning a user to the DB')
- $resources: new(sys:Resources)
- $command: $resources.yaml('AssignUser.template').bind(dict(
time => 'now'
))
- $.agent.call($command, $resources)
getConnectionString:
Arguments:
username:
Contract: $.string().notNull()
password:
Contract: $.string().notNull()
Body:
- $._environment.reporter.report($this, 'Generating a connection string for the PDB')
- Return: format('{0}/{1}@//{2}/{3}',$.username, $.password, $.listener, $.database)
demo:
Usage: Action
Body:
- $.createDatabase(database => 'demo')
- $.createUser(database => 'demo',
username => 'test',
password => 'DemoTest01')