def main():
opts = parseOptions()
if (not opts):
exit(1)
#pushUrl = opts.push_url
obsList = opts.obs_list.split(',')
host = opts.push_host
port = int(opts.port)
client = ngamsPClient.ngamsPClient(host, port, timeOut = NGAMS_SOCK_TIMEOUT_DEF)
toUrl = getPushURL("%s:%d" % (host, port), gateway = proxy_archive)
stageUrl = 'http://%s/ASYNCLISTRETRIEVE' % opts.data_mover
for obsNum in obsList:
print "Checking observation: %s" % obsNum
files = getFileIdsByObsNum(obsNum)
deliverFileIds = []
for fileId in files:
# first check if MIT has it or not
if (not hasMITGotIt(client, fileId)):
deliverFileIds.append(fileId)
"""
fileName = getFileFullPath(fileId)
if (not os.path.exists(fileName)):
print "\tFile %s does not exist" % fileName
continue
onTape = ngamsMWACortexTapeApi.isFileOnTape(fileName)
if (1 == onTape):
stageFile(fileName)
print "\tPushing file %s to MIT" % fileId
archiveFile(fileName, client)
"""
else:
print "\tFile %s is already at MIT. Skip it." % fileId
myReq = AsyncListRetrieveRequest(deliverFileIds, toUrl)
strReq = pickle.dumps(myReq)
try:
print "Sending async retrieve request to the data mover %s" % opts.data_mover
request = urllib2.Request(stageUrl)
base64string = base64.encodestring('ngasmgr:ngas$dba').replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
strRes = urllib2.urlopen(request, data = strReq, timeout = NGAMS_SOCK_TIMEOUT_DEF).read()
myRes = pickle.loads(strRes)
#strRes = urllib2.urlopen(stageUrl, data = strReq, timeout = NGAMS_SOCK_TIMEOUT_DEF).read()
#myRes = pickle.loads(strRes)
if (myRes):
print myRes.errorcode
else:
print 'Response is None when async staging files for obsNum %s' % obsNum
except (UnpicklingError, socket.timeout) as uerr:
print "Something wrong while sending async retrieve request for obsNum %s, %s" % (obsNum, str(uerr))
评论列表
文章目录