-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathshadow.py
119 lines (94 loc) · 3.96 KB
/
shadow.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
# Copyright (C) 2018 RW Bunney
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Mosws.py is the entry point for running test and experiments from the command line
import argparse
import unittest
import logging
from test import test_workflow, test_heuristic
from shadow.algorithms.heuristic import heft
from shadow.models.workflow import Workflow
from shadow.models.environment import Environment
testcases = { # Tests for the test runner
"workflow": test_workflow,
"heuristic": test_heuristic
}
def run_tests(arg, tests, curr_parser):
if arg['all']:
suite = unittest.TestSuite()
loader = unittest.TestLoader()
for test in tests:
suite.addTests(loader.loadTestsFromModule(tests[test]))
runner = unittest.TextTestRunner()
runner.run(suite)
return True
if arg['case']:
for case in arg['case']:
suite = unittest.TestSuite()
loader = unittest.TestLoader()
suite.addTests(loader.loadTestsFromModule(tests[case]))
runner = unittest.TextTestRunner()
runner.run(suite)
else:
curr_parser.print_help()
def run_shadow():
"""
env = Environment(environment_config)
wf = Workflow(workflow_config)
wf.add_environment()
env.run_workflows(heuristic.heft)
:return:
"""
pass
def run_algorithm(arg, parser):
if arg['algorithm'] == 'heft':
pass
wf = Workflow(arg['workflow'])
env = Environment(arg['environment'])
wf.add_environment(env)
print(heft(wf).makespan)
# print(wf.machine_alloc)
# wf = Workflow(arg['graph'])
# calc_time = (arg['calc_time'] == 'True')
# wf.load_attributes(arg['attr'], calc_time)
# heft(wf)
# wf.pretty_print_allocation()
if __name__ == "__main__":
# logging.basicConfig(level="DEBUG")
parser = argparse.ArgumentParser(
description='ScHeduling Algorithms for Data-Intensive Workflows')
parser.add_argument('--log',
help='Log-level for logger (default is 3 [Warning])')
subparsers = parser.add_subparsers(help='Command', dest='command')
test_parser = subparsers.add_parser('test', help='Test Runner')
test_parser.add_argument('--all', action='store_true', help='Run all test')
test_parser.add_argument('--case', nargs='+', choices=list(testcases),
help='Run the following test cases')
test_parser.set_defaults(func=run_tests)
algorithm_parser = subparsers.add_parser('algorithm',
help='Run a single algorithm on a given data file')
algorithm_parser.set_defaults(func=run_algorithm)
algorithm_parser.add_argument('algorithm', help='Name of algorithm')
algorithm_parser.add_argument('workflow',
help='Location of workflow config')
algorithm_parser.add_argument('environment',
help='Location of the environment config')
args = parser.parse_args()
if not args.command:
parser.print_help()
if args.log:
# Levels in logger are multiples of 10, so we multiply by 10 so people use the logical 1/2/3/4
loglevel = int(args.log) * 10
logging.basicConfig(level=loglevel)
if args.command == 'algorithm':
args.func(vars(args), algorithm_parser)
if args.command == 'test':
args.func(vars(args), testcases, test_parser)