Omaha #4129 Fix server selection logic used by requestAT, requestTCV, and sendTCV

Change-Id: I1b31a05844e8a760d01bac57e2897bed28df198c

Former-commit-id: fb32cc53c476d64368e1a9b607e8b2a8e21dfb2c
This commit is contained in:
Ron Anderson 2015-03-12 09:47:36 -05:00
parent 40fdfa4495
commit bf2ff2d80f
8 changed files with 220 additions and 425 deletions

View file

@ -26,6 +26,7 @@
# Date Ticket# Engineer Description
# ------------ ---------- ----------- --------------------------
# 12/05/14 4953 randerso Changed to use LocalizationSupport
# 03/10/2015 #4129 randerso Fixed error logging
#
##
@ -225,7 +226,7 @@ def createAreaDictionary(outputDir, mapDict):
if areadict.has_key(ean) and d != areadict[ean]:
LogStream.logDiag("Mismatch of definitions in " +\
LogStream.logProblem("Mismatch of definitions in " +\
"AreaDictionary creation. EditAreaName=", ean,
"AreaDict=\n", areadict[ean], "\nIgnored=\n", d)
else:

View file

@ -35,6 +35,7 @@
# ------------ ---------- ----------- --------------------------
# 12/10/14 #4953 randerso Cleaned up imports,
# improved spawning of shell cmd
# 03/10/2015 #4129 randerso Refactored server selection code into a reusable method
#
##
@ -49,12 +50,15 @@ import iscUtil
class IrtAccess():
#Constructor taking the web URL for the ISC Routing Table
def __init__(self, ancfURL=None, bncfURL=None):
def __init__(self, ancfURL=None, bncfURL=None, logger=None):
self.__addrs = {}
self.__addrs['ANCF'] = ancfURL
self.__addrs['BNCF'] = bncfURL
self.__registered = None #flag to indicate whether we registered
self.__logger=iscUtil.getLogger("irtAccess","irtServer.log")
if logger is not None:
self.__logger=logger
else:
self.__logger=iscUtil.getLogger("irtAccess","irtServer.log")
def logEvent(self,*msg):
self.__logger.info(iscUtil.tupleToString(*msg))
@ -527,3 +531,118 @@ class IrtAccess():
s = "mhs=" + mhsid + ",host=" + host + ",port=" + port +\
",proto=" + protocol + ",site=" + site
return s
def createDestinationXML(self, destSites, requestingServer):
#--------------------------------------------------------------------
# Assemble XML source/destination document
#--------------------------------------------------------------------
iscE = ElementTree.Element('isc')
self.addSourceXML(iscE, requestingServer)
self.logEvent("Requesting Server:", self.printServerInfo(requestingServer))
# who is running the domains requested?
status, xml = self.getServers(destSites)
if not status:
raise Exception('Failure to getServers from IRT')
# decode the XML
try:
serverTree = ElementTree.ElementTree(ElementTree.XML(xml))
serversE = serverTree.getroot()
except:
self.logException("Malformed XML from getServers()")
raise
if serversE.tag != "servers":
raise Exception("Servers packet missing from web server")
# process each requested domain returned to us
msgSendDest = []
chosenServers = []
matchingServers = []
for domainE in serversE:
if domainE.tag != "domain":
continue
domain = domainE.get('site')
servers = [] #list of servers for this domain
# decode each server in the domain
for addressE in domainE.getchildren():
info = self.decodeXMLAddress(addressE)
if info is None:
continue #not address tag
servers.append(info)
matchingServers.append(info)
# server search list in priority. The px3 entries are used for
# dual domain for AFC.
hp = [('dx4','98000000'),('px3', '98000000'), ('dx4','98000001'),
('px3', '98000001')]
# choose one server from this domain, find first dx4, 98000000
# try to use one with the same mhsidDest as the site, which
# would be the primary operational GFE. Note that the px3 entries
# are for AFC.
found = False
for matchServer, matchPort in hp:
if found:
break
for server in servers:
if server['host'][0:3] == matchServer and \
server['port'] == matchPort and server['mhsid'] == domain:
chosenServers.append(server)
if server['mhsid'] not in msgSendDest:
msgSendDest.append(server['mhsid'])
found = True
break
# find first dx4, 98000000, but perhaps a different mhsid
# this is probably not the primary operational GFE
for matchServer, matchPort in hp:
if found:
break
for server in servers:
if server['host'][0:3] == matchServer and \
server['port'] == matchPort:
chosenServers.append(server)
if server['mhsid'] not in msgSendDest:
msgSendDest.append(server['mhsid'])
found = True
break
# if didn't find standard one, then take the first one, but don't
# take ourselves unless we are the only one.
if not found and servers:
for server in servers:
if server['mhsid'] != requestingServer['mhsid'] \
and server['host'] != requestingServer['host'] \
and server['port'] != requestingServer['port'] \
and server['site'] != requestingServer['site']:
chosenServers.append(server)
if server['mhsid'] not in msgSendDest:
msgSendDest.append(server['mhsid'])
found = True
break;
if not found:
chosenServers.append(servers[0])
if servers[0]['mhsid'] not in msgSendDest:
msgSendDest.append(servers[0]['mhsid'])
# Display the set of matching servers
s = "Matching Servers:"
for x in matchingServers:
s += "\n" + self.printServerInfo(x)
self.logEvent(s)
# Display the chosen set of servers
s = "Chosen Servers:"
for x in chosenServers:
s += "\n" + self.printServerInfo(x)
self.logEvent(s)
self.addDestinationXML(iscE, chosenServers)
return msgSendDest, iscE

View file

@ -49,6 +49,7 @@ from subprocess import CalledProcessError
# 12/08/2014 4953 randerso Added support for sending/receiving TCV files
# Additional code clean up
# 03/05/2015 4129 randerso Fix exception handling on subprocess calls
# Fixed error when no TCV files were found
#
##
PURGE_AGE = 30 * 24 * 60 * 60 # 30 days in seconds
@ -319,21 +320,24 @@ def getTCVFiles(ourMhsID, srcServer, destE):
fname = fp.name
try:
TCVUtil.packageTCVFiles(localSites, fname, getLogger())
if TCVUtil.packageTCVFiles(localSites, fname, getLogger()):
from xml.etree import ElementTree
from xml.etree.ElementTree import Element, SubElement
iscE = ElementTree.Element('isc')
irt.addSourceXML(iscE, destServer)
irt.addDestinationXML(iscE, [srcServer])
# create the XML file
with tempfile.NamedTemporaryFile(suffix='.xml', dir=tcvProductsDir, delete=False) as fd:
fnameXML = fd.name
fd.write(ElementTree.tostring(iscE))
# send the files to srcServer
sendMHSMessage("PUT_TCV_FILES", srcServer['mhsid'], [fname, fnameXML])
from xml.etree import ElementTree
from xml.etree.ElementTree import Element, SubElement
iscE = ElementTree.Element('isc')
irt.addSourceXML(iscE, destServer)
irt.addDestinationXML(iscE, [srcServer])
# create the XML file
with tempfile.NamedTemporaryFile(suffix='.xml', dir=tcvProductsDir, delete=False) as fd:
fnameXML = fd.name
fd.write(ElementTree.tostring(iscE))
# send the files to srcServer
sendMHSMessage("PUT_TCV_FILES", srcServer['mhsid'], [fname, fnameXML])
else:
logEvent('No TCV files to send')
except:
logException('Error sending TCV files for ' + str(localSites))
@ -508,14 +512,6 @@ def serviceISCRequest(dataFile):
ServiceISCRequest.serviceRequest(JUtil.pyValToJavaObj(info['parms']),xmlDestinations,siteConfig.GFESUITE_SITEID)
# ifpServer.serviceISCRequest(info['parms'], xmlDestinations)
# get servers direct call for IRT
def irtGetServers(ancfURL, bncfURL, iscWfosWanted):
import IrtAccess
irt = IrtAccess.IrtAccess(ancfURL, bncfURL)
xml = None
status, xml = irt.getServers(iscWfosWanted)
return xml
def sendMHSMessage(subject, adressees, attachments, xmtScript=None):
# Transmit the request -- do string substitution
import siteConfig

View file

@ -26,6 +26,7 @@
# Date Ticket# Engineer Description
# ------------ ---------- ----------- --------------------------
# 12/12/14 4953 randerso Initial Creation.
# 03/10/2015 #4129 randerso Fixed error when no TCV files were found
#
##
import glob, os, subprocess, time
@ -69,11 +70,20 @@ def packageTCVFiles(siteList, fileName, logger):
for siteID in siteList:
tcvDir = os.path.join(siteID, "gfe", "tcvAdvisories")
found = False
for fileType in ["*.json", "*.allCAN"]:
path = os.path.join(tcvDir, fileType)
if len(glob.glob(os.path.join(siteDir, path))) > 0:
cmd += " " + path
logger.debug("cmd: '" + cmd + "'")
subprocess.check_call([cmd], shell=True)
found = True
if found:
logger.info("cmd: '" + cmd + "'")
try:
subprocess.check_call([cmd], shell=True)
except subprocess.CalledProcessError as e:
logger.error("cmd returned error code: ", e.returncode, e.output)
except:
loggger.exception("cmd threw exception")
return found

View file

@ -29,6 +29,7 @@
# 02/06/13 1447 dgilling Initial Creation.
# 01/24/14 2504 randerso change to use iscUtil.getLogger for consistency
# 05/15/14 #3157 dgilling Support multiple TPC and SPC sites.
# 03/10/2015 #4129 randerso Refactored server selection code into a reusable method
#
#
@ -37,7 +38,7 @@ import os
import sys
import tempfile
import time
import xml.etree.ElementTree as ET
from xml.etree import ElementTree
import IrtAccess
import siteConfig
@ -115,125 +116,23 @@ def execute_request_at(serverHost, serverPort, serverProtocol, mhsid, siteID, an
buf = cPickle.dumps(data)
fp.write(buf)
#--------------------------------------------------------------------
# Assemble XML source/destination document
#--------------------------------------------------------------------
msgSendDest = [] #list of mhs sites to send request
sourceServer = {'mhsid' : mhsid,
'host' : serverHost,
'port' : serverPort,
'protocol': serverProtocol,
'site' : siteID}
irt = IrtAccess.IrtAccess(ancf, bncf)
iscE = ET.Element('isc')
# this is the requestor of the data
sourceServer = {'mhsid': mhsid, 'host': serverHost, 'port': serverPort,
'protocol': serverProtocol, 'site': siteID}
irt.addSourceXML(iscE, sourceServer)
logger.info("Requesting Server: " + irt.printServerInfo(sourceServer))
# who is running the domains requested?
sites = VTECPartners.VTEC_TABLE_REQUEST_SITES
if not sites:
logger.error('No sites defined for VTEC_TABLE_REQUEST_SITES')
sys.exit(1)
status, xml = irt.getServers(sites)
if not status:
logger.error('Failure to getServers from IRT')
sys.exit(1)
# decode the XML
try:
serverTree = ET.ElementTree(ET.XML(xml))
serversE = serverTree.getroot()
except:
logger.exception("Malformed XML on getServers()")
sys.exit(1)
if serversE.tag != "servers":
logger.error("Servers packet missing from web server")
sys.exit(1)
# process each requested domain returned to us
chosenServers = []
matchingServers = []
for domainE in serversE:
if domainE.tag != "domain":
continue
servers = [] #list of servers for this domain
# decode each server in the domain
for addressE in domainE.getchildren():
info = irt.decodeXMLAddress(addressE)
if info is None:
continue #not address tag
servers.append(info)
matchingServers.append(info)
# server search list in priority. The px3 entries are used for
# dual domain for AFC.
hp = [('dx4','98000000'),('px3', '98000000'), ('dx4','98000001'),
('px3', '98000001')]
# choose one server from this domain, find first dx4, 98000000
# try to use one with the same mhsidDest as the site, which
# would be the primary operational GFE. Note that the px3 entries
# are for AFC.
found = False
for matchServer, matchPort in hp:
for server in servers:
if server['host'][0:3] == matchServer and \
server['port'] == matchPort and server['mhsid'] == siteID:
chosenServers.append(server)
if server['mhsid'] not in msgSendDest:
msgSendDest.append(server['mhsid'])
found = True
break
# find first dx4, 98000000, but perhaps a different mhsid
# this is probably not the primary operational GFE
if not found:
for matchServer, matchPort in hp:
for server in servers:
if server['host'][0:3] == matchServer and \
server['port'] == matchPort:
chosenServers.append(server)
if server['mhsid'] not in msgSendDest:
msgSendDest.append(server['mhsid'])
found = True
break
# if didn't find standard one, then take the first one, but don't
# take ourselves unless we are the only one.
if not found and servers:
for server in servers:
if server['mhsid'] != mhsid and server['host'] != serverHost \
and server['port'] != serverPort and \
server['mhsid'] != siteID:
chosenServers.append(server)
if server['mhsid'] not in msgSendDest:
msgSendDest.append(server['mhsid'])
found = True
if not found:
chosenServers.append(servers[0])
if servers[0]['mhsid'] not in msgSendDest:
msgSendDest.append(servers[0]['mhsid'])
# Display the set of matching servers
s = "Matching Servers:"
for x in matchingServers:
s += "\n" + irt.printServerInfo(x)
logger.info(s)
# Display the chosen set of servers
s = "Chosen Servers:"
for x in chosenServers:
s += "\n" + irt.printServerInfo(x)
logger.info(s)
irt.addDestinationXML(iscE, chosenServers)
destSites = VTECPartners.VTEC_TABLE_REQUEST_SITES
if not destSites:
raise Exception('No destSites defined for VTEC_TABLE_REQUEST_SITES')
irt = IrtAccess.IrtAccess(ancf, bncf, logger=logger)
msgSendDest, xml = irt.createDestinationXML(destSites, sourceServer)
# create the XML file
with tempfile.NamedTemporaryFile(suffix='.xml', dir=tempdir, delete=False) as fd:
fnameXML = fd.name
fd.write(ET.tostring(iscE))
fd.write(ElementTree.tostring(xml))
#--------------------------------------------------------------------
# Now send the message

View file

@ -26,6 +26,7 @@
# Date Ticket# Engineer Description
# ------------ ---------- ----------- --------------------------
# 12/05/14 4953 randerso Initial Creation.
# 03/10/2015 #4129 randerso Refactored server selection code into a reusable method
#
##
import os, errno, tempfile
@ -43,134 +44,7 @@ def init_logging():
import iscUtil
import logging
global logger
logger = iscUtil.getLogger("requestTCV", logLevel=logging.DEBUG)
def createDestinationXML(siteID, host, port, protocol, mhsid, ancf, bncf, logger):
#--------------------------------------------------------------------
# Assemble XML source/destination document
#--------------------------------------------------------------------
msgSendDest = [] #list of mhs sites to send request
irt = IrtAccess.IrtAccess(ancf, bncf)
iscE = ElementTree.Element('isc')
# this is the requestor of the data
sourceServer = {'mhsid' : mhsid,
'host' : host,
'port' : port,
'protocol': protocol,
'site' : siteID}
irt.addSourceXML(iscE, sourceServer)
logger.info("Requesting Server: " + irt.printServerInfo(sourceServer))
# who is running the domains requested?
sites = VTECPartners.VTEC_TABLE_REQUEST_SITES
if not sites:
logger.error('No sites defined for VTEC_TABLE_REQUEST_SITES')
sys.exit(1)
status, xml = irt.getServers(sites)
if not status:
logger.error('Failure to getServers from IRT')
sys.exit(1)
# decode the XML
try:
serverTree = ElementTree.ElementTree(ElementTree.XML(xml))
serversE = serverTree.getroot()
except:
logger.exception("Malformed XML on getServers()")
sys.exit(1)
if serversE.tag != "servers":
logger.error("Servers packet missing from web server")
sys.exit(1)
# process each requested domain returned to us
chosenServers = []
matchingServers = []
for domainE in serversE:
if domainE.tag != "domain":
continue
servers = [] #list of servers for this domain
# decode each server in the domain
for addressE in domainE.getchildren():
info = irt.decodeXMLAddress(addressE)
if info is None:
continue #not address tag
# remove unneeded keys
for key in ['parms', 'area', 'domain']:
if info.has_key(key):
del info[key]
servers.append(info)
matchingServers.append(info)
# server search list in priority. The px3 entries are used for
# dual domain for AFC.
hp = [('dx4','98000000'),('px3', '98000000'), ('dx4','98000001'),
('px3', '98000001')]
# choose one server from this domain, find first dx4, 98000000
# try to use one with the same mhsidDest as the site, which
# would be the primary operational GFE. Note that the px3 entries
# are for AFC.
found = False
for matchServer, matchPort in hp:
for server in servers:
if server['host'][0:3] == matchServer and \
server['port'] == matchPort and server['mhsid'] == siteID:
chosenServers.append(server)
if server['mhsid'] not in msgSendDest:
msgSendDest.append(server['mhsid'])
found = True
break
# find first dx4, 98000000, but perhaps a different mhsid
# this is probably not the primary operational GFE
if not found:
for matchServer, matchPort in hp:
for server in servers:
if server['host'][0:3] == matchServer and \
server['port'] == matchPort:
chosenServers.append(server)
if server['mhsid'] not in msgSendDest:
msgSendDest.append(server['mhsid'])
found = True
break
# if didn't find standard one, then take the first one, but don't
# take ourselves unless we are the only one.
if not found and servers:
for server in servers:
if server['mhsid'] != mhsid and server['host'] != host \
and server['port'] != port and \
server['mhsid'] != siteID:
chosenServers.append(server)
if server['mhsid'] not in msgSendDest:
msgSendDest.append(server['mhsid'])
found = True
if not found:
chosenServers.append(server)
if servers[0]['mhsid'] not in msgSendDest:
msgSendDest.append(servers[0]['mhsid'])
# Display the set of matching servers
s = "Matching Servers:"
for x in matchingServers:
s += "\n" + irt.printServerInfo(x)
logger.info(s)
# Display the chosen set of servers
s = "Chosen Servers:"
for x in chosenServers:
s += "\n" + irt.printServerInfo(x)
logger.info(s)
irt.addDestinationXML(iscE, chosenServers)
return msgSendDest, iscE
logger = iscUtil.getLogger("requestTCV", logLevel=logging.INFO)
def runFromJava(siteID, config):
import siteConfig
@ -191,8 +65,19 @@ def runFromJava(siteID, config):
if e.errno != errno.EEXIST:
logger.warn("%s: '%s'" % (e.strerror,e.filename))
sourceServer = {'mhsid' : mhsid,
'host' : host,
'port' : port,
'protocol': protocol,
'site' : siteID}
try:
msgSendDest, xml = createDestinationXML(siteID, host, port, protocol, mhsid, ancf, bncf, logger)
destSites = VTECPartners.VTEC_TABLE_REQUEST_SITES
if not destSites:
raise Exception('No destSites defined for VTEC_TABLE_REQUEST_SITES')
irt = IrtAccess.IrtAccess(ancf, bncf, logger=logger)
msgSendDest, xml = irt.createDestinationXML(destSites, sourceServer)
# create the XML file
with tempfile.NamedTemporaryFile(suffix='.xml', dir=tempdir, delete=False) as fd:
fnameXML = fd.name
@ -204,7 +89,6 @@ def runFromJava(siteID, config):
if len(msgSendDest) > 0:
# Now send the message
irt = IrtAccess.IrtAccess(ancf, bncf)
irt.transmitFiles("GET_TCV_FILES", msgSendDest, mhsid, [fnameXML], xmtScript)
except:
logger.exception('Error requesting TCV files for site: ' + siteID)

View file

@ -29,6 +29,7 @@
# 02/08/13 1447 dgilling Initial Creation.
# 01/24/14 2504 randerso change to use iscUtil.getLogger for consistency
# 05/15/14 #3157 dgilling Support multiple TPC and SPC sites.
# 03/10/2015 #4129 randerso Removed sys.exit() call
#
#
@ -36,11 +37,10 @@
import cPickle
import gzip
import os
import sys
import time
import tempfile
import stat
import xml.etree.ElementTree as ET
from xml.etree import ElementTree
import IrtAccess
import JUtil
@ -170,7 +170,7 @@ def execute_send_at(myServerHost, myServerPort, myServerProtocol,
#--------------------------------------------------------------------
# Create the destination XML file
#--------------------------------------------------------------------
iscOut = ET.Element('isc')
iscOut = ElementTree.Element('isc')
irt.addSourceXML(iscOut, myServer)
destServers = []
@ -179,7 +179,7 @@ def execute_send_at(myServerHost, myServerPort, myServerProtocol,
with open(xmlIncoming,'rb') as fd:
xml = fd.read()
os.remove(xmlIncoming)
reqTree = ET.ElementTree(ET.XML(xml))
reqTree = ElementTree.ElementTree(ElementTree.XML(xml))
sourceE = reqTree.find('source')
for addressE in sourceE.getchildren():
destServer = irt.decodeXMLAddress(addressE)
@ -214,7 +214,7 @@ def execute_send_at(myServerHost, myServerPort, myServerProtocol,
tempdir = os.path.join(siteConfig.GFESUITE_HOME, "products", "ATBL")
with tempfile.NamedTemporaryFile(suffix='.xml', dir=tempdir, delete=False) as fd:
fnameXML = fd.name
fd.write(ET.tostring(iscOut))
fd.write(ElementTree.tostring(iscOut))
#--------------------------------------------------------------------
# Send it
@ -285,7 +285,7 @@ def runFromJava(myServerHost, myServerPort, myServerProtocol, myServerMHSID,
xmtScript)
except:
logger.exception('Error in sendAT:')
sys.exit(1)
raise
#--------------------------------------------------------------------
# Finish

View file

@ -26,6 +26,7 @@
# Date Ticket# Engineer Description
# ------------ ---------- ----------- --------------------------
# 12/05/14 4953 randerso Initial Creation.
# 03/10/2015 #4129 randerso Refactored server selection code into a reusable method
#
##
import os, errno, tempfile
@ -44,136 +45,9 @@ def init_logging():
import iscUtil
import logging
global logger
logger = iscUtil.getLogger("sendTCV", logLevel=logging.DEBUG)
logger = iscUtil.getLogger("sendTCV", logLevel=logging.INFO)
def createDestinationXML(siteID, host, port, protocol, mhsid, ancf, bncf, logger):
#--------------------------------------------------------------------
# Assemble XML source/destination document
#--------------------------------------------------------------------
msgSendDest = [] #list of mhs sites to send request
irt = IrtAccess.IrtAccess(ancf, bncf)
iscE = ElementTree.Element('isc')
# this is the requestor of the data
sourceServer = {'mhsid' : mhsid,
'host' : host,
'port' : port,
'protocol': protocol,
'site' : siteID}
irt.addSourceXML(iscE, sourceServer)
logger.info("Requesting Server: " + irt.printServerInfo(sourceServer))
# who is running the domains requested?
sites = VTECPartners.VTEC_TABLE_REQUEST_SITES
if not sites:
logger.error('No sites defined for VTEC_TABLE_REQUEST_SITES')
sys.exit(1)
status, xml = irt.getServers(sites)
if not status:
logger.error('Failure to getServers from IRT')
sys.exit(1)
# decode the XML
try:
serverTree = ElementTree.ElementTree(ElementTree.XML(xml))
serversE = serverTree.getroot()
except:
logger.exception("Malformed XML on getServers()")
sys.exit(1)
if serversE.tag != "servers":
logger.error("Servers packet missing from web server")
sys.exit(1)
# process each requested domain returned to us
chosenServers = []
matchingServers = []
for domainE in serversE:
if domainE.tag != "domain":
continue
servers = [] #list of servers for this domain
# decode each server in the domain
for addressE in domainE.getchildren():
info = irt.decodeXMLAddress(addressE)
if info is None:
continue #not address tag
# remove unneeded keys
for key in ['parms', 'area', 'domain']:
if info.has_key(key):
del info[key]
servers.append(info)
matchingServers.append(info)
# server search list in priority. The px3 entries are used for
# dual domain for AFC.
hp = [('dx4','98000000'),('px3', '98000000'), ('dx4','98000001'),
('px3', '98000001')]
# choose one server from this domain, find first dx4, 98000000
# try to use one with the same mhsidDest as the site, which
# would be the primary operational GFE. Note that the px3 entries
# are for AFC.
found = False
for matchServer, matchPort in hp:
for server in servers:
if server['host'][0:3] == matchServer and \
server['port'] == matchPort and server['mhsid'] == siteID:
if server['mhsid'] not in msgSendDest:
chosenServers.append(server)
msgSendDest.append(server['mhsid'])
found = True
break
# find first dx4, 98000000, but perhaps a different mhsid
# this is probably not the primary operational GFE
if not found:
for matchServer, matchPort in hp:
for server in servers:
if server['host'][0:3] == matchServer and \
server['port'] == matchPort:
if server['mhsid'] not in msgSendDest:
chosenServers.append(server)
msgSendDest.append(server['mhsid'])
found = True
break
# if didn't find standard one, then take the first one, but don't
# take ourselves unless we are the only one.
if not found and servers:
for server in servers:
if server['mhsid'] != mhsid and server['host'] != host \
and server['port'] != port and \
server['mhsid'] != siteID:
if server['mhsid'] not in msgSendDest:
chosenServers.append(server)
msgSendDest.append(server['mhsid'])
found = True
if not found:
if servers[0]['mhsid'] not in msgSendDest:
chosenServers.append(servers[0])
msgSendDest.append(servers[0]['mhsid'])
# Display the set of matching servers
s = "Matching Servers:"
for x in matchingServers:
s += "\n" + irt.printServerInfo(x)
logger.info(s)
# Display the chosen set of servers
s = "Chosen Servers:"
for x in chosenServers:
s += "\n" + irt.printServerInfo(x)
logger.info(s)
irt.addDestinationXML(iscE, chosenServers)
return msgSendDest, iscE
def runFromJava(siteID, config):
import siteConfig
host = str(config.getServerHost())
@ -201,25 +75,37 @@ def runFromJava(siteID, config):
with tempfile.NamedTemporaryFile(suffix='.sendtcv', dir=tcvProductsDir, delete=False) as fp:
fname = fp.name
try:
TCVUtil.packageTCVFiles([siteID], fname, logger)
sourceServer = {'mhsid' : mhsid,
'host' : host,
'port' : port,
'protocol': protocol,
'site' : siteID}
msgSendDest, xml = createDestinationXML(siteID, host, port, protocol, mhsid, ancf, bncf, logger)
# create the XML file
with tempfile.NamedTemporaryFile(suffix='.xml', dir=tcvProductsDir, delete=False) as fd:
fnameXML = fd.name
fd.write(ElementTree.tostring(xml))
# don't send to ourselves
if mhsid in msgSendDest:
msgSendDest.remove(mhsid)
try:
if TCVUtil.packageTCVFiles([siteID], fname, logger):
destSites = VTECPartners.VTEC_TABLE_REQUEST_SITES
if not destSites:
raise Exception('No destSites defined for VTEC_TABLE_REQUEST_SITES')
irt = IrtAccess.IrtAccess(ancf, bncf, logger=logger)
msgSendDest, xml = irt.createDestinationXML(destSites, sourceServer)
if len(msgSendDest) > 0:
# Now send the message
irt = IrtAccess.IrtAccess(ancf, bncf)
logger.debug("msgSendDest: "+ str(msgSendDest))
irt.transmitFiles("PUT_TCV_FILES", msgSendDest, mhsid, [fname, fnameXML], xmtScript)
# create the XML file
with tempfile.NamedTemporaryFile(suffix='.xml', dir=tcvProductsDir, delete=False) as fd:
fnameXML = fd.name
fd.write(ElementTree.tostring(xml))
# don't send to ourselves
if mhsid in msgSendDest:
msgSendDest.remove(mhsid)
if len(msgSendDest) > 0:
# Now send the message
logger.debug("msgSendDest: "+ str(msgSendDest))
irt.transmitFiles("PUT_TCV_FILES", msgSendDest, mhsid, [fname, fnameXML], xmtScript)
else:
logger.info('No TCV files to send')
except:
logger.exception('Error sending TCV files for site: ' + siteID)