Search in sources :

Example 16 with DeploymentView

use of com.structurizr.view.DeploymentView in project kroki by yuzutech.

the class Structurizr method convert.

static byte[] convert(String source, FileFormat fileFormat, StructurizrPlantUMLExporter structurizrPlantUMLExporter, JsonObject options) {
    StructurizrDslParser parser = new StructurizrDslParser();
    try {
        parser.parse(source);
        Collection<View> views = parser.getWorkspace().getViews().getViews();
        if (views.isEmpty()) {
            throw new BadRequestException("Empty diagram, does not have any view.");
        }
        View selectedView;
        String viewKey = options.getString("view-key");
        if (viewKey != null && !viewKey.trim().isEmpty()) {
            Optional<View> viewFound = views.stream().filter(view -> Objects.equals(view.getKey(), viewKey)).findFirst();
            if (!viewFound.isPresent()) {
                throw new BadRequestException("Unable to find view for key: " + viewKey + ".");
            }
            selectedView = viewFound.get();
        } else {
            // take the first view if not specified
            selectedView = views.iterator().next();
        }
        final Diagram diagram;
        if (selectedView instanceof DynamicView) {
            diagram = structurizrPlantUMLExporter.export((DynamicView) selectedView);
        } else if (selectedView instanceof DeploymentView) {
            diagram = structurizrPlantUMLExporter.export((DeploymentView) selectedView);
        } else if (selectedView instanceof ComponentView) {
            diagram = structurizrPlantUMLExporter.export((ComponentView) selectedView);
        } else if (selectedView instanceof ContainerView) {
            diagram = structurizrPlantUMLExporter.export((ContainerView) selectedView);
        } else if (selectedView instanceof SystemContextView) {
            diagram = structurizrPlantUMLExporter.export((SystemContextView) selectedView);
        } else if (selectedView instanceof SystemLandscapeView) {
            diagram = structurizrPlantUMLExporter.export((SystemLandscapeView) selectedView);
        } else {
            throw new BadRequestException("View type is not supported: " + selectedView.getClass().getSimpleName() + ", must be a DynamicView, DeploymentView, ComponentView, ContainerView, SystemContextView or SystemLandscapeView.");
        }
        return Plantuml.convert(diagram.getDefinition(), fileFormat, new JsonObject());
    } catch (StructurizrDslParserException e) {
        String cause = e.getMessage();
        final String message;
        if (cause != null && !cause.trim().isEmpty()) {
            message = "Unable to parse the Structurizr DSL. " + cause + ".";
        } else {
            message = "Unable to parse the Structurizr DSL.";
        }
        throw new BadRequestException(message, e);
    }
}
Also used : Arrays(java.util.Arrays) DecodeException(io.kroki.server.error.DecodeException) DiagramSource(io.kroki.server.decode.DiagramSource) StructurizrDslParserException(com.structurizr.dsl.StructurizrDslParserException) View(com.structurizr.view.View) SystemLandscapeView(com.structurizr.view.SystemLandscapeView) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) DeploymentView(com.structurizr.view.DeploymentView) Diagram(com.structurizr.export.Diagram) BadRequestException(io.kroki.server.error.BadRequestException) ComponentView(com.structurizr.view.ComponentView) ContainerView(com.structurizr.view.ContainerView) DynamicView(com.structurizr.view.DynamicView) Collection(java.util.Collection) StructurizrPlantUMLExporter(com.structurizr.export.plantuml.StructurizrPlantUMLExporter) Vertx(io.vertx.core.Vertx) FileFormat(io.kroki.server.format.FileFormat) SourceDecoder(io.kroki.server.decode.SourceDecoder) Objects(java.util.Objects) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) StructurizrDslParser(com.structurizr.dsl.StructurizrDslParser) SystemContextView(com.structurizr.view.SystemContextView) Optional(java.util.Optional) Handler(io.vertx.core.Handler) StructurizrDslParser(com.structurizr.dsl.StructurizrDslParser) JsonObject(io.vertx.core.json.JsonObject) StructurizrDslParserException(com.structurizr.dsl.StructurizrDslParserException) View(com.structurizr.view.View) SystemLandscapeView(com.structurizr.view.SystemLandscapeView) DeploymentView(com.structurizr.view.DeploymentView) ComponentView(com.structurizr.view.ComponentView) ContainerView(com.structurizr.view.ContainerView) DynamicView(com.structurizr.view.DynamicView) SystemContextView(com.structurizr.view.SystemContextView) Diagram(com.structurizr.export.Diagram) ComponentView(com.structurizr.view.ComponentView) SystemContextView(com.structurizr.view.SystemContextView) BadRequestException(io.kroki.server.error.BadRequestException) SystemLandscapeView(com.structurizr.view.SystemLandscapeView) DynamicView(com.structurizr.view.DynamicView) ContainerView(com.structurizr.view.ContainerView) DeploymentView(com.structurizr.view.DeploymentView)

