Exemple #1
0
    def create(self, operator, inputs=None, outputs=None, **kwargs):
        if (inputs is not None
                or outputs is not None) and operator is not None:
            # Figure out node type
            if inputs is None and outputs is not None:
                node_type = NodeTypes.INPUT.value
            elif inputs is not None and outputs is None:
                node_type = NodeTypes.MIDDLE.value
            else:
                raise Exception("Invalid node type")

            if inputs is not None:
                if len(inputs) == 1:
                    op_type = OpTypes.UNARY.value
                elif len(inputs) == 2:
                    op_type = OpTypes.BINARY.value
                else:
                    raise Exception("Invalid number of inputs")
            else:
                op_type = OpTypes.OTHER.value

            if outputs is None:
                status = OpStatus.PENDING.value
            else:
                status = OpStatus.COMPUTED.value

            inputs = json.dumps(inputs)
            outputs = json.dumps(outputs)

            op = db.create_op(name=kwargs.get("name", None),
                              graph_id=g.graph_id,
                              node_type=node_type,
                              inputs=inputs,
                              outputs=outputs,
                              op_type=op_type,
                              operator=operator,
                              status=status,
                              params=json.dumps(kwargs))
            # Add op to queue
            if op.status != OpStatus.COMPUTED.value and op.status != OpStatus.FAILED.value:
                if g.graph_id is None:
                    q = RavQueue(name=QUEUE_HIGH_PRIORITY)
                    q.push(op.id)
                else:
                    q = RavQueue(name=QUEUE_LOW_PRIORITY)
                    q.push(op.id)

            return op
        else:
            raise Exception("Invalid parameters")
Exemple #2
0
def __create_math_op2(op1, operator, **kwargs):
    if op1 is None:
        raise Exception("Null Op")

    op = db.create_op(name=kwargs.get('name', None),
                      graph_id=g.graph_id,
                      node_type=NodeTypes.MIDDLE.value,
                      inputs=json.dumps([op1.id]),
                      outputs=json.dumps(None),
                      op_type=OpTypes.UNARY.value,
                      operator=operator,
                      status=OpStatus.PENDING.value)

    # Add op to queue
    if op.status != OpStatus.COMPUTED.value and op.status != OpStatus.FAILED.value:
        if g.graph_id is None:
            q = RavQueue(name=QUEUE_HIGH_PRIORITY)
            q.push(op.id)
        else:
            q = RavQueue(name=QUEUE_LOW_PRIORITY)
            q.push(op.id)

    return Op(id=op.id)
Exemple #3
0
from common import RavQueue

if __name__ == '__main__':
    QUEUE_HIGH_PRIORITY = "queue:high_priority"
    QUEUE_LOW_PRIORITY = "queue:low_priority"
    QUEUE_COMPUTING = "queue:computing"
    r = RavQueue(QUEUE_HIGH_PRIORITY)
    r.delete()
    r1 = RavQueue(QUEUE_LOW_PRIORITY)
    r1.delete()
    r2 = RavQueue(QUEUE_COMPUTING)
    r2.delete()
Exemple #4
0
from common import RavQueue
from common.constants import MYSQL_HOST, MYSQL_PORT, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE
from ravop.core import QUEUE_HIGH_PRIORITY, QUEUE_LOW_PRIORITY, Graph, Op
from common import db as db_manager

app = Flask(__name__, static_folder='static')
app.config["DEBUG"] = True
SQLALCHEMY_DATABASE_URI = 'mysql://{}:{}@{}:{}/{}?host={}?port={}'.format(
    MYSQL_USER, MYSQL_PASSWORD, MYSQL_HOST, MYSQL_PORT, MYSQL_DATABASE,
    MYSQL_HOST, MYSQL_PORT)
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)

queue_high_priority = RavQueue(name=QUEUE_HIGH_PRIORITY)
queue_low_priority = RavQueue(name=QUEUE_LOW_PRIORITY)


def get_queued_ops():
    high_priority_ops = []
    for i in range(queue_high_priority.__len__()):
        high_priority_ops.append(queue_high_priority.get(i))

    low_priority_ops = []
    for i in range(queue_low_priority.__len__()):
        low_priority_ops.append(queue_low_priority.get(i))

    return high_priority_ops, low_priority_ops

Exemple #5
0
def find_op():
    op = db.get_incomplete_op()

    if op is not None:
        return op
    else:
        q1 = RavQueue(name=QUEUE_HIGH_PRIORITY)
        q2 = RavQueue(name=QUEUE_LOW_PRIORITY)

        while True:
            op_id1 = None
            op_id2 = None

            if q1.__len__() > 0:
                op_id1 = q1.get(0)
            elif q2.__len__() > 0:
                op_id2 = q2.get(0)

            if op_id1 is None and op_id2 is None:
                return None

            ops = [op_id1, op_id2]

            for index, op_id in enumerate(ops):
                if op_id is None:
                    continue

                op = db.get_op(op_id=op_id)

                if op.graph_id is not None:
                    if db.get_graph(op.graph_id).status == "failed":
                        # Change this op's status to failed
                        if op.status != "failed":
                            db.update_op(op, status=OpStatus.FAILED.value)
                            continue

                    elif db.get_graph(op.graph_id).status == "computed":
                        if index == 0:
                            q1.pop()
                        elif index == 1:
                            q2.pop()
                        continue

                r = db.get_op_readiness(op)
                if r == "ready":
                    if index == 0:
                        q1.pop()
                    elif index == 1:
                        q2.pop()

                    return op
                elif r == "parent_op_failed":
                    if index == 0:
                        q1.pop()
                    elif index == 1:
                        q2.pop()

                    # Change this op's status to failed
                    if op.status != "failed":
                        db.update_op(op, status=OpStatus.FAILED.value)

            return None
Exemple #6
0
handler = logging.handlers.RotatingFileHandler(RAVSOCK_LOG_FILE)

logger.addHandler(handler)

sio = socketio.AsyncServer(cors_allowed_origins="*",
                           async_mode='aiohttp',
                           async_handlers=True)

# Creates a new Aiohttp Web Application
app = web.Application()

# Binds our Socket.IO server to our Web App instance
sio.attach(app)

# Instantiate queues
queue_high_priority = RavQueue(name=QUEUE_HIGH_PRIORITY)
queue_low_priority = RavQueue(name=QUEUE_LOW_PRIORITY)
queue_computing = RavQueue(name=QUEUE_COMPUTING)


# we can define aiohttp endpoints just as we normally
# would with no change
async def index(request):
    with open('ravclient/index.html') as f:
        return web.Response(text=f.read(), content_type='text/html')


"""
Connect and disconnect events
"""
Exemple #7
0
def clear_redis_queues():
    QUEUE_HIGH_PRIORITY = "queue:high_priority"
    QUEUE_LOW_PRIORITY = "queue:low_priority"
    QUEUE_COMPUTING = "queue:computing"
    r = RavQueue(QUEUE_HIGH_PRIORITY)
    r.delete()
    r1 = RavQueue(QUEUE_LOW_PRIORITY)
    r1.delete()
    r2 = RavQueue(QUEUE_COMPUTING)
    r2.delete()