本文整理汇总了Python中cpc.util.conf.server_conf.ServerConf.getNodes方法的典型用法代码示例。如果您正苦于以下问题:Python ServerConf.getNodes方法的具体用法?Python ServerConf.getNodes怎么用?Python ServerConf.getNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cpc.util.conf.server_conf.ServerConf
的用法示例。
在下文中一共展示了ServerConf.getNodes方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from cpc.util.conf.server_conf import ServerConf [as 别名]
# 或者: from cpc.util.conf.server_conf.ServerConf import getNodes [as 别名]
def run(self, serverState, request, response):
conf = ServerConf()
host = request.getParam('host')
client_secure_port = request.getParam('client_secure_port')
result = dict()
#do we have a server with this hostname or fqdn?
connectedNodes = conf.getNodes()
if (connectedNodes.hostnameOrFQDNExists(host) == False):
serv = RawServerMessage(host, client_secure_port)
resp = ProcessedResponse(serv.sendAddNodeRequest(host))
if resp.isOK():
result = resp.getData()
nodeConnectRequest = NodeConnectRequest(result['serverId'],
int(client_secure_port),None,None,result['fqdn'],host)
conf.addSentNodeConnectRequest(nodeConnectRequest)
result['nodeConnectRequest']=nodeConnectRequest
log.info("Added node %s" % host)
response.add('', result)
else:
response.add("Remote server said: %s"%resp.getMessage(),
status="ERROR")
else:
errorMessage = "%s is already trusted" % host
response.add(errorMessage, status="ERROR")
log.info(errorMessage)
示例2: testRemoveNodes
# 需要导入模块: from cpc.util.conf.server_conf import ServerConf [as 别名]
# 或者: from cpc.util.conf.server_conf.ServerConf import getNodes [as 别名]
def testRemoveNodes(self):
conf = ServerConf(confdir=self.confDir)
conf.addNode('localhost1')
conf.addNode('localhost2')
nodes = conf.getNodes()
self.assertEquals(nodes.size(),2)
self.assertTrue(nodes.exists("localhost1","13807"))
self.assertTrue(nodes.exists("localhost2","13807") )
conf.removeNode('localhost1')
nodes = conf.getNodes()
self.assertEquals(nodes.size(),1)
self.assertFalse(nodes.exists("localhost1","13807"))
self.assertTrue(nodes.exists("localhost2","13807") )
示例3: testStart2Servers
# 需要导入模块: from cpc.util.conf.server_conf import ServerConf [as 别名]
# 或者: from cpc.util.conf.server_conf.ServerConf import getNodes [as 别名]
def testStart2Servers(self):
numServers = 2
self.createConfFolders(numServers)
hostname = gethostname()
node0HttpsPort = 13807
node1HttpsPort = 13808
node0HttpPort = 14807
node1HttpPort = 14808
for i in range(numServers):
args = ['../../../../cpc-server','-c',self.serverConfs[i],'start'] #doing cpc.server.server.forkAndRun(cf, debug ) directly here will will for some strange reason mess up things when shutting down, the process wont shutdown
subprocess.call(args)
time.sleep(2)
#connect node 0 to node 1
args = ['../../../../cpc-server','-c',self.serverConfs[0],'connnect-server',hostname,str(node1HttpPort)] #doing cpc.server.server.forkAndRun(cf, debug ) directly here will will for some strange reason mess up things when shutting down, the process wont shutdown
subprocess.call(args)
args = ['../../../../cpc-server','-c',self.serverConfs[1],'trust',hostname,str(node0HttpsPort)] #doing cpc.server.server.forkAndRun(cf, debug ) directly here will will for some strange reason mess up things when shutting down, the process wont shutdown
subprocess.call(args)
#verify existense of of nodes in each conf file
conf1 = ServerConf(confdir=self.serverConfs[0], reload=True)
node0Nodes = conf1.getNodes()
self.assertTrue(node0Nodes.exists(hostname,node1HttpsPort))
conf2 = ServerConf(confdir=self.serverConfs[1],reload=True)
node1Nodes = conf2.getNodes()
self.assertTrue(node1Nodes.exists(hostname,node0HttpsPort))
#do a network topology call
conf = ConnectionBundle(confdir=self.serverConfs[0],reload=True)
client = ClientMessage()
topology =ProcessedResponse(client.networkTopology()).getData()
self.assertEquals(topology.size() ,2)
示例4: establishOutBoundConnections
# 需要导入模块: from cpc.util.conf.server_conf import ServerConf [as 别名]
# 或者: from cpc.util.conf.server_conf.ServerConf import getNodes [as 别名]
def establishOutBoundConnections():
conf = ServerConf()
log.log(cpc.util.log.TRACE,"Starting to establish outgoing connections")
for node in conf.getNodes().nodes.itervalues():
establishOutboundConnection(node)
log.log(cpc.util.log.TRACE,"Finished establishing outgoing "
"connections")
示例5: establishInboundConnections
# 需要导入模块: from cpc.util.conf.server_conf import ServerConf [as 别名]
# 或者: from cpc.util.conf.server_conf.ServerConf import getNodes [as 别名]
def establishInboundConnections(serverState):
"""
for each node that is not connected
try to establish an inbound connection
"""
conf = ServerConf()
log.log(cpc.util.log.TRACE,"Starting to establish incoming connections")
for node in conf.getNodes().nodes.itervalues():
establishInboundConnection(node, serverState)
log.log(cpc.util.log.TRACE,"Finished establishing incoming "
"connections")
示例6: requestNetworkTopology
# 需要导入模块: from cpc.util.conf.server_conf import ServerConf [as 别名]
# 或者: from cpc.util.conf.server_conf.ServerConf import getNodes [as 别名]
def requestNetworkTopology(topology,serverState=None):
"""
Asks each neigbouring node for their network topology
inputs:
topology:Nodes The list of the topology generated so far
serverState:ServerState
if provided worker states are fetched.
since this method is called by getNetworkTopology() which in turn
is called from places where we do not pass (and don't want) the serverState
we provide this option. Also it is not needed as the calling server always
knows the most up to date state of its own workers.
"""
conf = ServerConf()
thisNode = Node.getSelfNode(conf)
thisNode.setNodes(conf.getNodes())
topology.addNode(thisNode)
if serverState:
thisNode.workerStates = WorkerStateHandler.getConnectedWorkers(serverState.getWorkerStates())
for node in thisNode.getNodes().nodes.itervalues():
if topology.exists(node.getId()) == False:
#connect to correct node
if node.isConnected():
try:
clnt = DirectServerMessage(node,conf=conf)
#send along the current topology
rawresp = clnt.networkTopology(topology)
processedResponse = ProcessedResponse(rawresp)
topology = processedResponse.getData()
except ServerConnectionError as e:
#we cannot connect to the node,
# and its marked as unreachable
#we must still add it to the topology
log.error("node %s unreachable when asking for network "
"topology: error was %s"%(node.getId(),e.__str__()))
topology.addNode(node)
#todo notify in topology that this node is not connected?
return topology
示例7: reestablishConnections
# 需要导入模块: from cpc.util.conf.server_conf import ServerConf [as 别名]
# 或者: from cpc.util.conf.server_conf.ServerConf import getNodes [as 别名]
def reestablishConnections(serverState):
'''
Tries to periodically check for nodes that have gone down and reestablish
connections to them
'''
log.log(cpc.util.log.TRACE,"Starting reestablish connection thread")
conf = ServerConf()
while True:
for node in conf.getNodes().nodes.itervalues():
if not node.isConnected():
establishInboundConnection(node,serverState)
establishOutboundConnection(node)
if not node.isConnected():
log.log(cpc.util.log.TRACE,("Tried to reestablish a "
"connection"
" to %s but failed "%node.toString()))
reconnectInterval = conf.getReconnectInterval()
time.sleep(reconnectInterval)
示例8: broadcastToNeighboursOnly
# 需要导入模块: from cpc.util.conf.server_conf import ServerConf [as 别名]
# 或者: from cpc.util.conf.server_conf.ServerConf import getNodes [as 别名]
def broadcastToNeighboursOnly(self, fields, files=[], headers=dict()):
conf = ServerConf()
for node in conf.getNodes().nodes.itervalues():
self._sendMessage(node, fields, files, headers)