def initialize(self,endNodeId): topology=self.getNetworkTopology() if not topology: log.error("Cannot get network topology") return # this is myself: startNode = Node.getSelfNode(self.conf) self.endNode = topology.nodes.get(endNodeId) log.log(cpc.util.log.TRACE,"Finding route between %s(%s %s) and %s(%s " "%s"")"%(startNode.server_id,startNode.getHostname(), startNode.getServerSecurePort(), self.endNode.server_id, self.endNode.getHostname(),self.endNode.getServerSecurePort())) route = Nodes.findRoute(startNode, self.endNode,topology) self.hostNode = route[1] #route[0] is the current host self.host = self.hostNode.getHostname() self.port = self.hostNode.getServerSecurePort() self.serverId = self.hostNode.getId() log.log(cpc.util.log.TRACE,"Server-to-server connecting to %s(%s:%s)"% (self.serverId,self.host,self.port))
def getCommandOutputData(cmdID, workerServer): log.log(cpc.util.log.TRACE,"Trying to pull command output from %s"% workerServer) s2smsg=ServerMessage(workerServer) rundata_response = s2smsg.pullAssetRequest(cmdID, Asset.cmdOutput()) if rundata_response.getType() != "application/x-tar": log.error("Incorrect response type: %s, should be %s"% (rundata_response.getType(), 'application/x-tar')) if rundata_response.getType() == "text/json": errormsg=rundata_response.message.read(len(rundata_response. message)) presp=ProcessedResponse(rundata_response) if not presp.isOK(): log.error('Response from worker server not OK: %s'% errormsg) else: s2smsg.clearAssetRequest(cmdID) log.log(cpc.util.log.TRACE, "Successfully pulled command output data from %s."% workerServer) return rundata_response #runfile = rundata_response.getRawData() #this doesnt work because the mmap closes as it is returned return None
def run(self, serverState, request, response): cmdID=request.getParam('cmd_id') assetType=request.getParam('asset_type') try: runfile=serverState.getLocalAssets().getAsset(cmdID, assetType).getData() except: log.error("Local asset cmdid=%s not found!"%cmdID) response.add("Command output data from cmdID %s not found on this server (%s)."% (cmdID,serverState.conf.getHostName()), status="ERROR") else: asset=serverState.getLocalAssets().getCmdOutputAsset(cmdID) log.log(cpc.util.log.TRACE,"Local asset cmdid=%s \nproject server=%s"% (asset.cmdID, asset.projectServer)) response.setFile(runfile,'application/x-tar') log.info("Pulled asset %s/%s"%(cmdID, assetType))
def run(self, serverState, request, response): cmdID = request.getParam('cmd_id') assetType = request.getParam('asset_type') try: runfile = serverState.getLocalAssets().getAsset( cmdID, assetType).getData() except: log.error("Local asset cmdid=%s not found!" % cmdID) response.add( "Command output data from cmdID %s not found on this server (%s)." % (cmdID, serverState.conf.getHostName()), status="ERROR") else: asset = serverState.getLocalAssets().getCmdOutputAsset(cmdID) log.log( cpc.util.log.TRACE, "Local asset cmdid=%s \nproject server=%s" % (asset.cmdID, asset.projectServer)) response.setFile(runfile, 'application/x-tar') log.info("Pulled asset %s/%s" % (cmdID, assetType))
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