Extracted replication capabilities from ServerGroup

ServerGroup is now split into ServerGroupList and ServerReplicationGroup.
The ServerGroup class is now the base interface for both.

ServerGroupList (previously just ServerGroup) class no longer
inherits ReplicationGroup, thus just being a collection of servers,
without the mandatory provider property.

Replication functionality extracted to ServerReplicationGroup, being a
subclass of both ServerGroup and ReplicationGroup. Apps requiring
autoscaling may narrow down their contracts to ServerReplicationGroup.
Others may stay with a base class.

Also introduces CompositeServerGroup which is a convenient
way to join several ServerGroups into one.

Change-Id: Ia15659c43422551785a762b4dce3bde312a7915f
This commit is contained in:
Alexander Tivelkov 2016-08-17 18:01:50 +03:00 committed by Serg Melikyan
parent 1ada89f0db
commit 5da4efd9bb
6 changed files with 161 additions and 38 deletions

View File

@ -37,7 +37,8 @@ Methods:
- serverGroup:
Contract: $.class(ServerGroup).notNull()
Body:
- $serversToInstall: $serverGroup.items.pselect(switch($this.checkServerIsInstalled($) => null, true => $)).where($ != null)
- $serversToInstall: $serverGroup.getServers().pselect(
switch($this.checkServerIsInstalled($) => null, true => $)).where($ != null)
- If: any($serversToInstall)
Then:
- $.beforeInstall($serversToInstall, $serverGroup)
@ -198,7 +199,8 @@ Methods:
- If: $this.checkClusterIsConfigured($serverGroup)
Then:
- Return:
- $serversToConfigure: $serverGroup.items.pselect(switch($this.checkServerIsConfigured($, $serverGroup) => null, true => $)).where($ != null)
- $serversToConfigure: $serverGroup.getServers().pselect(
switch($this.checkServerIsConfigured($, $serverGroup) => null, true => $)).where($ != null)
- $this.preConfigure($serversToConfigure, $serverGroup)
- $failures: $serversToConfigure.pselect($this.configureServer($, $serverGroup)).where($ != null)
- $.completeConfiguration($serversToConfigure, $serverGroup, $failures)
@ -417,7 +419,7 @@ Methods:
any:
- Return: true
quorum:
- $numServers: len($serverGroup.items)
- $numServers: $serverGroup.getServers().count()
- $maxFailures: $numServers - ($numServers/2 + 1)
- Return: $numFailures <= $maxFailures
Value: $allowedFailures

View File

@ -37,7 +37,7 @@ Properties:
Default: 1
items:
Usage: InOut
Usage: Out
Contract:
- $.class(std:Object)

View File

@ -16,20 +16,122 @@ Namespaces:
res: io.murano.resources
std: io.murano
--- # ------------------------------------------------------------------ # ---
# A group of Servers
Name: ServerGroup
Methods:
getServers:
deployServers:
Usage: Static
Arguments:
- servers:
Contract:
- $.class(res:Instance).notNull()
- environment:
Contract: $.class(std:Environment)
Body:
- $servers.select($this._deployServer($, $environment))
- $servers.select($.endDeploy())
releaseServers:
Usage: Static
Arguments:
- servers:
Contract:
- $.class(res:Instance).notNull()
Body:
- $servers.select($.beginReleaseResources())
- $servers.select($.endReleaseResources())
_deployServer:
Usage: Static
Arguments:
- server:
Contract: $.class(res:Instance).notNull()
- environment:
Contract: $.class(std:Environment)
Body:
- If: $environment and not $server.openstackId
Then:
- $environment.reporter.report($this, 'Provisioning VM for ' + name($server) or $server.name)
- $server.beginDeploy()
--- # ------------------------------------------------------------------ # ---
# A group of prepopulated servers
Name: ServerList
Extends: ServerGroup
Properties:
servers:
Contract:
- $.class(res:Instance).notNull()
Methods:
.init:
Body:
- $this._env: $.find(std:Environment)
deploy:
Body:
- $this.deployServers($this.servers, $this._env)
.destroy:
Body:
- $this.releaseServers($this.items)
getServers:
Body:
Return: $.servers
--- # ------------------------------------------------------------------ # ---
# Degenrate case of a server group which consists of a single server
Name: SingleServerGroup
Extends: ServerGroup
Properties:
server:
Contract: $.class(res:Instance).notNull()
Methods:
setServer:
Arguments:
- server:
Contract: $.class(res:Instance).notNull()
Body:
- $this.items: $server
deploy:
Body:
- $this.deployServers([$this.server], $this._env)
.destroy:
Body:
- $this.releaseServers([$this.server])
getServers:
Body:
Return: [$.server]
--- # ------------------------------------------------------------------ # ---
# A replication group aggregating Servers
# Adds a logic to concurrently provision and unprovision servers
Name: ServerGroup
Name: ServerReplicationGroup
Extends:
- ReplicationGroup
- ServerGroup
Properties:
provider:
Contract: $.class(ReplicaProvider).notNull()
items:
Usage: InOut
Usage: Out
Contract:
- $.class(res:Instance)
@ -50,27 +152,38 @@ Methods:
- $target: format(' {0} {1}', $target, name($this))
Else:
- $target: ''
- $this._env.reporter.report($this, format('{0} {1} servers{2}', $verb, abs($delta), $target))
- $this._env.reporter.report($this, format('{0} {1} servers{2}',
$verb, abs($delta), $target))
- cast($this, ReplicationGroup).deploy()
- $this.items.select($this._deployServer($))
- $this.items.select($.endDeploy())
_deployServer:
Arguments:
- server:
Contract: $.class(res:Instance)
Body:
- If: $this._env and not $server.openstackId
Then:
- $this._env.reporter.report($this, 'Provisioning VM for ' + name($server) or $server.name)
- $server.beginDeploy()
- $this.deployServers($this.items, $this._env)
.destroy:
Body:
- $this.items.select($.beginReleaseResources())
- $this.items.select($.endReleaseResources())
- $this.releaseServers($this.items)
getServers:
Body:
Return: $.items
--- # ------------------------------------------------------------------ # ---
# A server group that composed of other server groups
Name: CompositeServerGroup
Extends: ServerGroup
Properties:
serverGroups:
Contract:
- $.class(ServerGroup).notNull()
Methods:
deploy:
Body:
- $this.serverGroups.pselect($.deploy())
getServers:
Body:
Return: $this.serverGroups.selectMany($.getServers())
--- # ------------------------------------------------------------------ # ---
# A replication provider acting as a default factory class for Servers

