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);
}
}
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 });
}
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;
}
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());
}
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));
}
Aggregations