models.py 6.34 KB
Newer Older
1 2
from __future__ import unicode_literals

BERJON Matthieu's avatar
BERJON Matthieu committed
3
from django.contrib.auth.models import User
4 5 6
from django.db import models


BERJON Matthieu's avatar
BERJON Matthieu committed
7 8 9 10 11 12 13 14
class TimeStampModel(models.Model):
    """
    An abstract base class model that provides self-updating ``created_at`` and
    ``updated_at`` fields.
    """

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now_add=True)
15 16

    class Meta:
BERJON Matthieu's avatar
BERJON Matthieu committed
17
        abstract = True
18 19


BERJON Matthieu's avatar
BERJON Matthieu committed
20
class AllgoUser(models.Model):
BERJON Matthieu's avatar
BERJON Matthieu committed
21
    """
BERJON Matthieu's avatar
BERJON Matthieu committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    Class linked to the Django user management. If there is a need to add a
    field related to a user, it should be added here and not in the auth_user
    table.
    """

    sshkey = models.CharField(max_length=40)

    # Relationships
    user = models.OneToOneField(
            User, on_delete=models.CASCADE, related_name="allgouser")

    class Meta:
        db_table = 'allgo_user'


class DockerOs(TimeStampModel):
    """
    Contains the different Operating Systems that a user can choose from to
    build its container.
BERJON Matthieu's avatar
BERJON Matthieu committed
41
    """
42

BERJON Matthieu's avatar
BERJON Matthieu committed
43 44 45 46
    # Fields
    name = models.CharField(max_length=255, blank=True)
    version = models.CharField(max_length=255, blank=True)
    docker_name = models.CharField(max_length=255, blank=True)
47 48

    class Meta:
BERJON Matthieu's avatar
BERJON Matthieu committed
49
        db_table = 'docker_os'
50 51


BERJON Matthieu's avatar
BERJON Matthieu committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65
class JobQueue(TimeStampModel):
    """
    Data regarding the type of queues available for the system.
    """

    # Fields
    name = models.CharField(max_length=255)
    timeout = models.IntegerField(blank=True, null=True)
    is_default = models.IntegerField()

    class Meta:
        db_table = 'job_queues'


BERJON Matthieu's avatar
BERJON Matthieu committed
66 67 68 69 70 71 72 73
class Webapp(TimeStampModel):
    """
    Webapp model related to the creation and management of a particular web
    app belonging to one or more users.
    """

    # Fields
    name = models.CharField(unique=True, max_length=255, blank=True)
74
    description = models.TextField(blank=True, null=True)
BERJON Matthieu's avatar
BERJON Matthieu committed
75 76 77

    # Should given according to the number of users declared as admin to this
    # app
78
    contact = models.CharField(max_length=255, blank=True, null=True)
BERJON Matthieu's avatar
BERJON Matthieu committed
79 80

    # Logo
81 82 83 84
    logo_file_name = models.CharField(max_length=255, blank=True, null=True)
    logo_content_type = models.CharField(max_length=255, blank=True, null=True)
    logo_file_size = models.IntegerField(blank=True, null=True)
    logo_updated_at = models.DateTimeField(blank=True, null=True)
BERJON Matthieu's avatar
BERJON Matthieu committed
85 86

    # Default quota
87
    default_quota = models.IntegerField(blank=True, null=True)
BERJON Matthieu's avatar
BERJON Matthieu committed
88 89 90

    # Docker and parameters related stuff
    docker_name = models.CharField(max_length=255, blank=True)
91
    readme = models.IntegerField(blank=True, null=True)
BERJON Matthieu's avatar
BERJON Matthieu committed
92
    entrypoint = models.CharField(max_length=255, blank=True)
93 94 95
    exec_time = models.IntegerField(blank=True, null=True)
    private = models.IntegerField(blank=True, null=True)
    access_token = models.CharField(max_length=255, blank=True, null=True)
BERJON Matthieu's avatar
BERJON Matthieu committed
96
    sandbox_state = models.IntegerField(null=True)
97

BERJON Matthieu's avatar
BERJON Matthieu committed
98 99
    # Not integrated in this model yet
    #  sandbox_version_id = models.IntegerField(blank=True, null=True)
100

BERJON Matthieu's avatar
BERJON Matthieu committed
101
    memory_limit = models.BigIntegerField(blank=True, null=True)
102

BERJON Matthieu's avatar
BERJON Matthieu committed
103 104 105 106 107 108 109 110
    # Relationships

    # A webapp has one docker os type
    docker_os = models.OneToOneField(DockerOs, related_name="webappdockeros")
    user = models.ForeignKey(
            User, on_delete=models.CASCADE, related_name="webappuser")
    job_queue = models.OneToOneField(
            JobQueue, on_delete=models.CASCADE, related_name="webappjobqueue")
111 112

    class Meta:
BERJON Matthieu's avatar
BERJON Matthieu committed
113
        db_table = 'webapps'
114

BERJON Matthieu's avatar
BERJON Matthieu committed
115 116

class WebappParameter(TimeStampModel):
BERJON Matthieu's avatar
BERJON Matthieu committed
117
    """
BERJON Matthieu's avatar
BERJON Matthieu committed
118
    Given parameters for a specific webapp
BERJON Matthieu's avatar
BERJON Matthieu committed
119
    """