View File

@ -83,22 +83,22 @@ Methods:
- $serverTemplate: new(res:LinuxMuranoInstance, $this.environment,
name=>'whatever',
image=>'murano-latest',
flavor=>'t1.medium')
- $this.provider: new(apps:ServerProvider, source=>$serverTemplate,
serverNamePattern=>'testNode-{0}')
name => 'whatever',
image => 'murano-latest',
flavor => 't1.medium')
- $this.provider: new(apps:ServerProvider, source => $serverTemplate,
serverNamePattern => 'testNode-{0}')
testCreateSingleServer:
Body:
- $ssg: new(apps:ServerGroup, provider=>$this.provider)
- $ssg: new(apps:ServerReplicationGroup, provider => $this.provider)
- $ssg.deploy()
- $this.assertServerCount(1)
testServersHaveProperName:
Body:
- $model:
apps:ServerGroup:
apps:ServerReplicationGroup:
numItems: 2
provider:
apps:ServerProvider:
@ -113,13 +113,13 @@ Methods:
testCreateMultipleServers:
Body:
- $ssg: new(apps:ServerGroup, provider=>$this.provider, numItems=>5)
- $ssg: new(apps:ServerReplicationGroup, provider => $this.provider, numItems => 5)
- $ssg.deploy()
- $this.assertServerCount(5)
testCreateScaleUp:
Body:
- $ssg: new(apps:ServerGroup, provider=>$this.provider, numItems=>3)
- $ssg: new(apps:ServerReplicationGroup, provider => $this.provider, numItems => 3)
- $ssg.deploy()
- $this.assertServerCount(3)
- $ssg.scale(4)
@ -128,7 +128,7 @@ Methods:
testCreateScaleDown:
Body:
- $ssg: new(apps:ServerGroup, provider=>$this.provider, numItems=>3)
- $ssg: new(apps:ServerReplicationGroup, provider => $this.provider, numItems => 3)
- $ssg.deploy()
- $this.assertServerCount(3)
- $ssg.scale(-2)
@ -137,7 +137,8 @@ Methods:
testMultipleServersReporting:
Body:
- $ssg: new(apps:ServerGroup, $this.environment, TestGroup, provider=>$this.provider, numItems=>3)
- $ssg: new(apps:ServerReplicationGroup, $this.environment, TestGroup,
provider => $this.provider, numItems => 3)
- $ssg.deploy()
- $this.assertEqual('Creating 3 servers for TestGroup', $this.reports[0])
- $ssg.scale(-2)
@ -145,7 +146,8 @@ Methods:
testMultipleServersReportingNoGroupName:
Body:
- $ssg: new(apps:ServerGroup, $this.environment, null, provider=>$this.provider, numItems=>3)
- $ssg: new(apps:ServerReplicationGroup, $this.environment, null,
provider => $this.provider, numItems => 3)
- $ssg.deploy()
- $this.assertEqual('Creating 3 servers', $this.reports[0])
- $ssg.scale(-2)
@ -153,7 +155,8 @@ Methods:
testNoReportingIfSingleServer:
Body:
- $ssg: new(apps:ServerGroup, $this.environment, TestGroup, provider=>$this.provider, numItems=>1)
- $ssg: new(apps:ServerReplicationGroup, $this.environment, TestGroup,
provider => $this.provider, numItems => 1)
- $ssg.deploy()
- $this.assertEqual(1, len($this.reports))
@ -163,4 +166,5 @@ Methods:
- count:
Contract: $.int()
Body:
- $this.assertEqual($count, $this.currentTemplate.resources.values().where($.type='OS::Nova::Server').len())
- $this.assertEqual($count, $this.currentTemplate.resources.values().where(
$.type = 'OS::Nova::Server').len())

View File

@ -54,7 +54,7 @@ Methods:
flavor=>'noop')
- $provider: new(apps:ServerProvider, $this.environment,
source=>$server, serverNamePattern=>'testNode-{0}')
- $this.group: new(apps:ServerGroup, provider=>$provider, numItems=>5)
- $this.group: new(apps:ServerReplicationGroup, provider=>$provider, numItems=>5)
- $this.group.deploy()
- $this.reports: []
- inject($this.environment.reporter, report, $this, report)

View File

@ -32,6 +32,10 @@ Classes:
io.murano.applications.Event: events.yaml
io.murano.applications.ServerGroup: servers.yaml
io.murano.applications.ServerList: servers.yaml
io.murano.applications.CompositeServerGroup: servers.yaml
io.murano.applications.SingleServerGroup: servers.yaml
io.murano.applications.ServerReplicationGroup: servers.yaml
io.murano.applications.ServerProvider: servers.yaml
io.murano.applications.Installable: component.yaml