Skip to content

Commit 6a3ecac

Browse files
yt-msMidnighter
authored andcommitted
refactor: enable deployment nodes in big_bank.py example and refactor method signatures to support.
1 parent e77e89a commit 6a3ecac

File tree

4 files changed

+151
-125
lines changed

4 files changed

+151
-125
lines changed

examples/big_bank.py

Lines changed: 111 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -244,117 +244,120 @@ def create_big_bank_workspace():
244244
# TODO:!
245245
# model.AddImplicitRelationships()
246246

247-
# # deployment nodes and container instances
248-
# developer_laptop = model.add_deployment_node(
249-
# environment="Development",
250-
# name="Developer Laptop",
251-
# description="A developer laptop.",
252-
# technology="Microsoft Windows 10 or Apple macOS",
253-
# )
254-
# apache_tomcat = developer_laptop.add_deployment_node(
255-
# name="Docker - Web Server",
256-
# description="A Docker container.",
257-
# technology="Docker",
258-
# ).add_deployment_node(
259-
# name="Apache Tomcat",
260-
# description="An open source Java EE web server.",
261-
# technology="Apache Tomcat 8.x",
262-
# instances=1,
263-
# properties={"Xmx": "512M", "Xms": "1024M", "Java Version": "8"},
264-
# )
265-
# apache_tomcat.add_container(webApplication)
266-
# apache_tomcat.Add(apiApplication)
267-
268-
# developer_laptop.add_deployment_node(
269-
# "Docker - Database Server", "A Docker container.", "Docker"
270-
# ).add_deployment_node(
271-
# "Database Server", "A development database.", "Oracle 12c"
272-
# ).Add(
273-
# database
274-
# )
275-
276-
# developer_laptop.add_deployment_node(
277-
# "Web Browser", "", "Chrome, Firefox, Safari, or Edge"
278-
# ).Add(single_page_application)
279-
280-
# customer_mobile_device = model.add_deployment_node(
281-
# "Live", "Customer's mobile device", "", "Apple iOS or Android"
282-
# )
283-
# customer_mobile_device.Add(mobile_app)
284-
285-
# customer_computer = model.add_deployment_node(
286-
# "Live", "Customer's computer", "", "Microsoft Windows or Apple macOS"
287-
# )
288-
# customer_computer.add_deployment_node(
289-
# "Web Browser", "", "Chrome, Firefox, Safari, or Edge"
290-
# ).Add(single_page_application)
291-
292-
# bigBankDataCenter = model.add_deployment_node(
293-
# "Live", "Big Bank plc", "", "Big Bank plc data center"
294-
# )
295-
296-
# liveWebServer = bigBankDataCenter.add_deployment_node(
297-
# "bigbank-web***",
298-
# "A web server residing in the web server farm, accessed via F5 BIG-IP LTMs.",
299-
# "Ubuntu 16.04 LTS",
300-
# 4,
301-
# DictionaryUtils.Create("Location=London and Reading"),
302-
# )
303-
# liveWebServer.add_deployment_node(
304-
# "Apache Tomcat",
305-
# "An open source Java EE web server.",
306-
# "Apache Tomcat 8.x",
307-
# 1,
308-
# DictionaryUtils.Create("Xmx=512M", "Xms=1024M", "Java Version=8"),
309-
# ).Add(webApplication)
310-
311-
# liveApiServer = bigBankDataCenter.add_deployment_node(
312-
# "bigbank-api***",
313-
# "A web server residing in the web server farm, accessed via F5 BIG-IP LTMs.",
314-
# "Ubuntu 16.04 LTS",
315-
# 8,
316-
# DictionaryUtils.Create("Location=London and Reading"),
317-
# )
318-
# liveApiServer.add_deployment_node(
319-
# "Apache Tomcat",
320-
# "An open source Java EE web server.",
321-
# "Apache Tomcat 8.x",
322-
# 1,
323-
# DictionaryUtils.Create("Xmx=512M", "Xms=1024M", "Java Version=8"),
324-
# ).Add(apiApplication)
325-
326-
# primaryDatabaseServer = bigBankDataCenter.add_deployment_node(
327-
# "bigbank-db01",
328-
# "The primary database server.",
329-
# "Ubuntu 16.04 LTS",
330-
# 1,
331-
# DictionaryUtils.Create("Location=London"),
332-
# ).add_deployment_node(
333-
# "Oracle - Primary", "The primary, live database server.", "Oracle 12c"
334-
# )
335-
# primaryDatabaseServer.Add(database)
336-
337-
# bigBankdb02 = bigBankDataCenter.add_deployment_node(
338-
# "bigbank-db02",
339-
# "The secondary database server.",
340-
# "Ubuntu 16.04 LTS",
341-
# 1,
342-
# DictionaryUtils.Create("Location=Reading"),
343-
# )
344-
# bigBankdb02.tags.add(FailoverTag)
345-
# secondaryDatabaseServer = bigBankdb02.add_deployment_node(
346-
# "Oracle - Secondary",
347-
# "A secondary, standby database server, used for failover purposes only.",
348-
# "Oracle 12c",
349-
# )
350-
# secondaryDatabaseServer.tags.add(FailoverTag)
351-
# secondaryDatabase = secondaryDatabaseServer.Add(database)
352-
353-
# # model.Relationships.Where(r=>r.Destination.Equals(secondaryDatabase)).ToList().ForEach(r=>r.tags.add(FailoverTag))
247+
# deployment nodes and container instances
248+
developer_laptop = model.add_deployment_node(
249+
environment="Development",
250+
name="Developer Laptop",
251+
description="A developer laptop.",
252+
technology="Microsoft Windows 10 or Apple macOS",
253+
)
254+
apache_tomcat = developer_laptop.add_deployment_node(
255+
name="Docker - Web Server",
256+
description="A Docker container.",
257+
technology="Docker",
258+
).add_deployment_node(
259+
name="Apache Tomcat",
260+
description="An open source Java EE web server.",
261+
technology="Apache Tomcat 8.x",
262+
instances=1,
263+
properties={"Xmx": "512M", "Xms": "1024M", "Java Version": "8"},
264+
)
265+
apache_tomcat.add_container(web_application)
266+
apache_tomcat.add_container(api_application)
267+
268+
developer_laptop.add_deployment_node(
269+
"Docker - Database Server", "A Docker container.", "Docker"
270+
).add_deployment_node(
271+
"Database Server", "A development database.", "Oracle 12c"
272+
).add_container(
273+
database
274+
)
275+
276+
developer_laptop.add_deployment_node(
277+
"Web Browser", "", "Chrome, Firefox, Safari, or Edge"
278+
).add_container(single_page_application)
279+
280+
customer_mobile_device = model.add_deployment_node(
281+
"Customer's mobile device", "", "Apple iOS or Android", environment="Live"
282+
)
283+
customer_mobile_device.add_container(mobile_app)
284+
285+
customer_computer = model.add_deployment_node(
286+
"Customer's computer",
287+
"",
288+
"Microsoft Windows or Apple macOS",
289+
environment="Live",
290+
)
291+
customer_computer.add_deployment_node(
292+
"Web Browser", "", "Chrome, Firefox, Safari, or Edge"
293+
).add_container(single_page_application)
294+
295+
bigBankDataCenter = model.add_deployment_node(
296+
"Big Bank plc", "", "Big Bank plc data center", environment="Live"
297+
)
298+
299+
liveWebServer = bigBankDataCenter.add_deployment_node(
300+
"bigbank-web***",
301+
"A web server residing in the web server farm, accessed via F5 BIG-IP LTMs.",
302+
"Ubuntu 16.04 LTS",
303+
instances=4,
304+
properties={"Location": "London and Reading"},
305+
)
306+
liveWebServer.add_deployment_node(
307+
"Apache Tomcat",
308+
"An open source Java EE web server.",
309+
"Apache Tomcat 8.x",
310+
instances=1,
311+
properties={"Xmx": "512M", "Xms": "1024M", "Java Version": "8"},
312+
).add_container(web_application)
313+
314+
liveApiServer = bigBankDataCenter.add_deployment_node(
315+
"bigbank-api***",
316+
"A web server residing in the web server farm, accessed via F5 BIG-IP LTMs.",
317+
"Ubuntu 16.04 LTS",
318+
instances=8,
319+
properties={"Location": "London and Reading"},
320+
)
321+
liveApiServer.add_deployment_node(
322+
"Apache Tomcat",
323+
"An open source Java EE web server.",
324+
"Apache Tomcat 8.x",
325+
instances=1,
326+
properties={"Xmx": "512M", "Xms": "1024M", "Java Version": "8"},
327+
).add_container(api_application)
328+
329+
primaryDatabaseServer = bigBankDataCenter.add_deployment_node(
330+
"bigbank-db01",
331+
"The primary database server.",
332+
"Ubuntu 16.04 LTS",
333+
instances=1,
334+
properties={"Location": "London"},
335+
).add_deployment_node(
336+
"Oracle - Primary", "The primary, live database server.", "Oracle 12c"
337+
)
338+
primaryDatabaseServer.add_container(database)
339+
340+
bigBankdb02 = bigBankDataCenter.add_deployment_node(
341+
"bigbank-db02",
342+
"The secondary database server.",
343+
"Ubuntu 16.04 LTS",
344+
instances=1,
345+
properties={"Location": "Reading"},
346+
)
347+
bigBankdb02.tags.add(failover_tag)
348+
secondaryDatabaseServer = bigBankdb02.add_deployment_node(
349+
"Oracle - Secondary",
350+
"A secondary, standby database server, used for failover purposes only.",
351+
"Oracle 12c",
352+
)
353+
secondaryDatabaseServer.tags.add(failover_tag)
354+
secondaryDatabase = secondaryDatabaseServer.add_container(database)
355+
356+
# # model.Relationships.Where(r=>r.Destination.Equals(secondaryDatabase)).ToList().ForEach(r=>r.tags.add(failover_tag))
354357
# dataReplicationRelationship = primaryDatabaseServer.uses(
355358
# secondaryDatabaseServer, "Replicates data to", ""
356359
# )
357-
# secondaryDatabase.tags.add(FailoverTag)
360+
# secondaryDatabase.tags.add(failover_tag)
358361

