def wait(self, timeout = None): """ Wait for all threads tp terminate execute, then return. timeout: Timeout in seconds to apply before returning (float). Returns: Reference to object itself. """ T = TRACE() startTime = time.time() thrWaitingList = [] for thrHandle in self.__threadHandles: thrWaitingList.append(thrHandle) curTimeout = None while (True): if (timeout): curTimeout = (timeout - (time.time() - startTime)) if (curTimeout < 0): msg = "Timeout encountered while waiting for threads " +\ "to terminate" raise Exception, msg thrWaitingList[0].join(curTimeout) if (not thrWaitingList[0].isAlive()): del thrWaitingList[0] if (thrWaitingList == []): return self
def unpackSqlResult(self, sqlResult): """ Unpack the result from an SQL query, whereby the columns of one row in the ngas_subscribers table is queried with ngamsDb.getSubscriberInfo() (specific Subscriber specified). sqlResult: List with elements from the ngas_subscribers table (list). Returns: Reference to object itself. """ T = TRACE() self.setHostId(sqlResult[0]).\ setPortNo(sqlResult[1]).\ setPriority(sqlResult[2]).\ setId(sqlResult[3]).\ setUrl(sqlResult[4]).\ setFilterPi(sqlResult[6]).\ setFilterPiPars(sqlResult[7]).\ setLastFileIngDate(fromiso8601(sqlResult[8], local=True)).\ setConcurrentThreads(sqlResult[9]) if sqlResult[5]: self.setStartDate(fromiso8601(sqlResult[5], local=True)) else: self.setStartDate(None) return self
def updateSrvHostInfo(self, hostId, srvInfo): """ Update the information in the DB, which is managed by the server itself. All columns starting with 'srv_' in the ngas_hosts tables are defined. The values can be taken from an instance of the ngamsHostInfo class. srvInfo: List containing all information about the host. These are all fields starting with 'srv_' from 'srv_version' to 'srv_state' (list). ignoreErr: If set to 1, a possible exception thrown will be caught, and this error ignored. Otherwise the method will throw an exception itself (integer/0|1). Returns: Void. """ T = TRACE(5) sql = "UPDATE ngas_hosts SET " +\ "srv_version={0}, srv_port={1}, srv_archive={2}, " +\ "srv_retrieve={3}, srv_process={4}, srv_remove={5}, " +\ "srv_data_checking={6}, srv_state={7} WHERE host_id={8}" args = list(srvInfo) args.append(hostId) self.query2(sql, args=args) self.triggerEvents()
def getFileInfoFromDiskIdFilename(self, diskId, filename): """ The method queries the file information for a file referred to by the Disk ID for the disk hosting it and the filename as stored in the NGAS DB. diskId: ID for disk hosting the file (string). filename: NGAS (relative) filename (string). Returns: Return ngamsFileInfo object with the information for the file if found or None if the file was not found (ngamsFileInfo|None). """ T = TRACE() # Query for the file. sql = "SELECT %s FROM ngas_files nf WHERE nf.disk_id={0} AND nf.file_name={1}" sql = sql % (ngamsDbCore.getNgasFilesCols( self._file_ignore_columnname), ) # Execute the query directly and return the result. res = self.query2(sql, args=(diskId, filename)) if res: return ngamsFileInfo.ngamsFileInfo().unpackSqlResult(res[0]) else: return None
def addSrvList(self, srvList): """ Add a server list in the NGAS Server List Table and allocate a unique server list ID for it. srvList: List of servers to add (string). Returns: New server list ID (integer). """ T = TRACE() # Find a free ID. srvListId = -1 while True: srvListId = int(2**31 * random.random()) if self.getSrvListFromId(srvListId) is None: break # Write the new entry to the list. srvlist = cleanSrvList(srvList) creationDate = self.asTimestamp(time.time()) sql = "INSERT INTO ngas_srv_list (srv_list_id, srv_list, creation_date) " +\ "VALUES ({0}, {1}, {2})" self.query2(sql, args=(srvListId, srvlist, creationDate)) return srvListId
def genXml(self, genLimitedInfo=0, genFileStatus=1, ignoreUndefFields=0): """ Generate an XML DOM Node from the contents of the object. genLimitedInfo: 1 = generate only generic info (integer). genFileStatus: Generate file status (integer/0|1). ignoreUndefFields: Don't take fields, which have a length of 0 (integer/0|1). Returns: XML Dom Node (Node). """ T = TRACE(5) ign = ignoreUndefFields diskStatusEl = xml.dom.minidom.Document().createElement("DiskStatus") objStat = self.getObjStatus() for fieldName, val in objStat: if ((fieldName == "HostId") or (fieldName == "SlotId") or (fieldName == "Mounted") or (fieldName == "MountPoint") or (fieldName == "LastCheck")): if ((not genLimitedInfo) and (not ignoreValue(ign, val))): diskStatusEl.setAttribute(fieldName, str(val)) else: if (not ignoreValue(ign, val)): diskStatusEl.setAttribute(fieldName, str(val)) if (genFileStatus): for file in self.getFileObjList(): fileStatusEl = file.genXml(0, ignoreUndefFields) diskStatusEl.appendChild(fileStatusEl) return diskStatusEl
def getClusterReadyArchivingUnits(self, clusterName): """ Return list of NAUs in the local cluster with archiving capability (archiving enabled + have capacity). The resulting list of nodes will be formatted as: [<Node>:<Port>, ...] (list). clusterName: Name of cluster to consider (string). Returns: List with ready NAU nodes in the cluster (list/string). """ T = TRACE() sql = ("SELECT host_id, srv_port FROM ngas_hosts " "WHERE cluster_name={} AND host_id in " "(SELECT host_id FROM ngas_disks WHERE completed=0 " "AND mounted=1) ORDER BY host_id") res = self.query2(sql, args=(clusterName, )) if not res: return [] hostList = [] for node in res: hostList.append("%s:%s" % (node[0], node[1])) return hostList
def fileInDb(self, diskId, fileId, fileVersion=-1): """ Check if file with the given File ID is registered in NGAS DB in connection with the given Disk ID. diskId: Disk ID (string) fileId: File ID (string). fileVersion: Version of the file. If -1 version is not taken into account (integer). Returns: 1 = file found, 0 = file no found (integer). """ T = TRACE() sql = [ "SELECT file_id FROM ngas_files WHERE file_id={0} AND disk_id={1}" ] args = [fileId, diskId] if fileVersion != -1: sql.append(" AND file_version={2}") args.append(fileVersion) res = self.query2(''.join(sql), args=args) if len(res) == 1: return 1 return 0
def insertCacheEntry(self, diskId, fileId, fileVersion, cacheTime, delete): """ Insert a new cache entry into the NGAS Cache Table. diskId: Disk ID of the cache entry (string). fileId: File ID of the cache entry (string). fileVersion: File Version of the cache entry (string). cacheTime: Time the file entered in the cache (= ngas_files.ingestion_time) (float). delete: Flag indicating if the entry is scheduled for deletion (boolean). Returns: Reference to object itself. """ T = TRACE() # The entry must be inserted. sqlQuery = "INSERT INTO ngas_cache (disk_id, file_id, " +\ "file_version, cache_time, cache_delete) VALUES " +\ "({0}, {1}, {2}, {3}, {4})" delete = 1 if delete else 0 self.query2(sqlQuery, args=(diskId, fileId, fileVersion, cacheTime, delete)) return self
def getDiskIdsMountedDisks(self, host, mtRootDir): """ Get the Disk IDs for the disks mounted on the given host. A list is returned, which contains the Disk IDs of the disks mounted. host: Name of host where the disk must be mounted (string). mtRootDir: Base directory for NG/AMS (string). Returns: List with Disk IDs (list). """ T = TRACE() if not mtRootDir.endswith('/'): mtRootDir += "/" mtRootDir += "%" sql = ("SELECT disk_id FROM ngas_disks WHERE host_id={} AND mounted=1 " "AND mount_point LIKE {}") res = self.query2(sql, args=(host, mtRootDir)) if not res: return [] diskIds = [] for disk in res: diskIds.append(disk[0]) return diskIds
def insertSubscriberEntry(self, sub_obj): T = TRACE() hostId = sub_obj.getHostId() portNo = sub_obj.getPortNo() subscrId = sub_obj.getId() subscrUrl = sub_obj.getUrl() priority = sub_obj.getPriority() startDate = self.asTimestamp(sub_obj.getStartDate()) filterPlugIn = sub_obj.getFilterPi() filterPlugInPars = sub_obj.getFilterPiPars() lastFileIngDate = self.asTimestamp(sub_obj.getLastFileIngDate()) concurrent_threads = sub_obj.getConcurrentThreads() sql = ("INSERT INTO ngas_subscribers" " (host_id, srv_port, subscr_prio, subscr_id," " subscr_url, subscr_start_date," " subscr_filter_plugin," " subscr_filter_plugin_pars," " last_file_ingestion_date, concurrent_threads) " " VALUES ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9})") vals = (hostId, portNo, priority, \ subscrId, subscrUrl, startDate, \ filterPlugIn, filterPlugInPars, \ lastFileIngDate, concurrent_threads) self.query2(sql, args = vals) self.triggerEvents()
def resolveHostAddress(localHostId, dbConObj, ngamsCfgObj, hostList): """ Generate a dictionary mapping hostnames into the name of the host that should actually be contacted for communication. This is done since when using the concept of Clusters having a Master Unit as entry point, rather than contacting one of the hosts within the Private Network of the NGAS Cluster, the Master Unit of the cluster should be contacted. If for a host no information is found in the NGAS DB, the same port number as for the contacted host is taken. dbConObj: DB object used when accessing the DB (ngamsDb). hostList: List containing names of hosts for which to find the corresponding port numbers (list/string). Returns: Dictionary with hostnames as keys containing ngamsHostInfo objects (dictionary). """ T = TRACE() try: hostInfoDic = getHostInfoFromHostIds(dbConObj, hostList) except Exception, e: hostInfoDic = {} for host in hostList: hostInfoDic[host] = None
def getNgasDiskInfoFile(diskDic, slotId): """ Check if the disk has an NGAS Disk Info file. In case yes, return this. Otherwise return None. diskDic: Dictionary containing ngamsPhysDiskInfo objects with the information about the disk configuration (dictionary). slotId: Slot ID (string). Returns: A Disk Info Object (ngamsDiskInfo) or None if no NGAS Disk Info found for the disk. """ T = TRACE() # Check if there is an NgasDiskInfo file for the disk. In case yes, # load this and use these values for adding the entry in the DB. diskInfoFile = os.path.normpath(diskDic[slotId].getMountPoint() + "/" +\ NGAMS_DISK_INFO) logger.debug("Checking if NGAS Disk Info file available: %s", diskInfoFile) retVal = None if (os.path.exists(diskInfoFile)): logger.info("Found Disk Info File for disk in slot: %s", slotId) statusObj = ngamsStatus.ngamsStatus().load(diskInfoFile, 1) retVal = statusObj.getDiskStatusList()[0] return retVal
def updateSrvHostInfo(dbConObj, hostInfoObj): """ Update the information in the DB, which is managed by the server itself. All members of the ngamsHostInfo object starting with 'setSrv' are written from the object into the DB. The member set by 'setHostId()' must be defined as well. dbConObj: Instance of NG/AMS DB class (ngamsDb). hostInfoObj: Instance of the ngamsHostInfo class. The information in this object will be written in the DB (ngamsHostInfo). ignoreErr: If set to 1, a possible exception thrown will be caught, and this error ignored. Otherwise the method will throw an exception itself (integer/0|1). Returns: Void. """ T = TRACE(5) dbConObj.updateSrvHostInfo(hostInfoObj.getHostId(), [ hostInfoObj.getSrvVersion(), hostInfoObj.getSrvPort(), hostInfoObj.getSrvArchive(), hostInfoObj.getSrvRetrieve(), hostInfoObj.getSrvProcess(), hostInfoObj.getSrvRemove(), hostInfoObj.getSrvDataChecking(), hostInfoObj.getSrvState() ])
def genXml(self, storeDiskId=0, ignoreUndefFields=0): """ Generate an XML DOM Node object from the contents of this instance of ngamsFileInfo. storeDiskId: Store Disk ID in XML document (1 = store) (integer). ignoreUndefFields: Don't take fields, which have a length of 0 (integer/0|1). Returns: XML DOM Node object (Node). """ T = TRACE(5) ign = ignoreUndefFields fileStatusEl = xml.dom.minidom.Document().createElement("FileStatus") objStat = self.getObjStatus() for fieldName, val in objStat: if (fieldName == "DiskId"): if (storeDiskId and (not ignoreValue(ign, self.getDiskId()))): fileStatusEl.setAttribute("DiskId", self.getDiskId()) else: if (not ignoreValue(ign, val)): fileStatusEl.setAttribute(fieldName, str(val)) return fileStatusEl
def write(self, hostId, dbConObj, genSnapshot=1, updateDiskInfo=0): """ Write the contents of the object into the NGAS DB. dbConObj: DB connection object (ngamsDb). genSnapshot: Generate temporay snapshot file (integer/0|1). updateDiskInfo: Update automatically the disk info for the disk hosting this file (integer/0|1). Returns: Reference to object itself. """ T = TRACE(5) dbConObj.writeFileEntry(hostId, self.getDiskId(), self.getFilename(), self.getFileId(), self.getFileVersion(), self.getFormat(), self.getFileSize(), self.getUncompressedFileSize(), self.getCompression(), self.getIngestionDate(), self.getIgnore(), self.getChecksum(), self.getChecksumPlugIn(), self.getFileStatus(), self.getCreationDate(), self.getIoTime(), self.getIngestionRate(), genSnapshot=genSnapshot, updateDiskInfo=updateDiskInfo) return self
def unpackSqlResult(self, sqlQueryRes): """ Sets the members of the class from the query information as returned from ngamsDb.getFileInfoFromFileIdHostId(). sqlQueryRes: Query information (list). Return: Reference to object itself. """ T = TRACE(5) self.setDiskId(sqlQueryRes[0]) self.setFilename(sqlQueryRes[1]) self.setFileId(sqlQueryRes[2]) self.setFileVersion(sqlQueryRes[3]) self.setFormat(sqlQueryRes[4]) self.setFileSize(sqlQueryRes[5]) uncomprSz = sqlQueryRes[6] self.setUncompressedFileSize(uncomprSz) self.setCompression(sqlQueryRes[7]) if sqlQueryRes[8]: self.setIngestionDate(fromiso8601(sqlQueryRes[8], local=True)) self.setIgnore(sqlQueryRes[9]) self.setChecksum(sqlQueryRes[10]) self.setChecksumPlugIn(sqlQueryRes[11]) self.setFileStatus(sqlQueryRes[12]) if sqlQueryRes[13]: self.setCreationDate(fromiso8601(sqlQueryRes[13], local=True)) self.setIoTime(sqlQueryRes[14]) self.setIngestionRate(sqlQueryRes[15]) self.setContainerId(sqlQueryRes[16]) return self
def getDiskInfoForSlotsAndHost(self, host, slotIdList): """ From a given host and a given list of Slot IDs, the method returns a list with the disk info for the disks matching these. host: Host name where the disks considered must be mounted (string). slotIdList: List of Slot IDs for the disk considered (list). Returns: List with Disk Info objects or [] if no matches were found (list/ngamsDiskInfo). """ T = TRACE() vals = [] params = [] sql = [] sql.append("SELECT %s FROM ngas_disks nd WHERE " % ngamsDbCore.getNgasDisksCols()) if slotIdList: for p in slotIdList: params.append('{}') vals.append(p) sql.append(" nd.slot_id IN (%s) AND " % ','.join(params)) sql.append("nd.host_id={}") vals.append(host) res = self.query2(''.join(sql), args=vals) if not res: return [] return res
def getSubscrBackLogBySubscrId(self, subscrId): """ Get all entries in the Susbscriber Back-log Table to be delivered to a specific subscriber subscrId Subscriber Id Returns List containing sublist with the following information: [[<file_id>, <file_version>], ...] """ T = TRACE() # need to join ngas_file table to get the disk id!!! sql = ("SELECT a.file_id, a.file_version, b.disk_id " "FROM ngas_subscr_back_log a, ngas_files b " "WHERE a.subscr_id = {} AND a.file_id = b.file_id " "AND a.file_version = b.file_version") res = self.query2(sql, args = (subscrId,)) if not res: return [] procList = [] for fi in res: newItem = [fi[0]] + [fi[1]] + [fi[2]] procList.append(newItem) return procList
def digestXmlDic(self, xmlDic, clear=0): """ Go through the elements and attributes represented as an XML Dictionary, and build up the internal structure. xmlDic: XML Dictionary (dictionary). clear: Clear the object before processing the XML dictionary (integer/0|1). Returns: Reference to object itself. """ T = TRACE() if (clear): self.clear() xmlDicKeys = xmlDic.keys() xmlDicKeys.sort() # First element should be the root element. self.__rootElObj = xmlDic[xmlDicKeys[0]] self.__xmlDic[xmlDicKeys[0]] = xmlDic[xmlDicKeys[0]] for xmlDicKey in xmlDicKeys[1:]: logger.debug("Handling configuration parameter with key: %s", xmlDicKey) self.addElOrAttr(xmlDicKey, xmlDic[xmlDicKey]) return self
def getFileSummary3(self, fileId, hostId=None, domain=None, diskId=None, fileVersion=-1, cursor=True): """ Return information about files matching the conditions which are not in ignore and which are not marked as bad. Files are ordered by the File Version (descending). The resulting file information will be: <Host ID>, <Ip Address>, <Port>, <Mountpoint>, <Filename>, <File Version>, <format> fileId: ID of file to retrieve (string). hostId: Host ID of node hosting file (string|None). domain: Domain in which the node is residing (string|None). diskId: Disk ID of disk hosting file (string|None). fileVersion: Version of file to retrieve (integer). cursor: Return DB cursor rather than the results (boolean). Returns: Cursor object (<NG/AMS DB Cursor Object API>). """ T = TRACE(5) sql = [] vals = [] sql.append( ("SELECT nh.host_id, nh.ip_address, nh.srv_port, " "nd.mount_point, nf.file_name, nf.file_version, " "nf.format FROM ngas_files nf, ngas_disks nd, ngas_hosts nh " "WHERE nf.file_id={} AND nf.disk_id=nd.disk_id AND " "nd.host_id=nh.host_id AND nf.%s=0 AND " "nf.file_status='00000000'") % (self._file_ignore_columnname, )) vals.append(fileId) if hostId: sql.append(" AND nh.host_id={}") vals.append(hostId) if domain: sql.append(" AND nh.domain={}") vals.append(domain) if diskId: sql.append(" AND nd.disk_id={}") vals.append(diskId) if fileVersion > 0: sql.append(" AND nf.file_version={}") vals.append(fileVersion) sql.append(" ORDER BY nf.file_version DESC") return self.query2(''.join(sql), args=vals)
def getMaxDiskNumber(self, cat=None): """ Get the maximum disk index (number) in connection with the Logical Disk Names in the DB. cat: 'M' for Main, 'R' for Replication (string). Returns: The maximum disk number or None if this could not be generated (integer). """ T = TRACE() sql = [] vals = [] sql.append("SELECT logical_name FROM ngas_disks") if cat: sql.append(" WHERE logical_name LIKE {}") vals.append('%%%s-%%' % (cat, )) else: sql.append(" WHERE logical_name LIKE {} or logical_name LIKE {}") vals.append('%M-%') vals.append('%R-%') res = self.query2(''.join(sql), args=vals) if not res: return None logNameDic = {} for subRes in res: tmpName = subRes[0] logNameDic[tmpName[(len(tmpName) - 6):]] = 1 logNames = logNameDic.keys() logNames.sort() retVal = int(logNames[-1]) return retVal
def read(self, dbConObj, subscrId, hostId="", portNo=-1): """ Query information about a specific Subscriber and set the class member variables accordingly. dbConObj: Reference to DB connection object (ngamsDb). subscrId: Subscriber ID (string). hostId: Limit the query to Subscribers in connection with one host (Data Provider) (string). portNo: Limit the query to Subscribers in connection with one host (Data Provider) (integer). Returns: Reference to object itself. """ T = TRACE() res = dbConObj.getSubscriberInfo(subscrId, hostId, portNo) if not res: raise Exception('%s %s %s not found in DB' % (subscrId, hostId, portNo)) self.unpackSqlResult(res[0]) return self
def close(self): """ Close the DB pool. Returns: Void. """ T = TRACE() self.__pool.close()
def __init__(self, interface, parameters={}, createSnapshot=1, maxpoolcons=6, use_file_ignore=True, session_sql=None): """ Creates a new ngamsDbCore object using ``interface`` as the underlying PEP-249-compliant database connection driver. Connections creation parameters are given via ``parameters``. This object maintains a pool of connections to avoid connection creation overheads. The maximum amount of connections held in the pool is set via ``maxpoolcons``. Finally, some combinations of old versions of NGAS and database engines used a different column name for the same field in the "ngas_files" table. ``use_file_ignore`` controls this behavior to provide backwards-compatibility. If true, the code will use "file_ignore" for the column name as opposed to "ignore". """ T = TRACE() self.__dbSem = threading.Lock() # Controls if the snapshot of the DB should be created. self.__createSnapshot = createSnapshot # List of Event Objects which are used to inform other instances # about changes in the DB. self.__dbChangeEvents = [] # Timer for analyzing time spent for DB access self.__dbAccessTime = 0.0 # Import the DB Interface Plug-In (PEP-249 compliant) logger.info("Importing DB Module: %s", interface) self.module_name = interface self.__dbModule = importlib.import_module(interface) logger.info("DB Module param style: %s", self.__dbModule.paramstyle) logger.info("DB Module API Level: %s", self.__dbModule.apilevel) self.__paramstyle = self.__dbModule.paramstyle logger.info( 'Preparing database pool with %d connections. Initial SQL: %s', maxpoolcons, session_sql) self.__pool = PooledDB(self.__dbModule, maxshared=maxpoolcons, maxconnections=maxpoolcons, blocking=True, setsession=session_sql, **parameters) self.__dbTmpDir = "/tmp" self._use_file_ignore = use_file_ignore self._file_ignore_columnname = 'file_ignore' if use_file_ignore else 'ignore'
def getSubscriberStatus(self, subscrIds, hostId = "", portNo = -1): """ Method to query the information about the Ingestion Date of the last file delivered to the Subscriber. A list is returned, which contains the following: [(<Subscriber ID>, <Last File Ingestion Date (ISO 8601)>), ...] subscrIds: List of Subscriber ID to query (list/string). hostId: Host name of Subscriber host (string). portNo: Port number used by Subscriber host (integer). Returns: List with Subscriber status (list/tuple/string). """ T = TRACE() if not subscrIds: return [] sql = [] vals = [] sql_tmp = ("SELECT subscr_id, last_file_ingestion_date " "FROM ngas_subscribers WHERE subscr_id IN (%s)") params = [] for i in subscrIds: params.append('{}') vals.append(i) sql_tmp = sql_tmp % ','.join(params) sql.append(sql_tmp) if hostId: sql.append(" AND host_id = {}") vals.append(hostId) if portNo != -1: sql.append(" AND srv_port = {}") vals.append(portNo) res = self.query2(''.join(sql), args = vals) if not res: return [] subscrStatus = [] for subscrInfo in res: if subscrInfo[1]: lastIngDate = fromiso8601(subscrInfo[1], local=True) else: lastIngDate = None subscrStatus.append((subscrInfo[0], lastIngDate)) return subscrStatus
def _sendNotifMsg(hostId, ngamsCfgObj, type, subject, msg, recList=[], contentType=None, attachmentName=None, dataInFile=0): """ Function, which actually sends the Email Notification Message. Parameters: See notify(). Returns: Void. """ T = TRACE() lst = [] if (recList): lst = recList elif (type == NGAMS_NOTIF_ALERT): lst = ngamsCfgObj.getAlertNotifList() elif (type == NGAMS_NOTIF_ERROR): lst = ngamsCfgObj.getErrorNotifList() elif (type == NGAMS_NOTIF_DISK_SPACE): lst = ngamsCfgObj.getDiskSpaceNotifList() elif (type == NGAMS_NOTIF_DISK_CHANGE): lst = ngamsCfgObj.getDiskChangeNotifList() elif (type == NGAMS_NOTIF_NO_DISKS): lst = ngamsCfgObj.getNoDiskSpaceNotifList() elif (type == NGAMS_NOTIF_DATA_CHECK): lst = ngamsCfgObj.getDataCheckNotifList() else: pass if ((contentType == None) and (attachmentName == None) and (msg != "")): msg = "Notification Message:\n\n" + msg + "\n\n\n" +\ "Note: This is an automatically generated message" if (lst != []): subject = hostId + ": " + subject fromField = ngamsCfgObj.getSender() for recipient in lst: # Small trick to avoid to distribute emails when default values # contained in the configuration. if (recipient.find(NGAMS_DEFINE) != -1): continue logger.info("Sending Notification Message to: %s. Subject: %s", recipient, subject) try: smtpHost = ngamsCfgObj.getNotifSmtpHost() ngamsHighLevelLib.sendEmail(ngamsCfgObj, smtpHost, subject, [recipient], fromField, msg, contentType, attachmentName, dataInFile) except Exception, e: pass
def unpackFromDomNode(self, diskNode, ignoreVarDiskPars=0): """ Unpack the disk information contained in a DOM DiskStatus Node and set the members of the object accordingly. diskNode: DOM Disk Node (Node). ignoreVarDiskPars: Ignore the variable part of the disk status: Host ID, Slot ID, Mounted, Mount Point (integer/0|1). Returns: Reference to object itself. """ T = TRACE() self.setDiskId(getAttribValue(diskNode, "DiskId")) self.setArchive(getAttribValue(diskNode, "Archive")) instDate = getAttribValue(diskNode, "InstallationDate") if instDate: self.setInstallationDate(fromiso8601(instDate)) self.setType(getAttribValue(diskNode, "Type")) self.setManufacturer(getAttribValue(diskNode, "Manufacturer", 1)) self.setLogicalName(getAttribValue(diskNode, "LogicalName")) # These attributes are not contained in certain Status XML # Documents, e.g. in the NgasDiskInfo files. if (not ignoreVarDiskPars): self.setHostId(getAttribValue(diskNode, "HostId")) self.setSlotId(getAttribValue(diskNode, "SlotId")) self.setMounted(getAttribValue(diskNode, "Mounted")) self.setMountPoint(getAttribValue(diskNode, "MountPoint")) self.setNumberOfFiles(getAttribValue(diskNode, "NumberOfFiles")) self.setAvailableMb(getAttribValue(diskNode, "AvailableMb")) self.setBytesStored(getAttribValue(diskNode, "BytesStored")) self.setCompleted(getAttribValue(diskNode, "Completed")) compDate = getAttribValue(diskNode, "CompletionDate", 1) if compDate: self.setCompletionDate(fromiso8601(compDate)) self.setChecksum(getAttribValue(diskNode, "Checksum")) write_time = getAttribValue(diskNode, "TotalDiskWriteTime") if write_time: self.setTotalDiskWriteTime(float(write_time)) # Handle files. fileNodes = diskNode.getElementsByTagName("FileStatus") for fileNode in fileNodes: fileInfo = ngamsFileInfo.ngamsFileInfo().\ unpackFromDomNode(fileNode, self.getDiskId()) self.addFileObj(fileInfo) return self
def releaseGenMux(self): """ Release the general mutual exclusion semaphore. Returns: Reference to object itself. """ T = TRACE(5) self.__generalMux.release() return self
def genXml(self, critInfoNameList=[]): """ Generate an XML DOM Node object from the contents of the object. Returns: XML DOM Node (Node). """ T = TRACE() xmlDomObj = self._genXml(self.__rootElObj, critInfoNameList) return xmlDomObj