class TestProcessInt(IonIntegrationTestCase): def setUp(self): self._start_container() self.pid = self.container.spawn_process('fake', 'pyon.ion.test.test_process', 'FakeService') self.fsclient = RPCClient(to_name='fake_service') @unittest.skip("timeouts removed 18 oct 2012") def test_timeout_with_messaging(self): with self.assertRaises(IonTimeout) as cm: self.fsclient.request({}, op='takes_too_long', timeout=5) self.assertIn('execute in allotted time', cm.exception.message) @unittest.skipIf(os.getenv('CEI_LAUNCH_TEST', False), "Test reaches into container, doesn't work with CEI") @unittest.skip("heartbeat failing process is disabled") def test_heartbeat_failure(self): self.patch_cfg( 'pyon.ion.process.CFG', { 'cc': { 'timeout': { 'heartbeat_proc_count_threshold': 2, 'heartbeat': 1.0 } } }) svc = self.container.proc_manager.procs[self.pid] ip = svc._process stopar = AsyncResult() self.container.proc_manager.add_proc_state_changed_callback( lambda *args: stopar.set(args)) noticear = AsyncResult() # notify us when the call has been made ar = ip._routing_call(svc.takes_too_long, None, noticear=noticear) noticear.get(timeout=10) # wait for the call to be made # heartbeat a few times so we trigger the failure soon for x in xrange(2): ip.heartbeat() # wait for ip thread to kick over ip._ctrl_thread.join(timeout=5) # now wait for notice proc got canned stopargs = stopar.get(timeout=5) self.assertEquals(stopargs, (svc, ProcessStateEnum.FAILED, self.container)) # should've shut down, no longer in container's process list self.assertEquals(len(self.container.proc_manager.procs), 0)
def register_dataset(self, data_product_id=''): procs,_ = self.clients.resource_registry.find_resources(restype=RT.Process, id_only=True) pid = None for p in procs: if 'registration_worker' in p: pid = p if not pid: log.warning('No registration worker found') return rpc_cli = RPCClient(to_name=pid) rpc_cli.request({'data_product_id':data_product_id}, op='register_dap_dataset')
def register_dataset(self, dataset_id='', external_data_product_name=''): dataset_obj = self.read_dataset(dataset_id) dataset_obj.registered = True self.update_dataset(dataset=dataset_obj) external_data_product_name = external_data_product_name or dataset_obj.name procs,_ = self.clients.resource_registry.find_resources(restype=RT.Process, id_only=True) pid = None for p in procs: if 'registration_worker' in p: pid = p if not pid: log.warning('No registration worker found') return rpc_cli = RPCClient(to_name=pid) rpc_cli.request({'dataset_id':dataset_id, 'data_product_name':external_data_product_name}, op='register_dap_dataset')
def main(): parser = argparse.ArgumentParser(description="CC Control script") parser.add_argument("pidfile", help="pidfile to use. If not specified, uses the first one found.") parser.add_argument("command", help="command to send to the container agent", choices=IContainerAgent.names()) parser.add_argument("commandargs", metavar="arg", nargs="*", help="arguments to the command being sent") opts = parser.parse_args() pidfile = opts.pidfile if not pidfile: raise Exception("No pidfile specified") parms = {} with open(pidfile, "r") as pf: parms = msgpack.loads(pf.read()) assert parms, "No content in pidfile" node, ioloop = make_node(parms["messaging"]) cc = RPCClient(node=node, name=(parms["container-xp"], parms["container-agent"])) # make a manual call - this is to avoid having to have the IonObject for the call methdefs = [x[1] for x in IContainerAgent.namesAndDescriptions() if x[0] == opts.command] assert len(methdefs) == 1 arg_names = methdefs[0].positional # ('name', 'module', 'cls', 'config') msg_args = msgpack.dumps( dict(zip(arg_names, opts.commandargs)) ) # ('name', <usrinp1>, 'cls', <usrinp2>) -> { 'name' : <usrinp1>, 'cls': <usrinp2> } retval = cc.request(msg_args, op=opts.command) print "Returned", retval node.client.close()
class TestProcessInt(IonIntegrationTestCase): def setUp(self): self._start_container() self.pid = self.container.spawn_process('fake', 'pyon.ion.test.test_process', 'FakeService') self.fsclient = RPCClient(to_name='fake_service') @unittest.skip("timeouts removed 18 oct 2012") def test_timeout_with_messaging(self): with self.assertRaises(IonTimeout) as cm: self.fsclient.request({}, op='takes_too_long', timeout=5) self.assertIn('execute in allotted time', cm.exception.message) @unittest.skipIf(os.getenv('CEI_LAUNCH_TEST', False), "Test reaches into container, doesn't work with CEI") @unittest.skip("heartbeat failing process is disabled") def test_heartbeat_failure(self): self.patch_cfg('pyon.ion.process.CFG', {'cc':{'timeout':{'heartbeat_proc_count_threshold':2, 'heartbeat':1.0}}}) svc = self.container.proc_manager.procs[self.pid] ip = svc._process stopar = AsyncResult() self.container.proc_manager.add_proc_state_changed_callback(lambda *args: stopar.set(args)) noticear = AsyncResult() # notify us when the call has been made ar = ip._routing_call(svc.takes_too_long, None, noticear=noticear) noticear.get(timeout=10) # wait for the call to be made # heartbeat a few times so we trigger the failure soon for x in xrange(2): ip.heartbeat() # wait for ip thread to kick over ip._ctrl_thread.join(timeout=5) # now wait for notice proc got canned stopargs = stopar.get(timeout=5) self.assertEquals(stopargs, (svc, ProcessStateEnum.FAILED, self.container)) # should've shut down, no longer in container's process list self.assertEquals(len(self.container.proc_manager.procs), 0)
def register_dataset(self, dataset_id='', external_data_product_name=''): dataset_obj = self.read_dataset(dataset_id) dataset_obj.registered = True self.update_dataset(dataset=dataset_obj) external_data_product_name = external_data_product_name or dataset_obj.name procs, _ = self.clients.resource_registry.find_resources( restype=RT.Process, id_only=True) pid = None for p in procs: if 'registration_worker' in p: pid = p if not pid: log.warning('No registration worker found') return rpc_cli = RPCClient(to_name=pid) rpc_cli.request( { 'dataset_id': dataset_id, 'data_product_name': external_data_product_name }, op='register_dap_dataset')
def stats(cls,pid): ''' RPC Method for querying a Transform's internal statistics ''' rpc_cli = RPCClient(to_name=pid) return rpc_cli.request({},op='_stat')
def stats(cls, pid): ''' RPC Method for querying a Transform's internal statistics ''' rpc_cli = RPCClient(to_name=pid) return rpc_cli.request({}, op='_stat')