Exemplo n.º 1
0
def jobqueue_create():
    if request.method == 'POST':
        jobqueue = JobQueue()
        jobqueue.name = request.form["name"]
        if request.form["parent"] != "":
            jobqueue.parent_jobqueue_id = request.form["parent"]
        if request.form["minimum_agents"] != "":
            jobqueue.minimum_agents = request.form["minimum_agents"]
        if request.form["maximum_agents"] != "":
            jobqueue.maximum_agents = request.form["maximum_agents"]
        if request.form["priority"] != "":
            jobqueue.priority = request.form["priority"]
        if request.form["weight"] != "":
            jobqueue.weight = request.form["weight"]

        db.session.add(jobqueue)
        db.session.flush()

        jobqueue.fullpath = jobqueue.path()
        db.session.add(jobqueue)
        db.session.commit()

        flash("Created new jobqueue \"%s\"." % jobqueue.name)

        return redirect(url_for("jobqueues_index_ui"), SEE_OTHER)
    else:
        jobqueues = JobQueue.query

        parent = request.args.get("parent", None)
        if parent:
            parent = int(parent)

        return render_template("pyfarm/user_interface/jobqueue_create.html",
                               parent=parent,
                               jobqueues=jobqueues)
    def test_insert(self):
        # A job can not be created without a jobtype, create one first
        jobtype = JobType()
        jobtype.name = "foo"
        jobtype.description = "this is a job type"
        jobtype_version = JobTypeVersion()
        jobtype_version.jobtype = jobtype
        jobtype_version.version = 1
        jobtype_version.classname = "Foobar"
        jobtype_version.code = ("""
            class Foobar(JobType):
                pass""").encode("utf-8")
        db.session.add(jobtype_version)

        queue = JobQueue()
        queue.name = "FooQueue"

        job = Job()
        job.title = "Test Job"
        job.jobtype_version = jobtype_version
        job.queue = queue

        tag = Tag()
        tag.jobs = [job]
        tag.tag = "foo456"
        db.session.add_all([tag, job])
        db.session.commit()
        model_id = tag.id
        job_id = job.id
        db.session.remove()
        result = Tag.query.filter_by(id=model_id).first()
        self.assertEqual(result.tag, "foo456")
        self.assertEqual(result.jobs[0].id, job_id)
Exemplo n.º 3
0
    def post(self):
        """
        A ``POST`` to this endpoint will create a new job queue.

        .. http:post:: /api/v1/jobqueues/ HTTP/1.1

            **Request**

            .. sourcecode:: http

                POST /api/v1/jobqueues/ HTTP/1.1
                Accept: application/json

                {
                    "name": "Test Queue"
                }


            **Response**

            .. sourcecode:: http

                HTTP/1.1 201 CREATED
                Content-Type: application/json

                {
                    "weight": 10,
                    "jobs": [],
                    "minimum_agents": null,
                    "priority": 5,
                    "name": "Test Queue",
                    "maximum_agents": null,
                    "id": 1,
                    "parent": null,
                    "parent_jobqueue_id": null
                }

        :statuscode 201: a new job queue was created
        :statuscode 400: there was something wrong with the request (such as
                         invalid columns being included)
        :statuscode 409: a job queue with that name already exists
        """
        jobqueue = JobQueue.query.filter_by(name=g.json["name"]).first()
        if jobqueue:
            return (jsonify(error="Job queue %s already exists" %
                            g.json["name"]), CONFLICT)

        jobqueue = JobQueue(**g.json)
        db.session.add(jobqueue)
        db.session.flush()

        jobqueue.fullpath = jobqueue.path()
        db.session.add(jobqueue)
        db.session.commit()

        jobqueue_data = jobqueue.to_dict()
        logger.info("Created job queue %s: %r", jobqueue.name, jobqueue_data)

        return jsonify(jobqueue_data), CREATED
Exemplo n.º 4
0
    def post(self):
        """
        A ``POST`` to this endpoint will create a new job queue.

        .. http:post:: /api/v1/jobqueues/ HTTP/1.1

            **Request**

            .. sourcecode:: http

                POST /api/v1/jobqueues/ HTTP/1.1
                Accept: application/json

                {
                    "name": "Test Queue"
                }


            **Response**

            .. sourcecode:: http

                HTTP/1.1 201 CREATED
                Content-Type: application/json

                {
                    "weight": 10,
                    "jobs": [],
                    "minimum_agents": null,
                    "priority": 5,
                    "name": "Test Queue",
                    "maximum_agents": null,
                    "id": 1,
                    "parent": null,
                    "parent_jobqueue_id": null
                }

        :statuscode 201: a new job queue was created
        :statuscode 400: there was something wrong with the request (such as
                         invalid columns being included)
        :statuscode 409: a job queue with that name already exists
        """
        jobqueue = JobQueue.query.filter_by(name=g.json["name"]).first()
        if jobqueue:
            return (jsonify(error="Job queue %s already exists" %
                            g.json["name"]), CONFLICT)

        jobqueue = JobQueue(**g.json)
        db.session.add(jobqueue)
        db.session.flush()

        jobqueue.fullpath = jobqueue.path()
        db.session.add(jobqueue)
        db.session.commit()

        jobqueue_data = jobqueue.to_dict()
        logger.info("Created job queue %s: %r", jobqueue.name, jobqueue_data)

        return jsonify(jobqueue_data), CREATED
Exemplo n.º 5
0
def jobqueue_create():
    if request.method == 'POST':
        jobqueue = JobQueue()
        jobqueue.name = request.form["name"]
        if request.form["parent"] != "":
            jobqueue.parent_jobqueue_id = request.form["parent"]
        if request.form["minimum_agents"] != "":
            jobqueue.minimum_agents = request.form["minimum_agents"]
        if request.form["maximum_agents"] != "":
            jobqueue.maximum_agents = request.form["maximum_agents"]
        if request.form["priority"] != "":
            jobqueue.priority = request.form["priority"]
        if request.form["weight"] != "":
            jobqueue.weight = request.form["weight"]

        db.session.add(jobqueue)
        db.session.flush()

        jobqueue.fullpath = jobqueue.path()
        db.session.add(jobqueue)
        db.session.commit()

        flash("Created new jobqueue \"%s\"." % jobqueue.name)

        return redirect(url_for("jobqueues_index_ui"), SEE_OTHER)
    else:
        jobqueues = JobQueue.query

        parent = request.args.get("parent", None)
        if parent:
            parent = int(parent)

        return render_template("pyfarm/user_interface/jobqueue_create.html",
                            parent=parent, jobqueues=jobqueues)
Exemplo n.º 6
0
def schema():
    """
    Returns the basic schema of :class:`.JobQueue`

    .. http:get:: /api/v1/jobqueues/schema HTTP/1.1

        **Request**

        .. sourcecode:: http

            GET /api/v1/jobqueues/schema HTTP/1.1
            Accept: application/json

        **Response**

        .. sourcecode:: http

            HTTP/1.1 200 OK
            Content-Type: application/json

            {
                "id": "INTEGER",
                "name": VARCHAR(255)",
                "minimum_agents": "INTEGER",
                "maximum_agents": "INTEGER",
                "priority": "INTEGER",
                "weight": "INTEGER",
                "parent_jobqueue_id": "INTEGER"
            }

    :statuscode 200: no error
    """
    return jsonify(JobQueue.to_schema()), OK
Exemplo n.º 7
0
def schema():
    """
    Returns the basic schema of :class:`.JobQueue`

    .. http:get:: /api/v1/jobqueues/schema HTTP/1.1

        **Request**

        .. sourcecode:: http

            GET /api/v1/jobqueues/schema HTTP/1.1
            Accept: application/json

        **Response**

        .. sourcecode:: http

            HTTP/1.1 200 OK
            Content-Type: application/json

            {
                "id": "INTEGER",
                "name": VARCHAR(255)",
                "minimum_agents": "INTEGER",
                "maximum_agents": "INTEGER",
                "priority": "INTEGER",
                "weight": "INTEGER",
                "parent_jobqueue_id": "INTEGER"
            }

    :statuscode 200: no error
    """
    return jsonify(JobQueue.to_schema()), OK
Exemplo n.º 8
0
    def test_assign_by_weight_additional_queues(self):
        jobtype_version = self.create_jobtype_version()
        high_queue = self.create_queue_with_job("heavyweight", jobtype_version)
        high_queue.weight = 6
        mid_queue = self.create_queue_with_job("mediumweight", jobtype_version)
        mid_queue.weight = 3
        low_queue = self.create_queue_with_job("lightweight", jobtype_version)
        low_queue.weight = 1
        db.session.add_all([high_queue, mid_queue, low_queue])

        # The presence of additional queues with arbitrary weights should not
        # make any difference if they aren't drawing any agents
        additional_queue1 = JobQueue(name="additional1", weight=10)
        additional_queue2 = JobQueue(name="additional2", weight=10)
        additional_queue3 = JobQueue(name="additional3", weight=10)
        db.session.add_all(
            [additional_queue1, additional_queue2, additional_queue3])

        db.session.commit()

        agents = []
        for i in range(0, 100):
            agent = Agent(hostname="agent%s" % i,
                          id=uuid.uuid4(),
                          ram=32,
                          free_ram=32,
                          cpus=1,
                          port=50000)
            db.session.add(agent)
            agents.append(agent)
        db.session.commit()

        for agent in agents:
            assign_tasks_to_agent(agent.id)

        self.assertGreaterEqual(high_queue.num_assigned_agents(), 59)
        self.assertLessEqual(high_queue.num_assigned_agents(), 61)

        self.assertGreaterEqual(mid_queue.num_assigned_agents(), 29)
        self.assertLessEqual(mid_queue.num_assigned_agents(), 31)

        self.assertGreaterEqual(low_queue.num_assigned_agents(), 9)
        self.assertLessEqual(low_queue.num_assigned_agents(), 11)
Exemplo n.º 9
0
    def create_queue_with_job(self, name, jobtype_version):
        queue = JobQueue(name=name)
        job = Job(title="Test Job %s" % name,
                  jobtype_version=jobtype_version,
                  queue=queue)

        for i in range(0, 100):
            task = Task(job=job, frame=i)
            db.session.add(task)
        db.session.add(job)
        db.session.flush()

        return queue
    def test_insert(self):
        # A job can not be created without a jobtype, create one first
        jobtype = JobType()
        jobtype.name = "foo"
        jobtype.description = "this is a job type"
        jobtype_version = JobTypeVersion()
        jobtype_version.jobtype = jobtype
        jobtype_version.version = 1
        jobtype_version.classname = "Foobar"
        jobtype_version.code = ("""
            class Foobar(JobType):
                pass""").encode("utf-8")
        db.session.add(jobtype_version)

        queue = JobQueue()
        queue.name = "FooQueue"

        job = Job()
        job.title = "Test Job"
        job.jobtype_version = jobtype_version
        job.queue = queue

        # Software requirement needs a software first
        software = Software()
        software.software = "foo"
        requirement = JobSoftwareRequirement()
        requirement.job = job
        requirement.software = software
        db.session.add(job)
        db.session.commit()
        job_id = job.id
        requirement_id = requirement.id
        requirement2 = JobSoftwareRequirement.query.\
            filter_by(id=requirement_id).first()
        self.assertEqual(requirement.job.id, job_id)
        self.assertEqual(requirement2.software.software, "foo")
        self.assertEqual(requirement2.min_version, None)
        self.assertEqual(requirement2.max_version, None)
Exemplo n.º 11
0
from flask.views import MethodView

from pyfarm.core.logger import getLogger
from pyfarm.core.enums import STRING_TYPES

from pyfarm.models.job import Job
from pyfarm.models.jobqueue import JobQueue
from pyfarm.master.application import db
from pyfarm.master.utility import jsonify, validate_with_model


logger = getLogger("api.jobqueues")


# Load model mappings once per process
JOBQUEUE_MODEL_MAPPINGS = JobQueue.types().mappings


def schema():
    """
    Returns the basic schema of :class:`.JobQueue`

    .. http:get:: /api/v1/jobqueues/schema HTTP/1.1

        **Request**

        .. sourcecode:: http

            GET /api/v1/jobqueues/schema HTTP/1.1
            Accept: application/json
 def test_jobqueue_schema(self):
     response = self.client.get("/api/v1/jobqueues/schema")
     self.assert_ok(response)
     schema = JobQueue.to_schema()
     self.assertEqual(response.json, schema)
Exemplo n.º 13
0
from flask import g
from flask.views import MethodView

from pyfarm.core.logger import getLogger
from pyfarm.core.enums import STRING_TYPES

from pyfarm.models.job import Job
from pyfarm.models.jobqueue import JobQueue
from pyfarm.master.application import db
from pyfarm.master.utility import jsonify, validate_with_model

logger = getLogger("api.jobqueues")

# Load model mappings once per process
JOBQUEUE_MODEL_MAPPINGS = JobQueue.types().mappings


def schema():
    """
    Returns the basic schema of :class:`.JobQueue`

    .. http:get:: /api/v1/jobqueues/schema HTTP/1.1

        **Request**

        .. sourcecode:: http

            GET /api/v1/jobqueues/schema HTTP/1.1
            Accept: application/json
Exemplo n.º 14
0
 def test_jobqueue_schema(self):
     response = self.client.get("/api/v1/jobqueues/schema")
     self.assert_ok(response)
     schema = JobQueue.to_schema()
     self.assertEqual(response.json, schema)