from diagrams import Cluster, Diagram, Edge

from diagrams.onprem.database import Mariadb
from diagrams.azure.database import DatabaseForMariadbServers
from diagrams.onprem.inmemory import Redis
from diagrams.onprem.groupware import Nextcloud

from diagrams.custom import Custom

with Diagram(filename="./assets/dia_db_cluster", show=False):
    nc = Nextcloud()

    with Cluster("Database cluster"):

        with Cluster("Load balancer"):
            paSQL = Custom("ProxySQL Active", "../assets/proxysql.png")
            ppSQL = Custom("ProxySQL Passive", "../assets/proxysql.png")
        
        with Cluster("Galera cluster"):
            bckp1 = DatabaseForMariadbServers("Backup writer")
            primary = Mariadb("Primary writer")
            bckp2 = DatabaseForMariadbServers("Backup writer")            
    
        paSQL - Edge(color="firebrick") - primary
        bckp1 - Edge(style="dashed") - paSQL - Edge(style="dashed") - bckp2
        
        ppSQL - Edge(color="firebrick") - primary
        bckp1 - Edge(style="dashed") - ppSQL - Edge(style="dashed") - bckp2

    paSQL << nc >> ppSQL