131 lines
4.4 KiB
YAML
131 lines
4.4 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:
|
|
=: com.mirantis.clearwater.components.base
|
|
std: io.murano
|
|
res: io.murano.resources
|
|
sys: io.murano.system
|
|
conf: io.murano.configuration
|
|
apps: io.murano.applications
|
|
cw: com.mirantis.clearwater
|
|
|
|
|
|
|
|
Name: ClearwaterComponentBase
|
|
|
|
Extends:
|
|
- apps:SoftwareComponent
|
|
- apps:OpenStackSecurityConfigurable
|
|
|
|
Properties:
|
|
clusterSize:
|
|
Contract: $.int().notNull()
|
|
Default: 1
|
|
|
|
cluster:
|
|
Contract: $.class(apps:ServerReplicationGroup)
|
|
Usage: Out
|
|
|
|
serverProvider:
|
|
Contract: $.class(apps:TemplateServerProvider)
|
|
Usage: Out
|
|
|
|
Methods:
|
|
_createReplacements:
|
|
Arguments:
|
|
- instance:
|
|
Contract: $.class(res:LinuxInstance).notNull()
|
|
- index:
|
|
Contract: $.int().notNull()
|
|
Body:
|
|
- $instancePrivateIp: $instance.joinedNetworks.first().ipList.where($ != $instance.floatingIpAddress).first()
|
|
- Return:
|
|
"%INDEX%": $index
|
|
"%PUBLIC_IP%": $instance.floatingIpAddress
|
|
"%PRIVATE_IP%": $instancePrivateIp
|
|
"%PRIVATE_NETWORK_CIDR%": $instance.joinedNetworks.first().network.describe().cidr
|
|
"%PRIVATE_NETWORK_GATEWAY%": $instance.joinedNetworks.first().network.describe().gateway
|
|
"%ZONE%": $.parent.dnsApp.zoneName
|
|
"%DNSSEC_KEY%": $.parent.dnsApp.dnsSecKey
|
|
"%DNS_PRIVATE_IP%": $.parent.dnsApp.instance.joinedNetworks.first().ipList.where($ = $instance.floatingIpAddress).first()
|
|
"%ETCD_IP%": $.parent.etcdClusterIp or $instancePrivateIp
|
|
|
|
getDeployScriptName:
|
|
Body:
|
|
- Return: $this.componentName + '/deploy.sh'
|
|
|
|
getConfigureScriptName:
|
|
Body:
|
|
- Return: $this.componentName + '/configure.sh'
|
|
|
|
.init:
|
|
Body:
|
|
- $._environment: $.find(std:Environment).require()
|
|
- $.componentName: typeinfo($).name.split(".").last()
|
|
- $.parent: $.find(cw:Clearwater).require()
|
|
- $.serverProvider: $.serverProvider or new(apps:TemplateServerProvider, $this,
|
|
template => $.parent.instanceTemplate,
|
|
serverNamePattern => $this.componentName + "-{}")
|
|
- $.cluster: $.cluster or new(apps:ServerReplicationGroup, $this,
|
|
provider => $this.serverProvider, minItems => 1, numItems => $this.clusterSize)
|
|
|
|
onInstallServer:
|
|
Arguments:
|
|
- instance:
|
|
Contract: $.class(res:LinuxInstance).notNull()
|
|
- serverGroup:
|
|
Contract: $.class(apps:ServerReplicationGroup).notNull()
|
|
Body:
|
|
- $index: $serverGroup.getServers().indexWhere($.name = $instance.name)
|
|
- $instancePrivateIp: $instance.joinedNetworks.first().ipList.where($ != $instance.floatingIpAddress).first()
|
|
- If: not $.parent.etcdClusterIp
|
|
Then:
|
|
- $this.parent.setEtcdClusterIp($instancePrivateIp)
|
|
- $replacements: $._createReplacements($instance, $index)
|
|
- $file: sys:Resources.string($.getDeployScriptName()).replace($replacements)
|
|
- conf:Linux.runCommand($instance.agent, $file)
|
|
|
|
|
|
|
|
onConfigureServer:
|
|
Arguments:
|
|
- instance:
|
|
Contract: $.class(res:LinuxInstance).notNull()
|
|
- serverGroup:
|
|
Contract: $.class(apps:ServerReplicationGroup).notNull()
|
|
Body:
|
|
- $index: $serverGroup.getServers().indexWhere($.name = $instance.name)
|
|
- $instancePrivateIp: $instance.joinedNetworks.first().ipList.where($ != $instance.floatingIpAddress).first()
|
|
- $replacements: $._createReplacements($instance, $index)
|
|
- $file: sys:Resources.string($.getConfigureScriptName()).replace($replacements)
|
|
- conf:Linux.runCommand($instance.agent, $file)
|
|
|
|
|
|
|
|
deploy:
|
|
Body:
|
|
- $this.deployAt($this.cluster)
|
|
|
|
|
|
scaleOut:
|
|
Body:
|
|
- $.report(format("Scale up {} cluster", $.componentName))
|
|
- $this.cluster.scale(1)
|
|
- $this.deploy()
|
|
|
|
|
|
scaleIn:
|
|
Body:
|
|
- $this.cluster.scale(-1)
|
|
- $this.deploy()
|