def getNodes(self): """ Return tuple with two lists of nodes (NodeAdmin instances) for all active nodes. First item in the returned tuple is a list of czar nodes, second item is a list of worker nodes. """ mgmt = nodeMgmt.NodeMgmt(self.css, self.wmgrSecretFile) czars = [] workers = [] try: # try get node(s) from CSS czars = mgmt.select(css.NODE_STATE_ACTIVE, 'czar') workers = mgmt.select(css.NODE_STATE_ACTIVE, 'worker') except css.CssError as exc: _LOG.error('Failed to get nodes from CSS: %s', exc) # add explicit car node if there was no czar in CSS if not czars and self.czar: host, port = self.czar czars.append( nodeAdmin.NodeAdmin(host=host, port=port, wmgrSecretFile=self.wmgrSecretFile)) return czars, workers
def __init__(self, config, data_reader, db_name, multi_node, out_dirname): self.config = config self.dataConfig = data_reader self._dbName = db_name self._multi_node = multi_node self._out_dirname = out_dirname self.logger = logging.getLogger(__name__) if self._multi_node: self.css = css.CssAccess.createFromConfig(self.config['css'], '') self.nMgmt = nodeMgmt.NodeMgmt( self.css, wmgrSecretFile=self.config['wmgr']['secret']) self.nWmgrs = {} for node in self.nMgmt.select(nodeType='worker', state='ACTIVE'): self.nWmgrs[node.name()] = node.wmgrClient() # Host name for wmgr is the same as master qserv host self.czar_wmgr = WmgrClient(host=self.config['qserv']['master'], port=self.config['wmgr']['port'], secretFile=self.config['wmgr']['secret'])
def testMgmtSelect(self): """ Test for WorkerMgmt.select methods """ # instantiate CSS with some initial data initData = """\ /\t\\N /css_meta\t\\N /css_meta/version\t{version} /NODES\t\\N /NODES/worker-1\tACTIVE /NODES/worker-1/.packed.json\t{{"type": "worker", "host": "worker.domain", "port": 5012}} /NODES/worker-2\tINACTIVE /NODES/worker-2/.packed.json\t{{"type": "backup", "host": "worker.domain", "port": 5013}} """ initData = initData.format(version=css.VERSION) css_inst = _makeCss(initData) mgr = nodeMgmt.NodeMgmt(css_inst) # should return all nodes nodes = mgr.selectDict() self.assertEqual(len(nodes), 2) self.assertIn('worker-1', nodes) self.assertIn('worker-2', nodes) # select 'ACTIVE' or 'INACTIVE', should return two nodes nodes = mgr.selectDict(state=["ACTIVE", "INACTIVE"]) self.assertEqual(len(nodes), 2) self.assertIn('worker-1', nodes) self.assertIn('worker-2', nodes) # select 'ACTIVE', should return one node nodes = mgr.selectDict(state=["ACTIVE"]) self.assertEqual(len(nodes), 1) self.assertIn('worker-1', nodes) # select 'INACTIVE', should return one node nodes = mgr.selectDict(state="INACTIVE") self.assertEqual(len(nodes), 1) self.assertIn('worker-2', nodes) # select 'worker' or 'backup', should return two nodes nodes = mgr.selectDict(nodeType=['worker', 'backup']) self.assertEqual(len(nodes), 2) self.assertIn('worker-1', nodes) self.assertIn('worker-2', nodes) # select 'worker', should return one node nodes = mgr.selectDict(nodeType=['worker']) self.assertEqual(len(nodes), 1) self.assertIn('worker-1', nodes) # select 'backup', should return one node nodes = mgr.selectDict(nodeType='backup') self.assertEqual(len(nodes), 1) self.assertIn('worker-2', nodes) # combinations nodes = mgr.selectDict(state="ACTIVE", nodeType='worker') self.assertEqual(len(nodes), 1) self.assertIn('worker-1', nodes) nodes = mgr.selectDict(state="INACTIVE", nodeType='backup') self.assertEqual(len(nodes), 1) self.assertIn('worker-2', nodes) nodes = mgr.selectDict(state="ACTIVE", nodeType='backup') self.assertEqual(len(nodes), 0) nodes = mgr.selectDict(state="INACTIVE", nodeType='worker') self.assertEqual(len(nodes), 0)