Commit b6f61546 authored by Lionel Walter's avatar Lionel Walter
Browse files

Load mapping.yml as configmap

parent 7c9d9f20
Pipeline #10763 passed with stages
in 9 minutes and 35 seconds
......@@ -27,6 +27,7 @@ class JobList(Resource):
# label_selector="jobType=import-job,institutionId=123"
# )
# todo add try except here
# only jobs which have import-job in the jobType job label
jobs = v1.list_namespaced_job(
namespace=current_app.config['NAMESPACE'],
......
from flask_restful import Resource, reqparse
from flask_restful import Resource, reqparse, current_app
from flasgger import swag_from
from import_api_app.models.Error import ImportApiError
......@@ -8,6 +8,10 @@ from import_api_app.resources.HelmStart import start
from import_api_app.resources.JobReport import get_report
from import_api_app.resources.WriteJobResultsToDrupal import write_results
from kubernetes import client
import requests
class JobStart(Resource):
# Todo validate requests
......@@ -38,9 +42,49 @@ class JobStart(Resource):
process_reporting_topic = f"{process_id}-reporting"
topics.append(process_reporting_topic)
# create job topics
if job_name == 'mapper-service':
# load mapping file from url
try:
# only allow mapping file at url starting with
mapping_file_url = job_parameters['configFileName']
if not(mapping_file_url.startswith(
'https://gitlab.switch.ch/memoriav/memobase-2020/'
)):
return {
'error': 'The url of the mapping file should start'
'with https://gitlab.switch.ch/memoriav/memobase-2020/'
}, 500
response = requests.get(mapping_file_url)
mapping_file_content = response.text
# Instantiate the configmap object
metadata = client.V1ObjectMeta(
labels=dict(app="import-api-app"),
name=process_id+"-mapper-service-mapping-config",
namespace=current_app.config['NAMESPACE'],
)
configmap = client.V1ConfigMap(
api_version="v1",
kind="ConfigMap",
data=dict(test=mapping_file_content),
metadata=metadata
)
v1 = client.CoreV1Api()
v1.create_namespaced_config_map(
namespace=current_app.config['NAMESPACE'],
body=configmap
)
except Exception:
return {
'error': 'impossible to load the mapping file as a config map. Url: '
+ mapping_file_url
}, 500
try:
create_topics(topics, True)
create_topics(topics)
except ImportApiError as e:
return {'error': e.message}, 500
......
......@@ -14,7 +14,11 @@ parameters:
appDirectory:
type: string
example: BAZ-B_MEI
description: The directory in the SFTP server
description: The directory in the SFTP server (for text-file-validation)
configFileName:
type: string
example: https://gitlab.switch.ch/memoriav/memobase-2020/services/import-process/import-process-cli/-/raw/master/baz/baz-b-mei/configs/mapping.yml
description: Url of the mapping file (for mapper-service)
drupalProcessUuid:
type: string
example: e43997f5-a80a-4c02-8dd0-cd67cdae10ab
......
......@@ -3,6 +3,7 @@ import import_api_app.helm as helm
from flasgger import swag_from
from import_api_app.utility import generate_helm_name
from subprocess import CalledProcessError
from kubernetes import client
class JobStop(Resource):
......@@ -18,6 +19,18 @@ class JobStop(Resource):
current_app.logger.debug("process_id : " + process_id)
current_app.logger.debug("job_name : " + job_name)
if job_name == 'mapper-service':
# delete config map
try:
v1 = client.CoreV1Api()
v1.delete_namespaced_config_map(
name=process_id+"-mapper-service-mapping-config",
namespace=current_app.config['NAMESPACE'],
)
except Exception:
return {'error': 'impossible to delete the configmap needed for mapping'}, 500
try:
output = helm_client.uninstall(
name=helm_name,
......
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