Example 17 with DeploymentView

use of com.structurizr.view.DeploymentView in project cia by Hack23.

the class AwsPublicSystemDocumentation method main.

/**
 * The main method.
 *
 * @param args
 *            the arguments
 * @throws Exception
 *             the exception
 */
public static void main(final String[] args) throws Exception {
    final Workspace workspace = new Workspace("Citizen Intelligence Agency", "Public Aws System Documentation");
    final Model model = workspace.getModel();
    final ViewSet viewSet = workspace.getViews();
    final SoftwareSystem ciaSystem = model.addSoftwareSystem("Citizen Intelligence Agency", "Tracking politicians like bugs!");
    final DeploymentNode masterAccountNode = model.addDeploymentNode("Master Account", "AWS", "Aws Account");
    final Container awsAccountContainer = ciaSystem.addContainer("Master Account", "AWS", "Aws Account");
    final DeploymentNode iamAccountNode = model.addDeploymentNode("IAM Account", "AWS", "Aws Account");
    final Container iamAccountContainer = ciaSystem.addContainer("IAM Account", "AWS", "Aws Account");
    final DeploymentNode devAccountNode = model.addDeploymentNode("Development Account", "AWS", "Aws Account");
    final Container devAccountContainer = ciaSystem.addContainer("Development Account", "AWS", "Aws Account");
    final DeploymentNode opCenterAccountNode = model.addDeploymentNode("Operation Center Account", "AWS", "Aws Account");
    final Container opCenterAccountContainer = ciaSystem.addContainer("Operation Center Account", "AWS", "Aws Account");
    final DeploymentNode auditAccountNode = model.addDeploymentNode("Audit Account", "AWS", "Aws Account");
    final Container auditAccountContainer = ciaSystem.addContainer("Audit Account", "AWS", "Aws Account");
    final DeploymentNode appAccountNode = model.addDeploymentNode("Application Account", "AWS", "Aws Account");
    final Container appAccountContainer = ciaSystem.addContainer("Application Account", "AWS", "Aws Account");
    awsAccountContainer.uses(iamAccountContainer, "create/restrict");
    awsAccountContainer.uses(devAccountContainer, "create/restrict");
    awsAccountContainer.uses(opCenterAccountContainer, "create/restrict");
    awsAccountContainer.uses(auditAccountContainer, "create/restrict");
    awsAccountContainer.uses(appAccountContainer, "create/restrict");
    awsAccountContainer.uses(auditAccountContainer, "publish event/audit");
    iamAccountContainer.uses(auditAccountContainer, "publish event/audit");
    devAccountContainer.uses(auditAccountContainer, "publish event/audit");
    opCenterAccountContainer.uses(auditAccountContainer, "publish event/audit");
    appAccountContainer.uses(auditAccountContainer, "publish event/audit");
    opCenterAccountContainer.uses(auditAccountContainer, "Monitor event/audit");
    iamAccountContainer.uses(devAccountContainer, "manage access");
    iamAccountContainer.uses(appAccountContainer, "manage access");
    iamAccountContainer.uses(opCenterAccountContainer, "manage access");
    opCenterAccountNode.add(opCenterAccountContainer);
    devAccountNode.add(devAccountContainer);
    auditAccountNode.add(auditAccountContainer);
    appAccountNode.add(appAccountContainer);
    iamAccountNode.add(iamAccountContainer);
    masterAccountNode.add(awsAccountContainer);
    final DeploymentView developmentDeploymentView = viewSet.createDeploymentView(ciaSystem, "\"Production Aws Account structure\"", "\"Production Aws Account structure\"");
    developmentDeploymentView.add(masterAccountNode);
    developmentDeploymentView.add(iamAccountNode);
    developmentDeploymentView.add(devAccountNode);
    developmentDeploymentView.add(opCenterAccountNode);
    developmentDeploymentView.add(auditAccountNode);
    developmentDeploymentView.add(appAccountNode);
    final Styles styles = viewSet.getConfiguration().getStyles();
    styles.addElementStyle(Tags.COMPONENT).background("#1168bd").color("#ffffff");
    styles.addElementStyle(Tags.CONTAINER).background("#1168bd").color("#ffffff");
    styles.addElementStyle(Tags.SOFTWARE_SYSTEM).background("#1168bd").color("#ffffff");
    styles.addElementStyle(Tags.PERSON).background("#519823").color("#ffffff").shape(Shape.Person);
    styles.addElementStyle("Database").shape(Shape.Cylinder);
    printPlantUml(workspace);
    System.setProperty("PLANTUML_LIMIT_SIZE", "8192");
    Run.main(new String[] { Paths.get(".").toAbsolutePath().normalize().toString() + File.separator + "target" + File.separator + "site" + File.separator + "architecture" + File.separator });
}
Also used : Container(com.structurizr.model.Container) ViewSet(com.structurizr.view.ViewSet) DeploymentNode(com.structurizr.model.DeploymentNode) Model(com.structurizr.model.Model) SoftwareSystem(com.structurizr.model.SoftwareSystem) Workspace(com.structurizr.Workspace) DeploymentView(com.structurizr.view.DeploymentView) Styles(com.structurizr.view.Styles)

