Ejemplo n.º 1
0
    def post(self):

        valid = Validate().validate()

        if valid:
            owner_id = valid['owner_id']
            type = valid['type']
            graph_id = valid['_id']

            filterTrans = FilterTransformation()
            filters = filterTrans.transformation(valid)

            try:
                if filterTrans.is_("apps"):
                    entry_id = task_graphlookup.delay(owner_id=owner_id,
                                                      graph_id=graph_id,
                                                      entries=filters,
                                                      typed=type)
                else:
                    entry_id = task_entry.delay(filters=filters,
                                                graph_id=graph_id,
                                                owner_id=owner_id,
                                                typed=type)

                logger.info(entry_id)
                return str(entry_id), 201

            except Exception as error:
                task_notification.delay(graph_id=graph_id,
                                        msg=str(error),
                                        status='error')
                logger.error(error)
                return {'message': str(error)}, 501

        return valid, 502
Ejemplo n.º 2
0
def task_counter(_id):
    if not _id:
        logger.error("Scheduler: [TASK Counter] Missing ID", _id)
        return

    post = {'body': [{'_id': _id, '$inc': {'total_run_count': 1}}]}

    result = ExternalMaestroData() \
        .put_request(path="schedulers", body=post)

    if result:
        logger.debug("TASK Counter Success")

    return {'statuc_code': result.get_status()}
Ejemplo n.º 3
0
def task_send_to_front_app(owner_id, graph_id, payload):

    try:
        token = Jwt.create_tkn(graph_id, owner_id)
        access = Jwt.encode(token)
    except Exception as error:
        logger.error(error)
        task_notification.delay(graph_id=graph_id,
                                msg=str(error),
                                status="danger")

    headers = {'Authorization': 'JWT %s' % access.decode("utf-8")}

    ExternalMaestroAnalyticsFront(graph_id) \
        .set_headers(headers) \
        .post_request(path="graphs", body=payload)

    task_ws.delay(graph_id, owner_id)
    return {'graph_id': graph_id, 'owner_id': owner_id}
Ejemplo n.º 4
0
    def default(self, obj):
        val = None

        if isinstance(obj, (datetime.datetime, datetime.date, datetime.time)):
            val = obj.isoformat()

        if isinstance(obj, datetime.timedelta):
            val = (datetime.datetime.min + obj).time().isoformat()

        if isinstance(obj, (bytes, bytearray)):
            try:
                val = obj.decode('utf-8')
            except Exception as err:
                return logger.error(
                    "==================================> Decode is not utf-8")

        if val is None:
            val = json.JSONEncoder.default(self, obj)

        return val
Ejemplo n.º 5
0
    def error_handling(self, task, msg):

        if self.ent_id:
            return notify_error(task=task, msg=msg, graph_id=self.ent_id)

        logger.error("MaestroData:  [%s] - %s", task, msg)
Ejemplo n.º 6
0
 def error_handling(self, task, msg):
     self._error = "[%s] - %s" % (task, msg)
     logger.error("MaestroExternal: %s" % self._error)
Ejemplo n.º 7
0
 def error_handling(self, task='', msg=''):
     logger.error("MaestroData:  [%s] - %s", task, msg)
     task_notify_event.delay(msg=msg,
                             roles=self.templateRoles(),
                             description=msg,
                             status='danger')
Ejemplo n.º 8
0
# -*- encoding: utf-8 -*-
"""
Python Aplication Template
Licence: GPLv3
"""

import pymongo
from flask import Flask
from pymongo import MongoClient
from app.libs.logger import logger

app = Flask(__name__)
app.config.from_object('instance.config.Config')

client = MongoClient(app.config['DATABASE_URI'], serverSelectionTimeoutMS=1)
db = client[app.config['DATABASE_NAME']]

if __name__ != '__main__':
    gunicorn_logger = logger.getLogger('gunicorn.error')
    app.logger.handlers = gunicorn_logger.handlers
    app.logger.setLevel(gunicorn_logger.level)

try:
    client.server_info()
    logger.info("Mongo Online")
except pymongo.errors.ServerSelectionTimeoutError as err:
    logger.error("==================================> MongoDB is down %s", err)