120

BERJON Matthieu's avatar
BERJON Matthieu committed
121 122
    # Fields
    value = models.CharField(max_length=255, blank=True, null=True)
123
    name = models.CharField(max_length=255, blank=True, null=True)
BERJON Matthieu's avatar
BERJON Matthieu committed
124 125 126 127
    detail = models.CharField(max_length=255, blank=True, null=True)

    # Relationships
    # a Webapp parameters corresponds to one webapp
BERJON Matthieu's avatar
BERJON Matthieu committed
128
    webapp = models.OneToOneField(Webapp, related_name="webappparameters")
129 130

    class Meta:
BERJON Matthieu's avatar
BERJON Matthieu committed
131
        db_table = 'webapp_parameters'
132 133


BERJON Matthieu's avatar
BERJON Matthieu committed
134 135
class WebappVersion(TimeStampModel):
    """
BERJON Matthieu's avatar
BERJON Matthieu committed
136
    Version of a given webapp
BERJON Matthieu's avatar
BERJON Matthieu committed
137 138 139 140 141 142 143 144
    """

    # Fields
    number = models.CharField(max_length=255, blank=True)
    changelog = models.CharField(max_length=255, blank=True)
    docker_image_size = models.FloatField(blank=True, null=True)
    state = models.IntegerField(null=True)
    published = models.IntegerField()
145 146

    # Relationships
BERJON Matthieu's avatar
BERJON Matthieu committed
147
    webapp = models.ForeignKey(Webapp, related_name="webappversion")
148 149

    class Meta:
BERJON Matthieu's avatar
BERJON Matthieu committed
150
        db_table = 'webapp_versions'
151 152


BERJON Matthieu's avatar
BERJON Matthieu committed
153 154
class Quota(TimeStampModel):
    """
BERJON Matthieu's avatar
BERJON Matthieu committed
155
    Quota given to a certain user for a given webapp.
156

BERJON Matthieu's avatar
BERJON Matthieu committed
157 158 159
    Todo
        - write a function that calculates the quota left to the user
    """
160

BERJON Matthieu's avatar
BERJON Matthieu committed
161 162
    # Fields
    quantity = models.BigIntegerField(blank=True, null=True)
163

BERJON Matthieu's avatar
BERJON Matthieu committed
164 165 166 167 168
    # Relationships
    user = models.ForeignKey(
            User, on_delete=models.CASCADE, related_name="quotauser")
    webapp = models.ForeignKey(
            Webapp, on_delete=models.CASCADE, related_name="quotawebapp")
169 170

    class Meta:
BERJON Matthieu's avatar
BERJON Matthieu committed
171
        db_table = 'quotas'
172 173


BERJON Matthieu's avatar
BERJON Matthieu committed
174 175
class Job(TimeStampModel):
    """
BERJON Matthieu's avatar
BERJON Matthieu committed
176
    Jobs ran with the specific data (user, webapp, queue type, ...)
BERJON Matthieu's avatar
BERJON Matthieu committed
177
    """
178

BERJON Matthieu's avatar
BERJON Matthieu committed
179 180 181 182 183 184 185 186
    # Fields
    param = models.CharField(max_length=255, blank=True, null=True)
    datasize = models.IntegerField(blank=True, null=True)
    version = models.CharField(max_length=255, blank=True, null=True)
    exec_time = models.IntegerField(blank=True, null=True)
    access_token = models.CharField(max_length=255, blank=True, null=True)
    state = models.IntegerField()
    result = models.IntegerField()
187

BERJON Matthieu's avatar
BERJON Matthieu committed
188 189 190 191 192 193 194
    # Relationships
    queue = models.ForeignKey(JobQueue, related_name="jobqueue")
    webapp = models.ForeignKey(Webapp, related_name="jobwebapp")
    user = models.ForeignKey(AllgoUser, related_name="jobuser")

    # Not in use because I don't have any related table yet
    container_id = models.IntegerField(blank=True, null=True)
195 196

    class Meta:
BERJON Matthieu's avatar
BERJON Matthieu committed
197
        db_table = 'jobs'
198 199


BERJON Matthieu's avatar
BERJON Matthieu committed
200
class JobUploads(TimeStampModel):
BERJON Matthieu's avatar
BERJON Matthieu committed
201
    """
BERJON Matthieu's avatar
BERJON Matthieu committed
202
    Data uploaded by the user to feed a given webapp
BERJON Matthieu's avatar
BERJON Matthieu committed
203
    """
204

BERJON Matthieu's avatar
BERJON Matthieu committed
205 206 207 208
    # Fields
    job_file_file_name = models.CharField(max_length=255, blank=True)
    job_file_content_type = models.CharField(max_length=255, blank=True)
    job_file_file_size = models.IntegerField(blank=True, null=True)
BERJON Matthieu's avatar
BERJON Matthieu committed
209 210
    job_file_updated_at = models.DateTimeField(
            blank=True, auto_now_add=True, null=True)
211

BERJON Matthieu's avatar
BERJON Matthieu committed
212
    # Relationships
BERJON Matthieu's avatar
BERJON Matthieu committed
213
    job = models.ForeignKey(Job, related_name="jobuploadjob")
214 215

    class Meta:
BERJON Matthieu's avatar
BERJON Matthieu committed
216
        db_table = 'job_uploads'