HostingAsset-Hierarchie spec in enum HsHostingAssetType and generates PlantUML #72

Merged
hsh-michaelhoennig merged 9 commits from add-mermaid-graph-generator-for-hosting-asset-type-structure into master 2024-07-09 14:32:14 +02:00
3 changed files with 106 additions and 97 deletions
Showing only changes of commit af466dde2e - Show all commits

View File

@ -1,77 +1,84 @@
### HostingAsset Type Structure
```mermaid
%%{init:{'flowchart':{'htmlLabels':false}}}%%
flowchart RL
```plantuml
@startuml
subgraph Booking
style Booking fill:white,stroke:white,stroke-width:0px
BI:PRIVATE_CLOUD
BI:CLOUD_SERVER
BI:MANAGED_SERVER
BI:MANAGED_WEBSPACE
BI:DOMAIN_DNS_SETUP
BI:DOMAIN_EMAIL_SUBMISSION_SETUP
end
left to right direction
%% subgraph Hosting
subgraph Server[ ]
style Server fill:white,stroke:white,stroke-width:0px
HA:CLOUD_SERVER
HA:MANAGED_SERVER
HA:IP_NUMBER
end
package Booking #99bcdb {
entity BI_PRIVATE_CLOUD
entity BI_CLOUD_SERVER
entity BI_MANAGED_SERVER
entity BI_MANAGED_WEBSPACE
entity BI_DOMAIN_DNS_SETUP
entity BI_DOMAIN_EMAIL_SUBMISSION_SETUP
}
subgraph Domain[ ]
style Domain fill:white,stroke:white,stroke-width:0px
HA:DOMAIN_DNS_SETUP
HA:DOMAIN_HTTP_SETUP
HA:DOMAIN_EMAIL_SUBMISSION_SETUP
HA:DOMAIN_EMAIL_MAILBOX_SETUP
HA:EMAIL_ADDRESS
end
package Hosting #white {
package Server #99bcdb {
entity HA_CLOUD_SERVER
entity HA_MANAGED_SERVER
entity HA_IP_NUMBER
}
subgraph Webspace[ ]
style Webspace fill:white,stroke:white,stroke-width:0px
HA:MANAGED_WEBSPACE
HA:UNIX_USER
HA:EMAIL_ALIAS
end
package PostgreSQL #99bcdb {
entity HA_PGSQL_INSTANCE
entity HA_PGSQL_USER
entity HA_PGSQL_DATABASE
}
%% end
package MariaDB #99bcdb {
entity HA_MARIADB_INSTANCE
entity HA_MARIADB_USER
entity HA_MARIADB_DATABASE
}
style HA:CLOUD_SERVER fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:MANAGED_SERVER fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:MANAGED_WEBSPACE fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:UNIX_USER fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:DOMAIN_DNS_SETUP fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:DOMAIN_HTTP_SETUP fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:DOMAIN_EMAIL_SUBMISSION_SETUP fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:DOMAIN_EMAIL_MAILBOX_SETUP fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:EMAIL_ALIAS fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:EMAIL_ADDRESS fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:IP_NUMBER fill:#99bcdb,stroke:#274d6e,stroke-width:4px
package Domain #99bcdb {
entity HA_DOMAIN_DNS_SETUP
entity HA_DOMAIN_HTTP_SETUP
entity HA_DOMAIN_EMAIL_SUBMISSION_SETUP
entity HA_DOMAIN_EMAIL_MAILBOX_SETUP
entity HA_EMAIL_ADDRESS
}
BI:CLOUD_SERVER --> BI:PRIVATE_CLOUD
BI:MANAGED_SERVER --> BI:PRIVATE_CLOUD
BI:MANAGED_WEBSPACE --> BI:MANAGED_SERVER
package Webspace #99bcdb {
entity HA_MANAGED_WEBSPACE
entity HA_UNIX_USER
entity HA_EMAIL_ALIAS
}
HA:CLOUD_SERVER ==> BI:CLOUD_SERVER
HA:MANAGED_SERVER ==> BI:MANAGED_SERVER
HA:MANAGED_WEBSPACE ==> BI:MANAGED_WEBSPACE
HA:MANAGED_WEBSPACE ==o HA:MANAGED_SERVER
HA:UNIX_USER ==> HA:MANAGED_WEBSPACE
HA:DOMAIN_DNS_SETUP ==> BI:DOMAIN_DNS_SETUP
HA:DOMAIN_HTTP_SETUP ==> HA:MANAGED_WEBSPACE
HA:DOMAIN_HTTP_SETUP -.-> HA:UNIX_USER
HA:DOMAIN_EMAIL_SUBMISSION_SETUP ==> BI:DOMAIN_EMAIL_SUBMISSION_SETUP
HA:DOMAIN_EMAIL_SUBMISSION_SETUP -.-o HA:MANAGED_WEBSPACE
HA:DOMAIN_EMAIL_MAILBOX_SETUP ==> HA:MANAGED_WEBSPACE
HA:EMAIL_ALIAS ==> HA:MANAGED_WEBSPACE
HA:EMAIL_ADDRESS ==> HA:DOMAIN_EMAIL_MAILBOX_SETUP
HA:IP_NUMBER -.-> HA:CLOUD_SERVER
HA:IP_NUMBER -.-> HA:MANAGED_SERVER
HA:IP_NUMBER -.-> HA:MANAGED_WEBSPACE
}
BI_CLOUD_SERVER o..> BI_PRIVATE_CLOUD
BI_MANAGED_SERVER o..> BI_PRIVATE_CLOUD
BI_MANAGED_WEBSPACE o..> BI_MANAGED_SERVER
HA_CLOUD_SERVER *==> BI_CLOUD_SERVER
HA_MANAGED_SERVER *==> BI_MANAGED_SERVER
HA_MANAGED_WEBSPACE *==> BI_MANAGED_WEBSPACE
HA_MANAGED_WEBSPACE o..> HA_MANAGED_SERVER
HA_UNIX_USER *==> HA_MANAGED_WEBSPACE
HA_DOMAIN_DNS_SETUP *==> BI_DOMAIN_DNS_SETUP
HA_DOMAIN_HTTP_SETUP *==> HA_MANAGED_WEBSPACE
HA_DOMAIN_HTTP_SETUP o..> HA_UNIX_USER
HA_DOMAIN_EMAIL_SUBMISSION_SETUP *==> BI_DOMAIN_EMAIL_SUBMISSION_SETUP
HA_DOMAIN_EMAIL_SUBMISSION_SETUP o..> HA_MANAGED_WEBSPACE
HA_DOMAIN_EMAIL_MAILBOX_SETUP *==> HA_MANAGED_WEBSPACE
HA_EMAIL_ALIAS *==> HA_MANAGED_WEBSPACE
HA_EMAIL_ADDRESS *==> HA_DOMAIN_EMAIL_MAILBOX_SETUP
HA_PGSQL_INSTANCE *==> HA_MANAGED_SERVER
HA_PGSQL_USER *==> HA_PGSQL_INSTANCE
HA_PGSQL_USER o..> HA_MANAGED_WEBSPACE
HA_PGSQL_DATABASE *==> HA_MANAGED_WEBSPACE
HA_PGSQL_DATABASE o..> HA_PGSQL_INSTANCE
HA_MARIADB_INSTANCE *==> HA_MANAGED_SERVER
HA_MARIADB_USER *==> HA_MARIADB_INSTANCE
HA_MARIADB_USER o..> HA_MANAGED_WEBSPACE
HA_MARIADB_DATABASE *==> HA_MANAGED_WEBSPACE
HA_MARIADB_DATABASE o..> HA_MARIADB_INSTANCE
HA_IP_NUMBER o..> HA_CLOUD_SERVER
HA_IP_NUMBER o..> HA_MANAGED_SERVER
HA_IP_NUMBER o..> HA_MANAGED_WEBSPACE
```
This code generated was by HsHostingAssetType.main, do not amend manually.

View File

@ -25,13 +25,13 @@ public enum HsBookingItemType implements Node {
@Override
public List<String> edges() {
return ofNullable(parentItemType)
.map(p -> (nodeName() + " --> " + p.nodeName()))
.map(p -> (nodeName() + " o..> " + p.nodeName()))
.stream().toList();
}
@Override
public String nodeName() {
return "BI:" + name();
return "BI_" + name();
}
}

View File

@ -9,10 +9,11 @@ import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toSet;
import static net.hostsharing.hsadminng.hs.hosting.asset.EntityTypeRelation.*;
public enum HsHostingAssetType implements Node {
@ -100,7 +101,7 @@ public enum HsHostingAssetType implements Node {
assignedTo(MANAGED_WEBSPACE)
);
private final String groupName;
final String groupName;
private final EntityTypeRelation<?>[] relations;
HsHostingAssetType(
@ -125,7 +126,7 @@ public enum HsHostingAssetType implements Node {
@Override
public String nodeName() {
return "HA:" + name();
return "HA_" + name();
}
public static <T extends Enum<?>> HsHostingAssetType of(final T value) {
@ -138,17 +139,20 @@ public enum HsHostingAssetType implements Node {
public static void main(final String[] args) throws IOException {
final var includedHostingGroups = Set.of("Domain", "Server", "Webspace");
final var includedHostingGroups = stream(HsHostingAssetType.values())
.map(t -> t.groupName)
.collect(toSet());
// final var includedHostingGroups = Set.of("Domain", "Server", "Webspace");
final String bookingNodes = stream(HsBookingItemType.values())
.map(t -> " " + t.nodeName())
.map(t -> " entity " + t.nodeName())
.collect(joining("\n"));
final String hostingGroups = includedHostingGroups.stream()
.map(HsHostingAssetType::generateGroup)
.collect(joining("\n"));
final String hostingAssetNodeStyles = stream(HsHostingAssetType.values())
.filter(t -> includedHostingGroups.contains(t.groupName))
.map(n -> "style HA:"+n.name()+" fill:#99bcdb,stroke:#274d6e,stroke-width:4px")
final String hostingAssetNodes = stream(HsHostingAssetType.values())
.filter(a -> includedHostingGroups.contains(a.groupName))
.map(a -> "entity "+a.nodeName())
.collect(joining("\n"));
final String bookingItemEdges = stream(HsBookingItemType.values())
.map(HsBookingItemType::edges)
@ -164,20 +168,19 @@ public enum HsHostingAssetType implements Node {
"""
### HostingAsset Type Structure
```mermaid
%%{init:{'flowchart':{'htmlLabels':false}}}%%
flowchart RL
```plantuml
@startuml
left to right direction
subgraph Booking
style Booking fill:white,stroke:white,stroke-width:0px
package Booking #99bcdb {
%{bookingNodes}
end
}
%% subgraph Hosting
package Hosting #white {
%{hostingGroups}
%% end
}
%{hostingAssetNodeStyles}
Booking -left-> Hosting
%{bookingItemEdges}
@ -189,20 +192,19 @@ public enum HsHostingAssetType implements Node {
.replace("%{this}", HsHostingAssetType.class.getSimpleName())
.replace("%{bookingNodes}", bookingNodes)
.replace("%{hostingGroups}", hostingGroups)
.replace("%{hostingAssetNodeStyles}", hostingAssetNodeStyles)
.replace("%{hostingAssetNodeStyles}", hostingAssetNodes)
.replace("%{bookingItemEdges}", bookingItemEdges)
.replace("%{hostingAssetEdges}", hostingAssetEdges),
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
}
private static String generateGroup(final String group) {
return "subgraph " + group + "[ ]\n"
+ " style " + group + " fill:white,stroke:white,stroke-width:0px\n"
return " package " + group + " #99bcdb {\n"
+ stream(HsHostingAssetType.values())
.filter(t -> t.groupName.equals(group))
.map(HsHostingAssetType::nodeName)
.map(t -> " entity " + t.nodeName())
.collect(joining(" \n"))
+ "\nend\n";
+ "\n }\n";
}
}
@ -222,22 +224,22 @@ class EntityTypeRelation<T extends Node> {
}
static EntityTypeRelation<HsBookingItemType> requires(final HsBookingItemType bookingItemType) {
return new EntityTypeRelation<>(" ==> ", TypeRelationType.REQUIRED, bookingItemType);
return new EntityTypeRelation<>(" *==> ", TypeRelationType.REQUIRED, bookingItemType);
}
static EntityTypeRelation<HsHostingAssetType> optionalParent(final HsHostingAssetType hostingAssetType) {
return new EntityTypeRelation<>(" ==o ", TypeRelationType.OPTIONAL, hostingAssetType);
return new EntityTypeRelation<>(" o..> ", TypeRelationType.OPTIONAL, hostingAssetType);
}
static EntityTypeRelation<HsHostingAssetType> requiredParent(final HsHostingAssetType hostingAssetType) {
return new EntityTypeRelation<>(" ==> ", TypeRelationType.REQUIRED, hostingAssetType);
return new EntityTypeRelation<>(" *==> ", TypeRelationType.REQUIRED, hostingAssetType);
}
static EntityTypeRelation<HsHostingAssetType> assignedTo(final HsHostingAssetType hostingAssetType) {
return new EntityTypeRelation<>(" -.-> ", TypeRelationType.REQUIRED, hostingAssetType);
return new EntityTypeRelation<>(" o..> ", TypeRelationType.REQUIRED, hostingAssetType);
}
static EntityTypeRelation<HsHostingAssetType> optionallyAssignedTo(final HsHostingAssetType hostingAssetType) {
return new EntityTypeRelation<>(" -.-o ", TypeRelationType.OPTIONAL, hostingAssetType);
return new EntityTypeRelation<>(" o..> ", TypeRelationType.OPTIONAL, hostingAssetType);
}
}