Skip to content
Browse files

Bootstrap improvements, procutils, datastore test

  • Loading branch information...
1 parent 0f3766d commit 3a84fde467015cc2b09a4e9adf8a75b335d1fad0 mmeisinger committed
View
9 README.txt
@@ -4,4 +4,11 @@ It contains the core services and their architectural dependencies, and relies o
external pacakges, such as Magnet, etc.
Start CC shell with:
-twistd -n magnet -h amoeba.ucsd.edu shell
+twistd -n magnet -h amoeba.ucsd.edu shell
+
+Start system by executing within the CC shell:
+
+><> from ion.core import bootstrap
+><> spawn(bootstrap)
+><> send(1, '')
+
View
2 bootstrap.cmd
@@ -0,0 +1,2 @@
+from ion.core import bootstrap
+bootstrap.start()
View
60 ion/core/bootstrap.py
@@ -3,25 +3,21 @@
"""
@file ion/core/bootstrap.py
@author Michael Meisinger
-@package ion.misc bootstrapping the system.
+@package ion.core bootstrapping the system.
"""
from twisted.python import log
from twisted.internet import defer
import logging
+import time
from magnet.spawnable import Receiver
from magnet.spawnable import send
from magnet.spawnable import spawn
from magnet.store import Store
-# Build a service properties dict
-def service_deploy_factory(package,name):
- scv_dict = {'name' : name,
- 'package' : package,
- 'module' : name,
- }
- return scv_dict
+import ion.util.procutils as pu
+from ion.util.procutils import service_deploy_factory
# Static definition of service names and message queues
# @todo
@@ -41,55 +37,67 @@ def service_deploy_factory(package,name):
#logging.basicConfig(level=logging.DEBUG, \
# format='%(asctime)s %(levelname)s (%(funcName)s) %(message)s')
-logging.info('Starting up...')
+# logging.info('Starting up...')
store = Store()
receiver = Receiver(__name__)
-started = False
+
@defer.inlineCallbacks
def start():
id = yield spawn(receiver)
store.put('bootstrap', id)
-
+ op_bootstrap()
+
@defer.inlineCallbacks
def op_bootstrap():
print "Bootstrapping now"
- started = True
for svc_name in ion_services:
# logging.info('Adding ' + svc_name)
- print('Adding ' + svc_name)
+ print 'Adding ' + svc_name
svc = ion_services[svc_name]
# Importing service module
svc_import = svc['package'] + "." + svc['module']
- print('Import ' + svc_import)
+ print 'Import ' + svc_import
svc_mod = __import__(svc_import, globals(), locals(), [svc['module']])
svc['module_import'] = svc_mod
# Spawn instance of a service
svc_id = yield spawn(svc_mod)
+ svc['instance'] = svc_id
store.put(svc['name'], svc_id)
- print("Service "+svc['name']+" ID: ",svc_id)
+ print "Service "+svc['name']+" ID: ",svc_id
# Send a start message to service instance
- to = yield store.get(svc['name'])
- print("Send to: ",to)
- receiver.send(to, {'method':'START','args':{}})
+# to = yield store.get(svc['name'])
+# print "Send to: ",to
+# receiver.send(to, {'op':'START','args':{}})
+ print "Store: ", store.kvs
+ # test_datastore()
+
+@defer.inlineCallbacks
+def test_datastore():
+ print "===================================================================="
+ print "===================================================================="
+ print "Testing datastore"
+
+ to = yield store.get('datastore')
-# to = yield store.get('datastore')
-# receiver.send(to, {'method':'PUT','args':{'key':'obj1','value':999}})
+ print "Send PUT to: ",to
+ # receiver.send(to,{'op':'PUT','content':{'key':'key1','value':'val1'}})
+ pu.send_message(receiver, '', to, 'PUT', {'key':'obj1','value':'999'}, {'some':'header'})
-# replyto = yield store.get('bootstrap')
-# receiver.send(to, {'method':'GET','args':{'key':'obj1','reply-to':replyto}})
+ print "===================================================================="
+ print "Send GET to: ",to
+ # receiver.send(to,{'op':'GET','args':{'key':'key1'}})
+ pu.send_message(receiver, '', to, 'GET', {'key':'obj1'}, {})
def receive(content, msg):
-
- print 'in receive ', content
- if not started:
- op_bootstrap()
+ pu.log_message(__name__, content, msg)
receiver.handle(receive)
+
View
BIN ion/core/bootstrap.pyc
Binary file not shown.
View
48 ion/core/supervisor.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+
+"""
+@file ion/core/supervisor.py
+@author Michael Meisinger
+@package ion.core abstract base class for processes that supervise other processes
+"""
+
+from twisted.python import log
+from twisted.internet import defer
+
+from magnet.spawnable import Receiver
+from magnet.spawnable import send
+from magnet.spawnable import spawn
+from magnet.store import Store
+
+
+class Supervisor:
+
+ # Static definition of services and properties
+ dependent_services = {}
+
+ def spawnDependents():
+ for svc_name in dependent_services:
+ # logging.info('Adding ' + svc_name)
+ print('Adding ' + svc_name)
+ svc = ion_services[svc_name]
+
+ # Importing service module
+ svc_import = svc['package'] + "." + svc['module']
+ print('Import ' + svc_import)
+ svc_mod = __import__(svc_import, globals(), locals(), [svc['module']])
+ svc['module_import'] = svc_mod
+
+ # Spawn instance of a service
+ svc_id = yield spawn(svc_mod)
+ store.put(svc['name'], svc_id)
+ print("Service "+svc['name']+" ID: ",svc_id)
+
+ # Send a start message to service instance
+ to = yield store.get(svc['name'])
+ print("Send to: ",to)
+ receiver.send(to, {'method':'START','args':{}})
+
+ def event_failure():
+ return
+
+
View
2 ion/services/cei/provisioner.py
@@ -16,8 +16,6 @@
store = Store()
-datastore = Store()
-
receiver = Receiver(__name__)
@defer.inlineCallbacks
View
BIN ion/services/cei/provisioner.pyc
Binary file not shown.
View
48 ion/services/coi/coi_supervisor.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+
+"""
+@file ion/services/coi/supervisor.py
+@author Michael Meisinger
+@package ion.services supervisor for COI services
+"""
+
+from twisted.python import log
+from twisted.internet import defer
+
+from magnet.spawnable import Receiver
+from magnet.spawnable import send
+from magnet.spawnable import spawn
+from magnet.store import Store
+
+
+class Supervisor:
+
+ # Static definition of services and properties
+ dependent_services = {}
+
+ def spawnDependents():
+ for svc_name in dependent_services:
+ # logging.info('Adding ' + svc_name)
+ print('Adding ' + svc_name)
+ svc = ion_services[svc_name]
+
+ # Importing service module
+ svc_import = svc['package'] + "." + svc['module']
+ print('Import ' + svc_import)
+ svc_mod = __import__(svc_import, globals(), locals(), [svc['module']])
+ svc['module_import'] = svc_mod
+
+ # Spawn instance of a service
+ svc_id = yield spawn(svc_mod)
+ store.put(svc['name'], svc_id)
+ print("Service "+svc['name']+" ID: ",svc_id)
+
+ # Send a start message to service instance
+ to = yield store.get(svc['name'])
+ print("Send to: ",to)
+ receiver.send(to, {'method':'START','args':{}})
+
+ def event_failure():
+ return
+
+
View
53 ion/services/coi/datastore.py
@@ -14,26 +14,32 @@
from magnet.spawnable import spawn
from magnet.store import Store
+import ion.util.procutils as pu
+
store = Store()
datastore = Store()
receiver = Receiver(__name__)
+selfid = None
@defer.inlineCallbacks
def start():
id = yield spawn(receiver)
store.put('datastore', id)
+ selfid = id
def op_put(args):
print 'in "put" with ', args
datastore.put(args['key'],args['value'])
@defer.inlineCallbacks
-def op_get(args):
- print 'in "get" with ', args
+def op_get(args, replyto):
+ print 'in "get" with ', args, replyto
value = yield datastore.get(args['key'])
- receiver.send(args['reply-to'], {'from':'id', 'return-value':value})
+ print "GET '"+args['key']+"'='"+value+"'"
+
+ receiver.send(pu.get_process_id(replyto), {'from':'id', 'return-value':value})
def receive(content, msg):
@@ -42,23 +48,32 @@ def receive(content, msg):
For this implementation, 'content' will be a dictionary:
content = {
- "method": "method name here",
- "args": ('arg1', 'arg2')
+ "op": "operation name here",
+ "args": {'key1':'arg1', 'key2':'arg2'}
}
"""
- print 'in receive ', content, msg
- try:
- if "method" in content:
- if content["method"] == "START":
- print 'Start message received'
- if content["method"] == "GET":
- return op_get(content['args'])
- if content["method"] == "PUT":
- return op_put(content['args'])
- else:
- raise NameError
- except Exception:
- log.error("Receive() failed. Method call does not match a service",
- content)
+ pu.log_message(__name__, content, msg)
+ if "op" in content:
+ if content["op"] == "START":
+ print 'Start message received'
+ return
+ elif content["op"] == "GET":
+ return op_get(content['content'],msg.reply_to)
+ elif content["op"] == "PUT":
+ return op_put(content['content'])
+# else:
+# log.error("Receive() failed. Op call does not match a service", content)
+# else:
+ log.error("Receive() failed. Bad message", content)
receiver.handle(receive)
+
+def test_put():
+ start()
+ receiver.send(selfid, {'op':'PUT','args':{'key':'key1','value':'val1'}})
+ # send(1,{'op':'PUT','args':{'key':'key1','value':'val1'}})
+
+def test_get():
+ receiver.send(selfid, {'op':'GET','args':{'key':'key1'}})
+ # send(1, {'op':'GET','args':{'key':'key1'}})
+
View
BIN ion/services/coi/datastore.pyc
Binary file not shown.
View
7 ion/services/coi/resource_registry.py
@@ -14,9 +14,9 @@
from magnet.spawnable import spawn
from magnet.store import Store
-store = Store()
+import ion.util.procutils as pu
-datastore = Store()
+store = Store()
receiver = Receiver(__name__)
@@ -27,6 +27,7 @@ def start():
def receive(content, msg):
- print 'in receive ', content, msg
+ pu.log_message(__name__, content, msg)
+
receiver.handle(receive)
View
BIN ion/services/coi/resource_registry.pyc
Binary file not shown.
View
6 ion/services/coi/service_registry.py
@@ -14,9 +14,9 @@
from magnet.spawnable import spawn
from magnet.store import Store
-store = Store()
+import ion.util.procutils as pu
-datastore = Store()
+store = Store()
receiver = Receiver(__name__)
@@ -27,6 +27,6 @@ def start():
def receive(content, msg):
- print 'in receive ', content, msg
+ pu.log_message(__name__, content, msg)
receiver.handle(receive)
View
BIN ion/services/coi/service_registry.pyc
Binary file not shown.
View
33 ion/ts.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+
+"""
+@file ion/ts.py
+@author Michael Meisinger
+@package ion test service with short packet and module name
+"""
+
+from twisted.python import log
+from twisted.internet import defer
+
+from magnet.spawnable import Receiver
+from magnet.spawnable import send
+from magnet.spawnable import spawn
+from magnet.store import Store
+
+import ion.util.procutils as pu
+
+store = Store()
+
+receiver = Receiver(__name__)
+
+@defer.inlineCallbacks
+def start():
+ id = yield spawn(receiver)
+ store.put('ts', id)
+
+def receive(content, msg):
+ print 'in receive ', content, msg
+ pu.print_attributes(msg)
+
+
+receiver.handle(receive)
View
BIN ion/ts.pyc
Binary file not shown.
View
BIN ion/util/__init__.pyc
Binary file not shown.
View
53 ion/util/procutils.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+
+"""
+@file ion/util/procutils.py
+@author Michael Meisinger
+@package ion.util utility helper functions for processes in capability containers
+"""
+
+from twisted.python import log
+from twisted.internet import defer
+
+# Build a service properties dict
+def service_deploy_factory(package,name):
+ scv_dict = {'name' : name,
+ 'package' : package,
+ 'module' : name,
+ }
+ return scv_dict
+
+# Print an object's attributes
+def print_attributes(obj):
+ str = ''
+ for attr, value in obj.__dict__.iteritems():
+ #str = str + attr + ": " + value + "\n"
+ print attr, ": ", value
+ #print str
+
+def log_message(proc,content,msg):
+ print "===Message=== @", proc
+ print_attributes(msg)
+ print "-------------"
+ print content
+ print "============="
+
+# Returns the instance part of a long process id
+def get_process_id(long_id):
+ parts = str(long_id).rpartition('.')
+ return parts[2]
+
+# Constructs a message with standard headers
+def send_message(receiver,src,to,operation,content,headers):
+ msg = {}
+ msg.update(headers)
+ msg['op'] = operation
+ msg['sender'] = str(src)
+ msg['receiver'] = str(to)
+ msg['encoding'] = ''
+ msg['structure'] = ''
+ msg['semantics'] = ''
+ msg['conversation'] = ''
+ msg['intpattern'] = ''
+ msg['content'] = content
+ receiver.send(to,msg)
View
BIN ion/util/procutils.pyc
Binary file not shown.
View
2 twistd
@@ -0,0 +1,2 @@
+from ion.core import bootstrap
+bootstrap.start()

0 comments on commit 3a84fde

Please sign in to comment.
Something went wrong with that request. Please try again.