Created
July 21, 2018 13:19
-
-
Save tomncooper/36101dca7e06dd2e735ee67adc4bd2e8 to your computer and use it in GitHub Desktop.
Creates a toy topology graph using gremlin. Set the number of instances for each component by supplying an integer as the 1st argument when you call the script.
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
import sys | |
from tests.local.graph_connect import graph_client | |
g = graph_client.graph_traversal | |
parallelism = int(sys.argv[1]) | |
components = {"Sp" : parallelism, "A" : parallelism, "B" : parallelism, | |
"C" : parallelism} | |
task_id = 0 | |
# Create all the nodes | |
print("Creating nodes") | |
for component, parallelism in components.items(): | |
print(f"Adding nodes for component {component}") | |
for _ in range(parallelism): | |
print(f"Creating node: {task_id}") | |
(g.addV("instance").property("component", component) | |
.property("task_id", task_id) | |
.next()) | |
task_id += 1 | |
# Create all the connections | |
print("Creating edges") | |
order = list(components.keys()) | |
for i, source_component in enumerate(order): | |
if i == (len(order) - 1): | |
break | |
print(f"Connecting instances of component {source_component}") | |
destination_component = order[i+1] | |
sources = (g.V().hasLabel("instance") | |
.has("component", source_component) | |
.toList()) | |
destinations = (g.V().hasLabel("instance") | |
.has("component", destination_component) | |
.toList()) | |
for j, source in enumerate(sources): | |
print(f"Connecting source vertex {j+1} of {len(sources)}") | |
for destination in destinations: | |
g.V(source).addE("logical").to(destination).next() | |
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment