Пример #1
0
 def get(self):
     db = get_plasma_db()
     project_collection = db.get_collection('projects')
     projects = []
     for item in project_collection.find():
         projects.append(marshal(item, project))
     response = generate_response(200, projects)
     return response
Пример #2
0
 def delete(self, project_id):
     db = get_plasma_db()
     project_collection = db.get_collection('projects')
     deleted_project = project_collection.delete_one(
         {"project-id": project_id})
     if deleted_project.deleted_count == 1:
         response = generate_response(200)
     else:
         response = generate_response(404)
     return response
Пример #3
0
 def get(self, project_id):
     db = get_plasma_db()
     project_collection = db.get_collection('projects')
     result = project_collection.find_one({'project-id': project_id})
     if result:
         response_data = marshal(result, project)
         response = generate_response(200, response_data)
     else:
         response = generate_response(404)
     return response
Пример #4
0
 def get(self, execution_id):
     db = get_plasma_db()
     execution_collection = db.get_collection('executions')
     result = execution_collection.find_one({'execution-id': execution_id})
     if result:
         response_data = marshal(result, execution_pass)
         response = generate_response(200, response_data)
     else:
         response = generate_response(404)
     return response
Пример #5
0
 def delete(self, execution_id):
     db = get_plasma_db()
     execution_collection = db.get_collection('executions')
     deleted_execution = execution_collection.delete_one(
         {"execution-id": execution_id})
     if deleted_execution.deleted_count == 1:
         response = generate_response(200)
     else:
         response = generate_response(404)
     return response
Пример #6
0
 def get(self):
     db = get_plasma_db()
     settings_collection = db.get_collection('settings')
     result = settings_collection.find_one({'settings-type': 'general'})
     if result:
         response_data = marshal(result, settings)
         response = generate_response(200, response_data)
     else:
         response = generate_response(404)
     return response
Пример #7
0
def stop_workflow(client, execution_id):
    try:
        client.publish(execution_id, 'stop')
        db = get_plasma_db()
        execution = db.executions.find_one({"execution-id": execution_id})
        db.workflows.find_one_and_update(
            {'workflow-id': execution['workflow-id']}, {'$set': {
                'status': 4
            }})
        return True
    except Exception as e:
        logger.error('Failed to stop execution job  : ' + str(e))
        return False
Пример #8
0
def run_workflow(client, execution_job):
    try:
        client.publish('execution_queue', json.dumps(execution_job))
        db = get_plasma_db()
        db.workflows.find_one_and_update(
            {'workflow-id': execution_job['workflow-id']}, {
                '$set': {
                    'status': 1,
                    'execution-id': execution_job['execution-id']
                }
            })
        return True
    except Exception as e:
        logger.error('Failed to insert execution job in queue : ' + str(e))
        return False
Пример #9
0
 def put(self, project_id):
     parser = reqparse.RequestParser()
     parser.add_argument('update', type=dict, required=True,
                         help='values which need to be updated')
     args = parser.parse_args()
     db = get_plasma_db()
     project_collection = db.get_collection('projects')
     updated_resource = project_collection.find_one_and_update(
         {"project-id": project_id},
         {"$set": dict(args)['update']}
     )
     if updated_resource:
         response = generate_response(204)
     else:
         response = generate_response(404)
     return response
Пример #10
0
 def get(self):
     parser = reqparse.RequestParser()
     parser.add_argument('workflow-id', type=str, location='args')
     args = parser.parse_args()
     if args['workflow-id']:
         query = {'workflow-id': args['workflow-id']}
     else:
         query = {}
     print(query)
     db = get_plasma_db()
     execution_collection = db.get_collection('executions')
     executions = []
     for item in execution_collection.find(query):
         executions.append(marshal(item, execution_pass))
     response = generate_response(200, executions)
     return response
Пример #11
0
 def post(self, project_id):
     parser = reqparse.RequestParser()
     parser.add_argument('project-name', type=str,
                         required=True, help='project name')
     parser.add_argument('project-path', type=str,
                         required=True, help='project path')
     parser.add_argument('workflows', type=int, default=0,
                         help='number of connected workfows')
     parser.add_argument('models', type=int, default=0,
                         help='number of connected models')
     args = parser.parse_args()
     project_id = str(xxh32_intdigest(args['project-name']))
     args['project-id'] = project_id
     db = get_plasma_db()
     project_collection = db.get_collection('projects')
     project_collection.insert(dict(args))
     response_data = {'project-id': project_id}
     response = generate_response(201, response_data)
     return response
Пример #12
0
 def get(self, execution_id):
     db = get_plasma_db()
     execution = db.executions.find_one({'execution-id': execution_id})
     if not execution:
         response = generate_response(404)
     else:
         workflow = db.workflows.find_one(
             {'workflow-id': execution['workflow-id']})
         project = db.projects.find_one(
             {'project-id': workflow['project-id']})
         project_path = project['project-path']
         log_path = path.join(project_path, 'logs', execution_id + ".log")
         if path.exists(log_path):
             with open(log_path, 'r') as log_file:
                 log_data = log_file.read()
             response_data = {"logs": log_data}
             response = generate_response(200, response_data)
         else:
             response = generate_response(404)
     return response