- Timestamp:
- Mar 1, 2020, 12:25:19 PM (7 years ago)
- Branches:
- debian/bullseye, master
- Children:
- f601952
- Parents:
- bd0cb38
- Location:
- src
- Files:
-
- 5 added
- 14 edited
- 1 moved
-
common/icon/log-deployed.svg (moved) (moved from src/common/icon/log-processed.svg )
-
mapservice-webclient/src/app/logs/logs.component.html (modified) (1 diff)
-
mapservice-webclient/src/app/mygnuboat/logadd.component.ts (modified) (3 diffs)
-
mapservice-webclient/webpack.config.js (modified) (1 diff)
-
mapservice/codegen/code_generator (modified) (4 diffs)
-
mapservice/codegen/templates/__init__.mustache (modified) (1 diff)
-
mapservice/codegen/templates/__main__.mustache (modified) (1 diff)
-
mapservice/codegen/templates/requirements.mustache (modified) (1 diff)
-
mapservice/openapi.yaml (modified) (1 diff)
-
mapservice/src/server_impl/CeleryWorker.py (added)
-
mapservice/src/server_impl/Config.py (modified) (2 diffs)
-
mapservice/src/server_impl/__init__.py (modified) (1 diff)
-
mapservice/src/server_impl/controllers/LogsController.py (modified) (3 diffs)
-
mapservice/src/server_impl/controllers/UsersController.py (modified) (2 diffs)
-
mapservice/src/server_impl/database/Model.py (modified) (5 diffs)
-
mapservice/src/server_impl/tasks/__init__.py (added)
-
mapservice/src/server_impl/tasks/tasks.py (added)
-
mapservice/templates/activation_mail.html (modified) (1 diff)
-
mapservice/templates/log_parsed.html (added)
-
mapservice/templates/log_parsing_error.html (added)
Legend:
- Unmodified
- Added
- Removed
-
src/mapservice-webclient/src/app/logs/logs.component.html
rbd0cb38 ra88607b 29 29 <img *ngSwitchCase="2" class="pure-img state-icon" src='/resources/log-queued.svg' title='Status: {{log.processingState.label}}'> 30 30 <img *ngSwitchCase="3" class="pure-img state-icon" src='/resources/processing.svg' title='Status: {{log.processingState.label}}'> 31 <img *ngSwitchCase="4" class="pure-img state-icon" src='/resources/log-processed.svg' title='Status: {{log.processingState.label}}'> 32 <img *ngSwitchCase="4" class="pure-img state-icon" src='/resources/log-excluded.svg' title='Status: {{log.processingState.label}}'> 31 <img *ngSwitchCase="4" class="pure-img state-icon" src='/resources/log-queued.svg' title='Status: {{log.processingState.label}}'> 32 <img *ngSwitchCase="5" class="pure-img state-icon" src='/resources/processing.svg' title='Status: {{log.processingState.label}}'> 33 <img *ngSwitchCase="6" class="pure-img state-icon" src='/resources/log-deployed.svg' title='Status: {{log.processingState.label}}'> 34 <img *ngSwitchCase="7" class="pure-img state-icon" src='/resources/log-excluded.svg' title='Status: {{log.processingState.label}}'> 33 35 <img *ngSwitchDefault class="pure-img state-icon" src='/resources/log-undefined.svg' title='Status: {{log.processingState.label}}'> 34 36 </td> -
src/mapservice-webclient/src/app/mygnuboat/logadd.component.ts
rbd0cb38 ra88607b 16 16 id: number, 17 17 originalObject: {}, 18 }19 20 interface LogCreated {21 metaData: LogMetaData,22 logGeoJson: LogGeoJson,23 18 } 24 19 … … 33 28 currentUser: User = undefined; 34 29 @Output() cancel = new EventEmitter(); 35 @Output() logCreated = new EventEmitter<LogCreated>();36 30 @ViewChild('logFileInput') logFileInput; 37 31 … … 218 212 this.logsService.logsLogCreate(logCreation).pipe(first()).subscribe(result => { 219 213 this.logsService.logsLogUpload(result.logId, new Blob([fileReader.result], {type: 'text/plain'})).pipe(first()).subscribe(resultUpload => { 220 var logCreated = {} as LogCreated;221 logCreated.metaData = result;222 logCreated.logGeoJson = resultUpload;223 this.logCreated.emit(logCreated);224 214 this.isUploading = false; 225 215 this.logForm.reset(); -
src/mapservice-webclient/webpack.config.js
rbd0cb38 ra88607b 50 50 { from: '../common/icon/processing.svg', to: 'resources' }, 51 51 { from: '../common/icon/log-excluded.svg', to: 'resources' }, 52 { from: '../common/icon/log- processed.svg', to: 'resources' },52 { from: '../common/icon/log-deployed.svg', to: 'resources' }, 53 53 { from: '../common/icon/log-queued.svg', to: 'resources' }, 54 54 { from: '../common/icon/log-undefined.svg', to: 'resources' } -
src/mapservice/codegen/code_generator
rbd0cb38 ra88607b 4 4 SRC_GEN="${DIR}/../src-gen" 5 5 TARGET="${SRC_GEN}/openapi_server/" 6 CELERY_WORKER_SCRIPT="${SRC_GEN}/celery_worker" 6 7 7 8 echo "Cleaning directory" … … 11 12 mkdir -p "${TARGET}" 12 13 cd "${TARGET}" 13 if [ ! -L server_impl ]; then 14 ln -s ../../src/server_impl/ 15 fi 14 #if [ ! -L server_impl ]; then 15 # ln -s ../../src/server_impl/ 16 #fi 17 mkdir -p server_impl 18 cp -a ../../src/server_impl/* server_impl/ 19 #mv server_impl/CeleryWorker.py ./ 16 20 17 21 #echo "Copying static files" … … 27 31 mkdir -p templates 28 32 cp -a ../../templates/* templates/ 33 ln -s ../templates server_impl/templates 29 34 30 35 echo "Generating backend and client API code" … … 37 42 38 43 44 echo "#!/bin/bash" > "${CELERY_WORKER_SCRIPT}" 45 echo 'export FLASK_ENV="development"' >> "${CELERY_WORKER_SCRIPT}" 46 echo "celery -A openapi_server.server_impl.CeleryWorker:celery worker -l info -E" >> "${CELERY_WORKER_SCRIPT}" 47 chmod +x "${CELERY_WORKER_SCRIPT}" 48 39 49 cd src-gen/ 40 50 tox > /tmp/openapi_tox.log 51 echo "###########################" 52 echo "#" 53 echo "# Do not forget to start the celery worker with" 54 echo "# 1. start RabbitMQ broker with" 55 echo "# sudo service rabbitmq-server start" 56 echo "# 2. start celery worker with" 57 echo "# cd ${SRC_GEN} && ${CELERY_WORKER_SCRIPT}" 58 echo "#" 59 echo "###########################" 60 export FLASK_ENV="development" 41 61 python3 -m openapi_server -
src/mapservice/codegen/templates/__init__.mustache
rbd0cb38 ra88607b 1 import connexion 2 from flask_cors import CORS 3 from flask_mail import Mail 1 #import connexion 2 #from flask_cors import CORS 3 #from flask_mail import Mail 4 #from celery import Celery 4 5 5 app = connexion.App(__name__, specification_dir='./openapi/') 6 application = app.app 7 CORS(application) 8 mail = Mail() 6 #app = connexion.App(__name__, specification_dir='./openapi/') 7 #application = app.app 8 #CORS(application) 9 #mail = Mail() 10 #celery = Celery(application.name) -
src/mapservice/codegen/templates/__main__.mustache
rbd0cb38 ra88607b 6 6 {{/supportPython2}} 7 7 8 import flask 9 from sqlalchemy import event 8 from {{packageName}}.server_impl import app, application, mail, celery, setup_app 10 9 11 from {{packageName}} import encoder, app, application, mail12 from {{packageName}}.server_impl.database.Model import db, User, ApiKey, db_setup, db_test_setup13 from {{packageName}}.server_impl.ValidatorWorkaround import ValidatorWorkaround14 15 @application.before_first_request16 def create_database():17 @event.listens_for(db.engine, "connect")18 def load_spatialite(dbapi_conn, connection_record):19 if 'sqlite' in flask.current_app.config['SQLALCHEMY_DATABASE_URI']:20 # From https://geoalchemy-2.readthedocs.io/en/latest/spatialite_tutorial.html21 dbapi_conn.enable_load_extension(True)22 dbapi_conn.load_extension('/usr/local/lib64/mod_spatialite')23 24 if flask.current_app.config['CREATE_TEST_DATABASE'] == True:25 db_test_setup()26 else:27 db_setup()28 29 @application.route("/mapservice/")30 def index():31 return render_template('index.html')32 33 10 def main(): 34 application.json_encoder = encoder.JSONEncoder 35 app.add_api('openapi.yaml', arguments={'title': '{{appName}}'}, validate_responses=True, strict_validation=True, validator_map={'response': ValidatorWorkaround}) 36 application.config.from_object('{{packageName}}.server_impl.Config.DevelopmentConfig') 37 38 db.init_app(application) 39 mail.init_app(application) 40 41 app.run(port={{serverPort}}) 11 setup_app('{{appName}}', 'DevelopmentConfig') 12 app.run(host=application.config.get("HOST", "localhost"), port=application.config.get("PORT", {{serverPort}})) 42 13 43 14 if __name__ == '__main__': -
src/mapservice/codegen/templates/requirements.mustache
rbd0cb38 ra88607b 13 13 sqlalchemy_utc 14 14 sqlalchemy-utils 15 celery 15 16 gnuboat_common -
src/mapservice/openapi.yaml
rbd0cb38 ra88607b 617 617 description: Logs uploaded 618 618 content: 619 application/ geo+json:620 schema: 621 $ref: '#/components/schemas/Log GeoJson'619 application/json: 620 schema: 621 $ref: '#/components/schemas/LogMetaData' 622 622 examples: 623 623 Log: 624 $ref: '#/components/examples/LogGeoJson' 625 application/json: 626 schema: 627 $ref: '#/components/schemas/Log' 628 examples: 629 Log: 630 $ref: '#/components/examples/Log' 624 $ref: '#/components/examples/LogMetaData' 631 625 '400': 632 626 $ref: '#/components/responses/BadRequest' -
src/mapservice/src/server_impl/Config.py
rbd0cb38 ra88607b 25 25 MAIL_DEFAULT_SENDER = 'GNUBoat Mapservice <gnuboat@engsas.de>' 26 26 MAPSERVICE_WEBCLIENT = '/' 27 CELERY_BROKER_URL = 'pyamqp://guest@localhost//' 28 CELERY_IMPORTS = ("openapi_server.server_impl.tasks") 27 29 28 30 class ProductionConfig(Config): … … 33 35 CREATE_TEST_DATABASE = True 34 36 MAPSERVICE_WEBCLIENT = 'http://localhost:8081' 37 #SERVER_NAME = 'gnuboat-mapservice:8080' 38 HOST = 'localhost' 39 SERVER_NAME = 'localhost:8080' 35 40 36 41 class TestingConfig(Config): -
src/mapservice/src/server_impl/__init__.py
rbd0cb38 ra88607b 1 ''' 2 Copyright (C) 2019 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. 3 4 This program is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 3 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 ''' 17 18 import connexion 19 import flask 20 from flask_cors import CORS 21 from flask_mail import Mail 22 from sqlalchemy import event 23 from celery import Celery 24 from werkzeug.utils import import_string 25 import os 26 27 from .. import encoder 28 from .database.Model import db, User, ApiKey, db_setup, db_test_setup 29 from .ValidatorWorkaround import ValidatorWorkaround 30 31 # determine requested configuration 32 if 'FLASK_ENV' in os.environ and os.environ['FLASK_ENV']: 33 config_name = os.environ['FLASK_ENV'].title() 34 else: 35 config_name = 'Production' 36 config_name = 'openapi_server.server_impl.Config.{}Config'.format(config_name) 37 config = import_string(config_name) 38 39 app = connexion.App(__name__, specification_dir='../openapi/') 40 application = app.app 41 CORS(application) 42 mail = Mail() 43 celery = Celery(__name__, broker=config.CELERY_BROKER_URL) 44 45 @application.before_first_request 46 def create_database(): 47 @event.listens_for(db.engine, "connect") 48 def load_spatialite(dbapi_conn, connection_record): 49 if 'sqlite' in flask.current_app.config['SQLALCHEMY_DATABASE_URI']: 50 # From https://geoalchemy-2.readthedocs.io/en/latest/spatialite_tutorial.html 51 dbapi_conn.enable_load_extension(True) 52 dbapi_conn.load_extension('/usr/local/lib64/mod_spatialite') 53 54 if flask.current_app.config['CREATE_TEST_DATABASE'] == True: 55 db_test_setup() 56 else: 57 db_setup() 58 59 @application.route("/mapservice/") 60 def index(): 61 return render_template('index.html') 62 63 def setup_app(app_name, config_name="Config"): 64 application.json_encoder = encoder.JSONEncoder 65 app.add_api('openapi.yaml', arguments={'title': app_name}, validate_responses=True, strict_validation=True, validator_map={'response': ValidatorWorkaround}) 66 application.config.from_object(config) 67 68 db.init_app(application) 69 mail.init_app(application) 70 celery.config_from_object(config) -
src/mapservice/src/server_impl/controllers/LogsController.py
rbd0cb38 ra88607b 17 17 import connexion 18 18 19 from gnuboat_common.datahandler import loghandler20 21 19 from ..database.Model import User, Log, LogEntry, Water, Device, Gauge, ProcessingStatus, Queue, db 22 20 from ..HttpErrors import MapserviceBadRequest, MapserviceUnauthorized, MapserviceNotFound 23 24 class LogEntryCallback: 25 def __init__(self): 26 self._entries = [] 27 self._start = None 28 self._end = None 29 30 def valid(self): 31 if self._start is None: 32 return False 33 if self._end is None: 34 return False 35 if len(self._entries) < 1: 36 return False 37 return True 38 39 def start(self): 40 return self._start 41 42 def end(self): 43 return self._end 44 45 def entries(self): 46 return self._entries 47 48 def callback(self, dataset): 49 self._entries.append(dataset) 50 51 # check / set start and end date 52 entry_datetime = dataset.datetime_object() 53 if self.start() is None or entry_datetime < self.start(): 54 self._start = entry_datetime 55 if self.end() is None or self.end() < entry_datetime: 56 self._end = entry_datetime 21 from ..tasks.tasks import log_parse 57 22 58 23 def logs_get(submitter=None, order_by=None, offset=None, limit=None): … … 129 94 raise MapserviceBadRequest(detail='No log data') 130 95 131 processing_state = ProcessingStatus.query.filter_by(label='Queued ').all()96 processing_state = ProcessingStatus.query.filter_by(label='Queued for Parsing').all() 132 97 if len(processing_state) != 1: 133 raise MapserviceBadRequest(detail='Processing status Queued not found database')98 raise MapserviceBadRequest(detail='Processing status Queued for Parsing not found database') 134 99 processing_state = processing_state[0] 135 100 … … 142 107 if LogEntry.query.filter_by(log=log).count() > 0: 143 108 raise MapserviceBadRequest(detail='Log {} has already log entries. Aborting'.format(log_id)) 144 145 # updating start / end of Log according to log file 146 body = body.decode() 147 log_callback = LogEntryCallback() 148 log_handler = loghandler.LogHandler() 149 result = log_handler.gnuboat_read(body.splitlines(), log_callback.callback, False, False) 150 if not result.success(): 151 raise MapserviceBadRequest(detail='Could not parse logfile: {}'.format('\n'.join(result.errors()))) 152 if not log_callback.valid(): 153 if len(log_callback.entries()) < 1: 154 raise MapserviceBadRequest(detail='No entry in logfile') 155 raise MapserviceBadRequest(detail='No start or end date found') 156 157 for entry in log_callback.entries(): 158 if entry.water_depth() is not None: 159 location = entry.location() 160 log_entry = LogEntry(log=log, datetime=entry.datetime_object(), location='SRID=4326;POINT({} {})'.format(location.longitude, location.latitude), water_depth=entry.water_depth()) 161 db.session.add(log_entry) 162 109 110 # Add Log to Queued table and change the processing state of Log 163 111 queue = Queue(log=log) 164 112 db.session.add(queue) 165 166 log.start = log_callback.start()167 log.end = log_callback.end()168 113 log.processingstatus = processing_state 169 170 114 db.session.commit() 171 115 172 if connexion.request.headers['Accept'] == "application/geo+json": 173 return log.to_geojson(), 200, {'Content-Type': 'application/geo+json; charset=utf-8'} 174 return log.log() 116 # request log parsing 117 log_parse.delay(log.id, body.decode()) 118 119 return log.meta_data() 175 120 176 121 def logs_log_delete(id): -
src/mapservice/src/server_impl/controllers/UsersController.py
rbd0cb38 ra88607b 24 24 from flask_mail import Message 25 25 26 from openapi_serverimport mail26 from .. import mail 27 27 from ..database.Model import User, ApiKey, db 28 28 from ..HttpErrors import MapserviceBadRequest, MapserviceUnauthorized, MapserviceNotFound … … 82 82 if user_creation is None: 83 83 raise MapserviceBadRequest(detail='No data specified') 84 if user_creation.username is None or user_creation.username == "":84 if user_creation.username is None or not user_creation.username: 85 85 raise MapserviceBadRequest(detail='No username given') 86 if user_creation.password is None or user_creation.password == "":86 if user_creation.password is None or not user_creation.password: 87 87 raise MapserviceBadRequest(detail='No password given') 88 if user_creation.first_name is None or user_creation.first_name == "":88 if user_creation.first_name is None or not user_creation.first_name: 89 89 raise MapserviceBadRequest(detail='No first name given') 90 if user_creation.last_name is None or user_creation.last_name == "":90 if user_creation.last_name is None or not user_creation.last_name: 91 91 raise MapserviceBadRequest(detail='No last name given') 92 if user_creation.email is None or user_creation.email == "":92 if user_creation.email is None or not user_creation.email: 93 93 raise MapserviceBadRequest(detail='No email given') 94 94 if not mail_regex.match(user_creation.email): -
src/mapservice/src/server_impl/database/Model.py
rbd0cb38 ra88607b 22 22 from geoalchemy2.shape import to_shape 23 23 from sqlalchemy_utc import UtcDateTime 24 from sqlalchemy_utils import create_view 24 from sqlalchemy_utils import create_view, database_exists, create_database 25 25 from shapely import wkb 26 26 import hashlib … … 218 218 @staticmethod 219 219 def insert_states(): 220 states = [ 'Undefined', 'Queued ', 'Processing', 'Processed', 'To Old' ]220 states = [ 'Undefined', 'Queued for Parsing', 'Parsing', 'Queued for Processing', 'Processing', 'Deployed', 'To Old', 'Error' ] 221 221 changed = False 222 222 for state in states: … … 366 366 367 367 def db_setup(): 368 if 'sqlite' in flask.current_app.config['SQLALCHEMY_DATABASE_URI']: 369 print("Initiate spatial meta data for Spatialite...") 370 db.engine.execute(select([func.InitSpatialMetaData()])) 371 print("...Finished") 372 db.create_all() 373 ProcessingStatus.insert_states() 368 if not database_exists(db.engine.url): 369 create_database(db.engine.url) 370 if 'sqlite' in flask.current_app.config['SQLALCHEMY_DATABASE_URI']: 371 print("Initiate spatial meta data for Spatialite...") 372 db.engine.execute(select([func.InitSpatialMetaData()])) 373 print("...Finished") 374 db.create_all() 375 ProcessingStatus.insert_states() 374 376 375 377 def db_test_setup(): … … 383 385 test_user_john = query[0] 384 386 else: 385 test_user_john = User.factory('john', 'testpass2', 'john@example.org' , license_accepted=True)387 test_user_john = User.factory('john', 'testpass2', 'john@example.org') 386 388 test_user_john.activation_code = 'dac9630aec642a428cd73f4be0a03569' 389 test_user_john.license_accepted = True 387 390 db.session.add(test_user_john) 388 391 db.session.commit() … … 393 396 test_user_jane = query[0] 394 397 else: 395 test_user_jane = User.factory('jane', 'testpass', 'jane@example.org' , license_accepted=True)398 test_user_jane = User.factory('jane', 'testpass', 'jane@example.org') 396 399 test_user_jane.activated = True 397 400 test_user_jane.first_name = 'Jane' 401 test_user_jane.license_accepted = True 398 402 db.session.add(test_user_jane) 399 403 db.session.commit() -
src/mapservice/templates/activation_mail.html
rbd0cb38 ra88607b 2 2 <p>thank you for supporting the project with your own measurings. All your measurings are handled under the <a href="https://www.opendatacommons.org/licenses/odbl/summary/index.html" target="_blank">Open Data Commons Open Database License (ODbL)</a>, which you have already accepted. It is the same license as OpenStreetmap uses.</p> 3 3 <p>To activate your GNUBoat account, you need ot visit <a href="{{activation_url}}">{{activation_url}}</a>.</p> 4 <p>Kind regards,<br> 5 Your GNUBOat team</p> 4 <p>Kind regards,<br>Your GNUBoat team</p>
Note:
See TracChangeset
for help on using the changeset viewer.
