murano/meta/io.murano/Classes/CloudRegion.yaml
Stan Lagun dcbf5e1899 Raise exception on call of method of destroyed object
In theory using destruction dependencies one can obtain a new
reference to an object that is about to be destroyed. In this
case any attempt to call a method on such object should result
in exception being raised. This guarantees that the nothing can
be done on the object after its .destroy method was executed.

Also because the HeatStack instance is owned by the CloudRegion
it is going to be destroyed prior to it. But CloudRegion needs
to call $stack.delete() in its .destroy method and this will cause
error. As a solution HeatStack made not to be owned by the
region and instead be an independent object with destruction
dependency on it which guarantees that it will be destroyed
after the CloudRegion.

Targets-blueprint: dependency-driven-resource-deallocation
Change-Id: I5650ea672d5f121be69669f27dd5f513fbdd5c44
2016-09-14 03:44:36 +00:00

58 lines
1.6 KiB
YAML

Namespaces:
res: io.murano.resources
sys: io.murano.system
=: io.murano
Name: CloudRegion
Properties:
name:
Contract: $.string()
agentListener:
Contract: $.class(sys:AgentListener)
Usage: Runtime
stack:
Contract: $.class(sys:HeatStack)
Usage: Runtime
defaultNetworks:
Contract:
environment: $.class(res:Network)
flat: $.class(res:Network)
securityGroupManager:
Contract: $.class(sys:SecurityGroupManager)
Usage: Runtime
Methods:
getConfig:
Body:
- Return: $._environment.regionConfigs.get(
$.name, $._environment.regionConfigs.get(''))
.init:
Body:
- $._environment: $.find(Environment).require()
- $generatedStackName: $.getAttr(generatedStackName)
- If: $generatedStackName = null
Then:
- $generatedStackName: list($.name, randomName()).join('-')
- $.setAttr(generatedStackName, $generatedStackName)
- $this.agentListener: new(sys:AgentListener, $this, name => $generatedStackName)
- $stackDescriptionFormat: 'This stack was generated by Murano for environment {0} (ID: {1}) - region {2}'
- $this.stack: new(sys:HeatStack,
regionName => $.name,
name => 'murano-' + $generatedStackName,
description => $stackDescriptionFormat.format($._environment.name, id($._environment), $.name))
- sys:GC.subscribeDestruction($this, $this.stack)
- $this.securityGroupManager:
coalesce($.defaultNetworks.environment, $.defaultNetworks.flat)?.
generateSecurityGroupManager()
.destroy:
Body:
- $.stack.delete()