Ejemplo n.º 1
0
def api():
    data = {'title': 'vwmodels',
            'version': 1.0,
            'description': 'The model Server api endpoint for virtual watershed platform.',
            'models': load_schemas()
            }
    return jsonify(data)
Ejemplo n.º 2
0
def api():
    data = {
        'title': 'vwmodels',
        'version': 1.0,
        'description':
        'The model Server api endpoint for virtual watershed platform.',
        'models': load_schemas()
    }
    return jsonify(data)
Ejemplo n.º 3
0
def start(id):
    modelrun = ModelRun.query.get(id)
    if modelrun:
      if modelrun.progress_state==PROGRESS_STATES['NOT_STARTED']:
        schemas = load_schemas()
        schema = schemas[modelrun.model_name]
        needed_resources = set(schema['resources']['inputs'].keys())
        available_resources = set([r.resource_type for r in modelrun.resources])
        if needed_resources==available_resources:
          modelrun.progress_state = PROGRESS_STATES['QUEUED']
          modelrun = modelrun.update()
          task_id = celery.send_task('vwadaptor.run', args=[], kwargs={'modelrun_id':modelrun.id})
          return jsonify({'message':'ModelRun submitted in queue','modelrun':modelrun_serializer(modelrun)}), 200
        else:
          error = {'message':"ModelRun {0} Doesn't have the necessary resources attached".format(modelrun),'missing':list(needed_resources-available_resources)}
          return jsonify(error), 400
      else:
        error = {'message':PROGRESS_STATES_MSG[modelrun.progress_state].format(modelrun_id=modelrun.id)}
        return jsonify(error), 400
    else:
      err = {"message":"ModelRun {0} Not Found".format(id)}
      return jsonify(err), 404
Ejemplo n.º 4
0
def start(id):
    modelrun = ModelRun.query.get(id)
    if modelrun:
        if modelrun.progress_state == PROGRESS_STATES['NOT_STARTED']:
            schemas = load_schemas()
            schema = schemas[modelrun.model_name]
            needed_resources = set(schema['resources']['inputs'].keys())
            available_resources = set(
                [r.resource_type for r in modelrun.resources])
            if needed_resources == available_resources:
                modelrun.progress_state = PROGRESS_STATES['QUEUED']
                modelrun = modelrun.update()
                task_id = celery.send_task('vwadaptor.run',
                                           args=[],
                                           kwargs={'modelrun_id': modelrun.id})
                return jsonify({
                    'message': 'ModelRun submitted in queue',
                    'modelrun': modelrun_serializer(modelrun)
                }), 200
            else:
                error = {
                    'message':
                    "ModelRun {0} Doesn't have the necessary resources attached"
                    .format(modelrun),
                    'missing':
                    list(needed_resources - available_resources)
                }
                return jsonify(error), 400
        else:
            error = {
                'message':
                PROGRESS_STATES_MSG[modelrun.progress_state].format(
                    modelrun_id=modelrun.id)
            }
            return jsonify(error), 400
    else:
        err = {"message": "ModelRun {0} Not Found".format(id)}
        return jsonify(err), 404
Ejemplo n.º 5
0
def modelschema(model):
    data = load_schemas(model)
    return jsonify(data)
Ejemplo n.º 6
0
# -*- coding: utf-8 -*-
import os
import pytest
import json

from flask import url_for


from vwadaptor.user.models import User
from vwadaptor.helpers import modelrun_serializer
from .factories import UserFactory
from .conftest import TEST_DIR

from vwpy.modelschema import load_schemas

schemas = load_schemas()
class TestModelRun:
    def test_create_modelrun(self,testapp):
        modelrun=dict(title="test modelrun isnobal 1",model_name="isnobal",user_id=1)
        res = testapp.post_json('/api/modelruns', modelrun)
        assert res.status_code == 201
        assert bool(res.json['id'])
        assert len(res.json['resources'])==0

    def test_get_modelrun(self,testapp,modelrun):
        res = testapp.get('/api/modelruns/{id}'.format(id=modelrun.id))
        assert res.status_code == 200
        assert res.json['id']==modelrun.id

    def test_delete_modelrun(self,testapp,modelrun):
        res = testapp.delete('/api/modelruns/{id}'.format(id=modelrun.id))
Ejemplo n.º 7
0
# -*- coding: utf-8 -*-
import os
import pytest
import json

from flask import url_for

from vwadaptor.user.models import User
from vwadaptor.helpers import modelrun_serializer
from .factories import UserFactory
from .conftest import TEST_DIR

from vwpy.modelschema import load_schemas

schemas = load_schemas()


class TestModelRun:
    def test_create_modelrun(self, testapp):
        modelrun = dict(title="test modelrun isnobal 1",
                        model_name="isnobal",
                        user_id=1)
        res = testapp.post_json('/api/modelruns', modelrun)
        assert res.status_code == 201
        assert bool(res.json['id'])
        assert len(res.json['resources']) == 0

    def test_get_modelrun(self, testapp, modelrun):
        res = testapp.get('/api/modelruns/{id}'.format(id=modelrun.id))
        assert res.status_code == 200
        assert res.json['id'] == modelrun.id
Ejemplo n.º 8
0
                modelrun.resources.append(output_resource)
        modelrun.progress_state=PROGRESS_STATES['FINISHED']
        logging.info('done running::{modelrun}'.format(modelrun=modelrun))
    except:
        logging.info('Erorr Happended while running model:{modelrun}'.format(modelrun=modelrun))
        logging.info(traceback.format_exc())

        modelrun.progress_state=PROGRESS_STATES['ERROR']
    dbsession.commit()


LOG_FILE = 'model_runner.log'
logging.basicConfig(filename=LOG_FILE,level=logging.DEBUG,format='%(asctime)s %(message)s',datefmt='%m/%d/%Y %I:%M:%S')


modelschemas = load_schemas()
model_modules = load_model_modules(modelschemas)


if os.environ.get("VWADAPTOR_ENV") == 'prod':
    config = ProdConfig
else:
    config = DevConfig

db_engine = create_engine(config.SQLALCHEMY_DATABASE_URI)
# create a configured "Session" class
Session = sessionmaker(bind=db_engine)
# create a Session
session = Session()

Ejemplo n.º 9
0
def modelschema(model):
    data = load_schemas(model)
    return jsonify(data)