def __init__(self, threadMgr, service, manifest, name = 'agent_thread', parentId = None): """ Constructor """ AgentThread.__init__(self, threadMgr, cat = [manifestutil.serviceCat(service)], name = name, parentId = parentId) self.__manifest = manifest self.__service = service contextutils.injectcontext(self, {'service':service}) self._LOG = manifestutil.getServiceLogger(self, logging.getLogger(__name__))
def __init__(self, threadMgr, service, manifest, name = 'agent_thread'): """ Constructor """ AgentThread.__init__(self, threadMgr, cat = [manifestutil.serviceCat(service)], name = name) self.__manifest = manifest self.__service = service injectcontext(self, {'service':service}) # maintain a stack that has all the recovery script paths # this stack is protected self._stack = []
def testContextUtils(self): sc = SomeClass() contextutils.injectcontext(sc, {'guid':'test-guid'}) assert contextutils.existcontext(sc, 'guid') assert not contextutils.existcontext(sc, 'guid1') assert contextutils.getcontext(sc, 'guid1', 'test-guid1') == 'test-guid1' assert contextutils.getcontext(sc, 'guid') == 'test-guid' contextutils.injectcontext(sc, {'guid':'new-guid'}) assert contextutils.getcontext(sc, 'guid') == 'new-guid' assert contextutils.popcontext(sc, 'guid') == 'new-guid' assert not contextutils.existcontext(sc, 'guid')
def __init__(self, threadMgr, service, manifest, name='agent_thread'): """ Constructor """ AgentThread.__init__(self, threadMgr, cat=[manifestutil.serviceCat(service)], name=name) self.__manifest = manifest self.__service = service injectcontext(self, {'service': service}) # maintain a stack that has all the recovery script paths # this stack is protected self._stack = []
def testContextUtils(self): sc = SomeClass() contextutils.injectcontext(sc, {'guid': 'test-guid'}) assert contextutils.existcontext(sc, 'guid') assert not contextutils.existcontext(sc, 'guid1') assert contextutils.getcontext(sc, 'guid1', 'test-guid1') == 'test-guid1' assert contextutils.getcontext(sc, 'guid') == 'test-guid' contextutils.injectcontext(sc, {'guid': 'new-guid'}) assert contextutils.getcontext(sc, 'guid') == 'new-guid' assert contextutils.popcontext(sc, 'guid') == 'new-guid' assert not contextutils.existcontext(sc, 'guid')
def __injectcontext(target, reqstr, status, msg=None): ''' inject additional status and message @param target: target to inject context @param status: status @param msg: message ''' if target is not None: if reqstr is not None: contextutils.injectcontext(target, {'caltitle': reqstr}) if status is not None: contextutils.injectcontext(target, {'calstatus': status}) if msg is not None: contextutils.injectcontext(target, {'calbody': msg})
def testtrackable(self): global counter counter = 0 sc = SomeClass() contextutils.injectcontext(sc, {'guid':'test-guid'}) evttrackerpath = 'test-path' contextutils.injectcontext(sc, {'evt_tracker_path':evttrackerpath+'.agent'}) contextutils.injectcontext(sc, {'calbody':'more message'}) sc.doSomething() assert counter == 1 doSomething('something') assert counter == 2 try: sc.doSomethingElse('somethingelse') assert False except Exception as ex: assert 'somethingelse' == str(ex) assert counter == 3
def testtrackable(self): global counter counter = 0 sc = SomeClass() contextutils.injectcontext(sc, {'guid': 'test-guid'}) evttrackerpath = 'test-path' contextutils.injectcontext( sc, {'evt_tracker_path': evttrackerpath + '.agent'}) contextutils.injectcontext(sc, {'calbody': 'more message'}) sc.doSomething() assert counter == 1 doSomething('something') assert counter == 2 try: sc.doSomethingElse('somethingelse') assert False except Exception as ex: assert 'somethingelse' == str(ex) assert counter == 3
def __call__(self, environ, start_response): """Invoke the Controller""" # WSGIController.__call__ dispatches to the Controller method # the request is routed to. This routing information is # available in environ['pylons.routes_dict'] # before setting anything new, first reset the old values from previous request if any contextutils.resetcontext(self) #LOG.debug(environ) if 'service' in environ['pylons.routes_dict']: servicename = environ['pylons.routes_dict']['service'] #if not registered, agent will not try to replace if servicename is not None and servicename.count('.') == 2: servicename = manifestutil.expandServiceName(servicename) LOG.info('service name expanded %s ' % servicename) environ['pylons.routes_dict']['service'] = servicename contextutils.injectcontext(self, {'service': servicename}) # get correlationid into context if 'X-CORRELATIONID' in request.headers and request.headers[ 'X-CORRELATIONID'] is not None: contextutils.injectcontext( self, {'guid': request.headers['X-CORRELATIONID']}) else: contextutils.injectcontext(self, {'guid': ''}) # get timeouts and inject into context if 'X-THREAD_TIMEOUT' in request.headers and request.headers[ 'X-THREAD_TIMEOUT'] is not None: contextutils.injectcontext( self, {'thread_timeout': request.headers['X-AGENT_THREAD_TIMEOUT']}) # get progress timeouts and inject into context if 'X-THREAD_PROGRESS_TIMEOUT' in request.headers and request.headers[ 'X-THREAD_PROGRESS_TIMEOUT'] is not None: contextutils.injectcontext( self, { 'thread_progress_timeout': request.headers['X-THREAD_PROGRESS_TIMEOUT'] }) # get remote address from request remoteAddr = request.environ.get("X_FORWARDED_FOR", request.environ.get("REMOTE_ADDR")) contextutils.injectcontext(self, {'remote_addr': remoteAddr}) reqChecksum = '%s,%s,%s' % (request.method, request.url, request.body) contextutils.injectcontext(self, {'reqChecksum': reqChecksum}) return WSGIController.__call__(self, environ, start_response)
def __call__(self, environ, start_response): """Invoke the Controller""" # WSGIController.__call__ dispatches to the Controller method # the request is routed to. This routing information is # available in environ['pylons.routes_dict'] # before setting anything new, first reset the old values from previous request if any contextutils.resetcontext(self) #LOG.debug(environ) if 'service' in environ['pylons.routes_dict']: servicename = environ['pylons.routes_dict']['service'] #if not registered, agent will not try to replace if servicename is not None and servicename.count('.') == 2: servicename = manifestutil.expandServiceName(servicename) LOG.info('service name expanded %s ' % servicename) environ['pylons.routes_dict']['service'] = servicename contextutils.injectcontext(self, {'service': servicename}) # get correlationid into context if 'X-CORRELATIONID' in request.headers and request.headers['X-CORRELATIONID'] is not None: contextutils.injectcontext(self, {'guid': request.headers['X-CORRELATIONID']}) # get timeouts and inject into context if 'X-THREAD_TIMEOUT' in request.headers and request.headers['X-THREAD_TIMEOUT'] is not None: contextutils.injectcontext(self, {'thread_timeout': request.headers['X-AGENT_THREAD_TIMEOUT']}) # get progress timeouts and inject into context if 'X-THREAD_PROGRESS_TIMEOUT' in request.headers and request.headers['X-THREAD_PROGRESS_TIMEOUT'] is not None: contextutils.injectcontext(self, {'thread_progress_timeout': request.headers['X-THREAD_PROGRESS_TIMEOUT']}) contextutils.injectcontext(self, {'requrl': request.path_qs}) reqChecksum = '%s %s %s' % (request.method, request.path_qs, request.body if request.body else '') contextutils.injectcontext(self, {'reqstr': reqChecksum}) # get remote address from request remoteAddr = request.environ.get("X_FORWARDED_FOR", request.environ.get("REMOTE_ADDR")) contextutils.injectcontext(self, {'remote_addr': remoteAddr}) return WSGIController.__call__(self, environ, start_response)