Skip to content

Commit

Permalink
add neomodel templates
Browse files Browse the repository at this point in the history
  • Loading branch information
metacoma committed Feb 15, 2024
1 parent 9c89137 commit 9b85db0
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 12 deletions.
3 changes: 2 additions & 1 deletion files/neomodel/docker_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ docker run \
-e NEO4J_apoc_export_file_enabled=true \
-e NEO4J_apoc_import_file_enabled=true \
-e NEO4J_apoc_import_file_use__neo4j__config=true \
-e NEO4JLABS_PLUGINS=\[\"apoc\"\] \
--publish=7474:7474 --publish=7687:7687 \
--volume=`pwd`/plugins:/plugins \
neo4j:4.4.0

# -e NEO4JLABS_PLUGINS=\[\"apoc\"] \
2 changes: 2 additions & 0 deletions inventory/targets/fvwm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ parameters:
body: |
Module FvwmMFL
exec exec setxkbmap -layout 'us,ru' -option 'grp:caps_toggle,grp_led:caps'
Key L A M Exec exec i3lock
Key F12 A A exec exec import /home/bebebeko/Downloads/screenshot.png
tmuxinator:
windows:
Expand Down
2 changes: 1 addition & 1 deletion inventory/targets/kafka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ parameters:
strimzi_uninstall \${ns}
kafka_helm_install: |
helm upgrade --install --namespace ${kafka_k8s_namespace} ${kafka_cluster_name} ${kapitan_root}/files/helm-charts/strimzi-kafka-operator
helm upgrade --install --create-namespace --namespace ${kafka_k8s_namespace} ${kafka_cluster_name} ${kapitan_root}/files/helm-charts/strimzi-kafka-operator
kafka_helm_deinstall:
helm uninstall --namespace ${kafka_k8s_namespace} ${kafka_cluster_name}
Expand Down
34 changes: 24 additions & 10 deletions jsonnet/tmuxinator.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,34 @@ local pre = [

local arrayIf(arr, condition) = if condition then arr else [];


//
//std.join("\n", [std.join("\n", nestedArray) for nestedArray in pre])
local generate_pre(pre) =
if std.type(pre) == "array" then
if std.type(pre[0]) == "array" then
std.join("\n", [std.join("\n", nestedArray) for nestedArray in pre])
else
std.join("\n", pre)
else if std.type(pre) == "string" then
pre
else
"XXX";



{
"tmuxinator": {
name: p.target_name,
root: p.compiled_dir,
windows: [
{
[window_name]: {
pre: [
"source " + p.compiled_dir + "/functions.bash"
] + arrayIf(p.tmuxinator.windows[window_name].pre, std.objectHas(p.tmuxinator.windows[window_name], "pre")),
panes: p.tmuxinator.windows[window_name].panes,
}
} for window_name in std.objectFieldsAll(p.tmuxinator.windows)
]
windows: if std.objectHas(p.tmuxinator, "windows") then [
{
[window_name]: {
pre: "source " + p.compiled_dir + "/functions.bash\n" + if std.objectHas(p.tmuxinator.windows[window_name], "pre") then generate_pre(p.tmuxinator.windows[window_name]["pre"]) else "YY",
panes: p.tmuxinator.windows[window_name].panes
}
} for window_name in std.objectFieldsAll(p.tmuxinator.windows)
] else []
}
}

10 changes: 10 additions & 0 deletions templates/neomodel/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM alpine:latest
RUN apk add --update \
py3-pip \
graphviz-dev \
alpine-sdk
ADD . /processing/
WORKDIR /processing
RUN pip3 install -r ./requirements.txt
ENTRYPOINT [ "python3", "/processing/processing.py" ]

13 changes: 13 additions & 0 deletions templates/neomodel/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
IMAGE_REPO := {{ processing_name }}
IMAGE_TAG := latest
IMAGE_NAME := $(IMAGE_REPO):$(IMAGE_TAG)

build:
docker build -t $(IMAGE_NAME) .
run: build
$(eval NEO4J_PORT := $(shell kubectl get svc neo4j-admin -n neo4j -o jsonpath='{.spec.ports[?(@.name=="tcp-bolt")].nodePort}'))
$(eval NEO4J_HOST := $(shell minikube ip))
$(eval NEO4J_URL := bolt://$(NEO4J_HOST):$(NEO4J_PORT))
docker run --rm -it --network=host \
-e NEO4J_URL="$(NEO4J_URL)" \
$(IMAGE_NAME)
12 changes: 12 additions & 0 deletions templates/neomodel/classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% set p = inventory.parameters %}
{% for class_name, class_data in p.knowledge_graph.items() %}
# {{ class_name }}
class {{ class_name }}(StructuredNode):
{% for property_name, property in class_data.items() %}
{{ property_name -}} =
{%- if "type" in property and property.type|lower == "string" %}StringProperty()
{% elif "rel_to" in property %}
RelationshipTo('{{ property.rel_to.class }}', '{{ property.rel_to.type }}')
{% endif %}
{% endfor %}
{% endfor %}
47 changes: 47 additions & 0 deletions templates/neomodel/processing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% set p = inventory.parameters %}
import pika
import pprint
import json
import os
from neomodel import config
from neo4j import GraphDatabase

from neomodel import (config, StructuredNode, StringProperty, IntegerProperty,
UniqueIdProperty, RelationshipTo, One)

rabbitmq_url = os.getenv("RABBITMQ_URL")
neo4j_url = os.getenv("NEO4J_URL")
neo4j_username = os.getenv("NEO4J_USERNAME")
neo4j_password = os.getenv("NEO4J_PASSWORD")

config.DRIVER = GraphDatabase().driver(neo4j_url, auth=(neo4j_username, neo4j_password))

connection = pika.BlockingConnection(pika.URLParameters(rabbitmq_url))
rabbitmq_channel = connection.channel()

exchange_name = "io-context"
result = rabbitmq_channel.queue_declare(queue="", exclusive=True)
queue_name = result.method.queue

rabbitmq_channel.queue_bind(exchange=exchange_name, queue=queue_name)

{% for class_name, class_data in p.knowledge_graph.items() %}
# {{ class_name }}
class {{ class_name }}(StructuredNode):
{% for property_name, property in class_data.items() %}
{{ property_name -}} =
{%- if "type" in property and property.type|lower == "string" %}StringProperty()
{% elif "rel_to" in property %}
RelationshipTo('{{ property.rel_to.class }}', '{{ property.rel_to.type }}')
{% endif %}
{% endfor %}
{% endfor %}

def callback(ch, method, properties, body):
{{ processing.code | indent(4) }}

rabbitmq_channel.basic_consume(queue=queue_name, on_message_callback=callback, auto_ack=True)
print("Waiting for messages. To exit, press Ctrl+C")
rabbitmq_channel.start_consuming()


4 changes: 4 additions & 0 deletions templates/neomodel/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% for requirement in processing.requirements %}
{{ requirement }}
{% endfor %}

0 comments on commit 9b85db0

Please sign in to comment.