Commit e9798b8d authored by Matthias's avatar Matthias
Browse files

implement MEMO-429

parent 18e654ac
Pipeline #11311 passed with stages
in 7 minutes and 17 seconds
......@@ -13,6 +13,7 @@ import import_api_app.configuration
from import_api_app.resources.WriteJobResultsToDrupal import WriteJobResultToDrupal
from import_api_app.resources.ReadJobOptionsFromDrupal import ReadJobOptionsFromDrupal
from import_api_app.resources.MonitorDrupalJsonApiInstitution import MonitorDrupalJsonApiInstitution
from import_api_app.resources.MonitorDrupalJsonApiRecordSet import MonitorDrupalJsonApiRecordSet
# from import_api_app.resources.HelmStart import HelmStart
# from import_api_app.resources.HelmStop import HelmStop
import os
......@@ -77,7 +78,8 @@ def create_app(test_config=None):
api.add_resource(WriteJobResultToDrupal, '/v1/drupal/<job_log_drupal_uuid>/<report>')
api.add_resource(ReadJobOptionsFromDrupal, '/v1/drupal/<job_name>/<job_drupal_uuid>')
api.add_resource(MonitorDrupalJsonApiInstitution, '/v1/drupal/<topic_name>')
api.add_resource(MonitorDrupalJsonApiInstitution, '/v1/drupal/institution/<topic_name>')
api.add_resource(MonitorDrupalJsonApiRecordSet, '/v1/drupal/recordset/<topic_name>')
api.add_resource(KafkaTopics, '/v1/kafka/topics')
api.add_resource(JobReport, '/v1/job/<topic_name>/report')
......
from flask_restful import Resource, current_app
from kafka import KafkaProducer
import requests
import json
class MonitorDrupalJsonApiRecordSet(Resource):
# Todo write/correct comment for swagger
def get(self, topic_name):
"""
Get uuid of updated recordset form drupal, gets more information form \
drupal and puts it into the dedicated kafka topic
---
tags:
- Monitor Drupal JSON API
parameters:
- in: path
name: topic_name
required: true
description: The UUID of the updated recordset
example: 0c4c777c-94f8-45ba-945a-bfe6967d40da
type: string
responses:
200:
description: Success, the information has been written into
the kafka topic
schema:
properties:
status:
type: string
example: SUCCESS/FAILURE
enum: ['SUCCESS', 'FAILURE']
topic_value:
type: string/json
example: the value written into the topic
"""
report = ''
topicValue = ''
# 1. request info from drupal with received uuid
try:
drupalResponse =\
requests.get('https://mb-wf1.memobase.unibas.ch/jsonapi/node/' +
'institution/' + topic_name).json()['data']
topicValue = {
'title': drupalResponse['attributes']['title'],
'field_address': drupalResponse['attributes']['field_address'],
'field_isil': drupalResponse['attributes']['field_isil'],
'field_memobase_id': drupalResponse['attributes']['field_memobase_id'],
'field_email': drupalResponse['attributes']['field_email'],
'field_website': drupalResponse['attributes']['field_website'],
'field_link_archive_catalog':
drupalResponse['attributes']['field_link_archive_catalog'],
'field_text': drupalResponse['attributes']['field_text'],
'field_import_process': drupalResponse['relationships']['field_import_process'],
'field_institution': drupalResponse['relationships']['field_institution']
}
except Exception as ex:
report += 'Exception' + str(ex) + '\n'
# 2. write info into kafka topic
try:
producer = KafkaProducer(bootstrap_servers=current_app.config['kafka-broker-url'],
value_serializer=lambda m: json.dumps(m, ensure_ascii=False)
.encode('utf-8'))
producer.send('drupal-json-api-institutions', topicValue)
except Exception as ex:
report += 'Exception' + str(ex) + '\n'
if report == '':
report = 'success'
return {
'status': 'SUCCESS',
'topic_value': topicValue,
'report': report
}, 200
else:
return {
'status': 'FAILURE',
'topic_value': topicValue,
'report': report
}, 200
Markdown is supported
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