359362
# views/diagrams
360363
system_landscape_view = views.create_system_landscape_view(

src/structurizr/model/deployment_node.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class DeploymentNode(DeploymentElement):
8282
id: The ID of this deployment node in the model.
8383
name: The name of this node.
8484
description: A short description of this node.
85-
environment (str):
85+
environment (str): The environment this node lives in.
8686
tags: A comma separated list of tags associated with this node.
8787
children: The deployment nodes that are direct children of this node.
8888
properties: A set of arbitrary name-value properties.
@@ -133,17 +133,29 @@ def infrastructure_nodes(self) -> Iterable[InfrastructureNode]:
133133
"""Return read-only list of infrastructure nodes."""
134134
return list(self._infrastructure_nodes)
135135

136-
def add_deployment_node(self, **kwargs) -> "DeploymentNode":
137-
"""Add a new child deployment node to this node."""
138-
node = DeploymentNode(**kwargs)
136+
def add_deployment_node(
137+
self, name: str, description: str = "", technology: str = "", **kwargs
138+
) -> "DeploymentNode":
139+
"""
140+
Add a new child deployment node to this node.
141+
142+
Args:
143+
name(str): Name of the deployment node
144+
description(str): Optional description
145+
technology(str): Optional technologies
146+
**kwargs: additional keyword arguments for instantiating a `DeploymentNode`
147+
"""
148+
node = DeploymentNode(
149+
name=name, description=description, technology=technology, **kwargs
150+
)
139151
self += node
140152
return node
141153

142-
def add_container_instance(
143-
self, container: Container, *, replicate_relationships: bool
154+
def add_container(
155+
self, container: Container, *, replicate_relationships: bool = True
144156
) -> ContainerInstance:
145157
"""
146-
Create a new instance of the given container.
158+
Create a new instance of a container in this deployment node.
147159
148160
Args:
149161
container(Container): the Container to add an instance of.
@@ -170,11 +182,11 @@ def add_container_instance(
170182
model += instance
171183
return instance
172184

173-
def add_software_system_instance(
174-
self, software_system: SoftwareSystem, *, replicate_relationships: bool
185+
def add_software_system(
186+
self, software_system: SoftwareSystem, *, replicate_relationships: bool = True
175187
) -> SoftwareSystemInstance:
176188
"""
177-
Create a new instance of the given software system.
189+
Create a new instance of a software system in this deployment node.
178190
179191
Args:
180192
software_system(SoftwareSystem): the SoftwareSystem to add an instance of.

src/structurizr/model/model.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,21 @@ def add_container_instance(
271271
# TODO: implement
272272
# instance_number =
273273

274-
def add_deployment_node(self, **kwargs) -> DeploymentNode:
274+
def add_deployment_node(
275+
self,
276+
name: str,
277+
description: str = "",
278+
technology: str = "",
279+
**kwargs,
280+
) -> DeploymentNode:
275281
"""
276282
Add a new deployment node to the model.
277283
278284
Args:
279-
**kwargs: Provide keyword arguments for instantiating a `DeploymentNode`.
285+
name(str): Name of the deployment node
286+
description(str): Optional description
287+
technology(str): Optional technologies
288+
**kwargs: additional keyword arguments for instantiating a `DeploymentNode`.
280289
281290
Returns:
282291
DeploymentNode: The newly created DeploymentNode.
@@ -288,7 +297,9 @@ def add_deployment_node(self, **kwargs) -> DeploymentNode:
288297
DeploymentNode
289298
290299
"""
291-
deployment_node = DeploymentNode(**kwargs)
300+
deployment_node = DeploymentNode(
301+
name=name, description=description, technology=technology, **kwargs
302+
)
292303
self += deployment_node
293304
return deployment_node
294305

tests/unit/model/test_deployment_node.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def test_deployment_node_add_container(model_with_node):
130130
node = model_with_node.empty_node
131131
container = MockElement("element")
132132

133-
instance = node.add_container_instance(container, replicate_relationships=False)
133+
instance = node.add_container(container, replicate_relationships=False)
134134

135135
assert instance.container is container
136136
assert instance.model is model_with_node
@@ -143,7 +143,7 @@ def test_deployment_node_serialising_container(model_with_node):
143143
"""Test serialisation and deserialisation includes container instances."""
144144
node = model_with_node.empty_node
145145
container = model_with_node.mock_element
146-
node.add_container_instance(container, replicate_relationships=False)
146+
node.add_container(container, replicate_relationships=False)
147147

148148
io = DeploymentNodeIO.from_orm(node)
149149

@@ -171,7 +171,7 @@ def test_deployment_node_add_software_system(model_with_node):
171171
node = model_with_node.empty_node
172172
system = MockElement("element")
173173

174-
instance = node.add_software_system_instance(system, replicate_relationships=False)
174+
instance = node.add_software_system(system, replicate_relationships=False)
175175

176176
assert instance.software_system is system
177177
assert instance.model is model_with_node
@@ -184,7 +184,7 @@ def test_deployment_node_serialising_software_system(model_with_node):
184184
"""Test serialisation and deserialisation includes container instances."""
185185
node = model_with_node.empty_node
186186
system = model_with_node.mock_element
187-
node.add_software_system_instance(system, replicate_relationships=False)
187+
node.add_software_system(system, replicate_relationships=False)
188188

189189
io = DeploymentNodeIO.from_orm(node)
190190

0 commit comments

Comments
 (0)