Commit c2f8c4da authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Initial implementation for cli library

parent d4d79a9a
from deployement.api.kafka import KafkaTopics
from kubernetes.client import CoreV1Api
class ConfigMap:
def __init__(self, **kwargs):
self.name = kwargs['name']
self.path = kwargs['path']
self.k8s = CoreV1Api()
def create(self):
with open(self.path, 'r') as fp:
self.k8s.create_namespaced_config_map(namespace='memobase', body=fp.read())
def delete(self):
self.k8s.delete_namespaced_config_map(name=self.name, namespace='memobase')
splitEntity:
- type: skos:Concept
property: skos:prefLabel
delimiter: ","
- type: rico:Agent
property: rico:name
delimiter: ","
- type: rico:Place
property: rico:name
delimiter: ","
- type: rico:Language
property: rico:name
delimiter: ","
\ No newline at end of file
apiVersion: v1
kind: ConfigMap
metadata:
name: ${name}
namespace: ${namespace}
data:
${file_name}: |
${content}
\ No newline at end of file
......@@ -22,7 +22,7 @@ class HelmChart:
self.fail_on_error = fail_on_error
self.wait = wait
def install(self, process_id: str, values: Union[Dict, str, None]) -> Union[CompletedProcess[str], CompletedProcess]:
def install(self, process_id: str, values: Union[Dict, str, None]) -> CompletedProcess:
"""Install the helm chart on the cluster.
Arguments
......@@ -48,7 +48,7 @@ class HelmChart:
helm_cmd.append("--wait")
return self._exec_command(helm_cmd, self.fail_on_error)
def uninstall(self, process_id: str) -> Union[CompletedProcess[str], CompletedProcess]:
def uninstall(self, process_id: str) -> CompletedProcess:
"""Uninstall the chart from the cluster.
Arguments
......@@ -65,7 +65,7 @@ class HelmChart:
return self._exec_command(helm_cmd, self.fail_on_error)
@staticmethod
def _exec_command(cmd, fail_on_err=True) -> Union[CompletedProcess[str], CompletedProcess]:
def _exec_command(cmd, fail_on_err=True) -> CompletedProcess:
base_cmd = [
"helm",
]
......
from kubernetes.client import CoreV1Api
from string import Template
class ConfigMap:
def __init__(self, **kwargs):
self.name = kwargs['name']
self.path = kwargs['path']
self.k8s = CoreV1Api()
with open('api/data/config_map_template.yml', 'r') as fp:
self.template = Template(fp.read())
def create(self, process_id: str):
with open(self.path, 'r') as fp:
content = fp.read()
body = Template(content).substitute(name=f'{process_id}-{self.name}', namespace='memobase')
# body = self.template.substitute(name=f'{process_id}-{self.name}',
# namespace='memobase',
# file_name=self.path.split('/')[-1],
# content=content)
print(body)
self.k8s.create_namespaced_config_map(namespace='memobase', body=body)
def delete(self, process_id: str):
self.k8s.delete_namespaced_config_map(name=f'{process_id}-{self.name}', namespace='memobase')
from deployement import KafkaTopics
from deployement.api.helm import all_charts
from deployement.api.kubernetes import ConfigMap
from api.kafka import KafkaTopics
from api.helm import all_charts
from api.kubernetes import ConfigMap
import json
......@@ -17,7 +17,7 @@ class ImportProcess:
def start(self):
self.topics.create()
for config_map in self.config_maps:
config_map.create()
config_map.create(self.process_id)
values = self.values['global']
for chart in self.charts:
if chart.name in self.values:
......@@ -28,5 +28,5 @@ class ImportProcess:
for chart in self.charts:
chart.uninstall(self.process_id)
for config_map in self.config_maps:
config_map.delete()
config_map.delete(self.process_id)
self.topics.delete()
apiVersion: v1
kind: ConfigMap
metadata:
name: ${name}
namespace: ${namespace}
data:
localTransforms.yml: |
splitEntity:
- type: skos:Concept
property: skos:prefLabel
delimiter: ","
- type: rico:Agent
property: rico:name
delimiter: ","
- type: rico:Place
property: rico:name
delimiter: ","
- type: rico:Language
property: rico:name
delimiter: ","
\ No newline at end of file
{
"configMaps": [
"config-maps": [
{
"path": "./becker/mappings/localTransform.yml",
"name": "-normalization-service-local-transform-config"
"path": "configurations/becker/mappings/localTransforms.yml",
"name": "normalization-service-local-transform-config"
},
{
"path": "./becker/mappings/mapping.yml",
"name": "-mapper-service-mapping-config"
"path": "configurations/becker/mappings/mapping.yml",
"name": "mapper-service-mapping-config"
}
],
"global": {
......@@ -22,6 +22,9 @@
"normalization-service",
"fedora-ingest-service"
],
"text-file-validation": {
"appDirectory": "./BECKER"
},
"table-data-transform": {
"sheetIndex": 1,
"headerCount": 1,
......
import json
from kubernetes.config import load_kube_config
from deployement.api.process import ImportProcess
from api.process import ImportProcess
load_kube_config()
......
import json
from kubernetes.config import load_kube_config
from deployement.api.process import ImportProcess
from api.process import ImportProcess
import os
print(os.getcwd())
load_kube_config()
......
apiVersion: v1
kind: ConfigMap
metadata:
name: p0001-normalization-service-local-transform-config
namespace: memobase
data:
localTransforms.yml: |
splitEntity:
- type: skos:Concept
property: skos:prefLabel
delimiter: ","
- type: rico:Agent
property: rico:name
delimiter: ","
- type: rico:Place
property: rico:name
delimiter: ","
- type: rico:Language
property: rico:name
delimiter: ","
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment