Skip to content

Commit

Permalink
manually merging origin/master
Browse files Browse the repository at this point in the history
  • Loading branch information
opalmer committed May 12, 2015
2 parents 130574e + 7557eb0 commit 2dfa294
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 65 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: python

python:
- 2.7
- 3.3
- 3.4

sudo: false
Expand Down
51 changes: 28 additions & 23 deletions pyfarm/models/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,32 +282,37 @@ class Agent(db.Model, ValidatePriorityMixin, ValidateWorkStateMixin,
#

tasks = db.relationship(
"Task", backref="agent", lazy="dynamic",
"Task",
backref="agent", lazy="dynamic",
doc="Relationship between an :class:`Agent` and any "
":class:`pyfarm.models.Task` objects")

tags = db.relationship("Tag", secondary=AgentTagAssociation,
backref=db.backref("agents", lazy="dynamic"),
lazy="dynamic",
doc="Tags associated with this agent")
software_versions = db.relationship("SoftwareVersion",
secondary=AgentSoftwareVersionAssociation,
backref=db.backref("agents",
lazy="dynamic"),
lazy="dynamic",
doc="software this agent has installed "
"or is configured for")
mac_addresses = db.relationship("AgentMacAddress", backref="agent",
lazy="dynamic",
doc="The MAC addresses this agent has",
cascade="save-update, merge, delete, "
"delete-orphan")
gpus = db.relationship("GPU",
secondary=GPUInAgent,
backref=db.backref("agents", lazy="dynamic"),
lazy="dynamic",
doc="The graphics cards that are installed in this "
"agent")
tags = db.relationship(
"Tag",
secondary=AgentTagAssociation,
backref=db.backref("agents", lazy="dynamic"),
lazy="dynamic",
doc="Tags associated with this agent")

software_versions = db.relationship(
"SoftwareVersion",
secondary=AgentSoftwareVersionAssociation,
backref=db.backref("agents", lazy="dynamic"),
lazy="dynamic",
doc="software this agent has installed or is configured for")

mac_addresses = db.relationship(
"AgentMacAddress", backref="agent",
lazy="dynamic",
doc="The MAC addresses this agent has",
cascade="save-update, merge, delete, delete-orphan")

gpus = db.relationship(
"GPU",
secondary=GPUInAgent,
backref=db.backref("agents", lazy="dynamic"),
lazy="dynamic",
doc="The graphics cards that are installed in this agent")

def is_offline(self):
return self.state == AgentState.OFFLINE
Expand Down
4 changes: 2 additions & 2 deletions pyfarm/models/gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# limitations under the License.

"""
GPU
===
GPU Model
=========
Model describing a given make and model of graphics card.
Every agent can have zero or more GPUs associated with it.
Expand Down
4 changes: 3 additions & 1 deletion pyfarm/models/jobqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ class JobQueue(db.Model, UtilityMixins, ReprMixin):
"path must be computed by recursively querying "
"the parent queues.")

#
# Relationship
#
parent = db.relationship(
"JobQueue",
remote_side=[id],
backref=db.backref("children", lazy="dynamic"),
doc="Relationship between this queue its parent")


def path(self):
# Import here instead of at the top to break circular dependency
from pyfarm.scheduler.tasks import cache_jobqueue_path
Expand Down
5 changes: 3 additions & 2 deletions pyfarm/models/jobtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class JobType(db.Model, UtilityMixins, ReprMixin):
doc="Human readable description of the job type. This field is not "
"required and is not directly relied upon anywhere.")


success_subject = db.Column(
db.Text,
nullable=True,
Expand Down Expand Up @@ -99,6 +98,9 @@ def validate_name(self, key, value):


class JobTypeVersion(db.Model, UtilityMixins, ReprMixin):
"""
Defines a specific jobtype version.
"""
__tablename__ = config.get("table_job_type_version")
__table_args__ = (UniqueConstraint("jobtype_id", "version"),)

Expand Down Expand Up @@ -133,7 +135,6 @@ class JobTypeVersion(db.Model, UtilityMixins, ReprMixin):
"together but not 2, 4, 6, 8. If this column is False "
"however the queue will batch non-contiguous tasks too.")


classname = db.Column(
db.String(config.get("job_type_max_class_name_length")),
nullable=True,
Expand Down
3 changes: 3 additions & 0 deletions pyfarm/models/pathmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class PathMap(db.Model, ReprMixin, UtilityMixins):
"agents, but is overridden by applying path maps "
"that do specify a tag.")

#
# Relationships
#
tag = db.relationship(
"Tag",
backref=db.backref("path_maps", lazy="dynamic"),
Expand Down
45 changes: 22 additions & 23 deletions pyfarm/models/software.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Software
========
Software Models
===============
Table of software items. Agents can reference this table to show that they
provide a given software. Jobs or jobtypes can depend on a software via the
SoftwareRequirement table
Expand All @@ -37,7 +39,6 @@ class Software(db.Model, UtilityMixins):
Model to represent a versioned piece of software that can be present on an
agent and may be depended on by a job and/or jobtype through the appropriate
SoftwareRequirement table
"""
__tablename__ = config.get("table_software")
__table_args__ = (
Expand All @@ -52,20 +53,17 @@ class Software(db.Model, UtilityMixins):
#
# Relationships
#

versions = db.relationship("SoftwareVersion",
backref=db.backref("software"),
lazy="dynamic",
cascade="all, delete-orphan",
order_by="asc(SoftwareVersion.rank)",
doc="All known versions of this "
"software")
versions = db.relationship(
"SoftwareVersion",
backref=db.backref("software"),
lazy="dynamic", order_by="asc(SoftwareVersion.rank)",
cascade="all, delete-orphan",
doc="All known versions of this software")


class SoftwareVersion(db.Model, UtilityMixins):
"""
Model to represent a version for a given software
"""
__tablename__ = config.get("table_software_version")
__table_args__ = (
Expand Down Expand Up @@ -104,7 +102,6 @@ class JobSoftwareRequirement(db.Model, UtilityMixins):
"""
Model representing a dependency of a job on a software tag, with optional
version constraints
"""
__tablename__ = config.get("table_job_software_req")
__table_args__ = (
Expand Down Expand Up @@ -135,24 +132,26 @@ class JobSoftwareRequirement(db.Model, UtilityMixins):
#
# Relationships
#

job = db.relationship(
"Job",
backref=db.backref("software_requirements",
lazy="dynamic", cascade="all, delete-orphan"))
backref=db.backref(
"software_requirements",
lazy="dynamic",
cascade="all, delete-orphan"))

software = db.relationship("Software")
min_version = db.relationship("SoftwareVersion",
foreign_keys=[min_version_id])
max_version = db.relationship("SoftwareVersion",
foreign_keys=[max_version_id])

min_version = db.relationship(
"SoftwareVersion", foreign_keys=[min_version_id])

max_version = db.relationship(
"SoftwareVersion", foreign_keys=[max_version_id])


class JobTypeSoftwareRequirement(db.Model, UtilityMixins):
"""
Model representing a dependency of a job on a software tag, with optional
version constraints
"""
__tablename__ = config.get("table_job_type_software_req")
__table_args__ = (
Expand Down Expand Up @@ -183,12 +182,12 @@ class JobTypeSoftwareRequirement(db.Model, UtilityMixins):
#
# Relationships
#

jobtype_version = db.relationship(
"JobTypeVersion",
backref=db.backref(
"software_requirements",
lazy="dynamic", cascade="all, delete-orphan"))
lazy="dynamic",
cascade="all, delete-orphan"))

software = db.relationship("Software")

Expand Down
5 changes: 3 additions & 2 deletions pyfarm/models/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
# limitations under the License.

"""
Tag
===
Tag Model
=========
Table with tags for both jobs and agents
"""

Expand Down
9 changes: 9 additions & 0 deletions pyfarm/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class Task(db.Model, ValidatePriorityMixin, ValidateWorkStateMixin,
doc="The progress for this task, as a value between "
"0.0 and 1.0. Used purely for display purposes.")

#
# Relationships
#
job = db.relationship(
"Job",
backref=db.backref("tasks", lazy="dynamic"),
Expand All @@ -127,6 +130,11 @@ def increment_attempts(target, new_value, old_value, initiator):
if new_value is not None and new_value != old_value:
target.attempts += 1

@staticmethod
def log_assign_change(target, new_value, old_value, initiator):
logger.debug("Agent change for task %s: old %s new: %s",
target.id, old_value, new_value)

@staticmethod
def update_failures(target, new_value, old_value, initiator):
if new_value == WorkState.FAILED and new_value != old_value:
Expand Down Expand Up @@ -167,5 +175,6 @@ def clear_error_state(target, new_value, old_value, initiator):
event.listen(Task.state, "set", Task.update_failures)
event.listen(Task.state, "set", Task.set_progress_on_success)
event.listen(Task.agent_id, "set", Task.increment_attempts)
event.listen(Task.agent_id, "set", Task.log_assign_change)
event.listen(Task.state, "set", Task.reset_agent_if_failed_and_retry,
retval=True)
16 changes: 13 additions & 3 deletions pyfarm/models/tasklog.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,16 @@ class TaskTaskLogAssociation(db.Model):
nullable=True,
doc="The state of the work being performed")

task = db.relationship("Task", backref=db.backref("log_associations",
lazy="dynamic",
passive_deletes=True))
#
# Relationships
#
task = db.relationship(
"Task",
backref=db.backref(
"log_associations",
lazy="dynamic",
passive_deletes=True))



class TaskLog(db.Model, UtilityMixins, ReprMixin):
Expand All @@ -94,6 +101,9 @@ class TaskLog(db.Model, UtilityMixins, ReprMixin):
default=datetime.utcnow,
doc="The time when this log was created")

#
# Relationships
#
agent = db.relationship(
"Agent",
backref=db.backref("task_logs", lazy="dynamic"),
Expand Down
27 changes: 18 additions & 9 deletions pyfarm/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# limitations under the License.

"""
Permissions
===========
User and Role Models
====================
Stores users and their roles in the database.
"""
Expand All @@ -32,7 +32,7 @@
from pyfarm.models.core.mixins import ReprMixin
from pyfarm.models.core.functions import split_and_extend

__all__ = ("User", )
__all__ = ("User", "Role")

SHA256_ASCII_LENGTH = 64 # static length of a sha256 string

Expand Down Expand Up @@ -82,8 +82,8 @@ class User(db.Model, UserMixin, ReprMixin):

expiration = db.Column(
db.DateTime,
doc="User expiration. If this value is set then the user"
"will no longer be able to access PyFarm past the"
doc="User expiration. If this value is set then the user "
"will no longer be able to access PyFarm past the "
"expiration.")

onetime_code = db.Column(
Expand All @@ -95,9 +95,13 @@ class User(db.Model, UserMixin, ReprMixin):
db.DateTime,
doc="The last date that this user was logged in.")

#
# Relationships
#
roles = db.relationship(
"Role",
secondary=UserRole, backref=db.backref("users", lazy="dynamic"))
secondary=UserRole,
backref=db.backref("users", lazy="dynamic"))

@classmethod
def create(cls, username, password, email=None, roles=None):
Expand Down Expand Up @@ -205,12 +209,15 @@ class Role(db.Model):
"""
__tablename__ = config.get("table_role")

id = db.Column(db.Integer, primary_key=True, nullable=False)
id = db.Column(
db.Integer,
primary_key=True,
nullable=False)

active = db.Column(
db.Boolean,
default=True,
doc="Enables or disables a role. Disabling a role"
doc="Enables or disables a role. Disabling a role "
"will prevent any users of this role from accessing "
"PyFarm")

Expand All @@ -225,7 +232,9 @@ class Role(db.Model):
"anyone assigned to it, will no longer be able to access "
"PyFarm past the expiration.")

description = db.Column(db.Text, doc="Human description of the role.")
description = db.Column(
db.Text,
doc="Human description of the role.")

@classmethod
def create(cls, name, description=None):
Expand Down

0 comments on commit 2dfa294

Please sign in to comment.