Skip to content
This repository has been archived by the owner on Jul 29, 2020. It is now read-only.

Commit

Permalink
added todos, updates to api
Browse files Browse the repository at this point in the history
  • Loading branch information
cglewis committed Sep 18, 2013
1 parent 773ae3f commit 0df1afb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 15 additions & 2 deletions hemlock/hemlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ def __init__(self):
self.log = Hemlock_Debugger()
self.HELP_COUNTER = 0

# !! TODO new api calls:
# schedule_change_server
# schedule_server_create
# schedule_server_delete
# schedule_server_get
# schedule_server_list
def client_add_schedule(self, args, var_d):
"""
Adds a specific schedule to a specific client.
Expand Down Expand Up @@ -147,7 +153,8 @@ def client_schedule(self, args, var_d):
'--day_of_month',
'--month',
'--day_of_week',
'--client_id'
'--client_id',
'--schedule_server_id'
]
return self.check_args(args, arg_d, var_d)

Expand Down Expand Up @@ -456,7 +463,8 @@ def start_scheduler(self, args, var_d):
"""
# !! TODO this should not be required, if the creds are already stored
arg_d = [
'--hemlock_creds_path'
'--hemlock_creds_path',
'--schedule_server_id'
]
return self.check_args(args, arg_d, var_d)

Expand Down Expand Up @@ -820,6 +828,7 @@ def print_help(self, action):
--month (cron month)
--day_of_week (cron day of week)
--client_id (uuid of the client this schedule will run on)
--schedule_server_id (uuid of the server that will run the schedule)
""",
'client-schedules-list' : """
client-schedules-list (list schedules a client belongs to)
Expand Down Expand Up @@ -926,6 +935,7 @@ def print_help(self, action):
'start-scheduler' : """
start-scheduler (start the scheduler)
--hemlock_creds_path (file path to the hemlock_creds file)
--schedule_server_id (uuid of the server that will run the scheduler)
""",
'system-add-tenant' : """
system-add-tenant (add a tenant to a system)
Expand Down Expand Up @@ -1469,6 +1479,7 @@ def process_action(self, debug, action, var_d, m_server, c_server, c_user, bucke
i += 1
self.log.debug(debug, "Tables: "+str(tables))

# !! TODO need to add a table for schedule_servers
# create mysql tables that don't already exist
if "clients" not in tables:
client_table = "CREATE TABLE IF NOT EXISTS clients(id INT PRIMARY KEY AUTO_INCREMENT, uuid VARCHAR(36), name VARCHAR(50), type VARCHAR(50), credentials BLOB, created DATETIME, INDEX (uuid)) ENGINE = INNODB"
Expand All @@ -1482,6 +1493,7 @@ def process_action(self, debug, action, var_d, m_server, c_server, c_user, bucke
role_table = "CREATE TABLE IF NOT EXISTS roles(id INT PRIMARY KEY AUTO_INCREMENT, uuid VARCHAR(36), name VARCHAR(50), created DATETIME, INDEX (uuid)) ENGINE = INNODB"
cur.execute(role_table)
self.log.debug(debug, "Created table: "+str(role_table))
# !! TODO this needs to be updated with foreign key of schedule_servers
if "schedules" not in tables:
schedule_table = "CREATE TABLE IF NOT EXISTS schedules(id INT PRIMARY KEY AUTO_INCREMENT, uuid VARCHAR(36), name VARCHAR(50), minute VARCHAR(10), hour VARCHAR(10), day_of_month VARCHAR(10), month VARCHAR(10), day_of_week VARCHAR(10), created DATETIME, INDEX (uuid)) ENGINE = INNODB"
cur.execute(schedule_table)
Expand Down Expand Up @@ -1805,6 +1817,7 @@ def process_action(self, debug, action, var_d, m_server, c_server, c_user, bucke
elif "start" in action_a:
# check if there is already a hemlock_scheduler running
# if there is already one running, don't spawn another one
# !! TODO pass server argument to hemlock-scheduler
cmd = "ps cax | grep hemlock-sched | wc -l"
result = os.popen(cmd).read()
if result[0] == "0":
Expand Down
3 changes: 3 additions & 0 deletions hemlock/hemlock_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Hemlock_Scheduler():
"""

def __init__(self):
# !! TODO take the server argument
self.log = Hemlock_Debugger()
self.sched = self.init_schedule()
args = []
Expand Down Expand Up @@ -105,6 +106,8 @@ def check_schedules(self):
cur = m_server.cursor()
self.log.debug(self.debug, "MySQL Cursor: "+str(cur))

# !! TODO limie this to just the jobs for the server that is running
# this scheduler
cur.execute("SELECT * FROM schedules")
results = cur.fetchall()
self.log.debug(self.debug, str(results))
Expand Down

0 comments on commit 0df1afb

Please sign in to comment.