import logging
import config
import traceback
from minio import Minio
from minio.error import ResponseError, BucketAlreadyOwnedByYou, BucketAlreadyExists
from data_importer import import_epv_from_s3_http
from graph_manager import BayesianGraph

logging.basicConfig()
logger = logging.getLogger(__name__)

# Check whether schema is created or not
# populate schema if not already done
try:
    status, json_result = BayesianGraph.populate_schema()
except Exception as exc:
    # Py2 compatibility: switch to "from exc" once we're on Py3
    new_exc = RuntimeError("Failed to initialize graph schema")
    new_exc.__cause__ = exc
    raise new_exc

if status:
    logger.info("Graph Schema Created")
else:
    logger.error(json_result)
    raise RuntimeError("Failed to setup graph schema")


def test_create_minio_bucket():
    """Test if buckets can be put into the Minio storage."""
Example #2
0
    reload(sys)
    sys.setdefaultencoding('UTF8')


app = Flask(__name__)
app.config.from_object('config')
CORS(app)

# Check whether schema is created or not
# populate schema if not already done
if not BayesianGraph.is_index_created():
    print("Index is not created as yet, checking schema creation")
    app.logger.info("Index is not created as yet, checking schema creation")
    if not BayesianGraph.is_schema_defined():
        print("Schema is not yet created, creating now...")
        BayesianGraph.populate_schema()
        # double check
        schema_definition_success = BayesianGraph.is_schema_defined()
        print("Double check: schema_definition_success %s" % schema_definition_success)
        if not schema_definition_success:
            raise RuntimeError("Failed to setup graph schema")
        else:
            print("Ready to serve requests")
else:
    print("Ready to serve requests")


@app.route('/api/v1/readiness')
def readiness():
    return flask.jsonify({}), 200