Last active
August 29, 2015 14:11
-
-
Save rvanbruggen/81b646bacd907d832c6e to your computer and use it in GitHub Desktop.
Prototyping a Graph Database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//for use in the Arrows tool on www.apcjones.com/arrows | |
<ul class="graph-diagram-markup" data-internal-scale="1" data-external-scale="1"> | |
<li class="node" data-node-id="0" data-x="-503" data-y="-142.51348876953125"> | |
<span class="caption">Company</span> | |
</li> | |
<li class="node" data-node-id="1" data-x="-299" data-y="-281.2999267578125"> | |
<span class="caption">Service</span> | |
</li> | |
<li class="node" data-node-id="6" data-x="-134.14306640625" data-y="-281.2999267578125"> | |
<span class="caption">Software</span> | |
</li> | |
<li class="node" data-node-id="7" data-x="-642.1857299804688" data-y="-304.2203369140625"> | |
<span class="caption">Deparment</span> | |
</li> | |
<li class="node" data-node-id="8" data-x="-773.2464599609375" data-y="-304.2203369140625"> | |
<span class="caption">User</span> | |
</li> | |
<li class="node" data-node-id="9" data-x="-773.2464599609375" data-y="-242.78485107421875"> | |
<span class="caption">User</span> | |
</li> | |
<li class="node" data-node-id="10" data-x="-773.2464599609375" data-y="-171.78485107421875"> | |
<span class="caption">User</span> | |
</li> | |
<li class="node" data-node-id="11" data-x="-642.1857299804688" data-y="31.48651123046875"> | |
<span class="caption">Department</span> | |
</li> | |
<li class="node" data-node-id="12" data-x="-299" data-y="-142.51348876953125"> | |
<span class="caption">Service</span> | |
</li> | |
<li class="node" data-node-id="13" data-x="-299" data-y="4.21514892578125"> | |
<span class="caption">Service</span> | |
</li> | |
<li class="node" data-node-id="14" data-x="-134.14306640625" data-y="4.21514892578125"> | |
<span class="caption">Hardware</span> | |
</li> | |
<li class="node" data-node-id="15" data-x="-134.14306640625" data-y="-142.51348876953125"> | |
<span class="caption">Software</span> | |
</li> | |
<li class="node" data-node-id="16" data-x="-773.2464599609375" data-y="31.48651123046875"> | |
<span class="caption">User</span> | |
</li> | |
<li class="relationship" data-from="0" data-to="1"> | |
<span class="type">USES</span> | |
</li> | |
<li class="relationship" data-from="1" data-to="6"> | |
<span class="type">USES</span> | |
</li> | |
<li class="relationship" data-from="0" data-to="7"> | |
<span class="type">PART_OF</span> | |
</li> | |
<li class="relationship" data-from="8" data-to="7"> | |
<span class="type">PART_OF</span> | |
</li> | |
<li class="relationship" data-from="9" data-to="7"></li> | |
<li class="relationship" data-from="10" data-to="7"></li> | |
<li class="relationship" data-from="11" data-to="0"></li> | |
<li class="relationship" data-from="0" data-to="12"></li> | |
<li class="relationship" data-from="0" data-to="13"></li> | |
<li class="relationship" data-from="13" data-to="6"></li> | |
<li class="relationship" data-from="13" data-to="14"></li> | |
<li class="relationship" data-from="13" data-to="15"></li> | |
<li class="relationship" data-from="16" data-to="11"></li> | |
<li class="relationship" data-from="12" data-to="6"></li> | |
<li class="relationship" data-from="12" data-to="15"></li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// for use in the GraphGen tool at http://graphgen.neoxygen.io/ | |
(customer:Company {name: company } *50) | |
(dept:Department {name: {randomElement:['IT','Sales','Marketing','Operations','Finance'] }} *100)-[:PART_OF *n..1]->(customer) | |
(u:User {name: fullName} *100)-[:PART_OF *1..1]->(dept) | |
(customer)-[:USES {percentage: {randomFloat:[2,0,1]}} *n..n]->(serv:Service {name: {randomElement:['Web','ERP','CRM','Mail','Calendar','Files']}} *10) | |
(serv)-[:USES *1..n]->(soft:Software {name: {randomElement:['OS','Database','Webserver']}} *3) | |
(serv)-[:USES *1..n]->(hard:Hardware {name: {randomElement:['Storage','Processor','Memory']}} *2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CMDB query examples | |
//set up the indexes | |
create index on :Software(name) | |
create index on :Hardware(name) | |
create index on :User(name) | |
//find the impact of a particular hardware failure on users | |
//// first we identify the different storage arrays | |
match (h:Hardware {name:"Storage"}) | |
return id(h) | |
//// then we look for the paths betweek the storage array that is creating problems to see who is impacted: in this case the one with id=865 | |
match (h:Hardware {name:"Storage"}),(u:User), p=AllShortestPaths((h)-[*..5]-(u)) | |
where id(h)=865 | |
return p; | |
// Same Query we can exttract the services affected as well | |
match (h:Hardware {name:"Storage"}),(u:User), p=AllShortestPaths((h)-[*..5]-(u)) | |
where id(h)=865 | |
with h, u, filter(n in nodes(p) where n:Service) as n | |
return h.name as HardwareName, u.name as UserName, extract (x in n | x.name) as ServiceName | |
//What hardware does a user use? | |
match p=Allshortestpaths((u:User {name:"Leland Blanda"})-[*..5]-(h:Hardware)) | |
return p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment