use of com.structurizr.Workspace in project java by structurizr.
the class StructurizrClient method putWorkspace.
/**
* Updates the given workspace.
*
* @param workspaceId the workspace ID
* @param workspace the workspace instance to update
* @throws StructurizrClientException if there are problems related to the network, authorization, JSON serialization, etc
*/
public void putWorkspace(long workspaceId, Workspace workspace) throws StructurizrClientException {
if (workspace == null) {
throw new IllegalArgumentException("The workspace must not be null.");
} else if (workspaceId <= 0) {
throw new IllegalArgumentException("The workspace ID must be a positive integer.");
}
try (CloseableHttpClient httpClient = HttpClients.createSystem()) {
if (mergeFromRemote) {
Workspace remoteWorkspace = getWorkspace(workspaceId);
if (remoteWorkspace != null) {
workspace.getViews().copyLayoutInformationFrom(remoteWorkspace.getViews());
workspace.getViews().getConfiguration().copyConfigurationFrom(remoteWorkspace.getViews().getConfiguration());
}
}
workspace.setId(workspaceId);
workspace.setThumbnail(null);
workspace.setLastModifiedDate(new Date());
workspace.setLastModifiedAgent(agent);
workspace.setLastModifiedUser(getUser());
workspace.countAndLogWarnings();
HttpPut httpPut = new HttpPut(url + WORKSPACE_PATH + workspaceId);
StringWriter stringWriter = new StringWriter();
if (encryptionStrategy == null) {
JsonWriter jsonWriter = new JsonWriter(false);
jsonWriter.write(workspace, stringWriter);
} else {
EncryptedWorkspace encryptedWorkspace = new EncryptedWorkspace(workspace, encryptionStrategy);
encryptionStrategy.setLocation(EncryptionLocation.Client);
EncryptedJsonWriter jsonWriter = new EncryptedJsonWriter(false);
jsonWriter.write(encryptedWorkspace, stringWriter);
}
StringEntity stringEntity = new StringEntity(stringWriter.toString(), ContentType.APPLICATION_JSON);
httpPut.setEntity(stringEntity);
addHeaders(httpPut, EntityUtils.toString(stringEntity), ContentType.APPLICATION_JSON.toString());
debugRequest(httpPut, EntityUtils.toString(stringEntity));
log.info("Putting workspace with ID " + workspaceId);
try (CloseableHttpResponse response = httpClient.execute(httpPut)) {
String json = EntityUtils.toString(response.getEntity());
if (response.getCode() == HttpStatus.SC_OK) {
debugResponse(response);
log.info(json);
} else {
ApiResponse apiResponse = ApiResponse.parse(json);
throw new StructurizrClientException(apiResponse.getMessage());
}
}
} catch (Exception e) {
log.error(e);
throw new StructurizrClientException(e);
}
}
use of com.structurizr.Workspace in project tutorials by eugenp.
the class StructurizrSimple method main.
public static void main(String[] args) throws Exception {
Workspace workspace = getSoftwareSystem();
addContainers(workspace);
addComponents(workspace);
addSpringComponents(workspace);
exportToPlantUml(workspace.getViews().getViewWithKey(SOFTWARE_SYSTEM_VIEW));
exportToPlantUml(workspace.getViews().getViewWithKey(CONTAINER_VIEW));
exportToPlantUml(workspace.getViews().getViewWithKey(COMPONENT_VIEW));
exportToPlantUml(workspace.getViews().getViewWithKey(JVM2_COMPONENT_VIEW));
addStyles(workspace.getViews());
// uploadToExternal(workspace);
}
use of com.structurizr.Workspace in project cia by Hack23.
the class AppPublicSystemDocumentation 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 System Documentation");
final Model model = workspace.getModel();
final ViewSet viewSet = workspace.getViews();
final Person userPerson = model.addPerson("User", "User of the system");
final Person adminPerson = model.addPerson("Admin", "Manager of the system");
final SoftwareSystem ciaSystem = model.addSoftwareSystem("Citizen Intelligence Agency System", "Tracking politicians like bugs!");
final SoftwareSystem riksdagenApiSystem = model.addSoftwareSystem(Location.External, "data.riksdagen.se", "Public API Swedish Parliament data");
final SoftwareSystem worldBankApiSystem = model.addSoftwareSystem(Location.External, "data.worldbank.org", "Public API Country indicators");
final SoftwareSystem valApiSystem = model.addSoftwareSystem(Location.External, "www.val.se", "Public API Swedish Election data");
final SoftwareSystem esvApiSystem = model.addSoftwareSystem(Location.External, "www.esv.se", "Public Data Swedish public sector spending data");
final Container loadBalancerContainer = ciaSystem.addContainer("Loadbalancer", "Loadbalancer", "ALB/ELB/Apache/Nginx/HaProxy");
final Container ciaWebContainer = ciaSystem.addContainer("Web Application", "Web Application", "Jetty/Java");
// final SpringComponentFinderStrategy springComponentFinderStrategy = new SpringComponentFinderStrategy(new FirstImplementationOfInterfaceSupportingTypesStrategy()
// ,new ReferencedTypesSupportingTypesStrategy(),new ReferencedTypesInSamePackageSupportingTypesStrategy());
// springComponentFinderStrategy.setIncludePublicTypesOnly(false);
// final ComponentFinder componentFinderWeb = new ComponentFinder(ciaWebContainer, "com.hack23.cia",
// springComponentFinderStrategy);
// componentFinderWeb.exclude(".*ui.application.web.*");
// componentFinderWeb.exclude(".*ui.application.views.common.pagelinks.*");
// componentFinderWeb.exclude(".*ui.application.views.admin.*");
// componentFinderWeb.exclude(".*ui.application.views.user.*");
//
// componentFinderWeb.exclude(".*service.external.*");
// componentFinderWeb.exclude(".*service.component.*");
// componentFinderWeb.exclude(".*package.*");
// componentFinderWeb.exclude(".*service.impl.action.*");
// componentFinderWeb.exclude(".*service.impl.email.*");
// componentFinderWeb.exclude(".*service.impl.rules.*");
// componentFinderWeb.exclude(".*service.impl.task.*");
// componentFinderWeb.exclude(".*service.data.impl.*");
// componentFinderWeb.findComponents();
final Container relationalDatabase = ciaSystem.addContainer("Database", "Stores information", "Postgresql");
relationalDatabase.addTags("Database");
adminPerson.uses(ciaSystem, "Manages");
userPerson.uses(ciaSystem, "Uses");
ciaSystem.uses(riksdagenApiSystem, "Loads data");
ciaSystem.uses(worldBankApiSystem, "Loads data");
ciaSystem.uses(valApiSystem, "Loads data");
ciaSystem.uses(esvApiSystem, "Loads data");
loadBalancerContainer.uses(ciaWebContainer, "HTTPS/H2");
ciaWebContainer.uses(relationalDatabase, "JDBC");
final SystemLandscapeView enterpriseContextView = viewSet.createSystemLandscapeView("\"Enterprise\"", "\"Enterprise\"");
enterpriseContextView.addAllElements();
final Enterprise enterprise = new Enterprise("Hack23");
enterpriseContextView.getModel().setEnterprise(enterprise);
viewSet.createSystemContextView(ciaSystem, "\"System context\"", "\"System context\"").addAllElements();
viewSet.createContainerView(ciaSystem, "\"Container view\"", "\"Application Overview\"").addAllContainers();
viewSet.createComponentView(ciaWebContainer, "\"Web\"", "\"Web\"").addAllComponents();
final DeploymentNode awsAccountNode = model.addDeploymentNode("AppOrg Account", "AWS", "Aws Account");
final DeploymentNode awsVpcNode = awsAccountNode.addDeploymentNode("Project Network", "AWS", "VPC");
final DeploymentNode wafNode = awsAccountNode.addDeploymentNode("Web Application Firewall", "AWS", "WAF");
final Container ciaWafContainer = ciaSystem.addContainer("WebACL Rules", "AWS", "WAF");
wafNode.add(ciaWafContainer);
ciaWafContainer.uses(loadBalancerContainer, "Protects/Filter");
final DeploymentNode awsAuditAccountNode = model.addDeploymentNode("Audit Account", "AWS", "Aws Account");
final DeploymentNode awsConfigNode = awsAuditAccountNode.addDeploymentNode("Config", "AWS", "Config");
final Container awsConfigContainer = ciaSystem.addContainer("Rules", "AWS", "Config Rules");
awsConfigNode.add(awsConfigContainer);
final DeploymentNode awsInspectorNode = awsAccountNode.addDeploymentNode("System Compliance checks", "AWS", "Inspector");
final Container awsInspectorContainer = ciaSystem.addContainer("ScanningRules", "AWS", "Scanning Rules");
awsInspectorNode.add(awsInspectorContainer);
awsInspectorContainer.uses(ciaWebContainer, "Inspects");
final DeploymentNode awsSSMNode = awsAccountNode.addDeploymentNode("Patch Compliance", "AWS", "System Mananger");
final Container awsSSMContainer = ciaSystem.addContainer("InventoryList", "AWS", "InventoryList");
awsSSMNode.add(awsSSMContainer);
awsSSMContainer.uses(ciaWebContainer, "Run Commands");
final DeploymentNode awsQuickSightNode = awsAccountNode.addDeploymentNode("Business analytics", "AWS", "QuickSight");
final Container awsQuickSightContainer = ciaSystem.addContainer("Dashboards", "AWS", "Dashboards");
awsQuickSightNode.add(awsQuickSightContainer);
awsQuickSightContainer.uses(relationalDatabase, "Loads Data");
final DeploymentNode awsGuardDutyNode = awsAuditAccountNode.addDeploymentNode("Guard Duty", "AWS", "GuardDuty");
final Container awsGuardDutyContainer = ciaSystem.addContainer("Intelligent threat detection and continuous monitoring", "AWS", "Intelligent threat detection and continuous monitoring");
awsGuardDutyNode.add(awsGuardDutyContainer);
final DeploymentNode awsMacieNode = awsAuditAccountNode.addDeploymentNode("A machine learning-powered security", "AWS", "macie");
final Container awsMacieContainer = ciaSystem.addContainer("discover, classify, and protect sensitive data", "AWS", "discover, classify, and protect sensitive data");
awsMacieNode.add(awsMacieContainer);
final DeploymentNode awsLogGroupNode = awsAuditAccountNode.addDeploymentNode("LogGroup", "AWS", "Cloudwatch");
final Container awsLogstreamContainer = ciaSystem.addContainer("Logstreams", "AWS", "LogStream");
awsLogGroupNode.add(awsLogstreamContainer);
ciaWebContainer.uses(awsLogstreamContainer, "Write logs");
relationalDatabase.uses(awsLogstreamContainer, "Write logs");
final DeploymentNode awsCloudtrailNode = awsAuditAccountNode.addDeploymentNode("Audit", "AWS", "Cloudtrail");
final Container awsAuditLogBucketContainer = ciaSystem.addContainer("LogBucket", "AWS", "S3");
awsCloudtrailNode.add(awsAuditLogBucketContainer);
final DeploymentNode awsAcessLogsNode = awsAuditAccountNode.addDeploymentNode("Access Logs", "AWS", "S3");
final Container awsAccessLogBucketContainer = ciaSystem.addContainer("AccessLogBucket", "AWS", "S3");
awsAcessLogsNode.add(awsAccessLogBucketContainer);
loadBalancerContainer.uses(awsAccessLogBucketContainer, "Write logs");
final DeploymentNode applicationLoadbalancerNode = awsAccountNode.addDeploymentNode("Application Loadbalancer", "AWS", "ALB");
applicationLoadbalancerNode.add(loadBalancerContainer);
wafNode.uses(applicationLoadbalancerNode, "Protects", "filter rules");
final DeploymentNode webNode = awsVpcNode.addDeploymentNode("Application", "AWS", "EC2", 2);
webNode.addDeploymentNode("Jetty", "Jetty", "JVM").add(ciaWebContainer);
applicationLoadbalancerNode.uses(webNode, "Uses", "https");
final DeploymentNode databaseNode = awsVpcNode.addDeploymentNode("Database", "AWS", "RDS", 2);
databaseNode.add(relationalDatabase);
webNode.uses(databaseNode, "Uses", "jdbc");
final DeploymentNode githubAccountNode = model.addDeploymentNode("Github Org", "Github", "Github Org");
final Container sourceCodeContainer = ciaSystem.addContainer("SCM", "Github", "Scm");
githubAccountNode.add(sourceCodeContainer);
final Container documentationContainer = ciaSystem.addContainer("Documentation", "Github", "Documentation");
githubAccountNode.add(documentationContainer);
final DeploymentNode devNetworkNode = model.addDeploymentNode("Dev Network", "AWS", "Dev Network");
final Container nexusContainer = ciaSystem.addContainer("Nexus", "Dev", "Nexus");
devNetworkNode.add(nexusContainer);
final Container sonarContainer = ciaSystem.addContainer("Sonarqube", "Dev", "Sonarqube");
devNetworkNode.add(sonarContainer);
final Container jenkinsContainer = ciaSystem.addContainer("Jenkins", "Dev", "Jenkins");
jenkinsContainer.uses(sourceCodeContainer, "builds");
jenkinsContainer.uses(sonarContainer, "Publish QA metrics", "https");
jenkinsContainer.uses(nexusContainer, "publish artifacts", "https");
jenkinsContainer.uses(documentationContainer, "publish Documentation", "https");
devNetworkNode.add(jenkinsContainer);
final DeploymentNode sumologicSecurityAccountNode = model.addDeploymentNode("Security Account", "Sumologic", "Sumologic Account");
final DeploymentNode sumologicNetworkSecurityDashboardNode = sumologicSecurityAccountNode.addDeploymentNode("Nework Security Dashboard", "AWS", "Nework Security Dashboard");
final DeploymentNode sumologicServerSecurityDashboardNode = sumologicSecurityAccountNode.addDeploymentNode("Server Security Dashboard", "AWS", "Server Security Dashboard");
final DeploymentNode sumologicAwsAccountSecurityDashboardNode = sumologicSecurityAccountNode.addDeploymentNode("AWS Account Security Dashboard", "AWS", "AWS Account Security Dashboard");
final DeploymentNode sumologicApplicationSecurityDashboardNode = sumologicSecurityAccountNode.addDeploymentNode("Application Security Dashboard", "AWS", "Application Security Dashboard");
final Container sumologicVpcFlowLogsContainer = ciaSystem.addContainer("VpcFlowLogs", "Sumologic", "VpcFlowLogs");
sumologicVpcFlowLogsContainer.uses(awsLogstreamContainer, "Recieve logs");
sumologicNetworkSecurityDashboardNode.add(sumologicVpcFlowLogsContainer);
final Container sumologicCloudtrailConfigContainer = ciaSystem.addContainer("CloudTrailLogs", "Sumologic", "CloudTrailLogs");
sumologicCloudtrailConfigContainer.uses(awsAuditLogBucketContainer, "Recieve logs");
sumologicAwsAccountSecurityDashboardNode.add(sumologicCloudtrailConfigContainer);
final Container sumologicAwsConfigContainer = ciaSystem.addContainer("AwsConfigLogs", "Sumologic", "AwsConfigLogs");
sumologicAwsConfigContainer.uses(awsConfigContainer, "Recieve logs");
sumologicAwsAccountSecurityDashboardNode.add(sumologicAwsConfigContainer);
final Container sumologicEc2SystemLogsContainer = ciaSystem.addContainer("Ec2SystemLogs", "Sumologic", "Ec2SystemLogs");
sumologicEc2SystemLogsContainer.uses(awsLogstreamContainer, "Recieve logs");
sumologicServerSecurityDashboardNode.add(sumologicEc2SystemLogsContainer);
final Container sumologicEc2ApplicationLogsContainer = ciaSystem.addContainer("Ec2ApplicationLogs", "Sumologic", "Ec2ApplicationLogs");
sumologicEc2ApplicationLogsContainer.uses(awsLogstreamContainer, "Recieve logs");
sumologicApplicationSecurityDashboardNode.add(sumologicEc2ApplicationLogsContainer);
final Container sumologicAwsInspectorResultsContainer = ciaSystem.addContainer("AwsInspectorResults", "Sumologic", "AwsInspectorResults");
sumologicAwsInspectorResultsContainer.uses(awsInspectorContainer, "Recieve reports");
sumologicServerSecurityDashboardNode.add(sumologicAwsInspectorResultsContainer);
final Container sumologicAwsAlbLogsContainer = ciaSystem.addContainer("AwsLoadbalancerAccessLogs", "Sumologic", "AwsLoadbalancerAccessLogs");
sumologicAwsAlbLogsContainer.uses(awsAccessLogBucketContainer, "Recieve logs");
sumologicNetworkSecurityDashboardNode.add(sumologicAwsAlbLogsContainer);
final DeploymentView developmentDeploymentView = viewSet.createDeploymentView(ciaSystem, "\"Deployment\"", "\"Deployment Aws.\"");
developmentDeploymentView.add(awsAuditAccountNode);
developmentDeploymentView.add(wafNode);
developmentDeploymentView.add(awsQuickSightNode);
developmentDeploymentView.add(awsInspectorNode);
developmentDeploymentView.add(awsSSMNode);
developmentDeploymentView.add(sumologicSecurityAccountNode);
developmentDeploymentView.add(githubAccountNode);
developmentDeploymentView.add(devNetworkNode);
developmentDeploymentView.add(applicationLoadbalancerNode);
developmentDeploymentView.add(webNode);
developmentDeploymentView.add(databaseNode);
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);
// StructurizrClient structurizrClient = new StructurizrClient(API_KEY,
// API_SECRET);
// structurizrClient.putWorkspace(WORKSPACE_ID, workspace);
printPlantUml(workspace);
System.setProperty("PLANTUML_LIMIT_SIZE", "16384");
Run.main(new String[] { Paths.get(".").toAbsolutePath().normalize().toString() + File.separator + "target" + File.separator + "site" + File.separator + "architecture" + File.separator });
}
use of com.structurizr.Workspace in project agile-architecture-documentation-system by Riduidel.
the class SequenceDiagramVisitorTest method can_read_a_model.
@Test
@Disabled
void can_read_a_model() {
// Given all those elements
Workspace workspace = new Workspace("test workspace", "test workspace");
Model model = workspace.getModel();
SoftwareSystem system = model.addSoftwareSystem("agile-architecture-documentation-system");
Container sequenceGenerator = system.addContainer("sequence-generator", "generator", "Java/Maven");
sequenceGenerator.addProperty(SequenceGenerator.GENERATES_WITH, StructurizrUtils.getCanonicalPath(sequenceGenerator));
sequenceGenerator.addProperty(ModelElementKeys.JAVA_SOURCES, new File("src/main/java").toURI().toString());
Component visitor = sequenceGenerator.addComponent(SequenceDiagramVisitor.class.getSimpleName(), "visitor building the sequence");
visitor.addSupportingType(SequenceDiagramVisitor.class.getName());
Component callGraphModel = sequenceGenerator.addComponent(CallGraphModel.class.getSimpleName(), "navigator accumulating data");
callGraphModel.addSupportingType(CallGraphModel.class.getName());
Component generator = sequenceGenerator.addComponent(SequenceDiagramGenerator.class.getSimpleName(), "Component producing the sequence diagram");
generator.addSupportingType(SequenceDiagramGenerator.class.getName());
// Let's build a sequence diagram visitor
SequenceDiagramVisitor tested = new SequenceDiagramVisitor();
tested.logger = Logger.getLogger(getClass().getName());
tested.destination = new File("target/tests/" + getClass().getSimpleName());
// Emulate the standard visit
tested.startVisit(model);
tested.startVisit(system);
assertThat(tested.allContainers).hasSize(1);
assertThat(tested.codeToComponents).hasSize(3);
assertThat(tested.callGraphModel).isNull();
// And finally, visit the container and parse source code
tested.startVisit(sequenceGenerator);
assertThat(tested.callGraphModel).isNotNull();
// And visit components to see what happens
assertThat(tested.startVisit(visitor)).isTrue();
// And that something is generated
tested.endVisit(visitor, new SimpleOutputBuilder(tested.destination));
assertThat(tested.destination).isDirectoryContaining(file -> file.getName().equals(system.getName()));
}
use of com.structurizr.Workspace in project agile-architecture-documentation-system by Riduidel.
the class ArchitectureDocumentationBuilder method run.
/**
* Run method that will allow the description to be invoked and augmentations to be performed
* prior to have elements written. You should not have to overwrite this method.
* @throws IOException
*/
public void run() throws IOException {
Workspace workspace = getArchitecture();
logger.info("Architecture has been described. Now enhancing it (including writing the diagrams)!");
enhancer.enhance(workspace);
}
Aggregations