Permalink
Browse files

Merge pull request #11 from jaredbischof/master

Added upload component, using more standard status entity in MCP API.  Updating config.
  • Loading branch information...
jaredbischof committed Mar 18, 2013
2 parents 3fee5e8 + aabff26 commit f958a1256753c236ba0151a684628fb9d356cdef
Showing with 82 additions and 31 deletions.
  1. +5 −2 MCP
  2. +28 −16 conf/config_template.json
  3. +1 −2 mcp_modules/mcp_api.py
  4. +1 −4 mcp_modules/mlog.py
  5. +4 −7 mcp_modules/queue.py
  6. +1 −0 mcp_modules/subsystem.py
  7. +42 −0 mcp_modules/upload.py
View
7 MCP
@@ -22,7 +22,7 @@ json_conf = json.load(json_conf_file)
__doc__ = """
MG-RAST Control Program (MCP)
-SERVICE \tACTIONS\t\tUSER
+SERVICE \tUSER@HOST\t\t\tACTIONS
"""
service_name_to_module = {}
@@ -39,7 +39,10 @@ for module_name in json_conf["global"]["services"]:
for action in obj.actions.split(','):
service_action_to_req_user[name + " " + action.strip()] = userhost
- __doc__ += name + " \t" + obj.actions + " \t" + userhost + "\n"
+ if userhost == '':
+ userhost = 'ANY '
+
+ __doc__ += name + " \t" + userhost + " \t" + obj.actions + "\n"
def main(args):
usage = "\nUsage: MCP service action\n" + __doc__
View
@@ -1,4 +1,23 @@
{
+ "global": {
+ "apiurl": "",
+ "services": [
+ "memcache",
+ "mcp_api",
+ "mlog",
+ "queue",
+ "upload"
+ ]
+ },
+ "mcp_api": {
+ "user": "",
+ "host": "",
+ "dir": "",
+ "version": 1
+ },
+ "memcache": {
+ "memhost": ""
+ },
"mlog": {
"user": "",
"host": "",
@@ -7,26 +26,19 @@
"mgrast": 3
}
},
+ "prod": {
+ "host": "",
+ "user": "",
+ "nginx_conf_dir": "",
+ "site": ""
+ },
"queue": {
"host": "",
"user": ""
},
- "mcp_api": {
- "user": "",
+ "upload": {
"host": "",
- "dir": "",
- "version": 1
- },
- "global": {
- "apiurl": "",
- "services": [
- "memcache",
- "mcp_api",
- "mlog",
- "queue"
- ]
- },
- "memcache": {
- "memhost": ""
+ "user": "",
+ "lock_dir": ""
}
}
View
@@ -9,9 +9,8 @@ def __init__(self, MCP_dir):
self.state = { 'resource':self.__class__.__name__,
'updated':time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
'url':self.json_conf['global']['apiurl'] + "/" + str(self.json_conf['mcp_api']['version']) + "/" + self.__class__.__name__,
- 'status':'online'
+ 'status': { 'site' : 'online' }
}
- self.apidir = self.json_conf['mcp_api']['dir'] + "/" + str(self.json_conf['mcp_api']['version'])
self.services = self.json_conf['global']['services']
def start(self):
View
@@ -1,6 +1,5 @@
-import glob, json, sys, time
+import json, sys, time
from subsystem import subsystem
-from mcp_api import mcp_api
class mlog(subsystem):
actions = "set"
@@ -16,8 +15,6 @@ def __init__(self, MCP_dir):
for component in self.json_conf['mlog']['log_levels']:
self.state['log_levels'][component] = self.json_conf['mlog']['log_levels'][component]
- self.apidir = self.json_conf['mcp_api']['dir'] + "/" + str(self.json_conf['mcp_api']['version'])
-
def set(self, component, level):
if component not in self.json_conf['mlog']['log_levels']:
sys.stderr.write("ERROR: '" + component + "' is not a valid logging component.\n")
View
@@ -1,4 +1,4 @@
-import json, time
+import time
from subsystem import subsystem
class queue(subsystem):
@@ -19,12 +19,9 @@ def __init__(self, MCP_dir):
self.state = { 'resource':self.__class__.__name__,
'updated':time.strftime("%Y-%m-%d %H:%M:%S"),
'url':self.json_conf['global']['apiurl'] + "/" + str(self.json_conf['mcp_api']['version']) + "/" + self.__class__.__name__,
- 'queues': [ { 'name': 'batch',
- 'status': batch_status
- },
- { 'name': 'fast',
- 'status': fast_status
- } ]
+ 'status': { 'batch': batch_status,
+ 'fast': fast_status
+ }
}
def start(self):
View
@@ -7,6 +7,7 @@ def __init__(self, MCP_dir):
self.state = {}
json_conf_file = open(self.MCP_dir+'conf/conf.json')
self.json_conf = json.load(json_conf_file)
+ self.apidir = self.json_conf['mcp_api']['dir'] + "/" + str(self.json_conf['mcp_api']['version'])
def get_state(self):
return self.state
View
@@ -0,0 +1,42 @@
+import os, json, sys, time
+from subsystem import subsystem
+
+class upload(subsystem):
+ actions = "lock_page, unlock_page"
+
+ def __init__(self, MCP_dir):
+ subsystem.__init__(self, MCP_dir)
+ self.state = { 'resource':self.__class__.__name__,
+ 'updated':time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
+ 'url':self.json_conf['global']['apiurl'] + "/" + str(self.json_conf['mcp_api']['version']) + "/" + self.__class__.__name__,
+ 'status':{}
+ }
+
+ self.lock_file = self.json_conf['upload']['lock_dir'] + "/upload.lock"
+ if os.path.isfile(self.lock_file):
+ self.state['status']['page'] = "locked"
+ else:
+ self.state['status']['page'] = "not locked"
+
+ def lock_page(self):
+ fh = file(self.lock_file, 'a')
+ try:
+ os.utime(self.lock_file, None)
+ finally:
+ fh.close()
+
+ self.state['status']['page'] = "locked"
+ jstate = json.dumps(self.get_state())
+ f = open(self.apidir + "/" + self.__class__.__name__, 'w')
+ f.write(jstate)
+ return 1
+
+ def unlock_page(self):
+ if os.path.isfile(self.lock_file):
+ os.unlink(self.lock_file)
+
+ self.state['status']['page'] = "not locked"
+ jstate = json.dumps(self.get_state())
+ f = open(self.apidir + "/" + self.__class__.__name__, 'w')
+ f.write(jstate)
+ return 1

0 comments on commit f958a12

Please sign in to comment.