-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathread_analytics_automated.py
185 lines (153 loc) · 5.45 KB
/
read_analytics_automated.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#
# Short reads the contents of the jobs, task, step, param and output to file
#
#
import os
import django
import uuid
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
'analytics_automated_project.settings.dev')
django.setup()
from django.core.files.uploadedfile import SimpleUploadedFile
from analytics_automated.models import Backend, Job, Task, Step, QueueType
from analytics_automated.models import Parameter, Submission, Result
from analytics_automated.models import Validator, BackendUser
def prep_db():
# clear out everything
Backend.objects.all().delete()
QueueType.objects.all().delete()
Job.objects.all().delete()
Task.objects.all().delete()
Step.objects.all().delete()
Submission.objects.all().delete()
Parameter.objects.all().delete()
Result.objects.all().delete()
def populate():
# clear out everything
prep_db()
# this_backend = add_backend(name="local1",
# server_type=Backend.LOCALHOST,
# ip="127.0.0.1",
# port=80,
# root_path="/tmp/")
# this_backenduser = add_BackendUser(backend=this_backend,
# userid="dummyid",
# password="p4ssw0rd",
# priority=2)
# this_task = add_task(backend=this_backend,
# name="task1",
# in_glob=".in",
# out_glob=".out",
# executable="ls $FLAGS > $OUTPUT")
# that_task = add_task(backend=this_backend,
# name="task2",
# in_glob=".out",
# out_glob=".final",
# executable='/usr/bin/grep "/" $INPUT > $OUTPUT || :')
# this_param = add_parameter(task=this_task,
# flag="-lah",
# default=None,
# bool_valued=True,
# rest_alias="all")
# that_param = add_parameter(task=that_task,
# flag="-a",
# default=10,
# bool_valued=False,
# rest_alias="number")
# this_job = add_job(name="job1",
# runnable=True)
# add_step(this_job, this_task, 0)
# add_step(this_job, that_task, 1)
# add_validator(this_job, 0, ".+")
# file1 = SimpleUploadedFile('file1.txt',
# bytes('these are the file contents!', 'utf-8'))
# file2 = SimpleUploadedFile('file2.txt',
# bytes('these are the file contents!', 'utf-8'))
# id1 = str(uuid.uuid1())
# id2 = str(uuid.uuid1())
# add_submisson(this_job, "sub1", id1,
# "[email protected]", "127.0.0.1", file1)
# add_submisson(this_job, "sub2", id2,
# "[email protected]", "127.0.0.1", file2)
# for b in Backend.objects.all():
# for t in Task.objects.filter(backend=b):
# print("- {0} - {1}".format(str(b), str(t)))
def add_backend(name, server_type, ip, port, root_path):
b = Backend.objects.create(name=name)
b.server_type = server_type
b.ip = ip
b.port = port
b.root_path = root_path
b.save()
return b
def add_task(backend, name, in_glob, out_glob, executable):
t = Task.objects.create(backend=backend)
t.name = name
t.in_glob = in_glob
t.out_glob = out_glob
t.executable = executable
t.save()
return t
def add_parameter(task, flag, default, bool_valued, rest_alias):
p = Parameter.objects.create(task=task)
p.flag = flag
p.default = default
p.bool_valued = bool_valued
p.rest_alias = rest_alias
p.save()
return p
def add_job(name, runnable):
j = Job.objects.create(name=name)
j.runnable = True
j.save()
return j
def add_step(job, task, ordering):
s = Step.objects.create(job=job, task=task, ordering=ordering)
s.save()
return s
def add_submisson(job, name, UUID, email, ip, input_data):
s = Submission.objects.create(job=job)
s.submission_name = name
s.UUID = UUID
s.email = email
s.ip = ip
s.input_data = input_data
s.save()
return(s)
def add_validator(job, val_type, re_string):
v = Validator.objects.create(job=job)
v.validation_type = val_type
v.re_string = re_string
v.save()
return(v)
def add_BackendUser(backend, userid, password, priority):
bu = BackendUser.objects.create(backend=backend)
bu.login_name = userid
bu.password = password
bu.priority = priority
bu.save()
def read_queue_type():
# queuetypes = QueueType.objects.all()
# for qt in queuetypes:
# print(qt)
# backends = Backend.objects.all()
# for bk in backends:
# print(bk)
jobs = Job.objects.all()
for job in jobs:
print(f"JOB {job}")
for step in job.steps.all():
print(step, step.ordering)
task = step.task
for config in task.configuration.all():
print(config)
for env in task.environment.all():
print(env)
for param in task.parameters.all():
print(param)
def read_db_contents():
read_queue_type()
# Start execution here!
if __name__ == '__main__':
print("Starting A_A population script...")
read_db_contents()