Commit d926c45e authored by Matthias's avatar Matthias
Browse files

implement MEMO-433

parent 7a40c72f
Pipeline #11182 passed with stages
in 6 minutes and 41 seconds
......@@ -12,6 +12,7 @@ from import_api_app.resources.KafkaTopics import KafkaTopics
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.HelmStart import HelmStart
# from import_api_app.resources.HelmStop import HelmStop
import os
......@@ -76,6 +77,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(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 MonitorDrupalJsonApiInstitution(Resource):
# Todo write/correct comment for swagger
def get(self, topic_name):
"""
Get uuid of updated institution 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_value
required: true
description: The UUID of the updated institution
example: institutionXYZ-235323B
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/'
+ '0c4c777c-94f8-45ba-945a-bfe6967d40da').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']
}
except Exception as ex:
report += 'Exception' + str(ex) + '\n'
# 2. write info into kafka topic
# use kafka-procuder and topic 'drupal-json-api-institutions'
try:
# producer = KafkaProducer(bootstrap_servers=current_app.config['kafka-broker-url'])
# future = producer.send('drupal-json-api-institutions', "str(topicValue)")
producer = KafkaProducer(bootstrap_servers=current_app.config['kafka-broker-url'],
value_serializer=lambda m: json.dumps(m).encode('ascii'))
  • This would require me to read the values with ASCII as well.

    You can tell the library to not use ASCII -> json.dumps(m, ensure_ascii=False)

    @edelmatthias

Please register or sign in to reply
producer.send('drupal-json-api-institutions', topicValue)
except AssertionError as ex:
report += 'Exception' + str(ex) + '\n'
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