Example 18 with DeploymentView

use of com.structurizr.view.DeploymentView in project dsl by structurizr.

the class DeploymentViewParser method parse.

DeploymentView parse(DslContext context, Tokens tokens) {
    if (tokens.hasMoreThan(DESCRIPTION_INDEX)) {
        throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
    }
    if (!tokens.includes(ENVIRONMENT_INDEX)) {
        throw new RuntimeException("Expected: " + GRAMMAR);
    }
    Workspace workspace = context.getWorkspace();
    String key = "";
    String scopeIdentifier = tokens.get(SCOPE_IDENTIFIER_INDEX);
    String environment = tokens.get(ENVIRONMENT_INDEX);
    if (context.getElement(environment) != null && context.getElement(environment) instanceof DeploymentEnvironment) {
        environment = context.getElement(environment).getName();
    }
    // check that the deployment environment exists in the model
    final String env = environment;
    if (context.getWorkspace().getModel().getDeploymentNodes().stream().noneMatch(dn -> dn.getEnvironment().equals(env))) {
        throw new RuntimeException("The environment \"" + environment + "\" does not exist");
    }
    String description = "";
    if (tokens.includes(DESCRIPTION_INDEX)) {
        description = tokens.get(DESCRIPTION_INDEX);
    }
    DeploymentView view;
    if ("*".equals(scopeIdentifier)) {
        if (tokens.includes(KEY_INDEX)) {
            key = tokens.get(KEY_INDEX);
        } else {
            key = removeNonWordCharacters(environment) + "-" + VIEW_TYPE;
        }
        validateViewKey(key);
        view = workspace.getViews().createDeploymentView(key, description);
    } else {
        Element element = context.getElement(scopeIdentifier);
        if (element == null) {
            throw new RuntimeException("The software system \"" + scopeIdentifier + "\" does not exist");
        }
        if (element instanceof SoftwareSystem) {
            if (tokens.includes(KEY_INDEX)) {
                key = tokens.get(KEY_INDEX);
            } else {
                key = removeNonWordCharacters(element.getName()) + "-" + removeNonWordCharacters(environment) + "-" + VIEW_TYPE;
            }
            validateViewKey(key);
            view = workspace.getViews().createDeploymentView((SoftwareSystem) element, key, description);
        } else {
            throw new RuntimeException("The element \"" + scopeIdentifier + "\" is not a software system");
        }
    }
    view.setEnvironment(environment);
    return view;
}
Also used : Element(com.structurizr.model.Element) SoftwareSystem(com.structurizr.model.SoftwareSystem) Workspace(com.structurizr.Workspace) DeploymentView(com.structurizr.view.DeploymentView)

