mingrammer / diagrams

:art: Diagram as Code for prototyping cloud system architectures
https://diagrams.mingrammer.com
MIT License
35.72k stars 2.32k forks source link

set the position of a cluster / node #249

Open xu4wang opened 3 years ago

xu4wang commented 3 years ago

I have one diagram as below:

from diagrams import Cluster, Diagram, Edge
from diagrams.onprem.analytics import Spark
from diagrams.onprem.compute import Server
from diagrams.onprem.container import Docker
from diagrams.onprem.database import PostgreSQL
from diagrams.onprem.inmemory import Redis
from diagrams.onprem.logging import Fluentd
from diagrams.onprem.monitoring import Grafana, Prometheus
from diagrams.onprem.network import Nginx

from urllib.request import urlretrieve
from diagrams.aws.database import Aurora
from diagrams.custom import Custom
from diagrams.k8s.compute import Pod
from diagrams.azure.compute import CloudServices

# Download an image to be used into a Custom Node class
zmq_url = "https://zeromq.org/images/logo.gif"
zmq_icon = "zmq.gif"
urlretrieve(zmq_url, zmq_icon)

with Diagram(name=" Architecture", show=False):
    nginx = Nginx("LoadBalancer")

    metrics = Prometheus("metric")
    metrics << Edge(color="firebrick", style="dashed") << Grafana("monitoring")

    with Cluster("Service Cluster"):
        with Cluster("Multitenancy #1"):
            odoo1 = Docker("Application #1")
            db1   = PostgreSQL("db #1")
            odoo1 -  Edge(color="brown") - db1
        with Cluster("Multitenancy #2"):
            odoo2 = Docker("Application #2")
            db2   = PostgreSQL("db #2")
            odoo2 -  Edge(color="brown") - db2
        with Cluster("Dedicated #3"):
            odoo3 = Docker("Application #3")
            db3   = PostgreSQL("db #3")
            odoo3 -  Edge(color="brown") - db3

        nginx >> Edge(color="darkgreen") << odoo1
        nginx >> Edge(color="darkgreen") << odoo2
        nginx >> Edge(color="darkgreen") << odoo3

    with Cluster("Sessions HA"):
        master = Redis("session")
        master - Edge(color="brown", style="dashed") - Redis("replica") << Edge(label="collect") << metrics
        odoo1 >> Edge(color="brown") >> master
        odoo2 >> Edge(color="brown") >> master
        odoo3 >> Edge(color="brown") >> master

    with Cluster("Messenging HA"):
        zmq =  Custom("Broker Active", zmq_icon)
        zmq - Edge(color="brown", style="dashed") - Custom("Broker Standby", zmq_icon) << Edge(label="collect") << metrics
        odoo1 >> Edge(color="brown") >> zmq
        odoo2 >> Edge(color="brown") >> zmq
        odoo3 >> Edge(color="brown") >> zmq

    with Cluster("Client Integration"):
        clients = CloudServices("client #1")
        clients - Edge(color="brown", style="dashed") - CloudServices("client #2") - Edge(color="brown", style="dashed") - CloudServices("client #3")         
        zmq >> Edge(color="red") >> clients 

The generated diagram is as below:

architecture

Is there a way I can set the position of the cluster? to make them aligned..

abhi0977 commented 3 years ago

@xu4wang did you find any solution around this?

xu4wang commented 3 years ago

not yet... looking forward a solution.

Abhi Ramani notifications@github.com 于 2020年9月12日周六 下午4:50写道:

@xu4wang https://github.com/xu4wang did you find any solution around this?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mingrammer/diagrams/issues/249#issuecomment-691458744, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACMAZKXYUVPWM5KEBW6TL3SFNAAFANCNFSM4P45ONMA .

mingrammer commented 3 years ago

I need to find a solution to this issue too. Thank you for reporting it.

andreujuanc commented 3 years ago

