diff --git a/meta/io.murano.applications/Classes/component.yaml b/meta/io.murano.applications/Classes/component.yaml index 66aef5673..494e14092 100644 --- a/meta/io.murano.applications/Classes/component.yaml +++ b/meta/io.murano.applications/Classes/component.yaml @@ -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 diff --git a/meta/io.murano.applications/Classes/replication.yaml b/meta/io.murano.applications/Classes/replication.yaml index 3859f2ec6..775688580 100644 --- a/meta/io.murano.applications/Classes/replication.yaml +++ b/meta/io.murano.applications/Classes/replication.yaml @@ -37,7 +37,7 @@ Properties: Default: 1 items: - Usage: InOut + Usage: Out Contract: - $.class(std:Object) diff --git a/meta/io.murano.applications/Classes/servers.yaml b/meta/io.murano.applications/Classes/servers.yaml index 4e0b01f08..b795d21e5 100644 --- a/meta/io.murano.applications/Classes/servers.yaml +++ b/meta/io.murano.applications/Classes/servers.yaml @@ -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 diff --git a/meta/io.murano.applications/Classes/tests/TestServerProviders.yaml b/meta/io.murano.applications/Classes/tests/TestServerProviders.yaml index fe6065437..a514e4119 100644 --- a/meta/io.murano.applications/Classes/tests/TestServerProviders.yaml +++ b/meta/io.murano.applications/Classes/tests/TestServerProviders.yaml @@ -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()) diff --git a/meta/io.murano.applications/Classes/tests/TestSoftwareComponent.yaml b/meta/io.murano.applications/Classes/tests/TestSoftwareComponent.yaml index deccdd964..45f1d0537 100644 --- a/meta/io.murano.applications/Classes/tests/TestSoftwareComponent.yaml +++ b/meta/io.murano.applications/Classes/tests/TestSoftwareComponent.yaml @@ -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) diff --git a/meta/io.murano.applications/manifest.yaml b/meta/io.murano.applications/manifest.yaml index f3470cd55..26d7e1f5c 100644 --- a/meta/io.murano.applications/manifest.yaml +++ b/meta/io.murano.applications/manifest.yaml @@ -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