Example 19 with DeploymentView

use of com.structurizr.view.DeploymentView in project dsl by structurizr.

the class DeploymentViewContentParserTests method test_parseExclude_RemovesAllRelationshipsFromAView_WhenAnExpressionIsSpecifiedWithAWildcard.

@Test
void test_parseExclude_RemovesAllRelationshipsFromAView_WhenAnExpressionIsSpecifiedWithAWildcard() {
    SoftwareSystem ss1 = model.addSoftwareSystem("SS1", "Description");
    SoftwareSystem ss2 = model.addSoftwareSystem("SS2", "Description");
    Relationship rel = ss1.uses(ss2, "Uses");
    DeploymentNode dn = model.addDeploymentNode("Live", "Live", "Description", "Technology");
    dn.add(ss1);
    dn.add(ss2);
    DeploymentView view = views.createDeploymentView("key", "Description");
    view.setEnvironment("Live");
    view.add(dn);
    DeploymentViewDslContext context = new DeploymentViewDslContext(view);
    context.setWorkspace(workspace);
    IdentifiersRegister elements = new IdentifiersRegister();
    elements.register("ss1", ss1);
    elements.register("ss2", ss2);
    context.setIdentifierRegister(elements);
    parser.parseExclude(context, tokens("exclude", "relationship==*"));
    assertEquals(0, view.getRelationships().size());
}
Also used : DeploymentView(com.structurizr.view.DeploymentView) Test(org.junit.jupiter.api.Test)

Example 20 with DeploymentView

use of com.structurizr.view.DeploymentView in project dsl by structurizr.

the class DeploymentViewContentParserTests method test_parseInclude_AddsTheElement_WhenTheElementIsASoftwareSystemInstance.

@Test
void test_parseInclude_AddsTheElement_WhenTheElementIsASoftwareSystemInstance() {
    DeploymentNode dn = model.addDeploymentNode("Live", "DN", "Description", "Technology");
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System");
    SoftwareSystemInstance softwareSystemInstance = dn.add(softwareSystem);
    IdentifiersRegister elements = new IdentifiersRegister();
    elements.register("element", softwareSystemInstance);
    DeploymentView view = views.createDeploymentView("key", "Description");
    view.setEnvironment("Live");
    DeploymentViewDslContext context = new DeploymentViewDslContext(view);
    context.setWorkspace(workspace);
    context.setIdentifierRegister(elements);
    parser.parseInclude(context, tokens("include", "element"));
    assertEquals(2, view.getElements().size());
    assertNotNull(view.getElementView(dn));
    assertNotNull(view.getElementView(softwareSystemInstance));
}
Also used : DeploymentView(com.structurizr.view.DeploymentView) Test(org.junit.jupiter.api.Test)

Aggregations

DeploymentView (com.structurizr.view.DeploymentView)31 Test (org.junit.jupiter.api.Test)27 SoftwareSystem (com.structurizr.model.SoftwareSystem)6 com.structurizr.model (com.structurizr.model)4 RelationshipView (com.structurizr.view.RelationshipView)4 Assertions (org.junit.jupiter.api.Assertions)4 Workspace (com.structurizr.Workspace)3 ArrayList (java.util.ArrayList)3 Container (com.structurizr.model.Container)2 DeploymentNode (com.structurizr.model.DeploymentNode)2 Model (com.structurizr.model.Model)2 Styles (com.structurizr.view.Styles)2 SystemLandscapeView (com.structurizr.view.SystemLandscapeView)2 ViewSet (com.structurizr.view.ViewSet)2 StructurizrDslParser (com.structurizr.dsl.StructurizrDslParser)1 StructurizrDslParserException (com.structurizr.dsl.StructurizrDslParserException)1 Diagram (com.structurizr.export.Diagram)1 StructurizrPlantUMLExporter (com.structurizr.export.plantuml.StructurizrPlantUMLExporter)1 Element (com.structurizr.model.Element)1 Enterprise (com.structurizr.model.Enterprise)1