Hi!, just found this project, (It's really cool). I found a workaround for this issue (while we work out how to do it properly)

I was having exactly the same problem and what I did was to remove the "internal" communication edge between the items causing the problem:

     with Cluster("Multitenancy #1"):
            odoo1 = Docker("Application #1")
            db1   = PostgreSQL("db #1")
            # By commenting this out, Postgres and Docker will show Vertically instead
            # odoo1 -  Edge(color="brown") - db1

Since the arrow goes from the Docker node to the SessionsHA nodes, if we go horizontally as intended, it will have go on top of the Postgres node, and that's why it does this weird rendering.

The ideal solution is to allow Cluster to Cluster arrows, or even Cluster to Node.

Open issues asking for this: https://github.com/mingrammer/diagrams/issues/261 https://github.com/mingrammer/diagrams/issues/128 https://github.com/mingrammer/diagrams/issues/17

Another solution is to use a custom image node (made from another diagram???) that is a combination of docker+postgres?

Best!

EDIT: Attaching demo: image

clayms commented 3 years ago

If you don't mind the arrows coming off of your dbs and placing some Custom transparent 'spacers'.

with Diagram(name=" Architecture", show=False) as diag:
    nginx = Nginx("LoadBalancer")

    metrics = Prometheus("metric")
    metrics << Edge(color="firebrick", style="dashed") << Grafana("monitoring")

    with Cluster("Service Cluster"):
        with Cluster("Multitenancy #1"):
            odoo1 = Docker("Application #1")
            db1   = PostgreSQL("db #1")
            odoo1 -  Edge(color="brown") - db1
        with Cluster("Multitenancy #2"):
            odoo2 = Docker("Application #2")
            db2   = PostgreSQL("db #2")
            odoo2 -  Edge(color="brown") - db2
        with Cluster("Dedicated #3"):
            odoo3 = Docker("Application #3")
            db3   = PostgreSQL("db #3")
            odoo3 -  Edge(color="brown") - db3

        nginx >> Edge(color="darkgreen") << odoo1
        nginx >> Edge(color="darkgreen") << odoo2
        nginx >> Edge(color="darkgreen") << odoo3

    blank1 = Custom("","transparent.png")
    db2 - Edge(penwidth="0.0") - blank1 - Edge(penwidth="0.0") - metrics

    with Cluster("Sessions HA"):
        master = Redis("session")
        replica = Redis("replica")
        master - Edge(color="brown", style="dashed") - replica << Edge(label="collect") 
        master << metrics
        db1 >> Edge(color="brown") >> master
        db2 >> Edge(color="brown") >> master
        db3 >> Edge(color="brown") >> master

    with Cluster("Messenging HA"):
        zmq =  Custom("Broker Active", zmq_icon)
        zmq2 =  Custom("Broker Standby", zmq_icon)
        zmq - Edge(color="brown", style="dashed") - zmq2 << Edge(label="collect")
        zmq << metrics
        db1 >> Edge(color="brown") >> zmq
        db2 >> Edge(color="brown") >> zmq
        db3 >> Edge(color="brown") >> zmq

    with Cluster("Client Integration"):
        client1 = CloudServices("client #1")
        client2 = CloudServices("client #2")
        client3 = CloudServices("client #3")
        client1 - Edge(color="brown", style="dashed") - client2 - Edge(color="brown", style="dashed") - client3
        zmq2 >> Edge(color="red") >> client1

diag

image

xu4wang commented 3 years ago

Thanks for the help. I like this workaround.

If you don't mind the arrows coming off of your dbs and placing some Custom transparent 'spacers'.

clayms commented 3 years ago

@xu4wang Another option you might like is to set the graph_attr "splines" to "polyline" or "line". See output below.

graph_attr = {"splines":"polyline",}

with Diagram(name=" Architecture", show=False, graph_attr=graph_attr) as diag:
     # ... Same as previous posts

image

xu4wang commented 3 years ago

@xu4wang Another option you might like is to set the graph_attr "splines" to "polyline" or "line". See output below.

Yes! Thanks for sharing the magic. 👍