| 
									
										
										
										
											2015-04-20 17:52:07 +03:00
										 |  |  | #  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.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-09 10:18:33 +03:00
										 |  |  | Namespaces:
 | 
					
						
							| 
									
										
										
										
											2016-06-16 20:49:00 +03:00
										 |  |  |   =: com.mirantis.docker
 | 
					
						
							| 
									
										
										
										
											2015-04-09 10:18:33 +03:00
										 |  |  |   std: io.murano
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Name: DockerApplication
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Extends: std:Application
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Properties:
 | 
					
						
							|  |  |  |   host:
 | 
					
						
							|  |  |  |     Contract: $.class(DockerContainerHost).notNull()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   applicationEndpoints:
 | 
					
						
							|  |  |  |     Contract:
 | 
					
						
							|  |  |  |       - port: $.int().notNull().check($ > 0)
 | 
					
						
							|  |  |  |         address: $.string().notNull()
 | 
					
						
							|  |  |  |         scope: $.string().notNull().check($ in list(public, cloud, internal, host))
 | 
					
						
							|  |  |  |         portScope: $.string().notNull().check($ in list(public, cloud, internal, host))
 | 
					
						
							|  |  |  |         containerPort: $.int().notNull().check($ > 0)
 | 
					
						
							|  |  |  |         protocol: $.string().notNull().check($ in list(TCP, UDP))
 | 
					
						
							|  |  |  |     Usage: Out
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Methods:
 | 
					
						
							|  |  |  |   initialize:
 | 
					
						
							|  |  |  |     Body:
 | 
					
						
							|  |  |  |       - $._environment: $.find(std:Environment).require()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   deploy:
 | 
					
						
							|  |  |  |     Body:
 | 
					
						
							|  |  |  |       - $.host.deploy()
 | 
					
						
							|  |  |  |       - $container: $.getContainer()
 | 
					
						
							|  |  |  |       - $repr: $._getContainerRepresentation($container)
 | 
					
						
							|  |  |  |       - If: $.getAttr(container, null) != $repr
 | 
					
						
							|  |  |  |         Then:
 | 
					
						
							| 
									
										
										
										
											2015-04-15 03:26:06 +03:00
										 |  |  |         - $.onInstallationStart()
 | 
					
						
							|  |  |  |         - Try:
 | 
					
						
							| 
									
										
										
										
											2015-04-09 10:18:33 +03:00
										 |  |  |           - $.applicationEndpoints: $.host.hostContainer($container)
 | 
					
						
							|  |  |  |           - $.setAttr(container, $repr)
 | 
					
						
							| 
									
										
										
										
											2015-04-15 03:26:06 +03:00
										 |  |  |           Catch:
 | 
					
						
							|  |  |  |           - As: e
 | 
					
						
							|  |  |  |             Do:
 | 
					
						
							|  |  |  |             - $formatString: 'Error: {0}'
 | 
					
						
							|  |  |  |             - $._environment.reporter.report_error($, $formatString.format($e.message))
 | 
					
						
							|  |  |  |             - Rethrow:
 | 
					
						
							|  |  |  |           Else:
 | 
					
						
							|  |  |  |           - $.onInstallationFinish()
 | 
					
						
							| 
									
										
										
										
											2015-04-09 10:18:33 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-29 18:21:31 +03:00
										 |  |  |   destroy:
 | 
					
						
							|  |  |  |     Body:
 | 
					
						
							|  |  |  |       - If: $.getAttr(container, null) != null
 | 
					
						
							|  |  |  |         Then:
 | 
					
						
							|  |  |  |           - $container: $.getContainer()
 | 
					
						
							|  |  |  |           - $.host.deleteContainer($container.name)
 | 
					
						
							|  |  |  |           - $.setAttr(container, null)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-09 10:18:33 +03:00
										 |  |  |   getConnectionTo:
 | 
					
						
							|  |  |  |     Arguments:
 | 
					
						
							|  |  |  |       - application:
 | 
					
						
							|  |  |  |           Contract: $.class(DockerApplication).notNull()
 | 
					
						
							|  |  |  |       - port:
 | 
					
						
							|  |  |  |           Contract: $.int().notNull().check($ > 0)
 | 
					
						
							|  |  |  |       - protocol:
 | 
					
						
							|  |  |  |           Contract: $.string().notNull().check($ in list(TCP, UDP))
 | 
					
						
							|  |  |  |           Default: TCP
 | 
					
						
							|  |  |  |     Body:
 | 
					
						
							|  |  |  |       - $scopes: [cloud, public]
 | 
					
						
							|  |  |  |       - If: $.host = $application.host
 | 
					
						
							|  |  |  |         Then:
 | 
					
						
							|  |  |  |           - $scopes: list(host, internal) + $scopes
 | 
					
						
							|  |  |  |         Else:
 | 
					
						
							|  |  |  |           - If: $.host.getInternalScopeId() = $application.host.getInternalScopeId()
 | 
					
						
							|  |  |  |             Then:
 | 
					
						
							| 
									
										
										
										
											2015-05-12 08:00:48 +03:00
										 |  |  |               - $scopes: list(internal) + $scopes
 | 
					
						
							| 
									
										
										
										
											2015-04-09 10:18:33 +03:00
										 |  |  |       - For: s
 | 
					
						
							|  |  |  |         In: $scopes
 | 
					
						
							|  |  |  |         Do:
 | 
					
						
							|  |  |  |           - $endpoints: $application.applicationEndpoints.where(true).where(
 | 
					
						
							|  |  |  |               $.scope = $s and $.containerPort = $port and $.protocol = $protocol)
 | 
					
						
							|  |  |  |           - If: len($endpoints) > 0
 | 
					
						
							|  |  |  |             Then:
 | 
					
						
							|  |  |  |               - $index: int(len($endpoints) * random())
 | 
					
						
							|  |  |  |               - $endpoint: $endpoints[$index]
 | 
					
						
							|  |  |  |               - Return:
 | 
					
						
							|  |  |  |                   host: $endpoint.address
 | 
					
						
							|  |  |  |                   port: $endpoint.port
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   _getContainerRepresentation:
 | 
					
						
							|  |  |  |     Arguments:
 | 
					
						
							|  |  |  |       - container:
 | 
					
						
							|  |  |  |           Contract: $.class(DockerContainer).notNull()
 | 
					
						
							|  |  |  |     Body:
 | 
					
						
							|  |  |  |       Return: $container.getRepresentation()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   getContainer:
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onInstallationStart:
 | 
					
						
							|  |  |  |     Body:
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onInstallationFinish:
 | 
					
						
							|  |  |  |     Body:
 |